From jsf80238 at gmail.com Wed Jan 1 00:30:38 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Tue, 31 Dec 2013 22:30:38 -0700 Subject: lookup xpath (other?) to value in html In-Reply-To: References: Message-ID: > For example this URL; > http://jeffco.us/ats/displaygeneral.do?sch=001690 > The the land sqft is 11082. > Google Chrome gives me the xpath to that data as; > //*[@id="content"]/p[1]/table[4]/tbody/tr[2]/td[8] > > What I would like to do (using python) is given 11082 at what xpath can that > be found? (may be more that one) > The examples I can find using google refer to, given xpath what is the value > (the opposite of what I want) Which Chrome extension are you using to get that path? Are you always interested in the square footage? Here is a solution using Beautiful Soup: $ cat square-feet.py #!/usr/bin/env python import bs4 import requests import sys url = sys.argv[1] request = requests.get(url) soup = bs4.BeautifulSoup(request.text) is_sqft_mark_found, is_total_mark_found = False, False for line in soup.get_text().splitlines(): if line.startswith("Land Sqft"): is_sqft_mark_found = True continue elif is_sqft_mark_found and line.startswith("Total"): is_total_mark_found = True continue elif is_total_mark_found: print(line.strip() + " total square feet.") break $ python3 square-feet.py http://jeffco.us/ats/displaygeneral.do?sch=001690 11082 total square feet. From nobody at gmail.com Wed Jan 1 01:39:44 2014 From: nobody at gmail.com (Travis McGee) Date: Wed, 01 Jan 2014 01:39:44 -0500 Subject: PySerial for Python 2 vs. Python 3 Message-ID: I've been working with a simple serial device that attaches to a USB port. It takes as commands short strings. I wanted to use PySerial under Python 3, and, of course had the Devil's own time getting it installed and working since everything is geared towards Python 2. Anyway, I finally got it installed, but when I try to use a statement of the sort ser.write("string") I get an exception which seems to imply that the argument needs to be an integer, rather than a string. With some minor adjustments it works just fine under Python 2, so, in a sense, this is a non-issue. However, I'd be interested to hear from anyone who can comment on what the problem is. Thanks, Travis From jeanpierreda at gmail.com Wed Jan 1 01:43:35 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 31 Dec 2013 22:43:35 -0800 Subject: PySerial for Python 2 vs. Python 3 In-Reply-To: References: Message-ID: On Tue, Dec 31, 2013 at 10:39 PM, Travis McGee wrote: > Anyway, I finally got it installed, but when I try to use a statement of the > sort ser.write("string") I get an exception which seems to imply that the > argument needs to be an integer, rather than a string. You will get the most help if you provide a minimal, self-contained, runnable example, and an example of its exact output. -- Devin From rosuav at gmail.com Wed Jan 1 01:48:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jan 2014 17:48:00 +1100 Subject: PySerial for Python 2 vs. Python 3 In-Reply-To: References: Message-ID: On Wed, Jan 1, 2014 at 5:39 PM, Travis McGee wrote: > Anyway, I finally got it installed, but when I try to use a statement of the > sort ser.write("string") I get an exception which seems to imply that the > argument needs to be an integer, rather than a string. Quoting the full exception would help! My suspicion is that it works with byte strings, not Unicode strings. So you could do: ser.write(b"string") or: ser.write("string".encode()) to turn it into a stream of bytes (the latter uses UTF-8, the former would use your source file encoding). ChrisA From vincent at vincentdavis.net Wed Jan 1 00:47:26 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Tue, 31 Dec 2013 22:47:26 -0700 Subject: lookup xpath (other?) to value in html In-Reply-To: References: Message-ID: > > Which Chrome extension are you using to get that path? Built in, right click on source > copy xpath?? Ya that gets square footage and I like how you did it, are you interested in doing that for all information on the page and also the historical pages ;-) Since I have the data for some of the pages, I got this from the county on a cd, I thought defining the xpath would be easier using bs4 or http://lxml.de/ Vincent Davis 720-301-3003 On Tue, Dec 31, 2013 at 10:30 PM, Jason Friedman wrote: > > For example this URL; > > http://jeffco.us/ats/displaygeneral.do?sch=001690 > > The the land sqft is 11082. > > Google Chrome gives me the xpath to that data as; > > //*[@id="content"]/p[1]/table[4]/tbody/tr[2]/td[8] > > > > What I would like to do (using python) is given 11082 at what xpath can > that > > be found? (may be more that one) > > The examples I can find using google refer to, given xpath what is the > value > > (the opposite of what I want) > > Which Chrome extension are you using to get that path? > > Are you always interested in the square footage? Here is a solution > using Beautiful Soup: > > $ cat square-feet.py > #!/usr/bin/env python > import bs4 > import requests > import sys > url = sys.argv[1] > request = requests.get(url) > soup = bs4.BeautifulSoup(request.text) > is_sqft_mark_found, is_total_mark_found = False, False > for line in soup.get_text().splitlines(): > if line.startswith("Land Sqft"): > is_sqft_mark_found = True > continue > elif is_sqft_mark_found and line.startswith("Total"): > is_total_mark_found = True > continue > elif is_total_mark_found: > print(line.strip() + " total square feet.") > break > > $ python3 square-feet.py http://jeffco.us/ats/displaygeneral.do?sch=001690 > 11082 total square feet. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Wed Jan 1 01:57:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 01 Jan 2014 17:57:39 +1100 Subject: PySerial for Python 2 vs. Python 3 References: Message-ID: <52c3bc64$0$29967$c3e8da3$5496439d@news.astraweb.com> Travis McGee wrote: > I've been working with a simple serial device that attaches to a USB > port. It takes as commands short strings. > > I wanted to use PySerial under Python 3, and, of course had the Devil's > own time getting it installed and working since everything is geared > towards Python 2. > > Anyway, I finally got it installed, but when I try to use a statement of > the sort ser.write("string") I get an exception which seems to imply > that the argument needs to be an integer, rather than a string. "Seems to imply"? > With some minor adjustments it works just fine under Python 2, so, in a > sense, this is a non-issue. However, I'd be interested to hear from > anyone who can comment on what the problem is. While I'd love to tell you exactly what the problem is, my crystal ball is out of action. If you'd be so kind as to copy and paste the actual exception, assuming it isn't a secret, perhaps we'll be able to tell you what it actually says. -- Steven From piet at vanoostrum.org Wed Jan 1 04:30:32 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 01 Jan 2014 10:30:32 +0100 Subject: Python/Django Extract and append only new links References: Message-ID: Max Cuban writes: > I am putting together a project using Python 2.7 Django 1.5 on Windows 7. > I believe this should be on the django group but I haven't had help > from there so I figured I would try the python list > I have the following view: > views.py: [snip] > Right now as my code stands, anytime I run it, it scraps all the links > on the frontpage of the sites selected and presents them paginated?all > afresh. However, I don't think its a good idea for the script to > read/write all the links that had previously extracted links all over > again and therefore would like to check for and append only new links. > I would like to save the previously scraped links so that over the > course of say, a week, all the links that have appeared on the > frontpage of these sites will be available on my site as older pages. > > It's my first programming project and don't know how to incorporate > this logic into my code. > > Any help/pointers/references will be greatly appreciated. > > regards, Max I don't know anything about Django, but I don't think this is a Django question. I think the best way would be to put the urls in a database with the time that they have been retrieved. Then you could retrieve the links from the database next time, and when present, sort them on time retrieved and put them at the end of the list. Now if you want to do this on a user basis you should add user information with it also (and then it would be partly a Django problem because you would get the user id from Django). -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From hayesstw at telkomsa.net Wed Jan 1 05:41:44 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Wed, 01 Jan 2014 12:41:44 +0200 Subject: Python 2.x and 3.x usage survey References: Message-ID: On Mon, 30 Dec 2013 13:56:30 -0800, Dan Stromberg wrote: >I keep hearing naysayers, nay saying about Python 3.x. > >Here's a 9 question, multiple choice survey I put together about >Python 2.x use vs Python 3.x use. > >I'd be very pleased if you could take 5 or 10 minutes to fill it out. I had a look at it, but I've got about as far as "Hello World" in both. I borrowed a book called "Learning Python" by Lutz and Asher, which is geared for 2.2/2.3. But the version I have in Windows is 3.2, and it seems that even "Hello World" presents and insurmountable problem. Eventually I discovered that one of the differences bytween 2.x and 3.x is that the former has "print" and the latter has "print()" but weven using that it tells me it cant find the PRN device or something. I've got 2.x on Linux, so I booted into that and it seemed to work there, but it seems that the differences between the versions are not trivial. So perhaps I should just try to install 2.x in Windows, and learn that. -- 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 rosuav at gmail.com Wed Jan 1 05:52:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jan 2014 21:52:56 +1100 Subject: Python 2.x and 3.x usage survey In-Reply-To: References: Message-ID: On Wed, Jan 1, 2014 at 9:41 PM, Steve Hayes wrote: > I borrowed a book called "Learning Python" by Lutz and Asher, which is geared > for 2.2/2.3. That's really REALLY old. Even Red Hat isn't still supporting 2.2. You can quite easily get started on 3.2 on Windows - though I would recommend grabbing 3.3 and using that - just start with this tutorial: http://docs.python.org/3/tutorial/ I don't know exactly what will be different in 2.2, but there's no point learning a version that old. If nothing else, you'll miss out on a lot of neat features. ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 1 06:37:45 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 01 Jan 2014 22:37:45 +1100 Subject: Python 2.x and 3.x usage survey References: Message-ID: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Steve Hayes wrote: > I borrowed a book called "Learning Python" by Lutz and Asher, which is > geared for 2.2/2.3. > > But the version I have in Windows is 3.2, and it seems that even "Hello > World" presents and insurmountable problem. It certainly is not *insurmountable*. Not unless you consider typing brackets ( ) to be an inhumanly difficult task, in which case you might as well give up on being a programmer and take up something easier like brain surgery. # Python 2 version print "Hello World!" # Python 3 version print("Hello World!") > Eventually I discovered that one of the differences bytween 2.x and 3.x is > that the former has "print" and the latter has "print()" but weven using > that it tells me it cant find the PRN device or something. Possibly you're trying to run print("Hello World") at the DOS command prompt rather than using Python. I'm not sure exactly what you're doing, but I do know that you shouldn't get any errors about the PRN device from Python. That sounds like it is a Windows error. > I've got 2.x on Linux, so I booted into that and it seemed to work there, > but it seems that the differences between the versions are not trivial. For the most part, they are trivial. With only a few exceptions, everything in Python 2 can be easily, even mechanically, translated to Python 3. Python 3 includes a lot of new features that a Python 2.3 book won't even mention. But if course, since the book doesn't mention them, you won't need to deal with them. It also includes a few changes from statements to functions, like print and exec (but as a beginner, you shouldn't be using exec). A few modules have been renamed. In my personal opinion, the most annoying change from Python 2 to 3 is renaming modules, because I can never remember the new name. None of these are *difficult* changes. As a beginner, of course, you cannot be expected to automatically know how to deal with a problem like this one: py> from StringIO import StringIO Traceback (most recent call last): File "", line 1, in ImportError: No module named 'StringIO' But let me give you a secret known only to a few: to solve this problem is not hard. Just google for "StringIO renamed Python 3". which will take you to the "What's New in Python 3" document, which reveals that the StringIO module is renamed to io.StringIO, and so you should use this instead: from io import StringIO https://duckduckgo.com/?q=StringIO%20renamed%20Python%203 If googling fails, feel free to ask here! -- Steven From hayesstw at telkomsa.net Wed Jan 1 07:38:59 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Wed, 01 Jan 2014 14:38:59 +0200 Subject: Python 2.x and 3.x usage survey References: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 01 Jan 2014 22:37:45 +1100, Steven D'Aprano wrote: >Steve Hayes wrote: > >> I borrowed a book called "Learning Python" by Lutz and Asher, which is >> geared for 2.2/2.3. >> >> But the version I have in Windows is 3.2, and it seems that even "Hello >> World" presents and insurmountable problem. > >It certainly is not *insurmountable*. Not unless you consider typing >brackets ( ) to be an inhumanly difficult task, in which case you might as >well give up on being a programmer and take up something easier like brain >surgery. > ># Python 2 version >print "Hello World!" > ># Python 3 version >print("Hello World!") I was thinking or of this: >>> python g:\work\module1.py File "", line 1 python g:\work\module1.py ^ Which gave a different error the previous time I did it. But, hey, it worked from the DOS prompt C:\Python32>python g:\work\module1.py Hello Module World But hey, don't mind me. The biggest problem I have is that when something doesn't work, I don't know if I have done something stupid, or if it's just an incompatibility of the different versions. -- 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 rosuav at gmail.com Wed Jan 1 07:39:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 1 Jan 2014 23:39:57 +1100 Subject: Python 2.x and 3.x usage survey In-Reply-To: References: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 1, 2014 at 11:38 PM, Steve Hayes wrote: > I was thinking or of this: > >>>> python g:\work\module1.py > File "", line 1 > python g:\work\module1.py > ^ > > Which gave a different error the previous time I did it. > > But, hey, it worked from the DOS prompt > > C:\Python32>python g:\work\module1.py > Hello Module World That's how you invoke a script. Python isn't fundamentally a shell scripting language (like bash, REXX, batch, etc), so there's a distinct difference between Python commands (which go into .py files or are executed at the ">>>" prompt) and shell commands (including "python", which invokes the Python interpreter). > The biggest problem I have is that when something doesn't work, I don't know > if I have done something stupid, or if it's just an incompatibility of the > different versions. Easiest way to eliminate the confusion is to match your tutorial and your interpreter. That's why I recommend going with the python.org tutorial; you can drop down the little box in the top left and choose the exact version of Python that you're running. It WILL match. ChrisA From breamoreboy at yahoo.co.uk Wed Jan 1 07:44:42 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 01 Jan 2014 12:44:42 +0000 Subject: Python 2.x and 3.x usage survey In-Reply-To: References: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/01/2014 12:38, Steve Hayes wrote: > On Wed, 01 Jan 2014 22:37:45 +1100, Steven D'Aprano > wrote: > >> Steve Hayes wrote: >> >>> I borrowed a book called "Learning Python" by Lutz and Asher, which is >>> geared for 2.2/2.3. >>> >>> But the version I have in Windows is 3.2, and it seems that even "Hello >>> World" presents and insurmountable problem. >> >> It certainly is not *insurmountable*. Not unless you consider typing >> brackets ( ) to be an inhumanly difficult task, in which case you might as >> well give up on being a programmer and take up something easier like brain >> surgery. >> >> # Python 2 version >> print "Hello World!" >> >> # Python 3 version >> print("Hello World!") > > I was thinking or of this: > >>>> python g:\work\module1.py > File "", line 1 > python g:\work\module1.py > ^ > > Which gave a different error the previous time I did it. > > But, hey, it worked from the DOS prompt > > C:\Python32>python g:\work\module1.py > Hello Module World > > But hey, don't mind me. > > The biggest problem I have is that when something doesn't work, I don't know > if I have done something stupid, or if it's just an incompatibility of the > different versions. > Almost inevitably if you search for the last line of the error that you get you'll find more than enough hits to point you in the right direction. Failing that ask here as we don't bite. There's also the tutor mailing list https://mail.python.org/mailman/listinfo/tutor -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bouncingcats at gmail.com Wed Jan 1 09:07:54 2014 From: bouncingcats at gmail.com (David) Date: Thu, 2 Jan 2014 01:07:54 +1100 Subject: Python 2.x and 3.x usage survey In-Reply-To: References: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1 January 2014 23:38, Steve Hayes wrote: > > I was thinking or of this: > >>>> python g:\work\module1.py > File "", line 1 > python g:\work\module1.py > ^ > > Which gave a different error the previous time I did it. > > But, hey, it worked from the DOS prompt > > C:\Python32>python g:\work\module1.py > Hello Module World Your windows command shell prompt looks like this: "C:\Python32>" It indicates that windows shell is waiting for you to type something. It expects the first word you type to be an executable command. If you do this: C:\Python32>python g:\work\module1.py it tells the shell to run the python interpreter and feed it all the python statments contained in the file g:\work\module1.py If you do this: C:\Python32>python it tells the shell to run the python interpreter interactively, and wait for you to directly type python statements. When the python intepreter is ready for you to type a python statement, it gives you a ">>>" prompt. It expects you to type a valid python language statement. The reason this gave an error: >>> python g:\work\module1.py is because you are using the python interpreter as shown by ">>>", but you typed a windows shell command, not a python statement. From davea at davea.name Wed Jan 1 09:32:37 2014 From: davea at davea.name (Dave Angel) Date: Wed, 01 Jan 2014 09:32:37 -0500 Subject: Python 2.x and 3.x usage survey In-Reply-To: References: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, 01 Jan 2014 14:38:59 +0200, Steve Hayes wrote: > >>> python g:\work\module1.py > File "", line 1 > python g:\work\module1.py > ^ > Which gave a different error the previous time I did it. > But, hey, it worked from the DOS prompt > C:\Python32>python g:\work\module1.py > Hello Module World You need to understand that you are using two VERY different languages, one at the DOS prompt, the other at the python prompt and in .py files. You cannot use shell syntax at the python prompt, any more than you can do the reverse. -- DaveA From angedward3 at gmail.com Wed Jan 1 09:53:48 2014 From: angedward3 at gmail.com (angedward3 at gmail.com) Date: Wed, 1 Jan 2014 06:53:48 -0800 (PST) Subject: Retaining drawing across paintevents Message-ID: <396bc9f8-2ed6-4ebf-853d-a50e3c7ce521@googlegroups.com> Hi all, I am sub-classing the paintevent at the moment to create a 2D plot. I find that I have to re-paint the whole widget every time I call an update(), as I have create a new QPainter() instance. Is there a way to update only a small part of the widget, while retaining the rest of the widget? Thanks in advance Ed BTW if this is the wrong forum to post this, pls let me know. From amirouche.boubekki at gmail.com Wed Jan 1 10:01:41 2014 From: amirouche.boubekki at gmail.com (Amirouche Boubekki) Date: Wed, 1 Jan 2014 16:01:41 +0100 Subject: [OT] Culture and Empire Message-ID: H?llo everybody, I stumbled on Culture and Empire a few days ago and I've been reading it since then. I'm not finished yet. It's insigthful, smart and provocative. It bridge past, present and future. I will put it in my armory *ahem* library between Fundation and The Cathedral and the Bazaar until I read Present Shock. This is the book you want, need and will read this year if any. I quick glimpse into the very readable book: ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8< Chapter 1. Magic Machines Far away, in a different place, a civilization called Culture had taken seed, and was growing. It owned little except a magic spell called Knowledge. In this chapter, I?ll examine how the Internet is changing our society. It?s happening quickly. The most significant changes have occurred during just the last 10 years or so. More and more of our knowledge about the world and other people is transmitted and stored digitally. What we know and who we know are moving out of our minds and into databases. These changes scare many people, whereas in fact they contain the potential to free us, empowering us to improve society in ways that were never before possible. -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<----- There is also a presentation of the content of the book that I didn't review yet. But it seems like you don't need to read all the book to understand what is in inside. There is also a related crowdfunding project, but I don't know more that since I want to finish the book first. http://cultureandempire.com/ Happy new year (indeed), Amirouche ~ http://hypermove.net/ From rosuav at gmail.com Wed Jan 1 10:05:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 2 Jan 2014 02:05:56 +1100 Subject: Retaining drawing across paintevents In-Reply-To: <396bc9f8-2ed6-4ebf-853d-a50e3c7ce521@googlegroups.com> References: <396bc9f8-2ed6-4ebf-853d-a50e3c7ce521@googlegroups.com> Message-ID: On Thu, Jan 2, 2014 at 1:53 AM, wrote: > I find that I have to re-paint the whole widget every time I call an update(), as I have create a new QPainter() instance. Is there a way to update only a small part of the widget, while retaining the rest of the widget? In general, it would help to say which windowing toolkit you're using :) Fortunately you mention something that implies you're using QT, so I'm going to forge ahead with that. When you call update(), you're effectively saying "the whole object needs to be repainted". If you can restrict that to just a particular rectangle, simply pass those coordinates to the update call: http://pyqt.sourceforge.net/Docs/PyQt4/qwidget.html#update-4 I'm not sure if you're using PyQt4 or not, but if you're using something else, look through its docs for a similar function. Same goes for pretty much any windowing toolkit; it's always possible to report that a small area needs updating. Once you then get the update event, you should be given a rectangle that tells you which part needs to be repainted. But painting outside that area will be reasonably fast, so don't stress too much about that part if it's a lot of trouble. For instance, I have a MUD client that will always attempt to draw complete lines, even if only part of a line needs to be redrawn - but it'll repaint only those lines which need repainting (so it looks at the Y coordinates of the "please repaint me" rectangle, but not the X coords). ChrisA From ivanmarinkoviczu at gmail.com Wed Jan 1 12:37:34 2014 From: ivanmarinkoviczu at gmail.com (ivanmarinkoviczu at gmail.com) Date: Wed, 1 Jan 2014 09:37:34 -0800 (PST) Subject: Project from github Message-ID: Hi, I'm trying to install this Django project https://github.com/changer/socialschools-cms and it 'success'. The problem is, there's no manage.py file in it and i don't know how to run this script on the server. May someone try to help me, please? Thank you very much! Ivan From hayesstw at telkomsa.net Wed Jan 1 12:55:23 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Wed, 01 Jan 2014 19:55:23 +0200 Subject: Python 2.x and 3.x usage survey References: <52c3fe0b$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 2 Jan 2014 01:07:54 +1100, David wrote: >On 1 January 2014 23:38, Steve Hayes wrote: >> >> I was thinking or of this: >> >>>>> python g:\work\module1.py >> File "", line 1 >> python g:\work\module1.py >> ^ >> >> Which gave a different error the previous time I did it. >> >> But, hey, it worked from the DOS prompt >> >> C:\Python32>python g:\work\module1.py >> Hello Module World > >Your windows command shell prompt looks like this: "C:\Python32>" >It indicates that windows shell is waiting for you to type something. >It expects the first word you type to be an executable command. If you >do this: > C:\Python32>python g:\work\module1.py >it tells the shell to run the python interpreter and feed it all the >python statments contained in the file g:\work\module1.py > >If you do this: > C:\Python32>python >it tells the shell to run the python interpreter interactively, and >wait for you to directly type python statements. When the python >intepreter is ready for you to type a python statement, it gives you a >">>>" prompt. It expects you to type a valid python language >statement. > >The reason this gave an error: >>>> python g:\work\module1.py > >is because you are using the python interpreter as shown by ">>>", but >you typed a windows shell command, not a python statement. Thank you. Back to the book! -- 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 tjreedy at udel.edu Wed Jan 1 14:54:05 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Jan 2014 14:54:05 -0500 Subject: PySerial for Python 2 vs. Python 3 In-Reply-To: References: Message-ID: On 1/1/2014 1:48 AM, Chris Angelico wrote: > On Wed, Jan 1, 2014 at 5:39 PM, Travis McGee wrote: What OS? If Windows, did you install the -py3k version for 3.x? >> Anyway, I finally got it installed, but when I try to use a statement of the >> sort ser.write("string") I get an exception which seems to imply that the >> argument needs to be an integer, rather than a string. According to a Stackoverflow issue, .write(n) will write n 0 bytes because it will send bytes(n) == n * bytes(b'\0'). PySerial is written in Python, so you could look at the .write method of the Serial class (presuming that 'ser' is an instance thereof) to see what it does. > Quoting the full exception would help! > > My suspicion is that it works with byte strings, not Unicode strings. That is what the doc either says or implies. > So you could do: > > ser.write(b"string") > > or: > > ser.write("string".encode()) > > to turn it into a stream of bytes (the latter uses UTF-8, the former > would use your source file encoding). -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 1 15:24:52 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 01 Jan 2014 15:24:52 -0500 Subject: [OT] Culture and Empire In-Reply-To: References: Message-ID: On 1/1/2014 10:01 AM, Amirouche Boubekki wrote: > I stumbled on Culture and Empire a few days ago and I've been reading > it since then. I'm not finished yet. It's insigthful, smart and > provocative. It bridge past, present and future. I will put it in my > armory *ahem* library between Fundation and The Cathedral and the > Bazaar until I read Present Shock. This is the book you want, need and > will read this year if any. > ---8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8< > > Chapter 1. Magic Machines > > Far away, in a different place, a civilization called Culture had > taken seed, and was growing. It owned little except a magic spell > called Knowledge. > > In this chapter, I?ll examine how the Internet is changing our > society. It?s happening quickly. The most significant changes have > occurred during just the last 10 years or so. More and more of our > knowledge about the world and other people is transmitted and stored > digitally. What we know and who we know are moving out of our minds > and into databases. These changes scare many people, whereas in fact > they contain the potential to free us, empowering us to improve > society in ways that were never before possible. > > -----8<-----8<-----8<-----8<-----8<-----8<-----8<-----8<----- > > http://cultureandempire.com/ The entire book appears to be free and online with a liberal licence "Free to share and remix under CC-BY-SA-3.0" so this is not a commercial ad. I am reading it now. -- Terry Jan Reedy From submissionfighting at gmx.com Wed Jan 1 16:45:45 2014 From: submissionfighting at gmx.com (Jacob Goodson) Date: Wed, 1 Jan 2014 13:45:45 -0800 (PST) Subject: ipython and pyglet Message-ID: <1c401967-c672-448c-8e4b-bef9f933847c@googlegroups.com> Hello! Has anyone here tried to get ipython to interact with the event loop for pyglet? If so, would you be willing to share come example code? I would like to be able to interactively code in pyglet, creating and updating objects while the program is running. Thanks! From gary719_list1 at verizon.net Wed Jan 1 20:51:10 2014 From: gary719_list1 at verizon.net (Gary Roach) Date: Wed, 01 Jan 2014 17:51:10 -0800 Subject: Django filer plugins for django-cms installation Message-ID: <52C4C60E.9080903@verizon.net> I'm trying to set up a python django_cms system using: Debian OS Wheezy distribution Python 2.7.3 ` Django 1.5.5 PostgreSQL 9.1 with pip and virtualenv. The last test errored out and I traced the problem to the missing cmsplugin-filer-0.9.4.tar.gz package not being installed. The settings.py file has been properly annotated. Where should I put the untared files in a typical Debian Wheezy installation. All help will be sincerely appreciated. Gary R. From alec.taylor6 at gmail.com Thu Jan 2 00:40:19 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 2 Jan 2014 16:40:19 +1100 Subject: Suggest an open-source log analyser? Message-ID: I use the Python logger class; with the example syntax of: Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') Can of course easily use e.g.: a JSON syntax here instead. Are there any open-source log viewers (e.g.: with a web-interface) that you'd recommend; for drilling down into my logs? Thanks for your suggestions, Alec Taylor From roy at panix.com Thu Jan 2 00:48:02 2014 From: roy at panix.com (Roy Smith) Date: Thu, 02 Jan 2014 00:48:02 -0500 Subject: Suggest an open-source log analyser? References: Message-ID: In article , Alec Taylor wrote: > I use the Python logger class; with the example syntax of: > Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') > > Can of course easily use e.g.: a JSON syntax here instead. > > Are there any open-source log viewers (e.g.: with a web-interface) > that you'd recommend; for drilling down into my logs? > > Thanks for your suggestions, > > Alec Taylor I've been experimenting with elasticsearch (to store JSON-format log messages) and kibana (as a front-end search tool). The jury is still out on how well it's going to work. It seems like a pretty powerful combination, but there's definitely a bit of a learning curve to using it. I certainly like the idea of logging structured data, as opposed to plain text. It opens up a world of better ways to search, slice, and dice your log data. From ben+python at benfinney.id.au Thu Jan 2 00:52:11 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 02 Jan 2014 16:52:11 +1100 Subject: looking for a quote on age and technology References: Message-ID: <7wbnzvhqwk.fsf@benfinney.id.au> Rustom Mody writes: > For a new technology: > If you are a kid when it comes out, you just take it as a matter of course > If you are a young adult, then it becomes a hot topic for discussion > If you are past middle-age you never get it > > Anyone knows/remembers it? I think you're referring to an article by the late, great Douglas Adams, ?How to Stop Worrying and Learn to Love the Internet?: I suppose earlier generations had to sit through all this huffing and puffing with the invention of television, the phone, cinema, radio, the car, the bicycle, printing, the wheel and so on, but you would think we would learn the way these things work, which is this: 1) everything that?s already in the world when you?re born is just normal; 2) anything that gets invented between then and before you turn thirty is incredibly exciting and creative and with any luck you can make a career out of it; 3) anything that gets invented after you?re thirty is against the natural order of things and the beginning of the end of civilisation as we know it until it?s been around for about ten years when it gradually turns out to be alright really. Apply this list to movies, rock music, word processors and mobile phones to work out how old you are. -- \ ?For fast acting relief, try slowing down.? ?Jane Wagner, via | `\ Lily Tomlin | _o__) | Ben Finney From alokmahor at gmail.com Thu Jan 2 04:04:38 2014 From: alokmahor at gmail.com (Alok Singh Mahor) Date: Thu, 2 Jan 2014 14:34:38 +0530 Subject: editing video using python Message-ID: Hello everyone, I want to join 2 or 3 video and want to add effect of fading in and out. I also want to add text strip on the video. I am not able to decide what to adopt for doing this task. I have option of MLT ( http://www.mltframework.org/bin/view/MLT/WebHome ) but I guess its too complex and I didnt find any documentation of MLT I have another option of FFmpeg, but I am not sure whether I can do all three requirement with ffmpeg. if I adopt ffmpeg then should I use ffmpeg's wrapper for python like http://code.google.com/p/pyffmpeg/ or I should use pure ffmpeg in python as subprocess? how is pymedia? can I do my task with pymedia? please tell me easy way to do my task in python. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From dss.leb at gmail.com Thu Jan 2 06:37:59 2014 From: dss.leb at gmail.com (d ss) Date: Thu, 2 Jan 2014 03:37:59 -0800 (PST) Subject: python finance Message-ID: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> dailystockselect.com needs a couple of talented python people for the development and implementation of new trading strategies. it may be also some pythonic design change for the displayed figures now the web app consists of 1 of the 8 conceived strategies. contact us at the email on the website for more details Samir From invalid at invalid.invalid Thu Jan 2 11:23:22 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Jan 2014 16:23:22 +0000 (UTC) Subject: need to print seconds from the epoch including the millisecond References: <59aa73ac-e06e-4c0e-83a4-147ac42cad2e@googlegroups.com> <52bcaeed$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-26, Steven D'Aprano wrote: > matt.doolittle33 at gmail.com wrote: > >> On Thursday, December 26, 2013 2:22:10 PM UTC-5, Dan Stromberg wrote: >>> On Thu, Dec 26, 2013 at 10:32 AM, wrote: >>> >>> > i am using 2.7. I need to print the time in seconds from the epoch >>> > with millisecond precision. i have tried many things but have failed. > [...] >>> In [1]: import time >>> In [2]: time.time() >>> Out[2]: 1388085670.1567955 >> >> >> OK i did what you said but I am only getting 2 decimal places. >> Why is this and what can I do to get the millisecond? > > Please show *exactly* what you did. Also please tell us what operating > system you are using. It may be that your operating system's clock doesn't > provide millisecond precision. AFAIK, that's irrelevent. time.time() returns a float. On all the CPython implementations I know of, that is a 64-bit IEEE format, which provides 16 decimal digits of precision regardless of the granularity of the system time value. At this point in time, that means 10 digits left of the decimal point and 6 to the right. -- Grant Edwards grant.b.edwards Yow! Will the third world at war keep "Bosom Buddies" gmail.com off the air? From invalid at invalid.invalid Thu Jan 2 11:28:11 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Jan 2014 16:28:11 +0000 (UTC) Subject: So, what's the real story on Python 2 vs Python 3? References: Message-ID: On 2013-12-27, Travis McGee wrote: > The Python.org site says that the future is Python 3, yet whenever I > try something new in Python, such as Tkinter which I am learning now, > everything seems to default to Python 2. By this I mean that, > whenever I find that I need to install another package, it shows up > as Python 2 unless I explicitly specify Python 3. That's a function of whatever you're using to "install another package". I can tell you how to configure Gentoo Linux so that portage/emerge always installs Python packages for Python 3, Python 2, or both. > What's the deal? If I want to make a distributable software package, > should it be 2 or 3? Both. :) -- Grant Edwards grant.b.edwards Yow! This ASEXUAL PIG at really BOILS my BLOOD gmail.com ... He's so ... so ... URGENT!! From invalid at invalid.invalid Thu Jan 2 11:34:46 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Jan 2014 16:34:46 +0000 (UTC) Subject: So, what's the real story on Python 2 vs Python 3? References: Message-ID: On 2013-12-27, Andrew Berg wrote: > On 2013.12.26 23:04, Travis McGee wrote: >> The Python.org site says that the future is Python 3, yet whenever I try >> something new in Python, such as Tkinter which I am learning now, >> everything seems to default to Python 2. By this I mean that, whenever I >> find that I need to install another package, it shows up as Python 2 >> unless I explicitly specify Python 3. >> >> What's the deal? If I want to make a distributable software package, >> should it be 2 or 3? Enquiring minds want to know. > > Oh boy, another 2 vs. 3 thread! > > Always use 3 unless you absolutely have to use 2. Python 3 is not a > shiny new thing. It is *five* years old at this point While Python 3 may not be shiney and new, the Python 3 support in some third-party packages and libraries is still shiney and new at best, and missing at worst. The situation is improving steadily, and while I do try to write new code work with both 2.7 and 3.x, I still use 2.7 for my day-to-day work. -- Grant Edwards grant.b.edwards Yow! Of course, you at UNDERSTAND about the PLAIDS gmail.com in the SPIN CYCLE -- From rajkumar84730 at gmail.com Thu Jan 2 11:31:53 2014 From: rajkumar84730 at gmail.com (raj kumar) Date: Thu, 2 Jan 2014 22:01:53 +0530 Subject: About some problem Message-ID: Hello, I am beginner to python and i am writing following code from pytesser import * and i am getting an error as follow Traceback (most recent call last): File "", line 1, in File "C:\Python33\lib\site-packages\pytesser.py", line 61 print text ^ SyntaxError: invalid syntax How to resolve it ? Give me all steps to resolve it. -------------- next part -------------- An HTML attachment was scrubbed... URL: From joel.goldstick at gmail.com Thu Jan 2 11:53:13 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Thu, 2 Jan 2014 11:53:13 -0500 Subject: About some problem In-Reply-To: References: Message-ID: On Thu, Jan 2, 2014 at 11:31 AM, raj kumar wrote: > Hello, I am beginner to python and i am writing following code > > from pytesser import * > > and i am getting an error as follow > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python33\lib\site-packages\pytesser.py", line 61 > print text > ^ > SyntaxError: invalid syntax > > > How to resolve it ? Give me all steps to resolve it. > > -- > https://mail.python.org/mailman/listinfo/python-list > > First, you should give version and os when you ask a question. However it is clear you are using python 3.3 and Windows. Your print statement implies that pytesser.py is written in the 2.x dialect of python. In version 3.x print became a function and requires parenthesis around the arguments. So, you need to find a version of pytesser.py that is compatible with python 3, or if you can't do that, and you need pytesser.py, you have to install python 2.7 Also, this is usually a bad idea: from pytesser import * Probably better not to muddle the namespace with a chance of naming collisions and do: import pytesser Good luck. Come back after you've had a go with those ideas -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From invalid at invalid.invalid Thu Jan 2 11:55:01 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 2 Jan 2014 16:55:01 +0000 (UTC) Subject: Python 2.x and 3.x usage survey References: <52c29782$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2013-12-31, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> On 30/12/2013 21:56, Dan Stromberg wrote: >>> I keep hearing naysayers, nay saying about Python 3.x. >>> >>> Here's a 9 question, multiple choice survey I put together about >>> Python 2.x use vs Python 3.x use. >>> >>> I'd be very pleased if you could take 5 or 10 minutes to fill it out. >>> >>> Here's the URL: >>> https://www.surveymonkey.com/s/N5N5PG2 >>> >> >> People using 1.x will be miffed as their baby has been missed out :) > > You laugh, but there was at least one attendee at the last PyCon who was > still using 1.5 professionally. Software never quite dies so long as there > is hardware capable of running it. ITYM: ... so long as there is hardware capable of running an emulator that is capable of running it. -- Grant Edwards grant.b.edwards Yow! I don't understand at the HUMOUR of the THREE gmail.com STOOGES!! From breamoreboy at yahoo.co.uk Thu Jan 2 12:01:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 02 Jan 2014 17:01:08 +0000 Subject: About some problem In-Reply-To: References: Message-ID: On 02/01/2014 16:53, Joel Goldstick wrote: > > > > On Thu, Jan 2, 2014 at 11:31 AM, raj kumar > wrote: > > Hello, I am beginner to python and i am writing following code > > from pytesser import * > > and i am getting an error as follow > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python33\lib\site-packages\pytesser.py", line 61 > print text > ^ > SyntaxError: invalid syntax > > > How to resolve it ? Give me all steps to resolve it. "Please" goes a long way. > > -- > https://mail.python.org/mailman/listinfo/python-list > > First, you should give version and os when you ask a question. However > it is clear you are using python 3.3 and Windows. > > Your print statement implies that pytesser.py is written in the 2.x > dialect of python. In version 3.x print became a function and requires > parenthesis around the arguments. > > So, you need to find a version of pytesser.py that is compatible with > python 3, or if you can't do that, and you need pytesser.py, you have to > install python 2.7 > What's wrong with making a compatible version using this command? 2to3 -w pytesser.py -- 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 Thu Jan 2 12:05:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 2 Jan 2014 22:35:26 +0530 Subject: About some problem In-Reply-To: References: Message-ID: On Thu, Jan 2, 2014 at 10:23 PM, Joel Goldstick wrote: > > > > On Thu, Jan 2, 2014 at 11:31 AM, raj kumar wrote: >> >> Hello, I am beginner to python and i am writing following code >> >> from pytesser import * >> >> and i am getting an error as follow >> >> Traceback (most recent call last): >> File "", line 1, in >> File "C:\Python33\lib\site-packages\pytesser.py", line 61 >> print text >> ^ >> SyntaxError: invalid syntax >> >> >> How to resolve it ? Give me all steps to resolve it. >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > First, you should give version and os when you ask a question. However it > is clear you are using python 3.3 and Windows. > > Your print statement implies that pytesser.py is written in the 2.x dialect > of python. In version 3.x print became a function and requires parenthesis > around the arguments. > > So, you need to find a version of pytesser.py that is compatible with python > 3, or if you can't do that, and you need pytesser.py, you have to install > python 2.7 > > Also, this is usually a bad idea: > > from pytesser import * > > Probably better not to muddle the namespace with a chance of naming > collisions and do: > > import pytesser > > > Good luck. Come back after you've had a go with those ideas i'm not sure about this but isnt it normally the case that different version modules dont get mixed up like that? IOW if pytesser was a properly packaged 2.7 module would python 3 be able to get at it ?? From rustompmody at gmail.com Thu Jan 2 11:53:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 2 Jan 2014 22:23:21 +0530 Subject: looking for a quote on age and technology Message-ID: On Thu, Jan 2, 2014 at 11:22 AM, Ben Finney wrote: > I think you're referring to an article by the late, great Douglas Adams, > ?How to Stop Worrying and Learn to Love the Internet?: Thanks Ben -- Yes thats the one I was looking for! From pydev at allsup.co Thu Jan 2 12:20:54 2014 From: pydev at allsup.co (John Allsup) Date: Thu, 02 Jan 2014 17:20:54 +0000 Subject: Ifs and assignments Message-ID: <52C59FF6.5000607@allsup.co> Hi, This is my debut on this list. In many languages, such as C, one can use assignments in conditionals and expressions. The most common, and useful case turns up when you have if/else if/else if/else constructs. Consider the following non-working pseudoPython. import re r1 = re.compile("hello (\d)") r2 = re.compile("world([!?])") w = "hello world!" if m = r1.search(w): handleMatch1(m) elif m = r2.search(w): handleMatch2(m) else: print("No match") If the regular expressions are complex, running them multiple times (once to test, another to capture groups) isn't ideal. On the other hand, at present, one has to either do: m = r1.search(w) if m: handleMatch1(m) else: m = r2.search(w) if m: handleMatch2(m) else: print("No match") if not running unnecessary matches, yet capturing groups in the event of a successful match, is what is desired. If there are multiple tests, the indentation gets silly. This arises because having removed the ability to assign in an expression, there is no way to save the result of a function call that is used in a conditional at all. I am aware that this facility in C is a source of bugs, = being only a typo away from the more common ==. With exceptions and contexts, we have: with open("file") as f: doSomethingWith(f) try: trySomething() except SomethingRandomGoingWrong as e: lookAtException(e) What I am wondering is why not use a similar syntax with if, so that one could do if r1.search(w) as m: g = m.groups() print(g[1]) This would remove the risk of errors by typos since the syntax for equality testing (if x == y:) is completely different from that for assigning in a conditional (which would look like 'if y as x:' Related would be to have Nonetype work with contexts such that with None as x: doStuff(x) would do nothing. This would allow things like: with maybeGetSomething as x: doStuff(x) to call doStuff(x) within a context of maybeGetSomething returns something, or do nothing if nothing is returned. (Adding an else-like keyword to with, or possibly using else in that context, would allow one to process a non-None object if returned, or else do something in response to a None object being returned by the maybeGetSomething.) Just a thought. Or what is the current 'Pythonic' way to do something like: if x = func1(): do1(x) elif x = func2(): do2(x) elif x = func3(): do3(x) elif x = func4(): do4(x) else: do5() where each of func1,func2,func3,func4 have side effects so that func2 is tested if and only if func1 returns a false value, func1 must be called only once, and what is returned from func1 must be available to the code inside the if block? John From jcasale at activenetwerx.com Thu Jan 2 12:29:59 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 2 Jan 2014 17:29:59 +0000 Subject: Argparse class method based instantiation Message-ID: I have an Python3 argparse implementation that is invoked as a method from an imported class within a users script __main__. When argparse is setup in __main__ instead, all the help switches produce help then exit. When a help switch is passed based on the above implementation, they are ignored? Anyone seen this and or know of a workaround? Thanks, jlc From robin at reportlab.com Thu Jan 2 12:36:58 2014 From: robin at reportlab.com (Robin Becker) Date: Thu, 02 Jan 2014 17:36:58 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C5A3BA.5080700@chamonix.reportlab.co.uk> On 31/12/2013 15:41, Roy Smith wrote: > I'm using 2.7 in production. I realize that at some point we'll need to > upgrade to 3.x. We'll keep putting that off as long as the "effort + > dependencies + risk" metric exceeds the "perceived added value" metric. > We too are using python 2.4 - 2.7 in production. Different clients migrate at different speeds. > > To be honest, the "perceived added value" in 3.x is pretty low for us. > What we're running now works. Switching to 3.x isn't going to increase > our monthly average users, or our retention rate, or decrease our COGS, > or increase our revenue. There's no killer features we need. In > summary, the decision to migrate will be driven more by risk aversion, > when the risk of staying on an obsolete, unsupported platform, exceeds > the risk of moving to a new one. Or, there will be some third-party > module that we must have which is no longer supported on 2.x. > +1 > If I were starting a new project today, I would probably start it in 3.x. +1 I just spent a large amount of effort porting reportlab to a version which works with both python2.7 and python3.3. I have a large number of functions etc which handle the conversions that differ between the two pythons. For fairly sensible reasons we changed the internal default to use unicode rather than bytes. After doing all that and making the tests compatible etc etc I have a version which runs in both and passes all its tests. However, for whatever reason the python 3.3 version runs slower 2.7 Ran 223 tests in 66.578s 3.3 Ran 223 tests in 75.703s I know some of these tests are fairly variable, but even for simple things like paragraph parsing 3.3 seems to be slower. Since both use unicode internally it can't be that can it, or is python 2.7's unicode faster? So far the superiority of 3.3 escapes me, but I'm tasked with enjoying this process so I'm sure there must be some new 'feature' that will help. Perhaps 'yield from' or 'raise from None' or ....... In any case I think we will be maintaining python 2.x code for at least another 5 years; the version gap is then a real hindrance. -- Robin Becker From ned at nedbatchelder.com Thu Jan 2 12:36:59 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 02 Jan 2014 12:36:59 -0500 Subject: About some problem In-Reply-To: References: Message-ID: On 1/2/14 12:05 PM, Rustom Mody wrote: > > i'm not sure about this but isnt it normally the case that different > version modules dont get mixed up like that? > IOW if pytesser was a properly packaged 2.7 module would python 3 be > able to get at it ?? > If you use a Python 3 installer it can succeed at installing a Python 2 package. Then you won't find out until you try to run the package that it is incompatible. A mechanism to prevent this seems like a good idea, but since it wasn't in place at the dawn of Python 3, it would be difficult to put in place now. -- Ned Batchelder, http://nedbatchelder.com From rustompmody at gmail.com Thu Jan 2 12:46:26 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 2 Jan 2014 23:16:26 +0530 Subject: About some problem In-Reply-To: References: Message-ID: On Thu, Jan 2, 2014 at 11:06 PM, Ned Batchelder wrote: > On 1/2/14 12:05 PM, Rustom Mody wrote: > >> >> i'm not sure about this but isnt it normally the case that different >> version modules dont get mixed up like that? >> IOW if pytesser was a properly packaged 2.7 module would python 3 be >> able to get at it ?? >> > > If you use a Python 3 installer it can succeed at installing a Python 2 > package. Then you won't find out until you try to run the package that it is > incompatible. A mechanism to prevent this seems like a good idea, but since > it wasn't in place at the dawn of Python 3, it would be difficult to put in > place now. $ python3 Python 3.3.3 (default, Dec 8 2013, 16:34:29) [GCC 4.8.2] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from sys import path >>> path ['', '/usr/lib/python3.3', '/usr/lib/python3.3/plat-i386-linux-gnu', '/usr/lib/python3.3/lib-dynload', '/usr/local/lib/python3.3/dist-packages', '/usr/lib/python3/dist-packages'] $ python Python 2.7.6 (default, Dec 6 2013, 21:56:56) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from sys import path >>> path ['', '/usr/local/lib/python2.7/dist-packages/pip-1.0-py2.7.egg', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gst-0.10', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] So as far as I can see (on a debian linux system) the paths are clearly 2.7-prefixed or 3.3-prefixed. So apart from being stupid and/or malicious to munge sys.path to tread on the other python's toes...??? Oh ok I get what you are saying: python3 will not recognize a python2 package and install it seemingly correctly but actually wrongly From dwightdhutto at gmail.com Thu Jan 2 13:07:46 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Thu, 2 Jan 2014 13:07:46 -0500 Subject: About some problem In-Reply-To: References: Message-ID: I think, but haven't tried, and this would be 2-3 from __future__ import On Thu, Jan 2, 2014 at 12:46 PM, Rustom Mody wrote: > On Thu, Jan 2, 2014 at 11:06 PM, Ned Batchelder > wrote: > > On 1/2/14 12:05 PM, Rustom Mody wrote: > > > >> > >> i'm not sure about this but isnt it normally the case that different > >> version modules dont get mixed up like that? > >> IOW if pytesser was a properly packaged 2.7 module would python 3 be > >> able to get at it ?? > >> > > > > If you use a Python 3 installer it can succeed at installing a Python 2 > > package. Then you won't find out until you try to run the package that > it is > > incompatible. A mechanism to prevent this seems like a good idea, but > since > > it wasn't in place at the dawn of Python 3, it would be difficult to put > in > > place now. > > $ python3 > Python 3.3.3 (default, Dec 8 2013, 16:34:29) > [GCC 4.8.2] on linux > Type "help", "copyright", "credits" or "license" for more information. > >>> from sys import path > >>> path > ['', '/usr/lib/python3.3', '/usr/lib/python3.3/plat-i386-linux-gnu', > '/usr/lib/python3.3/lib-dynload', > '/usr/local/lib/python3.3/dist-packages', > '/usr/lib/python3/dist-packages'] > > > $ python > Python 2.7.6 (default, Dec 6 2013, 21:56:56) > [GCC 4.8.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> from sys import path > >>> path > ['', '/usr/local/lib/python2.7/dist-packages/pip-1.0-py2.7.egg', > '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', > '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', > '/usr/lib/python2.7/lib-dynload', > '/usr/local/lib/python2.7/dist-packages', > '/usr/lib/python2.7/dist-packages', > '/usr/lib/python2.7/dist-packages/PILcompat', > '/usr/lib/python2.7/dist-packages/gst-0.10', > '/usr/lib/python2.7/dist-packages/gtk-2.0', > '/usr/lib/pymodules/python2.7', > '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] > > > So as far as I can see (on a debian linux system) the paths are > clearly 2.7-prefixed or 3.3-prefixed. > > So apart from being stupid and/or malicious to munge sys.path to tread > on the other python's toes...??? > > Oh ok I get what you are saying: python3 will not recognize a python2 > package and install it seemingly correctly but actually wrongly > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Thu Jan 2 13:10:50 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Thu, 2 Jan 2014 13:10:50 -0500 Subject: About some problem In-Reply-To: References: Message-ID: and as I usually do, keep with the older stable version in order to keep up with other packages compatibiity. On Thu, Jan 2, 2014 at 1:07 PM, David Hutto wrote: > I think, but haven't tried, and this would be 2-3 from __future__ import > > > On Thu, Jan 2, 2014 at 12:46 PM, Rustom Mody wrote: > >> On Thu, Jan 2, 2014 at 11:06 PM, Ned Batchelder >> wrote: >> > On 1/2/14 12:05 PM, Rustom Mody wrote: >> > >> >> >> >> i'm not sure about this but isnt it normally the case that different >> >> version modules dont get mixed up like that? >> >> IOW if pytesser was a properly packaged 2.7 module would python 3 be >> >> able to get at it ?? >> >> >> > >> > If you use a Python 3 installer it can succeed at installing a Python 2 >> > package. Then you won't find out until you try to run the package that >> it is >> > incompatible. A mechanism to prevent this seems like a good idea, but >> since >> > it wasn't in place at the dawn of Python 3, it would be difficult to >> put in >> > place now. >> >> $ python3 >> Python 3.3.3 (default, Dec 8 2013, 16:34:29) >> [GCC 4.8.2] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> from sys import path >> >>> path >> ['', '/usr/lib/python3.3', '/usr/lib/python3.3/plat-i386-linux-gnu', >> '/usr/lib/python3.3/lib-dynload', >> '/usr/local/lib/python3.3/dist-packages', >> '/usr/lib/python3/dist-packages'] >> >> >> $ python >> Python 2.7.6 (default, Dec 6 2013, 21:56:56) >> [GCC 4.8.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> from sys import path >> >>> path >> ['', '/usr/local/lib/python2.7/dist-packages/pip-1.0-py2.7.egg', >> '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', >> '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', >> '/usr/lib/python2.7/lib-dynload', >> '/usr/local/lib/python2.7/dist-packages', >> '/usr/lib/python2.7/dist-packages', >> '/usr/lib/python2.7/dist-packages/PILcompat', >> '/usr/lib/python2.7/dist-packages/gst-0.10', >> '/usr/lib/python2.7/dist-packages/gtk-2.0', >> '/usr/lib/pymodules/python2.7', >> '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] >> >> >> So as far as I can see (on a debian linux system) the paths are >> clearly 2.7-prefixed or 3.3-prefixed. >> >> So apart from being stupid and/or malicious to munge sys.path to tread >> on the other python's toes...??? >> >> Oh ok I get what you are saying: python3 will not recognize a python2 >> package and install it seemingly correctly but actually wrongly >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com > * > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Thu Jan 2 13:20:09 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Thu, 2 Jan 2014 13:20:09 -0500 Subject: About some problem In-Reply-To: References: Message-ID: Looks like you have a a list of 2.7 dependencies in the path args. The first you seem to have 3.3 args, and the second a longer list of 2.7 args....I would assume the second is the full list...correct? On Thu, Jan 2, 2014 at 1:07 PM, David Hutto wrote: > I think, but haven't tried, and this would be 2-3 from __future__ import > > > On Thu, Jan 2, 2014 at 12:46 PM, Rustom Mody wrote: > >> On Thu, Jan 2, 2014 at 11:06 PM, Ned Batchelder >> wrote: >> > On 1/2/14 12:05 PM, Rustom Mody wrote: >> > >> >> >> >> i'm not sure about this but isnt it normally the case that different >> >> version modules dont get mixed up like that? >> >> IOW if pytesser was a properly packaged 2.7 module would python 3 be >> >> able to get at it ?? >> >> >> > >> > If you use a Python 3 installer it can succeed at installing a Python 2 >> > package. Then you won't find out until you try to run the package that >> it is >> > incompatible. A mechanism to prevent this seems like a good idea, but >> since >> > it wasn't in place at the dawn of Python 3, it would be difficult to >> put in >> > place now. >> >> $ python3 >> Python 3.3.3 (default, Dec 8 2013, 16:34:29) >> [GCC 4.8.2] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> from sys import path >> >>> path >> ['', '/usr/lib/python3.3', '/usr/lib/python3.3/plat-i386-linux-gnu', >> '/usr/lib/python3.3/lib-dynload', >> '/usr/local/lib/python3.3/dist-packages', >> '/usr/lib/python3/dist-packages'] >> >> >> $ python >> Python 2.7.6 (default, Dec 6 2013, 21:56:56) >> [GCC 4.8.2] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> from sys import path >> >>> path >> ['', '/usr/local/lib/python2.7/dist-packages/pip-1.0-py2.7.egg', >> '/usr/lib/python2.7', '/usr/lib/python2.7/plat-i386-linux-gnu', >> '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', >> '/usr/lib/python2.7/lib-dynload', >> '/usr/local/lib/python2.7/dist-packages', >> '/usr/lib/python2.7/dist-packages', >> '/usr/lib/python2.7/dist-packages/PILcompat', >> '/usr/lib/python2.7/dist-packages/gst-0.10', >> '/usr/lib/python2.7/dist-packages/gtk-2.0', >> '/usr/lib/pymodules/python2.7', >> '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode'] >> >> >> So as far as I can see (on a debian linux system) the paths are >> clearly 2.7-prefixed or 3.3-prefixed. >> >> So apart from being stupid and/or malicious to munge sys.path to tread >> on the other python's toes...??? >> >> Oh ok I get what you are saying: python3 will not recognize a python2 >> package and install it seemingly correctly but actually wrongly >> -- >> https://mail.python.org/mailman/listinfo/python-list >> > > > > -- > Best Regards, > David Hutto > *CEO:* *http://www.hitwebdevelopment.com > * > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From dwightdhutto at gmail.com Thu Jan 2 13:25:28 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Thu, 2 Jan 2014 13:25:28 -0500 Subject: Blog "about python 3" In-Reply-To: <52C5A3BA.5080700@chamonix.reportlab.co.uk> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: Just because it's 3.3 doesn't matter...the main interest is in compatibility. Secondly, you used just one piece of code, which could be a fluke, try others, and check the PEP. You need to realize that evebn the older versions are benig worked on, and they have to be refined. So if you have a problem, use the older and import from the future would be my suggestion On Thu, Jan 2, 2014 at 12:36 PM, Robin Becker wrote: > On 31/12/2013 15:41, Roy Smith wrote: > >> I'm using 2.7 in production. I realize that at some point we'll need to >> upgrade to 3.x. We'll keep putting that off as long as the "effort + >> dependencies + risk" metric exceeds the "perceived added value" metric. >> >> We too are using python 2.4 - 2.7 in production. Different clients > migrate at different speeds. > > >> To be honest, the "perceived added value" in 3.x is pretty low for us. >> What we're running now works. Switching to 3.x isn't going to increase >> our monthly average users, or our retention rate, or decrease our COGS, >> or increase our revenue. There's no killer features we need. In >> summary, the decision to migrate will be driven more by risk aversion, >> when the risk of staying on an obsolete, unsupported platform, exceeds >> the risk of moving to a new one. Or, there will be some third-party >> module that we must have which is no longer supported on 2.x. >> >> > +1 > > If I were starting a new project today, I would probably start it in 3.x. >> > +1 > > I just spent a large amount of effort porting reportlab to a version which > works with both python2.7 and python3.3. I have a large number of functions > etc which handle the conversions that differ between the two pythons. > > For fairly sensible reasons we changed the internal default to use unicode > rather than bytes. After doing all that and making the tests compatible etc > etc I have a version which runs in both and passes all its tests. However, > for whatever reason the python 3.3 version runs slower > > 2.7 Ran 223 tests in 66.578s > > 3.3 Ran 223 tests in 75.703s > > I know some of these tests are fairly variable, but even for simple things > like paragraph parsing 3.3 seems to be slower. Since both use unicode > internally it can't be that can it, or is python 2.7's unicode faster? > > So far the superiority of 3.3 escapes me, but I'm tasked with enjoying > this process so I'm sure there must be some new 'feature' that will help. > Perhaps 'yield from' or 'raise from None' or ....... > > In any case I think we will be maintaining python 2.x code for at least > another 5 years; the version gap is then a real hindrance. > -- > Robin Becker > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com * -------------- next part -------------- An HTML attachment was scrubbed... URL: From ethan at stoneleaf.us Thu Jan 2 12:46:52 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 02 Jan 2014 09:46:52 -0800 Subject: Ifs and assignments In-Reply-To: <52C59FF6.5000607@allsup.co> References: <52C59FF6.5000607@allsup.co> Message-ID: <52C5A60C.3020507@stoneleaf.us> On 01/02/2014 09:20 AM, John Allsup wrote: > > In many languages, such as C, one can use assignments in conditionals > and expressions. The most common, and useful case turns up when you > have if/else if/else if/else constructs. Consider the following > non-working pseudoPython. > > import re > r1 = re.compile("hello (\d)") > r2 = re.compile("world([!?])") > > w = "hello world!" > > if m = r1.search(w): > handleMatch1(m) > elif m = r2.search(w): > handleMatch2(m) > else: > print("No match") What you're looking for is a pocket function: #untested class assign(object): def set(self, value): self._assignment = value return value def get(self): return self._assignment m = assign() if m.set(r1.search(w)): handleMatch1(m.get()) elif m.set(r2.search(w)): handleMatch2(m.get()) else: print("No match") -- ~Ethan~ From tjreedy at udel.edu Thu Jan 2 13:37:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Jan 2014 13:37:16 -0500 Subject: Blog "about python 3" In-Reply-To: <52C5A3BA.5080700@chamonix.reportlab.co.uk> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: On 1/2/2014 12:36 PM, Robin Becker wrote: > I just spent a large amount of effort porting reportlab to a version > which works with both python2.7 and python3.3. I have a large number of > functions etc which handle the conversions that differ between the two > pythons. I am imagine that this was not fun. [For those who do not know, reportlab produces pdf documents.] > For fairly sensible reasons we changed the internal default to use > unicode rather than bytes. Do you mean 'from __future__ import unicode_literals'? Am I correct in thinking that this change increases the capabilities of reportlab? For instance, easily producing an article with abstracts in English, Arabic, Russian, and Chinese? > After doing all that and making the tests > compatible etc etc I have a version which runs in both and passes all > its tests. However, for whatever reason the python 3.3 version runs slower. Python 3 is slower in some things, like integer arithmetic with small ints. > 2.7 Ran 223 tests in 66.578s > > 3.3 Ran 223 tests in 75.703s > > I know some of these tests are fairly variable, but even for simple > things like paragraph parsing 3.3 seems to be slower. Since both use > unicode internally it can't be that can it, or is python 2.7's unicode > faster? The new unicode implementation in 3.3 is faster for some operations and slower for others. It is definitely more space efficient, especially compared to a wide build system. It is definitely less buggy, especially compared to a narrow build system. Do your tests use any astral (non-BMP) chars? If so, do they pass on narrow 2.7 builds (like on Windows)? > So far the superiority of 3.3 escapes me, For one thing, indexing and slicing just works on all machines for all unicode strings. Code for 2.7 and 3.3 either a) does not index or slice, b) does not work for all text on 2.7 narrow builds, or c) has extra conditional code only for 2.7. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Thu Jan 2 14:27:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 02 Jan 2014 19:27:48 +0000 Subject: About some problem In-Reply-To: References: Message-ID: On 02/01/2014 17:46, Rustom Mody wrote: > > Oh ok I get what you are saying: python3 will not recognize a python2 > package and install it seemingly correctly but actually wrongly > No, it will install it quite correctly. What it won't know is that some of the code is valid in Python 2 but invalid in Python 3. An example I discovered 30 minutes ago. raise "Not Valid DB Type" is perfectly valid in Python 2. In Python 3 it's so illegal the 2to3 conversion tool can't cope with it :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gary.herron at islandtraining.com Thu Jan 2 14:27:12 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Thu, 02 Jan 2014 11:27:12 -0800 Subject: Ifs and assignments In-Reply-To: <52C59FF6.5000607@allsup.co> References: <52C59FF6.5000607@allsup.co> Message-ID: <52C5BD90.9020609@islandtraining.com> On 01/02/2014 09:20 AM, John Allsup wrote: > Hi, > > This is my debut on this list. > > In many languages, such as C, one can use assignments in conditionals > and expressions. The most common, and useful case turns up when you > have if/else if/else if/else constructs. Consider the following > non-working pseudoPython. > > import re > r1 = re.compile("hello (\d)") > r2 = re.compile("world([!?])") > > w = "hello world!" > > if m = r1.search(w): This kind of thing in C/C+ has always been the source of much confusion and potential errors, because the construct is so similar to an "==" test. Python does not replicate this potential for confusion. Instead, we use two lines of code, an assignment and then the test. If you find that extra line of code inconvenient than at least you can take comfort in the fact that it is clearer code. If you are still not convinced, ... then sorry, that's just the way Python is. Gary Herron > handleMatch1(m) > elif m = r2.search(w): > handleMatch2(m) > else: > print("No match") > > If the regular expressions are complex, running them multiple times > (once to test, another to capture groups) isn't ideal. On the other > hand, at present, one has to either do: > > m = r1.search(w) > if m: > handleMatch1(m) > else: > m = r2.search(w) > if m: > handleMatch2(m) > else: > print("No match") > > if not running unnecessary matches, yet capturing groups in the event > of a successful match, is what is desired. > > If there are multiple tests, the indentation gets silly. This arises > because having removed the ability to assign in an expression, there > is no way to save the result of a function call that is used in a > conditional at all. > > I am aware that this facility in C is a source of bugs, = being only a > typo away from the more common ==. With exceptions and contexts, we > have: > > with open("file") as f: > doSomethingWith(f) > > try: > trySomething() > except SomethingRandomGoingWrong as e: > lookAtException(e) > > What I am wondering is why not use a similar syntax with if, so that > one could do > > if r1.search(w) as m: > g = m.groups() > print(g[1]) > > This would remove the risk of errors by typos since the syntax for > equality testing (if x == y:) is completely different from that for > assigning in a conditional (which would look like 'if y as x:' > > Related would be to have Nonetype work with contexts such that > > with None as x: > doStuff(x) > > would do nothing. This would allow things like: > > with maybeGetSomething as x: > doStuff(x) > > to call doStuff(x) within a context of maybeGetSomething returns > something, or do nothing if nothing is returned. (Adding an else-like > keyword to with, or possibly using else in that context, would allow > one to process a non-None object if returned, or else do something in > response to a None object being returned by the maybeGetSomething.) > > Just a thought. > > Or what is the current 'Pythonic' way to do something like: > > if x = func1(): > do1(x) > elif x = func2(): > do2(x) > elif x = func3(): > do3(x) > elif x = func4(): > do4(x) > else: > do5() > > where each of func1,func2,func3,func4 have side effects so that func2 > is tested if and only if func1 returns a false value, func1 must be > called only once, and what is returned from func1 must be available to > the code inside the if block? > > > John > From eneskristo at gmail.com Thu Jan 2 14:52:00 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Thu, 2 Jan 2014 11:52:00 -0800 (PST) Subject: On a scrollbar for tkinter Message-ID: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> Hello people! I'm new to tkinter, but I have to use it for a program for a competition. So, I make a RadioButton program using a while loop. So far so good, fully working. BUT it didn't show the full content, even after maximising the window. So, my question is, how do I make a scroll bar(On x and y axis) for my Main Frame. I can provide additional info if needed. Notes: Python 3.2 (Using Portable Python for a while. Outdated but meh.) Thank you in advance! From tjreedy at udel.edu Thu Jan 2 15:41:23 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 02 Jan 2014 15:41:23 -0500 Subject: On a scrollbar for tkinter In-Reply-To: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> References: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> Message-ID: On 1/2/2014 2:52 PM, eneskristo at gmail.com wrote: > I'm new to tkinter, but I have to use it for a program for a competition. So, I make a RadioButton program using a while loop. So far so good, fully working. BUT it didn't show the full content, even after maximising the window. So, my question is, how do I make a scroll bar(On x and y axis) for my Main Frame. I can provide additional info if needed. Have you already searched 'python tkinter scrollbar', with maybe 'example' added? Or looked at the links given in the library manual chapter? -- Terry Jan Reedy From python.list at tim.thechases.com Thu Jan 2 17:08:23 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 2 Jan 2014 16:08:23 -0600 Subject: Ifs and assignments In-Reply-To: <52C59FF6.5000607@allsup.co> References: <52C59FF6.5000607@allsup.co> Message-ID: <20140102160823.15bf889d@bigbox.christie.dr> On 2014-01-02 17:20, John Allsup wrote: > m = r1.search(w) > if m: > handleMatch1(m) > else: > m = r2.search(w) > if m: > handleMatch2(m) > else: > print("No match") > > if not running unnecessary matches, yet capturing groups in the > event of a successful match, is what is desired. > > If there are multiple tests, the indentation gets silly. This > arises because having removed the ability to assign in an > expression, there is no way to save the result of a function call > that is used in a conditional at all. Usually this is done something like pairs = ( for r, fn in ( (r1, handleMatch1), (r2, handleMatch2), (r3, handleMatch3), ): m = r.search(w) if m: fn(m) break else: # yes, a for/else, a handy Python construct if new to you print("No match") which simplifies the logic considerably, avoiding the deep nesting. -tkc From tim.hamza at gmail.com Thu Jan 2 17:26:48 2014 From: tim.hamza at gmail.com (tim.hamza at gmail.com) Date: Thu, 2 Jan 2014 14:26:48 -0800 (PST) Subject: Setuptools - cannot install Message-ID: <6c137d0d-a20c-48c4-9115-f8d2d8134433@googlegroups.com> setuptools 2.0.2, win7 x64, python 3.3.3 (64bit), tried as user (who is admin, and as admin) This started happening several versions ago. Could not track down a setuptools support list. Any ideas? C:\Users\tim\Desktop\setuptools-2.0.2>python setup.py install Traceback (most recent call last): File "setup.py", line 17, in exec(init_file.read(), command_ns) File "", line 8, in File "C:\Users\tim\Desktop\setuptools-2.0.2\setuptools\__init__.py", line 11, in from setuptools.extension import Extension File "C:\Users\tim\Desktop\setuptools-2.0.2\setuptools\extension.py", line 5, in from setuptools.dist import _get_unpatched File "C:\Users\tim\Desktop\setuptools-2.0.2\setuptools\dist.py", line 15, in from setuptools.compat import numeric_types, basestring File "C:\Users\tim\Desktop\setuptools-2.0.2\setuptools\compat.py", line 49, in from http.server import HTTPServer, SimpleHTTPRequestHandler File "C:\Python\lib\http\server.py", line 654, in class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): File "C:\Python\lib\http\server.py", line 839, in SimpleHTTPRequestHandler mimetypes.init() # try to read system mime.types File "C:\Python\lib\mimetypes.py", line 348, in init db.read_windows_registry() File "C:\Python\lib\mimetypes.py", line 255, in read_windows_registry with _winreg.OpenKey(hkcr, subkeyname) as subkey: TypeError: OpenKey() argument 2 must be str without null characters or None, not str From eneskristo at gmail.com Thu Jan 2 17:30:54 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Thu, 2 Jan 2014 14:30:54 -0800 (PST) Subject: On a scrollbar for tkinter In-Reply-To: References: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> Message-ID: @Teddy Yes, indeed I have, but so far I have only found material for scrolling in other stuff, not the main frame. If you can give me a link... From roy at panix.com Thu Jan 2 17:53:28 2014 From: roy at panix.com (Roy Smith) Date: Thu, 02 Jan 2014 17:53:28 -0500 Subject: Score one for unit testing. Message-ID: We've got a test that's been running fine ever since it was written a month or so ago. Now, it's failing intermittently on our CI (continuous integration) box, so I took a look. It turns out it's a stupid test because it depends on pre-existing data in the database. But, the win is that while looking at the code to figure out why this was failing, I noticed a completely unrelated bug in the production code. See, unit testing helps find bugs :-) From rosuav at gmail.com Thu Jan 2 18:00:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 10:00:45 +1100 Subject: Score one for unit testing. In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 9:53 AM, Roy Smith wrote: > We've got a test that's been running fine ever since it was written a > month or so ago. Now, it's failing intermittently on our CI (continuous > integration) box, so I took a look. I recommend you solve these problems the way these folks did: http://thedailywtf.com/Articles/Productive-Testing.aspx ChrisA From pydev at allsup.co Thu Jan 2 16:44:06 2014 From: pydev at allsup.co (John Allsup) Date: Thu, 02 Jan 2014 21:44:06 +0000 Subject: Ifs and assignments In-Reply-To: <52C5BD90.9020609@islandtraining.com> References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> Message-ID: <52C5DDA6.5090207@allsup.co> The point of my original post was that, whilst C's if( x = 2 ) { do something } and if( x == 2 ) { do something } are easy to confuse, and a source of bugs, having a construct like follows: if x == 2: do something # what happens at present if testFunc() as x: do something with x using the 'as' syntax that appears with 'with' and 'except', would allow for the advantages of C style assignments in conditionals but without the easy confusion, since here the syntax is significantly different between assignment and equality testing (rather than a character apart as happens with C). This occurs further down in my original post (past the point where you inserted your reply). Another post suggested a workaround by defining a 'pocket' class, for which I am grateful. John On 02/01/2014 19:27, Gary Herron wrote: > On 01/02/2014 09:20 AM, John Allsup wrote: >> Hi, >> >> This is my debut on this list. >> >> In many languages, such as C, one can use assignments in conditionals >> and expressions. The most common, and useful case turns up when you >> have if/else if/else if/else constructs. Consider the following >> non-working pseudoPython. >> >> import re >> r1 = re.compile("hello (\d)") >> r2 = re.compile("world([!?])") >> >> w = "hello world!" >> >> if m = r1.search(w): > > This kind of thing in C/C+ has always been the source of much confusion > and potential errors, because the construct is so similar to an "==" > test. Python does not replicate this potential for confusion. Instead, > we use two lines of code, an assignment and then the test. If you find > that extra line of code inconvenient than at least you can take comfort > in the fact that it is clearer code. If you are still not convinced, > ... then sorry, that's just the way Python is. > > Gary Herron > > >> handleMatch1(m) >> elif m = r2.search(w): >> handleMatch2(m) >> else: >> print("No match") >> >> If the regular expressions are complex, running them multiple times >> (once to test, another to capture groups) isn't ideal. On the other >> hand, at present, one has to either do: >> >> m = r1.search(w) >> if m: >> handleMatch1(m) >> else: >> m = r2.search(w) >> if m: >> handleMatch2(m) >> else: >> print("No match") >> >> if not running unnecessary matches, yet capturing groups in the event >> of a successful match, is what is desired. >> >> If there are multiple tests, the indentation gets silly. This arises >> because having removed the ability to assign in an expression, there >> is no way to save the result of a function call that is used in a >> conditional at all. >> >> I am aware that this facility in C is a source of bugs, = being only a >> typo away from the more common ==. With exceptions and contexts, we >> have: >> >> with open("file") as f: >> doSomethingWith(f) >> >> try: >> trySomething() >> except SomethingRandomGoingWrong as e: >> lookAtException(e) >> >> What I am wondering is why not use a similar syntax with if, so that >> one could do >> >> if r1.search(w) as m: >> g = m.groups() >> print(g[1]) >> >> This would remove the risk of errors by typos since the syntax for >> equality testing (if x == y:) is completely different from that for >> assigning in a conditional (which would look like 'if y as x:' >> >> Related would be to have Nonetype work with contexts such that >> >> with None as x: >> doStuff(x) >> >> would do nothing. This would allow things like: >> >> with maybeGetSomething as x: >> doStuff(x) >> >> to call doStuff(x) within a context of maybeGetSomething returns >> something, or do nothing if nothing is returned. (Adding an else-like >> keyword to with, or possibly using else in that context, would allow >> one to process a non-None object if returned, or else do something in >> response to a None object being returned by the maybeGetSomething.) >> >> Just a thought. >> >> Or what is the current 'Pythonic' way to do something like: >> >> if x = func1(): >> do1(x) >> elif x = func2(): >> do2(x) >> elif x = func3(): >> do3(x) >> elif x = func4(): >> do4(x) >> else: >> do5() >> >> where each of func1,func2,func3,func4 have side effects so that func2 >> is tested if and only if func1 returns a false value, func1 must be >> called only once, and what is returned from func1 must be available to >> the code inside the if block? >> >> >> John >> > From roy at panix.com Thu Jan 2 18:36:15 2014 From: roy at panix.com (Roy Smith) Date: Thu, 02 Jan 2014 18:36:15 -0500 Subject: Ifs and assignments References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> Message-ID: In article , John Allsup wrote: > if testFunc() as x: > do something with x +1 The most common place I wish for an atomic "test and assign" is with regexes, as in your examples. This would be so much nicer than what we have to do now: if re.match(string) as m: print m.group(0) The analogy to except SomeError as ex: is very clear. They are both "Perform some action, capture the result, do some test on it, and then make that captured value available bound to a name". From steve+comp.lang.python at pearwood.info Thu Jan 2 18:49:19 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 03 Jan 2014 10:49:19 +1100 Subject: About some problem References: Message-ID: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> Mark Lawrence wrote: > raise "Not Valid DB Type" > > is perfectly valid in Python 2. Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, string exceptions display a warning but continue to work, and in Python 2.6 they generate a compile-time SyntaxError. You know how the world ended when Python 2.6 broke backwards compatibility and split the Python community into two? No, me neither. -- Steven From rantingrickjohnson at gmail.com Thu Jan 2 18:49:02 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Thu, 2 Jan 2014 15:49:02 -0800 (PST) Subject: On a scrollbar for tkinter In-Reply-To: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> References: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> Message-ID: <3cd10b81-178b-4003-b5e0-237246878e15@googlegroups.com> I know you're using Python3.x, so there may be new functionality in Tkinter that i am not aware of yet. I still have oodles of Python2.x dependencies and really don't see a need to make the jump yet -- so keep that in mind when taking my advice below. In the old days of Tkinter, if you wanted to scroll the mainframe (aka:root, aka:Tkinter.Tk) you had two choices: OPTION_1. Use tk.Canvas and "create_window" method http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/create_window.html OPTION_2. The "TIX" extension widgets for Tkinter has a "scrolledwindow" object that requires much less work and provides a more intuitive interface than the canvas. PS: It's "Terry" not "Teddy". From solipsis at pitrou.net Thu Jan 2 18:57:56 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 2 Jan 2014 23:57:56 +0000 (UTC) Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: Hi, Robin Becker reportlab.com> writes: > > For fairly sensible reasons we changed the internal default to use unicode > rather than bytes. After doing all that and making the tests compatible etc etc > I have a version which runs in both and passes all its tests. However, for > whatever reason the python 3.3 version runs slower > > 2.7 Ran 223 tests in 66.578s > > 3.3 Ran 223 tests in 75.703s Running a test suite is a completely broken benchmarking methodology. You should isolate workloads you are interested in and write a benchmark simulating them. Regards Antoine. From rosuav at gmail.com Thu Jan 2 19:07:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 11:07:58 +1100 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> Message-ID: On Fri, Jan 3, 2014 at 11:06 AM, Chris Angelico wrote: > Pass any object through truth() and it'll either stay the same (if > it's true) or become this object (if it's false). You can then carry > on with other method calls, and they'll all happily return false. > > result = ( > truth(re1.match(string)).group(0) or > truth(re2.match(string)).group(0) or > truth(re3.match(string)).group(0) or > default_value > ) Oh, just thought of a possible snag. Since an empty string comes up as false, this exact notation would fail if the re can match nothing. But you probably know if it's possible for that to happen, so don't use this simple short-hand. :) ChrisA From rosuav at gmail.com Thu Jan 2 19:06:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 11:06:05 +1100 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> Message-ID: On Fri, Jan 3, 2014 at 10:36 AM, Roy Smith wrote: > The most common place I wish for an atomic "test and assign" is with > regexes, as in your examples. This would be so much nicer than what we > have to do now: > > if re.match(string) as m: > print m.group(0) Here's a crazy idea. Suppose we have a "sticky falseness" that can quietly propagate through an expression the way a NaN can... then we could just float that right through the .group() call. class truth: def __new__(cls, x): if x: return x return object.__new__(cls) def __bool__(self): return False def __getattr__(self, name): return self def __call__(self, *args, **kwargs): return self def __repr__(self): return repr(False) Pass any object through truth() and it'll either stay the same (if it's true) or become this object (if it's false). You can then carry on with other method calls, and they'll all happily return false. result = ( truth(re1.match(string)).group(0) or truth(re2.match(string)).group(0) or truth(re3.match(string)).group(0) or default_value ) (I'm not sure if I'm using __new__ correctly; I've never actually done it in production code, and the info I found online was mainly Py2 examples. Should that be done with super(), or is that applicable only once there's an actual instance with a real MRO?) I've given the class a lower-case first letter as I'm basically using this as a function. If this were ever to be considered for the standard library I would expect to see that aspect of it heavily bikeshedded, so I'm not too concerned about the details. In a spirit of full disclosure, I must confess that the idea came from Pike, where there's a variant member-lookup operator that will happily return false from false rather than throwing an exception. :) ChrisA From rosuav at gmail.com Thu Jan 2 19:26:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 11:26:56 +1100 Subject: Setuptools - cannot install In-Reply-To: <6c137d0d-a20c-48c4-9115-f8d2d8134433@googlegroups.com> References: <6c137d0d-a20c-48c4-9115-f8d2d8134433@googlegroups.com> Message-ID: On Fri, Jan 3, 2014 at 9:26 AM, wrote: > File "C:\Python\lib\mimetypes.py", line 255, in read_windows_registry > with _winreg.OpenKey(hkcr, subkeyname) as subkey: > TypeError: OpenKey() argument 2 must be str without null characters or None, not str Interestingly, I pulled up that file on my 3.3.0 (Windows) and that line is different. May be related to this issue, which was cited in the commit summary that effected the change: http://bugs.python.org/issue15207 In 3.3.0, it looks for HKEY_CLASSES_ROOT plus subkey r'MIME\Database\Content Type', but in 3.3.3 it's iterating over all the subkeys in HKEY_CLASSES_ROOT. (Note that _winreg is simply the winreg module or None if it couldn't be imported.) I wonder is it possible you have a null character in a key?? It's worth a try. >>> import winreg >>> hkcr=winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, '') >>> for i in range(999999): key=winreg.EnumKey(hkcr,i) if '\0' in key: print(repr(key)) If that throws a "No more data available" error without printing any keys, then this isn't your problem. Alternatively, you could hack C:\Python\lib\mimetypes.py to print out subkeyname before attempting to open it. That would at least tell you what the offending key is. My suspicion at the moment is that you may have a corrupted registry, or else there's something that's possible that the winreg module doesn't expect. BTW, thanks for the first-line summary of version numbers. Much appreciated! So many people don't give that. ChrisA From gary.herron at islandtraining.com Thu Jan 2 19:57:26 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Thu, 02 Jan 2014 16:57:26 -0800 Subject: Ifs and assignments In-Reply-To: <52C5DDA6.5090207@allsup.co> References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <52C5DDA6.5090207@allsup.co> Message-ID: <52C60AF6.8060004@islandtraining.com> On 01/02/2014 01:44 PM, John Allsup wrote: > The point of my original post was that, whilst C's > if( x = 2 ) { do something } > and > if( x == 2 ) { do something } > are easy to confuse, and a source of bugs, having a construct like > follows: > > if x == 2: > do something # what happens at present > if testFunc() as x: > do something with x > > using the 'as' syntax that appears with 'with' and 'except', would allow > for the advantages of C style assignments in conditionals but without > the easy confusion, since here the syntax is significantly different > between assignment and equality testing (rather than a character apart > as happens with C). > > This occurs further down in my original post (past the point where you > inserted your reply). > > Another post suggested a workaround by defining a 'pocket' class, for > which I am grateful. > > John Sorry. I shot off my answer before reading the whole post. That's never a good idea. After reading to the end, I rather like your suggestion. It works well in your example, , nicely avoids the C/C++ trap, and has some consistency with other parts of Python. Gary Herron > > > On 02/01/2014 19:27, Gary Herron wrote: >> On 01/02/2014 09:20 AM, John Allsup wrote: >>> Hi, >>> >>> This is my debut on this list. >>> >>> In many languages, such as C, one can use assignments in conditionals >>> and expressions. The most common, and useful case turns up when you >>> have if/else if/else if/else constructs. Consider the following >>> non-working pseudoPython. >>> >>> import re >>> r1 = re.compile("hello (\d)") >>> r2 = re.compile("world([!?])") >>> >>> w = "hello world!" >>> >>> if m = r1.search(w): >> >> This kind of thing in C/C+ has always been the source of much confusion >> and potential errors, because the construct is so similar to an "==" >> test. Python does not replicate this potential for confusion. Instead, >> we use two lines of code, an assignment and then the test. If you find >> that extra line of code inconvenient than at least you can take comfort >> in the fact that it is clearer code. If you are still not convinced, >> ... then sorry, that's just the way Python is. >> >> Gary Herron >> >> >>> handleMatch1(m) >>> elif m = r2.search(w): >>> handleMatch2(m) >>> else: >>> print("No match") >>> >>> If the regular expressions are complex, running them multiple times >>> (once to test, another to capture groups) isn't ideal. On the other >>> hand, at present, one has to either do: >>> >>> m = r1.search(w) >>> if m: >>> handleMatch1(m) >>> else: >>> m = r2.search(w) >>> if m: >>> handleMatch2(m) >>> else: >>> print("No match") >>> >>> if not running unnecessary matches, yet capturing groups in the event >>> of a successful match, is what is desired. >>> >>> If there are multiple tests, the indentation gets silly. This arises >>> because having removed the ability to assign in an expression, there >>> is no way to save the result of a function call that is used in a >>> conditional at all. >>> >>> I am aware that this facility in C is a source of bugs, = being only a >>> typo away from the more common ==. With exceptions and contexts, we >>> have: >>> >>> with open("file") as f: >>> doSomethingWith(f) >>> >>> try: >>> trySomething() >>> except SomethingRandomGoingWrong as e: >>> lookAtException(e) >>> >>> What I am wondering is why not use a similar syntax with if, so that >>> one could do >>> >>> if r1.search(w) as m: >>> g = m.groups() >>> print(g[1]) >>> >>> This would remove the risk of errors by typos since the syntax for >>> equality testing (if x == y:) is completely different from that for >>> assigning in a conditional (which would look like 'if y as x:' >>> >>> Related would be to have Nonetype work with contexts such that >>> >>> with None as x: >>> doStuff(x) >>> >>> would do nothing. This would allow things like: >>> >>> with maybeGetSomething as x: >>> doStuff(x) >>> >>> to call doStuff(x) within a context of maybeGetSomething returns >>> something, or do nothing if nothing is returned. (Adding an else-like >>> keyword to with, or possibly using else in that context, would allow >>> one to process a non-None object if returned, or else do something in >>> response to a None object being returned by the maybeGetSomething.) >>> >>> Just a thought. >>> >>> Or what is the current 'Pythonic' way to do something like: >>> >>> if x = func1(): >>> do1(x) >>> elif x = func2(): >>> do2(x) >>> elif x = func3(): >>> do3(x) >>> elif x = func4(): >>> do4(x) >>> else: >>> do5() >>> >>> where each of func1,func2,func3,func4 have side effects so that func2 >>> is tested if and only if func1 returns a false value, func1 must be >>> called only once, and what is returned from func1 must be available to >>> the code inside the if block? >>> >>> >>> John >>> >> > From breamoreboy at yahoo.co.uk Thu Jan 2 20:14:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Jan 2014 01:14:02 +0000 Subject: About some problem In-Reply-To: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> References: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 02/01/2014 23:49, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> raise "Not Valid DB Type" >> >> is perfectly valid in Python 2. > > Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, > string exceptions display a warning but continue to work, and in Python 2.6 > they generate a compile-time SyntaxError. > Thaanks for the correction. > You know how the world ended when Python 2.6 broke backwards compatibility > and split the Python community into two? No, me neither. > I'm 100% certain that you're wrong on this one, the split was simply never noticed by anybody :) -- 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 Thu Jan 2 20:20:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Jan 2014 01:20:51 +0000 Subject: Ifs and assignments In-Reply-To: <52C60AF6.8060004@islandtraining.com> References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <52C5DDA6.5090207@allsup.co> <52C60AF6.8060004@islandtraining.com> Message-ID: On 03/01/2014 00:57, Gary Herron wrote: > On 01/02/2014 01:44 PM, John Allsup wrote: >> The point of my original post was that, whilst C's >> if( x = 2 ) { do something } >> and >> if( x == 2 ) { do something } >> are easy to confuse, and a source of bugs, having a construct like >> follows: >> >> if x == 2: >> do something # what happens at present >> if testFunc() as x: >> do something with x >> >> using the 'as' syntax that appears with 'with' and 'except', would allow >> for the advantages of C style assignments in conditionals but without >> the easy confusion, since here the syntax is significantly different >> between assignment and equality testing (rather than a character apart >> as happens with C). >> >> This occurs further down in my original post (past the point where you >> inserted your reply). >> >> Another post suggested a workaround by defining a 'pocket' class, for >> which I am grateful. >> >> John > > Sorry. I shot off my answer before reading the whole post. That's > never a good idea. > > > After reading to the end, I rather like your suggestion. It works well > in your example, , nicely avoids the C/C++ trap, and has some > consistency with other parts of Python. > > Gary Herron > > I liked the look of this as well. It ought to go to python ideas, or has it been suggested there in the past? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From davea at davea.name Thu Jan 2 21:41:05 2014 From: davea at davea.name (Dave Angel) Date: Thu, 02 Jan 2014 21:41:05 -0500 Subject: need to print seconds from the epoch including the millisecond In-Reply-To: References: <59aa73ac-e06e-4c0e-83a4-147ac42cad2e@googlegroups.com> <52bcaeed$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, 2 Jan 2014 16:23:22 +0000 (UTC), Grant Edwards wrote: > AFAIK, that's irrelevent. time.time() returns a float. On all the > CPython implementations I know of, that is a 64-bit IEEE format, which > provides 16 decimal digits of precision regardless of the granularity > of the system time value. At this point in time, that means 10 digits > left of the decimal point and 6 to the right. Correction: no more than about 6 to the right. You can certainly get less, from an os with a smaller resolution. Or you can lose some of what you do get by printing in a sub-optimal way. -- DaveA From j2mcgaha at gmail.com Thu Jan 2 19:12:24 2014 From: j2mcgaha at gmail.com (J. McGaha) Date: Thu, 2 Jan 2014 18:12:24 -0600 Subject: Registry Key Value Help Message-ID: <00ea01cf0818$7b7b01d0$72710570$@com> Good evening, I am a complete noob at Python. I am attempting to create a key and update its value. The code below is what I have come up with after reading everything I can get my hands on. When I run the this code I get an error that says the 'int' can't be called. I appreciate your help import _winreg as wr aReg = wr.ConnectRegistry(None, wr.HKEY_LOCAL_MACHINE) targ = r'SOFTWARE\Policies\Google\Update' aKey = wr.OpenKey(aReg, targ, 0, wr.KEY_WRITE) wr.KEY_SET_VALUE(aKey,"DisableAutoUpdateChecksCheckboxValue", 1, wr.REG_DWORD) wr.CloseKey(aKey) wr.CloseKey(aReg) I appreciate your help John -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jan 2 22:05:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 14:05:10 +1100 Subject: Registry Key Value Help In-Reply-To: <00ea01cf0818$7b7b01d0$72710570$@com> References: <00ea01cf0818$7b7b01d0$72710570$@com> Message-ID: On Fri, Jan 3, 2014 at 11:12 AM, J. McGaha wrote: > When I run the this code I get an error that says the ?int? can?t be called. > Python errors include full backtraces that show exactly what's going on. They are extremely helpful, so when you post questions like this, you should copy and paste the whole thing. In this case, though, I'm pretty sure the problem is here: wr.KEY_SET_VALUE(aKey,"DisableAutoUpdateChecksCheckboxValue", 1, wr.REG_DWORD) The all-uppercase keyword strongly suggests that this is a constant, as I can confirm with my Python 3.3.0 (by the way, it's also helpful to say what version of Python you're using). I suspect, without looking at the docs, that what you want is actually wr.SetValue or wr.SetValueEx, which are named like functions (or classes). Check out the docs for those functions and see if they're what you need. ChrisA From steve+comp.lang.python at pearwood.info Thu Jan 2 22:33:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 03 Jan 2014 14:33:59 +1100 Subject: Ifs and assignments References: <52C59FF6.5000607@allsup.co> Message-ID: <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Dennis Lee Bieber wrote: > On Thu, 02 Jan 2014 17:20:54 +0000, John Allsup > declaimed the following: >>In many languages, such as C, one can use assignments in conditionals >>and expressions. The most common, and useful case turns up when you > > Really? You can't do it in FORTRAN, BASIC, COBOL, Pascal, Ada... > > C, C++, Java, C# are all based on the same core syntax. For all > effective purposes, they are the same as grouping M$ Visual BASIC, > GW-BASIC, Kemeny&Kurtz TrueBASIC as "most languages, such as BASIC"... Thank you for pointing this out! Far too many people imagine that C and the C-inspired languages make up the entire universe of programming. But having said that, features should be judged on their merit, not on whether they are familiar to Ada/Lisp/C/Algol/... programmers. (Although familiarity is one factor out of many which should be considered.) Personally, I find it hard to care about assignment as an expression. I find the obvious C-inspired syntax terrible, as it is too easy to mistakenly use == instead of = or visa versa: if m = re.match(pattern, text): ... Using "as" is slightly better: if re.match(pattern, text) as m: ... but I don't think it's sufficiently useful for me to get excited about it. However, I don't think we should treat this as specific to if statements: for i, obj in enumerate(alist + blist + clist as items): items[i] = process(obj) Is that really better than this? items = alist + blist + clist for i, obj in enumerate(items): items[i] = process(obj) -- Steven From rosuav at gmail.com Thu Jan 2 22:49:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 14:49:41 +1100 Subject: Ifs and assignments In-Reply-To: <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 3, 2014 at 2:33 PM, Steven D'Aprano wrote: > However, I don't think we should treat this as specific to if statements: > > for i, obj in enumerate(alist + blist + clist as items): > items[i] = process(obj) > > > Is that really better than this? > > items = alist + blist + clist > for i, obj in enumerate(items): > items[i] = process(obj) It definitely shouldn't be specific to if statements, though I think that's probably going to be the biggest use-case (chained if/elif blocks). Maybe a for loop isn't the best other example, but I frequently work with places where I want to call some function and keep iterating with the result of that until it returns false: while (var = func()) { .... } In Python, that gets a lot clunkier. The most popular way is to turn it into an infinite loop: while True: var = func() if not var: break .... which is pretty much how the C version will compile down, most likely. It feels like an assembly language solution. The point of a while loop is to put its condition into the loop header - burying it inside the indented block (at the same indentation level as most of the code) conceals that, and this is a very simple and common condition. So this is what I'd cite as a second use-case: while func() as var: .... And that definitely looks more readable. ChrisA From orgnut at yahoo.com Thu Jan 2 22:47:35 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Thu, 02 Jan 2014 19:47:35 -0800 Subject: About some problem In-Reply-To: References: Message-ID: On 01/02/2014 08:31 AM, raj kumar wrote: > Hello, I am beginner to python and i am writing following code > > from pytesser import * > > and i am getting an error as follow > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python33\lib\site-packages\pytesser.py", line 61 > print text > ^ > SyntaxError: invalid syntax > From your traceback: File "C:\Python33\lib\site-packages\pytesser.py", line 61 ^ You are using Python 3.3, but the line "print text" is Python 2 syntax. Python 3 requires parentheses: print(text) Obviously the pytesser.py file is written for Python 2 and it is an error to be installed with your Python 3 packages. > > How to resolve it ? Give me all steps to resolve it. > It would be nicer if you would request help rather than demand it. However, it seems to be some sort of installation error. Without knowing anything about your system we can't help with that. You'll have to figure it out for yourself, or give us more information: where you got it, how you installed it, anything else relevant. (We do appreciate full tracebacks, however. Thank you for that. Many people summarize or paraphrase error messages, which is not as helpful.) -=- Larry -=- From rosuav at gmail.com Thu Jan 2 22:55:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 14:55:24 +1100 Subject: Ifs and assignments In-Reply-To: <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 3, 2014 at 2:33 PM, Steven D'Aprano wrote: > Personally, I find it hard to care about assignment as an expression. I find > the obvious C-inspired syntax terrible, as it is too easy to mistakenly use > == instead of = or visa versa: Python has similar problems, though. It's inherent to the nature of symbolic languages. a = (1, 2, 3) b = {1, 2, 3} In many fonts, it's hard to tell one from the other without peering. Do people decry set literal notation in favour of explicitly writing the word "set"? No; and I think most of us agree that it's better to have the symbols. At least with == vs = there's a length difference. I don't think it's C's fault or problem that equality and assignment look similar and can be used in the same places, any more than it's a problem to have assignment and subtraction differ by only one stroke: a - (1, 2, 3) Is that confusingly similar to assignment? ChrisA From rustompmody at gmail.com Thu Jan 2 22:58:21 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 3 Jan 2014 09:28:21 +0530 Subject: How to read and post tracebacks (was Registry Key Value Help) Message-ID: On Fri, Jan 3, 2014 at 8:35 AM, Chris Angelico wrote: > On Fri, Jan 3, 2014 at 11:12 AM, J. McGaha wrote: >> When I run the this code I get an error that says the ?int? can?t be called. >> > > Python errors include full backtraces that show exactly what's going > on. They are extremely helpful, so when you post questions like this, > you should copy and paste the whole thing. > > In this case, though, I'm pretty sure the problem is here: Hey Chris! Why not write up a few lines on "How to read and post python tracebacks" and post it on the wiki? If you feel like just summarizing the points and let someone else post it, I or someone else can do it [Or does such a page already exist?] From rosuav at gmail.com Thu Jan 2 23:03:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 15:03:52 +1100 Subject: How to read and post tracebacks (was Registry Key Value Help) In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 2:58 PM, Rustom Mody wrote: > Why not write up a few lines on "How to read and post python tracebacks" > and post it on the wiki? You mean "copy and paste the whole output"? I'm not sure what more needs to be said about posting them. Reading them is a bit more complicated, but possibly _too_ complicated for a simple wiki post. Being able to quickly eyeball a traceback and know which level to look for the problem at is part of the skill of debugging, and it usually requires that you know the codebase fairly well too. Though even with unfamiliar code, it's possible to figure a lot out by naming conventions, which is why they're so important (all uppercase meaning "constant" and normally a scalar - so useful). ChrisA From roy at panix.com Thu Jan 2 23:00:49 2014 From: roy at panix.com (Roy Smith) Date: Thu, 02 Jan 2014 23:00:49 -0500 Subject: Ifs and assignments References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Fri, Jan 3, 2014 at 2:33 PM, Steven D'Aprano > wrote: > > Personally, I find it hard to care about assignment as an expression. I find > > the obvious C-inspired syntax terrible, as it is too easy to mistakenly use > > == instead of = or visa versa: > > Python has similar problems, though. It's inherent to the nature of > symbolic languages. > > a = (1, 2, 3) > b = {1, 2, 3} > > In many fonts, it's hard to tell one from the other without peering. > Do people decry set literal notation in favour of explicitly writing > the word "set"? No; and I think most of us agree that it's better to > have the symbols. At least with == vs = there's a length difference. I > don't think it's C's fault or problem that equality and assignment > look similar and can be used in the same places, any more than it's a > problem to have assignment and subtraction differ by only one stroke: > > a - (1, 2, 3) > > Is that confusingly similar to assignment? > > ChrisA I do this all the time: t0 = time.time() [some code] t1 = time.time() dt = t1 = t0 # <-- spot the typo? From rosuav at gmail.com Thu Jan 2 23:08:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 15:08:33 +1100 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 3, 2014 at 3:00 PM, Roy Smith wrote: > I do this all the time: > > t0 = time.time() > [some code] > t1 = time.time() > dt = t1 = t0 # <-- spot the typo? Yep, I see that... now that it's pointed out as a typo. Without the marker, I'd assume it's correct chained assignment, and only an examination of the name (dt = delta t) hints otherwise. ChrisA From roy at panix.com Thu Jan 2 23:14:47 2014 From: roy at panix.com (Roy Smith) Date: Thu, 02 Jan 2014 23:14:47 -0500 Subject: Ifs and assignments References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > while (var = func()) > { > .... > } > > In Python, that gets a lot clunkier. The most popular way is to turn > it into an infinite loop: > > while True: > var = func() > if not var: break > .... Or turn it into a generator: def funcinator(): while True: var = func() if var: yield var else: break for var in funcinator(): .... That certainly makes your mainline code cleaner, but it's a lot of crud when all you really wanted to write was: while func() as var: .... From rosuav at gmail.com Thu Jan 2 23:25:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 15:25:21 +1100 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 3, 2014 at 3:14 PM, Roy Smith wrote: > Or turn it into a generator: > That certainly makes your mainline code cleaner... Cleaner perhaps, but not clearer. Instead of seeing the original function (say, a database retrieve-next call), you see a wrapper and have to go dig to find out what it's actually doing. Unless it's some kind of generic handler, like: def funcinator(func,*args): while True: var = func(*args) if var: yield var else: break while funcinator(cur.getnext): .... But even that would be problematic until it got so thoroughly understood that it's like enumerate() - which is itself still not perfect. ChrisA From breamoreboy at yahoo.co.uk Thu Jan 2 23:29:49 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Jan 2014 04:29:49 +0000 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 03/01/2014 04:25, Chris Angelico wrote: > On Fri, Jan 3, 2014 at 3:14 PM, Roy Smith wrote: >> Or turn it into a generator: >> That certainly makes your mainline code cleaner... > > Cleaner perhaps, but not clearer. Instead of seeing the original > function (say, a database retrieve-next call), you see a wrapper and > have to go dig to find out what it's actually doing. Unless it's some > kind of generic handler, like: > > def funcinator(func,*args): > while True: > var = func(*args) > if var: > yield var > else: > break > > while funcinator(cur.getnext): > .... > > But even that would be problematic until it got so thoroughly > understood that it's like enumerate() - which is itself still not > perfect. > > ChrisA > I find the above rather funcy :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Thu Jan 2 23:30:22 2014 From: roy at panix.com (Roy Smith) Date: Thu, 02 Jan 2014 23:30:22 -0500 Subject: How to read and post tracebacks (was Registry Key Value Help) References: Message-ID: In article , Chris Angelico wrote: > On Fri, Jan 3, 2014 at 2:58 PM, Rustom Mody wrote: > > Why not write up a few lines on "How to read and post python tracebacks" > > and post it on the wiki? > > You mean "copy and paste the whole output"? I'm not sure what more > needs to be said about posting them. > > Reading them is a bit more complicated, but possibly _too_ complicated > for a simple wiki post. Being able to quickly eyeball a traceback and > know which level to look for the problem at is part of the skill of > debugging, and it usually requires that you know the codebase fairly > well too. Though even with unfamiliar code, it's possible to figure a > lot out by naming conventions, which is why they're so important (all > uppercase meaning "constant" and normally a scalar - so useful). > > ChrisA One of the things I dislike about Python stack dumps is the alternation between lines of file locations and source code snippets. Cognitively, jumping back and forth makes it more difficult to understand than it has to be. They would be much easier to read (IMHO) if each stack frame took one line. Sure, the lines would be longer, but I can easily get 300 columns of text on my laptop screen and still read it easily with my 50-something eyes. Yeah, yeah, I know, we're still living in an 80-column world. From ethan at stoneleaf.us Thu Jan 2 23:18:51 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 02 Jan 2014 20:18:51 -0800 Subject: About some problem In-Reply-To: References: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C63A2B.6070704@stoneleaf.us> On 01/02/2014 05:14 PM, Mark Lawrence wrote: > On 02/01/2014 23:49, Steven D'Aprano wrote: >> Mark Lawrence wrote: >> >>> raise "Not Valid DB Type" >>> >>> is perfectly valid in Python 2. >> >> Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, >> string exceptions display a warning but continue to work, and in >> Python 2.6 >> they generate a compile-time SyntaxError. >> > > Thaanks for the correction. > >> You know how the world ended when Python 2.6 broke backwards >> compatibility >> and split the Python community into two? No, me neither. >> > > I'm 100% certain that you're wrong on this one, the split was simply > never noticed by anybody :) Actually, the split was so severe the universe itself noticed and split into two -- one where folks noticed, and one where nobody did... I wonder which one we're in? -- ~Ethan~ From ethan at stoneleaf.us Thu Jan 2 23:16:51 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 02 Jan 2014 20:16:51 -0800 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> Message-ID: <52C639B3.9030909@stoneleaf.us> On 01/02/2014 04:06 PM, Chris Angelico wrote: > > Here's a crazy idea. Suppose we have a "sticky falseness" that can > quietly propagate through an expression the way a NaN can... then we > could just float that right through the .group() call. > > class truth: > def __new__(cls, x): > if x: return x > return object.__new__(cls) > def __bool__(self): > return False > def __getattr__(self, name): > return self > def __call__(self, *args, **kwargs): > return self > def __repr__(self): > return repr(False) > > Pass any object through truth() and it'll either stay the same (if > it's true) or become this object (if it's false). You can then carry > on with other method calls, and they'll all happily return false. An interesting idea. You'd need to add (at least) __getitem__, and I'll probably call it `maybe`, myself. ;) > (I'm not sure if I'm using __new__ correctly; I've never actually done > it in production code, and the info I found online was mainly Py2 > examples. Should that be done with super(), or is that applicable only > once there's an actual instance with a real MRO?) I haven't tested it, but your __new__ looks fine. The only thing you lose by not calling super() is the inability for cooperative multiple inheritance, except as the ultimate base class. -- ~Ethan~ From breamoreboy at yahoo.co.uk Thu Jan 2 23:46:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 03 Jan 2014 04:46:06 +0000 Subject: About some problem In-Reply-To: <52C63A2B.6070704@stoneleaf.us> References: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> <52C63A2B.6070704@stoneleaf.us> Message-ID: On 03/01/2014 04:18, Ethan Furman wrote: > On 01/02/2014 05:14 PM, Mark Lawrence wrote: >> On 02/01/2014 23:49, Steven D'Aprano wrote: >>> Mark Lawrence wrote: >>> >>>> raise "Not Valid DB Type" >>>> >>>> is perfectly valid in Python 2. >>> >>> Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, >>> string exceptions display a warning but continue to work, and in >>> Python 2.6 >>> they generate a compile-time SyntaxError. >>> >> >> Thaanks for the correction. >> >>> You know how the world ended when Python 2.6 broke backwards >>> compatibility >>> and split the Python community into two? No, me neither. >>> >> >> I'm 100% certain that you're wrong on this one, the split was simply >> never noticed by anybody :) > > Actually, the split was so severe the universe itself noticed and split > into two -- one where folks noticed, and one where nobody did... I > wonder which one we're in? > > -- > ~Ethan~ > The one where Breamore's at the centre. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Thu Jan 2 23:49:31 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Fri, 03 Jan 2014 15:49:31 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Robin Becker wrote: > For fairly sensible reasons we changed the internal default to use unicode > rather than bytes. After doing all that and making the tests compatible > etc etc I have a version which runs in both and passes all its tests. > However, for whatever reason the python 3.3 version runs slower "For whatever reason" is right, unfortunately there's no real way to tell from the limited information you give what that might be. Are you comparing a 2.7 "wide" or "narrow" build? Do your tests use any so-called "astral characters" (characters in the Supplementary Multilingual Planes, i.e. characters with ord() > 0xFFFF)? If I remember correctly, some early alpha(?) versions of Python 3.3 consistently ran Unicode operations a small but measurable amount slower than 3.2 or 2.7. That especially effected Windows. But I understand that this was sped up in the release version of 3.3. There are some operations with Unicode strings in 3.3 which unavoidably are slower. If you happen to hit a combination of such operations (mostly to do with creating lots of new strings and then throwing them away without doing much work) your code may turn out to be a bit slower. But that's a pretty artificial set of code. Generally, test code doesn't make good benchmarks. Tests only get run once, in arbitrary order, it spends a lot of time setting up and tearing down test instances, there are all sorts of confounding factors. This plays merry hell with modern hardware optimizations. In addition, it's quite possible that you're seeing some other slow down (the unittest module?) and misinterpreting it as related to string handling. But without seeing your entire code base and all the tests, who can say for sure? > 2.7 Ran 223 tests in 66.578s > > 3.3 Ran 223 tests in 75.703s > > I know some of these tests are fairly variable, but even for simple things > like paragraph parsing 3.3 seems to be slower. Since both use unicode > internally it can't be that can it, or is python 2.7's unicode faster? Faster in some circumstances, slower in others. If your application bottleneck is the availability of RAM for strings, 3.3 will potentially be faster since it can use anything up to 1/4 of the memory for strings. If your application doesn't use much memory, or if it uses lots of strings which get created then thrown away. > So far the superiority of 3.3 escapes me, Yeah I know, I resisted migrating from 1.5 to 2.x for years. When I finally migrated to 2.3, at first I couldn't see any benefit either. New style classes? Super? Properties? Unified ints and longs? Big deal. Especially since I was still writing 1.5 compatible code and couldn't really take advantage of the new features. When I eventually gave up on supporting versions pre-2.3, it was a load off my shoulders. Now I can't wait to stop supporting 2.4 and 2.5, which will make things even easier. And when I can ignore everything below 3.3 will be a truly happy day. > but I'm tasked with enjoying > this process so I'm sure there must be some new 'feature' that will help. > Perhaps 'yield from' or 'raise from None' or ....... No, you have this completely backwards. New features don't help you support old versions of Python that lack those new features. New features are an incentive to drop support for old versions. > In any case I think we will be maintaining python 2.x code for at least > another 5 years; the version gap is then a real hindrance. Five years sounds about right. -- Steven From rustompmody at gmail.com Fri Jan 3 00:16:30 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 3 Jan 2014 10:46:30 +0530 Subject: How to read and post tracebacks (was Registry Key Value Help) In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 9:33 AM, Chris Angelico wrote: > On Fri, Jan 3, 2014 at 2:58 PM, Rustom Mody wrote: >> Why not write up a few lines on "How to read and post python tracebacks" >> and post it on the wiki? > > You mean "copy and paste the whole output"? I'm not sure what more > needs to be said about posting them. > > Reading them is a bit more complicated, but possibly _too_ complicated > for a simple wiki post. Being able to quickly eyeball a traceback and > know which level to look for the problem at is part of the skill of > debugging, and it usually requires that you know the codebase fairly > well too. Though even with unfamiliar code, it's possible to figure a > lot out by naming conventions, which is why they're so important (all > uppercase meaning "constant" and normally a scalar - so useful). Something like this is what I had in mind http://help.openerp.com/question/9704/how-to-read-and-understand-errors-from-tracebacks/ Obviously it can be written much better (and thought you could make a start :D) [I wonder if the "please make it readable thus not thus" at end proves or disproves Roy's point??] From rosuav at gmail.com Fri Jan 3 00:35:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 16:35:25 +1100 Subject: Ifs and assignments In-Reply-To: <52C639B3.9030909@stoneleaf.us> References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <52C639B3.9030909@stoneleaf.us> Message-ID: On Fri, Jan 3, 2014 at 3:16 PM, Ethan Furman wrote: > On 01/02/2014 04:06 PM, Chris Angelico wrote: >> >> >> Here's a crazy idea. Suppose we have a "sticky falseness" that can >> quietly propagate through an expression the way a NaN can... then we >> could just float that right through the .group() call. >> >> class truth: > > An interesting idea. You'd need to add (at least) __getitem__, and I'll > probably call it `maybe`, myself. ;) I was going for something like bool(). If you pass something through bool(), you get either True or False; if you pass something through this, you get either itself or something that acts like False. >> (I'm not sure if I'm using __new__ correctly; I've never actually done >> it in production code, and the info I found online was mainly Py2 >> examples. Should that be done with super(), or is that applicable only >> once there's an actual instance with a real MRO?) > > I haven't tested it, but your __new__ looks fine. The only thing you lose > by not calling super() is the inability for cooperative multiple > inheritance, except as the ultimate base class. Is it possible to have multiple inheritance at this point, though? I get a class argument, not an instance, because there isn't an instance. ChrisA From rosuav at gmail.com Fri Jan 3 01:30:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 17:30:28 +1100 Subject: How to read and post tracebacks (was Registry Key Value Help) In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 4:16 PM, Rustom Mody wrote: > Something like this is what I had in mind > http://help.openerp.com/question/9704/how-to-read-and-understand-errors-from-tracebacks/ > Hrm, site's having trouble. First time I tried it, it came back with a gateway timeout. Seemed to work second time, though, so now I have the content up. That sort of thing is fine when you're working with a very specific framework. (Look at point 6, for instance. Knowing the boundary between "code we trust because it's really thoroughly tested" and "code that might be the cause of the bug" means knowing what the framework is, usually.) If you understand the code enough to pinpoint the problem, you probably know enough to fix the problem, and if you don't, you can save yourself a lot of analysis by just posting the whole traceback for someone else to read. So while that advice may be helpful on that site's forum, for the general field of python-list it's probably more useful to just tell people to quote the whole traceback, and then we can figure things out. That's the "advice for python-list" part, though. What about the opposite side of that - helping people to understand their own code? Well, it's what I said in the parens about knowing the boundary. This is completely language-independent now; I had the same thing come up in REXX, the same thing will happen if you're debugging something in gdb, and it happens to me all the time in Pike. In all four languages it's common for the actual exception (or signal, in the case of gdb) to emanate from somewhere below user code. So there are two options: Either get so familiar with the library code that you recognize where to stop reading, or get so familiar with the code you're debugging that you recognize where to start reading. The first one is great for users-helping-users forums, the second is superb for your own code :) And if you can't do either of those, a crystal ball helps alot; chances are an expert can go to the right area even without knowing the code, just by what "looks right" and what "looks wrong". A handy fallback. ChrisA PS. I left a typo in there because I'd love to see a drawing of a crystal ball helping Alot. http://hyperboleandahalf.blogspot.com/2010/04/alot-is-better-than-you-at-everything.html From eneskristo at gmail.com Fri Jan 3 03:14:33 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Fri, 3 Jan 2014 00:14:33 -0800 (PST) Subject: On a scrollbar for tkinter In-Reply-To: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> References: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> Message-ID: <3a771930-0b4f-4ac8-87f6-89d72625b09e@googlegroups.com> @Terry Quite sorry but had to write that message in a hurry, didn't notice the name. @Rick I found some solutions for python 2.x, but still, as I am with the future, I need a futuristic solution or 2, so if anyone else could help me, I'd be grateful! From tjreedy at udel.edu Fri Jan 3 03:53:53 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 03 Jan 2014 03:53:53 -0500 Subject: Ifs and assignments In-Reply-To: References: <52C59FF6.5000607@allsup.co> <52C5BD90.9020609@islandtraining.com> <52C5DDA6.5090207@allsup.co> <52C60AF6.8060004@islandtraining.com> Message-ID: On 1/2/2014 8:20 PM, Mark Lawrence wrote: > On 03/01/2014 00:57, Gary Herron wrote: >> On 01/02/2014 01:44 PM, John Allsup wrote: >>> The point of my original post was that, whilst C's >>> if( x = 2 ) { do something } >>> and >>> if( x == 2 ) { do something } >>> are easy to confuse, and a source of bugs, having a construct like >>> follows: >>> >>> if x == 2: >>> do something # what happens at present >>> if testFunc() as x: >>> do something with x >>> >>> using the 'as' syntax that appears with 'with' and 'except', would allow >>> for the advantages of C style assignments in conditionals but without >>> the easy confusion, since here the syntax is significantly different >>> between assignment and equality testing (rather than a character apart >>> as happens with C). >>> >>> This occurs further down in my original post (past the point where you >>> inserted your reply). >>> >>> Another post suggested a workaround by defining a 'pocket' class, for >>> which I am grateful. >>> >>> John >> >> Sorry. I shot off my answer before reading the whole post. That's >> never a good idea. >> >> >> After reading to the end, I rather like your suggestion. It works well >> in your example, , nicely avoids the C/C++ trap, and has some >> consistency with other parts of Python. >> >> Gary Herron >> >> > > I liked the look of this as well. It ought to go to python ideas, or > has it been suggested there in the past? Yes, and rejected (I am quite sure). Consistency would 'demand' at least "while expr as target" and possibly "for i in iterable_expr as target". -- Terry Jan Reedy From mhysnm1964 at gmail.com Thu Jan 2 23:17:37 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Fri, 3 Jan 2014 15:17:37 +1100 Subject: Debugging on the Mac question. Message-ID: <3D25D30F-A973-41EE-9F20-24E2013F042C@gmail.com> Team, I am a Vision Impaired programmer on the Mac and Window platforms. I have started to learn Python. The biggest road block I have is the ability of debugging my simple scripts. The IDLE program does not work with the screen readers I use on the Mac or Windows. A screen reader is a program that grabs the text on the screen and converts it into speech output, at least this is the 50000 feet explanation. I cannot see the screen at all. I have looked at eclipse and it doesn't work with Voice-Over (the screen reader on the Mac). I have java issues on my windows machine preventing me running this app. If I use $python -d script.py the debugger doesn't seem to trigger on the mac. So how I can perform a debug on a script so I can step through it, set up break points, watch variables, etc. It is really annoying me, since under Perl I just added the -d switch and had a full debugger that worked at the console level. Sean From tjreedy at udel.edu Fri Jan 3 04:01:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 03 Jan 2014 04:01:18 -0500 Subject: Blog "about python 3" In-Reply-To: <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/2/2014 11:49 PM, Steven D'Aprano wrote: > Robin Becker wrote: > >> For fairly sensible reasons we changed the internal default to use unicode >> rather than bytes. After doing all that and making the tests compatible >> etc etc I have a version which runs in both and passes all its tests. >> However, for whatever reason the python 3.3 version runs slower > > "For whatever reason" is right, unfortunately there's no real way to tell > from the limited information you give what that might be. > > Are you comparing a 2.7 "wide" or "narrow" build? Do your tests use any > so-called "astral characters" (characters in the Supplementary Multilingual > Planes, i.e. characters with ord() > 0xFFFF)? > > If I remember correctly, some early alpha(?) versions of Python 3.3 > consistently ran Unicode operations a small but measurable amount slower > than 3.2 or 2.7. That especially effected Windows. But I understand that > this was sped up in the release version of 3.3. There was more speedup in 3.3.2 and possibly even more in 3.3.3, so OP should run the latter. -- Terry Jan Reedy From paul.nospam at rudin.co.uk Fri Jan 3 04:08:20 2014 From: paul.nospam at rudin.co.uk (Paul Rudin) Date: Fri, 03 Jan 2014 09:08:20 +0000 Subject: Debugging on the Mac question. References: Message-ID: <87bnzt301n.fsf@rudin.co.uk> Sean Murphy writes: > I am a Vision Impaired programmer on the Mac and Window platforms. I have > started to learn Python. The biggest road block I have is the ability of > debugging my simple scripts. The IDLE program does not work with the screen > readers I use on the Mac or Windows. A screen reader is a program that grabs > the text on the screen and converts it into speech output, at least this is the > 50000 feet explanation. I cannot see the screen at all. > > I have looked at eclipse and it doesn't work with Voice-Over (the screen reader > on the Mac). I have java issues on my windows machine preventing me running > this app. > > If I use $python -d script.py the debugger doesn't seem to trigger on the mac. > > So how I can perform a debug on a script so I can step through it, set up break > points, watch variables, etc. > > It is really annoying me, since under Perl I just added the -d switch and had a > full debugger that worked at the console level. For command line debugging see . More generally you might want to investigate (disclaimer - I have never used this, but from what you say you might find it useful). From cseberino at gmail.com Fri Jan 3 01:46:58 2014 From: cseberino at gmail.com (Chris Seberino) Date: Thu, 2 Jan 2014 22:46:58 -0800 (PST) Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? Message-ID: I've heard it said, by no less a guru than Peter Norvig, that Python is a lot like Lisp without the parentheses.... at least for the basics of Python. For pedagogical reasons, I'm wondering if it would be easy to implement a big subset of Python in Scheme. The basics of Scheme or Lisp are amazingly easy to implement. Would implementing a subset of Python in a Scheme subset be a clever way to easily implement a lot of Python? (This isn't for practical reasons....I'm just curious.) Chris From rustompmody at gmail.com Fri Jan 3 05:00:28 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 3 Jan 2014 15:30:28 +0530 Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 12:16 PM, Chris Seberino wrote: > I've heard it said, by no less a guru than Peter Norvig, that Python is a lot like Lisp without the parentheses.... at least for the basics of Python. > > For pedagogical reasons, I'm wondering if it would be easy to implement a big subset of Python in Scheme. > > The basics of Scheme or Lisp are amazingly easy to implement. Because parsing and unparsing (aka printing) are so trivial for s-expressions > Would implementing a subset of Python in a Scheme subset be a clever way > to easily implement a lot of Python? At the innards of lisp and python are garbage collected data structures. Building one with the other gets you that for free [Doing it in a lower level language like C is what invokes the humorous: Greenspuns tenth law] So yes in that one respect what you say is true. But then theres also (apart from parsing) all kinds of semantic differences eg: - exceptions - modules - OOP milarky - C interfacing in Baskin Robbins number of flavours - carefully crafted portable veneer on top of intrinsically non portable OSes All these have to be handled one way or other > > (This isn't for practical reasons....I'm just curious.) A crucial difference between python and lisp is that python is practical and lisp is utopian From wxjmfauth at gmail.com Fri Jan 3 05:10:36 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 3 Jan 2014 02:10:36 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5cd87255-344b-44e6-a307-162d266ad606@googlegroups.com> It's time to understand the Character Encoding Models and the math behind it. Unicode does not differ from any other coding scheme. How? With a sheet of paper and a pencil. jmf From rosuav at gmail.com Fri Jan 3 05:24:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 3 Jan 2014 21:24:43 +1100 Subject: Blog "about python 3" In-Reply-To: <5cd87255-344b-44e6-a307-162d266ad606@googlegroups.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <5cd87255-344b-44e6-a307-162d266ad606@googlegroups.com> Message-ID: On Fri, Jan 3, 2014 at 9:10 PM, wrote: > It's time to understand the Character Encoding Models > and the math behind it. > Unicode does not differ from any other coding scheme. > > How? With a sheet of paper and a pencil. > One plus one is two, therefore Python is better than Haskell. Four times five is twelve, and four times six is thirteen, and four times seven is enough to make Alice think she's Mabel, and London is the capital of Paris, and the crocodile cheerfully grins. Therefore, by obvious analogy, Unicode times new-style classes equals a 64-bit process. I worked that out with a sheet of paper and a pencil. The pencil was a little help, but the paper was three sheets in the wind. ChrisA From robin at reportlab.com Fri Jan 3 05:32:26 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 03 Jan 2014 10:32:26 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: <52C691BA.8040409@chamonix.reportlab.co.uk> On 02/01/2014 18:25, David Hutto wrote: > Just because it's 3.3 doesn't matter...the main interest is in > compatibility. Secondly, you used just one piece of code, which could be a > fluke, try others, and check the PEP. You need to realize that evebn the > older versions are benig worked on, and they have to be refined. So if you > have a problem, use the older and import from the future would be my > suggestion Suggesting that I use another piece of code to test python3 against python2 is a bit silly. I'm sure I can find stuff which runs faster under python3, but reportlab is the code I'm porting and that is going the wrong way. -- Robin Becker From vlastimil.brom at gmail.com Fri Jan 3 06:00:05 2014 From: vlastimil.brom at gmail.com (Vlastimil Brom) Date: Fri, 3 Jan 2014 12:00:05 +0100 Subject: On a scrollbar for tkinter In-Reply-To: <3a771930-0b4f-4ac8-87f6-89d72625b09e@googlegroups.com> References: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> <3a771930-0b4f-4ac8-87f6-89d72625b09e@googlegroups.com> Message-ID: 2014/1/3 : > @Rick > I found some solutions for python 2.x, but still, as I am with the future, I need a futuristic solution or 2, so if anyone else could help me, I'd be grateful! > -- Hi, I usually don't use tkinter myself, hence others may have more idiomatic suggestions, but you can of course use ScrolledWindow tix with python3; cf.: from tkinter import tix root = tix.Tk() root.title("scrolled window") root.geometry("50x500+50+50") sw= tix.ScrolledWindow(root) sw.pack(fill=tix.BOTH, expand=1) for i in range(1,101): cb = tix.Checkbutton(sw.window, text=str(i)) cb.pack(fill=tix.BOTH, expand=0) root.mainloop() hth, vbr From robin at reportlab.com Fri Jan 3 06:14:41 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 03 Jan 2014 11:14:41 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: <52C69BA1.30908@chamonix.reportlab.co.uk> On 02/01/2014 18:37, Terry Reedy wrote: > On 1/2/2014 12:36 PM, Robin Becker wrote: > >> I just spent a large amount of effort porting reportlab to a version >> which works with both python2.7 and python3.3. I have a large number of >> functions etc which handle the conversions that differ between the two >> pythons. > > I am imagine that this was not fun. indeed :) > >> For fairly sensible reasons we changed the internal default to use >> unicode rather than bytes. > > Do you mean 'from __future__ import unicode_literals'? No, previously we had default of utf8 encoded strings in the lower levels of the code and we accepted either unicode or utf8 string literals as inputs to text functions. As part of the port process we made the decision to change from default utf8 str (bytes) to default unicode. > Am I correct in thinking that this change increases the capabilities of > reportlab? For instance, easily producing an article with abstracts in English, > Arabic, Russian, and Chinese? > It's made no real difference to what we are able to produce or accept since utf8 or unicode can encode anything in the input and what can be produced depends on fonts mainly. > > After doing all that and making the tests ........... >> I know some of these tests are fairly variable, but even for simple >> things like paragraph parsing 3.3 seems to be slower. Since both use >> unicode internally it can't be that can it, or is python 2.7's unicode >> faster? > > The new unicode implementation in 3.3 is faster for some operations and slower > for others. It is definitely more space efficient, especially compared to a wide > build system. It is definitely less buggy, especially compared to a narrow build > system. > > Do your tests use any astral (non-BMP) chars? If so, do they pass on narrow 2.7 > builds (like on Windows)? I'm not sure if we have any non-bmp characters in the tests. Simple CJK etc etc for the most part. I'm fairly certain we don't have any ability to handle composed glyphs (multi-codepoint) etc etc .... > For one thing, indexing and slicing just works on all machines for all unicode > strings. Code for 2.7 and 3.3 either a) does not index or slice, b) does not > work for all text on 2.7 narrow builds, or c) has extra conditional code only > for 2.7. > probably -- Robin Becker From robin at reportlab.com Fri Jan 3 06:37:42 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 03 Jan 2014 11:37:42 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: <52C6A106.9040702@chamonix.reportlab.co.uk> On 02/01/2014 23:57, Antoine Pitrou wrote: > .......... > > Running a test suite is a completely broken benchmarking methodology. > You should isolate workloads you are interested in and write a benchmark > simulating them. > I'm certain you're right, but individual bits of code like generating our reference manual also appear to be slower in 3.3. > Regards > > Antoine. > > -- Robin Becker From tobias.oberstein at tavendo.de Fri Jan 3 07:07:52 2014 From: tobias.oberstein at tavendo.de (Tobias Oberstein) Date: Fri, 3 Jan 2014 04:07:52 -0800 Subject: WebSocket for Python 2 and 3 on Twisted and asyncio Message-ID: <634914A010D0B943A035D226786325D4446BD1EABA@EXVMBX020-12.exch020.serverdata.net> Hi, Autobahn provides open-source implementations of * The WebSocket Protocol * The Web Application Messaging Protocol (WAMP) https://github.com/tavendo/AutobahnPython https://pypi.python.org/pypi/autobahn Starting with the release 0.7.0, Autobahn now fully supports (with all features) both * Twisted (on Python 2/3) and * asyncio (on Python 3.3+) as the underlying networking framework. Here is a complete example of WebSocket server and client: Twisted: https://github.com/tavendo/AutobahnPython/tree/master/examples/twisted/websocket/echo Asyncio: https://github.com/tavendo/AutobahnPython/tree/master/examples/asyncio/websocket/echo The application code is very similar or even identical. Cheers, /Tobias From seaders at gmail.com Fri Jan 3 07:21:46 2014 From: seaders at gmail.com (seaders at gmail.com) Date: Fri, 3 Jan 2014 04:21:46 -0800 (PST) Subject: pip's wheel support requires setuptools >= 0.8 for dist-info support Message-ID: I have a Jenkins server running Ubuntu which has been running perfectly fine for as long as I've been using it, and in one of the jobs, it runs a few things under the shiningpanda plugin (a python virtual environment wrapper). At some point today, or over the weekend, the job that uses it started failing, with the main error seemingly being the title, full error reported is > pip install Jinja2 Wheel installs require setuptools >= 0.8 for dist-info support. pip's wheel support requires setuptools >= 0.8 for dist-info support. I've googled for this error, or anything like it, but I haven't been able to find anything useful towards solving it. From robin at reportlab.com Fri Jan 3 07:28:48 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 03 Jan 2014 12:28:48 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C6AD00.5050000@chamonix.reportlab.co.uk> On 03/01/2014 09:01, Terry Reedy wrote: > There was more speedup in 3.3.2 and possibly even more in 3.3.3, so OP > should run the latter. python 3.3.3 is what I use on windows. As for astral / non-bmp etc etc that's almost irrelevant for the sort of tests we're doing which are mostly simple english text. -- Robin Becker From robert.kern at gmail.com Fri Jan 3 08:50:03 2014 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 03 Jan 2014 13:50:03 +0000 Subject: Debugging on the Mac question. In-Reply-To: <3D25D30F-A973-41EE-9F20-24E2013F042C@gmail.com> References: <3D25D30F-A973-41EE-9F20-24E2013F042C@gmail.com> Message-ID: On 2014-01-03 04:17, Sean Murphy wrote: > Team, > > > I am a Vision Impaired programmer on the Mac and Window platforms. I have started to learn Python. The biggest road block I have is the ability of debugging my simple scripts. The IDLE program does not work with the screen readers I use on the Mac or Windows. A screen reader is a program that grabs the text on the screen and converts it into speech output, at least this is the 50000 feet explanation. I cannot see the screen at all. > > I have looked at eclipse and it doesn't work with Voice-Over (the screen reader on the Mac). I have java issues on my windows machine preventing me running this app. > > If I use $python -d script.py the debugger doesn't seem to trigger on the mac. > > So how I can perform a debug on a script so I can step through it, set up break points, watch variables, etc. > > It is really annoying me, since under Perl I just added the -d switch and had a full debugger that worked at the console level. Python also has a console debugger. -d does not invoke it; -d is for something else. $ python -m pdb myscript.py http://docs.python.org/3.3/library/pdb -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From roy at panix.com Fri Jan 3 09:57:48 2014 From: roy at panix.com (Roy Smith) Date: Fri, 03 Jan 2014 09:57:48 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Robin Becker wrote: > On 03/01/2014 09:01, Terry Reedy wrote: > > There was more speedup in 3.3.2 and possibly even more in 3.3.3, so OP > > should run the latter. > > python 3.3.3 is what I use on windows. As for astral / non-bmp etc etc that's > almost irrelevant for the sort of tests we're doing which are mostly simple > english text. The sad part is, if you're accepting any text from external sources, you need to be able to deal with astral. I was doing a project a while ago importing 20-something million records into a MySQL database. Little did I know that FOUR of those records contained astral characters (which MySQL, at least the version I was using, couldn't handle). My way of dealing with those records was to nuke them. Longer term we ended up switching to Postgress. From larry.martell at gmail.com Fri Jan 3 10:19:09 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 3 Jan 2014 10:19:09 -0500 Subject: Creating a list with holes Message-ID: I think I know the answer is no, but is there any package that allows creating a list with holes in it? E.g. I'd want to do something like: x[10] = 12 x[20] = 30 I'm thinking of something like defaultdict but for lists (I know that's very different, but ... ) Thanks! -larry From eneskristo at gmail.com Fri Jan 3 10:30:08 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Fri, 3 Jan 2014 07:30:08 -0800 (PST) Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Friday, January 3, 2014 4:19:09 PM UTC+1, Larry.... at gmail.com wrote: > I think I know the answer is no, but is there any package that allows > > creating a list with holes in it? E.g. I'd want to do something like: > > > > x[10] = 12 > > x[20] = 30 > > > > I'm thinking of something like defaultdict but for lists (I know > > that's very different, but ... ) > > > > Thanks! > > -larry Hello Larry! The thing is, where to put the holes? A costum function can be made if you want the hole to be placed for example: 1. In random 2. Every nth hole(Or with another sequence) 3. In the beginning or end. Please tell me how do you want them, and I will try my best to help! - Enes From invalid at invalid.invalid Fri Jan 3 10:33:18 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 3 Jan 2014 15:33:18 +0000 (UTC) Subject: need to print seconds from the epoch including the millisecond References: <59aa73ac-e06e-4c0e-83a4-147ac42cad2e@googlegroups.com> <52bcaeed$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-01-03, Dave Angel wrote: > On Thu, 2 Jan 2014 16:23:22 +0000 (UTC), Grant Edwards > wrote: >> AFAIK, that's irrelevent. time.time() returns a float. On all the >> CPython implementations I know of, that is a 64-bit IEEE format, >> which provides 16 decimal digits of precision regardless of the >> granularity of the system time value. At this point in time, that >> means 10 digits left of the decimal point and 6 to the right. > > Correction: no more than about 6 to the right. You can certainly get > less, from an os with a smaller resolution. time.time() returns a Python float. A Python float will have 16 digits of precision. Perhaps the OS always sets some of those digits to 0 (or even random values), but they're still there. Perhaps the accuracy or granularity of the values returned is problematic on some OSes, but the precision of the value doesn't change: there's no way he's "only getting 2 decimal places" from time.time() unless (as you mention below) he's printing them using a method that truncates/rounds. > Or you can lose some of what you do get by printing in a sub-optimal > way. Yes, depending on how you print the value, you can hide some of the digits. But, there's no way for time.time() to return a value with less than ~16 decimal digits of precicsion. -- Grant Edwards grant.b.edwards Yow! ! Everybody out of at the GENETIC POOL! gmail.com From rosuav at gmail.com Fri Jan 3 10:37:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 02:37:05 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 2:19 AM, Larry Martell wrote: > I think I know the answer is no, but is there any package that allows > creating a list with holes in it? E.g. I'd want to do something like: > > x[10] = 12 > x[20] = 30 > > I'm thinking of something like defaultdict but for lists (I know > that's very different, but ... ) Depending on what exactly you need, it's probably worth just using a dict. In what ways do you need it to function as a list? You can always iterate over sorted(some_dict.keys()) if you need to run through them in order. Alternatively, if you expect to fill in most of the elements, it's possible you'd be happier working with a subclass of list that auto-expands by filling in the spare space with a singleton meaning "no element here". The code probably exists somewhere, but if not, it wouldn't be hard to write. Then it'd be a list, but you can start with it empty and assign as you describe above. What's the use case? I expect that one or the other of those options would cover most cases, but maybe yours is different. ChrisA From rosuav at gmail.com Fri Jan 3 10:32:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 02:32:14 +1100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 4, 2014 at 1:57 AM, Roy Smith wrote: > I was doing a project a while ago importing 20-something million records > into a MySQL database. Little did I know that FOUR of those records > contained astral characters (which MySQL, at least the version I was > using, couldn't handle). > > My way of dealing with those records was to nuke them. Longer term we > ended up switching to Postgress. Look! Postgres means you don't lose data!! Seriously though, that's a much better long-term solution than destroying data. But MySQL does support the full Unicode range - just not in its "UTF8" type. You have to specify "UTF8MB4" - that is, "maximum bytes 4" rather than the default of 3. According to [1], the UTF8MB4 encoding is stored as UTF-16, and UTF8 is stored as UCS-2. And according to [2], it's even possible to explicitly choose the mindblowing behaviour of UCS-2 for a data type that calls itself "UTF8", so that a vague theoretical subsequent version of MySQL might be able to make "UTF8" mean UTF-8, and people can choose to use the other alias. To my mind, this is a bug with backward-compatibility concerns. That means it can't be fixed in a point release. Fine. But the behaviour change is "this used to throw an error, now it works". Surely that can be fixed in the next release. Or surely a version or two of deprecating "UTF8" in favour of the two "MB?" types (and never ever returning "UTF8" from any query), followed by a reintroduction of "UTF8" as an alias for MB4, and the deprecation of MB3. Or am I spoiled by the quality of Python (and other) version numbering, where I can (largely) depend on functionality not changing in point releases? ChrisA [1] http://dev.mysql.com/doc/refman/5.7/en/charset-unicode-utf8mb4.html [2] http://dev.mysql.com/doc/refman/5.7/en/charset-unicode-utf8mb3.html From roy at panix.com Fri Jan 3 10:38:34 2014 From: roy at panix.com (Roy Smith) Date: Fri, 03 Jan 2014 10:38:34 -0500 Subject: Creating a list with holes References: Message-ID: In article , Larry Martell wrote: > I think I know the answer is no, but is there any package that allows > creating a list with holes in it? E.g. I'd want to do something like: > > x[10] = 12 > x[20] = 30 Whenever you ask, "What data structure do I want", you need to be able to answer, "What operations do I want to perform?, and, "What constraints do I have on memory use?" Why do you want holes? Is the issue that you're storing sparse data and don't want to waste memory on unused keys? If so, a dictionary should do you fine. Do you need to be able to read the values back out in a specific order? You can still do that with a dictionary if you're willing to re-sort the keys; that's O(n log n) on the number of keys, but if n is small, it doesn't matter. From rosuav at gmail.com Fri Jan 3 10:41:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 02:41:11 +1100 Subject: need to print seconds from the epoch including the millisecond In-Reply-To: References: <59aa73ac-e06e-4c0e-83a4-147ac42cad2e@googlegroups.com> <52bcaeed$0$29995$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 4, 2014 at 2:33 AM, Grant Edwards wrote: > time.time() returns a Python float. A Python float will have 16 digits > of precision. Perhaps the OS always sets some of those digits to 0 (or > even random values), but they're still there. Perhaps the accuracy or > granularity of the values returned is problematic on some OSes, but > the precision of the value doesn't change: there's no way he's "only > getting 2 decimal places" from time.time() unless (as you mention > below) he's printing them using a method that truncates/rounds. If I print out the value float("1.01"), I get just three digits. When those trailing digits are all zeroes, they won't be displayed. That's exactly what the OP was seeing. ChrisA From larry.martell at gmail.com Fri Jan 3 10:41:21 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 3 Jan 2014 10:41:21 -0500 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 10:30 AM, wrote: > On Friday, January 3, 2014 4:19:09 PM UTC+1, Larry.... at gmail.com wrote: >> I think I know the answer is no, but is there any package that allows >> >> creating a list with holes in it? E.g. I'd want to do something like: >> >> x[10] = 12 >> x[20] = 30 >> >> I'm thinking of something like defaultdict but for lists (I know >> >> that's very different, but ... ) > > Hello Larry! > > The thing is, where to put the holes? A costum function can be made if you want the hole to be placed for example: > 1. In random > 2. Every nth hole(Or with another sequence) > 3. In the beginning or end. > > Please tell me how do you want them, and I will try my best to help! The holes would be between the items I put in. In my example above, if I assigned to [10] and [20], then the other items ([0..9] and [11..19]) would have None. From rosuav at gmail.com Fri Jan 3 10:46:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 02:46:04 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 2:38 AM, Roy Smith wrote: > Why do you want holes? Is the issue that you're storing sparse data and > don't want to waste memory on unused keys? If so, a dictionary should > do you fine. > > Do you need to be able to read the values back out in a specific order? > You can still do that with a dictionary if you're willing to re-sort the > keys; that's O(n log n) on the number of keys, but if n is small, it > doesn't matter. There's another factor, which is iteration time. Maybe you don't care about the memory usage, but compare these: foo = [None]*1000 foo[123] = 234 foo[543] = 432 for key,value in enumerate(foo): if value: print("Slot %d is %d"%(key,value)) # versus foo = {} foo[123] = 234 foo[543] = 432 for key in sorted(foo.keys()): value = foo[key] if value: print("Slot %d is %d"%(key,value)) Which one's going to be faster? The dictionary, by far, in this example. I'm not sure how populated the list would have to be to beat it (as the dict will get slower on O(n log n) on keys, as you mention, while the list will run at O(n) on the highest element, which may well be a constant), but it's something to consider. ChrisA From duncan.booth at invalid.invalid Fri Jan 3 10:46:50 2014 From: duncan.booth at invalid.invalid (Duncan Booth) Date: 3 Jan 2014 15:46:50 GMT Subject: Ifs and assignments References: <52C59FF6.5000607@allsup.co> <52c62fa8$0$30001$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > Maybe a for loop isn't the best other example, but I > frequently work with places where I want to call some function and > keep iterating with the result of that until it returns false: > > while (var = func()) > { > .... > } > > In Python, that gets a lot clunkier. The most popular way is to turn > it into an infinite loop: > > while True: > var = func() > if not var: break > .... > My preferred way would be to write it as a `for` loop: for var in iter(func, False): ... Though you do have to be sure to get the sentinel value correct as it will only break for the expected terminal False, not for 0, "", or None. -- Duncan Booth From roy at panix.com Fri Jan 3 10:51:47 2014 From: roy at panix.com (Roy Smith) Date: Fri, 03 Jan 2014 10:51:47 -0500 Subject: Creating a list with holes References: Message-ID: In article , Chris Angelico wrote: > Alternatively, if you expect to fill in most of the elements, it's > possible you'd be happier working with a subclass of list that > auto-expands by filling in the spare space with a singleton meaning > "no element here". And, if you know ahead of time the maximum number of elements you will ever have: x = [None] * max_count will preallocate them all with a minimum of fuss. From larry.martell at gmail.com Fri Jan 3 10:55:58 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 3 Jan 2014 10:55:58 -0500 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 10:37 AM, Chris Angelico wrote: > On Sat, Jan 4, 2014 at 2:19 AM, Larry Martell wrote: >> I think I know the answer is no, but is there any package that allows >> creating a list with holes in it? E.g. I'd want to do something like: >> >> x[10] = 12 >> x[20] = 30 >> >> I'm thinking of something like defaultdict but for lists (I know >> that's very different, but ... ) > > Depending on what exactly you need, it's probably worth just using a > dict. In what ways do you need it to function as a list? You can > always iterate over sorted(some_dict.keys()) if you need to run > through them in order. > > Alternatively, if you expect to fill in most of the elements, it's > possible you'd be happier working with a subclass of list that > auto-expands by filling in the spare space with a singleton meaning > "no element here". The code probably exists somewhere, but if not, it > wouldn't be hard to write. Then it'd be a list, but you can start with > it empty and assign as you describe above. > > What's the use case? I expect that one or the other of those options > would cover most cases, but maybe yours is different. Yeah, googled and didn't find anything, then started writing it myself last night, then this morning decided to ask if it already existed. The use case is that I'm parsing a XML file like this: True False True False True This is an existing program that is putting the data into a dict. The dict keys are ['DefaultVersion','Default'] and ['DefaultVersion','Current']. These contain lists that have the True/False values. It's currently not correctly handling the missing items so it ends up with: ['DefaultVersion','Default'][0] = True ['DefaultVersion','Default'][1] = True ['DefaultVersion','Current'][0] = False When it should be: ['DefaultVersion','Default'][0] = True ['DefaultVersion','Default'][1] = None ['DefaultVersion','Current'][0] = None And so on. This dict/list is then processed by other existing code, so I don't want to have to rewrite a ton of code - I just want to fix the list so the items end up in their correct slots. From rosuav at gmail.com Fri Jan 3 10:57:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 02:57:56 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 2:51 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> Alternatively, if you expect to fill in most of the elements, it's >> possible you'd be happier working with a subclass of list that >> auto-expands by filling in the spare space with a singleton meaning >> "no element here". > > And, if you know ahead of time the maximum number of elements you will > ever have: > > x = [None] * max_count > > will preallocate them all with a minimum of fuss. Yes, as I use in the trivial example in the subsequent post. But as a general solution this is usually insufficient. (Whether or not None is valid as a sentinel is, of course, quite orthogonal to the discussion. I avoided assuming that it was, the OP's now shown that it does seem to be.) ChrisA From rosuav at gmail.com Fri Jan 3 11:07:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 03:07:08 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 2:55 AM, Larry Martell wrote: > The use case is that I'm parsing a XML file like this: > > > > > True > > > > > False > > > > > True > False > > > > True > > > This is an existing program that is putting the data into a dict. The > dict keys are ['DefaultVersion','Default'] and > ['DefaultVersion','Current']. These contain lists that have the > True/False values. Are you assigning keys by value, or are you simply appending to the lists? It looks to me like you could simply append another element to both lists for each unit, with the given Default and Current if available, or with None for any that aren't set. Alternatively, when you get up to the , append None to each list, and then when you see a value, assign to [-1] and overwrite the None. ChrisA From robin at reportlab.com Fri Jan 3 07:28:48 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 03 Jan 2014 12:28:48 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C6AD00.5050000@chamonix.reportlab.co.uk> On 03/01/2014 09:01, Terry Reedy wrote: > There was more speedup in 3.3.2 and possibly even more in 3.3.3, so OP > should run the latter. python 3.3.3 is what I use on windows. As for astral / non-bmp etc etc that's almost irrelevant for the sort of tests we're doing which are mostly simple english text. -- Robin Becker From cseberino at gmail.com Fri Jan 3 11:50:48 2014 From: cseberino at gmail.com (Chris Seberino) Date: Fri, 3 Jan 2014 08:50:48 -0800 (PST) Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: References: Message-ID: <374d1574-94f8-4817-8406-23d6f38fc740@googlegroups.com> Exceptions, modules, OOP, etc. would be tricky to implement in Scheme but at least the basics like for loops, while loops, assignment etc. would seem doable and very instructive for students.....they would thereafter, for all time, have a mental image of what the Python interpreter is doing. > But then theres also (apart from parsing) all kinds of semantic differences eg: > > - exceptions > > - modules > > - OOP milarky > > - C interfacing in Baskin Robbins number of flavours > > - carefully crafted portable veneer on top of intrinsically non portable OSes > > From jeanpierreda at gmail.com Fri Jan 3 12:10:07 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 3 Jan 2014 09:10:07 -0800 Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: References: Message-ID: On Thu, Jan 2, 2014 at 10:46 PM, Chris Seberino wrote: > I've heard it said, by no less a guru than Peter Norvig, that Python is a lot like Lisp without the parentheses.... at least for the basics of Python. There are plenty of non-superficial differences. Python has lexical scope, lisps usually have dynamic scope. Python has statements and expressions, lisps have expressions and maybe only a few tiny extra restrictions. Python has dynamic dispatch everywhere, lisps have it usually almost nowhere. And the unifying thing that makes a lisp a lisp is macros, which Python lacks. > For pedagogical reasons, I'm wondering if it would be easy to implement a big subset of Python in Scheme. A lecturer of mine back in university did this (implemented a subset of Python in Racket). My understanding is that this is primarily interesting to show that Racket is not as crazily different as it looks from the syntax. When I TA'd for him, he had a really neat lecture where he gave the following three snippets of code: // C++ Foo x = y; x.bar = 3; // Java Foo x = y; x.bar = 3; // Scheme (define x y) (foo-bar x 3) The syntax of the first two is identical, so the uneducated would assume they do the same thing. But actually, the latter two are the ones with the identical behaviour. It is definitely true that the syntax differences hide how similar Scheme and Python are. These two languages are close enough together that any > The basics of Scheme or Lisp are amazingly easy to implement. Would implementing a subset of Python in a Scheme subset be a clever way to easily implement a lot of Python? If it's easy to implement in terms of Scheme, which is itself easy to implement, then it would be easy to implement directly, so this doesn't seem like a useful question to ask. Anyway, most of the useful bits of Python aren't present or have different semantics than how they work in lisps. -- Devin From ethan at stoneleaf.us Fri Jan 3 11:56:39 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Jan 2014 08:56:39 -0800 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <5cd87255-344b-44e6-a307-162d266ad606@googlegroups.com> Message-ID: <52C6EBC7.1060601@stoneleaf.us> On 01/03/2014 02:24 AM, Chris Angelico wrote: > > I worked that out with a sheet of paper and a pencil. The pencil was a > little help, but the paper was three sheets in the wind. Beautiful! -- ~Ethan~ From cseberino at gmail.com Fri Jan 3 12:26:35 2014 From: cseberino at gmail.com (Chris Seberino) Date: Fri, 3 Jan 2014 09:26:35 -0800 (PST) Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: References: Message-ID: <4d0281ee-2b28-484b-943d-666ea40800df@googlegroups.com> On Friday, January 3, 2014 11:10:07 AM UTC-6, Devin Jeanpierre wrote: > A lecturer of mine back in university did this (implemented a subset > > of Python in Racket). My understanding is that this is primarily > > interesting to show that Racket is not as crazily different as it > > looks from the syntax. Is that on the web anywhere? That would be very interesting to look at. I'm sure others would find it useful too. From roy at panix.com Fri Jan 3 12:26:35 2014 From: roy at panix.com (Roy Smith) Date: Fri, 03 Jan 2014 12:26:35 -0500 Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? References: Message-ID: In article , Devin Jeanpierre wrote: > // C++ > Foo x = y; > x.bar = 3; > > // Java > Foo x = y; > x.bar = 3; > > // Scheme > (define x y) > (foo-bar x 3) > > The syntax of the first two is identical, so the uneducated would > assume they do the same thing. This is one of the things that tripped me up when I first tried to learn JavaScript. They syntax is superficially identical to C++, so I assumed it worked the same way. Bad assumption. From emile at fenx.com Fri Jan 3 12:33:48 2014 From: emile at fenx.com (emile) Date: Fri, 03 Jan 2014 09:33:48 -0800 Subject: Python 2.x and 3.x usage survey In-Reply-To: References: <52c29782$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 01/02/2014 08:55 AM, Grant Edwards wrote: > On 2013-12-31, Steven D'Aprano wrote: >> You laugh, but there was at least one attendee at the last PyCon who was >> still using 1.5 professionally. Software never quite dies so long as there >> is hardware capable of running it. > > ITYM: ... so long as there is hardware capable of running an emulator > that is capable of running it. > ...or as long as there's business value in keeping it running. As I recall it took the banking industry decades to move things forward. I still maintain software for customers that I originally wrote 35 years ago. Rule one is don't fix it if it ain't broke, so yes, I've got python projects deployed that run under everything from 1.5.2 on. Fortunately, they all work without issue so maintenance isn't a problem. Emile From rustompmody at gmail.com Fri Jan 3 12:33:40 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 3 Jan 2014 23:03:40 +0530 Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: <374d1574-94f8-4817-8406-23d6f38fc740@googlegroups.com> References: <374d1574-94f8-4817-8406-23d6f38fc740@googlegroups.com> Message-ID: On Fri, Jan 3, 2014 at 10:20 PM, Chris Seberino wrote: > > Exceptions, modules, OOP, etc. would be tricky to implement in Scheme but at least the basics like for loops, while loops, assignment etc. would seem doable and very instructive for students.....they would thereafter, for all time, have a mental image of what the Python interpreter is doing. If thats the intent, sure, scheme is heaven for such In particular, take a language, break it up into a dozen or so 'little-languages' eg one for types, one for control structures, one for scoping/parameter passing etc while 'stubbing out' the rest -- for such scheme is simply unbeatable. And this includes IDEAS of oop modules etc. Its only when you then start demanding: "Why cant this become realistic?" that things start creaking and groaning at the edges A simple example: One of the much touted features of modern functional languages like Haskell (actually its the SML family) is pattern matching. I implemented a macro -- destruct -- to do it in scheme -- all of 91 lines! Now one gets greedy and says: "Hey! Neat! Only small catch is that haskell patterns looks so much neater than these home-cooked Lots-of-Irritating-Single-Parenthesis (aka Lisp-y) patterns." And Wham! The shit begins to hit the ceiling To my mind, scheme is so powerful that even Abelson and Sussman dont get how powerful. I wrote a blog post on that but then diluted the title :D http://blog.languager.org/2013/08/applying-si-on-sicp.html On the whole though, functional languages are distinctly weaker than lisps but much easier for students. Heres an old Wadler paper explaining that: http://www.cs.kent.ac.uk/people/staff/dat/miranda/wadler87.pdf From denismfmcmahon at gmail.com Fri Jan 3 13:07:10 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 3 Jan 2014 18:07:10 +0000 (UTC) Subject: Creating a list with holes References: Message-ID: On Fri, 03 Jan 2014 10:41:21 -0500, Larry Martell wrote: > The holes would be between the items I put in. In my example above, if I > assigned to [10] and [20], then the other items ([0..9] and [11..19]) > would have None. >>> dic = { 10:6, 20:11} >>> dic.get(10) 6 >>> dic.get(14) >>> dic.get(27,"oh god there's nothing here") "oh god there's nothing here" >>> dic.get(99,None) >>> dic.get(168,False) False >>> dic.get(20,"Boo Yah") 11 >>> So a standard dictionary does this returning None (or any other default value you care to pass it) as long as you use the dict.get(key[,default]) method rather than dict[key] to return the value. See also: http://stackoverflow.com/questions/6130768/return-none-if-dictionary-key- is-not-available -- Denis McMahon, denismfmcmahon at gmail.com From jeanpierreda at gmail.com Fri Jan 3 13:32:48 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Fri, 3 Jan 2014 10:32:48 -0800 Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: <4d0281ee-2b28-484b-943d-666ea40800df@googlegroups.com> References: <4d0281ee-2b28-484b-943d-666ea40800df@googlegroups.com> Message-ID: On Fri, Jan 3, 2014 at 9:26 AM, Chris Seberino wrote: > On Friday, January 3, 2014 11:10:07 AM UTC-6, Devin Jeanpierre wrote: >> A lecturer of mine back in university did this (implemented a subset >> of Python in Racket). My understanding is that this is primarily >> interesting to show that Racket is not as crazily different as it >> looks from the syntax. > > Is that on the web anywhere? That would be very interesting to look at. I'm sure others would find it useful too. As far as I know, no. There was an early version of it that was part of a course, but as I understand it he did something much more thorough later on. Even that course content seems to be offline and not very available by archive.org; the relevant bits aren't archived: https://web.archive.org/web/20111119221012/http://www.cs.toronto.edu/~gfb/csc324/2010F/content.shtml Feel free to dig around and try to find something, but as I recall the assignment on that page was to write some very minor interpreter actions with a list generated from the AST of a python source file. His later work was translating Python to Racket, with macros to implement various Python operations. That wasn't an assignment or course content, it was stuff he'd show to students during office hours and such. I believe the end goal was to turn it into a real tool for teaching programming. The idea there was that Python is 90% irrelevant to teaching students how to program, and the full generality of Python makes it harder for students to learn due to weird behaviours or unreasonable complexity. If you decide to only implement the 10% of Python that you care to teach, then it's much easier to implement (in fact, without that, the goal isn't even achievable for one person), plus it serves your goals potentially better than Python does. Regardless of if it's a particularly good idea, this is what Python must look like if you try to elegantly directly translate it to Scheme (or any lisp), just because the semantics will be so different once you get out of the basics and the trivial things. If the translation is to be clean, the input language can't actually be Python. If the input language is Python, the output will be a horrible mess that isn't useful for the student, and also it will take a lot of work until it is even correct. Scheme is far simpler and smaller than Python is. -- Devin From bv8bv8bv8 at gmail.com Fri Jan 3 13:44:37 2014 From: bv8bv8bv8 at gmail.com (BV BV) Date: Fri, 3 Jan 2014 10:44:37 -0800 (PST) Subject: The Economic System of Islam Message-ID: The Economic System of Islam 1-An introduction to the principles Islam has legislated to guide the economic system of society. Part 1: The sources from which the laws that guide economical activity are derived. 2-The Ideological Basis of Economic Activity and the general principles by which they are guided Introduction As a complete way of life, Islam has provided guidelines and rules for every sphere of life and society. Naturally, a functioning economic system is vital for a healthy society, as the consumption of goods and services, and the facilitation of this by a common medium of exchange, play a major role in allowing people to realize their material and other goals in life. Islam has set some standards, based on justice and practicality, for such economic systems to be established. These standards aim to prevent the enmity that often occurs between different socioeconomic sections. Of course, it is true that the gathering of money concerns almost every human being who participates in transactions with others. Yet, while these standards recognize money as being among the most important elements in society, they do not lose sight of the fact that its position is secondary to the real purpose of human existence, which is the worship of God. An Islamic economic system is not necessarily concerned with the precise amount of financial income and expenditure, imports and exports, and other economic statistics. While such matters are no doubt important, Islam is more concerned with the spirit of the economic system. A society that implements Islamic laws and promotes Islamic manners will find that it bring together all the systems ? social, economic, and so forth ? that it deals with. Islam teaches that God has created provision for every person who He has brought to life. Therefore, the competition for natural resources that is presumed to exist among the nations of the world is an illusion. While the earth has sufficient bounty to satisfy the needs of mankind, the challenge for humans lies in discovering, extracting, processing, and distributing these resources to those who need them. Islam consists of a set of beliefs which organizes the relationship between the individual and his Creator; between the person and other human beings; between the person and universe; and even the relationship of the person to himself. In that sense, Islam regulates human behavior, and one type of human behavior is economic behavior. Economic behavior is dealt by Muslims as a means of production, distribution, and consumption of goods and services. In Islam, human behavior -whether in the economic area or others - is not value free; nor is it value neutral. It is connected with the ideological foundation of the faith. The Sources of Islamic Economics The fundamental sources of Islam - the Quran and the Sunnah of the Prophet[1] - provide guidelines for economic behavior and a blueprint of how the economic system of a society should be organized. Therefore, the values and objectives of all ?Islamic? economic systems must necessarily conform to, and comply with, the principles derived from these fundamental sources. The purpose of these articles is to outline the most salient characteristics of an economic system based on the fundamental sources of Islam. The focus here is on the principal features of the Islamic system. The Islamic economic system is defined by a network of rules called the Shariah. The rules which are contained in the Shariah are both constitutive and regulative, meaning that they either lay the rules for the creation of economic entities and systems, as well the rules which regulate existing one. As an integral part of the revelation, the Shariah is the guide for human action which encompasses every aspect of life ? spiritual, individual, social, political, cultural, and economic. It provides a scale by which all actions, whether on the part of the individual agents, society, and the state, are classified in regards to their legality. Thus there are five types of actions recognized, namely: obligatory; recommended; permissible; discouraged; and forbidden. This classification is also inclusive of economic behavior. The basic source of the Shariah in Islam is the Quran and the Sunnah, which include all the necessary rules of the Shariah as guidance for mankind. The Sunnah further explains these rules by the practical application of Prophet Muhammad, may the mercy and blessings of God be upon him. The expansion of the regulative rules of the Shariah and their extensions to new situations in later times was accomplished with the aid of consensus of the scholars, analogical reasoning - which derived rules by discerning an analogy between new problems and those existing in the primary sources - and finally, through textual reasoning of scholars specialized in the Shariah. These five sources - the Quran, the Sunnah, consensus of the scholars, analogical reasoning, and textual reasoning - constitute the components of the Shariah, and these components are also used as a basis for governing economic affairs. Justice In summary, we can say that the Islamic Economic system is based upon the notion of justice It is through justice that the existence of the rules governing the economic behavior of the individual and economic institutions in Islam can be understood. Justice in Islam is a multifaceted concept, and there several words exist to define it. The most common word in usage which refers to the overall concept of justice is the Arabic word ?adl?. This word and its many synonyms imply the concepts of ?right?, as equivalent to fairness, ?putting things in their proper place?, ?equality?, ?equalizing?, ?balance?, ?temperance? and ?moderation.? In practice, justice is defined as acting in accordance with the Shariah, which, in turn, contains both substantive and procedural justice[2] covering economic issues. Substantive justice consists of those elements of justice contained in the substance of the Shariah, while procedural justice consists of rules of procedure assuring the attainment of justice contained in the substance of the Law. The notion of economic justice, and its attendant concept of distributive justice, [3] is particularly important as an identifying characteristic of the Islamic economic system. The rules governing permissible and forbidden economic behavior on the part of consumers, producers and government, as well as questions of property rights, and of the production and distribution of wealth, are all based on the Islamic view of justice. The following topics will be discussed in the following articles: (a) individual obligations, rights, and self-interest; (b) property rights; (c) importance of contracts; (d) work and wealth; (e) the concept of barakah; (f) economic justice; (g) prohibition of interest (riba); (h) competition and cooperation; and (i) the role of the state. The Ideological Basis of Economic Activity The ideological basis in Islam may be summarized into six basic principles: The cornerstone is that everything has to start from the belief in God as the Creator, Lord, and Sovereign of the universe. This implies willingness to submit to God?s will, to accept His guidance, and to have complete and unqualified servitude to Him. This means that Muslims - individually and collectively - should not imitate or emulate any other system if it differs from their particular principles, for example, the system of usury or interest. The second basic principle is that Islam, as a religion, is a complete way of life; something that guides a person?s life in all its aspects: the moral, social, ethical, economic, political, etc. All of these aspects are based on the guidance of God. Therefore, it is not a question of the person?s acceptance of God?s teaching in one matter and the refusal of acceptance in another. Everything has to be within that basic guidance. ??And we have revealed to you in stages this book, a clarification of all things, a guidance, a mercy, and glad tidings?? (Quran 16:89) A third principle is that God created human beings on earth as His trustees, which means that everyone is created to fulfill a certain responsibility on this earth. God has entrusted human beings with free will in order that they live their lives according to the moral and ethical values that He Himself provided. In addition, Islam provides an opportunity in material progress, thereby combining moral, social, and material progress, all interlinked in harmony. The fourth principle is that God, in order to help humankind to fulfill the responsibility of trusteeship, has made everything in this universe subservient to them. There are many verses in the Quran that suggest this meaning, such as: ?God is He Who made subservient to you the sea that the ships may run therein by His command, and that you may seek of His grace, and that you may give thanks.? (Quran 45:12) This does not mean, however, that humans are given free reign to use and abuse the resources God has provided us however we choose. Rather, there are many verses that urge humankind to harness the various resources that God has made available to them on this earth responsibly. Humans are encouraged to enjoy of the good things that God has created, but they are to do so within the boundaries that He has given. Doing so is not regarded as sinful as long as it follows His path and does not transgress His limits. God says: ?It is He Who produces gardens, with trellises and without, and dates, and tilth with produce of all kinds, and olives and pomegranates, similar (in kind) and different (in variety): eat of their fruit in their season, but render the dues that are proper on the day that the harvest is gathered. But waste not by excess: for God loves not those who waste.? (Quran 6:141) The fifth principle is the principle of accountability in the Hereafter. God has given human beings trusteeship and resources. This means that every single person will be questioned on the Day of Judgment as to how he or she behaved whilst enjoying his or her earthly life. This, of course, includes our economic behavior. God says: ?And then on that Day (the Day of Resurrection) you will be called to account for every comfort and delight [we bestowed upon you].? (Quran 102:8) The sixth principle is that the variation in wealth among people in itself does not give a person either inferiority or superiority. Rather, poverty and affluence are in the total control of God Who, out of His Infinite Justice and Wisdom, has specified these things for whom he chooses. ?Indeed God increases provision to whom He pleases and straitens it [in regards to others]?? (Quran 13:26) Affluence, like poverty, is also seen as a trial from God, one through which it is seen what one will do with their wealth ? indulge oneself or use constructively in ways legislated in the religion, God says: ?Your wealth and your children are only a trial, whereas God! With Him is a great reward (Paradise).?(Quran 64:15) After being bestowed with numerous gifts and bounties and a kingdom incomparable to any other on the earth, God in the Quran narrates that Solomon said: ??This is from the bounties of my Lord, to test me whether I will be thankful or ungrateful?? (Quran 27:40) God is not concerned with the amount of wealth a person may have amassed, their beauty or color, but rather, His measure of honor is the piety of the hearts. God says: ?On humankind! Indeed We created you from a male and female, and we made you different nations and tribes, that you may come to know one other. Indeed the most honored amongst you are the most God-conscious.? (Quran 49:13) The Prophet also said: ?Indeed God is not concerned with your appearances nor your wealth, but rather your hearts and deeds.? (Saheeh Muslim) As one can immediately surmise from these principles that the Islamic economic system is radically different from others, due to the difference of the values upon which it is based. In a capitalist society, one may see certain rules of economics which take precedence over moral and ethical values due to the intrinsic nature and values of that system. The same may be seen in communist, socialist and other societies as well. From the principles mentioned in these articles does the Islamic system of economics spring, striking balance between personal benefit and the benefit of society as a whole, as well as mundane profits and spiritual gains, all which ensure that one gain the Pleasure of the Lord of the Worlds. [1] The Sunnah is general body of narrations of the speech, deeds, and tacit approvals of the Prophet. [2] ?Substantive justice means reaching the ?right? result. Procedural justice means getting the result in the ?right? way.? (A speech entitled ?Effective Arbitration Techniques in a Global Context? delivered by the Secretary for Justice of Hong Kong ,Ms Elsie Leung) [3] ?Normative principles designed to allocate goods in limited supply relative to demand.? Stanford Encyclopedia of Philosophy: (http://plato.stanford.edu/entries/justice-distributive/) http://www.islamhouse.com/429666/en/en/articles/The_Economic_System_of_Islam Thank you From ndparker at gmail.com Fri Jan 3 15:28:37 2014 From: ndparker at gmail.com (=?UTF-8?B?QW5kcsOp?= Malo) Date: Fri, 03 Jan 2014 21:28:37 +0100 Subject: About some problem References: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> Message-ID: <5838476.4I4dOAImpA@news.perlig.de> * Steven D'Aprano wrote: > Mark Lawrence wrote: > >> raise "Not Valid DB Type" >> >> is perfectly valid in Python 2. > > Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, > string exceptions display a warning but continue to work, and in Python > 2.6 they generate a compile-time SyntaxError. Oh? Doesn't look like it. $ cat x.py try: raise "foo" except: print "bar" $ python2.7 x.py bar $ python2.6 x.py bar A lone '''raise "foo"''' raises a TypeError, though. nd -- sub the($){+shift} sub answer (){ord q [* It is always 42! *] } print the answer # Andr? Malo # http://pub.perlig.de/ # From steve+comp.lang.python at pearwood.info Fri Jan 3 15:38:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jan 2014 07:38:39 +1100 Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? References: Message-ID: <52c71fd0$0$29999$c3e8da3$5496439d@news.astraweb.com> Chris Seberino wrote: > The basics of Scheme or Lisp are amazingly easy to implement. Would > implementing a subset of Python in a Scheme subset be a clever way to > easily implement a lot of Python? I don't know how easy it was, but it was done: http://common-lisp.net/project/clpython/ -- Steven From drsalists at gmail.com Fri Jan 3 15:50:06 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 3 Jan 2014 12:50:06 -0800 Subject: Python 2.x vs 3.x survey Message-ID: The results of the survey are at: https://wiki.python.org/moin/2.x-vs-3.x-survey From steve+comp.lang.python at pearwood.info Fri Jan 3 15:55:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sat, 04 Jan 2014 07:55:24 +1100 Subject: About some problem References: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> <5838476.4I4dOAImpA@news.perlig.de> Message-ID: <52c723bc$0$29982$c3e8da3$5496439d@news.astraweb.com> Andr? Malo wrote: > * Steven D'Aprano wrote: > >> Mark Lawrence wrote: >> >>> raise "Not Valid DB Type" >>> >>> is perfectly valid in Python 2. >> >> Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, >> string exceptions display a warning but continue to work, and in Python >> 2.6 they generate a compile-time SyntaxError. > > Oh? Doesn't look like it. Oh, it's a runtime TypeError, not SyntaxError. I learn something new everyday, thanks for the correction. -- Steven From mhysnm1964 at gmail.com Fri Jan 3 07:38:53 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Fri, 3 Jan 2014 23:38:53 +1100 Subject: Debugging on the Mac question. In-Reply-To: <87bnzt301n.fsf@rudin.co.uk> References: <87bnzt301n.fsf@rudin.co.uk> Message-ID: PETER, thanks Peter, I have already found the PDB module and have had a play with it. It will do for now. On 03/01/2014, at 8:08 PM, Paul Rudin wrote: > Sean Murphy writes: > > >> I am a Vision Impaired programmer on the Mac and Window platforms. I have >> started to learn Python. The biggest road block I have is the ability of >> debugging my simple scripts. The IDLE program does not work with the screen >> readers I use on the Mac or Windows. A screen reader is a program that grabs >> the text on the screen and converts it into speech output, at least this is the >> 50000 feet explanation. I cannot see the screen at all. >> >> I have looked at eclipse and it doesn't work with Voice-Over (the screen reader >> on the Mac). I have java issues on my windows machine preventing me running >> this app. >> >> If I use $python -d script.py the debugger doesn't seem to trigger on the mac. >> >> So how I can perform a debug on a script so I can step through it, set up break >> points, watch variables, etc. >> >> It is really annoying me, since under Perl I just added the -d switch and had a >> full debugger that worked at the console level. > > For command line debugging see > . > > > More generally you might want to investigate > (disclaimer - I have never used > this, but from what you say you might find it useful). > -- > https://mail.python.org/mailman/listinfo/python-list From ethan at stoneleaf.us Fri Jan 3 16:17:53 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 03 Jan 2014 13:17:53 -0800 Subject: About some problem In-Reply-To: <52c723bc$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <52c5fb00$0$29981$c3e8da3$5496439d@news.astraweb.com> <5838476.4I4dOAImpA@news.perlig.de> <52c723bc$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C72901.1090708@stoneleaf.us> On 01/03/2014 12:55 PM, Steven D'Aprano wrote: > Andr? Malo wrote: > >> * Steven D'Aprano wrote: >> >>> Mark Lawrence wrote: >>> >>>> raise "Not Valid DB Type" >>>> >>>> is perfectly valid in Python 2. >>> >>> Actually, no it isn't. It's only valid up to Python 2.4. In Python 2.5, >>> string exceptions display a warning but continue to work, and in Python >>> 2.6 they generate a compile-time SyntaxError. >> >> Oh? Doesn't look like it. > > Oh, it's a runtime TypeError, not SyntaxError. The main point being that in 2.6 and 2.7 string exceptions do /not/ work. -- ~Ethan~ From tjreedy at udel.edu Fri Jan 3 17:00:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 03 Jan 2014 17:00:32 -0500 Subject: Blog "about python 3" In-Reply-To: <52C6AD00.5050000@chamonix.reportlab.co.uk> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: On 1/3/2014 7:28 AM, Robin Becker wrote: > On 03/01/2014 09:01, Terry Reedy wrote: >> There was more speedup in 3.3.2 and possibly even more in 3.3.3, so OP >> should run the latter. > > python 3.3.3 is what I use on windows. As for astral / non-bmp etc etc > that's almost irrelevant for the sort of tests we're doing which are > mostly simple english text. If you do not test the cases where 2.7 is buggy and requires nasty workarounds, then I can understand why you do not so much appreciate 3.3 ;-). -- Terry Jan Reedy From look at signature.invalid Fri Jan 3 19:13:05 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 01:13:05 +0100 Subject: [newbie] Recursive algorithm - review Message-ID: Hi, it's my first post on this newsgroup so welcome everyone. :) I'm still learning Python (v3.3), and today I had idea to design (my first) recursive function, that generates board to 'Towers' Puzzle: http://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/towers.html (so I could in future write algorithm to solve it ;-)) I'm pretty proud of myself - that it works, and that took me only 4 hours to debug. ;-) But on Project Euler site sometimes I'm also proud, that I solved some problem in 30-line script, and then on forum there's one lined solution... So maybe You might look at this script, and tell me if this can be more pythonic. It's nothing urgent. I can wait - it works after all. ;-) Idea is that function "generate()" 'finds' one number at a time (well, besides first row), then checks if there are no repetitions in column (because in row there cannot be by design - I pop out numbers from shuffled list [1, 2, 3, ..., size] for every row.) If no repetition - calls the same function to find next number, and so on. If there is repetition at some point - recursion jumps back, and try different number on previous position. import random def check(towers, x=None): if x: c = x % len(towers) # check only column with column = [] # value added on pos. x for i in range(len(towers)): column.append(towers[i][c]) column = [x for x in column if x != 0] # print(column) # debugging leftovers ;-) return len(column) == len(set(column)) else: for c in range(len(towers)): # 'x' not provided, column = [] # so check all columns for i in range(len(towers)): column.append(towers[i][c]) column = [x for x in column if x != 0] # print(column) if len(column) != len(set(column)): return False return True def generate(size=4, towers=None, row=None, x=0): if not towers: # executed only once. row = [a for a in range(1, size+1)] # Then I'll pass towers list random.shuffle(row) # at every recursion towers = [] # not so pretty way to generate for i in range(size): # matrix filled with 0's towers.append([]) # I tried: towers = [[0]*size]*size for j in range(size): # but this doesn't work. ;-) towers[i].append(0) # I don't know how to do this with # list comprehension (one inside row_ = row[:] # other?) towers[0] = row_ # after adding first row, columns will be row = [] # always unique, so I add entire row at once. x = size - 1 # Then I will be adding only one num at time. # 'x' is pretty much position of last added el. if not row: row = [a for a in range(1, size+1)] random.shuffle(row) if x + 1 < size**2: repeat = True attempt = 0 while repeat: # print(towers, row, x) x += 1 num = row.pop(0) # take num from right, and towers[x // size][x % size] = num # if doesn't match - put repeat = not check(towers, x) # back (append) on left - # - to rotate if repeat: # I'll repeat 'matching' next row.append(num) # number as long as last x -= 1 # changed column is unique attempt += 1 # after some attempts I give if attempt > len(row) - 1: # up and jump back from return False # current recursion else: if not generate(size, towers, row, x): repeat = True row.append(num) # after some failed attempts x -= 1 # on this 'level' I give up attempt += 1 # again... if attempt > len(row) - 1: return False # ...and jump back one # more time... return towers def main(): towers6by6 = generate(6) # print(check(towers6by6)) print(towers6by6) if __name__ == "__main__": main() Footnote: English isn't my native language, so forgive me my bad grammar and/or vocabulary. :-) -- Best regrds, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # spam trap From larry.martell at gmail.com Fri Jan 3 19:15:26 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 3 Jan 2014 19:15:26 -0500 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 1:07 PM, Denis McMahon wrote: > On Fri, 03 Jan 2014 10:41:21 -0500, Larry Martell wrote: > >> The holes would be between the items I put in. In my example above, if I >> assigned to [10] and [20], then the other items ([0..9] and [11..19]) >> would have None. > >>>> dic = { 10:6, 20:11} >>>> dic.get(10) > 6 >>>> dic.get(14) >>>> dic.get(27,"oh god there's nothing here") > "oh god there's nothing here" >>>> dic.get(99,None) >>>> dic.get(168,False) > False >>>> dic.get(20,"Boo Yah") > 11 >>>> > > So a standard dictionary does this returning None (or any other default > value you care to pass it) as long as you use the dict.get(key[,default]) > method rather than dict[key] to return the value. > > See also: > > http://stackoverflow.com/questions/6130768/return-none-if-dictionary-key- > is-not-available Thanks, but I know all that about dicts. I need to use a list for compatibility with existing code. From larry.martell at gmail.com Fri Jan 3 19:18:26 2014 From: larry.martell at gmail.com (Larry Martell) Date: Fri, 3 Jan 2014 19:18:26 -0500 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 11:07 AM, Chris Angelico wrote: > On Sat, Jan 4, 2014 at 2:55 AM, Larry Martell wrote: >> The use case is that I'm parsing a XML file like this: >> >> >> >> >> True >> >> >> >> >> False >> >> >> >> >> True >> False >> >> >> >> True >> >> >> This is an existing program that is putting the data into a dict. The >> dict keys are ['DefaultVersion','Default'] and >> ['DefaultVersion','Current']. These contain lists that have the >> True/False values. > > Are you assigning keys by value, or are you simply appending to the > lists? It looks to me like you could simply append another element to > both lists for each unit, with the given Default and > Current if available, or with None for any that aren't set. > Alternatively, when you get up to the , append None to each > list, and then when you see a value, assign to [-1] and overwrite the > None. Your last suggestion is what I ended up doing, but I had to key off the unit - I couldn't use because that isn't present for ones that have no - that messed me up for hours. But it's working now. Thanks all! From look at signature.invalid Fri Jan 3 19:16:14 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 01:16:14 +0100 Subject: [newbie] Recursive algorithm - review Message-ID: Hi, it's my first post on this newsgroup so welcome everyone. :) I'm still learning Python (v3.3), and today I had idea to design (my first) recursive function, that generates (filled out) board to 'Towers' Puzzle: http://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/towers.html (so I could in future write algorithm to solve it ;-)) I'm pretty proud of myself - that it works, and that took me only 4 hours to debug. ;-) But on Project Euler site sometimes I'm also proud, that I solved some problem in 30-line script, and then on forum there's one lined solution... So maybe You might look at this script, and tell me if this can be more pythonic. It's nothing urgent. I can wait - it works after all. ;-) Idea is that function "generate()" 'finds' one number at a time (well, besides first row), then checks if there are no repetitions in column (because in row there cannot be by design - I pop out numbers from shuffled list [1, 2, 3, ..., size] for every row.) If no repetition - calls the same function to find next number, and so on. If there is repetition at some point - recursion jumps back, and try different number on previous position. import random def check(towers, x=None): if x: c = x % len(towers) # check only column with column = [] # value added on pos. x for i in range(len(towers)): column.append(towers[i][c]) column = [x for x in column if x != 0] # print(column) # debugging leftovers ;-) return len(column) == len(set(column)) else: for c in range(len(towers)): # 'x' not provided, column = [] # so check all columns for i in range(len(towers)): column.append(towers[i][c]) column = [x for x in column if x != 0] # print(column) if len(column) != len(set(column)): return False return True def generate(size=4, towers=None, row=None, x=0): if not towers: # executed only once. row = [a for a in range(1, size+1)] # Then I'll pass towers list random.shuffle(row) # at every recursion towers = [] # not so pretty way to generate for i in range(size): # matrix filled with 0's towers.append([]) # I tried: towers = [[0]*size]*size for j in range(size): # but this doesn't work. ;-) towers[i].append(0) # I don't know how to do this with # list comprehension (one inside row_ = row[:] # other?) towers[0] = row_ # after adding first row, columns will be row = [] # always unique, so I add entire row at once. x = size - 1 # Then I will be adding only one num at time. # 'x' is pretty much position of last added el. if not row: row = [a for a in range(1, size+1)] random.shuffle(row) if x + 1 < size**2: repeat = True attempt = 0 while repeat: # print(towers, row, x) x += 1 num = row.pop(0) # take num from right, and towers[x // size][x % size] = num # if doesn't match - put repeat = not check(towers, x) # back (append) on left - # - to rotate if repeat: # I'll repeat 'matching' next row.append(num) # number as long as last x -= 1 # changed column is unique attempt += 1 # after some attempts I give if attempt > len(row) - 1: # up and jump back from return False # current recursion else: if not generate(size, towers, row, x): repeat = True row.append(num) # after some failed attempts x -= 1 # on this 'level' I give up attempt += 1 # again... if attempt > len(row) - 1: return False # ...and jump back one # more time... return towers def main(): towers6by6 = generate(6) # print(check(towers6by6)) print(towers6by6) if __name__ == "__main__": main() Footnote: English isn't my native language, so forgive me my bad grammar and/or vocabulary. :-) -- Best regrds, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # spam trap From roy at panix.com Fri Jan 3 20:18:06 2014 From: roy at panix.com (Roy Smith) Date: Fri, 03 Jan 2014 20:18:06 -0500 Subject: Creating a list with holes References: Message-ID: In article , Larry Martell wrote: > > Thanks, but I know all that about dicts. I need to use a list for > compatibility with existing code. Generalizing what I think the situation is, "A dict is the best data structure for the parsing phase, but I need a list later to hand off to legacy interfaces". No problem. Parse the data using a dict, then convert the dict to a list later. I haven't been following all the details here, but just wanted to point out that using different data structures to hold the same data at different phases of a program is a perfectly reasonable approach. From rosuav at gmail.com Fri Jan 3 20:24:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 12:24:45 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 11:18 AM, Larry Martell wrote: > Your last suggestion is what I ended up doing, but I had to key off > the unit - I couldn't use because that > isn't present for ones that have no - that messed me up for > hours. But it's working now. Thanks all! Sure, you know your data better than I do after a quick glance. Sounds good! Such a classic problem. "I have this data, I need that structure. How can I turn the one into the other?" So many different answers. ChrisA From tjreedy at udel.edu Fri Jan 3 20:47:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 03 Jan 2014 20:47:16 -0500 Subject: [newbie] Recursive algorithm - review In-Reply-To: References: Message-ID: On 1/3/2014 7:16 PM, Wiktor wrote: > Hi, > it's my first post on this newsgroup so welcome everyone. :) > > I'm still learning Python (v3.3), and today I had idea to design (my first) > recursive function, that generates (filled out) board to 'Towers' Puzzle: > > http://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/towers.html > > (so I could in future write algorithm to solve it ;-)) > > > I'm pretty proud of myself - that it works, and that took me only 4 hours > to debug. ;-) > But on Project Euler site sometimes I'm also proud, that I solved some > problem in 30-line script, and then on forum there's one lined solution... > > So maybe You might look at this script, and tell me if this can be more > pythonic. It's nothing urgent. I can wait - it works after all. ;-) > > > Idea is that function "generate()" 'finds' one number at a time (well, > besides first row), then checks if there are no repetitions in column > (because in row there cannot be by design - I pop out numbers from shuffled > list [1, 2, 3, ..., size] for every row.) > If no repetition - calls the same function to find next number, and so on. > If there is repetition at some point - recursion jumps back, and try > different number on previous position. > > > > import random > > > def check(towers, x=None): > if x: > c = x % len(towers) # check only column with > column = [] # value added on pos. x > for i in range(len(towers)): > column.append(towers[i][c]) > column = [x for x in column if x != 0] > # print(column) # debugging leftovers ;-) > return len(column) == len(set(column)) > else: > for c in range(len(towers)): # 'x' not provided, > column = [] # so check all columns > for i in range(len(towers)): > column.append(towers[i][c]) > column = [x for x in column if x != 0] > # print(column) > if len(column) != len(set(column)): > return False > return True > > > def generate(size=4, towers=None, row=None, x=0): > if not towers: # executed only once. > row = [a for a in range(1, size+1)] # Then I'll pass towers list > random.shuffle(row) # at every recursion > towers = [] > # not so pretty way to generate > for i in range(size): # matrix filled with 0's > towers.append([]) # I tried: towers = [[0]*size]*size > for j in range(size): # but this doesn't work. ;-) > towers[i].append(0) # I don't know how to do this with > # list comprehension (one inside [0]*size] is fine for one row towers = [[0]*size] for i in range(size)] should do what you want for a 2-d array instead of the above. I cannot look at the rest right now. -- Terry Jan Reedy From rosuav at gmail.com Fri Jan 3 21:02:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 13:02:37 +1100 Subject: [newbie] Recursive algorithm - review In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 11:13 AM, Wiktor wrote: > Hi, > it's my first post on this newsgroup so welcome everyone. :) Hi! Welcome! > I'm still learning Python (v3.3), and today I had idea to design (my first) > recursive function, that generates board to 'Towers' Puzzle: > http://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/towers.html > (so I could in future write algorithm to solve it ;-)) Yep, that's the way to do things. When I wrote some code for a sort of "binary sudoku" system (they're a lot of fun, btw), I went through this sequence: 0) Figure out a data structure to hold a board state 1) Write code that will ascertain whether a given board state is valid 2) Write code that will deduce more information from a given board state 3) Write code that will completely solve a board 4) Write code that can "solve" an empty board, thus generating a puzzle. > But on Project Euler site sometimes I'm also proud, that I solved some > problem in 30-line script, and then on forum there's one lined solution... That's not a problem in itself. In fact, in many situations the 30-liner is better. But mainly, once you get a working-but-slightly-verbose script, it's fairly straight-forward to simplify it a little bit at a time. > def check(towers, x=None): > column = [] # value added on pos. x > for i in range(len(towers)): > column.append(towers[i][c]) > column = [x for x in column if x != 0] Any time you iterate over range(len(something)), you probably want to iterate over the thing instead: for t in towers: column.append(t[c]) And any time you iterate over something and append to another list, you probably want a list comprehension: column = [t[c] for t in towers] And two comprehensions can usually be combined into one: column = [t[c] for t in towers if t[c] != 0] That has a little bit of redundancy in there (mentioning t[c] twice), but I think it's cleaner than having the separate pass. Finally, since you're working here with integers, you can drop the "!= 0" check and simply test the truthiness of t[c] itself: column = [t[c] for t in towers if t[c]] > for c in range(len(towers)): # 'x' not provided, > column = [] # so check all columns I wouldn't normally wrap a comment onto an unrelated line; I'd put the comment above the loop, since it's too long to be a part of the loop header itself. It goes as much with the "else" as with the loop, anyhow. This is one case where you probably _do_ want to iterate up to range(len(towers)), though, which is why I said "probably" above. :) > for i in range(len(towers)): > column.append(towers[i][c]) > column = [x for x in column if x != 0] This is the same code you had above, so it can benefit from the same translation. But maybe it'd be even cleaner to simply call yourself? if not check(towers, i): return False > # print(column) > if len(column) != len(set(column)): > return False > return True And in fact, you might want to turn this whole branch into something that harks to a more functional programming style: return all((check(towers, i) for i in range(len(towers))) But that's a stylistic choice. > def generate(size=4, towers=None, row=None, x=0): > if not towers: # executed only once. > row = [a for a in range(1, size+1)] # Then I'll pass towers list row = list(range(1, size+1)) > random.shuffle(row) # at every recursion Again, I wouldn't wrap comments onto unrelated lines. You see how confusing this looks, now that I take this line out of context? Same will happen if it throws an exception. > towers = [] > # not so pretty way to generate > for i in range(size): # matrix filled with 0's > towers.append([]) # I tried: towers = [[0]*size]*size > for j in range(size): # but this doesn't work. ;-) > towers[i].append(0) # I don't know how to do this with > # list comprehension (one inside > row_ = row[:] # other?) > towers[0] = row_ # after adding first row, columns will be > row = [] # always unique, so I add entire row at once. > x = size - 1 # Then I will be adding only one num at time. > # 'x' is pretty much position of last added el. When you multiply a list of lists, you get references to the same list, yes. But you could use multiplication for one level: towers = [[0]*size for _ in range(size)] That'll give you independent lists. I'm not wholly sure what the rest of your code is trying to do here, so I can't comment on it. > if not row: > row = [a for a in range(1, size+1)] > random.shuffle(row) This is the same as you have at the top of 'if not towers'. Can you be confident that row is None any time towers is None? If so, just move this up above the other check and save the duplication. > num = row.pop(0) # take num from right, and > towers[x // size][x % size] = num # if doesn't match - put > repeat = not check(towers, x) # back (append) on left - > # - to rotate > if repeat: # I'll repeat 'matching' next > row.append(num) # number as long as last > x -= 1 # changed column is unique Hmm, I'm slightly confused by your comments here. You pop(0) and append(), and describe that as taking from the right and putting on the left. Normally I'd write a list like this: >>> a [20, 30, 40] And then pop(0) takes the zeroth element: >>> a.pop(0) 20 And append() puts that back on at the end: >>> a.append(_) >>> a [30, 40, 20] So I would describe that as taking from the left and putting on the right. > Footnote: English isn't my native language, so forgive me my bad grammar > and/or vocabulary. :-) Your English looks fine. Usually, people who apologize for their non-native English are far more competent with the language than those whose English is native and sloppy :) In fact, the effort required to learn a second language almost certainly means that you're both better with English and better with Python than you would otherwise be. ChrisA From denismfmcmahon at gmail.com Fri Jan 3 21:03:13 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 4 Jan 2014 02:03:13 +0000 (UTC) Subject: Creating a list with holes References: Message-ID: On Fri, 03 Jan 2014 20:18:06 -0500, Roy Smith wrote: > In article , > Larry Martell wrote: > > >> Thanks, but I know all that about dicts. I need to use a list for >> compatibility with existing code. > > Generalizing what I think the situation is, "A dict is the best data > structure for the parsing phase, but I need a list later to hand off to > legacy interfaces". > > No problem. Parse the data using a dict, then convert the dict to a > list later. I haven't been following all the details here, but just > wanted to point out that using different data structures to hold the > same data at different phases of a program is a perfectly reasonable > approach. Indeed, assuming the requirement is to have a list of some length n units representing integer keys into a range of values from start to end, and he creates a dict initially: list = [ dict.get(x,None) for x in range(start,end + 1) ] Examples: >>> dic = {1:"fred", 9:"jim", 15:"susan", 25:"albert" } >>> l = [ dic.get(x,None) for x in range(1,20) ] >>> l ['fred', None, None, None, None, None, None, None, 'jim', None, None, None, None, None, 'susan', None, None, None, None] >>> l = [ dic.get(x,None) for x in range(-10,50) ] >>> l [None, None, None, None, None, None, None, None, None, None, None, 'fred', None, None, None, None, None, None, None, 'jim', None, None, None, None, None, 'susan', None, None, None, None, None, None, None, None, None, 'albert', None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None] >>> len(l) 60 then the value of l[offset] will either be None or some string depending on the offset into the list -- Denis McMahon, denismfmcmahon at gmail.com From li.beinan at gmail.com Fri Jan 3 21:44:01 2014 From: li.beinan at gmail.com (Beinan Li) Date: Fri, 3 Jan 2014 21:44:01 -0500 Subject: How to make a tkinter GUI work on top of a CUI program? Message-ID: I know how to make a GUI program work on top of a console program like "ls", which exits immediately. But some console programs have their own shell or ncurse-like CUI, such as cscope. So I figured that I need to first subprocess.popen a bidirectional pipe and send command through stdin and get results from stdout and stderr. But in such a case I found that communicate('cmd') will freeze. Am I in the right direction? Here is my code, in which the application connects to cscope through pipe, the GUI has only one button that tries to invoke a cscope search command and get the result, the Enter key is represented as \n in the stdin argument of communicate(): import sys, os, os.path, subprocess, shlex if sys.version_info.major < 3: import Tkinter as Tk else: import tkinter as Tk class MyGUI(object): ''' Frontend of the main command-line module. ''' def __init__(self): self.subProc = None self.root = Tk.Tk() self.frame = Tk.Frame(self.root) self.btn = Tk.Button(self.frame, text='My Command') self.btn.pack() self.btn.bind('', self.OnClickBtn) def MainLoop(self): os.chdir('path/to/myfolder') cmd = shlex.split('/usr/local/bin/cscope -d') self.subProc = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) self.root.mainloop() def OnClickBtn(self, event): print('OnClickBtn') (stdOut, stdErr) = self.subProc.communicate('symbolName\n') print(stdOut) if __name__ == '__main__': gui = MyGUI() gui.MainLoop() -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Fri Jan 3 21:55:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 13:55:15 +1100 Subject: How to make a tkinter GUI work on top of a CUI program? In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 1:44 PM, Beinan Li wrote: > But some console programs have their own shell or ncurse-like CUI, such as > cscope. > So I figured that I need to first subprocess.popen a bidirectional pipe and > send command through stdin and get results from stdout and stderr. > > But in such a case I found that communicate('cmd') will freeze. You can't use communicate(), as it'll wait for the process to end. But there are several quite different types of console UI, some of which you'll be able to use and some you won't: 1) There's the simple, straight-forward writing to stdout/stderr. Maybe it's a long-running 'make' or the burning of a DVD, but whatever it does, it takes no input and writes to the standard streams. Easy to work with - just read and handle incoming text. 2) There are interactive shell-type systems. You'll need to send them more than just lines of text, probably, as you might need to send command keys and such. But still fairly workable. 3) Then there's stuff that doesn't actually use the standard streams at all, or uses them and uses something else as well. You can pipe something into 'less', but it'll still look for actual keyboard input for its control. You'll have a lot more trouble manipulating those programs. Something that uses ncurses is most likely to land in box 3. ChrisA From drsalists at gmail.com Fri Jan 3 21:58:21 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 3 Jan 2014 18:58:21 -0800 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 7:37 AM, Chris Angelico wrote: > Depending on what exactly you need, it's probably worth just using a > dict. In what ways do you need it to function as a list? You can > always iterate over sorted(some_dict.keys()) if you need to run > through them in order. FWIW, sorting inside a loop is rarely a good idea, unless your lists are pretty small. For that, there are many tree datastructures available. From rosuav at gmail.com Fri Jan 3 22:00:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 14:00:12 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 1:58 PM, Dan Stromberg wrote: > On Fri, Jan 3, 2014 at 7:37 AM, Chris Angelico wrote: >> Depending on what exactly you need, it's probably worth just using a >> dict. In what ways do you need it to function as a list? You can >> always iterate over sorted(some_dict.keys()) if you need to run >> through them in order. > > FWIW, sorting inside a loop is rarely a good idea, unless your lists > are pretty small. What do you mean by "sorting inside a loop"? I was thinking of this: for key in sorted(some_dict.keys()): # blah blah which will sort once and then iterate over it. ChrisA From drsalists at gmail.com Fri Jan 3 22:32:13 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 3 Jan 2014 19:32:13 -0800 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 7:00 PM, Chris Angelico wrote: > On Sat, Jan 4, 2014 at 1:58 PM, Dan Stromberg wrote: >> On Fri, Jan 3, 2014 at 7:37 AM, Chris Angelico wrote: >>> Depending on what exactly you need, it's probably worth just using a >>> dict. In what ways do you need it to function as a list? You can >>> always iterate over sorted(some_dict.keys()) if you need to run >>> through them in order. >> >> FWIW, sorting inside a loop is rarely a good idea, unless your lists >> are pretty small. > > What do you mean by "sorting inside a loop"? I was thinking of this: > > for key in sorted(some_dict.keys()): > # blah blah > > which will sort once and then iterate over it. That is fine, sorting once at then end of a script is a good use of sorted(some_dict.keys()). However, it probably should be pointed out that this, while similar, is not so good: for thing in range(n): for key in sorted(some_dict.keys()): do_something(thing, key) ...because it's sorting n times. From rosuav at gmail.com Fri Jan 3 22:38:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 14:38:56 +1100 Subject: Creating a list with holes In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 2:32 PM, Dan Stromberg wrote: > That is fine, sorting once at then end of a script is a good use of > sorted(some_dict.keys()). However, it probably should be pointed out > that this, while similar, is not so good: > > for thing in range(n): > for key in sorted(some_dict.keys()): > do_something(thing, key) > > ...because it's sorting n times. Oh! Yeah. Yeah, that would be inefficient. ChrisA From breamoreboy at yahoo.co.uk Fri Jan 3 23:04:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Jan 2014 04:04:39 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: On 03/01/2014 22:00, Terry Reedy wrote: > On 1/3/2014 7:28 AM, Robin Becker wrote: >> On 03/01/2014 09:01, Terry Reedy wrote: >>> There was more speedup in 3.3.2 and possibly even more in 3.3.3, so OP >>> should run the latter. >> >> python 3.3.3 is what I use on windows. As for astral / non-bmp etc etc >> that's almost irrelevant for the sort of tests we're doing which are >> mostly simple english text. > > If you do not test the cases where 2.7 is buggy and requires nasty > workarounds, then I can understand why you do not so much appreciate 3.3 > ;-). > Are you crazy? Surely everybody prefers fast but incorrect code in preference to something that is correct but slow? Except that Python 3.3.3 is often faster. And always (to my knowledge) correct. Upper Class Twit of the Year anybody? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From alec.taylor6 at gmail.com Fri Jan 3 23:24:19 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 4 Jan 2014 15:24:19 +1100 Subject: Suggest an open-source log analyser? In-Reply-To: <2F5C38F8-EC06-453F-8461-A0FF72519170@mac.com> References: <2F5C38F8-EC06-453F-8461-A0FF72519170@mac.com> Message-ID: Web interface (and/or SQL-like query interface); is useful for drilling down and rolling up multiparametric analyses. Currently looking at logstash, kibana, graylog2 and a few others. Might end up writing my own to escape the Java dependency. Would welcome further suggestions. On Fri, Jan 3, 2014 at 1:13 AM, William Ray Wing wrote: > On Jan 2, 2014, at 12:40 AM, Alec Taylor wrote: > >> I use the Python logger class; with the example syntax of: >> Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') >> >> Can of course easily use e.g.: a JSON syntax here instead. >> >> Are there any open-source log viewers (e.g.: with a web-interface) >> that you'd recommend; for drilling down into my logs? >> >> Thanks for your suggestions, >> >> Alec Taylor >> -- >> https://mail.python.org/mailman/listinfo/python-list > > Why web interface? That's a ton of overhead just to look at a text file. > If you are on UNIX or Linux, I'd just use my favorite editor (or possibly View, which is vi in read-only mode, or More or Less). > If you give them the extension .log you can use whatever app you use to look at console logs. > > -Bill From alec.taylor6 at gmail.com Fri Jan 3 23:26:41 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sat, 4 Jan 2014 15:26:41 +1100 Subject: Highest performance HTTP REST microframework? Message-ID: What is the highest performance REST microframework? Happy if it's mostly written in C or C++; as long as it provides a simple routes interface in Python. Currently using bottle and utilising its application, @route and app.merge(app2) extra features. From mhysnq1964 at icloud.com Fri Jan 3 23:03:35 2014 From: mhysnq1964 at icloud.com (Sean Murphy) Date: Sat, 04 Jan 2014 15:03:35 +1100 Subject: Strange behaviour with a for loop. Message-ID: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> Hello all. This is a newly question. But I wish to understand why the below code is providing different results. import os, sys if len(sys.argv) > 2: filenames = sys.argv[1:] else print ("no parameters provided\n") sys.edit() for filename in filenames: print ("filename is: %s\n" %filename) The above code will return results like: filename is test.txt If I modify the above script slightly as shown below, I get a completely different result. if len(sys.argv) > 2: filenames = sys.argv[1] else print ("no parameters provided\n") sys.exit() for filename in filenames: print ("filename is: %s\n" % filename) The result is the filename is spelled out a character at a time. The bit I am missing is something to do with splicing or referencing in Python. Why am I getting different results? In other languages I would have got the whole content of the element when using the index of the array (list). Sean filename is: t filename From larry.martell at gmail.com Sat Jan 4 00:09:58 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sat, 4 Jan 2014 00:09:58 -0500 Subject: Strange behaviour with a for loop. In-Reply-To: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> Message-ID: On Fri, Jan 3, 2014 at 11:03 PM, Sean Murphy wrote: > Hello all. > > This is a newly question. But I wish to understand why the below code is providing different results. > > import os, sys > > > if len(sys.argv) > 2: > filenames = sys.argv[1:] > else > print ("no parameters provided\n") > sys.edit() > > for filename in filenames: > print ("filename is: %s\n" %filename) > > The above code will return results like: > > filename is test.txt > > If I modify the above script slightly as shown below, I get a completely different result. > > if len(sys.argv) > 2: > filenames = sys.argv[1] > else > print ("no parameters provided\n") > sys.exit() > > for filename in filenames: > print ("filename is: %s\n" % filename) > > The result is the filename is spelled out a character at a time. The bit I am missing is something to do with splicing or referencing in Python. > > Why am I getting different results? In other languages I would have got the whole content of the element when using the index of the array (list). > > > Sean > filename is: t > filename argv[1] gives just the second item in the list argv[1:] gives a list containing the items in the list, from the second to the end >>> x = ['foo', 'bar', 'baz'] >>> print x[1] bar >>> print x[1:] ['bar', 'baz'] From rosuav at gmail.com Sat Jan 4 00:18:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 16:18:55 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> Message-ID: On Sat, Jan 4, 2014 at 3:03 PM, Sean Murphy wrote: > filenames = sys.argv[1:] > > for filename in filenames: > print ("filename is: %s\n" %filename) versus > filenames = sys.argv[1] > > for filename in filenames: > print ("filename is: %s\n" % filename) The first one is slicing sys.argv, so it returns another list. For instance, sys.argv might be: ['foo.py', 'test', 'zxcv'] in which case sys.argv[1:] would be: ['test', 'zxcv'] which is still a list. But sys.argv[1] is a single string: 'test' Now, when you use that in a for loop, you iterate over it. Iterating over a list yields its items, as you'd expect. Iterating over a string yields its characters. That's why you see it spelled out. Instead of iterating over a list of file names, you're iterating over a single file name, which isn't (in this case) all that useful. Does that explain what you're seeing? ChrisA From rosuav at gmail.com Sat Jan 4 00:35:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 16:35:14 +1100 Subject: Highest performance HTTP REST microframework? In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 3:26 PM, Alec Taylor wrote: > What is the highest performance REST microframework? > > Happy if it's mostly written in C or C++; as long as it provides a > simple routes interface in Python. > > Currently using bottle and utilising its application, @route and > app.merge(app2) extra features. What do you mean by performance? Most of the time is going to be spent waiting for the network. Are you looking for maximum concurrent requests handled? Minimum latency/overhead? Something else? ChrisA From breamoreboy at yahoo.co.uk Sat Jan 4 00:38:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Jan 2014 05:38:20 +0000 Subject: Strange behaviour with a for loop. In-Reply-To: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> Message-ID: On 04/01/2014 04:03, Sean Murphy wrote: > Hello all. > > This is a newly question. But I wish to understand why the below code is providing different results. > > import os, sys > > > if len(sys.argv) > 2: > filenames = sys.argv[1:] > else > print ("no parameters provided\n") > sys.edit() > > for filename in filenames: > print ("filename is: %s\n" %filename) > > The above code will return results like: > > filename is test.txt > > If I modify the above script slightly as shown below, I get a completely different result. > > if len(sys.argv) > 2: > filenames = sys.argv[1] > else > print ("no parameters provided\n") > sys.exit() > > for filename in filenames: > print ("filename is: %s\n" % filename) > > The result is the filename is spelled out a character at a time. The bit I am missing is something to do with splicing or referencing in Python. > > Why am I getting different results? In other languages I would have got the whole content of the element when using the index of the array (list). > > > Sean > filename is: t > filename > As you've already had answers I'd like to point out that your test for len(sys.argv) is wrong, else is missing a colon and sys.edit() is very unlikely to work :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From malaclypse2 at gmail.com Sat Jan 4 01:35:26 2014 From: malaclypse2 at gmail.com (Jerry Hill) Date: Sat, 4 Jan 2014 01:35:26 -0500 Subject: How to make a tkinter GUI work on top of a CUI program? In-Reply-To: References: Message-ID: On Fri, Jan 3, 2014 at 9:44 PM, Beinan Li wrote: > But some console programs have their own shell or ncurse-like CUI, such as > cscope. > So I figured that I need to first subprocess.popen a bidirectional pipe and > send command through stdin and get results from stdout and stderr. > > But in such a case I found that communicate('cmd') will freeze. Right. communicate() waits for the subprocess to end, and the subprocess is still waiting for you to do something. Instead, you'll need to read() and write() to the subprocess' stdin and stdout attributes, probably something like this (untested): def OnClickBtn(self, event): print('OnClickBtn') self.subProc.stdin.write('symbolName\n') print(self.subProc.stdout.read()) It looks like cscope has both a screen-oriented mode and a line-based mode. When you're working with a subprocess like this, you're going to want to be in the line-based mode, so you'll probably want to add -l or -L to your command line. -- Jerry From walterhurry at lavabit.com Sat Jan 4 01:35:27 2014 From: walterhurry at lavabit.com (Walter Hurry) Date: Sat, 4 Jan 2014 06:35:27 +0000 (UTC) Subject: Suggest an open-source log analyser? References: Message-ID: On Thu, 02 Jan 2014 16:40:19 +1100, Alec Taylor wrote: > I use the Python logger class; with the example syntax of: > Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') > > Can of course easily use e.g.: a JSON syntax here instead. > > Are there any open-source log viewers (e.g.: with a web-interface) > that you'd recommend; for drilling down into my logs? > If you want to do in-depth analysis, why not just stick it into an SQL database; e.g. SQLite or Postgres? From frank at chagford.com Sat Jan 4 02:00:22 2014 From: frank at chagford.com (Frank Millman) Date: Sat, 4 Jan 2014 09:00:22 +0200 Subject: Creating a list with holes References: Message-ID: "Larry Martell" wrote in message news:CACwCsY5P47-dB1NLQTUTQ=0aF6B+-M3y4hCxcUGmcVmHM8=-xQ at mail.gmail.com... >I think I know the answer is no, but is there any package that allows > creating a list with holes in it? E.g. I'd want to do something like: > > x[10] = 12 > x[20] = 30 > > I'm thinking of something like defaultdict but for lists (I know > that's very different, but ... ) > > Thanks! > -larry Just out of interest, I asked the same question on this list many years ago, and someone actually gave me an answer. It was something like the following - >>> class MyList(list): ... def __getitem__(self, pos): ... try: ... return list.__getitem__(self, pos) ... except IndexError: ... return None ... def __setitem__(self, pos, value): ... try: ... list.__setitem__(self, pos, value) ... except IndexError: ... diff = pos - list.__len__(self) ... self.extend([None] * diff) ... self.append(value) ... >>> ml = MyList() >>> ml[3] >>> ml[3] = 'a' >>> ml [None, None, None, 'a'] >>> I wanted it because I was familiar with it from a previous language I had used. As is turns out, I never actually used it, but I was impressed! Frank Millman From breamoreboy at yahoo.co.uk Sat Jan 4 02:30:55 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Jan 2014 07:30:55 +0000 Subject: Blog "about python 3" In-Reply-To: <52C5A3BA.5080700@chamonix.reportlab.co.uk> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: On 02/01/2014 17:36, Robin Becker wrote: > On 31/12/2013 15:41, Roy Smith wrote: >> I'm using 2.7 in production. I realize that at some point we'll need to >> upgrade to 3.x. We'll keep putting that off as long as the "effort + >> dependencies + risk" metric exceeds the "perceived added value" metric. >> > We too are using python 2.4 - 2.7 in production. Different clients > migrate at different speeds. > >> >> To be honest, the "perceived added value" in 3.x is pretty low for us. >> What we're running now works. Switching to 3.x isn't going to increase >> our monthly average users, or our retention rate, or decrease our COGS, >> or increase our revenue. There's no killer features we need. In >> summary, the decision to migrate will be driven more by risk aversion, >> when the risk of staying on an obsolete, unsupported platform, exceeds >> the risk of moving to a new one. Or, there will be some third-party >> module that we must have which is no longer supported on 2.x. >> > > +1 > >> If I were starting a new project today, I would probably start it in 3.x. > +1 > > I just spent a large amount of effort porting reportlab to a version > which works with both python2.7 and python3.3. I have a large number of > functions etc which handle the conversions that differ between the two > pythons. > > For fairly sensible reasons we changed the internal default to use > unicode rather than bytes. After doing all that and making the tests > compatible etc etc I have a version which runs in both and passes all > its tests. However, for whatever reason the python 3.3 version runs slower > > 2.7 Ran 223 tests in 66.578s > > 3.3 Ran 223 tests in 75.703s > > I know some of these tests are fairly variable, but even for simple > things like paragraph parsing 3.3 seems to be slower. Since both use > unicode internally it can't be that can it, or is python 2.7's unicode > faster? > > So far the superiority of 3.3 escapes me, but I'm tasked with enjoying > this process so I'm sure there must be some new 'feature' that will > help. Perhaps 'yield from' or 'raise from None' or ....... > > In any case I think we will be maintaining python 2.x code for at least > another 5 years; the version gap is then a real hindrance. Of interest https://mail.python.org/pipermail/python-dev/2012-October/121919.html ? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mhysnm1964 at gmail.com Sat Jan 4 00:54:42 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Sat, 4 Jan 2014 16:54:42 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> Message-ID: <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> Thanks everyone. Mark thanks for the correction on the ':'. Since I didn't cut and copy, rather typed it out. Errors crept in. :-) another question in relation to slicing strings. If you want to get a single character, just using the index position will get it. If I use the following, shouldn't it also work? when I use Python 3.3, it didn't provide anything. a = "test.txt" print a[3] result is: 't print a[3:1] Nothing is printed. print a[3:2] Nothing is printed. print a[3:-1] t.tx is printed. Why doesn't the positive number of characters to be splice return anything while the negative value does? sorry about these basic questions. I do like the splice feature within Python. Also what is the best method of testing for a blank string? end of paragraph line 1 new paragraph of line 1. The above example text is what I want to test for. I am planning to either load the whole file in as a single chunk of memory using fp.read() or store it into an array by using fp.readlines(). The first option I see being useful because you can create a regular expression to test for multiple '\n'. While in an array (list) I would have to test for a blank line which I assume would be "". Any suggestions on this would be welcomed. Sean print a[ On 04/01/2014, at 4:38 PM, Mark Lawrence wrote: > On 04/01/2014 04:03, Sean Murphy wrote: >> Hello all. >> >> This is a newly question. But I wish to understand why the below code is providing different results. >> >> import os, sys >> >> >> if len(sys.argv) > 2: >> filenames = sys.argv[1:] >> else >> print ("no parameters provided\n") >> sys.edit() >> >> for filename in filenames: >> print ("filename is: %s\n" %filename) >> >> The above code will return results like: >> >> filename is test.txt >> >> If I modify the above script slightly as shown below, I get a completely different result. >> >> if len(sys.argv) > 2: >> filenames = sys.argv[1] >> else >> print ("no parameters provided\n") >> sys.exit() >> >> for filename in filenames: >> print ("filename is: %s\n" % filename) >> >> The result is the filename is spelled out a character at a time. The bit I am missing is something to do with splicing or referencing in Python. >> >> Why am I getting different results? In other languages I would have got the whole content of the element when using the index of the array (list). >> >> >> Sean >> filename is: t >> filename >> > > As you've already had answers I'd like to point out that your test for len(sys.argv) is wrong, else is missing a colon and sys.edit() is very unlikely to work :) > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list From mhysnm1964 at gmail.com Sat Jan 4 01:32:44 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Sat, 4 Jan 2014 17:32:44 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> Message-ID: <30ADAFAF-4708-4580-9F8A-641D269864B5@gmail.com> Hi everyone. Worked out what I was doing wrong with the string splicing. The offset number was lower then the index number, so it was failing. E.G: On 04/01/2014, at 4:54 PM, Sean Murphy wrote: > Thanks everyone. > > Mark thanks for the correction on the ':'. Since I didn't cut and copy, rather typed it out. Errors crept in. :-) > > another question in relation to slicing strings. If you want to get a single character, just using the index position will get it. If I use the following, shouldn't it also work? when I use Python 3.3, it didn't provide anything. > > a = "test.txt" > print a[3] > print a[4:1] <--- index is 4 and offset is one. This is invalid. So I suspect the offset number still starts at the beginning of the string and counts forward or another way to look at it you are slicing from element x to element y. If element y is less then element x, return nothing. Does this make sense? I should have used: print a[4:6]) to get: t.t The 2nd part of my original question still stands. I will expand upon this a bit more to give more context. I want to print from the beginning of the paragraph to the end. Each paragraph ends with "\n\n\n". If I use "\n\n\n" in lines this does return true for the string. But I don't have a starting position and ending position. The list method which I mention before can be sliced by going back one element. Any suggestion on this would be welcomed. I want to achieve this using standard core python objects/methods. Sean > result is: > > 't > > > print a[3:1] > > Nothing is printed. > > print a[3:2] > > > Nothing is printed. > > print a[3:-1] > > t.tx is printed. > > > Why doesn't the positive number of characters to be splice return anything while the negative value does? > > sorry about these basic questions. I do like the splice feature within Python. Also what is the best method of testing for a blank string? > > end of paragraph line 1 > > > new paragraph of line 1. > > > The above example text is what I want to test for. I am planning to either load the whole file in as a single chunk of memory using fp.read() or store it into an array by using fp.readlines(). The first option I see being useful because you can create a regular expression to test for multiple '\n'. While in an array (list) I would have to test for a blank line which I assume would be "". > > Any suggestions on this would be welcomed. > > Sean > > > > print a[ > > On 04/01/2014, at 4:38 PM, Mark Lawrence wrote: > >> On 04/01/2014 04:03, Sean Murphy wrote: >>> Hello all. >>> >>> This is a newly question. But I wish to understand why the below code is providing different results. >>> >>> import os, sys >>> >>> >>> if len(sys.argv) > 2: >>> filenames = sys.argv[1:] >>> else >>> print ("no parameters provided\n") >>> sys.edit() >>> >>> for filename in filenames: >>> print ("filename is: %s\n" %filename) >>> >>> The above code will return results like: >>> >>> filename is test.txt >>> >>> If I modify the above script slightly as shown below, I get a completely different result. >>> >>> if len(sys.argv) > 2: >>> filenames = sys.argv[1] >>> else >>> print ("no parameters provided\n") >>> sys.exit() >>> >>> for filename in filenames: >>> print ("filename is: %s\n" % filename) >>> >>> The result is the filename is spelled out a character at a time. The bit I am missing is something to do with splicing or referencing in Python. >>> >>> Why am I getting different results? In other languages I would have got the whole content of the element when using the index of the array (list). >>> >>> >>> Sean >>> filename is: t >>> filename >>> >> >> As you've already had answers I'd like to point out that your test for len(sys.argv) is wrong, else is missing a colon and sys.edit() is very unlikely to work :) >> >> -- >> My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. >> >> Mark Lawrence >> >> -- >> https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sat Jan 4 02:39:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 18:39:32 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: <30ADAFAF-4708-4580-9F8A-641D269864B5@gmail.com> References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> <30ADAFAF-4708-4580-9F8A-641D269864B5@gmail.com> Message-ID: On Sat, Jan 4, 2014 at 5:32 PM, Sean Murphy wrote: > So I suspect the offset number still starts at the beginning of the string and counts forward or another way to look at it you are slicing from element x to element y. If element y is less then element x, return nothing. Does this make sense? > > I should have used: > > print a[4:6]) > > to get: > > t.t Yep, it's start and end indices, not start and length. When you use a negative number, it counts from the back: >>> "asdf"[-1] 'f' >>> "asdf"[-2] 'd' > The 2nd part of my original question still stands. I will expand upon this a bit more to give more context. I want to print from the beginning of the paragraph to the end. Each paragraph ends with "\n\n\n". > > If I use "\n\n\n" in lines this does return true for the string. But I don't have a starting position and ending position. The list method which I mention before can be sliced by going back one element. The "in" operator just tells you whether it's there or not; strings have a .index() method that tells you where something can be found. That might be what you want here! ChrisA From cs at zip.com.au Sat Jan 4 02:52:54 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 4 Jan 2014 18:52:54 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> References: <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> Message-ID: <20140104075254.GA38712@cskk.homeip.net> On 04Jan2014 16:54, Sean Murphy wrote: > Thanks everyone. > > Mark thanks for the correction on the ':'. Since I didn't cut and copy, rather typed it out. Errors crept in. :-) > > another question in relation to slicing strings. If you want to get a single character, just using the index position will get it. If I use the following, shouldn't it also work? when I use Python 3.3, it didn't provide anything. > > a = "test.txt" > print a[3] > result is: > > 't As expected, yes? > print a[3:1] > Nothing is printed. > > print a[3:2] > Nothing is printed. These are not requests for 1 and 2 character strings. They are requests for the character in the span from, respectively, 3 to 1 and from 3 to 2. Important: counting FORWARDS. So: zero length strings. > print a[3:-1] > t.tx is printed. > > Why doesn't the positive number of characters to be splice return anything while the negative value does? -1 is shorthand for len(a)-1 It is often convenient to refer to a position from the end of the array instead of the start. So this means: [3:7], so positions 3,4,5,6. > sorry about these basic questions. I do like the splice feature within Python. Also what is the best method of testing for a blank string? Well, and empty string: a == '' or len(a) == 0. And, because an "if" tests the nonzeroness of a single argument and an empty string has length zero, you can also go: if a: print "long string", a else: print "empty string" OTOH, if you mean a "blank string" to mean "containing only whitespace", you can use the string method "isspace", which tests that all characters are whitespace and that the string is not empty. The doco for isspace() actually says: Return true if there are only whitespace characters in the string and there is at least one character, false otherwise. So you might write: if not a or a.isspace(): print "blank string:", repr(a) Really you'd want to put that it a (trivial) function: def isblank(s): ''' Test that the string `s` is entirely blank. ''' return not s or s.isspace() That way you can write isblank() all through your program and control the precise meaning by modifying the function. Cheers, -- The perl5 internals are a complete mess. It's like Jenga - to get the perl5 tower taller and do something new you select a block somewhere in the middle, with trepidation pull it out slowly, and then carefully balance it somewhere new, hoping the whole edifice won't collapse as a result. - Nicholas Clark, restating an insight of Simon Cozens From cseberino at gmail.com Sat Jan 4 01:48:28 2014 From: cseberino at gmail.com (Chris Seberino) Date: Fri, 3 Jan 2014 22:48:28 -0800 (PST) Subject: Is Python really "Lisp without parentheses"? So would it be easy to *implement* a lot of Python in Scheme/Lisp? In-Reply-To: References: <4d0281ee-2b28-484b-943d-666ea40800df@googlegroups.com> Message-ID: <58c2b080-cc39-4c10-b407-e5c9124ad814@googlegroups.com> Thanks.. I think your 10% Python idea is the way to go. And you are right that most of Python is not needed in an intro course. From eneskristo at gmail.com Sat Jan 4 04:45:25 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Sat, 4 Jan 2014 01:45:25 -0800 (PST) Subject: On a scrollbar for tkinter In-Reply-To: References: <4e8eb7ab-4df0-4d89-ad92-617bd376d85b@googlegroups.com> <3a771930-0b4f-4ac8-87f6-89d72625b09e@googlegroups.com> Message-ID: On Friday, January 3, 2014 12:00:05 PM UTC+1, Vlastimil Brom wrote: > 2014/1/3 : > > > @Rick > > > I found some solutions for python 2.x, but still, as I am with the future, I need a futuristic solution or 2, so if anyone else could help me, I'd be grateful! > > > -- > > > > Hi, > > I usually don't use tkinter myself, hence others may have more > > idiomatic suggestions, > > but you can of course use ScrolledWindow tix with python3; cf.: > > > > from tkinter import tix > > > > root = tix.Tk() > > root.title("scrolled window") > > root.geometry("50x500+50+50") > > sw= tix.ScrolledWindow(root) > > sw.pack(fill=tix.BOTH, expand=1) > > for i in range(1,101): > > cb = tix.Checkbutton(sw.window, text=str(i)) > > cb.pack(fill=tix.BOTH, expand=0) > > root.mainloop() > > > > hth, > > vbr Thank you sir! It really helped! From mhysnm1964 at gmail.com Sat Jan 4 04:52:01 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Sat, 4 Jan 2014 20:52:01 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: <20140104075254.GA38712@cskk.homeip.net> References: <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> <20140104075254.GA38712@cskk.homeip.net> Message-ID: <565DD705-9FFF-4F31-BC3E-62CA3A47160B@gmail.com> Chris, Thanks for the tip on the function. I was not aware of that function, Grin. Creating the function as you mention makes a lot of sense. I am doing a lot of little bits and pieces focusing on things I need to eventually build a script that is going to compile data from a router and config it. I have hundreds of other questions, if I don't find answers on the net before hand. Sean On 04/01/2014, at 6:52 PM, Cameron Simpson wrote: > On 04Jan2014 16:54, Sean Murphy wrote: >> Thanks everyone. >> >> Mark thanks for the correction on the ':'. Since I didn't cut and copy, rather typed it out. Errors crept in. :-) >> >> another question in relation to slicing strings. If you want to get a single character, just using the index position will get it. If I use the following, shouldn't it also work? when I use Python 3.3, it didn't provide anything. >> >> a = "test.txt" >> print a[3] >> result is: >> >> 't > > As expected, yes? > >> print a[3:1] >> Nothing is printed. >> >> print a[3:2] >> Nothing is printed. > > These are not requests for 1 and 2 character strings. They are > requests for the character in the span from, respectively, 3 to 1 > and from 3 to 2. Important: counting FORWARDS. So: zero length > strings. > >> print a[3:-1] >> t.tx is printed. >> >> Why doesn't the positive number of characters to be splice return anything while the negative value does? > > -1 is shorthand for len(a)-1 > It is often convenient to refer to a position from the end of the > array instead of the start. > > So this means: [3:7], so positions 3,4,5,6. > >> sorry about these basic questions. I do like the splice feature within Python. Also what is the best method of testing for a blank string? > > Well, and empty string: a == '' or len(a) == 0. > And, because an "if" tests the nonzeroness of a single argument and > an empty string has length zero, you can also go: > > if a: > print "long string", a > else: > print "empty string" > > OTOH, if you mean a "blank string" to mean "containing only > whitespace", you can use the string method "isspace", which tests > that all characters are whitespace and that the string is not empty. > The doco for isspace() actually says: > > Return true if there are only whitespace characters in the string > and there is at least one character, false otherwise. > > So you might write: > > if not a or a.isspace(): > print "blank string:", repr(a) > > Really you'd want to put that it a (trivial) function: > > def isblank(s): > ''' Test that the string `s` is entirely blank. > ''' > return not s or s.isspace() > > That way you can write isblank() all through your program and control the > precise meaning by modifying the function. > > Cheers, > -- > > The perl5 internals are a complete mess. It's like Jenga - to get the perl5 > tower taller and do something new you select a block somewhere in the middle, > with trepidation pull it out slowly, and then carefully balance it somewhere > new, hoping the whole edifice won't collapse as a result. > - Nicholas Clark, restating an insight of Simon Cozens From glicerinu at gmail.com Sat Jan 4 04:54:21 2014 From: glicerinu at gmail.com (Marc Aymerich) Date: Sat, 4 Jan 2014 10:54:21 +0100 Subject: Highest performance HTTP REST microframework? In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 5:26 AM, Alec Taylor wrote: > What is the highest performance REST microframework? > > Happy if it's mostly written in C or C++; as long as it provides a > simple routes interface in Python. > > Currently using bottle and utilising its application, @route and > app.merge(app2) extra features. The biggest performance gains on HTTP architectures are usually made by doing proper HTTP caching. Without knowing anything about your architecture is hard to tell something more specific :) -- Marc From rosuav at gmail.com Sat Jan 4 05:01:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 21:01:01 +1100 Subject: Strange behaviour with a for loop. In-Reply-To: <565DD705-9FFF-4F31-BC3E-62CA3A47160B@gmail.com> References: <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> <20140104075254.GA38712@cskk.homeip.net> <565DD705-9FFF-4F31-BC3E-62CA3A47160B@gmail.com> Message-ID: On Sat, Jan 4, 2014 at 8:52 PM, Sean Murphy wrote: > Thanks for the tip on the function. I was not aware of that function, Grin. Creating the function as you mention makes a lot of sense. > > I am doing a lot of little bits and pieces focusing on things I need to eventually build a script that is going to compile data from a router and config it. > > I have hundreds of other questions, if I don't find answers on the net before hand. Glad it helped! You may find it helpful to get familiar with the Python interactive interpreter; if you're on Windows, I strongly recommend IDLE, which probably came with your Python install anyway. It's easy and fast to just try something out and see what it does. Plus, it makes for a really powerful pocket calculator :) ChrisA From eneskristo at gmail.com Sat Jan 4 05:17:20 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Sat, 4 Jan 2014 02:17:20 -0800 (PST) Subject: On radio buttons in tkinter Message-ID: So the issue is like this. I have to make a 2 x N grid like this: o Radio - 1 o Radio - 2 o Radio - 3 o Radio - 4 ... o Radio - N - 1 o Radio - N How to do so with a loop? From rosuav at gmail.com Sat Jan 4 05:30:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 21:30:50 +1100 Subject: On radio buttons in tkinter In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 9:17 PM, wrote: > So the issue is like this. I have to make a 2 x N grid like this: > o Radio - 1 o Radio - 2 > o Radio - 3 o Radio - 4 > ... > o Radio - N - 1 o Radio - N > > How to do so with a loop? How far have you managed to get so far? Do you have a Tkinter program that you're adding this to? Do you know how to iterate across integers two by two, so that you see the numbers 1, 3, 5, ... N-1? Don't just show us the question and expect us to do your homework for you. ChrisA From look at signature.invalid Sat Jan 4 06:09:00 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 12:09:00 +0100 Subject: [newbie] Recursive algorithm - review References: Message-ID: On Sat, 4 Jan 2014 13:02:37 +1100, Chris Angelico wrote: >> def check(towers, x=None): >> column = [] # value added on pos. x >> for i in range(len(towers)): >> column.append(towers[i][c]) >> column = [x for x in column if x != 0] > > Any time you iterate over range(len(something)), you probably want to > iterate over the thing instead: > > for t in towers: > column.append(t[c]) Right, /facepalm/ I've done it so many times. Don't know why not this time. > And any time you iterate over something and append to another list, > you probably want a list comprehension: > > column = [t[c] for t in towers] > [...] > column = [t[c] for t in towers if t[c] != 0] > [...] > column = [t[c] for t in towers if t[c]] Nice. >> for c in range(len(towers)): # 'x' not provided, >> column = [] # so check all columns > > I wouldn't normally wrap a comment onto an unrelated line; I'd put the > comment above the loop, since it's too long to be a part of the loop > header itself. It goes as much with the "else" as with the loop, > anyhow. My mistake. I know, that sometimes comment doesn't relate to line that is next to, but for one second I belived that it would be more readable ('talk' about the code whitout providing more unnecessary whitespace). Now I see that it isn't. > This is one case where you probably _do_ want to iterate up to > range(len(towers)), though, which is why I said "probably" above. :) > >> for i in range(len(towers)): >> column.append(towers[i][c]) >> column = [x for x in column if x != 0] > > This is the same code you had above, so it can benefit from the same > translation. But maybe it'd be even cleaner to simply call yourself? > > if not check(towers, i): return False You're right. It's cleaner this way. >> # print(column) >> if len(column) != len(set(column)): >> return False >> return True > > And in fact, you might want to turn this whole branch into something > that harks to a more functional programming style: > > return all((check(towers, i) for i in range(len(towers))) Great. I didn't know all() before. :-) Now check() function looks very neat. Although 'if' statement must now looks like: 'if x is not None:'. Earlier x never was going to be 0. Now it can be. >> random.shuffle(row) # at every recursion > > Again, I wouldn't wrap comments onto unrelated lines. You see how > confusing this looks, now that I take this line out of context? Same > will happen if it throws an exception. Yeap. Now I see it. Never gonna do that again. :-) > When you multiply a list of lists, you get references to the same > list, yes. But you could use multiplication for one level: > > towers = [[0]*size for _ in range(size)] > > That'll give you independent lists. Got it! >> if not row: >> row = [a for a in range(1, size+1)] >> random.shuffle(row) > > This is the same as you have at the top of 'if not towers'. Can you be > confident that row is None any time towers is None? If so, just move > this up above the other check and save the duplication. row is None at start, but later it is list - sometimes an empty list. For that cases this if statement was written. If row == [] -> generate new random row that I can pop out from. >> num = row.pop(0) # take num from right, and >> towers[x // size][x % size] = num # if doesn't match - put >> repeat = not check(towers, x) # back (append) on left - >> # - to rotate >> if repeat: # I'll repeat 'matching' next >> row.append(num) # number as long as last >> x -= 1 # changed column is unique > > Hmm, I'm slightly confused by your comments here. You pop(0) and > append(), and describe that as taking from the right and putting on > the left. Normally I'd write a list like this: Of course, of course. I was thinking one, writing another. I switched left and right in my explanation. It looks stupid now. ;-) Thank you for all Your comments. -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From rosuav at gmail.com Sat Jan 4 06:18:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 4 Jan 2014 22:18:09 +1100 Subject: [newbie] Recursive algorithm - review In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 10:09 PM, Wiktor wrote: > On Sat, 4 Jan 2014 13:02:37 +1100, Chris Angelico wrote: >> And in fact, you might want to turn this whole branch into something >> that harks to a more functional programming style: >> >> return all((check(towers, i) for i in range(len(towers))) > > Great. I didn't know all() before. :-) > Now check() function looks very neat. Sometimes they aren't any help at all (puns intended), but sometimes any() and all() are exactly what you want. > Although 'if' statement must now looks like: 'if x is not None:'. Earlier x > never was going to be 0. Now it can be. Nicely spotted, I hadn't thought of that implication. >>> random.shuffle(row) # at every recursion >> >> Again, I wouldn't wrap comments onto unrelated lines. You see how >> confusing this looks, now that I take this line out of context? Same >> will happen if it throws an exception. > > Yeap. Now I see it. Never gonna do that again. :-) Please note that I didn't intend this as criticism, or a "this is the rule so follow it" directive, just as advice :) I'm not bearing down on you with a sergeant-major's string of orders, just offering some tips that you're free to ignore if you like. And in fact, you probably WILL ignore some of them, at some points, even if you believe them to be good advice now - every stylistic rule must be secondary to the overriding rule "Make it work and be readable", and should be broken if it violates the prime directive. >> This is the same as you have at the top of 'if not towers'. Can you be >> confident that row is None any time towers is None? If so, just move >> this up above the other check and save the duplication. > > row is None at start, but later it is list - sometimes an empty list. For > that cases this if statement was written. If row == [] -> generate new random > row that I can pop out from. Yes, but will you ever pass a non-None row and a None towers? If not, you can deduplicate that bit of code by simply checking one before the other. > Thank you for all Your comments. My pleasure! Always happy to help out. ChrisA From auriocus at gmx.de Sat Jan 4 06:23:27 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Sat, 04 Jan 2014 12:23:27 +0100 Subject: On radio buttons in tkinter In-Reply-To: References: Message-ID: Am 04.01.14 11:17, schrieb eneskristo at gmail.com: > So the issue is like this. I have to make a 2 x N grid like this: > o Radio - 1 o Radio - 2 > o Radio - 3 o Radio - 4 > ... > o Radio - N - 1 o Radio - N > > How to do so with a loop? > Create the buttons and append them into a list, so you can later refer to them. Use grid() to create the layout you want (the text widget is an alternative) Make sure you set the same variable and different "values", so that the radiobuttons can distinguish which one is selected. The rule is: 1) If the associated variable has the value of "value", the button is selected 2) If the associated variable has a different value, the button is not selected (thus you can implement selecting nothing by setting the variable to some bogus value) 3) For Ttk widgets: If the variable is undefined, the button is in the third state I'm not sure Tkinter handles case 3, because if you delete the variable object by letting it go out of scope, there is probably no way to reattach it to the buttons. And there is no unset method, let alone a translation from unset variables to None if you do it by bypassing Tkinter: Apfelkiste:~ chris$ python Python 2.7.2 (default, Oct 11 2012, 20:14:37) [GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter >>> t=Tkinter.Tk() >>> s=Tkinter.StringVar() >>> s.set('Hello') >>> s.get() 'Hello' >>> t.eval('unset ' + str(s)) '' >>> s.get() Traceback (most recent call last): File "", line 1, in File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 255, in get value = self._tk.globalgetvar(self._name) _tkinter.TclError: can't read "PY_VAR0": no such variable >>> IMHO the last call should translate an unset variable to None to by useful for three-state widgets. You can still do it manually by invoking the widget's state() method Christian From look at signature.invalid Sat Jan 4 06:23:55 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 12:23:55 +0100 Subject: [newbie] Recursive algorithm - review References: Message-ID: On Fri, 03 Jan 2014 20:47:16 -0500, Terry Reedy wrote: > [0]*size] is fine for one row > > towers = [[0]*size] for i in range(size)] > > should do what you want for a 2-d array instead of the above. Right. Thank you also. -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From look at signature.invalid Sat Jan 4 06:53:46 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 12:53:46 +0100 Subject: [newbie] Recursive algorithm - review References: Message-ID: <1xm2a5ae3fh0d.16i07futw6fmc.dlg@40tude.net> On Sat, 4 Jan 2014 22:18:09 +1100, Chris Angelico wrote: >>> This is the same as you have at the top of 'if not towers'. Can you be >>> confident that row is None any time towers is None? If so, just move >>> this up above the other check and save the duplication. >> >> row is None at start, but later it is list - sometimes an empty list. For >> that cases this if statement was written. If row == [] -> generate new random >> row that I can pop out from. > > Yes, but will you ever pass a non-None row and a None towers? If not, > you can deduplicate that bit of code by simply checking one before the > other. Oh, now I understand what You mean. I rewrote that part. def generate(size=4, towers=None, row=None, x=0): if not row: row = [a for a in range(1, size+1)] random.shuffle(row) if not towers: towers = [[0]*size for _ in range(size)] towers[0] = row[:] random.shuffle(row) x = size - 1 if x + 1 < size**2: # [...] Much more cleaner. Thanks! -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From look at signature.invalid Sat Jan 4 08:01:49 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 14:01:49 +0100 Subject: [newbie] Recursive algorithm - review References: Message-ID: On Sat, 4 Jan 2014 22:18:09 +1100, Chris Angelico wrote: >> Thank you for all Your comments. > > My pleasure! Always happy to help out. I'm aware, that at my point of education there's no sense in optimizing code to squeeze from it every millisecond, but Project Euler gave me habit to compare time consumption of script every time I make serious change in it. Your tune-ups made this script (mostly check() I guess) about 20% faster. So it's not only 'more readable' profit. :-) -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From wxjmfauth at gmail.com Sat Jan 4 08:52:20 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 4 Jan 2014 05:52:20 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> Message-ID: <7978ffc2-8e6a-40b2-a4c7-66990d6af1be@googlegroups.com> Le vendredi 3 janvier 2014 12:14:41 UTC+1, Robin Becker a ?crit?: > On 02/01/2014 18:37, Terry Reedy wrote: > > > On 1/2/2014 12:36 PM, Robin Becker wrote: > > > > > >> I just spent a large amount of effort porting reportlab to a version > > >> which works with both python2.7 and python3.3. I have a large number of > > >> functions etc which handle the conversions that differ between the two > > >> pythons. > > > > > > I am imagine that this was not fun. > > > > indeed :) > > > > > >> For fairly sensible reasons we changed the internal default to use > > >> unicode rather than bytes. > > > > > > Do you mean 'from __future__ import unicode_literals'? > > > > No, previously we had default of utf8 encoded strings in the lower levels of the > > code and we accepted either unicode or utf8 string literals as inputs to text > > functions. As part of the port process we made the decision to change from > > default utf8 str (bytes) to default unicode. > > > > > Am I correct in thinking that this change increases the capabilities of > > > reportlab? For instance, easily producing an article with abstracts in English, > > > Arabic, Russian, and Chinese? > > > > > It's made no real difference to what we are able to produce or accept since utf8 > > or unicode can encode anything in the input and what can be produced depends on > > fonts mainly. > > > > > > After doing all that and making the tests > > ........... > > >> I know some of these tests are fairly variable, but even for simple > > >> things like paragraph parsing 3.3 seems to be slower. Since both use > > >> unicode internally it can't be that can it, or is python 2.7's unicode > > >> faster? > > > > > > The new unicode implementation in 3.3 is faster for some operations and slower > > > for others. It is definitely more space efficient, especially compared to a wide > > > build system. It is definitely less buggy, especially compared to a narrow build > > > system. > > > > > > Do your tests use any astral (non-BMP) chars? If so, do they pass on narrow 2.7 > > > builds (like on Windows)? > > > > I'm not sure if we have any non-bmp characters in the tests. Simple CJK etc etc > > for the most part. I'm fairly certain we don't have any ability to handle > > composed glyphs (multi-codepoint) etc etc > > > > > > > > .... > > > For one thing, indexing and slicing just works on all machines for all unicode > > > strings. Code for 2.7 and 3.3 either a) does not index or slice, b) does not > > > work for all text on 2.7 narrow builds, or c) has extra conditional code only > > > for 2.7. ---- To Robin Becker I know nothing about ReportLab except its existence. Your story is very interesting. As I pointed, I know nothing about the internal of ReportLab, the technical aspects: the "Python part", "the used api for the PDF creation"). I have however some experience with the unicode TeX engine, XeTeX, understand I'm understanding a little bit what's happening behind the scene. The very interesting aspect in the way you are holding unicodes (strings). By comparing Python 2 with Python 3.3, you are comparing utf-8 with the the internal "representation" of Python 3.3 (the flexible string represenation). In one sense, more than comparing Py2 with Py3. It will be much more interesting to compare utf-8/Python internals at the light of Python 3.2 and Python 3.3. Python 3.2 has a decent unicode handling, Python 3.3 has an absurd (in mathematical sense) unicode handling. This is really shining with utf-8, where this flexible string representation is just doing the opposite of what a correct unicode implementation does! On the memory side, it is obvious to see it. >>> sys.getsizeof('a'*10000 + 'z') 10026 >>> sys.getsizeof('a'*10000 + '?') 20040 >>> sys.getsizeof(('a'*10000 + 'z').encode('utf-8')) 10018 >>> sys.getsizeof(('a'*10000 + '?').encode('utf-8')) 10020 On the performance side, it is much more complexe, but qualitatively, you may expect the same results. The funny aspect is that by working with utf-8 in that case, you are (or one has) forcing Python to work properly, but one pays on the side of the performance. And if one wishes to save memory, one has to pay on the side of performance. In othe words, attempting to do what Python is not able to do natively is just impossible! I'm skipping the very interesting composed glyphs subject (unicode normalization, ...), but I wish to point that with the flexible string representation, one reaches the top level of surrealism. For a tool which is supposed to handle these very specific unicode tasks... jmf From roy at panix.com Sat Jan 4 08:55:11 2014 From: roy at panix.com (Roy Smith) Date: Sat, 04 Jan 2014 08:55:11 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: In article , Mark Lawrence wrote: > Surely everybody prefers fast but incorrect code in > preference to something that is correct but slow? I realize I'm taking this statement out of context, but yes, sometimes fast is more important than correct. Sometimes the other way around. From rosuav at gmail.com Sat Jan 4 09:17:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 01:17:40 +1100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: On Sun, Jan 5, 2014 at 12:55 AM, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> Surely everybody prefers fast but incorrect code in >> preference to something that is correct but slow? > > I realize I'm taking this statement out of context, but yes, sometimes > fast is more important than correct. Sometimes the other way around. More usually, it's sometimes better to be really fast and mostly correct than really really slow and entirely correct. That's why we use IEEE floating point instead of Decimal most of the time. Though I'm glad that Python 3 now deems the default int type to be capable of representing arbitrary integers (instead of dropping out to a separate long type as Py2 did), I think it's possibly worth optimizing small integers to machine words - but mainly, the int type focuses on correctness above performance, because the cost is low compared to the benefit. With float, the cost of arbitrary precision is extremely high, and the benefit much lower. With Unicode, the cost of perfect support is normally seen to be a doubling of internal memory usage (UTF-16 vs UCS-4). Pike and Python decided that the cost could, instead, be a tiny measure of complexity and actually *less* memory usage (compared to UTF-16, when lots of identifiers are ASCII). It's a system that works only when strings are immutable, but works beautifully there. Fortunately Pike doesn't have any, and Python has only one, idiot like jmf who completely misunderstands what's going on and uses microbenchmarks to prove obscure points... and then uses nonsense to try to prove... uhh... actually I'm not even sure what, sometimes. I wouldn't dare try to read his posts except that my mind's already in a rather broken state, as a combination of programming and Alice in Wonderland. ChrisA From li.beinan at gmail.com Sat Jan 4 11:29:27 2014 From: li.beinan at gmail.com (Beinan Li) Date: Sat, 4 Jan 2014 11:29:27 -0500 Subject: How to make a tkinter GUI work on top of a CUI program? In-Reply-To: References: Message-ID: Thank you so much Jerry. I should have read though the man page more carefully. The available online cscope tutorials never mentioned the line-oriented mode. On Sat, Jan 4, 2014 at 1:35 AM, Jerry Hill wrote: > On Fri, Jan 3, 2014 at 9:44 PM, Beinan Li wrote: > > But some console programs have their own shell or ncurse-like CUI, such > as > > cscope. > > So I figured that I need to first subprocess.popen a bidirectional pipe > and > > send command through stdin and get results from stdout and stderr. > > > > But in such a case I found that communicate('cmd') will freeze. > > Right. communicate() waits for the subprocess to end, and the > subprocess is still waiting for you to do something. Instead, you'll > need to read() and write() to the subprocess' stdin and stdout > attributes, probably something like this (untested): > > def OnClickBtn(self, event): > print('OnClickBtn') > self.subProc.stdin.write('symbolName\n') > print(self.subProc.stdout.read()) > > It looks like cscope has both a screen-oriented mode and a line-based > mode. When you're working with a subprocess like this, you're going > to want to be in the line-based mode, so you'll probably want to add > -l or -L to your command line. > > -- > Jerry > -------------- next part -------------- An HTML attachment was scrubbed... URL: From li.beinan at gmail.com Sat Jan 4 11:31:06 2014 From: li.beinan at gmail.com (Beinan Li) Date: Sat, 4 Jan 2014 11:31:06 -0500 Subject: How to make a tkinter GUI work on top of a CUI program? In-Reply-To: References: Message-ID: ... and thanks to Chris too. Now I got the better idea how the subprocess module works. On Sat, Jan 4, 2014 at 11:29 AM, Beinan Li wrote: > Thank you so much Jerry. > I should have read though the man page more carefully. > The available online cscope tutorials never mentioned the line-oriented > mode. > > > > On Sat, Jan 4, 2014 at 1:35 AM, Jerry Hill wrote: > >> On Fri, Jan 3, 2014 at 9:44 PM, Beinan Li wrote: >> > But some console programs have their own shell or ncurse-like CUI, such >> as >> > cscope. >> > So I figured that I need to first subprocess.popen a bidirectional pipe >> and >> > send command through stdin and get results from stdout and stderr. >> > >> > But in such a case I found that communicate('cmd') will freeze. >> >> Right. communicate() waits for the subprocess to end, and the >> subprocess is still waiting for you to do something. Instead, you'll >> need to read() and write() to the subprocess' stdin and stdout >> attributes, probably something like this (untested): >> >> def OnClickBtn(self, event): >> print('OnClickBtn') >> self.subProc.stdin.write('symbolName\n') >> print(self.subProc.stdout.read()) >> >> It looks like cscope has both a screen-oriented mode and a line-based >> mode. When you're working with a subprocess like this, you're going >> to want to be in the line-based mode, so you'll probably want to add >> -l or -L to your command line. >> >> -- >> Jerry >> > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ned at nedbatchelder.com Sat Jan 4 12:51:32 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 04 Jan 2014 12:51:32 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: On 1/4/14 9:17 AM, Chris Angelico wrote: > On Sun, Jan 5, 2014 at 12:55 AM, Roy Smith wrote: >> In article , >> Mark Lawrence wrote: >> >>> Surely everybody prefers fast but incorrect code in >>> preference to something that is correct but slow? >> >> I realize I'm taking this statement out of context, but yes, sometimes >> fast is more important than correct. Sometimes the other way around. > > More usually, it's sometimes better to be really fast and mostly > correct than really really slow and entirely correct. That's why we > use IEEE floating point instead of Decimal most of the time. Though > I'm glad that Python 3 now deems the default int type to be capable of > representing arbitrary integers (instead of dropping out to a separate > long type as Py2 did), I think it's possibly worth optimizing small > integers to machine words - but mainly, the int type focuses on > correctness above performance, because the cost is low compared to the > benefit. With float, the cost of arbitrary precision is extremely > high, and the benefit much lower. > > With Unicode, the cost of perfect support is normally seen to be a > doubling of internal memory usage (UTF-16 vs UCS-4). Pike and Python > decided that the cost could, instead, be a tiny measure of complexity > and actually *less* memory usage (compared to UTF-16, when lots of > identifiers are ASCII). It's a system that works only when strings are > immutable, but works beautifully there. Fortunately Pike doesn't have > any, and Python has only one, idiot like jmf who completely > misunderstands what's going on and uses microbenchmarks to prove > obscure points... and then uses nonsense to try to prove... uhh... > actually I'm not even sure what, sometimes. I wouldn't dare try to > read his posts except that my mind's already in a rather broken state, > as a combination of programming and Alice in Wonderland. > > ChrisA > I really wish we could discuss these things without baiting trolls. -- Ned Batchelder, http://nedbatchelder.com From look at signature.invalid Sat Jan 4 14:07:33 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 20:07:33 +0100 Subject: [newbie] Recursive algorithm - review References: Message-ID: <17yrxkdy2ipni$.1k46s6c6xxte4$.dlg@40tude.net> On Sat, 4 Jan 2014 01:16:14 +0100, Wiktor wrote: > Hi, OK, another question. This time, I think, closer to the original subject (recursive algorithm). Thanks to Terry's and Chris' advises I refined script. Then I thought, that with some changes and with minimal effort I can force this script to generate Sudoku board (again: filled out, 'solved' one). Well, I was wrong. ;-) It actually took me 2 hours to make this script working fine - even though changes weren't so big. And another one hour to make it clear enough to share here. Idea is still the same. I start with 2d array [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] And then I fill it up one number by one (exception: first row). At every step checking if current column is unique (0's not counted) and if also current segment 3x3 is unique. If that condition is True I call another instance of generate(), passing to it a) the board, b) the position in which I last putted number, and c) a list of numbers that in next step this function can choose from (if empty, function will generate new list). And so on. If that condition is False, I try another number from list of available numbers, and check again. If all numbers fail, I go back one level and try another number on previous position. I'll paste code now, and under that I'll write what's mine concern now. (if you uncomment hashed lines it will print out entire process of generating board, but watch out - it can be several thousands of lines) ### import random attempt_global = 0 def check(board, x=None, sudoku=False): global attempt_global attempt_global += 1 if sudoku and len(board) == 9 and x is not None: c = x % len(board) r = x // len(board) # print('Attempt #{}; Checking ({}x{})'.format(attempt_global, # r, c)) # for row in board: # print(row) # print() column = [t[c] for t in board if t[c]] br_min, br_max = r//3 * 3, r//3 * 3 + 3 bc_min, bc_max = c//3 * 3, c//3 * 3 + 3 block = [t[bc_min:bc_max] for t in board[br_min:br_max]] block_flat = [item for row in block for item in row if item] return len(column) == len(set(column)) and \ len(block_flat) == len(set(block_flat)) elif x is not None: c = x % len(board) column = [t[c] for t in board if t[c]] return len(column) == len(set(column)) elif sudoku and len(board) == 9: return all((check(board, i, sudoku) for i in range(0, len(board)**2, 4))) else: return all((check(board, i) for i in range(len(board)))) def generate(size=4, board=None, row=None, x=0, sudoku=False): if not row: row = [a for a in range(1, size+1)] random.shuffle(row) if not board: board = [[0]*size for _ in range(size)] board[0] = row[:] random.shuffle(row) x = size - 1 if x + 1 < size**2: repeat = True attempt = 0 while repeat: x += 1 num = row.pop(0) board[x // size][x % size] = num repeat = not check(board, x, sudoku) if repeat: row.append(num) board[x // size][x % size] = 0 x -= 1 attempt += 1 if attempt > len(row) - 1: return False else: if not generate(size, board, row, x, sudoku): repeat = True row.append(num) board[x // size][x % size] = 0 x -= 1 attempt += 1 if attempt > len(row) - 1: return False return board def main(): global attempt_global sudoku_board = generate(9, sudoku=True) for row in sudoku_board: print(row) print('Attempts:', attempt_global) if __name__ == "__main__": main() ### OK, it works fine. Most of the time it generates board in less than 400 attempts, so not so bad. But sometimes it takes over thousand tries to generate board. For example, one time, at attempt #46 it validates last putted '1', and of course it passes, Attempt #46; Checking (4x1) [1, 5, 3, 9, 4, 2, 8, 6, 7] [2, 7, 6, 5, 8, 1, 3, 9, 4] [9, 8, 4, 7, 3, 6, 1, 5, 2] [8, 9, 5, 3, 7, 4, 6, 2, 1] [7, 1, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] then fills out entire row, and starting from attempt #61... Attempt #61; Checking (5x0) [1, 5, 3, 9, 4, 2, 8, 6, 7] [2, 7, 6, 5, 8, 1, 3, 9, 4] [9, 8, 4, 7, 3, 6, 1, 5, 2] [8, 9, 5, 3, 7, 4, 6, 2, 1] [7, 1, 2, 8, 6, 9, 4, 3, 5] [3, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] ... through attempt #1055 it struggles whith so many combinations in that one segment 3x3: 8 9 5 7 1 2 A B C and entire row 4, to find out, that only solution is go back to position (4x1) and replace '1' with another number. In this case '6' was fine. Attempt #1056; Checking (4x1) [1, 5, 3, 9, 4, 2, 8, 6, 7] [2, 7, 6, 5, 8, 1, 3, 9, 4] [9, 8, 4, 7, 3, 6, 1, 5, 2] [8, 9, 5, 3, 7, 4, 6, 2, 1] [7, 6, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0] Final board in this case looked like that: Attempt #1251; Checking (8x8) [1, 5, 3, 9, 4, 2, 8, 6, 7] [2, 7, 6, 5, 8, 1, 3, 9, 4] [9, 8, 4, 7, 3, 6, 1, 5, 2] [8, 9, 5, 3, 7, 4, 6, 2, 1] [7, 6, 2, 8, 1, 9, 4, 3, 5] [4, 3, 1, 2, 6, 5, 7, 8, 9] [6, 2, 7, 4, 5, 3, 9, 1, 8] [3, 4, 9, 1, 2, 8, 5, 7, 6] [5, 1, 8, 6, 9, 7, 2, 4, 3] It takes so much time, obviously, because every time number on position A (in segment 3x3) doesn't match, it doesn't jump back to 2 (above C), but instead it walks through entire recursion tree. Now, my question is - should I implement mechanism that recognises this kind of situation, and jumps back (let's say) 9 levels of recursion at once? My guess is that it will take me at least several hours to solve this properly. Also, now it's simple algorithm, and if I start to tamper with it, it will overgrow by many conditions, and extra arguments. Won't be so clear anymore. Or maybe I should accept that this is how recursion works, and let go? What would you do? Or maybe there's better way to generate pseudo-random Sudoku board? Not by recursion. Or maybe by recursion, but nicer with less attempts in those kind of situation? I guess that some kind of you have done this before. ;-) Any tips? TIA -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From wxjmfauth at gmail.com Sat Jan 4 14:10:03 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 4 Jan 2014 11:10:03 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Le samedi 4 janvier 2014 15:17:40 UTC+1, Chris Angelico a ?crit?: > On Sun, Jan 5, 2014 at 12:55 AM, Roy Smith wrote: > > > In article , > > > Mark Lawrence wrote: > > > > > >> Surely everybody prefers fast but incorrect code in > > >> preference to something that is correct but slow? > > > > > > I realize I'm taking this statement out of context, but yes, sometimes > > > fast is more important than correct. Sometimes the other way around. > > > > More usually, it's sometimes better to be really fast and mostly > > correct than really really slow and entirely correct. That's why we > > use IEEE floating point instead of Decimal most of the time. Though > > I'm glad that Python 3 now deems the default int type to be capable of > > representing arbitrary integers (instead of dropping out to a separate > > long type as Py2 did), I think it's possibly worth optimizing small > > integers to machine words - but mainly, the int type focuses on > > correctness above performance, because the cost is low compared to the > > benefit. With float, the cost of arbitrary precision is extremely > > high, and the benefit much lower. > > > > With Unicode, the cost of perfect support is normally seen to be a > > doubling of internal memory usage (UTF-16 vs UCS-4). Pike and Python > > decided that the cost could, instead, be a tiny measure of complexity > > and actually *less* memory usage (compared to UTF-16, when lots of > > identifiers are ASCII). It's a system that works only when strings are > > immutable, but works beautifully there. Fortunately Pike doesn't have > > any, and Python has only one, idiot like jmf who completely > > misunderstands what's going on and uses microbenchmarks to prove > > obscure points... and then uses nonsense to try to prove... uhh... > > actually I'm not even sure what, sometimes. I wouldn't dare try to > > read his posts except that my mind's already in a rather broken state, > > as a combination of programming and Alice in Wonderland. > I do not mind to be considered as an idiot, but I'm definitively not blind. And I could add, I *never* saw once one soul, who is explaining what I'm doing wrong in the gazillion of examples I gave on this list. --- Back to ReportLab. Technically I would be really interested to see what could happen at the light of my previous post. jmf From breamoreboy at yahoo.co.uk Sat Jan 4 14:35:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 04 Jan 2014 19:35:01 +0000 Subject: 3.4 on Windows ImportError: cannot import name 'IntEnum' Message-ID: I first saw this when tring to run the command "py -3.4 -m ensurepip" which gave me this lot. Traceback (most recent call last): File "C:\Python34\lib\runpy.py", line 160, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Python34\lib\runpy.py", line 73, in _run_code exec(code, run_globals) File "C:\Python34\lib\ensurepip\__main__.py", line 66, in main() File "C:\Python34\lib\ensurepip\__main__.py", line 61, in main default_pip=args.default_pip, File "C:\Python34\lib\ensurepip\__init__.py", line 92, in bootstrap _run_pip(args + [p[0] for p in _PROJECTS], additional_paths) File "C:\Python34\lib\ensurepip\__init__.py", line 28, in _run_pip import pip File "C:\Users\Mark\AppData\Local\Temp\tmpysmgllcx\pip-1.5.rc1-py2.py3-none-any.whl\pip\__init__.py", line 9, in File "C:\Users\Mark\AppData\Local\Temp\tmpysmgllcx\pip-1.5.rc1-py2.py3-none-any.whl\pip\backwardcompat\__init__.py", lin File "C:\Python34\lib\urllib\request.py", line 88, in import http.client File "C:\Python34\lib\http\client.py", line 69, in import email.parser File "C:\Python34\lib\email\parser.py", line 13, in from email.feedparser import FeedParser, BytesFeedParser File "C:\Python34\lib\email\feedparser.py", line 27, in from email import message File "C:\Python34\lib\email\message.py", line 14, in from email import utils File "C:\Python34\lib\email\utils.py", line 30, in import socket File "C:\Python34\lib\socket.py", line 51, in from enum import IntEnum ImportError: cannot import name 'IntEnum' Before I raise an issue on the bug tracker can another Windows user or two please confirm that this is a genuine problem and not my installation being corrupt or whatever. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From look at signature.invalid Sat Jan 4 14:36:26 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 20:36:26 +0100 Subject: [newbie] Recursive algorithm - review References: <17yrxkdy2ipni$.1k46s6c6xxte4$.dlg@40tude.net> Message-ID: On Sat, 4 Jan 2014 20:07:33 +0100, Wiktor wrote: > I guess that some kind of you have done this before. ;-) ^^^^ Damn it. This 'kind' shouldn't be there. Now it sounds silly, even offensive. ;-) Normally I would supersede it, but probably attached mailing-list doesn't recognize those Usenet articles (Chris previously answered to my superseded article). -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From jsf80238 at gmail.com Sat Jan 4 11:15:39 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Sat, 4 Jan 2014 09:15:39 -0700 Subject: Flip a graph Message-ID: I am teaching Python to a class of six-graders as part of an after-school enrichment. These are average students. We wrote a non-GUI "rocket lander" program: you have a rocket some distance above the ground, a limited amount of fuel and a limited burn rate, and the goal is to have the rocket touch the ground below some threshold velocity. I thought it would be neat, after a game completes, to print a graph showing the descent. Given these measurements: measurement_dict = { # time, height 0: 10, 1: 9, 2: 9, 3: 8, 4: 8, 5: 7, 6: 6, 7: 4, 8: 5, 9: 3, 10: 2, 11: 1, 12: 0, } The easiest solution is to have the Y axis be time and the X axis distance from the ground, and the code would be: for t, y in measurement_dict.items(): print("X" * y) That output is not especially intuitive, though. A better visual would be an X axis of time and Y axis of distance: max_height = max(measurement_dict.values()) max_time = max(measurement_dict.keys()) for height in range(max_height, 0, -1): row = list(" " * max_time) for t, y in measurement_dict.items(): if y >= height: row[t] = 'X' print("".join(row)) My concern is whether the average 11-year-old will be able to follow such logic. Is there a better approach? -------------- next part -------------- An HTML attachment was scrubbed... URL: From orgnut at yahoo.com Sat Jan 4 16:25:20 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 04 Jan 2014 13:25:20 -0800 Subject: Strange behaviour with a for loop. In-Reply-To: References: Message-ID: On 01/03/2014 08:03 PM, Sean Murphy wrote: > Hello all. > > This is a newly question. But I wish to understand why the below code is providing different results. > > import os, sys > > > if len(sys.argv) > 2: > filenames = sys.argv[1:] > else > print ("no parameters provided\n") > sys.edit() > > for filename in filenames: > print ("filename is: %s\n" %filename) > > The above code will return results like: > > filename is test.txt > > If I modify the above script slightly as shown below, I get a completely different result. > > if len(sys.argv) > 2: > filenames = sys.argv[1] > else > print ("no parameters provided\n") > sys.exit() > > for filename in filenames: > print ("filename is: %s\n" % filename) > > The result is the filename is spelled out a character at a time. The bit I am missing is something to do with splicing or referencing in Python. > > Why am I getting different results? In other languages I would have got the whole content of the element when using the index of the array (list). > > > Sean > filename is: t > filename > How easy it is to overlook your own typos... (No worry, everybody does it) ;-) In your first version you have: filenames = sys.argv[1:] which gives you a list of filenames (which is what you want). In your second version you have: filenames = sys.argv[1] which is ONE item -- a string, not a list. You left out the colon. -=- Larry -=- From look at signature.invalid Sat Jan 4 16:38:19 2014 From: look at signature.invalid (Wiktor) Date: Sat, 4 Jan 2014 22:38:19 +0100 Subject: Flip a graph References: Message-ID: <1dcwwr0boi0rx$.pkva7zzcz0wl$.dlg@40tude.net> On Sat, 4 Jan 2014 09:15:39 -0700, Jason Friedman wrote: > My concern is whether the average 11-year-old will be able to follow such > logic. Is there a better approach? Basically mine approach is the same, but maybe is easier to explain it to kids. max_height = max(measurement_dict.values()) temporary_graph = [] for t, y in measurement_dict.items(): temporary_graph.append('X'*y + ' '*(max_height - y)) for i in range(max_height-1, -1, -1): for item in temporary_graph: print(item[i], end='') print() -- Best regards, Wiktor Matuszewski 'py{}@wu{}em.pl'.format('wkm', 'ka') # email spam trap From tjreedy at udel.edu Sat Jan 4 16:57:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 04 Jan 2014 16:57:49 -0500 Subject: Flip a graph In-Reply-To: References: Message-ID: On 1/4/2014 11:15 AM, Jason Friedman wrote: > I am teaching Python to a class of six-graders as part of an > after-school enrichment. Great. I love seeing basic Python used for that sort of thing. > These are average students. We wrote a > non-GUI "rocket lander" program: you have a rocket some distance above > the ground, a limited amount of fuel and a limited burn rate, and the > goal is to have the rocket touch the ground below some threshold velocity. > > I thought it would be neat, after a game completes, to print a graph > showing the descent. > > Given these measurements: > measurement_dict = { # time, height > 0: 10, > 1: 9, > 2: 9, > 3: 8, > 4: 8, > 5: 7, > 6: 6, > 7: 4, > 8: 5, > 9: 3, > 10: 2, > 11: 1, > 12: 0, > } > > The easiest solution is to have the Y axis be time and the X axis > distance from the ground, and the code would be: > > for t, y in measurement_dict.items(): > print("X" * y) > > That output is not especially intuitive, though. A better visual would > be an X axis of time and Y axis of distance: > > max_height = max(measurement_dict.values()) > max_time = max(measurement_dict.keys()) > for height in range(max_height, 0, -1): > row = list(" " * max_time) > for t, y in measurement_dict.items(): > if y >= height: > row[t] = 'X' > print("".join(row)) > > My concern is whether the average 11-year-old will be able to follow > such logic. Is there a better approach? I would take a black and white 'canvas' (rectangular array of printable blocks) approach. First, separate creating the plot (output) and printing it. (If nothing else, this allows easy automatic testing of the output without capturing print output.) plot = [] for t, y in measurement_dict.items(): plot[t] = "X" * y def printplot(plot): for row in plot: print(row) printplot(plot) The plot loop could be a list comprehension, but I assume you are not doing those. Next, I would modify the plot loop to make a rectangular array. max_height = max(measurement_dict.values()) ...plot[t] = "X" * y + ' ' * max_height - y Then transpose the array either with zip or an explicit double loop and print it with the rows reversed. Example: plot = ['xxxx', 'xx ', 'x '] def printplot(plot): for row in plot: if not isinstance(row, str): row = ''.join(row) print(row) printplot(plot) print() printplot(reversed(list(zip(*plot)))) >>> xxxx xx x x x xx xxx Or start with a list of lists of chars (blank canvas) and fill in 'x's column by column. -- Terry Jan Reedy From tjreedy at udel.edu Sat Jan 4 16:58:40 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 04 Jan 2014 16:58:40 -0500 Subject: Flip a graph In-Reply-To: References: Message-ID: PS to my previous response: please send plain text only, and not the html in addition. -- Terry Jan Reedy From vincent at vincentdavis.net Sat Jan 4 17:10:41 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 4 Jan 2014 15:10:41 -0700 Subject: Flip a graph In-Reply-To: References: Message-ID: You might think about using an array to represent the canvas. Starting with it filled with "" and then for each point change it to "X". The print the rows of the array. You can make the array/canvas arbitrarily large and then plot multiple different paths onto the same array. Vincent Davis 720-301-3003 On Sat, Jan 4, 2014 at 9:15 AM, Jason Friedman wrote: > I am teaching Python to a class of six-graders as part of an after-school > enrichment. These are average students. We wrote a non-GUI "rocket > lander" program: you have a rocket some distance above the ground, a > limited amount of fuel and a limited burn rate, and the goal is to have the > rocket touch the ground below some threshold velocity. > > I thought it would be neat, after a game completes, to print a graph > showing the descent. > > Given these measurements: > measurement_dict = { # time, height > 0: 10, > 1: 9, > 2: 9, > 3: 8, > 4: 8, > 5: 7, > 6: 6, > 7: 4, > 8: 5, > 9: 3, > 10: 2, > 11: 1, > 12: 0, > } > > The easiest solution is to have the Y axis be time and the X axis distance > from the ground, and the code would be: > > for t, y in measurement_dict.items(): > print("X" * y) > > That output is not especially intuitive, though. A better visual would be > an X axis of time and Y axis of distance: > > max_height = max(measurement_dict.values()) > max_time = max(measurement_dict.keys()) > for height in range(max_height, 0, -1): > row = list(" " * max_time) > for t, y in measurement_dict.items(): > if y >= height: > row[t] = 'X' > print("".join(row)) > > My concern is whether the average 11-year-old will be able to follow such > logic. Is there a better approach? > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Sat Jan 4 17:13:49 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Sat, 4 Jan 2014 15:13:49 -0700 Subject: Flip a graph In-Reply-To: References: Message-ID: When printing the rows of the array/canvas you might add \n to the end of each row and print the canvas all at once rather than a print statement for each row. Vincent Davis 720-301-3003 On Sat, Jan 4, 2014 at 3:10 PM, Vincent Davis wrote: > You might think about using an array to represent the canvas. Starting > with it filled with "" and then for each point change it to "X". > The print the rows of the array. > > You can make the array/canvas arbitrarily large and then plot multiple > different paths onto the same array. > > > Vincent Davis > 720-301-3003 > > > On Sat, Jan 4, 2014 at 9:15 AM, Jason Friedman wrote: > >> I am teaching Python to a class of six-graders as part of an after-school >> enrichment. These are average students. We wrote a non-GUI "rocket >> lander" program: you have a rocket some distance above the ground, a >> limited amount of fuel and a limited burn rate, and the goal is to have the >> rocket touch the ground below some threshold velocity. >> >> I thought it would be neat, after a game completes, to print a graph >> showing the descent. >> >> Given these measurements: >> measurement_dict = { # time, height >> 0: 10, >> 1: 9, >> 2: 9, >> 3: 8, >> 4: 8, >> 5: 7, >> 6: 6, >> 7: 4, >> 8: 5, >> 9: 3, >> 10: 2, >> 11: 1, >> 12: 0, >> } >> >> The easiest solution is to have the Y axis be time and the X axis >> distance from the ground, and the code would be: >> >> for t, y in measurement_dict.items(): >> print("X" * y) >> >> That output is not especially intuitive, though. A better visual would >> be an X axis of time and Y axis of distance: >> >> max_height = max(measurement_dict.values()) >> max_time = max(measurement_dict.keys()) >> for height in range(max_height, 0, -1): >> row = list(" " * max_time) >> for t, y in measurement_dict.items(): >> if y >= height: >> row[t] = 'X' >> print("".join(row)) >> >> My concern is whether the average 11-year-old will be able to follow such >> logic. Is there a better approach? >> >> -- >> https://mail.python.org/mailman/listinfo/python-list >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From orgnut at yahoo.com Sat Jan 4 17:20:10 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Sat, 04 Jan 2014 14:20:10 -0800 Subject: Strange behaviour with a for loop. In-Reply-To: References: <4DC5A4FC-CCAF-446B-B41C-23E52C2389B6@icloud.com> <3EA05A2F-8F5D-43D3-AB9A-B3C50C4B74A6@gmail.com> Message-ID: On 01/03/2014 10:32 PM, Sean Murphy wrote: > Hi everyone. [snip] > The 2nd part of my original question still stands. I will expand upon this a bit more to give more context. I want to print from the beginning of the paragraph to the end. Each paragraph ends with "\n\n\n". > > If I use "\n\n\n" in lines this does return true for the string. But I don't have a starting position and ending position. The list method which I mention before can be sliced by going back one element. > > Any suggestion on this would be welcomed. I want to achieve this using standard core python objects/methods. > Another useful string method is endswith(). With that you don't need to know the line length: if line.endswith('\n\n\n'): ... (Of course, there is a corresponding startswith() method also.) If you are specifically looking for blank lines, someone already suggested isspace(). Another possibility is rstrip(), which will remove all trailing whitespace. So you can check for blank lines with: if line.rstrip() == '': ... There are three of these: lstrip() is left-strip, which removes leading whitespace, rstrip() is right-strip, which removes trailing whitespace, and strip() which removes whitespace from both ends. All of these are very useful functions. -=- Larry -=- From tjreedy at udel.edu Sat Jan 4 17:46:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 04 Jan 2014 17:46:49 -0500 Subject: Blog "about python 3" In-Reply-To: <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: On 1/4/2014 2:10 PM, wxjmfauth at gmail.com wrote: > Le samedi 4 janvier 2014 15:17:40 UTC+1, Chris Angelico a ?crit : >> any, and Python has only one, idiot like jmf who completely Chris, I appreciate the many contributions you make to this list, but that does not exempt you from out standard of conduct. >> misunderstands what's going on and uses microbenchmarks to prove >> obscure points... and then uses nonsense to try to prove... uhh... Troll baiting is a form of trolling. I think you are intelligent enough to know this. Please stop. > I do not mind to be considered as an idiot, but > I'm definitively not blind. > > And I could add, I *never* saw once one soul, who is > explaining what I'm doing wrong in the gazillion > of examples I gave on this list. If this is true, it is because you have ignored and not read my numerous, relatively polite posts. To repeat very briefly: 1. Cherry picking (presenting the most extreme case as representative). 2. Calling space saving a problem (repeatedly). 3. Ignoring bug fixes. 4. Repetition (of the 'gazillion example' without new content). Have you ever acknowledged, let alone thank people for, the fix for the one bad regression you did find. The FSR is still a work in progress. Just today, Serhiy pushed a patch speeding up the UTF-32 encoder, after previously speeding up the UTF-32 decoder. -- Terry Jan Reedy From mcepl at redhat.com Sat Jan 4 17:57:40 2014 From: mcepl at redhat.com (Matej Cepl) Date: Sat, 4 Jan 2014 23:57:40 +0100 Subject: [ANN] gg_scrapper -- scrapping of the Google Groups Message-ID: <20140104225739.GA32309@wycliff.ceplovi.cz> Did you try to archive email list hosted on the Google Groups? Were you endlessly frustrated by the black hole which is Google Groups, conscpicious by its absence on the Data Liberation Front website? Yes, I was too_ So, I have created a script webscrapping a google group and created gg_scrapper_ . Thanks to `Sean Hogan`_ for the first inspiration for the script. Any comments would be welcome via email (I am sure you can find my addresses somewhere on the Web). Best, Mat?j .. _too: http://matej.ceplovi.cz/blog/2013/09/we-should-stop-even-pretending-google-is-trying-to-do-the-right-thing/ .. _gg_scrapper: https://pypi.python.org/pypi/gg_scrapper .. _`Sean Hogan`: http://matej.ceplovi.cz/blog/2013/09/we-should-stop-even-pretending-google-is-trying-to-do-the-right-thing/#comment-482 -- http://www.ceplovi.cz/matej/, Jabber: mceplceplovi.cz GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC <"}}}>< -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 190 bytes Desc: not available URL: From dwightdhutto at gmail.com Sat Jan 4 16:03:18 2014 From: dwightdhutto at gmail.com (David Hutto) Date: Sat, 4 Jan 2014 16:03:18 -0500 Subject: Flip a graph In-Reply-To: References: Message-ID: I would definitely utilize y axis as an altitudinal derivative of time,x. I'd go with more of a dart type of graphic, so you might be able to show a peak in altitude from take off, and the rotate the graphic in relation to the deceleration . But, you could also depict the velocity, fuel rate, etc with different colored plots, or as a side meter alongside the canvas the plot is being displayed on. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Jan 4 18:11:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 10:11:09 +1100 Subject: [newbie] Recursive algorithm - review In-Reply-To: <17yrxkdy2ipni$.1k46s6c6xxte4$.dlg@40tude.net> References: <17yrxkdy2ipni$.1k46s6c6xxte4$.dlg@40tude.net> Message-ID: On Sun, Jan 5, 2014 at 6:07 AM, Wiktor wrote: > On Sat, 4 Jan 2014 01:16:14 +0100, Wiktor wrote: > Idea is still the same. I start with 2d array > And then I fill it up one number by one (exception: first row). At every step > checking if current column is unique (0's not counted) and if also current > segment 3x3 is unique. If that condition is True I call another instance of > generate(), passing to it a) the board, b) the position in which I last putted > number, and c) a list of numbers that in next step this function can choose > from (if empty, function will generate new list). And so on. > If that condition is False, I try another number from list of available > numbers, and check again. If all numbers fail, I go back one level and try > another number on previous position. That's a reasonable brute-force algorithm. I'll get onto some alternatives down below. > def check(board, x=None, sudoku=False): You seem here to have two completely different programs that share almost no code. This is going to cause confusion, more than anything else. I recommend saving away the other program and making the Sudoku one completely separate.programs. > if sudoku and len(board) == 9 and x is not None: > c = x % len(board) > r = x // len(board) Your algorithm involves a *lot* of division. This may be a premature optimization (I haven't measured to see if that's actually a bottleneck), but I would consider rejigging things to minimize this. (Edit: It almost certainly *is* premature to try to cut out division. Much better targets elsewhere.) > br_min, br_max = r//3 * 3, r//3 * 3 + 3 > bc_min, bc_max = c//3 * 3, c//3 * 3 + 3 > block = [t[bc_min:bc_max] for t in board[br_min:br_max]] You can define max in terms of min, here. I think it'd be clearer than doing the division again (plus it might be faster, see above): br = r//3 * 3 bc = c//3 * 3 block = [t[bc:bc+3] for t in board[br:br+3]] > return len(column) == len(set(column)) and \ > len(block_flat) == len(set(block_flat)) Style point: In Python, it's more normal to bracket conditions like that, rather than use a backslash. return (len(column) == len(set(column)) and len(block_flat) == len(set(block_flat))) > elif sudoku and len(board) == 9: > return all((check(board, i, sudoku) for i in range(0, > len(board)**2, > 4))) Ultimately, this is testing to see if the board state is valid. It does this in 81 steps (len(board) squared), each one checking the column and the block for validity, and not checking the row, because you assume that to be valid elsewhere. (This last bit is worthy of a code comment, I think.) Instead, you could simply check the nine columns and the nine blocks, iteratively. > def generate(size=4, board=None, row=None, x=0, sudoku=False): > while repeat: > x += 1 > num = row.pop(0) > board[x // size][x % size] = num > repeat = not check(board, x, sudoku) > > if repeat: > row.append(num) > board[x // size][x % size] = 0 > x -= 1 > attempt += 1 > > if attempt > len(row) - 1: > return False > else: > if not generate(size, board, row, x, sudoku): > repeat = True > row.append(num) > board[x // size][x % size] = 0 > x -= 1 > attempt += 1 > > if attempt > len(row) - 1: > return False > > return board Code's getting complicated, I'm getting bogged down in the indentation levels. Is it possible to break out some of this into separate functions? You're calling the same function in different modes; stuff's getting a bit messy. > OK, it works fine. Most of the time it generates board in less than 400 > attempts, so not so bad. But sometimes it takes over thousand tries to generate > board. That's the result of a brute-force algorithm. You're working top-down and rolling back step by step. It's simple but not fast. Here's the code for my Binary Sudoku engine. It's not in Python (it's Pike - semantically similar, but uses a C-like syntax), but hopefully you should be able to see what it's doing. https://github.com/Rosuav/binary There are three distinct parts to it: 1) Validate a state 2) Attempt to solve, by logic 3) Generate a puzzle The key here is that step 2 uses the same techniques that a human would use. In the case of Sudoku, that would basically mean implementing the techniques you'd find on a Sudoku solving help web site (eg figuring out that the only digit legal in this spot is a 3). That's going to be far FAR more efficient than brute force, and it'll take you a long way. Then in step 3, you simply do this: 1) Place a random digit at a random position on the grid. 2) Attempt to solve (call the previous function). 2a) If, at any time, the state comes up invalid, remove this digit. 2b) Otherwise, this digit is now canon. Make it part of the puzzle. 3) While there are empty spaces on the grid, go to 1. (In step 2b, I distinguish between the current solved state and the printed puzzle. That's an optional distinction.) > Now, my question is - should I implement mechanism that recognises this kind > of situation, and jumps back (let's say) 9 levels of recursion at once? My > guess is that it will take me at least several hours to solve this properly. > Also, now it's simple algorithm, and if I start to tamper with it, it will > overgrow by many conditions, and extra arguments. Won't be so clear anymore. > Or maybe I should accept that this is how recursion works, and let go? > What would you do? > Or maybe there's better way to generate pseudo-random Sudoku board? Not by > recursion. Or maybe by recursion, but nicer with less attempts in those kind of > situation? I guess that some kind of you have done this before. ;-) > Any tips? Messing with a brute-force algorithm can get really hairy. Changing algorithm completely is far more effective. :) My method as described above is still recursive, but by solving by rules rather than brute force, it's guaranteed to resolve more quickly. The brute force method you're using will shuffle a row and then attempt each one, which is pretty much the same as the absolute simplest method: place every possible digit in every possible slot. That means that the worst-case is 10**81 attempts, which is faintly ridiculous :) By attempting to solve it at each iteration, your iterations will be slower, but you'll have 10*81 (multiplication rather than exponentiation) possibilities. Or alternatively, you could part-solve the grid and pick whichever slot has the least possibilities (if it's 0, the state's unsolvable, if it's 1, you have a certainty, and otherwise you try them all). That would be a reasonably simple algorithm that'd probably average out at about 3**81 attempts to brute-force the grid. Much better! :) ChrisA From rosuav at gmail.com Sat Jan 4 18:28:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 10:28:37 +1100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: On Sun, Jan 5, 2014 at 9:46 AM, Terry Reedy wrote: > On 1/4/2014 2:10 PM, wxjmfauth at gmail.com wrote: >> >> Le samedi 4 janvier 2014 15:17:40 UTC+1, Chris Angelico a ?crit : > > >>> any, and Python has only one, idiot like jmf who completely > > > Chris, I appreciate the many contributions you make to this list, but that > does not exempt you from out standard of conduct. > > >>> misunderstands what's going on and uses microbenchmarks to prove >>> obscure points... and then uses nonsense to try to prove... uhh... > > > Troll baiting is a form of trolling. I think you are intelligent enough to > know this. Please stop. My apologies. I withdraw the aforequoted post. You and Ned are correct, those comments were inappropriate. Sorry. ChrisA From ikorot01 at gmail.com Sat Jan 4 18:30:17 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sat, 4 Jan 2014 15:30:17 -0800 Subject: django question Message-ID: Hi, ALL, Does anybody here use django? I have a very basic question about it. Is it possible to display a data grid table with django? Basically I am looking for displaying a data from the db table on the web interface thru django or some other web interface. My main application is in Python, that's why I'd like to explore Python possibilities first. Thank you. From joel.goldstick at gmail.com Sat Jan 4 18:44:45 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sat, 4 Jan 2014 18:44:45 -0500 Subject: django question In-Reply-To: References: Message-ID: On Sat, Jan 4, 2014 at 6:30 PM, Igor Korot wrote: > Hi, ALL, > Does anybody here use django? > I have a very basic question about it. > > Is it possible to display a data grid table with django? > Yes, using the django template language. If you learn django (perhaps 2 days of exploring), you would have the skills to do this. Check out the django tutorial > Basically I am looking for displaying a data from the db table on the > web interface thru django or some other web interface. > My main application is in Python, that's why I'd like to explore > Python possibilities first. > > Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From python.list at tim.thechases.com Sat Jan 4 20:37:05 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sat, 4 Jan 2014 19:37:05 -0600 Subject: django question In-Reply-To: References: Message-ID: <20140104193705.0db361cc@bigbox.christie.dr> On 2014-01-04 15:30, Igor Korot wrote: > Does anybody here use django? Yes. However there's also a Django-users mailing list[1] for Django-specific questions. Folks there are friendly & helpful. > Is it possible to display a data grid table with django? The short answer is yes. > Basically I am looking for displaying a data from the db table on > the web interface thru django or some other web interface. While I prefer Django for larger projects, for a lighter-weight project such as what you describe, I'd be tempted to go with something a little more light-weight unless you need additional interactivity. I've recently been impressed with Bottle[2] for a small & clean web framework. CherryPy comes somewhere in the middle, but I can't say it met my needs/wants on the last project where it was chosen (mostly in the documentation department, but it's hard to beat Django's stellar docs). -tkc [1] http://groups.google.com/group/django-users [2] http://bottlepy.org/ From research at johnohagan.com Sat Jan 4 20:40:46 2014 From: research at johnohagan.com (John O'Hagan) Date: Sun, 5 Jan 2014 12:40:46 +1100 Subject: Update image in same window with, say, PIL Message-ID: <20140105124046.0ef46e53@mini.home> I'm using something like the following to display an image and refresh it in the same window each time the image file is updated: import cv def display(filename): """Display scores as they are created""" cv.NamedWindow(filename) while 1: ... #wait for signal that filename has been updated, #or to break image = cv.LoadImage(filename) cv.ShowImage(filename, image) cv.WaitKey(1000) I would like to do the same thing using PIL, for two reasons. First, the main project is written in Python 3, but cv is only available in Python 2, so I have to launch the above as a separate process and do IPC with it, which is annoying; whereas PIL has recently come into Python 3. Second, PIL seems like a more appropriate tool. CV is a sophisticated computer-vision project which I happen to be more familiar with, but I'm using it just to display an image, so I feel as if I'm using the Mars Explorer to vacuum my apartment. I have found a couple of StackOverflow and ActiveState recipes to do this but they all seem to involve great globs of windowing code involving Tkinter or Qt, which I know nothing about. CV does seem to magically manage the windowing. Can I do this equally simply with PIL, or perhaps something else in Python 3? Thanks, -- John From steve+comp.lang.python at pearwood.info Sat Jan 4 21:27:13 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jan 2014 13:27:13 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> Message-ID: <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> Surely everybody prefers fast but incorrect code in >> preference to something that is correct but slow? > > I realize I'm taking this statement out of context, but yes, sometimes > fast is more important than correct. I know somebody who was once touring in the States, and ended up travelling cross-country by road with the roadies rather than flying. She tells me of the time someone pointed out that they were travelling in the wrong direction, away from their destination. The roadie driving replied "Who cares? We're making fantastic time!" (Ah, the seventies. So many drugs...) Fast is never more important than correct. It's just that sometimes you might compromise a little (or a lot) on what counts as correct in order for some speed. To give an example, say you want to solve the Travelling Salesman Problem, and find the shortest path through a whole lot of cities A, B, C, ..., Z. That's a Hard Problem, expensive to solve correctly. But if you loosen the requirements so that a correct solution no longer has to be the absolutely shortest path, and instead accept solutions which are nearly always close to the shortest (but without any guarantee of how close), then you can make the problem considerably easier to solve. But regardless of how fast your path-finder algorithm might become, you're unlikely to be satisfied with a solution that travels around in a circle from A to B a million times then shoots off straight to Z without passing through any of the other cities. -- Steven From rosuav at gmail.com Sat Jan 4 21:32:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 13:32:44 +1100 Subject: Blog "about python 3" In-Reply-To: <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 5, 2014 at 1:27 PM, Steven D'Aprano wrote: > But regardless of how fast your path-finder algorithm might become, you're > unlikely to be satisfied with a solution that travels around in a circle > from A to B a million times then shoots off straight to Z without passing > through any of the other cities. On the flip side, that might be the best salesman your company has ever known, if those three cities have the most customers! ChrisA wondering why nobody cares about the customers in TSP discussions From python at mrabarnett.plus.com Sat Jan 4 21:41:05 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 05 Jan 2014 02:41:05 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C8C641.6070102@mrabarnett.plus.com> On 2014-01-05 02:32, Chris Angelico wrote: > On Sun, Jan 5, 2014 at 1:27 PM, Steven D'Aprano > wrote: >> But regardless of how fast your path-finder algorithm might become, you're >> unlikely to be satisfied with a solution that travels around in a circle >> from A to B a million times then shoots off straight to Z without passing >> through any of the other cities. > > On the flip side, that might be the best salesman your company has > ever known, if those three cities have the most customers! > > ChrisA > wondering why nobody cares about the customers in TSP discussions > Or, for that matter, ISP customers who don't live in an urban area. :-) From steve+comp.lang.python at pearwood.info Sat Jan 4 21:41:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jan 2014 13:41:20 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> <7978ffc2-8e6a-40b2-a4c7-66990d6af1be@googlegroups.com> Message-ID: <52c8c650$0$9505$c3e8da3$5496439d@news.astraweb.com> wxjmfauth at gmail.com wrote: > The very interesting aspect in the way you are holding > unicodes (strings). By comparing Python 2 with Python 3.3, > you are comparing utf-8 with the the internal "representation" > of Python 3.3 (the flexible string represenation). This is incorrect. Python 2 has never used UTF-8 internally for Unicode strings. In narrow builds, it uses UTF-16, but makes no allowance for surrogate pairs in strings. In wide builds, it uses UTF-32. Other implementations, such as Jython or IronPython, may do something else. -- Steven From rosuav at gmail.com Sat Jan 4 21:54:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 13:54:29 +1100 Subject: Blog "about python 3" In-Reply-To: <52c8c650$0$9505$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> <7978ffc2-8e6a-40b2-a4c7-66990d6af1be@googlegroups.com> <52c8c650$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 5, 2014 at 1:41 PM, Steven D'Aprano wrote: > wxjmfauth at gmail.com wrote: > >> The very interesting aspect in the way you are holding >> unicodes (strings). By comparing Python 2 with Python 3.3, >> you are comparing utf-8 with the the internal "representation" >> of Python 3.3 (the flexible string represenation). > > This is incorrect. Python 2 has never used UTF-8 internally for Unicode > strings. In narrow builds, it uses UTF-16, but makes no allowance for > surrogate pairs in strings. In wide builds, it uses UTF-32. That's for Python's unicode type. What Robin said was that they were using either a byte string ("str") with UTF-8 data, or a Unicode string ("unicode") with character data. So jmf was right, except that it's not specifically to do with Py2 vs Py3.3. ChrisA From roy at panix.com Sat Jan 4 22:20:40 2014 From: roy at panix.com (Roy Smith) Date: Sat, 04 Jan 2014 22:20:40 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: I wrote: > > I realize I'm taking this statement out of context, but yes, sometimes > > fast is more important than correct. In article <52c8c301$0$29998$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Fast is never more important than correct. Sure it is. Let's imagine you're building a system which sorts packages for delivery. You sort 1 million packages every night and put them on trucks going out for final delivery. Some assumptions: Every second I can cut from the sort time saves me $0.01. If I mis-sort a package, it goes out on the wrong truck, doesn't get discovered until the end of the day, and ends up costing me $5 (including not just the direct cost of redelivering it, but also factoring in ill will and having to make the occasional refund for not meeting the promised delivery time). I've got a new sorting algorithm which is guaranteed to cut 10 seconds off the sorting time (i.e. $0.10 per package). The problem is, it makes a mistake 1% of the time. Let's see: 1 million packages x $0.10 = $100,000 saved per day because I sort them faster. 10,000 of them will go to the wrong place, and that will cost me $50,000 per day. By going fast and making mistakes once in a while, I increase my profit by $50,000 per day. The numbers above are fabricated, but I'm sure UPS, FexEx, and all the other package delivery companies are doing these sorts of analyses every day. I watch the UPS guy come to my house. He gets out of his truck, walks to my front door, rings the bell, waits approximately 5 microseconds, leaves the package on the porch, and goes back to his truck. I'm sure UPS has figured out that the amortized cost of the occasional stolen or lost package is less than the cost for the delivery guy to wait for me to come to the front door and sign for the delivery. Looking at another problem domain, let's say you're a contestant on Jeopardy. If you listen to the entire clue and spend 3 seconds making sure you know the correct answer before hitting the buzzer, it doesn't matter if you're right or wrong. Somebody else beat you to the buzzer, 2.5 seconds ago. Or, let's take an example from sports. I'm standing at home plate holding a bat. 60 feet away from me, the pitcher is about to throw a baseball towards me at darn close to 100 MPH (insert words like "bowl" and "wicket" as geographically appropriate). 400 ms later, the ball is going to be in the catcher's glove if you don't hit it. If you have an absolutely perfect algorithm to determining if it's a ball or a strike, which takes 500 ms to run, you're going back to the minor leagues. If you have a 300 ms algorithm which is right 75% of the time, you're heading to the hall of fame. From alec.taylor6 at gmail.com Sat Jan 4 22:50:18 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 5 Jan 2014 14:50:18 +1100 Subject: Suggest an open-source log analyser? In-Reply-To: References: Message-ID: Because I'm thinking that something with a much less expressive query interface would serve me better in the long run... e.g.: Redis or maybe Hadoop On Sat, Jan 4, 2014 at 5:35 PM, Walter Hurry wrote: > On Thu, 02 Jan 2014 16:40:19 +1100, Alec Taylor wrote: > >> I use the Python logger class; with the example syntax of: >> Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') >> >> Can of course easily use e.g.: a JSON syntax here instead. >> >> Are there any open-source log viewers (e.g.: with a web-interface) >> that you'd recommend; for drilling down into my logs? >> > If you want to do in-depth analysis, why not just stick it into an SQL > database; e.g. SQLite or Postgres? > > -- > https://mail.python.org/mailman/listinfo/python-list From alec.taylor6 at gmail.com Sat Jan 4 22:58:22 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 5 Jan 2014 14:58:22 +1100 Subject: =?windows-1252?Q?Using_multiple_ORMs=3F_=2D_And_SQLalchemy_vs_Pony_vs_Pee?= =?windows-1252?Q?wee_vs_stdnet_vs_=85?= Message-ID: Investigating possible using multiple ORMs in my project. Toy project, want to make it as generic as humanly possible; whilst still exposing abstract pythonic interfaces. E.g.: support most number of backends, including SQL ones like: Postgres, SQLite, MySQL, ? and NoSQL ones such as Redis (using python-stdnet). One way of doing this is to write generic Python libraries; with different models, insert and query lines for each of the backend ORMs. What are your thoughts on this? Additionally, there are a variety of new ORMs popping up, what are your thoughts on them; and is there something other than the 4 mentioned in the subject which I should look into? Thanks for all suggestions, Alec Taylor From rustompmody at gmail.com Sat Jan 4 23:42:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 5 Jan 2014 10:12:47 +0530 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 5, 2014 at 8:50 AM, Roy Smith wrote: > I wrote: >> > I realize I'm taking this statement out of context, but yes, sometimes >> > fast is more important than correct. > > In article <52c8c301$0$29998$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: >> Fast is never more important than correct. > > Sure it is. > > Let's imagine you're building a system which sorts packages for > delivery. You sort 1 million packages every night and put them on > trucks going out for final delivery. > > Some assumptions: > > Every second I can cut from the sort time saves me $0.01. > > If I mis-sort a package, it goes out on the wrong truck, doesn't get > discovered until the end of the day, and ends up costing me $5 > (including not just the direct cost of redelivering it, but also > factoring in ill will and having to make the occasional refund for not > meeting the promised delivery time). > > I've got a new sorting algorithm which is guaranteed to cut 10 seconds > off the sorting time (i.e. $0.10 per package). The problem is, it makes > a mistake 1% of the time. > > Let's see: > > 1 million packages x $0.10 = $100,000 saved per day because I sort them > faster. 10,000 of them will go to the wrong place, and that will cost > me $50,000 per day. By going fast and making mistakes once in a while, > I increase my profit by $50,000 per day. > > The numbers above are fabricated, but I'm sure UPS, FexEx, and all the > other package delivery companies are doing these sorts of analyses every > day. I watch the UPS guy come to my house. He gets out of his truck, > walks to my front door, rings the bell, waits approximately 5 > microseconds, leaves the package on the porch, and goes back to his > truck. I'm sure UPS has figured out that the amortized cost of the > occasional stolen or lost package is less than the cost for the delivery > guy to wait for me to come to the front door and sign for the delivery. > > Looking at another problem domain, let's say you're a contestant on > Jeopardy. If you listen to the entire clue and spend 3 seconds making > sure you know the correct answer before hitting the buzzer, it doesn't > matter if you're right or wrong. Somebody else beat you to the buzzer, > 2.5 seconds ago. > > Or, let's take an example from sports. I'm standing at home plate > holding a bat. 60 feet away from me, the pitcher is about to throw a > baseball towards me at darn close to 100 MPH (insert words like "bowl" > and "wicket" as geographically appropriate). 400 ms later, the ball is > going to be in the catcher's glove if you don't hit it. If you have an > absolutely perfect algorithm to determining if it's a ball or a strike, > which takes 500 ms to run, you're going back to the minor leagues. If > you have a 300 ms algorithm which is right 75% of the time, you're > heading to the hall of fame. Neat examples -- thanks Only minor quibble isnt $5 cost of mis-sorting a gross underestimate? I am reminded of a passage of Dijkstra in Discipline of Programming -- something to this effect He laments the fact that hardware engineers were not including overflow checks in machine ALUs. He explained as follows: If a test is moderately balanced (statistically speaking) a programmer will not mind writing an if statement If however the test is very skew -- say if 99% times, else 1% -- he will tend to skimp on the test, producing 'buggy' code [EWD would never use the bad b word or course] The cost equation for hardware is very different -- once the investment in the silicon is done with -- fixed cost albeit high -- there is no variable cost to executing that circuitry once or a zillion times Moral of Story: Intel should take up FSR [Ducks and runs for cover] From roy at panix.com Sun Jan 5 00:11:13 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 00:11:13 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Rustom Mody wrote: > On Sun, Jan 5, 2014 at 8:50 AM, Roy Smith wrote: > > I wrote: > >> > I realize I'm taking this statement out of context, but yes, sometimes > >> > fast is more important than correct. > > > > In article <52c8c301$0$29998$c3e8da3$5496439d at news.astraweb.com>, > > Steven D'Aprano wrote: > >> Fast is never more important than correct. > > > > Sure it is. > > > > Let's imagine you're building a system which sorts packages for > > delivery. You sort 1 million packages every night and put them on > > trucks going out for final delivery. > > > > Some assumptions: > > > > Every second I can cut from the sort time saves me $0.01. > > > > If I mis-sort a package, it goes out on the wrong truck, doesn't get > > discovered until the end of the day, and ends up costing me $5 > > (including not just the direct cost of redelivering it, but also > > factoring in ill will and having to make the occasional refund for not > > meeting the promised delivery time). > > > > I've got a new sorting algorithm which is guaranteed to cut 10 seconds > > off the sorting time (i.e. $0.10 per package). The problem is, it makes > > a mistake 1% of the time. > > > > Let's see: > > > > 1 million packages x $0.10 = $100,000 saved per day because I sort them > > faster. 10,000 of them will go to the wrong place, and that will cost > > me $50,000 per day. By going fast and making mistakes once in a while, > > I increase my profit by $50,000 per day. > > > > The numbers above are fabricated, but I'm sure UPS, FexEx, and all the > > other package delivery companies are doing these sorts of analyses every > > day. I watch the UPS guy come to my house. He gets out of his truck, > > walks to my front door, rings the bell, waits approximately 5 > > microseconds, leaves the package on the porch, and goes back to his > > truck. I'm sure UPS has figured out that the amortized cost of the > > occasional stolen or lost package is less than the cost for the delivery > > guy to wait for me to come to the front door and sign for the delivery. > > > > Looking at another problem domain, let's say you're a contestant on > > Jeopardy. If you listen to the entire clue and spend 3 seconds making > > sure you know the correct answer before hitting the buzzer, it doesn't > > matter if you're right or wrong. Somebody else beat you to the buzzer, > > 2.5 seconds ago. > > > > Or, let's take an example from sports. I'm standing at home plate > > holding a bat. 60 feet away from me, the pitcher is about to throw a > > baseball towards me at darn close to 100 MPH (insert words like "bowl" > > and "wicket" as geographically appropriate). 400 ms later, the ball is > > going to be in the catcher's glove if you don't hit it. If you have an > > absolutely perfect algorithm to determining if it's a ball or a strike, > > which takes 500 ms to run, you're going back to the minor leagues. If > > you have a 300 ms algorithm which is right 75% of the time, you're > > heading to the hall of fame. > > > Neat examples -- thanks > Only minor quibble isnt $5 cost of mis-sorting a gross underestimate? I have no idea. Like I said, the numbers are all fabricated. I do have a friend who used to work for UPS. He told me lots of UPS efficiency stories. One of them had to do with mis-routed packages. IIRC, the process for dealing with a mis-routed package was to NOT waste any time trying to figure out why it was mis-routed. It was just thrown back into the input hopper to go through the whole system again. The sorting software kept track of how many times it had sorted a particular package. Only after N attempts (where N was something like 3), was it kicked out of the automated process for human intervention. From steve+comp.lang.python at pearwood.info Sun Jan 5 01:28:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jan 2014 17:28:14 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52c8fb7f$0$29969$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > I wrote: >> > I realize I'm taking this statement out of context, but yes, sometimes >> > fast is more important than correct. > > In article <52c8c301$0$29998$c3e8da3$5496439d at news.astraweb.com>, > Steven D'Aprano wrote: >> Fast is never more important than correct. > > Sure it is. Sure it isn't. I think you stopped reading my post too early. None of your examples contradict what I am saying. They all involve exactly the same sort of compromise regarding "correctness" that I'm talking about, where you loosen what counts as "correct" for the purpose of getting extra speed. So, for example: > Let's imagine you're building a system which sorts packages for > delivery. You sort 1 million packages every night and put them on > trucks going out for final delivery. What's your requirement, i.e. what counts as "correct" for the delivery algorithm being used? Is it that every parcel is delivered to the specified delivery address the first time? No it is not. What counts as "correct" for the delivery algorithm is something on the lines of "No less than 95% of parcels will be sorted correctly and delivered directly; no more than 5% may be mis-sorted at most three times" (or some similar requirement). It may even been that the requirements are even looser, e.g.: "No more than 1% of parcels will be lost/damaged/stolen/destroyed" in which case they don't care unless a particular driver loses or destroys more than 1% of his deliveries. But if it turns out that Fred is dumping every single one of his parcels straight into the river, the fact that he can make thirty deliveries in the time it takes other drivers to make one will not save his job. "But it's much faster to dump the parcels in the river" does not matter. What matters is that the deliveries are made within the bounds of allowable time and loss. Things get interesting when the people setting the requirements and the people responsible for meeting those requirements aren't able to agree. Then you have customers who complain that the software is buggy, and developers who complain that the customer requirements are impossible to provide. Sometimes they're both right. > Looking at another problem domain, let's say you're a contestant on > Jeopardy. If you listen to the entire clue and spend 3 seconds making > sure you know the correct answer before hitting the buzzer, it doesn't > matter if you're right or wrong. Somebody else beat you to the buzzer, > 2.5 seconds ago. I've heard of Jeopardy, but never seen it. But I know about game shows, and in this case, what you care about is *winning the game*, not answering the questions correctly. Answering the questions correctly is only a means to the end, which is "Win". If the rules allow it, your best strategy might even be to give wrong answers, every time! (It's not quite a game show, but the British quiz show QI is almost like that. The rules, if there are any, encourage *interesting* answers over correct answers. Occasionally that leads to panelists telling what can best be described as utter porkies[1].) If Jeopardy does not penalise wrong answers, the "best" strategy might be to jump in with an answer as quickly as possible, without caring too much about whether it is the right answer. But if Jeopardy penalises mistakes, then the "best" strategy might be to take as much time as you can to answer the question, and hope for others to make mistakes. That's often the strategy in Test cricket: play defensively, and wait for the opposition to make a mistake. > Or, let's take an example from sports. I'm standing at home plate > holding a bat. 60 feet away from me, the pitcher is about to throw a > baseball towards me at darn close to 100 MPH (insert words like "bowl" > and "wicket" as geographically appropriate). 400 ms later, the ball is > going to be in the catcher's glove if you don't hit it. If you have an > absolutely perfect algorithm to determining if it's a ball or a strike, > which takes 500 ms to run, you're going back to the minor leagues. If > you have a 300 ms algorithm which is right 75% of the time, you're > heading to the hall of fame. And if you catch the ball, stick it in your pocket and race through all the bases, what's that? It's almost certainly faster than trying to play by the rules. If speed is all that matters, that's what people would do. But it isn't -- the "correct" strategy depends on many different factors, one of which is that you have a de facto time limit on deciding whether to swing or let the ball through. Your baseball example is no different from the example I gave before. "Find the optimal path for the Travelling Salesman Problem in a week's time", versus "Find a close to optimal path in three minutes" is conceptually the same problem, with the same solution: an imperfect answer *now* can be better than a perfect answer *later*. [1] Porkies, or "pork pies", from Cockney rhyming slang. -- Steven From rosuav at gmail.com Sat Jan 4 23:01:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 15:01:22 +1100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 5, 2014 at 2:20 PM, Roy Smith wrote: > I've got a new sorting algorithm which is guaranteed to cut 10 seconds > off the sorting time (i.e. $0.10 per package). The problem is, it makes > a mistake 1% of the time. That's a valid line of argument in big business, these days, because we've been conditioned to accept low quality. But there are places where quality trumps all, and we're happy to pay for that. Allow me to expound two examples. 1) Amazon http://www.amazon.com/exec/obidos/ASIN/1782010165/evertype-20 I bought this book a while ago. It's about the size of a typical paperback. It arrived in a box too large for it on every dimension, with absolutely no packaging. I complained. Clearly their algorithm was: "Most stuff will get there in good enough shape, so people can't be bothered complaining. And when they do complain, it's cheaper to ship them another for free than to debate with them on chat." Because that's what they did. Fortunately I bought the book for myself, not for a gift, because the *replacement* arrived in another box of the same size, with ... one little sausage for protection. That saved it in one dimension out of three, so it arrived only slightly used-looking instead of very used-looking. And this a brand new book. When I complained the second time, I was basically told "any replacement we ship you will be exactly the same". Thanks. 2) Bad Monkey Productions http://kck.st/1bgG8Pl The cheapest the book itself will be is $60, and the limited edition early ones are more (I'm getting the gold level book, $200 for one of the first 25 books, with special sauce). The people producing this are absolutely committed to quality, as are the nearly 800 backers. If this project is delayed slightly in order to ensure that we get something fully awesome, I don't think there will be complaints. This promises to be a beautiful book that'll be treasured for generations, so quality's far FAR more important than the exact delivery date. I don't think we'll ever see type #2 become universal, for the same reason that people buy cheap Chinese imports in the supermarket rather than something that costs five times as much from a specialist. The expensive one might be better, but why bother? When the cheap one breaks, you just get another. The expensive one might fail too, so why take that risk? But it's always a tradeoff, and there'll always be a few companies around who offer the more expensive product. (We have a really high quality cheese slicer. It's still the best I've seen, after something like 20 years of usage.) Fast or right? It'd have to be really *really* fast to justify not being right, unless the lack of rightness is less than measurable (like representing time in nanoseconds - anything smaller than that is unlikely to be measurable on most computers). ChrisA From elearn2014 at gmail.com Sun Jan 5 02:38:13 2014 From: elearn2014 at gmail.com (luofeiyu) Date: Sun, 05 Jan 2014 15:38:13 +0800 Subject: print range in python3.3 Message-ID: <52C90BE5.3010909@gmail.com> >>> range(1,10) range(1, 10) >>> print(range(1,10)) range(1, 10) how can i get 1,2,3,4,5,6,7,8,9 in python3.3 ? From rosuav at gmail.com Sun Jan 5 02:56:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 18:56:42 +1100 Subject: print range in python3.3 In-Reply-To: <52C90BE5.3010909@gmail.com> References: <52C90BE5.3010909@gmail.com> Message-ID: On Sun, Jan 5, 2014 at 6:38 PM, luofeiyu wrote: >>>> range(1,10) > range(1, 10) >>>> print(range(1,10)) > range(1, 10) > > how can i get 1,2,3,4,5,6,7,8,9 in python3.3 ? Are you looking for a list? That's what Python 2 returned. In Python 3, you can get that like this: >>> list(range(1,10)) [1, 2, 3, 4, 5, 6, 7, 8, 9] ChrisA From marco.buttu at gmail.com Sun Jan 5 02:59:08 2014 From: marco.buttu at gmail.com (Marco Buttu) Date: Sun, 05 Jan 2014 08:59:08 +0100 Subject: 3.4 on Windows ImportError: cannot import name 'IntEnum' References: Message-ID: On 01/04/2014 08:35 PM, Mark Lawrence wrote: > I first saw this when tring to run the command "py -3.4 -m ensurepip" > which gave me this lot. > > Traceback (most recent call last): ... > from enum import IntEnum > ImportError: cannot import name 'IntEnum' > > Before I raise an issue on the bug tracker can another Windows user or > two please confirm that this is a genuine problem and not my > installation being corrupt or whatever. Hi, it works for me (Windows XP, 32) -- Marco Buttu From jeanpierreda at gmail.com Sun Jan 5 03:00:24 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sun, 5 Jan 2014 00:00:24 -0800 Subject: Blog "about python 3" In-Reply-To: <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 4, 2014 at 6:27 PM, Steven D'Aprano wrote: > Fast is never more important than correct. It's just that sometimes you > might compromise a little (or a lot) on what counts as correct in order for > some speed. Is this statement even falsifiable? Can you conceive of a circumstance where someone has traded correctness for speed, but where one couldn't describe it that latter way? I can't. I think by definition you can always describe it that way, you just make "what counts as correctness" be "what the customer wants given the resources available". The conventional definition, however, is "what the customer wants, imagining that you have infinite resources". With just a little redefinition that seems reasonable, you can be made never to be wrong! I avoid making unfalsifiable arguments that aren't explicitly labeled as such. I try to reword them as, "I prefer to look at it as ..." -- it's less aggressive, which means people are more likely to really listen to what you have to say. It also doesn't pretend to be an argument when it isn't. -- Devin From breamoreboy at yahoo.co.uk Sun Jan 5 03:03:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Jan 2014 08:03:08 +0000 Subject: print range in python3.3 In-Reply-To: <52C90BE5.3010909@gmail.com> References: <52C90BE5.3010909@gmail.com> Message-ID: On 05/01/2014 07:38, luofeiyu wrote: >>>> range(1,10) > range(1, 10) >>>> print(range(1,10)) > range(1, 10) > > how can i get 1,2,3,4,5,6,7,8,9 in python3.3 ? > for i in range(1,10): print(i, end=',') print() I hope you can cope with the comma at EOL :) -- 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 Jan 5 03:15:55 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Jan 2014 08:15:55 +0000 Subject: 3.4 on Windows ImportError: cannot import name 'IntEnum' In-Reply-To: References: Message-ID: On 04/01/2014 19:35, Mark Lawrence wrote: Raised an issue anyway and then found a file caused enum.py. Whoops :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ikorot01 at gmail.com Sun Jan 5 03:24:37 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 5 Jan 2014 00:24:37 -0800 Subject: django question In-Reply-To: <20140104193705.0db361cc@bigbox.christie.dr> References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: Hi, Tim, On Sat, Jan 4, 2014 at 5:37 PM, Tim Chase wrote: > On 2014-01-04 15:30, Igor Korot wrote: >> Does anybody here use django? > > Yes. However there's also a Django-users mailing list[1] for > Django-specific questions. Folks there are friendly & helpful. Thank you for that. I didn't look too close on the django web site. ;-) > >> Is it possible to display a data grid table with django? > > The short answer is yes. > >> Basically I am looking for displaying a data from the db table on >> the web interface thru django or some other web interface. > > While I prefer Django for larger projects, for a lighter-weight > project such as what you describe, I'd be tempted to go with > something a little more light-weight unless you need additional > interactivity. I've recently been impressed with Bottle[2] for a > small & clean web framework. CherryPy comes somewhere in the middle, > but I can't say it met my needs/wants on the last project where it > was chosen (mostly in the documentation department, but it's hard to > beat Django's stellar docs). And thank you for those points as well. This piece will be for the proof of concept, which later on will go to much bigger application with reporting, plotting and different types of data presentation. Now would it be easy to switch from either on of them to django? Or is there a better choice for the main application? Thank you. > > -tkc > > [1] > http://groups.google.com/group/django-users > > [2] > http://bottlepy.org/ > > > > > -- > https://mail.python.org/mailman/listinfo/python-list From tristan at realss.com Sun Jan 5 03:35:01 2014 From: tristan at realss.com (Zhang Weiwu) Date: Sun, 5 Jan 2014 16:35:01 +0800 Subject: should error class be defined in the class it logically belongs? Message-ID: Let's say we have in livestocks.py # livestocks.py stores all livestock classes class cat() ... class Dog() ... class CanineDistemper(Exception) ''' <<< Buddy = Dog(name = "Buddy") <<< raise CanineDistemper(Buddy) # horrible test code! ''' def __init__(self, dog) self.owner = dog # a specific dog def __str__(self) return "{} has had Canine Distemper".format(self.canine) One would naturally wonder, since 1. by definition only a canine (a dog) can have CanineDistemper, and 2. in no case can CanineDistemper be raised without specifying which object (canine) is having the problem, Thus, CanineDistemper is an integral part of Canine class, and one is naturally tempted to defined CanineDistemper inside Canine class. Let some experienced OOP guy explain a bit if this line of thinking is logical, or impratical. Thanks! From ben+python at benfinney.id.au Sun Jan 5 03:49:23 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 05 Jan 2014 19:49:23 +1100 Subject: should error class be defined in the class it logically belongs? References: Message-ID: <7wr48mhkz0.fsf@benfinney.id.au> Zhang Weiwu writes: > 1. by definition only a canine (a dog) can have CanineDistemper, and > 2. in no case can CanineDistemper be raised without specifying which > object (canine) is having the problem, > > Thus, CanineDistemper is an integral part of Canine class You haven't supported that claim, and it doesn't follow from the above premises. It's not that CanineDistemper is integral to Canine, but merely that CanineDistemper is conceptually related to Canine. > and one is naturally tempted to defined CanineDistemper inside Canine > class. I'd recommend you decline that temptation. Exception classes should be defined at module level, because it makes for more readable tracebacks and there's not much to be gained from defining exception classes inside other classes. A class is a distinct namespace, and it will be more difficult for users of your module to make use of CanineDistemper if they have to reach down into the implementation of Canine in order to get at that exception class. > Let some experienced OOP guy explain a bit if this line of thinking is > logical, or impratical. Thanks! I think it's illogical, because of the way you've laid out your logic; the conclusion you assert doesn't follow from your premises. Even if you contrived a different situation where it would be logical, I think it is almost surely going to be impractical. -- \ ?Of course, everybody says they're for peace. Hitler was for | `\ peace. Everybody is for peace. The question is: what kind of | _o__) peace?? ?Noam Chomsky, 1984-05-14 | Ben Finney From maxwell34m at gmail.com Sun Jan 5 04:14:22 2014 From: maxwell34m at gmail.com (maxwell34m at gmail.com) Date: Sun, 5 Jan 2014 01:14:22 -0800 (PST) Subject: python finance In-Reply-To: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> Message-ID: <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> On Thursday, January 2, 2014 11:37:59 AM UTC, d ss wrote: > dailystockselect.com needs a couple of talented python people for the development and implementation of new trading strategies. it may be also some pythonic design change for the displayed figures now the web app consists of 1 of the 8 conceived strategies. contact us at the email on the website for more details > Samir Please this is a spam.. I've reported this as a spam. I wish everyone who sees this also reports it as spam to get the user bannned. This way GG will be a wee bit better Thanks From ian.g.kelly at gmail.com Sun Jan 5 04:16:59 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 5 Jan 2014 02:16:59 -0700 Subject: print range in python3.3 In-Reply-To: References: <52C90BE5.3010909@gmail.com> Message-ID: On Jan 5, 2014 1:04 AM, "Mark Lawrence" wrote: > > On 05/01/2014 07:38, luofeiyu wrote: >>>>> >>>>> range(1,10) >> >> range(1, 10) >>>>> >>>>> print(range(1,10)) >> >> range(1, 10) >> >> how can i get 1,2,3,4,5,6,7,8,9 in python3.3 ? >> > > for i in range(1,10): > print(i, end=',') > print() > > I hope you can cope with the comma at EOL :) print(*range(1, 10), sep=',') -------------- next part -------------- An HTML attachment was scrubbed... URL: From mhysnm1964 at gmail.com Sun Jan 5 04:25:11 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Sun, 5 Jan 2014 20:25:11 +1100 Subject: Dos cursor and input management. Message-ID: <58EDD9C8-2310-46EA-8E77-2C3B049C8BFC@gmail.com> Hi all. I am after a module that manages keyboard input. I am aware of raw_input for python 2.x and input for 3.x. They don't quite achieve what I want. I want to except a single key without printing it to the screen and then the key would perform an action. Sudo code: print line of text wait for key press If key press equals delete line. Delete list element. else if key press equals edit display line for interactive edit. else move to next line The module must work under dos for now. Eventually Mac. Sean From wxjmfauth at gmail.com Sun Jan 5 05:39:52 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 5 Jan 2014 02:39:52 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52C5A3BA.5080700@chamonix.reportlab.co.uk> <7978ffc2-8e6a-40b2-a4c7-66990d6af1be@googlegroups.com> <52c8c650$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <651bb3ec-dd9e-49ab-8475-ea78b65ed32c@googlegroups.com> Le dimanche 5 janvier 2014 03:54:29 UTC+1, Chris Angelico a ?crit?: > On Sun, Jan 5, 2014 at 1:41 PM, Steven D'Aprano > > wrote: > > > wxjmfauth at gmail.com wrote: > > > > > >> The very interesting aspect in the way you are holding > > >> unicodes (strings). By comparing Python 2 with Python 3.3, > > >> you are comparing utf-8 with the the internal "representation" > > >> of Python 3.3 (the flexible string represenation). > > > > > > This is incorrect. Python 2 has never used UTF-8 internally for Unicode > > > strings. In narrow builds, it uses UTF-16, but makes no allowance for > > > surrogate pairs in strings. In wide builds, it uses UTF-32. > > > > That's for Python's unicode type. What Robin said was that they were > > using either a byte string ("str") with UTF-8 data, or a Unicode > > string ("unicode") with character data. So jmf was right, except that > > it's not specifically to do with Py2 vs Py3.3. > > Yes, the key point is the preparation of the "unicode text" for the PDF producer. This is at this level the different flavours of Python may be relevant. I see four possibilites, I do not know what the PDF producer API is expecting. - Py2 with utf-8 byte string (ev. utf-16, utf-32) - Py2 with its internal unicode - Py3.2 with its internal unicode - Py3.3 with its internal unicode jmf From dfnsonfsduifb at gmx.de Sun Jan 5 07:14:36 2014 From: dfnsonfsduifb at gmx.de (Johannes Bauer) Date: Sun, 05 Jan 2014 13:14:36 +0100 Subject: Blog "about python 3" In-Reply-To: <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 31.12.2013 10:53, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> http://blog.startifact.com/posts/alex-gaynor-on-python-3.html. > > I quote: > > "...perhaps a brave group of volunteers will stand up and fork Python 2, and > take the incremental steps forward. This will have to remain just an idle > suggestion, as I'm not volunteering myself." > > I expect that as excuses for not migrating get fewer, and the deadline for > Python 2.7 end-of-life starts to loom closer, more and more haters^W > Concerned People will whine about the lack of version 2.8 and ask for > *somebody else* to fork Python. > > I find it, hmmm, interesting, that so many of these Concerned People who say > that they're worried about splitting the Python community[1] end up > suggesting that we *split the community* into those who have moved forward > to Python 3 and those who won't. Exactly. I don't know what exactly their problem is. I've pushed the migration of *large* projects at work to Python3 when support was pretty early and it really wasn't a huge deal. Specifically because I love pretty much every single aspect that Python3 introduced. The codec support is so good that I've never seen anything like it in any other programming language and then there's the tons of beautiful changes (div/intdiv, functools.lru_cache, print(), datetime.timedelta.total_seconds(), int.bit_length(), bytes/bytearray). Regards, Joe -- >> Wo hattest Du das Beben nochmal GENAU vorhergesagt? > Zumindest nicht ?ffentlich! Ah, der neueste und bis heute genialste Streich unsere gro?en Kosmologen: Die Geheim-Vorhersage. - Karl Kaos ?ber R?diger Thomas in dsa From steve+comp.lang.python at pearwood.info Sun Jan 5 07:28:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Sun, 05 Jan 2014 23:28:27 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52c94fec$0$29973$c3e8da3$5496439d@news.astraweb.com> Devin Jeanpierre wrote: > On Sat, Jan 4, 2014 at 6:27 PM, Steven D'Aprano > wrote: >> Fast is never more important than correct. It's just that sometimes you >> might compromise a little (or a lot) on what counts as correct in order >> for some speed. > > Is this statement even falsifiable? Can you conceive of a circumstance > where someone has traded correctness for speed, but where one couldn't > describe it that latter way? I can't. Every time some programmer "optimises" a piece of code (or, more often, *thinks* they have optimised it) which introduces bugs into the software, that's a case where somebody has traded correctness for speed where my statement doesn't apply. Sometimes the response to the subsequent bug report is "will not fix", and a retroactive change in the software requirements. ("Oh, did we say that indexing a string would return a character? We meant it would return a character, so long as the string only includes no Unicode characters in the astral planes.") Sometimes it is to revert the optimisation or otherwise fix the bug. I accept that there is sometimes a fine line here. I'm assuming that software applications have their requirements fully documented, which in the real world is hardly ever the case. Although, even if the requirements aren't always written down, often they are implicitly understood. (Although it gets very interesting when the users' understanding and the developers' understanding is different.) Take as an example this "torture test" for a mathematical sum function, where the built-in sum() gets the wrong answer but math.fsum() gets it right: py> from math import fsum py> values = [1e12, 0.0001, -1e12, 0.0001]*10000 py> fsum(values) 2.0 py> sum(values) 2.4413841796875 Here's another example of the same thing, just to prove it's not a fluke: py> values = [1e17, 1, 1, -1e17] py> fsum(values) 2.0 py> sum(values) 0.0 The reason for the different results is that fsum() tries hard to account for intermediate rounding errors and sum() does not. If you benchmark the two functions, you'll find that sum() is significantly faster than fsum. So the question to be asked is, does sum() promise to calculate floating point sums accurately? If so, then this is a bug, probably introduced by the desire for speed. But in fact, sum() does not promise to calculate floating point sums accurately. What it promises to do is to calculate the equivalent of a + b + c + ... for as many values as given, and that's exactly what it does. Conveniently, that's faster than fsum(), and usually accurate enough for most uses. Is sum() buggy? No, of course not. It does what it promises, it's just that what it promises to do falls short of "calculate floating point summations to high accuracy". Now, here's something which *would* be a bug, if sum() did it: class MyInt(int): def __add__(self, other): return MyInt(super(MyInt, self).__add__(other)) def __radd__(self, other): return MyInt(super(MyInt, self).__radd__(other)) def __repr__(self): return "MyInt(%d)" % self Adding a zero MyInt to an int gives a MyInt: py> MyInt(0) + 23 MyInt(23) so sum() should do the same thing. If it didn't, if it optimised away the actual addition because "adding zero to a number can't change anything", it would be buggy. But in fact, sum() does the right thing: py> sum([MyInt(0), 23]) MyInt(23) > I think by definition you can > always describe it that way, you just make "what counts as > correctness" be "what the customer wants given the resources > available". Not quite. "Correct" means "does what the customer wants". Or if there is no customer, it's "does what you say it will do". How do we tell when software is buggy? We compare what it actually does to the promised behaviour, or expected behaviour, and if there is a discrepancy, we call it a bug. We don't compare it to some ideal that cannot be met. A bug report that math.pi does not have infinite number of decimal places would be closed as "Will Not Fix". Likewise, if your customer pays you to solve the Travelling Salesman Problem exactly, even if it takes a week to calculate, then nothing short of a program that solves the Travelling Salesman Problem exactly will satisfy their requirements. It's no good telling the customer that you can calculate a non-optimal answer twenty times faster if they want the actual optimal answer. (Of course, you may try to persuade them that they don't really need the optimal solution, or that they cannot afford it, or that you cannot deliver and they need to compromise.) > The conventional definition, however, is "what the > customer wants, imagining that you have infinite resources". I don't think the resources really come into it. At least, certainly not *infinite* resources. fsum() doesn't require infinite resources to calculate floating point summations to high accuracy. An even more accurate (but even slower) version would convert each float into a Fraction, then add the Fractions. > With just > a little redefinition that seems reasonable, you can be made never to > be wrong! I'm never wrong because I'm always right! *wink* Let's bring this back to the claim made at the beginning. Someone (Mark?) made a facetious comment about preferring fast code to correct code. Someone else (I forget who, and am too lazy to look it up -- Roy Smith perhaps?) suggested that we accept incorrect code if it is fast quite often. But I maintain that we don't. If we did, we'd explicitly say: "Sure, I know this program calculates the wrong answer, but gosh look how fast it is!" much like a anecdote I gave about the roadie driving in the wrong direction who stated "Who cares, we're making great time!". I maintain that people don't as a rule justify incorrect code on the basis of it being fast. They claim the code isn't incorrect, that any compromises made are deliberate and not bugs: - "sum() doesn't promise to calculate floats to high accuracy, it promises to give the same answer as if you repeatedly added them with the + operator." - "We never promised 100% uptime, we promised four nines uptime." - "Our anti-virus scanner is blindingly fast, while still identifying at least 99% of all known computer viruses!" - "The Unix 'locate' command doesn't do a live search of the file system because that would be too slow, it uses a snapshot of the state of the file system." Is locate buggy because it tells you what files existed the last time the updatedb command ran, instead of what files exist right now? No, of course not. locate does exactly what it promises to do. -- Steven From rosuav at gmail.com Sun Jan 5 07:48:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 5 Jan 2014 23:48:14 +1100 Subject: Blog "about python 3" In-Reply-To: <52c94fec$0$29973$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> <52c94fec$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 5, 2014 at 11:28 PM, Steven D'Aprano wrote: > - "The Unix 'locate' command doesn't do a live search of the file > system because that would be too slow, it uses a snapshot of the > state of the file system." > > > Is locate buggy because it tells you what files existed the last time the > updatedb command ran, instead of what files exist right now? No, of course > not. locate does exactly what it promises to do. Even more strongly: We say colloquially that Google, DuckDuckGo, etc, etc, are tools for "searching the web". But they're not. They're tools for *indexing* the World Wide Web, and then searching that index. It's plausible to actually search your file system (and there are times when you want that), but completely implausible to search the (F or otherwise) web. We accept the delayed appearance of a page in the search results because we want immediate results, no waiting a month to find anything! So the difference between what's technically promised and what's colloquially described may be more than just concealing bugs - it may be the vital difference between uselessness and usefulness. And yet we like the handwave. ChrisA From breamoreboy at yahoo.co.uk Sun Jan 5 08:10:26 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Jan 2014 13:10:26 +0000 Subject: Blog "about python 3" In-Reply-To: <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 31/12/2013 09:53, Steven D'Aprano wrote: > Mark Lawrence wrote: > >> http://blog.startifact.com/posts/alex-gaynor-on-python-3.html. > > I quote: > > "...perhaps a brave group of volunteers will stand up and fork Python 2, and > take the incremental steps forward. This will have to remain just an idle > suggestion, as I'm not volunteering myself." > > I expect that as excuses for not migrating get fewer, and the deadline for > Python 2.7 end-of-life starts to loom closer, more and more haters^W > Concerned People will whine about the lack of version 2.8 and ask for > *somebody else* to fork Python. > Should the "somebody else" fork Python, in ten (ish) years time the Concerned People will be complaining that they can't port their code to Python 4 and will "somebody else" please produce version 2.9. -- 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 Jan 5 08:14:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Jan 2014 13:14:24 +0000 Subject: "More About Unicode in Python 2 and 3" Message-ID: http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ Please don't shoot the messenger :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ned at nedbatchelder.com Sun Jan 5 08:22:38 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 05 Jan 2014 08:22:38 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/14 8:14 AM, Mark Lawrence wrote: > http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ > > Please don't shoot the messenger :) > With all of the talk about py 2 vs. py3 these days, this is the blog post that I think deserves the most real attention. I haven't had to do the kind of coding that Armin is talking about, but I've heard more than one person talk about the difficulty of it in Python 3. If anyone wants Python 3 uptake improved, the best thing would be to either explain to Armin how he missed the easy way to do what he wants (seems unlikely), or advocate to the core devs why they should change things to improve this situation. -- Ned Batchelder, http://nedbatchelder.com From rosuav at gmail.com Sun Jan 5 08:34:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 00:34:50 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 12:14 AM, Mark Lawrence wrote: > http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ > > Please don't shoot the messenger :) Most of that is tiresome reiterations of the same arguments ("It worked fine, there were just a few problems" - which means that you haven't thought through text vs bytes properly; the switch to Py3 highlights a problem that was already there, which means that Py3 showed up what was already a problem - sounds a bit like Romans 7 to me), plus complaints that have been heard elsewhere, like the encode/decode methods and the removal of codecs that aren't str<->bytes. (Don't know if that one will ever be resolved, but it's not enough to say that Python 3 "got it wrong". As we've seen from 3.3, there has been a progressive improvement in compatibility between Py2 and Py3. Maybe 3.5 will recreate some of these things people are moaning about the lack of, which would then prove that the Py3 model isn't fundamentally flawed by their loss. Anyhow.) But this bit looks odd: """ For instance passing a urllib request object to Flask's JSON parse function breaks on Python 3 but works on Python 2 as a result of this: >>> from urllib.request import urlopen >>> r = urlopen('https://pypi.python.org/pypi/Flask/json') >>> from flask import json >>> json.load(r) Traceback (most recent call last): File "decoder.py", line 368, in raw_decode StopIteration During handling of the above exception, another exception occurred: Traceback (most recent call last): File "", line 1, in ValueError: No JSON object could be decoded """ Why is a StopIteration bubbling up? (I don't have Flask, so I can't verify this.) Is it as simple as "this should be raising from None", or is there something else going on? ChrisA From rosuav at gmail.com Sun Jan 5 08:55:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 00:55:03 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 12:22 AM, Ned Batchelder wrote: > If anyone wants Python 3 uptake improved, the best thing would be to either > explain to Armin how he missed the easy way to do what he wants (seems > unlikely), or advocate to the core devs why they should change things to > improve this situation. I'm not sure that there is an "easy way". See, here's the deal. If all your data is ASCII, you can shut your eyes to the difference between bytes and text and Python 2 will work perfectly for you. Then some day you'll get a non-ASCII character come up (or maybe you'll get all of Latin-1 "for free" and it's when you get a non-Latin-1 character - same difference), and you start throwing in encode() and decode() calls in places. But you feel like you're fixing little problems with little solutions, so it's no big deal. Making the switch to Python 3 forces you to distinguish bytes from text, even when that text is all ASCII. Suddenly that's a huge job, a huge change through all your code, and it's all because of this switch to Python 3. The fact that you then get the entire Unicode range "for free" doesn't comfort people who are dealing with URLs and are confident they'll never see anything else (if they *do* see anything else, it's a bug at the far end). Maybe it's the better way, but like trying to get people to switch from MS Word onto an open system, it's far easier to push for Open Office than for LaTeX. Getting your head around a whole new way of thinking about your data is work, and people want to be lazy. (That's not a bad thing, by the way. Laziness means schedules get met.) So what can be done about it? Would it be useful to have a type that represents an ASCII string? (Either 'bytes' or something else, it doesn't matter what.) I'm inclined to say no, because as of the current versions, encoding/decoding UTF-8 has (if I understand correctly) been extremely optimized in the specific case of an all-ASCII string; so the complaint that there's no "string formatting for bytes" could be resolved by simply decoding to str, then encoding to bytes. I'd look on that as having two costs, a run-time performance cost and a code readability cost, and then look at reducing each of them - but without blurring the bytes/text distinction. Yes, that distinction is a cost. It's like any other mental cost, and it just has to be paid. The only way to explain it is that Py2 has the "cost gap" between ASCII (or Latin-1) and the rest of Unicode, but Py3 puts that cost gap before ASCII, and then gives you all of Unicode for the same low price (just $19.99 a month, you won't even notice the payments!). Question, to people who have large Py2 codebases that manipulate mostly-ASCII text. How bad would it be to your code to do this: # Py2: build a URL url = "http://my.server.name/%s/%s" % (path, fn) # Py3: build a URL as bytes def B(s): if isinstance(s, str): return s.encode() return s.decode() url = B(B(b"http://my.server.name/%s/%s") % (path, fn)) ? This little utility function lets you do the formatting as text (let's assume the URL pattern comes from somewhere else, or you'd just strip off the b'' prefix), while still mostly working with bytes. Is it an unacceptable level of code clutter? ChrisA From stefan_ml at behnel.de Sun Jan 5 08:55:46 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 05 Jan 2014 14:55:46 +0100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> Message-ID: Johannes Bauer, 05.01.2014 13:14: > I've pushed the > migration of *large* projects at work to Python3 when support was pretty > early and it really wasn't a huge deal. I think there are two sides to consider. Those who can switch their code base to Py3 and be happy (as you did, apparently), and those who cannot make the switch but have to keep supporting Py2 until 'everyone' else has switched, too. The latter is a bit more work generally and applies mostly to Python packages on PyPI, i.e. application dependencies. There are two ways to approach that problem. One is to try convincing people that "Py3 has failed, let's stop migrating more code before I have to start migrating mine", and the other is to say "let's finish the migration and get it done, so that we can finally drop Py2 support in our new releases and clean up our code again". As long as we stick in the middle and keep the status quo, we keep the worst of both worlds. And, IMHO, pushing loudly for a Py2.8 release provides a very good excuse for others to not finish their part of the migration, thus prolonging the maintenance burden for those who already did their share. Maybe a couple of major projects should start dropping their Py2 support, just to make their own life easier and to help others in taking their decision, too. (And that's me saying that, who maintains two major projects that still have legacy support for Py2.4 ...) Stefan From wxjmfauth at gmail.com Sun Jan 5 09:23:30 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sun, 5 Jan 2014 06:23:30 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: Le samedi 4 janvier 2014 23:46:49 UTC+1, Terry Reedy a ?crit?: > On 1/4/2014 2:10 PM, wxjmfauth at gmail.com wrote: > > > Le samedi 4 janvier 2014 15:17:40 UTC+1, Chris Angelico a ?crit : > > > > >> any, and Python has only one, idiot like jmf who completely > > > > Chris, I appreciate the many contributions you make to this list, but > > that does not exempt you from out standard of conduct. > > > > >> misunderstands what's going on and uses microbenchmarks to prove > > >> obscure points... and then uses nonsense to try to prove... uhh... > > > > Troll baiting is a form of trolling. I think you are intelligent enough > > to know this. Please stop. > > > > > I do not mind to be considered as an idiot, but > > > I'm definitively not blind. > > > > > > And I could add, I *never* saw once one soul, who is > > > explaining what I'm doing wrong in the gazillion > > > of examples I gave on this list. > > > > If this is true, it is because you have ignored and not read my > > numerous, relatively polite posts. To repeat very briefly: > > > > 1. Cherry picking (presenting the most extreme case as representative). > > > > 2. Calling space saving a problem (repeatedly). > > > > 3. Ignoring bug fixes. > > > > 4. Repetition (of the 'gazillion example' without new content). > > > > Have you ever acknowledged, let alone thank people for, the fix for the > > one bad regression you did find. The FSR is still a work in progress. > > Just today, Serhiy pushed a patch speeding up the UTF-32 encoder, after > > previously speeding up the UTF-32 decoder. > > > > -- My examples are ONLY ILLUSTRATING, this FSR is wrong by design, can be on the side of memory, performance, linguistic or even typography. I will not refrain you to waste your time in adjusting bytes, if the problem is not on that side. jmf From solipsis at pitrou.net Sun Jan 5 09:37:17 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Sun, 5 Jan 2014 15:37:17 +0100 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: <20140105153717.20aa23d5@fsol> On Sun, 05 Jan 2014 08:22:38 -0500 Ned Batchelder wrote: > On 1/5/14 8:14 AM, Mark Lawrence wrote: > > http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ > > > > Please don't shoot the messenger :) > > > > With all of the talk about py 2 vs. py3 these days, this is the blog > post that I think deserves the most real attention. I haven't had to do > the kind of coding that Armin is talking about, but I've heard more than > one person talk about the difficulty of it in Python 3. > > If anyone wants Python 3 uptake improved, the best thing would be to > either explain to Armin how he missed the easy way to do what he wants > (seems unlikely), or advocate to the core devs why they should change > things to improve this situation. Sometimes the best way to "advocate to the core devs" is to do part of the work, though. There are several people arguing for %-formatting or .format() on bytes, but that still lacks a clear description of which formatting codes would be supported, with which semantics. (see e.g. http://bugs.python.org/issue3982) As for the rest of Armin's rant, well, it's a rant. "In some cases Python 3 is a bit less practical than Python 2" doesn't equate to "Python 3 is broken and 2.8 should be released instead". Regards Antoine. From ned at nedbatchelder.com Sun Jan 5 10:20:11 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 05 Jan 2014 10:20:11 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: On 1/5/14 9:23 AM, wxjmfauth at gmail.com wrote: > Le samedi 4 janvier 2014 23:46:49 UTC+1, Terry Reedy a ?crit : >> On 1/4/2014 2:10 PM, wxjmfauth at gmail.com wrote: >>> I do not mind to be considered as an idiot, but >>> I'm definitively not blind. >>> >>> And I could add, I *never* saw once one soul, who is >>> explaining what I'm doing wrong in the gazillion >>> of examples I gave on this list. >> >> If this is true, it is because you have ignored and not read my >> numerous, relatively polite posts. To repeat very briefly: >> >> 1. Cherry picking (presenting the most extreme case as representative). >> >> 2. Calling space saving a problem (repeatedly). >> >> 3. Ignoring bug fixes. >> >> 4. Repetition (of the 'gazillion example' without new content). >> >> Have you ever acknowledged, let alone thank people for, the fix for the >> one bad regression you did find. The FSR is still a work in progress. >> Just today, Serhiy pushed a patch speeding up the UTF-32 encoder, after >> previously speeding up the UTF-32 decoder. >> >> -- > > My examples are ONLY ILLUSTRATING, this FSR > is wrong by design, can be on the side of > memory, performance, linguistic or even > typography. JMF: this has been pointed out to you time and again: the flexible string representation is not wrong. To show that it is wrong, you would have to demonstrate some semantic of Unicode that is violated. You have never done this. You've picked pathological cases and shown micro-timing output, and memory usage. The Unicode standard doesn't promise anything about timing or memory use. The FSR makes a trade-off of time and space. Everyone but you considers it a good trade-off. I don't think you are showing real use cases, but if they are, I'm sorry that your use-case suffers. That doesn't make the FSR wrong. The most accurate statement is that you don't like the FSR. That's fine, you're entitled to your opinion. You say the FSR is wrong linguistically. This can't be true, since an FSR Unicode string is indistinguishable from an internally-UTF-32 Unicode string, and no, memory use or timings are irrelevant when discussing the linguistic performance of a Unicode string. You've also said that the internal representation of the FSR is incorrect because of encodings somehow. Encodings have nothing to do with the internal representation of a Unicode string, they are for interchanging data. You seem to know a lot about Unicode, but when you make this fundamental mistake, you call all of your expertise into question. To re-iterate what you are doing wrong: 1) You continue to claim things that are not true, and that you have never substantiated. 2) You paste code samples without accompanying text that explain what you are trying to demonstrate. 3) You ignore refutations that disprove your points. These are all the behaviors of a troll. Please stop. If you want to discuss the details of Unicode implementations, I'd welcome an offlist discussion, but only if you will approach it honestly enough to leave open the possibility that you are wrong. I know I would be glad to learn details of Unicode that I have missed, but so far you haven't provided any. --Ned. > > I will not refrain you to waste your time > in adjusting bytes, if the problem is not > on that side. > > jmf > -- Ned Batchelder, http://nedbatchelder.com From roy at panix.com Sun Jan 5 11:10:56 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 11:10:56 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> <52c94fec$0$29973$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52c94fec$0$29973$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > How do we tell when software is buggy? We compare what it actually does to > the promised behaviour, or expected behaviour, and if there is a > discrepancy, we call it a bug. We don't compare it to some ideal that > cannot be met. A bug report that math.pi does not have infinite number of > decimal places would be closed as "Will Not Fix". That's because it is inherently impossible to "fix" that. But lots of bug reports legitimately get closed with "Will Not Fix" simply because the added value from fixing it doesn't justify the cost (whether in terms of development effort, or run-time resource consumption). Go back to the package sorting example I gave. If the sorting software mis-reads the address and sends my package to Newark instead of New York by mistake, that's clearly a bug. Presumably, it's an error which could be eliminated (or, at least, the rate of occurrence reduced) by using a more sophisticated OCR algorithm. But, if those algorithms take longer to run, the overall expected value of implementing the bug fix software may well be negative. In the real world, nobody cares if software is buggy. They care that it provides value. From eneskristo at gmail.com Sun Jan 5 11:32:50 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Sun, 5 Jan 2014 08:32:50 -0800 (PST) Subject: Struggling with an anchor in my hands Message-ID: <60b4d55f-2e6a-422c-a02d-9791b800d691@googlegroups.com> SO, I'm still trying to make that tkinter code. I've come far enough, but I now should place the elements in the window. But I'm having problems with anchor. No matter how I use it, it always goes to the SW part. I want them to go to the NW part. Any help please? I can provide any needed info. From roy at panix.com Sun Jan 5 11:34:31 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 11:34:31 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Sun, Jan 5, 2014 at 2:20 PM, Roy Smith wrote: > > I've got a new sorting algorithm which is guaranteed to cut 10 seconds > > off the sorting time (i.e. $0.10 per package). The problem is, it makes > > a mistake 1% of the time. > > That's a valid line of argument in big business, these days, because > we've been conditioned to accept low quality. But there are places > where quality trumps all, and we're happy to pay for that. Allow me to > expound two examples. > > 1) Amazon > > http://www.amazon.com/exec/obidos/ASIN/1782010165/evertype-20 > > I bought this book a while ago. It's about the size of a typical > paperback. It arrived in a box too large for it on every dimension, > with absolutely no packaging. I complained. Clearly their algorithm > was: "Most stuff will get there in good enough shape, so people can't > be bothered complaining. And when they do complain, it's cheaper to > ship them another for free than to debate with them on chat." You're missing my point. Amazon's (short-term) goal is to increase their market share by undercutting everybody on price. They have implemented a box-packing algorithm which clearly has a bug in it. You are complaining that they failed to deliver your purchase in good condition, and apparently don't care. You're right, they don't. The cost to them to manually correct this situation exceeds the value. This is one shipment. It doesn't matter. You are one customer, you don't matter either. Seriously. This may be annoying to you, but it's good business for Amazon. For them, fast and cheap is absolutely better than correct. I'm not saying this is always the case. Clearly, there are companies which have been very successful at producing a premium product (Apple, for example). I'm not saying that fast is always better than correct. I'm just saying that correct is not always better than fast. From denismfmcmahon at gmail.com Sun Jan 5 11:48:24 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 5 Jan 2014 16:48:24 +0000 (UTC) Subject: Dos cursor and input management. References: Message-ID: On Sun, 05 Jan 2014 20:25:11 +1100, Sean Murphy wrote: > The module must work under dos for now. Eventually Mac. Do you mean a windows command line terminal window, or some *nix shell? As far as I know, dos as an operating system hasn't been around since version 6.22 or thereabouts, although I believe ms windows provides a dos shell like interface on top of the windows os. I'm not aware that any version of python is supported on dos, but I may be wrong, there may be some 15 year old hardware running dos somewhere that also has a working python install. I associate dos with machines of the pre-pentium era, although I suspect that might not be quite accurate either. -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Sun Jan 5 11:51:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 03:51:20 +1100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 6, 2014 at 3:34 AM, Roy Smith wrote: > Amazon's (short-term) goal is to increase their market share by > undercutting everybody on price. They have implemented a box-packing > algorithm which clearly has a bug in it. You are complaining that they > failed to deliver your purchase in good condition, and apparently don't > care. You're right, they don't. The cost to them to manually correct > this situation exceeds the value. This is one shipment. It doesn't > matter. If it stopped there, it would be mildly annoying ("1% of our shipments will need to be replaced, that's a 1% cost for free replacements"). The trouble is that they don't care about the replacement either, so it's really that 100% (or some fairly large proportion) of their shipments will arrive with some measure of damage, and they're hoping that their customers' threshold for complaining is often higher than the damage sustained. Which it probably is, a lot of the time. > You are one customer, you don't matter either. Seriously. > This may be annoying to you, but it's good business for Amazon. For > them, fast and cheap is absolutely better than correct. But this is the real problem, business-wise. Can you really run a business by not caring about your customers? (I also think it's pretty disappointing that a business like Amazon can't just toss in some bubbles, or packing peanuts (what we call "trucks" for hysterical raisins), or something. It's not that hard to have a machine just blow in some sealed air before the box gets closed... surely?) Do they have that much of a monopoly, or that solid a customer base, that they're happy to leave *everyone* dissatisfied? We're not talking about 1% here. From the way the cust svc guy was talking, I get the impression that they do this with all parcels. And yet.... I can't disagree with your final conclusion. Empirical evidence goes against my incredulous declaration that "surely this is a bad idea" - according to XKCD 1165, they're kicking out nearly a cubic meter a *SECOND* of packages. That's fairly good evidence that they're doing something that, whether it be right or wrong, does fit with the world's economy. Sigh. ChrisA From breamoreboy at yahoo.co.uk Sun Jan 5 12:08:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Jan 2014 17:08:43 +0000 Subject: Dos cursor and input management. In-Reply-To: <58EDD9C8-2310-46EA-8E77-2C3B049C8BFC@gmail.com> References: <58EDD9C8-2310-46EA-8E77-2C3B049C8BFC@gmail.com> Message-ID: On 05/01/2014 09:25, Sean Murphy wrote: > Hi all. > > I am after a module that manages keyboard input. I am aware of raw_input for python 2.x and input for 3.x. They don't quite achieve what I want. > > I want to except a single key without printing it to the screen and then the key would perform an action. Sudo code: > > print line of text > wait for key press > If key press equals delete line. > Delete list element. > else if key press equals edit > display line for interactive edit. > else > move to next line > > > The module must work under dos for now. Eventually Mac. > > Sean > I think you're looking for something like this https://github.com/jmcb/python-pdcurses -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Sun Jan 5 12:09:50 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 12:09:50 -0500 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: Chris Angelico wrote: > Can you really run a business by not caring about your customers? http://snltranscripts.jt.org/76/76aphonecompany.phtml From feliphil at gmx.net Sun Jan 5 12:22:43 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Sun, 5 Jan 2014 18:22:43 +0100 Subject: Using multiple ORMs? - And SQLalchemy vs Pony vs Peewee vs stdnet vs =?UTF-8?Q?=E2=80=A6?= References: Message-ID: <20140105182243.21fd342b4ef5f89ca855c23e@gmx.net> > Thanks for all suggestions, Two essential criteria: If an ORM only allows 1:1 mapping between classes and tables ? la "active record", then it's entirely pointless. And if an ORM allows only surrogate keys, then its developers don't have a clue of databases or they don't give a darn. Or both. Sincerely, Wolfgang From eneskristo at gmail.com Sun Jan 5 13:18:56 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Sun, 5 Jan 2014 10:18:56 -0800 (PST) Subject: gotta love radio buttons Message-ID: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> So, I'm having this radio button issue in tkinter: First I assign the IntVar: var = [] while i < self.something: var.append(IntVar()) i += 2 Later on I use them, but I get this error: for r in var: helper = var[r].get() self.something_else[helper] += 1 Then, this happens: Traceback (most recent call last): File "F:\Portable Python 3.2.5.1\App\lib\tkinter\__init__.py", line 1456, in __call__ return self.func(*args) File "----(Not giving this)", line 26, in submit_data helper = var[r].get() TypeError: list indices must be integers, not IntVar I'm willing to give additional info. Thank you in advance. From roy at panix.com Sun Jan 5 13:33:12 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 13:33:12 -0500 Subject: gotta love radio buttons References: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> Message-ID: In article <8dca57e8-8258-4020-9788-987af332b5b2 at googlegroups.com>, eneskristo at gmail.com wrote: I don't use tkinter, but here's what I can figure out from looking at your code and http://effbot.org/tkinterbook/variable.htm > var = [] > while i < self.something: > var.append(IntVar()) > i += 2 At this point, var is a list of IntVar instances. > for r in var: > helper = var[r].get() > self.something_else[helper] += 1 You are iterating over the element of var, so each time through the loop, r is an IntVar instance. But, you're using r to index a list in > helper = var[r].get() That's what > TypeError: list indices must be integers, not IntVar means. I suspect what you want is to retrieve the integer value from r, and use that as the index: > helper = var[r.get()] but without knowing more about your code, that's just a guess. At a deeper level, however, there's something that fundamentally doesn't make sense here. You are iterating over the values in var, then using each value as an index again. That's not *wrong*, but it seems unlikely to be what you want. From ned at nedbatchelder.com Sun Jan 5 13:37:25 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 05 Jan 2014 13:37:25 -0500 Subject: gotta love radio buttons In-Reply-To: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> References: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> Message-ID: On 1/5/14 1:18 PM, eneskristo at gmail.com wrote: > So, I'm having this radio button issue in tkinter: > First I assign the IntVar: > var = [] > while i < self.something: > var.append(IntVar()) > i += 2 > Later on I use them, but I get this error: > for r in var: > helper = var[r].get() > self.something_else[helper] += 1 > Then, this happens: > Traceback (most recent call last): > File "F:\Portable Python 3.2.5.1\App\lib\tkinter\__init__.py", line 1456, in __call__ > return self.func(*args) > File "----(Not giving this)", line 26, in submit_data > helper = var[r].get() > TypeError: list indices must be integers, not IntVar > I'm willing to give additional info. Thank you in advance. > This isn't about radio buttons, it's about how for loops work. I think you want: for r in var: helper = r.get() The iteration variable in a for loop (r in this case) takes on the values of the elements of the list, not the indexes of the elements. -- Ned Batchelder, http://nedbatchelder.com From kevin.p.dwyer at gmail.com Sun Jan 5 13:40:41 2014 From: kevin.p.dwyer at gmail.com (Kev Dwyer) Date: Sun, 05 Jan 2014 18:40:41 +0000 Subject: gotta love radio buttons References: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> Message-ID: eneskristo at gmail.com wrote: > So, I'm having this radio button issue in tkinter: > First I assign the IntVar: > var = [] > while i < self.something: > var.append(IntVar()) > i += 2 > Later on I use them, but I get this error: > for r in var: > helper = var[r].get() > self.something_else[helper] += 1 > Then, this happens: > Traceback (most recent call last): > File "F:\Portable Python 3.2.5.1\App\lib\tkinter\__init__.py", line > 1456, in __call__ > return self.func(*args) > File "----(Not giving this)", line 26, in submit_data > helper = var[r].get() > TypeError: list indices must be integers, not IntVar > I'm willing to give additional info. Thank you in advance. (untested) for r in var: helper = var[r.get()] I think you need to call get on the IntVar instance to get an int that can be used to index the list. From gary.herron at islandtraining.com Sun Jan 5 13:38:08 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 05 Jan 2014 10:38:08 -0800 Subject: gotta love radio buttons In-Reply-To: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> References: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> Message-ID: <52C9A690.7080706@islandtraining.com> On 01/05/2014 10:18 AM, eneskristo at gmail.com wrote: > So, I'm having this radio button issue in tkinter: > First I assign the IntVar: > var = [] > while i < self.something: > var.append(IntVar()) > i += 2 > Later on I use them, but I get this error: > for r in var: > helper = var[r].get() > self.something_else[helper] += 1 > Then, this happens: > Traceback (most recent call last): > File "F:\Portable Python 3.2.5.1\App\lib\tkinter\__init__.py", line 1456, in __call__ > return self.func(*args) > File "----(Not giving this)", line 26, in submit_data > helper = var[r].get() > TypeError: list indices must be integers, not IntVar > I'm willing to give additional info. Thank you in advance. These two lines for r in var: helper = var[r].get() are being redundant. The loop returns elements from the list (one-by-one). Also var[r] attempts to return an element from the list (indexed by r -- expected to be an integer). Either of these remove the redundancy (but the first is more Pythonic) for r in var: helper = r.get() or for i in range(len(var)): helper = var[i].get() Gary Herron From eneskristo at gmail.com Sun Jan 5 13:47:13 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Sun, 5 Jan 2014 10:47:13 -0800 (PST) Subject: gotta love radio buttons In-Reply-To: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> References: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> Message-ID: <1dffaef8-ba59-4bbf-b8ac-02c611640f92@googlegroups.com> Now it is giving me this error, after changing to helper = var[r.get()] line 27, in submit_data self.something_else[r][1] += 1 TypeError: list indices must be integers, not IntVar From ethan at stoneleaf.us Sun Jan 5 14:12:56 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Jan 2014 11:12:56 -0800 Subject: [ANN] gg_scrapper -- scrapping of the Google Groups In-Reply-To: <20140104225739.GA32309@wycliff.ceplovi.cz> References: <20140104225739.GA32309@wycliff.ceplovi.cz> Message-ID: <52C9AEB8.3080906@stoneleaf.us> Mat?j, Thanks for your efforts! However, you should only have one 'p' in scraping and scraper. ;) -- ~Ethan~ From pietrodcof at gmail.com Sun Jan 5 14:39:26 2014 From: pietrodcof at gmail.com (pietrodcof at gmail.com) Date: Sun, 5 Jan 2014 11:39:26 -0800 (PST) Subject: converting a string to a function parameter In-Reply-To: References: Message-ID: Il giorno venerd? 13 marzo 2009 08:52:39 UTC+1, koranthala ha scritto: > Hi, > Is it possible to convert a string to a function parameter? > Ex: > str = 'True, type=rect, sizes=[3, 4]' > and I should be able to use it as: > test(convert(str)) and the behaviour should be same as calling test > with those values : > i.e. test(True, type=rect, sizes=[3, 4]) > > I tried eval, but it did not work. And any other mechanism I think > turns out to be creating a full fledged python parser. > > Is there any mechanism with which we can do this straight away? I need the exact opposite, what is the inverse function? example: i pass to a function an argument m=[654,54,65] def function(m): return takethenameof(m) and it have to return to me 'm' not [654,54,65] or '[654,54,65]' anybody can help? i think that when one is talking about a function he have to talk also of the inverse function (also because google have problems searching about this...) From gary.herron at islandtraining.com Sun Jan 5 14:51:48 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 05 Jan 2014 11:51:48 -0800 Subject: gotta love radio buttons In-Reply-To: <1dffaef8-ba59-4bbf-b8ac-02c611640f92@googlegroups.com> References: <8dca57e8-8258-4020-9788-987af332b5b2@googlegroups.com> <1dffaef8-ba59-4bbf-b8ac-02c611640f92@googlegroups.com> Message-ID: <52C9B7D4.8070205@islandtraining.com> On 01/05/2014 10:47 AM, eneskristo at gmail.com wrote: > Now it is giving me this error, after changing to helper = var[r.get()] > line 27, in submit_data > self.something_else[r][1] += 1 > TypeError: list indices must be integers, not IntVar In such an easy case, you really ought to be able to read the error and understand it rather than needing to rely on us to do that for you. The message: List indices must be integers, not IntVar clearly indicates you are indexing a list with something of type IntVar instead of the required int. That would have to be the ...[r]. The value of r is *not* an integer, it's an IntVar which is container of an int but not an int itself. You can access the contained int with r.get(), so perhaps ...[r.get()] is what you want. (Or perhaps not... We really don't know what you are trying to do here.) Reading error messages and understanding tracebacks are skills well worth trying to develop. Good luck. Gary Herron From ned at nedbatchelder.com Sun Jan 5 14:58:09 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 05 Jan 2014 14:58:09 -0500 Subject: converting a string to a function parameter In-Reply-To: References: Message-ID: On 1/5/14 2:39 PM, pietrodcof at gmail.com wrote: > Il giorno venerd? 13 marzo 2009 08:52:39 UTC+1, koranthala ha scritto: >> Hi, >> Is it possible to convert a string to a function parameter? >> Ex: >> str = 'True, type=rect, sizes=[3, 4]' >> and I should be able to use it as: >> test(convert(str)) and the behaviour should be same as calling test >> with those values : >> i.e. test(True, type=rect, sizes=[3, 4]) >> >> I tried eval, but it did not work. And any other mechanism I think >> turns out to be creating a full fledged python parser. >> >> Is there any mechanism with which we can do this straight away? > > I need the exact opposite, what is the inverse function? > example: i pass to a function an argument > > m=[654,54,65] > def function(m): > return takethenameof(m) > > and it have to return to me 'm' not [654,54,65] or '[654,54,65]' > > anybody can help? > i think that when one is talking about a function he have to talk also of the inverse function (also because google have problems searching about this...) > The difficulty in writing such a function is that values don't have unique names, if they have names at all. What should be returned in these cases? m = [654, 54, 65] def function(m): m2 = m m3 = m[:] takethenameof(m) takethenameof(m2) takethenameof(m3) takethenameof(m[:]) takethenameof(2) takethenameof(2+2) There are samples online that try to do a "reasonable" job of this, but my googling isn't turning them up... -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Sun Jan 5 15:04:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 05 Jan 2014 20:04:43 +0000 Subject: [ANN] gg_scrapper -- scrapping of the Google Groups In-Reply-To: <52C9AEB8.3080906@stoneleaf.us> References: <20140104225739.GA32309@wycliff.ceplovi.cz> <52C9AEB8.3080906@stoneleaf.us> Message-ID: On 05/01/2014 19:12, Ethan Furman wrote: > Mat?j, > > Thanks for your efforts! > > However, you should only have one 'p' in scraping and scraper. ;) > > -- > ~Ethan~ My hopes were falsely raised when I first saw the title :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gary.herron at islandtraining.com Sun Jan 5 15:09:52 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 05 Jan 2014 12:09:52 -0800 Subject: converting a string to a function parameter In-Reply-To: References: Message-ID: <52C9BC10.9030304@islandtraining.com> On 01/05/2014 11:39 AM, pietrodcof at gmail.com wrote: > Il giorno venerd? 13 marzo 2009 08:52:39 UTC+1, koranthala ha scritto: >> Hi, >> Is it possible to convert a string to a function parameter? >> Ex: >> str = 'True, type=rect, sizes=[3, 4]' >> and I should be able to use it as: >> test(convert(str)) and the behaviour should be same as calling test >> with those values : >> i.e. test(True, type=rect, sizes=[3, 4]) >> >> I tried eval, but it did not work. And any other mechanism I think >> turns out to be creating a full fledged python parser. >> >> Is there any mechanism with which we can do this straight away? > I need the exact opposite, what is the inverse function? > example: i pass to a function an argument > > m=[654,54,65] > def function(m): > return takethenameof(m) > > and it have to return to me 'm' not [654,54,65] or '[654,54,65]' > > anybody can help? > i think that when one is talking about a function he have to talk also of the inverse function (also because google have problems searching about this... Absolutely not. Objects (like [654,54,65]) do not have names, never did and never will! Objects do have a type and a value (and an identity), but not a name. Various namespaces will have dictionary-like associations between a name (like "m") and an object, and it *is* possible to get your hands on a (dictionary representing a) namespace and search it, but this is troublesome. For instance, consider this small variation of your code: def function(m): return takethenameof(m) a=[654,54,65] b = a function(a) While function is running, there will be three names associated with the list object. The outer namespace will have "a" and "b" associated with the list object, and the namespace local to function will have "m" associated with the same object. That's one object associated with three names in two different namespaces. Gary Herron From self at gkayaalp.com Sun Jan 5 15:24:53 2014 From: self at gkayaalp.com (=?UTF-8?B?R8O2a3R1xJ8gS2F5YWFscA==?=) Date: Sun, 05 Jan 2014 22:24:53 +0200 Subject: Postfix conditionals Message-ID: <52C9BF95.5000006@gkayaalp.com> Hi, AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition appended to a statement, which determines whether the statement runs or not: py> for i in [False]: ... break if not i The above piece of code is equivalent to this in Python: py> for i in [False]: ... if not i ... break I believe that the first example is superior to the second example when the two is compared for readability and intuitiveness. We already have a ternary statement that looks similar, py> print('hi') if True else None so I reckon there would be no breakage in old code if this kind of syntax was added. Ruby has this, and AFAIK Perl also does. I lack the knowledge of whether the community has opinions on this kind of notation, so I am posting this here instead of the ideas list. What are your thoughts on this? gk From roy at panix.com Sun Jan 5 15:41:06 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 15:41:06 -0500 Subject: Postfix conditionals References: Message-ID: In article , G??ktu??? Kayaalp wrote: > py> for i in [False]: > ... break if not i Python is not Perl. From self at gkayaalp.com Sun Jan 5 15:54:37 2014 From: self at gkayaalp.com (=?UTF-8?B?R8O2a3R1xJ8gS2F5YWFscA==?=) Date: Sun, 05 Jan 2014 22:54:37 +0200 Subject: Postfix conditionals In-Reply-To: References: Message-ID: <52C9C68D.1020602@gkayaalp.com> On 05-01-2014 22:41, Roy Smith wrote: > In article , > G??ktu??? Kayaalp wrote: > >> py> for i in [False]: >> ... break if not i > Python is not Perl. Well done! Good for you, that you know the fact; but you are not being constructive. Python is not C either, but we have the while loop. Python is not Smalltalk, but we have classes. Python is not LISP, but we have function literals. Hopefully Guido did not have your approach back when he created Python, or we'd have an assembly language or something instead today. From tjreedy at udel.edu Sun Jan 5 16:10:01 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 16:10:01 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/2014 8:14 AM, Mark Lawrence wrote: > http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ I disagree with the following claims: "Looking at that you can see that Python 3 removed something: support for non Unicode data text. " I believe 2.7 str text methods like .upper only supported ascii. General non-unicode bytes text support would require an encoding as an attribute of the bytes text object. Python never had that. "Python 3 essentially removed the byte-string type which in 2.x was called str." Python 3 renamed unicode as str and str as bytes. Bytes have essentially all the text methods of 2.7 str. Compare dir(str) in 2.7 and dir(bytes) in 3.x. The main change of the class itself is that indexing and iteration yield ints i, 0 <= i < 256. "all text operations now are only defined for Unicode strings." ?? Text methods are still defined on (ascii) bytes. It is true that one text operation -- string formatting no longer is (and there is an issue about that). But one is not all. There is also still discussion about within-class transforms, but they are still possible, even if not with the codecs module. I suspect there are other basic errors, but I mostly quit reading at this point. -- Terry Jan Reedy From drsalists at gmail.com Sun Jan 5 16:08:44 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Jan 2014 13:08:44 -0800 Subject: Postfix conditionals In-Reply-To: References: Message-ID: On Sun, Jan 5, 2014 at 12:41 PM, Roy Smith wrote: > In article , > G?ktu? Kayaalp wrote: > >> py> for i in [False]: >> ... break if not i > > Python is not Perl. Personally, I find the suggested syntax jarring. I'd prefer that it not go into Python. From tjreedy at udel.edu Sun Jan 5 16:17:25 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 16:17:25 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/2014 8:14 AM, Mark Lawrence wrote: > http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ I meant to mention in my previous reply that Armin authored PEP 414, Explicit Unicode Literal for Python 3.3, which brought back the u'' prefix. So it is not the case that core devs pay no attention to Armin when he engages us on an 'improve 3.x' basis. -- Terry Jan Reedy From larry at hastings.org Sun Jan 5 16:20:50 2014 From: larry at hastings.org (Larry Hastings) Date: Sun, 05 Jan 2014 13:20:50 -0800 Subject: [RELEASED] Python 3.4.0b2 Message-ID: <52C9CCB2.7080703@hastings.org> On behalf of the Python development team, I'm pleased to announce the second beta release of Python 3.4. This is a preview release, and its use is not recommended for production settings. Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes. Major new features and changes in the 3.4 release series include: * PEP 428, a "pathlib" module providing object-oriented filesystem paths * PEP 435, a standardized "enum" module * PEP 436, a build enhancement that will help generate introspection information for builtins * PEP 442, improved semantics for object finalization * PEP 443, adding single-dispatch generic functions to the standard library * PEP 445, a new C API for implementing custom memory allocators * PEP 446, changing file descriptors to not be inherited by default in subprocesses * PEP 450, a new "statistics" module * PEP 451, standardizing module metadata for Python's module import system * PEP 453, a bundled installer for the *pip* package manager * PEP 454, a new "tracemalloc" module for tracing Python memory allocations * PEP 456, a new hash algorithm for Python strings and binary data * PEP 3154, a new and improved protocol for pickled objects * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O Python 3.4 is now in "feature freeze", meaning that no new features will be added. The final release is projected for late February 2014. To download Python 3.4.0b2 visit: http://www.python.org/download/releases/3.4.0/ Please consider trying Python 3.4.0b2 with your code and reporting any new issues you notice to: http://bugs.python.org/ Enjoy! -- Larry Hastings, Release Manager larry at hastings.org (on behalf of the entire python-dev team and 3.4's contributors) From python.list at tim.thechases.com Sun Jan 5 16:39:19 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 5 Jan 2014 15:39:19 -0600 Subject: django question In-Reply-To: References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: <20140105153919.78aa5c44@bigbox.christie.dr> On 2014-01-05 00:24, Igor Korot wrote: > > While I prefer Django for larger projects, for a lighter-weight > > project such as what you describe, I'd be tempted to go with > > something a little more light-weight unless you need additional > > interactivity. I've recently been impressed with Bottle[2] for a > > small & clean web framework. CherryPy comes somewhere in the > > middle, but I can't say it met my needs/wants on the last project > > where it was chosen (mostly in the documentation department, but > > it's hard to beat Django's stellar docs). > > And thank you for those points as well. > This piece will be for the proof of concept, which later on will go > to much bigger application with reporting, > plotting and different types of data presentation. > Now would it be easy to switch from either on of them to django? > Or is there a better choice for the main application? Integration is one of the things that Django does particularly well: out of the box, you get a web framework, database abstraction (ORM), templating, out-of-the-box functionality, and PHENOMENAL documentation. The others just bring the web-framework to the table and *you* then have to choose your templating engine (and ORM if you're using one). Some people see this as an advantage, some see it as a disadvantage. If you like a particular templating engine (Mako, Jinja, etc) or ORM (SQLAlchemy, SQLObject, etc), you /can/ use them in Django or other frameworks, but in Django, you'd be fighting the Django Way? and don't get to take advantage of some of the tight integration in areas where it does some of the hard work for you (such as integration into the admin interface). I haven't found it to be that easy to directly transition projects between Django and other frameworks. Jumping from Bottle to CherryPy might be easier, as the non-framework parts (templating, ORM) would/should mostly stay the same. Depending on the scope of your work, it might be possible to just use something light-weight like Bottle to get a demo up and running, then scrap it and start mostly-from-scratch on a Django project once you've impressed folks with a proof-of-concept. -tkc From roy at panix.com Sun Jan 5 16:50:55 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 16:50:55 -0500 Subject: django question References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: In article , Tim Chase wrote: > Integration is one of the things that Django does particularly well: > out of the box, you get a web framework, database abstraction (ORM), > templating, out-of-the-box functionality, and PHENOMENAL > documentation. The others just bring the web-framework to the table > and *you* then have to choose your templating engine (and ORM if > you're using one). Some people see this as an advantage, some see it > as a disadvantage. If you like a particular templating engine (Mako, > Jinja, etc) or ORM (SQLAlchemy, SQLObject, etc), you /can/ use them in > Django or other frameworks, but in Django, you'd be fighting the > Django Way??? and don't get to take advantage of some of the tight > integration in areas where it does some of the hard work for you > (such as integration into the admin interface). On the other hand, it's all modular enough that it's quite reasonable to plug in your own components. For example, at Songza, we don't use the django ORM at all (we use mongoengine). We also have a number of django-based services which don't use templates at all (we return JSON objects). Neither of these required any major surgery to do this. In fact, for a lot of what we do, all we really get from django is the request parsing, URL routing, middleware scaffolding, and cache interface. But, that's enough to be worthwhile. > I haven't found it to be that easy to directly transition projects > between Django and other frameworks. One of the things we try to do is put as little in the views as possible. Views should be all about accepting and validating request parameters, and generating output (be that HTML via templates, or JSON, or whatever). All the business logic should be kept isolated from the views. The better (and more disciplined) you are about doing this, the easier it will be to move your business logic to a different framework. That's not to say it will be *easy*, but you can certainly make things harder on yourself than they need to be if you don't keep things distinct. Oh, and yes, the django team does a really amazing job on the docs. From mhysnm1964 at gmail.com Sun Jan 5 17:03:10 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Mon, 6 Jan 2014 09:03:10 +1100 Subject: Dos cursor and input management. In-Reply-To: References: Message-ID: Dennis, Loose terminology. The Command terminal within windows which the app will be executed in. Not native DOS. On 06/01/2014, at 3:48 AM, Denis McMahon wrote: > On Sun, 05 Jan 2014 20:25:11 +1100, Sean Murphy wrote: > >> The module must work under dos for now. Eventually Mac. > > Do you mean a windows command line terminal window, or some *nix shell? > > As far as I know, dos as an operating system hasn't been around since > version 6.22 or thereabouts, although I believe ms windows provides a dos > shell like interface on top of the windows os. I'm not aware that any > version of python is supported on dos, but I may be wrong, there may be > some 15 year old hardware running dos somewhere that also has a working > python install. > > I associate dos with machines of the pre-pentium era, although I suspect > that might not be quite accurate either. > > -- > Denis McMahon, denismfmcmahon at gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list From clp2 at rebertia.com Sun Jan 5 17:09:14 2014 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 5 Jan 2014 14:09:14 -0800 Subject: Postfix conditionals In-Reply-To: <52C9BF95.5000006@gkayaalp.com> References: <52C9BF95.5000006@gkayaalp.com> Message-ID: On Sun, Jan 5, 2014 at 12:24 PM, G?ktu? Kayaalp wrote: > Hi, > > AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition > appended to a > statement, which determines whether the statement runs or not: > > py> for i in [False]: > ... break if not i > > The above piece of code is equivalent to this in Python: > > py> for i in [False]: > ... if not i > ... break > > I believe that the first example is superior to the second example when the > two is compared > for readability and intuitiveness. I'm going to have to disagree. I dislike how this obscures the if-statement, complicates the language grammar, and adds another unnecessary way to express the same thing (which violates TOOWTDI) with little countervailing benefit. > We already have a ternary statement that > looks similar, > > py> print('hi') if True else None Actually, to be pedantic, it's a ternary *expression*. Using it purely for side-effects (i.e. as a statement) is rather unidiomatic, in the same way that abusing list comprehensions, e.g.: [print(i) for i in range(42)] is frowned upon. Not to mention that the ternary doesn't work for actual statements (print() is just a function call in Python 3): >>> (x = 1) if True else (x = 2) File "", line 1 (x = 1) if True else (x = 2) ^ SyntaxError: invalid syntax > so I reckon there would be no breakage in old code if this kind of syntax > was added. Ruby has > this, and AFAIK Perl also does. > > I lack the knowledge of whether the community has opinions on this kind of > notation, so I am > posting this here instead of the ideas list. What are your thoughts on > this? You can already write: for i in [False]: if not i: break if you feel the need for terseness or a one-liner. Perhaps this satisfies your desire? Cheers, Chris From self at gkayaalp.com Sun Jan 5 17:12:17 2014 From: self at gkayaalp.com (=?UTF-8?B?R8O2a3R1xJ8gS2F5YWFscA==?=) Date: Mon, 06 Jan 2014 00:12:17 +0200 Subject: Fwd: Re: Postfix conditionals In-Reply-To: References: Message-ID: <52C9D8C1.2090402@gkayaalp.com> This was sent to me as a private reply to a question that I have posted to python-list at python.org, so I am forwarding it to here. Chris, please send your messages to the list, and cc the OP. -------- Original Message -------- Subject: Re: Postfix conditionals Date: Sun, 5 Jan 2014 14:09:14 -0800 From: Chris Rebert To: G?ktu? Kayaalp CC: Python On Sun, Jan 5, 2014 at 12:24 PM, G?ktu? Kayaalp wrote: > Hi, > > AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition > appended to a > statement, which determines whether the statement runs or not: > > py> for i in [False]: > ... break if not i > > The above piece of code is equivalent to this in Python: > > py> for i in [False]: > ... if not i > ... break > > I believe that the first example is superior to the second example when the > two is compared > for readability and intuitiveness. I'm going to have to disagree. I dislike how this obscures the if-statement, complicates the language grammar, and adds another unnecessary way to express the same thing (which violates TOOWTDI) with little countervailing benefit. > We already have a ternary statement that > looks similar, > > py> print('hi') if True else None Actually, to be pedantic, it's a ternary *expression*. Using it purely for side-effects (i.e. as a statement) is rather unidiomatic, in the same way that abusing list comprehensions, e.g.: [print(i) for i in range(42)] is frowned upon. Not to mention that the ternary doesn't work for actual statements (print() is just a function call in Python 3): >>> (x = 1) if True else (x = 2) File "", line 1 (x = 1) if True else (x = 2) ^ SyntaxError: invalid syntax > so I reckon there would be no breakage in old code if this kind of syntax > was added. Ruby has > this, and AFAIK Perl also does. > > I lack the knowledge of whether the community has opinions on this kind of > notation, so I am > posting this here instead of the ideas list. What are your thoughts on > this? You can already write: for i in [False]: if not i: break if you feel the need for terseness or a one-liner. Perhaps this satisfies your desire? Cheers, Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Sun Jan 5 17:14:07 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 17:14:07 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: On 1/5/2014 9:23 AM, wxjmfauth at gmail.com wrote: > Le samedi 4 janvier 2014 23:46:49 UTC+1, Terry Reedy a ?crit : >> On 1/4/2014 2:10 PM, wxjmfauth at gmail.com wrote: >>> And I could add, I *never* saw once one soul, who is >>> explaining what I'm doing wrong in the gazillion >>> of examples I gave on this list. >> If this is true, it is because you have ignored and not read my >> numerous, relatively polite posts. To repeat very briefly: >> 1. Cherry picking (presenting the most extreme case as representative). >> 2. Calling space saving a problem (repeatedly). >> 3. Ignoring bug fixes. ... > My examples are ONLY ILLUSTRATING, this FSR > is wrong by design, can be on the side of > memory, performance, linguistic or even > typography. Let me expand on 3 of my points. First, performance == time: Point 3. You correctly identified a time regression in finding a character in a string. I saw that the slowdown was *not* inherent in the FSR but had to be a glitch in the code, and reported it on pydev with the hope that someone would fix it even if it were not too important in real use cases. Someone did. Point 1. You incorrectly generalized that extreme case. I reported (a year ago last September) that the overall stringbench results were about the same. I also pointed out that there is an equally non-representative extreme case in the opposite direction, and that it would equally be wrong of me to use that to claim that FSR is faster. (It turns out that this FSR speed advantage *is* inherent in the design.) Memory: Point 2. A *design goal* of FSR was to save memory relative to UTF-32, which is what you apparently prefer. Your examples show that FSF successfully met its design goal. But you call that success, saving memory, 'wrong'. On what basis? You *claim* the FSR is 'wrong by design', but your examples only show that is was temporarily wrong in implementation as far as speed and correct by design as far as memory goes. -- Terry Jan Reedy From clp2 at rebertia.com Sun Jan 5 17:26:51 2014 From: clp2 at rebertia.com (Chris Rebert) Date: Sun, 5 Jan 2014 14:26:51 -0800 Subject: Postfix conditionals In-Reply-To: <52C9D8C1.2090402@gkayaalp.com> References: <52C9D8C1.2090402@gkayaalp.com> Message-ID: On Sun, Jan 5, 2014 at 2:12 PM, G?ktu? Kayaalp wrote: > > This was sent to me as a private reply No, it was sent as a public reply via Reply-All; note that python-list was CC-ed, which works just fine: https://mail.python.org/pipermail/python-list/2014-January/663858.html > to a question that I have posted > to python-list at python.org, so I am forwarding it to here. > -------- Original Message -------- > Subject: Re: Postfix conditionals > Date: Sun, 5 Jan 2014 14:09:14 -0800 > From: Chris Rebert > To: G?ktu? Kayaalp > CC: Python From storchaka at gmail.com Sun Jan 5 17:28:41 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 06 Jan 2014 00:28:41 +0200 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: 05.01.14 15:34, Chris Angelico ???????(??): > Why is a StopIteration bubbling up? (I don't have Flask, so I can't > verify this.) Is it as simple as "this should be raising from None", > or is there something else going on? Yes, it is. Stdlib json module uses "from None". From storchaka at gmail.com Sun Jan 5 17:32:47 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 06 Jan 2014 00:32:47 +0200 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: I wonder why nobody complains about the absent of implicit conversion between int and str. In PHP you can write 2 + "3" and got 5, but in Python this is an error. So sad! From tjreedy at udel.edu Sun Jan 5 17:48:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 17:48:43 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: On 1/5/2014 9:23 AM, wxjmfauth at gmail.com wrote: > My examples are ONLY ILLUSTRATING, this FSR > is wrong by design, Let me answer you a different way. If FSR is 'wrong by design', so are the alternatives. Hence, the claim is, in itself, useless as a guide to choosing. The choices: * Keep the previous complicated system of buggy narrow builds on some systems and space-wasting wide builds on other systems, with Python code potentially acting differently on the different builds. I am sure that you agree that this is a bad design. * Improved the dual-build system by de-bugging narrow builds. I proposed to do this (and gave Python code proving the idea) by adding the complication of an auxiliary array of indexes of astral chars in a UTF-16 string. I suspect you would call this design 'wrong' also. * Use the memory-wasting UTF-32 (wide) build on all systems. I know you do not consider this 'wrong', but come on. From an information theoretic and coding viewpoint, it clearly is. The top (4th) byte is *never* used. The 3rd byte is *almost never* used. The 2nd byte usage ranges from common to almost never for different users. Memory waste is also time waste, as moving information-free 0 bytes takes the same time as moving informative bytes. Here is the beginning of the rationale for the FSR (from http://www.python.org/dev/peps/pep-0393/ -- have you ever read it?). "There are two classes of complaints about the current implementation of the unicode type: on systems only supporting UTF-16, users complain that non-BMP characters are not properly supported. On systems using UCS-4 internally (and also sometimes on systems using UCS-2), there is a complaint that Unicode strings take up too much memory - especially compared to Python 2.x, where the same code would often use ASCII strings...". The memory waste was a reason to stick with 2.7. It could break code that worked in 2.x. By removing the waste, the FSR makes switching to Python 3 more feasible for some people. It was a response to real problems encountered by real people using Python. It fixed both classes of complaint about the previous system. * Switch to the time-wasting UTF-8 for text storage, as some have done. This is different from using UTF-8 for text transmission, which I hope becomes the norm soon. -- Terry Jan Reedy From tjreedy at udel.edu Sun Jan 5 17:56:07 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 17:56:07 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/5/2014 11:51 AM, Chris Angelico wrote: > On Mon, Jan 6, 2014 at 3:34 AM, Roy Smith wrote: >> Amazon's (short-term) goal is to increase their market share by >> undercutting everybody on price. They have implemented a box-packing >> algorithm which clearly has a bug in it. You are complaining that they >> failed to deliver your purchase in good condition, and apparently don't >> care. You're right, they don't. The cost to them to manually correct >> this situation exceeds the value. This is one shipment. It doesn't >> matter. > > If it stopped there, it would be mildly annoying ("1% of our shipments > will need to be replaced, that's a 1% cost for free replacements"). > The trouble is that they don't care about the replacement either, so > it's really that 100% (or some fairly large proportion) of their > shipments will arrive with some measure of damage, and they're hoping > that their customers' threshold for complaining is often higher than > the damage sustained. Which it probably is, a lot of the time. My wife has gotten several books from Amazon and partners and we have never gotten one loose enough in a big enough box to be damaged. Either the box is tight or has bubble packing. Leaving aside partners, maybe distribution centers have different rules. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Sun Jan 5 17:56:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 06 Jan 2014 09:56:27 +1100 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: <52c9e31d$0$9505$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote: > But this bit looks odd: > > """ > For instance passing a urllib request object to Flask's JSON parse > function breaks on Python 3 but works on Python 2 as a result of this: > >>>> from urllib.request import urlopen >>>> r = urlopen('https://pypi.python.org/pypi/Flask/json') >>>> from flask import json >>>> json.load(r) > Traceback (most recent call last): > File "decoder.py", line 368, in raw_decode > StopIteration > > During handling of the above exception, another exception occurred: > > Traceback (most recent call last): > File "", line 1, in > ValueError: No JSON object could be decoded > """ I'm not sure about the "works on Python 2" part. Is Armin just complaining about the StopIteration being visible in Python 3 but hidden in Python 2? I don't have Flask installed, and aren't going to install it just for this. > Why is a StopIteration bubbling up? (I don't have Flask, so I can't > verify this.) Is it as simple as "this should be raising from None", > or is there something else going on? Remember that "raise Spam from None" only works from Python 3.3 onwards. Personally, I think that releasing nested tracebacks before having a way to suppress the display was a strategic blunder, but it's fixed now, at least for those who can jump straight to 3.3 and not bother supporting 3.1 and 3.2. -- Steven From ben+python at benfinney.id.au Sun Jan 5 18:30:16 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Jan 2014 10:30:16 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice (was: "More About Unicode in Python 2 and 3") References: Message-ID: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Chris Angelico writes: > Maybe it's the better way, but like trying to get people to switch > from MS Word onto an open system, it's far easier to push for Open > Office than for LaTeX. If you're going to be pushing people to a free software system, OpenOffice is no longer the one to choose; its owners several years ago shunted it to a dead end where very little active development can happen, and its development community have moved to more productive ground. Rather, the same code base has since 2010 been actively developed as LibreOffice , and it is now showing far more improvement and document compatibility as a result. In short: Everything that was good about OpenOffice is now called LibreOffice, which had to change its name only because the owners of that name refused to let it go. > Getting your head around a whole new way of thinking about your data > is work, and people want to be lazy. (That's not a bad thing, by the > way. Laziness means schedules get met.) Right. I think shifting people to LibreOffice is an excellent and realistic step toward imcreasing people's software and data freedom. -- \ ?It is far better to grasp the universe as it really is than to | `\ persist in delusion, however satisfying and reassuring.? ?Carl | _o__) Sagan | Ben Finney From emile at fenx.com Sun Jan 5 18:31:28 2014 From: emile at fenx.com (Emile van Sebille) Date: Sun, 05 Jan 2014 15:31:28 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 01/05/2014 02:32 PM, Serhiy Storchaka wrote: > I wonder why nobody complains about the absent of implicit conversion > between int and str. In PHP you can write 2 + "3" and got 5, but in > Python this is an error. So sad! I'd want my implicit conversion of 2 + '3' to get '23' That's why it's not there... Emile From ben+python at benfinney.id.au Sun Jan 5 18:36:16 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 06 Jan 2014 10:36:16 +1100 Subject: [ANN] gg_scrapper -- scrapping of the Google Groups References: <20140104225739.GA32309@wycliff.ceplovi.cz> Message-ID: <7wa9fagfwv.fsf@benfinney.id.au> Matej Cepl writes: > Did you try to archive email list hosted on the Google Groups? Were > you endlessly frustrated by the black hole which is Google Groups, > conscpicious by its absence on the Data Liberation Front website? Yes, > I was too_ Yes, I am very frustrated by everything Google Groups does. It is in sore need of scrapping. > So, I have created a script webscrapping a google group and created > gg_scrapper_ . Hooray! Thank you for any progress toward scrapping Google Groups . I look forward with great hope to Google Groups being scrapped! -- \ ?And if I laugh at any mortal thing, / 'Tis that I may not | `\ weep.? ??Lord? George Gordon Noel Byron, _Don Juan_ | _o__) | Ben Finney From ethan at stoneleaf.us Sun Jan 5 18:45:51 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Jan 2014 15:45:51 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: <52C9EEAF.4000702@stoneleaf.us> On 01/05/2014 03:31 PM, Emile van Sebille wrote: > On 01/05/2014 02:32 PM, Serhiy Storchaka wrote: >> I wonder why nobody complains about the absent of implicit conversion >> between int and str. In PHP you can write 2 + "3" and got 5, but in >> Python this is an error. So sad! > > > I'd want my implicit conversion of 2 + '3' to get '23' Huh. And here I thought 'twenty-three' was the right answer! ;) -- ~Ethan~ From rosuav at gmail.com Sun Jan 5 18:59:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 10:59:59 +1100 Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 6, 2014 at 9:56 AM, Terry Reedy wrote: > On 1/5/2014 11:51 AM, Chris Angelico wrote: >> >> On Mon, Jan 6, 2014 at 3:34 AM, Roy Smith wrote: >>> >>> Amazon's (short-term) goal is to increase their market share by >>> undercutting everybody on price. They have implemented a box-packing >>> algorithm which clearly has a bug in it. You are complaining that they >>> failed to deliver your purchase in good condition, and apparently don't >>> care. You're right, they don't. The cost to them to manually correct >>> this situation exceeds the value. This is one shipment. It doesn't >>> matter. >> >> >> If it stopped there, it would be mildly annoying ("1% of our shipments >> will need to be replaced, that's a 1% cost for free replacements"). >> The trouble is that they don't care about the replacement either, so >> it's really that 100% (or some fairly large proportion) of their >> shipments will arrive with some measure of damage, and they're hoping >> that their customers' threshold for complaining is often higher than >> the damage sustained. Which it probably is, a lot of the time. > > > My wife has gotten several books from Amazon and partners and we have never > gotten one loose enough in a big enough box to be damaged. Either the box is > tight or has bubble packing. Leaving aside partners, maybe distribution > centers have different rules. Or possibly (my personal theory) the CS rep I was talking to just couldn't be bothered solving the problem. Way way too much work to make the customer happy, much easier and cheaper to give a 30% refund and hope that shuts him up. But they managed to ship two books (the original and the replacement) with insufficient packaging. Firstly, that requires the square of the probability of failure; and secondly, if you care even a little bit about making your customers happy, put a little note on the second order instructing people to be particularly careful of this one! Get someone to check it before it's sent out. Make sure it's right this time. I know that's what we used to do in the family business whenever anything got mucked up. (BTW, I had separately confirmed that the problem was with Amazon, and not - as has happened to me with other shipments - caused by Australian customs officials opening the box, looking through it, and then packing it back in without its protection. No, it was shipped that way.) Anyway, this is veering so far off topic that we're at no risk of meeting any Python Alliance ships - as Mal said, we're at the corner of No and Where. But maybe someone can find an on-topic analogy to put some tentative link back into this thread... ChrisA From rosuav at gmail.com Sun Jan 5 19:04:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 11:04:37 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52c9e31d$0$9505$c3e8da3$5496439d@news.astraweb.com> References: <52c9e31d$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 6, 2014 at 9:56 AM, Steven D'Aprano wrote: >> Why is a StopIteration bubbling up? (I don't have Flask, so I can't >> verify this.) Is it as simple as "this should be raising from None", >> or is there something else going on? > > Remember that "raise Spam from None" only works from Python 3.3 onwards. > Personally, I think that releasing nested tracebacks before having a way to > suppress the display was a strategic blunder, but it's fixed now, at least > for those who can jump straight to 3.3 and not bother supporting 3.1 and > 3.2. Fair enough. If it's a problem, I'm sure Flask could do something like (untested): error = False try: next(whatever) except StopIteration: error = True if error: raise ValueError("...") which would work across all. But that's assuming that it really is just a small matter of traceback ugliness. The post implies that it's a lot worse than that. ChrisA From ikorot01 at gmail.com Sun Jan 5 19:06:59 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Sun, 5 Jan 2014 16:06:59 -0800 Subject: django question In-Reply-To: References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: Hi, ALL, Well, my employer does not know anything about web programming and I don't know anything about web programming and this is my first job with python. So since django is a well documented framework I guess it will be easier to go with a well documented framework. Thank you everybody for such a good input. Happy New Year and happy coding in this year as well. ;-) On Sun, Jan 5, 2014 at 1:50 PM, Roy Smith wrote: > In article , > Tim Chase wrote: > >> Integration is one of the things that Django does particularly well: >> out of the box, you get a web framework, database abstraction (ORM), >> templating, out-of-the-box functionality, and PHENOMENAL >> documentation. The others just bring the web-framework to the table >> and *you* then have to choose your templating engine (and ORM if >> you're using one). Some people see this as an advantage, some see it >> as a disadvantage. If you like a particular templating engine (Mako, >> Jinja, etc) or ORM (SQLAlchemy, SQLObject, etc), you /can/ use them in >> Django or other frameworks, but in Django, you'd be fighting the >> Django Way? and don't get to take advantage of some of the tight >> integration in areas where it does some of the hard work for you >> (such as integration into the admin interface). > > On the other hand, it's all modular enough that it's quite reasonable to > plug in your own components. > > For example, at Songza, we don't use the django ORM at all (we use > mongoengine). We also have a number of django-based services which > don't use templates at all (we return JSON objects). Neither of these > required any major surgery to do this. > > In fact, for a lot of what we do, all we really get from django is the > request parsing, URL routing, middleware scaffolding, and cache > interface. But, that's enough to be worthwhile. > >> I haven't found it to be that easy to directly transition projects >> between Django and other frameworks. > > One of the things we try to do is put as little in the views as > possible. Views should be all about accepting and validating request > parameters, and generating output (be that HTML via templates, or JSON, > or whatever). All the business logic should be kept isolated from the > views. The better (and more disciplined) you are about doing this, the > easier it will be to move your business logic to a different framework. > > That's not to say it will be *easy*, but you can certainly make things > harder on yourself than they need to be if you don't keep things > distinct. > > Oh, and yes, the django team does a really amazing job on the docs. > > -- > https://mail.python.org/mailman/listinfo/python-list > From rosuav at gmail.com Sun Jan 5 19:09:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 11:09:07 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52C9EEAF.4000702@stoneleaf.us> References: <52C9EEAF.4000702@stoneleaf.us> Message-ID: On Mon, Jan 6, 2014 at 10:45 AM, Ethan Furman wrote: > On 01/05/2014 03:31 PM, Emile van Sebille wrote: >> >> On 01/05/2014 02:32 PM, Serhiy Storchaka wrote: >>> >>> I wonder why nobody complains about the absent of implicit conversion >>> between int and str. In PHP you can write 2 + "3" and got 5, but in >>> Python this is an error. So sad! >> >> I'd want my implicit conversion of 2 + '3' to get '23' > > Huh. And here I thought 'twenty-three' was the right answer! ;) I quite like 2+"3" being "23", as it simplifies a lot of string manipulation. But there's another option: 2+"3456" could be "56". That one makes even more sense... doesn't it? I mean, C does it so it must make sense... ChrisA From rosuav at gmail.com Sun Jan 5 19:23:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 11:23:02 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice (was: "More About Unicode in Python 2 and 3") In-Reply-To: <7wfvp2gg6v.fsf_-_@benfinney.id.au> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: On Mon, Jan 6, 2014 at 10:30 AM, Ben Finney wrote: > Chris Angelico writes: > >> Maybe it's the better way, but like trying to get people to switch >> from MS Word onto an open system, it's far easier to push for Open >> Office than for LaTeX. > > If you're going to be pushing people to a free software system, > OpenOffice is no longer the one to choose; its owners several years ago > shunted it to a dead end where very little active development can > happen, and its development community have moved to more productive > ground. Handwave, handwave. The FOSS office suite that comes conveniently in the Debian repositories. It was OO a while ago, it's now LO, but same difference. If LO ever renames and becomes FreeOffice or ZOffice or anything else under the sun, it would still be the easier option for MS Word users to switch to. (And actually, I haven't been pushing people off MS Word so much as off DeScribe Word Processor. But since most people here won't have heard of that, I went for the more accessible analogy.) >> Getting your head around a whole new way of thinking about your data >> is work, and people want to be lazy. (That's not a bad thing, by the >> way. Laziness means schedules get met.) > > Right. I think shifting people to LibreOffice is an excellent and > realistic step toward imcreasing people's software and data freedom. Yeah. Which is why I do it. But the other night, my mum was trying to lay out her book in LO, and was having some problems with the system of having each chapter in a separate file. (Among other things, styles weren't shared across them all, so a tweak to a style means opening up every chapter and either doing a parallel edit or figuring out how to import styles.) So yes, it's a realistic and worthwhile step, but it's not a magic solution to all problems. She doesn't have time to learn a whole new system. Maybe - in the long term - LaTeX would actually save her time, but it's certainly a much harder 'sell' than LO. ChrisA From ethan at stoneleaf.us Sun Jan 5 19:13:32 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Jan 2014 16:13:32 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52c9e31d$0$9505$c3e8da3$5496439d@news.astraweb.com> References: <52c9e31d$0$9505$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52C9F52C.2010103@stoneleaf.us> On 01/05/2014 02:56 PM, Steven D'Aprano wrote: > > Remember that "raise Spam from None" only works from Python 3.3 onwards. > Personally, I think that releasing nested tracebacks before having a way to > suppress the display was a strategic blunder [...] I would just call it really really annoying. ;) On the upside adding 'from None' was a small enough project that I was able to get it going, and that was the bridge to eventually becoming a dev. :D -- ~Ethan~ From drsalists at gmail.com Sun Jan 5 19:39:55 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Jan 2014 16:39:55 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Sun, Jan 5, 2014 at 2:32 PM, Serhiy Storchaka wrote: > I wonder why nobody complains about the absent of implicit conversion > between int and str. In PHP you can write 2 + "3" and got 5, but in Python > this is an error. So sad! I like Python strongly typed, thank you very much. Please don't break it. Not raising an exception when implicitly converting types tends to lead to hard-to-track-down bugs. From steve+comp.lang.python at pearwood.info Sun Jan 5 19:42:14 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 06 Jan 2014 11:42:14 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52c9fbe8$0$29969$c3e8da3$5496439d@news.astraweb.com> Chris Angelico wrote about Amazon: > And yet.... I can't disagree with your final conclusion. Empirical > evidence goes against my incredulous declaration that "surely this is > a bad idea" - according to XKCD 1165, they're kicking out nearly a > cubic meter a SECOND of packages. Yes, but judging by what you described as their packing algorithm that's probably only a tenth of a cubic metre of *books*, the rest being empty box for the book to rattle around in and get damaged. -- Steven From ned at nedbatchelder.com Sun Jan 5 20:16:47 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 05 Jan 2014 20:16:47 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/14 8:22 AM, Ned Batchelder wrote: > On 1/5/14 8:14 AM, Mark Lawrence wrote: >> http://lucumr.pocoo.org/2014/1/5/unicode-in-2-and-3/ >> >> Please don't shoot the messenger :) >> > > With all of the talk about py 2 vs. py3 these days, this is the blog > post that I think deserves the most real attention. I haven't had to do > the kind of coding that Armin is talking about, but I've heard more than > one person talk about the difficulty of it in Python 3. > > If anyone wants Python 3 uptake improved, the best thing would be to > either explain to Armin how he missed the easy way to do what he wants > (seems unlikely), or advocate to the core devs why they should change > things to improve this situation. > OK, let's see what we got from three core developers on this list: - Antoine dismissed the post as "a rant". - Terry took issue with three claims made, and ended with, "I suspect there are other basic errors, but I mostly quit reading at this point." - Serhiy made a sarcastic comment comparing Python 3's bytes/unicode handling with Python 2's int/str handling, implying that since int/str wasn't a problem, then bytes/unicode isn't either. This is discouraging. Armin is a prolific and well-known contributor to a number of very popular packages. He's devoted a great deal of time to the Python ecosystem, including writing the PEP that got u"" literals back in Python 3.3. If he's having trouble with Python 3, it's a serious problem. You can look through his problems and decide that he's "wrong," or that he's "ranting," but that doesn't change the fact that Python 3 is encountering friction. What happens when a significant fraction of your customers are "wrong"? Core developers: I thank you for the countless hours you have devoted to building all of the versions of Python. I'm sure in many ways it's a thankless task. But you have a problem. What's the point in being right if you end up with a product that people don't use? If Armin, with all of his skills and energy, is having problems using your product, then there's a problem. Compounding that problem is the attitude that dismisses him as wrong. Kenneth Reitz's reaction to Armin's blog post was: "A fantastic article about why Python 2 is a superior programming language for my personal use case." https://twitter.com/kennethreitz/status/419889312935993344 So now we have two revered developers vocally having trouble with Python 3. You can dismiss their concerns as niche because it's only network programming, but that would be a mistake. Given the centrality of network programming in today's world, and the dominance these two developers have in building libraries to solve networking problems, I think someone should take their concerns seriously. Maybe there are core developers who are trying hard to solve the problems Kenneth and Armin are facing. It would be great if that work was more visible. I don't see it, and apparently Armin doesn't either. -- Ned Batchelder, http://nedbatchelder.com From steve+comp.lang.python at pearwood.info Sun Jan 5 20:23:15 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Mon, 06 Jan 2014 12:23:15 +1100 Subject: Blog "about python 3" References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52ca0584$0$29982$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Sun, Jan 5, 2014 at 2:20 PM, Roy Smith wrote: >> > I've got a new sorting algorithm which is guaranteed to cut 10 seconds >> > off the sorting time (i.e. $0.10 per package). The problem is, it >> > makes a mistake 1% of the time. >> >> That's a valid line of argument in big business, these days, because >> we've been conditioned to accept low quality. But there are places >> where quality trumps all, and we're happy to pay for that. Allow me to >> expound two examples. >> >> 1) Amazon >> >> http://www.amazon.com/exec/obidos/ASIN/1782010165/evertype-20 >> >> I bought this book a while ago. It's about the size of a typical >> paperback. It arrived in a box too large for it on every dimension, >> with absolutely no packaging. I complained. Clearly their algorithm >> was: "Most stuff will get there in good enough shape, so people can't >> be bothered complaining. And when they do complain, it's cheaper to >> ship them another for free than to debate with them on chat." > > You're missing my point. > > Amazon's (short-term) goal is to increase their market share by > undercutting everybody on price. They have implemented a box-packing > algorithm which clearly has a bug in it. You are complaining that they > failed to deliver your purchase in good condition, and apparently don't > care. You're right, they don't. The cost to them to manually correct > this situation exceeds the value. This is one shipment. It doesn't > matter. You are one customer, you don't matter either. Seriously. > This may be annoying to you, but it's good business for Amazon. For > them, fast and cheap is absolutely better than correct. One, you're missing my point that to Amazon, "fast and cheap" *is* correct. They would not agree with you that their box-packing algorithm is buggy, so long as their customers don't punish them for it. It meets their requirements: ship parcels as quickly as possible, and push as many of the costs (damaged books) onto the customer as they can get away with. If they thought it was buggy, they would be trying to fix it. Two, nobody is arguing against the concept that different parties have different concepts of what's correct. To JMF, the flexible string representation is buggy, because he's detected a trivially small slowdown in some artificial benchmarks. To everyone else, it is not buggy, because it does what it sets out to do: save memory while still complying with the Unicode standard. A small slowdown on certain operations is a cost worth paying. Normally, the definition of "correct" that matters is that belonging to the paying customer, or failing that, the programmer who is giving his labour away for free. (Extend this out to more stakeholders if you wish, but the more stakeholders you include, the harder it is to get consensus on what's correct and what isn't.) From the perspective of Amazon's customers, presumably so long as the cost of damaged and lost books isn't too high, they too are willing to accept Amazon's definition of "correct" in order to get cheap books, or else they would buy from someone else. (However, to the extent that Amazon has gained monopoly power over the book market, that reasoning may not apply. Amazon is not *technically* a monopoly, but they are clearly well on the way to becoming one, at which point the customer has no effective choice and the market is no longer free.) The Amazon example is an interesting example of market failure, in the sense that the free market provides a *suboptimal solution* to a problem. We'd all like reasonably-priced books AND reliable delivery, but maybe we can't have both. Personally, I'm not so sure about that. Maybe Jeff Bezos could make do with only five solid gold Mercedes instead of ten[1], for the sake of improved delivery? But apparently not. But I digress... ultimately, you are trying to argue that there is a single absolute source of truth for what counts as "correct". I don't believe there is. We can agree that some things are clearly not correct -- Amazon takes your money and sets the book on fire, or hires an armed military escort costing $20 million a day to deliver your book of funny cat pictures. We might even agree on what we'd all like in a perfect world: cheap books, reliable delivery, and a pony. But in practice we have to choose some features over others, and compromise on requirements, and ultimately we have to make a *pragmatic* choice on what counts as correct based on the functional requirements, not on a wishlist of things we'd like with infinite time and money. Sticking to the Amazon example, what percentage of books damaged in delivery ceases to be a bug in the packing algorithm and becomes "just one of those things"? One in ten? One in ten thousand? One in a hundred billion billion? I do not accept that "book gets damaged in transit" counts as a bug. "More than x% of books get damaged", that's a bug. "Average cost to ship a book is more than $y" is a bug. And Amazon gets to decide what the values of x% and $y are. > I'm not saying this is always the case. Clearly, there are companies > which have been very successful at producing a premium product (Apple, > for example). I'm not saying that fast is always better than correct. > I'm just saying that correct is not always better than fast. In the case of Amazon, "correct" in the sense of "books are packed better" is not better than fast. It's better for the customer, and better for society as a whole (less redundant shipping and less ecological harm), but not better for Amazon. Since Amazon gets to decide what's better, their greedy, short-term outlook wins, at least until such time as customers find an alternative. Amazon would absolutely not agree with you that packing the books more securely is "better", if they did, they would do it. They're not stupid, just focused on short-term gain for themselves at the expense of everyone else. (Perhaps a specialised, and common, form of stupidity.) By the way, this whole debate is known as "Worse is better", and bringing it back to programming languages and operating systems, you can read more about it here: http://www.jwz.org/doc/worse-is-better.html [1] Figuratively speaking. -- Steven From ethan at stoneleaf.us Sun Jan 5 19:46:58 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Jan 2014 16:46:58 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: <52C9FD02.3080109@stoneleaf.us> On 01/05/2014 05:14 AM, Mark Lawrence wrote: > > Please don't shoot the messenger :) While I don't agree with his assessment of Python 3 in total, I definitely feel his pain with regards to bytestrings in Py3 -- because they don't exist. 'bytes' /looks/ like a bytestring, but really it's just a bunch of integers: --> b'abc 'b'abc' --> b'abc'[1] 98 Maybe for 3.5 somebody *cough* will make a bytestring type for those of us who have to support the lower-level protocols... -- ~Ethan~ *Cast your vote over on Python Ideas! From rhodri at wildebst.org.uk Sun Jan 5 20:40:02 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Mon, 06 Jan 2014 01:40:02 -0000 Subject: Postfix conditionals References: Message-ID: On Sun, 05 Jan 2014 20:24:53 -0000, G?ktu? Kayaalp wrote: > AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition > appended to a statement, which determines whether the statement runs or > not: > py> for i in [False]: > ... break if not i > The above piece of code is equivalent to this in Python: > py> for i in [False]: > ... if not i > ... break > I believe that the first example is superior to the second example when > the two is compared for readability and intuitiveness. In my past life as a newcomer to Perl, I thought this too. Postfix conditionals read more like English, so they would be easier to take in and understand. As I wrote more code, I discovered that this didn't seem to be the case; except in very simple cases, I had to mentally transpose the conditional back to the start of the statement to properly comprehend what was going on and what the results would be for my sample data. It looks like a good idea, but I don't think it works that well in practice. -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Sun Jan 5 20:48:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 12:48:03 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 12:16 PM, Ned Batchelder wrote: > So now we have two revered developers vocally having trouble with Python 3. > You can dismiss their concerns as niche because it's only network > programming, but that would be a mistake. IMO, network programming (at least on the internet) is even more Py3's domain (pun not intended). 1) The internet is global. You WILL come across other languages, other scripts, everything. 2) In most cases, everything is clearly either text or binary, and usually text has an associated (and very clear) encoding (eg HTTP headers). If it's not explicitly given, the RFCs will often stipulate what the encoding should be. It's pretty easy, you don't have to go "Is this Latin-1? Maybe CP-1252? Could it be something else?". 3) The likelihood is high that you'll be working with someone else's code at the other end. Ties in with #2 - this is why the specs are so carefully written. Getting these things right is incredibly important. If I'm writing something that might have to work with anything from anywhere, I want a system that catches potential errors earlier rather than later. I don't want to write interpolated SQL that works perfectly until Mr O'Hara tries to sign up (or, worse, young Robert whose sister is named "Help I'm trapped in a driver's license factory"); I want to get it right from the start. Yes, that means more work to get "Hello, World" going. Yes, it means that I need to get my head around stuff that I didn't think I'd have to. (One time I implemented Oauth manually rather than using a library - the immediate reason was some kind of issue with the library, but I was glad I did, because it meant I actually understood what was going on; came in handy about two weeks later when the far end had a protocol problem.) Most of the complaints about Py3 are "it's harder to get something started (or port from Py2)". My answer is that it's easier to get something finished. ChrisA From rosuav at gmail.com Sun Jan 5 20:54:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 12:54:48 +1100 Subject: Blog "about python 3" In-Reply-To: <52ca0584$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> <52ca0584$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 6, 2014 at 12:23 PM, Steven D'Aprano wrote: > (However, to the extent that Amazon has gained monopoly power over the book > market, that reasoning may not apply. Amazon is not *technically* a > monopoly, but they are clearly well on the way to becoming one, at which > point the customer has no effective choice and the market is no longer > free.) They don't need a monopoly on the whole book market, just on specific books - which they did have, in the cited case. I actually asked the author (translator, really - it's a translation of "Alice in Wonderland") how he would prefer me to buy, as there are some who sell on Amazon and somewhere else. There was no alternative to Amazon, ergo no choice and the market was not free. Like so many things, one choice ("I want to buy Ailice's Anters in Ferlielann") mandates another ("Must buy through Amazon"). I don't know what it cost Amazon to ship me two copies of a book, but still probably less than they got out of me, so they're still ahead. Even if they lost money on this particular deal, they're still way ahead because of all the people who decide it's not worth their time to spend an hour or so trying to get a replacement. So yep, this policy is serving Amazon fairly well. ChrisA From roy at panix.com Sun Jan 5 20:56:51 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 20:56:51 -0500 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: In article , Chris Angelico wrote: > One time I implemented Oauth manually rather than using a library Me too. You have my sympathy. What a mess. From ned at nedbatchelder.com Sun Jan 5 21:17:05 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 05 Jan 2014 21:17:05 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/14 8:48 PM, Chris Angelico wrote: > On Mon, Jan 6, 2014 at 12:16 PM, Ned Batchelder wrote: >> So now we have two revered developers vocally having trouble with Python 3. >> You can dismiss their concerns as niche because it's only network >> programming, but that would be a mistake. > > IMO, network programming (at least on the internet) is even more Py3's > domain (pun not intended). > > 1) The internet is global. You WILL come across other languages, other > scripts, everything. > > 2) In most cases, everything is clearly either text or binary, and > usually text has an associated (and very clear) encoding (eg HTTP > headers). If it's not explicitly given, the RFCs will often stipulate > what the encoding should be. It's pretty easy, you don't have to go > "Is this Latin-1? Maybe CP-1252? Could it be something else?". > > 3) The likelihood is high that you'll be working with someone else's > code at the other end. Ties in with #2 - this is why the specs are so > carefully written. Getting these things right is incredibly important. > > If I'm writing something that might have to work with anything from > anywhere, I want a system that catches potential errors earlier rather > than later. I don't want to write interpolated SQL that works > perfectly until Mr O'Hara tries to sign up (or, worse, young Robert > whose sister is named "Help I'm trapped in a driver's license > factory"); I want to get it right from the start. Yes, that means more > work to get "Hello, World" going. Yes, it means that I need to get my > head around stuff that I didn't think I'd have to. (One time I > implemented Oauth manually rather than using a library - the immediate > reason was some kind of issue with the library, but I was glad I did, > because it meant I actually understood what was going on; came in > handy about two weeks later when the far end had a protocol problem.) > > Most of the complaints about Py3 are "it's harder to get something > started (or port from Py2)". My answer is that it's easier to get > something finished. I like all of this logic, it makes sense to me. But Armin and Kenneth have more experience than I do actually writing networking software. They are both very smart and very willing to do a ton of work. And both are unhappy. I don't know how to square that with the logic that makes sense to me. And no amount of logic about why Python 3 is better is going to solve the problem of the two of them being unhappy. They are speaking from experience working with the actual product. I'm not trying to convince anyone that Python 3 is good or bad. I'm talking about our approach to unhappy and influential customers. -- Ned Batchelder, http://nedbatchelder.com From dreamingforward at gmail.com Sun Jan 5 21:25:37 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Sun, 5 Jan 2014 20:25:37 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: >> Most of the complaints about Py3 are "it's harder to get something >> started (or port from Py2)". My answer is that it's easier to get >> something finished. > > I like all of this logic, it makes sense to me. But Armin and Kenneth have > more experience than I do actually writing networking software. They are > both very smart and very willing to do a ton of work. And both are unhappy. > I don't know how to square that with the logic that makes sense to me. > > And no amount of logic about why Python 3 is better is going to solve the > problem of the two of them being unhappy. They are speaking from experience > working with the actual product. +1, well-said. I hope you'll see my comments on the thread on the "bytestring type". This issue also goes back to the schism in 2004 from the VPython folks over floating point. Again the ***whole*** issue is ignoring the relationship between your abstractions and your concrete architectural implementations. I honestly think Python3 will have to be regressed despite all the circle jerking about how "everyone's moving to Python 3 now". I see how I was inadequately explaining the whole issue by using high-level concepts like "models of computation", but the comments on the aforementioned thread go right down to the heart of the issue. markj From drsalists at gmail.com Sun Jan 5 21:37:40 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 5 Jan 2014 18:37:40 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52C9FD02.3080109@stoneleaf.us> References: <52C9FD02.3080109@stoneleaf.us> Message-ID: On Sun, Jan 5, 2014 at 4:46 PM, Ethan Furman wrote: > While I don't agree with his assessment of Python 3 in total, I definitely > feel his pain with regards to bytestrings in Py3 -- because they don't > exist. 'bytes' /looks/ like a bytestring, but really it's just a bunch of > integers: > > --> b'abc > 'b'abc' > --> b'abc'[1] > 98 > > Maybe for 3.5 somebody *cough* will make a bytestring type for those of us > who have to support the lower-level protocols... I don't see anything wrong with the new bytes type, including the example above. I wrote a backup program that used bytes or str's (3.x or 2.x respectively), and they both worked fine for that. I had to code around some limited number of surprises, but they weren't substantive problems, they were just differences. The argument seems to be "3.x doesn't work the way I'm accustomed to, so I'm not going to use it, and I'm going to shout about it until others agree with me." And yes, I read Armin's article - it was pretty long.... Also, I never once wrote a program to use 2.x's unicode type. I always used str. It was important to make str handle unicode, to get people (like me!) to actually use unicode. Two modules helped me quite a bit with backshift, the backup program I mentioned: http://stromberg.dnsalias.org/~dstromberg/backshift/documentation/html/python2x3-module.html http://stromberg.dnsalias.org/~dstromberg/backshift/documentation/html/bufsock-module.html python2x3 is tiny, and similar in spirit to the popular six module. bufsock is something I wrote years ago that enables consistent I/O on sockets, files or file descriptors; 2.x or 3.x. HTH From ethan at stoneleaf.us Sun Jan 5 21:23:57 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 05 Jan 2014 18:23:57 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: <52CA13BD.4050708@stoneleaf.us> On 01/05/2014 05:48 PM, Chris Angelico wrote: > On Mon, Jan 6, 2014 at 12:16 PM, Ned Batchelder wrote: >> So now we have two revered developers vocally having trouble with Python 3. >> You can dismiss their concerns as niche because it's only network >> programming, but that would be a mistake. > > IMO, network programming (at least on the internet) is even more Py3's > domain (pun not intended). The issue is not how to handle text, the issue is how to handle ascii when it's in a bytes object. Using my own project [1] as a reference: good ol' dbf files -- character fields, numeric fields, logic fields, time fields, and of course the metadata that describes these fields and the dbf as a whole. The character fields I turn into unicode, no sweat. The metadata fields are simple ascii, and in Py2 something like `if header[FIELD_TYPE] == 'C'` did the job just fine. In Py3 that compares an int (67) to the unicode letter 'C' and returns False. For me this is simply a major annoyance, but I only have a handful of places where I have to deal with this. Dealing with protocols where bytes is the norm and embedded ascii is prevalent -- well, I can easily imagine the nightmare. The most unfortunate aspect is that even if we did "fix" it in 3.5, it wouldn't help any body who has to support multiple versions... unless, of course, a backport could also be made. -- ~Ethan~ From rosuav at gmail.com Sun Jan 5 21:55:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 13:55:34 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52CA13BD.4050708@stoneleaf.us> References: <52CA13BD.4050708@stoneleaf.us> Message-ID: On Mon, Jan 6, 2014 at 1:23 PM, Ethan Furman wrote: > The metadata fields are simple ascii, and in Py2 something like `if > header[FIELD_TYPE] == 'C'` did the job just fine. In Py3 that compares an > int (67) to the unicode letter 'C' and returns False. For me this is simply > a major annoyance, but I only have a handful of places where I have to deal > with this. Dealing with protocols where bytes is the norm and embedded > ascii is prevalent -- well, I can easily imagine the nightmare. It can't be both things. It's either bytes or it's text. If it's text, then decoding it as ascii will give you a Unicode string; if it's small unsigned integers that just happen to correspond to ASCII values, then I would say the right thing to do is integer constants - or, in Python 3.4, an integer enumeration: >>> socket.AF_INET >>> socket.AF_INET == 2 True I'm not sure what FIELD_TYPE of 'C' means, but my guess is that it's a CHAR field. I'd just have that as the name, something like: CHAR = b'C'[0] if header[FIELD_TYPE] == CHAR: # handle char field If nothing else, this would reduce the number of places where you actually have to handle this. Plus, the code above will work on many versions of Python (I'm not sure how far back the b'' prefix is allowed - probably 2.6). ChrisA From tjreedy at udel.edu Sun Jan 5 21:58:46 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 21:58:46 -0500 Subject: Postfix conditionals In-Reply-To: <52C9BF95.5000006@gkayaalp.com> References: <52C9BF95.5000006@gkayaalp.com> Message-ID: On 1/5/2014 3:24 PM, G?ktu? Kayaalp wrote: > Hi, > > AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition > appended to a > statement, which determines whether the statement runs or not: > > py> for i in [False]: > ... break if not i > > The above piece of code is equivalent to this in Python: > > py> for i in [False]: > ... if not i > ... break > > I believe that the first example is superior to the second example when > the two is compared > for readability and intuitiveness. We already have a ternary statement 'conditional expression', which happens to be a ternary as opposed to binary expression. > that looks similar, > > py> print('hi') if True else None > > so I reckon there would be no breakage in old code if this kind of > syntax was added. Ruby has > this, and AFAIK Perl also does. > > I lack the knowledge of whether the community has opinions on this kind > of notation, In general, negative on pure duplication. Guido has said he strongly dislikes the perl reverse if. -- Terry Jan Reedy From roy at panix.com Sun Jan 5 23:05:01 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 23:05:01 -0500 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: In article , Mark Janssen wrote: > I honestly think Python3 will have to be regressed despite all the > [obscenity elided] about how "everyone's moving to Python 3 now". This forum has seen a lot honest disagreement about issues, sometimes hotly debated. That's OK. Sometimes the discussion has not been completely professional, which is less than wonderful, but everything can't always be wonderful. There is absolutely no reason, however, to resort to profanity. That's just unacceptable. From roy at panix.com Sun Jan 5 23:24:11 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 23:24:11 -0500 Subject: "More About Unicode in Python 2 and 3" References: <52CA13BD.4050708@stoneleaf.us> Message-ID: In article , Chris Angelico wrote: > It can't be both things. It's either bytes or it's text. I've never used Python 3, so forgive me if these are naive questions. Let's say you had an input stream which contained the following hex values: $ hexdump data 0000000 d7 a8 a3 88 96 95 That's EBCDIC for "Python". What would I write in Python 3 to read that file and print it back out as utf-8 encoded Unicode? Or, how about a slightly different example: $ hexdump data 0000000 43 6c 67 75 62 61 That's "Python" in rot-13 encoded ascii. How would I turn that into cleartext Unicode in Python 3? From tjreedy at udel.edu Sun Jan 5 23:26:14 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 05 Jan 2014 23:26:14 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/2014 8:16 PM, Ned Batchelder wrote: > OK, let's see what we got from three core developers on this list: To me, the following is a partly unfair summary. > - Antoine dismissed the post as "a rant". He called it a rant while acknowledging that there is a unsolved issue with transforms. Whether he was 'dismissing' it or not, I do not know. Antoine also noted that there does not seem to be anything new in this post that Armin has not said before. Without reading in detail, I had the same impression. > - Terry took issue with three claims made, and ended with, "I suspect > there are other basic errors, but I mostly quit reading at this point." You are discouraged that I quit reading? How much sludge do you expect me to wade through? If Armin wants my attention (and I do not think he does), it is *his* responsibility to write in a readable manner. But I read a bit more and found a 4th claim to 'take issue with' (to be polite): "only about 3% of all Python developers using Python 3 properly" with a link to http://alexgaynor.net/2014/jan/03/pypi-download-statistics/ The download statistics say nothing about the percent of all Python developers using Python 3, let alone properly, and Alex Gaynor makes no such claim as Armin did. I would not be surprised if a majority of Python users have never downloaded from pypi. What I do know from reading the catalog-sig (pypi) list for a couple of years is that there are commercial developers who use pypi heavily to update 1000s of installations and that they drive the development of the pypi infrastructure. I strongly suspect that they strongly skew the download statistics. Dubious claim 5 is this: "For 97% of us, Python 2 is our beloved world for years to come". For Armin's narrow circle, that may be true, but I suspect that more than 3% of Python programmers have never written Python2 only code. > - Serhiy made a sarcastic comment comparing Python 3's bytes/unicode > handling with Python 2's int/str handling, implying that since int/str > wasn't a problem, then bytes/unicode isn't either. Serhiy's point was about the expectation of implicit conversion (int/str) versus (bytes/str) and the complaint about removal of implicit conversion. I suspect that part of his point is that if we never had implicit bytes/unicode conversion, it would not be expected. -- Terry Jan Reedy From python.list at tim.thechases.com Sun Jan 5 23:41:23 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 5 Jan 2014 22:41:23 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Message-ID: <20140105224123.78609d58@bigbox.christie.dr> On 2014-01-05 23:24, Roy Smith wrote: > $ hexdump data > 0000000 d7 a8 a3 88 96 95 > > That's EBCDIC for "Python". What would I write in Python 3 to read > that file and print it back out as utf-8 encoded Unicode? > > Or, how about a slightly different example: > > $ hexdump data > 0000000 43 6c 67 75 62 61 > > That's "Python" in rot-13 encoded ascii. How would I turn that > into cleartext Unicode in Python 3? tim at laptop$ python3 Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s1 = b'\xd7\xa8\xa3\x88\x96\x95' >>> s1.decode('ebcdic-cp-be') 'Python' >>> s2 = b'\x43\x6c\x67\x75\x62\x61' >>> from codecs import getencoder >>> getencoder("rot-13")(s2.decode('utf-8'))[0] 'Python' -tkc From roy at panix.com Sun Jan 5 23:49:47 2014 From: roy at panix.com (Roy Smith) Date: Sun, 05 Jan 2014 23:49:47 -0500 Subject: "More About Unicode in Python 2 and 3" References: <52CA13BD.4050708@stoneleaf.us> Message-ID: In article , Tim Chase wrote: > On 2014-01-05 23:24, Roy Smith wrote: > > $ hexdump data > > 0000000 d7 a8 a3 88 96 95 > > > > That's EBCDIC for "Python". What would I write in Python 3 to read > > that file and print it back out as utf-8 encoded Unicode? > > > > Or, how about a slightly different example: > > > > $ hexdump data > > 0000000 43 6c 67 75 62 61 > > > > That's "Python" in rot-13 encoded ascii. How would I turn that > > into cleartext Unicode in Python 3? > > > tim at laptop$ python3 > Python 3.2.3 (default, Feb 20 2013, 14:44:27) > [GCC 4.7.2] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> s1 = b'\xd7\xa8\xa3\x88\x96\x95' > >>> s1.decode('ebcdic-cp-be') > 'Python' > >>> s2 = b'\x43\x6c\x67\x75\x62\x61' > >>> from codecs import getencoder > >>> getencoder("rot-13")(s2.decode('utf-8'))[0] > 'Python' > > -tkc Thanks. But, I see I didn't formulate my problem statement well. I was (naively) assuming there wouldn't be a built-in codec for rot-13. Let's assume there isn't; I was trying to find a case where you had to treat the data as integers in one place and text in another. How would you do that? From rosuav at gmail.com Sun Jan 5 23:51:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 15:51:09 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Message-ID: On Mon, Jan 6, 2014 at 3:24 PM, Roy Smith wrote: > I've never used Python 3, so forgive me if these are naive questions. > Let's say you had an input stream which contained the following hex > values: > > $ hexdump data > 0000000 d7 a8 a3 88 96 95 > > That's EBCDIC for "Python". What would I write in Python 3 to read that > file and print it back out as utf-8 encoded Unicode? *deletes the two paragraphs that used to be here* Turns out Python 3 _does_ have an EBCDIC decoder... but it's not called EBCDIC. >>> b"\xd7\xa8\xa3\x88\x96\x95".decode("cp500") 'Python' This sounds like a good one for getting an alias, either "ebcdic" or "EBCDIC". I didn't know that this was possible till I googled the problem and saw someone else's solution. To print that out as UTF-8, just decode and then encode: >>> b"\xd7\xa8\xa3\x88\x96\x95".decode("cp500").encode("utf-8") b'Python' In the specific case of files on the disk, you could open them with encodings specified, in which case you don't need to worry about the details. with open("data",encoding="cp500") as infile: with open("data_utf8","w",encoding="utf-8") as outfile: outfile.write(infile.read()) Of course, this is assuming that Unicode has a perfect mapping for every EBCDIC character. I'm not familiar enough with EBCDIC to be sure that that's true, but I strongly suspect it is. And if it's not, you'll get an exception somewhere along the way, so you'll know something's gone wrong. (In theory, a "transcode" function might be able to give you a warning before it even sees your data - transcode("utf-8", "iso-8859-3") could alert you to the possibility that not everything in the source character set can be encoded. But that's a pretty esoteric requirement.) > Or, how about a slightly different example: > > $ hexdump data > 0000000 43 6c 67 75 62 61 > > That's "Python" in rot-13 encoded ascii. How would I turn that into > cleartext Unicode in Python 3? That's one of the points that's under dispute. Is rot13 a bytes<->bytes encoding, or is it str<->str, or is it bytes<->str? The issue isn't clear. Personally, I think it makes good sense as a str<->str translation, which would mean that the process would be somewhat thus: >>> rot13={} >>> for i in range(13): rot13[65+i]=65+i+13 rot13[65+i+13]=65+i rot13[97+i]=97+i+13 rot13[97+i+13]=97+i >>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to turn a hex dump into a bytes literal? >>> data.decode().translate(rot13) 'Python' This is treating rot13 as a translation of Unicode codepoints to other Unicode codepoints, which is different from an encode operation (which takes abstract Unicode data and produces concrete bytes) or a decode operation (which does the reverse). But this is definitely a grey area. It's common for cryptographic algorithms to work with bytes, meaning that their "decoded" text is still bytes. (Or even less than bytes. The famous Enigma machines from World War II worked with the 26 letters as their domain and range.) Should the Python codecs module restrict itself to the job of translating between bytes and str, or is it a tidy place to put those other translations as well? ChrisA From rosuav at gmail.com Sun Jan 5 23:59:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 6 Jan 2014 15:59:34 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Message-ID: On Mon, Jan 6, 2014 at 3:49 PM, Roy Smith wrote: > Thanks. But, I see I didn't formulate my problem statement well. I was > (naively) assuming there wouldn't be a built-in codec for rot-13. Let's > assume there isn't; I was trying to find a case where you had to treat > the data as integers in one place and text in another. How would you do > that? I assumed that you would have checked that one, and answered accordingly :) Though I did dig into the EBCDIC part of the question. My thinking is that, if you're working with integers, you probably mean either bytes (so encode it before you do stuff - typical for crypto) or codepoints / Unicode ordinals (so use ord()/chr()). In other languages there are ways to treat strings as though they were arrays of integers (lots of C-derived languages treat 'a' as 97 and "a"[0] as 97 also; some extend this to the full Unicode range), and even there, I almost never actually use that identity much. There's only one case that I can think of where I did a lot of string<->integer-array transmutation, and that was using a diff function that expected an integer array - if the transformation to and from strings hadn't been really easy, that function would probably have been written to take strings. The Py2 str.translate() method was a little clunky to use, but presumably fast to execute - you build up a lookup table and translate through that. The Py3 equivalent takes a dict mapping the from and to values. Pretty easy to use. And it lets you work with codepoints or strings, as you please. ChrisA From prapulla447 at gmail.com Sun Jan 5 23:36:02 2014 From: prapulla447 at gmail.com (Prapulla Kumar) Date: Mon, 6 Jan 2014 10:06:02 +0530 Subject: Reg : Creating a exe file from pyinstaller of python application Message-ID: Hi, I'm creating GUI using python gtk, and which uses external library gtk , M2Crypto I want make executable file by using pyinstaller, Which is not including external library How to make external library include into executable file . Can you give any suggestion how to import external library in make of executable file in windows xp. Thanks & With Regards Prapulla -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Jan 6 00:53:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 05:53:12 +0000 Subject: Blog "about python 3" In-Reply-To: References: <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <52c8c301$0$29998$c3e8da3$5496439d@news.astraweb.com> <52ca0584$0$29982$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/01/2014 01:54, Chris Angelico wrote: > On Mon, Jan 6, 2014 at 12:23 PM, Steven D'Aprano > wrote: >> (However, to the extent that Amazon has gained monopoly power over the book >> market, that reasoning may not apply. Amazon is not *technically* a >> monopoly, but they are clearly well on the way to becoming one, at which >> point the customer has no effective choice and the market is no longer >> free.) > > They don't need a monopoly on the whole book market, just on specific > books - which they did have, in the cited case. I actually asked the > author (translator, really - it's a translation of "Alice in > Wonderland") how he would prefer me to buy, as there are some who sell > on Amazon and somewhere else. There was no alternative to Amazon, ergo > no choice and the market was not free. Like so many things, one choice > ("I want to buy Ailice's Anters in Ferlielann") mandates another > ("Must buy through Amazon"). > > I don't know what it cost Amazon to ship me two copies of a book, but > still probably less than they got out of me, so they're still ahead. > Even if they lost money on this particular deal, they're still way > ahead because of all the people who decide it's not worth their time > to spend an hour or so trying to get a replacement. So yep, this > policy is serving Amazon fairly well. > > ChrisA > So much for my "You never know, we might even end up with a thread whereby the discussion is Python, the whole Python and nothing but the Python." :) -- 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 Jan 6 01:48:11 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 06:48:11 +0000 Subject: function to split strings and lists on predicate Message-ID: I came across this over the weekend http://paddy3118.blogspot.co.uk/2013/10/unifying-pythons-string-and-list.html. I couldn't come up with a solution to the fsplit function that seemed in any way cleaner. What can our nest of avid Pythonistas come up with? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From self at gkayaalp.com Mon Jan 6 02:51:28 2014 From: self at gkayaalp.com (=?UTF-8?B?R8O2a3R1xJ8gS2F5YWFscA==?=) Date: Mon, 06 Jan 2014 09:51:28 +0200 Subject: Postfix conditionals In-Reply-To: References: Message-ID: <52CA6080.7000007@gkayaalp.com> On 06-01-2014 03:40, Rhodri James wrote: > On Sun, 05 Jan 2014 20:24:53 -0000, G?ktu? Kayaalp > wrote: > >> AFAIK, we do not have "postfix conditionals" in Python, i.e. a >> condition appended to a statement, which determines whether the >> statement runs or not: > >> py> for i in [False]: >> ... break if not i > >> The above piece of code is equivalent to this in Python: > >> py> for i in [False]: >> ... if not i >> ... break > >> I believe that the first example is superior to the second example >> when the two is compared for readability and intuitiveness. > > In my past life as a newcomer to Perl, I thought this too. Postfix > conditionals read more like English, so they would be easier to take > in and understand. As I wrote more code, I discovered that this > didn't seem to be the case; except in very simple cases, I had to > mentally transpose the conditional back to the start of the statement > to properly comprehend what was going on and what the results would be > for my sample data. > > It looks like a good idea, but I don't think it works that well in > practice. > Thanks for the input! I'd be quite interested in examples which required you to "mentally transpose the conditional back to the start of the statement", by the way. gk From ethan at stoneleaf.us Mon Jan 6 03:40:28 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Jan 2014 00:40:28 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52CA13BD.4050708@stoneleaf.us> References: <52CA13BD.4050708@stoneleaf.us> Message-ID: <52CA6BFC.1070607@stoneleaf.us> On 01/05/2014 06:23 PM, Ethan Furman wrote: > > Using my own project [1] as a reference [1] https://pypi.python.org/pypi/dbf From python.list at tim.thechases.com Mon Jan 6 06:49:28 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 6 Jan 2014 05:49:28 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Message-ID: <20140106054928.5948e749@bigbox.christie.dr> On 2014-01-06 15:51, Chris Angelico wrote: > >>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to > >>> turn a hex dump into a bytes literal? Depends on how you source them: # space separated: >>> s1 = "43 6c 67 75 62 61" >>> ''.join(chr(int(pair, 16)) for pair in s1.split()) 'Clguba' # all smooshed together: >>> s2 = s1.replace(' ','') >>> s2 '436c67756261' >>> ''.join(chr(int(s2[i*2:(i+1)*2], 16)) for i in range(len(s2)/2)) 'Clguba' # as \xHH escaped: >>> s3 = ''.join('\\x'+s2[i*2:(i+1)*2] for i in range(len(s2)/2)) >>> print(s3) \x43\x6c\x67\x75\x62\x61 >>> print(b3) b'\\x43\\x6c\\x67\\x75\\x62\\x61' >>> b3.decode('unicode_escape') 'Clguba' It might get more complex if you're not just dealing with bytes, or if you have some other encoding scheme, but "s1" (space-separated, or some other delimiter such as colon-separated that can be passed to the .split() call) and "s2" (all smooshed together) are the two I encounter most frequently. -tkc From ned at nedbatchelder.com Mon Jan 6 07:39:27 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 07:39:27 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/5/14 11:26 PM, Terry Reedy wrote: > On 1/5/2014 8:16 PM, Ned Batchelder wrote: > >> OK, let's see what we got from three core developers on this list: > > To me, the following is a partly unfair summary. I apologize, I'm sure there were details I skipped in my short summary. > >> - Antoine dismissed the post as "a rant". > > He called it a rant while acknowledging that there is a unsolved issue > with transforms. Whether he was 'dismissing' it or not, I do not know. > Antoine also noted that there does not seem to be anything new in this > post that Armin has not said before. Without reading in detail, I had > the same impression. > >> - Terry took issue with three claims made, and ended with, "I suspect >> there are other basic errors, but I mostly quit reading at this point." > > You are discouraged that I quit reading? How much sludge do you expect > me to wade through? If Armin wants my attention (and I do not think he > does), it is *his* responsibility to write in a readable manner. > > But I read a bit more and found a 4th claim to 'take issue with' (to be > polite): > "only about 3% of all Python developers using Python 3 properly" > with a link to > http://alexgaynor.net/2014/jan/03/pypi-download-statistics/ > The download statistics say nothing about the percent of all Python > developers using Python 3, let alone properly, and Alex Gaynor makes no > such claim as Armin did. > > I would not be surprised if a majority of Python users have never > downloaded from pypi. What I do know from reading the catalog-sig (pypi) > list for a couple of years is that there are commercial developers who > use pypi heavily to update 1000s of installations and that they drive > the development of the pypi infrastructure. I strongly suspect that they > strongly skew the download statistics. > > Dubious claim 5 is this: "For 97% of us, Python 2 is our beloved world > for years to come". For Armin's narrow circle, that may be true, but I > suspect that more than 3% of Python programmers have never written > Python2 only code. > >> - Serhiy made a sarcastic comment comparing Python 3's bytes/unicode >> handling with Python 2's int/str handling, implying that since int/str >> wasn't a problem, then bytes/unicode isn't either. > > Serhiy's point was about the expectation of implicit conversion > (int/str) versus (bytes/str) and the complaint about removal of implicit > conversion. I suspect that part of his point is that if we never had > implicit bytes/unicode conversion, it would not be expected. > You are still talking about whether Armin is right, and whether he writes well, about flaws in his statistics, etc. I'm talking about the fact that an organization (Python core development) has a product (Python 3) that is getting bad press. Popular and vocal customers (Armin, Kenneth, and others) are unhappy. What is being done to make them happy? Who is working with them? They are not unique, and their viewpoints are not outliers. I'm not talking about the technical details of bytes and Unicode. I'm talking about making customers happy. -- Ned Batchelder, http://nedbatchelder.com From faassen at startifact.com Mon Jan 6 07:45:07 2014 From: faassen at startifact.com (Martijn Faassen) Date: Mon, 06 Jan 2014 13:45:07 +0100 Subject: informal #python2.8 channel on freenode Message-ID: <8b12b$52caa550$541826b9$23016@cache1.tilbu1.nb.home.nl> Fellow Pythoneers, I've started an informal channel "#python2.8" on freenode. It's to discuss the potential for a Python 2.8 version -- to see whether there is interest in it, what it could contain, how it could facilitate porting to Python 3, who would work on it, etc. If you are interested in constructive discussion about a Python 2.8, please join. I realize that if there is actual code created, and if it's not under the umbrella of the PSF, it couldn't be called "Python 2.8" due to trademark reasons. But that's premature - let's have some discussions first to see whether anything can happen. Hope to see you there for some discussion! Regards, Martijn From davea at davea.name Mon Jan 6 08:35:34 2014 From: davea at davea.name (Dave Angel) Date: Mon, 06 Jan 2014 08:35:34 -0500 Subject: function to split strings and lists on predicate In-Reply-To: References: Message-ID: On Mon, 06 Jan 2014 06:48:11 +0000, Mark Lawrence wrote: > I came across this over the weekend > http://paddy3118.blogspot.co.uk/2013/10/unifying-pythons-string-and-lis t.html. > I couldn't come up with a solution to the fsplit function that seemed > in any way cleaner. What can our nest of avid Pythonistas come up with? Looks like that link is already broken. Try the first half of page: http://paddy3118.blogspot.co.uk/2013_10_01_archive.html I can't see any way to simplify the generator Paddy produced, but the thing that bothered me is that it won't work on iterables, such as itself. For thar reason I think I'd stick with the separate functions, or write an adaptor to convert a iterable of lists to one of strings. -- DaveA From breamoreboy at yahoo.co.uk Mon Jan 6 08:44:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 13:44:41 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 06/01/2014 12:39, Ned Batchelder wrote: > > I'm not talking about the technical details of bytes and Unicode. I'm > talking about making customers happy. > Simply scrap PEP 404 and the currently unhappy customers will be happy as they'll be free to do all the work they want on Python 2.8, as my understanding is that the vast majority of the Python core developers won't do it for them. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ycui at outlook.com Mon Jan 6 09:01:25 2014 From: ycui at outlook.com (Frank Cui) Date: Mon, 6 Jan 2014 11:01:25 -0300 Subject: word replacing in a paragraph Message-ID: Hey guys, I'm trying to automate a process by initially creating a standard template and then replace some text fields with variable values. [for example, "DATE" in the paragraph will be replaced by the current date value. it doesn't have to be a literal word of "DATE", "DATE" in "TESTDATE" can also be replaced.] Is there some lightweight built-in or 3rd party libraries which are good for such kind of work ? ThanksFrank -------------- next part -------------- An HTML attachment was scrubbed... URL: From gheskett at wdtv.com Mon Jan 6 09:32:35 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 6 Jan 2014 09:32:35 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: <201401060932.35410.gheskett@wdtv.com> On Monday 06 January 2014 08:52:42 Ned Batchelder did opine: [...] > You are still talking about whether Armin is right, and whether he > writes well, about flaws in his statistics, etc. I'm talking about the > fact that an organization (Python core development) has a product > (Python 3) that is getting bad press. Popular and vocal customers > (Armin, Kenneth, and others) are unhappy. What is being done to make > them happy? Who is working with them? They are not unique, and their > viewpoints are not outliers. > > I'm not talking about the technical details of bytes and Unicode. I'm > talking about making customers happy. +1 Ned. Quite well said. And from my lurking here, its quite plain to me that 3.x python has a problem with everyday dealing with strings. If it is not solved relatively quickly, then I expect there will be a fork, a 2.8 by those most heavily invested. Or an exodus to the next "cool" language. No language will remain "cool" for long if it cannot simply and dependably solve the everyday problem of printing the monthly water bill. If it can be done in assembly, C or even bash, then it should be doable in python even simpler. Its nice to be able abstract the functions so they become one word macro's that wind up using 2 megs of program memory and 200k of stack to print Hello World, but I can do that with 3 or 4 lines of assembly on a coco3 running nitros9. Or 3 lines of C. The assembly will use perhaps 20 bytes of stack, the C version maybe 30. And the assembly will be lightening fast on a cpu with a less than 2 megahertz clock. Given that the problem IS understood, a language that can simplify solving a problem is nice, and will be used. But if the problem is not well understood, then you can write gigo crap in your choice of languages. Python is supposed to be a problem solver, not a problem creator. I'll get me coat. :) Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page We are using Linux daily to UP our productivity - so UP yours! -- Adapted from Pat Paulsen by Joe Sloan A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From david.froger at inria.fr Mon Jan 6 09:39:50 2014 From: david.froger at inria.fr (David Froger) Date: Mon, 06 Jan 2014 15:39:50 +0100 Subject: word replacing in a paragraph In-Reply-To: References: Message-ID: <20140106143950.31922.23652@fl-58186.rocq.inria.fr> Quoting Frank Cui (2014-01-06 15:01:25) > Hey guys, > > I'm trying to automate a process by initially creating a standard template and > then replace some text fields with variable values. > > [for example, "DATE" in the paragraph will be replaced by the current date > value. it doesn't have to be a literal word of "DATE", "DATE" in "TESTDATE" can > also be replaced.] > > Is there some lightweight built-in or 3rd party libraries which are good for > such kind of work ? Hi Franck, There is the standard module: http://docs.python.org/2/library/string.html#template-strings Or maybe if you need more power, something like jinja2. It's for Web (HTML documents), but it can also be used for any kind of document. http://jinja.pocoo.org/docs/ David From kirotawa at gmail.com Mon Jan 6 09:42:44 2014 From: kirotawa at gmail.com (leo kirotawa) Date: Mon, 6 Jan 2014 12:42:44 -0200 Subject: word replacing in a paragraph In-Reply-To: References: Message-ID: Since it is for a template you can round the keyword to be replaced , something like $data$ and then just string.replace('$data','1234') On Mon, Jan 6, 2014 at 12:01 PM, Frank Cui wrote: > Hey guys, > > I'm trying to automate a process by initially creating a standard template > and then replace some text fields with variable values. > > [for example, "DATE" in the paragraph will be replaced by the current date > value. it doesn't have to be a literal word of "DATE", "DATE" in "TESTDATE" > can also be replaced.] > > Is there some lightweight built-in or 3rd party libraries which are good > for such kind of work ? > > Thanks > Frank > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- ---------------------------------------------- Le?nidas S. Barbosa (Kirotawa) -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Jan 6 09:55:57 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 14:55:57 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <201401060932.35410.gheskett@wdtv.com> References: <201401060932.35410.gheskett@wdtv.com> Message-ID: On 06/01/2014 14:32, Gene Heskett wrote: > On Monday 06 January 2014 08:52:42 Ned Batchelder did opine: > [...] >> You are still talking about whether Armin is right, and whether he >> writes well, about flaws in his statistics, etc. I'm talking about the >> fact that an organization (Python core development) has a product >> (Python 3) that is getting bad press. Popular and vocal customers >> (Armin, Kenneth, and others) are unhappy. What is being done to make >> them happy? Who is working with them? They are not unique, and their >> viewpoints are not outliers. >> >> I'm not talking about the technical details of bytes and Unicode. I'm >> talking about making customers happy. > > +1 Ned. Quite well said. > > And from my lurking here, its quite plain to me that 3.x python has a > problem with everyday dealing with strings. If it is not solved relatively > quickly, then I expect there will be a fork, a 2.8 by those most heavily > invested. Or an exodus to the next "cool" language. > It's not at all plain to me, in fact quite the opposite. Please expand on these problems for mere mortals such as myself. -- 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 Mon Jan 6 10:16:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 02:16:36 +1100 Subject: word replacing in a paragraph In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 1:01 AM, Frank Cui wrote: > I'm trying to automate a process by initially creating a standard template > and then replace some text fields with variable values. > > [for example, "DATE" in the paragraph will be replaced by the current date > value. it doesn't have to be a literal word of "DATE", "DATE" in "TESTDATE" > can also be replaced.] How much do you trust the person creating that template? If it's you yourself, then probably the easiest way is to use the inbuilt str.format() method or %-formatting: template = """Today is: %(date)s Test ran on %(version)s, in %(time)f seconds.""" data = {"date":"2014-01-07", "version":"v3.4.0b2", "time":123.45} print(template % data) Today is: 2014-01-07 Test ran on v3.4.0b2, in 123.450000 seconds. This gives you a lot of flexibility, as you can lay things out tidily as well as simply substituting in values. ChrisA From ethan at stoneleaf.us Mon Jan 6 10:10:56 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Jan 2014 07:10:56 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> Message-ID: <52CAC780.1010204@stoneleaf.us> On 01/05/2014 06:37 PM, Dan Stromberg wrote: > > The argument seems to be "3.x doesn't work the way I'm accustomed to, > so I'm not going to use it, and I'm going to shout about it until > others agree with me." The argument is that a very important, if small, subset a data manipulation become very painful in Py3. Not impossible, and not difficult, but painful because the mental model and the contortions needed to get things to work don't sync up anymore. Painful because Python is, at heart, a simple and elegant language, but with the use-case of embedded ascii in binary data that elegance went right out the window. On 01/05/2014 06:55 PM, Chris Angelico wrote: > > It can't be both things. It's either bytes or it's text. Of course it can be: 0000000: 0372 0106 0000 0000 6100 1d00 0000 0000 .r......a....... 0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 0000020: 4e41 4d45 0000 0000 0000 0043 0100 0000 NAME.......C.... 0000030: 1900 0000 0000 0000 0000 0000 0000 0000 ................ 0000040: 4147 4500 0000 0000 0000 004e 1a00 0000 AGE........N.... 0000050: 0300 0000 0000 0000 0000 0000 0000 0000 ................ 0000060: 0d1a 0a ... And there we are, mixed bytes and ascii data. As I said earlier, my example is minimal, but still very frustrating in that normal operations no longer work. Incidentally, if you were thinking that NAME and AGE were part of the ascii text, you'd be wrong -- the field names are also encoded, as are the Character and Memo fields. -- ~Ethan~ From invalid at invalid.invalid Mon Jan 6 10:40:08 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Jan 2014 15:40:08 +0000 (UTC) Subject: [ANN] gg_scrapper -- scrapping of the Google Groups References: <20140104225739.GA32309@wycliff.ceplovi.cz> Message-ID: On 2014-01-05, Ethan Furman wrote: > Mat??j, > > Thanks for your efforts! > > However, you should only have one 'p' in scraping and scraper. ;) Rats. I thought he had figured out a way to scrap GG. -- Grant Edwards grant.b.edwards Yow! Like I always say at -- nothing can beat gmail.com the BRATWURST here in DUSSELDORF!! From rosuav at gmail.com Mon Jan 6 10:46:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 02:46:08 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52CAC780.1010204@stoneleaf.us> References: <52C9FD02.3080109@stoneleaf.us> <52CAC780.1010204@stoneleaf.us> Message-ID: On Tue, Jan 7, 2014 at 2:10 AM, Ethan Furman wrote: > On 01/05/2014 06:55 PM, Chris Angelico wrote: >> >> >> It can't be both things. It's either bytes or it's text. > > > Of course it can be: > > 0000000: 0372 0106 0000 0000 6100 1d00 0000 0000 .r......a....... > 0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ > 0000020: 4e41 4d45 0000 0000 0000 0043 0100 0000 NAME.......C.... > 0000030: 1900 0000 0000 0000 0000 0000 0000 0000 ................ > 0000040: 4147 4500 0000 0000 0000 004e 1a00 0000 AGE........N.... > 0000050: 0300 0000 0000 0000 0000 0000 0000 0000 ................ > 0000060: 0d1a 0a ... > > And there we are, mixed bytes and ascii data. As I said earlier, my example > is minimal, but still very frustrating in that normal operations no longer > work. Incidentally, if you were thinking that NAME and AGE were part of the > ascii text, you'd be wrong -- the field names are also encoded, as are the > Character and Memo fields. That's alternating between encoded text and non-text bytes. Each individual piece is either text or non-text, not both. The ideal way to manipulate it would most likely be a simple decode operation that turns this into (probably) a dictionary, decoding both the structure/layout and UTF-8 in a single operation. But a less ideal (and more convenient) solution might be involving what's currently under discussion elsewhere: a (possibly partial) percent-formatting or .format() method for bytes. None of this changes the fact that there are bytes used to store/transmit stuff, and abstract concepts used to manipulate them. Just like nobody expects to be able to write a dict to a file without some form of encoding (pickle, JSON, whatever), you shouldn't expect to write a character string without first turning it into bytes. ChrisA From invalid at invalid.invalid Mon Jan 6 10:53:58 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Jan 2014 15:53:58 +0000 (UTC) Subject: [OT] Migrating from non-free programs to LibreOffice (was: "More About Unicode in Python 2 and 3") References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: On 2014-01-06, Chris Angelico wrote: >> Right. I think shifting people to LibreOffice is an excellent and >> realistic step toward imcreasing people's software and data freedom. > > Yeah. Which is why I do it. But the other night, my mum was trying to > lay out her book in LO, and was having some problems with the system > of having each chapter in a separate file. (Among other things, styles > weren't shared across them all, so a tweak to a style means opening up > every chapter and either doing a parallel edit or figuring out how to > import styles.) So yes, it's a realistic and worthwhile step, but it's > not a magic solution to all problems. She doesn't have time to learn a > whole new system. Maybe - in the long term - LaTeX would actually save > her time, but it's certainly a much harder 'sell' than LO. Yea, I think laying out a book with something like MS Word or LibreOffice is nuts. Depending on her formatting needs, a lighter-weight mark-up language (something like asciidoc) might suite: http://asciidoc.org/ http://en.wikipedia.org/wiki/AsciiDoc I've used it to write a 150 page manual, and was quite happy with the results. It produces DocBook XML, PDF, HTML and a few other output formats (Including, I think, LibreOffice/OpenOffice). It's _much_ easier to get started with than LaTeX. For printing purposes the quality of the output is no match for TeX -- but it's better than a "word processor", and it does a very nice job with HTML output. -- Grant Edwards grant.b.edwards Yow! It's a hole all the at way to downtown Burbank! gmail.com From jeanmichel at sequans.com Mon Jan 6 10:56:01 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Mon, 6 Jan 2014 16:56:01 +0100 (CET) Subject: word replacing in a paragraph In-Reply-To: Message-ID: <1490224480.2904479.1389023761842.JavaMail.root@sequans.com> ----- Original Message ----- > Hey guys, > I'm trying to automate a process by initially creating a standard > template and then replace some text fields with variable values. > [for example, "DATE" in the paragraph will be replaced by the current > date value. it doesn't have to be a literal word of "DATE", "DATE" > in "TESTDATE" can also be replaced.] > Is there some lightweight built-in or 3rd party libraries which are > good for such kind of work ? > Thanks > Frank Jinja2 would be able to do it, with very few line of code. And you get all the features provided by a template engine should you need them to build more advanced templates. 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 rosuav at gmail.com Mon Jan 6 11:01:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 03:01:16 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice (was: "More About Unicode in Python 2 and 3") In-Reply-To: References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: On Tue, Jan 7, 2014 at 2:53 AM, Grant Edwards wrote: > Yea, I think laying out a book with something like MS Word or > LibreOffice is nuts. Depending on her formatting needs, a > lighter-weight mark-up language (something like asciidoc) might suite: > > http://asciidoc.org/ > http://en.wikipedia.org/wiki/AsciiDoc > > I've used it to write a 150 page manual, and was quite happy with the > results. It produces DocBook XML, PDF, HTML and a few other output > formats (Including, I think, LibreOffice/OpenOffice). It's _much_ > easier to get started with than LaTeX. For printing purposes the > quality of the output is no match for TeX -- but it's better than a > "word processor", and it does a very nice job with HTML output. Hmm. Might be useful in some other places. I'm currently trying to push for a web site design that involves docutils/reStructuredText, but am flexible on the exact markup system used. My main goal, though, is to separate content from structure and style - and my secondary goal is to have everything done as plain text files (apart from actual images), so the source control diffs are useful :) ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 6 11:24:19 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 03:24:19 +1100 Subject: "More About Unicode in Python 2 and 3" References: <52CA13BD.4050708@stoneleaf.us> Message-ID: <52cad8b4$0$29984$c3e8da3$5496439d@news.astraweb.com> Roy Smith wrote: > In article , > Chris Angelico wrote: > >> It can't be both things. It's either bytes or it's text. > > I've never used Python 3, so forgive me if these are naive questions. > Let's say you had an input stream which contained the following hex > values: > > $ hexdump data > 0000000 d7 a8 a3 88 96 95 > > That's EBCDIC for "Python". What would I write in Python 3 to read that > file and print it back out as utf-8 encoded Unicode? There's no one EBCDIC encoding. Like the so-called "extended ASCII" or "ANSI" encodings that followed, IBM had many different versions of EBCDIC customised for different machines and markets -- only even more poorly documented. But since the characters in that are all US English letters, any EBCDIC dialect ought to do it: py> b = b'\xd7\xa8\xa3\x88\x96\x95' py> b.decode('CP500') 'Python' To read it from a file: text = open("somefile", encoding='CP500').read() And to print out the UTF-8 encoded bytes: print(text.encode('utf-8')) > Or, how about a slightly different example: > > $ hexdump data > 0000000 43 6c 67 75 62 61 > > That's "Python" in rot-13 encoded ascii. How would I turn that into > cleartext Unicode in Python 3? In Python 3.3, you can do this: py> b = b'\x43\x6c\x67\x75\x62\x61' py> s = b.decode('ascii') py> print(s) Clguba py> import codecs py> codecs.decode(s, 'rot-13') 'Python' (This may not work in Python 3.1 or 3.2, since rot13 and assorted other string-to-string and byte-to-byte codecs were mistakenly removed. I say mistakenly, not in the sense of "by accident", but in the sense of "it was an error of judgement". Somebody was under the misapprehension that the codec machinery could only work on Unicode <-> bytes.) If you don't want to use the codec, you can do it by hand: def rot13(astring): result = [] for c in astring: i = ord(c) if ord('a') <= i <= ord('m') or ord('A') <= i <= ord('M'): i += 13 elif ord('n') <= i <= ord('z') or ord('N') <= i <= ord('Z'): i -= 13 result.append(chr(i)) return ''.join(result) But why would you want to do it the slow way? -- Steven From solipsis at pitrou.net Mon Jan 6 11:29:01 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Jan 2014 16:29:01 +0000 (UTC) Subject: "More About Unicode in Python 2 and 3" References: Message-ID: Ned Batchelder nedbatchelder.com> writes: > > You can look through his problems and decide that he's "wrong," or that > he's "ranting," but that doesn't change the fact that Python 3 is > encountering friction. What happens when a significant fraction of your > customers are "wrong"? Well, yes, there is some friction and this is quite expectable, when shipping incompatible changes. Other pieces of software have undergone a similar process (e.g. Apache 1.x -> Apache 2.x). (the alternative is to maintain a piece of software that sticks with obsolete conventions, e.g. emacs) > Core developers: I thank you for the countless hours you have devoted to > building all of the versions of Python. I'm sure in many ways it's a > thankless task. But you have a problem. What's the point in being > right if you end up with a product that people don't use? People don't use? According to available figures, there are more downloads of Python 3 than downloads of Python 2 (Windows installers, mostly): http://www.python.org/webstats/ The number of Python 3-compatible packages has been showing a constant and healthy increase for years: http://dev.pocoo.org/~gbrandl/py3.html And Dan's survey shows 77% of respondents think Python 3 wasn't a mistake: https://wiki.python.org/moin/2.x-vs-3.x-survey > Maybe there are core developers who are trying hard to solve the > problems Kenneth and Armin are facing. It would be great if that work > was more visible. I don't see it, and apparently Armin doesn't either. While this is being discussed: https://mail.python.org/pipermail/python-dev/2014-January/130923.html I would still point out that "Kenneth and Armin" are not the whole Python community. Your whole argument seems to be that a couple "revered" (!!) individuals should see their complaints taken for granted. I am opposed to rockstarizing the community. Their contribution is always welcome, of course. (as for network programming, the people working on and with asyncio don't seem to find Python 3 terrible) Regards Antoine. From rosuav at gmail.com Mon Jan 6 11:30:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 03:30:17 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52cad8b4$0$29984$c3e8da3$5496439d@news.astraweb.com> References: <52CA13BD.4050708@stoneleaf.us> <52cad8b4$0$29984$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 7, 2014 at 3:24 AM, Steven D'Aprano wrote: > If you don't want to use the codec, you can do it by hand: > > def rot13(astring): > result = [] > for c in astring: > i = ord(c) > if ord('a') <= i <= ord('m') or ord('A') <= i <= ord('M'): > i += 13 > elif ord('n') <= i <= ord('z') or ord('N') <= i <= ord('Z'): > i -= 13 > result.append(chr(i)) > return ''.join(result) > > But why would you want to do it the slow way? Eww. I'd much rather use .translate() than that :) ChrisA From rosuav at gmail.com Mon Jan 6 11:36:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 03:36:51 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 3:29 AM, Antoine Pitrou wrote: > People don't use? According to available figures, there are more downloads of > Python 3 than downloads of Python 2 (Windows installers, mostly): > http://www.python.org/webstats/ > Unfortunately, that has a massive inherent bias, because there are Python builds available in most Linux distributions - and stats from those (like Debian's popcon) will be nearly as useless, because a lot of them will install one or the other (probably 2.x) without waiting for the user (so either they'll skew in favour of the one installed, or in favour of the one NOT installed, because that's the only one that'll be explicitly requested). It's probably fairly accurate for Windows stats, though, since most people who want Python on Windows are going to come to python.org for an installer. ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 6 11:43:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 03:43:52 +1100 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: <52cadd49$0$29999$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > Using my own project [1] as a reference: ?good ol' dbf files -- character > fields, numeric fields, logic fields, time fields, and of course the > metadata that describes these fields and the dbf as a whole. ?The > character fields I turn into unicode, no sweat. ?The metadata fields are > simple ascii, and in Py2 something like `if header[FIELD_TYPE] == 'C'` did > the job just fine. ?In Py3 that compares an int (67) to the unicode letter > 'C' and returns False. ? Why haven't you converted the headers to text too? You're using them as if they were text. They might happen to merely contain the small subset of Unicode which matches the ASCII encoding, but that in itself is no good reason to keep it as bytes. If you want to work with stuff as if it were text, convert it to text. If you do have a good reason for keeping them as bytes, say because you need to do a bunch of bitwise operations on it, it's not that hard to do the job correctly: instead of defining FIELD_TYPE as 3 (for example), define it as slice(3,4). Then: if header[FIELD_TYPE] == b'C': will work. For sure, this is a bit of a nuisance, and slightly error-prone, since Python won't complain if you forget the b prefix, it will silently return False. Which is the right thing to do, inconvenient though it may be in this case. But it is workable, with a bit of discipline. Or define a helper, and use that: def eq(byte, char): return byte == ord(char) if eq(header[FIELD_TYPE], 'C'): Worried about the cost of all those function calls, all those ord()'s? I'll give you the benefit of the doubt and assume that this is not premature optimisation. So do it yourself: C = ord('C') # Convert it once. if header[FIELD_TYPE] == C: # And use it many times. [Note to self: when I'm BDFL, encourage much more compile-time optimisations.] > For me this is simply a major annoyance, but I > only have a handful of places where I have to deal with this. ?Dealing > with protocols where bytes is the norm and embedded ascii is prevalent -- > well, I can easily imagine the nightmare. Is it one of those nightmares where you're being chased down an endless long corridor by a small kitten wanting hugs? 'Cos so far I'm not seeing the terror... -- Steven From gheskett at wdtv.com Mon Jan 6 11:46:18 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 6 Jan 2014 11:46:18 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> Message-ID: <201401061146.18518.gheskett@wdtv.com> On Monday 06 January 2014 11:42:55 Mark Lawrence did opine: > On 06/01/2014 14:32, Gene Heskett wrote: > > On Monday 06 January 2014 08:52:42 Ned Batchelder did opine: > > [...] > > > >> You are still talking about whether Armin is right, and whether he > >> writes well, about flaws in his statistics, etc. I'm talking about > >> the fact that an organization (Python core development) has a > >> product (Python 3) that is getting bad press. Popular and vocal > >> customers (Armin, Kenneth, and others) are unhappy. What is being > >> done to make them happy? Who is working with them? They are not > >> unique, and their viewpoints are not outliers. > >> > >> I'm not talking about the technical details of bytes and Unicode. > >> I'm talking about making customers happy. > > > > +1 Ned. Quite well said. > > > > And from my lurking here, its quite plain to me that 3.x python has a > > problem with everyday dealing with strings. If it is not solved > > relatively quickly, then I expect there will be a fork, a 2.8 by > > those most heavily invested. Or an exodus to the next "cool" > > language. > > It's not at all plain to me, in fact quite the opposite. Please expand > on these problems for mere mortals such as myself. Mortals? Likely nobody here is more acutely aware of his mortality Mark. But what is the most common post here asking for help? Tossup as to whether its database related, or strings. Most everything else seems to be a pretty distant 3rd. Cheers, Gene From ethan at stoneleaf.us Mon Jan 6 11:23:15 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Jan 2014 08:23:15 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52CAC780.1010204@stoneleaf.us> Message-ID: <52CAD873.4050707@stoneleaf.us> On 01/06/2014 07:46 AM, Chris Angelico wrote: > > None of this changes the fact that there are bytes used to > store/transmit stuff, and abstract concepts used to manipulate them. > Just like nobody expects to be able to write a dict to a file without > some form of encoding (pickle, JSON, whatever), you shouldn't expect > to write a character string without first turning it into bytes. Writing is only half the battle, and not, as it happens, where I experience the pain. This data must also be /read/. It has been stated many times that the Py2 str became the Py3 bytes, and yet never in Py2 did 'abc'[1] return 98. -- ~Ethan~ From ethan at stoneleaf.us Mon Jan 6 11:28:01 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Jan 2014 08:28:01 -0800 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: <52CAD991.8040301@stoneleaf.us> On 01/06/2014 07:53 AM, Grant Edwards wrote: > > Yea, I think laying out a book with something like MS Word or > LibreOffice is nuts. Depending on her formatting needs, a > lighter-weight mark-up language (something like asciidoc) might suite: > > http://asciidoc.org/ > http://en.wikipedia.org/wiki/AsciiDoc Thanks for that! -- ~Ethan~ From rosuav at gmail.com Mon Jan 6 11:54:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 03:54:53 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52cadd49$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52cadd49$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 7, 2014 at 3:43 AM, Steven D'Aprano wrote: >> For me this is simply a major annoyance, but I >> only have a handful of places where I have to deal with this. Dealing >> with protocols where bytes is the norm and embedded ascii is prevalent -- >> well, I can easily imagine the nightmare. > > Is it one of those nightmares where you're being chased down an endless long > corridor by a small kitten wanting hugs? 'Cos so far I'm not seeing the > terror... Uhh, I think you're the only one here who has that nightmare, like Chris Knight with his sun-god robes and naked women throwing pickles at him. ChrisA From dss.leb at gmail.com Mon Jan 6 11:58:35 2014 From: dss.leb at gmail.com (d ss) Date: Mon, 6 Jan 2014 08:58:35 -0800 (PST) Subject: python finance In-Reply-To: <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> Message-ID: <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> what the heck! who told you this is a spam! this is a call for cooperation and collaboration how retarded! On Sunday, January 5, 2014 4:14:22 AM UTC-5, maxwe... at gmail.com wrote: > On Thursday, January 2, 2014 11:37:59 AM UTC, d ss wrote: > > > dailystockselect.com needs a couple of talented python people for the development and implementation of new trading strategies. it may be also some pythonic design change for the displayed figures now the web app consists of 1 of the 8 conceived strategies. contact us at the email on the website for more details > > > Samir > > > > Please this is a spam.. I've reported this as a spam. I wish everyone who sees this also reports it as spam to get the user bannned. This way GG will be a wee bit better > > > > Thanks From blissend at gmail.com Mon Jan 6 12:02:31 2014 From: blissend at gmail.com (blissend at gmail.com) Date: Mon, 6 Jan 2014 09:02:31 -0800 (PST) Subject: Which python framework? Message-ID: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> I love programming in python but I'm having trouble deciding over a framework for a single player MUD like game I'm making for fun. Ideally it's a cross-platform free framework in case I want make it open source later with good capabilities of customizing the GUI look/style. Currently I'm using wxpython which is great but I'm reading that if I want more customization over the look (i.e. a frame being all black and not using windows 7 blue borders) then I may want to look elsewhere? If so what would be more ideal? Keep in mind this is only a text based game so 3D is not needed. Perhaps I have to forgo my love of python for something else? Something comparable to appealing look of python syntax? From rosuav at gmail.com Mon Jan 6 12:06:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 04:06:45 +1100 Subject: python finance In-Reply-To: <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> Message-ID: On Tue, Jan 7, 2014 at 3:58 AM, d ss wrote: > what the heck! > who told you this is a spam! > this is a call for cooperation and collaboration > how retarded! It is, at best, misdirected. There is a Python job board [1] where these sorts of things can be posted, but the main mailing list isn't the place for it. However, if you want your posts to be seen as legitimate, I would recommend putting a little more content into them, and putting some effort into the quality of English. Most of us will just skip over something that looks like unsolicited commercial email, if we even see it at all (spam filtering is getting pretty effective these days). ChrisA [1] http://www.python.org/community/jobs/ From breamoreboy at yahoo.co.uk Mon Jan 6 12:07:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 17:07:00 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52cadd49$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52cadd49$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 06/01/2014 16:43, Steven D'Aprano wrote: > Ethan Furman wrote: > >> For me this is simply a major annoyance, but I >> only have a handful of places where I have to deal with this. Dealing >> with protocols where bytes is the norm and embedded ascii is prevalent -- >> well, I can easily imagine the nightmare. > > Is it one of those nightmares where you're being chased down an endless long > corridor by a small kitten wanting hugs? 'Cos so far I'm not seeing the > terror... > Great minds think alike? :) -- 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 Mon Jan 6 12:09:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 04:09:28 +1100 Subject: Which python framework? In-Reply-To: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> References: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> Message-ID: On Tue, Jan 7, 2014 at 4:02 AM, wrote: > I love programming in python but I'm having trouble deciding over a framework for a single player MUD like game I'm making for fun. Ideally it's a cross-platform free framework in case I want make it open source later with good capabilities of customizing the GUI look/style. If by "MUD-like" you mean that it's fundamentally based on scrolling text and inputted commands, you may be able to just skip the GUI altogether and use the console (print() and input()). That'd save you a lot of trouble. Alternatively, it might be worth going the other way and actually making it a MUD. Wait for a socket connection, let the user TELNET in. Your GUI would then be an actual MUD client, off the shelf, giving you all its features absolutely for free. Either way, you put zero effort into building a GUI, and you get something every bit as powerful as you could build manually. ChrisA From breamoreboy at yahoo.co.uk Mon Jan 6 12:13:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 17:13:34 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <201401061146.18518.gheskett@wdtv.com> References: <201401060932.35410.gheskett@wdtv.com> <201401061146.18518.gheskett@wdtv.com> Message-ID: On 06/01/2014 16:46, Gene Heskett wrote: > On Monday 06 January 2014 11:42:55 Mark Lawrence did opine: > >> On 06/01/2014 14:32, Gene Heskett wrote: >>> On Monday 06 January 2014 08:52:42 Ned Batchelder did opine: >>> [...] >>> >>>> You are still talking about whether Armin is right, and whether he >>>> writes well, about flaws in his statistics, etc. I'm talking about >>>> the fact that an organization (Python core development) has a >>>> product (Python 3) that is getting bad press. Popular and vocal >>>> customers (Armin, Kenneth, and others) are unhappy. What is being >>>> done to make them happy? Who is working with them? They are not >>>> unique, and their viewpoints are not outliers. >>>> >>>> I'm not talking about the technical details of bytes and Unicode. >>>> I'm talking about making customers happy. >>> >>> +1 Ned. Quite well said. >>> >>> And from my lurking here, its quite plain to me that 3.x python has a >>> problem with everyday dealing with strings. If it is not solved >>> relatively quickly, then I expect there will be a fork, a 2.8 by >>> those most heavily invested. Or an exodus to the next "cool" >>> language. >> >> It's not at all plain to me, in fact quite the opposite. Please expand >> on these problems for mere mortals such as myself. > > Mortals? Likely nobody here is more acutely aware of his mortality Mark. > > But what is the most common post here asking for help? Tossup as to > whether its database related, or strings. Most everything else seems to be > a pretty distant 3rd. > > Cheers, Gene > > As the take of Python 3 is so poor then that must mean all the problems being reported are still with Python 2. The solution is to upgrade to Python 3.3+ and the superb PEP 393 FSR which is faster and uses less memory. Or is it simply that people are so used to doing things sloppily with Python 2 that they don't like being forced into doing things correctly with Python 3? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Mon Jan 6 12:10:52 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Mon, 6 Jan 2014 17:10:52 +0000 (UTC) Subject: python finance References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> Message-ID: On 2014-01-06, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 3:58 AM, d ss wrote: >> what the heck! >> who told you this is a spam! >> this is a call for cooperation and collaboration >> how retarded! > > It is, at best, misdirected. There is a Python job board [1] where > these sorts of things can be posted, but the main mailing list isn't > the place for it. > > However, if you want your posts to be seen as legitimate, I would > recommend [...] And don't post them via Google Groups. Chris's reply is the first post in this thread that many of us saw. ;) -- Grant Edwards grant.b.edwards Yow! Used staples are good at with SOY SAUCE! gmail.com From jwe.van.dijk at gmail.com Mon Jan 6 12:14:08 2014 From: jwe.van.dijk at gmail.com (jwe.van.dijk at gmail.com) Date: Mon, 6 Jan 2014 09:14:08 -0800 (PST) Subject: class inheritance python2.7 vs python3.3 Message-ID: I have problems with these two classes: class LPU1(): def __init__(self, formula): """ formula is a string that is parsed into a SymPy function and several derived functions """ self.formula = formula ... ... class LPU3(LPU1): def __new__(self): """ the same functions as LPU1 but some added functions and some functions redefined """ ... ... if __name__ == '__main__: y = y = 'x_0 * x_1 + x_2' stats1 = LPU1(y) stats3 = LPU3(y) Worked perfectly on Python 2.7.5+ but on Python 3.3.2+ I get on instantiatiating stat3: TypeError: __new__() takes 1 positional argument but 2 were given What am I doing wrong? I must confess I am a bit out of my depth here so any explanation will be a learning experience. Many thanks, Janwillem From rosuav at gmail.com Mon Jan 6 12:24:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 04:24:41 +1100 Subject: class inheritance python2.7 vs python3.3 In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 4:14 AM, wrote: > class LPU3(LPU1): > def __new__(self): > """ > the same functions as LPU1 but some added functions > and some functions redefined > """ You probably don't want to be using __new__ here. Try using __init__ instead, or simply not defining __new__ at all. I suspect that the reason that appears to work under Py2 is that you're using an old-style class, there. That means it'll be subtly different on the two versions. To make them do the same thing, explicitly subclass object: class LPU1(object): In Python 3, that's redundant - subclassing object is the default. In Python 2, though, it's important. ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 6 12:27:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 04:27:40 +1100 Subject: "More About Unicode in Python 2 and 3" References: <52C9FD02.3080109@stoneleaf.us> Message-ID: <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > On 01/05/2014 06:37 PM, Dan Stromberg wrote: >> >> The argument seems to be "3.x doesn't work the way I'm accustomed to, >> so I'm not going to use it, and I'm going to shout about it until >> others agree with me." > > The argument is that a very important, if small, subset a data > manipulation become very painful in Py3. Not impossible, and not > difficult, but painful because the mental model and the contortions needed > to get things to work don't sync up > anymore. Painful because Python is, at heart, a simple and elegant > language, but with the use-case of embedded ascii in binary data that > elegance went right out the window. > > On 01/05/2014 06:55 PM, Chris Angelico wrote: >> >> It can't be both things. It's either bytes or it's text. > > Of course it can be: > > 0000000: 0372 0106 0000 0000 6100 1d00 0000 0000 .r......a....... > 0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ > 0000020: 4e41 4d45 0000 0000 0000 0043 0100 0000 NAME.......C.... > 0000030: 1900 0000 0000 0000 0000 0000 0000 0000 ................ > 0000040: 4147 4500 0000 0000 0000 004e 1a00 0000 AGE........N.... > 0000050: 0300 0000 0000 0000 0000 0000 0000 0000 ................ > 0000060: 0d1a 0a ... > > And there we are, mixed bytes and ascii data. Chris didn't say "bytes and ascii data", he said "bytes and TEXT". Text != "ascii data", and the fact that some people apparently think it does is pretty much the heart of the problem. I see no mixed bytes and text. I see bytes. Since the above comes from a file, it cannot be anything else but bytes. Do you think that a file that happens to be a JPEG contains pixels? No. It contains bytes which, after decoding, represents pixels. Same with text, ascii or otherwise. Now, it is true that some of those bytes happen to fall into the same range of values as ASCII-encoded text. They may even represent text after decoding, but since we don't know what the file contents mean, we can't know that. It might be a mere coincidence that the four bytes starting at hex offset 40 is the C long 1095189760 which happens to look like "AGE" with a null at the end. For historical reasons, your hexdump utility performs that decoding step for you, which is why you can see "NAME" and "AGE" in the right-hand block, but that doesn't mean the file contains text. It contains bytes, some of which represents text after decoding. If you (generic you) don't get that, you'll have a bad time. I mean *really* get it, deep down in the bone. The long, bad habit of thinking as ASCII-encoded bytes as text is the problem here. The average programmer has years and years of experience thinking about decoding bytes to numbers and back (just not by that name), so it doesn't lead to any cognitive dissonance to think of hex 4147 4500 as either four bytes, two double-byte ints, or a single four-byte int. But as soon as "text" comes into the picture, the average programmer has equally many years of thinking that the byte 41 "just is" the letter "A", and that's simply *wrong*. > As I said earlier, my > example is minimal, but still very frustrating in > that normal operations no longer work. Incidentally, if you were thinking > that NAME and AGE were part of the ascii text, you'd be wrong -- the field > names are also encoded, as are the Character and Memo fields. What Character and Memo fields? Are you trying to say that the NAME and AGE are *not* actually ASCII text, but a mere coincidence, like my example of 1095189760? Or are you referring to the fact that they're actually encoded as ASCII? If not, I have no idea what you are trying to say. -- Steven From steve+comp.lang.python at pearwood.info Mon Jan 6 12:30:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 04:30:24 +1100 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: <52cae831$0$29971$c3e8da3$5496439d@news.astraweb.com> Gene Heskett wrote: > And from my lurking here, its quite plain to me that 3.x python has a > problem with everyday dealing with strings. I've been using Python 3.x since Python 3.1 came out, and I haven't come across any meaningful problems with the everyday dealing with strings. Quite the opposite -- I never quite understood the difference between text strings and byte strings until I started using Python 3. Perhaps you would care to explain what these everyday problems are that you have seen? -- Steven From blissend at gmail.com Mon Jan 6 12:37:24 2014 From: blissend at gmail.com (blissend at gmail.com) Date: Mon, 6 Jan 2014 09:37:24 -0800 (PST) Subject: Which python framework? In-Reply-To: References: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> Message-ID: On Monday, January 6, 2014 12:09:28 PM UTC-5, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 4:02 AM, wrote: > > > I love programming in python but I'm having trouble deciding over a framework for a single player MUD like game I'm making for fun. Ideally it's a cross-platform free framework in case I want make it open source later with good capabilities of customizing the GUI look/style. > > > > If by "MUD-like" you mean that it's fundamentally based on scrolling > > text and inputted commands, you may be able to just skip the GUI > > altogether and use the console (print() and input()). That'd save you > > a lot of trouble. Alternatively, it might be worth going the other way > > and actually making it a MUD. Wait for a socket connection, let the > > user TELNET in. Your GUI would then be an actual MUD client, off the > > shelf, giving you all its features absolutely for free. Either way, > > you put zero effort into building a GUI, and you get something every > > bit as powerful as you could build manually. > > > > ChrisA I suppose what I'm trying to accomplish isn't ordinary. Yes, it's fundamentally a scrolling text based game but... with input commands only as a secondary option. I'm going to design a new user experience I have in mind via a GUI that can engage users without having to type commands. This is why I'm wondering about alternatives. From davea at davea.name Mon Jan 6 12:46:39 2014 From: davea at davea.name (Dave Angel) Date: Mon, 06 Jan 2014 12:46:39 -0500 Subject: class inheritance python2.7 vs python3.3 In-Reply-To: References: Message-ID: On Mon, 6 Jan 2014 09:14:08 -0800 (PST), jwe.van.dijk at gmail.com wrote: > I have problems with these two classes: > class LPU1() : You forgot to derive from object. That's implied on 3.x, but you say you're also running on 2.7 Without naming your base class you're asking for an old style class which has been obsolete maybe 10 years. I sure don't recall how it differs. > def __init__(self, formula): > """ > formula is a string that is parsed into a SymPy function > and several derived functions > """ > self.formula = formula > ... ... > class LPU3(LPU1): > def __new__(self): > """ > the same functions as LPU1 but some added functions > and some functions redefined You don't show where you call super, so we can't tell what you had in mind. And did you actually mean __new__ here or should you have defined __init__ as you did in the base class? > if __name__ == '__main__: > y = y = 'x_0 * x_1 + x_2' > stats1 = LPU1(y) > stats3 = LPU3(y) And where did you expect that y to go? > Worked perfectly on Python 2.7.5+ but on Python 3.3.2+ I get on instantiatiating stat3: I don't see anything called stat3. Presumably you mean stats3, but you're not instantiating it you're instantiating LPU3. > TypeError: __new__() takes 1 positional argument but 2 were given You forgot to include the rest of the stack trace. I think the real problem is you forgot to include the second parameter on the misnamed __init__ method. It should have parameters self and arg, and pass arg up through super. -- DaveA From steve+comp.lang.python at pearwood.info Mon Jan 6 12:50:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 04:50:18 +1100 Subject: "More About Unicode in Python 2 and 3" References: Message-ID: <52caecdb$0$29968$c3e8da3$5496439d@news.astraweb.com> Ned Batchelder wrote: > You are still talking about whether Armin is right, and whether he > writes well, about flaws in his statistics, etc. ?I'm talking about the > fact that an organization (Python core development) has a product > (Python 3) that is getting bad press. ?Popular and vocal customers > (Armin, Kenneth, and others) are unhappy. ?What is being done to make > them happy? ?Who is working with them? ?They are not unique, and their > viewpoints are not outliers. > > I'm not talking about the technical details of bytes and Unicode. ?I'm > talking about making customers happy. Oh? How much did Armin pay for his Python support? If he didn't pay, he's not a customer. He's a user. When something gets bad press, the normal process is to first determine just how justified that bad press is. (Unless, of course, you're more interested in just *covering it up* than fixing the problem.) The best solutions are: - if the bad press is justified, admit it, and fix the problems; - if the bad press is not justified, try to educate Armin (and others) so they stop blaming Python for their own errors; try to counter their bad press with good press; or ignore it, knowing that the internet is notoriously fickle and in a week people will be hating on Go, or Ruby instead. But I get the idea from your post that you don't want to talk about the technical details of bytes and Unicode, and by extension, whether Python 3 is better or worse than Python 2. That makes it impossible to determine how valid the bad press is, which leaves us hamstrung. Our only responses are: - Patronise him. "Yes yes, you poor little thing, we feel your pain. But what can we do about it?" - Abuse him and hope he shuts up. - Give in to his (and by extension, everyone elses) complaints, whether justified or not, and make Python worse. - Counter his bad press with good press, and come across as arrogant idiots by denying actual real problems (if any). - Wait for the Internet to move on. -- Steven From steve+comp.lang.python at pearwood.info Mon Jan 6 13:10:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 05:10:18 +1100 Subject: class inheritance python2.7 vs python3.3 References: Message-ID: <52caf18b$0$30003$c3e8da3$5496439d@news.astraweb.com> jwe.van.dijk at gmail.com wrote: > I have problems with these two classes: > > class LPU1(): > def __init__(self, formula): > """ > formula is a string that is parsed into a SymPy function > and several derived functions > """ > self.formula = formula > ... ... > > class LPU3(LPU1): > def __new__(self): > """ > the same functions as LPU1 but some added functions > and some functions redefined > """ > ... ... If this actually is your class, then in Python 2.7 the __new__ method will do nothing at all. However, if you actually inherited from object in LPU1, then it (might) work in Python 2.7. In Python 3.3, it will work regardless. Perhaps you have a bug in the __new__ method? In Python 2.7, it is never called, and so the bug never occurs. In Python 3.3, it is called, and the bug occurs. > Worked perfectly on Python 2.7.5+ but on Python 3.3.2+ I get on > instantiatiating stat3: TypeError: __new__() takes 1 positional argument > but 2 were given And sure enough, that's exactly it. > What am I doing wrong? > I must confess I am a bit out of my depth here so any explanation will be > a learning experience. Back in the Dark Ages of Python 1.x, built-in types like int, str, list and so forth were completely independent of classes created with the class statement. So you couldn't subclass them. In Python 2.2, Python underwent what was called "class/type unification", which added a new mechanism to allow built-in types to be subclassed. For reasons of backward compatibility, the existing classes were left alone, and were called "old style" or "classic" classes. But a new built-in, called object, was created. All the other built-in types (str, list, int, etc.) inherit from object. These became known as "new style classes". New style classes had extra features that classic classes don't have, including the __new__ constructor method. (Classic classes don't let you override the constructor, only the initializer, __init__. New-style classes let you override both.) So Python 2.2 and beyond has two distinct models for classes, which *mostly* work the same but have a few differences -- those that inherit from object or some other built-in type, and those that don't. # Python 2 classic class: class LPU1(): def __new__(cls): ... __new__ is dead code here, and won't be called. # Python 2 new-style class: class LPU1(object): def __new__(cls): ... __new__ is called. So when you inherit from LPU1, your LPU3 class gets the same "old" versus "new" behaviour, and __new__ is either dead code or not. Now fast forward to Python 3. In Python 3, having two types of classes was considered one too many. The old-style classes were dropped. Inheriting from object became optional. Either way, you would get the same behaviour, and __new__ is always used. So if you have a buggy __new__ method, it could be ignored in Python 2 and suddenly run in Python 3, giving you an error. -- Steven From ippolito.marco at gmail.com Mon Jan 6 12:20:27 2014 From: ippolito.marco at gmail.com (Marco Ippolito) Date: Mon, 6 Jan 2014 18:20:27 +0100 Subject: /usr/lib/python2.7/subprocess.py:OSError: [Errno 2] No such file or directory Message-ID: Hi everybody, I'm trying to use MEGAM with NLTK. running the file: [Found /home/ubuntu/nltk_data/megam_i686.opt: /home/ubuntu/nltk_data/megam_i686.opt] Traceback (most recent call last): File "classifying.py", line 494, in me_classifier = MaxentClassifier.train(train_feats, algorithm='megam') File "/usr/local/lib/python2.7/dist-packages/nltk/classify/maxent.py", line 319, in train gaussian_prior_sigma, **cutoffs) File "/usr/local/lib/python2.7/dist-packages/nltk/classify/maxent.py", line 1522, in train_maxent_classifier_with_megam stdout = call_megam(options) File "/usr/local/lib/python2.7/dist-packages/nltk/classify/megam.py", line 167, in call_megam p = subprocess.Popen(cmd, stdout=subprocess.PIPE) File "/usr/lib/python2.7/subprocess.py", line 679, ininit errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory subprocess.py exists: # subprocess - Subprocesses with accessible I/O streams # # For more information about this module, see PEP 324. # # This module should remain compatible with Python 2.2, see PEP 291. # # Copyright (c) 2003-2005 by Peter Astrand # # Licensed to PSF under a Contributor Agreement. # See http://www.python.org/2.4/license for licensing details. r"""subprocess - Subprocesses with accessible I/O streams Any hints or suggestions? Thank you very much for your help. Marco From emile at fenx.com Mon Jan 6 13:53:00 2014 From: emile at fenx.com (Emile van Sebille) Date: Mon, 06 Jan 2014 10:53:00 -0800 Subject: informal #python2.8 channel on freenode In-Reply-To: <8b12b$52caa550$541826b9$23016@cache1.tilbu1.nb.home.nl> References: <8b12b$52caa550$541826b9$23016@cache1.tilbu1.nb.home.nl> Message-ID: Why not contribute to the planned Stackless 2.8? As I understand their direction, they'll be backporting certain v3.x features and will be prepping both SLP and nonSLP versions. Emile On 01/06/2014 04:45 AM, Martijn Faassen wrote: > Fellow Pythoneers, > > I've started an informal channel "#python2.8" on freenode. It's to > discuss the potential for a Python 2.8 version -- to see whether there > is interest in it, what it could contain, how it could facilitate > porting to Python 3, who would work on it, etc. If you are interested in > constructive discussion about a Python 2.8, please join. > > I realize that if there is actual code created, and if it's not under > the umbrella of the PSF, it couldn't be called "Python 2.8" due to > trademark reasons. But that's premature - let's have some discussions > first to see whether anything can happen. > > Hope to see you there for some discussion! > > Regards, > > Martijn From ethan at stoneleaf.us Mon Jan 6 13:34:10 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 06 Jan 2014 10:34:10 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52CAF722.6010301@stoneleaf.us> On 01/06/2014 09:27 AM, Steven D'Aprano wrote: > Ethan Furman wrote: > > Chris didn't say "bytes and ascii data", he said "bytes and TEXT". > Text != "ascii data", and the fact that some people apparently think it > does is pretty much the heart of the problem. The heart of a different problem, not this one. The problem I refer to is that many binary formats have well-defined ascii-encoded text tidbits. These tidbits were quite easy to work with in Py2, not difficult but not elegant in Py3, and even worse if you have to support both 2 and 3. > Now, it is true that some of those bytes happen to fall into the same range > of values as ASCII-encoded text. They may even represent text after > decoding, but since we don't know what the file contents mean, we can't > know that. Of course we can -- we're the programmer, after all. This is not a random bunch of bytes but a well defined format for storing data. > It might be a mere coincidence that the four bytes starting at > hex offset 40 is the C long 1095189760 which happens to look like "AGE" > with a null at the end. For historical reasons, your hexdump utility > performs that decoding step for you, which is why you can see "NAME" > and "AGE" in the right-hand block, but that doesn't mean the file contains > text. It contains bytes, some of which represents text after decoding. As it happens, 'NAME' and 'AGE' are encoded, and will be decoded. They could just as easily have contained tilde's, accents, umlauts, and other strange (to me) characters. It's actually the 'C' and the 'N' that bug me (like I said, my example is minimal, especially compared to a network protocol). And you're right -- it is easy to say FIELD_TYPE = slice(15,16), and it was also easy to say FIELD_TYPE = 15, but there is a critical difference -- can you spot it? .. .. .. In case you didn't: both work in Py2, only the slice version works (correctly) in Py3, but the worst part is why do I have to use a slice to take a single byte when a simple index should work? Because the bytes type lies. It shows, for example, b'\r\n\x12\x08N\x00' but when I try to access that N to see if this is a Numeric field I get: --> b'\r\n\x12\x08N\x00'[4] 78 This is a cognitive dissonance that one does not expect in Python. > If you (generic you) don't get that, you'll have a bad time. I mean *really* > get it, deep down in the bone. The long, bad habit of thinking as > ASCII-encoded bytes as text is the problem here. Different problem. The problem here is that bytes and byte literals don't compare equal. > the average programmer has equally many years of thinking that the > byte 41 "just is" the letter "A", and that's simply *wrong*. Agreed. But byte 41 != b'A', and that is equally wrong. >> As I said earlier, my >> example is minimal, but still very frustrating in >> that normal operations no longer work. Incidentally, if you were thinking >> that NAME and AGE were part of the ascii text, you'd be wrong -- the field >> names are also encoded, as are the Character and Memo fields. > > What Character and Memo fields? Are you trying to say that the NAME and AGE > are *not* actually ASCII text, but a mere coincidence, like my example of > 1095189760? Or are you referring to the fact that they're actually encoded > as ASCII? If not, I have no idea what you are trying to say. Yes, NAME and AGE are *not* ASCII text, but latin-1 encoded. The C and the N are ASCII, meaningful as-is. The actual data stored in a Character (NAME in this case) or Memo (not shown) field would also be latin-1 encoded. (And before you ask, the encoding is stored in the file header.) -- ~Ethan~ From blissend at gmail.com Mon Jan 6 14:07:10 2014 From: blissend at gmail.com (blissend at gmail.com) Date: Mon, 6 Jan 2014 11:07:10 -0800 (PST) Subject: Which python framework? In-Reply-To: References: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> Message-ID: <70cdce3d-cdc1-4c7f-ab24-fa26d1c770fb@googlegroups.com> On Monday, January 6, 2014 12:37:24 PM UTC-5, blis... at gmail.com wrote: > On Monday, January 6, 2014 12:09:28 PM UTC-5, Chris Angelico wrote: > > > On Tue, Jan 7, 2014 at 4:02 AM, wrote: > > > > > > > I love programming in python but I'm having trouble deciding over a framework for a single player MUD like game I'm making for fun. Ideally it's a cross-platform free framework in case I want make it open source later with good capabilities of customizing the GUI look/style. > > > > > > > > > > > > If by "MUD-like" you mean that it's fundamentally based on scrolling > > > > > > text and inputted commands, you may be able to just skip the GUI > > > > > > altogether and use the console (print() and input()). That'd save you > > > > > > a lot of trouble. Alternatively, it might be worth going the other way > > > > > > and actually making it a MUD. Wait for a socket connection, let the > > > > > > user TELNET in. Your GUI would then be an actual MUD client, off the > > > > > > shelf, giving you all its features absolutely for free. Either way, > > > > > > you put zero effort into building a GUI, and you get something every > > > > > > bit as powerful as you could build manually. > > > > > > > > > > > > ChrisA > > > > I suppose what I'm trying to accomplish isn't ordinary. Yes, it's fundamentally a scrolling text based game but... with input commands only as a secondary option. I'm going to design a new user experience I have in mind via a GUI that can engage users without having to type commands. This is why I'm wondering about alternatives. It appears pyqt has better theming capabilities from what I'm reading up on. From breamoreboy at yahoo.co.uk Mon Jan 6 14:12:44 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 19:12:44 +0000 Subject: Which python framework? In-Reply-To: <70cdce3d-cdc1-4c7f-ab24-fa26d1c770fb@googlegroups.com> References: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> <70cdce3d-cdc1-4c7f-ab24-fa26d1c770fb@googlegroups.com> Message-ID: On 06/01/2014 19:07, blissend at gmail.com wrote: Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dreamingforward at gmail.com Mon Jan 6 14:21:44 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 13:21:44 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52CAC780.1010204@stoneleaf.us> References: <52C9FD02.3080109@stoneleaf.us> <52CAC780.1010204@stoneleaf.us> Message-ID: > The argument is that a very important, if small, subset a data manipulation > become very painful in Py3. Not impossible, and not difficult, but painful > because the mental model and the contortions needed to get things to work > don't sync up anymore. You are confused. Please see my reply to you on the bytestring type thread. > Painful because Python is, at heart, a simple and > elegant language, but with the use-case of embedded ascii in binary data > that elegance went right out the window. It went out the window only because the Object model with the type/class unification was wrong. It was fine before. Mark >> It can't be both things. It's either bytes or it's text. > > Of course it can be: > > 0000000: 0372 0106 0000 0000 6100 1d00 0000 0000 .r......a....... > 0000010: 0000 0000 0000 0000 0000 0000 0000 0000 ................ > 0000020: 4e41 4d45 0000 0000 0000 0043 0100 0000 NAME.......C.... > 0000030: 1900 0000 0000 0000 0000 0000 0000 0000 ................ > 0000040: 4147 4500 0000 0000 0000 004e 1a00 0000 AGE........N.... > 0000050: 0300 0000 0000 0000 0000 0000 0000 0000 ................ > 0000060: 0d1a 0a ... > > And there we are, mixed bytes and ascii data. No, you are printing a debug output which shows both. That's called CHEATING. Mark From breamoreboy at yahoo.co.uk Mon Jan 6 14:26:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 19:26:21 +0000 Subject: the Gravity of Python 2 Message-ID: http://blog.startifact.com/posts/python-2-gravity.html "A Way Forward - How to go forward then? I think it makes sense to work as hard as possible to lift those Python 2 codebases out of the gravity well." I think this is complete nonsense. There's only been five years since the first release of Python 3. Surely much more time should be made available for people using Python 2 to plan for a migration? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dreamingforward at gmail.com Mon Jan 6 14:30:55 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 13:30:55 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52CAF722.6010301@stoneleaf.us> References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: >> Chris didn't say "bytes and ascii data", he said "bytes and TEXT". >> Text != "ascii data", and the fact that some people apparently think it >> does is pretty much the heart of the problem. > > The heart of a different problem, not this one. The problem I refer to is > that many binary formats have well-defined ascii-encoded text tidbits. Really? If people are using binary with "well-defined ascii-encoded tidbits", they're doing something wrong. Perhaps you think escape characters "\n" are "well defined tidbits", but YOU WOULD BE WRONG. The purpose of binary is to keep things raw. WTF? You guys are so strange. > >> If you (generic you) don't get that, you'll have a bad time. I mean >> *really* >> get it, deep down in the bone. The long, bad habit of thinking as >> ASCII-encoded bytes as text is the problem here. I think the whole forking community is confused at because of your own arrogance. Foo(l)s. markj From breamoreboy at yahoo.co.uk Mon Jan 6 14:36:22 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 19:36:22 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: On 06/01/2014 19:30, Mark Janssen wrote: >>> Chris didn't say "bytes and ascii data", he said "bytes and TEXT". >>> Text != "ascii data", and the fact that some people apparently think it >>> does is pretty much the heart of the problem. >> >> The heart of a different problem, not this one. The problem I refer to is >> that many binary formats have well-defined ascii-encoded text tidbits. > > Really? If people are using binary with "well-defined ascii-encoded > tidbits", they're doing something wrong. Perhaps you think escape > characters "\n" are "well defined tidbits", but YOU WOULD BE WRONG. > The purpose of binary is to keep things raw. WTF? You guys are so > strange. > >> >>> If you (generic you) don't get that, you'll have a bad time. I mean >>> *really* >>> get it, deep down in the bone. The long, bad habit of thinking as >>> ASCII-encoded bytes as text is the problem here. > > I think the whole forking community is confused at because of your own > arrogance. Foo(l)s. > > markj > Looks like another bad batch, time to change your dealer again. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dreamingforward at gmail.com Mon Jan 6 14:41:34 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 13:41:34 -0600 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: > http://blog.startifact.com/posts/python-2-gravity.html > > "A Way Forward - How to go forward then? I think it makes sense to work as > hard as possible to lift those Python 2 codebases out of the gravity well." > > I think this is complete nonsense. There's only been five years since the > first release of Python 3. Surely much more time should be made available > for people using Python 2 to plan for a migration? What makes no sense is that you've started a whole 'nother thread on an issue whose gravity is right here, already on the list. Add your new commentary and links to existing threads would be easier, yes? Mark unLawrence From dreamingforward at gmail.com Mon Jan 6 14:44:21 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 13:44:21 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: > Looks like another bad batch, time to change your dealer again. ??? Strange, when the debate hits bottom, accusations about doing drugs come up. This is like the third reference (and I don't even drink alcohol). mark From breamoreboy at yahoo.co.uk Mon Jan 6 14:44:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 19:44:25 +0000 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On 06/01/2014 19:41, Mark Janssen wrote: >> http://blog.startifact.com/posts/python-2-gravity.html >> >> "A Way Forward - How to go forward then? I think it makes sense to work as >> hard as possible to lift those Python 2 codebases out of the gravity well." >> >> I think this is complete nonsense. There's only been five years since the >> first release of Python 3. Surely much more time should be made available >> for people using Python 2 to plan for a migration? > > What makes no sense is that you've started a whole 'nother thread on > an issue whose gravity is right here, already on the list. Add your > new commentary and links to existing threads would be easier, yes? > I've just had a really good chuckle reading that coming from you. Got the new dealer yet? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From 7390621 at telenormail.rs Mon Jan 6 14:29:37 2014 From: 7390621 at telenormail.rs (7390621 at telenormail.rs) Date: Mon, 6 Jan 2014 20:29:37 +0100 Subject: porno srbija srbija porno porno video srbija kurve srbija porno&In-Reply Message-ID: -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From winefrog at gmail.com Mon Jan 6 15:08:19 2014 From: winefrog at gmail.com (Isaac Won) Date: Mon, 6 Jan 2014 12:08:19 -0800 (PST) Subject: Drawing shaded area depending on distance with latitude and altitude coordinate Message-ID: <7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com> I have tried to make a plot of points with longitude and latitude coordinate, and draw shaded area with distance from one point. So, I thought that I could uae contourf function from matplotlibrary. My code is: import haversine import numpy as np import matplotlib.pyplot as plt with open(filin, 'r') as f: arrays = [map(float, line.split()) for line in f] newa = [[x[1],-x[2]] for x in arrays] lat = np.zeros(275) lon = np.zeros(275) for c in range(0,275): lat[c] = newa[c][0] lon[c] = newa[c][1] with open(filin, 'r') as f: arrays = [map(float, line.split()) for line in f] newa = [[x[1],-x[2]] for x in arrays] lat = np.zeros(275) lon = np.zeros(275) for c in range(0,275): lat[c] = newa[c][0] lon[c] = newa[c][1] dis = np.zeros(275) for c in range(0,275): dis[c] = haversine.distance(newa[0],[lat[c],lon[c]]) dis1 = [[]]*1 for c in range(0,275): dis1[0].append(dis[c]) cs = plt.contourf(lon,lat,dis1) cb = plt.colorbar(cs) plt.plot(-lon[0],lat[0],'ro') plt.plot(-lon[275],lat[275],'ko') plt.plot(-lon[1:275],lat[1:275],'bo') plt.xlabel('Longitude(West)') plt.ylabel('Latitude(North)') plt.gca().invert_xaxis() plt.show() My idea in this code was that I could made a shaded contour by distance from a certain point which was noted as newa[0] in the code. I calculated distances between newa[0] and other points by haversine module which calculate distances with longitudes and latitudes of two points. However, whenever I ran this code, I got the error related to X, Y or Z in contourf such as: TypeError: Length of x must be number of columns in z, and length of y must be number of rows. IF I use meshgrid for X and Y, I also get: TypeError: Inputs x and y must be 1D or 2D. I just need to draw shaded contour with distance from one point on the top of the plot of each point. If you give any idea or hint, I will really apprecite. Thank you, Isaac From tjreedy at udel.edu Mon Jan 6 15:14:23 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 15:14:23 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <201401060932.35410.gheskett@wdtv.com> References: <201401060932.35410.gheskett@wdtv.com> Message-ID: On 1/6/2014 9:32 AM, Gene Heskett wrote: > And from my lurking here, its quite plain to me that 3.x python has a > problem with everyday dealing with strings. Strings of what? And what specific 'everyday' problem are you referring to? -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Mon Jan 6 15:16:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 20:16:53 +0000 Subject: Drawing shaded area depending on distance with latitude and altitude coordinate In-Reply-To: <7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com> References: <7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com> Message-ID: On 06/01/2014 20:08, Isaac Won wrote: > I have tried to make a plot of points with longitude and latitude coordinate, and draw shaded area with distance from one point. So, I thought that I could uae contourf function from matplotlibrary. My code is: > import haversine > import numpy as np > import matplotlib.pyplot as plt > with open(filin, 'r') as f: > arrays = [map(float, line.split()) for line in f] > newa = [[x[1],-x[2]] for x in arrays] > > lat = np.zeros(275) > lon = np.zeros(275) > for c in range(0,275): > lat[c] = newa[c][0] > lon[c] = newa[c][1] > > with open(filin, 'r') as f: > arrays = [map(float, line.split()) for line in f] > newa = [[x[1],-x[2]] for x in arrays] > > lat = np.zeros(275) > lon = np.zeros(275) > for c in range(0,275): > lat[c] = newa[c][0] > lon[c] = newa[c][1] > > > dis = np.zeros(275) > > for c in range(0,275): > dis[c] = haversine.distance(newa[0],[lat[c],lon[c]]) > > dis1 = [[]]*1 > > for c in range(0,275): > dis1[0].append(dis[c]) > > > cs = plt.contourf(lon,lat,dis1) > cb = plt.colorbar(cs) > > plt.plot(-lon[0],lat[0],'ro') > plt.plot(-lon[275],lat[275],'ko') > plt.plot(-lon[1:275],lat[1:275],'bo') > plt.xlabel('Longitude(West)') > plt.ylabel('Latitude(North)') > plt.gca().invert_xaxis() > plt.show() > > My idea in this code was that I could made a shaded contour by distance from a certain point which was noted as newa[0] in the code. I calculated distances between newa[0] and other points by haversine module which calculate distances with longitudes and latitudes of two points. However, whenever I ran this code, I got the error related to X, Y or Z in contourf such as: > TypeError: Length of x must be number of columns in z, and length of y must be number of rows. > > IF I use meshgrid for X and Y, I also get: > TypeError: Inputs x and y must be 1D or 2D. > > I just need to draw shaded contour with distance from one point on the top of the plot of each point. > > If you give any idea or hint, I will really apprecite. Thank you, Isaac > Sorry I can't help directly but can point you here https://lists.sourceforge.net/lists/listinfo/matplotlib-users or perhaps stackoverflow. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From storchaka at gmail.com Mon Jan 6 15:20:15 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 06 Jan 2014 22:20:15 +0200 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Message-ID: 06.01.14 06:51, Chris Angelico ???????(??): >>>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to turn a hex dump into a bytes literal? >>> bytes.fromhex('43 6c 67 75 62 61') b'Clguba' From storchaka at gmail.com Mon Jan 6 15:21:45 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 06 Jan 2014 22:21:45 +0200 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <20140105224123.78609d58@bigbox.christie.dr> References: <52CA13BD.4050708@stoneleaf.us> <20140105224123.78609d58@bigbox.christie.dr> Message-ID: 06.01.14 06:41, Tim Chase ???????(??): >>>> from codecs import getencoder >>>> getencoder("rot-13")(s2.decode('utf-8'))[0] > 'Python' codecs.decode('rot13', s2.decode()) From storchaka at gmail.com Mon Jan 6 15:31:23 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Mon, 06 Jan 2014 22:31:23 +0200 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: 06.01.14 15:44, Mark Lawrence ???????(??): > Simply scrap PEP 404 and the currently unhappy customers will be happy > as they'll be free to do all the work they want on Python 2.8, as my > understanding is that the vast majority of the Python core developers > won't do it for them. It's not necessary. You are free to make a fork and call it Qython 2.8. From solipsis at pitrou.net Mon Jan 6 15:32:50 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Jan 2014 20:32:50 +0000 (UTC) Subject: "More About Unicode in Python 2 and 3" References: Message-ID: Chris Angelico gmail.com> writes: > > On Tue, Jan 7, 2014 at 3:29 AM, Antoine Pitrou pitrou.net> wrote: > > People don't use? According to available figures, there are more downloads of > > Python 3 than downloads of Python 2 (Windows installers, mostly): > > http://www.python.org/webstats/ > > > > Unfortunately, that has a massive inherent bias, because there are > Python builds available in most Linux distributions - and stats from > those (like Debian's popcon) will be nearly as useless, because a lot > of them will install one or the other (probably 2.x) without waiting > for the user (so either they'll skew in favour of the one installed, > or in favour of the one NOT installed, because that's the only one > that'll be explicitly requested). It's probably fairly accurate for > Windows stats, though, since most people who want Python on Windows > are going to come to python.org for an installer. Agreed, but it's enough to rebut the claim that "people don't use Python 3". More than one million Python 3.3 downloads per month under Windows is a very respectable number (no 2.x release seems to reach that level). Regards Antoine. From python.list at tim.thechases.com Mon Jan 6 15:42:18 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Mon, 6 Jan 2014 14:42:18 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CA13BD.4050708@stoneleaf.us> Message-ID: <20140106144218.225787b3@bigbox.christie.dr> On 2014-01-06 22:20, Serhiy Storchaka wrote: > >>>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to > >>>> turn a hex dump into a bytes literal? > > >>> bytes.fromhex('43 6c 67 75 62 61') > b'Clguba' Very nice new functionality in Py3k, but 2.x doesn't seem to have such a method. :-( -tkc From breamoreboy at yahoo.co.uk Mon Jan 6 15:41:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 20:41:54 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 06/01/2014 20:31, Serhiy Storchaka wrote: > 06.01.14 15:44, Mark Lawrence ???????(??): >> Simply scrap PEP 404 and the currently unhappy customers will be happy >> as they'll be free to do all the work they want on Python 2.8, as my >> understanding is that the vast majority of the Python core developers >> won't do it for them. > > It's not necessary. You are free to make a fork and call it Qython 2.8. > You plural is fine, you singular simply doesn't apply, it'll stop raining in the UK first :) -- 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 Jan 6 15:47:11 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 20:47:11 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <20140106144218.225787b3@bigbox.christie.dr> References: <52CA13BD.4050708@stoneleaf.us> <20140106144218.225787b3@bigbox.christie.dr> Message-ID: On 06/01/2014 20:42, Tim Chase wrote: > On 2014-01-06 22:20, Serhiy Storchaka wrote: >>>>>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to >>>>>> turn a hex dump into a bytes literal? >> >> >>> bytes.fromhex('43 6c 67 75 62 61') >> b'Clguba' > > Very nice new functionality in Py3k, but 2.x doesn't seem to have such > a method. :-( > > -tkc > Seems like another mistake, that'll have to be regressed to make sure there is Python 2 and Python 3 compatibility, which can then be reintroduced into Python 2.8 so that it gets back into Python 3. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Mon Jan 6 15:49:53 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 15:49:53 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/6/2014 8:44 AM, Mark Lawrence wrote: > On 06/01/2014 12:39, Ned Batchelder wrote: >> >> I'm not talking about the technical details of bytes and Unicode. I'm >> talking about making customers happy. >> > > Simply scrap PEP 404 Not necessary. > and the currently unhappy customers will be happy > as they'll be free to do all the work they want on Python 2.8, They are already free to do so, as long as they do not call the result 'Python 2.8'. > as my > understanding is that the vast majority of the Python core developers > won't do it for them. Which is what some of them want and why they will never be happy. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jan 6 15:53:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 15:53:32 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52CAC780.1010204@stoneleaf.us> References: <52C9FD02.3080109@stoneleaf.us> <52CAC780.1010204@stoneleaf.us> Message-ID: On 1/6/2014 10:10 AM, Ethan Furman wrote: > The argument is that a very important, if small, subset a data > manipulation become very painful in Py3. Not impossible, and not > difficult, but painful because the mental model and the contortions > needed to get things to work don't sync up anymore. Thank you for a succinct summary. I presume you are referring in part by bytes manipulations that would be easier with bytes.format. In http://bugs.python.org/issue3982 Guido gave approval in principle to a minimal new method a year ago. The proponents failed to build on that to get anything in 3.4. Finally, however, Viktor Stinner has written a PEP http://www.python.org/dev/peps/pep-0460/ so something might happen for 3.5. -- Terry Jan Reedy From jwe.van.dijk at gmail.com Mon Jan 6 15:57:05 2014 From: jwe.van.dijk at gmail.com (jwe.van.dijk at gmail.com) Date: Mon, 6 Jan 2014 12:57:05 -0800 (PST) Subject: class inheritance python2.7 vs python3.3 In-Reply-To: References: Message-ID: <0156a9b0-1eb0-49a2-9ce9-fbed61f2c8d2@googlegroups.com> On Monday, 6 January 2014 18:14:08 UTC+1, jwe.va... at gmail.com wrote: > I have problems with these two classes: > > > > class LPU1(): > > def __init__(self, formula): > > """ > > formula is a string that is parsed into a SymPy function > > and several derived functions > > """ > > self.formula = formula > > ... ... > > > > class LPU3(LPU1): > > def __new__(self): > > """ > > the same functions as LPU1 but some added functions > > and some functions redefined > > """ > > ... ... > > > > if __name__ == '__main__: > > y = y = 'x_0 * x_1 + x_2' > > stats1 = LPU1(y) > > stats3 = LPU3(y) > > > > Worked perfectly on Python 2.7.5+ but on Python 3.3.2+ I get on instantiatiating stat3: > > TypeError: __new__() takes 1 positional argument but 2 were given > > > > What am I doing wrong? > > I must confess I am a bit out of my depth here so any explanation will be a learning experience. > > > > Many thanks, Janwillem Thanks for all the contributions. I now have: class LPU1(object): def __init__(self, formula): ... ... and class LPU3(LPU1): def __init__(self, y): LPU1.__init__(self, y) ... ... which gives the correct results both on 2.7 and 3.3. Is that more or less good practice? Now I stumble on a SymPy problem under 3.3 but that obviously is an other topic Cheers, janwillem From breamoreboy at yahoo.co.uk Mon Jan 6 16:02:15 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 21:02:15 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 06/01/2014 20:49, Terry Reedy wrote: > On 1/6/2014 8:44 AM, Mark Lawrence wrote: >> On 06/01/2014 12:39, Ned Batchelder wrote: >>> >>> I'm not talking about the technical details of bytes and Unicode. I'm >>> talking about making customers happy. >>> >> >> Simply scrap PEP 404 > > Not necessary. > >> and the currently unhappy customers will be happy >> as they'll be free to do all the work they want on Python 2.8, > > They are already free to do so, as long as they do not call the result > 'Python 2.8'. > > > as my >> understanding is that the vast majority of the Python core developers >> won't do it for them. > > Which is what some of them want and why they will never be happy. > I find all this intriguing. People haven't found time to migrate from Python 2 to Python 3, but now intend finding time to produce a fork of Python 2 which will ease the migration to Python 3. Have I got that correct? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dss.leb at gmail.com Mon Jan 6 16:11:53 2014 From: dss.leb at gmail.com (d ss) Date: Mon, 6 Jan 2014 13:11:53 -0800 (PST) Subject: python finance In-Reply-To: References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> Message-ID: <4bef9196-be41-4f1e-a904-d098952053bf@googlegroups.com> On Monday, January 6, 2014 12:06:45 PM UTC-5, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 3:58 AM, d ss wrote: > > > what the heck! > > > who told you this is a spam! > > > this is a call for cooperation and collaboration > > > how retarded! > > > > It is, at best, misdirected. There is a Python job board [1] where > > these sorts of things can be posted, but the main mailing list isn't > > the place for it. > > > > However, if you want your posts to be seen as legitimate, I would > > recommend putting a little more content into them, and putting some > > effort into the quality of English. Most of us will just skip over > > something that looks like unsolicited commercial email, if we even see > > it at all (spam filtering is getting pretty effective these days). > > > > ChrisA > > > > [1] http://www.python.org/community/jobs/ thanks Chris, i am checking the link i wrote just 2 words with a clear indicative title: "Python, Finance" which summarizes the following "if you are good in python and interested in applying your python knowledge to the field of finance then we may have a common interest in talking together" :D that s it! From ned at nedbatchelder.com Mon Jan 6 16:14:51 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 16:14:51 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: On 1/6/14 2:30 PM, Mark Janssen wrote: >>> Chris didn't say "bytes and ascii data", he said "bytes and TEXT". >>> Text != "ascii data", and the fact that some people apparently think it >>> does is pretty much the heart of the problem. >> >> The heart of a different problem, not this one. The problem I refer to is >> that many binary formats have well-defined ascii-encoded text tidbits. > > Really? If people are using binary with "well-defined ascii-encoded > tidbits", they're doing something wrong. Perhaps you think escape > characters "\n" are "well defined tidbits", but YOU WOULD BE WRONG. > The purpose of binary is to keep things raw. WTF? You guys are so > strange. > >> >>> If you (generic you) don't get that, you'll have a bad time. I mean >>> *really* >>> get it, deep down in the bone. The long, bad habit of thinking as >>> ASCII-encoded bytes as text is the problem here. > > I think the whole forking community is confused at because of your own > arrogance. Foo(l)s. > > markj > If you want to participate in this discussion, do so. Calling people strange, arrogant, and fools with no technical content is just rude. Typing "YOU WOULD BE WRONG" in all caps doesn't count as technical content. -- Ned Batchelder, http://nedbatchelder.com From gheskett at wdtv.com Mon Jan 6 16:17:06 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Mon, 6 Jan 2014 16:17:06 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> Message-ID: <201401061617.06746.gheskett@wdtv.com> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: > On 1/6/2014 9:32 AM, Gene Heskett wrote: > > And from my lurking here, its quite plain to me that 3.x python has a > > problem with everyday dealing with strings. > > Strings of what? And what specific 'everyday' problem are you referring > to? Strings start a new thread here at nominally weekly intervals. Seems to me that might be usable info. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page Tip the world over on its side and everything loose will land in Los Angeles. -- Frank Lloyd Wright A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From dreamingforward at gmail.com Mon Jan 6 16:23:08 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 15:23:08 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: >> Really? If people are using binary with "well-defined ascii-encoded >> tidbits", they're doing something wrong. Perhaps you think escape >> characters "\n" are "well defined tidbits", but YOU WOULD BE WRONG. >> The purpose of binary is to keep things raw. WTF? > If you want to participate in this discussion, do so. Calling people > strange, arrogant, and fools with no technical content is just rude. Typing > "YOU WOULD BE WRONG" in all caps doesn't count as technical content. Ned -- IF From ned at nedbatchelder.com Mon Jan 6 16:32:01 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 16:32:01 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52caecdb$0$29968$c3e8da3$5496439d@news.astraweb.com> References: <52caecdb$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/6/14 12:50 PM, Steven D'Aprano wrote: > Ned Batchelder wrote: > >> You are still talking about whether Armin is right, and whether he >> writes well, about flaws in his statistics, etc. I'm talking about the >> fact that an organization (Python core development) has a product >> (Python 3) that is getting bad press. Popular and vocal customers >> (Armin, Kenneth, and others) are unhappy. What is being done to make >> them happy? Who is working with them? They are not unique, and their >> viewpoints are not outliers. >> >> I'm not talking about the technical details of bytes and Unicode. I'm >> talking about making customers happy. > > Oh? How much did Armin pay for his Python support? If he didn't pay, he's > not a customer. He's a user. I use the term "customer" in the larger sense of, "someone using your product that you are trying to please." I'd like to think that an open source project with only users would treat them as customers. Not in the sense of a legal obligation in exchange for money, but in the sense that the point of the work is to please them. > > When something gets bad press, the normal process is to first determine just > how justified that bad press is. (Unless, of course, you're more interested > in just *covering it up* than fixing the problem.) The best solutions are: > > - if the bad press is justified, admit it, and fix the problems; > > - if the bad press is not justified, try to educate Armin (and others) so > they stop blaming Python for their own errors; try to counter their bad > press with good press; or ignore it, knowing that the internet is > notoriously fickle and in a week people will be hating on Go, or Ruby > instead. > > But I get the idea from your post that you don't want to talk about the > technical details of bytes and Unicode, and by extension, whether Python 3 > is better or worse than Python 2. That makes it impossible to determine how > valid the bad press is, which leaves us hamstrung. Our only responses are: > > - Patronise him. "Yes yes, you poor little thing, we feel your pain. But > what can we do about it?" > > - Abuse him and hope he shuts up. > > - Give in to his (and by extension, everyone elses) complaints, whether > justified or not, and make Python worse. > > - Counter his bad press with good press, and come across as arrogant idiots > by denying actual real problems (if any). > > - Wait for the Internet to move on. > I was only avoiding talking about Unicode vs bytes because I'm not the one who needs a better way to do it, Armin and Kenneth are. You seem to be arguing from the standpoint of, "I've never had problems, so there are no problems." I suspect an undercurrent here is also the difference between writing Python 3 code, and writing code that can run on both Python 2 and 3. In my original post, I provided two possible responses, one of which you've omitted: work with Armin to explain the easier way that he has missed. It sounds like you think there isn't an easier way, and that's OK? I would love to see a Python 3 advocate work with Armin or Kenneth on the code that's caused them such pain, and find a way to make it good. It's clear from other discussions happening elsewhere that there is the possibility of improving the situation, for example PEP 460 proposing "bytes % args" and "bytes.format(args)". That's good. -- Ned Batchelder, http://nedbatchelder.com From dreamingforward at gmail.com Mon Jan 6 16:32:35 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 15:32:35 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: >> Really? If people are using binary with "well-defined ascii-encoded >> tidbits", they're doing something wrong. Perhaps you think escape >> characters "\n" are "well defined tidbits", but YOU WOULD BE WRONG. >> The purpose of binary is to keep things raw. WTF? > > If you want to participate in this discussion, do so. Calling people > strange, arrogant, and fools with no technical content is just rude. Typing > "YOU WOULD BE WRONG" in all caps doesn't count as technical content. Ned -- IF YOU'RE A REAL PERSON -- you will see that several words prior to that declaration, you'll find (or be able to arrange) the proposition: "Escape characters are well-defined tidbits of binary data is FALSE". Now that is a technical point that i'm saying is simply the "way things are" coming from the mass of experience held by the OS community and the C programming community which is responsible for much of the world's computer systems. Do you have an argument against it, or do you piss off and argue against anything I say?? Perhaps I said it too loudly, and I take responsibility for that, but don't claim I'm not making a technical point which seems to be at the heart of all the confusion regarding python/python3 and str/unicode/bytes. mark From breamoreboy at yahoo.co.uk Mon Jan 6 16:33:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 21:33:54 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <201401061617.06746.gheskett@wdtv.com> References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 06/01/2014 21:17, Gene Heskett wrote: > On Monday 06 January 2014 16:16:13 Terry Reedy did opine: > >> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>> And from my lurking here, its quite plain to me that 3.x python has a >>> problem with everyday dealing with strings. >> >> Strings of what? And what specific 'everyday' problem are you referring >> to? > > Strings start a new thread here at nominally weekly intervals. Seems to me > that might be usable info. > > Cheers, Gene > That strikes me as being as useful as "The PEP 393 FSR is completely wrong but I'm not going to tell you why" approach. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ned at nedbatchelder.com Mon Jan 6 16:40:47 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 16:40:47 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/6/14 11:29 AM, Antoine Pitrou wrote: > Ned Batchelder nedbatchelder.com> writes: >> >> You can look through his problems and decide that he's "wrong," or that >> he's "ranting," but that doesn't change the fact that Python 3 is >> encountering friction. What happens when a significant fraction of your >> customers are "wrong"? > > Well, yes, there is some friction and this is quite expectable, when > shipping incompatible changes. Other pieces of software have undergone a > similar process (e.g. Apache 1.x -> Apache 2.x). > > (the alternative is to maintain a piece of software that sticks with obsolete > conventions, e.g. emacs) > >> Core developers: I thank you for the countless hours you have devoted to >> building all of the versions of Python. I'm sure in many ways it's a >> thankless task. But you have a problem. What's the point in being >> right if you end up with a product that people don't use? > > People don't use? According to available figures, there are more downloads of > Python 3 than downloads of Python 2 (Windows installers, mostly): > http://www.python.org/webstats/ > > The number of Python 3-compatible packages has been showing a constant and > healthy increase for years: > http://dev.pocoo.org/~gbrandl/py3.html > > And Dan's survey shows 77% of respondents think Python 3 wasn't a mistake: > https://wiki.python.org/moin/2.x-vs-3.x-survey > >> Maybe there are core developers who are trying hard to solve the >> problems Kenneth and Armin are facing. It would be great if that work >> was more visible. I don't see it, and apparently Armin doesn't either. > > While this is being discussed: > https://mail.python.org/pipermail/python-dev/2014-January/130923.html > > I would still point out that "Kenneth and Armin" are not the whole Python > community. I never said they were the whole community, of course. But they are not outliers either. By your own statistics above, 23% of respondents think Python 3 was a mistake. Armin and Kenneth are just two very visible people. > Your whole argument seems to be that a couple "revered" (!!) > individuals should see their complaints taken for granted. I am opposed to > rockstarizing the community. I'm not creating rock stars. I'm acknowledging that these two people are listened to by many others. It sounds like part of your effort to avoid rockstars is to ignore any one person's specific feedback? I must be misunderstanding what you mean. > > Their contribution is always welcome, of course. > > (as for network programming, the people working on and with asyncio don't > seem to find Python 3 terrible) Some people don't have problems. That doesn't mean that other people don't have problems. You are being given detailed specific feedback from intelligent dedicated customers that many people listen to, and who are building important components of the ecosystem, and your response is, "sorry, you are wrong, it will be fine if I ignore you." That's disheartening. > > Regards > > Antoine. -- Ned Batchelder, http://nedbatchelder.com From jeanpierreda at gmail.com Mon Jan 6 16:43:06 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 6 Jan 2014 13:43:06 -0800 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 1:02 PM, Mark Lawrence wrote: > I find all this intriguing. People haven't found time to migrate from > Python 2 to Python 3, but now intend finding time to produce a fork of > Python 2 which will ease the migration to Python 3. Have I got that > correct? Keeping old, unsupported (by upstream) things up-to-date is a common operation (e.g. this is what Red Hat does for an entire operating system). It might take a few hours to backport a module or bugfix you want, but updating an entire million-LOC codebase would take significantly longer. Plus, if a benefit of backporting things is an easier eventual migration to 3.x, it's killing two birds with one stone. At any rate it's not a possibility to sneer at and suggest is improbable or a waste of time. It is a rational outcome for a codebase of a large enough size. -- Devin From ned at nedbatchelder.com Mon Jan 6 16:42:01 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 16:42:01 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 1/6/14 4:33 PM, Mark Lawrence wrote: > On 06/01/2014 21:17, Gene Heskett wrote: >> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: >> >>> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>>> And from my lurking here, its quite plain to me that 3.x python has a >>>> problem with everyday dealing with strings. >>> >>> Strings of what? And what specific 'everyday' problem are you referring >>> to? >> >> Strings start a new thread here at nominally weekly intervals. Seems >> to me >> that might be usable info. >> >> Cheers, Gene >> > > That strikes me as being as useful as "The PEP 393 FSR is completely > wrong but I'm not going to tell you why" approach. > Please stop baiting people. -- Ned Batchelder, http://nedbatchelder.com From tjreedy at udel.edu Mon Jan 6 17:07:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 17:07:16 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/6/2014 7:39 AM, Ned Batchelder wrote: > You are still talking about whether Armin is right, and whether he > writes well, about flaws in his statistics, etc. That is how *I* decide whether someone is worth attending to. He failed. > I'm talking about the fact that an organization of volunteers > (Python core development) has a product given away for free, with a liberal license that allows derivative products > (Python 3) that is getting bad press. Inevitable and nothing new. > (Armin, Kenneth, and others) are unhappy. There are many unhappy people in the world. Some will be unhappy no matter what. > What is being done to make them happy? Huh? What are they doing to make core developers happy? >Who is working with them? You? Really the wrong question. Which of 'them' is working with us -- in a respectful manner -- through established means? (See my response to Ethan about what 'unhappy customers' failed to do for a year.) > I'm talking about making customers happy. Python has 'customers' around the world. I am more am more concerned with helping poor kids in Asia, Africa, and Latin America than with well-off professional developers in Latin-alphabet regions. A certain person is unhappy with a feature of 3.3+. When we fixed the first ostensible problem he identified, without his help, he found other reasons to be unhappy with the feature. When we voluntarily fix more of the ostensible problems with Python 3, which we will, without help from most of the 'unhappy customers', I expect that some of them will also continue to be unhappy customers. Some of them are opposed to the fundamental changes in Python 3 and will never be happy with it. -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Mon Jan 6 17:08:27 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 22:08:27 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 06/01/2014 21:42, Ned Batchelder wrote: > On 1/6/14 4:33 PM, Mark Lawrence wrote: >> On 06/01/2014 21:17, Gene Heskett wrote: >>> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: >>> >>>> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>>>> And from my lurking here, its quite plain to me that 3.x python has a >>>>> problem with everyday dealing with strings. >>>> >>>> Strings of what? And what specific 'everyday' problem are you referring >>>> to? >>> >>> Strings start a new thread here at nominally weekly intervals. Seems >>> to me >>> that might be usable info. >>> >>> Cheers, Gene >>> >> >> That strikes me as being as useful as "The PEP 393 FSR is completely >> wrong but I'm not going to tell you why" approach. >> > > Please stop baiting people. > What are you on about? The comment has been made that "its quite plain to me that 3.x python has a problem with everyday dealing with strings". Myself, Terry Reedy and Steven D'Aprano have all commented on this, asking for more data. We've been given nothing, which is precisely what our resident unicode expert has given us. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From solipsis at pitrou.net Mon Jan 6 17:16:22 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Jan 2014 22:16:22 +0000 (UTC) Subject: "More About Unicode in Python 2 and 3" References: Message-ID: Ned Batchelder nedbatchelder.com> writes: > > > I never said they were the whole community, of course. But they are not > outliers either. By your own statistics above, 23% of respondents think > Python 3 was a mistake. Armin and Kenneth are just two very visible > people. Indeed, they are two very visible people. > I'm not creating rock stars. I'm acknowledging that these two people > are listened to by many others. It sounds like part of your effort to > avoid rockstars is to ignore any one person's specific feedback? I must > be misunderstanding what you mean. I am not trying to ignore "any one person's specific feedback". I am ignoring your claim that we should give Armin's blog posts an extraordinary importance because he is "revered". Speaking of which, posting blog articles is not the preferred way to give feedback. There are ample community resources for that. I am irritated that we are apparently supposed to be monitoring blog posts, Twitter feeds and whatnot for any sign of dissent, and immediately react to a criticism that wasn't even voiced directly to us. > You are being given detailed specific feedback from intelligent > dedicated customers that many people listen to, Could you please stop talking about customers? We are not selling Python to anyone (*). Writing open source software as a volunteer is not supposed to be a sacrificial activity where we will bow with extreme diligence to the community's every outburst. Please try to respect us. ((*) Wikipedia: "A customer (sometimes known as a client, buyer, or purchaser) is the recipient of a good, service, product, or idea, obtained from a seller, vendor, or supplier for a monetary or other valuable consideration") Regards Antoine. From ned at nedbatchelder.com Mon Jan 6 17:22:34 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 17:22:34 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 1/6/14 5:08 PM, Mark Lawrence wrote: > On 06/01/2014 21:42, Ned Batchelder wrote: >> On 1/6/14 4:33 PM, Mark Lawrence wrote: >>> On 06/01/2014 21:17, Gene Heskett wrote: >>>> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: >>>> >>>>> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>>>>> And from my lurking here, its quite plain to me that 3.x python has a >>>>>> problem with everyday dealing with strings. >>>>> >>>>> Strings of what? And what specific 'everyday' problem are you >>>>> referring >>>>> to? >>>> >>>> Strings start a new thread here at nominally weekly intervals. Seems >>>> to me >>>> that might be usable info. >>>> >>>> Cheers, Gene >>>> >>> >>> That strikes me as being as useful as "The PEP 393 FSR is completely >>> wrong but I'm not going to tell you why" approach. >>> >> >> Please stop baiting people. >> > > What are you on about? The comment has been made that "its quite plain > to me that 3.x python has a problem with everyday dealing with strings". > Myself, Terry Reedy and Steven D'Aprano have all commented on this, > asking for more data. We've been given nothing, which is precisely what > our resident unicode expert has given us. > I'm on about your comment being a gratuitous jab at someone who isn't even participating in the thread. Stop it. -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Mon Jan 6 17:25:15 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Mon, 06 Jan 2014 17:25:15 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 1/6/14 5:16 PM, Antoine Pitrou wrote: > Ned Batchelder nedbatchelder.com> writes: >> >> >> I never said they were the whole community, of course. But they are not >> outliers either. By your own statistics above, 23% of respondents think >> Python 3 was a mistake. Armin and Kenneth are just two very visible >> people. > > Indeed, they are two very visible people. > >> I'm not creating rock stars. I'm acknowledging that these two people >> are listened to by many others. It sounds like part of your effort to >> avoid rockstars is to ignore any one person's specific feedback? I must >> be misunderstanding what you mean. > > I am not trying to ignore "any one person's specific feedback". I am > ignoring your claim that we should give Armin's blog posts an > extraordinary importance because he is "revered". > > Speaking of which, posting blog articles is not the preferred way to > give feedback. There are ample community resources for that. I am > irritated that we are apparently supposed to be monitoring blog posts, > Twitter feeds and whatnot for any sign of dissent, and immediately react > to a criticism that wasn't even voiced directly to us. > >> You are being given detailed specific feedback from intelligent >> dedicated customers that many people listen to, > > Could you please stop talking about customers? We are not selling > Python to anyone (*). Writing open source software as a volunteer is > not supposed to be a sacrificial activity where we will bow with > extreme diligence to the community's every outburst. Please try to > respect us. I do respect you, and all the core developers. As I've said elsewhere in the thread, I greatly appreciate everything you do. I dedicate a great deal of time and energy to the Python community, primarily because of the amazing product that you have all built. I've made my point as best as I can, I'll stop now. > > ((*) Wikipedia: "A customer (sometimes known as a client, buyer, or > purchaser) is the recipient of a good, service, product, or idea, > obtained from a seller, vendor, or supplier for a monetary or other > valuable consideration") > > Regards > > Antoine. > > -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Mon Jan 6 17:30:14 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 22:30:14 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 06/01/2014 22:22, Ned Batchelder wrote: > On 1/6/14 5:08 PM, Mark Lawrence wrote: >> On 06/01/2014 21:42, Ned Batchelder wrote: >>> On 1/6/14 4:33 PM, Mark Lawrence wrote: >>>> On 06/01/2014 21:17, Gene Heskett wrote: >>>>> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: >>>>> >>>>>> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>>>>>> And from my lurking here, its quite plain to me that 3.x python >>>>>>> has a >>>>>>> problem with everyday dealing with strings. >>>>>> >>>>>> Strings of what? And what specific 'everyday' problem are you >>>>>> referring >>>>>> to? >>>>> >>>>> Strings start a new thread here at nominally weekly intervals. Seems >>>>> to me >>>>> that might be usable info. >>>>> >>>>> Cheers, Gene >>>>> >>>> >>>> That strikes me as being as useful as "The PEP 393 FSR is completely >>>> wrong but I'm not going to tell you why" approach. >>>> >>> >>> Please stop baiting people. >>> >> >> What are you on about? The comment has been made that "its quite plain >> to me that 3.x python has a problem with everyday dealing with strings". >> Myself, Terry Reedy and Steven D'Aprano have all commented on this, >> asking for more data. We've been given nothing, which is precisely what >> our resident unicode expert has given us. >> > > I'm on about your comment being a gratuitous jab at someone who isn't > even participating in the thread. Stop it. > You arrogance really has no bounds. If you'd have done the job that you should have done in the first place and stopped that blithering idiot 16 months ago, we wouldn't still be putting up with him now. To top that, you're now defending "customers" when you should be saying quite clearly that PEP 404 stands as is and THERE WILL BE NO PYTHON 2.8. Have I made my message perfectly clear? And as I started this thread, I'll say what I please, throwing my toys out of my pram in just the same way that your pal Armin is currently doing. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From rowen at uw.edu Mon Jan 6 17:31:04 2014 From: rowen at uw.edu (Russell E. Owen) Date: Mon, 06 Jan 2014 14:31:04 -0800 Subject: Suggested GUI framework for Mac and unix? Message-ID: I have a free cross-platform Python GUI application that has to run on Mac and linux. It is presently written in Tkinter, but for various reasons* it may be time to switch. I've heard many good things about wxpython and qt, but not used either, and am wondering if somebody could tell me if either (or both) would meet the following needs: - Reliable on mac and linux. (I see that wxpython now runs under Cocoa but I've not seen any reports on how well that went.) - Compatible with matplotlib. - Able to display (grayscale) images with arbitrary zoom. I currently use PIL with Tkinter's Canvas widget for this. - Compatible with a sound library for playing sound cues. I presently use pygame for this and have been considering switching to PySDL. - Compatible with Twisted Framework. - Prediction is hard, but indications of a long-term future would be a definite bonus. -- Russell *I have no wish to disparage Tkinter. I personally like it and am very grateful to the developers. However, several issues are driving me to look for alternatives: * There is a known crashing bug in recent versions of Tcl/Tk that keeps me at 8.5.11. Unfortunately I've not found a workaround. * Tcl/Tk 8.5.11 is not compatible with Mavericks unless one runs in 32-bit mode. * There are known issues with the Tcl/Tk event loop since the switch to Cocoa. These are unlikely to be fixed, though in many cases it is practical to work around them. This is more of a long-term worry than a concrete problem. From solipsis at pitrou.net Mon Jan 6 17:35:02 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Jan 2014 22:35:02 +0000 (UTC) Subject: "More About Unicode in Python 2 and 3" References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: Mark Lawrence yahoo.co.uk> writes: > [...] > > And as I started this thread, I'll say what I please, throwing my toys > out of my pram in just the same way that your pal Armin is currently doing. I'll join Ned here: please stop it. You are doing a disservice to everyone. Thanks in advance Antoine. From nicholas.cole at gmail.com Mon Jan 6 17:41:26 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Mon, 6 Jan 2014 22:41:26 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: I hardly know which of the various threads on this topic to reply to! No one is taking Python 2.7 away from anyone. It is going to be on the net for years to come. Goodness! I expect if I wanted to go and download Python 1.5 I could find it easily enough. Like everyone else, when Python 3 came out I was nervous. A lot of my code broke - but it broke for a good reason. I had been being cavalier about strings and ASCII and bytes. A lot of my code was working by accident rather than by design, or because my users had never fed it anything that would make it fall over. Of course, my first reaction was a defensive one, but once I had got over that and got my head around Python 3's view of the world, I was pleased I had. I find writing in Python 3 leads to more robust code. I like the way it forces me to do the right thing, and I like the way it raises errors if I try to get away with something I shouldn't. Going back to Python 2 now feels a bit like stepping back to the seductive and permissive hell of PHP in some ways! If I could be sure that I was coding just for me and not having to support things still running on Python 2, I would move to Python 3.3 and not look back. Except, yes, there are still libraries that haven't made the change....blast! Python 2.7 is there if your software was written to run on the 2 series. I am sure it will either be distributed with (as default or option) major operating systems for some time. I am totally unpersuaded by the argument that 'back porting' more and more into Python 2 will ease the transition. I think it will just use up developer time, and delay further the day when releasing new code for Python 3 only becomes not only reasonable but the natural and default choice. I am really glad to see that at least one distribution of Linux is moving to Python 3 as the default. I'd much rather see developer time spent improving Python 3 than managing a transition. I realised when Python 3.0 came out that eventually I would have to move to Python 3. I spent the next release in a state of denial. But I had years to get used to it, and I'm glad I have. It "feels" more robust. Of course, I haven't ported every little program: but no one is forcing me too! All of these threads are written as if everyone's code is about to be broken. It isn't. But if you want the new features, you need to make a move, and it is probably time to write all new code in Python 3. If there's a dependency holding you back, then there will be a Python 2 interpreter around to run your code. That all seems pretty reasonable and straightforward to me. Nicholas -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Mon Jan 6 17:46:52 2014 From: davea at davea.name (Dave Angel) Date: Mon, 06 Jan 2014 17:46:52 -0500 Subject: =?UTF-8?Q?Re:_Drawing_shaded_area_depending_on_dista?= =?UTF-8?Q?nce_with_latitude_and_altitude=0A_coordinate?= In-Reply-To: <7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com> References: <7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com> <7f58342b-9b75-4a2c-b98e-cc43a4bb05a6@googlegroups.com> Message-ID: On Mon, 6 Jan 2014 12:08:19 -0800 (PST), Isaac Won wrote: > dis1 = [[]]*1 > for c in range(0,275): > dis1[0].append(dis[c]) So dis1 has 1 row in it. But contourf is expecting many rows, matching the length of lat. I'm guessing you have to fill in the others. > cs = plt.contourf(lon,lat,dis1) > TypeError: Length of x must be number of columns in z, and length of y must be number of rows. That's only a tiny part of the error message. Please post the whole traceback. I made a guess here knowing nothing about these libraries you're using. -- DaveA From tjreedy at udel.edu Mon Jan 6 17:53:55 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 17:53:55 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: <52CB3403.3000903@udel.edu> On 1/6/2014 11:29 AM, Antoine Pitrou wrote: > People don't use? According to available figures, there are more downloads of > Python 3 than downloads of Python 2 (Windows installers, mostly): > http://www.python.org/webstats/ While I would like the claim to be true, I do not see 2 versus 3 downloads on that page. Did you mean another link? > The number of Python 3-compatible packages has been showing a constant and > healthy increase for years: > http://dev.pocoo.org/~gbrandl/py3.html This looks like the beginning of a sigmoid adoption curve. I do not expect to see a peak of 100% unless and until old, dead, Python 2 only projects get purged (in some future decade, if ever). -- Terry Jan Reedy From breamoreboy at yahoo.co.uk Mon Jan 6 17:55:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 22:55:40 +0000 Subject: Suggested GUI framework for Mac and unix? In-Reply-To: References: Message-ID: On 06/01/2014 22:31, Russell E. Owen wrote: I'm no expert on GUIs but I've just picked wxPython via the age old system of tossing a coin :) > I have a free cross-platform Python GUI application that has to run on > Mac and linux. It is presently written in Tkinter, but for various > reasons* it may be time to switch. > > I've heard many good things about wxpython and qt, but not used either, > and am wondering if somebody could tell me if either (or both) would > meet the following needs: > - Reliable on mac and linux. (I see that wxpython now runs under Cocoa > but I've not seen any reports on how well that went.) I can't comment but there's bound to be data on either the wxpython development or users mailing lists. > - Compatible with matplotlib. Demo here looks good http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/ > - Able to display (grayscale) images with arbitrary zoom. I currently > use PIL with Tkinter's Canvas widget for this. > - Compatible with a sound library for playing sound cues. I presently > use pygame for this and have been considering switching to PySDL. > - Compatible with Twisted Framework. > - Prediction is hard, but indications of a long-term future would be a > definite bonus. From wxpython.org "(25-Dec-2013) wxPython (classic) 3.0.0.0 has been released. No new features but lots of bug fixes in wxWidgets and of course the bump (finally!) up to 3.0." See also http://wiki.wxpython.org/ProjectPhoenix which is the port of wxpython to support Python 3. I'm not sure when it will be released by I believe we're talking months. > > -- Russell > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dreamingforward at gmail.com Mon Jan 6 17:56:10 2014 From: dreamingforward at gmail.com (Mark Janssen) Date: Mon, 6 Jan 2014 16:56:10 -0600 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: >> I would still point out that "Kenneth and Armin" are not the whole Python >> community. > > I never said they were the whole community, of course. But they are not > outliers either. [...] > >> Your whole argument seems to be that a couple "revered" (!!) >> individuals should see their complaints taken for granted. I am opposed to >> rockstarizing the community. > > I'm not creating rock stars. I'm acknowledging that these two people are > listened to by many others. It sounds like part of your effort to avoid > rockstars is to ignore any one person's specific feedback? I must be > misunderstanding what you mean. To Ned's defense, it doesn't always work to treat everyone in the community as equal. That's not to say that those two examples are the most important, but some people work on core aspects of the field which are critical for everything else to work properly. Without diving into it, one can't say whether Ned's intuition is wrong or not. markj From breamoreboy at yahoo.co.uk Mon Jan 6 17:57:45 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 22:57:45 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 06/01/2014 22:35, Antoine Pitrou wrote: > > Mark Lawrence yahoo.co.uk> writes: >> [...] >> >> And as I started this thread, I'll say what I please, throwing my toys >> out of my pram in just the same way that your pal Armin is currently doing. > > I'll join Ned here: please stop it. You are doing a disservice to > everyone. > > Thanks in advance > > Antoine. > > I will for you as I have great respect for the amount of work that I've seen you do over the years that I've been using Python. -- 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 Mon Jan 6 18:03:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 10:03:27 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: On Tue, Jan 7, 2014 at 8:32 AM, Mark Janssen wrote: >>> Really? If people are using binary with "well-defined ascii-encoded >>> tidbits", they're doing something wrong. Perhaps you think escape >>> characters "\n" are "well defined tidbits", but YOU WOULD BE WRONG. >>> The purpose of binary is to keep things raw. WTF? >> >> If you want to participate in this discussion, do so. Calling people >> strange, arrogant, and fools with no technical content is just rude. Typing >> "YOU WOULD BE WRONG" in all caps doesn't count as technical content. > > Ned -- [chomp verbiage] Mark, please watch your citations. Several (all?) of your posts in this thread have omitted the line(s) at the top saying who you're quoting. Have a look at my post here, and then imagine how confused Mark Lawrence would be if I hadn't made it clear that I wasn't addressing him. Thanks! ChrisA From breamoreboy at yahoo.co.uk Mon Jan 6 18:02:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 23:02:05 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 06/01/2014 22:41, Nicholas Cole wrote: > I hardly know which of the various threads on this topic to reply to! > > No one is taking Python 2.7 away from anyone. It is going to be on the > net for years to come. Goodness! I expect if I wanted to go and > download Python 1.5 I could find it easily enough. > > Like everyone else, when Python 3 came out I was nervous. A lot of my > code broke - but it broke for a good reason. I had been being cavalier > about strings and ASCII and bytes. A lot of my code was working by > accident rather than by design, or because my users had never fed it > anything that would make it fall over. Of course, my first reaction was > a defensive one, but once I had got over that and got my head around > Python 3's view of the world, I was pleased I had. I find writing in > Python 3 leads to more robust code. I like the way it forces me to do > the right thing, and I like the way it raises errors if I try to get > away with something I shouldn't. Going back to Python 2 now feels a bit > like stepping back to the seductive and permissive hell of PHP in some > ways! If I could be sure that I was coding just for me and not having > to support things still running on Python 2, I would move to Python 3.3 > and not look back. Except, yes, there are still libraries that haven't > made the change....blast! > > Python 2.7 is there if your software was written to run on the 2 series. > I am sure it will either be distributed with (as default or option) > major operating systems for some time. I am totally unpersuaded by the > argument that 'back porting' more and more into Python 2 will ease the > transition. I think it will just use up developer time, and delay > further the day when releasing new code for Python 3 only becomes not > only reasonable but the natural and default choice. > > I am really glad to see that at least one distribution of Linux is > moving to Python 3 as the default. I'd much rather see developer time > spent improving Python 3 than managing a transition. > I realised when Python 3.0 came out that eventually I would have to move > to Python 3. I spent the next release in a state of denial. But I had > years to get used to it, and I'm glad I have. It "feels" more robust. > Of course, I haven't ported every little program: but no one is > forcing me too! > > All of these threads are written as if everyone's code is about to be > broken. It isn't. But if you want the new features, you need to make a > move, and it is probably time to write all new code in Python 3. If > there's a dependency holding you back, then there will be a Python 2 > interpreter around to run your code. That all seems pretty reasonable > and straightforward to me. > > Nicholas > > The first sentence from the blog which gives this thread its title "It's becoming increasingly harder to have reasonable discussions about the differences between Python 2 and 3 because one language is dead and the other is actively developed". Funny really as I see bug fixes going into Python 2.7 on a daily basis so I can only assume that their definition of dead is different to mine and presumably yours. -- 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 Mon Jan 6 18:06:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 10:06:01 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <20140106144218.225787b3@bigbox.christie.dr> References: <52CA13BD.4050708@stoneleaf.us> <20140106144218.225787b3@bigbox.christie.dr> Message-ID: On Tue, Jan 7, 2014 at 7:42 AM, Tim Chase wrote: > On 2014-01-06 22:20, Serhiy Storchaka wrote: >> >>>> data = b"\x43\x6c\x67\x75\x62\x61" # is there an easier way to >> >>>> turn a hex dump into a bytes literal? >> >> >>> bytes.fromhex('43 6c 67 75 62 61') >> b'Clguba' > > Very nice new functionality in Py3k, but 2.x doesn't seem to have such > a method. :-( Thanks, Serhiy. Very nice new functionality indeed, and not having it in 2.x isn't a problem to me. That's exactly what I was looking for - it doesn't insist on (or complain about) separators between bytes. (Though the error from putting a space _inside_ a byte is a little confusing. But that's trivial.) ChrisA From solipsis at pitrou.net Mon Jan 6 18:06:57 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Mon, 6 Jan 2014 23:06:57 +0000 (UTC) Subject: "More About Unicode in Python 2 and 3" References: <52CB3403.3000903@udel.edu> Message-ID: Terry Reedy udel.edu> writes: > > On 1/6/2014 11:29 AM, Antoine Pitrou wrote: > > > People don't use? According to available figures, there are more downloads of > > Python 3 than downloads of Python 2 (Windows installers, mostly): > > http://www.python.org/webstats/ > > While I would like the claim to be true, I do not see 2 versus 3 > downloads on that page. Did you mean another link? Just click on a recent month, scroll down to the "Total URLs By kB" table, and compute the sum of the largest numbers for each Python version. Regards Antoine. From ben+python at benfinney.id.au Mon Jan 6 18:14:55 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 07 Jan 2014 10:14:55 +1100 Subject: "More About Unicode in Python 2 and 3" References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: <7w1u0khfdc.fsf@benfinney.id.au> Mark Lawrence writes: > You arrogance really has no bounds. If you'd have done the job that > you should have done in the first place and stopped that blithering > idiot 16 months ago, we wouldn't still be putting up with him now. That is a misdirection; Ned's request that you stop bad behaviour (baiting known trolls into responding on a thread) is unrelated to Armin's bad behaviour. Don't use the bad behaviour of others to justify yours. > And as I started this thread, I'll say what I please, throwing my toys > out of my pram in just the same way that your pal Armin is currently > doing. We expect everyone to behave well, regardless of whether they start a thread or not. Don't use the bad behaviour of others to justify yours. We know you're better than this, Mark. Please stop. -- \ ?To have the choice between proprietary software packages, is | `\ being able to choose your master. Freedom means not having a | _o__) master.? ?Richard M. Stallman, 2007-05-16 | Ben Finney From rosuav at gmail.com Mon Jan 6 18:15:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 10:15:23 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 7:32 AM, Antoine Pitrou wrote: > Chris Angelico gmail.com> writes: >> >> On Tue, Jan 7, 2014 at 3:29 AM, Antoine Pitrou pitrou.net> > wrote: >> > People don't use? According to available figures, there are more > downloads of >> > Python 3 than downloads of Python 2 (Windows installers, mostly): >> > http://www.python.org/webstats/ >> > >> >> Unfortunately, that has a massive inherent bias, because there are >> Python builds available in most Linux distributions - and stats from >> those (like Debian's popcon) will be nearly as useless, because a lot >> of them will install one or the other (probably 2.x) without waiting >> for the user (so either they'll skew in favour of the one installed, >> or in favour of the one NOT installed, because that's the only one >> that'll be explicitly requested). It's probably fairly accurate for >> Windows stats, though, since most people who want Python on Windows >> are going to come to python.org for an installer. > > Agreed, but it's enough to rebut the claim that "people don't use > Python 3". More than one million Python 3.3 downloads per month under > Windows is a very respectable number (no 2.x release seems to reach > that level). Sure. The absolute number is useful; I just don't think the relative number is - you started by talking about there being "more downloads of Python 3 than downloads of Python 2", and it's that comparison that I think is unfair. But the absolute numbers are definitely significant. I'm not quite sure how to interpret the non-link lines in [1] but I see the month of December showing roughly 1.2 million Python 3.3.3 downloads for Windows - interestingly, split almost fifty-fifty between 64-bit and 32-bit installs - and just over one million Python 2.7.6 installs. That's one month, two million installations of Python. That's 73,021 *per day* for the month of December. That is a lot of Python. ChrisA [1] http://www.python.org/webstats/usage_201312.html#TOPURLS From breamoreboy at yahoo.co.uk Mon Jan 6 18:21:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 06 Jan 2014 23:21:48 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <7w1u0khfdc.fsf@benfinney.id.au> References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> <7w1u0khfdc.fsf@benfinney.id.au> Message-ID: On 06/01/2014 23:14, Ben Finney wrote: > Mark Lawrence writes: > >> You arrogance really has no bounds. If you'd have done the job that >> you should have done in the first place and stopped that blithering >> idiot 16 months ago, we wouldn't still be putting up with him now. > > That is a misdirection; Ned's request that you stop bad behaviour > (baiting known trolls into responding on a thread) is unrelated to > Armin's bad behaviour. Don't use the bad behaviour of others to justify > yours. > Armin isn't our resident unicode expert!!! >> And as I started this thread, I'll say what I please, throwing my toys >> out of my pram in just the same way that your pal Armin is currently >> doing. > > We expect everyone to behave well, regardless of whether they start a > thread or not. Don't use the bad behaviour of others to justify yours. > > We know you're better than this, Mark. Please stop. > Fair comment, though I'll confess I feel rather better for having let off a bit of steam. At the same time I really must stop being so defensive of the python ecosytem and its core developers and start complaining about what they haven't done for me. My list follows below. -- 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 Mon Jan 6 18:24:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 10:24:30 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CB3403.3000903@udel.edu> Message-ID: On Tue, Jan 7, 2014 at 10:06 AM, Antoine Pitrou wrote: > Terry Reedy udel.edu> writes: >> >> On 1/6/2014 11:29 AM, Antoine Pitrou wrote: >> >> > People don't use? According to available figures, there are more > downloads of >> > Python 3 than downloads of Python 2 (Windows installers, mostly): >> > http://www.python.org/webstats/ >> >> While I would like the claim to be true, I do not see 2 versus 3 >> downloads on that page. Did you mean another link? > > Just click on a recent month, scroll down to the "Total URLs By kB" > table, and compute the sum of the largest numbers for each Python > version. Here's what I see there (expanding on what I said in the other post, which was based on one table further up, URLs by hit count) for December: 3.3.3: 1214571 - amd64 627672 - win32 586899 2.7.6: 1049096 - win32 607972 - amd64 441124 The next highest number is 167K downloads, so I'm going to ignore their figures as they won't make more than 15% difference in these stats. This is 2263667 total downloads of the current versions of Python, 46% 2.7.6 and 54% 3.3.3. That's not incredibly significant statistically, but certainly it disproves the notion that 3.x isn't used at all. ChrisA From nicholas.cole at gmail.com Mon Jan 6 18:39:13 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Mon, 6 Jan 2014 23:39:13 +0000 Subject: Python program distribution - a source of constant friction Message-ID: This email is inspired by a YouTube video of a talk that Jessica McKellar recently gave. I was struck by her analysis that it is hard to remain a popular language (as Python currently is) and her call to action to address friction points that make it hard for a non-Python audience to use Python and applications developed in Python. Well, here is one. All of the early books one reads on Python compare it to Java or similar languages. Write code once, is the promise, and as long as your target computer has a Python interpreter, your code will run. For Java, I have to say! this really does seem true. Once I have a Java environment installed, Java applications work seamlessly. I download them, execute them, and, unless they are very old and give themselves away by using a non-native set of GUI widgets, I probably forget that I am running Java at all. But as we all know, Python isn't that simple. I'm not talking about the problems of cross-platform GUIs or other such things. I'm taking about the problem of distributing anything more complicated than a single-file program to end users. I realise that I'm not really, either, taking about the much written about Python packaging problem. I was going to berate the packaging documentation for not really helping with the problem I have in mind, but I realised that actually the kinds of packages that the Packaging Guide is taking about are the kinds of things that developers and python-proficient system administrators will be installing. But what about the end-user? The end-user who just wants a blob (he doesn't care about what language it is in - he just wants to solve the problem at hand with your shiny, cool, problem-solving application). He is hopefully using a system on which Python comes as default. At most one might get him to install a new Python interpreter and standard library, but asking him to do more than that is simply asking more than he will do. Will your code run or not? (i.e. without him having to learn what pip is!) There are tools that will package up binaries of python and create something that will even run without an interpreter installed on the target system. If only they were better documented, less fragile and worked consistently with Python 3! Even then, I'm not sure this is the answer - anything like that is bound to be a bit fragile and break one of the attractive features of Python - that all things being equal, I don't need to maintain development environments for every possible target platform to get code to run. What would be nice is something much less complicated. Something , for example, that just takes everything except the python interpreter from a virtual environment, packs it up and turns it into a zip archive that really will run on a user's python installation without any additional steps. There are a couple of tools to do something close to this, but they are hardly well signposted in the python documentation (in fact I only found them with the help of this list), and even these tools need more than a little experimentation to get right. No doubt even here some extra glue or magic would be useful - what is the right thing to do when C modules are needed? But at any rate, I think that some more thought in this area would be very useful. And what about WSGI apps? I regard WSGI as one of the great features of modern Python. But again, end users don't really want to have to learn all about python and proxy servers running in front of special WSGI servers. Most are not going to serve hundreds of thousands of users, but probably do need a little more than one connection at a time. Even if the right solution is to create these complicated setups, I defy anyone to find me a page I could point a competent system administrator (but non-Python developer) at and say, "here is my code, install it in this directory and set up a webserver according to the instructions on this single web page and everything will just work." We are even further away from saying, "Here is a special zip file. Make sure you have a Python 3 interpreter ready and then just treat this file as you would any other service on your system. Have it started by whatever daemon manages services on your server, and it will all just work and be able to handle a reasonable number of users with a reasonable level of security and reliability. Of course, if you end up with more than a few hundred users, you will need something more specialised." Python *packaging* looks as if it is getting sorted out. Pip is going to be part of Python 3.4 and PyPI works very well. The instructions on the net for packaging things for a Python audience are extremely good. Sending python code to other python developers is extremely easy. But it is not easy to send code to non-python developers. The promise that you can just get your users to install a Python interpreter and then give them code to run on it is a worthy dream. Perhaps all the pieces to do this all seamlessly exist already, but if so they need much better documentation, somewhere that it is really easy to find it. IMHO, anyway. Nicholas -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 6 18:49:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 10:49:12 +1100 Subject: Python program distribution - a source of constant friction In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 10:39 AM, Nicholas Cole wrote: > But what about the end-user? The end-user who just wants a blob (he doesn't > care about what language it is in - he just wants to solve the problem at > hand with your shiny, cool, problem-solving application). This is where OS-provided package managers really shine. It should be possible to type: $ sudo apt-get install shiny-cool-problem-solver and have it go and fetch Python, the magical library you need (matching to the binary architecture of the target platform), and your code, plop them all into the right places in the file system, and give you a new command "shinycool" that just happens to shebang into Python. Well and good. Trouble is... Windows isn't up there. And trying to maintain packages for lots of different platforms is a lot of work. ChrisA From walterhurry at lavabit.com Mon Jan 6 18:58:30 2014 From: walterhurry at lavabit.com (Walter Hurry) Date: Mon, 6 Jan 2014 23:58:30 +0000 (UTC) Subject: python finance References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> < 56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> < 9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> < 4bef9196-be41-4f1e-a904-d098952053bf@googlegroups.com> Message-ID: On Mon, 06 Jan 2014 13:11:53 -0800, d ss wrote: i wrote just 2 words with a clear > indicative title: "Python, Finance" which summarizes the following "if > you are good in python and interested in applying your python knowledge > to the field of finance then we may have a common interest in talking > together" :D that s it! No, you didn't. The title wasn't capitalised. The advertisement was similarly poor English, the post was to the wrong mailing list and you posted usong G**gle G****s. Would any competent developer be interested? I think not. From rosuav at gmail.com Mon Jan 6 19:04:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 11:04:11 +1100 Subject: python finance In-Reply-To: <4bef9196-be41-4f1e-a904-d098952053bf@googlegroups.com> References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> <4bef9196-be41-4f1e-a904-d098952053bf@googlegroups.com> Message-ID: On Tue, Jan 7, 2014 at 8:11 AM, d ss wrote: > i wrote just 2 words with a clear indicative title: "Python, Finance" which summarizes the following "if you are good in python and interested in applying your python knowledge to the field of finance then we may have a common interest in talking together" :D Trouble is, you run into the same problem seen here: http://www.catb.org/~esr/writings/unix-koans/gui-programmer.html "Python finance" could also be interpreted in many other ways, including "I want to write a finance application in Python", and "How does the PSF get its money?". The other trouble that you're running into is Google Groups. I recommend you stop using it, because it makes a mess of your posts. ChrisA From nicholas.cole at gmail.com Mon Jan 6 19:09:52 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Tue, 7 Jan 2014 00:09:52 +0000 Subject: Python program distribution - a source of constant friction In-Reply-To: References: Message-ID: On Monday, 6 January 2014, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 10:39 AM, Nicholas Cole > > wrote: > > But what about the end-user? The end-user who just wants a blob (he > doesn't > > care about what language it is in - he just wants to solve the problem at > > hand with your shiny, cool, problem-solving application). > > This is where OS-provided package managers really shine. It should be > possible to type: > > $ sudo apt-get install shiny-cool-problem-solver > > and have it go and fetch Python, the magical library you need > (matching to the binary architecture of the target platform), and your > code, plop them all into the right places in the file system, and give > you a new command "shinycool" that just happens to shebang into > Python. Well and good. Trouble is... Windows isn't up there. And > trying to maintain packages for lots of different platforms is a lot > of work. > Even providing packages for (unfamiliar?) Linux distributions is a lot of work - unless a distribution picks up responsibility for an application. For sending applications to end users, something they can just copy straight into a bin/ directory is a real winner. The python zip file format is really good for many things, and from the end-user point of view extremely low friction. Even so, things like that are harder to create than they could be, or less prominently documented than one might have expected. Case in point: I have an application a friend/colleague of mine would like to look at. I've no idea if he is running Debian or Redhat or FreeBSD or a Mac. Assuming I've not used any C extensions, it is *possible* to create something that will run on all of the above without any fuss at his end. It just isn't nearly as easy as it could be, which must be a shame. Nicholas. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 6 19:19:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 11:19:20 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 6:26 AM, Mark Lawrence wrote: > http://blog.startifact.com/posts/python-2-gravity.html > > "A Way Forward - How to go forward then? I think it makes sense to work as > hard as possible to lift those Python 2 codebases out of the gravity well." > > I think this is complete nonsense. There's only been five years since the > first release of Python 3. Surely much more time should be made available > for people using Python 2 to plan for a migration? """And to make it even more obvious, we need Python 2.x releases where the deprecated stuff is removed, incrementally. Breaking code is making it as obvious as you can get! But you don't want to break it all at once, because then people will be inclined to give up before they even start.""" Suppose there's a Python 2.8 that breaks just some of the things that might break in 2.7->3.3 migration. What does it achieve? 1) Everything that has to be fixed before moving onto 3.3+ will still need to be fixed. 2) Instead of ONE code-breaking shift with a major version number to highlight it, there are now TWO code-breaking shifts. Can we get a run-down of everything that actually must be broken in 2.7 -> 3.3, that can't be backported via __future__, so we can start cherry-picking which bits to break in 2.8? The biggest one is going to be Unicode strings, for a large number of people (the print statement and division operators can be __future__'d, lots of other stuff got backported into 2.7). I'd be prepared to bet money that that one will NOT be broken in 2.8, meaning that it achieves nothing on that score. So how much easier will the migration actually be? ChrisA From jeanpierreda at gmail.com Mon Jan 6 19:27:04 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 6 Jan 2014 16:27:04 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 4:19 PM, Chris Angelico wrote: > Can we get a run-down of everything that actually must be broken in > 2.7 -> 3.3, that can't be backported via __future__, so we can start > cherry-picking which bits to break in 2.8? The biggest one is going to > be Unicode strings, for a large number of people (the print statement > and division operators can be __future__'d, lots of other stuff got > backported into 2.7). I'd be prepared to bet money that that one will > NOT be broken in 2.8, meaning that it achieves nothing on that score. > So how much easier will the migration actually be? Actually, this brings up something I'm unsure of. Is there any change that can't, in theory, be put into __future__, so that if every module in your project and its transitive dependencies imports everything from __future__, it can run on Python 3 without changes, and where it is realistically feasible to allow different modules to have different things they import from __future__? For example, I imagine that it is kind of _silly_ to have a __future__.disable_str_autoencoding on a per-module basis, because some modules' functions will fail when they are given the wrong type, and some won't -- but in the context of making migration easier, that silliness is probably OK. More fundamental is probably that it can't actually be done easily or without serious performance penalties (e.g. the relevant string method would have to look up the callstack to see if its direct caller came from a module which enabled that future feature). I'm not sure there's anything that can't in principle be sort-of-sanely encoded as a __future__ feature though. -- Devin From steve+comp.lang.python at pearwood.info Mon Jan 6 19:42:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 11:42:41 +1100 Subject: "More About Unicode in Python 2 and 3" References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52cb4d82$0$29979$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > On 01/06/2014 09:27 AM, Steven D'Aprano wrote: >> Ethan Furman wrote: >> >> Chris didn't say "bytes and ascii data", he said "bytes and TEXT". >> Text != "ascii data", and the fact that some people apparently think it >> does is pretty much the heart of the problem. > > The heart of a different problem, not this one. The problem I refer to is > that many binary formats have well-defined > ascii-encoded text tidbits. These tidbits were quite easy to work with in > Py2, not difficult but not elegant in Py3, and even worse if you have to > support both 2 and 3. Many things are more difficult if you have to support a large range of versions. That's life, for a programmer. >> Now, it is true that some of those bytes happen to fall into the same >> range of values as ASCII-encoded text. They may even represent text after >> decoding, but since we don't know what the file contents mean, we can't >> know that. > > Of course we can -- we're the programmer, after all. This is not a random > bunch of bytes but a well defined format for storing data. No, you misunderstand me. *You* may know what the data represents, but *we* don't, because you just drop a hex dump in our laps with no explanation. >> It might be a mere coincidence that the four bytes starting at >> hex offset 40 is the C long 1095189760 which happens to look like "AGE" >> with a null at the end. For historical reasons, your hexdump utility >> performs that decoding step for you, which is why you can see "NAME" >> and "AGE" in the right-hand block, but that doesn't mean the file >> contains text. It contains bytes, some of which represents text after >> decoding. > > As it happens, 'NAME' and 'AGE' are encoded, and will be decoded. You're either saying something utterly trivial, or something utterly profound, and I can't tell which. Of course they are encoded. The file doesn't contain the letter "N", it contains the byte 0x4E. So what are you actually trying to say? > They could just as easily have contained tilde's, > accents, umlauts, and other strange (to me) characters. I'm especially confused here because tildes are including in the ASCII character set. Here's one here: ~ > It's actually the > 'C' and the 'N' that bug me (like I said, my example is minimal, > especially compared to a network protocol). > > And you're right -- it is easy to say FIELD_TYPE = slice(15,16), and it > was also easy to say FIELD_TYPE = 15, but there is a critical difference > -- can you spot it? > > .. > .. > .. > In case you didn't: both work in Py2, only the slice version works > (correctly) in Py3, I accept that using the slice is inelegant. But lots of things are inelegant when you do them them wrong way. Treating your textual data as bytes is the wrong way. You apparently know that that your data is encoded text, you apparently know the encoding... so why don't you just decode it and treat it as text instead of insisting on dealing with the raw bytes? Are you worried about performance? I'd be sympathetic if you were writing some low-level network protocol stuff where performance is vital, but you keep saying that your application is "minimal", which I interpret as performance not being critical. So what's the deal? > but the worst part is why do I > have to use a slice to take a single byte when a simple index should work? I don't understand the rationale for having byte indexing return an int instead of a one-byte substring. Especially since we still have a perfectly good way to extract the numeric value from a one-byte byte-string: py> ord(b'N') 78 > Because the bytes type lies. It shows, for example, b'\r\n\x12\x08N\x00' > but when I try to access that N to see if this is a Numeric field I get: > > --> b'\r\n\x12\x08N\x00'[4] > 78 > > This is a cognitive dissonance that one does not expect in Python. Yes, I agree. I think it was a terrible mistake to have bytes continue to pretend to be ASCII. Having this occur: py> print(b'\x4E') b'N' does nothing but muddy the water. I think it would be too much to disallowing using ASCII literals in byte strings, but we shouldn't *display* byte strings as ASCII. py> print(b'N') # This would be better. b'\x4E' [...] > Different problem. The problem here is that bytes and byte literals don't > compare equal. Right! Now I get where you are coming from. -- Steven From cmpython at gmail.com Mon Jan 6 19:42:49 2014 From: cmpython at gmail.com (CM) Date: Mon, 6 Jan 2014 16:42:49 -0800 (PST) Subject: Which python framework? In-Reply-To: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> References: <2e5c9033-1bb5-46e4-93e6-046069923297@googlegroups.com> Message-ID: <0fbd425b-ec62-485a-99ab-1403aac75644@googlegroups.com> On Monday, January 6, 2014 12:02:31 PM UTC-5, blis... at gmail.com wrote: > I love programming in python but I'm having trouble deciding over a framework for a single player MUD like game I'm making for fun. Ideally it's a cross-platform free framework in case I want make it open source later with good capabilities of customizing the GUI look/style. > > > > Currently I'm using wxpython which is great but I'm reading that if I want more customization over the look (i.e. a frame being all black and not using windows 7 blue borders) You can turn off some of the frame style flags and make the frame look a number of different ways, though the point in a frame in wxPython is *native*, and so will be limited in look to what the OS natively draws. (So, in a sense, don't blame wxPython, blame Windows, OS X, or Linux, if you want). You'd have to describe what you mean by "all black" more (I mean, do you want a top border at all? Do you want a gripper? Full screen? Etc), but I suggest you ask on the wxPython list and they can tell you best what is and what is not possible. My guess is that whatever you have in mind that is beyond wxPython's capabilities is going to fall into YAGNI territory (user-experience-wise) anyway. > Keep in mind this is only a text based game so 3D is not needed. Perhaps I > have to forgo my love of python for something else? I highly doubt that. I'm sure whatever you want to do is doable with Python. From cmpython at gmail.com Mon Jan 6 19:48:54 2014 From: cmpython at gmail.com (CM) Date: Mon, 6 Jan 2014 16:48:54 -0800 (PST) Subject: django question In-Reply-To: References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: On Sunday, January 5, 2014 4:50:55 PM UTC-5, Roy Smith wrote: > One of the things we try to do is put as little in the views as > possible. Views should be all about accepting and validating request > parameters, and generating output (be that HTML via templates, or JSON, > or whatever). All the business logic should be kept isolated from the > views. The better (and more disciplined) you are about doing this, the > easier it will be to move your business logic to a different framework. I just started playing with Django and hadn't realized that yet. So, what, you have other modules that you import into Views that you call functions from to do the business logic? Do you just keep a modules folder in the Django project folder I guess? Thanks for the tip(s). > > > That's not to say it will be *easy*, but you can certainly make things > > harder on yourself than they need to be if you don't keep things > > distinct. > > > > Oh, and yes, the django team does a really amazing job on the docs. From rhodri at wildebst.org.uk Mon Jan 6 19:48:57 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Tue, 07 Jan 2014 00:48:57 -0000 Subject: Postfix conditionals References: Message-ID: On Mon, 06 Jan 2014 07:51:28 -0000, G?ktu? Kayaalp wrote: > Thanks for the input! I'd be quite interested in examples which required > you to "mentally transpose the conditional back to the start of the > statement", by the way. Sorry, it's been too long and I don't have any relevant Perl around any more. I think it had to do with losing the visual cue of indentation, and just having to think that little bit harder to notice that I wasn't dealing with purely linear code. -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Mon Jan 6 19:54:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 11:54:03 +1100 Subject: "More About Unicode in Python 2 and 3" References: <52C9FD02.3080109@stoneleaf.us> <52cae78d$0$29971$c3e8da3$5496439d@news.astraweb.com> <52CAF722.6010301@stoneleaf.us> Message-ID: <52cb502d$0$30002$c3e8da3$5496439d@news.astraweb.com> Mark Janssen wrote: >> Looks like another bad batch, time to change your dealer again. > > ??? Strange, when the debate hits bottom, accusations about doing > drugs come up. This is like the third reference (and I don't even > drink alcohol). It is an oblique reference to the fact that your posts are incoherent and confused. It is considered more socially polite to attribute that to external substances such as drugs or alcohol (which you could, in principle, do something about) than to explicitly say that you and your views are disconnected from reality, i.e. crazy. People aren't actually debating you. We've tried. You respond with insults and don't give any evidence for your irrational assertions, so don't think that this is a debate. Until you can (1) explain your thoughts in detail rather than in vague terms that don't make sense, (2) demonstrate at least a minimal level of competence rather than making utter n00b mistakes while insisting that you know so much more than experts in the field, and (3) give actual evidence for your assertions, this will not be a debate. -- Steven From skip.montanaro at gmail.com Mon Jan 6 19:56:00 2014 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Mon, 6 Jan 2014 18:56:00 -0600 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: References: Message-ID: I've been programming for a long while in an event&callback-driven world. While I am comfortable enough with the mechanisms available (almost 100% of what I do is in a PyGTK world with its signal mechanism), it's never been all that satisfying, breaking up my calculations into various pieces, and thus having my algorithm scattered all over the place. So, I'm looking for a little guidance. It seems to me that futures, coroutines, and/or the new Tulip/asyncio package might be my salvation, but I'm having a bit of trouble seeing exactly how that would work. Let me outline a simple hypothetical calculation. I'm looking for ways in which these new facilities might improve the structure of my code. Let's say I have a dead simple GUI with two buttons labeled, "Do A" and "Do B". Each corresponds to executing a particular activity, A or B, which take some non-zero amount of time to complete (as perceived by the user) or cancel (as perceived by the state of the running system - not safe to run A until B is complete/canceled, and vice versa). The user, being the fickle sort that he is, might change his mind while A is running, and decide to execute B instead. (The roles can also be reversed.) If s/he wants to run task A, task B must be canceled or allowed to complete before A can be started. Logically, the code looks something like (I fear Gmail is going to destroy my indentation): def do_A(): when B is complete, _do_A() cancel_B() def do_B(): when A is complete, _do_B() cancel_A() def _do_A(): do the real A work here, we are guaranteed B is no longer running def _do_B(): do the real B work here, we are guaranteed A is no longer running cancel_A and cancel_B might be no-ops, in which case they need to start up the other calculation immediately, if one is pending. This is pretty simple execution, and if my job was this simple, I'd probably just keep doing things the way I do now, which is basically to catch a "complete" or "canceled" signal from the A and B tasks and execute the opposite task if it's pending. But it's not this simple. In reality there are lots of, "oh, you want to do X? You need to make sure A, B, and C are not active." And other stuff like that. I have this notion that I should be able to write do_A() something like this: def do_A(): cancel_B() yield from ... ??? _do_A() ... or def do_A(): future = cancel_B() future.on_completion(_do_A) ... or ??? with the obvious similar structure for do_B. To my mind's eye, the first option is preferable, since it's obvious that when control reaches the line after the yield from statement, it's fine to do the guts of task A. So, is my simpleminded view of the world a possibility with the current facilities available in 3.3 or 3.4? Thx, Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Mon Jan 6 20:00:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 12:00:40 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 11:27 AM, Devin Jeanpierre wrote: > For example, I imagine that it is kind of _silly_ to have a > __future__.disable_str_autoencoding on a per-module basis, because > some modules' functions will fail when they are given the wrong type, > and some won't -- but in the context of making migration easier, that > silliness is probably OK. At what point does the auto-encoding happen, though? If a function calls another function calls another function, at what point do you decide that this ought to have become a str? I suspect there'll be quite a few problems that can't be solved per-module. The division change is easy, because it just changes the way code gets compiled (there's still "integer division" and "float division", it's just that / gets compiled into the latter instead of the former). With print_function I can imagine there might be some interactions that are affected, but nothing too major. Deploying new-style classes exclusively could be minorly problematic, but it'd probably work (effectively, a future directive stipulates that everything in this module inherits from object - technically should work, but might cause code readability confusion). But there are much subtler issues. Compare this code in Python 2 and Python 3: def f1(): return {1:2, 11:22, 111:222} def f2(d): return d.keys() def f3(k): return k.pop() process_me = f2(f1()) try: while True: current = f3(process_me) # .... except IndexError: pass Obviously this works in Python 2, and fails in Python 3 (because keys() returns a view). Now imagine these are four separate modules. Somewhere along the way, something needs to pass the view through list() to make it poppable. Or, putting it the other way, somewhere there needs to be an alert saying that this won't work in Py3. Whose responsibility is it? * Is it f1's responsibility to create a different sort of dict that has a keys() method that returns a view? * Is it f2's responsibility to notice that it's calling keys() on a dictionary, and that it should warn that this will change (or switch to compatibility mode, or raise error, or whatever)? This is where the error actually is. * Is it f3's responsibility? This one I'm pretty sure is not so. * Is it the main routine's job to turn process_me into a list? I don't think so. There's nothing in that code that indicates that it's using either a dictionary or a list. I'd put the job either on f1 or on f2. A __future__ directive could change the interpretation of the { } literal syntax and have it return a dictionary with a keys view, but the fix would be better done in f2 - where it's not obvious that it's using a dictionary at all. I'm not sure that a future directive can really solve this one. Maybe a command-line argument could, but that doesn't help with the gradual migration of individual modules. ChrisA From rosuav at gmail.com Mon Jan 6 20:05:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 12:05:10 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52cadd49$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 7, 2014 at 11:23 AM, Dennis Lee Bieber wrote: >>Uhh, I think you're the only one here who has that nightmare, like >>Chris Knight with his sun-god robes and naked women throwing pickles >>at him. >> > > Will somebody please wash out my brain... "Pickles straight from the > jar, or somewhat 'used'?" I was making a reference to the movie "Real Genius", which involves lasers, popcorn, and geeks. And it's been explored by Mythbusters. If you haven't seen it, do! ChrisA From rhodri at wildebst.org.uk Mon Jan 6 20:26:17 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Tue, 07 Jan 2014 01:26:17 -0000 Subject: "More About Unicode in Python 2 and 3" References: <201401060932.35410.gheskett@wdtv.com> Message-ID: On Mon, 06 Jan 2014 21:17:06 -0000, Gene Heskett wrote: > On Monday 06 January 2014 16:16:13 Terry Reedy did opine: > >> On 1/6/2014 9:32 AM, Gene Heskett wrote: >> > And from my lurking here, its quite plain to me that 3.x python has a >> > problem with everyday dealing with strings. >> >> Strings of what? And what specific 'everyday' problem are you referring >> to? > > Strings start a new thread here at nominally weekly intervals. Seems to > me that might be usable info. I haven't actually checked subject lines, but I'm pretty sure GUIs raise more questions than that by some considerable margin. -- Rhodri James *-* Wildebeest Herder to the Masses From rosuav at gmail.com Mon Jan 6 20:35:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 12:35:54 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> Message-ID: On Tue, Jan 7, 2014 at 12:26 PM, Rhodri James wrote: > On Mon, 06 Jan 2014 21:17:06 -0000, Gene Heskett wrote: > >> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: >> >>> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>> > And from my lurking here, its quite plain to me that 3.x python has a >>> > problem with everyday dealing with strings. >>> >>> Strings of what? And what specific 'everyday' problem are you referring >>> to? >> >> >> Strings start a new thread here at nominally weekly intervals. Seems to >> me that might be usable info. > > > I haven't actually checked subject lines, but I'm pretty sure GUIs raise > more questions than that by some considerable margin. About the difference between Py2 and Py3? Most of the GUI toolkits work fine on both. ChrisA From jeanpierreda at gmail.com Mon Jan 6 20:55:01 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 6 Jan 2014 17:55:01 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 5:00 PM, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 11:27 AM, Devin Jeanpierre > wrote: >> For example, I imagine that it is kind of _silly_ to have a >> __future__.disable_str_autoencoding on a per-module basis, because >> some modules' functions will fail when they are given the wrong type, >> and some won't -- but in the context of making migration easier, that >> silliness is probably OK. > > At what point does the auto-encoding happen, though? If a function > calls another function calls another function, at what point do you > decide that this ought to have become a str? Python has a defined place where it happens. For example the __add__ method of str objects can do it. As you note below for dicts, the place where you change behavior can change, though. e.g. maybe all str objects created in a module cannot be coerced anywhere else, or maybe it's coercions that happen inside a module that are disabled. The former is more efficient, but it has effects that creep out transitively in the most difficult way possible. The latter is essentially just an API change (rather than type change), and so easy enough, but it's prohibitively expensive, in a way that makes all code everywhere in Python slower. In the end, we can still choose one of those, and in principle the __future__ feature would work, even if it's not the best. (In fact, if you want, you could even do both.) > I suspect there'll be quite a few problems that can't be solved > per-module. The division change is easy, because it just changes the > way code gets compiled (there's still "integer division" and "float > division", it's just that / gets compiled into the latter instead of > the former). With print_function I can imagine there might be some > interactions that are affected, but nothing too major. Deploying > new-style classes exclusively could be minorly problematic, but it'd > probably work (effectively, a future directive stipulates that > everything in this module inherits from object - technically should > work, but might cause code readability confusion). But there are much > subtler issues. Compare this code in Python 2 and Python 3: > > def f1(): > return {1:2, 11:22, 111:222} > > def f2(d): > return d.keys() > > def f3(k): > return k.pop() > > process_me = f2(f1()) > try: > while True: > current = f3(process_me) > # .... > except IndexError: > pass > > Obviously this works in Python 2, and fails in Python 3 (because > keys() returns a view). Now imagine these are four separate modules. > Somewhere along the way, something needs to pass the view through > list() to make it poppable. Or, putting it the other way, somewhere > there needs to be an alert saying that this won't work in Py3. Whose > responsibility is it? > > * Is it f1's responsibility to create a different sort of dict that > has a keys() method that returns a view? > * Is it f2's responsibility to notice that it's calling keys() on a > dictionary, and that it should warn that this will change (or switch > to compatibility mode, or raise error, or whatever)? This is where the > error actually is. > * Is it f3's responsibility? This one I'm pretty sure is not so. > * Is it the main routine's job to turn process_me into a list? I don't > think so. There's nothing in that code that indicates that it's using > either a dictionary or a list. > > I'd put the job either on f1 or on f2. A __future__ directive could > change the interpretation of the { } literal syntax and have it return > a dictionary with a keys view, but the fix would be better done in f2 > - where it's not obvious that it's using a dictionary at all. > > I'm not sure that a future directive can really solve this one. Maybe > a command-line argument could, but that doesn't help with the gradual > migration of individual modules. What if we decide there is no single source of responsibility, and it can't be limited exactly to a module, and make a __future__ feature the best we can regardless? We can still exact some benefit from a "sloppy" __future__ feature: we can still move code piecemeal. If whatever __future__ feature there is, when enabled on the module with f2 (or, in another case, f1), causes an error in f3, that's a little misleading in that the error is in the wrong place, but it doesn't fundamentally mean we can't move the codebase piecemeal. It means that the change we make to the file for f2 (or f1) might require some additional changes elsewhere or internally due to outside-facing changes in semantics. It makes the required changes larger than in the case of division, like you say, but it's still potentially smaller and simpler than in the case of an atomic migration to Python 3. -- Devin From roy at panix.com Mon Jan 6 20:57:22 2014 From: roy at panix.com (Roy Smith) Date: Mon, 06 Jan 2014 20:57:22 -0500 Subject: django question References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: In article , CM wrote: > On Sunday, January 5, 2014 4:50:55 PM UTC-5, Roy Smith wrote: > > > One of the things we try to do is put as little in the views as > > possible. Views should be all about accepting and validating request > > parameters, and generating output (be that HTML via templates, or JSON, > > or whatever). All the business logic should be kept isolated from the > > views. The better (and more disciplined) you are about doing this, the > > easier it will be to move your business logic to a different framework. > > I just started playing with Django and hadn't realized that yet. So, > what, you have other modules that you import into Views that you call > functions from to do the business logic? Yes, exactly. There's nothing magic about a django view. It's just a function which is passed an instance of HttpRequest (and possibly a few other things, depending on your url mapping), and which is expected to return an instance of HttpResponse. Within that framework, it can call any other functions it wants. For example, http://legalipsum.com/ is a silly little site I built in django. Here's the view for the home page: from markov import markov files = markov.corpus_files() chainer = markov.from_files(files) @require_GET def home(request): count = request.GET.get('count', 0) try: count = int(count) except ValueError: count = 0 paragraphs = [chainer.paragraph(3, 3) for i in range(count)] ctx = { 'paragraphs': paragraphs, 'selected': str(count), 'pagename': 'home', } return render(request, 'legal_ipsum/home.html', ctx) Notice how the view knows nothing about generating the actual markov text. That's in another module, which lives somewhere on my PYTHONPATH. ALso, the view knows nothing about how the page is laid out; only the templates know that. If I decided to redo this in tornado or flask, whatever, I would need to rewrite my view, but there's not much to rewrite. Most of the logic is in the Markov chainer, and that would cary over to the new implementation unchanged. BTW, my suggestion to keep business logic and presentation code distinct isn't unique to django, it's a good idea in pretty much all systems. From rosuav at gmail.com Mon Jan 6 21:00:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 13:00:59 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 12:55 PM, Devin Jeanpierre wrote: > What if we decide there is no single source of responsibility, and it > can't be limited exactly to a module, and make a __future__ feature > the best we can regardless? We can still exact some benefit from a > "sloppy" __future__ feature: we can still move code piecemeal. I worry that it's starting to get into the realm of magic, though. Maybe dict.keys() isn't the best example (you can easily make your code 2+3 compat by just calling list() on it immediately, which is effectively "from __past__ import absence_of_views"), but the issue is the same with string autoencodings. It's really hard to define that the + operator will do magic differently based on a future directive, and changing the object ("this string will not autoencode") means you're not tweaking things per-module, and behaviour will change and/or break based on where some object was created, rather than the settings on the module with the code in it. ChrisA From tjreedy at udel.edu Mon Jan 6 21:07:03 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 21:07:03 -0500 Subject: Python 3 Q & A (Nick C.) updated Message-ID: As a counterpoint to 2 versus 3: http://python-notes.curiousefficiency.org/en/latest/python3/questions_and_answers.html by Nick Coughlan, one of Python's major core developers. A couple of points related to the other threads. 1. There were real social and technical reasons for the non-2.8 pep (404). 2. Python 3 is a work in progress with respect to the new text model. In particular wire protocol programming is a known problem area and will get attention. But it is only a small part of the total Python universe. -- Terry Jan Reedy From jeanpierreda at gmail.com Mon Jan 6 21:15:18 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 6 Jan 2014 18:15:18 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 6:00 PM, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 12:55 PM, Devin Jeanpierre > wrote: >> What if we decide there is no single source of responsibility, and it >> can't be limited exactly to a module, and make a __future__ feature >> the best we can regardless? We can still exact some benefit from a >> "sloppy" __future__ feature: we can still move code piecemeal. > > I worry that it's starting to get into the realm of magic, though. > Maybe dict.keys() isn't the best example (you can easily make your > code 2+3 compat by just calling list() on it immediately, which is > effectively "from __past__ import absence_of_views"), but the issue is > the same with string autoencodings. It's really hard to define that > the + operator will do magic differently based on a future directive, > and changing the object ("this string will not autoencode") means > you're not tweaking things per-module, and behaviour will change > and/or break based on where some object was created, rather than the > settings on the module with the code in it. Well, what's "magic"? There are two ideas that I know roughly how to implement, and that maybe would make the world better. Behaviour that changes or breaks based on what module some object was created in sounds pretty bad, but I don't think it's so bad that it's not a tolerable solution. The error messages can be made obvious, and it would still allow a gradual migration. Allowing the exception to be toned down to a warning might help with the gradual move without breaking code unpredictably. It's bad, but if there were no better alternative, I would be OK with it. (i.e. I think it's better than nothing.) The other alternative is having + (etc.) do something different depending on what module it's in. It's not hard to do: add a condition to all places where Python automatically converts, and check the call stack to see what module you're in. I mostly retract my worries about performance, I for some reason was thinking you'd do it on all operations, but it only has to be checked if the string is about to be automatically encoded or decoded, (and that's already slow). It still has the effect that your API is different and you raise exceptions when you didn't before, which usually affects your callers more than it affects you, but I feel like it propagates outside of the module more "nicely". It's "magic" in that looking at the call stack is "magic", but that's the kind of magic that you can even do without touching the interpreter, using functions from sys. I don't think the definition of when exactly automatic encoding/decoding occurs is magical. It's already a part of Python behaviour, changing it isn't outrageous. -- Devin From rhodri at wildebst.org.uk Mon Jan 6 21:15:30 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Tue, 07 Jan 2014 02:15:30 -0000 Subject: "More About Unicode in Python 2 and 3" References: <201401060932.35410.gheskett@wdtv.com> Message-ID: On Tue, 07 Jan 2014 01:35:54 -0000, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 12:26 PM, Rhodri James > wrote: >> On Mon, 06 Jan 2014 21:17:06 -0000, Gene Heskett >> wrote: >> >>> On Monday 06 January 2014 16:16:13 Terry Reedy did opine: >>> >>>> On 1/6/2014 9:32 AM, Gene Heskett wrote: >>>> > And from my lurking here, its quite plain to me that 3.x python has >>>> a >>>> > problem with everyday dealing with strings. >>>> >>>> Strings of what? And what specific 'everyday' problem are you >>>> referring >>>> to? >>> >>> >>> Strings start a new thread here at nominally weekly intervals. Seems >>> to >>> me that might be usable info. >> >> >> I haven't actually checked subject lines, but I'm pretty sure GUIs raise >> more questions than that by some considerable margin. > > About the difference between Py2 and Py3? Most of the GUI toolkits > work fine on both. Sorry, I assumed we were talking about threads in general. Py2 vs Py3 threads that aren't interminable trolling don't show up often enough to register for me; the current set is something of an exception. -- Rhodri James *-* Wildebeest Herder to the Masses From python at mrabarnett.plus.com Mon Jan 6 21:22:22 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Jan 2014 02:22:22 +0000 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: References: Message-ID: <52CB64DE.10608@mrabarnett.plus.com> On 2014-01-07 00:56, Skip Montanaro wrote: > I've been programming for a long while in an event&callback-driven > world. While I am comfortable enough with the mechanisms available > (almost 100% of what I do is in a PyGTK world with its signal > mechanism), it's never been all that satisfying, breaking up my > calculations into various pieces, and thus having my algorithm scattered > all over the place. > > So, I'm looking for a little guidance. It seems to me that futures, > coroutines, and/or the new Tulip/asyncio package might be my salvation, > but I'm having a bit of trouble seeing exactly how that would work. Let > me outline a simple hypothetical calculation. I'm looking for ways in > which these new facilities might improve the structure of my code. > > Let's say I have a dead simple GUI with two buttons labeled, "Do A" and > "Do B". Each corresponds to executing a particular activity, A or B, > which take some non-zero amount of time to complete (as perceived by the > user) or cancel (as perceived by the state of the running system - not > safe to run A until B is complete/canceled, and vice versa). The user, > being the fickle sort that he is, might change his mind while A is > running, and decide to execute B instead. (The roles can also be > reversed.) If s/he wants to run task A, task B must be canceled or > allowed to complete before A can be started. Logically, the code looks > something like (I fear Gmail is going to destroy my indentation): > > def do_A(): > when B is complete, _do_A() > cancel_B() > > def do_B(): > when A is complete, _do_B() > cancel_A() > > def _do_A(): > do the real A work here, we are guaranteed B is no longer running > > def _do_B(): > do the real B work here, we are guaranteed A is no longer running > > cancel_A and cancel_B might be no-ops, in which case they need to start > up the other calculation immediately, if one is pending. > > This is pretty simple execution, and if my job was this simple, I'd > probably just keep doing things the way I do now, which is basically to > catch a "complete" or "canceled" signal from the A and B tasks and > execute the opposite task if it's pending. But it's not this simple. In > reality there are lots of, "oh, you want to do X? You need to make sure > A, B, and C are not active." And other stuff like that. > [snip] Do you really need to use futures, etc? What you could do is keep track of which tasks are active. When the user clicks a button to start a task, the task checks whether it can run. If it can run, it starts the real work. On the other hand, if it can't run, it's set as the pending task. When a task completes or is cancelled, if there is a pending task, that task is unset as the pending task and retried; it'll then either start the real work or be set as the pending task again. From tjreedy at udel.edu Mon Jan 6 21:23:24 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 21:23:24 -0500 Subject: Pragmatic Unicode (was Re: "More About Unicode in Python 2 and 3") In-Reply-To: References: Message-ID: On 1/6/2014 5:25 PM, Ned Batchelder wrote: > I do respect you, and all the core developers. As I've said elsewhere > in the thread, I greatly appreciate everything you do. I dedicate a > great deal of time and energy to the Python community, primarily because > of the amazing product that you have all built. Let me add a quote from Nick's essay (see other new thread). '''Ned Batchelder?s wonderful Pragmatic Unicode talk/essay could just as well be titled ?This is why Python 3 exists?.''' http://nedbatchelder.com/text/unipain.html I do not know if Nick's re-titling expression your intent or not, but it expresses my feeling also. Part of what makes the presentation great is the humor, which we need more of. I recommend it to anyone who has not seen it. -- Terry Jan Reedy From rosuav at gmail.com Mon Jan 6 21:28:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 13:28:39 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 1:15 PM, Devin Jeanpierre wrote: > The other alternative is having + (etc.) do something different > depending on what module it's in. It's not hard to do: add a condition > to all places where Python automatically converts, and check the call > stack to see what module you're in. Currently, there are __add__ methods (and __radd__ but let's focus on __add__) on a bunch of objects, which determine what happens when you use the + operator. class Foo(str): def __add__(self, other): if isinstance(other, unicode): return self + other.encode("cp500") return str.__add__(self, other) What happens if you have the __future__ directive disabling autoencoding on (a) the module in which this class is defined, (b) the one in which the it was instantiated, (c) the one that actually uses the +? This is why I think it's getting magical. Far better to do this sort of change on a per-application basis - maybe with a warning parameter that you can enable when running your test suite, as has been suggested (and in many cases implemented) for other 2-vs-3 problems. ChrisA From rosuav at gmail.com Mon Jan 6 21:29:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 13:29:59 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> Message-ID: On Tue, Jan 7, 2014 at 1:15 PM, Rhodri James wrote: > Sorry, I assumed we were talking about threads in general. Py2 vs Py3 > threads that aren't interminable trolling don't show up often enough to > register for me; the current set is something of an exception. Sure. In that case, I would agree that yes, GUI coding is at least comparable to Unicode in terms of number of threads. I don't have figures, but it wouldn't surprise me to learn that either exceeds the other. ChrisA From cs at zip.com.au Mon Jan 6 21:29:58 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 7 Jan 2014 13:29:58 +1100 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: References: Message-ID: <20140107022958.GA59457@cskk.homeip.net> On 06Jan2014 18:56, Skip Montanaro wrote: [...] > Let's say I have a dead simple GUI with two buttons labeled, "Do A" and "Do > B". Each corresponds to executing a particular activity, A or B, which take > some non-zero amount of time to complete (as perceived by the user) or > cancel (as perceived by the state of the running system - not safe to run A > until B is complete/canceled, and vice versa). The user, being the fickle > sort that he is, might change his mind while A is running, and decide to > execute B instead. (The roles can also be reversed.) If s/he wants to run > task A, task B must be canceled or allowed to complete before A can be > started. I take it we can ignore user's hammering on buttons faster than jobs can run or be cancelled? > Logically, the code looks something like (I fear Gmail is going to > destroy my indentation): > > def do_A(): > when B is complete, _do_A() > cancel_B() [...] > def _do_A(): > do the real A work here, we are guaranteed B is no longer running [...] > cancel_A and cancel_B might be no-ops, in which case they need to start up > the other calculation immediately, if one is pending. I wouldn't have cancel_A do this, I'd have do_A do this more overtly. > This is pretty simple execution, and if my job was this simple, I'd > probably just keep doing things the way I do now, which is basically to > catch a "complete" or "canceled" signal from the A and B tasks and execute > the opposite task if it's pending. But it's not this simple. In reality > there are lots of, "oh, you want to do X? You need to make sure A, B, and C > are not active." And other stuff like that. What's wrong with variations on: from threading import Lock lock_A = Lock() lock_B = Lock() def do_A(): with lock_B(): with lock_A(): _do_A() def do_B(): with lock_A(): with lock_B(): _do_B() You can extend this with multiple locks for A,B,C provided you take the excluding locks before taking the inner lock for the core task. Regarding cancellation, I presume your code polls some cancellation flag regularly during the task? Cheers, -- Cameron Simpson Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal. - Friedrich Nietzsche From tjreedy at udel.edu Mon Jan 6 21:42:34 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 06 Jan 2014 21:42:34 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CB3403.3000903@udel.edu> Message-ID: On 1/6/2014 6:24 PM, Chris Angelico wrote: > On Tue, Jan 7, 2014 at 10:06 AM, Antoine Pitrou wrote: >> Terry Reedy udel.edu> writes: >>> >>> On 1/6/2014 11:29 AM, Antoine Pitrou wrote: >>> >>>> People don't use? According to available figures, there are more >> downloads of >>>> Python 3 than downloads of Python 2 (Windows installers, mostly): >>>> http://www.python.org/webstats/ >>> >>> While I would like the claim to be true, I do not see 2 versus 3 >>> downloads on that page. Did you mean another link? >> >> Just click on a recent month, scroll down to the "Total URLs By kB" >> table, and compute the sum of the largest numbers for each Python >> version. > > Here's what I see there (expanding on what I said in the other post, > which was based on one table further up, URLs by hit count) for > December: > > 3.3.3: 1214571 > - amd64 627672 > - win32 586899 > 2.7.6: 1049096 > - win32 607972 > - amd64 441124 Earlier today, I was guessing 1000000 Python programmers. I do not know how downloads translates to programmers, but I may have been a bit low. > The next highest number is 167K downloads, so I'm going to ignore > their figures as they won't make more than 15% difference in these > stats. This is 2263667 total downloads of the current versions of > Python, 46% 2.7.6 and 54% 3.3.3. That's not incredibly significant > statistically, but certainly it disproves the notion that 3.x isn't > used at all. Last February: 1 553203 0.82% /ftp/python/3.3.0/python-3.3.0.msi 2 498926 0.74% /ftp/python/2.7.3/python-2.7.3.msi 3 336601 0.50% /ftp/python/3.3.0/python-3.3.0.amd64.msi 4 241796 0.36% /ftp/python/2.7.3/python-2.7.3.amd64.msi What has really increased are the amd64 numbers. I am pleased to see that the bug-fix releases get downloaded so heavily. -- Terry Jan Reedy From cs at zip.com.au Mon Jan 6 21:45:21 2014 From: cs at zip.com.au (Cameron Simpson) Date: Tue, 7 Jan 2014 13:45:21 +1100 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: <20140107022958.GA59457@cskk.homeip.net> References: <20140107022958.GA59457@cskk.homeip.net> Message-ID: <20140107024521.GA75679@cskk.homeip.net> On 07Jan2014 13:29, I wrote: > def do_A(): > with lock_B(): > with lock_A(): > _do_A() Um, of course there would be a cancel_B() up front above, like this: def do_A(): cancel_B() with lock_B(): with lock_A(): _do_A() I'm with MRAB: you don't really need futures unless you looking to move to a multithreaded appraoch and aren't multithreaded already. Even then, you don't need futures, just track running threads and what's meant to run next. You can do all your blocking with Locks fairly easily unless there are complexities not yet revealed. (Of course, this is a truism, but I mean "conveniently".) Cheers, -- Cameron Simpson Follow! But! Follow only if ye be men of valor, for the entrance to this cave is guarded by a creature so foul, so cruel that no man yet has fought with it and lived! Bones of four fifty men lie strewn about its lair. So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty big pointy teeth. - Tim The Enchanter From jeanpierreda at gmail.com Mon Jan 6 22:12:05 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 6 Jan 2014 19:12:05 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Mon, Jan 6, 2014 at 6:28 PM, Chris Angelico wrote: > class Foo(str): > def __add__(self, other): > if isinstance(other, unicode): return self + other.encode("cp500") > return str.__add__(self, other) > > What happens if you have the __future__ directive disabling > autoencoding on (a) the module in which this class is defined, (b) the > one in which the it was instantiated, (c) the one that actually uses > the +? In both methods I described, all uses of instances of the class are changed, but only in case A. That's a really good point, I hadn't considered that the second case could be converted into the first. > This is why I think it's getting magical. Yes, it's magical, but to be fair that's stack inspection as it always is. I am OK with a little ugliness if it makes actual work easier. > Far better to do this sort > of change on a per-application basis - maybe with a warning parameter > that you can enable when running your test suite, as has been > suggested (and in many cases implemented) for other 2-vs-3 problems. Doing a flag like that that enables a backwards incompatible change does in fact address that issue you were worried about originally, so that's something. And feature-by-feature moves are, like the OP said, still lower cost than a wholesale move. In the end a gradual transition can still be done with the polyglot approach, but I'm not happy that there's no way to enforce/test a polyglot conversion until it is complete. Any kind of granularity would have helped. :( -- Devin From skip at pobox.com Mon Jan 6 22:15:56 2014 From: skip at pobox.com (Skip Montanaro) Date: Mon, 6 Jan 2014 21:15:56 -0600 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: <20140107024521.GA75679@cskk.homeip.net> References: <20140107022958.GA59457@cskk.homeip.net> <20140107024521.GA75679@cskk.homeip.net> Message-ID: >From the couple responses I've seen, I must have not made myself clear. Let's skip specific hypothetical tasks. Using coroutines, futures, or other programming paradigms that have been introduced in recent versions of Python 3.x, can traditionally event-driven code be written in a more linear manner so that the overall algorithms implemented in the code are easier to follow? My code is not multi-threaded, so using threads and locking is not really part of the picture. In fact, I'm thinking about this now precisely because the first sentence of the asyncio documentation mentions single-threaded concurrent code: "This module provides infrastructure for writing single-threaded concurrent code using coroutines, multiplexing I/O access over sockets and other resources, running network clients and servers, and other related primitives." I'm trying to understand if it's possible to use coroutines or objects like asyncio.Future to write more readable code, that today would be implemented using callbacks, GTK signals, etc. S From python at mrabarnett.plus.com Mon Jan 6 22:23:32 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Jan 2014 03:23:32 +0000 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: <20140107022958.GA59457@cskk.homeip.net> References: <20140107022958.GA59457@cskk.homeip.net> Message-ID: <52CB7334.60005@mrabarnett.plus.com> On 2014-01-07 02:29, Cameron Simpson wrote: > On 06Jan2014 18:56, Skip Montanaro wrote: > [...] >> Let's say I have a dead simple GUI with two buttons labeled, "Do A" and "Do >> B". Each corresponds to executing a particular activity, A or B, which take >> some non-zero amount of time to complete (as perceived by the user) or >> cancel (as perceived by the state of the running system - not safe to run A >> until B is complete/canceled, and vice versa). The user, being the fickle >> sort that he is, might change his mind while A is running, and decide to >> execute B instead. (The roles can also be reversed.) If s/he wants to run >> task A, task B must be canceled or allowed to complete before A can be >> started. > > I take it we can ignore user's hammering on buttons faster than > jobs can run or be cancelled? > >> Logically, the code looks something like (I fear Gmail is going to >> destroy my indentation): >> >> def do_A(): >> when B is complete, _do_A() >> cancel_B() > [...] >> def _do_A(): >> do the real A work here, we are guaranteed B is no longer running > [...] >> cancel_A and cancel_B might be no-ops, in which case they need to start up >> the other calculation immediately, if one is pending. > > I wouldn't have cancel_A do this, I'd have do_A do this more overtly. > >> This is pretty simple execution, and if my job was this simple, I'd >> probably just keep doing things the way I do now, which is basically to >> catch a "complete" or "canceled" signal from the A and B tasks and execute >> the opposite task if it's pending. But it's not this simple. In reality >> there are lots of, "oh, you want to do X? You need to make sure A, B, and C >> are not active." And other stuff like that. > > What's wrong with variations on: > > from threading import Lock > > lock_A = Lock() > lock_B = Lock() > > def do_A(): > with lock_B(): > with lock_A(): > _do_A() > > def do_B(): > with lock_A(): > with lock_B(): > _do_B() > It's safer to lock in the same order to reduce the chance of deadlock: def do_A(): with lock_A(): with lock_B(): _do_A() def do_B(): with lock_A(): with lock_B(): _do_B() > You can extend this with multiple locks for A,B,C provided you take > the excluding locks before taking the inner lock for the core task. > > Regarding cancellation, I presume your code polls some cancellation > flag regularly during the task? > From rosuav at gmail.com Mon Jan 6 22:59:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 14:59:42 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 2:12 PM, Devin Jeanpierre wrote: > Doing a flag like that that enables a backwards incompatible change > does in fact address that issue you were worried about originally, so > that's something. And feature-by-feature moves are, like the OP said, > still lower cost than a wholesale move. > > In the end a gradual transition can still be done with the polyglot > approach, but I'm not happy that there's no way to enforce/test a > polyglot conversion until it is complete. Any kind of granularity > would have helped. :( Yeah, feature-by-feature is possible; but it doesn't help with one of the big (and common) complaints, that a library can't migrate without the application migrating. The way I see it, polyglot coding should be considered a superset of 2.7 coding, at which point there should hopefully be some perceived value in boasting "Requires 2.7 *OR 3.3*!", and ideally that value should be greater than the cost of supporting both. There are two ways to achieve that: Increase the perceived value, and decrease the cost. Making 3.3 (or 3.4, or whatever) look better is simply a matter of there being more applications (or potential applications) written for that, and that's going to be largely circular, and it's completely not in the hands of Python development, so the focus has to be on decreasing the cost. Hence the question: What are the breakages between 2.7 and 3.3, and which ones can be solved per-module? If the solution to the breakage has to be done per-application, that's a problem, even if it is feature-by-feature. But stuff that can be changed per-module can entirely eliminate the cost of polyglot code (for that feature), as it'll simply be written in the Py3 way, with one little future directive at the top. ChrisA From rosuav at gmail.com Mon Jan 6 23:01:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 15:01:23 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <52CB3403.3000903@udel.edu> Message-ID: On Tue, Jan 7, 2014 at 1:42 PM, Terry Reedy wrote: > I am pleased to see that the bug-fix releases get downloaded so heavily. That's a tricky one, though. It's impossible to say how many 3.3.1 downloads were upgrading from 3.3.0, and how many were simply "I want Python, give me the latest". But either way, it's still a lot of downloads. ChrisA From steve at pearwood.info Mon Jan 6 23:01:36 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 07 Jan 2014 04:01:36 GMT Subject: "More About Unicode in Python 2 and 3" References: <52caecdb$0$29968$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52cb7c20$0$2877$c3e8da3$76491128@news.astraweb.com> On Mon, 06 Jan 2014 16:32:01 -0500, Ned Batchelder wrote: > On 1/6/14 12:50 PM, Steven D'Aprano wrote: >> Ned Batchelder wrote: >> >>> You are still talking about whether Armin is right, and whether he >>> writes well, about flaws in his statistics, etc. I'm talking about >>> the fact that an organization (Python core development) has a product >>> (Python 3) that is getting bad press. Popular and vocal customers >>> (Armin, Kenneth, and others) are unhappy. What is being done to make >>> them happy? Who is working with them? They are not unique, and their >>> viewpoints are not outliers. >>> >>> I'm not talking about the technical details of bytes and Unicode. I'm >>> talking about making customers happy. >> >> Oh? How much did Armin pay for his Python support? If he didn't pay, >> he's not a customer. He's a user. > > I use the term "customer" in the larger sense of, "someone using your > product that you are trying to please." I'd like to think that an open > source project with only users would treat them as customers. Not in > the sense of a legal obligation in exchange for money, but in the sense > that the point of the work is to please them. But isn't the strength of open source that people write software that pleases *themselves*, and if others can make use of it, we all win? If GvR wrote Python to please others, it would have braces, it would be more like Perl and C, and it would probably be a mess. All else being equal, it's better for open source software if your users are happy than if they are unhappy, but at what cost? You can't make everyone happy. [...] > I was only avoiding talking about Unicode vs bytes because I'm not the > one who needs a better way to do it, Armin and Kenneth are. You seem to > be arguing from the standpoint of, "I've never had problems, so there > are no problems." Certainly not. I've tried hard not to say, or imply, that Armin is wrong. I know he is an extremely competent Python developer, and I don't understand his problem domain well enough to categorically say he's wrong. I *suspect* he's doing something wrong, or at least sub-optimally, and making things more difficult for himself than they need be, but what do I know? Maybe that's just my wishful thinking. > I suspect an undercurrent here is also the difference between writing > Python 3 code, and writing code that can run on both Python 2 and 3. Of course. It's always harder to target multiple versions with incompatibilities than a single version. > In my original post, I provided two possible responses, one of which > you've omitted: work with Armin to explain the easier way that he has > missed. Isn't that just another way of saying what I said earlier? "try to educate Armin (and others) so they stop blaming Python for their own errors" Although your version is more diplomatic. > It sounds like you think there isn't an easier way, and that's > OK? I would love to see a Python 3 advocate work with Armin or Kenneth > on the code that's caused them such pain, and find a way to make it > good. Is it a good think that there's code that's hard to write in Python 3? Not in isolation. But sometimes when you design a language, you implicitly or explicitly decide that certain types of code will not be a good fit for that language: you can't write an efficient operating system kernel in Python. Maybe you can't easily do the sort of low-level network stuff that Armin is trying to do in Python 3. But I doubt it. I expect that probably half the problem is that he's missing something, or doing something wrong, and the other half is that Python 3 genuinely makes it harder than it should be. But again, what do I know? > It's clear from other discussions happening elsewhere that there is the > possibility of improving the situation, for example PEP 460 proposing > "bytes % args" and "bytes.format(args)". That's good. I don't know... if byte formatting ends up encouraging people to use bytes when they ought to use strings, maybe it will be an attractive nuisance and in the long-term do more harm than good. But I'm keeping an open mind. -- Steven From rosuav at gmail.com Tue Jan 7 00:21:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 7 Jan 2014 16:21:38 +1100 Subject: /usr/lib/python2.7/subprocess.py:OSError: [Errno 2] No such file or directory In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 4:20 AM, Marco Ippolito wrote: > File "/usr/local/lib/python2.7/dist-packages/nltk/classify/megam.py", > line 167, in call_megam > p = subprocess.Popen(cmd, stdout=subprocess.PIPE) > File "/usr/lib/python2.7/subprocess.py", line 679, ininit > errread, errwrite) > File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child > raise child_exception > OSError: [Errno 2] No such file or directory > > subprocess.py exists: The problem isn't inside subprocess itself, which is raising the error. It looks like the problem is with the command being executed via Popen. I would look in megam.py (the first line that I quoted here) and see what the command is, and then see if you have that installed correctly. It ought to be listed as a prerequisite. ChrisA From cmpython at gmail.com Tue Jan 7 02:55:07 2014 From: cmpython at gmail.com (CM) Date: Mon, 6 Jan 2014 23:55:07 -0800 (PST) Subject: django question In-Reply-To: References: <20140104193705.0db361cc@bigbox.christie.dr> Message-ID: <8ba0b041-ffc6-419d-883d-d2efdfdfadf9@googlegroups.com> On Monday, January 6, 2014 8:57:22 PM UTC-5, Roy Smith wrote: > Yes, exactly. There's nothing magic about a django view. It's just a > function which is passed an instance of HttpRequest (and possibly a few > other things, depending on your url mapping), and which is expected to > return an instance of HttpResponse. Within that framework, it can call > any other functions it wants. > > For example, http://legalipsum.com/ is a silly little site I built in > django. Here's the view for the home page: Nice! > Notice how the view knows nothing about generating the actual markov > text. That's in another module, which lives somewhere on my PYTHONPATH. > ALso, the view knows nothing about how the page is laid out; only the > templates know that. If I decided to redo this in tornado or flask, > whatever, I would need to rewrite my view, but there's not much to > rewrite. Most of the logic is in the Markov chainer, and that would > cary over to the new implementation unchanged. > > BTW, my suggestion to keep business logic and presentation code distinct > isn't unique to django, it's a good idea in pretty much all systems. Thanks for these points, helpful to see in practice. I'm trying to be more mindful of good coding practices, and this will be helpful as I continue to learn Django and making web applications generally. From mhysnm1964 at gmail.com Tue Jan 7 05:05:49 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Tue, 7 Jan 2014 21:05:49 +1100 Subject: nested dictionaries and functions in data structures. Message-ID: <0CF6151E-E063-4252-9AC3-4FD4698EB28C@gmail.com> Hello all. I have some questions again. :-) I wish to be able to place a function within a data structure. I would like to use a dictionary because I could pass it a key and then the function could be called. I couldn't find anything on the net to show me how to do this. More then likely, not using the right search terms. For example: funct_call = { 'bhp' : 'bhp_counters (addict[key1][key2])', 'ospf' : 'ospf_counters (addict[key1][key2])'} I am sure there is a way to do this. The other issue is I cannot nest dictionaries. I have seen examples and when I apply them to the code below. They do not provide the result I want. The program does 3 actions. 1. Opens all the files in the directory. Each file begins with "data_". The 6 character in the file name is the occurrence of the output. Ranging from 1 to 9. The8th character plus the remaining part of the file is the output of the command. For example: data_1_ospf.txt The commands stored in this file are related to OSPF. When I build the nested dictionary I want to have "OSPF" as the primary key. Nested under "OSPF" is the number of times the command has been captured. The file content stored as an array and is the value of the 2nd key. data structure could look like this: outputs = { 'ospf' : { '1' : lines_of_file[], '2' : lines of_file[]} } Below is the code I have used to try and achieve the above. I just don't get the nested dictionary effect I am after. Again, I am trying to use standard core which some of the examples I have seen appeared to use. I am aware of collection module. #! /usr/bin/env python # Identifying if memory leaks are occurring. # goal is to import output to Excel. # created on 28 Dec 2013 By Sean Murphy import os, sys from os.path import exists # main code begins if len(sys.argv) >= 2: # storing file names into variable from command line. filenames = sys.argv[1:] else: filenames = os.listdir(os.getcwd()) # print ("Error, must provide at least one file name\n") # quit() outputs = {} # empty dictionary (hash) capture = "" # key used for the capture version command = "" # key for the command output for filename in filenames: if exists(filename): fp = open(filename, "r") capture = filename[6] command = filename[8:] # nested dictionary. Command and then number of captures. outputs = {command : { capture :[fp.readlines() } } fp.close() else: print ("error %s doesn't exists\n" % filename) quit() print ("%r\n" % outputs.keys()) for key in sorted(outputs): print (outputs[key].keys ()) Cheers Sean From jeanmichel at sequans.com Tue Jan 7 05:21:26 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 7 Jan 2014 11:21:26 +0100 (CET) Subject: nested dictionaries and functions in data structures. In-Reply-To: <0CF6151E-E063-4252-9AC3-4FD4698EB28C@gmail.com> Message-ID: <152874620.3018132.1389090086363.JavaMail.root@sequans.com> ----- Original Message ----- > Hello all. > > I have some questions again. :-) > > I wish to be able to place a function within a data structure. I > would like to use a dictionary because I could pass it a key and > then the function could be called. I couldn't find anything on the > net to show me how to do this. More then likely, not using the right > search terms. > > For example: > > funct_call = { 'bhp' : 'bhp_counters (addict[key1][key2])', 'ospf' : > 'ospf_counters (addict[key1][key2])'} > > I am sure there is a way to do this. > > The other issue is I cannot nest dictionaries. I have seen examples > and when I apply them to the code below. They do not provide the > result I want. The program does 3 actions. > > > 1. Opens all the files in the directory. Each file begins with > "data_". The 6 character in the file name is the occurrence of the > output. Ranging from 1 to 9. The8th character plus the remaining > part of the file is the output of the command. For example: > > data_1_ospf.txt > > The commands stored in this file are related to OSPF. When I build > the nested dictionary I want to have "OSPF" as the primary key. > Nested under "OSPF" is the number of times the command has been > captured. The file content stored as an array and is the value of > the 2nd key. data structure could look like this: > > outputs = { 'ospf' : { '1' : lines_of_file[], '2' : lines of_file[]} > } > > Below is the code I have used to try and achieve the above. I just > don't get the nested dictionary effect I am after. Again, I am > trying to use standard core which some of the examples I have seen > appeared to use. I am aware of collection module. > > #! /usr/bin/env python > > # Identifying if memory leaks are occurring. > # goal is to import output to Excel. > # created on 28 Dec 2013 By Sean Murphy > > import os, sys > from os.path import exists > > # main code begins > > if len(sys.argv) >= 2: > # storing file names into variable from command line. > filenames = sys.argv[1:] > else: > filenames = os.listdir(os.getcwd()) > # print ("Error, must provide at least one file name\n") > # quit() > > outputs = {} # empty dictionary (hash) > capture = "" # key used for the capture version > command = "" # key for the command output > > for filename in filenames: > if exists(filename): > fp = open(filename, "r") > capture = filename[6] > command = filename[8:] > # nested dictionary. Command and then number of captures. > outputs = {command : { capture :[fp.readlines() } } > fp.close() > else: > print ("error %s doesn't exists\n" % filename) > quit() > > print ("%r\n" % outputs.keys()) > for key in sorted(outputs): > print (outputs[key].keys ()) > > > Cheers > Sean outputs keeps track of the last loop only because you're assigning a new dict on every loop. You need to update the current dict instead. try to replace outputs = {command : { capture :fp.readlines() } } with (untested code) if command not in outputs: outputs[command] = {} outputs[command][capture] = fp.readlines() 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 ned at nedbatchelder.com Tue Jan 7 05:54:23 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 07 Jan 2014 05:54:23 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: On 1/6/14 5:30 PM, Mark Lawrence wrote: > On 06/01/2014 22:22, Ned Batchelder wrote: >> On 1/6/14 5:08 PM, Mark Lawrence wrote: >>> On 06/01/2014 21:42, Ned Batchelder wrote: >>>> On 1/6/14 4:33 PM, Mark Lawrence wrote: >>>>> That strikes me as being as useful as "The PEP 393 FSR is completely >>>>> wrong but I'm not going to tell you why" approach. >>>>> >>>> >>>> Please stop baiting people. >>>> >>> >>> What are you on about? The comment has been made that "its quite plain >>> to me that 3.x python has a problem with everyday dealing with strings". >>> Myself, Terry Reedy and Steven D'Aprano have all commented on this, >>> asking for more data. We've been given nothing, which is precisely what >>> our resident unicode expert has given us. >>> >> >> I'm on about your comment being a gratuitous jab at someone who isn't >> even participating in the thread. Stop it. >> > > You arrogance really has no bounds. If you'd have done the job that you > should have done in the first place and stopped that blithering idiot 16 > months ago, we wouldn't still be putting up with him now. I don't understand how you can accuse me both of arrogance (presumably for speaking up about bad behavior), and also of not doing my job (presumably, speaking up about bad behavior) at the same time. 16 months ago I wasn't even a reader of this list, let alone a moderator. I don't know why you think it was my job to fix something back then. Now I have no special powers or jobs, just an interest in this list running smoothly. If you don't want to put up with someone, don't invite them into a thread by baiting them. > > And as I started this thread, I'll say what I please, throwing my toys > out of my pram in just the same way that your pal Armin is currently doing. > Starting threads doesn't give you any special rights. I don't see how your displeasure with Armin entitles you to gratuitous baiting of someone else. Declaring "I'm acting badly, and I intend to keep acting badly" is just childish. Forget the code of conduct, forget common civility, just think about your own self-interest: if you don't want to hear from someone on the list, why would you invite them in with that kind of provocation? Let sleeping dogs lie. -- Ned Batchelder, http://nedbatchelder.com From mhysnm1964 at gmail.com Tue Jan 7 05:56:46 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Tue, 7 Jan 2014 21:56:46 +1100 Subject: nested dictionaries and functions in data structures. In-Reply-To: <152874620.3018132.1389090086363.JavaMail.root@sequans.com> References: <152874620.3018132.1389090086363.JavaMail.root@sequans.com> Message-ID: <0F937DFF-E25B-4DE2-BE49-6E93A3CF4B1E@gmail.com> Thanks for that. It resolved the issue and it was so simple compared to everything else I saw on the net. Only outstanding thing I have to work out is how to execute functions from a dictionary. I will continue searching on the net. Sean On 07/01/2014, at 9:21 PM, Jean-Michel Pichavant wrote: > > > ----- Original Message ----- >> Hello all. >> >> I have some questions again. :-) >> >> I wish to be able to place a function within a data structure. I >> would like to use a dictionary because I could pass it a key and >> then the function could be called. I couldn't find anything on the >> net to show me how to do this. More then likely, not using the right >> search terms. >> >> For example: >> >> funct_call = { 'bhp' : 'bhp_counters (addict[key1][key2])', 'ospf' : >> 'ospf_counters (addict[key1][key2])'} >> >> I am sure there is a way to do this. >> >> The other issue is I cannot nest dictionaries. I have seen examples >> and when I apply them to the code below. They do not provide the >> result I want. The program does 3 actions. >> >> >> 1. Opens all the files in the directory. Each file begins with >> "data_". The 6 character in the file name is the occurrence of the >> output. Ranging from 1 to 9. The8th character plus the remaining >> part of the file is the output of the command. For example: >> >> data_1_ospf.txt >> >> The commands stored in this file are related to OSPF. When I build >> the nested dictionary I want to have "OSPF" as the primary key. >> Nested under "OSPF" is the number of times the command has been >> captured. The file content stored as an array and is the value of >> the 2nd key. data structure could look like this: >> >> outputs = { 'ospf' : { '1' : lines_of_file[], '2' : lines of_file[]} >> } >> >> Below is the code I have used to try and achieve the above. I just >> don't get the nested dictionary effect I am after. Again, I am >> trying to use standard core which some of the examples I have seen >> appeared to use. I am aware of collection module. >> >> #! /usr/bin/env python >> >> # Identifying if memory leaks are occurring. >> # goal is to import output to Excel. >> # created on 28 Dec 2013 By Sean Murphy >> >> import os, sys >> from os.path import exists >> >> # main code begins >> >> if len(sys.argv) >= 2: >> # storing file names into variable from command line. >> filenames = sys.argv[1:] >> else: >> filenames = os.listdir(os.getcwd()) >> # print ("Error, must provide at least one file name\n") >> # quit() >> >> outputs = {} # empty dictionary (hash) >> capture = "" # key used for the capture version >> command = "" # key for the command output >> >> for filename in filenames: >> if exists(filename): >> fp = open(filename, "r") >> capture = filename[6] >> command = filename[8:] >> # nested dictionary. Command and then number of captures. >> outputs = {command : { capture :[fp.readlines() } } >> fp.close() >> else: >> print ("error %s doesn't exists\n" % filename) >> quit() >> >> print ("%r\n" % outputs.keys()) >> for key in sorted(outputs): >> print (outputs[key].keys ()) >> >> >> Cheers >> Sean > > outputs keeps track of the last loop only because you're assigning a new dict on every loop. You need to update the current dict instead. > > try to replace > outputs = {command : { capture :fp.readlines() } } > > with (untested code) > > if command not in outputs: > outputs[command] = {} > outputs[command][capture] = fp.readlines() > > 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 steve+comp.lang.python at pearwood.info Tue Jan 7 06:06:28 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 22:06:28 +1100 Subject: nested dictionaries and functions in data structures. References: <152874620.3018132.1389090086363.JavaMail.root@sequans.com> Message-ID: <52cbdfb5$0$29973$c3e8da3$5496439d@news.astraweb.com> Sean Murphy wrote: > Only outstanding thing I have to work out is how to execute functions from > a dictionary. I will continue searching on the net. I don't quite understand this question. Do you mean something like this? def spam(n): return "spam"*n def eggs(n): return "eggs"*n d = {1: spam, 2: eggs} print( d[1](3) ) print( d[2](3) ) -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 7 06:13:29 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 22:13:29 +1100 Subject: Bytes indexing returns an int Message-ID: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Does anyone know what the rationale behind making byte-string indexing return an int rather than a byte-string of length one? That is, given b = b'xyz', b[1] returns 121 rather than b'y'. This is especially surprising when one considers that it's easy to extract the ordinal value of a byte: ord(b'y') => 121 -- Steven From ned at nedbatchelder.com Tue Jan 7 06:16:35 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 07 Jan 2014 06:16:35 -0500 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: <52cb7c20$0$2877$c3e8da3$76491128@news.astraweb.com> References: <52caecdb$0$29968$c3e8da3$5496439d@news.astraweb.com> <52cb7c20$0$2877$c3e8da3$76491128@news.astraweb.com> Message-ID: On 1/6/14 11:01 PM, Steven D'Aprano wrote: > On Mon, 06 Jan 2014 16:32:01 -0500, Ned Batchelder wrote: > >> On 1/6/14 12:50 PM, Steven D'Aprano wrote: >>> Ned Batchelder wrote: >>> >>>> You are still talking about whether Armin is right, and whether he >>>> writes well, about flaws in his statistics, etc. I'm talking about >>>> the fact that an organization (Python core development) has a product >>>> (Python 3) that is getting bad press. Popular and vocal customers >>>> (Armin, Kenneth, and others) are unhappy. What is being done to make >>>> them happy? Who is working with them? They are not unique, and their >>>> viewpoints are not outliers. >>>> >>>> I'm not talking about the technical details of bytes and Unicode. I'm >>>> talking about making customers happy. >>> >>> Oh? How much did Armin pay for his Python support? If he didn't pay, >>> he's not a customer. He's a user. >> >> I use the term "customer" in the larger sense of, "someone using your >> product that you are trying to please." I'd like to think that an open >> source project with only users would treat them as customers. Not in >> the sense of a legal obligation in exchange for money, but in the sense >> that the point of the work is to please them. > > But isn't the strength of open source that people write software that > pleases *themselves*, and if others can make use of it, we all win? If GvR > wrote Python to please others, it would have braces, it would be more > like Perl and C, and it would probably be a mess. > > All else being equal, it's better for open source software if your users > are happy than if they are unhappy, but at what cost? You can't make > everyone happy. Of course, but there has to be a balance. One of the strengths of Python is that the core developers listen to people and will take a pragmatic approach that solves real problems. The change in 3.3 that re-added u"" literals is an interesting case: there was strong opposition to the proposal, because it weakened the purity of the new approach to Unicode. It won out because it made it easier to port code to 3.3, not because it made it easier to write a program that ran on 3.3, but because it made it easier to write a program that ran on both 2.7 and 3.3. > [...] >> I was only avoiding talking about Unicode vs bytes because I'm not the >> one who needs a better way to do it, Armin and Kenneth are. You seem to >> be arguing from the standpoint of, "I've never had problems, so there >> are no problems." > > Certainly not. I've tried hard not to say, or imply, that Armin is wrong. > I know he is an extremely competent Python developer, and I don't > understand his problem domain well enough to categorically say he's > wrong. I *suspect* he's doing something wrong, or at least sub-optimally, > and making things more difficult for himself than they need be, but what > do I know? Maybe that's just my wishful thinking. I was advocating for people learning more about his problem domain to understand where the friction was, and improve the situation. >> I suspect an undercurrent here is also the difference between writing >> Python 3 code, and writing code that can run on both Python 2 and 3. > > Of course. It's always harder to target multiple versions with > incompatibilities than a single version. As I mentioned above, I think one of the under-exposed points of disagreement is how much Python 3 needs to make it possible to write polyglots, and how much it can focus on pure Python 3 programs. When the debate comes down to, "It's hard to write my programs!" countered with, "But Python 3 does this better than Python 2!", perhaps we need to uncover that the first person cares a lot about writing 2+3 code, and the second person does not. At least then we could understand why we seem to be talking past each other. >> In my original post, I provided two possible responses, one of which >> you've omitted: work with Armin to explain the easier way that he has >> missed. > > Isn't that just another way of saying what I said earlier? > > "try to educate Armin (and others) so they stop blaming Python for their > own errors" > > Although your version is more diplomatic. > > >> It sounds like you think there isn't an easier way, and that's >> OK? I would love to see a Python 3 advocate work with Armin or Kenneth >> on the code that's caused them such pain, and find a way to make it >> good. > > Is it a good think that there's code that's hard to write in Python 3? > Not in isolation. But sometimes when you design a language, you > implicitly or explicitly decide that certain types of code will not be a > good fit for that language: you can't write an efficient operating system > kernel in Python. Maybe you can't easily do the sort of low-level network > stuff that Armin is trying to do in Python 3. But I doubt it. I expect > that probably half the problem is that he's missing something, or doing > something wrong, and the other half is that Python 3 genuinely makes it > harder than it should be. But again, what do I know? I appreciate the allowance for the possibility that Python 3 still has changes to make to improve the situation. >> It's clear from other discussions happening elsewhere that there is the >> possibility of improving the situation, for example PEP 460 proposing >> "bytes % args" and "bytes.format(args)". That's good. > > > I don't know... if byte formatting ends up encouraging people to use > bytes when they ought to use strings, maybe it will be an attractive > nuisance and in the long-term do more harm than good. But I'm keeping an > open mind. Eh, there are lots of things that have narrow uses and get mis-applied, and Python is better for having them available. Practicality beats purity. In all this, I've been very impressed (as usual!) with Nick Coghlan's responses (https://twitter.com/jubiweb/status/419812396085960704): "'tis healthy criticism - a change of this magnitude *deserves* to be challenged to make sure we articulate our motives." "I still learn more from Armin's disagreement than if he instead chose to just walk away." -- Ned Batchelder, http://nedbatchelder.com From frank at chagford.com Tue Jan 7 06:46:57 2014 From: frank at chagford.com (Frank Millman) Date: Tue, 7 Jan 2014 13:46:57 +0200 Subject: nested dictionaries and functions in data structures. References: <0CF6151E-E063-4252-9AC3-4FD4698EB28C@gmail.com> Message-ID: "Sean Murphy" wrote in message news:0CF6151E-E063-4252-9AC3-4FD4698EB28C at gmail.com... > Hello all. > > I have some questions again. :-) > > I wish to be able to place a function within a data structure. I would > like to use a dictionary because I could pass it a key and then the > function could be called. I couldn't find anything on the net to show me > how to do this. More then likely, not using the right search terms. > > For example: > > funct_call = { 'bhp' : 'bhp_counters (addict[key1][key2])', 'ospf' : > 'ospf_counters (addict[key1][key2])'} > > I am sure there is a way to do this. > [...] There are two problems with your example. First, it is (probably) correct to enclose the key in quotes, but definitely incorrect to enclose the function name in quotes. Assuming you have already declared the function, you just use the function name, without quotes, as the value. Secondly, you must not place brackets, with or without arguments, after the function name. The difference is that, without brackets it *refers* to the function, with brackets it *calls* the function. You only want to call it at execution time, not when setting up the dictionary. If you have a variable 'var' which contains 'bhp' or 'ospf', you would at execution time have the following - funct = funct_call[var] # retrieve the function from the dictionary funct(addict[key1][key2]) # call the function with arguments This is usually compressed into one line - funct_call[var](addict[key1][key2]) This works if you always use the same arguments, no matter which function you call. Things get trickier if they differ. Frank Millman From airween at gmail.com Tue Jan 7 06:53:04 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Tue, 7 Jan 2014 12:53:04 +0100 Subject: Bytes indexing returns an int In-Reply-To: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140107115303.GA9202@arxnet.hu> hi, On Tue, Jan 07, 2014 at 10:13:29PM +1100, Steven D'Aprano wrote: > Does anyone know what the rationale behind making byte-string indexing > return an int rather than a byte-string of length one? > > That is, given b = b'xyz', b[1] returns 121 rather than b'y'. > > This is especially surprising when one considers that it's easy to extract > the ordinal value of a byte: > > ord(b'y') => 121 Which Python version? http://docs.python.org/2/reference/lexical_analysis.html#strings "A prefix of 'b' or 'B' is ignored in Python 2;" if you want to store the string literal as byte array, you have to use "bytearray()" function: >>> a = bytearray('xyz') >>> a bytearray(b'xyz') >>> a[0] 120 >>> a[1] 121 http://docs.python.org/2/library/stdtypes.html 5.6. Sequence Types hth, a. From steve+comp.lang.python at pearwood.info Tue Jan 7 07:04:25 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Tue, 07 Jan 2014 23:04:25 +1100 Subject: Bytes indexing returns an int References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52cbed4a$0$29979$c3e8da3$5496439d@news.astraweb.com> Ervin Heged?s wrote: > hi, > > On Tue, Jan 07, 2014 at 10:13:29PM +1100, Steven D'Aprano wrote: >> Does anyone know what the rationale behind making byte-string indexing >> return an int rather than a byte-string of length one? >> >> That is, given b = b'xyz', b[1] returns 121 rather than b'y'. >> >> This is especially surprising when one considers that it's easy to >> extract the ordinal value of a byte: >> >> ord(b'y') => 121 > > Which Python version? My apologies... I've been so taken up with various threads on this list discussing Python 3, I forgot to mention that I'm talking about Python 3. I understand the behaviour of bytes and bytearray, I'm asking *why* that specific behaviour was chosen. -- Steven From jeanmichel at sequans.com Tue Jan 7 07:19:36 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 7 Jan 2014 13:19:36 +0100 (CET) Subject: nested dictionaries and functions in data structures. In-Reply-To: <0F937DFF-E25B-4DE2-BE49-6E93A3CF4B1E@gmail.com> Message-ID: <59989803.3050665.1389097176191.JavaMail.root@sequans.com> ----- Original Message ----- > Thanks for that. It resolved the issue and it was so simple compared > to everything else I saw on the net. > > Only outstanding thing I have to work out is how to execute functions > from a dictionary. I will continue searching on the net. > > > Sean This may help you (untested code) class Workers: @staticmethod def ospf(*args, **kwargs): print args, kwargs return 'Bar' @staticmethod def bhp(*args, **kwargs): return 'Foo' outputs = {'ospf' : {1 : {'param1' : 'foo', 'param2' : 'foo2'}} for command, value in outputs.items(): for counter, kwargs in value: func = getattr(Workers, command) # get the function func(**kwargs) # the actual call It would be possible to do it without the *args, **kwargs magic. You can write ospf and bhp with the explicit parameters, however you must make sure you pass the correct number of parameter in the call. 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 faassen at startifact.com Tue Jan 7 07:54:18 2014 From: faassen at startifact.com (Martijn Faassen) Date: Tue, 07 Jan 2014 13:54:18 +0100 Subject: the Gravity of Python 2 In-Reply-To: References: Message-ID: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> On 01/07/2014 01:19 AM, Chris Angelico wrote: > Can we get a run-down of everything that actually must be broken in > 2.7 -> 3.3, that can't be backported via __future__, so we can start > cherry-picking which bits to break in 2.8? The biggest one is going to > be Unicode strings, for a large number of people (the print statement > and division operators can be __future__'d, lots of other stuff got > backported into 2.7). I'd be prepared to bet money that that one will > NOT be broken in 2.8, meaning that it achieves nothing on that score. > So how much easier will the migration actually be? That's a good question. I envision support for per-module upgrades, though I'm not 100% sure that it would work. This way a large project can incrementally start porting modules to the Python 3 unicode behavior. The 'future' module (python-future.org) effectively backports the Python 3 str and bytes into Python 2.7. The question is then what happens when they interact with Python 2 str and unicode. I'm speculating about the behavior of the 'future' module here, but here's what I could imagine. First the Python 3 behavior: py3str + py3str = py3str py3bytes + py3bytes = py3bytes py3str + py3bytes = error Then the behavior of when Python 3 str/bytes are mixed with Python 2 str and unicode: py3str + py2unicode = py2unicode py3str + py2str = py2unicode py3bytes + py2str = py2str Plus the regular old Python 2 behavior. I'm quite sure I could be getting something wrong; it's only a few days since I saw 'future' and started thinking along these lines. Regards, Martijn From wxjmfauth at gmail.com Tue Jan 7 08:34:36 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Tue, 7 Jan 2014 05:34:36 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> Message-ID: <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Le dimanche 5 janvier 2014 23:14:07 UTC+1, Terry Reedy a ?crit?: > On 1/5/2014 9:23 AM, wxjmfauth at gmail.com wrote: > > > Le samedi 4 janvier 2014 23:46:49 UTC+1, Terry Reedy a ?crit : > > >> On 1/4/2014 2:10 PM, wxjmfauth at gmail.com wrote: > > >>> And I could add, I *never* saw once one soul, who is > > >>> explaining what I'm doing wrong in the gazillion > > >>> of examples I gave on this list. > > > > >> If this is true, it is because you have ignored and not read my > > >> numerous, relatively polite posts. To repeat very briefly: > > >> 1. Cherry picking (presenting the most extreme case as representative). > > >> 2. Calling space saving a problem (repeatedly). > > >> 3. Ignoring bug fixes. > > ... > > > > > My examples are ONLY ILLUSTRATING, this FSR > > > is wrong by design, can be on the side of > > > memory, performance, linguistic or even > > > typography. > > > > Let me expand on 3 of my points. First, performance == time: > > > > Point 3. You correctly identified a time regression in finding a > > character in a string. I saw that the slowdown was *not* inherent in the > > FSR but had to be a glitch in the code, and reported it on pydev with > > the hope that someone would fix it even if it were not too important in > > real use cases. Someone did. > > > > Point 1. You incorrectly generalized that extreme case. I reported (a > > year ago last September) that the overall stringbench results were about > > the same. I also pointed out that there is an equally non-representative > > extreme case in the opposite direction, and that it would equally be > > wrong of me to use that to claim that FSR is faster. (It turns out that > > this FSR speed advantage *is* inherent in the design.) > > > > Memory: Point 2. A *design goal* of FSR was to save memory relative to > > UTF-32, which is what you apparently prefer. Your examples show that FSF > > successfully met its design goal. But you call that success, saving > > memory, 'wrong'. On what basis? > > > > You *claim* the FSR is 'wrong by design', but your examples only show > > that is was temporarily wrong in implementation as far as speed and > > correct by design as far as memory goes. > > Point 3: You are right. I'm very happy to agree. Point 2: This Flexible String Representation does no "effectuate" any memory optimization. It only succeeds to do the opposite of what a corrrect usage of utf* do. Ned : this has already been explained and illustrated. jmf From tjreedy at udel.edu Tue Jan 7 09:29:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Jan 2014 09:29:41 -0500 Subject: Bytes indexing returns an int In-Reply-To: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/7/2014 6:13 AM, Steven D'Aprano wrote: > Does anyone know what the rationale behind making byte-string indexing > return an int rather than a byte-string of length one? > > That is, given b = b'xyz', b[1] returns 121 rather than b'y'. This former is the normal behavior of sequences, the latter is peculiar to strings, because there is no separate character class. A byte is a count n, 0 <= n < 256 and bytes and bytearrays are sequences of bytes. It was ultimately Guido's decision after some discussion and debate on, I believe, the py3k list. I do not remember enough to be any more specific. -- Terry Jan Reedy From tjreedy at udel.edu Tue Jan 7 09:54:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Jan 2014 09:54:18 -0500 Subject: Blog "about python 3" In-Reply-To: <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> References: <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Message-ID: On 1/7/2014 8:34 AM, wxjmfauth at gmail.com wrote: > Le dimanche 5 janvier 2014 23:14:07 UTC+1, Terry Reedy a ?crit : >> Memory: Point 2. A *design goal* of FSR was to save memory relative to >> UTF-32, which is what you apparently prefer. Your examples show that FSF >> successfully met its design goal. But you call that success, saving >> memory, 'wrong'. On what basis? > Point 2: This Flexible String Representation does no > "effectuate" any memory optimization. It only succeeds > to do the opposite of what a corrrect usage of utf* > do. Since the FSF *was* successful in saving memory, and indeed shrank the Python binary by about a megabyte, I have no idea what you mean. -- Terry Jan Reedy From drobinow at gmail.com Tue Jan 7 10:19:13 2014 From: drobinow at gmail.com (David Robinow) Date: Tue, 7 Jan 2014 10:19:13 -0500 Subject: Bytes indexing returns an int In-Reply-To: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: "treating bytes as chars" considered harmful? I don't know the answer to your question but the behavior seems right to me. Python 3 grudgingly allows the "abomination" of byte strings (is that what they're called? I haven't fully embraced Python3 yet). If you want a substring you use a slice. b = b'xyz' b[1:2] => b'y' also, chr(121) => 'y' which is really what the Python 3 gods prefer. On Tue, Jan 7, 2014 at 6:13 AM, Steven D'Aprano wrote: > Does anyone know what the rationale behind making byte-string indexing > return an int rather than a byte-string of length one? > > That is, given b = b'xyz', b[1] returns 121 rather than b'y'. > > This is especially surprising when one considers that it's easy to extract > the ordinal value of a byte: > > ord(b'y') => 121 > > > > -- > Steven > > -- > https://mail.python.org/mailman/listinfo/python-list From drobinow at gmail.com Tue Jan 7 10:23:05 2014 From: drobinow at gmail.com (David Robinow) Date: Tue, 7 Jan 2014 10:23:05 -0500 Subject: Bytes indexing returns an int In-Reply-To: References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: Sorry for top-posting. I thought I'd mastered gmail. From faassen at startifact.com Tue Jan 7 11:07:10 2014 From: faassen at startifact.com (Martijn Faassen) Date: Tue, 07 Jan 2014 17:07:10 +0100 Subject: the Gravity of Python 2 In-Reply-To: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> Message-ID: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> Hi there, I just tried this out with the future module to see what it actually does, and I got this: On 01/07/2014 01:54 PM, Martijn Faassen wrote: > First the Python 3 behavior: > > py3str + py3str = py3str Yup, of course. > py3bytes + py3bytes = py3bytes Again of course. > py3str + py3bytes = error Yup, that's an error. > Then the behavior of when Python 3 str/bytes are mixed with Python 2 str > and unicode: > > py3str + py2unicode = py2unicode This didn't work as I expected; I'd have expected py2unicode for compatibility reasons, as py3str cannot be combined with py2str (but in fact it *can*, odd). > py3str + py2str = py2unicode This in fact returns py3str, which I didn't expect either. > py3bytes + py2str = py2str And this gets me py3bytes. I'll get in touch with the author of the 'future' module to try to understand why his reasoning is different from mine, i.e. where I'm wrong. Regards, Martijn From steve+comp.lang.python at pearwood.info Tue Jan 7 11:12:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 08 Jan 2014 03:12:59 +1100 Subject: Bytes indexing returns an int References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> David Robinow wrote: > "treating bytes as chars" considered harmful? Who is talking about treating bytes as chars? You're making assumptions that aren't justified by my question. > I don't know the answer to your question but the behavior seems right to > me. This issue was raised in an earlier discussion about *binary data* in Python 3. (The earlier discussion also involved some ASCII-encoded text, but that's actually irrelevant to the issue.) In Python 2.7, if you have a chunk of binary data, you can easily do this: data = b'\xE1\xE2\xE3\xE4' data[0] == b'\xE1' and it returns True just as expected. It even works if that binary data happens to look like ASCII text: data = b'\xE1a\xE2\xE3\xE4' data[1] == b'a' But in Python 3, the same code silently returns False in both cases, because indexing a bytes object gives an int. So you have to write something like these, all of which are ugly or inelegant: data = b'\xE1a\xE2\xE3\xE4' data[1] == 0x61 data[1] == ord(b'a') chr(data[1]) == 'a' data[1:2] == b'a' I believe that only the last one, the one with the slice, works in both Python 2.7 and Python 3.x. > Python 3 grudgingly allows the "abomination" of byte strings (is that > what they're called? I haven't fully embraced Python3 yet). They're not abominations. They exist for processing bytes (hence the name) and other binary data. They are necessary for low-level protocols, for dealing with email, web, files, and similar. Application code may not need to deal with bytes, but that is only because the libraries you call do the hard work for you. People trying to port these libraries from 2.7 to 3 run into this problem, and it causes them grief. This little difference between bytes in 2.7 and bytes in 3.x is a point of friction which makes porting harder, and I'm trying to understand the reason for it. -- Steven From torriem at gmail.com Tue Jan 7 11:38:44 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 07 Jan 2014 09:38:44 -0700 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: <7wfvp2gg6v.fsf_-_@benfinney.id.au> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: <52CC2D94.9040401@gmail.com> On 01/05/2014 04:30 PM, Ben Finney wrote: > In short: Everything that was good about OpenOffice is now called > LibreOffice, which had to change its name only because the owners of > that name refused to let it go. Your information is a year or two out of date. OpenOffice.org is alive and well, under the auspices of the Apache foundation. And in fact development is proceeding on it quite well. I believe they released OpenOffice v4 some time ago. It is mostly feature identical to LibreOffice 4, and even has a couple of features that LibreOffice lacks. They really need to merge back into one project again, but I suspect they won't either for ideological or legal reasons. The former is very sad and not a good commentary on the viability of open source software. OpenOffice is a much better name than LibreOffice as well, especially for trying to convert users off of proprietary Office. From faassen at startifact.com Tue Jan 7 11:42:42 2014 From: faassen at startifact.com (Martijn Faassen) Date: Tue, 07 Jan 2014 17:42:42 +0100 Subject: the Gravity of Python 2 In-Reply-To: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> Message-ID: <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> Hi, I've posted a documentation issue to the 'future' module which includes a further evolution of my thinking. As I expected, the author of the 'future' module has thought this through more than I had: https://github.com/PythonCharmers/python-future/issues/27 To get back to a hypothetical Python 2.8, it could implement this kind of behavior, and I think it would help support incremental upgrades. As long as you're using Py 3 bytes and str in your code, you'll be aware of errors and be forced to think about it. Other Python code in the system can remain unchanged, and to the magic of ducktyping will continue to work. You can then tackle things incrementally. Regards, Martijn From torriem at gmail.com Tue Jan 7 11:45:03 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 07 Jan 2014 09:45:03 -0700 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: <52CC2F0F.8040703@gmail.com> On 01/06/2014 08:53 AM, Grant Edwards wrote: > Yea, I think laying out a book with something like MS Word or > LibreOffice is nuts. Depending on her formatting needs, a > lighter-weight mark-up language (something like asciidoc) might suite: I've laid out a book with LibreOffice and it actually is quite capable. In fact when used correctly, LibreOffice can function much like a markup language. Instead of markup, you use styles (page, paragraph, character). The styles form the structure of the book (H1, H2, H3, etc). In fact the default styles mirror html to a degree. I tend to add my own for quotes, captions, etc. After composing the document, then you modify the styles to set the spacings, fonts, indentations, border lines, etc. The workflow is very similar to using LyX, or even a plain markup language for that matter. The weakest part of LibreOffice is embedding images. From rosuav at gmail.com Tue Jan 7 11:58:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 03:58:12 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: <52CC2F0F.8040703@gmail.com> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2F0F.8040703@gmail.com> Message-ID: On Wed, Jan 8, 2014 at 3:45 AM, Michael Torrie wrote: > I tend to add my own [styles] > for quotes, captions, etc. After composing the document, > then you modify the styles to set the spacings, fonts, indentations, > border lines, etc. The workflow is very similar to using LyX, or even a > plain markup language for that matter. That's all very well when you put everything into a single file, but how do you manage those styles across a multi-file book? Mum's project was partially rescued by the discovery that you can import styles from another document, but that's still unworkable for repeated edits. > The weakest part of LibreOffice is embedding images. And that's why this particular book is being divided up: it's full of images. Putting the whole thing into a single file makes that file way way too big to work with (at least on the computer Mum's using - it's X times larger than her installed RAM, so Writer is constantly hammering the page file), and there's no convenient way to read in only part of the file. Hence my recommendation of a markup system like LaTeX that simply *references* images, and which deliberately isn't WYSIWYG; plus, having the concept of content, structure, and style all separate means it's not difficult to build just one file - maybe not even a whole chapter - while still being confident that all pages reference the same styles. ChrisA From rosuav at gmail.com Tue Jan 7 11:50:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 03:50:56 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: <52CC2D94.9040401@gmail.com> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2D94.9040401@gmail.com> Message-ID: On Wed, Jan 8, 2014 at 3:38 AM, Michael Torrie wrote: > [OpenOffice v4] is mostly feature identical to > LibreOffice 4, and even has a couple of features that LibreOffice lacks. > They really need to merge back into one project again, but I suspect > they won't either for ideological or legal reasons. Sad. This is yet another of those politically-charged distinctions that, quite frankly, I have no interest in. Just look at cdrtools vs wodim, or Ruby 1.9.1 vs Ruby whatever-the-other-is, or for that matter (switching genres a bit) Caucasian vs {Aboriginal, Native American, dark skinned, etc, etc, etc}. I can't be bothered figuring out the differences between them all, and it's disappointing that the difference has to matter to someone. ChrisA From rosuav at gmail.com Tue Jan 7 12:00:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 04:00:26 +1100 Subject: the Gravity of Python 2 In-Reply-To: <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> Message-ID: On Wed, Jan 8, 2014 at 3:42 AM, Martijn Faassen wrote: > To get back to a hypothetical Python 2.8, it could implement this kind of > behavior, and I think it would help support incremental upgrades. As long as > you're using Py 3 bytes and str in your code, you'll be aware of errors and > be forced to think about it. Other Python code in the system can remain > unchanged, and to the magic of ducktyping will continue to work. You can > then tackle things incrementally. I'm still not sure how Python 2.8 needs to differ from 2.7. Maybe the touted upgrade path is simply a Python 2.7 installer plus a few handy libraries/modules that will now be preinstalled? These modules look great (I can't say, as I don't have a huge Py2 codebase to judge based on), and they presumably work on the existing Pythons. ChrisA From torriem at gmail.com Tue Jan 7 12:10:04 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 07 Jan 2014 10:10:04 -0700 Subject: [way OT] Migrating from non-free programs to LibreOffice In-Reply-To: References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2F0F.8040703@gmail.com> Message-ID: <52CC34EC.4000805@gmail.com> On 01/07/2014 09:58 AM, Chris Angelico wrote: > On Wed, Jan 8, 2014 at 3:45 AM, Michael Torrie wrote: >> I tend to add my own [styles] >> for quotes, captions, etc. After composing the document, >> then you modify the styles to set the spacings, fonts, indentations, >> border lines, etc. The workflow is very similar to using LyX, or even a >> plain markup language for that matter. > > That's all very well when you put everything into a single file, but > how do you manage those styles across a multi-file book? Mum's project > was partially rescued by the discovery that you can import styles from > another document, but that's still unworkable for repeated edits. Sorry should have been clearer on this. I do use multiple documents with LO with a master document. The table of contents can even be generated across documents. I believe my TOC is in my master document, along with the front matter. As for styles, basically you create a master template style that you use as a basis for each of your files (master document as well as the subdocuments). I make all my changes to the master template style and then when I open the various documents LO will update the templates. They aren't linked templates per se; they are copied. But the mechanism works okay, if a bit clunky. > >> The weakest part of LibreOffice is embedding images. > > And that's why this particular book is being divided up: it's full of > images. Putting the whole thing into a single file makes that file way > way too big to work with (at least on the computer Mum's using - it's > X times larger than her installed RAM, so Writer is constantly > hammering the page file), and there's no convenient way to read in > only part of the file. Hence my recommendation of a markup system like > LaTeX that simply *references* images, and which deliberately isn't > WYSIWYG; plus, having the concept of content, structure, and style all > separate means it's not difficult to build just one file - maybe not > even a whole chapter - while still being confident that all pages > reference the same styles. LO does reference images if you would like. But I find embedding the whole works is just more self-contained. And with multiple file documents the chances of losing data or messing with pagination are contained to individual sections. From rosuav at gmail.com Tue Jan 7 12:14:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 04:14:00 +1100 Subject: [way OT] Migrating from non-free programs to LibreOffice In-Reply-To: <52CC34EC.4000805@gmail.com> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2F0F.8040703@gmail.com> <52CC34EC.4000805@gmail.com> Message-ID: On Wed, Jan 8, 2014 at 4:10 AM, Michael Torrie wrote: > LO does reference images if you would like. But I find embedding the > whole works is just more self-contained. And with multiple file > documents the chances of losing data or messing with pagination are > contained to individual sections. Referencing isn't sufficient to prevent the massive memory use, though. Whatever's in the document will need to be loaded into RAM in order to edit the file. It's a fundamental limitation of big files and WYSIWYG editors. ChrisA From torriem at gmail.com Tue Jan 7 12:45:06 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 07 Jan 2014 10:45:06 -0700 Subject: [way OT] Migrating from non-free programs to LibreOffice In-Reply-To: References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2F0F.8040703@gmail.com> <52CC34EC.4000805@gmail.com> Message-ID: <52CC3D22.9030004@gmail.com> On 01/07/2014 10:14 AM, Chris Angelico wrote: > On Wed, Jan 8, 2014 at 4:10 AM, Michael Torrie wrote: >> LO does reference images if you would like. But I find embedding the >> whole works is just more self-contained. And with multiple file >> documents the chances of losing data or messing with pagination are >> contained to individual sections. > > Referencing isn't sufficient to prevent the massive memory use, > though. Whatever's in the document will need to be loaded into RAM in > order to edit the file. It's a fundamental limitation of big files and > WYSIWYG editors. I suppose. Working with multiple-part documents mitigates this issue to a large extent. Granted my sections are only about 30 pages or so, and only about 20 mb of imagery per section. From torriem at gmail.com Tue Jan 7 12:45:45 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 07 Jan 2014 10:45:45 -0700 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: <7wfvp2gg6v.fsf_-_@benfinney.id.au> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> Message-ID: <52CC3D49.9000805@gmail.com> Apologies to the list for the noise! Should have replied off-list. From ethan at stoneleaf.us Tue Jan 7 12:02:33 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 07 Jan 2014 09:02:33 -0800 Subject: Bytes indexing returns an int In-Reply-To: References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52CC3329.7030505@stoneleaf.us> On 01/07/2014 07:19 AM, David Robinow wrote: > > Python 3 grudgingly allows the "abomination" of byte strings (is that > what they're called?) No, that is *not* what they're called. If you find any place in the Python3 docs that does call them bytestrings please submit a bug report. On 01/07/2014 08:12 AM, Steven D'Aprano wrote: > People trying to port these libraries from 2.7 to 3 run into this problem, > and it causes them grief. This little difference between bytes in 2.7 and > bytes in 3.x is a point of friction which makes porting harder, and I'm > trying to understand the reason for it. If I recall correctly the way it was explained to me: bytes (lists, arrays, etc.) is a container, and when a container is indexed you get whatever the container held. If you slice the container you get a smaller container with the appropriate items. bytes (and bytearrays) are containers of ints, so indexing returns an int. One big problem with this whole scenario is that bytes then lies about what it contains. (And I hate lies! [1]) Anyway, I believe that's the rationale behind the change. -- ~Ethan~ [1] http://www.quickmeme.com/meme/3ts325 From python at mrabarnett.plus.com Tue Jan 7 13:22:28 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 07 Jan 2014 18:22:28 +0000 Subject: [Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?] In-Reply-To: References: <52C9B39F.6060205@stoneleaf.us> <87fvp1idip.fsf@uwakimon.sk.tsukuba.ac.jp> <1389009153.31778.YahooMailNeo@web181001.mail.ne1.yahoo.com> <87bnzphs7j.fsf@uwakimon.sk.tsukuba.ac.jp> <20140107154401.GK29356@ando> Message-ID: <52CC45E4.7010400@mrabarnett.plus.com> On 2014-01-07 17:46, Andrew Barnert wrote: > I think Stephen's name "7-bit" is confusing people. If you try to > interpret the name sensibly, you get Steven's broken interpretation. > But if you read it as a nonsense word and work through the logic, it > all makes sense. > > On Jan 7, 2014, at 7:44, Steven D'Aprano wrote: > I was thinking about Ethan's suggestion of introducing a new bytestring class and a lot of these suggestions are what I thought the bytestring class could do. [snip] >> >> Suppose we take a pure-ASCII byte-string and decode it: >> >> b'abcd'.decode('ascii-compatible') >> That would be: bytestring(b'abcd') or even: bytestring('abcd') [snip] > >> Suppose we take a byte-string with a non-ASCII byte: >> >> b'abc\xFF'.decode('ascii-compatible') >> That would be: bytestring(b'abc\xFF') Bytes outside the ASCII range would be mapped to Unicode low surrogates: bytestring(b'abc\xFF') == bytestring('abc\uDCFF') [snip] >> Presumably they will compare equal, yes? > > I would hope not. One of them has the Unicode character U+FF, the > other has smuggled byte 0xFF, so they'd better not compare equal. > > However, the latter should compare equal to 'abc\uDCFF'. That's the > entire key here: the new representation is nothing but a more compact > way to represent strings that contain nothing but ASCII and surrogate > escapes. > [snip] >> >> A concrete example: >> >> s = b'abcd'.decode('ascii-compatible') >> t = 'x' # ASCII-compatible >> s + t >> => returns 'abcdx', with the "7-bit repr" flag cleared. s = bytestring(b'abcd') t = 'x' # ASCII-compatible s + t => returns 'abcdx' > > Right. Here both s and t are normal 8-bit strings reprs in the first > place, so the new logic doesn't even get invoked. So yes, that's what > it returns. > >> s = b'abcd'.decode('ascii-compatible') >> t = '?' # U+00FF, non-ASCII. >> >> s + t >> => returns 'abcd\uDCFF', with the "7-bit repr" flag set s = bytestring(b'abcd') t = '?' # U+00FF, non-ASCII. s + t => returns 'abcd\xFF' [snip] There were also some other equivalences I was considering: bytestring(b'abc') == b'abc' bytestring(b'abc') == 'abc' The problem there is that it wouldn't be transitive because: b'abc' != 'abc' From ethan at stoneleaf.us Tue Jan 7 13:38:40 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 07 Jan 2014 10:38:40 -0800 Subject: [Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?] In-Reply-To: <52CC45E4.7010400@mrabarnett.plus.com> References: <52C9B39F.6060205@stoneleaf.us> <87fvp1idip.fsf@uwakimon.sk.tsukuba.ac.jp> <1389009153.31778.YahooMailNeo@web181001.mail.ne1.yahoo.com> <87bnzphs7j.fsf@uwakimon.sk.tsukuba.ac.jp> <20140107154401.GK29356@ando> <52CC45E4.7010400@mrabarnett.plus.com> Message-ID: <52CC49B0.2090406@stoneleaf.us> On 01/07/2014 10:22 AM, MRAB wrote: > On 2014-01-07 17:46, Andrew Barnert wrote: >> On Jan 7, 2014, at 7:44, Steven D'Aprano wrote: >> > I was thinking about Ethan's suggestion of introducing a new bytestring > class and a lot of these suggestions are what I thought the bytestring > class could do. >>> >>> Suppose we take a pure-ASCII byte-string and decode it: >>> >>> b'abcd'.decode('ascii-compatible') >>> > That would be: > > bytestring(b'abcd') > > or even: > > bytestring('abcd') > > [snip] >> >>> Suppose we take a byte-string with a non-ASCII byte: >>> >>> b'abc\xFF'.decode('ascii-compatible') >>> > That would be: > > bytestring(b'abc\xFF') > > Bytes outside the ASCII range would be mapped to Unicode low > surrogates: > > bytestring(b'abc\xFF') == bytestring('abc\uDCFF') Not sure what you mean here. The resulting bytes should be 'abc\xFF' and of length 4. -- ~Ethan~ From storchaka at gmail.com Tue Jan 7 14:48:24 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Tue, 07 Jan 2014 21:48:24 +0200 Subject: Bytes indexing returns an int In-Reply-To: <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: 07.01.14 18:12, Steven D'Aprano ???????(??): > In Python 2.7, if you have a > chunk of binary data, you can easily do this: > > data = b'\xE1\xE2\xE3\xE4' > data[0] == b'\xE1' > > and it returns True just as expected. data[0] == b'\xE1'[0] works as expected in both Python 2.7 and 3.x. From rzantow at gmail.com Tue Jan 7 14:49:01 2014 From: rzantow at gmail.com (Rzed) Date: Tue, 07 Jan 2014 14:49:01 -0500 Subject: Difficulty with ez_setup.py Message-ID: I am trying to run ez_setup.py on a fresh installation of Python 2.7.6 in a Win XP environment, but I keep getting an error. Here's the traceback: C:\Python27\Lib>python ez_setup.py Extracting in c:\docume~1\dick\locals~1\temp\tmpkjidy0 Now working in c:\docume~1\dick\locals~1\temp\tmpkjidy0\setuptools-2.0.2 Installing Setuptools Traceback (most recent call last): File "setup.py", line 17, in exec(init_file.read(), command_ns) File "", line 8, in File "c:\docume~1\dick\locals~1\temp\tmpkjidy0\setuptools-2.0.2\setuptools\__init__.py", line 11, in from setuptools.extension import Extension File "c:\docume~1\dick\locals~1\temp\tmpkjidy0\setuptools-2.0.2\setuptools\extension.py", line 5, in from setuptools.dist import _get_unpatched File "c:\docume~1\dick\locals~1\temp\tmpkjidy0\setuptools-2.0.2\setuptools\dist.py", line 16, in import pkg_resources File "c:\docume~1\dick\locals~1\temp\tmpkjidy0\setuptools-2.0.2\pkg_resources.py", line 31, in from pkgutil import get_importer ImportError: cannot import name get_importer Something went wrong during the installation. See the error message above. It's been awhile since I last installed ez_install, and I remember it being a pain, but I don't remember this issue. What am I doing wrong? On a possibly related note, is there a specific place that ez_setup.py is expected to be in when this is run? -- rzed From aerojunkemail at gmail.com Tue Jan 7 14:53:45 2014 From: aerojunkemail at gmail.com (aerojunkemail at gmail.com) Date: Tue, 7 Jan 2014 11:53:45 -0800 (PST) Subject: django question In-Reply-To: <8ba0b041-ffc6-419d-883d-d2efdfdfadf9@googlegroups.com> References: <20140104193705.0db361cc@bigbox.christie.dr> <8ba0b041-ffc6-419d-883d-d2efdfdfadf9@googlegroups.com> Message-ID: <41332301-50e1-465e-8760-754af656cc08@googlegroups.com> Django is great On Tuesday, January 7, 2014 12:55:07 AM UTC-7, CM wrote: > On Monday, January 6, 2014 8:57:22 PM UTC-5, Roy Smith wrote: > > > > > Yes, exactly. There's nothing magic about a django view. It's just a > > > function which is passed an instance of HttpRequest (and possibly a few > > > other things, depending on your url mapping), and which is expected to > > > return an instance of HttpResponse. Within that framework, it can call > > > any other functions it wants. > > > > > > For example, http://legalipsum.com/ is a silly little site I built in > > > django. Here's the view for the home page: > > > > Nice! > > > > > Notice how the view knows nothing about generating the actual markov > > > text. That's in another module, which lives somewhere on my PYTHONPATH. > > > ALso, the view knows nothing about how the page is laid out; only the > > > templates know that. If I decided to redo this in tornado or flask, > > > whatever, I would need to rewrite my view, but there's not much to > > > rewrite. Most of the logic is in the Markov chainer, and that would > > > cary over to the new implementation unchanged. > > > > > > BTW, my suggestion to keep business logic and presentation code distinct > > > isn't unique to django, it's a good idea in pretty much all systems. > > > > Thanks for these points, helpful to see in practice. I'm trying to be > > more mindful of good coding practices, and this will be helpful as I continue > > to learn Django and making web applications generally. From ben+python at benfinney.id.au Tue Jan 7 16:54:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 08 Jan 2014 08:54:21 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2D94.9040401@gmail.com> Message-ID: <7wfvozfofm.fsf@benfinney.id.au> Michael Torrie writes: > On 01/05/2014 04:30 PM, Ben Finney wrote: > > In short: Everything that was good about OpenOffice is now called > > LibreOffice, which had to change its name only because the owners of > > that name refused to let it go. > > Your information is a year or two out of date. [?] I'm aware of the facts you listed, and they don't change what I stated above. > They really need to merge back into one project again, but I suspect > they won't either for ideological or legal reasons. The former is very > sad and not a good commentary on the viability of open source > software. On the contrary: It's a sad commentary on what happens to any software project under a centralised party that loses interest in it and just sits on it for years. The fact that we have the vibrant free-software office suites we now have is a testament to the strength of free software ? the developers were able to rescue the project from the grip of a corporation that would never have freed it otherwise. Chris Angelico writes: > Sad. This is yet another of those politically-charged distinctions > that, quite frankly, I have no interest in. I raised the point because you're giving advice to others on which software to use. If you have no interest in the distinctions, perhaps you should cultivate such an interest to know what software you're referring to when advising others. -- \ ?With Lisp or Forth, a master programmer has unlimited power | `\ and expressiveness. With Python, even a regular guy can reach | _o__) for the stars.? ?Raymond Hettinger | Ben Finney From timothy.c.delaney at gmail.com Tue Jan 7 17:38:51 2014 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Wed, 8 Jan 2014 09:38:51 +1100 Subject: Blog "about python 3" In-Reply-To: <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> References: <52c1dc4c$0$2877$c3e8da3$76491128@news.astraweb.com> <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Message-ID: On 8 January 2014 00:34, wrote: > > Point 2: This Flexible String Representation does no > "effectuate" any memory optimization. It only succeeds > to do the opposite of what a corrrect usage of utf* > do. > UTF-8 is a variable-width encoding that uses less memory to encode code points with lower numerical values, on a per-character basis e.g. if a code point <= U+007F it will use a single byte to encode; if <= U+07FF two bytes will be used; ... up to a maximum of 6 bytes for code points >= U+4000000. FSR is a variable-width memory structure that uses the width of the code point with the highest numerical value in the string e.g. if all code points in the string are <= U+00FF a single byte will be used per character; if all code points are <= U+FFFF two bytes will be used per character; and in all other cases 4 bytes will be used per character. In terms of memory usage the difference is that UTF-8 varies its width per-character, whereas the FSR varies its width per-string. For any particular string, UTF-8 may well result in using less memory than the FSR, but in other (quite common) cases the FSR will use less memory than UTF-8 e.g. if the string contains only contains code points <= U+00FF, but some are between U+0080 and U+00FF (inclusive). In most cases the FSR uses the same or less memory than earlier versions of Python 3 and correctly handles all code points (just like UTF-8). In the cases where the FSR uses more memory than previously, the previous behaviour was incorrect. No matter which representation is used, there will be a certain amount of overhead (which is the majority of what most of your examples have shown). Here are examples which demonstrate cases where UTF-8 uses less memory, cases where the FSR uses less memory, and cases where they use the same amount of memory (accounting for the minimum amount of overhead required for each). Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> >>> fsr = u"" >>> utf8 = fsr.encode("utf-8") >>> min_fsr_overhead = sys.getsizeof(fsr) >>> min_utf8_overhead = sys.getsizeof(utf8) >>> min_fsr_overhead 49 >>> min_utf8_overhead 33 >>> >>> fsr = u"\u0001" * 1000 >>> utf8 = fsr.encode("utf-8") >>> sys.getsizeof(fsr) - min_fsr_overhead 1000 >>> sys.getsizeof(utf8) - min_utf8_overhead 1000 >>> >>> fsr = u"\u0081" * 1000 >>> utf8 = fsr.encode("utf-8") >>> sys.getsizeof(fsr) - min_fsr_overhead 1024 >>> sys.getsizeof(utf8) - min_utf8_overhead 2000 >>> >>> fsr = u"\u0001\u0081" * 1000 >>> utf8 = fsr.encode("utf-8") >>> sys.getsizeof(fsr) - min_fsr_overhead 2024 >>> sys.getsizeof(utf8) - min_utf8_overhead 3000 >>> >>> fsr = u"\u0101" * 1000 >>> utf8 = fsr.encode("utf-8") >>> sys.getsizeof(fsr) - min_fsr_overhead 2025 >>> sys.getsizeof(utf8) - min_utf8_overhead 2000 >>> >>> fsr = u"\u0101\u0081" * 1000 >>> utf8 = fsr.encode("utf-8") >>> sys.getsizeof(fsr) - min_fsr_overhead 4025 >>> sys.getsizeof(utf8) - min_utf8_overhead 4000 Indexing a character in UTF-8 is O(N) - you have to traverse the the string up to the character being indexed. Indexing a character in the FSR is O(1). In all cases the FSR has better performance characteristics for indexing and slicing than UTF-8. There are tradeoffs with both UTF-8 and the FSR. The Python developers decided the priorities for Unicode handling in Python were: 1. Correctness a. all code points must be handled correctly; b. it must not be possible to obtain part of a code point (e.g. the first byte only of a multi-byte code point); 2. No change in the Big O characteristics of string operations e.g. indexing must remain O(1); 3. Reduced memory use in most cases. It is impossible for UTF-8 to meet both criteria 1b and 2 without additional auxiliary data (which uses more memory and increases complexity of the implementation). The FSR meets all 3 criteria. Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From kpippus at gmx.com Tue Jan 7 18:03:55 2014 From: kpippus at gmx.com (kpippus at gmx.com) Date: Tue, 7 Jan 2014 15:03:55 -0800 (PST) Subject: RFD: pt.comp.lang.python Message-ID: ? ? ? ? ? ? ? ? ? REQUEST FOR DISCUSSION (RFD) ? ? ? ? ? ? ?unmoderated group pt.comp.lang.python This is a formal Request for Discussion (RFD) for the creation of the unmoderated newsgroup pt.comp.lang.python. NEWSGROUPS LINE: pt.comp.lang.python???????Portuguese version of comp.lang.python newsgroup RATIONALE: Portuguese is the seventh most spoken language in the world with around 215 million native speakers in all continents, and the third most spoken in Europe. Python is taught in most universities from Angola to Brazil, not only in Computer Science (CS) courses but mostly in biological sciences (e.g., biopython is used to teach genome and proteome sequence analysis), earth sciences (python is widely used as a scripting language in open source GIS software), statistics (numpy, pandas), etc. The focus of most courses outside CS is neither on developing programming skills nor on python as a language, resulting in huge deficiencies in python programming, and many questions remain unanswered. This is more so in developing countries such as Mozambique, Guinea-Bissau, Cape verde, etc. where the english language is neither well spoken nor read. For those reasons, I propose the creation of the pt.comp.lang.python newsgroup, similar to it.comp.lang.python, es.comp.lang.python or de.comp.lang.python. CHARTER: The newsgroup pt.comp.lang.python is intended for general discussions and questions about Python with some flexibility for more general programming topics (e.g. software design) all using the Portuguese language. Posters to this newsgroup are asked to refrain from harrassment, personal attacks, and disruptive communication. Articles containing binary computer files including, but not limited to, programs or images, are forbidden. HTML posts are discouraged. Users should exercise their best judgement and use consideration for the copyright laws of their country. If in doubt, ask. PROCEDURE: For more information on the newsgroup creation process, please see: ? http://www.big-8.org/wiki/How_to_Create_a_New_Big-8_Newsgroup Those who wish to influence the development of this RFD and its final resolution should subscribe to news.groups.proposals and participate in the relevant threads in that newsgroup. ?This is both a courtesy to groups in which discussion of creating a new group is off-topic as well as the best method of making sure that one's comments or criticisms are heard. All discussion of active proposals should be posted to news.groups.proposals To this end, the followup header of this RFD has been set to news.groups.proposals. If desired by the readership of closely affected groups, the discussion may be crossposted to those groups, but care must be taken to ensure that all discussion appears in news.groups.proposals as well. We urge those who would like to read or post in the proposed newsgroup to make a comment to that effect in this thread; we ask proponents to keep a list of such positive posts with the relevant message ID. Such lists of positive feedback for the proposal may constitute good evidence that the group will be well-used if it is created. DISTRIBUTION: This document has been posted to the following newsgroups: ? news.announce.newgroups ? news.groups.proposals ? comp.lang.python PROPONENT: C?sar Ribeiro From tjreedy at udel.edu Tue Jan 7 19:02:22 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 07 Jan 2014 19:02:22 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Message-ID: On 1/7/2014 9:54 AM, Terry Reedy wrote: > On 1/7/2014 8:34 AM, wxjmfauth at gmail.com wrote: >> Le dimanche 5 janvier 2014 23:14:07 UTC+1, Terry Reedy a ?crit : > >>> Memory: Point 2. A *design goal* of FSR was to save memory relative to >>> UTF-32, which is what you apparently prefer. Your examples show that FSF >>> successfully met its design goal. But you call that success, saving >>> memory, 'wrong'. On what basis? > >> Point 2: This Flexible String Representation does no >> "effectuate" any memory optimization. It only succeeds >> to do the opposite of what a corrrect usage of utf* >> do. > > Since the FSF *was* successful in saving memory, and indeed shrank the > Python binary by about a megabyte, I have no idea what you mean. Tim Delaney apparently did, and answered on the basis of his understanding. Note that I said that the design goal was 'save memory RELATIVE TO UTF-32', not 'optimize memory'. UTF-8 was not considered an option. Nor was any form of arithmetic coding https://en.wikipedia.org/wiki/Arithmetic_coding to truly 'optimize memory'. -- Terry Jan Reedy From rosuav at gmail.com Tue Jan 7 19:09:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 11:09:32 +1100 Subject: [OT] Migrating from non-free programs to LibreOffice In-Reply-To: <7wfvozfofm.fsf@benfinney.id.au> References: <7wfvp2gg6v.fsf_-_@benfinney.id.au> <52CC2D94.9040401@gmail.com> <7wfvozfofm.fsf@benfinney.id.au> Message-ID: On Wed, Jan 8, 2014 at 8:54 AM, Ben Finney wrote: > Chris Angelico writes: > >> Sad. This is yet another of those politically-charged distinctions >> that, quite frankly, I have no interest in. > > I raised the point because you're giving advice to others on which > software to use. If you have no interest in the distinctions, perhaps > you should cultivate such an interest to know what software you're > referring to when advising others. The mention of OpenOffice was extremely tangential. I was simply making a point about there being a "best option" that's hard to attain (but probably worthwhile long-term) and a "next-best option" that's less of a jump for the end user. If you take that original post and switch the name OpenOffice to Libre Office, it will not make a penn'orth of difference to the argument. If I were giving advice in that post, the advice being given was surely "use LaTeX". ChrisA From steve+comp.lang.python at pearwood.info Tue Jan 7 19:15:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Wed, 08 Jan 2014 11:15:10 +1100 Subject: Bytes indexing returns an int References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> Ethan Furman wrote: > On 01/07/2014 07:19 AM, David Robinow wrote: >> >> Python 3 grudgingly allows the "abomination" of byte strings (is that >> what they're called?) > > No, that is *not* what they're called. If you find any place in the > Python3 docs that does call them bytestrings please submit a bug report. The name of the class is "bytes", but what they represent *is* a string of bytes, hence "byte-string". It's a standard computer science term for distinguishing strings of text from strings of bytes. > On 01/07/2014 08:12 AM, Steven D'Aprano wrote: >> People trying to port these libraries from 2.7 to 3 run into this >> problem, and it causes them grief. This little difference between bytes >> in 2.7 and bytes in 3.x is a point of friction which makes porting >> harder, and I'm trying to understand the reason for it. > > If I recall correctly the way it was explained to me: > > bytes (lists, arrays, etc.) is a container, and when a container is > indexed you get whatever the container held. If you slice the container > you get a smaller container with the appropriate items. (There's also a bytearray type, which is best considered as an array. Hence the name.) Why decide that the bytes type is best considered as a list of bytes rather than a string of bytes? It doesn't have any list methods, it looks like a string and people use it as a string. As you have discovered, it is an inconvenient annoyance that indexing returns an int instead of a one-byte byte-string. I think that, in hindsight, this was a major screw-up in Python 3. > bytes (and bytearrays) are containers of ints, so indexing returns an int. > One big problem with this whole scenario is > that bytes then lies about what it contains. (And I hate lies! [1]) > > Anyway, I believe that's the rationale behind the change. > > -- > ~Ethan~ > > [1] http://www.quickmeme.com/meme/3ts325 -- Steven From rosuav at gmail.com Tue Jan 7 19:30:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 11:30:49 +1100 Subject: Bytes indexing returns an int In-Reply-To: <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 8, 2014 at 11:15 AM, Steven D'Aprano wrote: > Why decide that the bytes type is best considered as a list of > bytes rather than a string of bytes? It doesn't have any list methods, it > looks like a string and people use it as a string. As you have discovered, > it is an inconvenient annoyance that indexing returns an int instead of a > one-byte byte-string. > > I think that, in hindsight, this was a major screw-up in Python 3. Which part was? The fact that it can be represented with a (prefixed) quoted string? bytes_value = (41, 42, 43, 44) string = bytes_value.decode() # "ABCD" I think it's more convenient to let people use a notation similar to what was used in Py2, but perhaps this is an attractive nuisance, if it gives rise to issues like this. If a bytes were more like a tuple of ints (not a list - immutability is closer) than it is like a string, would that be clearer? Perhaps the solution isn't even a code one, but a mental one. "A bytes is like a tuple of ints" might be a useful mantra. ChrisA From ethan at stoneleaf.us Tue Jan 7 19:37:08 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 07 Jan 2014 16:37:08 -0800 Subject: Bytes indexing returns an int In-Reply-To: <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52CC9DB4.1040502@stoneleaf.us> On 01/07/2014 04:15 PM, Steven D'Aprano wrote: > Ethan Furman wrote: >> On 01/07/2014 07:19 AM, David Robinow wrote: >>> >>> Python 3 grudgingly allows the "abomination" of byte strings (is that >>> what they're called?) >> >> No, that is *not* what they're called. If you find any place in the >> Python3 docs that does call them bytestrings please submit a bug report. > > The name of the class is "bytes", but what they represent *is* a string of > bytes, hence "byte-string". It's a standard computer science term for > distinguishing strings of text from strings of bytes. I do not disagree with your statements, yet calling the bytes type a bytestring suggests things which are not true, such as indexing returning another bytestring. The core-dev have thus agreed to not call it that in the documentation in hopes of lessening any confusion. >> On 01/07/2014 08:12 AM, Steven D'Aprano wrote: >>> People trying to port these libraries from 2.7 to 3 run into this >>> problem, and it causes them grief. This little difference between bytes >>> in 2.7 and bytes in 3.x is a point of friction which makes porting >>> harder, and I'm trying to understand the reason for it. >> >> If I recall correctly the way it was explained to me: >> >> bytes (lists, arrays, etc.) is a container, and when a container is >> indexed you get whatever the container held. If you slice the container >> you get a smaller container with the appropriate items. > > (There's also a bytearray type, which is best considered as an array. Hence > the name.) Why decide that the bytes type is best considered as a list of > bytes rather than a string of bytes? It doesn't have any list methods, it > looks like a string and people use it as a string. As you have discovered, > it is an inconvenient annoyance that indexing returns an int instead of a > one-byte byte-string. > > I think that, in hindsight, this was a major screw-up in Python 3. The general consensus seems to be agreement (more or less) with that feeling, but alas it is too late to change it now. -- ~Ethan~ From invalid at invalid.invalid Tue Jan 7 21:34:29 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Jan 2014 02:34:29 +0000 (UTC) Subject: Bytes indexing returns an int References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-01-08, Chris Angelico wrote: > On Wed, Jan 8, 2014 at 11:15 AM, Steven D'Aprano > wrote: >> Why decide that the bytes type is best considered as a list of >> bytes rather than a string of bytes? It doesn't have any list methods, it >> looks like a string and people use it as a string. As you have discovered, >> it is an inconvenient annoyance that indexing returns an int instead of a >> one-byte byte-string. >> >> I think that, in hindsight, this was a major screw-up in Python 3. > > Which part was? The fact that b'ASDF'[0] in Python2 yeilds something different than it does in Python3 -- one yields b'A' and the other yields 0x41. It makes portable code a lot harder to write. I don't really have any preference for one over the other, but changing it for no apparent reason was a horrible idea. -- Grant From xahlee at gmail.com Tue Jan 7 22:30:18 2014 From: xahlee at gmail.com (Xah Lee) Date: Tue, 7 Jan 2014 19:30:18 -0800 (PST) Subject: Programing Challenge: Constructing a Tree Given Its Edges. Message-ID: Programing Challenge: Constructing a Tree Given Its Edges. Show you are the boss. http://xahlee.info/perl-python/python_construct_tree_from_edge.html here's plain text. ?????????? ?????????? ?????????? ?????????? ?????????? Problem: given a list of edges of a tree: [child, parent], construct the tree. Here's a sample input: [[0, 2], [3, 0], [1, 4], [2, 4]]. Here's a sample print of a tree data structure: 4 1 2 0 3 this means, the root node's name is 4. It has 2 branches, named 1 and 2. The branche named 2 has 1 children, named 0, and it has one children named 3. The node's names are given as integers, but you can assume them to be strings. You can choose your own data structure for the output. For example, nested list with 1st element being the node name, or use nested hash of hash, where key is the node name, and value is its children. Here's sample data structure in python, using hash of hash. { "4": { "1": {}, "2": { "0": { "3": {} } } } } Other data structure are accepted. Code it using your favorite language. I'll be able to look at and verify in Mathematica, Python, Ruby, Perl, PHP, JavaScript, Emacs Lisp, Java. But other langs, such as Clojure and other lisps, OCaml, Haskell, erlang, Fortress, APL, HOL, Coq, Lua, Factor, Rust, Julia ? are very welcome. ?? Proliferation of Computing Languages? You should be able to do this within 8 hours from scratch. Took me 5 hours. Python solution will be posted in a week, on 2014-01-14 (or sooner if many showed solutions). Post your solution in comment (or link to github or pastebin). From rosuav at gmail.com Tue Jan 7 22:46:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 14:46:24 +1100 Subject: Bytes indexing returns an int In-Reply-To: References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc988f$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Jan 8, 2014 at 1:34 PM, Grant Edwards wrote: > On 2014-01-08, Chris Angelico wrote: >>> I think that, in hindsight, this was a major screw-up in Python 3. >> >> Which part was? > > The fact that b'ASDF'[0] in Python2 yeilds something different than it > does in Python3 -- one yields b'A' and the other yields 0x41. Fair enough. Either can be justified, changing is awkward. ChrisA From phil at riverbankcomputing.com Wed Jan 8 01:33:38 2014 From: phil at riverbankcomputing.com (Phil Thompson) Date: Wed, 08 Jan 2014 06:33:38 +0000 Subject: ANN: PyQt v5.2 Released Message-ID: <69bd17ff4486d1800198a172f30e1775@www.riverbankcomputing.com> PyQt5 v5.2 has been released and is available from http://www.riverbankcomputing.com/software/pyqt/download5. PyQt5 is a comprehensive set of bindings for v5 of Digia's Qt cross-platform application framework. It supports Python v3, v2.7 and v2.6. The highlights of this release include full support for Qt v5.2, and the QtBluetooth, QtPositioning, QtMacExtras, QtWinExtras and QtX11Extras modules. Windows installers are provided which contain everything needed for PyQt5 development (including Qt, Qt Designer, QScintilla, and MySQL, PostgreSQL, SQLite and ODBC drivers) except Python itself. Installers are provided for the 32 and 64 bit versions of Python v3.3. PyQt5 is implemented as a set of 27 extension modules including support for: - non-GUI infrastructure including event loops, threads, i18n, user and application settings, mapped files and shared memory - GUI infrastructure including window system integration, event handling, 2D graphics, basic imaging, fonts, OpenGL - a comprehensive set of desktop widgets - WebKit - full integration with Quick2 and QML allowing new Quick items to be implemented in Python and created in QML - event driven network programming - multimedia including cameras, audio and radios - Bluetooth - global positioning using satellite, Wi-Fi or text file sources - sensors including accelerometers, altimeters, compasses, gyroscopes, magnetometers, and light, pressure, proximity, rotation and temperature sensors - serial ports - SQL - printing - DBus - XPath, XQuery, XSLT and XML Schema validation - a help system for creating and viewing searchable documentation - unit testing of GUI applications. From breamoreboy at yahoo.co.uk Wed Jan 8 02:50:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 07:50:03 +0000 Subject: python finance In-Reply-To: <437pc9dflako932br6j3nuu3ps9lj5ppn6@4ax.com> References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> <4bef9196-be41-4f1e-a904-d098952053bf@googlegroups.com> <437pc9dflako932br6j3nuu3ps9lj5ppn6@4ax.com> Message-ID: On 08/01/2014 00:32, Dennis Lee Bieber wrote: > On Tue, 7 Jan 2014 11:04:11 +1100, Chris Angelico > declaimed the following: > >> "Python finance" could also be interpreted in many other ways, >> including "I want to write a finance application in Python", and "How >> does the PSF get its money?". >> > Or a misplaced need for funding to support a pet Burmese Python > Or European? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve at pearwood.info Wed Jan 8 03:33:03 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 08 Jan 2014 08:33:03 GMT Subject: "More About Unicode in Python 2 and 3" References: <201401060932.35410.gheskett@wdtv.com> <201401061617.06746.gheskett@wdtv.com> Message-ID: <52cd0d3f$0$2877$c3e8da3$76491128@news.astraweb.com> On Mon, 06 Jan 2014 22:41:26 +0000, Nicholas Cole wrote: [...] > Like everyone else, when Python 3 came out I was nervous. A lot of my > code broke - but it broke for a good reason. I had been being cavalier > about strings and ASCII and bytes. A lot of my code was working by > accident rather than by design, or because my users had never fed it > anything that would make it fall over. Of course, my first reaction was > a defensive one, but once I had got over that and got my head around > Python 3's view of the world, I was pleased I had. ... Well said! -- Steven From wxjmfauth at gmail.com Wed Jan 8 04:59:48 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 8 Jan 2014 01:59:48 -0800 (PST) Subject: Blog "about python 3" In-Reply-To: References: <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Message-ID: Le mercredi 8 janvier 2014 01:02:22 UTC+1, Terry Reedy a ?crit?: > On 1/7/2014 9:54 AM, Terry Reedy wrote: > > > On 1/7/2014 8:34 AM, wxjmfauth at gmail.com wrote: > > >> Le dimanche 5 janvier 2014 23:14:07 UTC+1, Terry Reedy a ?crit : > > > > > >>> Memory: Point 2. A *design goal* of FSR was to save memory relative to > > >>> UTF-32, which is what you apparently prefer. Your examples show that FSF > > >>> successfully met its design goal. But you call that success, saving > > >>> memory, 'wrong'. On what basis? > > > > > >> Point 2: This Flexible String Representation does no > > >> "effectuate" any memory optimization. It only succeeds > > >> to do the opposite of what a corrrect usage of utf* > > >> do. > > > > > > Since the FSF *was* successful in saving memory, and indeed shrank the > > > Python binary by about a megabyte, I have no idea what you mean. > > > > Tim Delaney apparently did, and answered on the basis of his > > understanding. Note that I said that the design goal was 'save memory > > RELATIVE TO UTF-32', not 'optimize memory'. UTF-8 was not considered an > > option. Nor was any form of arithmetic coding > > https://en.wikipedia.org/wiki/Arithmetic_coding > > to truly 'optimize memory'. > > The FSR acts more as an coding scheme selector than as a code point optimizer. Claiming that it saves memory is some kind of illusion; a little bit as saying "Py2.7 uses "relatively" less memory than Py3.2 (UCS-2)". >>> sys.getsizeof('a' * 10000 + 'z') 10026 >>> sys.getsizeof('a' * 10000 + '?') 20040 >>> sys.getsizeof('a' * 10000 + '\U00010000') 40044 >>> sys.getsizeof('?' * 10000 + '?') 20040 >>> sys.getsizeof('?' * 10000 + '\U00010000') 40044 >>> sys.getsizeof('\U00010000' * 10000 + '\U00010000') 40044 jmf From robin at reportlab.com Wed Jan 8 06:05:49 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 08 Jan 2014 11:05:49 +0000 Subject: Bytes indexing returns an int In-Reply-To: References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52CD310D.6060308@chamonix.reportlab.co.uk> On 07/01/2014 19:48, Serhiy Storchaka wrote: ........ > data[0] == b'\xE1'[0] works as expected in both Python 2.7 and 3.x. > > I have been porting a lot of python 2 only code to a python2.7 + 3.3 version for a few months now. Bytes indexing was a particular problem. PDF uses quite a lot of single byte indicators so code like if text[k] == 'R': ..... or dispatch_dict.get(text[k],error)() is much harder to make compatible because of this issue. I think this change was a mistake. To get round this I have tried the following class to resurrect the old style behaviour if isPy3: class RLBytes(bytes): '''simply ensures that B[x] returns a bytes type object and not an int''' def __getitem__(self,x): if isinstance(x,int): return RLBytes([bytes.__getitem__(self,x)]) else: return RLBytes(bytes.__getitem__(self,x)) I'm not sure if that covers all possible cases, but it works for my dispatching cases. Unfortunately you can't do simple class assignment to change the behaviour so you have to copy the text. I find a lot of the "so glad we got rid of byte strings" fervour a bit silly. Bytes, chars, words etc etc were around long before unicode. Byte strings could already represent unicode in efficient ways that happened to be useful for western languages. Having two string types is inconvenient and error prone, swapping their labels and making subtle changes is a real pain. -- Robin Becker From ayushpokharna at gmail.com Wed Jan 8 06:27:00 2014 From: ayushpokharna at gmail.com (ayushpokharna at gmail.com) Date: Wed, 8 Jan 2014 03:27:00 -0800 (PST) Subject: Editor for Python In-Reply-To: <3bfd7f87@news.airtel.net> References: <3bfd7f87@news.airtel.net> Message-ID: <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ wrote: > Hello, > I'm looking for an editor for Python.I' m interested it works on Windows.Can > anybody help me? > > Thank you > > Manuel From jeanmichel at sequans.com Wed Jan 8 07:23:56 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 8 Jan 2014 13:23:56 +0100 (CET) Subject: Editor for Python In-Reply-To: <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: <643637232.3190289.1389183836637.JavaMail.root@sequans.com> ----- Original Message ----- > On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ > wrote: > > Hello, > > I'm looking for an editor for Python.I' m interested it works on > > Windows.Can > > anybody help me? > > > > Thank you > > > > Manuel http://lmgtfy.com/?q=python+editor+windows Otherwise, must of the newcomers will be pleased with http://notepad-plus-plus.org/ Ideally, try to use an editor that will allow you to edit any type of code, python or anything else. JM PS : you could also have searched this archive, this subject has been already discussed... a lot. -- 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 faassen at startifact.com Wed Jan 8 07:36:18 2014 From: faassen at startifact.com (Martijn Faassen) Date: Wed, 08 Jan 2014 13:36:18 +0100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> Message-ID: <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Hi there, On 01/07/2014 06:00 PM, Chris Angelico wrote: > I'm still not sure how Python 2.8 needs to differ from 2.7. Maybe the > touted upgrade path is simply a Python 2.7 installer plus a few handy > libraries/modules that will now be preinstalled? These modules look > great (I can't say, as I don't have a huge Py2 codebase to judge based > on), and they presumably work on the existing Pythons. Well, in the original article I argue that it may be risky for the Python community to leave the large 2.7 projects behind because they tend to be the ones that pay us in the end. I also argue that for those projects to move anywhere, they need a clear, blessed, official, as simple as possible, incremental upgrade path. That's why I argue for a Python 2.8. Pointing out the 'future' module is existence proof that further incremental steps could be taken on top of what Python 2.7 already does. I may be that these points are wrong or should be weighed differently. It's possible that: * the risk of losing existing big 2.x projects is low, they'll port anyway, the money will keep flowing into our community, they won't look at other languages, etc. * these big 2.x projects are going to all find the 'future' module themselves and use it as incremental upgrade path, so there's no need for a new blessed Python 2.x. * the approach of the 'future' module turns out to be fatally flawed and/or doesn't really help with incremental upgrades after all. But that's how I reason about it, and how I weigh things. I think the current strategy is risky. Regards, Martijn From rosuav at gmail.com Wed Jan 8 07:46:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 8 Jan 2014 23:46:14 +1100 Subject: the Gravity of Python 2 In-Reply-To: <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Wed, Jan 8, 2014 at 11:36 PM, Martijn Faassen wrote: > Well, in the original article I argue that it may be risky for the Python > community to leave the large 2.7 projects behind because they tend to be the > ones that pay us in the end. > > I also argue that for those projects to move anywhere, they need a clear, > blessed, official, as simple as possible, incremental upgrade path. That's > why I argue for a Python 2.8. > > Pointing out the 'future' module is existence proof that further incremental > steps could be taken on top of what Python 2.7 already does. Yep, but suppose it were simply that the future module is blessed as the official, simple, incremental upgrade path. That doesn't violate PEP 404, it allows the future module to continue to be expanded without worrying about the PSF's schedules (more stuff might be added to it in response to Python 3.5, but this is all in the hands of future's maintainer), and it should be relatively simple to produce an installer that goes and grabs it. I'm all in favour of changes that don't require core support :) Let's see how much can be done without touching the Python language in any way at all. Maybe it'll turn out that there's some tiny change to Python that would facilitate a huge improvement in commonality, but we won't know without first trying to solve the problem under the restriction of "there will be no Py2.8". As Mark Rosewater is fond of saying, restrictions breed creativity. Can the porting community take the PEP 404 restriction and be creative within it? I suspect it'll go a long way. ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 8 08:01:29 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 09 Jan 2014 00:01:29 +1100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> Martijn Faassen wrote: > I also argue that for those projects to move anywhere, they need a > clear, blessed, official, as simple as possible, incremental upgrade > path. That's why I argue for a Python 2.8. That incremental upgrade path is Python 2.7. Remember, when Python 3 first came out, the current version of Python was 2.5. 2.6 came out roughly simultaneously with Python 3. So the expected upgrade path is: "Bleeding edge" adaptors: 2.5 -> 3.0 Early adaptors: 2.5 -> 2.6 -> 3.1 or 3.2 Slower adaptors: 2.5 -> 2.6 -> 2.7 -> 3.3 or 3.4 Late adaptors: 2.5 -> 2.6 -> 2.7 -> 3.5 (expected to be about 18-24 months) Laggards who wait until support for 2.7 is dropped: 2.5 -> 2.6 -> 2.7 -> 3.6 or 3.7 Adding 2.8 doesn't help. It just gives people another excuse to delay migrating. Then, in another two or three years, they'll demand 2.9, and put it off again. Then they'll insist that 15 years wasn't long enough to migrate their code, and demand 2.10. I have no objection to people delaying migrating. There were lots of risks and difficulties in migrating to 3.1 or 3.2, there are fewer risks and difficulties in migrating to 3.3 and 3.4, and there will be even fewer by the time 3.5 and 3.6 come out. People should migrate when they are comfortable. They may even decide to stick to 2.7 for as long as they can find a computer capable of running it, security updates or no security updates. That's all fine. What's not fine though is people holding the rest of us back with their negativity and FUD that Python 3 is a mistake. -- Steven From mailinglists at xgm.de Wed Jan 8 08:14:29 2014 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 08 Jan 2014 14:14:29 +0100 Subject: Trouble with UnicodeEncodeError and email Message-ID: <1566196.GRmDzgaeKX@horus> Hello! I've written some tiny script using Python 3 and it used to work perfectly. Then I realized it needs to run on my Debian Stable server too, which offers only Python 2. Ok, most backporting was a matter of minutes, but I'm becoming desperate on some Unicode error... i use scikit-learn to train a filter on a set of email messages: vectorizer = CountVectorizer(input='filename', decode_error='replace', strip_accents='unicode', preprocessor=self.mail_preprocessor, stop_words='english') http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html The vectorizer gets a list of filenames, reads them and passes them to the preprocessor: def mail_preprocessor(self, message): # Filter POPFile cruft by matching date string at the beginning. print("Type:", type(message)) # imported from __future__ pop_reg = re.compile(r"^[0-9]{4}/[0-1][1-9]/[0-3]?[0-9]") message = [line for line in message.splitlines(True) if not pop_reg.match(line)] xxx = "".join(message) msg = email.message_from_string(xxx) # <-- CRASH here msg_body = "" for part in msg.walk(): if part.get_content_type() in ["text/plain", "text/html"]: body = part.get_payload(decode=True) soup = BeautifulSoup(body) msg_body += soup.get_text(" ", strip=True) if "-----BEGIN PGP MESSAGE-----" in msg_body: msg_body = "" msg_body += " ".join(email.utils.parseaddr(msg["From"])) try: msg_body += " " + msg["Subject"] except TypeError: # Can't convert 'NoneType' object to str implicitly pass msg_body = msg_body.lower() return msg_body Type: Traceback (most recent call last): File "flofify.py", line 182, in main() File "flofify.py", line 161, in main model.train() File "flofify.py", line 73, in train vectors = vectorizer.fit_transform(data[:,1]) File "/usr/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 780, in fit_transform vocabulary, X = self._count_vocab(raw_documents, self.fixed_vocabulary) File "/usr/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 715, in _count_vocab for feature in analyze(doc): File "/usr/lib/python2.7/site-packages/sklearn/feature_extraction/text.py", line 229, in tokenize(preprocess(self.decode(doc))), stop_words) File "flofify.py", line 119, in mail_preprocessor msg = email.message_from_string(xxx) File "/usr/lib/python2.7/email/__init__.py", line 57, in message_from_string return Parser(*args, **kws).parsestr(s) File "/usr/lib/python2.7/email/parser.py", line 82, in parsestr return self.parse(StringIO(text), headersonly=headersonly) UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 1624: ordinal not in range(128) I've tried various modifications like encoding/decoding the message argument to utf-8. Any help? Thanks! Florian From rosuav at gmail.com Wed Jan 8 08:26:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 00:26:15 +1100 Subject: Trouble with UnicodeEncodeError and email In-Reply-To: <1566196.GRmDzgaeKX@horus> References: <1566196.GRmDzgaeKX@horus> Message-ID: On Thu, Jan 9, 2014 at 12:14 AM, Florian Lindner wrote: > I've written some tiny script using Python 3 and it used to work perfectly. Then I realized it needs to run on my Debian Stable server too, which offers only Python 2. Ok, most backporting was a matter of minutes, but I'm becoming desperate on some Unicode error... Are you sure it does? The current Debian stable is Wheezy, which comes with a package 'python3' in the repository, which will install 3.2.3. (The previous Debian stable, Squeeze, has 3.1.3 under the same name.) You may need to change your shebang, but that's all you'd need to do. Or are you unable to install new packages? If so, I strongly recommend getting Python 3 added, as it's going to spare you a lot of Unicode headaches. Mind you, I compile my own Py3 for Wheezy, since I like to be on the bleeding edge. But that's not for everyone. :) ChrisA From breamoreboy at yahoo.co.uk Wed Jan 8 09:08:10 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 14:08:10 +0000 Subject: the Gravity of Python 2 In-Reply-To: <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/01/2014 13:01, Steven D'Aprano wrote: > Martijn Faassen wrote: > >> I also argue that for those projects to move anywhere, they need a >> clear, blessed, official, as simple as possible, incremental upgrade >> path. That's why I argue for a Python 2.8. > > That incremental upgrade path is Python 2.7. > > Remember, when Python 3 first came out, the current version of Python was > 2.5. 2.6 came out roughly simultaneously with Python 3. So the expected > upgrade path is: > > > "Bleeding edge" adaptors: > 2.5 -> 3.0 > > Early adaptors: > 2.5 -> 2.6 -> 3.1 or 3.2 > > Slower adaptors: > 2.5 -> 2.6 -> 2.7 -> 3.3 or 3.4 > > Late adaptors: > 2.5 -> 2.6 -> 2.7 -> 3.5 (expected to be about 18-24 months) > > Laggards who wait until support for 2.7 is dropped: > 2.5 -> 2.6 -> 2.7 -> 3.6 or 3.7 > > Adding 2.8 doesn't help. It just gives people another excuse to delay > migrating. Then, in another two or three years, they'll demand 2.9, and put > it off again. Then they'll insist that 15 years wasn't long enough to > migrate their code, and demand 2.10. > > I have no objection to people delaying migrating. There were lots of risks > and difficulties in migrating to 3.1 or 3.2, there are fewer risks and > difficulties in migrating to 3.3 and 3.4, and there will be even fewer by > the time 3.5 and 3.6 come out. People should migrate when they are > comfortable. They may even decide to stick to 2.7 for as long as they can > find a computer capable of running it, security updates or no security > updates. That's all fine. > > What's not fine though is people holding the rest of us back with their > negativity and FUD that Python 3 is a mistake. > > Big +1 from me to all the above. -- 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 bdurham.com Wed Jan 8 09:11:54 2014 From: python at bdurham.com (python at bdurham.com) Date: Wed, 08 Jan 2014 09:11:54 -0500 Subject: Looking for tips for moving dev environment from Windows to Mac Message-ID: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> Long time Windows developer making the move to Apple platform. My new development environment is a 15" MacBook Pro with 16 Gb RAM and a 512 Gb SSD. I'm totally new to the world of Apple hardware and software and am looking for advice on what apps, utilities and hardware I should consider for my new environment.. Some early questions: 1. Which distribution of Python to install (Python.org, ActivateState, other?) and do I need to do anything special to avoid overwriting the system copy of Python? 2. Text editor: Textmate, BBEdit, Emacs/VI, or other? 3. Multiple external monitors: Any recommendations on monitor specs/models for 2 external monitors for a MacBook? 4. Best visual diff utility for Mac? Any other "gotta have" Mac apps, utilities, or hardware accessories you would recommend? Thank you! Malcolm -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Wed Jan 8 09:15:45 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 14:15:45 +0000 Subject: the Gravity of Python 2 In-Reply-To: <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On 08/01/2014 12:36, Martijn Faassen wrote: > Hi there, > > On 01/07/2014 06:00 PM, Chris Angelico wrote: >> I'm still not sure how Python 2.8 needs to differ from 2.7. Maybe the >> touted upgrade path is simply a Python 2.7 installer plus a few handy >> libraries/modules that will now be preinstalled? These modules look >> great (I can't say, as I don't have a huge Py2 codebase to judge based >> on), and they presumably work on the existing Pythons. > > Well, in the original article I argue that it may be risky for the > Python community to leave the large 2.7 projects behind because they > tend to be the ones that pay us in the end. > > I also argue that for those projects to move anywhere, they need a > clear, blessed, official, as simple as possible, incremental upgrade > path. That's why I argue for a Python 2.8. > > Pointing out the 'future' module is existence proof that further > incremental steps could be taken on top of what Python 2.7 already does. > > I may be that these points are wrong or should be weighed differently. > It's possible that: > > * the risk of losing existing big 2.x projects is low, they'll port > anyway, the money will keep flowing into our community, they won't look > at other languages, etc. > > * these big 2.x projects are going to all find the 'future' module > themselves and use it as incremental upgrade path, so there's no need > for a new blessed Python 2.x. > > * the approach of the 'future' module turns out to be fatally flawed > and/or doesn't really help with incremental upgrades after all. > > But that's how I reason about it, and how I weigh things. I think the > current strategy is risky. > > Regards, > > Martijn > My understanding is that 95% of core developers won't work on 2.8, partly I suspect because of the massive overhead they've already had to do supporting 2 and 3 in parellel. Assuming that I'm correct, who is going to do the work involved, you Martijn? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Wed Jan 8 09:15:35 2014 From: roy at panix.com (Roy Smith) Date: Wed, 08 Jan 2014 09:15:35 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: As somebody who is still firmly in the 2.x world, I'm worried about the idea of a 2.x fork. While I have my doubts that 3.x was a good idea, the fact is, it's here. Having the community fractured between the two camps is not good. Let's say I'm somebody who wants to contribute some OSS. I have three basic choices: 1) I can make it 3.x only. Now, (nominally) half of the python community is unable to realize value from my contribution. 2) I can make it 2.x only. Same thing in reverse. 3) I can make it work on both 2.x and 3.x, which means I'm investing more effort than I had to if it were single platform. Any of those alternatives is worse than ideal. Forking 2.x to create an unofficial 2.8 release would just prolong the situation. As I've stated before, I don't see any urgency in moving to 3.x, and don't imagine doing there for another couple of years, but I absolutely can't imagine moving to a 2.8 fork. From breamoreboy at yahoo.co.uk Wed Jan 8 09:30:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 14:30:20 +0000 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On 08/01/2014 14:15, Roy Smith wrote: > As somebody who is still firmly in the 2.x world, I'm worried about the > idea of a 2.x fork. While I have my doubts that 3.x was a good idea, > the fact is, it's here. Having the community fractured between the two > camps is not good. Let's say I'm somebody who wants to contribute some > OSS. I have three basic choices: > > 1) I can make it 3.x only. Now, (nominally) half of the python > community is unable to realize value from my contribution. > > 2) I can make it 2.x only. Same thing in reverse. > > 3) I can make it work on both 2.x and 3.x, which means I'm investing > more effort than I had to if it were single platform. > > Any of those alternatives is worse than ideal. Forking 2.x to create an > unofficial 2.8 release would just prolong the situation. As I've stated > before, I don't see any urgency in moving to 3.x, and don't imagine > doing there for another couple of years, but I absolutely can't imagine > moving to a 2.8 fork. > The above strikes me as common sense. Surely that's out of place on this list? :) But to be serious why not stick with 2.x if there's no compelling reason to move? Whatever happened to "if it ain't broke, don't fix it"? And before anyone says anything please don't start on about the bytes versus string debate, I'm fairly certain that there are a substantial number of application areas that don't run into these problems. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From douglas.duhaime at gmail.com Wed Jan 8 09:23:44 2014 From: douglas.duhaime at gmail.com (Douglas Duhaime) Date: Wed, 8 Jan 2014 09:23:44 -0500 Subject: Editor for Python In-Reply-To: <643637232.3190289.1389183836637.JavaMail.root@sequans.com> References: <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> <643637232.3190289.1389183836637.JavaMail.root@sequans.com> Message-ID: I've been pleased with Komodo, and certainly prefer it over Notepad++. Komodo: http://www.activestate.com/komodo-ide?gclid=COHE4eLj7rsCFQISMwodOUQAiw On Wed, Jan 8, 2014 at 7:23 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > ----- Original Message ----- > > On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ > > wrote: > > > Hello, > > > I'm looking for an editor for Python.I' m interested it works on > > > Windows.Can > > > anybody help me? > > > > > > Thank you > > > > > > Manuel > > http://lmgtfy.com/?q=python+editor+windows > > Otherwise, must of the newcomers will be pleased with > http://notepad-plus-plus.org/ > > Ideally, try to use an editor that will allow you to edit any type of > code, python or anything else. > > JM > > PS : you could also have searched this archive, this subject has been > already discussed... a lot. > > > -- 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. > -- > https://mail.python.org/mailman/listinfo/python-list > -- Douglas Duhaime Department of English, University of Notre Dame douglasduhaime.com, dduhaime at nd.edu -------------- next part -------------- An HTML attachment was scrubbed... URL: From pedro.larroy.lists at gmail.com Wed Jan 8 09:45:04 2014 From: pedro.larroy.lists at gmail.com (Pedro Larroy) Date: Wed, 8 Jan 2014 15:45:04 +0100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: I think for new projects one should go with 3.x this is the right thing to do. If you require a module that's 2.x only it's easy enough to port it unless it depends on some monster like protobuf which doesn't have python3.x support Pedro. On Wed, Jan 8, 2014 at 3:30 PM, Mark Lawrence wrote: > On 08/01/2014 14:15, Roy Smith wrote: > >> As somebody who is still firmly in the 2.x world, I'm worried about the >> idea of a 2.x fork. While I have my doubts that 3.x was a good idea, >> the fact is, it's here. Having the community fractured between the two >> camps is not good. Let's say I'm somebody who wants to contribute some >> OSS. I have three basic choices: >> >> 1) I can make it 3.x only. Now, (nominally) half of the python >> community is unable to realize value from my contribution. >> >> 2) I can make it 2.x only. Same thing in reverse. >> >> 3) I can make it work on both 2.x and 3.x, which means I'm investing >> more effort than I had to if it were single platform. >> >> Any of those alternatives is worse than ideal. Forking 2.x to create an >> unofficial 2.8 release would just prolong the situation. As I've stated >> before, I don't see any urgency in moving to 3.x, and don't imagine >> doing there for another couple of years, but I absolutely can't imagine >> moving to a 2.8 fork. >> >> > The above strikes me as common sense. Surely that's out of place on this > list? :) > > But to be serious why not stick with 2.x if there's no compelling reason > to move? Whatever happened to "if it ain't broke, don't fix it"? And > before anyone says anything please don't start on about the bytes versus > string debate, I'm fairly certain that there are a substantial number of > application areas that don't run into these problems. > > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 8 09:50:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 01:50:46 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 1:30 AM, Mark Lawrence wrote: > But to be serious why not stick with 2.x if there's no compelling reason to > move? Whatever happened to "if it ain't broke, don't fix it"? And before > anyone says anything please don't start on about the bytes versus string > debate, I'm fairly certain that there are a substantial number of > application areas that don't run into these problems. Two reasons for moving: 1) Support for newer hardware, underlying libraries, etc 2) Bug fixes and security patches. #1 won't be a visible problem for most people - they'll be using a Python packaged by their OS, so if there are any issues with building Python against version X.Y of libfoobar, the OS maintainers will either ship the older version of libfoobar, or make Python work. Only a handful of people (the OS package maintainers themselves) will even need to consider that. So it's #2 that people will be thinking about. There's going to come a time when python.org will no longer provide updates for Python 2.7, and at that point, everyone has to decide which is greater: the risk of undiscovered flaws, or the hassle of shifting. For most end users, they'll choose to stick with an unsupported Python rather than shift, but there are those (corporates, mainly) for whom a promise of bug fixes is critical, so that'd be their date to shift. After all, it worked for Windows XP, right? End-of-life date rolls around and everyone moves onto Windows 7.... hmm, maybe that didn't quite happen. Still, it does put pressure on people. ChrisA From invalid at invalid.invalid Wed Jan 8 10:06:28 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 8 Jan 2014 15:06:28 +0000 (UTC) Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On 2014-01-08, Chris Angelico wrote: > Two reasons for moving: > > 1) Support for newer hardware How does Python 3.x support newer hardware than Python 2.7? -- Grant Edwards grant.b.edwards Yow! Psychoanalysis?? at I thought this was a nude gmail.com rap session!!! From faassen at startifact.com Wed Jan 8 10:08:09 2014 From: faassen at startifact.com (Martijn Faassen) Date: Wed, 08 Jan 2014 16:08:09 +0100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <8630b$52cd69d8$541826b9$20923@cache1.tilbu1.nb.home.nl> On 01/08/2014 01:46 PM, Chris Angelico wrote: > On Wed, Jan 8, 2014 at 11:36 PM, Martijn Faassen wrote: >> Well, in the original article I argue that it may be risky for the Python >> community to leave the large 2.7 projects behind because they tend to be the >> ones that pay us in the end. >> >> I also argue that for those projects to move anywhere, they need a clear, >> blessed, official, as simple as possible, incremental upgrade path. That's >> why I argue for a Python 2.8. >> >> Pointing out the 'future' module is existence proof that further incremental >> steps could be taken on top of what Python 2.7 already does. > > Yep, but suppose it were simply that the future module is blessed as > the official, simple, incremental upgrade path. That doesn't violate > PEP 404, it allows the future module to continue to be expanded > without worrying about the PSF's schedules (more stuff might be added > to it in response to Python 3.5, but this is all in the hands of > future's maintainer), and it should be relatively simple to produce an > installer that goes and grabs it. That would be better than nothing, but would break the: "upgrade path should be totally obvious" guideline. Also the core developers are generally not in the habit of blessing external projects except by taking them into the stdlib, so that'd be a first. > As Mark Rosewater is fond of saying, restrictions breed creativity. > Can the porting community take the PEP 404 restriction and be creative > within it? I suspect it'll go a long way. How many actively maintained applications on Python 2.7 are being ported? Do we know? If not many, is this a problem? As problems also breed creativity. Regards, Martijn From jeanmichel at sequans.com Wed Jan 8 10:13:09 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 8 Jan 2014 16:13:09 +0100 (CET) Subject: Editor for Python In-Reply-To: Message-ID: <1103911247.3232889.1389193989073.JavaMail.root@sequans.com> ----- Original Message ----- > I've been pleased with Komodo, and certainly prefer it over > Notepad++. > Komodo: > http://www.activestate.com/komodo-ide?gclid=COHE4eLj7rsCFQISMwodOUQAiw Komodo is an IDE and costs 385$. I certainly expect it to better than notepad++. 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 alister.ware at ntlworld.com Wed Jan 8 10:19:37 2014 From: alister.ware at ntlworld.com (Alister) Date: Wed, 08 Jan 2014 15:19:37 GMT Subject: Editor for Python References: Message-ID: On Wed, 08 Jan 2014 16:13:09 +0100, Jean-Michel Pichavant wrote: > ----- Original Message ----- > >> I've been pleased with Komodo, and certainly prefer it over Notepad++. > >> Komodo: >> http://www.activestate.com/komodo-ide?gclid=COHE4eLj7rsCFQISMwodOUQAiw > > Komodo is an IDE and costs 385$. I certainly expect it to better than > notepad++. > > JM > I like Geany it is almost & IDE & considerably cheaper (about $385 cheaper if your price is correct :-) ) > > -- 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. too late you have sent this to a public forum -- Harriet's Dining Observation: In every restaurant, the hardness of the butter pats increases in direct proportion to the softness of the bread. From faassen at startifact.com Wed Jan 8 10:22:12 2014 From: faassen at startifact.com (Martijn Faassen) Date: Wed, 08 Jan 2014 16:22:12 +0100 Subject: the Gravity of Python 2 In-Reply-To: <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: Hey, I'm pointing out possible improvements that Python 2.8 could offer that would help incremental porting efforts of applications. I'm pointing about that helping application developers move forward incrementally may be a worthwhile consideration. Like, there's money there. You can point out that 2.6 and 2.7 were already such releases, and I will then point out that many people *have* upgraded their applications to these releases. Is there now going to be a giant leap forward to Python 3 by these projects, or is the jump still too far? Opinions differ. On 01/08/2014 02:01 PM, Steven D'Aprano wrote: > Adding 2.8 doesn't help. It just gives people another excuse to delay > migrating. Then, in another two or three years, they'll demand 2.9, and put > it off again. Then they'll insist that 15 years wasn't long enough to > migrate their code, and demand 2.10. I can play this kind of rhetorical game too, including demands and such fun. Who is demanding who does what? It's not really a surprise that people expect there to be a compatible release of a programming language. We'll have to see whether the demand for it is strong enough to tear out community apart, or whether all will be right in the end. > What's not fine though is people holding the rest of us back with their > negativity and FUD that Python 3 is a mistake. That's not what I believe I've been doing. Though if people do this, is the Python community really so fragile it can't deal with a little bit of pushback? What's not fine is that people who think all is well tell the people who disagree to shut up. Maybe we should introduce the concept of "check your Python 3 privilege". Regards, Martijn From faassen at startifact.com Wed Jan 8 10:26:18 2014 From: faassen at startifact.com (Martijn Faassen) Date: Wed, 08 Jan 2014 16:26:18 +0100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <59bde$52cd6e19$541826b9$25367@cache1.tilbu1.nb.home.nl> Hey, On 01/08/2014 03:30 PM, Mark Lawrence wrote: > But to be serious why not stick with 2.x if there's no compelling reason > to move? Whatever happened to "if it ain't broke, don't fix it"? That's fine for static applications that don't have to change. Successful applications tend to grow new features over the years. It's not fun to do so if new capabilities are growing out of reach in Python 3 land. It's possible if enough features exist in Python 3 land bosses of successful applications will fund a port, with all the risks of introducing bugs that this entails. But a smoother upgrade path would help those applications more. And as I pointed out before, these applications are where a lot of money and development resources are coming from in our community. Of course it's possible my assessment of the importance of these applications, their development resources, and the bump a Python 3 port presents for them, is off. Regards, Martijn From rosuav at gmail.com Wed Jan 8 10:31:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 02:31:00 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 2:06 AM, Grant Edwards wrote: > On 2014-01-08, Chris Angelico wrote: > >> Two reasons for moving: >> >> 1) Support for newer hardware > > How does Python 3.x support newer hardware than Python 2.7? At the moment, I would say there's no difference between those two versions. But there was an issue a short while ago about OS X 10.9 and the compilers/libraries available for it, which necessitated some patches, and those patches would have been applied to all currently-supported versions of Python. That means that 2.7 got them (in 2.7.6 [1]), so it'll build nicely, but 2.6 won't have, so anyone who wants to use 2.6 on 10.9 will have to manually backport that fix. I mention hardware because there are times when the new hardware won't run the old OS, the new OS won't work with the old compiler and/or library, and the new compiler/library won't work with the old Python. At that point, you have to either run a virtual machine (overkill) or remain on the old hardware (hence, Python X.Y doesn't support your hardware). So long as 2.7 is being supported, there are no problems with this. Same with the bug fixes and security patches that I mention in the next line. Once it's out of support, though, both will cease (or they might cease at different times), and then new hardware, new compilers, new versions of required libraries, could cause problems. I elaborated further down that these issues would be mainly dealt with by OS package maintainers (I'm sure Red Hat have been doing this for years), but they'll still be problems. [1] http://www.python.org/download/releases/2.7.6/ ChrisA From rosuav at gmail.com Wed Jan 8 10:39:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 02:39:18 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 9, 2014 at 2:22 AM, Martijn Faassen wrote: > I'm pointing out possible improvements that Python 2.8 could offer that > would help incremental porting efforts of applications. I'm pointing about > that helping application developers move forward incrementally may be a > worthwhile consideration. Like, there's money there. I'm not sure who's actually paying the PSF to develop a 2.8, so I'm not sure why you can say there's money there. Are you offering? Or do you have reason to believe someone else will? > You can point out that 2.6 and 2.7 were already such releases, and I will > then point out that many people *have* upgraded their applications to these > releases. Is there now going to be a giant leap forward to Python 3 by these > projects, or is the jump still too far? Opinions differ. Still waiting for a solid suggestion as to what would actually be different in 2.8 that can't be done with a module. If there's a really brilliant module that massively eases the burden of porting, then python.org / the PSF might well even add it to the stdlib, or at least point people to it from the home page. That would make for an excellent "smooth upgrade" path, dealing with the renamed modules and so on, and it takes no language changes at all. I'm pretty sure most people here are in broad agreement with your goal of making it easy to migrate to Py3. What we're not seeing - or at least, what I'm not seeing - is how a Python 2.8 would achieve that; and what several of us ARE seeing is how a Python 2.8 actually makes it harder. ChrisA From breamoreboy at yahoo.co.uk Wed Jan 8 10:50:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 15:50:03 +0000 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 08/01/2014 15:39, Chris Angelico wrote: > On Thu, Jan 9, 2014 at 2:22 AM, Martijn Faassen wrote: >> I'm pointing out possible improvements that Python 2.8 could offer that >> would help incremental porting efforts of applications. I'm pointing about >> that helping application developers move forward incrementally may be a >> worthwhile consideration. Like, there's money there. > > I'm not sure who's actually paying the PSF to develop a 2.8, so I'm > not sure why you can say there's money there. Are you offering? Or do > you have reason to believe someone else will? > There can be ?1,000,000 in the PSF kitty but if the core developers don't want to do the work it won't happen!!! Personally I still think the whole idea of a 2.8 is nonsense that would only serve to divert already scarce resources. Fixing some of the 4,000 (?) open issues on the bug tracker would come higher up my list, particularly as some of them have been sitting there for ten years. Or how about finally getting the "new" regex module into the standard library? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From wxjmfauth at gmail.com Wed Jan 8 11:08:28 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 8 Jan 2014 08:08:28 -0800 (PST) Subject: Bytes indexing returns an int In-Reply-To: References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> Le mercredi 8 janvier 2014 12:05:49 UTC+1, Robin Becker a ?crit?: > On 07/01/2014 19:48, Serhiy Storchaka wrote: > > ........ > > > data[0] == b'\xE1'[0] works as expected in both Python 2.7 and 3.x. > > > > > > > > I have been porting a lot of python 2 only code to a python2.7 + 3.3 version for > > a few months now. Bytes indexing was a particular problem. PDF uses quite a lot > > of single byte indicators so code like > > > > if text[k] == 'R': > > ..... > > > > or > > > > dispatch_dict.get(text[k],error)() > > > > is much harder to make compatible because of this issue. I think this change was > > a mistake. > > > > To get round this I have tried the following class to resurrect the old style > > behaviour > > > > if isPy3: > > class RLBytes(bytes): > > '''simply ensures that B[x] returns a bytes type object and not an int''' > > def __getitem__(self,x): > > if isinstance(x,int): > > return RLBytes([bytes.__getitem__(self,x)]) > > else: > > return RLBytes(bytes.__getitem__(self,x)) > > > > I'm not sure if that covers all possible cases, but it works for my dispatching > > cases. Unfortunately you can't do simple class assignment to change the > > behaviour so you have to copy the text. > > > > I find a lot of the "so glad we got rid of byte strings" fervour a bit silly. > > Bytes, chars, words etc etc were around long before unicode. Byte strings could > > already represent unicode in efficient ways that happened to be useful for > > western languages. Having two string types is inconvenient and error prone, > > swapping their labels and making subtle changes is a real pain. > > -- -- Byte strings (encoded code points) or native unicode is one thing. But on the other side, the problem is elsewhere. These very talented ascii narrow minded, unicode illiterate devs only succeded to produce this (I, really, do not wish to be rude). >>> import unicodedata >>> unicodedata.name('?') 'LATIN SMALL LETTER A WITH DIAERESIS AND MACRON' >>> sys.getsizeof('a') 26 >>> sys.getsizeof('?') 40 >>> timeit.timeit("unicodedata.normalize('NFKD', '?')", "import unicodedata") 0.8040018888575129 >>> timeit.timeit("unicodedata.normalize('NFKD', 'zzz')", "import unicodedata") 0.3073749330963995 >>> timeit.timeit("unicodedata.normalize('NFKD', 'z')", "import unicodedata") 0.2874013282653962 >>> >>> timeit.timeit("len(unicodedata.normalize('NFKD', 'zzz'))", "import unicodedata") 0.3803570633857589 >>> timeit.timeit("len(unicodedata.normalize('NFKD', '?'))", "import unicodedata") 0.9359970320201683 pdf, typography, linguistic, scripts, ... in mind, in other word the real *unicode* world. jmf From jeanmichel at sequans.com Wed Jan 8 10:53:09 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 8 Jan 2014 16:53:09 +0100 (CET) Subject: Editor for Python In-Reply-To: Message-ID: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> > > -- 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. > > too late you have sent this to a public forum No pb with that, the python list is the intended recipient :) I tried to negotiate this with my IT guys, but it looks like it's now mandatory, something related to being in the USA stock market. I have no way to remove it, it's added by the email server. I apologise for the noise. 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 Wed Jan 8 11:40:47 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Wed, 8 Jan 2014 11:40:47 -0500 Subject: Editor for Python In-Reply-To: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> References: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> Message-ID: On Wed, Jan 8, 2014 at 10:53 AM, Jean-Michel Pichavant < jeanmichel at sequans.com> wrote: > > > -- 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. > > > > too late you have sent this to a public forum > > No pb with that, the python list is the intended recipient :) > > I tried to negotiate this with my IT guys, but it looks like it's now > mandatory, something related to being in the USA stock market. > I have no way to remove it, it's added by the email server. I apologise > for the noise. > Two thoughts: maybe create a gmail account, and What is wrong with this world that some over paid lawyer requires a useless, silly statement to justify his employment. The money that person is being paid should be given to someone else. > > 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. > > -- > https://mail.python.org/mailman/listinfo/python-list > > -- Joel Goldstick http://joelgoldstick.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From alec.taylor6 at gmail.com Wed Jan 8 11:46:05 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Thu, 9 Jan 2014 03:46:05 +1100 Subject: Suggest an open-source log analyser? In-Reply-To: References: Message-ID: So yeah, if you know of a good one; please share. Thanks On Sun, Jan 5, 2014 at 2:50 PM, Alec Taylor wrote: > Because I'm thinking that something with a much less expressive query > interface would serve me better in the long run... e.g.: Redis or > maybe Hadoop > > On Sat, Jan 4, 2014 at 5:35 PM, Walter Hurry wrote: >> On Thu, 02 Jan 2014 16:40:19 +1100, Alec Taylor wrote: >> >>> I use the Python logger class; with the example syntax of: >>> Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') >>> >>> Can of course easily use e.g.: a JSON syntax here instead. >>> >>> Are there any open-source log viewers (e.g.: with a web-interface) >>> that you'd recommend; for drilling down into my logs? >>> >> If you want to do in-depth analysis, why not just stick it into an SQL >> database; e.g. SQLite or Postgres? >> >> -- >> https://mail.python.org/mailman/listinfo/python-list From wrw at mac.com Wed Jan 8 10:45:56 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 08 Jan 2014 10:45:56 -0500 Subject: Looking for tips for moving dev environment from Windows to Mac In-Reply-To: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> References: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> Message-ID: <1611C8AA-18D1-427D-A578-89C8A7AA94F4@mac.com> On Jan 8, 2014, at 9:11 AM, python at bdurham.com wrote: > Long time Windows developer making the move to Apple platform. My new development environment is a 15" MacBook Pro with 16 Gb RAM and a 512 Gb SSD. I'm totally new to the world of Apple hardware and software and am looking for advice on what apps, utilities and hardware I should consider for my new environment.. Welcome to the world of Macs, OS-X, and Darwin. > > Some early questions: > > 1. Which distribution of Python to install (Python.org, ActivateState, other?) and do I need to do anything special to avoid overwriting the system copy of Python? > The answer to this is going to depend on exactly what you are intending to do. ActiveState (for example) has what may well be the best totally integrated package of libraries (GUI, numpy, mathplotlib, and such), but has a pretty expensive license if you are going to do commercial development. Tell us more if you want a better recommendation. > 2. Text editor: Textmate, BBEdit, Emacs/VI, or other? > At the risk of setting off a religious war; I use BBEdit (have used it for years, and have been very pleased with its speed, power, regular updates, and integration with the OS). There is strong support for other editors on this list, I'm sure you will hear from supporters of vi, Emacs, and Vim. > 3. Multiple external monitors: Any recommendations on monitor specs/models for 2 external monitors for a MacBook? I use Apple monitors, but that's strictly personal. > > 4. Best visual diff utility for Mac? BBEdit has a nice built-in diff with side-by-side scrolling windows. When combined with its code-folding, multi-file search, and built-in python support, it makes a nice package. > > Any other "gotta have" Mac apps, utilities, or hardware accessories you would recommend? Two external disks. One dedicated to TimeMachine for continuous backups of code as you write it, and one dedicated to either CarbonCopy Cloner or SuperDuper. Whichever you choose, set it up to do once-a-week clones at say 2:00 AM Sunday. Modern Mac's are just as hard to crash as any other modern UNIX-derived system, and Mac laptops continue to top Consumer Reports list of trouble-free systems, but ANY hardware can develop problems and it pays to be paranoid. Again, welcome. -Bill > > Thank you! > Malcolm > -- > https://mail.python.org/mailman/listinfo/python-list From kwpolska at gmail.com Wed Jan 8 11:50:02 2014 From: kwpolska at gmail.com (=?UTF-8?B?Q2hyaXMg4oCcS3dwb2xza2HigJ0gV2Fycmljaw==?=) Date: Wed, 8 Jan 2014 17:50:02 +0100 Subject: Editor for Python In-Reply-To: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> References: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> Message-ID: On Wed, Jan 8, 2014 at 4:53 PM, Jean-Michel Pichavant wrote: > I tried to negotiate this with my IT guys, but it looks like it's now mandatory, something related to being in the USA stock market. > I have no way to remove it, it's added by the email server. I apologise for the noise. But you have a way to hide it for people whose clients do support that. Simply, instead of signing your letters with ?JM? yourself and having your employer add this spam, simply have your mail client add the sequence below as your signature. Some clients offer adding the separator automatically and you only have to type JM in the signature field. The ?magical? sequence is: -- \nJM (that is 0x2D 2D 20 0A 4A 4D, with a trailing space) > 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. > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Chris ?Kwpolska? Warrick PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense From rosuav at gmail.com Wed Jan 8 11:52:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 03:52:21 +1100 Subject: Editor for Python In-Reply-To: References: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> Message-ID: On Thu, Jan 9, 2014 at 3:40 AM, Joel Goldstick wrote: > What is wrong with this world that some over paid lawyer requires a useless, > silly statement to justify his employment. The money that person is being > paid should be given to someone else. Good luck. Guess who would be suing you for wrongful dismissal? :) I'm not sure those sorts of footers are enforceable or of any value, but they keep on popping up. Gmail at my end will happily fold it down as repeated/quoted text, so it doesn't bother me more than once per thread (usually), so hey, if it keeps the lawyers from hassling someone, I'm not fussed. ChrisA From rosuav at gmail.com Wed Jan 8 12:07:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 04:07:50 +1100 Subject: Looking for tips for moving dev environment from Windows to Mac In-Reply-To: <1611C8AA-18D1-427D-A578-89C8A7AA94F4@mac.com> References: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> <1611C8AA-18D1-427D-A578-89C8A7AA94F4@mac.com> Message-ID: On Thu, Jan 9, 2014 at 2:45 AM, William Ray Wing wrote: > Two external disks. One dedicated to TimeMachine for continuous backups of code as you write it, and one dedicated to either CarbonCopy Cloner or SuperDuper. Whichever you choose, set it up to do once-a-week clones at say 2:00 AM Sunday. Modern Mac's are just as hard to crash as any other modern UNIX-derived system, and Mac laptops continue to top Consumer Reports list of trouble-free systems, but ANY hardware can develop problems and it pays to be paranoid. That's one option. I prefer to put anything that's even vaguely important into a git repository, toss a remote clone of it onto one of my servers, and commit and push every change. (And if it's important, I'll clone that on another machine and pull, so I have a minimum of three copies.) It's a bit more work, a bit more manual, but it gives me versioning, backups, cryptographic hash checksums, notes ("Why the bleep did you do that, Past-Me?!?"), and replication, all in one tidy package. I don't know how much disk space you need for the two backup systems you describe there, but the size of a full-history repository isn't going to be huge, unless you're constantly editing big binary files. ChrisA From ned at nedbatchelder.com Wed Jan 8 12:19:03 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 08 Jan 2014 12:19:03 -0500 Subject: Bytes indexing returns an int In-Reply-To: <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> Message-ID: On 1/8/14 11:08 AM, wxjmfauth at gmail.com wrote: > Byte strings (encoded code points) or native unicode is one > thing. > > But on the other side, the problem is elsewhere. These very > talented ascii narrow minded, unicode illiterate devs only > succeded to produce this (I, really, do not wish to be rude). If you don't want to be rude, you are failing. You've been told a number of times that your obscure micro-benchmarks are meaningless. Now you've taken to calling the core devs narrow-minded and Unicode illiterate. They are neither of these things. Continuing to post these comments with no interest in learning is rude. Other recent threads have contained details rebuttals of your views, which you have ignored. This is rude. Please stop. --Ned. > >>>> import unicodedata >>>> unicodedata.name('?') > 'LATIN SMALL LETTER A WITH DIAERESIS AND MACRON' >>>> sys.getsizeof('a') > 26 >>>> sys.getsizeof('?') > 40 >>>> timeit.timeit("unicodedata.normalize('NFKD', '?')", "import unicodedata") > 0.8040018888575129 >>>> timeit.timeit("unicodedata.normalize('NFKD', 'zzz')", "import unicodedata") > 0.3073749330963995 >>>> timeit.timeit("unicodedata.normalize('NFKD', 'z')", "import unicodedata") > 0.2874013282653962 >>>> >>>> timeit.timeit("len(unicodedata.normalize('NFKD', 'zzz'))", "import unicodedata") > 0.3803570633857589 >>>> timeit.timeit("len(unicodedata.normalize('NFKD', '?'))", "import unicodedata") > 0.9359970320201683 > > pdf, typography, linguistic, scripts, ... in mind, in other word the real > *unicode* world. > > jmf > -- Ned Batchelder, http://nedbatchelder.com From torriem at gmail.com Wed Jan 8 12:25:09 2014 From: torriem at gmail.com (Michael Torrie) Date: Wed, 08 Jan 2014 10:25:09 -0700 Subject: Bytes indexing returns an int In-Reply-To: <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> Message-ID: <52CD89F5.90309@gmail.com> On 01/08/2014 09:08 AM, wxjmfauth at gmail.com wrote: > Byte strings (encoded code points) or native unicode is one > thing. Byte strings are not necessarily "encoded code points." Most byte streams I work with are definitely not unicode! They are in fact things such as BER-encoded ASN.1 data structures. Or PDF data streams. Or Gzip data streams. This issue in this thread has nothing to do with unicode. From bobjects at gmail.com Wed Jan 8 12:26:55 2014 From: bobjects at gmail.com (Bob Hartwig) Date: Wed, 8 Jan 2014 11:26:55 -0600 Subject: Looking for tips for moving dev environment from Windows to Mac In-Reply-To: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> References: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> Message-ID: "4. Best visual diff utility for Mac?" opendiff. I think it's part of xcode. Regarding Python IDEs, I really like PyCharm. It's written in Java, and sometimes you can tell that by its performance, but it's very featureful and has a great debugger, and your 16 GB box should support it nicely. Bob On Wed, Jan 8, 2014 at 8:11 AM, wrote: > Long time Windows developer making the move to Apple platform. My new > development environment is a 15" MacBook Pro with 16 Gb RAM and a 512 Gb > SSD. I'm totally new to the world of Apple hardware and software and am > looking for advice on what apps, utilities and hardware I should consider > for my new environment.. > > Some early questions: > > 1. Which distribution of Python to install (Python.org, ActivateState, > other?) and do I need to do anything special to avoid overwriting the > system copy of Python? > > 2. Text editor: Textmate, BBEdit, Emacs/VI, or other? > > 3. Multiple external monitors: Any recommendations on monitor specs/models > for 2 external monitors for a MacBook? > > 4. Best visual diff utility for Mac? > > Any other "gotta have" Mac apps, utilities, or hardware accessories you > would recommend? > > Thank you! > Malcolm > > -- > https://mail.python.org/mailman/listinfo/python-list > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mailinglists at xgm.de Wed Jan 8 13:09:19 2014 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 08 Jan 2014 19:09:19 +0100 Subject: Trouble with UnicodeEncodeError and email In-Reply-To: References: <1566196.GRmDzgaeKX@horus> Message-ID: <7896764.kr2SOXGTGt@horus> Am Donnerstag, 9. Januar 2014, 00:26:15 schrieb Chris Angelico: > On Thu, Jan 9, 2014 at 12:14 AM, Florian Lindner wrote: > > I've written some tiny script using Python 3 and it used to work perfectly. Then I realized it needs to run on my Debian Stable server too, which offers only Python 2. Ok, most backporting was a matter of minutes, but I'm becoming desperate on some Unicode error... > > Are you sure it does? The current Debian stable is Wheezy, which comes > with a package 'python3' in the repository, which will install 3.2.3. > (The previous Debian stable, Squeeze, has 3.1.3 under the same name.) > You may need to change your shebang, but that's all you'd need to do. > Or are you unable to install new packages? If so, I strongly recommend > getting Python 3 added, as it's going to spare you a lot of Unicode > headaches. > > Mind you, I compile my own Py3 for Wheezy, since I like to be on the > bleeding edge. But that's not for everyone. :) Well, I thought I had scanned to repos but obviously... I had to install BeautifulSoup and scikit-learn manually. Now some other Unicode issues have arised, but I need to sort them out first how they are connected to my mail delivery agent. Thx a lot, Florian From mailinglists at xgm.de Wed Jan 8 13:20:24 2014 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 08 Jan 2014 19:20:24 +0100 Subject: argparse action on default values Message-ID: <7353849.WXZ0zEZ0QV@horus> Hello, I use argparse from Python 3.3.3 with a custom action that normalizes path arguments: http://docs.python.org/3/library/argparse.html#action def norm_path(*parts): """ Returns the normalized, absolute, expanded and joined path, assembled of all parts. """ parts = [ str(p) for p in parts ] return os.path.abspath(os.path.expanduser(os.path.join(*parts))) # Taken from the docs class NormPath(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): print('%r %r %r' % (namespace, values, option_string)) setattr(namespace, self.dest, norm_path(values)) def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--config", help="Path to config file.", default = "~/.foobar/config", action=NormPath) return parser.parse_args() This works fine when there is actually a --config=path supplied. But it's not being applied on default arguments. Of course, I could use "default = norm_path('~/.foobar/config')" but I expect that custom actions are applied to default values as well. The store action works alike for default and supplied values. What do you think? Florian From carlos at zocko.com Wed Jan 8 13:23:38 2014 From: carlos at zocko.com (carlos at zocko.com) Date: Wed, 8 Jan 2014 10:23:38 -0800 (PST) Subject: Looking for Django/Python programmer in Jakarta Message-ID: <86ed6503-7e5e-4838-89fb-07bd947256e6@googlegroups.com> For working in a startup environment. Immediate incorporation. Please send your CV to talent at zocko.com From wrw at mac.com Wed Jan 8 13:32:19 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 08 Jan 2014 13:32:19 -0500 Subject: Looking for tips for moving dev environment from Windows to Mac In-Reply-To: References: <1389190314.4596.68121689.217AAEE5@webmail.messagingengine.com> Message-ID: <70469153-E812-4278-AFFC-301D1D9E4E29@mac.com> On Jan 8, 2014, at 12:26 PM, Bob Hartwig wrote: > "4. Best visual diff utility for Mac?" > > opendiff. I think it's part of xcode. > > Regarding Python IDEs, I really like PyCharm. It's written in Java, and sometimes you can tell that by its performance, but it's very featureful and has a great debugger, and your 16 GB box should support it nicely. > > Bob > Malcom - I didn't mention IDE's since you didn't explicitly ask, but I use WingIDE (and no, I have NO relationship with the company), and have been very pleased by the company's responsiveness and help. They have a free trial you can download and versions with three levels of capabilities, sophistication, and price. These range from student (free) through personal and professional. -Bill -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Wed Jan 8 13:53:11 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Jan 2014 19:53:11 +0100 Subject: argparse action on default values References: <7353849.WXZ0zEZ0QV@horus> Message-ID: Florian Lindner wrote: > I use argparse from Python 3.3.3 with a custom action that normalizes path arguments: > > http://docs.python.org/3/library/argparse.html#action > > def norm_path(*parts): > """ Returns the normalized, absolute, expanded and joined path, assembled of all parts. """ > parts = [ str(p) for p in parts ] This looks odd. > return os.path.abspath(os.path.expanduser(os.path.join(*parts))) > > # Taken from the docs > class NormPath(argparse.Action): > def __call__(self, parser, namespace, values, option_string=None): > print('%r %r %r' % (namespace, values, option_string)) > setattr(namespace, self.dest, norm_path(values)) > > > def parse_args(): > parser = argparse.ArgumentParser() > parser.add_argument("--config", help="Path to config file.", > default = "~/.foobar/config", action=NormPath) > > return parser.parse_args() > > > This works fine when there is actually a --config=path supplied. But it's not being applied on default arguments. Of course, I could use "default = norm_path('~/.foobar/config')" but I expect that custom actions are applied to default values as well. The store action works alike for default and supplied values. > > What do you think? Maybe you should specify type rather than action? $ cat tmp.py import argparse p = argparse.ArgumentParser() p.add_argument("--foo", default="42", type=int) print(p.parse_args()) $ python3.3 tmp.py --foo=123 Namespace(foo=123) $ python3.3 tmp.py Namespace(foo=42) From martin at jakis.adres.em Wed Jan 8 13:51:26 2014 From: martin at jakis.adres.em (Bischoop) Date: Wed, 08 Jan 2014 18:51:26 +0000 Subject: Dictionary References: Message-ID: Dennis Lee Bieber wrote: > On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop > declaimed the following: > >>I have a txt file with some words, and need simply program that will >>print me words containing provided letters. >> >>For example: >>Type the letters: >> (I type: g,m,o) >>open the dictionary.txt >>check words containing:g,m,o in dictionary.txt >>if there are words containing: ["g", "m", "o" ] >>print words with g,m,o > > Vague requirement... > > Do you need: > 1 any word containing any single letter > 2 any word containing all supplied letters (is there a limit on how many > letters?) > 3 any word containing the supplied letters in the entered order, but not > necessarily adjacent to each other > 4 any word containing the supplied letters in adjacent sequence > 5 any word that begins with the supplied sequence of letters 1.yes 2. Any combination with supplied letters. It would be great if possible that I could set also the combination for example: show me all words with: l,x 3. the order doesn't matter 4. doesnt matter 5 doesnt matter. From martin at jakis.adres.em Wed Jan 8 14:00:02 2014 From: martin at jakis.adres.em (Bischoop) Date: Wed, 08 Jan 2014 19:00:02 +0000 Subject: Dictionary References: Message-ID: Walter Hurry wrote: > On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop wrote: > >> I have a txt file with some words, and need simply program that will >> print me words containing provided letters. >> >> For example: >> Type the letters: >> (I type: g,m,o) >> open the dictionary.txt >> check words containing:g,m,o in dictionary.txt >> if there are words containing: ["g", "m", "o" ] >> print words with g,m,o > > Well, what have you tried so far, and what result did you get? > > The incredibly helpful people here will provide advice, guidance and > pointers, but it won't help you at all if they just do your homework for > you. Honestly Im newbie in Python, years ago (10 already) I wrote simply program something like a TEST: Capitals of Countries. You could learn the capitals of some countries, and then you could try to solve a test. I know it's seems so simply for you guys but I was quite pride of myself :-) Now because of free time I took my book which I used years ago about python and try to learn it again, and as motivation I try to write the program I described above just to give me a kick :-), however got no idea how to start it, I meand there is so many moduls (import this, import that), I know how to open, read file etc. Just stuck with that, got no clue what and how use this that what I need to seek the words from the files if I need a words with letters I want. From tjreedy at udel.edu Wed Jan 8 14:26:55 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 14:26:55 -0500 Subject: Blog "about python 3" In-Reply-To: References: <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Message-ID: On 1/8/2014 4:59 AM, wxjmfauth at gmail.com wrote: [responding to me] > The FSR acts more as an coding scheme selector That is what PEP 393 describes and what I and many others have said. The FSR saves memory by selecting from three choices the most compact coding scheme for each string. I ask again, have you read PEP 393? If you are going to critique the FSR, you should read its basic document. > than as a code point optimizer. I do not know what you mean by 'code point optimizer'. > Claiming that it saves memory is some kind of illusion; Do you really think that the mathematical fact "10026 < 20040 < 40044" (from your example below) is some kind of illusion? If so, please take your claim to a metaphysics list. If not, please stop trolling. > a little bit as saying "Py2.7 uses "relatively" less memory than > Py3.2 (UCS-2)". This is inane as 2.7 and 3.2 both use the same two coding schemes. Saying '1 < 2' is different from saying '2 < 2'. On 3.3+ >>>> sys.getsizeof('a' * 10000 + 'z') > 10026 >>>> sys.getsizeof('a' * 10000 + '?') > 20040 >>>> sys.getsizeof('a' * 10000 + '\U00010000') > 40044 3.2- wide (UCS-4) builds use about 40050 bytes for all three unicode strings. One again, you have posted examples that show how FSR saves memory, thus negating your denial of the saving. -- Terry Jan Reedy From drobinow at gmail.com Wed Jan 8 14:50:16 2014 From: drobinow at gmail.com (David Robinow) Date: Wed, 8 Jan 2014 14:50:16 -0500 Subject: Editor for Python In-Reply-To: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> References: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> Message-ID: <413939E4-4BE5-4923-A96D-18C8E28A0E0C@gmail.com> On Jan 8, 2014, at 10:53 AM, Jean-Michel Pichavant wrote: >>> -- IMPORTANT NOTICE: >>> >> >> too late you have sent this to a public forum > > No pb with that, the python list is the intended recipient :) > > I tried to negotiate this with my IT guys, but it looks like it's now mandatory, something related to being in the USA stock market. Yeah, when in doubt blame the Americans. > I have no way to remove it, it's added by the email server. I apologise for the noise. Maybe you should try Google Groups. From roy at panix.com Wed Jan 8 14:52:10 2014 From: roy at panix.com (Roy Smith) Date: Wed, 8 Jan 2014 14:52:10 -0500 Subject: Recover handle to shadowed builtin? Message-ID: <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> I'm working with ipython's pylab mode, which replaces the builtin sum() with the one from numpy: In [105]: sum Out[105]: Is there any way to recover a reference to the builtin sum()? --- Roy Smith roy at panix.com From axis.of.weasel at gmail.com Wed Jan 8 14:56:42 2014 From: axis.of.weasel at gmail.com (axis.of.weasel at gmail.com) Date: Wed, 8 Jan 2014 11:56:42 -0800 (PST) Subject: Understanding decorator and class methods Message-ID: can someone please explain why the following works, in contrast to the second example? def decorator(func): def on_call(*args): print args return func(args) return on_call class Foo: @decorator def bar(self, param1): print 'inside bar' f=Foo() f.bar(4) # from where is the decorator getting the Foo instance? I understand why the following works/does not work class decorator2: def __init__(self, func): self.func=func def __call__(self, *args): self.func(*args) class Foo2: @decorator2 def bar2(self, param): pass f2 = Foo2() Foo2.bar2(f2, 4) # works, Foo2 instance and param are passed to decorator2 call f2.bar2(4) # does not work, Foo2 instance is missing, decorator2 cannot invoke method bar From breamoreboy at yahoo.co.uk Wed Jan 8 15:04:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 20:04:06 +0000 Subject: Blog "about python 3" In-Reply-To: <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> References: <52C1F5EC.3020808@stoneleaf.us> <52c29416$0$29987$c3e8da3$5496439d@news.astraweb.com> <52c6415c$0$29972$c3e8da3$5496439d@news.astraweb.com> <52C6AD00.5050000@chamonix.reportlab.co.uk> <3519f85e-0909-4f5a-9a6e-09b6fd4c312d@googlegroups.com> <2fbf4f89-caaa-4fab-8d7e-ff7ef84029a2@googlegroups.com> Message-ID: On 07/01/2014 13:34, wxjmfauth at gmail.com wrote: > Le dimanche 5 janvier 2014 23:14:07 UTC+1, Terry Reedy a ?crit : > > Ned : this has already been explained and illustrated. > > jmf > This has never been explained and illustrated. Roughly 30 minutes ago Terry Reedy once again completely shot your argument about memory usage to pieces. You did not bother to respond to the comments from Tim Delaney made almost one day ago. Please give up. -- 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 Jan 8 15:11:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 20:11:52 +0000 Subject: Recover handle to shadowed builtin? In-Reply-To: <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> References: <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> Message-ID: On 08/01/2014 19:52, Roy Smith wrote: > I'm working with ipython's pylab mode, which replaces the builtin sum() with the one from numpy: > > In [105]: > sum > > Out[105]: > > > Is there any way to recover a reference to the builtin sum()? > > > --- > Roy Smith > roy at panix.com > Grab it from here I suppose. >>> help(__builtins__.sum) Help on built-in function sum in module __builtin__: ... -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Wed Jan 8 15:15:25 2014 From: roy at panix.com (Roy Smith) Date: 8 Jan 2014 15:15:25 -0500 Subject: Recover handle to shadowed builtin? References: Message-ID: In article , Roy Smith wrote: >I'm working with ipython's pylab mode, which replaces the builtin sum() = >with the one from numpy: >[...] >Is there any way to recover a reference to the builtin sum()? Sigh. I figured this out myself. What you want is __builtins__.sum ... BUT, not only does pylab overwrite sum(), it overwrites __builtins__ as well! Instead of a module, it's now a dict. You can still get at the builtin sum, but you need to do __builtins__["sum"] ======================================================== $ ipython Python 2.7.3 (default, Aug 1 2012, 05:14:39) Type "copyright", "credits" or "license" for more information. IPython 0.12.1 -- An enhanced Interactive Python. [...] In [1]: type(__builtins__) Out[1]: module ======================================================== $ ipython --pylab Python 2.7.3 (default, Aug 1 2012, 05:14:39) Type "copyright", "credits" or "license" for more information. IPython 0.12.1 -- An enhanced Interactive Python. [...] In [1]: type(__builtins__) Out[1]: dict ======================================================== I am slowly coming to the conclusion that the best way to deal with pylab is to not use it. Overwriting sum() with a different sum() I can accept, as a useful shortcut. Overwriting __builtins__ seems like wanton vandalism of the namespace. From breamoreboy at yahoo.co.uk Wed Jan 8 15:15:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 20:15:34 +0000 Subject: Editor for Python In-Reply-To: <413939E4-4BE5-4923-A96D-18C8E28A0E0C@gmail.com> References: <66750528.3238875.1389196389622.JavaMail.root@sequans.com> <413939E4-4BE5-4923-A96D-18C8E28A0E0C@gmail.com> Message-ID: On 08/01/2014 19:50, David Robinow wrote: > > On Jan 8, 2014, at 10:53 AM, Jean-Michel Pichavant wrote: > >>>> -- IMPORTANT NOTICE: >>>> >>> >>> too late you have sent this to a public forum >> >> No pb with that, the python list is the intended recipient :) >> >> I tried to negotiate this with my IT guys, but it looks like it's now mandatory, something related to being in the USA stock market. > Yeah, when in doubt blame the Americans. >> I have no way to remove it, it's added by the email server. I apologise for the noise. > Maybe you should try Google Groups. > Why not, it works fine provided people pay a little attention, and follow the instructions that others have kindly placed on the Python wiki to help resolve problems, repeated again for anyone who needs them https://wiki.python.org/moin/GoogleGroupsPython -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From __peter__ at web.de Wed Jan 8 15:24:37 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 08 Jan 2014 21:24:37 +0100 Subject: Recover handle to shadowed builtin? References: <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> Message-ID: Roy Smith wrote: > I'm working with ipython's pylab mode, which replaces the builtin sum() > with the one from numpy: > > In [105]: > sum > > Out[105]: > > > Is there any way to recover a reference to the builtin sum()? >>> from numpy import * >>> sum >>> del sum >>> sum Doing it more than once does no harm: >>> del sum Traceback (most recent call last): File "", line 1, in NameError: name 'sum' is not defined >>> sum From tjreedy at udel.edu Wed Jan 8 15:45:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 15:45:16 -0500 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On 1/8/2014 9:15 AM, Roy Smith wrote: > As somebody who is still firmly in the 2.x world, I'm worried about the > idea of a 2.x fork. While I have my doubts that 3.x was a good idea, > the fact is, it's here. Having the community fractured between the two > camps is not good. Let's say I'm somebody who wants to contribute some > OSS. I have three basic choices: > > 1) I can make it 3.x only. Now, (nominally) half of the python > community is unable to realize value from my contribution. > > 2) I can make it 2.x only. Same thing in reverse. > > 3) I can make it work on both 2.x and 3.x, which means I'm investing > more effort than I had to if it were single platform. > > Any of those alternatives is worse than ideal. Forking 2.x to create an > unofficial 2.8 release would just prolong the situation. As I've stated > before, I don't see any urgency in moving to 3.x, and don't imagine > doing there for another couple of years, but I absolutely can't imagine > moving to a 2.8 fork. This question cannot be answered generically. I think it worth noting that in part this is the same dilemma as 'how many versions to support' within each of 2.x and 3.x. Limiting code to 3.3+ allows use of the new asyncio module (via Pypy for 3.3) and the new FSR unicode. Use of asyncio or FSR features* also forces the choice you give above as neither can be backported to 2.7. * IE, support of all of unicode on all Python systems with straightforward code, without contortions. If I were giving away 'stand-alone' application code whose dependencies were available on both 2.7 and 3.x+, I would write for 3.x+ on the basis that everyone could install 3.x, and that new users are increasingly likely to only have 3.x only. I would have little sympathy for organizations that prohibit 3.x -- unless they were to pay me to. For numerical or combinatorial code, adding 'from __future__ import division' (which I think one should do anyway for 2.x code) might be the only extra work needed for option 3). -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 8 15:47:47 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 15:47:47 -0500 Subject: Editor for Python In-Reply-To: <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On 1/8/2014 6:27 AM, ayushpokharna at gmail.com wrote: > On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ wrote: I do not seem to have the original >> I'm looking for an editor for Python. I' m interested it works on Windows. For a Python editor, as opposed to a general code editor, the Idle editor works pretty well and has some advantages with respect to integration with the interpreter. -- Terry Jan Reedy From emile at fenx.com Wed Jan 8 15:56:31 2014 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 Jan 2014 12:56:31 -0800 Subject: Editor for Python In-Reply-To: References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On 1/8/2014 12:47 PM, Terry Reedy wrote: > For a Python editor, as opposed to a general code editor, the Idle > editor works pretty well and has some advantages with respect to > integration with the interpreter. While true, ISTM in the past there have been 'leakage' related issues with idle -- are those no longer a concern? Emile From breamoreboy at yahoo.co.uk Wed Jan 8 16:02:12 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 21:02:12 +0000 Subject: Editor for Python In-Reply-To: References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On 08/01/2014 20:47, Terry Reedy wrote: > On 1/8/2014 6:27 AM, ayushpokharna at gmail.com wrote: >> On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ >> wrote: > > I do not seem to have the original > You mean to say you don't keep 12 year old emails? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ricaraoz at gmail.com Wed Jan 8 16:38:22 2014 From: ricaraoz at gmail.com (=?ISO-8859-1?Q?Ricardo_Ar=E1oz?=) Date: Wed, 08 Jan 2014 18:38:22 -0300 Subject: Editor for Python In-Reply-To: <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: <52CDC54E.9050403@gmail.com> I use Spyder both in Windows as in Linux. Pretty good programing environment, lots of features, simple enough, works on both platforms and it's free. El 08/01/14 08:27, ayushpokharna at gmail.com escribi?: > On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ wrote: >> Hello, >> I'm looking for an editor for Python.I' m interested it works on Windows.Can >> anybody help me? >> >> Thank you >> >> Manuel From sagarnildass at gmail.com Wed Jan 8 16:51:40 2014 From: sagarnildass at gmail.com (sagarnildass at gmail.com) Date: Wed, 8 Jan 2014 13:51:40 -0800 (PST) Subject: python copy selected lines from one file to another using argparse or getopt Message-ID: I am trying to write a program in python which searches for user specified words in a txt file and copies the selected lines containing that word into another file. Also the user will have an option to exclude any word. (e.g Suppose the user searches for the word "exception" and want to exclude the word "abc", then the code will only copy the lines which has "exception" in it but not "abc"). Now all the work will be done from the command prompt. The input would be: file.py test.txt(input file) test_mod.txt(output file) -e abc(exclude word denoted by -e)-s exception(search word denoted by -s) Now the user will have an option to enter multiple exclude words and multiple search words. Now so far I have achieved that the input format is: file.py test.txt test_mod.txt abc exception". This excludes the word "abc" and search for "exception". But I don't know how to: Include multiple search word and exclude words How to denote them by -e and -s. I have seen the argparse and the getopt tutorial. But there's no tutorial on this specific topic. Please can somebody help me by modifying my code or write a new one? Here's my code as of now: #/Python33 import sys import os def main(): #main method try: f1 = open(sys.argv[1], 'r') #takes the first input file in command line found = False user_input1 = (sys.argv[3]) #takes the word which is to be excluded. user_input2 = (sys.argv[4]) #takes the word which is to be included. if sys.argv[1] == sys.argv[2]: f1.close() sys.exit('\nERROR!!\nThe two file names cannot be the same.') if sys.argv[3] != sys.argv[4]: for line in f1: if user_input1 in line or user_input2 in line: f2 = open(sys.argv[2], 'a') if user_input1 in line: if user_input2 in line: pass elif user_input2 in line: f2.write(line) found = True f2.close() if not found: print("ERROR: The Word couldn't be found.") f1.close() if sys.argv[3] == sys.argv[4]: f1.close() sys.exit('\nERROR!!\nThe word to be excluded and the word to be included cannot be the same.') except IOError: print('\nIO error or wrong file name.') except IndexError: print('\nYou must enter 5 parameters.') #prevents less than 5 inputs which is mandatory except SystemExit as e: #Exception handles sys.exit() sys.exit(e) if __name__ == '__main__': main() From steve+comp.lang.python at pearwood.info Wed Jan 8 16:55:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: Thu, 09 Jan 2014 08:55:36 +1100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52cd4c2a$0$29979$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52cdc959$0$29977$c3e8da3$5496439d@news.astraweb.com> Martijn Faassen wrote: > Hey, > > I'm pointing out possible improvements that Python 2.8 could offer that > would help incremental porting efforts of applications. I'm pointing > about that helping application developers move forward incrementally may > be a worthwhile consideration. Like, there's money there. Why don't you grab it? If you think people will pay for somebody to backport Python 3 to Python 2.8, just go ahead and do it and rake the money in. Python is open source, you don't have to ask anyone's permission. The only thing you may not be able to do is call it "Python 2.8", but the name isn't important. > You can point out that 2.6 and 2.7 were already such releases, and I > will then point out that many people *have* upgraded their applications > to these releases. Is there now going to be a giant leap forward to > Python 3 by these projects, or is the jump still too far? Opinions differ. It's not a giant leap. 95% of the migration can be handled by a relatively simple script, 2to3. The hardest part is supporting 2 *and* 3 in a single project, but for end-user applications that target a single Python version, rather than libraries and frameworks that target many different versions, migrating is a once-off cost, and for most apps, not a large one. Certainly much less than re-writing the app in another language. -- Steven From rosuav at gmail.com Wed Jan 8 17:22:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 09:22:52 +1100 Subject: Recover handle to shadowed builtin? In-Reply-To: References: Message-ID: On Thu, Jan 9, 2014 at 7:15 AM, Roy Smith wrote: > BUT, not only does pylab overwrite sum(), it overwrites __builtins__ > as well! Instead of a module, it's now a dict. You can still get at > the builtin sum, but you need to do __builtins__["sum"] That probably means that it _only_ overrides the one from __builtins__, which is the easiest way. You're talking about something that's done at the interactive prompt. It should be possible to play with sitecustomize.py to snapshot your original builtins. Try this (untested): # sitecustomize.py import builtins import sys sys.original_builtins = builtins sys.original_sum = sum (or use __builtins__ or __builtin__ or whatever's appropriate for your version) If snapshotting all of builtins doesn't work, snapshotting just sum should. The key is executing code before pylab does its overwriting. ChrisA From menkomigen6 at gmail.com Wed Jan 8 17:27:50 2014 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Wed, 8 Jan 2014 14:27:50 -0800 (PST) Subject: Learning python networking Message-ID: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> I'm trying to learn about socket, how to create and handle connections in python. This is the best I could come up with on my own, please take a look and give me critique: Server script: http://pastebin.com/KtapYfM0 Client script: http://pastebin.com/t4dYygmX How to run it: I open 3 terminals, in one I start the server script, and enter into it something like 'accept 2' Then in the two other terminals I start client scripts which will "connect to the server" so to speak. Now I can communicate between them by sending messages, and exit the whole operation by typing 'exit' into the server. Is the code overly complicated? More precisely: is there a more elegant and simple way to achieve the same thing? Some people have mentioned things like twisted and asyncore, but I don't know anything about them. If it turns out this kind of concept is very straight forward to set up in either of those I would be interested in sample code. I'm specifically looking into this kind of communication because I want to make a small multiplayer game. From gordon at panix.com Wed Jan 8 17:53:24 2014 From: gordon at panix.com (John Gordon) Date: Wed, 8 Jan 2014 22:53:24 +0000 (UTC) Subject: python copy selected lines from one file to another using argparse or getopt References: Message-ID: In sagarnildass at gmail.com writes: > But I don't know how to: > Include multiple search word and exclude words > How to denote them by -e and -s. I have seen the argparse and the getopt > tutorial. But there's no tutorial on this specific topic. This should help you get started: import argparse parser = argparse.ArgumentParser() parser.add_argument('-search', '-s', help='a word to search', action='append', required=True) parser.add_argument('-exclude', '-e', help='a word to exclude from search', action='append') parser.add_argument('input_file') parser.add_argument('output_file') args = parser.parse_args() Assuming the user provided correct arguments, the args object will have these attributes: args.search - a list of words to search for. args.exclude - a list of words to exclude. Can be None. args.input_file - the input file name. args.output_file - the output file name. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From breamoreboy at yahoo.co.uk Wed Jan 8 18:03:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 23:03:53 +0000 Subject: python copy selected lines from one file to another using argparse or getopt In-Reply-To: References: Message-ID: On 08/01/2014 21:51, sagarnildass at gmail.com wrote: > I am trying to write a program in python which searches for user specified words in a txt file and copies the selected lines containing that word into another file. > > Also the user will have an option to exclude any word. > > (e.g Suppose the user searches for the word "exception" and want to exclude the word "abc", then the code will only copy the lines which has "exception" in it but not "abc"). > > Now all the work will be done from the command prompt. > > The input would be: > > file.py test.txt(input file) test_mod.txt(output file) -e abc(exclude word denoted by -e)-s exception(search word denoted by -s) > Now the user will have an option to enter multiple exclude words and multiple search words. > > Now so far I have achieved that the input format is: > > file.py test.txt test_mod.txt abc exception". > This excludes the word "abc" and search for "exception". > > But I don't know how to: > > Include multiple search word and exclude words > How to denote them by -e and -s. I have seen the argparse and the getopt tutorial. But there's no tutorial on this specific topic. > Please can somebody help me by modifying my code or write a new one? > If you can use third party modules I suggest you look at docopt, it's available on pypi. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dihedral88888 at gmail.com Wed Jan 8 18:08:29 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Wed, 8 Jan 2014 15:08:29 -0800 (PST) Subject: Editor for Python In-Reply-To: <3bfd7f87@news.airtel.net> References: <3bfd7f87@news.airtel.net> Message-ID: <936ce516-0a7f-44d9-9e64-37bb0d7bf8b1@googlegroups.com> On Friday, November 23, 2001 6:43:40 AM UTC+8, MANUEL FERNANDEZ PEREZ wrote: > Hello, > I'm looking for an editor for Python.I' m interested it works on Windows.Can > anybody help me? > > Thank you > > Manuel OK, try the notepad++ at notepad-plus-plus.org/ or use IDLE with the pycrust. From sg552 at hotmail.co.uk Wed Jan 8 18:17:22 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Wed, 08 Jan 2014 23:17:22 +0000 Subject: Understanding decorator and class methods In-Reply-To: References: Message-ID: On 08/01/2014 19:56, axis.of.weasel at gmail.com wrote: > can someone please explain why the following works, in contrast to the second example? > > def decorator(func): > def on_call(*args): > print args > return func(args) > return on_call > > class Foo: > @decorator > def bar(self, param1): > print 'inside bar' > > f=Foo() > f.bar(4) # from where is the decorator getting the Foo instance? > > > > I understand why the following works/does not work > > class decorator2: > def __init__(self, func): > self.func=func > def __call__(self, *args): > self.func(*args) > > class Foo2: > @decorator2 > def bar2(self, param): pass > > > f2 = Foo2() > Foo2.bar2(f2, 4) # works, Foo2 instance and param are passed to decorator2 call > f2.bar2(4) # does not work, Foo2 instance is missing, decorator2 cannot invoke method bar From http://docs.python.org/3/reference/datamodel.html: Instance methods An instance method object combines a class, a class instance and any callable object (normally a user-defined function). [...] User-defined method objects may be created when getting an attribute of a class (perhaps via an instance of that class), if that attribute is a user-defined function object or a class method object. [...] Note that the transformation from function object to instance method object happens each time the attribute is retrieved from the instance. In some cases, a fruitful optimization is to assign the attribute to a local variable and call that local variable. Also notice that this transformation only happens for user-defined functions; other callable objects (and all non-callable objects) are retrieved without transformation. Notice the last sentence in particular. After being decorated by decorator2 Foo2.bar2 is not a user-defined function (i.e. an instance of types.FunctionType), so is not transformed into a method upon being accessed through an instance. I suppose you could create a class that mimics the behaviour of methods, though I don't know why you would want to. The following is tested with 3.3.0; I expect someone who knows more than I will probably be along soon to point out why it's stupid. class decorator3: def __init__(self, func): self.func = func def __call__(self, *args, **kwargs): print('Calling func(self, *%r, **%r)' % (args, kwargs)) return self.func(self.__self__, *args, **kwargs) def __get__(self, instance, owner): self.__self__ = instance return self class Foo3: @decorator3 def bar3(self, param): return self, param >>> f3 = Foo3() >>> f3.bar3('param') Calling func(self, *('param',), **{}) (<__main__.Foo3 object at 0x0000000002BDF198>, 'param') From tjreedy at udel.edu Wed Jan 8 18:20:15 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 18:20:15 -0500 Subject: argparse action on default values In-Reply-To: <7353849.WXZ0zEZ0QV@horus> References: <7353849.WXZ0zEZ0QV@horus> Message-ID: On 1/8/2014 1:20 PM, Florian Lindner wrote: > I use argparse from Python 3.3.3 with a custom action that normalizes > path arguments: > This works fine when there is actually a --config=path supplied. But > it's not being applied on default arguments. This behavior is how I interpret the doc. http://docs.python.org/3/library/argparse.html#the-add-argument-method "action - The basic type of action to be taken when this argument is encountered at the command line." "default - The value produced if the argument is absent from the command line." > Of course, I could use "default = norm_path('~/.foobar/config')" Do that. > but I expect that custom actions are applied to default values as well. See doc quote. > The store action works alike for default and supplied values. It would make no sense to ignore defaults. There may be some undocumented subtleties in the interaction of defaults and actions. -- Terry Jan Reedy From rdsteph at mac.com Wed Jan 8 18:23:43 2014 From: rdsteph at mac.com (rdsteph at mac.com) Date: Wed, 8 Jan 2014 15:23:43 -0800 (PST) Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: <57b9f52a-5989-43ad-a082-35bc68dac520@googlegroups.com> Chris A wrote: I'm not sure that there is an "easy way". See, here's the deal. If all your data is ASCII, you can shut your eyes to the difference between bytes and text and Python 2 will work perfectly for you. Then some day you'll get a non-ASCII character come up (or maybe you'll get all of Latin-1 "for free" and it's when you get a non-Latin-1 character - same difference), and you start throwing in encode() and decode() calls in places. But you feel like you're fixing little problems with little solutions, so it's no big deal. Making the switch to Python 3 forces you to distinguish bytes from text, even when that text is all ASCII. Suddenly that's a huge job, a huge change through all your code, and it's all because of this switch to Python 3. The fact that you then get the entire Unicode range "for free" doesn't comfort people who are dealing with URLs and are I think this is important because this kind of programming, working with urls is so common and so important. whEther anyone like's it or not, python 3 makes itch harder to do this very crucial kind of programming. And dismissing-Armin's frustrations and commetncnames dozens make this problem go away. From rosuav at gmail.com Wed Jan 8 18:29:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 10:29:03 +1100 Subject: Learning python networking In-Reply-To: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: On Thu, Jan 9, 2014 at 9:27 AM, Paul Pittlerson wrote: > I'm trying to learn about socket, how to create and handle connections in python. Awesome! I *love* socket networking. (Really. It's awesome. I've written a couple of MUD servers and quite a few MUD clients.) > This is the best I could come up with on my own, please take a look and give me critique: > Server script: > http://pastebin.com/KtapYfM0 > > Client script: > http://pastebin.com/t4dYygmX On this list we prefer in-line code as part of the post, but these are a little long. Posting like this creates a dependency on that web site, so a lot of people either can't or won't see your code. > How to run it: > I open 3 terminals, in one I start the server script, and enter into it something like 'accept 2' > > Then in the two other terminals I start client scripts which will "connect to the server" so to speak. > > Now I can communicate between them by sending messages, and exit the whole operation by typing 'exit' into the server. >From what I'm seeing in that code, all communication is one-way, right? The server sends to the clients, nothing comes back? > Is the code overly complicated? More precisely: is there a more elegant and simple way to achieve the same thing? Some people have mentioned things like twisted and asyncore, but I don't know anything about them. If it turns out this kind of concept is very straight forward to set up in either of those I would be interested in sample code. Those sorts of frameworks would be helpful if you need to scale to infinity, but threads work fine when it's small. > I'm specifically looking into this kind of communication because I want to make a small multiplayer game. Absolutely! The thing to look at is MUDs and chat servers. Ultimately, a multiplayer game is really just a chat room with a really fancy front end. So, some comments on your code. The server shouldn't require interaction at all. It should accept any number of clients (rather than getting the exact number that you enter), and drop them off the list when they're not there. That's a bit of extra effort but it's hugely beneficial. One extremely critical point about your protocol. TCP is a stream - you don't have message boundaries. You can't depend on one send() becoming one recv() at the other end. It might happen to work when you do one thing at a time on localhost, but it won't be reliable on the internet or when there's more traffic. So you'll need to delimit messages; I recommend you use one of two classic ways: either prefix it with a length (so you know how many more bytes to receive), or terminate it with a newline (which depends on there not being a newline in the text). Another rather important point, in two halves. You're writing this for Python 2, and you're writing with no Unicode handling. I strongly recommend that you switch to Python 3 and support full Unicode. Your current code might work fine so long as everyone uses the same codepage, but then you'll meet someone from Greece or Russia and they'll be typing in gibberish because you're decoding it wrongly. (You can get that sort of thing even without crossing country borders, but then it's tempting to just say "Don't use funny characters"; but the problem isn't funny characters, of which there aren't any (I swear, Spike Milligan is *so* not funny... okay, that's not true), but of encodings and character sets.) Using Python 3.4 (which isn't yet stable, but you can download betas) also gives you an asyncio module, but I'd leave that aside for the moment; first figure out threading, it's likely to be easier. So here's how I'd structure a program like this. # Server bind socket to port and listen on it while True: accept socket spawn thread thread: register self with list of connected clients while socket connected: receive data try to parse a message out of data - if not, buffer it handle message, eg by sending to all connected clients unregister self from connected client list # Client connect to server start thread while True: accept input from user act on input, which might 'break' shut down socket cleanly thread: receive data from socket try to parse a message out of data, as with the server # you might even be able to use the same code for both handle message, eg by displaying to screen That's a threaded system. It emphasizes that the server is doing one "thing" for each connected client (listening for incoming socket data), plus one more "thing" (listening for new clients), and the client is doing two "things" (listening for commands from the human, and listening for messages from the server). Moving to an async I/O system doesn't change that, it just runs it all on one thread. So do whichever's easier to get your head around :) Note, by the way, that it's helpful to distinguish "data" and "text", even in pseudo-code. It's impossible to send text across a socket - you have to send bytes of data. If you keep this distinction clearly in your head, you'll have no problem knowing when to encode and when to decode. For what you're doing here, for instance, I would packetize the bytes and then decode into text, and on sending, I'd encode text (UTF-8 would be hands-down best here) and then packetize. There are other options but that's how I'd do it. This is the Flight Level 200 overview of socket handling. I'm happy to expand on any part that interests or confuses you (especially if it does both at once). The world is so much fun when you can wield multiple computers! ChrisA From rdsteph at mac.com Wed Jan 8 18:34:16 2014 From: rdsteph at mac.com (rdsteph at mac.com) Date: Wed, 8 Jan 2014 15:34:16 -0800 (PST) Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: I'm so sorry for the mess in my post above, I apologize to all, I accidentally hit return ... I just meant to say that internet programming using ASCII urls is so common and important that it hurts that Python 3 makes it so much harder. It sure would be great if Python 3 could be improved to allow such programming to be done using ASCII urls without requiring all the unicode overhead. Armin is right. Calling his post a rant doesn't help. From kw at codebykevin.com Wed Jan 8 18:42:42 2014 From: kw at codebykevin.com (Kevin Walzer) Date: Wed, 08 Jan 2014 18:42:42 -0500 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On 1/8/14, 9:30 AM, Mark Lawrence wrote: > But to be serious why not stick with 2.x if there's no compelling reason > to move? Whatever happened to "if it ain't broke, don't fix it"? And > before anyone says anything please don't start on about the bytes versus > string debate, I'm fairly certain that there are a substantial number of > application areas that don't run into these problems. +1 to this. I haven't updated my Python apps to 3.x because there's nothing in 3.x that offers benefits to my users. I deal with constant API churn as a Mac developer. I have no interest in adding to this complexity and headaches by switching from 2.x to 3.x. I imagine I'll update someday, but not anytime soon. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From rosuav at gmail.com Wed Jan 8 18:45:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 10:45:37 +1100 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On Thu, Jan 9, 2014 at 10:34 AM, wrote: > I just meant to say that internet programming using ASCII urls is so common and important that it hurts that Python 3 makes it so much harder. It sure would be great if Python 3 could be improved to allow such programming to be done using ASCII urls without requiring all the unicode overhead. > > Armin is right. Calling his post a rant doesn't help. There's one big problem with that theory. We've been looking, on this list and on python-ideas, at some practical suggestions for adding something to Py3 that will help. So far, lots of people have suggested things, and the complainers haven't attempted to explain what they actually need. Hard facts and examples would help enormously. Incidentally, before referring to "all the Unicode overhead", it would help to actually measure the overhead of encoding and decoding. Python 2.7: >>> timeit.timeit("a.encode().decode()","a=u'a'*1000",number=500000) 8.787162614242874 Python 3.4: >>> timeit.timeit("a.encode().decode()","a=u'a'*1000",number=500000) 1.7354552045022515 Since 3.3, the cost of UTF-8 encoding/decoding an all-ASCII string is extremely low. So the real cost isn't in run-time performance but in code complexity. Would it be easier to work with ASCII URLs with a one-letter-name helper function? I never got an answer to that question. ChrisA From tjreedy at udel.edu Wed Jan 8 18:46:16 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 18:46:16 -0500 Subject: Editor for Python In-Reply-To: References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On 1/8/2014 3:56 PM, Emile van Sebille wrote: > On 1/8/2014 12:47 PM, Terry Reedy wrote: > >> For a Python editor, as opposed to a general code editor, the Idle >> editor works pretty well and has some advantages with respect to >> integration with the interpreter. > > While true, ISTM in the past there have been 'leakage' related issues > with idle -- are those no longer a concern? I have looked through most of the Idle issues on the tracker but do not remember anything about 'leakage' (of memory?) -- Terry Jan Reedy From drsalists at gmail.com Wed Jan 8 18:53:08 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 8 Jan 2014 15:53:08 -0800 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: Nice response Chris. Seriously. On Wed, Jan 8, 2014 at 3:29 PM, Chris Angelico wrote: > One extremely critical point about your protocol. TCP is a stream - > you don't have message boundaries. You can't depend on one send() > becoming one recv() at the other end. It might happen to work when you > do one thing at a time on localhost, but it won't be reliable on the > internet or when there's more traffic. So you'll need to delimit > messages; I recommend you use one of two classic ways: either prefix > it with a length (so you know how many more bytes to receive), or > terminate it with a newline (which depends on there not being a > newline in the text). Completely agree, and I'll point out http://stromberg.dnsalias.org/~dstromberg/bufsock.html , which makes it a little easier to deal with delimiters like newlines or null termination. > Another rather important point, in two halves. You're writing this for > Python 2, and you're writing with no Unicode handling. I strongly > recommend that you switch to Python 3 and support full Unicode. Agreed. It's time modernize. Don't leave out people on the other side of the world for no reason other than a modicum of convenience for the developer. > Using Python 3.4 (which isn't yet > stable, but you can download betas) also gives you an asyncio module, > but I'd leave that aside for the moment; first figure out threading, > it's likely to be easier. Personally, I don't like asynchronous I/O, EG twisted. It tends to give very complex, uniprocessor solutions to problems, even when those problems have quite simple, alternative solutions. I'd rather just accept and fork in most cases, with or without multiprocessing. From breamoreboy at yahoo.co.uk Wed Jan 8 18:53:29 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 08 Jan 2014 23:53:29 +0000 Subject: "More About Unicode in Python 2 and 3" In-Reply-To: References: Message-ID: On 08/01/2014 23:34, rdsteph at mac.com wrote: > I'm so sorry for the mess in my post above, I apologize to all, I accidentally hit return ... > > I just meant to say that internet programming using ASCII urls is so common and important that it hurts that Python 3 makes it so much harder. It sure would be great if Python 3 could be improved to allow such programming to be done using ASCII urls without requiring all the unicode overhead. > > Armin is right. Calling his post a rant doesn't help. > I disagree. If you want to make friends and influence people, your opening sentence is not "It's becoming increasingly harder to have reasonable discussions about the differences between Python 2 and 3 because one language is dead and the other is actively developed." If Python 2 is dead, why are the core developers wasting their time committing patches to the Python 2 source code, because they have nothing better to do? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From davea at davea.name Wed Jan 8 18:57:22 2014 From: davea at davea.name (Dave Angel) Date: Wed, 08 Jan 2014 18:57:22 -0500 Subject: =?UTF-8?Q?Re:_python_copy_selected_lines_from_one_?= =?UTF-8?Q?file_to_another_using_argparse_or=0A_getopt?= In-Reply-To: References: Message-ID: On Wed, 8 Jan 2014 13:51:40 -0800 (PST), sagarnildass at gmail.com wrote: > I am trying to write a program in python which searches for user specified words in a txt file and copies the selected lines containing that word into another file. John Gordon has given you a good start on argument parsing. So let's start with some general comments. Please indent by 4 columns. Please factor your code into multiple functions so it's readable, especially by you. Please learn that complementary conditions are best handled by else not by another if. So the arguments to your main function should probably be two file objects and two lists. The function should call another one for each list, in a loop that looks something like for line in infile: if check_include (includes, line and not check_exclude (excludes, line): dosomethingwith line By the way checking the 2 filenames for equals doesn't begin to protect against trashing some file. Better to check if the output file exists, perhaps by opening in append mode and checking size. -- DaveA From davea at davea.name Wed Jan 8 19:02:43 2014 From: davea at davea.name (Dave Angel) Date: Wed, 08 Jan 2014 19:02:43 -0500 Subject: Recover handle to shadowed builtin? In-Reply-To: <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> References: <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> <9D7A8CB8-A028-4DB0-A026-98BA4FF8124C@panix.com> Message-ID: On Wed, 8 Jan 2014 14:52:10 -0500, Roy Smith wrote: > I'm working with ipython's pylab mode, which replaces the builtin sum() with the one from numpy: > In [105]: > sum > Out[105]: > > Is there any way to recover a reference to the builtin sum()? goodsum=__builtins__.sum -- DaveA From emile at fenx.com Wed Jan 8 19:19:03 2014 From: emile at fenx.com (Emile van Sebille) Date: Wed, 08 Jan 2014 16:19:03 -0800 Subject: Editor for Python In-Reply-To: References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On 1/8/2014 3:46 PM, Terry Reedy wrote: > On 1/8/2014 3:56 PM, Emile van Sebille wrote: >> On 1/8/2014 12:47 PM, Terry Reedy wrote: >> >>> For a Python editor, as opposed to a general code editor, the Idle >>> editor works pretty well and has some advantages with respect to >>> integration with the interpreter. >> >> While true, ISTM in the past there have been 'leakage' related issues >> with idle -- are those no longer a concern? > > I have looked through most of the Idle issues on the tracker but do not > remember anything about 'leakage' (of memory?) Of names I think. As I recall it had something to do with both idle and the application running in the same namespace? So the leakage was from within idle affecting the running of the script under development? Admittedly, it was a while back. But I never went back to idle afterwards either... Emile From tjreedy at udel.edu Wed Jan 8 19:20:14 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 19:20:14 -0500 Subject: Understanding decorator and class methods In-Reply-To: References: Message-ID: On 1/8/2014 2:56 PM, axis.of.weasel at gmail.com wrote: > can someone please explain why the following works, in contrast to the second example? Because function attributes of classes become instance methods, with special behavior, when accessed via an instance of the class. > def decorator(func): > def on_call(*args): > print args > return func(args) This has to be func(*args) (as in second example) or one gets TypeError: bar() missing 1 required positional argument: 'param1' Did you re-type instead of pasting? > return on_call > > class Foo: > @decorator > def bar(self, param1): > print 'inside bar' > > f=Foo() > f.bar(4) # from where is the decorator getting the Foo instance? from args. f.bar(4) == Foo.bar(f, 4) == on_call(*args), which prints args (tuple f,4) and calls func(*args) == Foo.(f, 4) which prints 'inside bar' > I understand why the following works/does not work > > class decorator2: > def __init__(self, func): > self.func=func > def __call__(self, *args): > self.func(*args) > > class Foo2: > @decorator2 > def bar2(self, param): pass Using a class decorator to decorate an instance method of another class is asking for trouble. As explained below, the result is no longer an instance method. > f2 = Foo2() > Foo2.bar2(f2, 4) # works, Foo2 instance and param are passed to decorator2 call > f2.bar2(4) # does not work, Foo2 instance is missing, decorator2 cannot invoke method bar Remember that @deco def f(): pass is essentially equivalent to def f(): pass f = deco(f) Decorator decorator replaces a function with a function. So the wrapped bar is still seen as an instance method, so f.bar(x) gets the magic instance method translation to Foo.bar(f, x). Decorator2 replaces function bar with a callable instance of itself, which is *not* a 'function' and which therefore is not seen as an instance method, but merely a callable attribute of Foo2. So f.bar == Foo.bar, and you would need f2.bar(f2, 4). -- Terry Jan Reedy From rosuav at gmail.com Wed Jan 8 19:21:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 11:21:43 +1100 Subject: Dictionary In-Reply-To: References: Message-ID: On Thu, Jan 9, 2014 at 11:13 AM, Dennis Lee Bieber wrote: > #generate search re expression representing > # .* any character/multiple -- leading > # [l|e|t|t|e|r] match any of the letters supplied > # .* any character/multiple -- trailing > needle = ".*[" + "|".join(list(letters.lower())) + "].*" I don't think this will do what you think it will. It'll match anything that has any one of the supplied letters (or a pipe; it's a character class, so the pipe has no significance and is simply part of the class). I'm not sure a regex is the best thing here; but what you could do is sort the letters and sort the letters in the words: pat = ".*".join(sorted(letters.lower())) for word in open("/usr/share/dict/words"): # Ought to use with if re.search(pat, ''.join(sorted(word))): print(word) ChrisA From rosuav at gmail.com Wed Jan 8 19:23:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 11:23:53 +1100 Subject: Editor for Python In-Reply-To: References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On Thu, Jan 9, 2014 at 11:19 AM, Emile van Sebille wrote: > As I recall it had something to do with both idle and the application > running in the same namespace? So the leakage was from within idle > affecting the running of the script under development? > > Admittedly, it was a while back. But I never went back to idle afterwards > either... Personally, I don't edit source files in IDLE - I use SciTE or another editor for that. IDLE is, to me, an interactive Python session and nothing more. I find it better than command-line Python because it recalls entire blocks of code; it's not a superior editor to one that can do every language I want all in one window. ChrisA From rosuav at gmail.com Wed Jan 8 19:07:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 11:07:05 +1100 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: On Thu, Jan 9, 2014 at 10:53 AM, Dan Stromberg wrote: >> Using Python 3.4 (which isn't yet >> stable, but you can download betas) also gives you an asyncio module, >> but I'd leave that aside for the moment; first figure out threading, >> it's likely to be easier. > > Personally, I don't like asynchronous I/O, EG twisted. It tends to > give very complex, uniprocessor solutions to problems, even when those > problems have quite simple, alternative solutions. I'd rather just > accept and fork in most cases, with or without multiprocessing. I haven't used the Python asyncio module yet (haven't gotten around to it, no other reason), but in my Pike work, I've gotten quite friendly with a callback system. It plays nicely with the structure I have for code reloading, by separating code and data, and then simply running everything off a single thread, one callback at a time. Works really well when everything's waiting anyway. It does force you to think about things differently, though. Case in point: My MUD client allows an arbitrary number of code files to inspect a line of text that the user's entered, before it goes to the server. Any one of them can suppress the line, in which case subsequent hooks won't see it and it won't go to the server. What about changing the line as it goes through? That's easy enough, I guess. But what if that change involves a popup message and user response... or a network request to a remote server? (I do, in fact, have exactly that. Long URLs get shortened via tinyurl.com.) A threaded model wouldn't even help much, here, unless I'm prepared to spawn a separate thread for every command the user enters, which is stupid overhead. Instead, I have a function that reinjects the line and carries on as if it hadn't been suppressed in the first place. Maybe it's not the best way to do things, but it can be extremely simple in the code. Most operations don't even need the continuation-call mechanism that I used there; mostly, everything's just (conceptually) "when this happens, call this function". The fact that they're serialized doesn't matter. Events from the GUI, incoming socket data (on any socket - there might be multiple), time-delay events (eg a ticking clock), etc - everything works the same way. It's really easy once you get your head around it. ChrisA From roy at panix.com Wed Jan 8 20:27:30 2014 From: roy at panix.com (Roy Smith) Date: Wed, 08 Jan 2014 20:27:30 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: In article , Kevin Walzer wrote: > I haven't updated my Python apps to 3.x because there's nothing in 3.x > that offers benefits to my users. I almost found a reason to move to Python 3 today. Then I got smacked. I had a datetime. I needed a unix timestamp. People need to go back and forth between these two things all the time and in Python 2 it's the very definition of impedance mismatch. What should be a dead simple operation involves long threads on stackoverflow discussing which of several amalgamations of duct tape is the least ugly. Anyway, I discovered that Python 3.3's datetime has a .timestamp() method. Yeah. Finally. Exactly what the world had needed for years. Then I kept reading and found: Note: There is no method to obtain the POSIX timestamp directly from a naive datetime instance representing UTC time. Ugh. So, we're back to square one. They go on to suggest one of two workarounds, either calling datetime.replace() to insert a timezone, or subtracting from the epoch manually. Naive datetimes are what everybody uses. It's what utcnow() gives you. So why make life difficult for everybody? Python 3 didn't win a convert today. From breamoreboy at yahoo.co.uk Wed Jan 8 20:40:51 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 01:40:51 +0000 Subject: deja vu anybody Message-ID: I've been browsing for the fun on it and came across "[Python-Dev] SF:1463370 add .format() method to str and unicode" here https://mail.python.org/pipermail/python-dev/2006-April/063329.html I've vague recollections of seeing something along these lines fairly recently, a PEP I think, can someone please help me out, thanks. -- 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 Wed Jan 8 20:47:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 12:47:53 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 12:27 PM, Roy Smith wrote: > Anyway, I discovered that Python 3.3's datetime has a .timestamp() > method. Yeah. Finally. Exactly what the world had needed for years. > Then I kept reading and found: > > Note: There is no method to obtain the POSIX timestamp directly from a > naive datetime instance representing UTC time. In my experiments (admittedly with 3.4, not 3.3, but I don't know that there's any difference), I was able to round-trip a time_t through datetime with no problems. Why not simply use a UTC datetime instead of a naive one? What do you gain by using a naive datetime? You seem to know what timezone it's in anyway. ChrisA From tjreedy at udel.edu Wed Jan 8 20:51:01 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 08 Jan 2014 20:51:01 -0500 Subject: Editor for Python In-Reply-To: References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On 1/8/2014 7:19 PM, Emile van Sebille wrote: > On 1/8/2014 3:46 PM, Terry Reedy wrote: >> On 1/8/2014 3:56 PM, Emile van Sebille wrote: >>> On 1/8/2014 12:47 PM, Terry Reedy wrote: >>> >>>> For a Python editor, as opposed to a general code editor, the Idle >>>> editor works pretty well and has some advantages with respect to >>>> integration with the interpreter. >>> >>> While true, ISTM in the past there have been 'leakage' related issues >>> with idle -- are those no longer a concern? Almost not, see below. >> I have looked through most of the Idle issues on the tracker but do not >> remember anything about 'leakage' (of memory?) > > Of names I think. > > As I recall it had something to do with both idle and the application > running in the same namespace? So the leakage was from within idle > affecting the running of the script under development? By default, Idle runs user code in a separate process from the Idle process itself, and has for several years. There is a command line option to revert to the old way (user code in the same process). Some of us would like to remove that option (and simplify the remaining code a bit). This option is kept mainly because connecting to the separate process via sockets sometimes fails on some systems. -- Terry Jan Reedy From ethan at stoneleaf.us Wed Jan 8 20:52:05 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 08 Jan 2014 17:52:05 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <52CE00C5.1030909@stoneleaf.us> On 01/08/2014 05:27 PM, Roy Smith wrote: > In article , > Kevin Walzer wrote: > >> I haven't updated my Python apps to 3.x because there's nothing in 3.x >> that offers benefits to my users. > > I almost found a reason to move to Python 3 today. Then I got smacked. [snip] > Naive datetimes are what everybody uses. It's what utcnow() gives you. > So why make life difficult for everybody? Python 3 didn't win a convert > today. Naive datetimes suffer from the same problem as the old str/unicode problems: as soon as you try to mix different timezone datetimes that are naive, you have a mess (temporal-bake, anyone?). -- ~Ethan~ From rosuav at gmail.com Wed Jan 8 21:09:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 13:09:26 +1100 Subject: the Gravity of Python 2 In-Reply-To: <52CE00C5.1030909@stoneleaf.us> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE00C5.1030909@stoneleaf.us> Message-ID: On Thu, Jan 9, 2014 at 12:52 PM, Ethan Furman wrote: > as soon as you try to mix different timezone datetimes that are naive, you > have a mess (temporal-bake, anyone?). Doctor Who gets into cookies? ChrisA From roy at panix.com Wed Jan 8 21:25:55 2014 From: roy at panix.com (Roy Smith) Date: Wed, 08 Jan 2014 21:25:55 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: In article , Chris Angelico wrote: > Why not simply use a UTC datetime instead of a naive one? [Pet peeve of mine: uses of "simple" or "just" to imply that something is easy, when it's not. "Why not just get the Arabs and the Jews to be friends?" "Why not simply find a safe way to store nuclear waste?"] Because it's easy to get a naive one. You call datetime.utcnow(). If utcnow() returned an aware datetime, that's probably what we would be using. Why didn't utcnow() just return an aware datetime to begin with? Conversely, it's a pain in the butt to get an aware one. As far as I can tell, you have to do something like: utcnow().replace(tzinfo=pytz.utc) which is not only ugly, but requires installing a third-party module (pytz) to get the UTC timezone definition. Not to mention, our database (mongodb), doesn't support storing aware datetimes. I can insert a document with an aware datetime, but when I retrieve that document, I get back a naive one. I don't know what other databases do. From rosuav at gmail.com Wed Jan 8 22:17:07 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 14:17:07 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 1:25 PM, Roy Smith wrote: > Because it's easy to get a naive one. You call datetime.utcnow(). If > utcnow() returned an aware datetime, that's probably what we would be > using. Why didn't utcnow() just return an aware datetime to begin with? > > Conversely, it's a pain in the butt to get an aware one. As far as I > can tell, you have to do something like: > > utcnow().replace(tzinfo=pytz.utc) > > which is not only ugly, but requires installing a third-party module > (pytz) to get the UTC timezone definition. What's datetime.today() give you? I'm not experienced with the module, but a glance at the docs and then a quick try interactively suggests that this might be what you need. But even so, the problem is not "why can't naive timestamps do everything I want". The problem is "why is it so hard to get an aware timestamp for the current instant". And if you ask *that* question, then there's likely to be an answer. I might be wrong with my suggestion above, and maybe there isn't even any answer right now, but there certainly could be. Yes, it *is* simple. It *is* easy. I've been working with pure-UTC times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just float) for decades. Like with so many other things, the easiest solution is also the best, because you can just work with one stable representation and abstraction on the inside, with conversions to/from it at the boundaries. It IS that easy. ChrisA From ben+python at benfinney.id.au Wed Jan 8 22:34:54 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jan 2014 14:34:54 +1100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <7wvbxteskh.fsf@benfinney.id.au> Chris Angelico writes: > On Thu, Jan 9, 2014 at 1:25 PM, Roy Smith wrote: > > Because it's easy to get a naive one. You call datetime.utcnow(). If > > utcnow() returned an aware datetime, that's probably what we would > > be using. Why didn't utcnow() just return an aware datetime to begin > > with? [?] > But even so, the problem is not "why can't naive timestamps do > everything I want". The problem is "why is it so hard to get an aware > timestamp for the current instant". And if you ask *that* question, > then there's likely to be an answer. I think Roy's question hits close to a related problem: that the standard library makes it easy to do a sub-optimal thing, and the behaviour we all agree is best is not the default. So, two questions are raised. One is what you've correctly identified: ?Why is it so hard to get an aware timestamp for the current instant?? The short answer is: because doing that requires a lookup into a frequently-updated database, which (because it's so frequently updated) isn't installed along with Python. The other is: ?Why is the default behaviour from the standard library doing something which I later discover is the wrong thing to do?? The answer to that is, of course, related to the first one: the right thing to do isn't currently feasible by default. Not a very satisfactory answer, but nevertheless a situation we need to deal with today. > Yes, it *is* simple. It *is* easy. I've been working with pure-UTC > times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just > float) for decades. Like with so many other things, the easiest > solution is also the best, because you can just work with one stable > representation and abstraction on the inside, with conversions to/from > it at the boundaries. It IS that easy. The difficulty isn't in doing the right thing; the difficulty is in doscovering that the default behaviour is sub-optimal and then learning what, exactly *is* the right thing to do. The right behaviour is easy, but it's not default, and it's not obvious, and it's a difficult learning process to differentiate the right thing to do from the several competing easier-to-understand but wrong things. So, I think you're both correct. The messiness of getting to the right behaviour is highly obnoxious and technically unnecessary, if only the bureaucrats and politicians would give up trying to make their mark on time zones . With time zones, as with text encodings, there is a single technically elegant solution (for text: Unicode; for time zones: twelve simple, static zones that never change) that would work for the whole world if we could just be free to sweep away all the messy legacy crap and expect people to stop complicating the matter further. Until that day comes, though, we as programmers need to learn this messy arbitrary crap, at least to the point of knowing unambiguously what we ask the computer to do when it interacts with the messy real world. -- \ ?I prayed for twenty years but received no answer until I | `\ prayed with my legs.? ?Frederick Douglass, escaped slave | _o__) | Ben Finney From roy at panix.com Wed Jan 8 22:35:14 2014 From: roy at panix.com (Roy Smith) Date: Wed, 08 Jan 2014 22:35:14 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: In article , Chris Angelico wrote: > On Thu, Jan 9, 2014 at 1:25 PM, Roy Smith wrote: > > Because it's easy to get a naive one. You call datetime.utcnow(). If > > utcnow() returned an aware datetime, that's probably what we would be > > using. Why didn't utcnow() just return an aware datetime to begin with? > > > > Conversely, it's a pain in the butt to get an aware one. As far as I > > can tell, you have to do something like: > > > > utcnow().replace(tzinfo=pytz.utc) > > > > which is not only ugly, but requires installing a third-party module > > (pytz) to get the UTC timezone definition. > > What's datetime.today() give you? It almost gives you an aware UTC datetime. Other than it being naive, and being in local time, that is :-) > But even so, the problem is not "why can't naive timestamps do > everything I want". The problem is "why is it so hard to get an aware > timestamp for the current instant". And if you ask *that* question, > then there's likely to be an answer. You asked, Why not simply use a UTC datetime instead of a naive one?" My answer is that it's not simple at all. > Yes, it *is* simple. It *is* easy. I've been working with pure-UTC > times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just > float) for decades. Like with so many other things, the easiest > solution is also the best, because you can just work with one stable > representation and abstraction on the inside, with conversions to/from > it at the boundaries. It IS that easy. Please show me the simple code to obtain an aware UTC datetime representing the current time. From rosuav at gmail.com Wed Jan 8 22:42:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 14:42:53 +1100 Subject: the Gravity of Python 2 In-Reply-To: <7wvbxteskh.fsf@benfinney.id.au> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: On Thu, Jan 9, 2014 at 2:34 PM, Ben Finney wrote: > [ a bunch of stuff that I totally agree with ] No response needed here :) So I was wrong on the specific example of .today(), but asking the question the other way is at least helpful. Maybe the best solution is exactly what Roy already posted, or maybe there's some other way to achieve that. In any case, there is a solution, albeit not as clean as I would have liked. > With time zones, as with text encodings, there is a single technically > elegant solution (for text: Unicode; for time zones: twelve simple, > static zones that never change) Twelve or twenty-four? Or are you thinking we should all be an even number of hours away from UTC, which would also work? ChrisA From roy at panix.com Wed Jan 8 22:44:50 2014 From: roy at panix.com (Roy Smith) Date: Wed, 08 Jan 2014 22:44:50 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: In article , Ben Finney wrote: > Chris Angelico writes: > > > On Thu, Jan 9, 2014 at 1:25 PM, Roy Smith wrote: > > > Because it's easy to get a naive one. You call datetime.utcnow(). If > > > utcnow() returned an aware datetime, that's probably what we would > > > be using. Why didn't utcnow() just return an aware datetime to begin > > > with? > [???] > > > But even so, the problem is not "why can't naive timestamps do > > everything I want". The problem is "why is it so hard to get an aware > > timestamp for the current instant". And if you ask *that* question, > > then there's likely to be an answer. > > I think Roy's question hits close to a related problem: that the > standard library makes it easy to do a sub-optimal thing, and the > behaviour we all agree is best is not the default. > > So, two questions are raised. One is what you've correctly identified: > ???Why is it so hard to get an aware timestamp for the current instant???? > The short answer is: because doing that requires a lookup into a > frequently-updated database, which (because it's so frequently updated) > isn't installed along with Python. We have a call in the standard library named utcnow(). That shouldn't require a lookup in a database. "I'm sorry, which value of zero did you want?" From drsalists at gmail.com Wed Jan 8 22:49:40 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Wed, 8 Jan 2014 19:49:40 -0800 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: On Wed, Jan 8, 2014 at 4:07 PM, Chris Angelico wrote: > Maybe it's not the best way to do things, but it can be extremely > simple in the code. For small projects, the added complexity doesn't bite you. At least, not much. For large projects, with thousands or millions of callbacks, it can be very difficult to track down bugs in who-knows-which callback, given that they're all being called asynchronously. It's vastly simpler to fire up a debugger against a process, or insert print statements that are related to each other in time in some way. > It's > really easy once you get your head around it. IMO, it's not a matter of wrapping your head around it, but respecting complexity. Three quotes come to mind: * Make things as simple as possible, but not simpler. * Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it. * Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. I'm not trying to call you or anyone else a fool, but the Alan Perlis quote (the second) does give a flavor of what I'm trying to say. The third quote, from Brian Kernighan, seems to underestimate the complexity of asynchronous programming in the large - it's probably not just twice as hard. From ben+python at benfinney.id.au Wed Jan 8 22:54:48 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jan 2014 14:54:48 +1100 Subject: Time zones and why they change so damned often (was: the Gravity of Python 2) References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: <7wr48hernb.fsf_-_@benfinney.id.au> Chris Angelico writes: > On Thu, Jan 9, 2014 at 2:34 PM, Ben Finney wrote: > > With time zones, as with text encodings, there is a single > > technically elegant solution (for text: Unicode; for time zones: > > twelve simple, static zones that never change) > > Twelve or twenty-four? Twenty-four time zones, yes. My mistake. I'm currently reading David Prerau's _Saving the Daylight: Why We Put The Clocks Forward_. It's got an acknowledged bias, that DST is overall a good thing; I disagree strongly with that position. But it's also very well researched and engagingly written. Not only does it explain the motivations and history of the present system of Daylight Shifting Time (or, as the world misleadingly calls it, Daylight ?Saving? Time), it goes into the history that pre-dates that system and led to the system of time zones at all. I'm approaching it with the goal of knowing better what I'm talking about when I advocate scrapping the whole DST system :-) -- \ ?Only the educated are free.? ?Epictetus, _Discourses_ | `\ | _o__) | Ben Finney From rosuav at gmail.com Wed Jan 8 23:03:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 15:03:45 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 2:35 PM, Roy Smith wrote: >> Yes, it *is* simple. It *is* easy. I've been working with pure-UTC >> times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just >> float) for decades. Like with so many other things, the easiest >> solution is also the best, because you can just work with one stable >> representation and abstraction on the inside, with conversions to/from >> it at the boundaries. It IS that easy. > > Please show me the simple code to obtain an aware UTC datetime > representing the current time. In Pike: time(); In PostgreSQL: SELECT now(); In C: time(0); All of these give a value in UTC. The PostgreSQL one gives it to you as a TIMESTAMP WITH TIME ZONE, the others just as a simple value. I don't know how they go about figuring out what UTC is, on systems where the computer clock is in local time (eg Windows), but figure out they do. It might be expensive but it's done somehow. (Easiest way to check timezone in C is to look at what time(0)%86400/3600 is - that should be the hour-of-day in UTC, which as I type is 3. And it is.) I don't know how to do it in Python because I'm not familiar with the datetime module. But time.time() returns a value in UTC, which is verifiable by the above method: >>> int(time.time())%86400//3600 3 So maybe the key is to use utcfromtimestamp()? I don't know. My personal preference would be to simply use either int or float everywhere (float if you need subsecond resolution, int if you're concerned about massively past or future timestamps), and then translate to something else for display. Effectively, instead of working with a datetime object, I would just work with an alternative representation of instant-in-time which is simply seconds since 1970 (dealing with leap seconds whichever way you like). If the datetime module causes you pain, don't use it. Ben, if it's that expensive to get an aware timestamp, why does time.time() effectively do that? Is it a much more expensive call? ChrisA From rosuav at gmail.com Wed Jan 8 23:14:55 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 15:14:55 +1100 Subject: Time zones and why they change so damned often (was: the Gravity of Python 2) In-Reply-To: <7wr48hernb.fsf_-_@benfinney.id.au> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: On Thu, Jan 9, 2014 at 2:54 PM, Ben Finney wrote: > I'm approaching it with the goal of knowing better what I'm talking > about when I advocate scrapping the whole DST system :-) I would definitely support the scrapping of DST. I'm less sure that we need exactly 24 timezones around the world, though. It's not nearly as big a problem to have the half-hour and quarter-hour timezones - though it would be easier if timezone were strictly an integer number of hours. But DST is the real pain. What I find, most of the time, is that it's Americans who can't handle DST. I run an international Dungeons and Dragons campaign (we play online, and new players are most welcome, as are people watching!), and the Aussies (myself included) know to check UTC time, the Brits and Europeans check UTC or just know what UTC is, and the Americans say "Doesn't that happen at 8 o'clock Eastern time?" and get confused. I don't understand this. Are my players drawn exclusively from the pool of people who've never worked with anyone in Arizona [1]? Yes, I'm stereotyping a bit here, and not every US player has had problems with this, but it's the occasional US player who knows to check, and the rare European, British, or Aussie player who doesn't. In any case, the world-wide abolition of DST would eliminate the problem. The only remaining problem would be reminding people to change the batteries in their smoke detectors. ChrisA [1] For those who aren't right up on timezone trivia, AZ has no DST. Similarly the Australian state of Queensland does not shift its clocks. From rosuav at gmail.com Wed Jan 8 23:20:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 15:20:05 +1100 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: On Thu, Jan 9, 2014 at 2:49 PM, Dan Stromberg wrote: > The third quote, from Brian Kernighan, seems to underestimate the > complexity of asynchronous programming in the large - it's probably > not just twice as hard. Yeah, which is why I recommended a threaded approach to the OP. It won't scale to millions of simultaneous connections... but he's unlikely to have more than half a dozen in testing, and even in production, most games aren't going to run more than a couple hundred players. (A huge server might have more players than that simultaneously logged in, but they'll be running different games. If thread count becomes a problem, fork() to create a game, job done.) Threads are easier to get your head around: this and that happen at the same time. Sometimes it means creating lots of threads to do similar things (one for the GUI, one for this socket, one for that socket, one for the cron handler, etc, etc), but is that really a problem? Probably not. ChrisA From roy at panix.com Wed Jan 8 23:29:01 2014 From: roy at panix.com (Roy Smith) Date: Wed, 08 Jan 2014 23:29:01 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: In article , Chris Angelico wrote: > On Thu, Jan 9, 2014 at 2:35 PM, Roy Smith wrote: > >> Yes, it *is* simple. It *is* easy. I've been working with pure-UTC > >> times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just > >> float) for decades. Like with so many other things, the easiest > >> solution is also the best, because you can just work with one stable > >> representation and abstraction on the inside, with conversions to/from > >> it at the boundaries. It IS that easy. > > > > Please show me the simple code to obtain an aware UTC datetime > > representing the current time. > > In Pike: > time(); > > In PostgreSQL: > SELECT now(); > > In C: > time(0); > > All of these give a value in UTC. None of which answer my question. How, in Python, do you get an aware UTC datetime object? I know how to get a numeric representation of the time as the number of seconds since the Unix epoch. That's not what I asked. > So maybe the key is to use utcfromtimestamp()? I don't know. So, I'm really confused what point you're trying to make. You started out arguing that I should be using aware datetimes instead of naive datetimes. I said that the reason I don't use aware datetimes is because they're so much more difficult to generate. You said they were simple to generate. So, I'd like to see your code which generates an aware UTC datetime object in Python. And then we can argue about whether it's simple or not :-) From rosuav at gmail.com Wed Jan 8 23:34:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 15:34:17 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 3:29 PM, Roy Smith wrote: > So, I'd like to see your code which generates an aware UTC datetime > object in Python. And then we can argue about whether it's simple or > not :-) Like I said, I don't use the datetime module. But fundamentally, an aware datetime represents an instant in time - which is exactly what a POSIX timestamp ("time_t") represents. So I can't offer exact code for working with them, other than to say that time.time() is precisely accomplishing the same job. Maybe there needs to be a recipe posted somewhere saying "To create a datetime from a POSIX time, do this". This is simple: >>> time.time() 1389242048.669482 ChrisA From rosuav at gmail.com Wed Jan 8 23:38:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 15:38:19 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On Thu, Jan 9, 2014 at 3:29 PM, Roy Smith wrote: > So, I'd like to see your code which generates an aware UTC datetime > object in Python. And then we can argue about whether it's simple or > not :-) In fact, I'll go further. Why do you need a datetime object at all? What is it that you need? Arithmetic can be done with int and/or float, parsing and formatting can be done with time.str[pf]time, etc, etc. It's like if someone asks "How can I build a regular expression that will tell me if a string is valid JSON?". The question poses a restriction that may be unnecessary, and may eliminate all possible answers. ChrisA From ethan at stoneleaf.us Thu Jan 9 00:31:02 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 08 Jan 2014 21:31:02 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <52CE3416.9090501@stoneleaf.us> On 01/08/2014 08:34 PM, Chris Angelico wrote: > On Thu, Jan 9, 2014 at 3:29 PM, Roy Smith wrote: >> So, I'd like to see your code which generates an aware UTC datetime >> object in Python. And then we can argue about whether it's simple or >> not :-) > > Like I said, I don't use the datetime module. But fundamentally, an > aware datetime represents an instant in time - which is exactly what a > POSIX timestamp ("time_t") represents. So I can't offer exact code for > working with them, other than to say that time.time() is precisely > accomplishing the same job. Maybe there needs to be a recipe posted > somewhere saying "To create a datetime from a POSIX time, do this". > > This is simple: > >>>> time.time() > 1389242048.669482 I agree, and I'm sure Roy also agrees, that that is simple. However, that is *not* a timezone-aware datetime. The point of having the datetime module is so we all don't have to reroll our own from scratch, and yet this particular (and increasingly important) operation wasn't intuitive nor easy. http://docs.python.org/dev/library/datetime.html?highlight=datetime#datetime.tzinfo =================================================================================== class datetime.tzinfo An abstract base class for time zone information objects. These are used by the datetime and time classes to provide a customizable notion of time adjustment (for example, to account for time zone and/or daylight saving time). class datetime.timezone A class that implements the tzinfo abstract base class as a fixed offset from the UTC. New in version 3.2. Objects of these types are immutable. Objects of the date type are always naive. An object of type time or datetime may be naive or aware. A datetime object d is aware if d.tzinfo is not None and d.tzinfo.utcoffset(d) does not return None. If d.tzinfo is None, or if d.tzinfo is not None but d.tzinfo.utcoffset(d) returns None, d is naive. A time object t is aware if t.tzinfo is not None and t.tzinfo.utcoffset(None) does not return None. Otherwise, t is naive. =================================================================================== That is not simple. This however, may qualify (emphasis added): =================================================================================== classmethod datetime.utcnow() Return the current UTC date and time, with tzinfo None. This is like now(), but returns the current UTC date and time, as a naive datetime object. An aware current UTC datetime can be obtained by calling *datetime.now(timezone.utc)*. See also now(). =================================================================================== It looks like the .fromtimestamp also accepts tz=timezone.utc, so perhaps that is the simple way to get the timezone aware datetime. I haven't tested, I'm going to bed. :/ -- ~Ethan~ From jeremiahvalerio123 at gmail.com Thu Jan 9 00:56:57 2014 From: jeremiahvalerio123 at gmail.com (jeremiahvalerio123 at gmail.com) Date: Wed, 8 Jan 2014 21:56:57 -0800 (PST) Subject: Constructive Criticism Message-ID: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Hi, hows it going I've been self teaching myself python, and i typed up this small script now i know its not the best the coding is not the best but i would like to know of ways to make a small script like this better so all constructive critisim is Welcome. Here is the link to the code " http://pastebin.com/5uCFR2pz " From ben+python at benfinney.id.au Thu Jan 9 01:09:17 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jan 2014 17:09:17 +1100 Subject: Constructive Criticism References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: <7wmwj5elf6.fsf@benfinney.id.au> jeremiahvalerio123 at gmail.com writes: > Hi, hows it going I've been self teaching myself python Welcome to Python, and to this discussion forum! > and i typed up this small script now i know its not the best the > coding is not the best but i would like to know of ways to make a > small script like this better so all constructive critisim is Welcome. Some constructive criticism: * Please make an effort to write readable English here. A run-on sentence like the above makes it seem as though you don't care enough for our help to make your message easily readable. * Please paste the code in your actual message, rather than directing to an ephemeral website. This is so that the discussion will always have the code for context when later readers view it. Once you re-post your program and describe its purpose, I'm sure there will be some responses giving feedback. -- \ ?My girlfriend has a queen sized bed; I have a court jester | `\ sized bed. It's red and green and has bells on it, and the ends | _o__) curl up.? ?Steven Wright | Ben Finney From menkomigen6 at gmail.com Thu Jan 9 01:06:26 2014 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Wed, 8 Jan 2014 22:06:26 -0800 (PST) Subject: Constructive Criticism In-Reply-To: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: <81a9c283-4940-4ef4-9a79-ed8f118c5532@googlegroups.com> I think the only winning move is not to play. From jeremiahvalerio123 at gmail.com Thu Jan 9 01:16:59 2014 From: jeremiahvalerio123 at gmail.com (jeremiah valerio) Date: Wed, 8 Jan 2014 22:16:59 -0800 (PST) Subject: Constructive Criticism In-Reply-To: References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: <8aacf3b7-2e7f-4d74-80b1-faf3de09ac71@googlegroups.com> On Thursday, January 9, 2014 12:09:17 AM UTC-6, Ben Finney wrote: > jeremiahvalerio123 at gmail.com writes: > > > > > Hi, hows it going I've been self teaching myself python > > > > Welcome to Python, and to this discussion forum! > > > > > and i typed up this small script now i know its not the best the > > > coding is not the best but i would like to know of ways to make a > > > small script like this better so all constructive critisim is Welcome. > > > > Some constructive criticism: > > > > * Please make an effort to write readable English here. A run-on > > sentence like the above makes it seem as though you don't care enough > > for our help to make your message easily readable. > > > > * Please paste the code in your actual message, rather than directing to > > an ephemeral website. This is so that the discussion will always have > > the code for context when later readers view it. > > > > Once you re-post your program and describe its purpose, I'm sure there > > will be some responses giving feedback. > > > > -- > > \ ?My girlfriend has a queen sized bed; I have a court jester | > > `\ sized bed. It's red and green and has bells on it, and the ends | > > _o__) curl up.? ?Steven Wright | > > Ben Finney yea sorry about this screw up "i know its not the best the coding is not the best but" and i'm new to forums never posted so i will take all your input and re-post maybe later thank you. From rosuav at gmail.com Thu Jan 9 01:34:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 17:34:33 +1100 Subject: the Gravity of Python 2 In-Reply-To: <52CE3416.9090501@stoneleaf.us> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> Message-ID: On Thu, Jan 9, 2014 at 4:31 PM, Ethan Furman wrote: > On 01/08/2014 08:34 PM, Chris Angelico wrote: >> >> This is simple: >> >>>>> time.time() >> >> 1389242048.669482 > > > I agree, and I'm sure Roy also agrees, that that is simple. However, that > is *not* a timezone-aware datetime. The point of having the datetime module > is so we all don't have to reroll our own from scratch, and yet this > particular (and increasingly important) operation wasn't intuitive nor easy. What exactly does datetime offer you that a timestamp doesn't? Can we get a quick run-down, please? ChrisA From ben+python at benfinney.id.au Thu Jan 9 01:57:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jan 2014 17:57:21 +1100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> Message-ID: <7wiottej72.fsf@benfinney.id.au> Chris Angelico writes: > What exactly does datetime offer you that a timestamp doesn't? Can we > get a quick run-down, please? Isn't this answered by you reading the standard library documentation for the ?datetime? and ?time? modules? Are you asking for someone to read those for you? If not, can you explain more precisely what you're asking? -- \ ?A child of five could understand this. Fetch me a child of | `\ five.? ?Groucho Marx | _o__) | Ben Finney From breamoreboy at yahoo.co.uk Thu Jan 9 02:03:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 07:03:00 +0000 Subject: Constructive Criticism In-Reply-To: <8aacf3b7-2e7f-4d74-80b1-faf3de09ac71@googlegroups.com> References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> <8aacf3b7-2e7f-4d74-80b1-faf3de09ac71@googlegroups.com> Message-ID: On 09/01/2014 06:16, jeremiah valerio wrote: > On Thursday, January 9, 2014 12:09:17 AM UTC-6, Ben Finney wrote: >> jeremiahvalerio123 at gmail.com writes: >> >> >> >>> Hi, hows it going I've been self teaching myself python >> >> >> >> Welcome to Python, and to this discussion forum! >> >> >> >>> and i typed up this small script now i know its not the best the >> >>> coding is not the best but i would like to know of ways to make a >> >>> small script like this better so all constructive critisim is Welcome. >> >> >> >> Some constructive criticism: >> >> >> >> * Please make an effort to write readable English here. A run-on >> >> sentence like the above makes it seem as though you don't care enough >> >> for our help to make your message easily readable. >> >> >> >> * Please paste the code in your actual message, rather than directing to >> >> an ephemeral website. This is so that the discussion will always have >> >> the code for context when later readers view it. >> >> >> >> Once you re-post your program and describe its purpose, I'm sure there >> >> will be some responses giving feedback. >> >> >> >> -- >> >> \ ?My girlfriend has a queen sized bed; I have a court jester | >> >> `\ sized bed. It's red and green and has bells on it, and the ends | >> >> _o__) curl up.? ?Steven Wright | >> >> Ben Finney > > yea sorry about this screw up "i know its not the best the coding is not the best but" and i'm new to forums never posted so i will take all your input and re-post maybe later thank you. > Before you repost would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Thu Jan 9 02:10:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 07:10:28 +0000 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: On 09/01/2014 03:42, Chris Angelico wrote: > On Thu, Jan 9, 2014 at 2:34 PM, Ben Finney wrote: >> [ a bunch of stuff that I totally agree with ] > > No response needed here :) > > So I was wrong on the specific example of .today(), but asking the > question the other way is at least helpful. Maybe the best solution is > exactly what Roy already posted, or maybe there's some other way to > achieve that. In any case, there is a solution, albeit not as clean as > I would have liked. > >> With time zones, as with text encodings, there is a single technically >> elegant solution (for text: Unicode; for time zones: twelve simple, >> static zones that never change) > > Twelve or twenty-four? Or are you thinking we should all be an even > number of hours away from UTC, which would also work? > > ChrisA > I don't care what anyone says, I'm sticking with GMT. ("UTC" == "Universal Coordinated Time") == False. And what the hell *IS* coordinated? If that was the case this part of this thread wouldn't exist :) Perhaps the solution is the Chinese way, don't have timezones at all. -- 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 Thu Jan 9 02:17:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 07:17:25 +0000 Subject: Time zones and why they change so damned often In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: On 09/01/2014 04:14, Chris Angelico wrote: > On Thu, Jan 9, 2014 at 2:54 PM, Ben Finney wrote: >> I'm approaching it with the goal of knowing better what I'm talking >> about when I advocate scrapping the whole DST system :-) > > I would definitely support the scrapping of DST. I'm less sure that we > need exactly 24 timezones around the world, though. It's not nearly as > big a problem to have the half-hour and quarter-hour timezones - > though it would be easier if timezone were strictly an integer number > of hours. But DST is the real pain. > > What I find, most of the time, is that it's Americans who can't handle > DST. I run an international Dungeons and Dragons campaign (we play > online, and new players are most welcome, as are people watching!), > and the Aussies (myself included) know to check UTC time, the Brits > and Europeans check UTC or just know what UTC is, and the Americans > say "Doesn't that happen at 8 o'clock Eastern time?" and get confused. > I don't understand this. Are my players drawn exclusively from the > pool of people who've never worked with anyone in Arizona [1]? Yes, > I'm stereotyping a bit here, and not every US player has had problems > with this, but it's the occasional US player who knows to check, and > the rare European, British, or Aussie player who doesn't. > > In any case, the world-wide abolition of DST would eliminate the > problem. The only remaining problem would be reminding people to > change the batteries in their smoke detectors. > > ChrisA > > [1] For those who aren't right up on timezone trivia, AZ has no DST. > Similarly the Australian state of Queensland does not shift its > clocks. > I remember this "From February 1968 to November 1971 the UK kept daylight saving time throughout the year mainly for commercial reasons, especially regarding time conformity with other European countries". My source http://www.timeanddate.com/time/uk/time-zone-background.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From dss.leb at gmail.com Thu Jan 9 02:34:56 2014 From: dss.leb at gmail.com (d ss) Date: Wed, 8 Jan 2014 23:34:56 -0800 (PST) Subject: python finance In-Reply-To: References: <6b92efa1-b971-427a-820e-3580006fde40@googlegroups.com> <56fa735b-16bf-44f3-96a7-f2a68f7c7ac6@googlegroups.com> <9d5f1206-cdf5-43bd-9c50-278950aaa9f3@googlegroups.com> <1389028016.18130.python-list@python.org> <4bef9196-be41-4f1e-a904-d098952053bf@googlegroups.com> Message-ID: <03f55c16-595a-4482-94e6-fc422a2fe4b5@googlegroups.com> On Monday, January 6, 2014 6:58:30 PM UTC-5, Walter Hurry wrote: > On Mon, 06 Jan 2014 13:11:53 -0800, d ss wrote: > > > > i wrote just 2 words with a clear > > > indicative title: "Python, Finance" which summarizes the following "if > > > you are good in python and interested in applying your python knowledge > > > to the field of finance then we may have a common interest in talking > > > together" :D that s it! > > > > No, you didn't. The title wasn't capitalised. The advertisement was > > similarly poor English, the post was to the wrong mailing list and you > > posted usong G**gle G****s. > You meant USING! From rosuav at gmail.com Thu Jan 9 02:56:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 9 Jan 2014 18:56:34 +1100 Subject: the Gravity of Python 2 In-Reply-To: <7wiottej72.fsf@benfinney.id.au> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: On Thu, Jan 9, 2014 at 5:57 PM, Ben Finney wrote: > Chris Angelico writes: > >> What exactly does datetime offer you that a timestamp doesn't? Can we >> get a quick run-down, please? > > Isn't this answered by you reading the standard library documentation > for the ?datetime? and ?time? modules? Are you asking for someone to > read those for you? If not, can you explain more precisely what you're > asking? Sorry. I'm more specifically asking what Roy's using, here. I can see what functions it offers, so my language was a bit sloppy. What I meant is: What can you (Roy), with your use-case, achieve with datetime that you can't achieve (at least reasonably easily) with a timestamp? Nobody ever uses every feature of a module, and I often see people using some library/module/function when they could be using a simpler and easier base function (like using JQuery for basic web page scripting). ChrisA From wxjmfauth at gmail.com Thu Jan 9 03:31:55 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 9 Jan 2014 00:31:55 -0800 (PST) Subject: Dictionary In-Reply-To: References: Message-ID: <1a719495-c63a-4109-89d7-ca5118f5ccdc@googlegroups.com> Le mercredi 8 janvier 2014 20:00:02 UTC+1, Bischoop a ?crit?: > Walter Hurry wrote: > > > > > On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop wrote: > > > > > >> I have a txt file with some words, and need simply program that will > > >> print me words containing provided letters. > > >> > > >> For example: > > >> Type the letters: > > >> (I type: g,m,o) > > >> open the dictionary.txt > > >> check words containing:g,m,o in dictionary.txt > > >> if there are words containing: ["g", "m", "o" ] > > >> print words with g,m,o > > > > > > Well, what have you tried so far, and what result did you get? > > > > > > The incredibly helpful people here will provide advice, guidance and > > > pointers, but it won't help you at all if they just do your homework for > > > you. > > > > > > Honestly Im newbie in Python, years ago (10 already) I wrote simply program > > something like a TEST: Capitals of Countries. You could learn the capitals > > of some countries, and then you could try to solve a test. I know it's seems > > so simply for you guys but I was quite pride of myself :-) > > > > Now because of free time I took my book which I used years ago about python > > and try to learn it again, and as motivation I try to write the program I > > described above just to give me a kick :-), however got no idea how to start > > it, I meand there is so many moduls (import this, import that), I know how > > to open, read file etc. Just stuck with that, got no clue what and how use > > this that what I need to seek the words from the files if I need a words > > with letters I want. >>> # a starting point >>> lettres = set('???') >>> W?rter = ['abc???b', 'a????', '???zzz', '??zz', 'Strau?', '', 'nul'] >>> for word in W?rter: ... tmp = set(word) ... print('{:10} : {}'.format(word, lettres.issubset(tmp))) ... abc???b : True a???? : True ???zzz : True ??zz : False Strau? : False : False nul : False >>> From kushal.kumaran at gmail.com Thu Jan 9 01:06:29 2014 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Thu, 09 Jan 2014 11:36:29 +0530 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> Roy Smith writes: > In article , > Chris Angelico wrote: > >> On Thu, Jan 9, 2014 at 2:35 PM, Roy Smith wrote: >> >> Yes, it *is* simple. It *is* easy. I've been working with pure-UTC >> >> times (either called time_t, or TIMESTAMP WITH TIME ZONE, or even just >> >> float) for decades. Like with so many other things, the easiest >> >> solution is also the best, because you can just work with one stable >> >> representation and abstraction on the inside, with conversions to/from >> >> it at the boundaries. It IS that easy. >> > >> > Please show me the simple code to obtain an aware UTC datetime >> > representing the current time. >> >> In Pike: >> time(); >> >> In PostgreSQL: >> SELECT now(); >> >> In C: >> time(0); >> >> All of these give a value in UTC. > > None of which answer my question. How, in Python, do you get an aware > UTC datetime object? I know how to get a numeric representation of the > time as the number of seconds since the Unix epoch. That's not what I > asked. > My local copy of the python 3.2.3 docs says: classmethod datetime.utcnow() Return the current UTC date and time, with tzinfo None. This is like now(), but returns the current UTC date and time, as a naive datetime object. An aware current UTC datetime can be obtained by calling datetime.now(timezone.utc). See also now(). Hope this helps. >> So maybe the key is to use utcfromtimestamp()? I don't know. > > So, I'm really confused what point you're trying to make. You started > out arguing that I should be using aware datetimes instead of naive > datetimes. I said that the reason I don't use aware datetimes is > because they're so much more difficult to generate. You said they were > simple to generate. > > So, I'd like to see your code which generates an aware UTC datetime > object in Python. And then we can argue about whether it's simple or > not :-) -- regards, kushal -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 489 bytes Desc: not available URL: From breamoreboy at yahoo.co.uk Thu Jan 9 03:42:43 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 08:42:43 +0000 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: On 09/01/2014 01:27, Roy Smith wrote: > In article , > Kevin Walzer wrote: > >> I haven't updated my Python apps to 3.x because there's nothing in 3.x >> that offers benefits to my users. > > I almost found a reason to move to Python 3 today. Then I got smacked. > > I had a datetime. I needed a unix timestamp. People need to go back > and forth between these two things all the time and in Python 2 it's the > very definition of impedance mismatch. What should be a dead simple > operation involves long threads on stackoverflow discussing which of > several amalgamations of duct tape is the least ugly. > > Anyway, I discovered that Python 3.3's datetime has a .timestamp() > method. Yeah. Finally. Exactly what the world had needed for years. > Then I kept reading and found: > > Note: There is no method to obtain the POSIX timestamp directly from a > naive datetime instance representing UTC time. > > Ugh. So, we're back to square one. They go on to suggest one of two > workarounds, either calling datetime.replace() to insert a timezone, or > subtracting from the epoch manually. > > Naive datetimes are what everybody uses. It's what utcnow() gives you. > So why make life difficult for everybody? Python 3 didn't win a convert > today. > Yep, dates and times are easy. That's why there are 17 issues open on the bug tracker referencing tzinfo alone. Poor old 1100942 is high priority, was created 12/01/2005 and has missed 3.4. So if it gets into 3.5 it'll have already celebrated its 10th birthday. It doesn't say much for the amount of effort that we put into looking after issues. -- 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 Thu Jan 9 03:53:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 08:53:28 +0000 Subject: the Gravity of Python 2 In-Reply-To: <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> Message-ID: On 09/01/2014 06:06, Kushal Kumaran wrote: > > My local copy of the python 3.2.3 docs says: > > classmethod datetime.utcnow() > > Return the current UTC date and time, with tzinfo None. This is like > now(), but returns the current UTC date and time, as a naive > datetime object. An aware current UTC datetime can be obtained by > calling datetime.now(timezone.utc). See also now(). > > Hope this helps. > Blimey, you learn something new everyday, thanks. And it works :) In [7]: datetime.datetime.now(datetime.timezone.utc) Out[7]: datetime.datetime(2014, 1, 9, 8, 51, 13, 945312, tzinfo=datetime.timezone.utc) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Thu Jan 9 04:03:18 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 09 Jan 2014 20:03:18 +1100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> Message-ID: <7w8uupedd5.fsf@benfinney.id.au> Kushal Kumaran writes: > Roy Smith writes: > > How, in Python, do you get an aware UTC datetime object? > > My local copy of the python 3.2.3 docs says: > > classmethod datetime.utcnow() > > Return the current UTC date and time, with tzinfo None. This is > like now(), but returns the current UTC date and time, as a naive > datetime object. An aware current UTC datetime can be obtained by > calling datetime.now(timezone.utc). See also now(). > > Hope this helps. No, that won't do what was asked. The ?datetime.datetime.utcnow? function explicitly returns a naive datetime object, not an aware datetime object. -- \ ?We must respect the other fellow's religion, but only in the | `\ sense and to the extent that we respect his theory that his | _o__) wife is beautiful and his children smart.? ?Henry L. Mencken | Ben Finney From kushal.kumaran at gmail.com Thu Jan 9 04:21:51 2014 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Thu, 09 Jan 2014 14:51:51 +0530 Subject: the Gravity of Python 2 In-Reply-To: <7w8uupedd5.fsf@benfinney.id.au> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> <7w8uupedd5.fsf@benfinney.id.au> Message-ID: <52ce6a37.0b01310a.3c0d.ffff9926@mx.google.com> Ben Finney writes: > Kushal Kumaran writes: > >> Roy Smith writes: >> > How, in Python, do you get an aware UTC datetime object? >> >> My local copy of the python 3.2.3 docs says: >> >> classmethod datetime.utcnow() >> >> Return the current UTC date and time, with tzinfo None. This is >> like now(), but returns the current UTC date and time, as a naive >> datetime object. An aware current UTC datetime can be obtained by >> calling datetime.now(timezone.utc). See also now(). >> >> Hope this helps. > > No, that won't do what was asked. The ?datetime.datetime.utcnow? > function explicitly returns a naive datetime object, not an aware > datetime object. > Yes, but the documentation for utcnow explicitly tells you how to get an aware object. "An aware current UTC datetime can be obtained by calling datetime.now(timezone.utc)." -- regards, kushal -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 489 bytes Desc: not available URL: From breamoreboy at yahoo.co.uk Thu Jan 9 04:51:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 09:51:40 +0000 Subject: the Gravity of Python 2 In-Reply-To: <7w8uupedd5.fsf@benfinney.id.au> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> <7w8uupedd5.fsf@benfinney.id.au> Message-ID: On 09/01/2014 09:03, Ben Finney wrote: > Kushal Kumaran writes: > >> Roy Smith writes: >>> How, in Python, do you get an aware UTC datetime object? >> >> My local copy of the python 3.2.3 docs says: >> >> classmethod datetime.utcnow() >> >> Return the current UTC date and time, with tzinfo None. This is >> like now(), but returns the current UTC date and time, as a naive >> datetime object. An aware current UTC datetime can be obtained by >> calling datetime.now(timezone.utc). See also now(). >> >> Hope this helps. > > No, that won't do what was asked. The ?datetime.datetime.utcnow? > function explicitly returns a naive datetime object, not an aware > datetime object. > How closely do you bother to read posts that people like Kushal Kumaran have taken the trouble to post? Eleven lines above this one it says (my emphasis) "An *AWARE* current UTC datetime can be obtained by calling datetime.now(timezone.utc)". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From __peter__ at web.de Thu Jan 9 04:56:37 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jan 2014 10:56:37 +0100 Subject: Constructive Criticism References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: jeremiahvalerio123 at gmail.com wrote: > Hi, hows it going I've been self teaching myself python, and i typed up > this small script now i know its not the best the coding is not the best > but i would like to know of ways to make a small script like this better > so all constructive critisim is Welcome. > > > > Here is the link to the code > > " http://pastebin.com/5uCFR2pz " > time.sleep(1) > import time > print("Closing in 9 ") > time.sleep(1) > import time > print("Closing in 8 ") - You should import modules just once, at the beginning of your script. - Repetetive tasks are best handled with a for-loop, e. g.: >>> import time >>> for seconds_left in reversed(range(1, 10)): ... print("Closing in", seconds_left, "seconds") ... time.sleep(1) ... Closing in 9 seconds Closing in 8 seconds Closing in 7 seconds Closing in 6 seconds Closing in 5 seconds Closing in 4 seconds Closing in 3 seconds Closing in 2 seconds Closing in 1 seconds > user_input = input("\nWhos your favorite Football team? \n 1.Arizona > Cardinals\n 2.Atlanta Falcons\n 3.Baltimore Ravens\n 4.Buffalo Bills\n > 5.Miami Dolphins\n 6.Minnesota Vikings \n 7.New England Patriots \n > 8.New Orleans Saints \n 9.Carolina [snip] Python offers triple-quoted strings which may include newline literals: user_input = input(""" Who's your favorite Football team? 1. Arizona Cardinals 2. Atlanta Falcons ... """) > if user_input == "1" : > print("\nThey suck! BYE!") > > elif user_input == "2" : > print("\nThey suck! BYE!") > > elif user_input == "3" : > print("\nThey suck!BYE!") [snip] Ignoring the typos you are taking the same action for all inputs but "17". So: if user_input != "17": print() print("They suck! BYE!") You should give some thought how unexpected user input like "", "123", "whatever" should be handled. > elif user_input == "no" : > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.") > import time > time.sleep(1) > import time > print("Closing in 9 ") > time.sleep(1) > import time > print("Closing in 8 ") > time.sleep(1) > import time OK, you are doing the count-down thing twice -- time to write a function, say countdown(), that you can put where you need a count-down instead of the repetetive code. From mhysnm1964 at gmail.com Thu Jan 9 05:08:34 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Thu, 9 Jan 2014 21:08:34 +1100 Subject: nested dictionaries and functions in data structures. In-Reply-To: <59989803.3050665.1389097176191.JavaMail.root@sequans.com> References: <59989803.3050665.1389097176191.JavaMail.root@sequans.com> Message-ID: <43753CFC-B306-4845-A78C-176054D57381@gmail.com> Thanks for that. I will have a play and see how I can apply your example. On 07/01/2014, at 11:19 PM, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> Thanks for that. It resolved the issue and it was so simple compared >> to everything else I saw on the net. >> >> Only outstanding thing I have to work out is how to execute functions >> from a dictionary. I will continue searching on the net. >> >> >> Sean > > This may help you (untested code) > > class Workers: > @staticmethod > def ospf(*args, **kwargs): > print args, kwargs > return 'Bar' > > @staticmethod > def bhp(*args, **kwargs): > return 'Foo' > > outputs = {'ospf' : {1 : {'param1' : 'foo', 'param2' : 'foo2'}} > > for command, value in outputs.items(): > for counter, kwargs in value: > func = getattr(Workers, command) # get the function > func(**kwargs) # the actual call > > It would be possible to do it without the *args, **kwargs magic. You can write ospf and bhp with the explicit parameters, however you must make sure you pass the correct number of parameter in the call. > > 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 tobias.oberstein at tavendo.de Thu Jan 9 05:24:17 2014 From: tobias.oberstein at tavendo.de (Tobias Oberstein) Date: Thu, 9 Jan 2014 02:24:17 -0800 Subject: AW: WebSocket for Python 2 and 3 on Twisted and asyncio In-Reply-To: <634914A010D0B943A035D226786325D4446BD1EABA@EXVMBX020-12.exch020.serverdata.net> References: <634914A010D0B943A035D226786325D4446BD1EABA@EXVMBX020-12.exch020.serverdata.net> Message-ID: <634914A010D0B943A035D226786325D4446BE403E2@EXVMBX020-12.exch020.serverdata.net> Autobahn now also supports asyncio on Python 2! https://github.com/tavendo/AutobahnPython#python-support This is made possible by Trollius, an awesome backport of asyncio: https://pypi.python.org/pypi/trollius/0.1.2 > -----Urspr?ngliche Nachricht----- > Von: Python-list [mailto:python-list- > bounces+tobias.oberstein=tavendo.de at python.org] Im Auftrag von Tobias > Oberstein > Gesendet: Freitag, 3. Januar 2014 13:08 > An: python-list at python.org > Betreff: WebSocket for Python 2 and 3 on Twisted and asyncio > > Hi, > > Autobahn provides open-source implementations of > > * The WebSocket Protocol > * The Web Application Messaging Protocol (WAMP) > > https://github.com/tavendo/AutobahnPython > https://pypi.python.org/pypi/autobahn > > Starting with the release 0.7.0, Autobahn now fully supports (with all > features) both > > * Twisted (on Python 2/3) and > * asyncio (on Python 3.3+) > > as the underlying networking framework. > > Here is a complete example of WebSocket server and client: > > Twisted: > https://github.com/tavendo/AutobahnPython/tree/master/examples/twist > ed/websocket/echo > > Asyncio: > https://github.com/tavendo/AutobahnPython/tree/master/examples/asyn > cio/websocket/echo > > The application code is very similar or even identical. > > Cheers, > /Tobias > -- > https://mail.python.org/mailman/listinfo/python-list From piet at vanoostrum.org Thu Jan 9 06:26:21 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 09 Jan 2014 12:26:21 +0100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> <7w8uupedd5.fsf@benfinney.id.au> Message-ID: Kushal Kumaran writes: > Yes, but the documentation for utcnow explicitly tells you how to get > an aware object. > > "An aware current UTC datetime can be obtained by calling > datetime.now(timezone.utc)." And in Python 2.7 you can just copy the definition of utc from the doc and use that: from datetime import tzinfo, timedelta, datetime ZERO = timedelta(0) class UTC(tzinfo): """UTC""" def utcoffset(self, dt): return ZERO def tzname(self, dt): return "UTC" def dst(self, dt): return ZERO utc = UTC() -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From alister.ware at ntlworld.com Thu Jan 9 06:32:33 2014 From: alister.ware at ntlworld.com (Alister) Date: Thu, 09 Jan 2014 11:32:33 GMT Subject: Learning python networking References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: On Wed, 08 Jan 2014 19:49:40 -0800, Dan Stromberg wrote: > > The third quote, from Brian Kernighan, seems to underestimate the > complexity of asynchronous programming in the large - it's probably not > just twice as hard. Perhaps it should be rephrased as "at least twice as hard" It really does pay to follow the KISS (Keep It Simple Stupid) philosophy. -- Save energy: Drive a smaller shell. From prapulla447 at gmail.com Thu Jan 9 06:53:37 2014 From: prapulla447 at gmail.com (Prapulla Kumar) Date: Thu, 9 Jan 2014 17:23:37 +0530 Subject: Python GTK GUI struck when process is going on. Message-ID: Hi all, I'm using python gtk to upload file to S3 service by boto API , GUI struck when uploading file and releases the GUI after completed download I'm using thread to show progress of upload in GUI but it struck. Can you some suggestion how to show progress of upload in GUI or any spinner until upload finish With Regards Prapulla Kumar R -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.ware at ntlworld.com Thu Jan 9 07:07:41 2014 From: alister.ware at ntlworld.com (Alister) Date: Thu, 09 Jan 2014 12:07:41 GMT Subject: Time zones and why they change so damned often References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: On Thu, 09 Jan 2014 07:17:25 +0000, Mark Lawrence wrote: > On 09/01/2014 04:14, Chris Angelico wrote: >> On Thu, Jan 9, 2014 at 2:54 PM, Ben Finney >> wrote: >>> I'm approaching it with the goal of knowing better what I'm talking >>> about when I advocate scrapping the whole DST system :-) >> >> I would definitely support the scrapping of DST. I'm less sure that we >> need exactly 24 timezones around the world, though. It's not nearly as >> big a problem to have the half-hour and quarter-hour timezones - >> though it would be easier if timezone were strictly an integer number >> of hours. But DST is the real pain. >> >> What I find, most of the time, is that it's Americans who can't handle >> DST. I run an international Dungeons and Dragons campaign (we play >> online, and new players are most welcome, as are people watching!), >> and the Aussies (myself included) know to check UTC time, the Brits and >> Europeans check UTC or just know what UTC is, and the Americans say >> "Doesn't that happen at 8 o'clock Eastern time?" and get confused. >> I don't understand this. Are my players drawn exclusively from the pool >> of people who've never worked with anyone in Arizona [1]? Yes, >> I'm stereotyping a bit here, and not every US player has had problems >> with this, but it's the occasional US player who knows to check, and >> the rare European, British, or Aussie player who doesn't. >> >> In any case, the world-wide abolition of DST would eliminate the >> problem. The only remaining problem would be reminding people to change >> the batteries in their smoke detectors. >> >> ChrisA >> >> [1] For those who aren't right up on timezone trivia, AZ has no DST. >> Similarly the Australian state of Queensland does not shift its clocks. >> >> > I remember this "From February 1968 to November 1971 the UK kept > daylight saving time throughout the year mainly for commercial reasons, > especially regarding time conformity with other European countries". My > source http://www.timeanddate.com/time/uk/time-zone-background.html we dont have "Daylight saving time" we switch between GMT (Greenwich Mean Time) and BST (British Summer Time) at some point in the past we have also used DST (Double Summer Time). -- Endless the world's turn, endless the sun's spinning Endless the quest; I turn again, back to my own beginning, And here, find rest. From ben+python at benfinney.id.au Thu Jan 9 08:35:00 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 10 Jan 2014 00:35:00 +1100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> <7w8uupedd5.fsf@benfinney.id.au> <52ce6a37.0b01310a.3c0d.ffff9926@mx.google.com> Message-ID: <7wwqi9cm7v.fsf@benfinney.id.au> Kushal Kumaran writes: > Ben Finney writes: > > > Kushal Kumaran writes: > > > >> Roy Smith writes: > >> > How, in Python, do you get an aware UTC datetime object? > >> > >> classmethod datetime.utcnow() > >> > >> Return the current UTC date and time, with tzinfo None. [?] > > > > No, that won't do what was asked. The ?datetime.datetime.utcnow? > > function explicitly returns a naive datetime object, not an aware > > datetime object. > > Yes, but the documentation for utcnow explicitly tells you how to get > an aware object. > > "An aware current UTC datetime can be obtained by calling > datetime.now(timezone.utc)." And we come full circle: This is exactly what Roy's original question was (IIUC) trying to address. That process is not obvious, and it's not simple: it's a series of difficult-to-discover function calls instead of just one obvious one. -- \ ?If you don't know what your program is supposed to do, you'd | `\ better not start writing it.? ?Edsger W. Dijkstra | _o__) | Ben Finney From piet at vanoostrum.org Thu Jan 9 09:06:00 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 09 Jan 2014 15:06:00 +0100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: Chris Angelico writes: > On Thu, Jan 9, 2014 at 2:34 PM, Ben Finney wrote: >> [ a bunch of stuff that I totally agree with ] > > No response needed here :) > > So I was wrong on the specific example of .today(), but asking the > question the other way is at least helpful. Maybe the best solution is > exactly what Roy already posted, or maybe there's some other way to > achieve that. In any case, there is a solution, albeit not as clean as > I would have liked. > >> With time zones, as with text encodings, there is a single technically >> elegant solution (for text: Unicode; for time zones: twelve simple, >> static zones that never change) > > Twelve or twenty-four? Or are you thinking we should all be an even > number of hours away from UTC, which would also work? Even 24 doesn't take into account DST. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From roy at panix.com Thu Jan 9 09:14:22 2014 From: roy at panix.com (Roy Smith) Date: Thu, 09 Jan 2014 09:14:22 -0500 Subject: the Gravity of Python 2 References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: In article , Chris Angelico wrote: > What can you (Roy), with your use-case, achieve with datetime that > you can't achieve (at least reasonably easily) with a timestamp? As I'm mentioned several times, when you print a datetime, you get something that's human friendly. When you print a timestamp (i.e. a float), you get a lot of digits. I don't know about you, but I can't look at 1389274842 and get any feel for whether that was in the middle of the night or at 5 in the afternoon, near our peak traffic time. Nor can I tell if it was today, yesterday, last month, or a week from next Tuesday. Datetimes make it easy to do things like, "find the time of the preceding (or following) midnight". Or, "what month is this timestamp part of?" These are operations we need to do a lot, to answer questions like, "How many unique users did we have on a given day?", or "Which monthly database archive file do I need to grab to get information about this historical event?" Datetimes are self-documenting. If I'm in the python shell and have something called t, I can do help(t) or dir(t) to find out what operations it has. Datetimes are self-describing. If I have a datetime or a timedelta, I know what I've got. I've written more than one bug where I assumed a number somebody handed me was in seconds but it turned out to be in ms. That can never happen with a timedelta. We do a lot of stuff in javascript, where times are ms, so this is a common problem for us. Oh, and another thing I can do with a datetime that I can't do with a unix timestamp. I can represent the day I was born. From rosuav at gmail.com Thu Jan 9 09:34:13 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 01:34:13 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: On Fri, Jan 10, 2014 at 1:06 AM, Piet van Oostrum wrote: > Chris Angelico writes: > >> On Thu, Jan 9, 2014 at 2:34 PM, Ben Finney wrote: >>> With time zones, as with text encodings, there is a single technically >>> elegant solution (for text: Unicode; for time zones: twelve simple, >>> static zones that never change) >> >> Twelve or twenty-four? Or are you thinking we should all be an even >> number of hours away from UTC, which would also work? > > Even 24 doesn't take into account DST. That was the point. We can abolish codepages by using Unicode, which covers everything. We could abolish time messes by having every locality settle permanently on one timezone; Ben's theory demands that all timezones be some integer number of hours +/- UTC, which IMO is optional, but mainly it should be easy to figure out any two locations' difference: just subtract one's UTC offset from the other's. Similarly, you can calculate the difference between two times at the same location by simple subtraction; currently, you also have to consider the possibility of a DST switch (from noon to noon across a switch is either 23 or 25 hours). Actually, the nearest parallel to Unicode is probably "use UTC everywhere", which makes for a superb internal representation and transmission format, but bugs most human beings :) ChrisA From roy at panix.com Thu Jan 9 09:32:39 2014 From: roy at panix.com (Roy Smith) Date: Thu, 09 Jan 2014 09:32:39 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52ce3c6d.8814e00a.3abb.ffff86a7@mx.google.com> <7w8uupedd5.fsf@benfinney.id.au> <52ce6a37.0b01310a.3c0d.ffff9926@mx.google.com> Message-ID: In article , Ben Finney wrote: > Kushal Kumaran writes: > > > Ben Finney writes: > > > > > Kushal Kumaran writes: > > > > > >> Roy Smith writes: > > >> > How, in Python, do you get an aware UTC datetime object? > > >> > > >> classmethod datetime.utcnow() > > >> > > >> Return the current UTC date and time, with tzinfo None. [???] > > > > > > No, that won't do what was asked. The ???datetime.datetime.utcnow??? > > > function explicitly returns a naive datetime object, not an aware > > > datetime object. > > > > Yes, but the documentation for utcnow explicitly tells you how to get > > an aware object. > > > > "An aware current UTC datetime can be obtained by calling > > datetime.now(timezone.utc)." > > And we come full circle: This is exactly what Roy's original question > was (IIUC) trying to address. That process is not obvious, and it's not > simple: it's a series of difficult-to-discover function calls instead of > just one obvious one. Yes, exactly. Thank you. From roy at panix.com Thu Jan 9 09:44:56 2014 From: roy at panix.com (Roy Smith) Date: Thu, 09 Jan 2014 09:44:56 -0500 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: In article , Chris Angelico wrote: > Actually, the nearest parallel to Unicode is probably "use UTC > everywhere", which makes for a superb internal representation and > transmission format, but bugs most human beings :) It is, by the way, the solution that the aviation industry has adopted. All communication between aircraft and controllers is in UTC (pronounced "zulu"). Weather reports and forecasts are in UTC. Regulatory notices are in UTC. The time when one edition of a chart will be replaced by the next edition is in UTC. If I'm somewhere over the Atlantic, talking to a controller sitting in Shannon, Ireland, negotiating when I'm going to be allowed to continue on my route from New York to Istambul, the last thing I want is anybody to be confused about timezones. From rosuav at gmail.com Thu Jan 9 09:57:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 01:57:57 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: On Fri, Jan 10, 2014 at 1:14 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> What can you (Roy), with your use-case, achieve with datetime that >> you can't achieve (at least reasonably easily) with a timestamp? Thanks for this collection! Now we can discuss. > As I'm mentioned several times, when you print a datetime, you get > something that's human friendly. When you print a timestamp (i.e. a > float), you get a lot of digits. I don't know about you, but I can't > look at 1389274842 and get any feel for whether that was in the middle > of the night or at 5 in the afternoon, near our peak traffic time. Nor > can I tell if it was today, yesterday, last month, or a week from next > Tuesday. Sure. There is a lot of value in having a class that knows how it should be displayed. I'm not sure the current datetime repr is good for anything more than debugging, but I agree that "datetime.datetime(2014, 1, 9, 5, 57, 59, 929176)" is more likely to be useful than a raw number. > Datetimes make it easy to do things like, "find the time of the > preceding (or following) midnight". Or, "what month is this timestamp > part of?" These are operations we need to do a lot, to answer questions > like, "How many unique users did we have on a given day?", or "Which > monthly database archive file do I need to grab to get information about > this historical event?" That's true; the same operations done with timestamps look like this: >>> ts = time.time() >>> ts_at_midnight_utc = ts - ts%86400 >>> ts_at_midnight_utc 1389225600.0 Not nearly as obvious what's happening. And months are more complicated still, so it's probably easiest to use strftime: >>> time.strftime("%Y%m",time.gmtime(ts)) '201401' which could then be used as a lookup key for a counter or whatever. Yep, that's not as clean as simply calling a method. > Datetimes are self-documenting. If I'm in the python shell and have > something called t, I can do help(t) or dir(t) to find out what > operations it has. Partly true, but not everything's there. For instance, if you have a list of strings, you won't find a way to join them together in its help() or dir(), and yet it's a fundamental and very important operation. > Datetimes are self-describing. If I have a datetime or a timedelta, I > know what I've got. I've written more than one bug where I assumed a > number somebody handed me was in seconds but it turned out to be in ms. > That can never happen with a timedelta. We do a lot of stuff in > javascript, where times are ms, so this is a common problem for us. Sure. Though that's no different from other cases where you need out-of-band information to understand something, as we've just been discussing in the threads about text handling - if you have a puddle of bytes, you can't decode them to text without knowing what the encoding is. [1] If your data's coming from JS, it won't be a timedelta, it'll be a number; at some point you have to turn that into a timedelta object, so you still have the same problem. > Oh, and another thing I can do with a datetime that I can't do with a > unix timestamp. I can represent the day I was born. Maybe you can't with the original C definition of time_t as an unsigned integer, but the notion of a Unix timestamp can plausibly be extended (a) to negative numbers, and (b) to non-integers. Python definitely does the latter; its ability to do the former depends somewhat on the underlying C library's support: Windows: >>> time.strftime("%Y%m",time.gmtime(-100000)) Traceback (most recent call last): File "", line 1, in time.strftime("%Y%m",time.gmtime(-100000)) OSError: [Errno 22] Invalid argument Linux: >>> time.strftime("%Y%m",time.gmtime(-100000)) '196912' >>> time.strftime("%Y%m",time.gmtime(-2**31)) '190112' >>> time.strftime("%Y%m",time.gmtime(-2**31-1)) Traceback (most recent call last): File "", line 1, in ValueError: timestamp out of range for platform time_t So what I'm seeing here is that the direct use of a time_t will cover everything in an ugly way, but that a class wrapping it up could fix that. And fundamentally, the only problem with datetime (which, for the most part, is exactly that wrapper) is that it's unobvious how to get a simple UTC timestamp. Has the unobviousness been solved by a simple recipe? And if so, should that tip be added to the datetime module docs somewhere? ChrisA [1] Yes, I said "puddle of bytes". What would you call it? Am interested to hear! From dan at tombstonezero.net Thu Jan 9 10:01:18 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 9 Jan 2014 15:01:18 +0000 (UTC) Subject: the Gravity of Python 2 References: <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: On Thu, 09 Jan 2014 09:14:22 -0500, Roy Smith wrote: > Oh, and another thing I can do with a datetime that I can't do with a > unix timestamp. I can represent the day I was born. At the risk of dating myself, the day I was born is -231094800. Dan From python at mrabarnett.plus.com Thu Jan 9 10:15:01 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 09 Jan 2014 15:15:01 +0000 Subject: Python GTK GUI struck when process is going on. In-Reply-To: References: Message-ID: <52CEBCF5.6060804@mrabarnett.plus.com> On 2014-01-09 11:53, Prapulla Kumar wrote: > Hi all, > I'm using python gtk to upload file to S3 service by boto API , > GUI struck when uploading file and releases the GUI after completed download > I'm using thread to show progress of upload in GUI but it struck. > Can you some suggestion how to show progress of upload in GUI or any > spinner until upload finish > You say that you're using a thread to show the progress. Does that mean that you're doing the uploading in the main thread? If yes, then that's the wrong way round. It's the uploading that needs to be done in the background thread. From rosuav at gmail.com Thu Jan 9 10:17:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 02:17:45 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: On Fri, Jan 10, 2014 at 2:01 AM, Dan Sommers wrote: > On Thu, 09 Jan 2014 09:14:22 -0500, Roy Smith wrote: > >> Oh, and another thing I can do with a datetime that I can't do with a >> unix timestamp. I can represent the day I was born. > > At the risk of dating myself, the day I was born is -231094800. Which, according to a Unix build of Python, is quite representable: >>> time.strftime("%Y-%m-%d",time.gmtime(-231094800)) '1962-09-05' This isn't a problem. Now, if you were considering yourself for a romantic candle-lit dinner and a movie afterward, then maybe there's some risk in dating yourself :) ChrisA From rosuav at gmail.com Thu Jan 9 10:24:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 02:24:11 +1100 Subject: argparse action on default values In-Reply-To: <7353849.WXZ0zEZ0QV@horus> References: <7353849.WXZ0zEZ0QV@horus> Message-ID: On Thu, Jan 9, 2014 at 5:20 AM, Florian Lindner wrote: > def norm_path(*parts): > """ Returns the normalized, absolute, expanded and joined path, assembled of all parts. """ > parts = [ str(p) for p in parts ] > return os.path.abspath(os.path.expanduser(os.path.join(*parts))) Apologies for responding to something that's not the point of your post, but I see this as a job for map, rather than a list comp: def norm_path(*parts): """ Returns the normalized, absolute, expanded and joined path, assembled of all parts. """ path = os.path.join(*map(str,parts)) return os.path.abspath(os.path.expanduser(path)) (or completely onelinered, since you don't seem to mind longish lines). ChrisA From wingusr at gmail.com Thu Jan 9 10:29:18 2014 From: wingusr at gmail.com (TP) Date: Thu, 9 Jan 2014 07:29:18 -0800 Subject: Editor for Python In-Reply-To: <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> References: <3bfd7f87@news.airtel.net> <6b9049ab-e168-4f92-9526-edcaf806d2cd@googlegroups.com> Message-ID: On Friday, 23 November 2001 04:13:40 UTC+5:30, MANUEL FERNANDEZ PEREZ wrote: > > Hello, > > I'm looking for an editor for Python.I' m interested it works on > Windows.Can > > anybody help me? > It's an IDE rather than "just" an editor but how about PyCharm 3 Community Edition? [1] [1] https://www.jetbrains.com/pycharm/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From davea at davea.name Thu Jan 9 10:34:02 2014 From: davea at davea.name (Dave Angel) Date: Thu, 09 Jan 2014 10:34:02 -0500 Subject: =?UTF-8?Q?Re:_Time_zones_and_why_they_change_so_dam?= =?UTF-8?Q?ned_often_(was:_the_Gravity=0A_of_Python_2)?= In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: On Thu, 9 Jan 2014 15:14:55 +1100, Chris Angelico wrote: > [1] For those who aren't right up on timezone trivia, AZ has no DST. > Similarly the Australian state of Queensland does not shift its > clocks. And Indiana. -- DaveA From jeanmichel at sequans.com Thu Jan 9 10:50:21 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 9 Jan 2014 16:50:21 +0100 (CET) Subject: Editor for Python In-Reply-To: <413939E4-4BE5-4923-A96D-18C8E28A0E0C@gmail.com> Message-ID: <1293262712.3373607.1389282621830.JavaMail.root@sequans.com> ----- Original Message ----- > > On Jan 8, 2014, at 10:53 AM, Jean-Michel Pichavant > wrote: > > >>> -- IMPORTANT NOTICE: > >>> > >> > >> too late you have sent this to a public forum > > > > No pb with that, the python list is the intended recipient :) > > > > I tried to negotiate this with my IT guys, but it looks like it's > > now mandatory, something related to being in the USA stock market. > Yeah, when in doubt blame the Americans. Sorry if I hurt your feelings, have a look at http://www.sarbanes-oxley-101.com/ I don't blame anyone, would I be blaming the law, that wouldn't imply the americans anyway. cheers, JM "The Sarbanes-Oxley Act of 2002, sponsored by Paul Sarbanes and Michael Oxley, represents a huge change to federal securities law. It came as a result of the corporate financial scandals involving Enron, WorldCom and Global Crossing. Effective in 2006, all publicly-traded companies are required to implement and report internal accounting controls to the SEC for compliance." -- 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 mcepl at redhat.com Thu Jan 9 11:05:55 2014 From: mcepl at redhat.com (=?UTF-8?B?TWF0xJtqIENlcGw=?=) Date: Thu, 09 Jan 2014 17:05:55 +0100 Subject: Is email.parser a good replacement for formail? Message-ID: <52CEC8E3.3070201@redhat.com> Hi, I have a script (https://github.com/mcepl/gg_scraper) where I need to read possibly malformed mbox messages. I use subprocess.Popen() and /usr/bin/formail to clean up them to be correct mbox messages (with correct leading From line etc.). Now I try to run tests for my script on Travis-CI, where I don't have installed formail. Actually, I learned now that I can run apt-get install procmail in .travis.yml. But still, I started to think whether I couldn?t fix my script to be purely Pythonic. I know that msg = email.message_from_string(original_msg) print(msg.as_string(unixfrom=True)) works as a poor-man?s replacement for `formail -d`. Now, I would like to know how reliable replacement it is. Does anybody have (or know about) a corpus of poorly formatted messages which can be fixed by formail to test upon it? Thanks a lot for any reply, Mat?j -- http://www.ceplovi.cz/matej/, Jabber: mcepl at ceplovi.cz GPG Finger: 89EF 4BC6 288A BF43 1BAB 25C3 E09F EF25 D964 84AC Less is more or less more. -- Y_Plentyn on #LinuxGER (from fortunes -- I cannot resist :-) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 255 bytes Desc: OpenPGP digital signature URL: From roy at panix.com Thu Jan 9 11:21:33 2014 From: roy at panix.com (Roy Smith) Date: Thu, 9 Jan 2014 08:21:33 -0800 (PST) Subject: the Gravity of Python 2 In-Reply-To: References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> On Thursday, January 9, 2014 9:57:57 AM UTC-5, Chris Angelico wrote: > And months are more > complicated still, so it's probably easiest to use strftime: > > >>> time.strftime("%Y%m",time.gmtime(ts)) > > '201401' strftime is a non-starter at far as "easy" goes. I don't know about you, but I certainly haven't memorized the table of all the format specifiers. Is month "m" or "M"? What's "%U" or "%B". Every time I use strftime, I have to go pull up the docs and read the table. Not to mention that "%z" is not available on all platforms, and "%s" (which is incredibly useful) is not even documented (I suspect it's also not available on all platforms). > So what I'm seeing here is that the direct use of a time_t will cover > everything in an ugly way, but that a class wrapping it up could fix > that. And fundamentally, the only problem with datetime (which, for > the most part, is exactly that wrapper) is that it's unobvious how to > get a simple UTC timestamp. > > Has the unobviousness been solved by a simple recipe? And if so, > should that tip be added to the datetime module docs somewhere? No, it would be solved by a built-in method. Recipes are a cop-out. If something is complicated enough to require a recipe, and used frequently enough to be worth writing that recipe up and documenting it, you might as well have gone the one additional step and made it a method. From breamoreboy at yahoo.co.uk Thu Jan 9 11:30:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 16:30:31 +0000 Subject: the Gravity of Python 2 In-Reply-To: <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> References: <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> Message-ID: On 09/01/2014 16:21, Roy Smith wrote: > > No, it would be solved by a built-in method. Recipes are a cop-out. If something is complicated enough to require a recipe, and used frequently enough to be worth writing that recipe up and documenting it, you might as well have gone the one additional step and made it a method. > So all of the itertools recipes should be part of the Python module and not in more-itertools on pypi? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mail at timgolden.me.uk Thu Jan 9 11:41:16 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 09 Jan 2014 16:41:16 +0000 Subject: the Gravity of Python 2 In-Reply-To: References: <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> Message-ID: <52CED12C.3040101@timgolden.me.uk> On 09/01/2014 16:30, Mark Lawrence wrote: > On 09/01/2014 16:21, Roy Smith wrote: >> >> No, it would be solved by a built-in method. Recipes are a cop-out. >> If something is complicated enough to require a recipe, and used >> frequently enough to be worth writing that recipe up and documenting >> it, you might as well have gone the one additional step and made it a >> method. >> > > So all of the itertools recipes should be part of the Python module and > not in more-itertools on pypi? To be fair, Mark, it's a matter of taste. Raymond [the author/maintainer of itertools] prefers not to multiply the API; other developers might legitimately make other calls. Sometimes the cut-off is more obvious; say, when the effort to make a recipe general purpose creates an over-engineered API. Other times it's just preference. Does that mean that every recipe ever conceived should be stuffed into the class or module it uses? No; but it doesn't rule out adding things which are genuinely useful. I think the new statistics module has hit a nice balance on its initial release: it's a stripped down aesthetic without precluding later additions. TJG From nick.cash at npcinternational.com Thu Jan 9 11:42:03 2014 From: nick.cash at npcinternational.com (Nick Cash) Date: Thu, 9 Jan 2014 16:42:03 +0000 Subject: the Gravity of Python 2 In-Reply-To: <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> Message-ID: <9b60b576fc864413b1d2f74b8e333d73@DM2PR06MB542.namprd06.prod.outlook.com> > and "%s" (which is incredibly useful) is not even documented (I suspect it's also not available on all platforms). The format specifiers available to Python are just whatever is available to the underlying c time.h. The manpage for strftime indicates that %s isn't part of the C standard, but part of "Olson's timezone package", which means it's not available on Windows. Your suspicion is unfortunately correct. From ethan at stoneleaf.us Thu Jan 9 10:56:20 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 07:56:20 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> Message-ID: <52CEC6A4.7020705@stoneleaf.us> On 01/09/2014 06:57 AM, Chris Angelico wrote: > On Fri, Jan 10, 2014 at 1:14 AM, Roy Smith wrote: >> > > Thanks for this collection! Now we can discuss. [snip] >> Datetimes are self-describing. If I have a datetime or a timedelta, I >> know what I've got. I've written more than one bug where I assumed a >> number somebody handed me was in seconds but it turned out to be in ms. >> That can never happen with a timedelta. We do a lot of stuff in >> javascript, where times are ms, so this is a common problem for us. > > Sure. Though that's no different from other cases where you need > out-of-band information to understand something, as we've just been > discussing in the threads about text handling - if you have a puddle > of bytes, you can't decode them to text without knowing what the > encoding is. [1] If your data's coming from JS, it won't be a > timedelta, it'll be a number; at some point you have to turn that into > a timedelta object, so you still have the same problem. Yup, and you do at the boundary instead of having a float wandering through your code with an easily forgotten meta-data type. > So what I'm seeing here is that the direct use of a time_t will cover > everything in an ugly way, but that a class wrapping it up could fix > that. And fundamentally, the only problem with datetime (which, for > the most part, is exactly that wrapper) is that it's unobvious how to > get a simple UTC timestamp. It has at least one other problem: bool(midnight) == False. -- ~Ethan~ > [1] Yes, I said "puddle of bytes". What would you call it? Am > interested to hear! I think that's a perfect name! :) From ethan at stoneleaf.us Thu Jan 9 11:01:41 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 08:01:41 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> Message-ID: <52CEC7E5.60908@stoneleaf.us> On 01/09/2014 12:42 AM, Mark Lawrence wrote: > On 09/01/2014 01:27, Roy Smith wrote: >> >> Naive datetimes are what everybody uses. It's what utcnow() gives you. >> So why make life difficult for everybody? Python 3 didn't win a convert >> today. > > Yep, dates and times are easy. That's why there are 17 issues open on the bug tracker referencing tzinfo alone. Poor > old 1100942 is high priority, was created 12/01/2005 and has missed 3.4. So if it gets into 3.5 it'll have already > celebrated its 10th birthday. It doesn't say much for the amount of effort that we put into looking after issues. Mark, I hope you are addressing the community at large and not the core-devs. There are only so many of us, with limited time available. -- ~Ethan~ From breamoreboy at yahoo.co.uk Thu Jan 9 11:50:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 16:50:36 +0000 Subject: the Gravity of Python 2 In-Reply-To: <9b60b576fc864413b1d2f74b8e333d73@DM2PR06MB542.namprd06.prod.outlook.com> References: <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> <9b60b576fc864413b1d2f74b8e333d73@DM2PR06MB542.namprd06.prod.outlook.com> Message-ID: On 09/01/2014 16:42, Nick Cash wrote: >> and "%s" (which is incredibly useful) is not even documented (I suspect it's also not available on all platforms). > > The format specifiers available to Python are just whatever is available to the underlying c time.h. > The manpage for strftime indicates that %s isn't part of the C standard, but part of "Olson's timezone package", which means it's not available on Windows. Your suspicion is unfortunately correct. > Methinks http://www.python.org/dev/peps/pep-0431/ Time zone support improvements may be of interest here. Still at draft issue unfortunately. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From piet at vanoostrum.org Thu Jan 9 11:51:36 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 09 Jan 2014 17:51:36 +0100 Subject: the Gravity of Python 2 References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: Chris Angelico writes: > On Fri, Jan 10, 2014 at 1:06 AM, Piet van Oostrum wrote: >> Chris Angelico writes: >> >>> On Thu, Jan 9, 2014 at 2:34 PM, Ben Finney wrote: >>>> With time zones, as with text encodings, there is a single technically >>>> elegant solution (for text: Unicode; for time zones: twelve simple, >>>> static zones that never change) >>> >>> Twelve or twenty-four? Or are you thinking we should all be an even >>> number of hours away from UTC, which would also work? >> >> Even 24 doesn't take into account DST. > > That was the point. We can abolish codepages by using Unicode, which > covers everything. We could abolish time messes by having every > locality settle permanently on one timezone; Ben's theory demands that > all timezones be some integer number of hours +/- UTC, which IMO is > optional, but mainly it should be easy to figure out any two > locations' difference: just subtract one's UTC offset from the > other's. Similarly, you can calculate the difference between two times > at the same location by simple subtraction; currently, you also have > to consider the possibility of a DST switch (from noon to noon across > a switch is either 23 or 25 hours). > > Actually, the nearest parallel to Unicode is probably "use UTC > everywhere", which makes for a superb internal representation and > transmission format, but bugs most human beings :) I don't know how other countries do it, but here, when the clock goes back, it goes from 03:00 to 02:00. So I wonder how they communicate when your plane leaves at 02:30 in that night. Which 02:30? In that case using UTC may come out handy, if it would be understood. Or do the planes just stop leaving during that interval? Not that there will be many leaving during that time in general, I presume. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From piet at vanoostrum.org Thu Jan 9 12:05:29 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 09 Jan 2014 18:05:29 +0100 Subject: Bytes indexing returns an int References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> Message-ID: Ned Batchelder writes: > On 1/8/14 11:08 AM, wxjmfauth at gmail.com wrote: >> Byte strings (encoded code points) or native unicode is one >> thing. >> >> But on the other side, the problem is elsewhere. These very >> talented ascii narrow minded, unicode illiterate devs only >> succeded to produce this (I, really, do not wish to be rude). > > If you don't want to be rude, you are failing. You've been told a > number of times that your obscure micro-benchmarks are meaningless. Now > you've taken to calling the core devs narrow-minded and Unicode > illiterate. They are neither of these things. > > Continuing to post these comments with no interest in learning is rude. > Other recent threads have contained details rebuttals of your views, > which you have ignored. This is rude. Please stop. Please ignore jmf's repeated nonsense. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From roy at panix.com Thu Jan 9 12:07:30 2014 From: roy at panix.com (Roy Smith) Date: Thu, 9 Jan 2014 09:07:30 -0800 (PST) Subject: the Gravity of Python 2 In-Reply-To: References: <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> Message-ID: <6c2d5547-50e1-4bb0-a517-d35886085665@googlegroups.com> I wrote: > Recipes are a cop-out On Thursday, January 9, 2014 11:30:31 AM UTC-5, Mark Lawrence wrote: > So all of the itertools recipes should be part of the Python module and > not in more-itertools on pypi? Certainly, the recipes that are documented on the official itertools page, yes. From ethan at stoneleaf.us Thu Jan 9 12:28:17 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 09:28:17 -0800 Subject: Bytes indexing returns an int In-Reply-To: References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> Message-ID: <52CEDC31.7030809@stoneleaf.us> On 01/09/2014 09:05 AM, Piet van Oostrum wrote: > Ned Batchelder writes: > >> On 1/8/14 11:08 AM, wxjmfauth at gmail.com wrote: >>> Byte strings (encoded code points) or native unicode is one >>> thing. >>> >>> But on the other side, the problem is elsewhere. These very >>> talented ascii narrow minded, unicode illiterate devs only >>> succeded to produce this (I, really, do not wish to be rude). >> >> If you don't want to be rude, you are failing. You've been told a >> number of times that your obscure micro-benchmarks are meaningless. Now >> you've taken to calling the core devs narrow-minded and Unicode >> illiterate. They are neither of these things. >> >> Continuing to post these comments with no interest in learning is rude. >> Other recent threads have contained details rebuttals of your views, >> which you have ignored. This is rude. Please stop. > > Please ignore jmf's repeated nonsense. Or ban him. His one, minor, contribution has been completely swamped by the rest of his belligerent, unfounded, refuted posts. -- ~Ethan~ From breamoreboy at yahoo.co.uk Thu Jan 9 13:18:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 18:18:20 +0000 Subject: the Gravity of Python 2 In-Reply-To: <52CEC7E5.60908@stoneleaf.us> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CEC7E5.60908@stoneleaf.us> Message-ID: On 09/01/2014 16:01, Ethan Furman wrote: > On 01/09/2014 12:42 AM, Mark Lawrence wrote: >> On 09/01/2014 01:27, Roy Smith wrote: >>> >>> Naive datetimes are what everybody uses. It's what utcnow() gives you. >>> So why make life difficult for everybody? Python 3 didn't win a convert >>> today. >> >> Yep, dates and times are easy. That's why there are 17 issues open on >> the bug tracker referencing tzinfo alone. Poor >> old 1100942 is high priority, was created 12/01/2005 and has missed >> 3.4. So if it gets into 3.5 it'll have already >> celebrated its 10th birthday. It doesn't say much for the amount of >> effort that we put into looking after issues. > > Mark, I hope you are addressing the community at large and not the > core-devs. There are only so many of us, with limited time available. > > -- > ~Ethan~ As I'm not a core dev to whom do you think I'm referring? I'm aware that the high horse I get on about this is so tall that you'll need an oxygen supply to survive should you want to sit on it, but to me this is easily the worst aspect of the Python community as a whole. If every regular contributor to this list was to fix even one bug a week the figures would look rather better. Still, you can no more enforce that than you can enforce the core devs working on Python 2.8 :) Talking of which, have we got a PEP for that yet, or are the whingers still simply in whinging mode? -- 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 Thu Jan 9 13:20:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 09 Jan 2014 18:20:40 +0000 Subject: the Gravity of Python 2 In-Reply-To: <6c2d5547-50e1-4bb0-a517-d35886085665@googlegroups.com> References: <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> <6c2d5547-50e1-4bb0-a517-d35886085665@googlegroups.com> Message-ID: On 09/01/2014 17:07, Roy Smith wrote: > I wrote: >> Recipes are a cop-out > > On Thursday, January 9, 2014 11:30:31 AM UTC-5, Mark Lawrence wrote: >> So all of the itertools recipes should be part of the Python module and >> not in more-itertools on pypi? > > Certainly, the recipes that are documented on the official itertools page, yes. > No thank you, I don't want the Python docs getting anywhere near the size of their Java equivalents. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ethan at stoneleaf.us Thu Jan 9 13:33:10 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 10:33:10 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CEC7E5.60908@stoneleaf.us> Message-ID: <52CEEB66.8010109@stoneleaf.us> On 01/09/2014 10:18 AM, Mark Lawrence wrote: > On 09/01/2014 16:01, Ethan Furman wrote: >> On 01/09/2014 12:42 AM, Mark Lawrence wrote: >>> On 09/01/2014 01:27, Roy Smith wrote: >>>> >>>> Naive datetimes are what everybody uses. It's what utcnow() gives you. >>>> So why make life difficult for everybody? Python 3 didn't win a convert >>>> today. >>> >>> Yep, dates and times are easy. That's why there are 17 issues open on >>> the bug tracker referencing tzinfo alone. Poor >>> old 1100942 is high priority, was created 12/01/2005 and has missed >>> 3.4. So if it gets into 3.5 it'll have already >>> celebrated its 10th birthday. It doesn't say much for the amount of >>> effort that we put into looking after issues. >> >> Mark, I hope you are addressing the community at large and not the >> core-devs. There are only so many of us, with limited time available. > > As I'm not a core dev to whom do you think I'm referring? Cool, just double-checking. :) > Still, you can no more enforce that than you can enforce the core devs > working on Python 2.8 :) > > Talking of which, have we got a PEP for that yet. . . As a matter of fact. It's called PEP 404. ;) -- ~Ethan~ From ethan at stoneleaf.us Thu Jan 9 13:29:37 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 10:29:37 -0800 Subject: the Gravity of Python 2 In-Reply-To: References: <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> <6c2d5547-50e1-4bb0-a517-d35886085665@googlegroups.com> Message-ID: <52CEEA91.7030205@stoneleaf.us> On 01/09/2014 10:20 AM, Mark Lawrence wrote: >> On Thursday, January 9, 2014 11:30:31 AM UTC-5, Mark Lawrence wrote: >>> So all of the itertools recipes should be part of the Python module and >>> not in more-itertools on pypi? >> >> Certainly, the recipes that are documented on the official itertools page, yes. > > No thank you, I don't want the Python docs getting anywhere near the size of their Java equivalents. To be fair, the recipes on the itertools page are there so that minor changes can be made (flavor to taste, so to speak) to get exactly the semantics needed by the individual programmer. With the timezone stuff we're looking for The One Obvious Way, which should be a method, not a recipe. -- ~Ethan~ From ethan at stoneleaf.us Thu Jan 9 13:49:27 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 10:49:27 -0800 Subject: unicode troubles and postgres Message-ID: <52CEEF37.50504@stoneleaf.us> So I'm working with postgres, and I get a datadump which I try to restore to my test system, and I get this: ERROR: value too long for type character varying(4) CONTEXT: COPY res_currency, line 32, column symbol: "???" "py6" sure looks like it should fit, but it don't. Further investigation revealed that "py6" is made up of the bytes d1 80 d1 83 d0 b1. Any ideas on what that means, exactly? -- ~Ethan~ From storchaka at gmail.com Thu Jan 9 14:36:48 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 09 Jan 2014 21:36:48 +0200 Subject: Bytes indexing returns an int In-Reply-To: <52CEDC31.7030809@stoneleaf.us> References: <52cbe15a$0$29993$c3e8da3$5496439d@news.astraweb.com> <52cc278c$0$29979$c3e8da3$5496439d@news.astraweb.com> <7d2d5d85-afa2-474d-8739-c33745b7c00b@googlegroups.com> <52CEDC31.7030809@stoneleaf.us> Message-ID: 09.01.14 19:28, Ethan Furman ???????(??): > On 01/09/2014 09:05 AM, Piet van Oostrum wrote: >> Please ignore jmf's repeated nonsense. > > Or ban him. His one, minor, contribution has been completely swamped by > the rest of his belligerent, unfounded, refuted posts. Please not. I have a fun from every his appearance. From __peter__ at web.de Thu Jan 9 14:50:41 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 09 Jan 2014 20:50:41 +0100 Subject: unicode troubles and postgres References: <52CEEF37.50504@stoneleaf.us> Message-ID: Ethan Furman wrote: > So I'm working with postgres, and I get a datadump which I try to restore > to my test system, and I get this: > > ERROR: value too long for type character varying(4) > CONTEXT: COPY res_currency, line 32, column symbol: "???" > > "py6" sure looks like it should fit, but it don't. Further investigation > revealed that "py6" is made up of the bytes d1 80 d1 83 d0 b1. > > Any ideas on what that means, exactly? It may look like the ascii "py6", but you have three cyrillic letters: >>> import unicodedata as ud >>> [ud.name(c) for c in u"???"] ['CYRILLIC SMALL LETTER ER', 'CYRILLIC SMALL LETTER U', 'CYRILLIC SMALL LETTER BE'] The dump you are seeing are the corresponding bytes in UTF-8: >>> u"???".encode("utf-8") '\xd1\x80\xd1\x83\xd0\xb1' So postgres may be storing the string as utf-8. From jeremiahvalerio123 at gmail.com Thu Jan 9 15:08:28 2014 From: jeremiahvalerio123 at gmail.com (jeremiah valerio) Date: Thu, 9 Jan 2014 12:08:28 -0800 (PST) Subject: Constructive Criticism In-Reply-To: References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: On Thursday, January 9, 2014 3:56:37 AM UTC-6, Peter Otten wrote: > jeremiahvalerio123 at gmail.com wrote: > > > > > Hi, hows it going I've been self teaching myself python, and i typed up > > > this small script now i know its not the best the coding is not the best > > > but i would like to know of ways to make a small script like this better > > > so all constructive critisim is Welcome. > > > > > > > > > > > > Here is the link to the code > > > > > > " http://pastebin.com/5uCFR2pz " > > > > > time.sleep(1) > > > import time > > > print("Closing in 9 ") > > > time.sleep(1) > > > import time > > > print("Closing in 8 ") > > > > - You should import modules just once, at the beginning of your script. > > > > - Repetetive tasks are best handled with a for-loop, e. g.: > > > > >>> import time > > >>> for seconds_left in reversed(range(1, 10)): > > ... print("Closing in", seconds_left, "seconds") > > ... time.sleep(1) > > ... > > Closing in 9 seconds > > Closing in 8 seconds > > Closing in 7 seconds > > Closing in 6 seconds > > Closing in 5 seconds > > Closing in 4 seconds > > Closing in 3 seconds > > Closing in 2 seconds > > Closing in 1 seconds > > > > > user_input = input("\nWhos your favorite Football team? \n 1.Arizona > > > Cardinals\n 2.Atlanta Falcons\n 3.Baltimore Ravens\n 4.Buffalo Bills\n > > > 5.Miami Dolphins\n 6.Minnesota Vikings \n 7.New England Patriots \n > > > 8.New Orleans Saints \n 9.Carolina > > [snip] > > > > Python offers triple-quoted strings which may include newline literals: > > > > user_input = input(""" > > Who's your favorite Football team? > > 1. Arizona Cardinals > > 2. Atlanta Falcons > > ... > > """) > > > > > if user_input == "1" : > > > print("\nThey suck! BYE!") > > > > > > elif user_input == "2" : > > > print("\nThey suck! BYE!") > > > > > > elif user_input == "3" : > > > print("\nThey suck!BYE!") > > [snip] > > > > Ignoring the typos you are taking the same action for all inputs but "17". > > So: > > > > if user_input != "17": > > print() > > print("They suck! BYE!") > > > > You should give some thought how unexpected user input like "", "123", > > "whatever" should be handled. > > > > > elif user_input == "no" : > > > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.") > > > import time > > > time.sleep(1) > > > import time > > > print("Closing in 9 ") > > > time.sleep(1) > > > import time > > > print("Closing in 8 ") > > > time.sleep(1) > > > import time > > > > OK, you are doing the count-down thing twice -- time to write a function, > > say countdown(), that you can put where you need a count-down instead of the > > repetetive code. Thanks so much,exactly what i was looking for thanks for taking the time. From rosuav at gmail.com Thu Jan 9 15:35:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 07:35:05 +1100 Subject: the Gravity of Python 2 In-Reply-To: <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> Message-ID: On Fri, Jan 10, 2014 at 3:21 AM, Roy Smith wrote: > On Thursday, January 9, 2014 9:57:57 AM UTC-5, Chris Angelico wrote: >> And months are more >> complicated still, so it's probably easiest to use strftime: >> >> >>> time.strftime("%Y%m",time.gmtime(ts)) >> >> '201401' > > strftime is a non-starter at far as "easy" goes. I don't know about you, but I certainly haven't memorized the table of all the format specifiers. Is month "m" or "M"? What's "%U" or "%B". Every time I use strftime, I have to go pull up the docs and read the table. Not to mention that "%z" is not available on all platforms, and "%s" (which is incredibly useful) is not even documented (I suspect it's also not available on all platforms). > Have you ever used a regular expression? Does it bother you that both percent-formatting and str.format() have compact/cryptic mini-languages? Why is it a problem to have a mini-language for formatting dates? It at least follows a measure of common sense, unlike the PHP date function. In fact, I've given end users the ability to enter strftime strings (eg to construct a filename), and it's worked just fine. *Non-programmers* can figure them out without much difficulty. ChrisA From ethan at stoneleaf.us Thu Jan 9 14:51:21 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 09 Jan 2014 11:51:21 -0800 Subject: unicode troubles and postgres [SOLVED] In-Reply-To: <52CEEF37.50504@stoneleaf.us> References: <52CEEF37.50504@stoneleaf.us> Message-ID: <52CEFDB9.5050702@stoneleaf.us> On 01/09/2014 10:49 AM, Ethan Furman wrote: > So I'm working with postgres, and I get a datadump which I try to restore to my test system, and I get this: > > ERROR: value too long for type character varying(4) > CONTEXT: COPY res_currency, line 32, column symbol: "???" > > "py6" sure looks like it should fit, but it don't. Further investigation revealed that "py6" is made up of the bytes d1 > 80 d1 83 d0 b1. > > Any ideas on what that means, exactly? For the curious, it means CYRILLIC SMALL LETTER ER, CYRILLIC SMALL LETTER U, CYRILLIC CAPITAL LETTER IE WITH GRAVE in utf-8 format. The problem was I had created the database from template0 instead of template1, and 0 is SQL-ASCII while 1 is UTF8. -- ~Ethan~ From rosuav at gmail.com Thu Jan 9 15:43:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 07:43:36 +1100 Subject: the Gravity of Python 2 In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> Message-ID: On Fri, Jan 10, 2014 at 3:51 AM, Piet van Oostrum wrote: > I don't know how other countries do it, but here, when the clock goes back, it goes from 03:00 to 02:00. So I wonder how they communicate when your plane leaves at 02:30 in that night. Which 02:30? In that case using UTC may come out handy, if it would be understood. Or do the planes just stop leaving during that interval? Not that there will be many leaving during that time in general, I presume. > The fundamental is that the timezone changes. Times roll from 02:00 Daylight time through 02:30 Daylight time to the instant before 03:00 Daylight time, which doesn't happen, and instead time jumps to 02:00 Standard time and starts rolling forward. How this is adequately communicated on the plane ticket is a separate issue, though, and as I've never actually flown during a DST changeover, I wouldn't know. I'm sure there would be planes departing during those two hours (neither airlines nor airports can afford to have two, or even one, "dead" hour!), so this must have been solved somehow. Maybe people could figure it out from the "check-in by" time? For instance, last time I flew, the plane departed at 0240 local time (but this was in July, so not anywhere near changeover), and check-in opened at 2340; so if it were the "other" 0240, then check-in would have opened at 0040 instead. Either that, or they'll tell everyone to arrive in time for the first instance of that time, and then just make us all wait around for an extra hour.... ChrisA From cjwelborn at live.com Thu Jan 9 15:54:44 2014 From: cjwelborn at live.com (Christopher Welborn) Date: Thu, 09 Jan 2014 14:54:44 -0600 Subject: Constructive Criticism In-Reply-To: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: On 01/08/2014 11:56 PM, jeremiahvalerio123 at gmail.com wrote: > Hi, hows it going I've been self teaching myself python, and i typed up this small script now i know its not the best the coding is not the best but i would like to know of ways to make a small script like this better so all constructive critisim is Welcome. > > > > Here is the link to the code > > " http://pastebin.com/5uCFR2pz " > I'm not sure if someone already pointed this out, but imports only need to be done once. Usually at the beginning of the file, but not always. In your case I would say yes, at the beginning. import sys import time def countdown(seconds):' # start at 'seconds' and count down with a for-loop for i in range(seconds, 0, -1): # print the current second (i) print('closing in {} seconds.'.format(i)) # sleep for one second (no need to import time again). time.sleep(1) # Example usage: print('hello') # Prints the countdown. countdown(10) sys.exit(0) -- - Christopher Welborn http://welbornprod.com From roy at panix.com Thu Jan 9 15:54:10 2014 From: roy at panix.com (Roy Smith) Date: Thu, 9 Jan 2014 12:54:10 -0800 (PST) Subject: the Gravity of Python 2 In-Reply-To: References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> Message-ID: <9b9c51df-8c1d-43e8-a3da-41b879238a7b@googlegroups.com> On Thursday, January 9, 2014 3:35:05 PM UTC-5, Chris Angelico wrote: > In fact, I've given end users the ability to enter strftime strings (eg > to construct a filename), and it's worked just fine. I assume you realize that "../../../../../../../../../../../../../../../../etc/passwd" is a valid strftime() format specifier? :-) But, to answer your question, no, I have nothing against small languages, per-se (and I've done plenty of regex work). But, if my goal is to print a time in some human-readable form: >>> print t is a lot easier than anything involving strftime(). From rosuav at gmail.com Thu Jan 9 15:56:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 07:56:38 +1100 Subject: unicode troubles and postgres [SOLVED] In-Reply-To: <52CEFDB9.5050702@stoneleaf.us> References: <52CEEF37.50504@stoneleaf.us> <52CEFDB9.5050702@stoneleaf.us> Message-ID: On Fri, Jan 10, 2014 at 6:51 AM, Ethan Furman wrote: > The problem was I had created the database from template0 instead of > template1, and 0 is SQL-ASCII while 1 is UTF8. Ah, this is one of the traps with Postgres. This is one of the reasons I prefer not to touch template[01] and to script the initialization of a new database - any config changes are committed to source control as part of that script. ChrisA From jeremiahvalerio123 at gmail.com Thu Jan 9 16:05:23 2014 From: jeremiahvalerio123 at gmail.com (jeremiah valerio) Date: Thu, 9 Jan 2014 13:05:23 -0800 (PST) Subject: Constructive Criticism In-Reply-To: References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> Message-ID: <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn wrote: > On 01/08/2014 11:56 PM, jeremiahvalerio123 at gmail.com wrote: > > > Hi, hows it going I've been self teaching myself python, and i typed up this small script now i know its not the best the coding is not the best but i would like to know of ways to make a small script like this better so all constructive critisim is Welcome. > > > > > > > > > > > > Here is the link to the code > > > > > > " http://pastebin.com/5uCFR2pz " > > > > > > > I'm not sure if someone already pointed this out, but imports only need > > to be done once. Usually at the beginning of the file, but not always. > > In your case I would say yes, at the beginning. > > > > import sys > > import time > > > > def countdown(seconds):' > > # start at 'seconds' and count down with a for-loop > > for i in range(seconds, 0, -1): > > # print the current second (i) > > print('closing in {} seconds.'.format(i)) > > # sleep for one second (no need to import time again). > > time.sleep(1) > > > > # Example usage: > > print('hello') > > # Prints the countdown. > > countdown(10) > > sys.exit(0) > > -- > > > > - Christopher Welborn > > http://welbornprod.com Mr.Peter Otten did "- You should import modules just once, at the beginning of your script. " -Peter Otten With his help this is what i have now def countdown(): import time for seconds_left in reversed(range(1, 10)): print("Closing in", seconds_left, "seconds") time.sleep(1) exit() if user_input == "yes" : user_input = input("\nGreat what should we talk about?\nSports\nWeather") elif user_input == "no" : print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.") countdown() From rosuav at gmail.com Thu Jan 9 16:12:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 10 Jan 2014 08:12:27 +1100 Subject: the Gravity of Python 2 In-Reply-To: <9b9c51df-8c1d-43e8-a3da-41b879238a7b@googlegroups.com> References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <52CE3416.9090501@stoneleaf.us> <7wiottej72.fsf@benfinney.id.au> <82fa7f62-9625-41cc-8d1f-c87c0e51cb47@googlegroups.com> <9b9c51df-8c1d-43e8-a3da-41b879238a7b@googlegroups.com> Message-ID: On Fri, Jan 10, 2014 at 7:54 AM, Roy Smith wrote: > On Thursday, January 9, 2014 3:35:05 PM UTC-5, Chris Angelico wrote: >> In fact, I've given end users the ability to enter strftime strings (eg >> to construct a filename), and it's worked just fine. > > I assume you realize that "../../../../../../../../../../../../../../../../etc/passwd" is a valid strftime() format specifier? :-) Yes, and since this was for the creation of a log file by an unprivileged process, that would simply fail :) Though the specific case I'm thinking of here was on Windows, so you could probably find an equivalent filename (it didn't prevent absolute names, so you could just stuff whatever you want in) and shoot yourself in the foot big-time. It's the user's own system, let him make a mess of it if he wants :) > But, to answer your question, no, I have nothing against small languages, per-se (and I've done plenty of regex work). But, if my goal is to print a time in some human-readable form: > >>>> print t > > is a lot easier than anything involving strftime(). Sure, it's easier. But there are plenty of types that don't provide a particularly useful repr - regexes being one that only recently changed: 2.7 and 3.3: >>> re.compile(r"(.)\1\1\1") <_sre.SRE_Pattern object at 0x012464F0> >>> _.search("This is a test string with a quadrrrruple letter in it!") <_sre.SRE_Match object at 0x012C3EE0> 3.4: >>> re.compile(r"(.)\1\1\1") re.compile('(.)\\1\\1\\1') >>> _.search("This is a test string with a quadrrrruple letter in it!") <_sre.SRE_Match object; span=(33, 37), match='rrrr'> Would you avoid using regexes in anything less than 3.4 simply because of this lack of repr? It's a convenience, not a deal-breaker. (Or if you disagree with me on that point, you're cutting out a lot of very useful types.) It's not hard to call time.ctime(ts) or strftime(...) for display; the big loser is the interactive interpreter, where a good repr is everything. ChrisA From drobinow at gmail.com Thu Jan 9 21:32:39 2014 From: drobinow at gmail.com (David Robinow) Date: Thu, 9 Jan 2014 21:32:39 -0500 Subject: Editor for Python In-Reply-To: <1293262712.3373607.1389282621830.JavaMail.root@sequans.com> References: <413939E4-4BE5-4923-A96D-18C8E28A0E0C@gmail.com> <1293262712.3373607.1389282621830.JavaMail.root@sequans.com> Message-ID: On Thu, Jan 9, 2014 at 10:50 AM, Jean-Michel Pichavant wrote: > ----- Original Message ----- >> >> On Jan 8, 2014, at 10:53 AM, Jean-Michel Pichavant >> wrote: >> > I tried to negotiate this with my IT guys, but it looks like it's >> > now mandatory, something related to being in the USA stock market. >> Yeah, when in doubt blame the Americans. > > Sorry if I hurt your feelings, have a look at http://www.sarbanes-oxley-101.com/ You didn't. I was just having fun. However, I couldn't find anything at that site which referred to email disclaimers. It seems to me that this sort of thing has gone out of style. It was more common ten years ago. However, I won't waste any more time arguing the point. > > I don't blame anyone, would I be blaming the law, that wouldn't imply the americans anyway. > > cheers, > JM From roy at panix.com Fri Jan 10 00:23:11 2014 From: roy at panix.com (Roy Smith) Date: Fri, 10 Jan 2014 00:23:11 -0500 Subject: Monkeypatching a staticmethod? Message-ID: This is kind of surprising. I'm running Python 2.7.1. I've got a class with a staticmethod that I want to monkeypatch with a lambda: ---------------------------------- class Foo: @staticmethod def x(): return 1 Foo.x = lambda: 2 print Foo.x() ---------------------------------- What's weird is that it seems to remember that x is a staticmethod despite having been patched: Traceback (most recent call last): File "static.py", line 8, in Foo.x() TypeError: unbound method () must be called with Foo instance as first argument (got nothing instead) What seems to work is to patch it with another staticmethod: ---------------------------------- class Foo: @staticmethod def x(): return 1 @staticmethod def x(): return 2 Foo.x = x print Foo.x() ---------------------------------- $ python static.py 2 I didn't even know you could define a staticmethod outside of a class! I suspect this post is really just my way of admitting that while I've used staticmethods plenty, I've never fully understood the details of what happens when you construct them :-) From torriem at gmail.com Fri Jan 10 01:19:08 2014 From: torriem at gmail.com (Michael Torrie) Date: Thu, 09 Jan 2014 23:19:08 -0700 Subject: Python GTK GUI struck when process is going on. In-Reply-To: <52CEBCF5.6060804@mrabarnett.plus.com> References: <52CEBCF5.6060804@mrabarnett.plus.com> Message-ID: <52CF90DC.7060401@gmail.com> On 01/09/2014 08:15 AM, MRAB wrote: > On 2014-01-09 11:53, Prapulla Kumar wrote: >> Hi all, >> I'm using python gtk to upload file to S3 service by boto API , >> GUI struck when uploading file and releases the GUI after completed download >> I'm using thread to show progress of upload in GUI but it struck. >> Can you some suggestion how to show progress of upload in GUI or any >> spinner until upload finish >> > You say that you're using a thread to show the progress. Does that mean > that you're doing the uploading in the main thread? > > If yes, then that's the wrong way round. It's the uploading that needs > to be done in the background thread. And you can post update messages from the thread using a queue of some kind. The GUI just has to have a timeout that checks the queue and updates the gui with messages (percent complete, bytes transferred, etc). Or have the thread use gobject.idle_add to schedule a callback in the main thread that will check on the upload status and update the GUI. From ian.g.kelly at gmail.com Fri Jan 10 02:31:50 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 10 Jan 2014 00:31:50 -0700 Subject: Monkeypatching a staticmethod? In-Reply-To: References: Message-ID: On Thu, Jan 9, 2014 at 10:23 PM, Roy Smith wrote: > This is kind of surprising. I'm running Python 2.7.1. I've got a class > with a staticmethod that I want to monkeypatch with a lambda: > > ---------------------------------- > class Foo: > @staticmethod > def x(): > return 1 > > Foo.x = lambda: 2 > print Foo.x() > ---------------------------------- > > What's weird is that it seems to remember that x is a staticmethod > despite having been patched: > > Traceback (most recent call last): > File "static.py", line 8, in > Foo.x() > TypeError: unbound method () must be called with Foo instance as > first argument (got nothing instead) No, if it were still a staticmethod then the call would work without error. That error is the same that you would get in Python 2 if you defined the function directly in the class without the staticmethod decorator. (In Python 3 the call succeeds as long as it's made from the class and not from an instance). > What seems to work is to patch it with another staticmethod: > > ---------------------------------- > class Foo: > @staticmethod > def x(): > return 1 > > @staticmethod > def x(): > return 2 > > Foo.x = x > print Foo.x() > ---------------------------------- > > $ python static.py > 2 > > I didn't even know you could define a staticmethod outside of a class! I suggest defining x as a normal function and writing the assignment as "Foo.x = staticmethod(x)" to keep x callable from the global namespace. Or just del it after doing the monkey patch. From bob.martin at excite.com Fri Jan 10 02:31:11 2014 From: bob.martin at excite.com (Bob Martin) Date: Fri, 10 Jan 2014 07:31:11 GMT Subject: Time zones and why they change so damned often References: Message-ID: in 714232 20140109 120741 Alister wrote: >On Thu, 09 Jan 2014 07:17:25 +0000, Mark Lawrence wrote: > >> On 09/01/2014 04:14, Chris Angelico wrote: >>> On Thu, Jan 9, 2014 at 2:54 PM, Ben Finney >>> wrote: >>>> I'm approaching it with the goal of knowing better what I'm talking >>>> about when I advocate scrapping the whole DST system :-) >>> >>> I would definitely support the scrapping of DST. I'm less sure that we >>> need exactly 24 timezones around the world, though. It's not nearly as >>> big a problem to have the half-hour and quarter-hour timezones - >>> though it would be easier if timezone were strictly an integer number >>> of hours. But DST is the real pain. >>> >>> What I find, most of the time, is that it's Americans who can't handle >>> DST. I run an international Dungeons and Dragons campaign (we play >>> online, and new players are most welcome, as are people watching!), >>> and the Aussies (myself included) know to check UTC time, the Brits and >>> Europeans check UTC or just know what UTC is, and the Americans say >>> "Doesn't that happen at 8 o'clock Eastern time?" and get confused. >>> I don't understand this. Are my players drawn exclusively from the pool >>> of people who've never worked with anyone in Arizona [1]? Yes, >>> I'm stereotyping a bit here, and not every US player has had problems >>> with this, but it's the occasional US player who knows to check, and >>> the rare European, British, or Aussie player who doesn't. >>> >>> In any case, the world-wide abolition of DST would eliminate the >>> problem. The only remaining problem would be reminding people to change >>> the batteries in their smoke detectors. >>> >>> ChrisA >>> >>> [1] For those who aren't right up on timezone trivia, AZ has no DST. >>> Similarly the Australian state of Queensland does not shift its clocks. >>> >>> >> I remember this "From February 1968 to November 1971 the UK kept >> daylight saving time throughout the year mainly for commercial reasons, >> especially regarding time conformity with other European countries". My >> source http://www.timeanddate.com/time/uk/time-zone-background.html > >we dont have "Daylight saving time" we switch between GMT (Greenwich Mean >Time) and BST (British Summer Time) at some point in the past we have >also used DST (Double Summer Time). British Summer Time *is* Daylight Saving Time. From alister.ware at ntlworld.com Fri Jan 10 03:56:14 2014 From: alister.ware at ntlworld.com (Alister) Date: Fri, 10 Jan 2014 08:56:14 GMT Subject: Constructive Criticism References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> Message-ID: On Thu, 09 Jan 2014 13:05:23 -0800, jeremiah valerio wrote: > On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn > wrote: >> On 01/08/2014 11:56 PM, jeremiahvalerio123 at gmail.com wrote: >> >> > Hi, hows it going I've been self teaching myself python, and i typed >> > up this small script now i know its not the best the coding is not >> > the best but i would like to know of ways to make a small script like >> > this better so all constructive critisim is Welcome. >> >> >> > >> >> > >> >> > >> > Here is the link to the code >> >> >> > >> > " http://pastebin.com/5uCFR2pz " >> >> >> > >> >> >> I'm not sure if someone already pointed this out, but imports only need >> >> to be done once. Usually at the beginning of the file, but not always. >> >> In your case I would say yes, at the beginning. >> >> >> >> import sys >> >> import time >> >> >> >> def countdown(seconds):' >> >> # start at 'seconds' and count down with a for-loop >> >> for i in range(seconds, 0, -1): >> >> # print the current second (i) >> >> print('closing in {} seconds.'.format(i)) >> >> # sleep for one second (no need to import time again). >> >> time.sleep(1) >> >> >> >> # Example usage: >> >> print('hello') >> >> # Prints the countdown. >> >> countdown(10) >> >> sys.exit(0) >> >> -- >> >> >> >> - Christopher Welborn >> >> http://welbornprod.com > > Mr.Peter Otten did > > "- You should import modules just once, at the beginning of your script. > " > > -Peter Otten > With his help this is what i have now > > def countdown(): > import time for seconds_left in reversed(range(1, 10)): > print("Closing in", seconds_left, "seconds") > time.sleep(1) > exit() > > if user_input == "yes" : > user_input = input("\nGreat what should we talk > about?\nSports\nWeather") > elif user_input == "no" : > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.") > countdown() you could improve your countdown function further by adding an optional count vaule def countdown(count=10): for timeleft in reversed(1,count): print ("Shutting down in {} Seconds".format(timeleft)) time.sleep(1) -- Most people can't understand how others can blow their noses differently than they do. -- Turgenev From alister.ware at ntlworld.com Fri Jan 10 04:04:09 2014 From: alister.ware at ntlworld.com (Alister) Date: Fri, 10 Jan 2014 09:04:09 GMT Subject: Time zones and why they change so damned often References: Message-ID: On Fri, 10 Jan 2014 07:31:11 +0000, Bob Martin wrote: > in 714232 20140109 120741 Alister wrote: >>On Thu, 09 Jan 2014 07:17:25 +0000, Mark Lawrence wrote: >> >>> On 09/01/2014 04:14, Chris Angelico wrote: >>>> On Thu, Jan 9, 2014 at 2:54 PM, Ben Finney >>>> >>>> wrote: >>>>> I'm approaching it with the goal of knowing better what I'm talking >>>>> about when I advocate scrapping the whole DST system :-) >>>> >>>> I would definitely support the scrapping of DST. I'm less sure that >>>> we need exactly 24 timezones around the world, though. It's not >>>> nearly as big a problem to have the half-hour and quarter-hour >>>> timezones - though it would be easier if timezone were strictly an >>>> integer number of hours. But DST is the real pain. >>>> >>>> What I find, most of the time, is that it's Americans who can't >>>> handle DST. I run an international Dungeons and Dragons campaign (we >>>> play online, and new players are most welcome, as are people >>>> watching!), and the Aussies (myself included) know to check UTC time, >>>> the Brits and Europeans check UTC or just know what UTC is, and the >>>> Americans say "Doesn't that happen at 8 o'clock Eastern time?" and >>>> get confused. >>>> I don't understand this. Are my players drawn exclusively from the >>>> pool of people who've never worked with anyone in Arizona [1]? Yes, >>>> I'm stereotyping a bit here, and not every US player has had problems >>>> with this, but it's the occasional US player who knows to check, and >>>> the rare European, British, or Aussie player who doesn't. >>>> >>>> In any case, the world-wide abolition of DST would eliminate the >>>> problem. The only remaining problem would be reminding people to >>>> change the batteries in their smoke detectors. >>>> >>>> ChrisA >>>> >>>> [1] For those who aren't right up on timezone trivia, AZ has no DST. >>>> Similarly the Australian state of Queensland does not shift its >>>> clocks. >>>> >>>> >>> I remember this "From February 1968 to November 1971 the UK kept >>> daylight saving time throughout the year mainly for commercial >>> reasons, especially regarding time conformity with other European >>> countries". My source >>> http://www.timeanddate.com/time/uk/time-zone-background.html >> >>we dont have "Daylight saving time" we switch between GMT (Greenwich >>Mean Time) and BST (British Summer Time) at some point in the past we >>have also used DST (Double Summer Time). > > British Summer Time *is* Daylight Saving Time. My point is in the UK we have never refered to it as Daylight saving Time that is an Americanism :-) -- if (argc > 1 && strcmp(argv[1], "-advice") == 0) { printf("Don't Panic!\n"); exit(42); } -- Arnold Robbins in the LJ of February '95, describing RCS From wxjmfauth at gmail.com Fri Jan 10 05:44:57 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 10 Jan 2014 02:44:57 -0800 (PST) Subject: unicode troubles and postgres In-Reply-To: References: Message-ID: Le jeudi 9 janvier 2014 19:49:27 UTC+1, Ethan Furman a ?crit?: > So I'm working with postgres, and I get a datadump which I try to restore to my test system, and I get this: > > > > ERROR: value too long for type character varying(4) > > CONTEXT: COPY res_currency, line 32, column symbol: "???" > > > > "py6" sure looks like it should fit, but it don't. Further investigation revealed that "py6" is made up of the bytes d1 > > 80 d1 83 d0 b1. > > > > Any ideas on what that means, exactly? > > When one has to face such a characteristic sequence, the first thing to do is to think "utf-8". (Not a proof) >>> a = list(range(0x0410, 0x0415)) >>> a += list(range(0x0440, 0x0445)) >>> a += list(range(0x0480, 0x0485)) >>> import unicodedata as ud >>> for i in a: ... hex(i), chr(i).encode('utf-8'), ud.name(chr(i)) ... ('0x410', b'\xd0\x90', 'CYRILLIC CAPITAL LETTER A') ('0x411', b'\xd0\x91', 'CYRILLIC CAPITAL LETTER BE') ('0x412', b'\xd0\x92', 'CYRILLIC CAPITAL LETTER VE') ('0x413', b'\xd0\x93', 'CYRILLIC CAPITAL LETTER GHE') ('0x414', b'\xd0\x94', 'CYRILLIC CAPITAL LETTER DE') ('0x440', b'\xd1\x80', 'CYRILLIC SMALL LETTER ER') ('0x441', b'\xd1\x81', 'CYRILLIC SMALL LETTER ES') ('0x442', b'\xd1\x82', 'CYRILLIC SMALL LETTER TE') ('0x443', b'\xd1\x83', 'CYRILLIC SMALL LETTER U') ('0x444', b'\xd1\x84', 'CYRILLIC SMALL LETTER EF') ('0x480', b'\xd2\x80', 'CYRILLIC CAPITAL LETTER KOPPA') ('0x481', b'\xd2\x81', 'CYRILLIC SMALL LETTER KOPPA') ('0x482', b'\xd2\x82', 'CYRILLIC THOUSANDS SIGN') ('0x483', b'\xd2\x83', 'COMBINING CYRILLIC TITLO') ('0x484', b'\xd2\x84', 'COMBINING CYRILLIC PALATALIZATION') jmf From breamoreboy at yahoo.co.uk Fri Jan 10 07:43:30 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Jan 2014 12:43:30 +0000 Subject: [OT]All right, I'me trying, really I am Message-ID: It's a peanuts cartoon https://www.pinterest.com/pin/44613852532468697/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From piet at vanoostrum.org Fri Jan 10 09:04:55 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 10 Jan 2014 15:04:55 +0100 Subject: Monkeypatching a staticmethod? References: Message-ID: Ian Kelly writes: > I suggest defining x as a normal function and writing the assignment > as "Foo.x = staticmethod(x)" to keep x callable from the global > namespace. Or just del it after doing the monkey patch. You can use Foo.x = staticmethod(lambda: 2) -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From john_ladasky at sbcglobal.net Fri Jan 10 12:36:36 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 10 Jan 2014 09:36:36 -0800 (PST) Subject: Python 2.x and 3.x usage survey In-Reply-To: References: Message-ID: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> I responded to the survey about a week ago. Dan, I hope you will share the results with us soon. I also tried to reply to this thread, but I lost the ability to post to newsgroups for about a week. It seems to have been restored, so I will try again. My transition from Py2 to Py3 is implicitly documented in several posts here on comp.lang.python. I switched over to Py3 about a year ago, and I'm not looking back. I couldn't move to Py3 until numpy and matplotlib were ported. But once that was done, the advantages outweighed the costs, and I switched. Changing over has not been painless. I'm doing without wxPython for now, my favorite GUI. I know that Phoenix is coming to take wxPython's place. Meanwhile, I'm willing to be sold on any other Linux- and Py3-compatible GUI -- besides TKinter, that is. I also miss psyco. I had a lot of Py2 code which made very little use of dynamic typing. Psyco accelerated it nicely. I believe that that a lot of my Py3 code would also benefit from JIT compilation. Finally, I have encountered some small mental hurdles concerning Unicode. I am teaching a Silicon Valley test engineer Python on the side. His task is to implement an automated device testing suite over a telnet connection. We have to remember to convert between the remote device's expectation of strings of bytes, and Python's expectation of strings of Unicode characters. When we forget, there can be bugs. I'm sure that I'll get used to it eventually. From ned at nedbatchelder.com Fri Jan 10 12:48:43 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Jan 2014 12:48:43 -0500 Subject: Python 2.x and 3.x usage survey In-Reply-To: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> References: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> Message-ID: On 1/10/14 12:36 PM, John Ladasky wrote: > I responded to the survey about a week ago. Dan, I hope you will share the results with us soon. I also tried to reply to this thread, but I lost the ability to post to newsgroups for about a week. It seems to have been restored, so I will try again. > > My transition from Py2 to Py3 is implicitly documented in several posts here on comp.lang.python. I switched over to Py3 about a year ago, and I'm not looking back. I couldn't move to Py3 until numpy and matplotlib were ported. But once that was done, the advantages outweighed the costs, and I switched. > > Changing over has not been painless. I'm doing without wxPython for now, my favorite GUI. I know that Phoenix is coming to take wxPython's place. Meanwhile, I'm willing to be sold on any other Linux- and Py3-compatible GUI -- besides TKinter, that is. > > I also miss psyco. I had a lot of Py2 code which made very little use of dynamic typing. Psyco accelerated it nicely. I believe that that a lot of my Py3 code would also benefit from JIT compilation. > > Finally, I have encountered some small mental hurdles concerning Unicode. I am teaching a Silicon Valley test engineer Python on the side. His task is to implement an automated device testing suite over a telnet connection. We have to remember to convert between the remote device's expectation of strings of bytes, and Python's expectation of strings of Unicode characters. When we forget, there can be bugs. I'm sure that I'll get used to it eventually. > On Python-Dev, Dan Stromberg posted this link with the results: http://stromberg.dnsalias.org/~strombrg/python-2.x-vs-3.x-survey/ -- Ned Batchelder, http://nedbatchelder.com From ppearson at nowhere.invalid Fri Jan 10 13:22:41 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 10 Jan 2014 18:22:41 GMT Subject: Time zones and why they change so damned often (was: the Gravity of Python 2) References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: On Thu, 9 Jan 2014 15:14:55 +1100, Chris Angelico wrote: [snip] > What I find, most of the time, is that it's Americans who can't handle > DST. I run an international Dungeons and Dragons campaign (we play > online, and new players are most welcome, as are people watching!), > and the Aussies (myself included) know to check UTC time, the Brits > and Europeans check UTC or just know what UTC is, and the Americans > say "Doesn't that happen at 8 o'clock Eastern time?" and get confused. Around 30 years ago, the Wall Street Journal ran an opinion piece advocating the abandonment of time zones and the unification of the globe into a single glorious time zone. After enumerating the efficiencies to be achieved by this system, the writer briefly addressed the question of whose time zone would become the global standard, promptly arriving at the conclusion that, due to the concentration of important commerce, the logical choice was the east coast of the United States. My point: we deserve the teasing. -- To email me, substitute nowhere->spamcop, invalid->net. From ethan at stoneleaf.us Fri Jan 10 13:02:26 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 10 Jan 2014 10:02:26 -0800 Subject: Python 2.x and 3.x usage survey In-Reply-To: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> References: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> Message-ID: <52D035B2.1020704@stoneleaf.us> On 01/10/2014 09:36 AM, John Ladasky wrote: > > We have to remember to convert between the remote device's > expectation of strings of bytes, and Python's expectation of > strings of Unicode characters. When we forget, there can be > bugs. I'm sure that I'll get used to it eventually. A useful data point for why you don't just use bytes on the Python side would be valuable for the discussions currently taking place on PyDev. -- ~Ethan~ From python at mrabarnett.plus.com Fri Jan 10 13:48:41 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Jan 2014 18:48:41 +0000 Subject: Time zones and why they change so damned often In-Reply-To: References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: <52D04089.2090203@mrabarnett.plus.com> On 2014-01-10 18:22, Peter Pearson wrote: > On Thu, 9 Jan 2014 15:14:55 +1100, Chris Angelico wrote: > [snip] >> What I find, most of the time, is that it's Americans who can't handle >> DST. I run an international Dungeons and Dragons campaign (we play >> online, and new players are most welcome, as are people watching!), >> and the Aussies (myself included) know to check UTC time, the Brits >> and Europeans check UTC or just know what UTC is, and the Americans >> say "Doesn't that happen at 8 o'clock Eastern time?" and get confused. > > Around 30 years ago, the Wall Street Journal ran an opinion piece > advocating the abandonment of time zones and the unification of the > globe into a single glorious time zone. After enumerating the > efficiencies to be achieved by this system, the writer briefly > addressed the question of whose time zone would become the global > standard, promptly arriving at the conclusion that, due to the > concentration of important commerce, the logical choice was the > east coast of the United States. > What a silly idea! The logical choice is UTC. :-) > My point: we deserve the teasing. > From breamoreboy at yahoo.co.uk Fri Jan 10 13:53:18 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Jan 2014 18:53:18 +0000 Subject: Time zones and why they change so damned often In-Reply-To: <52D04089.2090203@mrabarnett.plus.com> References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> <52D04089.2090203@mrabarnett.plus.com> Message-ID: On 10/01/2014 18:48, MRAB wrote: > On 2014-01-10 18:22, Peter Pearson wrote: >> On Thu, 9 Jan 2014 15:14:55 +1100, Chris Angelico wrote: >> [snip] >>> What I find, most of the time, is that it's Americans who can't handle >>> DST. I run an international Dungeons and Dragons campaign (we play >>> online, and new players are most welcome, as are people watching!), >>> and the Aussies (myself included) know to check UTC time, the Brits >>> and Europeans check UTC or just know what UTC is, and the Americans >>> say "Doesn't that happen at 8 o'clock Eastern time?" and get confused. >> >> Around 30 years ago, the Wall Street Journal ran an opinion piece >> advocating the abandonment of time zones and the unification of the >> globe into a single glorious time zone. After enumerating the >> efficiencies to be achieved by this system, the writer briefly >> addressed the question of whose time zone would become the global >> standard, promptly arriving at the conclusion that, due to the >> concentration of important commerce, the logical choice was the >> east coast of the United States. >> > What a silly idea! > > The logical choice is UTC. :-) Hell will freeze over first. But apparently it already has in Minnesota. Drat, drat and double drat!!! > >> My point: we deserve the teasing. >> > -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bryan.kardisco at gmail.com Fri Jan 10 14:38:32 2014 From: bryan.kardisco at gmail.com (bryan.kardisco at gmail.com) Date: Fri, 10 Jan 2014 11:38:32 -0800 (PST) Subject: Input Error issues - Windows 7 Message-ID: I'm new to python and am trying to just get some basic stuff up and going. I have a very basic module called foo It's in the following directory on my machine C:\workspace\PyFoo\src\foo In that folder is __init__.py (created automatically) and foo.py foo.py looks like this class foo(): def __init__(self, name, number): self.name = name self.number = number def getName(self): return self.name def getNumber(self): return self.number If I open up command prompt and do following it works: C:\workspace\PyFoo\src\foo>python Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from foo import foo >>> f = foo(1,2) >>> f.getName() 1 >>> However, if I run this from C:\ I get the following C:\>python Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from foo import foo Traceback (most recent call last): File "", line 1, in ImportError: No module named 'foo' >>> I thought, well maybe it's a system error >>> import sys >>> print(sys.path) ['', 'C:\\Python33', 'C:\\Python33\\Lib', 'C:\\Python33\\DLLs', 'C:\\workspace', 'C:\\Windows\\system32\\python33.zip', 'C:\\Python33\\lib\\site-packages'] >>> C:\>echo %PYTHONPATH% C:\Python33;C:\Python33\Lib;C:\Python33\DLLs;C:\workspace However, that seems OK. Is there something I'm missing? From john_ladasky at sbcglobal.net Fri Jan 10 14:43:31 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 10 Jan 2014 11:43:31 -0800 (PST) Subject: Python 2.x and 3.x usage survey In-Reply-To: References: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> Message-ID: <1fd7f186-e78b-4806-a9bc-43b3e603929d@googlegroups.com> On Friday, January 10, 2014 9:48:43 AM UTC-8, Ned Batchelder wrote: > On Python-Dev, Dan Stromberg posted this link with the results: > > http://stromberg.dnsalias.org/~strombrg/python-2.x-vs-3.x-survey/ That link gave me a 404. :^( From ned at nedbatchelder.com Fri Jan 10 14:48:10 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Jan 2014 14:48:10 -0500 Subject: Input Error issues - Windows 7 In-Reply-To: References: Message-ID: On 1/10/14 2:38 PM, bryan.kardisco at gmail.com wrote: > I'm new to python and am trying to just get some basic stuff up and going. Welcome! > > I have a very basic module called foo > > It's in the following directory on my machine > > C:\workspace\PyFoo\src\foo > In that folder is __init__.py (created automatically) and foo.py > > foo.py looks like this > > class foo(): > def __init__(self, name, number): > self.name = name > self.number = number > def getName(self): > return self.name > def getNumber(self): > return self.number > > > If I open up command prompt and do following it works: > > C:\workspace\PyFoo\src\foo>python > Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from foo import foo >>>> f = foo(1,2) >>>> f.getName() > 1 >>>> > > > However, if I run this from C:\ I get the following > > C:\>python > Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from foo import foo > Traceback (most recent call last): > File "", line 1, in > ImportError: No module named 'foo' >>>> > > > I thought, well maybe it's a system error > >>>> import sys >>>> print(sys.path) > ['', 'C:\\Python33', 'C:\\Python33\\Lib', 'C:\\Python33\\DLLs', 'C:\\workspace', 'C:\\Windows\\system32\\python33.zip', > 'C:\\Python33\\lib\\site-packages'] >>>> > > C:\>echo %PYTHONPATH% > C:\Python33;C:\Python33\Lib;C:\Python33\DLLs;C:\workspace > > However, that seems OK. > > Is there something I'm missing? > The PYTHONPATH contains the directories that will be searched for modules and packages. Your package is called foo, and is in c:\workspace\PyFoo\src. That directory is not on the Python path, and it isn't the current directory. Therefore, your package can't be found and imported. BTW: writting getters like getName and getNumber is unusual in Python. The much more common technique is to simply use the attribute: f.name -- Ned Batchelder, http://nedbatchelder.com From python at mrabarnett.plus.com Fri Jan 10 14:53:30 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 10 Jan 2014 19:53:30 +0000 Subject: Python 2.x and 3.x usage survey In-Reply-To: <1fd7f186-e78b-4806-a9bc-43b3e603929d@googlegroups.com> References: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> <1fd7f186-e78b-4806-a9bc-43b3e603929d@googlegroups.com> Message-ID: <52D04FBA.5070406@mrabarnett.plus.com> On 2014-01-10 19:43, John Ladasky wrote: > On Friday, January 10, 2014 9:48:43 AM UTC-8, Ned Batchelder wrote: > >> On Python-Dev, Dan Stromberg posted this link with the results: >> >> http://stromberg.dnsalias.org/~strombrg/python-2.x-vs-3.x-survey/ > > That link gave me a 404. :^( > It's available here: https://wiki.python.org/moin/2.x-vs-3.x-survey?action=AttachFile&do=view&target=2013-2014+Python+2.x-3.x+survey.pdf From ned at nedbatchelder.com Fri Jan 10 14:50:02 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Jan 2014 14:50:02 -0500 Subject: Python 2.x and 3.x usage survey In-Reply-To: <1fd7f186-e78b-4806-a9bc-43b3e603929d@googlegroups.com> References: <7997d5b4-4616-4506-8191-62ee4a5b4ee3@googlegroups.com> <1fd7f186-e78b-4806-a9bc-43b3e603929d@googlegroups.com> Message-ID: On 1/10/14 2:43 PM, John Ladasky wrote: > On Friday, January 10, 2014 9:48:43 AM UTC-8, Ned Batchelder wrote: > >> On Python-Dev, Dan Stromberg posted this link with the results: >> >> http://stromberg.dnsalias.org/~strombrg/python-2.x-vs-3.x-survey/ > > That link gave me a 404. :^( > Sorry, it worked when I read it when first posted. They've been put on the Python wiki: https://wiki.python.org/moin/2.x-vs-3.x-survey -- Ned Batchelder, http://nedbatchelder.com From invalid at invalid.invalid Fri Jan 10 14:55:37 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 10 Jan 2014 19:55:37 +0000 (UTC) Subject: Time zones and why they change so damned often References: <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> <52D04089.2090203@mrabarnett.plus.com> Message-ID: On 2014-01-10, Mark Lawrence wrote: > Hell will freeze over first. But apparently it already has in > Minnesota. Drat, drat and double drat!!! It got darned cold here in Minnesota on Monday (-23F in Minneapolis, -35F in Embarass), but Hell is in Michigan -- where it only got down to -15F. http://en.wikipedia.org/wiki/Hell,_Michigan http://www.roadsideamerica.com/tip/2456 From breamoreboy at yahoo.co.uk Fri Jan 10 15:29:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Jan 2014 20:29:17 +0000 Subject: Porting mailing list underused? Message-ID: Given the adverse publicity recently over the problems with porting from 2 to 3, I find it strange that the subject list has only 351 messages that I can see dating from 15/12/2008 to 05/01/2014. This is despite it being clearly mentioned here http://www.python.org/community/lists/ Anyone in the know who can explain this phenomenon? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From jeremiahvalerio123 at gmail.com Fri Jan 10 15:26:54 2014 From: jeremiahvalerio123 at gmail.com (jeremiah valerio) Date: Fri, 10 Jan 2014 12:26:54 -0800 (PST) Subject: Constructive Criticism In-Reply-To: References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> Message-ID: <808615c3-ce1a-46ae-b875-55cd2f58b3b3@googlegroups.com> On Friday, January 10, 2014 2:56:14 AM UTC-6, Alister wrote: > On Thu, 09 Jan 2014 13:05:23 -0800, jeremiah valerio wrote: > > > > > On Thursday, January 9, 2014 2:54:44 PM UTC-6, Christopher Welborn > > > wrote: > > >> On 01/08/2014 11:56 PM, jeremiahvalerio123 at gmail.com wrote: > > >> > > >> > Hi, hows it going I've been self teaching myself python, and i typed > > >> > up this small script now i know its not the best the coding is not > > >> > the best but i would like to know of ways to make a small script like > > >> > this better so all constructive critisim is Welcome. > > >> > > >> > > >> > > > >> > > >> > > > >> > > >> > > > >> > Here is the link to the code > > >> > > >> > > >> > > > >> > " http://pastebin.com/5uCFR2pz " > > >> > > >> > > >> > > > >> > > >> > > >> I'm not sure if someone already pointed this out, but imports only need > > >> > > >> to be done once. Usually at the beginning of the file, but not always. > > >> > > >> In your case I would say yes, at the beginning. > > >> > > >> > > >> > > >> import sys > > >> > > >> import time > > >> > > >> > > >> > > >> def countdown(seconds):' > > >> > > >> # start at 'seconds' and count down with a for-loop > > >> > > >> for i in range(seconds, 0, -1): > > >> > > >> # print the current second (i) > > >> > > >> print('closing in {} seconds.'.format(i)) > > >> > > >> # sleep for one second (no need to import time again). > > >> > > >> time.sleep(1) > > >> > > >> > > >> > > >> # Example usage: > > >> > > >> print('hello') > > >> > > >> # Prints the countdown. > > >> > > >> countdown(10) > > >> > > >> sys.exit(0) > > >> > > >> -- > > >> > > >> > > >> > > >> - Christopher Welborn > > >> > > >> http://welbornprod.com > > > > > > Mr.Peter Otten did > > > > > > "- You should import modules just once, at the beginning of your script. > > > " > > > > > > -Peter Otten > > > With his help this is what i have now > > > > > > def countdown(): > > > import time for seconds_left in reversed(range(1, 10)): > > > print("Closing in", seconds_left, "seconds") > > > time.sleep(1) > > > exit() > > > > > > if user_input == "yes" : > > > user_input = input("\nGreat what should we talk > > > about?\nSports\nWeather") > > > elif user_input == "no" : > > > print("\nAlrighty bye have a nice day! :)\n\nClosing in 10.") > > > countdown() > > > > you could improve your countdown function further by adding an optional > > count vaule > > > > def countdown(count=10): > > for timeleft in reversed(1,count): > > print ("Shutting down in {} Seconds".format(timeleft)) > > time.sleep(1) > > -- > > Most people can't understand how others can blow their noses differently > > than they do. > > -- Turgenev So always think of the if's and possibility's that other people might do, thanks for you input. From rosuav at gmail.com Fri Jan 10 15:34:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Jan 2014 07:34:45 +1100 Subject: Constructive Criticism In-Reply-To: <808615c3-ce1a-46ae-b875-55cd2f58b3b3@googlegroups.com> References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> <808615c3-ce1a-46ae-b875-55cd2f58b3b3@googlegroups.com> Message-ID: On Sat, Jan 11, 2014 at 7:26 AM, jeremiah valerio wrote: > So always think of the if's and possibility's that > other people might do, thanks for you input. Also think of the possibility that someone will read your post and its quoted text. Please get off Google Groups, or if you must keep using it, clean up your quotes - they're all coming out double-spaced. You may find the mailing list easier to use: https://mail.python.org/mailman/listinfo/python-list ChrisA From skip at pobox.com Fri Jan 10 15:38:29 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 10 Jan 2014 14:38:29 -0600 Subject: Porting mailing list underused? In-Reply-To: References: Message-ID: > Anyone in the > know who can explain this phenomenon? I don't think I can explain it authoritatively, but I can hazard a guess. Skimming the archives sorted by author, it looks like most/all the correspondents are Python core developers. That leads me to believe this was a list created for the core Python developers to discuss issues related to porting tools such as 2to3 or six. I doubt it was intended for Python programmers to get help porting their own code. From the Python core development perspective, I think automated porting tools are likely pretty mature at this point and don't warrant a lot of discussion. Skip From gheskett at wdtv.com Fri Jan 10 15:26:22 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 10 Jan 2014 15:26:22 -0500 Subject: Time zones and why they change so damned often In-Reply-To: References: <52D04089.2090203@mrabarnett.plus.com> Message-ID: <201401101526.23061.gheskett@wdtv.com> On Friday 10 January 2014 15:24:11 Mark Lawrence did opine: > On 10/01/2014 18:48, MRAB wrote: > > On 2014-01-10 18:22, Peter Pearson wrote: > >> On Thu, 9 Jan 2014 15:14:55 +1100, Chris Angelico wrote: > >> [snip] > >> > >>> What I find, most of the time, is that it's Americans who can't > >>> handle DST. I run an international Dungeons and Dragons campaign > >>> (we play online, and new players are most welcome, as are people > >>> watching!), and the Aussies (myself included) know to check UTC > >>> time, the Brits and Europeans check UTC or just know what UTC is, > >>> and the Americans say "Doesn't that happen at 8 o'clock Eastern > >>> time?" and get confused. > >> > >> Around 30 years ago, the Wall Street Journal ran an opinion piece > >> advocating the abandonment of time zones and the unification of the > >> globe into a single glorious time zone. After enumerating the > >> efficiencies to be achieved by this system, the writer briefly > >> addressed the question of whose time zone would become the global > >> standard, promptly arriving at the conclusion that, due to the > >> concentration of important commerce, the logical choice was the > >> east coast of the United States. > > > > What a silly idea! > > > > The logical choice is UTC. :-) > > Hell will freeze over first. But apparently it already has in > Minnesota. Drat, drat and double drat!!! That Hell the headlines referred to is in Michigan... Its a headline they drag out every time we get a cold snap & its ano otherwise slow news day. Nothing to see here, now move along please... > > >> My point: we deserve the teasing. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page Young men want to be faithful and are not; old men want to be faithless and cannot. -- Oscar Wilde A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From fomcl at yahoo.com Fri Jan 10 12:38:27 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Fri, 10 Jan 2014 09:38:27 -0800 (PST) Subject: L[:] Message-ID: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> In Python Cookbook, one of the authors (I forgot who) consistently used the "L[:]" idiom like below. If the second line simply starts with "L =" (so no "[:]") only the name "L" would be rebound, not the underlying object. That was the author? explanation as far as I can remember. I do not get that. Why is the "L[:]" idiom more memory-efficient here? How could the increased efficiency be demonstrated? #Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 >>> L = [x ** 2 for x in range(10)] >>> L[:] = ["foo_" + str(x) for x in L] Thanks! Regards, Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From vanommen.robert at gmail.com Fri Jan 10 15:57:59 2014 From: vanommen.robert at gmail.com (vanommen.robert at gmail.com) Date: Fri, 10 Jan 2014 12:57:59 -0800 (PST) Subject: Send array back in result from urllib2.urlopen(request, postData) Message-ID: Hello, I have a Raspberry Pi with 10 temperature sensors. I send the data from the sensors and some other values with json encoding and: result = urllib2.urlopen(request, postData) to a online PHP script wich places the data in a mysql database. In the result: result.read() i am trying to send data back from the PHP to the RPI. I make an array in PHP $para[0] = $REGELING_ORG; $para[1] = $VLVERWL_ORG; $para[2] = $VLOERVRAAG_ORG; $para[3] = $TIJDVLOER_ORG; $para[4] = $SETPOINT_ORG; echo $para; In python when i do para = result.read() print para the output is: [null,null,null,null,null,"J"] This is correct according to the data in PHP from the mysql. when I do print para[1] the output is: n the seccond character from the data. Why is this not the seccond datafield? And why is para[5] not "J" but , ? How can I change the data back to an array? I've tried with json, but that doesn't change anything. Thanks in advance for the kind reactions! Greetings Robert. From breamoreboy at yahoo.co.uk Fri Jan 10 16:24:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Jan 2014 21:24:28 +0000 Subject: Constructive Criticism In-Reply-To: <808615c3-ce1a-46ae-b875-55cd2f58b3b3@googlegroups.com> References: <8574fa07-af12-4e62-9cbc-3bd00802b6e2@googlegroups.com> <483bb41e-4e0b-4506-91b3-197e03477144@googlegroups.com> <808615c3-ce1a-46ae-b875-55cd2f58b3b3@googlegroups.com> Message-ID: On 10/01/2014 20:26, jeremiah valerio wrote: For the second time of asking would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing double line spacing, thanks. Failing that, please arm yourself with a semi-decent email client, there are umpteen to choose from. -- 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 Fri Jan 10 16:31:13 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 10 Jan 2014 21:31:13 +0000 Subject: Porting mailing list underused? In-Reply-To: References: Message-ID: On 10/01/2014 20:38, Skip Montanaro wrote: >> Anyone in the >> know who can explain this phenomenon? > > I don't think I can explain it authoritatively, but I can hazard a > guess. Skimming the archives sorted by author, it looks like most/all > the correspondents are Python core developers. That leads me to > believe this was a list created for the core Python developers to > discuss issues related to porting tools such as 2to3 or six. I doubt > it was intended for Python programmers to get help porting their own > code. From the Python core development perspective, I think automated > porting tools are likely pretty mature at this point and don't warrant > a lot of discussion. > > Skip > If the dumbo OP had remembered to say that https://mail.python.org/mailman/listinfo/python-porting states rather vaguely "This list is to contain discussion of porting Python code between versions, mainly from Python 2.x to 3.x." it might have helped garner more answers. Still, if we leave the list open for long enough we'll all be able to discuss porting python 2.x to python 4.x :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ned at nedbatchelder.com Fri Jan 10 17:03:49 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 10 Jan 2014 17:03:49 -0500 Subject: L[:] In-Reply-To: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> References: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> Message-ID: On 1/10/14 12:38 PM, Albert-Jan Roskam wrote: > In Python Cookbook, one of the authors (I forgot who) consistently used the "L[:]" idiom like below. If the second line simply starts with "L =" (so no "[:]") only the name "L" would be rebound, not the underlying object. That was the author? explanation as far as I can remember. I do not get that. Why is the "L[:]" idiom more memory-efficient here? How could the increased efficiency be demonstrated? > > #Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 >>>> L = [x ** 2 for x in range(10)] >>>> L[:] = ["foo_" + str(x) for x in L] > I'm not sure there is a memory efficiency argument to make here. The big difference is that the first line make L refer to a completely new list, while the second line replaces the contents of an existing list. This makes a big difference if there are other names referring to the list: >>> L = [1, 2, 3, 4] >>> L2 = L >>> L[:] = [] >>> print L2 [] >>> L = [1, 2, 3, 4] >>> L2 = L >>> L = [] >>> print L2 [1, 2, 3, 4] Names and values in Python can be confusing. Here's an explanation of the mechanics: http://nedbatchelder.com/text/names.html HTH, --Ned. > > Thanks! > > > Regards, > > Albert-Jan -- Ned Batchelder, http://nedbatchelder.com From tjreedy at udel.edu Fri Jan 10 17:38:42 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 10 Jan 2014 17:38:42 -0500 Subject: L[:] In-Reply-To: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> References: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> Message-ID: On 1/10/2014 12:38 PM, Albert-Jan Roskam wrote: > In Python Cookbook, one of the authors (I forgot who) consistently used the "L[:]" idiom like below. If the second line simply starts with "L =" (so no "[:]") only the name "L" would be rebound, not the underlying object. That was the author? explanation as far as I can remember. I do not get that. Why is the "L[:]" idiom more memory-efficient here? How could the increased efficiency be demonstrated? > > #Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 >>>> L = [x ** 2 for x in range(10)] >>>> L[:] = ["foo_" + str(x) for x in L] Unless L is aliased, this is silly code. The list comp makes a new list object, so if L does not have aliases, it would be best to rebind 'L' to the existing list object instead of copying it. To do the replacement 'in place': L = [x ** 2 for x in range(10)] for i, n in enumerate(L): L[i] = "foo_" + str(n) print(L) >>> ['foo_0', 'foo_1', 'foo_4', 'foo_9', 'foo_16', 'foo_25', 'foo_36', 'foo_49', 'foo_64', 'foo_81'] -- Terry Jan Reedy From gordon at panix.com Fri Jan 10 17:53:19 2014 From: gordon at panix.com (John Gordon) Date: Fri, 10 Jan 2014 22:53:19 +0000 (UTC) Subject: Send array back in result from urllib2.urlopen(request, postData) References: Message-ID: In vanommen.robert at gmail.com writes: > result = urllib2.urlopen(request, postData) > para = result.read() > print para > the output is: > [null,null,null,null,null,"J"] > print para[1] > the output is: > n Probably because para is a string with the value '[null,null,null,null,null,"J"]' > How can I change the data back to an array? I've tried with json, but > that doesn't change anything. As far as I know, result.read() only returns text. If you want your results in some other format (like an array), you'll need to parse the string. This is a very simple (and ugly) way to do it, but it may give you a starting point: # open the url result = urllib2.urlopen(request, postData) # read the raw text results raw_text = result.read() # strip off the leading '[' and trailing ']' raw_text = raw_text[1:-1] # split raw_text into an array of strings text_array = raw_text.split(',') # declare a new list for storing the parsed items para = [] # process each string for item in text_array: if item == 'null': para.append(None) else: para.append(item) The python csv module might have a better way to do this; have a look. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From davea at davea.name Fri Jan 10 18:12:46 2014 From: davea at davea.name (Dave Angel) Date: Fri, 10 Jan 2014 18:12:46 -0500 Subject: Send array back in result from urllib2.urlopen(request, postData) In-Reply-To: References: Message-ID: On Fri, 10 Jan 2014 12:57:59 -0800 (PST), vanommen.robert at gmail.com wrote: No idea about the php.. > In python when i do > para = result.read() > print para > the output is: > [null,null,null,null,null,"J"] That's a string that just looks like a list. > This is correct according to the data in PHP from the mysql. > when I do > print para[1] > the output is: > n > the seccond character from the data. Why is this not the seccond datafield? There are no data fields in a string. > And why is para[5] not "J" but , ? That's character 5 of the string. > How can I change the data back to an array? I've tried with json, but that doesn't change anything. You have to parse it. I don't know what rules you used at the php end, but at a guess, I'd start by stripping the brackets, then splitting by comma. Then iterate through each item looking for special cases. Each item consisting of null gets replaced by None, each item starting with quotes gets them stripped, and perhaps anything else is replaced by float (item). Still questions to ask like whether quoted item can have embedded comma. -- DaveA From davea at davea.name Fri Jan 10 18:20:32 2014 From: davea at davea.name (Dave Angel) Date: Fri, 10 Jan 2014 18:20:32 -0500 Subject: Input Error issues - Windows 7 In-Reply-To: References: Message-ID: On Fri, 10 Jan 2014 11:38:32 -0800 (PST), bryan.kardisco at gmail.com wrote: > It's in the following directory on my machine > C:\workspace\PyFoo\src\foo > In that folder is __init__.py (created automatically) and foo.py > foo.py looks like this > class foo(): Ned has pointed out your path problem. But you have another, perhaps caused by overexposure to java. You have a package, a module and a class, all with the same name. Convention says at least uppercase for the class. I say make every name unique till you learn how they work. -- DaveA From denismfmcmahon at gmail.com Fri Jan 10 18:56:27 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 10 Jan 2014 23:56:27 +0000 (UTC) Subject: Send array back in result from urllib2.urlopen(request, postData) References: Message-ID: On Fri, 10 Jan 2014 12:57:59 -0800, vanommen.robert wrote: > Hello, > > I have a Raspberry Pi with 10 temperature sensors. I send the data from > the sensors and some other values with json encoding and: > > result = urllib2.urlopen(request, postData) > > to a online PHP script wich places the data in a mysql database. > > In the result: > > result.read() > > i am trying to send data back from the PHP to the RPI. I make an array > in PHP > > $para[0] = $REGELING_ORG; > $para[1] = $VLVERWL_ORG; > $para[2] = $VLOERVRAAG_ORG; > $para[3] = $TIJDVLOER_ORG; > $para[4] = $SETPOINT_ORG; > > echo $para; This is php code that prints out a string representation of the variable, in so far as it can. What you probably want to do is encode the array somehow, such as one element value per line, or json encode, or some other method, and then decode it in your python. > In python when i do > > para = result.read() > print para > > the output is: > > [null,null,null,null,null,"J"] Yep, that's because para is a string containing the text: '[null,null,null,null,null,"J"]' > This is correct according to the data in PHP from the mysql. > > when I do > > print para[1] > > the output is: > > n > > the seccond character from the data. Why is this not the seccond > datafield? > And why is para[5] not "J" but , ? This is because python is looking at a string containing the character sequence '[null,null,null,null,null,"J"]' para[0] = '[' para[1] = 'n' para[2] = 'u' para[3] = 'l' para[4] = 'l' para[5] = ',' para[6] = 'n' para[7] = 'u' > How can I change the data back to an array? I've tried with json, but > that doesn't change anything. To use json to convert it back to an array in the python code, you also need to use json to serialise the array in the php code. eg in the php: echo $para; would become: echo php_json_encoding_function( para ); and in the python: para = result.read() would become: para = python_json_decoding_function( result.read() ) or possibly even: para = json.decode( result.read() ) (I don't know the details, I'm trying to give you the general idea so you can work out where to look to figure this out) These two web pages may also help: http://uk3.php.net/manual/en/function.json-encode.php http://docs.python.org/2/library/json.html -- Denis McMahon, denismfmcmahon at gmail.com From python at mrabarnett.plus.com Fri Jan 10 19:23:49 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 11 Jan 2014 00:23:49 +0000 Subject: Send array back in result from urllib2.urlopen(request, postData) In-Reply-To: References: Message-ID: <52D08F15.2060708@mrabarnett.plus.com> On 2014-01-10 20:57, vanommen.robert at gmail.com wrote: > Hello, > > I have a Raspberry Pi with 10 temperature sensors. I send the data from the sensors and some other values with json encoding and: > > result = urllib2.urlopen(request, postData) > > to a online PHP script wich places the data in a mysql database. > > In the result: > > result.read() > > i am trying to send data back from the PHP to the RPI. I make an array in PHP > > $para[0] = $REGELING_ORG; > $para[1] = $VLVERWL_ORG; > $para[2] = $VLOERVRAAG_ORG; > $para[3] = $TIJDVLOER_ORG; > $para[4] = $SETPOINT_ORG; > > echo $para; > > In python when i do > > para = result.read() > print para > > the output is: > > [null,null,null,null,null,"J"] > > This is correct according to the data in PHP from the mysql. > > when I do > > print para[1] > > the output is: > > n > > the seccond character from the data. Why is this not the seccond datafield? > And why is para[5] not "J" but , ? > > How can I change the data back to an array? I've tried with json, but that doesn't change anything. > [snip] What exactly do you mean by "json doesn't change anything"? I get this: >>> para = '[null,null,null,null,null,"J"]' >>> print para [null,null,null,null,null,"J"] >>> import json >>> print json.loads(para) [None, None, None, None, None, u'J'] From roy at panix.com Fri Jan 10 19:49:51 2014 From: roy at panix.com (Roy Smith) Date: Fri, 10 Jan 2014 19:49:51 -0500 Subject: Time zones and why they change so damned often (was: the Gravity of Python 2) References: <78d91$52cbf8e9$541826b9$29485@cache1.tilbu1.nb.home.nl> <4b702$52cc262e$541826b9$22985@cache80.multikabel.net> <4cbf$52cc2e82$541826b9$11761@cache70.multikabel.net> <686$52cd4640$541826b9$21896@cache1.tilbu1.nb.home.nl> <7wvbxteskh.fsf@benfinney.id.au> <7wr48hernb.fsf_-_@benfinney.id.au> Message-ID: In article , Peter Pearson wrote: > Around 30 years ago, the Wall Street Journal ran an opinion piece > advocating the abandonment of time zones and the unification of the > globe into a single glorious time zone. After enumerating the > efficiencies to be achieved by this system, the writer briefly > addressed the question of whose time zone would become the global > standard, promptly arriving at the conclusion that, due to the > concentration of important commerce, the logical choice was the > east coast of the United States. 30 years ago, that would have been a plausible choice. Today, not so much. From simeon.chaos at gmail.com Fri Jan 10 19:59:27 2014 From: simeon.chaos at gmail.com (Simeon Chaos) Date: Fri, 10 Jan 2014 16:59:27 -0800 (PST) Subject: With this artifact, everyone can easily invent new languages Message-ID: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> How is peasy (https://github/chaosim/peasy) simpler and more powerful than other parser tools? Simpler and more powerful? Maybe it is a bit contrary to common sense. True or false? To affirm, please give this project (https://github.com/chaosim/peasy) a glimpse at first. Because of being simple , you can comprehend it in a little while; because of being powerful, it will deserve your every minute. All along, the design of programming languages ??is a complex task. Because we need to understand the esoteric compiler theory and technology, and one of the most critical and very difficult part is to define the rules of the new language and to parse with them.To solve this problem, there have been many theories , techniques and tools . These tools can be roughly divided into two categories: one is parser generator, another is to write the parser by hand with or without a parser library. The parser generator generally based on some type of formal languages ??, by which the generator make the lexer and parser from some rules. Strong aspect of these tools is that they can produce the most efficient parser support for their own form of language types , according to the characteristics of formal language , generally ensures linear time complexity. Commonly divided into three types : LR technology , LL technology , PEG technology. LR technology language has shift/reduction , from the bottom up , the most right derived and other technical features , they can only support LR languages ??, more accurately, mainly LALR variants , plus some special treatment for the priority of operator. One of the most famous was undoubtedly the lex / yacc and its numerous subsequent variants ( such as bison, jison (javascript language ), ply (python lex / yacc) , etc. ) . LL technology has a top-down form of the language , recursive descent , the most left-dereived and other technical features , although the concept is easier to understand than the LR language , but because LL covers less languages, so not used as universal as lex / yacc. Representative products are antlr. PEG technology refers to parsing expression grammar parser generator. peg is a kind of formal grammar particularly suited to be parsed, currently there are already many tools appear. The most common method is packrat algorithm based implementations. Such as rats, ometa (there are many versions , such as ometa / squeak, ometa-js, pyMeta etc. ), pyPEG under python, peg.js under javascript, treetop and citrus under ruby, and so on. No matter what type of parser generator , the method to use them is to design rules for these tools , and then the tools generate parser. This is the difficult aspects. First, the object program is generated based on the state transfer and stack process, it is difficult to understand, debug and modify. Second, we must understand parser theory and technology of these tools is based on, the rules used by these tools is actually a domain-specific language , their expressivenes is very limited, while we must understand and become familiar with the new language in order to design rules. Third, we must embed certain processing ( abstract syntax tree structure , semantics, error reporting and handling , etc) in the form of object parser language into lex/parser rules. Difficulties in these areas prevent the most programmers to easily use this type of tool. ???? Meanwhile, people have also been pursuing a more relaxed and flexible approach to write parsers. Most of these methods produce tools can be classified as combinational parser library , or peg grammar-based peg library . Use of such libraries, programmers can use their own language in daily use to design a new universal language , parsing text, so they are used more freguently. Representative works is parsec under haskell language which maybe is the most mature and powerful. However, because haskell is too academic, and parsec is not universally popular. c + + language has boost phoenix library, probably because it depends on the c++ template, an advanced language features, it has not been widely used too. Python has pyparsing, which is used by many users. For specific questions , there are many applications do not use any tools or libraries, but manually write the entire parser , for example: cpython implementation, esprima for javascript. However, unfortunately, in their grammar and parsing of these tools, there are two obvious difficulties not been solved: the first is left recursive grammar, because left-recursive function will lead to an unconditional infinite recursion. The second is the parsing efficiency. In order to obtain a linear time complexity , we should only parse same syntax component only once at any position. To achieve the latter, the result of parsing is required. Meanwhile , the parser also need to be considered in conjunction to produce abstract syntax trees , semantic processing , error handling , etc., and these libraries maybe try to keep away from some of the problems (in the combined libraries left recursion are generally fobidden), or in order to solve these problems the program becomes very complex , difficult to understand , use, modify and extend. Can be seen from the above description , parsing is a very common programming needs , but also has a very high technical difficulty , resulting in a large number of theories, technique, and tools you have seen above, in this regard a variety of technical papers, code and tools can be used simply to describe the voluminous , but still did not achieve the desired results . with peasy, a complete and elegant solution to all these problems emerge for the first time. On one hand you can say peasy the most simple and elegant , but also has the most powerful and adaptability , and does not need to sacrifice speed and efficiency. Its characteristics are as follows: * for the first time, peasy provides a simple and complete solution to the problem of left recursion in the hand-written recursive descent parser manner, no matter direct or indirect left-recursive rule . To handle left recursive in peasy, only one function is needed (only 20 lines of code in coffeescript). * peasy allows programmers to write the parser with common programming language, and the parser and the input to the grammar rules are similar to the parser generator , both concise and readable , easy to modify and extend. * the simple and flexible caching mechanism in peasy can improve the time efficiency of parsing, we can maintain a linear time for liner time complexity grammar by caching. For complex grammar and data , we can also improve time efficiency by caching mechanism, and avoide the exponential, cube or square time complexity like some other common parsing algorithm. peasy's cache implementation is very simple, only one function (only ten lines of code under coffeescript ) . * the entire peasy implementation is very simple. only two hundred lines of code under cofeescript. The concept is simple. Only two kind of components: some match functions which operate on the parsed data and parsing pointer and some combinational functions which generate match function. all of these functions are very simple , usually only a few lines of code , And they exists in the code of peasy for demonstration objective, can be deleted, modified and replaced, according to the specific needs. In fact, instead of to be considered as a library or a tool, maybe it's better to view peasy as a method, a way or some example to write parsers mannually. This will allow for a greater degree of power. peasy provide specific examples to support the above conclusion. The most obvious example is the common programming languages ??in order to adapt and modify their parser tool to prevent left- recursive grammar . For example python grammar (http://docs.python.org/2/reference/grammar.html), javascript grammar (http://www-archive.mozilla.org/js/language/grammar14.html), while by using peasy, all binary arithmetic expression can be condensed into a simple left -recursive rules , left recursion elimination is not needed any more. For expression parsing, in order to further improve time efficiency , peasy also provides an example , has many different priorities for computing the call stack example can skip directly to the highest priority constant direct expression resolves to the final rather than, as is currently common practice, the rules of writing as follows : or -> (or | | and) | and; ...; add -> add + mul | mul; mul -> mul * atom | atom. Rare is , peasy while achieving enhanced capabilities of these expressions can also ensure that the linear time complexity of the parsing process. Want to know how peasy achieve these results? Please give a glimpse to peasy on github(https://github.com/chaosim/peasy). the first two of following links is the messages I posted when I started to get the inspiration to start writing peasy. Because there are some of other tasks to finish, intermediate interrupted for some time. Not long ago, I use peasy to parse something in another projects , and I further optimize the api of peasy, and which is now very simple and elegant, and I am satisfied :) As for the most critical left recursive , and caching algorithms , withstood the subsequent examples of the test , there is no any change. Together, these examples also continues to demonstrate the advantages of peasy . Finally, I need to mention the impact of language on thought: Without coffeescript language, maybe it's difficult for me to have these ideas. in coffeescript, the -> function notation and "assignment is an expression" making special concise readable grammar. In python similar results can be achieved, need to go through some twists and turns, and that is not so natural as in coffeescript.There should exists no big obstacle in other dynamic languages, but they is not as elegant as coffeescript tool. This point is obvious with the difference between the javascript code of peasy and its coffeescript source. messages I posted in google groups before: https://groups.google.com/forum/#!search/left$20recursive/comp.lang.javascript/GN7b9Tr6j98/DoiHzi9i77oJ https://groups.google.com/forum/#!search/%E5%B7%A6%E9%80%92%E5%BD%92/python-cn/Uqr-Xf3I3LM/oUd3Sj4HvxYJ lr grammar and lex/yacc, bison, ply http://en.wikipedia.org/wiki/LR_parser http://dinosaur.compilertools.net/ http://en.wikipedia.org/wiki/Yacc http://www.dabeaz.com/ply/ http://www.gnu.org/software/bison/ http://zaach.github.io/jison/ LL grammar http://en.wikipedia.org/wiki/LL_parser http://www.antlr.org/ some one asked for parser to handle left recursion on SO: http://stackoverflow.com/questions/4397039/any-peg-parser-capable-to-handle-left-recursion peg and packrat http://bford.info/packrat/ http://en.wikipedia.org/wiki/Parsing_expression_grammar http://cs.nyu.edu/rgrimm/xtc/rats-intro.html http://java-source.net/open-source/parser-generators/rats! phoenix http://www.boost.org/doc/libs/1_55_0/libs/spirit/phoenix/doc/html/index.html http://www.ontolinux.com/community/phoenix/Phoenix_Manual.pdf ometa? Alessandro Warth describe a method to handle left recursion in peg grammar in his PhD paper firstly. After I have my idea about Peasy and algorith to handle left recursion, I searched and found his paper, and found my algorithm is actully similar to his method. http://tinlizzie.org/ometa/ Memoization in Top-Down Parsing http://www.tinlizzie.org/~awarth/johnson.html https://github.com/alexwarth/ometa-js parsing under python https://wiki.python.org/moin/LanguageParsing parser for javascript or in javascript http://esprima.org/ http://zaach.github.io/jison/ From rosuav at gmail.com Fri Jan 10 21:17:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Jan 2014 13:17:33 +1100 Subject: With this artifact, everyone can easily invent new languages In-Reply-To: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> References: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> Message-ID: On Sat, Jan 11, 2014 at 11:59 AM, Simeon Chaos wrote: > All along, the design of programming languages is a complex task. Because we need to understand the esoteric compiler theory and technology, and one of the most critical and very difficult part is to define the rules of the new language and to parse with them.To solve this problem, there have been many theories , techniques and tools . These tools can be roughly divided into two categories: one is parser generator, another is to write the parser by hand with or without a parser library. > No tool will change the fact that the *design* of a language is a complex task. Long before you get to implementing anything, you have to decide what your language will look like, what its special features are, how it distinguishes one thing from another, etc etc etc. That work won't change based on the tool you use - or rather, if it DOES change, it's because the tool is too restrictive. First write some code in your new language, then and only then work out how to implement an interpreter/compiler. The first part of the job is pretty complex (and extremely important), and tools don't come into play till the second. ChrisA From ngangsia at gmail.com Fri Jan 10 23:18:32 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Fri, 10 Jan 2014 20:18:32 -0800 (PST) Subject: python first project Message-ID: Hi everyone, I have been around this group for some time and i saw that we have very helpful people here. i have been learning python just for about 5 months now and i have been given a task to do. This will be a leap into the programming industry for me. i am programming a system that will be giving details about finance, purchase(bills pending bills and paid bill), employees record and salary details, warehouse records. That is just all i intend to do this all on one GUI application window and to make it to be able to keep records for all the transaction which has been done inputted. I have started programming it , but i still feel there are a lot of things i miss out. Please i need some support from any honest person, please and also how to guide me complete this. I am also looking for guides and sources which can help me complete it. import os, sys print "#" * 50 print "#" * 50 def fin_sec(): print "The financial sector" fin_name = raw_input("Enter your Name: ") fin_amount = input("Enter the amount for finance: ") if fin_amount > 0: print "We have a "DEBIT BALANCE" of", fin_amount,"FCFA" else: print "There is "CREDIT BALANCE" of", fin_amount, "FCFA" print "Name of person doing the the transaction is ", fin_name print "Amount available for finance is ", fin_amount print "#" * 50 print "#" * 50 def purch_sec(): print "#" * 20 print "The purchase center" purchase_name_good = raw_input("Please enter the name of good or goods purchase: ") if not purch_name_good istitle(): purch_name_good.capitalize() purch_price = input("Please enter the price for purchase made: ") purch_p = raw_input("Please enter the reason of this purchase made: ") purch_customer = raw_input("Please enter the name of customer: ") purch_address = raw_input("Please enter the contact details for the customer: ") print "Name of goods purchase: ", purch_name_good print "Price of Good:",purch_price,"FCFA" print "Reason for the purchase: ", purch_p print "Customers name is: ", purch_customer print "Contact: ",purch_address def purch_Bill(): print "Regulating the Bills" bill_total= int(input("Please enter the total bill of purchase: ") bill_paid = int(input("Enter the bills paid in: ") # bill_pending = input("Please enter the amount for pending bills: ") print "The total bill paid: ", bill_total,"FCFA" print "The amount already paid: ", bill_paid,"FCFA" # print "The amount still left: ", bill_total - bill_paid,":::", "FCFA" if bill_total == bill_paid: print "Tne purchase amount was completed" elif bill_total > bill_paid: i = bill_total - bill_paid print "The purchase amount left to be paid is ", i print "DONE" print "##" * 50 print ":::" * 50 def emp_rec(): print "Employee Record and Details" emp_name = raw_input("Please enter the employee name: ") emp_age = int(input("Age: ") if emp_age > 18: pass else: print "The candidate is too young to be an employee" print "Name: ", emp_name print "Age:", emp_age From rosuav at gmail.com Fri Jan 10 23:29:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Jan 2014 15:29:39 +1100 Subject: python first project In-Reply-To: References: Message-ID: On Sat, Jan 11, 2014 at 3:18 PM, ngangsia akumbo wrote: > purch_price = input("Please enter the price for purchase made: ") > purch_p = raw_input("Please enter the reason of this purchase made: ") Never use input() in a Python 2 program... always use raw_input() instead. You're mostly right, but you have a few cases where you're using input(). Probably what you want is int(input()) or float(input()). Incidentally, is there a strong reason for using Python 2 for this? If not, I'd recommend moving immediately to Python 3, as there are an increasing number of advantages. Unless something actually binds you to Py2, save yourself the trouble of shifting in a few years' time and just use Py3 now. ChrisA From blogdiriferimento at gmail.com Sat Jan 11 00:28:54 2014 From: blogdiriferimento at gmail.com (FRATELLI DI STEFANO BISI) Date: Fri, 10 Jan 2014 21:28:54 -0800 (PST) Subject: -- redacted -- Message-ID: <2aee9945-ad78-4578-ba6e-b786213a9eb4@googlegroups.com> -- redacted -- From simeon.chaos at gmail.com Sat Jan 11 00:43:02 2014 From: simeon.chaos at gmail.com (Simeon Chaos) Date: Fri, 10 Jan 2014 21:43:02 -0800 (PST) Subject: With this artifact, everyone can easily invent new languages In-Reply-To: References: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> Message-ID: Yes? it's complex to design a new language. So don't let the tool stand in the way. There is a saying: Grinding a chopper will not hold up the work of cutting firewood. ? 2014?1?11????UTC+8??10?17?33??Chris Angelico??? > On Sat, Jan 11, 2014 at 11:59 AM, Simeon Chaos wrote: > > > All along, the design of programming languages is a complex task. Because we need to understand the esoteric compiler theory and technology, and one of the most critical and very difficult part is to define the rules of the new language and to parse with them.To solve this problem, there have been many theories , techniques and tools . These tools can be roughly divided into two categories: one is parser generator, another is to write the parser by hand with or without a parser library. > > > > > > > No tool will change the fact that the *design* of a language is a > > complex task. Long before you get to implementing anything, you have > > to decide what your language will look like, what its special features > > are, how it distinguishes one thing from another, etc etc etc. That > > work won't change based on the tool you use - or rather, if it DOES > > change, it's because the tool is too restrictive. First write some > > code in your new language, then and only then work out how to > > implement an interpreter/compiler. The first part of the job is pretty > > complex (and extremely important), and tools don't come into play till > > the second. > > > > ChrisA From james.harris.1 at gmail.com Sat Jan 11 02:47:33 2014 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 11 Jan 2014 07:47:33 -0000 Subject: With this artifact, everyone can easily invent new languages References: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> Message-ID: "Simeon Chaos" wrote in message news:bb7d8d30-845a-4a3d-9b03-dee71ef42986 at googlegroups.com... > ? 2014?1?11????UTC+8??10?17?33?,Chris Angelico??: > > On Sat, Jan 11, 2014 at 11:59 AM, Simeon Chaos wrote: > > > > > All along, the design of programming languages is a complex task. > > > Because we need to understand the esoteric compiler theory and > > > technology, and one of the most critical and very difficult part is to > > > define the rules of the new language and to parse with them.To solve > > > this problem, there have been many theories , techniques and tools . > > > These tools can be roughly divided into two categories: one is parser > > > generator, another is to write the parser by hand with or without a > > > parser library. > Yes, it's complex to design a new language. So don't let the tool stand in > the way. There is a saying: Grinding a chopper will not hold up the work > of cutting firewood. To the OP: this is a suitable topic for comp.lang.misc which is used for discussions about programming language design and implementation such as parse mechanisms. James From bob.martin at excite.com Sat Jan 11 02:52:36 2014 From: bob.martin at excite.com (Bob Martin) Date: Sat, 11 Jan 2014 07:52:36 GMT Subject: Time zones and why they change so damned often References: Message-ID: in 714281 20140110 090409 Alister wrote: >On Fri, 10 Jan 2014 07:31:11 +0000, Bob Martin wrote: > >> in 714232 20140109 120741 Alister wrote: >>>On Thu, 09 Jan 2014 07:17:25 +0000, Mark Lawrence wrote: >>> >>>> On 09/01/2014 04:14, Chris Angelico wrote: >>>>> On Thu, Jan 9, 2014 at 2:54 PM, Ben Finney >>>>> >>>>> wrote: >>>>>> I'm approaching it with the goal of knowing better what I'm talking >>>>>> about when I advocate scrapping the whole DST system :-) >>>>> >>>>> I would definitely support the scrapping of DST. I'm less sure that >>>>> we need exactly 24 timezones around the world, though. It's not >>>>> nearly as big a problem to have the half-hour and quarter-hour >>>>> timezones - though it would be easier if timezone were strictly an >>>>> integer number of hours. But DST is the real pain. >>>>> >>>>> What I find, most of the time, is that it's Americans who can't >>>>> handle DST. I run an international Dungeons and Dragons campaign (we >>>>> play online, and new players are most welcome, as are people >>>>> watching!), and the Aussies (myself included) know to check UTC time, >>>>> the Brits and Europeans check UTC or just know what UTC is, and the >>>>> Americans say "Doesn't that happen at 8 o'clock Eastern time?" and >>>>> get confused. >>>>> I don't understand this. Are my players drawn exclusively from the >>>>> pool of people who've never worked with anyone in Arizona [1]? Yes, >>>>> I'm stereotyping a bit here, and not every US player has had problems >>>>> with this, but it's the occasional US player who knows to check, and >>>>> the rare European, British, or Aussie player who doesn't. >>>>> >>>>> In any case, the world-wide abolition of DST would eliminate the >>>>> problem. The only remaining problem would be reminding people to >>>>> change the batteries in their smoke detectors. >>>>> >>>>> ChrisA >>>>> >>>>> [1] For those who aren't right up on timezone trivia, AZ has no DST. >>>>> Similarly the Australian state of Queensland does not shift its >>>>> clocks. >>>>> >>>>> >>>> I remember this "From February 1968 to November 1971 the UK kept >>>> daylight saving time throughout the year mainly for commercial >>>> reasons, especially regarding time conformity with other European >>>> countries". My source >>>> http://www.timeanddate.com/time/uk/time-zone-background.html >>> >>>we dont have "Daylight saving time" we switch between GMT (Greenwich >>>Mean Time) and BST (British Summer Time) at some point in the past we >>>have also used DST (Double Summer Time). >> >> British Summer Time *is* Daylight Saving Time. > >My point is in the UK we have never refered to it as Daylight saving Time >that is an Americanism :-) Sorry, but you are wrong again! Just Google it. From bigearl497 at outlook.com Sat Jan 11 03:07:37 2014 From: bigearl497 at outlook.com (pintreo mardi) Date: Sat, 11 Jan 2014 00:07:37 -0800 (PST) Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? Message-ID: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Hi, I've just begun to learn programming, I have an open question for the group: Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. Thanks!! From rosuav at gmail.com Sat Jan 11 03:21:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 11 Jan 2014 19:21:53 +1100 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On Sat, Jan 11, 2014 at 7:07 PM, pintreo mardi wrote: > Hi, I've just begun to learn programming, I have an open question for the group: > Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. > Thanks!! Python is a viable applications language, yes. There's nothing you can't write in Python that you can write in (say) Java - both languages are what's called "Turing complete". Every language has its special focus, though, so there'll be some things that are far easier in one language than another. In general, Python is a fine language for simple tasks like printing "Hello, world", for scripting, for writing GUI programs, and for building web applications. It's not restricted to tiny projects or to huge ones. There's no critical limit on the amount of "stuff" you can do before the code gets unwieldy, for instance, nor is there a level below which it's just too much hassle to put together a program. ChrisA From gheskett at wdtv.com Fri Jan 10 21:53:06 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Fri, 10 Jan 2014 21:53:06 -0500 Subject: Time zones and why they change so damned often In-Reply-To: References: Message-ID: <201401102153.06741.gheskett@wdtv.com> On Friday 10 January 2014 21:52:49 Dennis Lee Bieber did opine: > On Fri, 10 Jan 2014 19:55:37 +0000 (UTC), Grant Edwards > > declaimed the following: > >It got darned cold here in Minnesota on Monday (-23F in Minneapolis, > >-35F in Embarass), but Hell is in Michigan -- where it only got down > >to -15F. > > Does that mean that Hell should be Embarassed? Nah, they are used to it by now. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page May cause drowsiness. A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From mheieis at alois.ca Sat Jan 11 00:47:01 2014 From: mheieis at alois.ca (Mark Heieis) Date: Fri, 10 Jan 2014 21:47:01 -0800 Subject: Porting c extension - PyBuffer_New() deprecated in python3. What's the replacement? Message-ID: <52D0DAD5.3020803@alois.ca> Hi I need to convert the following existing c extension code to support Python 3. // --- existing code ------ // PyBuffer_New() deprecated in python3 if (!(pyBuf = PyBuffer_New(len))) { return NULL; } // should use memoryview object in python3 if (PyObject_AsWriteBuffer(pyBuf, &cbuf, &len)) { Py_DECREF(pyBuf); return NULL ; } // fill in cbuf ... return pyBuf ; //----------- I'm somewhat confounded in finding an equivalent (PyBuffer_New()) for creating a buffer of size len that has continuous memory in the c extension function for python3. cbuf is manipulated/filled in using c, after which the created pyBuf is then returned. So far, I haven't found much in the way of examples/doc for porting the deprecated Python-/C-level buffer API calls to the new C-level buffer API/memoryview object model. Any guidance or direction to existing doc/example is much appreciated. TIA. From stefan_ml at behnel.de Sat Jan 11 04:10:49 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 11 Jan 2014 10:10:49 +0100 Subject: Porting c extension - PyBuffer_New() deprecated in python3. What's the replacement? In-Reply-To: <52D0DAD5.3020803@alois.ca> References: <52D0DAD5.3020803@alois.ca> Message-ID: Mark Heieis, 11.01.2014 06:47: > I need to convert the following existing c extension code to support Python 3. > > // --- existing code ------ > > // PyBuffer_New() deprecated in python3 > if (!(pyBuf = PyBuffer_New(len))) > { > return NULL; > } > > // should use memoryview object in python3 > if (PyObject_AsWriteBuffer(pyBuf, &cbuf, &len)) > { > Py_DECREF(pyBuf); > return NULL ; > } > > // fill in cbuf > ... > > return pyBuf ; > > //----------- > > I'm somewhat confounded in finding an equivalent (PyBuffer_New()) for > creating a buffer of size len that has continuous memory in the c extension > function for python3. cbuf is manipulated/filled in using c, after which > the created pyBuf is then returned. So far, I haven't found much in the way > of examples/doc for porting the deprecated Python-/C-level buffer API calls > to the new C-level buffer API/memoryview object model. > > Any guidance or direction to existing doc/example is much appreciated. If the extension isn't huge, you should consider rewriting it in Cython. That can usually be done quite quickly - the main thing is to figure out what the verbose C code actually does and write it down in much simpler Python code. And it will make it easy to make the code portable and fast. Also likely safer and more generic and versatile, because Cython covers away a lot of the annoying boilerplate, ref-counting issues, type conversions, etc. For your specific problem at hand, you could use Cython's memory views: http://docs.cython.org/src/userguide/memoryviews.html They allow you to convert the input value to a 1-dim char buffer (or whatever you need, but you mentioned the old Py2 buffer interface, which can't do much more) by saying cdef char[:] my_memview = some_python_object If you need to pass the unpacked buffer into C code, you can get the address as "&my_memview[0]" (i.e. the address of the first item in the buffer). Memory views themselves support fast slicing and indexing, so you can efficiently work with them using the normal Python slicing/indexing syntax. In case what you actually receive are not arbitrary buffers but simple byte strings or bytearray instances, you can even use the normal byte string coercion in Cython and simply say cdef char* c_string = some_python_byte_string_object and then use that pointer to pass it on into C. I've written a string processing tutorial for Cython here: http://docs.cython.org/src/tutorial/strings.html These things may take a moment to learn, especially if you are used to doing everything in excessive manual detail in C code, but once you are through that, you should get things done much more quickly than when trying to do them by hand. Stefan From simeon.chaos at gmail.com Sat Jan 11 04:12:24 2014 From: simeon.chaos at gmail.com (Simeon Chaos) Date: Sat, 11 Jan 2014 01:12:24 -0800 (PST) Subject: With this artifact, everyone can easily invent new languages In-Reply-To: References: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> Message-ID: Thank you, James. I didn't know this group before. I'll post this message there. ? 2014?1?11????UTC+8??3?47?33??James Harris??? > "Simeon Chaos" wrote in message > > news:bb7d8d30-845a-4a3d-9b03-dee71ef42986 @googlegroups.com... > > > ? 2014?1?11????UTC+8??10?17?33?,Chris Angelico??: > > > > On Sat, Jan 11, 2014 at 11:59 AM, Simeon Chaos wrote: > > > > > > > > > All along, the design of programming languages is a complex task. > > > > > Because we need to understand the esoteric compiler theory and > > > > > technology, and one of the most critical and very difficult part is to > > > > > define the rules of the new language and to parse with them.To solve > > > > > this problem, there have been many theories , techniques and tools . > > > > > These tools can be roughly divided into two categories: one is parser > > > > > generator, another is to write the parser by hand with or without a > > > > > parser library. > > > > > Yes, it's complex to design a new language. So don't let the tool stand in > > > the way. There is a saying: Grinding a chopper will not hold up the work > > > of cutting firewood. > > > > To the OP: this is a suitable topic for comp.lang.misc which is used for > > discussions about programming language design and implementation such as > > parse mechanisms. > > > > James From vanommen.robert at gmail.com Sat Jan 11 04:31:44 2014 From: vanommen.robert at gmail.com (vanommen.robert at gmail.com) Date: Sat, 11 Jan 2014 01:31:44 -0800 (PST) Subject: Send array back in result from urllib2.urlopen(request, postData) In-Reply-To: References: Message-ID: <04e12d2a-122c-4ed1-a517-62c34a41a2aa@googlegroups.com> I understand the problem now. the echo is a string, wich can contain text but no array. I've changed the PHP script so I get only text separated with comma's and in python I separate the textfields and declare them in the array. With the split methode I saw in the answer of J. Gordon. Thank you for that. @MRAB When I encode the data in PHP and send it to Python, the results where the same. Thanks everyone for the answers! Greetings Robert. From bigearl497 at outlook.com Sat Jan 11 05:10:18 2014 From: bigearl497 at outlook.com (pintreo mardi) Date: Sat, 11 Jan 2014 02:10:18 -0800 (PST) Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: <80444995-a0b3-4f5f-8e7e-6f65906d27ab@googlegroups.com> On Saturday, January 11, 2014 1:51:53 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jan 11, 2014 at 7:07 PM, pintreo mardi wrote: > > > Hi, I've just begun to learn programming, I have an open question for the group: > > > Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. > > > Thanks!! > > > > Python is a viable applications language, yes. There's nothing you > > can't write in Python that you can write in (say) Java - both > > languages are what's called "Turing complete". Every language has its > > special focus, though, so there'll be some things that are far easier > > in one language than another. In general, Python is a fine language > > for simple tasks like printing "Hello, world", for scripting, for > > writing GUI programs, and for building web applications. It's not > > restricted to tiny projects or to huge ones. There's no critical limit > > on the amount of "stuff" you can do before the code gets unwieldy, for > > instance, nor is there a level below which it's just too much hassle > > to put together a program. > > > > ChrisA Thanks mate!! I'm a bit relieved. If I could get some really good books on programming with python, those for the beginners would be very helpful. From breamoreboy at yahoo.co.uk Sat Jan 11 05:47:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 11 Jan 2014 10:47:00 +0000 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On 11/01/2014 08:07, pintreo mardi wrote: > Hi, I've just begun to learn programming, I have an open question for the group: > Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. > Thanks!! > https://mail.python.org/pipermail/python-list/2002-November/141486.html -- 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 Jan 11 05:51:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 11 Jan 2014 10:51:41 +0000 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: <80444995-a0b3-4f5f-8e7e-6f65906d27ab@googlegroups.com> References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> <80444995-a0b3-4f5f-8e7e-6f65906d27ab@googlegroups.com> Message-ID: On 11/01/2014 10:10, pintreo mardi wrote: > On Saturday, January 11, 2014 1:51:53 PM UTC+5:30, Chris Angelico wrote: >> On Sat, Jan 11, 2014 at 7:07 PM, pintreo mardi wrote: >> >>> Hi, I've just begun to learn programming, I have an open question for the group: >> >>> Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. >> >>> Thanks!! >> >> >> >> Python is a viable applications language, yes. There's nothing you >> >> can't write in Python that you can write in (say) Java - both >> >> languages are what's called "Turing complete". Every language has its >> >> special focus, though, so there'll be some things that are far easier >> >> in one language than another. In general, Python is a fine language >> >> for simple tasks like printing "Hello, world", for scripting, for >> >> writing GUI programs, and for building web applications. It's not >> >> restricted to tiny projects or to huge ones. There's no critical limit >> >> on the amount of "stuff" you can do before the code gets unwieldy, for >> >> instance, nor is there a level below which it's just too much hassle >> >> to put together a program. >> >> >> >> ChrisA > > Thanks mate!! I'm a bit relieved. If I could get some really good books on programming with python, those for the beginners would be very helpful. > No, no, no, this can't be happening!!! Surely outlook can't have caught double spaced google disease, please see https://wiki.python.org/moin/GoogleGroupsPython for a description of the original problem and compare it to what's shown above. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bv4bv4bv4 at gmail.com Sat Jan 11 06:02:31 2014 From: bv4bv4bv4 at gmail.com (bv4bv4bv4 at gmail.com) Date: Sat, 11 Jan 2014 03:02:31 -0800 (PST) Subject: INTRODUCING ISLAM Message-ID: INTRODUCING ISLAM I. ISLAM AND MUSLIMS The name of this religion is Islam, the root of which is Silm and Salam which means peace. Salam may also mean greeting one another with peace. One of the beautiful names of God is that He is the Peace. It means more than that: submission to the One God, and to live in peace with the Creator, within one's self, with other people and with the environment. Thus, Islam is a total system of living. A Muslim is supposed to live in peace and harmony with all these segments; hence, a Muslim is any person anywhere in the world whose obedience, allegiance, and loyalty are to God, the Lord of the Universe. II. MUSLIMS AND ARABS The followers of Islam are called Muslims. Muslims are not to be confused with Arabs. Muslims may be Arabs, Turks, Persians, Indians, Pakistanis, Malaysians, Indonesians, Europeans, Africans, Americans, Chinese, or other nationalities. An Arab could be a Muslim, a Christian, a Jew or an atheist. Any person who adopts the Arabic language is called an Arab. However, the language of the Qur'an (the Holy Book of Islam) is Arabic. Muslims all over the world try to learn Arabic so that they may be able to read the Qur'an and understand its meaning. They pray in the language of the Qur'an, namely Arabic. Supplications to God could be in any language. While there are one billion Muslims in the world there are about 200 million Arabs. Among them, approximately ten percent are not Muslims. Thus Arab Muslims constitute only about twenty percent of the Muslim population of the world. III. ALLAH THE ONE AND THE ONLY GOD Allah is the name of the One and Only God. Allah has ninety-nine beautiful names, such as: The Gracious, The Merciful, The Beneficent, The Creator, The All-Knowing, The All-Wise, The Lord of the Universe, The First, The Last, and others. He is the Creator of all human beings. He is the God for the Christians, the Jews, the Muslims, the Buddhists, the Hindus, the atheists, and others. Muslims worship God whose name is Allah. They put their trust in Him and they seek His help and His guidance. IV. MUHAMMAD Muhammad was chosen by God to deliver His Message of Peace, namely Islam. He was born in 570 C.E. (Common Era) in Makkah, Arabia. He was entrusted with the Message of Islam when he was at the age of forty years. The revelation that he received is called the Qur'an, while the message is called Islam. Muhammad is the very last Prophet of God to mankind. He is the final Messenger of God. His message was and is still to the Christians, the Jews and the rest of mankind. He was sent to those religious people to inform them about the true mission of Jesus, Moses, Jacob, Isaac, and Abraham. Muhammad is considered to be the summation and the culmination of all the prophets and messengers that came before him. He purified the previous messages from adulteration and completed the Message of God for all humanity. He was entrusted with the power of explaining, interpreting and living the teaching of the Qur'an. V. SOURCE OF ISLAM The legal sources of Islam are the Qur'an and the Hadith. The Qur'an is the exact word of God; its authenticity, originality and totality are intact. The Hadith is the report of the sayings, deeds and approvals of the Prophet Muhammad. The Prophet's sayings and deeds are called Sunnah. The Seerah is the writings of followers of Muhammad about the life of the Prophet. Hence, it is the life history of the Prophet Muhammad which provides examples of daily living for Muslims. VI. SOME ISLAMIC PRINCIPLES A. Oneness of God: He is One and the Only One. He is not two in one or three in one. This means that Islam rejects the idea of trinity or such a unity of God which implies more than one God in one. B. Oneness of mankind: People are created equal in front of the Law of God. There is no superiority for one race over another. God made us of different colors, nationalities, languages and beliefs so as to test who is going to be better than others. No one can claim that he is better than others. It is only God Who knows who is better. It depends on piety and righteousness. C. Oneness of Messengers and the Message: Muslims believe that God sent different messengers throughout the history of mankind. All came with the same message and the same teachings. It was the people who misunderstood and misinterpreted them. Muslims believe in Noah, Abraham, Isaac, Ismail, Jacob, Moses, David, Jesus, and Muhammad. The Prophets of Christianity and Judaism are indeed the Prophets of Islam. D. Angels and the Day of Judgment: Muslims believe that there are unseen creatures such as angels created by God in the universe for special missions. Muslims believe that there is a Day of Judgment when all people of the world throughout the history of mankind till the last day of life on earth, are to be brought for accounting, reward and punishment. E. Innocence of Man at Birth: Muslim believe that people are born free of sin. It is only after they reach the age of puberty and it is only after they commit sins that they are to be charged for their mistakes. No one is responsible for or can take the responsibility for the sins of others. However, the door of forgiveness through true repentance is always open. F. State and Religion: Muslims believe that Islam is a total and a complete way of life. It encompasses all aspects of life. As such, the teachings of Islam do not separate religion from politics. As a matter of fact, state and religion are under the obedience of Allah through the teachings of Islam. Hence, economic and social transactions, as well as educational and political systems are also part of the teachings of Islam. VII. PRACTICES OF ISLAM God instructed the Muslims to practice what they believe in. In Islam there are five pillars, namely: 1. Creed (Shahada): The verbal commitment and pledge that there is only One God and that Muhammad is the Messenger of God, is considered to be the Creed of Islam. 2. Prayers (Salat): The performance of the five daily prayers is required of Muslims. 3. Fasting (Saum): Fasting is total abstinence from food, liquids and intimate intercourse (between married couples) from dawn to sunset during the entire month of Ramadan. 4. Purifying Tax (Zakat): This is an annual payment of a certain percentage of a Muslim's property which is distributed among the poor or other rightful beneficiaries. 5. Pilgrimage (Hajj): The performance of pilgrimage to Makkah is required once in a life time if means are available. Hajj is in part in memory of the trials and tribulations of Prophet Abraham, his wife Hagar and his eldest son Prophet Ishmael. VIII. OTHER RELATED ASPECTS A. Calendar: Islamic practices are based on the lunar calendar. However, Muslims also use the Gregorian calendar in their daily religious lives. Hence, the Islamic calendar includes both the common era and the migration (Higra) year of the Prophet of Islam from Makkah to Madinah in the year of 623 C.E. B. Celebrations (Eid): Muslims have two celebrations (Eid); namely, Eid of Sacrifice and Eid of Fast-Breaking. The Eid of Sacrifice is in remembrance of the sacrifice to be by Prophet Abraham of his son. The Eid of Fast-Breaking comes at the end of the month of fasting, Ramadan. C. Diets: Islam allows Muslims to eat everything which is good for the health. It restricts certain items such as pork and its by-products, alcohol and any narcotic or addictive drugs. D. Place of Worship: The place of worship is called Mosque or Masjid. There are three holy places of worship for the Muslims in the world. These are: Mosque of Kaaba in Makkah, Mosque of the Prophet Muhammad in Madinah, and Masjid Aqsa, adjacent to the Dome of the Rock in Jerusalem. A Muslim may pray any where in the world whether in a Mosque, a house, an office, or outside. The whole world is a place of worship. It is preferable that Muslims pray in a congregation, however, he/she may pray individually anywhere. E. Holidays: The holy day of the Muslims is Friday. It is considered to be sacred and the Day of Judgment will take place on Friday. Muslims join together shortly after noon on Friday for the Friday congregational prayer in a Mosque. A leader (Imam) gives a sermon (Khutba) and leads the congregational prayer. F. Distribution of Muslims in North America: There are approximately five million Muslims in North America and are distributed in its major cities such as New York, Detroit, Boston, Toledo, Chicago, Los Angeles, San Francisco, Houston, Cedar Rapids (Iowa), Toronto, Montreal, Ottawa, Edmonton, Vancouver, Windsor, Winnipeg, Calgary, and others. G. Contributions in North America: Muslims are established in North America. The Sears Tower and the John Hancock buildings in Chicago were designed by a Muslim chief architect, originally from Bangladesh. Muslims have established academic institutions, community centers and organizations, schools and places of worship. They live in peace and harmony among themselves and among other groups of people in the society. The rate of crime among Muslims is very minimal. Muslims in North America are highly educated and they have added to the success of American scientific and technological fields. The Muslims of the early period of the Islamic era were pioneers in medicine, chemistry, physics, geography, navigation, arts, poetry, mathematics, algebra, logarithms, calculus, etc. They contributed to the Renaissance of Europe and world civilization. IX. NON-MUSLIMS Muslims are required to respect all those who are faithful and God conscious people, namely those who received messages. Christians and Jews are called People of the Book. Muslims are asked to call upon the People of the Book for common terms, namely, to worship One God, and to work together for the solutions of the many problems in the society. Christians and Jews lived peacefully with Muslims throughout centuries in the Middle East and other Asian and African countries. The second Caliph Umar, did not pray in the church in Jerusalem so as not to give the Muslims an excuse to take it over. Christians entrusted the Muslims, and as such the key of the Church in Jerusalem is still in the hands of the Muslims. Jews fled from Spain during the Inquisition, and they were welcomed by the Muslims. They settled in the heart of the Islamic Caliphate. They enjoyed positions of power and authority. Throughout the Muslim world, churches, synagogues and missionary schools were built within the Muslim neighborhoods. These places were protected by Muslims even during the contemporary crises in the Middle East. --- Ahmad H. Sakr, Ph.D. For more information please contact: The Institute of Islamic Information and Education P.O. Box 41129 Chicago, IL 60641-0129 U.S.A. INTRODUCTION OF III&E The Institute of Islamic Information and Education (III&E) is dedicated to the cause of Islam in North America through striving to elevate the image of Islam in North America through striving to elevate the image of Islam and Muslims by providing the correct information about Islamic beliefs, history and civilization from the authentic sources. Enquiries are welcome. http://www.islamicity.com/mosque/intro_islam.htm thank you From alister.ware at ntlworld.com Sat Jan 11 06:10:41 2014 From: alister.ware at ntlworld.com (Alister) Date: Sat, 11 Jan 2014 11:10:41 GMT Subject: Time zones and why they change so damned often References: Message-ID: On Sat, 11 Jan 2014 07:52:36 +0000, Bob Martin wrote: >>>>we dont have "Daylight saving time" we switch between GMT (Greenwich >>>>Mean Time) and BST (British Summer Time) at some point in the past we >>>>have also used DST (Double Summer Time). >>> >>> British Summer Time *is* Daylight Saving Time. >> >>My point is in the UK we have never refered to it as Daylight saving >>Time that is an Americanism :-) > > Sorry, but you are wrong again! > Just Google it. Wikipedia Daylight saving time (DST)?usually referred to as Summer Time in the United Kingdom I had never heard the term daylight savings untill windows added it as a tick box. -- And I alone am returned to wag the tail. From alister.ware at ntlworld.com Sat Jan 11 06:14:46 2014 From: alister.ware at ntlworld.com (Alister) Date: Sat, 11 Jan 2014 11:14:46 GMT Subject: Time zones and why they change so damned often References: Message-ID: On Sat, 11 Jan 2014 11:10:41 +0000, Alister wrote: > On Sat, 11 Jan 2014 07:52:36 +0000, Bob Martin wrote: >>>>>we dont have "Daylight saving time" we switch between GMT (Greenwich >>>>>Mean Time) and BST (British Summer Time) at some point in the past we >>>>>have also used DST (Double Summer Time). >>>> >>>> British Summer Time *is* Daylight Saving Time. >>> >>>My point is in the UK we have never refered to it as Daylight saving >>>Time that is an Americanism :-) >> >> Sorry, but you are wrong again! >> Just Google it. > > Wikipedia > > Daylight saving time (DST)?usually referred to as Summer Time in the > United Kingdom > > I had never heard the term daylight savings untill windows added it as a > tick box. or a more Authoritave souce https://www.gov.uk/when-do-the-clocks-change The period when the clocks are 1 hour ahead is called British Summer Time (BST). -- The earth is like a tiny grain of sand, only much, much heavier. From alister.ware at ntlworld.com Sat Jan 11 06:14:16 2014 From: alister.ware at ntlworld.com (Alister) Date: Sat, 11 Jan 2014 11:14:16 GMT Subject: Time zones and why they change so damned often References: Message-ID: On Sat, 11 Jan 2014 11:10:41 +0000, Alister wrote: > On Sat, 11 Jan 2014 07:52:36 +0000, Bob Martin wrote: >>>>>we dont have "Daylight saving time" we switch between GMT (Greenwich >>>>>Mean Time) and BST (British Summer Time) at some point in the past we >>>>>have also used DST (Double Summer Time). >>>> >>>> British Summer Time *is* Daylight Saving Time. >>> >>>My point is in the UK we have never refered to it as Daylight saving >>>Time that is an Americanism :-) >> >> Sorry, but you are wrong again! >> Just Google it. > > Wikipedia > > Daylight saving time (DST)?usually referred to as Summer Time in the > United Kingdom > > I had never heard the term daylight savings untill windows added it as a > tick box. or a more Authoritave souce https://www.gov.uk/when-do-the-clocks-change The period when the clocks are 1 hour ahead is called British Summer Time (BST). -- The earth is like a tiny grain of sand, only much, much heavier. From davea at davea.name Sat Jan 11 08:06:41 2014 From: davea at davea.name (Dave Angel) Date: Sat, 11 Jan 2014 08:06:41 -0500 (EST) Subject: python first project References: Message-ID: ngangsia akumbo Wrote in message: > Hi everyone, > > I have been around this group for some time and i saw that we have very helpful people here. > Welcome to the group, and to Python. > i have been learning python just for about 5 months now and i have been given a task to do. This will be a leap into the programming industry for me. > Is this a class assignment, a book assignment, a self assignment, or is it to be used by a real business, perhaps to replace manual methods? > > i am programming a system that will be giving details about finance, purchase(bills pending bills and paid bill), employees record and salary details, warehouse records. > > That is just all i intend to do this all on one GUI application window But your code so far is all for a terminal window. Nothing wrong with that, but if the professor is expecting GUI, that's different. A GUI might be tkinter or qt or Wxpython or ... > and to make it to be able to keep records for all the transaction which has been done inputted. A key point. So you need persistence. You're going to need to write data to a file, and reread it next time the program is run. The file might be a bunch of text lines, or it might be a database. And it might belong to this program or be shared, even across multiple machines. > > I have started programming it , but i still feel there are a lot of things i miss out. I second the recommendation for version 3. And I suggest that if this is a business assignment, it's a lot harder than you think. For example, handling dollars and cents with floats is usually a mistake. > > Please i need some support from any honest person, please and also how to guide me complete this. > > > > -- DaveA nr ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From lightaiyee at gmail.com Sat Jan 11 09:26:33 2014 From: lightaiyee at gmail.com (Sam) Date: Sat, 11 Jan 2014 06:26:33 -0800 (PST) Subject: How to get Mac address of ethernet port? Message-ID: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> I would like to use python to retrieve the mac address of the ethernet port. Can this be done? Thank you. From andriy.kornatskyy at live.com Sat Jan 11 09:35:19 2014 From: andriy.kornatskyy at live.com (Andriy Kornatskyy) Date: Sat, 11 Jan 2014 16:35:19 +0200 Subject: How to get Mac address of ethernet port? In-Reply-To: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: Sam, How about this? from uuid import getnode as get_mac '%012x' % get_mac() Thanks. Andriy Kornatskyy On Jan 11, 2014, at 4:26 PM, Sam wrote: > I would like to use python to retrieve the mac address of the ethernet port. Can this be done? Thank you. > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Sat Jan 11 09:38:40 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 01:38:40 +1100 Subject: How to get Mac address of ethernet port? In-Reply-To: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 1:26 AM, Sam wrote: > I would like to use python to retrieve the mac address of the ethernet port. Can this be done? Thank you. > Did you try searching the web for 'python retrieve mac address' or similar? There are several options offered. ChrisA From rosuav at gmail.com Sat Jan 11 09:52:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 01:52:12 +1100 Subject: How to get Mac address of ethernet port? In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 1:35 AM, Andriy Kornatskyy wrote: > from uuid import getnode as get_mac > '%012x' % get_mac() > Code golf! Put colons in that, with as little code as possible. # Way too verbose. import uuid l=list("%012x"%uuid.getnode()) l[10:10]=l[8:8]=l[6:6]=l[4:4]=l[2:2]=':' mac = ''.join(l) # Shorter but not short enough import uuid s="%012x"%uuid.getnode() mac = ':'.join(s[i*2:i*2+2] for i in range(6)) :) ChrisA From skip at pobox.com Sat Jan 11 10:03:04 2014 From: skip at pobox.com (Skip Montanaro) Date: Sat, 11 Jan 2014 09:03:04 -0600 Subject: How to get Mac address of ethernet port? In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: This is slightly longer than ChrisA's second solution: >>> import uuid >>> s = "%12x" % uuid.getnode() >>> ":".join(x+y for x, y in zip(s[::2], s[1::2])) '18:03:73:cb:2a:ee' Skip From james.harris.1 at gmail.com Sat Jan 11 10:45:44 2014 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 11 Jan 2014 15:45:44 -0000 Subject: With this artifact, everyone can easily invent new languages References: <629488f0-0516-492e-8dcf-1fea9a53e383@googlegroups.com> Message-ID: "Simeon Chaos" wrote in message news:d7878ab7-2f6d-4bc4-9a28-3ea567bdfce8 at googlegroups.com... > Thank you, James. I didn't know this group before. I'll post this message > there. You're welcome. It can be hard to find apt groups on Usenet because there are so many. I don't think there was ever a group for programming language design (or invention) so that one which was about miscellaneous languages picked up the topic. By the way, you could use comp.lang.misc simply for an announcement such as you posted here. If you want to start a discussion about an aspect of your design, however, the best option is to post a specific topic. James From roy at panix.com Sat Jan 11 10:45:53 2014 From: roy at panix.com (Roy Smith) Date: Sat, 11 Jan 2014 10:45:53 -0500 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: In article <18b67e59-39d1-41e2-8977-b1c449b132e7 at googlegroups.com>, pintreo mardi wrote: > Hi, I've just begun to learn programming, I have an open question for the > group: > Is the Python language an all in one computer language which could replace C, > C++, Java etc.. I only ask becuase I am starting off with python and I want > to learn everything in basic and advanced programming with python itself...So > any advice and suggestions would be more than welcome. > Thanks!! That's a really hard question to answer, or at least to answer well. At a theoretical level, when you ask, "Is Python equivalent to C, C++ and Java", the answer is "yes". In computer science, programming languages are classified by whether they are "Turing Complete" or not (google that for more info). In theory, any Turing Complete language is capable of writing all programs which can be written in any other Turing Complete language. All of the languages you mention are Turing Complete, so, theoretically, they are all equivalent. But, at a more practical level, some languages are easier to learn, some run faster, some are more portable, some are more convenient to use, etc. If I had to rank the languages you mention by a few categories, I'd say something like: Python: Easiest to learn (and use), slowest execution speed. C: Pretty easy to learn, but difficult to write large projects in, fastest execution speed. C++: Hardest to learn, hard to use, speed close to C. Java: Somewhere in-between Python and C++ on all counts. All of these are currently in widespread commercial use today, so you can't go too far wrong staring out with any of them. The TIOBE people have been tracking programming language popularity for a long time (http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html), so that's a good place to get some vague idea of what's hot and what's not. One thing to be aware of is that some programming domains require a specific language. If you want to do iOS, you need Objective C. For Android, Java. Web front-end programming, Javascript. No getting away from those. In the server environment, it's a much more wide-open field. People write web servers, for example, in Python, Ruby, Scala, Javascript, PHP, Java, and probably a host of other languages. This has already turned into a longer essay than I intended, but there's just one thing I wanted to add. Whatever you pick to learn first, realize that if you embark on a life-long career in programming, it won't be your last. Languages come and go. I've done serious work in (in vaguely chronological order) Fortran, C, Python, Tcl, Perl, C++, and PHP. So, pick one, spend a year getting really good at it, then pick another language, preferably one that's very different, and learn that too. Repeat every so often :-) From james.harris.1 at gmail.com Sat Jan 11 10:54:12 2014 From: james.harris.1 at gmail.com (James Harris) Date: Sat, 11 Jan 2014 15:54:12 -0000 Subject: How to get Mac address of ethernet port? References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: "Andriy Kornatskyy" wrote in message news:mailman.5329.1389450993.18130.python-list at python.org... > Sam, > > How about this? > > from uuid import getnode as get_mac > '%012x' % get_mac() AIUI that will return a mac address even if there isn't one. That may or may not suit the OP. To the OP, depending on what you want to do remember that a machine can have more than one mac address and that a mac address can differ from the burned-in address (BIA) as some cards allow the effective mac address to be changed in software. So it's possible that two machines could show the same mac address. James From ngangsia at gmail.com Sat Jan 11 11:28:07 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 11 Jan 2014 08:28:07 -0800 (PST) Subject: python first project In-Reply-To: References: Message-ID: On Saturday, January 11, 2014 2:06:41 PM UTC+1, Dave Angel wrote: > ngangsia akumbo Wrote in message: > > > Hi everyone, > > > > > > I have been around this group for some time and i saw that we have very helpful people here. > > > > > Welcome to the group, and to Python. > > > > > i have been learning python just for about 5 months now and i have been given a task to do. This will be a leap into the programming industry for me. > > > > > Is this a class assignment, a book assignment, a self assignment, This will be use for real business. The ceo in person is willing to cut the office task. I am from cameroon west africa. > > or is it to be used by a real business, perhaps to replace > > manual methods? > > > > > > > > i am programming a system that will be giving details about finance, purchase(bills pending bills and paid bill), employees record and salary details, warehouse records. > > > > > > That is just all i intend to do this all on one GUI application window > > > > But your code so far is all for a terminal window. Nothing wrong > > with that, but if the professor is expecting GUI, that's > > different. A GUI might be tkinter or qt or Wxpython or > > ... > > > > > and to make it to be able to keep records for all the transaction which has been done inputted. > > > > A key point. So you need persistence. You're going to need to > > write data to a file, and reread it next time the program is > > run. The file might be a bunch of text lines, or it might be a > > database. And it might belong to this program or be shared, even > > across multiple machines. when i talk of record i mean details of all what will be inputed by the employees should be kept as a record. > > > > > > > > I have started programming it , but i still feel there are a lot of things i miss out. > > > > I second the recommendation for version 3. And I suggest that if > > this is a business assignment, it's a lot harder than you think. > > For example, handling dollars and cents with floats is usually a > > mistake. > How hard is it? Please i need your support > > > > > Please i need some support from any honest person, please and also how to guide me complete this. > > > > > > > > > > > > > > > > > > > > -- > > DaveA nr > > > > > > > > ----Android NewsGroup Reader---- > > http://www.piaohong.tk/newsgroup From denismfmcmahon at gmail.com Sat Jan 11 11:28:49 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 11 Jan 2014 16:28:49 +0000 (UTC) Subject: python first project References: Message-ID: On Fri, 10 Jan 2014 20:18:32 -0800, ngangsia akumbo wrote: > i have been learning python just for about 5 months now and i have been > given a task to do. This will be a leap into the programming industry > for me. > > i am programming a system that will be giving details about finance, > purchase(bills pending bills and paid bill), employees record and salary > details, warehouse records. It sounds as if your project has many aspects to it which may require you to understand and implement many different computing tasks. For example: You need to either analyse the data records that are required and produce a suitable database schema, or you need to work with an existing database schema. This may require some competence in developing database schemas, and will almost certainly require some sql knowledge in the chosen database (not all sqls are equal). You also need to develop a user interface. First of all you ned to consider who will access the user interface, and how? Mobile devices, desktop computers, both? Do you want os specific (eg ios, android) apps for mobile devices, or will you run in a mobile browser window? Will the application run on a web server, or locally on a single machine? Or will several gui clients connect to a single server host? In the latter case, you'll need to develop communication protocols (using a webapp removes some of this workload, but is a compromise that may require that you need other competences, possibly including but not limited to html, javascript and css). The most important phase of any project is the requirements capture, for if you do not capture all the requirements of all the users, you will not deliver the project that they want. Users are not just the people who sit in front of the screens, they may also be people who will want statistical reports based on the database, but who never expect to actually touch a computer themselves - they have secretaries for that sort of thing. However, if your system can't produce the report that the CEO or CFO wants at the end of each month / quarter / year, then it will be labelled as crap, even if no-one told you as the system designer that this report was required! So, first of all, you need to go and talk to everyone in the company that will use this system and obtain from them details of what they expect the system to do, what data they expect to input, and what data they expect to receive as outputs from it. Once you understand this, you may be in a position to start defining the database schema, and only then are you ready to think about the code that will put data into, and get it from, the database. -- Denis McMahon, denismfmcmahon at gmail.com From roy at panix.com Sat Jan 11 11:29:06 2014 From: roy at panix.com (Roy Smith) Date: Sat, 11 Jan 2014 11:29:06 -0500 Subject: How to get Mac address of ethernet port? References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: In article , "James Harris" wrote: > "Andriy Kornatskyy" wrote in message > news:mailman.5329.1389450993.18130.python-list at python.org... > > Sam, > > > > How about this? > > > > from uuid import getnode as get_mac > > '%012x' % get_mac() > > AIUI that will return a mac address even if there isn't one. That may or may > not suit the OP. Specifically, it says, "If all attempts to obtain the hardware address fail, we choose a random 48-bit number with its eighth bit set to 1 as recommended in RFC 4122". Keep in mind that 4122 is all about generating globally unique strings. The only reason it even talks about MAC addresses is in the context of one possible way to generate uuids. If your goal is to get the MAC address for some sort of networking reason, you need to bear in mind what James says below: > To the OP, depending on what you want to do remember that a machine can have > more than one mac address and that a mac address can differ from the > burned-in address (BIA) as some cards allow the effective mac address to be > changed in software. So it's possible that two machines could show the same > mac address. If you don't believe that two machines can have the same MAC address, look up Hot Standby Router Protocol. And if you don't believe a machine can ignore the BIA and assign a new MAC address in software, look up Decnet . From ngangsia at gmail.com Sat Jan 11 11:31:14 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 11 Jan 2014 08:31:14 -0800 (PST) Subject: python first project In-Reply-To: References: Message-ID: <5e0109c4-0d50-4c1d-9dd1-4907fa999e33@googlegroups.com> On Saturday, January 11, 2014 5:29:39 AM UTC+1, Chris Angelico wrote: > On Sat, Jan 11, 2014 at 3:18 PM, ngangsia akumbo wrote: > > > purch_price = input("Please enter the price for purchase made: ") > > > purch_p = raw_input("Please enter the reason of this purchase made: ") > > > > Never use input() in a Python 2 program... always use raw_input() > > instead. You're mostly right, but you have a few cases where you're > > using input(). Probably what you want is int(input()) or > > float(input()). > > > > Incidentally, is there a strong reason for using Python 2 for this? If > > not, I'd recommend moving immediately to Python 3, as there are an > > increasing number of advantages. Unless something actually binds you > > to Py2, save yourself the trouble of shifting in a few years' time and > > just use Py3 now. > > > > ChrisA Thanks for the reply From invalid at invalid.invalid Sat Jan 11 11:34:11 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 11 Jan 2014 16:34:11 +0000 (UTC) Subject: L[:] References: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> Message-ID: On 2014-01-10, Terry Reedy wrote: > On 1/10/2014 12:38 PM, Albert-Jan Roskam wrote: >> In Python Cookbook, one of the authors (I forgot who) consistently used the "L[:]" idiom like below. If the second line simply starts with "L =" (so no "[:]") only the name "L" would be rebound, not the underlying object. That was the author?? explanation as far as I can remember. I do not get that. Why is the "L[:]" idiom more memory-efficient here? How could the increased efficiency be demonstrated? >> >> #Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 >>>>> L = [x ** 2 for x in range(10)] >>>>> L[:] = ["foo_" + str(x) for x in L] > > Unless L is aliased, this is silly code. And if L _is_ aliaised, it's probably trying to be too clever and needs to be fixed. -- Grant From torriem at gmail.com Sat Jan 11 11:34:35 2014 From: torriem at gmail.com (Michael Torrie) Date: Sat, 11 Jan 2014 09:34:35 -0700 Subject: How to get Mac address of ethernet port? In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: <52D1729B.7050906@gmail.com> On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote: > Sam, > > How about this? > > from uuid import getnode as get_mac > '%012x' % get_mac() This seems to work if you have only one ethernet adapter. Most computers have two (wired and wireless) adapters. Getting a mac address is platform-specific, and the OP has not specified what OS he is using. On Windows I imagine you'd have to access the WMI subsystem in Windows. On Linux you could access the /sys/devices/virtual/net/ file in the sysfs filesystem. I'm sure there are other ways. No idea on OS X. From breamoreboy at yahoo.co.uk Sat Jan 11 11:40:40 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 11 Jan 2014 16:40:40 +0000 Subject: python first project In-Reply-To: <5e0109c4-0d50-4c1d-9dd1-4907fa999e33@googlegroups.com> References: <5e0109c4-0d50-4c1d-9dd1-4907fa999e33@googlegroups.com> Message-ID: On 11/01/2014 16:31, ngangsia akumbo wrote: > On Saturday, January 11, 2014 5:29:39 AM UTC+1, Chris Angelico wrote: >> >> Incidentally, is there a strong reason for using Python 2 for this? If >> >> not, I'd recommend moving immediately to Python 3, as there are an >> >> increasing number of advantages. Unless something actually binds you >> >> to Py2, save yourself the trouble of shifting in a few years' time and >> >> just use Py3 now. >> >> >> >> ChrisA > > Thanks for the reply > I'd like to wish you the best of luck with your project as you've chosen the second best programming language in the world :) However if you wish to ask more questions would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ngangsia at gmail.com Sat Jan 11 12:55:57 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 11 Jan 2014 09:55:57 -0800 (PST) Subject: python first project In-Reply-To: References: Message-ID: On Saturday, January 11, 2014 6:17:13 PM UTC+1, Dennis Lee Bieber wrote: On Fri, 10 Jan 2014 20:18:32 -0800 (PST), ngangsia akumbo > Do you have a requirements or use-case documentation, or even a manual paper system which you would be "duplicating" on the computer? This document should provide the information what/how the system should operate (use-cases will be narratives showing how a user would interact with the system, with a use-case for each potential operation [add new client, add billing, correct errors, produce reports]). I have a paper with the instructions that was given to me, these guys just want something very simple. The CEO in concern want that every day he get in to the office , it does not matter the time. He should be able to see a record of all the transaction for that day from his desktop > How familiar are you with double-entry bookkeeping (accounts receivable, etc. i am not very familiar with that > or is this just client billing application which may or may not feed into the main company accounting system)? Tax laws? yeah just a client billing app >(Or is "salary details" really just the human resources record of promotions/pay raises, and NOT actual payroll production). Just salary, employee record, etc > Are you familiar with relational database design and normalization? Not very familiar with that, but if i have the right info i can normalize in it > While an object-relational mapper [ORM] may take out the need to know SQL, Yes i have some knowledge of sql > they don't help you design efficient/usable databases. Or is their an existing system/database you have to interface with. What i need to do is simple, design an app for employees, finance sector, purchase, billing, bookkeeping etc. Ok there is not IT infrastructure in this firm, they have a group of workers just doing the manual input of data. so the ceo wants this data to interact with a program that can keep track of what is going in the company. > You have three separate applications defined: stock/warehouse, human resource/payroll, and billing/accounting. You probably do not want a single GUI application for this (the people updating warehouse records should have no access to employee/salary/payroll, nor to the billing system). Thanks very much for this brilliant idea > >I am also looking for guides and sources which can help me complete it. > > Text books on accounting principles, relational database design concepts, system analysis (if there are no requirements/use-cases) which may cross over with Object-Oriented Analysis (Object-Oriented Design would come in AFTER the system has been analyzed; it is a bit closer to the programming level than requirements). I did not fully understand this paragraph please > There is no persistence between runs (that is, no tracking of information from one run to another). Your "financial sector" basically requires the user to already know what their balance is and is just telling them if it is positive or negative. No ability to save a balance and later have them add or subtract an amount from it. Thanks for this point Richard From jaiprakashsingh213 at gmail.com Sat Jan 11 13:16:31 2014 From: jaiprakashsingh213 at gmail.com (Jai) Date: Sat, 11 Jan 2014 10:16:31 -0800 (PST) Subject: python querry on firebug extention Message-ID: <9386256d-74b8-428b-a1f1-9024549e299e@googlegroups.com> hello i am working on selenium module of python, i know how to make extension of firebug with selenium, but i want to know how to use firebug extension with request module / mechanize . i search a lot but unable to find it , please help . technique similar like :- from selenium import webdriver fp = webdriver.FirefoxProfile() fp.add_extension(extension='firebug-1.8.4.xpi') fp.set_preference("extensions.firebug.currentVersion", "1.8.4") #Avoid startup screen browser = webdriver.Firefox(firefox_profile=fp) From feliphil at gmx.net Sat Jan 11 13:34:44 2014 From: feliphil at gmx.net (Wolfgang Keller) Date: Sat, 11 Jan 2014 19:34:44 +0100 Subject: python first project References: Message-ID: <20140111193444.418b1f6121cfc414b80f0be4@gmx.net> > i am programming a system that will be giving details about finance, > purchase(bills pending bills and paid bill), employees record and > salary details, warehouse records. > > That is just all i intend to do this all on one GUI application > window and to make it to be able to keep records for all the > transaction which has been done inputted. If "keeping records" implies significant amounts of data, then this is a typical case of a database application. There are a couple of Python frameworks for this kind of application: using wxPython: Dabo http://www.dabodev.com (already mentioned) Defis http://sourceforge.net/projects/defis/ (Russian only) GNUe http://www.gnuenterprise.org/ using PyQt: Pypapi https://pypi.python.org/pypi/PyPaPi/0.8 Camelot http://www.python-camelot.com/ Qtalchemy http://www.qtalchemy.org/ Thyme http://clocksoft.co.uk/downloads/ Kexi http://www.kexi-project.org/ using PyGTK: SQLkit http://sqlkit.argolinux.org/ Kiwi http://www.async.com.br/projects/kiwi/ Glom http://www.glom.org Sincerely, Wolfgang From rosuav at gmail.com Sat Jan 11 16:40:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 08:40:01 +1100 Subject: How to get Mac address of ethernet port? In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 3:29 AM, Roy Smith wrote: > If you don't believe that two machines can have the same MAC address, > look up Hot Standby Router Protocol. And if you don't believe a machine > can ignore the BIA and assign a new MAC address in software, look up > Decnet . Most people shouldn't have to worry about MAC address duplication/collision on the same subnet (I used MACs as a means of guaranteeing uniqueness among a pool of application servers, for instance), but MAC switching in software can occur in a typical home internet connection scenario. We had a connection set up a few years ago where the ISP tech recorded the source MAC into the far end, and only that MAC would work - so when I stuck in a different router, I needed to switch it to the old MAC before it could establish a connection. Stupid? Yes. Unusual? I hope so, but still more likely than coming across DECnet in a typical home! ChrisA From breamoreboy at yahoo.co.uk Sat Jan 11 16:51:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 11 Jan 2014 21:51:53 +0000 Subject: Porting mailing list underused? In-Reply-To: References: Message-ID: On 10/01/2014 21:31, Mark Lawrence wrote: > On 10/01/2014 20:38, Skip Montanaro wrote: >>> Anyone in the >>> know who can explain this phenomenon? >> >> I don't think I can explain it authoritatively, but I can hazard a >> guess. Skimming the archives sorted by author, it looks like most/all >> the correspondents are Python core developers. That leads me to >> believe this was a list created for the core Python developers to >> discuss issues related to porting tools such as 2to3 or six. I doubt >> it was intended for Python programmers to get help porting their own >> code. From the Python core development perspective, I think automated >> porting tools are likely pretty mature at this point and don't warrant >> a lot of discussion. >> >> Skip >> > > If the dumbo OP had remembered to say that > https://mail.python.org/mailman/listinfo/python-porting states rather > vaguely "This list is to contain discussion of porting Python code > between versions, mainly from Python 2.x to 3.x." it might have helped > garner more answers. Still, if we leave the list open for long enough > we'll all be able to discuss porting python 2.x to python 4.x :) > I've now found this https://mail.python.org/pipermail/python-dev/2008-December/083951.html QUOTE It is a public mailing list open to everyone. We expect active participation of many people porting their libraries/programs, and hope that the list can be a help to all wanting to go this (not always smooth :-) way. ENDQUOTE Strikes me that if more people had participated, or maybe even known about it, we currently wouldn't be on the edge of WWIII regarding PEP 460. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ethan at stoneleaf.us Sat Jan 11 16:59:29 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 11 Jan 2014 13:59:29 -0800 Subject: Porting mailing list underused? In-Reply-To: References: Message-ID: <52D1BEC1.6090001@stoneleaf.us> On 01/11/2014 01:51 PM, Mark Lawrence wrote: > > I've now found this https://mail.python.org/pipermail/python-dev/2008-December/083951.html > > QUOTE > It is a public mailing list open to everyone. We expect active participation of many people porting their > libraries/programs, and hope that the list can be a help to all wanting to go this (not always smooth :-) way. > ENDQUOTE Thanks for finding this mailing list. I have subscribed to it. :) -- ~Ethan~ From roy at panix.com Sat Jan 11 16:55:53 2014 From: roy at panix.com (Roy Smith) Date: Sat, 11 Jan 2014 16:55:53 -0500 Subject: How to get Mac address of ethernet port? References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > We had a connection set up a few years > ago where the ISP tech recorded the source MAC into the far end, and > only that MAC would work - so when I stuck in a different router, I > needed to switch it to the old MAC before it could establish a > connection. Stupid? Yes. Unusual? I hope so Actually, I think it's pretty common. I had exactly the same problem a few years ago. My DSL router fried itself. I got a new one and it was easier to make it fake out the old router's MAC than to get my carrier to update their head end configuration[1]. [1] Roy's law of dealing with service providers. Anything you can do yourself is easier than interfacing with tech support. From drsalists at gmail.com Sat Jan 11 17:04:05 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 11 Jan 2014 14:04:05 -0800 Subject: setup.py issue - some files are included as intended, but one is not Message-ID: Hi folks. I have a setup.py problem that's driving me nuts. I have a treap.py file that tries to "import * from pyx_treap.so", and failing that, it'll "import * from py_treap.py" (sans extensions of course). Naturally, all 3 of these should be included - although in the case of pyx_treap.so, it probably should be a .c that's included. It is also intended to include nest.py, which has a simple form. Well, treap.py, nest.py and pyx_treap.c are included fine, but I can't seem to get py_treap.py to be included for some reason. I get no errors during "python setup.py sdist upload", but upon "python $(which pip) install treap", I get: $ sudo /usr/bin/python $(which pip) install treap Downloading/unpacking treap Running setup.py egg_info for package treap file py_treap.py (for module py_treap) not found Installing collected packages: treap Running setup.py install for treap file py_treap.py (for module py_treap) not found file py_treap.py (for module py_treap) not found file py_treap.py (for module py_treap) not found file py_treap.py (for module py_treap) not found Successfully installed treap Cleaning up... And it's not successfully installed - py_treap.py is missing. The pyx code does its job, so the problem is masked, other than the messages above, and the absence of py_treap.py from /usr/local/lib/python2.7/dist-packages I can clearly see py_treap.py in ./dist/treap-1.35.tar.gz - it's at least getting packaged up that much. It's not listed in /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/SOURCES.txt , but I can see it in /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/top_level.txt . My setup.py is at: http://stromberg.dnsalias.org/svn/treap/trunk/setup.py I've tried that setup.py and several variations on that theme, but none seem to include py_treap.py . Please make some suggestions? How can I get py_treap.py included in the pip install? Thanks! From rosuav at gmail.com Sat Jan 11 17:15:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 09:15:30 +1100 Subject: python first project In-Reply-To: References: Message-ID: On Sun, Jan 12, 2014 at 9:10 AM, Dennis Lee Bieber wrote: > Producing fancy reports for the CEO may be the last thing you > implement, as it relies upon having a stable database design, business > logic, and data entry. >From the sound of things, it might be the ONLY thing to implement, though, if the answer to your previous question is "Yes" (that is, if everything's already in a big fat database). Otherwise, the OP's going to be replicating stuff that businesses pay good money for - a full-on accounting and warehousing system. ChrisA From deanpodolsky at gmail.com Sat Jan 11 17:53:00 2014 From: deanpodolsky at gmail.com (DPod) Date: Sat, 11 Jan 2014 14:53:00 -0800 (PST) Subject: record pixel value with Python script Message-ID: A scripting newbie question... I'd like to write a Python script for ArcGIS 10.x (ArcPy or Python 2.6.5) that would record the pixel value for all pixels in a raster. Furthermore, I'd like to only record a given value once in the results. For example, if there are 23 values of 180 overall, only record one instance of that value. The raster in question is 4-band (6017 x 7715 pixels) so the results would have to include values for all pixels in each band, recorded separately by band. Ideally I'd like to write to an Excel file or at least a .csv file. Any help and examples would be greatly appreciated. From maxerickson at gmail.com Sat Jan 11 18:35:13 2014 From: maxerickson at gmail.com (maxerickson at gmail.com) Date: Sat, 11 Jan 2014 15:35:13 -0800 (PST) Subject: record pixel value with Python script In-Reply-To: References: Message-ID: On Saturday, January 11, 2014 5:53:00 PM UTC-5, DPod wrote: > > I'd like to write a Python script for ArcGIS 10.x (ArcPy or Python 2.6.5) >that would record the pixel value for all pixels in a raster. Furthermore, I'd >like to only record a given value once in the results. For example, if there >are 23 values of 180 overall, only record one instance of that value. > > The raster in question is 4-band (6017 x 7715 pixels) so the results would >have to include values for all pixels in each band, recorded separately by >band. Ideally I'd like to write to an Excel file or at least a .csv file. > Can you install libraries? Fetching the pixel values of an individual band is straightforward in PIL (and the fork Pillow), something like this: from PIL import Image im=Image.open("blah.jpg") red=im.getdata(0) If you can't install things you would need to figure out if ArcGIS has an API for fetching a band. The filtering step is easy, you just want the set of values: set(red) Max From deanpodolsky at gmail.com Sat Jan 11 18:40:53 2014 From: deanpodolsky at gmail.com (DPod) Date: Sat, 11 Jan 2014 15:40:53 -0800 (PST) Subject: record pixel value with Python script In-Reply-To: References: Message-ID: On Saturday, January 11, 2014 3:35:13 PM UTC-8, maxer... at gmail.com wrote: > On Saturday, January 11, 2014 5:53:00 PM UTC-5, DPod wrote: > > > > > > > > I'd like to write a Python script for ArcGIS 10.x (ArcPy or Python 2.6.5) >that would record the pixel value for all pixels in a raster. Furthermore, I'd >like to only record a given value once in the results. For example, if there >are 23 values of 180 overall, only record one instance of that value. > > > > > > The raster in question is 4-band (6017 x 7715 pixels) so the results would >have to include values for all pixels in each band, recorded separately by >band. Ideally I'd like to write to an Excel file or at least a .csv file. > > > > > > > Can you install libraries? > > > > Fetching the pixel values of an individual band is straightforward in PIL (and the fork Pillow), something like this: > > > > from PIL import Image > > im=Image.open("blah.jpg") > > red=im.getdata(0) > > > > If you can't install things you would need to figure out if ArcGIS has an API for fetching a band. > > > > The filtering step is easy, you just want the set of values: > > > > set(red) > > > > > > Max No, installing libraries doesn't seem to be an option From davea at davea.name Sat Jan 11 19:15:40 2014 From: davea at davea.name (Dave Angel) Date: Sat, 11 Jan 2014 19:15:40 -0500 (EST) Subject: python first project References: Message-ID: ngangsia akumbo Wrote in message: > On Saturday, January 11, 2014 2:06:41 PM UTC+1, Dave Angel wrote: >> >> I second the recommendation for version 3. And I suggest that if >> >> this is a business assignment, it's a lot harder than you think. >> >> For example, handling dollars and cents with floats is usually a >> >> mistake. >> > > How hard is it? Please i need your support >> > >> Not sure what units of measurement you'd like. How about ten thousand lines of code? -- DaveA nr ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From davea at davea.name Sat Jan 11 19:37:40 2014 From: davea at davea.name (Dave Angel) Date: Sat, 11 Jan 2014 19:37:40 -0500 (EST) Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: pintreo mardi Wrote in message: > Hi, I've just begun to learn programming, I have an open question for the group: > Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. > Thanks!! > As others have said you can do nearly anything in any of those languages. But you can expect to learn and use many over time. I've used about 35 professionally, and a few more for fun. I've done substantial work in machine language and also in microcode. Sometimes I had to write the assembler, simulator, and debugger while the actual machine was being designed. Was python an appropriate language to write add and subtract in? Nope. -- DaveA nr ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From ethan at stoneleaf.us Sat Jan 11 19:24:46 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 11 Jan 2014 16:24:46 -0800 Subject: Python 3 __bytes__ method Message-ID: <52D1E0CE.5030906@stoneleaf.us> Python 3 has a new method, __bytes__. The docs say: Called by bytes() to compute a byte-string representation of an object. This should return a bytes object. I must admit I'm not entirely clear how this should be used. Is anyone using this now? If so, how? -- ~Ethan~ From ethan at stoneleaf.us Sat Jan 11 19:56:16 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 11 Jan 2014 16:56:16 -0800 Subject: Python 3 __bytes__ method In-Reply-To: References: <52D1E0CE.5030906@stoneleaf.us> Message-ID: <52D1E830.8070305@stoneleaf.us> On 01/11/2014 04:53 PM, Daniel da Silva wrote: > > Where did you read this? I can't find any documentation about __bytes__ on google. http://docs.python.org/3.3/reference/datamodel.html?highlight=__bytes__#object.__bytes__ -- ~Ethan~ From rosuav at gmail.com Sat Jan 11 17:08:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 09:08:20 +1100 Subject: How to get Mac address of ethernet port? In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 8:55 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> We had a connection set up a few years >> ago where the ISP tech recorded the source MAC into the far end, and >> only that MAC would work - so when I stuck in a different router, I >> needed to switch it to the old MAC before it could establish a >> connection. Stupid? Yes. Unusual? I hope so > > Actually, I think it's pretty common. Sad. > I had exactly the same problem a few years ago. My DSL router fried > itself. I got a new one and it was easier to make it fake out the old > router's MAC than to get my carrier to update their head end > configuration[1]. > > [1] Roy's law of dealing with service providers. Anything you can do > yourself is easier than interfacing with tech support. Unless you expect that doing it yourself will take upwards of an hour, don't even bother talking to tech support, at least with the ISPs I know. There's only *ONE* time when I got results quicker than that (or, say, half an hour absolute minimum): with iiNet, I rang their support and got dropped into a classic IVR system, and one of the options was "Press whatever to get the basic setup information for your connection". A couple more prompts and I was given a prerecorded pile of numbers and settings, one of which was the exact one I was having trouble with. With any other kind of business, this sort of thing belongs on the web site, but for obvious reasons that's less useful for an ISP :) ChrisA From var.mail.daniel at gmail.com Sat Jan 11 19:53:06 2014 From: var.mail.daniel at gmail.com (Daniel da Silva) Date: Sat, 11 Jan 2014 19:53:06 -0500 Subject: Python 3 __bytes__ method In-Reply-To: <52D1E0CE.5030906@stoneleaf.us> References: <52D1E0CE.5030906@stoneleaf.us> Message-ID: Where did you read this? I can't find any documentation about __bytes__ on google. Regards, Daniel On Sat, Jan 11, 2014 at 7:24 PM, Ethan Furman wrote: > Python 3 has a new method, __bytes__. The docs say: Called by bytes() to > compute a byte-string representation of an object. This should return a > bytes object. > > I must admit I'm not entirely clear how this should be used. Is anyone > using this now? If so, how? > > -- > ~Ethan~ > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From lightaiyee at gmail.com Sat Jan 11 20:25:08 2014 From: lightaiyee at gmail.com (Sam) Date: Sat, 11 Jan 2014 17:25:08 -0800 (PST) Subject: How to get Mac address of ethernet port? In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Message-ID: <0e20ca68-5643-40e6-adde-6bb929a4bb5d@googlegroups.com> On Sunday, January 12, 2014 12:34:35 AM UTC+8, Michael Torrie wrote: > On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote: > > > On Linux you could access the /sys/devices/virtual/net/ > > file in the sysfs filesystem. I'm sure there are other ways. > Thank you to everyone for the helpful answers. I am using Linux in this case. I think this is the direction I am looking for. Thanks! From lightaiyee at gmail.com Sat Jan 11 20:28:18 2014 From: lightaiyee at gmail.com (Sam) Date: Sat, 11 Jan 2014 17:28:18 -0800 (PST) Subject: Is it better to import python modules inside function or at the top? What are the pros and cons? Message-ID: I have python modules which are used only in specific functions and the functions are not called all the time. Is it better to import the function inside the function only or is it a better practice to always import all modules at the top of the script? If I import the module inside the function, will it cause a big performance hit because of the import module action that gets to be called every time the function is called? What are the pros and cons of each approach? From matej at ceplovi.cz Sat Jan 11 20:36:15 2014 From: matej at ceplovi.cz (Matěj Cepl) Date: Sun, 12 Jan 2014 02:36:15 +0100 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: <20140112013621.7F6ED4195F@wycliff.ceplovi.cz> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2014-01-11, 08:07 GMT, you wrote: > Hi, I've just begun to learn programming, I have an open question for the group: > Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. - From one side this answer is probably as meaningful as the one from the Alice in Wonderland (http://www.gutenberg.org/files/19033/19033-h/19033-h.htm, page 35): ?Why is a raven like a writing-desk?? These are just different programming languages each designed for different purpose. On the other hand what people said about Turing complete langauges is true as well. So, yes it is true that any Turing complete language you can write anything you wrote in another Turing complete language. It doesn?t mean however that it would be as easy or as efficient tool for doing so. Some languages are specialized for high-power low-level specialist programming of low-level stuff (e.g., almost all serious operating systems are written in C), some are better suited for writing enormous complicated projects consisting of thousands of modules (Java, C++, Ada), some are designed to be very easy to write (that doesn?t mean primitive) although the speed and processing power of the result may suffer a little bit (JavaScript, Python, Perl, Ruby). If you ask for the language to start to learn programming as such, then Python was oriiginally intended exactly for that purpose (fortunately, it was written so well, it is now used en masse for ?serious? large programming projects as well). FOr the list of resources take a look at https://wiki.python.org/moin/BeginnersGuide/NonProgrammers . Particularly, I?ve heard a lot of good things about ?How to Think Like a Computer Scientist?. You won?t hurt yourself if you start there. Best, Mat?j -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS0fGP4J/vJdlkhKwRAu6TAKCCdGP9b3z2M+NJlIY4HnqZFi+v3gCfYgE0 69QHLyfyG//dFhb9pcjdoNk= =y2k/ -----END PGP SIGNATURE----- From rosuav at gmail.com Sat Jan 11 20:48:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 12:48:10 +1100 Subject: Is it better to import python modules inside function or at the top? What are the pros and cons? In-Reply-To: References: Message-ID: On Sun, Jan 12, 2014 at 12:28 PM, Sam wrote: > I have python modules which are used only in specific functions and the functions are not called all the time. Is it better to import the function inside the function only or is it a better practice to always import all modules at the top of the script? If I import the module inside the function, will it cause a big performance hit because of the import module action that gets to be called every time the function is called? > > What are the pros and cons of each approach? Most of the work of importing is still going to be done only once (after that, the import just grabs a cached reference to the same module). It's normally clearer to import at the top of the module, especially if you have multiple functions calling on the same module, but there are two other concerns: 1) If the module can't be found, would you rather know as soon as your module is loaded, or is it better to load your module without it and then fail only when that function is called? 2) If the module takes a long time to load, would you rather pay that cost as soon as your module is loaded, or on the first use of the function that needs it? ChrisA From ned at nedbatchelder.com Sat Jan 11 20:49:02 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 11 Jan 2014 20:49:02 -0500 Subject: Is it better to import python modules inside function or at the top? What are the pros and cons? In-Reply-To: References: Message-ID: On 1/11/14 8:28 PM, Sam wrote: > I have python modules which are used only in specific functions and the functions are not called all the time. Is it better to import the function inside the function only or is it a better practice to always import all modules at the top of the script? If I import the module inside the function, will it cause a big performance hit because of the import module action that gets to be called every time the function is called? > > What are the pros and cons of each approach? > Unless there's a good reason, you should import all the modules at the top of the file. Reasons to import in a function: 1) if a function is only sometimes called, and the import is expensive. 2) if a function is only sometimes called, and needs a dependency that not all users of your package need. For example, your library has both Flask and Django helper functions, and only Django users call the Django function, etc. 3) if you have a circular import, though that can often be fixed in better ways. Note that the cost of imports is only incurred at the first import, so you don't have to worry about the import statement executing each time your function is called. After the first import, the cost is about the same as a dict lookup (very fast). -- Ned Batchelder, http://nedbatchelder.com From drsalists at gmail.com Sat Jan 11 21:43:03 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sat, 11 Jan 2014 18:43:03 -0800 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On Sat, Jan 11, 2014 at 12:07 AM, pintreo mardi wrote: > Hi, I've just begun to learn programming, I have an open question for the group: > Is the Python language an all in one computer language which could replace C, C++, Java etc.. I only ask becuase I am starting off with python and I want to learn everything in basic and advanced programming with python itself...So any advice and suggestions would be more than welcome. > Thanks!! As others have mentioned, they're all turing-complete. In other words, with an infinite memory and infinite coding patience, they can all solve the same problems. The main distinctions, at least to my mind, are: 1) Python tends to require fewer words to solve the same problems, but tends to be slow running. 2) C tends to be very fast running, but takes a lot of words to solve the same problems, and is prone to hard-to-fix memory errors 3) C++ and Java aren't that different in performance today, because of Java's good JIT. 4) Java's not great for systems programming (apparently can't detect symlink races for example), but C, C++ and sometimes Python are. Each language will tend to have API's (Application Programming Interfaces) that make some classes of problems easier or harder. API's are basically reusable code you can use to make your own problems quicker and easier. You probably wouldn't write an operating system kernel in Python - it'd be too slow. However, writing an application in Python might be a very good use of time. If Python proves too slow for a problem (which is uncommon), you can rewrite small portions in C to get good performance. Also, there is another implementation of Python called PyPy that's much faster than the reference implementation, which is known as CPython. C++ and Java cover similar kinds of programming - they're both object oriented C-like languages. However, C++ is more prone to memory errors than Java, and I'm told that C++ has many incompatible implementations of fundamental things like strings. For these reasons, I'd recommend Java over C++ for most things (except systems programming). C, C++ and Java are all statically, manifestly typed. Python is duck typed. These are fundamentally different approaches to program correctness. In C, C++ and Java, programmers tend to assume that if a program compiles, it's working. This is not a great assumption, but it isn't that far off the mark, either. Python on the other hand, will compile a lot more programs than those that work - for this reason, it's a very good idea to use automated tests with Python. Automated tests are a good idea with C, C++ and Java too, just not as crucial. HTH From ethan at stoneleaf.us Sat Jan 11 21:44:55 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 11 Jan 2014 18:44:55 -0800 Subject: Python 3 __bytes__ method In-Reply-To: References: <52D1E0CE.5030906@stoneleaf.us> <52D1E830.8070305@stoneleaf.us> Message-ID: <52D201A7.3050403@stoneleaf.us> On 01/11/2014 06:19 PM, Daniel da Silva wrote: > > One use case is: > Suppose you have existing function that accepts a /bytes/ object. If you subclass /bytes/ and want it to be guaranteed > to work with that function, you can override/__bytes__()/ to use the logistics of your subclass implementation. I don't think so, for two reasons: 1) bytes objects do not have a __bytes__ method, 2) if the function is expecting a bytes object, it is unlikely to call bytes() on it. -- ~Ethan~ From var.mail.daniel at gmail.com Sat Jan 11 21:19:01 2014 From: var.mail.daniel at gmail.com (Daniel da Silva) Date: Sat, 11 Jan 2014 21:19:01 -0500 Subject: Python 3 __bytes__ method In-Reply-To: <52D1E830.8070305@stoneleaf.us> References: <52D1E0CE.5030906@stoneleaf.us> <52D1E830.8070305@stoneleaf.us> Message-ID: One use case is: Suppose you have existing function that accepts a *bytes* object. If you subclass *bytes* and want it to be guaranteed to work with that function, you can override* __bytes__()* to use the logistics of your subclass implementation. On Sat, Jan 11, 2014 at 7:56 PM, Ethan Furman wrote: > On 01/11/2014 04:53 PM, Daniel da Silva wrote: > >> >> Where did you read this? I can't find any documentation about __bytes__ >> on google. >> > > http://docs.python.org/3.3/reference/datamodel.html? > highlight=__bytes__#object.__bytes__ > > > -- > ~Ethan~ > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From hmmedina at gmail.com Sat Jan 11 23:00:05 2014 From: hmmedina at gmail.com (CraftyTech) Date: Sat, 11 Jan 2014 20:00:05 -0800 (PST) Subject: parametized unittest Message-ID: hello all, I'm trying parametize my unittest so that I can re-use over and over, perhaps in a for loop. Consider the following: ''' import unittest class TestCalc(unittest.TestCase): def testAdd(self): self.assertEqual(7, 7, "Didn't add up") if __name__=="__main__": unittest.main() ''' Simple and straight forward, but I'm trying to get to a place where I can run it this way: import unittest class TestCalc(unittest.TestCase): def testAdd(self,var): self.assertEqual(var, 7, "Didn't add up") if __name__=="__main__": unittest.main(testAdd(7)) is this possible? I'm finding it hard to use unittest in a for loop. Perhaps something like: for val in range(25): self.assertEqual(val,5,"not equal) The loop will break after the first failure. Anyone have a good approach for this? please advise. cheers, From ben+python at benfinney.id.au Sat Jan 11 23:22:47 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 12 Jan 2014 15:22:47 +1100 Subject: parametized unittest References: Message-ID: <7wfvotde20.fsf@benfinney.id.au> CraftyTech writes: > I'm trying parametize my unittest so that I can re-use over and over, > perhaps in a for loop. The ?testscenarios? library allows you to define a set of data scenarios on your FooBarTestCase and have all the test case functions in that class run for all the scenarios, as distinct test cases. e.g. a class with 5 scenarios defined, and 3 test case functions, will run as 15 distinct test cases with separate output in the report. > The loop will break after the first failure. Anyone have a good > approach for this? please advise. Yes, this is exactly the problem addressed by ?testscenarios?. Enjoy it! -- \ ?Program testing can be a very effective way to show the | `\ presence of bugs, but is hopelessly inadequate for showing | _o__) their absence.? ?Edsger W. Dijkstra | Ben Finney From wking at tremily.us Sat Jan 11 23:28:38 2014 From: wking at tremily.us (W. Trevor King) Date: Sat, 11 Jan 2014 20:28:38 -0800 Subject: parametized unittest In-Reply-To: References: Message-ID: <20140112042838.GK29954@odin.tremily.us> On Sat, Jan 11, 2014 at 08:00:05PM -0800, CraftyTech wrote: > I'm finding it hard to use unittest in a for loop. Perhaps something like: > > for val in range(25): > self.assertEqual(val,5,"not equal) > > The loop will break after the first failure. Anyone have a good > approach for this? please advise. If Python 3.4 is an option, you can stick to the standard library and use subtests [1]. Cheers, Trevor [1]: http://docs.python.org/3.4/library/unittest.html#distinguishing-test-iterations-using-subtests -- This email may be signed or encrypted with GnuPG (http://www.gnupg.org). For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: OpenPGP digital signature URL: From roy at panix.com Sat Jan 11 23:34:30 2014 From: roy at panix.com (Roy Smith) Date: Sat, 11 Jan 2014 23:34:30 -0500 Subject: parametized unittest References: Message-ID: In article , "W. Trevor King" wrote: > On Sat, Jan 11, 2014 at 08:00:05PM -0800, CraftyTech wrote: > > I'm finding it hard to use unittest in a for loop. Perhaps something like: > > > > for val in range(25): > > self.assertEqual(val,5,"not equal) > > > > The loop will break after the first failure. Anyone have a good > > approach for this? please advise. > > If Python 3.4 is an option, you can stick to the standard library and > use subtests [1]. Or, as yet another alternative, if you use nose, you can write test generators. https://nose.readthedocs.org/en/latest/writing_tests.html#test-generators From hayesstw at telkomsa.net Sun Jan 12 00:08:59 2014 From: hayesstw at telkomsa.net (Steve Hayes) Date: Sun, 12 Jan 2014 07:08:59 +0200 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On Sat, 11 Jan 2014 10:45:53 -0500, Roy Smith wrote: >In article <18b67e59-39d1-41e2-8977-b1c449b132e7 at googlegroups.com>, > pintreo mardi wrote: > >> Hi, I've just begun to learn programming, I have an open question for the >> group: >> Is the Python language an all in one computer language which could replace C, >> C++, Java etc.. I only ask becuase I am starting off with python and I want >> to learn everything in basic and advanced programming with python itself...So >> any advice and suggestions would be more than welcome. >> Thanks!! > >That's a really hard question to answer, or at least to answer well. > >At a theoretical level, when you ask, "Is Python equivalent to C, C++ >and Java", the answer is "yes". In computer science, programming >languages are classified by whether they are "Turing Complete" or not >(google that for more info). In theory, any Turing Complete language is >capable of writing all programs which can be written in any other Turing >Complete language. All of the languages you mention are Turing >Complete, so, theoretically, they are all equivalent. > >But, at a more practical level, some languages are easier to learn, some >run faster, some are more portable, some are more convenient to use, >etc. If I had to rank the languages you mention by a few categories, >I'd say something like: > I think the significant thing is that some languages are easier to use for some things than for others. Though you can use any language to write any kind of program in theory, in practice some languages are designed to write certain kinds of programs more easily and more quickly -- Prolog for AI programs, for example. So the question is, which kinds of programs is Python best for? I'm a novice at it, so it's a question that concerns me. From what I've heard and read, it seems to be a fairly good general-purpose language, and it seems to be most used for writing web applications (though that is not something I am particularly interested in). -- 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 ngangsia at gmail.com Sun Jan 12 00:14:24 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 11 Jan 2014 21:14:24 -0800 (PST) Subject: python first project In-Reply-To: References: Message-ID: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> On Saturday, January 11, 2014 11:10:20 PM UTC+1, Dennis Lee Bieber wrote: > On Sat, 11 Jan 2014 09:55:57 -0800 (PST), ngangsia akumbo > > declaimed the following: What options do you think i can give the Ceo. Because from what you have outline, i think i will like to follow your advice. If it is just some recording data stuff then some spreadsheet can do the work. >From all indication it is a very huge project. How much do you thing all this will cost if we were to put the system all complete. From ethan at stoneleaf.us Sun Jan 12 00:31:41 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sat, 11 Jan 2014 21:31:41 -0800 Subject: Python 3 __bytes__ method In-Reply-To: References: <52D1E0CE.5030906@stoneleaf.us> <52D1E830.8070305@stoneleaf.us> <52D201A7.3050403@stoneleaf.us> Message-ID: <52D228BD.8030900@stoneleaf.us> On 01/11/2014 08:56 PM, Daniel da Silva wrote: > > I agree with you that realistic use cases are hard to think of. > > Does that answer your question better? Well, since I was asking if anybody was already using the feature, no. ;) -- ~Ethan~ From rosuav at gmail.com Sun Jan 12 00:58:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 16:58:45 +1100 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 4:08 PM, Steve Hayes wrote: > So the question is, which kinds of programs is Python best for? > > I'm a novice at it, so it's a question that concerns me. From what I've heard > and read, it seems to be a fairly good general-purpose language, and it seems > to be most used for writing web applications (though that is not something I > am particularly interested in). Python puts heavy focus on code readability (which also means it's easy to write). So it gains you hugely for small scripts, less so for things that need to run millions of times a second. Python has a variety of libraries that make it well suited to internet applications (as server or as client). Python, especially as of version 3.3, is superb at handling internationalization, Unicode, and related messes - you can sort out files of different encodings and rewrite them in something consistent (eg UTF-8). It may seem a bit harder at first, as you're forced to think about the meaning of bytes and what's text and so on, but it's worth it. Python is NOT good at massively parallel numerical calculations.... on its own. But there are libraries that can do that sort of thing for you (NumPy, SciPy); I've no idea how good they are because I neither use them nor write code that would benefit from them, but they're extremely popular and well-used. As a general rule, if your program is likely to spend most of its time waiting (for the disk, the network, the user, etc), then Python is probably at least as good a choice as C, Java, or any other language, and the question will come down to library support and such. Python is also an excellent "super pocket calculator". The reasonably-compact notation for aggregate operations (list comprehensions and such) lets you work with a functional programming style, and you can use step-by-step imperative programming in the same way. Want to calculate the average result of rolling six six-sided dice, and discarding any results below 14? Try this: http://www.kickstarter.com/projects/916188323/doublesix-dice-roll-better/comments?cursor=5623335#comment-5623334 (BTW, is there no better notation than six nested for/range for doing 6d6? I couldn't think of one off-hand, but it didn't really much matter anyway.) The incremental execution of Python's interactive interpreter (REPL) is extremely convenient for this. I personally like using IDLE for this, as (unlike command-line Python) it will recall and edit an entire suite, rather than one line at a time. Extremely handy. ChrisA From rosuav at gmail.com Sun Jan 12 01:04:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 17:04:04 +1100 Subject: python first project In-Reply-To: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> References: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 4:14 PM, ngangsia akumbo wrote: > What options do you think i can give the Ceo. Because from what you have outline, i think i will like to follow your advice. > > If it is just some recording data stuff then some spreadsheet can do the work. > > From all indication it is a very huge project. > > How much do you thing all this will cost if we were to put the system all complete. If you currently do all your bills and things on paper, then this job is going to be extremely daunting. Even if you don't write a single line of code (ie you buy a ready-made system), you're going to have to convert everybody to doing things the new way. In that case, I would recommend getting some people together to discuss exactly what you need to do, and then purchase an accounting, warehousing, or inventory management system, based on what you actually need it to do. On the other hand, if it's already being done electronically, your job is IMMENSELY easier. Easier, but more complex to describe, because what you're really asking for is a program that will get certain data out of your accounting/inventory management system and display it. The difficulty of that job depends entirely on what you're using for that data entry. ChrisA From var.mail.daniel at gmail.com Sat Jan 11 23:56:42 2014 From: var.mail.daniel at gmail.com (Daniel da Silva) Date: Sat, 11 Jan 2014 23:56:42 -0500 Subject: Python 3 __bytes__ method In-Reply-To: <52D201A7.3050403@stoneleaf.us> References: <52D1E0CE.5030906@stoneleaf.us> <52D1E830.8070305@stoneleaf.us> <52D201A7.3050403@stoneleaf.us> Message-ID: On Sat, Jan 11, 2014 at 9:44 PM, Ethan Furman wrote: > On 01/11/2014 06:19 PM, Daniel da Silva wrote: > >> >> One use case is: >> Suppose you have existing function that accepts a /bytes/ object. If you >> subclass /bytes/ and want it to be guaranteed >> to work with that function, you can override/__bytes__()/ to use the >> logistics of your subclass implementation. >> > > I don't think so, for two reasons: > > 1) bytes objects do not have a __bytes__ method, > > 2) if the function is expecting a bytes object, it is unlikely to call > bytes() on it. In general __typename__() methods are for explicit typename(obj) conversion. There is __int__(), __str__(), etc. They are what is behind int('3') == 3 and str(4) == '4'. If for no other reason, __bytes__() is there for symmetry. I agree with you that realistic use cases are hard to think of. Does that answer your question better? All the best, Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From ngangsia at gmail.com Sun Jan 12 02:30:51 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sat, 11 Jan 2014 23:30:51 -0800 (PST) Subject: python first project In-Reply-To: References: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> Message-ID: <6dff042f-28bc-4f4f-a4a5-f5fcadc2eb54@googlegroups.com> On Sunday, January 12, 2014 7:04:04 AM UTC+1, Chris Angelico wrote: > On Sun, Jan 12, 2014 at 4:14 PM, ngangsia akumbo wrote: i am not sure i will give up, i will start with a small app for stock registry. >From there i think the others will come latter. >From the info u have given me , i will continue from there on. So now is i will try to build a small app for stock registry may be u can still give me some tips on that From wxjmfauth at gmail.com Sun Jan 12 02:50:55 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 11 Jan 2014 23:50:55 -0800 (PST) Subject: =?ISO-8859-1?B?J1N0cmHfZScgKCdTdHJhc3NlJykgYW5kIFB5dGhvbiAy?= Message-ID: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> >>> sys.version 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>> s = 'Stra?e' >>> assert len(s) == 6 >>> assert s[5] == 'e' >>> jmf From __peter__ at web.de Sun Jan 12 03:31:28 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 12 Jan 2014 09:31:28 +0100 Subject: =?UTF-8?B?J1N0cmHDn2Un?= ('Strasse') and Python 2 References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: wxjmfauth at gmail.com wrote: >>>> sys.version > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>> s = 'Stra?e' >>>> assert len(s) == 6 >>>> assert s[5] == 'e' >>>> > > jmf Signifying nothing. (Macbeth) Python 2.7.2+ (default, Jul 20 2012, 22:15:08) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> s = "Stra?e" >>> assert len(s) == 6 Traceback (most recent call last): File "", line 1, in AssertionError >>> assert s[5] == "e" Traceback (most recent call last): File "", line 1, in AssertionError From stefan_ml at behnel.de Sun Jan 12 04:00:58 2014 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sun, 12 Jan 2014 10:00:58 +0100 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: Peter Otten, 12.01.2014 09:31: > wxjmfauth at gmail.com wrote: > >> >>> sys.version >> 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >> >>> s = 'Stra?e' >> >>> assert len(s) == 6 >> >>> assert s[5] == 'e' >> >>> >> >> jmf > > Signifying nothing. (Macbeth) > > Python 2.7.2+ (default, Jul 20 2012, 22:15:08) > [GCC 4.6.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> s = "Stra?e" > >>> assert len(s) == 6 > Traceback (most recent call last): > File "", line 1, in > AssertionError > >>> assert s[5] == "e" > Traceback (most recent call last): > File "", line 1, in > AssertionError The point I think he was trying to make is that Linux is better than Windows, because the latter fails to fail on these assertions for some reason. Stefan :o) From thrinaxodon23 at gmail.com Sun Jan 12 05:25:31 2014 From: thrinaxodon23 at gmail.com (Thrinassodon) Date: Sun, 12 Jan 2014 05:25:31 -0500 Subject: The war on Leakey is over. Message-ID: =============== >BREAKING NEWS! =============== > IT WAS A DARK AND STORMY NIGHT, RICHARD LEAKEY and Peter Nyikos, Paul Gans, and Desertphile were scoping Thrinaxodon's house for signs of the Devonian human fossils to burn them and save the from being broke by burning the fossils and keeping the multi-billion dollar industry of evolution going. > However, what they didn't know was Thrinaxodon and his FBI buddies were armed and ready to attack. Carter shout "The evolutionists are coming, the evolutionists are coming!" > Thrinaxodon opened the window and started shooting, Gans was severely wounded and left to die. Nyikos ran for his life and Desertphile ran with Nyikos. Nyikos was subsequently shot by the police. > =================================== > MAN AS OLD AS FROGS! https://groups.google.com/forum/#!topic/sci.bio.paleontology/buAVigqX9Ts > =================================== > Leakey continued shooting and killing several officers. Thrinaxodon then jumped out and kicked Leakey's ass before he even knew it. However, Leakey jumped and shot Thrinaxodon in the stomach, only to be shot back by Thrinaxodon. > Then Leakey was arrested. > ================================================ > TO FIND OUT HOW MAN IS AS OLD AS FROGS, VISIT: http://thrinaxodon.wordpress.com/faq -- Thrinaxodon, The Ultimate Defender of USENET From jeandupont314 at gmail.com Sun Jan 12 05:36:42 2014 From: jeandupont314 at gmail.com (Jean Dupont) Date: Sun, 12 Jan 2014 02:36:42 -0800 (PST) Subject: [newbie] starting geany from within idle does not work Message-ID: <0a59b54b-1640-4afd-ad5a-f477c8cb5df6@googlegroups.com> I'm using the latest Raspbian on a Raspberry Pi and I'd like to start IDLE so that it uses Geany instead of Leafpad. This seems at first sight a trivial task: Perform a rightmouse click on the IDLE-icon-->Open with: Geany (in stead of the default Leafpad)-->OK LXTerminal-->lxpanelctl restart However if I then click on IDLE followed by File-->New Window a Leafpad-session is opened and not a Geany-session Is there a workaround for it? thanks in advance jean p.s. I posted this question before in the Raspberry Pi forum but nobody seems to know the answer From ned at nedbatchelder.com Sun Jan 12 07:17:18 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sun, 12 Jan 2014 07:17:18 -0500 Subject: =?ISO-8859-1?Q?=27Stra=DFe=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: On 1/12/14 2:50 AM, wxjmfauth at gmail.com wrote: >>>> sys.version > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>> s = 'Stra?e' >>>> assert len(s) == 6 >>>> assert s[5] == 'e' >>>> > > jmf > Dumping random snippets of Python sessions here is useless. If you are trying to make a point, you have to put some English around it. You know what is in your head, but we do not. -- Ned Batchelder, http://nedbatchelder.com From bilbaow at gmail.com Sun Jan 12 07:17:01 2014 From: bilbaow at gmail.com (KMeans Algorithm) Date: Sun, 12 Jan 2014 04:17:01 -0800 (PST) Subject: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' Message-ID: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> I'm trying to log in a webpage by using 'urllib' and this piece of code --------- import urllib2,urllib,os opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) login = urllib.urlencode({'username':'john', 'password':'foo'}) url = "https://www.mysite.com/loginpage" req = urllib2.Request(url, login) try: resp = urllib2.urlopen(req) print resp.read() except urllib2.HTTPError, e: print ":( Error = " + str(e.code) ---------------- But I get a "404" error (Not Found). The page "https://www.mysite.com/loginpage" does exist (note please the httpS, since I'm not sure if this the key of my problem). If I try with ------- resp = urllib2.urlopen(url) -------- (with no 'login' data), it works ok but, obviously, I'm not logged in. What am I doing wrong? Thank you very much. From breamoreboy at yahoo.co.uk Sun Jan 12 07:33:07 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 12 Jan 2014 12:33:07 +0000 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: On 12/01/2014 09:00, Stefan Behnel wrote: > Peter Otten, 12.01.2014 09:31: >> wxjmfauth at gmail.com wrote: >> >>>>>> sys.version >>> 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>>>> s = 'Stra?e' >>>>>> assert len(s) == 6 >>>>>> assert s[5] == 'e' >>>>>> >>> >>> jmf >> >> Signifying nothing. (Macbeth) >> >> Python 2.7.2+ (default, Jul 20 2012, 22:15:08) >> [GCC 4.6.1] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> s = "Stra?e" >>>>> assert len(s) == 6 >> Traceback (most recent call last): >> File "", line 1, in >> AssertionError >>>>> assert s[5] == "e" >> Traceback (most recent call last): >> File "", line 1, in >> AssertionError > > The point I think he was trying to make is that Linux is better than > Windows, because the latter fails to fail on these assertions for some reason. > > Stefan :o) > > The point he's trying to make is that he also reads the pythondev mailing list, where Steven D'Aprano posted this very example, stating it is "Python 2 nonsense". Fixed in Python 3. Don't mention... :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From kwa at kuwata-lab.com Sun Jan 12 07:38:07 2014 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Sun, 12 Jan 2014 21:38:07 +0900 Subject: [ANN] Oktest.py 0.12.0 released - a new-style testing library Message-ID: Hi, I released Oktest 0.12.0. https://pypi.python.org/pypi/Oktest/ Oktest is a new-style testing library for Python. ## unittest self.assertEqual(x, y) self.assertNotEqual(x, y) self.assertGreaterEqual(x, y) self.assertIsInstance(obj, cls) self.assertRegexpMatches(text, rexp) ## Oktest.py ok (x) == y ok (x) != y ok (x) >= y ok (obj).is_a(cls) ok (text).match(rexp) Install $ easy_install oktest User's Guide http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html Changes http://www.kuwata-lab.com/oktest/oktest-py_CHANGES.txt Highlight on this release ------------------------- This release contains new and important enhancements. * [enhance] `ok (actual) == expected' reports unified diff. Example:: AssertionError: --- expected +++ actual @@ -1,3 +1,3 @@ {'email': 'haruhi at sos-brigade.org', - 'gender': 'Female', + 'gender': 'female', 'username': 'Haruhi'} * [enhance] @at_end decorator registers callback which is called at end of test case. :: @test("example to remove temporary file automatically") def _(self): ## create dummy file with open('dummy.txt', 'w') as f: f.write("blablabla") ## register callback to delete dummy file at end of test case @at_end def _(): os.unlink(tmpfile) ## do test with open(tmpfile) as f: ok (f.read()) == "blablabla" * [enhance] New assertions for WebOb/Werkzeug response object. :: ok (resp).is_response(200) # status code ok (resp).is_response((302, 303)) # status code ok (resp).is_response('200 OK') # status line ok (resp).is_response(200, 'image/jpeg') # content-type ok (resp).is_response(200, re.compile(r'^image/(jpeg|png|gif)$')) ok (resp).is_response(302).header("Location", "/") # header ok (resp).is_response(200).json({"status": "OK"}) # json data ok (resp).is_response(200).body("

Hello

") # response body ok (resp).is_response(200).body(re.compile("

.*?

")) * [bugfix] @todo decorator now supports fixture injection. :: @test('example') @todo # error on previous version but not on this release def _(self, x): assert False You can see all enhancements and changes. See http://www.kuwata-lab.com/oktest/oktest-py_CHANGES.txt Have fun! -- regards, makoto kuwata -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sun Jan 12 07:42:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 23:42:22 +1100 Subject: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' In-Reply-To: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> References: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 11:17 PM, KMeans Algorithm wrote: > What am I doing wrong? Thank you very much. I can't say what's actually wrong, but I have a few ideas for getting more information out of the system... > opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) You don't do anything with this opener - could you have a cookie problem? > req = urllib2.Request(url, login) > > But I get a "404" error (Not Found). The page "https://www.mysite.com/loginpage" does exist (note please the httpS, since I'm not sure if this the key of my problem). > > If I try with > > ------- > resp = urllib2.urlopen(url) > -------- > (with no 'login' data), it works ok but, obviously, I'm not logged in. Note that adding a data parameter changes the request from a GET to a POST. I'd normally expect the server to respond 404 to both or neither, but it's theoretically possible. It's also possible that you're getting redirected, and that (maybe because cookies aren't being retained??) the destination is 404. I'm not familiar with urllib2, but if you get a response object back, you can call .geturl() on it - no idea how that goes with HTTP errors, though. You may want to look at the exception's .reason attribute - might be more informative than .code. As a last resort, try firing up Wireshark or something and watch exactly what gets sent and received. I went looking through the docs for a "verbose" mode or a "debug" setting but can't find one - that'd be ideal if it exists, though. Hope that's of at least some help! ChrisA From rosuav at gmail.com Sun Jan 12 07:44:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 12 Jan 2014 23:44:38 +1100 Subject: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' In-Reply-To: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> References: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> Message-ID: On Sun, Jan 12, 2014 at 11:17 PM, KMeans Algorithm wrote: > The page "https://www.mysite.com/loginpage" does exist PS. If it's not an intranet site and the URL isn't secret, it'd help if we could actually try things out. One of the tricks I like to use is to access the same page with a different program/library - maybe wget, or bare telnet, or something like that. Sometimes one succeeds and another doesn't, and then you dig into the difference (once I found that a web server failed unless the request headers were in a particular order - that was a pain to (a) find, and (b) work around!). ChrisA From roy at panix.com Sun Jan 12 08:02:11 2014 From: roy at panix.com (Roy Smith) Date: Sun, 12 Jan 2014 08:02:11 -0500 Subject: [ANN] Oktest.py 0.12.0 released - a new-style testing library References: Message-ID: In article , Makoto Kuwata wrote: > Hi, > > I released Oktest 0.12.0. > https://pypi.python.org/pypi/Oktest/ Wow, this looks neat. We use nose, but I'm thinking your ok() style exceptions should work just fine with nose. Just the notational convenience alone is worth it. Typing "ok(x) <= 1" is so much nicer than "assert_less(x, 1)". Unfortunately, I was unable to download it. There seems to be a broken redirect at pypi: $ wget http://pypi.python.org/packages/source/O/Oktest/Oktest-0.12.0.tar.gz --2014-01-12 07:57:01-- http://pypi.python.org/packages/source/O/Oktest/Oktest-0.12.0.tar.gz Resolving pypi.python.org (pypi.python.org)... 199.27.72.184, 199.27.72.185 Connecting to pypi.python.org (pypi.python.org)|199.27.72.184|:80... connected. HTTP request sent, awaiting response... 301 Moved Permanently Location: https://pypi.python.org/packages/source/O/Oktest/Oktest-0.12.0.tar.gz [following] --2014-01-12 07:57:01-- https://pypi.python.org/packages/source/O/Oktest/Oktest-0.12.0.tar.gz Connecting to pypi.python.org (pypi.python.org)|199.27.72.184|:443... connected. HTTP request sent, awaiting response... 404 Not Found 2014-01-12 07:57:02 ERROR 404: Not Found. From sg552 at hotmail.co.uk Sun Jan 12 09:36:24 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Sun, 12 Jan 2014 14:36:24 +0000 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On 12/01/2014 05:58, Chris Angelico wrote: > [...] > > (BTW, is there no better notation than six nested for/range for doing > 6d6? I couldn't think of one off-hand, but it didn't really much > matter anyway.) If you're willing to do an import, then how about this: >>> from itertools import product >>> len([x for x in product(range(1, 7), repeat = 6) if sum(x) < 14])/6**6 0.03587962962962963 From ngangsia at gmail.com Sun Jan 12 09:37:18 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 12 Jan 2014 06:37:18 -0800 (PST) Subject: Python example source code Message-ID: where can i find example source code by topic? Any help please From rosuav at gmail.com Sun Jan 12 09:44:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 01:44:28 +1100 Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? In-Reply-To: References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On Mon, Jan 13, 2014 at 1:36 AM, Rotwang wrote: > On 12/01/2014 05:58, Chris Angelico wrote: >> >> (BTW, is there no better notation than six nested for/range for doing >> 6d6? I couldn't think of one off-hand, but it didn't really much >> matter anyway.) > > > If you're willing to do an import, then how about this: > >>>> from itertools import product >>>> len([x for x in product(range(1, 7), repeat = 6) if sum(x) < 14])/6**6 > 0.03587962962962963 Should have known itertools would have something. That's a little more complicated to try to explain, but it's a lot shorter. ChrisA From bgailer at gmail.com Sun Jan 12 09:53:41 2014 From: bgailer at gmail.com (bob gailer) Date: Sun, 12 Jan 2014 09:53:41 -0500 Subject: Python example source code In-Reply-To: References: Message-ID: <52D2AC75.50503@gmail.com> On 1/12/2014 9:37 AM, ngangsia akumbo wrote: > where can i find example source code by topic? There are several Python tutorials on the internet. They have good code examples. Most modules also have module-specific examples. There are also some web sites that may address your needs. I will leave it to others to list these. What do you mean by topic? Give us some examples of topics and maybe we can help more. From davea at davea.name Sun Jan 12 10:06:13 2014 From: davea at davea.name (Dave Angel) Date: Sun, 12 Jan 2014 10:06:13 -0500 (EST) Subject: Python example source code References: Message-ID: ngangsia akumbo Wrote in message: > where can i find example source code by topic? > Any help please > http://code.activestate.com/recipes/langs/python/ http://code.activestate.com/recipes/sets/2-python-cookbook-edition-2/ http://shop.oreilly.com/product/mobile/0636920027072.do http://www.mindviewinc.com/Books/Python3Patterns/Index.php https://pypi.python.org/pypi -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From thrinaxodon23 at gmail.com Sun Jan 12 10:06:10 2014 From: thrinaxodon23 at gmail.com (Thrinassodon) Date: Sun, 12 Jan 2014 10:06:10 -0500 Subject: Dawkins arrested Message-ID: ================ >BREAKING NEWS! ================ > THRINAXODON SPEARHEADED THE ASSAULT ON RICHARD DAWKINS, KNOWN FOR SUPPRESSION OF VALID RESEARCH OF HUMAN ORIGINS FOR YEARS, JUST TO GET A BUCK OUT OF BRAINWASHING CHILDREN'S LIVES INTO THE SCAM OF EVOLUTION. > Dawkins was charged with OVER 9000! complaints of mind-control, torture, and pyramid schemes where he got millions of dollars out of the American populace over the scam of evolution. > This is what Dawkins said when he faced the charges, "SHIT! How am I going to get money now!" Later, his charges were reduced to probation. He is now broke. > According to Thrinaxodon, PHD, an expert on human origins, "The loss of Dawkins is a great blow to the evolutionist establishment, with no figurehead the scientific establishement that has been dominating American politics for 150 years is now falling down under it's own weight. How are people like AronRa or James Watson going to get money now? No-one knows." > When Dawkins was asked how the scientific establishement was going to rebuild, he said "I don't know. Maybe, just maybe, we'll have to move on to another scam. Like the Big Bang." > =================================== > MAN AS OLD AS FROGS! https://groups.google.com/forum/#!topic/sci.bio.paleontology/buAVigqX9Ts > TO FIND OUT HOW MAN IS AS OLD AS FROGS, VISIT: http://thrinaxodon.wordpress.com/faq -- Thrinaxodon, The Ultimate Defender of USENET From esj at harvee.org Sun Jan 12 10:08:31 2014 From: esj at harvee.org (Eric S. Johansson) Date: Sun, 12 Jan 2014 10:08:31 -0500 Subject: extracting string.Template substitution placeholders Message-ID: <52D2AFEF.3010505@harvee.org> As part of speech recognition accessibility tools that I'm building, I'm using string.Template. In order to construct on-the-fly grammar, I need to know all of the identifiers before the template is filled in. what is the best way to do this? can string.Template handle recursive expansion i.e. an identifier contains a template. Thanks --- eric From ngangsia at gmail.com Sun Jan 12 10:13:29 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 12 Jan 2014 07:13:29 -0800 (PST) Subject: Python example source code In-Reply-To: References: Message-ID: On Sunday, January 12, 2014 4:06:13 PM UTC+1, Dave Angel wrote: > ngangsia akumbo Wrote in message: > Thanks bro From thudfoo at gmail.com Sun Jan 12 10:17:41 2014 From: thudfoo at gmail.com (xDog Walker) Date: Sun, 12 Jan 2014 07:17:41 -0800 Subject: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' In-Reply-To: References: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> Message-ID: <201401120717.42108.thudfoo@gmail.com> On Sunday 2014 January 12 04:42, Chris Angelico wrote: > As a last resort, try firing up Wireshark or something and watch > exactly what gets sent and received. I went looking through the docs > for a "verbose" mode or a "debug" setting but can't find one - that'd > be ideal if it exists, though. I think you can set debug on httplib before using urllib to get the header traffic printed. I don't recall exactly how to do it though. -- Yonder nor sorghum stenches shut ladle gulls stopper torque wet strainers. From p_s_d_a_s_i_l_v_a at netcabo.pt Sun Jan 12 10:36:11 2014 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Sun, 12 Jan 2014 15:36:11 +0000 Subject: Problem writing some strings (UnicodeEncodeError) Message-ID: Hi! I am using a python3 script to produce a bash script from lots of filenames got using os.walk. I have a template string for each bash command in which I replace a special string with the filename and then write the command to the bash script file. Something like this: shf=open(bashfilename,'w') filenames=getfilenames() # uses os.walk for fn in filenames: ... cmd=templ.replace("",fn) shf.write(cmd) For certain filenames I got a UnicodeEncodeError exception at shf.write(cmd)! I use utf-8 and have # -*- coding: utf-8 -*- in the source .py. How can I fix this? Thanks for any help/comments. From fomcl at yahoo.com Sun Jan 12 11:19:10 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sun, 12 Jan 2014 08:19:10 -0800 (PST) Subject: Problem writing some strings (UnicodeEncodeError) In-Reply-To: Message-ID: <1389543550.43054.YahooMailBasic@web163801.mail.gq1.yahoo.com> -------------------------------------------- On Sun, 1/12/14, Paulo da Silva wrote: Subject: Problem writing some strings (UnicodeEncodeError) To: python-list at python.org Date: Sunday, January 12, 2014, 4:36 PM Hi! I am using a python3 script to produce a bash script from lots of filenames got using os.walk. I have a template string for each bash command in which I replace a special string with the filename and then write the command to the bash script file. Something like this: shf=open(bashfilename,'w') filenames=getfilenames() # uses os.walk for fn in filenames: ??? ... ??? cmd=templ.replace("",fn) ??? shf.write(cmd) For certain filenames I got a UnicodeEncodeError exception at shf.write(cmd)! I use utf-8 and have # -*- coding: utf-8 -*- in the source .py. How can I fix this? Thanks for any help/comments. ======> what is the output of locale.getpreferredencoding(False)? That is the default value of the "encoding" parameter of the open function. shf=open(bashfilename,'w', encoding='utf-8') might work, though on my Linux macine locale.getpreferredencoding(False) returns utf-8. help(open) ... In text mode, if encoding is not specified the encoding used is platform dependent: locale.getpreferredencoding(False) is called to get the current locale encoding. (For reading and writing raw bytes use binary mode and leave encoding unspecified.) ... From __peter__ at web.de Sun Jan 12 11:23:02 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 12 Jan 2014 17:23:02 +0100 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Paulo da Silva wrote: > I am using a python3 script to produce a bash script from lots of > filenames got using os.walk. > > I have a template string for each bash command in which I replace a > special string with the filename and then write the command to the bash > script file. > > Something like this: > > shf=open(bashfilename,'w') > filenames=getfilenames() # uses os.walk > for fn in filenames: > ... > cmd=templ.replace("",fn) > shf.write(cmd) > > For certain filenames I got a UnicodeEncodeError exception at > shf.write(cmd)! > I use utf-8 and have # -*- coding: utf-8 -*- in the source .py. > > How can I fix this? > > Thanks for any help/comments. You make it harder to debug your problem by not giving the complete traceback. If the error message contains 'surrogates not allowed' like in the demo below >>> with open("tmp.txt", "w") as f: ... f.write("\udcef") ... Traceback (most recent call last): File "", line 2, in UnicodeEncodeError: 'utf-8' codec can't encode character '\udcef' in position 0: surrogates not allowed you have filenames that are not valid UTF-8 on your harddisk. A possible fix would be to use bytes instead of str. For that you need to open `bashfilename` in binary mode ("wb") and pass bytes to the os.walk() call. Or you just go and fix the offending names. From joel.goldstick at gmail.com Sun Jan 12 11:38:03 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Sun, 12 Jan 2014 11:38:03 -0500 Subject: Python example source code In-Reply-To: References: Message-ID: On Sun, Jan 12, 2014 at 10:13 AM, ngangsia akumbo wrote: > > On Sunday, January 12, 2014 4:06:13 PM UTC+1, Dave Angel wrote: > > ngangsia akumbo Wrote in message: > > > > > Thanks bro > > -- > https://mail.python.org/mailman/listinfo/python-list Don't forget Python Module of the Week pymotw.com/? -- Joel Goldstick http://joelgoldstick.com From emile at fenx.com Sun Jan 12 11:37:41 2014 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Jan 2014 08:37:41 -0800 Subject: python first project In-Reply-To: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> References: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> Message-ID: On 01/11/2014 09:14 PM, ngangsia akumbo wrote: > From all indication it is a very huge project. Yep -- I built such a system in the late 70's with a team of seven over two-three years. Then modifications and improvements continued over the next 20 years keeping about 2-4 programmers busy full time. > How much do you thing all this will cost if we were to put the system all complete. A lot. In today's dollars a million or two to do it right at a minimalist level. Going for the gold will be much more. IMHO you'd be better off researching the existing software market for an application suite the 'best fits' their needs and allows for customization to fine tune things. I'm now working with OpenERP which is python based and is OSS with a subscription model to ensure an upgrade path. It already has most of what you're looking for built in or available as third party addons and is of a quality that you couldn't hope to attain in years of effort. Which reflects the millions they've invested. see http://www.openerp.com for more. For an example of a commercially available entry level alternative costs check out: http://www.erpsoftwareblog.com/2012/10/microsoft-dynamics-gp-2013-pricing-and-costs/ Overall a much better choice than starting from scratch. That said, it wouldn't surprise me that the CEO hasn't already looked into alternatives and been put off by the costs involved. (S)he is trying to cheap their way through things by deluding themselves into a its-not-that-big-a-problem way of thinking that I wouldn't involve myself in that train wreck. Call me a sceptic -- it's true. :) HTH, Emile From ngangsia at gmail.com Sun Jan 12 11:47:39 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 12 Jan 2014 08:47:39 -0800 (PST) Subject: python first project In-Reply-To: References: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> Message-ID: <7579aed2-1008-47f5-a76d-142a6770949a@googlegroups.com> On Sunday, January 12, 2014 5:37:41 PM UTC+1, Emile van Sebille wrote: > On 01/11/2014 09:14 PM, ngangsia akumbo wrote: > For an example of a commercially available entry level alternative costs check out: > That said, it wouldn't surprise me that the CEO hasn't already looked into alternatives and been put off by the costs involved. (S)he is trying to cheap their way through things by deluding themselves into a its-not-that-big-a-problem way of thinking that I wouldn't involve myself in that train wreck. Call me a sceptic -- it's true. :) HAHAHAHAH, LOL THAT IS TRUE YOU SPOKE LIKE A MAGICIAN. WHEN I START PUTTING THE CODE UP FOR STOCK/BOOKKEEPING I WILL NEED YOUR ASSISTANCE. THANKS From emile at fenx.com Sun Jan 12 11:52:19 2014 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Jan 2014 08:52:19 -0800 Subject: Python example source code In-Reply-To: References: Message-ID: On 01/12/2014 06:37 AM, ngangsia akumbo wrote: > where can i find example source code by topic? I'd recommend http://effbot.org/librarybook/ even though it's v2 specific and somewhat dated. Emile From hmmedina at gmail.com Sun Jan 12 11:57:16 2014 From: hmmedina at gmail.com (CraftyTech) Date: Sun, 12 Jan 2014 08:57:16 -0800 (PST) Subject: parametized unittest In-Reply-To: References: Message-ID: <11a152c3-edfb-4552-b296-cfb5e03c0f73@googlegroups.com> On Saturday, January 11, 2014 11:34:30 PM UTC-5, Roy Smith wrote: > In article , > > "W. Trevor King" wrote: > > > > > On Sat, Jan 11, 2014 at 08:00:05PM -0800, CraftyTech wrote: > > > > I'm finding it hard to use unittest in a for loop. Perhaps something like: > > > > > > > > for val in range(25): > > > > self.assertEqual(val,5,"not equal) > > > > > > > > The loop will break after the first failure. Anyone have a good > > > > approach for this? please advise. > > > > > > If Python 3.4 is an option, you can stick to the standard library and > > > use subtests [1]. > > > > Or, as yet another alternative, if you use nose, you can write test > > generators. > > > > https://nose.readthedocs.org/en/latest/writing_tests.html#test-generators Thank you all for the feedback. I now have what I need. Cheers On Saturday, January 11, 2014 11:34:30 PM UTC-5, Roy Smith wrote: > In article , > > "W. Trevor King" wrote: > > > > > On Sat, Jan 11, 2014 at 08:00:05PM -0800, CraftyTech wrote: > > > > I'm finding it hard to use unittest in a for loop. Perhaps something like: > > > > > > > > for val in range(25): > > > > self.assertEqual(val,5,"not equal) > > > > > > > > The loop will break after the first failure. Anyone have a good > > > > approach for this? please advise. > > > > > > If Python 3.4 is an option, you can stick to the standard library and > > > use subtests [1]. > > > > Or, as yet another alternative, if you use nose, you can write test > > generators. > > > > https://nose.readthedocs.org/en/latest/writing_tests.html#test-generators From ngangsia at gmail.com Sun Jan 12 11:59:52 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 12 Jan 2014 08:59:52 -0800 (PST) Subject: Python example source code In-Reply-To: References: Message-ID: <8c066ff0-446a-4feb-b515-46d09533bfc4@googlegroups.com> On Sunday, January 12, 2014 5:38:03 PM UTC+1, Joel Goldstick wrote: > On Sun, Jan 12, 2014 at 10:13 AM, ngangsia akumbo wrote: > > Don't forget Python Module of the Week pymotw.com/ Thanks From emile at fenx.com Sun Jan 12 11:55:12 2014 From: emile at fenx.com (Emile van Sebille) Date: Sun, 12 Jan 2014 08:55:12 -0800 Subject: Problem writing some strings (UnicodeEncodeError) In-Reply-To: References: Message-ID: On 01/12/2014 07:36 AM, Paulo da Silva wrote: > Hi! > > I am using a python3 script to produce a bash script from lots of > filenames got using os.walk. > > I have a template string for each bash command in which I replace a > special string with the filename and then write the command to the bash > script file. > > Something like this: > > shf=open(bashfilename,'w') > filenames=getfilenames() # uses os.walk > for fn in filenames: > ... > cmd=templ.replace("",fn) > shf.write(cmd) > > For certain filenames I got a UnicodeEncodeError exception at > shf.write(cmd)! > I use utf-8 and have # -*- coding: utf-8 -*- in the source .py. > > How can I fix this? Not sure exactly, but I'd try shf=open(bashfilename,'wb') as a start. HTH, Emile From ngangsia at gmail.com Sun Jan 12 12:06:51 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 12 Jan 2014 09:06:51 -0800 (PST) Subject: Python example source code In-Reply-To: References: Message-ID: <8fd9d81e-b9cc-4680-b5ff-7dd5b25702b9@googlegroups.com> On Sunday, January 12, 2014 5:52:19 PM UTC+1, Emile van Sebille wrote: > On 01/12/2014 06:37 AM, ngangsia akumbo wrote: > > I'd recommend http://effbot.org/librarybook/ even though it's v2 specific and somewhat dated. Thank very much , it is very nice From thorwhalen at gmail.com Sun Jan 12 12:36:08 2014 From: thorwhalen at gmail.com (Thor Whalen) Date: Sun, 12 Jan 2014 09:36:08 -0800 (PST) Subject: Data peeping function? Message-ID: <1902f0fc-4e8d-48b4-85f4-489c60a09ad1@googlegroups.com> The first thing I do once I import new data (as a pandas dataframe) is to .head() it, .describe() it, and then kick around a few specific stats according to what I see. But I'm not satisfied with .describe(). Amongst others, non-numerical columns are ignored, and off-the-shelf stats will be computed for any numerical column. I've been shopping around for a "data peeping" function that would: (1) Have a hands-off mode where simply typing diagnose_this(data) the function would figure things out on its own, and notify me when in doubt. For example, would assume that any string data with not too many unique values should be considered categorical and appropriate statistics erected. (2) Perform standard diagnoses and print them out. For example, (a) missing values? (b) heterogeneously formatted data? (c) columns with only one unique value? etc. (3) Be parametrizable, if I so choose. Does anyone know of such a function? From memilanuk at gmail.com Sun Jan 12 12:47:02 2014 From: memilanuk at gmail.com (memilanuk) Date: Sun, 12 Jan 2014 09:47:02 -0800 Subject: Python example source code In-Reply-To: References: Message-ID: On 01/12/2014 06:37 AM, ngangsia akumbo wrote: > where can i find example source code by topic? > Any help please > nullege.com is usually helpful... From p_s_d_a_s_i_l_v_a at netcabo.pt Sun Jan 12 12:51:46 2014 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Sun, 12 Jan 2014 17:51:46 +0000 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Em 12-01-2014 16:23, Peter Otten escreveu: > Paulo da Silva wrote: > >> I am using a python3 script to produce a bash script from lots of >> filenames got using os.walk. >> >> I have a template string for each bash command in which I replace a >> special string with the filename and then write the command to the bash >> script file. >> >> Something like this: >> >> shf=open(bashfilename,'w') >> filenames=getfilenames() # uses os.walk >> for fn in filenames: >> ... >> cmd=templ.replace("",fn) >> shf.write(cmd) >> >> For certain filenames I got a UnicodeEncodeError exception at >> shf.write(cmd)! >> I use utf-8 and have # -*- coding: utf-8 -*- in the source .py. >> >> How can I fix this? >> >> Thanks for any help/comments. > > You make it harder to debug your problem by not giving the complete > traceback. If the error message contains 'surrogates not allowed' like in > the demo below > >>>> with open("tmp.txt", "w") as f: > ... f.write("\udcef") > ... > Traceback (most recent call last): > File "", line 2, in > UnicodeEncodeError: 'utf-8' codec can't encode character '\udcef' in > position 0: surrogates not allowed That is the situation. I just lost it and it would take a few houres to repeat the situation. Sorry. > > you have filenames that are not valid UTF-8 on your harddisk. > > A possible fix would be to use bytes instead of str. For that you need to > open `bashfilename` in binary mode ("wb") and pass bytes to the os.walk() > call. This is my 1st time with python3, so I am confused! As much I could understand it seems that os.walk is returning the filenames exactly as they are on disk. Just bytes like in C. My template is a string. What is the result of the replace command? Is there any change in the filename from os.walk contents? Now, if the result of the replace has the replaced filename unchanged how do I "convert" it to bytes type, without changing its contents, so that I can write to the bashfile opened with "wb"? > > Or you just go and fix the offending names. This is impossible in my case. I need a bash script with the names as they are on disk. From python at mrabarnett.plus.com Sun Jan 12 13:33:03 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 12 Jan 2014 18:33:03 +0000 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: <52D2DFDF.5020301@mrabarnett.plus.com> On 2014-01-12 08:31, Peter Otten wrote: > wxjmfauth at gmail.com wrote: > >>>>> sys.version >> 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>>> s = 'Stra?e' >>>>> assert len(s) == 6 >>>>> assert s[5] == 'e' >>>>> >> >> jmf > > Signifying nothing. (Macbeth) > > Python 2.7.2+ (default, Jul 20 2012, 22:15:08) > [GCC 4.6.1] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> s = "Stra?e" >>>> assert len(s) == 6 > Traceback (most recent call last): > File "", line 1, in > AssertionError >>>> assert s[5] == "e" > Traceback (most recent call last): > File "", line 1, in > AssertionError > > The point is that in Python 2 'Stra?e' is a bytestring and its length depends on the encoding of the source file. If the source file is UTF-8 then 'Stra?e' is a string literal with 7 bytes between the single quotes. From python at mrabarnett.plus.com Sun Jan 12 13:50:11 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 12 Jan 2014 18:50:11 +0000 Subject: python first project In-Reply-To: References: <38538337-c978-4a5b-8532-072152310c69@googlegroups.com> Message-ID: <52D2E3E3.4000505@mrabarnett.plus.com> On 2014-01-12 06:04, Chris Angelico wrote: > On Sun, Jan 12, 2014 at 4:14 PM, ngangsia akumbo > wrote: >> What options do you think i can give the Ceo. Because from what you >> have outline, i think i will like to follow your advice. >> >> If it is just some recording data stuff then some spreadsheet can >> do the work. >> >> From all indication it is a very huge project. >> >> How much do you thing all this will cost if we were to put the >> system all complete. > > If you currently do all your bills and things on paper, then this > job is going to be extremely daunting. Even if you don't write a > single line of code (ie you buy a ready-made system), you're going to > have to convert everybody to doing things the new way. In that case, > I would recommend getting some people together to discuss exactly > what you need to do, and then purchase an accounting, warehousing, or > inventory management system, based on what you actually need it to > do. > > On the other hand, if it's already being done electronically, your > job is IMMENSELY easier. Easier, but more complex to describe, > because what you're really asking for is a program that will get > certain data out of your accounting/inventory management system and > display it. The difficulty of that job depends entirely on what > you're using for that data entry. > You should also consider whether you need to do it all at once or could do it incrementally. Look at what functionality you might want and where you might get the greatest benefit and start there. Doing it that way will reduce the chances of you committing a lot of resources (time and money) building a system, only to find at the end that you either left something out or added something that you didn't really need after all. From __peter__ at web.de Sun Jan 12 13:50:16 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 12 Jan 2014 19:50:16 +0100 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Paulo da Silva wrote: > Em 12-01-2014 16:23, Peter Otten escreveu: >> Paulo da Silva wrote: >> >>> I am using a python3 script to produce a bash script from lots of >>> filenames got using os.walk. >>> >>> I have a template string for each bash command in which I replace a >>> special string with the filename and then write the command to the bash >>> script file. >>> >>> Something like this: >>> >>> shf=open(bashfilename,'w') >>> filenames=getfilenames() # uses os.walk >>> for fn in filenames: >>> ... >>> cmd=templ.replace("",fn) >>> shf.write(cmd) >>> >>> For certain filenames I got a UnicodeEncodeError exception at >>> shf.write(cmd)! >>> I use utf-8 and have # -*- coding: utf-8 -*- in the source .py. >>> >>> How can I fix this? >>> >>> Thanks for any help/comments. >> >> You make it harder to debug your problem by not giving the complete >> traceback. If the error message contains 'surrogates not allowed' like in >> the demo below >> >>>>> with open("tmp.txt", "w") as f: >> ... f.write("\udcef") >> ... >> Traceback (most recent call last): >> File "", line 2, in >> UnicodeEncodeError: 'utf-8' codec can't encode character '\udcef' in >> position 0: surrogates not allowed > > That is the situation. I just lost it and it would take a few houres to > repeat the situation. Sorry. > > >> >> you have filenames that are not valid UTF-8 on your harddisk. >> >> A possible fix would be to use bytes instead of str. For that you need to >> open `bashfilename` in binary mode ("wb") and pass bytes to the os.walk() >> call. > This is my 1st time with python3, so I am confused! > > As much I could understand it seems that os.walk is returning the > filenames exactly as they are on disk. Just bytes like in C. No, they are decoded with the preferred encoding. With UTF-8 that can fail, and if it does the surrogateescape error handler replaces the offending bytes with special codepoints: >>> import os >>> with open(b"\xe4\xf6\xfc", "w") as f: f.write("whatever") ... 8 >>> os.listdir() ['\udce4\udcf6\udcfc'] You can bypass the decoding process by providing a bytes argument to os.listdir() (or os.walk() which uses os.listdir() internally): >>> os.listdir(b".") [b'\xe4\xf6\xfc'] To write these raw bytes into a file the file has of course to be binary, too. > My template is a string. What is the result of the replace command? Is > there any change in the filename from os.walk contents? > > Now, if the result of the replace has the replaced filename unchanged > how do I "convert" it to bytes type, without changing its contents, so > that I can write to the bashfile opened with "wb"? > > >> >> Or you just go and fix the offending names. > This is impossible in my case. > I need a bash script with the names as they are on disk. I think instead of the hard way sketched out above it will be sufficient to specify the error handler when opening the destination file shf = open(bashfilename, 'w', errors="surrogateescape") but I have not tried it myself. Also, some bytes may need to be escaped, either to be understood by the shell, or to address security concerns: >>> import os >>> template = "ls " >>> for filename in os.listdir(): ... print(template.replace("", filename)) ... ls foo; rm bar From invalid at invalid.invalid Sun Jan 12 13:53:48 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 12 Jan 2014 18:53:48 +0000 (UTC) Subject: Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined? References: <18b67e59-39d1-41e2-8977-b1c449b132e7@googlegroups.com> Message-ID: On 2014-01-11, pintreo mardi wrote: > Hi, I've just begun to learn programming, I have an open question for > the group: Is the Python language an all in one computer language > which could replace C, C++, Java etc.. No. Python can not replace C in a number of application areas: * Bare-metal applications without an OS. * Low-resource applications with limited memory (like a few KB). * Device driver and kernel modules for OSes like Linux, Unix, (and, AFAIK, Windows). * Computationally intensive applications where there isn't a library available written C or FORTRAN to do the heavy lifting. For general application programming on a server or PC, then Python can replace many/most uses of C/C++/Java. -- Grant Edwards grant.b.edwards Yow! Look into my eyes and at try to forget that you have gmail.com a Macy's charge card! From larry.martell at gmail.com Sun Jan 12 14:23:17 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Jan 2014 14:23:17 -0500 Subject: efficient way to process data Message-ID: I have an python app that queries a MySQL DB. The query has this form: SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f FROM t GROUP BY a, b, c, d, f x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or 10053.490, 2542.094). The business issue is that if either x or y in 2 rows that are in the same a, b, c, d group are within 1 of each other then they should be grouped together. And to make it more complicated, the tolerance is applied as a rolling continuum. For example, if the x and y in a set of grouped rows are: row 1: 1.5, 9.5 row 2: 2.4, 20.8 row 3: 3.3, 40.6 row 4: 4.2, 2.5 row 5: 5.1, 10.1 row 6: 6.0, 7.9 row 7: 8.0, 21.0 row 8: 100, 200 1 through 6 get combined because all their X values are within the tolerance of some other X in the set that's been combined. 7's Y value is within the tolerance of 2's Y, so that should be combined as well. 8 is not combined because neither the X or Y value is within the tolerance of any X or Y in the set that was combined. AFAIK, there is no way to do this in SQL. In python I can easily parse the data and identify the rows that need to be combined, but then I've lost the ability to calculate the average and std across the combined data set. The only way I can think of to do this is to remove the grouping from the SQL and do all the grouping and aggregating myself. But this query often returns 20k to 30k rows after grouping. It could easily be 80k to 100k rows or more that I have to process if I remove the grouping and I think that will end up being very slow. Anyone have any ideas how I can efficiently do this? Thanks! -larry From jaiprakashsingh213 at gmail.com Sun Jan 12 09:10:44 2014 From: jaiprakashsingh213 at gmail.com (JAI PRAKASH SINGH) Date: Sun, 12 Jan 2014 19:40:44 +0530 Subject: python query on firebug extention Message-ID: hello i am working on selenium module of python, i know how to make extension of firebug with selenium, but i want to know how to use firebug extension with request module / mechanize . i search a lot but unable to find it , please help . i want technique similar like :- from selenium import webdriver fp = webdriver.FirefoxProfile() fp.add_extension(extension='firebug-.8.4.xpi') fp.set_preference("extensions.firebug.currentVersion", "1.8.4") browser = webdriver.Firefox(firefox_profile=fp) in request module or mechanize module From p_s_d_a_s_i_l_v_a at netcabo.pt Sun Jan 12 14:41:01 2014 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Sun, 12 Jan 2014 19:41:01 +0000 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: > > I think instead of the hard way sketched out above it will be sufficient to > specify the error handler when opening the destination file > > shf = open(bashfilename, 'w', errors="surrogateescape") This seems to fix everything! I tried with a small test set and it worked. > > but I have not tried it myself. Also, some bytes may need to be escaped, > either to be understood by the shell, or to address security concerns: > Since I am puting the file names between "", the only char that needs to be escaped is the " itself. I'm gonna try with the real thing. Thank you very much for the fixing and for everything I have learned here. From petite.abeille at gmail.com Sun Jan 12 14:53:02 2014 From: petite.abeille at gmail.com (Petite Abeille) Date: Sun, 12 Jan 2014 20:53:02 +0100 Subject: efficient way to process data In-Reply-To: References: Message-ID: <101148D9-DACE-4572-801D-3DDB4A215BF9@gmail.com> On Jan 12, 2014, at 8:23 PM, Larry Martell wrote: > AFAIK, there is no way to do this in SQL. Sounds like a job for window functions (aka analytic functions) [1][2]. [1] http://www.postgresql.org/docs/9.3/static/tutorial-window.html [2] http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174 From __peter__ at web.de Sun Jan 12 15:29:54 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 12 Jan 2014 21:29:54 +0100 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Paulo da Silva wrote: >> but I have not tried it myself. Also, some bytes may need to be escaped, >> either to be understood by the shell, or to address security concerns: >> > > Since I am puting the file names between "", the only char that needs to > be escaped is the " itself. What about the escape char? From tjreedy at udel.edu Sun Jan 12 15:51:06 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 12 Jan 2014 15:51:06 -0500 Subject: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' In-Reply-To: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> References: <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com> Message-ID: On 1/12/2014 7:17 AM, KMeans Algorithm wrote: > But I get a "404" error (Not Found). The page "https://www.mysite.com/loginpage" does exist Firefox tells me the same thing. If that is a phony address, you should have said so. -- Terry Jan Reedy From rosuav at gmail.com Sun Jan 12 17:18:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 09:18:42 +1100 Subject: efficient way to process data In-Reply-To: <101148D9-DACE-4572-801D-3DDB4A215BF9@gmail.com> References: <101148D9-DACE-4572-801D-3DDB4A215BF9@gmail.com> Message-ID: On Mon, Jan 13, 2014 at 6:53 AM, Petite Abeille wrote: > On Jan 12, 2014, at 8:23 PM, Larry Martell wrote: > >> AFAIK, there is no way to do this in SQL. > > Sounds like a job for window functions (aka analytic functions) [1][2]. That's my thought too. I don't think MySQL has them, though, so it's either going to have to be done in Python, or the database back-end will need to change. Hard to say which would be harder. ChrisA From denismfmcmahon at gmail.com Sun Jan 12 18:16:43 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 12 Jan 2014 23:16:43 +0000 (UTC) Subject: Python example source code References: Message-ID: On Sun, 12 Jan 2014 06:37:18 -0800, ngangsia akumbo wrote: > where can i find example source code by topic? > Any help please You don't want to be looking at source code yet, you want to be talking to the users of the system you're trying to design to find out what their requirements are. -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Sun Jan 12 18:27:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 10:27:02 +1100 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Mon, Jan 13, 2014 at 6:23 AM, Larry Martell wrote: > I have an python app that queries a MySQL DB. The query has this form: > > SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f > FROM t > GROUP BY a, b, c, d, f > > x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or > 10053.490, 2542.094). > > The business issue is that if either x or y in 2 rows that are in the > same a, b, c, d group are within 1 of each other then they should be > grouped together. And to make it more complicated, the tolerance is > applied as a rolling continuum. For example, if the x and y in a set > of grouped rows are: > > row 1: 1.5, 9.5 > row 2: 2.4, 20.8 > row 3: 3.3, 40.6 > row 4: 4.2, 2.5 > row 5: 5.1, 10.1 > row 6: 6.0, 7.9 > row 7: 8.0, 21.0 > row 8: 100, 200 > > 1 through 6 get combined because all their X values are within the > tolerance of some other X in the set that's been combined. 7's Y value > is within the tolerance of 2's Y, so that should be combined as well. > 8 is not combined because neither the X or Y value is within the > tolerance of any X or Y in the set that was combined. Trying to get my head around this a bit more. Are columns a/b/c/d treated as a big category (eg type, brand, category, model), such that nothing will ever be grouped that has any difference in those four columns? If so, we can effectively ignore them and pretend we have a table with exactly one set (eg stick a WHERE clause onto the query that stipulates their values). Then what you have is this: * Aggregate based on proximity of x and y * Emit results derived from e Is that correct? So here's my way of writing it. * Subselect: List all values for x, in order, and figure out which ones are less than the previous value plus one * Subselect: Ditto, for y. * Outer select: Somehow do an either-or group. I'm not quite sure how to do that part, actually! A PGSQL window function would cover the two subselects - at least, I'm fairly sure it would. I can't quite get the whole thing, though; I can get a true/false flag that says whether it's near to the previous one (that's easy), and creating a grouping column value should be possible from that but I'm not sure how. But an either-or grouping is a bit trickier. The best I can think of is to collect all the y values for each group of x values, and then if any two groups 'overlap' (ie have points within 1.0 of each other), merge the groups. That's going to be seriously tricky to do in SQL, I think, so you may have to go back to Python on that one. My analysis suggests that, whatever happens, you're going to need every single y value somewhere. So it's probably not worth trying to do any grouping/aggregation in SQL, since you need to further analyze all the individual data points. I can't think of any way better than just leafing through the whole table (either in Python or in a stored procedure - if you can run your script on the same computer that's running the database, I'd do that, otherwise consider a stored procedure to reduce network transfers) and building up mappings. Of course, "I can't think of a way" does not equate to "There is no way". There may be some magic trick that I didn't think of, or some arcane incantation that gets what you want. Who knows? If you can produce an ASCII art Mandelbrot set [1] in pure SQL, why not this! ChrisA [1] http://wiki.postgresql.org/wiki/Mandelbrot_set From p_s_d_a_s_i_l_v_a at netcabo.pt Sun Jan 12 18:53:37 2014 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Sun, 12 Jan 2014 23:53:37 +0000 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Em 12-01-2014 20:29, Peter Otten escreveu: > Paulo da Silva wrote: > >>> but I have not tried it myself. Also, some bytes may need to be escaped, >>> either to be understood by the shell, or to address security concerns: >>> >> >> Since I am puting the file names between "", the only char that needs to >> be escaped is the " itself. > > What about the escape char? > Just this fn=fn.replace('"','\\"') So far I didn't find any problem, but the script is still running. From larry.martell at gmail.com Sun Jan 12 22:17:09 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Jan 2014 22:17:09 -0500 Subject: efficient way to process data In-Reply-To: <101148D9-DACE-4572-801D-3DDB4A215BF9@gmail.com> References: <101148D9-DACE-4572-801D-3DDB4A215BF9@gmail.com> Message-ID: On Sun, Jan 12, 2014 at 2:53 PM, Petite Abeille wrote: > > On Jan 12, 2014, at 8:23 PM, Larry Martell wrote: > >> AFAIK, there is no way to do this in SQL. > > Sounds like a job for window functions (aka analytic functions) [1][2]. > > [1] http://www.postgresql.org/docs/9.3/static/tutorial-window.html > [2] http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions004.htm#SQLRF06174 Unfortunately, MySQL does not support this. From larry.martell at gmail.com Sun Jan 12 22:18:22 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Jan 2014 22:18:22 -0500 Subject: efficient way to process data In-Reply-To: References: <101148D9-DACE-4572-801D-3DDB4A215BF9@gmail.com> Message-ID: On Sun, Jan 12, 2014 at 5:18 PM, Chris Angelico wrote: > On Mon, Jan 13, 2014 at 6:53 AM, Petite Abeille > wrote: >> On Jan 12, 2014, at 8:23 PM, Larry Martell wrote: >> >>> AFAIK, there is no way to do this in SQL. >> >> Sounds like a job for window functions (aka analytic functions) [1][2]. > > That's my thought too. I don't think MySQL has them, though, so it's > either going to have to be done in Python, or the database back-end > will need to change. Hard to say which would be harder. Changing the database is not feasible. From larry.martell at gmail.com Sun Jan 12 22:25:57 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Jan 2014 22:25:57 -0500 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Sun, Jan 12, 2014 at 5:43 PM, Dennis Lee Bieber wrote: > On Sun, 12 Jan 2014 14:23:17 -0500, Larry Martell > declaimed the following: > >>I have an python app that queries a MySQL DB. The query has this form: >> >>SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f >>FROM t >>GROUP BY a, b, c, d, f >> >>x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or >>10053.490, 2542.094). >> > > Decimal (Numeric) or floating/real. If the latter, the internal storage > may not be exact (378.1811111111 and 378.179999999 may both "display" as > 378.18, but will not match for grouping). In the database they are decimal. They are being converted to char by the CONCAT(x, ',', y). >>The business issue is that if either x or y in 2 rows that are in the >>same a, b, c, d group are within 1 of each other then they should be >>grouped together. And to make it more complicated, the tolerance is >>applied as a rolling continuum. For example, if the x and y in a set >>of grouped rows are: >> > As I understand group by, it will first group by "a", WITHIN the "a" > groups it will then group by "b"... Probably not a matter germane to the > problem as you are concerning yourself with the STRING representation of > "x" and "y" with a comma delimiter -- which is only looked at if the > "a,b,c,d" are equal... Thing is, a string comparison is going to operate > strictly left to right -- it won't even see your "y" value unless all the > "x" value is equal. Yes, that is correct. The original requirement was to group by (X, Y), so the CONCAT(x, ',', y) was correct and working. Then the requirement was change to apply the tolerance as I described. > > You may need to operate using subselects... So that you can specify > something like > > where abs(s1.x -s2.x) < tolerance or abs(s1.y-s2.y) < tolerance > and (s1.a = s2.a ... s1.d = s2.d) > > s1/s1 are the subselects (you may need a primary key <> primary key to > avoid having it output a record where the two subselects are for the SAME > record -- or maybe not, since you /do/ want that record also output). Going > to be a costly query since you are basically doing > > foreach r1 in s1 > foreach r2 in s2 > emit r2 when... Speed is an issue here, and while the current query performs well, in my experience subqueries and self joins do not. I'm going to try and do it all in python and see how it performs. The other option is to pre-process the data on the way into the database. Doing that will eliminate some of the data partitioning as all of the data that could be joined will be in the same input file. I'm just not sure if it will OK to actually munge the data. I'll find that out tomorrow. From larry.martell at gmail.com Sun Jan 12 22:35:47 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 12 Jan 2014 22:35:47 -0500 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Sun, Jan 12, 2014 at 6:27 PM, Chris Angelico wrote: > On Mon, Jan 13, 2014 at 6:23 AM, Larry Martell wrote: >> I have an python app that queries a MySQL DB. The query has this form: >> >> SELECT a, b, c, d, AVG(e), STD(e), CONCAT(x, ',', y) as f >> FROM t >> GROUP BY a, b, c, d, f >> >> x and y are numbers (378.18, 2213.797 or 378.218, 2213.949 or >> 10053.490, 2542.094). >> >> The business issue is that if either x or y in 2 rows that are in the >> same a, b, c, d group are within 1 of each other then they should be >> grouped together. And to make it more complicated, the tolerance is >> applied as a rolling continuum. For example, if the x and y in a set >> of grouped rows are: >> >> row 1: 1.5, 9.5 >> row 2: 2.4, 20.8 >> row 3: 3.3, 40.6 >> row 4: 4.2, 2.5 >> row 5: 5.1, 10.1 >> row 6: 6.0, 7.9 >> row 7: 8.0, 21.0 >> row 8: 100, 200 >> >> 1 through 6 get combined because all their X values are within the >> tolerance of some other X in the set that's been combined. 7's Y value >> is within the tolerance of 2's Y, so that should be combined as well. >> 8 is not combined because neither the X or Y value is within the >> tolerance of any X or Y in the set that was combined. > > Trying to get my head around this a bit more. Are columns a/b/c/d > treated as a big category (eg type, brand, category, model), such that > nothing will ever be grouped that has any difference in those four > columns? If so, we can effectively ignore them and pretend we have a > table with exactly one set (eg stick a WHERE clause onto the query > that stipulates their values). Then what you have is this: > > * Aggregate based on proximity of x and y > * Emit results derived from e > > Is that correct? There will be multiple groups of a/b/c/d. I simplified the query for the purposes of posting my question. There is a where clause with values that come from user input. None, any, or all of a, b, c, or d could be in the where clause. > So here's my way of writing it. > > * Subselect: List all values for x, in order, and figure out which > ones are less than the previous value plus one > * Subselect: Ditto, for y. > * Outer select: Somehow do an either-or group. I'm not quite sure how > to do that part, actually! > > A PGSQL window function would cover the two subselects - at least, I'm > fairly sure it would. I can't quite get the whole thing, though; I can > get a true/false flag that says whether it's near to the previous one > (that's easy), and creating a grouping column value should be possible > from that but I'm not sure how. > > But an either-or grouping is a bit trickier. The best I can think of > is to collect all the y values for each group of x values, and then if > any two groups 'overlap' (ie have points within 1.0 of each other), > merge the groups. That's going to be seriously tricky to do in SQL, I > think, so you may have to go back to Python on that one. > > My analysis suggests that, whatever happens, you're going to need > every single y value somewhere. So it's probably not worth trying to > do any grouping/aggregation in SQL, since you need to further analyze > all the individual data points. I can't think of any way better than > just leafing through the whole table (either in Python or in a stored > procedure - if you can run your script on the same computer that's > running the database, I'd do that, otherwise consider a stored > procedure to reduce network transfers) and building up mappings. > > Of course, "I can't think of a way" does not equate to "There is no > way". There may be some magic trick that I didn't think of, or some > arcane incantation that gets what you want. Who knows? If you can > produce an ASCII art Mandelbrot set [1] in pure SQL, why not this! > > ChrisA > > [1] http://wiki.postgresql.org/wiki/Mandelbrot_set Thanks for the reply. I'm going to take a stab at removing the group by and doing it all in python. It doesn't look too hard, but I don't know how it will perform. From rosuav at gmail.com Mon Jan 13 01:09:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 17:09:59 +1100 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell wrote: > Thanks for the reply. I'm going to take a stab at removing the group > by and doing it all in python. It doesn't look too hard, but I don't > know how it will perform. Well, if you can't switch to PostgreSQL or such, then doing it in Python is your only option. There are such things as GiST and GIN indexes that might be able to do some of this magic, but I don't think MySQL has anything even remotely like what you're looking for. So ultimately, you're going to have to do your filtering on the database, and then all the aggregation in Python. And it's going to be somewhat complicated code, too. Best I can think of is this, as partial pseudo-code: last_x = -999 x_map = []; y_map = {} merge_me = [] for x,y,e in (SELECT x,y,e FROM t WHERE whatever ORDER BY x): if x Message-ID: <52d394ad$0$29874$c3e8da3$5496439d@news.astraweb.com> On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote: > As part of speech recognition accessibility tools that I'm building, I'm > using string.Template. In order to construct on-the-fly grammar, I need > to know all of the identifiers before the template is filled in. what is > the best way to do this? py> import string py> t = string.Template("$sub some $text $here") py> t.template '$sub some $text $here' Now just walk the template for $ signs. Watch out for $$ which escapes the dollar sign. Here's a baby parser: def get_next(text, start=0): while True: i = text.find("$", start) if i == -1: return if text[i:i+2] == '$$': start += i continue j = text.find(' ', i) if j == -1: j = len(text) assert i < j return (text[i:j], j) start = 0 while start < len(t.template): word, start = get_next(t.template, start) print(word) > can string.Template handle recursive expansion i.e. an identifier > contains a template. If you mean, recursive expand the template until there's nothing left to substitute, then no, not directly. You would have to manually expand the template yourself. -- Steven From norman.elliott at gmail.com Mon Jan 13 03:15:08 2014 From: norman.elliott at gmail.com (norman.elliott at gmail.com) Date: Mon, 13 Jan 2014 00:15:08 -0800 (PST) Subject: plotting slows down Message-ID: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> First let me say I have not done much python programming! I am running Python 2.7.3. I am trying to use python as a front end to a simple oscilloscope. Ultimately I intend to use it with my micropython board. At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data. Each time it goes through the outer loop it gets slower and slower. I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds. Can anyone explain what I am doing wrong please? Here is the code: [code] #!/usr/bin/python from graphics import * import random import time xpos=1200 ypos=400 ypnt=ypos/2 pos=1 #setBackground("white") def main(): win = GraphWin("My Circle", xpos, ypos) # win.setBackGround('white') for y in range(1,5): cir2 = Circle(Point(xpos/2,20), 10) cir2.setFill("white") cir2.draw(win) message = Text(Point(win.getWidth()/2, 20), y) message.draw(win) j = random.randint(1,ypos) for x in range(1,xpos): updown = random.randint(0,1) if updown: j=j+1 else: j=j-1 if j <1: j=ypos/2 if j>ypos-1: j=ypos/2 win.plot(x,j,"red") time.sleep(.0001) main() time.sleep(5) [/code] From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jan 13 03:27:46 2014 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 13 Jan 2014 09:27:46 +0100 Subject: =?ISO-8859-1?Q?=27Stra=DFe=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: Am 12.01.2014 08:50 schrieb wxjmfauth at gmail.com: >>>> sys.version > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>> s = 'Stra?e' >>>> assert len(s) == 6 >>>> assert s[5] == 'e' >>>> Wow. You just found one of the major differences between Python 2 and 3. Your assertins are just wrong, as s = 'Stra?e' leads - provided you use UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a length of 7. Thomas From __peter__ at web.de Mon Jan 13 03:48:26 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 13 Jan 2014 09:48:26 +0100 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Paulo da Silva wrote: > Em 12-01-2014 20:29, Peter Otten escreveu: >> Paulo da Silva wrote: >> >>>> but I have not tried it myself. Also, some bytes may need to be >>>> escaped, either to be understood by the shell, or to address security >>>> concerns: >>>> >>> >>> Since I am puting the file names between "", the only char that needs to >>> be escaped is the " itself. >> >> What about the escape char? >> > Just this fn=fn.replace('"','\\"') > > So far I didn't find any problem, but the script is still running. To be a bit more explicit: >>> for filename in os.listdir(): ... print(template.replace("", filename.replace('"', '\\"'))) ... ls "\\"; rm whatever; ls \" From __peter__ at web.de Mon Jan 13 03:58:48 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 13 Jan 2014 09:58:48 +0100 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Peter Otten wrote: > Paulo da Silva wrote: > >> Em 12-01-2014 20:29, Peter Otten escreveu: >>> Paulo da Silva wrote: >>> >>>>> but I have not tried it myself. Also, some bytes may need to be >>>>> escaped, either to be understood by the shell, or to address security >>>>> concerns: >>>>> >>>> >>>> Since I am puting the file names between "", the only char that needs >>>> to be escaped is the " itself. >>> >>> What about the escape char? >>> >> Just this fn=fn.replace('"','\\"') >> >> So far I didn't find any problem, but the script is still running. > > To be a bit more explicit: > >>>> for filename in os.listdir(): > ... print(template.replace("", filename.replace('"', '\\"'))) > ... > ls "\\"; rm whatever; ls \" The complete session: >>> import os >>> template = 'ls ""' >>> with open('\\"; rm whatever; ls \\', "w") as f: pass ... >>> for filename in os.listdir(): ... print(template.replace("", filename.replace('"', '\\"'))) ... ls "\\"; rm whatever; ls \" Shell variable substitution is another problem. c.l.py is probably not the best place to get the complete list of possibilities. From gandalf at shopzeus.com Mon Jan 13 04:00:46 2014 From: gandalf at shopzeus.com (Laszlo Nagy) Date: Mon, 13 Jan 2014 10:00:46 +0100 Subject: L[:] In-Reply-To: References: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> Message-ID: <52D3AB3E.6050206@shopzeus.com> > Unless L is aliased, this is silly code. There is another use case. If you intend to modify a list within a for loop that goes over the same list, then you need to iterate over a copy. And this cannot be called an "alias" because it has no name: for idx,item in enumerate(L[:]): # do something with L here, including modification -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. From wxjmfauth at gmail.com Mon Jan 13 04:54:21 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 13 Jan 2014 01:54:21 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6ICdTdHJh32UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: Le lundi 13 janvier 2014 09:27:46 UTC+1, Thomas Rachel a ?crit?: > Am 12.01.2014 08:50 schrieb wxjmfauth at gmail.com: > > >>>> sys.version > > > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] > > >>>> s = 'Stra???e' > > >>>> assert len(s) == 6 > > >>>> assert s[5] == 'e' > > >>>> > > > > Wow. You just found one of the major differences between Python 2 and 3. > > > > Your assertins are just wrong, as s = 'Stra???e' leads - provided you use > > UTF8 - to a representation of 'Stra\xc3\x9fe', obviously leading to a > > length of 7. > > Not at all. I'm afraid I'm understanding Python (on this aspect very well). Do you belong to this group of people who are naively writing wrong Python code (usually not properly working) during more than a decade? '?' is the the fourth character in that text "Stra?e" (base index 0). This assertions are correct (byte string and unicode). >>> sys.version '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>> assert 'Stra?e'[4] == '?' >>> assert u'Stra?e'[4] == u'?' >>> jmf PS Nothing to do with Py2/Py3. From mhysnm1964 at gmail.com Mon Jan 13 05:05:21 2014 From: mhysnm1964 at gmail.com (Sean Murphy) Date: Mon, 13 Jan 2014 21:05:21 +1100 Subject: Module depositary Message-ID: <508F8651-CCB9-4EB0-A4EC-70AD3AAEB46B@gmail.com> Hi All. I am aware that active state python has a commercial module depositary which you can get modules from. Under PERL you had CPAN. Is there anything like this for Python? Sean From rosuav at gmail.com Mon Jan 13 05:24:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 21:24:44 +1100 Subject: Module depositary In-Reply-To: <508F8651-CCB9-4EB0-A4EC-70AD3AAEB46B@gmail.com> References: <508F8651-CCB9-4EB0-A4EC-70AD3AAEB46B@gmail.com> Message-ID: On Mon, Jan 13, 2014 at 9:05 PM, Sean Murphy wrote: > Hi All. > > I am aware that active state python has a commercial module depositary which you can get modules from. Under PERL you had CPAN. Is there anything like this for Python? Check out the Python Package Index: https://pypi.python.org/pypi It's not commercial, and (as far as I know) there's no curating of projects, so you need to make your own decision about what you trust and how you handle version dependencies. There are easy and convenient ways to install packages, most notably pip (which is mentioned on the landing page). ChrisA From rosuav at gmail.com Mon Jan 13 05:26:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 21:26:01 +1100 Subject: =?UTF-8?B?UmU6ICdTdHJhw59lJyAoJ1N0cmFzc2UnKSBhbmQgUHl0aG9uIDI=?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: On Mon, Jan 13, 2014 at 8:54 PM, wrote: > This assertions are correct (byte string and unicode). > >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> assert 'Stra?e'[4] == '?' >>>> assert u'Stra?e'[4] == u'?' >>>> > > jmf > > PS Nothing to do with Py2/Py3. This means that either your source encoding happens to include that character, or you have assertions disabled. It does NOT mean that you can rely on writing this string out to a file and having someone else read it in and understand it the same way. ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 13 05:38:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 13 Jan 2014 10:38:03 GMT Subject: =?iso-8859-1?q?'Stra=DFe'?= ('Strasse') and Python 2 References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: <52d3c20b$0$29970$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jan 2014 01:54:21 -0800, wxjmfauth wrote: >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> assert 'Stra?e'[4] == '?' >>>> assert u'Stra?e'[4] == u'?' I think you are using "from __future__ import unicode_literals". Otherwise, that cannot happen in Python 2.x. Using a narrow build: # on my machine "ando" py> sys.version '2.7.2 (default, May 18 2012, 18:25:10) \n[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)]' py> sys.maxunicode 65535 py> assert 'Stra?e'[4] == '?' Traceback (most recent call last): File "", line 1, in AssertionError py> list('Stra?e') ['S', 't', 'r', 'a', '\xc3', '\x9f', 'e'] Using a wide build is the same: # on my machine "orac" >>> sys.maxunicode 1114111 >>> assert 'Stra?e'[4] == '?' Traceback (most recent call last): File "", line 1, in AssertionError But once you run the "from __future__" line, the behaviour changes to what you show: py> from __future__ import unicode_literals py> list('Stra?e') [u'S', u't', u'r', u'a', u'\xdf', u'e'] py> assert 'Stra?e'[4] == '?' py> But I still don't understand the point you are trying to make. -- Steven From rosuav at gmail.com Mon Jan 13 05:57:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 13 Jan 2014 21:57:28 +1100 Subject: =?UTF-8?B?UmU6ICdTdHJhw59lJyAoJ1N0cmFzc2UnKSBhbmQgUHl0aG9uIDI=?= In-Reply-To: <52d3c20b$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52d3c20b$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 13, 2014 at 9:38 PM, Steven D'Aprano wrote: > I think you are using "from __future__ import unicode_literals". > Otherwise, that cannot happen in Python 2.x. > Alas, not true. >>> sys.version '2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]' >>> sys.maxunicode 65535 >>> assert 'Stra?e'[4] == '?' >>> list('Stra?e') ['S', 't', 'r', 'a', '\xdf', 'e'] That's Windows XP. Presumably Latin-1 (or CP-1252, they both have that char at 0xDF). He happens to be correct, *as long as the source code encoding matches the output encoding and is one that uses 0xDF to mean U+00DF*. Otherwise, he's not. ChrisA From davea at davea.name Mon Jan 13 08:26:11 2014 From: davea at davea.name (Dave Angel) Date: Mon, 13 Jan 2014 08:26:11 -0500 (EST) Subject: plotting slows down References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: norman.elliott at gmail.com Wrote in message: > First let me say I have not done much python programming! > I am running Python 2.7.3. > I am trying to use python as a front end to a simple oscilloscope. > Ultimately I intend to use it with my micropython board. > > At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data. > > Each time it goes through the outer loop it gets slower and slower. > I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds. > Can anyone explain what I am doing wrong please? > Here is the code: > [code] > #!/usr/bin/python > from graphics import * First things first. what operating system are you using, and where did you get the mysterious graphics. py? Thanks for telling us python 2.7.3 Next, please repost any source code with indentation preserved. Your message shows it all flushed to the left margin, probably due to posting in html mode. Use text mode here. Finally, since you seem to be using googlegroups, please make sure you don't double space your quotes. See. wiki.python.org/moi n/GoogleGroupsPython > -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From norman.elliott at gmail.com Mon Jan 13 08:32:19 2014 From: norman.elliott at gmail.com (Norman Elliott) Date: Mon, 13 Jan 2014 05:32:19 -0800 (PST) Subject: plotting slows down In-Reply-To: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: <3e0dcc90-a45f-4025-9cea-cf3c3f964178@googlegroups.com> On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott wrote: > First let me say I have not done much python programming! > > I am running Python 2.7.3. > > I am trying to use python as a front end to a simple oscilloscope. > > Ultimately I intend to use it with my micropython board. > > > > At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data. > > > > Each time it goes through the outer loop it gets slower and slower. > > I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds. > > Can anyone explain what I am doing wrong please? > > Here is the code: > > [code] > > #!/usr/bin/python > > from graphics import * > > import random > > import time > > > > xpos=1200 > > ypos=400 > > ypnt=ypos/2 > > pos=1 > > #setBackground("white") > > def main(): > > win = GraphWin("My Circle", xpos, ypos) > > # win.setBackGround('white') > > for y in range(1,5): > > cir2 = Circle(Point(xpos/2,20), 10) > > cir2.setFill("white") > > cir2.draw(win) > > message = Text(Point(win.getWidth()/2, 20), y) > > message.draw(win) > > j = random.randint(1,ypos) > > for x in range(1,xpos): > > updown = random.randint(0,1) > > if updown: > > j=j+1 > > else: > > j=j-1 > > if j <1: > > j=ypos/2 > > if j>ypos-1: > > j=ypos/2 > > win.plot(x,j,"red") > > time.sleep(.0001) > > > > main() > > time.sleep(5) > > [/code] From norman.elliott at gmail.com Mon Jan 13 08:45:03 2014 From: norman.elliott at gmail.com (Norman Elliott) Date: Mon, 13 Jan 2014 05:45:03 -0800 (PST) Subject: plotting slows down In-Reply-To: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: <00281afe-0a5e-4d9a-92ce-c341bbcf9331@googlegroups.com> I am running ubuntu 12.04 with all updates installed. I got the graphics here: http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html I cannot see how to change from html to text mode in chromium or within the group. I read the link about double spacing so I will watch out for it. From ndbecker2 at gmail.com Mon Jan 13 09:47:44 2014 From: ndbecker2 at gmail.com (Neal Becker) Date: Mon, 13 Jan 2014 09:47:44 -0500 Subject: proposal: bring nonlocal to py2.x Message-ID: py3 includes a fairly compelling feature: nonlocal keywork But backward compatibility is lost. It would be very helpful if this was available on py2.x. From rosuav at gmail.com Mon Jan 13 09:55:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 01:55:36 +1100 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: On Tue, Jan 14, 2014 at 1:47 AM, Neal Becker wrote: > py3 includes a fairly compelling feature: nonlocal keywork > But backward compatibility is lost. It would be very helpful > if this was available on py2.x. Python 2.x is no longer being developed. It won't be gaining features like this. Use the nonlocal feature as a reason for migrating to Python 3 :) ChrisA From g.rodola at gmail.com Mon Jan 13 10:12:53 2014 From: g.rodola at gmail.com (Giampaolo Rodola') Date: Mon, 13 Jan 2014 16:12:53 +0100 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker wrote: > py3 includes a fairly compelling feature: nonlocal keywork > But backward compatibility is lost. It would be very helpful > if this was available on py2.x. > > -- > https://mail.python.org/mailman/listinfo/python-list > It's not gonna happens as per PEP-404: http://www.python.org/dev/peps/pep-0404/ -- Giampaolo - http://grodola.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From breamoreboy at yahoo.co.uk Mon Jan 13 10:24:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Jan 2014 15:24:01 +0000 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: On 13/01/2014 15:12, Giampaolo Rodola' wrote: > > On Mon, Jan 13, 2014 at 3:47 PM, Neal Becker > wrote: > > py3 includes a fairly compelling feature: nonlocal keywork > But backward compatibility is lost. It would be very helpful > if this was available on py2.x. > > It's not gonna happens as per PEP-404: > http://www.python.org/dev/peps/pep-0404/ > But it could theoretically happen if Neal wants it so badly that he raises an issue on the bug tracker against Python 2.7, finds all the relevant source code in Python 3, back ports it, modifies all the relevant docs and unit tests, then finds some warm hearted person to commit the changes. Five minute job. Simples :) -- 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 Mon Jan 13 10:28:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 02:28:47 +1100 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: On Tue, Jan 14, 2014 at 2:24 AM, Mark Lawrence wrote: > But it could theoretically happen if Neal wants it so badly that he raises > an issue on the bug tracker against Python 2.7, finds all the relevant > source code in Python 3, back ports it, modifies all the relevant docs and > unit tests, then finds some warm hearted person to commit the changes. Five > minute job. Simples :) It's even worse than that, because adding 'nonlocal' is not a bugfix. So to be committed to the repo, it has to be approved for either 2.7 branch (which is in bugfix-only maintenance mode) or 2.8 branch (which does not exist). Good luck. :) ChrisA From breamoreboy at yahoo.co.uk Mon Jan 13 10:33:53 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Jan 2014 15:33:53 +0000 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: On 13/01/2014 15:28, Chris Angelico wrote: > On Tue, Jan 14, 2014 at 2:24 AM, Mark Lawrence wrote: >> But it could theoretically happen if Neal wants it so badly that he raises >> an issue on the bug tracker against Python 2.7, finds all the relevant >> source code in Python 3, back ports it, modifies all the relevant docs and >> unit tests, then finds some warm hearted person to commit the changes. Five >> minute job. Simples :) > > It's even worse than that, because adding 'nonlocal' is not a bugfix. > So to be committed to the repo, it has to be approved for either 2.7 > branch (which is in bugfix-only maintenance mode) or 2.8 branch (which > does not exist). Good luck. :) > > ChrisA > Then target the 2.8 fork that will take place if there's no agreement over PEP 460. Still a five minute job, still simples :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From torriem at gmail.com Mon Jan 13 10:58:50 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 13 Jan 2014 08:58:50 -0700 Subject: =?ISO-8859-1?Q?=27Stra=DFe=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: <52D40D3A.8090609@gmail.com> On 01/13/2014 02:54 AM, wxjmfauth at gmail.com wrote: > Not at all. I'm afraid I'm understanding Python (on this > aspect very well). Are you sure about that? Seems to me you're still confused as to the difference between unicode and encodings. > > Do you belong to this group of people who are naively > writing wrong Python code (usually not properly working) > during more than a decade? > > '?' is the the fourth character in that text "Stra?e" > (base index 0). > > This assertions are correct (byte string and unicode). How can they be? They only are true for the default encoding and character set you are using, which happens to have '?' as a single byte. Hence your little python 2.7 snippet is not using unicode at all, in any form. It's using a non-unicode character set. There are methods which can decode your character set to unicode and encode from unicode. But let's be clear. Your byte streams are not unicode! If the default byte encoding is UTF-8, which is a variable number of bytes per character, your assertions are completely wrong. Maybe it's time you stopped programming in Windows and use OS X or Linux which throw out the random single-byte character sets and instead provide a UTF-8 terminal environment to support non-latin characters. > >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> assert 'Stra?e'[4] == '?' >>>> assert u'Stra?e'[4] == u'?' >>>> > > jmf > > PS Nothing to do with Py2/Py3. From p_s_d_a_s_i_l_v_a at netcabo.pt Mon Jan 13 11:14:20 2014 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Mon, 13 Jan 2014 16:14:20 +0000 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Em 13-01-2014 08:58, Peter Otten escreveu: > Peter Otten wrote: > >> Paulo da Silva wrote: >> >>> Em 12-01-2014 20:29, Peter Otten escreveu: >>>> Paulo da Silva wrote: >>>> >>>>>> but I have not tried it myself. Also, some bytes may need to be >>>>>> escaped, either to be understood by the shell, or to address security >>>>>> concerns: >>>>>> >>>>> >>>>> Since I am puting the file names between "", the only char that needs >>>>> to be escaped is the " itself. >>>> >>>> What about the escape char? >>>> >>> Just this fn=fn.replace('"','\\"') >>> >>> So far I didn't find any problem, but the script is still running. >> >> To be a bit more explicit: >> >>>>> for filename in os.listdir(): >> ... print(template.replace("", filename.replace('"', '\\"'))) >> ... >> ls "\\"; rm whatever; ls \" > > The complete session: > >>>> import os >>>> template = 'ls ""' >>>> with open('\\"; rm whatever; ls \\', "w") as f: pass > ... >>>> for filename in os.listdir(): > ... print(template.replace("", filename.replace('"', '\\"'))) > ... > ls "\\"; rm whatever; ls \" > > > Shell variable substitution is another problem. c.l.py is probably not the > best place to get the complete list of possibilities. I see what you mean. This is a tedious problem. Don't know if there is a simple solution in python for this. I have to think about it ... On a more general and serious application I would not produce a bash script. I would do all the work in python. That's not the case, however. This is a few times execution script for a very special purpose. The only problem was the occurrence of some Portuguese characters in old filenames encoded in another code than utf-8. Very few also include the ". The worst thing that could happen was the bash script to abort. Then it would be easy to fix it using a simple editor. From wxjmfauth at gmail.com Mon Jan 13 11:24:09 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 13 Jan 2014 08:24:09 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6ICdTdHJh32UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52d3c20b$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3cfbd99e-da03-4b49-bd44-83d098aefc2d@googlegroups.com> Le lundi 13 janvier 2014 11:57:28 UTC+1, Chris Angelico a ?crit?: > On Mon, Jan 13, 2014 at 9:38 PM, Steven D'Aprano > > wrote: > > > I think you are using "from __future__ import unicode_literals". > > > Otherwise, that cannot happen in Python 2.x. > > > > > > > Alas, not true. > > > > >>> sys.version > > '2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]' > > >>> sys.maxunicode > > 65535 > > >>> assert 'Stra?e'[4] == '?' > > >>> list('Stra?e') > > ['S', 't', 'r', 'a', '\xdf', 'e'] > > > > That's Windows XP. Presumably Latin-1 (or CP-1252, they both have that > > char at 0xDF). He happens to be correct, *as long as the source code > > encoding matches the output encoding and is one that uses 0xDF to mean > > U+00DF*. Otherwise, he's not. > > You are right. It's on Windows. It is only showing how Python can be a holy mess. The funny aspect is when I'm reading " *YOUR* assertions are false" when I'm presenting *PYTHON* assertions! jmf From sk82712 at gmail.com Mon Jan 13 11:29:47 2014 From: sk82712 at gmail.com (Adam) Date: Mon, 13 Jan 2014 11:29:47 -0500 Subject: Code review? Message-ID: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> Hey all. New to the list. I?m working on a web app with 2.6 and Flask. I?m still relatively new to python. Is there a chance to get a code review from anyone? I really want someone to just tear up my code and tell me how to increase my efficiency and what I?m doing wrong (and how to upload images via a form in Flask, but that?s another story). Happy coding Adam From rosuav at gmail.com Mon Jan 13 11:40:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 03:40:25 +1100 Subject: Code review? In-Reply-To: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> References: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> Message-ID: On Tue, Jan 14, 2014 at 3:29 AM, Adam wrote: > Hey all. New to the list. I?m working on a web app with 2.6 and Flask. I?m still relatively new to python. Is there a chance to get a code review from anyone? I really want someone to just tear up my code and tell me how to increase my efficiency and what I?m doing wrong (and how to upload images via a form in Flask, but that?s another story). > Definitely! Preferably, post your code in-line; if it's too long for that, post it someplace else and link to it. Be sure not to damage indentation, of course, but no matter how new you are to Python you'll know that! Incidentally, is there a reason you're using Python 2.6? You should be able to upgrade at least to 2.7, and Flask ought to work fine on 3.3 (the current stable Python). If it's the beginning of your project, and you have nothing binding you to Python 2, go with Python 3. Converting a small project now will save you the job of converting a big project in ten years' time :) ChrisA From wrw at mac.com Mon Jan 13 10:42:25 2014 From: wrw at mac.com (William Ray Wing) Date: Mon, 13 Jan 2014 10:42:25 -0500 Subject: How to get Mac address of ethernet port? In-Reply-To: <52D1729B.7050906@gmail.com> References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> <52D1729B.7050906@gmail.com> Message-ID: <8B27ECD8-C6DB-414F-A76D-49B5E3DDD7E5@mac.com> On Jan 11, 2014, at 11:34 AM, Michael Torrie wrote: > On 01/11/2014 07:35 AM, Andriy Kornatskyy wrote: >> Sam, >> >> How about this? >> >> from uuid import getnode as get_mac >> '%012x' % get_mac() > > This seems to work if you have only one ethernet adapter. Most > computers have two (wired and wireless) adapters. > > Getting a mac address is platform-specific, and the OP has not specified > what OS he is using. > > On Windows I imagine you'd have to access the WMI subsystem in Windows. > > On Linux you could access the /sys/devices/virtual/net/ > file in the sysfs filesystem. I'm sure there are other ways. > > No idea on OS X. > -- > https://mail.python.org/mailman/listinfo/python-list There are probably several ways in OS-X, just as there are in any other UNIX system. The one I've used is to spawn a subprocess and run the "ifconfig" command with no arguments (which doesn't require any special privileges). This will return a string of all the network interfaces (including the loopback and firewire interfaces in addition to Ethernet and WiFi) and their config specs. The OP would then parse this string looking for the location of the phrase "status: active" and then back up to the mac address that precedes it. More work than using uuid, but this guarantees a current and correct answer. >>> import string >>> import subprocess >>> mac_result = subprocess.Popen(['ifconfig'], stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0] >>> mac_loc = string.find(mac_result, "status: active") ...and so on. Bill From rosuav at gmail.com Mon Jan 13 11:47:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 03:47:24 +1100 Subject: How to get Mac address of ethernet port? In-Reply-To: <8B27ECD8-C6DB-414F-A76D-49B5E3DDD7E5@mac.com> References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> <52D1729B.7050906@gmail.com> <8B27ECD8-C6DB-414F-A76D-49B5E3DDD7E5@mac.com> Message-ID: On Tue, Jan 14, 2014 at 2:42 AM, William Ray Wing wrote: > The one I've used is to spawn a subprocess and run the "ifconfig" command with no arguments (which doesn't require any special privileges). Very small caveat: On some systems, running ifconfig doesn't require privileges, but it's not in the unprivileged user's default path (it's in root's path though). I've seen this on Debian Linux, for instance. So you may need to explicitly call /sbin/ifconfig or whereever it's stored. ChrisA From breamoreboy at yahoo.co.uk Mon Jan 13 12:02:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Jan 2014 17:02:20 +0000 Subject: =?ISO-8859-1?Q?=27Stra=DFe=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: <3cfbd99e-da03-4b49-bd44-83d098aefc2d@googlegroups.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52d3c20b$0$29970$c3e8da3$5496439d@news.astraweb.com> <3cfbd99e-da03-4b49-bd44-83d098aefc2d@googlegroups.com> Message-ID: On 13/01/2014 16:24, wxjmfauth at gmail.com wrote: > > You are right. It's on Windows. It is only showing how > Python can be a holy mess. > Regarding unicode Python 2 was a holy mess, fixed in Python 3. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From __peter__ at web.de Mon Jan 13 12:29:28 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 13 Jan 2014 18:29:28 +0100 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Paulo da Silva wrote: > Em 13-01-2014 08:58, Peter Otten escreveu: >> Peter Otten wrote: >> >>> Paulo da Silva wrote: >>> >>>> Em 12-01-2014 20:29, Peter Otten escreveu: >>>>> Paulo da Silva wrote: >>>>> >>>>>>> but I have not tried it myself. Also, some bytes may need to be >>>>>>> escaped, either to be understood by the shell, or to address >>>>>>> security concerns: >>>>>>> >>>>>> >>>>>> Since I am puting the file names between "", the only char that needs >>>>>> to be escaped is the " itself. >>>>> >>>>> What about the escape char? >>>>> >>>> Just this fn=fn.replace('"','\\"') >>>> >>>> So far I didn't find any problem, but the script is still running. >>> >>> To be a bit more explicit: >>> >>>>>> for filename in os.listdir(): >>> ... print(template.replace("", filename.replace('"', '\\"'))) >>> ... >>> ls "\\"; rm whatever; ls \" >> >> The complete session: >> >>>>> import os >>>>> template = 'ls ""' >>>>> with open('\\"; rm whatever; ls \\', "w") as f: pass >> ... >>>>> for filename in os.listdir(): >> ... print(template.replace("", filename.replace('"', '\\"'))) >> ... >> ls "\\"; rm whatever; ls \" >> >> >> Shell variable substitution is another problem. c.l.py is probably not >> the best place to get the complete list of possibilities. > I see what you mean. > This is a tedious problem. Don't know if there is a simple solution in > python for this. I have to think about it ... > On a more general and serious application I would not produce a bash > script. I would do all the work in python. > > That's not the case, however. This is a few times execution script for a > very special purpose. The only problem was the occurrence of some > Portuguese characters in old filenames encoded in another code than > utf-8. Very few also include the ". > > The worst thing that could happen was the bash script to abort. Then it > would be easy to fix it using a simple editor. I looked around in the stdlib and found shlex.quote(). It uses ' instead of " which simplifies things, and special-cases only ': >>> print(shlex.quote("alpha'beta")) 'alpha'"'"'beta' So the answer is simpler than I had expected. From ian.g.kelly at gmail.com Mon Jan 13 12:39:03 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 13 Jan 2014 10:39:03 -0700 Subject: plotting slows down In-Reply-To: References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel wrote: > Next, please repost any source code with indentation preserved. > Your message shows it all flushed to the left margin, probably > due to posting in html mode. Use text mode here. That's odd, the message that I got includes proper indentation and is plain text, not html. From rosuav at gmail.com Mon Jan 13 12:45:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 04:45:12 +1100 Subject: plotting slows down In-Reply-To: References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly wrote: > On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel wrote: >> Next, please repost any source code with indentation preserved. >> Your message shows it all flushed to the left margin, probably >> due to posting in html mode. Use text mode here. > > That's odd, the message that I got includes proper indentation and is > plain text, not html. Also what I saw. Dave, do you get the newsgroup or the mailing list? I get the mailing list - it's possible the HTML version got stripped by Mailman. ChrisA From davea at davea.name Mon Jan 13 13:05:52 2014 From: davea at davea.name (Dave Angel) Date: Mon, 13 Jan 2014 13:05:52 -0500 (EST) Subject: plotting slows down References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: Chris Angelico Wrote in message: > On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly wrote: >> On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel wrote: >>> Next, please repost any source code with indentation preserved. >>> Your message shows it all flushed to the left margin, probably >>> due to posting in html mode. Use text mode here. >> >> That's odd, the message that I got includes proper indentation and is >> plain text, not html. > > Also what I saw. Dave, do you get the newsgroup or the mailing list? I > get the mailing list - it's possible the HTML version got stripped by > Mailman. > I'm using gmane newsgroup, and recently switched to the Android Newsgroup Reader. Previously was using Groundhog, which seemed to eat the body of any message containing an html part. (Though strangely it showed the footer in the tutor newsgroup). This one was mentioned byAlan, and she far has seemed much better. -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From ian.g.kelly at gmail.com Mon Jan 13 13:05:06 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Mon, 13 Jan 2014 11:05:06 -0700 Subject: plotting slows down In-Reply-To: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On Mon, Jan 13, 2014 at 1:15 AM, wrote: > First let me say I have not done much python programming! > I am running Python 2.7.3. > I am trying to use python as a front end to a simple oscilloscope. > Ultimately I intend to use it with my micropython board. > > At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data. > > Each time it goes through the outer loop it gets slower and slower. > I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds. > Can anyone explain what I am doing wrong please? I wager the problem is in the "range(1, xpos)" inner loop. Each time this runs the win.plot() call adds a 1-pixel line to the underlying Tk canvas. These 1-pixel lines are never deleted, so they accumulate over each outer loop. Every time a new object is drawn, the canvas has to process all of the lines that have been drawn in order to redraw itself, and so it gets slower and slower. One simple fix you might try to improve the rendering efficiency is to disable the autoflush option documented here: http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node14.html And then call the module-level update() function after each iteration of the outer loop to force things to redraw. In order to realistically use this module for animation it looks like you will at some point need to keep the number of graphics objects under some constant. To do this you could either reuse the existing objects by calling their "move" method to reposition them as needed, or simply remove them from the plot with the "undraw" method and draw new objects in their place. See: http://mcsp.wartburg.edu/zelle/python/graphics/graphics/node3.html If this still isn't fast enough for the number of objects you're drawing, then you may just need to find a new drawing package, as this one appears to be designed for teaching rather than efficiency. From larry.martell at gmail.com Mon Jan 13 13:27:37 2014 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 13 Jan 2014 13:27:37 -0500 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Mon, Jan 13, 2014 at 1:09 AM, Chris Angelico wrote: > On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell wrote: >> Thanks for the reply. I'm going to take a stab at removing the group >> by and doing it all in python. It doesn't look too hard, but I don't >> know how it will perform. > > Well, if you can't switch to PostgreSQL or such, then doing it in > Python is your only option. There are such things as GiST and GIN > indexes that might be able to do some of this magic, but I don't think > MySQL has anything even remotely like what you're looking for. > > So ultimately, you're going to have to do your filtering on the > database, and then all the aggregation in Python. And it's going to be > somewhat complicated code, too. Best I can think of is this, as > partial pseudo-code: > > last_x = -999 > x_map = []; y_map = {} > merge_me = [] > for x,y,e in (SELECT x,y,e FROM t WHERE whatever ORDER BY x): > if x x_map[-1].append((y,e)) > else: > x_map.append([(y,e)]) > last_x=x > if y in y_map: > merge_me.append((y_map[y], x_map[-1])) > y_map[y]=x_map[-1] > > # At this point, you have x_map which is a list of lists, each one > # being one group, and y_map which maps a y value to its x_map list. > > last_y = -999 > for y in sorted(y_map.keys()): > if y merge_me.append((y_map[y], last_x_map)) > last_y=y > last_x_map=y_map[y] > > for merge1,merge2 in merge_me: > merge1.extend(merge2) > merge2[:]=[] # Empty out the list > > for lst in x_map: > if not lst: continue # been emptied out, ignore it > do aggregate stats, get sum(lst) and whatever else > > I think this should be linear complexity overall, but there may be a > few aspects of it that are quadratic. It's a tad messy though, and > completely untested. But that's an algorithmic start. The idea is that > lists get collected based on x proximity, and then lists get merged > based on y proximity. That is, if you have (1.0, 10.1), (1.5, 2.3), > (3.0, 11.0), (3.2, 15.2), they'll all be treated as a single > aggregation unit. If that's not what you want, I'm not sure how to > handle it. Thanks. Unfortunately this has been made a low priority task and I've been put on to something else (I hate when they do that). I'll revive this thread when I'm allowed to get back on this. From rosuav at gmail.com Mon Jan 13 13:32:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 05:32:17 +1100 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell wrote: > Thanks. Unfortunately this has been made a low priority task and I've > been put on to something else (I hate when they do that). Ugh, I know that feeling all too well! Life's better when you're unemployed, and you can choose the interesting problems to work on. Apart from the "has to be in MySQL" restriction (dodged now that the work's all being done in Python anyway), yours is _definitely_ an interesting problem. ChrisA From norman.elliott at gmail.com Mon Jan 13 13:33:43 2014 From: norman.elliott at gmail.com (Norman Elliott) Date: Mon, 13 Jan 2014 10:33:43 -0800 (PST) Subject: plotting slows down In-Reply-To: References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On Monday, 13 January 2014 18:05:52 UTC, Dave Angel wrote: > Chris Angelico Wrote in message: > Well Ian's suggestion has really done the job. Now each iteration takes just 0.14 seconds now. changed to: [code] win = GraphWin("My Circle", xpos, ypos, autoflush=False) [/code] and added [code] update() [/code] immediately after the line [code] for y in range(1,12): [/code] previously the first iteration took 0.48 seconds and the the 10th 4.76 From breamoreboy at yahoo.co.uk Mon Jan 13 13:36:58 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Jan 2014 18:36:58 +0000 Subject: efficient way to process data In-Reply-To: References: Message-ID: On 13/01/2014 18:32, Chris Angelico wrote: > On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell wrote: >> Thanks. Unfortunately this has been made a low priority task and I've >> been put on to something else (I hate when they do that). > > Ugh, I know that feeling all too well! Life's better when you're > unemployed, and you can choose the interesting problems to work on. No it ain't :( -- 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 Jan 13 13:42:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 13 Jan 2014 18:42:39 +0000 Subject: efficient way to process data In-Reply-To: References: Message-ID: On 13/01/2014 18:27, Larry Martell wrote: > On Mon, Jan 13, 2014 at 1:09 AM, Chris Angelico wrote: >> On Mon, Jan 13, 2014 at 2:35 PM, Larry Martell wrote: >>> Thanks for the reply. I'm going to take a stab at removing the group >>> by and doing it all in python. It doesn't look too hard, but I don't >>> know how it will perform. >> >> Well, if you can't switch to PostgreSQL or such, then doing it in >> Python is your only option. There are such things as GiST and GIN >> indexes that might be able to do some of this magic, but I don't think >> MySQL has anything even remotely like what you're looking for. >> >> So ultimately, you're going to have to do your filtering on the >> database, and then all the aggregation in Python. And it's going to be >> somewhat complicated code, too. Best I can think of is this, as >> partial pseudo-code: >> >> last_x = -999 >> x_map = []; y_map = {} >> merge_me = [] >> for x,y,e in (SELECT x,y,e FROM t WHERE whatever ORDER BY x): >> if x> x_map[-1].append((y,e)) >> else: >> x_map.append([(y,e)]) >> last_x=x >> if y in y_map: >> merge_me.append((y_map[y], x_map[-1])) >> y_map[y]=x_map[-1] >> >> # At this point, you have x_map which is a list of lists, each one >> # being one group, and y_map which maps a y value to its x_map list. >> >> last_y = -999 >> for y in sorted(y_map.keys()): >> if y> merge_me.append((y_map[y], last_x_map)) >> last_y=y >> last_x_map=y_map[y] >> >> for merge1,merge2 in merge_me: >> merge1.extend(merge2) >> merge2[:]=[] # Empty out the list >> >> for lst in x_map: >> if not lst: continue # been emptied out, ignore it >> do aggregate stats, get sum(lst) and whatever else >> >> I think this should be linear complexity overall, but there may be a >> few aspects of it that are quadratic. It's a tad messy though, and >> completely untested. But that's an algorithmic start. The idea is that >> lists get collected based on x proximity, and then lists get merged >> based on y proximity. That is, if you have (1.0, 10.1), (1.5, 2.3), >> (3.0, 11.0), (3.2, 15.2), they'll all be treated as a single >> aggregation unit. If that's not what you want, I'm not sure how to >> handle it. > > Thanks. Unfortunately this has been made a low priority task and I've > been put on to something else (I hate when they do that). I'll revive > this thread when I'm allowed to get back on this. > I've not followed this thread closely but would this help http://pandas.pydata.org/ ? When and if you get back to it, that is!!! -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Mon Jan 13 13:37:23 2014 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Mon, 13 Jan 2014 19:37:23 +0100 Subject: =?ISO-8859-1?Q?=27Stra=DFe=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: Am 13.01.2014 10:54 schrieb wxjmfauth at gmail.com: > Not at all. I'm afraid I'm understanding Python (on this > aspect very well). IBTD. > Do you belong to this group of people who are naively > writing wrong Python code (usually not properly working) > during more than a decade? Why should I be? > '?' is the the fourth character in that text "Stra?e" > (base index 0). Character-wise, yes. But not byte-string-wise. In a byte string, this depends on the character set used. On CP 437, 850, 12xx (whatever Windows uses) or latin1, you are right, but not on the widely used UTF8. >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> assert 'Stra?e'[4] == '?' >>>> assert u'Stra?e'[4] == u'?' Linux box at home: Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> assert 'Stra?e'[4] == '?' Traceback (most recent call last): File "", line 1, in AssertionError >>> assert u'Stra?e'[4] == u'?' Python 3.3.0 (default, Oct 01 2012, 09:13:30) [GCC] on linux Type "help", "copyright", "credits" or "license" for more information. >>> assert 'Stra?e'[4] == '?' >>> assert u'Stra?e'[4] == u'?' Windows box at work: Python 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> assert 'Stra?e'[4] == '?' >>> assert u'Stra?e'[4] == u'?' > PS Nothing to do with Py2/Py3. As bytes and unicode and str stuff is heavily changed between them, of course it has to do. And I think you know that and try to confuse and FUD us all - with no avail. Thomas From p_s_d_a_s_i_l_v_a at netcabo.pt Mon Jan 13 13:44:01 2014 From: p_s_d_a_s_i_l_v_a at netcabo.pt (Paulo da Silva) Date: Mon, 13 Jan 2014 18:44:01 +0000 Subject: Problem writing some strings (UnicodeEncodeError) References: Message-ID: Em 13-01-2014 17:29, Peter Otten escreveu: > Paulo da Silva wrote: > >> Em 13-01-2014 08:58, Peter Otten escreveu: > > I looked around in the stdlib and found shlex.quote(). It uses ' instead of > " which simplifies things, and special-cases only ': > >>>> print(shlex.quote("alpha'beta")) > 'alpha'"'"'beta' > > So the answer is simpler than I had expected. > Yes, it should work, at least in this case. Although python oriented, it seems to work to bash also. I need to remove the "" from the templates and use shlex.quote for filenames. I'll give it a try. Thanks From fluttershy363 at gmail.com Mon Jan 13 13:49:07 2014 From: fluttershy363 at gmail.com (fluttershy363 at gmail.com) Date: Mon, 13 Jan 2014 10:49:07 -0800 (PST) Subject: Tkinter GUI Error Message-ID: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Inside the function is where I am having the problem, I am trying to get it to delete the label so that it may then replace it with a shorter text. Here is the full code: from tkinter import * import random main = Tk() main.title("Crack the Code") def check1(): entry = entry1var.get() if entry == num1: labelent1.destroy() labelent1 = Label(main, text="Correct!",fg="green").grid(row = 0, column = 3) elif entry > num1: labelent1.destroy() labelent1 = Label(main, text="Too Big",fg="red").grid(row = 0, column = 3) elif entry < num1: labelent1.destroy() labelent1 = Label(main, text="Too Small",fg="red").grid(row = 0, column = 3) global num1 global num2 global num3 num1 =str(random.randint(10,99)) num2 =str(random.randint(10,99)) num3 =str(random.randint(10,99)) mastercode = num1+num2+num3 entry1var = StringVar() entry2var = StringVar() entry3var = StringVar() number1 = Label(main, text="Number 1").grid(row = 0, column = 0) number2 = Label(main, text="Number 2").grid(row = 1, column = 0) number3 = Label(main, text="Number 3").grid(row = 2, column = 0) entry1 = Entry(main, textvariable=entry1var).grid(row=0,column=1) entry2 = Entry(main, textvariable=entry2var).grid(row=1,column=1) entry3 = Entry(main, textvariable=entry3var).grid(row=2,column=1) button1 = Button(main, text="Try Number",command=check1).grid(row=0,column=2) button2 = Button(main, text="Try Number").grid(row=1,column=2) button3 = Button(main, text="Try Number").grid(row=2,column=2) labelent1 = Label(main, text="Waiting for Input").grid(row = 0, column = 3) labelent2 = Label(main, text="Waiting for Input").grid(row = 1, column = 3) labelent3 = Label(main, text="Waiting for Input").grid(row = 2, column = 3) mastercodelabel= Label(main, text="Enter master code below:").grid(row=3,column=1) mastercodeentry= Entry(main).grid(row=4,column=1) mastercodebutton= Button(main,text="Enter").grid(row=4,column=2) #main.config(menu=menubar) main.mainloop() And this is the error displayed when clicking on button1: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:/Users/User/Desktop/Programming/Tkinter/Tkinter.py", line 15, in check1 labelent1.destroy() UnboundLocalError: local variable 'labelent1' referenced before assignment Thanks, Lewis. From fluttershy363 at gmail.com Mon Jan 13 13:51:23 2014 From: fluttershy363 at gmail.com (Lewis Wood) Date: Mon, 13 Jan 2014 10:51:23 -0800 (PST) Subject: Tkinter GUI Error In-Reply-To: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: <7b21d69d-7272-4e7b-ab85-621f044d205c@googlegroups.com> Forgot to mention I am using Python 3.3.3 From auriocus at gmx.de Mon Jan 13 14:03:42 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Mon, 13 Jan 2014 20:03:42 +0100 Subject: Tkinter GUI Error In-Reply-To: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: Am 13.01.14 19:49, schrieb fluttershy363 at gmail.com: > > Inside the function is where I am having the problem, I am trying to get it to delete the label so that it may then replace it with a shorter text. > Here is the full code: > > > > > from tkinter import * > import random > main = Tk() > main.title("Crack the Code") > > def check1(): > entry = entry1var.get() > if entry == num1: > labelent1.destroy() > labelent1 = Label(main, text="Correct!",fg="green").grid(row = 0, column = 3) This is the wrong way to do it. Yes, in principle you could remove the label and put a new one there; but it's much better to just change the text of it by means of either labelent1.configure(text="New text ") or by linking a variable with the label variable at the setup time somestringvar = StringVar("initial text") Label(main, textvariable=somestringvar) and then change that variable somestringvar.set("New text") Both of these don't solve the error, though; it has nothing to do with Tk, you just did not make labelent1 global. However, I strongly advise to use an object for the entire window, where you make this labelent1 an instance variable (put into self). Christian From fluttershy363 at gmail.com Mon Jan 13 14:21:12 2014 From: fluttershy363 at gmail.com (Lewis Wood) Date: Mon, 13 Jan 2014 11:21:12 -0800 (PST) Subject: Tkinter GUI Error In-Reply-To: References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: When I try to use the labelent1.configure, it greets me with an error: AttributeError: 'NoneType' object has no attribute 'configure' I changed the labelent's to global. Don't suppose you know why? Also how would I go about using an object for the entire window. I am still a Novice at Tkinter and Python but can make my way around it. From __peter__ at web.de Mon Jan 13 14:36:53 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 13 Jan 2014 20:36:53 +0100 Subject: Tkinter GUI Error References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: fluttershy363 at gmail.com wrote: > Inside the function is where I am having the problem, I am trying to get > it to delete the label so that it may then replace it with a shorter text. > Here is the full code: > def check1(): > entry = entry1var.get() > if entry == num1: > labelent1.destroy() > labelent1 = Label(main, text="Correct!",fg="green").grid(row = 0, > column = 3) > elif entry > num1: > labelent1.destroy() > labelent1 = Label(main, text="Too Big",fg="red").grid(row = 0, > column = 3) > elif entry < num1: > labelent1.destroy() > labelent1 = Label(main, text="Too Small",fg="red").grid(row = 0, > column = 3) > And this is the error displayed when clicking on button1: > > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ > return self.func(*args) > File "C:/Users/User/Desktop/Programming/Tkinter/Tkinter.py", line 15, in > check1 > labelent1.destroy() > UnboundLocalError: local variable 'labelent1' referenced before assignment > > > Thanks, Lewis. Kudos, your problem description is very clear! Your post would be perfect, had you reduced the number of Labels from three to one ;) The error you are seeing has nothing to do with the GUI. When you assign to a name inside a function Python determines that the name is local to that function. A minimal example that produces the same error is >>> a = "global" >>> def test(): ... print(a) ... a = "local" ... >>> test() Traceback (most recent call last): File "", line 1, in File "", line 2, in test UnboundLocalError: local variable 'a' referenced before assignment The name `a` passed to print() references the local `a` which is not yet defined. A possible fix is to tell Python to reference the global `a` >>> a = "global" >>> def test(): ... global a ... print(a) ... a = "local" ... >>> test() global >>> a 'local' However, in the case of your GUI code you should not destroy and create Label instances -- it is more efficient (and easier I think) to modify the Label's text: (1) working demo with 'global' -- don't do it that way: from tkinter import * main = Tk() def check1(): global labelent1 labelent1.destroy() labelent1 = Label(main, text="Correct!", fg="green") labelent1.grid(row = 0, column = 3) # must be a separate statement as # grid() returns None Button(main, text="Try Number", command=check1).grid(row=0, column=2) labelent1 = Label(main, text="Waiting for Input") labelent1.grid(row=0, column=3) # must be a separate statement as # grid() returns None main.mainloop() (2) The way to go, modify the label text instead of replacing it: from tkinter import * main = Tk() def check1(): labelent1.configure(text="Correct!", fg="green") Button(main, text="Try Number", command=check1).grid(row=0, column=2) labelent1 = Label(main, text="Waiting for Input") labelent1.grid(row=0, column=3) main.mainloop() > global num1 By the way, global declarations on the module level have no effect. From larry.martell at gmail.com Mon Jan 13 14:51:52 2014 From: larry.martell at gmail.com (Larry Martell) Date: Mon, 13 Jan 2014 14:51:52 -0500 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Mon, Jan 13, 2014 at 1:32 PM, Chris Angelico wrote: > On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell wrote: >> Thanks. Unfortunately this has been made a low priority task and I've >> been put on to something else (I hate when they do that). > > Ugh, I know that feeling all too well! Right? You're deep in debugging and researching and waking up in the middle of the night with potential solutions, and then they say put it aside. It's so hard to put it down, and then when you pick it up later (sometimes months) you're like WTF is this all about. I recently picked up something I had to put down in September - spent an entire day getting back to where I was, then it was put on the back burner again. > Life's better when you're > unemployed, and you can choose the interesting problems to work on. Ahhh .... I don't think so. > Apart from the "has to be in MySQL" restriction (dodged now that the > work's all being done in Python anyway), It's a big existing django app. > yours is _definitely_ an > interesting problem. Thanks! I thought so too. From tjreedy at udel.edu Mon Jan 13 15:23:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Jan 2014 15:23:17 -0500 Subject: L[:] In-Reply-To: <52D3AB3E.6050206@shopzeus.com> References: <1389375507.21198.YahooMailBasic@web163801.mail.gq1.yahoo.com> <52D3AB3E.6050206@shopzeus.com> Message-ID: On 1/13/2014 4:00 AM, Laszlo Nagy wrote: > >> Unless L is aliased, this is silly code. > There is another use case. If you intend to modify a list within a for > loop that goes over the same list, then you need to iterate over a copy. > And this cannot be called an "alias" because it has no name: for i in somelist: creates a second reference to somelist that somewhere in the loop code has a name, so it is effectively an 'alias'. The essential point is that there are two access paths to the same object. > for idx,item in enumerate(L[:]): > # do something with L here, including modification The copy is only needed in the above if one inserts or deletes. But if one inserts or deletes more than one item, one nearly always does better to iterate through the original and construct a new list with new items added and old items not copied. -- Terry Jan Reedy From steve at pearwood.info Mon Jan 13 15:33:11 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 Jan 2014 20:33:11 GMT Subject: plotting slows down References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: <52d44d86$0$6599$c3e8da3$5496439d@news.astraweb.com> On Mon, 13 Jan 2014 08:26:11 -0500, Dave Angel wrote: > norman.elliott at gmail.com Wrote in message: >> [code] >> #!/usr/bin/python >> from graphics import * > > First things first. what operating system are you using, and > where did you get the mysterious graphics. py? Thanks for telling us > python 2.7.3 > > Next, please repost any source code with indentation preserved. He did. If you look at the original message as posted to python- list at python.org and comp.lang.python, e.g. here: https://mail.python.org/pipermail/python-list/2014-January/664430.html you will see that the message is correctly indented with tabs. > Your message shows it all flushed to the left margin, probably due to > posting in html mode. Use text mode here. Looks like perhaps Gmane is stripping tabs from their mirror. You should report that as a bug to them. -- Steven From steve at pearwood.info Mon Jan 13 15:43:53 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 13 Jan 2014 20:43:53 GMT Subject: Code review? References: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> Message-ID: <52d45008$0$6599$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote: > Incidentally, is there a reason you're using Python 2.6? You should be > able to upgrade at least to 2.7, and Flask ought to work fine on 3.3 > (the current stable Python). If it's the beginning of your project, and > you have nothing binding you to Python 2, go with Python 3. Converting a > small project now will save you the job of converting a big project in > ten years' time Everything you say is correct, but remember that there is a rather large ecosystem of people writing code to run on servers where the supported version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example, still has at least one version of RHEL still under commercial support where the system Python is 2.3, at least that was the case a few months back, it may have reached end-of-life by now. But 2.4 will definitely still be under support. (I don't believe there is any mainstream Linux distro still supporting versions older than 2.3.) Not everyone is willing, permitted or able to install Python other than that which their OS provides, and we ought to respect that. Hell, if somebody wants to ask questions about Python 1.5, we can answer them! The core language is still recognisably Python, a surprisingly large number of libraries were around back then (it was Python 1.4 or 1.5 which first got the reputation of "batteries included"), and I for one still have it installed so I can even test code for it. -- Steven From petite.abeille at gmail.com Mon Jan 13 15:47:01 2014 From: petite.abeille at gmail.com (Petite Abeille) Date: Mon, 13 Jan 2014 21:47:01 +0100 Subject: efficient way to process data In-Reply-To: References: Message-ID: <12634483-48E7-455D-A08E-9D6481E12745@gmail.com> On Jan 13, 2014, at 7:42 PM, Mark Lawrence wrote: > I've not followed this thread closely but would this help http://pandas.pydata.org/ ? When and if you get back to it, that is!!! I doubt it. The mean overhead by far would be to shuffle pointless data between the server & client. Best to process data closest to their source. On the other hand: http://devour.com/video/never-say-no-to-panda/ From tjreedy at udel.edu Mon Jan 13 16:26:26 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Jan 2014 16:26:26 -0500 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: On 1/13/2014 9:47 AM, Neal Becker wrote: > py3 includes a fairly compelling feature: nonlocal keywork [keyword] > But backward compatibility is lost. I am not sure what your particular point is. Every new feature, in any release, if used, makes code not compatible with earlier releases that do not have the feature. Every new feature is compelling to someone, and to use it, one must use a version that has it. > It would be very helpful if this was available on py2.x. For every new feature, there is someone who thinks it would be helpful if it were availale in an earlier version. Backports of library features are sometimes available on PyPI, but this cannot be done for syntax features like 'nonlocal'. '2.x' refers to a sequence of feature-frozen versions. It literally means '2.0 to 2.7', but may refer to '2.2 to 2.7' (because 2.2 gained new classes and iterators) or even a more restricted sequence. Core developers consider 3.2, or maybe a later version, to be the successor of 2.7. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jan 13 16:42:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Jan 2014 16:42:18 -0500 Subject: plotting slows down In-Reply-To: References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On 1/13/2014 12:45 PM, Chris Angelico wrote: > On Tue, Jan 14, 2014 at 4:39 AM, Ian Kelly wrote: >> On Mon, Jan 13, 2014 at 6:26 AM, Dave Angel wrote: >>> Next, please repost any source code with indentation preserved. >>> Your message shows it all flushed to the left margin, probably >>> due to posting in html mode. Use text mode here. >> >> That's odd, the message that I got includes proper indentation and is >> plain text, not html. > > Also what I saw. Dave, do you get the newsgroup or the mailing list? I > get the mailing list - it's possible the HTML version got stripped by > Mailman. I am reading via gmane. Viewing the source, there is no html. BUT, indents are with tabs, not spaces. Some readers just delete tabs, as there is no standard for conversion to spaces, especially with proportional fonts. Thunderbird used to do this, but now uses tab stops every 8 spaces (maybe because a switched to a fixed font?) This means that the first tab gives an indent 8 chars in the original post, 6 in the first quotation, and, I presume, 4 in a second quotation, etc. It works better to post code with space indents. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jan 13 18:05:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 13 Jan 2014 18:05:04 -0500 Subject: Mistake or Troll (was Re: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScp?= =?UTF-8?B?IGFuZCBQeXRob24gMik=?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: On 1/13/2014 4:54 AM, wxjmfauth at gmail.com wrote: > I'm afraid I'm understanding Python (on this > aspect very well). Really? > Do you belong to this group of people who are naively > writing wrong Python code (usually not properly working) > during more than a decade? To me, the important question is whether this and previous similar posts are intentional trolls designed to stir up the flurry of responses they get or 'innocently' misleading or even erroneous. If your claim of understanding Python and Unicode is true, then this must be a troll post. Either way, please desist, or your access to python-list from google-groups may be removed. > '?' is the the fourth character in that text "Stra?e" > (base index 0). As others have said, in the *unicode text "Stra?e", '?' is the fifth character, at character index 4, ... > This assertions are correct (byte string and unicode). whereas, when the text is encoded into bytes, the byte index depends on the encoding and the assertion that it is always 4 is incorrect. Did you know this or were you truly ignorant? >>>> sys.version > '2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)]' >>>> assert 'Stra?e'[4] == '?' Sometimes true, sometimes not. >>>> assert u'Stra?e'[4] == u'?' > PS Nothing to do with Py2/Py3. This issue has everything to do with Py2, where 'Stra?e' is encoded bytes, versus Py3, where 'Stra?e' is unicode text where each character of that word takes one code unit, whether each is 2 bytes or 4 bytes. If you replace '?' with any astral (non-BMP) character, this issue appears even for unicode text in 3.2-, where an astral character requires 2, not 1, code units on narrow builds, thereby screwing up indexing, just as can happen for encoded bytes. In 3.3+, all characters use 1 code unit and indexing (and slicing) always works properly. This is another unicode issue where you appear not to understand, but might just be trolling. -- Terry Jan Reedy From rosuav at gmail.com Mon Jan 13 18:34:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 10:34:15 +1100 Subject: Code review? In-Reply-To: <52d45008$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> <52d45008$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano wrote: > On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote: > >> Incidentally, is there a reason you're using Python 2.6? You should be >> able to upgrade at least to 2.7, and Flask ought to work fine on 3.3 >> (the current stable Python). If it's the beginning of your project, and >> you have nothing binding you to Python 2, go with Python 3. Converting a >> small project now will save you the job of converting a big project in >> ten years' time > > Everything you say is correct, but remember that there is a rather large > ecosystem of people writing code to run on servers where the supported > version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example, > still has at least one version of RHEL still under commercial support > where the system Python is 2.3, at least that was the case a few months > back, it may have reached end-of-life by now. But 2.4 will definitely > still be under support. Pledging that your app will run on the system Python of RHEL is something that binds you to a particular set of versions of Python. It's not just library support that does that. ChrisA From rantingrickjohnson at gmail.com Mon Jan 13 21:47:39 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 13 Jan 2014 18:47:39 -0800 (PST) Subject: Tkinter GUI Error In-Reply-To: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: On Monday, January 13, 2014 12:49:07 PM UTC-6, Lewis Wood wrote: > labelent1 = Label(main, text="Correct!",fg="green").grid(row = 0, column = 3) > > [snip] > > UnboundLocalError: local variable 'labelent1' referenced before assignment Observe the following interactive session and prepare to be enlightened. ## INCORRECT ## py> from Tkinter import * py> root = Tk() py> label = Label(root, text="Blah").pack() py> type(label) ## CORRECT ## py> label = Label(root, text="Blah") py> label.pack() py> label py> type(label) ## ANY QUESTIONS? ## py> help() From rosuav at gmail.com Mon Jan 13 22:12:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 14:12:01 +1100 Subject: Tkinter GUI Error In-Reply-To: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: On Tue, Jan 14, 2014 at 5:49 AM, wrote: > entry = entry1var.get() > if entry == num1: > elif entry > num1: > elif entry < num1: > > num1 =str(random.randint(10,99)) > num2 =str(random.randint(10,99)) > num3 =str(random.randint(10,99)) > mastercode = num1+num2+num3 Be careful of code like this. You've specified that your three parts range from 10 through 99, so this will work as long as the user knows this and enters exactly two digits. Doing inequality comparisons on strings that represent numbers will work as long as they're the same length, but if the lengths vary, the string comparisons will start at the beginning - not what most people will expect. These are all true: "2" > "10" "3.14159" > "2,000,000" "42" < "Life, the universe, and everything" "00012" < "12" If your intention is to have a six-digit number, you could simply ask for one, and then format the pieces accordingly: num = random.randint(1,999999) num_str = "%06d" % num You can then slice up num_str as needed (it'll have leading zeroes if it needs them), or you can do numerical comparisons against num itself. ChrisA From bob.martin at excite.com Tue Jan 14 02:22:01 2014 From: bob.martin at excite.com (Bob Martin) Date: Tue, 14 Jan 2014 07:22:01 GMT Subject: Code review? References: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> Message-ID: in 714500 20140113 233415 Chris Angelico wrote: >On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano wrote: >> On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote: >> >>> Incidentally, is there a reason you're using Python 2.6? You should be >>> able to upgrade at least to 2.7, and Flask ought to work fine on 3.3 >>> (the current stable Python). If it's the beginning of your project, and >>> you have nothing binding you to Python 2, go with Python 3. Converting a >>> small project now will save you the job of converting a big project in >>> ten years' time >> >> Everything you say is correct, but remember that there is a rather large >> ecosystem of people writing code to run on servers where the supported >> version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example, >> still has at least one version of RHEL still under commercial support >> where the system Python is 2.3, at least that was the case a few months >> back, it may have reached end-of-life by now. But 2.4 will definitely >> still be under support. > >Pledging that your app will run on the system Python of RHEL is >something that binds you to a particular set of versions of Python. >It's not just library support that does that. Does any Linux distro ship with Python 3? I haven't seen one. From byrmgcl at yandex.com.tr Tue Jan 14 02:29:56 2014 From: byrmgcl at yandex.com.tr (=?ISO-8859-1?Q?Bayram_G=FC=E7l=FC?=) Date: Tue, 14 Jan 2014 11:29:56 +0400 Subject: Code review? References: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> Message-ID: <52D4E774.6090206@yandex.com.tr> On 14-01-2014 11:22, Bob Martin wrote: > in 714500 20140113 233415 Chris Angelico wrote: >> On Tue, Jan 14, 2014 at 7:43 AM, Steven D'Aprano wrote: >>> On Tue, 14 Jan 2014 03:40:25 +1100, Chris Angelico wrote: >>> >>>> Incidentally, is there a reason you're using Python 2.6? You should be >>>> able to upgrade at least to 2.7, and Flask ought to work fine on 3.3 >>>> (the current stable Python). If it's the beginning of your project, and >>>> you have nothing binding you to Python 2, go with Python 3. Converting a >>>> small project now will save you the job of converting a big project in >>>> ten years' time >>> >>> Everything you say is correct, but remember that there is a rather large >>> ecosystem of people writing code to run on servers where the supported >>> version of Python is 2.6, 2.5, 2.4 and even 2.3. RedHat, for example, >>> still has at least one version of RHEL still under commercial support >>> where the system Python is 2.3, at least that was the case a few months >>> back, it may have reached end-of-life by now. But 2.4 will definitely >>> still be under support. >> >> Pledging that your app will run on the system Python of RHEL is >> something that binds you to a particular set of versions of Python. >> It's not just library support that does that. > > Does any Linux distro ship with Python 3? I haven't seen one. > Debian GNU/Linux https://wiki.debian.org/Python/Python3.3 From rosuav at gmail.com Tue Jan 14 02:36:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 18:36:49 +1100 Subject: Code review? In-Reply-To: References: <13BCC15D-B1E0-4AB2-9641-673D5B1B6FDD@gmail.com> Message-ID: On Tue, Jan 14, 2014 at 6:22 PM, Bob Martin wrote: > Does any Linux distro ship with Python 3? I haven't seen one. On most Debian-based distros, you can simply 'apt-get install python3', and you'll get some 3.x version (in Debian Squeeze, that's 3.1, Debian Wheezy packages 3.2; Ubuntu since Raring gives you 3.3). Whether or not you actually have it - or python2 for that matter - installed depends on your choices, anything that depends on it will pull it in or you can grab it manually. Arch Linux ships 3.3.3 under the name "python", and 2.7.6 under the name "python2" - an inversion of the Debian practice. Other distros are looking toward shifting, too. I'd guess that all mainstream distributions carry both branches. It's just a question of what people get when they ask for "Python" in the most normal way to do that. ChrisA From kyilmaz80 at gmail.com Tue Jan 14 02:41:23 2014 From: kyilmaz80 at gmail.com (Koray YILMAZ) Date: Mon, 13 Jan 2014 23:41:23 -0800 (PST) Subject: Python example source code In-Reply-To: References: Message-ID: <8b1a148b-4546-49da-88ff-b0e8d2c17b22@googlegroups.com> On Sunday, January 12, 2014 4:37:18 PM UTC+2, ngangsia akumbo wrote: > where can i find example source code by topic? > > Any help please Hi, Take a look at https://github.com/dabeaz/python-cookbook. I am using "NapCat" mobile application to read codes. -Koray From ikorot01 at gmail.com Tue Jan 14 03:46:56 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 14 Jan 2014 00:46:56 -0800 Subject: What's correct Python syntax? Message-ID: Hi, ALL, I'm trying to process a file which has following lines: 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 (this is the text file out of tcpdump) Now I can esily split the line twice: once by ':' symbol to separate address and the protocol information and the second time by ',' to get information about the protocol. However, I don't need all the protocol info. All I'm interested in is the last field, which is length. Is there a way to write something like this: for data in f: (address,traffic) = string.split(data, ':') length = string.split(traffic, ',')[3] I'm interesred in only one element, so why should care about everything else? This can be easily done in Perl, but I'm stuck with Python now. ;-) Thank you. From rustompmody at gmail.com Tue Jan 14 03:54:56 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jan 2014 00:54:56 -0800 (PST) Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: On Tuesday, January 14, 2014 2:16:56 PM UTC+5:30, Igor Korot wrote: > Hi, ALL, > I'm trying to process a file which has following lines: > > 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > > (this is the text file out of tcpdump) > > > Now I can esily split the line twice: once by ':' symbol to separate > address and the protocol information and the second time by ',' to get > information about the protocol. > However, I don't need all the protocol info. All I'm interested in is > the last field, which is length. > > > > Is there a way to write something like this: > > > for data in f: > (address,traffic) = string.split(data, ':') > length = string.split(traffic, ',')[3] > > > > I'm interesred in only one element, so why should care about everything else? > This can be easily done in Perl, but I'm stuck with Python now. ;-) >>> data="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30" >>> (add,traff) = data.split(':') >>> add '192.168.1.6 > 192.168.1.7' >>> traff ' ICMP echo request, id 100, seq 200, length 30' >>> lenn = traff.split(',') >>> lenn = traff.split(',')[3] >>> lenn ' length 30' >>> From rosuav at gmail.com Tue Jan 14 03:58:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 14 Jan 2014 19:58:17 +1100 Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: On Tue, Jan 14, 2014 at 7:46 PM, Igor Korot wrote: > 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > > However, I don't need all the protocol info. All I'm interested in is > the last field, which is length. You can split on any string. If you're confident that this is the only instance of the word "length", you can split on that: for data in f: # This will throw an exception if there's no " length " # or if there are two of them. This means you're safe; # if anything unexpected happens, you'll know. _, length = data.split(" length ") # process length Alternatively, you can split on the space and take just the very last word: for data in f: length = data.split(" ")[-1] # process length Either way, the length will be a string. If you need it as an integer, just do this: length = int(length) >From there, you can do whatever analysis you need. Hope that helps! ChrisA From ikorot01 at gmail.com Tue Jan 14 04:25:00 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 14 Jan 2014 01:25:00 -0800 Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: Hi, Rustom, On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody wrote: > On Tuesday, January 14, 2014 2:16:56 PM UTC+5:30, Igor Korot wrote: >> Hi, ALL, >> I'm trying to process a file which has following lines: >> >> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 >> >> (this is the text file out of tcpdump) >> >> >> Now I can esily split the line twice: once by ':' symbol to separate >> address and the protocol information and the second time by ',' to get >> information about the protocol. >> However, I don't need all the protocol info. All I'm interested in is >> the last field, which is length. >> >> >> >> Is there a way to write something like this: >> >> >> for data in f: >> (address,traffic) = string.split(data, ':') >> length = string.split(traffic, ',')[3] >> >> >> >> I'm interesred in only one element, so why should care about everything else? >> This can be easily done in Perl, but I'm stuck with Python now. ;-) > > >>>> data="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30" >>>> (add,traff) = data.split(':') >>>> add > '192.168.1.6 > 192.168.1.7' >>>> traff > ' ICMP echo request, id 100, seq 200, length 30' >>>> lenn = traff.split(',') >>>> lenn = traff.split(',')[3] >>>> lenn > ' length 30' What if I want field 2 and field 3? ("seq 200" and "length 30") Thank you. >>>> > -- > https://mail.python.org/mailman/listinfo/python-list From davea at davea.name Tue Jan 14 04:32:01 2014 From: davea at davea.name (Dave Angel) Date: Tue, 14 Jan 2014 04:32:01 -0500 (EST) Subject: plotting slows down References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> <00281afe-0a5e-4d9a-92ce-c341bbcf9331@googlegroups.com> Message-ID: Norman Elliott Wrote in message: > > I cannot see how to change from html to text mode in chromium or within the group. > You already did post in text mode, my error. The new newsreader I'm using apparently eats tabs. -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From davea at davea.name Tue Jan 14 04:39:11 2014 From: davea at davea.name (Dave Angel) Date: Tue, 14 Jan 2014 04:39:11 -0500 (EST) Subject: plotting slows down References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> <52d44d86$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano Wrote in message: > On Mon, 13 Jan 2014 08:26:11 -0500, Dave Angel wrote: > >> norman.elliott at gmail.com Wrote in message: > >>> [code] >>> #!/usr/bin/python >>> from graphics import * >> >> First things first. what operating system are you using, and >> where did you get the mysterious graphics. py? Thanks for telling us >> python 2.7.3 >> >> Next, please repost any source code with indentation preserved. > > He did. If you look at the original message as posted to python- > list at python.org and comp.lang.python, e.g. here: > > https://mail.python.org/pipermail/python-list/2014-January/664430.html > > you will see that the message is correctly indented with tabs. > >> Your message shows it all flushed to the left margin, probably due to >> posting in html mode. Use text mode here. > > Looks like perhaps Gmane is stripping tabs from their mirror. You should > report that as a bug to them. > > > I just went to my Linux box and fired up thunderbird. When it reads the same message from gmane, it gets the tabs. So apparently it's this Android Newsgroups Reader that's buggy. -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From breamoreboy at yahoo.co.uk Tue Jan 14 04:37:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Jan 2014 09:37:48 +0000 Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: On 14/01/2014 09:25, Igor Korot wrote: > Hi, Rustom, > > On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody wrote: >> On Tuesday, January 14, 2014 2:16:56 PM UTC+5:30, Igor Korot wrote: >>> Hi, ALL, >>> I'm trying to process a file which has following lines: >>> >>> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 >>> >>> (this is the text file out of tcpdump) >>> >>> >>> Now I can esily split the line twice: once by ':' symbol to separate >>> address and the protocol information and the second time by ',' to get >>> information about the protocol. >>> However, I don't need all the protocol info. All I'm interested in is >>> the last field, which is length. >>> >>> >>> >>> Is there a way to write something like this: >>> >>> >>> for data in f: >>> (address,traffic) = string.split(data, ':') >>> length = string.split(traffic, ',')[3] >>> >>> >>> >>> I'm interesred in only one element, so why should care about everything else? >>> This can be easily done in Perl, but I'm stuck with Python now. ;-) >> >> >>>>> data="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30" >>>>> (add,traff) = data.split(':') >>>>> add >> '192.168.1.6 > 192.168.1.7' >>>>> traff >> ' ICMP echo request, id 100, seq 200, length 30' >>>>> lenn = traff.split(',') >>>>> lenn = traff.split(',')[3] >>>>> lenn >> ' length 30' > > What if I want field 2 and field 3? ("seq 200" and "length 30") > > Thank you. > >>>>> >> -- >> https://mail.python.org/mailman/listinfo/python-list Please do a little work before asking such a trivial question, it's hardly difficult from the interactive interpreter, particularly when you already have an example to start with. -- 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 Tue Jan 14 04:37:36 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jan 2014 01:37:36 -0800 (PST) Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote: > > What if I want field 2 and field 3? ("seq 200" and "length 30") Wee you did say: > I'm interesred in only one element, so why should care about everything else? So its not clear what you want! Do you want a one-liner? You could use a regular expression. [You will very soon find that the world divides between the regular and the irregular folks!] Or you want some other perl-ism? You need to say what... Or maybe you just want to use scapy instead of tcpdump? From jpiitula at ling.helsinki.fi Tue Jan 14 04:43:48 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 14 Jan 2014 11:43:48 +0200 Subject: What's correct Python syntax? References: Message-ID: Chris Angelico writes: > Alternatively, you can split on the space and take just the very > last word: > > for data in f: > length = data.split(" ")[-1] > # process length Also, data.rsplit(' ', 1) will split data in two at the last space. help(str.rsplit) From ikorot01 at gmail.com Tue Jan 14 05:02:24 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 14 Jan 2014 02:02:24 -0800 Subject: What's correct Python syntax? In-Reply-To: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: Hi, Rustom, On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote: > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote: >> >> What if I want field 2 and field 3? ("seq 200" and "length 30") > > Wee you did say: > >> I'm interesred in only one element, so why should care about everything else? > > So its not clear what you want! Sorry, I thought it would be easier to ask this way. Guess not. I am actually looking for a way to get a result from split which is sliced the way I want. Like in my example above. I mean I can probably make more variable by creating a tuple, but why? What is the purpose if I want only couple elements out of split. Doing it Perl way does not help: C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> test = "I,like,my,chocolate" >>> print test.split(',')[2,3] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not tuple I can do it this way: >>> testlist = test.split(',') >>> print testlist[2] my but it will needlessly creates a list on which I will access by the index. Why? All I need is couple of values out of n-dimensional list (array). > > Do you want a one-liner? You could use a regular expression. > [You will very soon find that the world divides between the regular and the > irregular folks!] > > Or you want some other perl-ism? You need to say what... Well is there a Python way to do what I want? I mention Perl only because I'm familiar with the language and this is easy in it to do that. Thank you. > > Or maybe you just want to use scapy instead of tcpdump? > -- > https://mail.python.org/mailman/listinfo/python-list From ikorot01 at gmail.com Tue Jan 14 05:03:07 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 14 Jan 2014 02:03:07 -0800 Subject: Fwd: What's correct Python syntax? In-Reply-To: References: Message-ID: Sorry, that was sent to Mark directly. Resending to the list. ---------- Forwarded message ---------- From: Igor Korot Date: Tue, Jan 14, 2014 at 1:50 AM Subject: Re: What's correct Python syntax? To: Mark Lawrence Hi, Mark, On Tue, Jan 14, 2014 at 1:37 AM, Mark Lawrence wrote: > On 14/01/2014 09:25, Igor Korot wrote: >> >> Hi, Rustom, >> >> On Tue, Jan 14, 2014 at 12:54 AM, Rustom Mody >> wrote: >>> >>> On Tuesday, January 14, 2014 2:16:56 PM UTC+5:30, Igor Korot wrote: >>>> >>>> Hi, ALL, >>>> I'm trying to process a file which has following lines: >>>> >>>> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 >>>> >>>> (this is the text file out of tcpdump) >>>> >>>> >>>> Now I can esily split the line twice: once by ':' symbol to separate >>>> address and the protocol information and the second time by ',' to get >>>> information about the protocol. >>>> However, I don't need all the protocol info. All I'm interested in is >>>> the last field, which is length. >>>> >>>> >>>> >>>> Is there a way to write something like this: >>>> >>>> >>>> for data in f: >>>> (address,traffic) = string.split(data, ':') >>>> length = string.split(traffic, ',')[3] >>>> >>>> >>>> >>>> I'm interesred in only one element, so why should care about everything >>>> else? >>>> This can be easily done in Perl, but I'm stuck with Python now. ;-) >>> >>> >>> >>>>>> data="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, >>>>>> length 30" >>>>>> (add,traff) = data.split(':') >>>>>> add >>> >>> '192.168.1.6 > 192.168.1.7' >>>>>> >>>>>> traff >>> >>> ' ICMP echo request, id 100, seq 200, length 30' >>>>>> >>>>>> lenn = traff.split(',') >>>>>> lenn = traff.split(',')[3] >>>>>> lenn >>> >>> ' length 30' >> >> >> What if I want field 2 and field 3? ("seq 200" and "length 30") >> >> Thank you. >> >>>>>> >>> -- >>> https://mail.python.org/mailman/listinfo/python-list > > > Please do a little work before asking such a trivial question, it's hardly > difficult from the interactive interpreter, particularly when you already > have an example to start with. C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> test = "I,like,my,chocolate" >>> print test.split(',')[2,3] Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not tuple Like I said, I'm more used to Perl, but need to work with Python for a moment. Thank you. > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what > you can do for our language. > > Mark Lawrence > > -- > https://mail.python.org/mailman/listinfo/python-list From rustompmody at gmail.com Tue Jan 14 05:16:16 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jan 2014 02:16:16 -0800 (PST) Subject: What's correct Python syntax? In-Reply-To: References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: On Tuesday, January 14, 2014 3:32:24 PM UTC+5:30, Igor Korot wrote: > Hi, Rustom, > On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote: > > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote: > >> What if I want field 2 and field 3? ("seq 200" and "length 30") > > Wee you did say: > >> I'm interesred in only one element, so why should care about everything else? > > So its not clear what you want! > Sorry, I thought it would be easier to ask this way. Guess not. > I am actually looking for a way to get a result from split which is > sliced the way I want. Like in my example above. > I mean I can probably make more variable by creating a tuple, but why? > What is the purpose if I want only couple elements out of split. > Doing it Perl way does not help: > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> test = "I,like,my,chocolate" > >>> print test.split(',')[2,3] You want this? >>> test = "I,like,my,chocolate" >>> test.split(',') ['I', 'like', 'my', 'chocolate'] >>> test.split(',')[2:4] ['my', 'chocolate'] > Well is there a Python way to do what I want? Well I for one still dont get what you want!! Heres a python one-liner using regexps >>> r=r'(.*) +> +(.*):.*length (\d*)' >>> re.findall(r,data) [('192.168.1.6', '192.168.1.7', '30')] Note: I am NOT suggesting you use regexps. Just that they will do what you want if you are so inclined From ikorot01 at gmail.com Tue Jan 14 05:35:27 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 14 Jan 2014 02:35:27 -0800 Subject: What's correct Python syntax? In-Reply-To: References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: Hi, Rustom, On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody wrote: > On Tuesday, January 14, 2014 3:32:24 PM UTC+5:30, Igor Korot wrote: >> Hi, Rustom, > >> On Tue, Jan 14, 2014 at 1:37 AM, Rustom Mody wrote: >> > On Tuesday, January 14, 2014 2:55:00 PM UTC+5:30, Igor Korot wrote: >> >> What if I want field 2 and field 3? ("seq 200" and "length 30") >> > Wee you did say: >> >> I'm interesred in only one element, so why should care about everything else? >> > So its not clear what you want! > >> Sorry, I thought it would be easier to ask this way. Guess not. > >> I am actually looking for a way to get a result from split which is >> sliced the way I want. Like in my example above. >> I mean I can probably make more variable by creating a tuple, but why? >> What is the purpose if I want only couple elements out of split. >> Doing it Perl way does not help: > >> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python >> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> test = "I,like,my,chocolate" >> >>> print test.split(',')[2,3] > > You want this? > >>>> test = "I,like,my,chocolate" >>>> test.split(',') > ['I', 'like', 'my', 'chocolate'] >>>> test.split(',')[2:4] > ['my', 'chocolate'] Yup, thats it. Now 2 and 4 - it's a starting point and ending point, right? Thank you. > > >> Well is there a Python way to do what I want? > > > Well I for one still dont get what you want!! > > Heres a python one-liner using regexps >>>> r=r'(.*) +> +(.*):.*length (\d*)' >>>> re.findall(r,data) > [('192.168.1.6', '192.168.1.7', '30')] > > Note: I am NOT suggesting you use regexps. Just that they will do what you want if you are so inclined > -- > https://mail.python.org/mailman/listinfo/python-list From fomcl at yahoo.com Tue Jan 14 05:42:07 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Tue, 14 Jan 2014 02:42:07 -0800 (PST) Subject: L[:] In-Reply-To: Message-ID: <1389696127.37654.YahooMailBasic@web163802.mail.gq1.yahoo.com> On 1/13/2014 4:00 AM, Laszlo Nagy wrote: > >> Unless L is aliased, this is silly code. > There is another use case. If you intend to modify a list within a for > loop that goes over the same list, then you need to iterate over a copy. > And this cannot be called an "alias" because it has no name: for i in somelist: creates a second reference to somelist that somewhere in the loop code has a name, so it is effectively an 'alias'. The essential point is that there are two access paths to the same object. > for idx,item in enumerate(L[:]): >? ???# do something with L here, including modification The copy is only needed in the above if one inserts or deletes. But if one inserts or deletes more than one item, one nearly always does better to iterate through the original and construct a new list with new items added and old items not copied. ====> Hi, first, thank you all for your replies -much appreciated! Terry, this would be making a shallow copy, right? If so, then "list(L)" is slightly nicer IMHO, but that's probably a matter of taste (however, I don't like copy.copy, even though that's perhaps most clear --oh well nitpicking ;-) I also found that item assignment ([1] below) is much faster than using the more standard (I think) .append ([2]). # [1] for idx,item in enumerate(L[:]): if some_condition: L[idx] = foobarify(item) # [2] L2 = [] for idx,item in enumerate(L): if some_condition: L2.append(foobarify(item)) else: L2.append(item) From rustompmody at gmail.com Tue Jan 14 05:51:15 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jan 2014 02:51:15 -0800 (PST) Subject: What's correct Python syntax? In-Reply-To: References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: On Tuesday, January 14, 2014 4:05:27 PM UTC+5:30, Igor Korot wrote: > Hi, Rustom, > > > > On Tue, Jan 14, 2014 at 2:16 AM, Rustom Mody wrote: > > You want this? > > > >>>> test = "I,like,my,chocolate" > >>>> test.split(',') > > ['I', 'like', 'my', 'chocolate'] > >>>> test.split(',')[2:4] > > ['my', 'chocolate'] > > > Yup, thats it. > Now 2 and 4 - it's a starting point and ending point, right? In python ranges are usually lo-inclusive hi-exclusive. Slices are one case of this See explanations: http://docs.python.org/2/tutorial/introduction.html#strings and http://stackoverflow.com/questions/509211/pythons-slice-notation Neat theoretical explanation http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html From alister.ware at ntlworld.com Tue Jan 14 05:59:44 2014 From: alister.ware at ntlworld.com (Alister) Date: Tue, 14 Jan 2014 10:59:44 GMT Subject: What's correct Python syntax? References: Message-ID: On Tue, 14 Jan 2014 00:46:56 -0800, Igor Korot wrote: > Hi, ALL, > I'm trying to process a file which has following lines: > > 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > > (this is the text file out of tcpdump) > > Now I can esily split the line twice: once by ':' symbol to separate > address and the protocol information and the second time by ',' to get > information about the protocol. > However, I don't need all the protocol info. All I'm interested in is > the last field, which is length. > > Is there a way to write something like this: > > for data in f: > (address,traffic) = string.split(data, ':') > length = string.split(traffic, ',')[3] > > I'm interesred in only one element, so why should care about everything > else? > This can be easily done in Perl, but I'm stuck with Python now. ;-) > > Thank you. Am I missing something obvious here? just split on ',' field [0] will contain a mix of data but who cares? you don't want it anyway (you can always process it again afterwards. >>> a='192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30' >>> data=a.split(',') >>> data ['192.168.1.6 > 192.168.1.7: ICMP echo request', ' id 100', ' seq 200', ' length 30'] >>> data[3] ' length 30' -- It's not against any religion to want to dispose of a pigeon. -- Tom Lehrer, "Poisoning Pigeons in the Park" From gilles.lenfant at gmail.com Tue Jan 14 06:21:03 2014 From: gilles.lenfant at gmail.com (Gilles Lenfant) Date: Tue, 14 Jan 2014 03:21:03 -0800 (PST) Subject: Stopping a wsgiref server programmatically Message-ID: Hi, I made a small / minimal wsgiref HTTP server dedicated to unittest stubs (testing custom REST client and other likes) that works pretty good in a separate thread. https://gist.github.com/glenfant/7369894 Feel free to reuse it in your own unittest stubs/mocks. But it only works like a charm in an Unix box, due to the use of a control pipe ( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L118 ) that's checked with select.select ( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L133 ) and can be stopped on request when writing in that pipe ( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L173 ). Is there a volunteer with a Windows box for helping me to get it fixed. Note: I have no windows box to experiment alternate. Many thanks by advance. -- Gilles Lenfant From __peter__ at web.de Tue Jan 14 06:33:26 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Jan 2014 12:33:26 +0100 Subject: What's correct Python syntax? References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: Igor Korot wrote: > I am actually looking for a way to get a result from split which is > sliced the way I want. Like in my example above. > I mean I can probably make more variable by creating a tuple, but why? > What is the purpose if I want only couple elements out of split. > Doing it Perl way does not help: > > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> test = "I,like,my,chocolate" >>>> print test.split(',')[2,3] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers, not tuple > > I can do it this way: > >>>> testlist = test.split(',') >>>> print testlist[2] > my > > but it will needlessly creates a list on which I will access by the index. > > Why? All I need is couple of values out of n-dimensional list (array). Python has no dedicated syntax for picking arbitrary items from a list If you are only concerned about printing use format(): >>> items = ["alpha", "beta", "gamma", "delta"] >>> print "{1} {3} {0}".format(*items) beta delta alpha If you want to work with the values use operator.itemgetter(): >>> from operator import itemgetter >>> itemgetter(1, 0, -1)(items) ('beta', 'alpha', 'delta') From ned at nedbatchelder.com Tue Jan 14 07:19:42 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 14 Jan 2014 07:19:42 -0500 Subject: What's correct Python syntax? In-Reply-To: References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: On 1/14/14 6:33 AM, Peter Otten wrote: > Python has no dedicated syntax for picking arbitrary items from a list > If you are only concerned about printing use format(): > >>>> >>>items = ["alpha", "beta", "gamma", "delta"] >>>> >>>print "{1} {3} {0}".format(*items) > beta delta alpha .format also supports item access directly: >>> items = ["alpha", "beta", "gamma", "delta"] >>> print "{0[1]} {0[3]} {0[0]}".format(items) beta delta alpha It's clunkier in this example, but if you have more than one value being formatted, this (and the "{0.foo}" syntax) can make digging into nested data more convenient. -- Ned Batchelder, http://nedbatchelder.com From ycui at outlook.com Tue Jan 14 07:20:36 2014 From: ycui at outlook.com (Frank Cui) Date: Tue, 14 Jan 2014 09:20:36 -0300 Subject: a web UI to invoke a python script at server side Message-ID: Hey guys, I'm working on to provide a lightweight web UI for providing an interface to invoke a python script(a sequential script which could involve some system calls) at the server side. The UI should collect some parameters for input into this python script, and conversely the output of the script needs to be returned to the web client side. I haven't done much web programming before, can you provide some hints on how this is usually implemented ? ThanksFrank -------------- next part -------------- An HTML attachment was scrubbed... URL: From norman.elliott at gmail.com Tue Jan 14 08:04:43 2014 From: norman.elliott at gmail.com (Norman Elliott) Date: Tue, 14 Jan 2014 05:04:43 -0800 (PST) Subject: plotting slows down In-Reply-To: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: @Dave, no problem. I am using gedit to write the files and have it set to translate tabs into 4 spaces which is what was recommended to me as the right amount of indenting for python scripts. On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott wrote: > First let me say I have not done much python programming! > > I am running Python 2.7.3. > > I am trying to use python as a front end to a simple oscilloscope. > > Ultimately I intend to use it with my micropython board. > > > > At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data. > > > > Each time it goes through the outer loop it gets slower and slower. > > I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds. > > Can anyone explain what I am doing wrong please? > > Here is the code: > > [code] > > #!/usr/bin/python > > from graphics import * > > import random > > import time > > > > xpos=1200 > > ypos=400 > > ypnt=ypos/2 > > pos=1 > > #setBackground("white") > > def main(): > > win = GraphWin("My Circle", xpos, ypos) > > # win.setBackGround('white') > > for y in range(1,5): > > cir2 = Circle(Point(xpos/2,20), 10) > > cir2.setFill("white") > > cir2.draw(win) > > message = Text(Point(win.getWidth()/2, 20), y) > > message.draw(win) > > j = random.randint(1,ypos) > > for x in range(1,xpos): > > updown = random.randint(0,1) > > if updown: > > j=j+1 > > else: > > j=j-1 > > if j <1: > > j=ypos/2 > > if j>ypos-1: > > j=ypos/2 > > win.plot(x,j,"red") > > time.sleep(.0001) > > > > main() > > time.sleep(5) > > [/code] From rustompmody at gmail.com Tue Jan 14 08:15:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 14 Jan 2014 05:15:01 -0800 (PST) Subject: plotting slows down In-Reply-To: References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On Tuesday, January 14, 2014 6:34:43 PM UTC+5:30, Norman Elliott wrote: > @Dave, no problem. I am using gedit to write the files and have it set to translate tabs into 4 spaces which is what was recommended to me as the right amount of indenting for python scripts. Dunno what you mean by 'translate' If that means actually replace the characters, then that will cause minimum problems However it can also mean that gedit sets tabstops at 4 character intervals Which will mean you will see 4 characters (in gedit) and everyone else will see a tab. This is a recipe for trouble. From jeanmichel at sequans.com Tue Jan 14 08:22:21 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Tue, 14 Jan 2014 14:22:21 +0100 (CET) Subject: a web UI to invoke a python script at server side In-Reply-To: Message-ID: <738026585.3780443.1389705741775.JavaMail.root@sequans.com> ----- Original Message ----- > Hey guys, > I'm working on to provide a lightweight web UI for providing an > interface to invoke a python script(a sequential script which could > involve some system calls) at the server side. The UI should collect > some parameters for input into this python script, and conversely > the output of the script needs to be returned to the web client > side. > I haven't done much web programming before, can you provide some > hints on how this is usually implemented ? > Thanks > Frank > -- > https://mail.python.org/mailman/listinfo/python-list Hi Frank, Have a look at http://flask.pocoo.org/ This is a micro web framework. Build your "hello world" web app, once it's working, look at the flask tutorial, you won't use the database but it'll give you a good overview of how things are organized. Flask support python 3 but your web server may not. You may need to stick with python 2. 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 roy at panix.com Tue Jan 14 08:34:31 2014 From: roy at panix.com (Roy Smith) Date: Tue, 14 Jan 2014 08:34:31 -0500 Subject: What's correct Python syntax? References: Message-ID: In article , Igor Korot wrote: > Hi, ALL, > I'm trying to process a file which has following lines: > > 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > > (this is the text file out of tcpdump) > > Now I can esily split the line twice: once by ':' symbol to separate > address and the protocol information and the second time by ',' to get > information about the protocol. > However, I don't need all the protocol info. All I'm interested in is > the last field, which is length. One possibility would be to forget about all the punctuation and just use "length " (note the trailing space) as the split delimiter: >>> line = '192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30' >>> line.split('length ') '30' this will only work if you're sure that "length " can never appear anywhere else in the line. Another, perhaps more idiomatic, way would be: >>> _, length = line.split('length ') >>> print length 30 What's happening here is split() is returning a list of two items, which you then unpack into two variables, "_" and "length". It's common to unpack unwanted fields into "_", as a hint (to the reader) that it's unused. From rosuav at gmail.com Tue Jan 14 08:36:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 00:36:34 +1100 Subject: plotting slows down In-Reply-To: References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 12:15 AM, Rustom Mody wrote: > However it can also mean that gedit sets tabstops at 4 character intervals > Which will mean you will see 4 characters (in gedit) and everyone else will see a > tab. This is a recipe for trouble. Not a recipe for trouble normally, it's just that some people's clients can't see them. So keep using tabs if you want to, but be prepared to search-and-replace them to spaces prior to posting code. Though I think the fault is with the client(s) that can't see tabs, and they're the ones that ought to be fixed. ChrisA From roy at panix.com Tue Jan 14 08:47:35 2014 From: roy at panix.com (Roy Smith) Date: Tue, 14 Jan 2014 08:47:35 -0500 Subject: What's correct Python syntax? References: <41a71031-be78-475f-bab2-822e35f909b7@googlegroups.com> Message-ID: In article , Igor Korot wrote: > I can do it this way: > > >>> testlist = test.split(',') > >>> print testlist[2] > my > > but it will needlessly creates a list on which I will access by the index. Stop worrying about needlessly creating lists. Write the code in a way that works and is easy to understand. If it turns out that it's not running fast enough, then you can go back and optimize. BTW, for those of you into code golf: >>> line = '192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30' >>> dict((k,int(v)) for k,v in (s.split() for s in line.split(', ')[1:])) {'length': 30, 'id': 100, 'seq': 200} From ayushidalmia2604 at gmail.com Tue Jan 14 08:50:06 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Tue, 14 Jan 2014 05:50:06 -0800 (PST) Subject: Python Fast I/o Message-ID: I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file. Presently I am using this: with open('index.txt','w') as f: f.write("".join(data)) f.close() where data is a list of strings which I want to dump into the index.txt file From rosuav at gmail.com Tue Jan 14 09:03:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 01:03:08 +1100 Subject: Python Fast I/o In-Reply-To: References: Message-ID: On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia wrote: > I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file. > > Presently I am using this: > > with open('index.txt','w') as f: > f.write("".join(data)) > f.close() with open('index.txt','w') as f: for hunk in data: f.write(hunk) You don't need to f.close() - that's what the 'with' block guarantees. Iterating over data and writing each block separately means you don't have to first build up a 200MB string. After that, your performance is going to be mainly tied to the speed of your disk, not anything that Python can affect. ChrisA From larry.martell at gmail.com Tue Jan 14 09:18:50 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 14 Jan 2014 07:18:50 -0700 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Mon, Jan 13, 2014 at 11:32 AM, Chris Angelico wrote: > On Tue, Jan 14, 2014 at 5:27 AM, Larry Martell wrote: >> Thanks. Unfortunately this has been made a low priority task and I've >> been put on to something else (I hate when they do that). > > Ugh, I know that feeling all too well! Life's better when you're > unemployed, and you can choose the interesting problems to work on. > Apart from the "has to be in MySQL" restriction (dodged now that the > work's all being done in Python anyway), yours is _definitely_ an > interesting problem. if you're interested in what the application is, this is data collected with an electron microscope from semiconductor wafers as they are being manufactured. The x and y are the position on the wafer that the data was collected, in microns. If 2 data points are collected within 1 micron of each other they need to be combined when being analyzed. From ayushidalmia2604 at gmail.com Tue Jan 14 09:24:19 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Tue, 14 Jan 2014 06:24:19 -0800 (PST) Subject: Python Fast I/o In-Reply-To: References: Message-ID: <53affb01-0c5e-46e3-9ff7-27a529db6425@googlegroups.com> On Tuesday, January 14, 2014 7:33:08 PM UTC+5:30, Chris Angelico wrote: > On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia > > wrote: > > > I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file. > > > > > > Presently I am using this: > > > > > > with open('index.txt','w') as f: > > > f.write("".join(data)) > > > f.close() > > > > with open('index.txt','w') as f: > > for hunk in data: > > f.write(hunk) > > > > You don't need to f.close() - that's what the 'with' block guarantees. > > Iterating over data and writing each block separately means you don't > > have to first build up a 200MB string. After that, your performance is > > going to be mainly tied to the speed of your disk, not anything that > > Python can affect. > > > > ChrisA Thanks for the tip on the closing of the file. I did not know that with ensures closing of the file after iteration is over. Which is more fast? Creating a 200 Mb string and then dumping into a file or dividing the 200 Mb string into chunks and then writing those chunks. Won't writing the chunks call more i/o operation? From rosuav at gmail.com Tue Jan 14 09:26:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 01:26:31 +1100 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Wed, Jan 15, 2014 at 1:18 AM, Larry Martell wrote: > if you're interested in what the application is, this is data > collected with an electron microscope from semiconductor wafers as > they are being manufactured. The x and y are the position on the wafer > that the data was collected, in microns. If 2 data points are > collected within 1 micron of each other they need to be combined when > being analyzed. As far as I'm concerned, you won geek cred the moment you said "electron microscope", and "semiconductor wafers as they are being manufactured" is just gravy I don't suppose you want to hire another programmer? :) Do you actually mean here that the two points need to be within 1 micron, or that data gets combined if it's nearby in *either* coordinate? There are libraries for figuring out if two things are near each other - I'm not 100% sure, but you might be able to do this inside PostgreSQL (though that just gets back to the previous rule: can't move off MySQL). Treat every data point as a circle or square, and then look for overlap. ChrisA From rosuav at gmail.com Tue Jan 14 09:32:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 01:32:44 +1100 Subject: Python Fast I/o In-Reply-To: <53affb01-0c5e-46e3-9ff7-27a529db6425@googlegroups.com> References: <53affb01-0c5e-46e3-9ff7-27a529db6425@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 1:24 AM, Ayushi Dalmia wrote: > On Tuesday, January 14, 2014 7:33:08 PM UTC+5:30, Chris Angelico wrote: >> On Wed, Jan 15, 2014 at 12:50 AM, Ayushi Dalmia >> >> wrote: >> >> > I need to write into a file for a project which will be evaluated on the basis of time. What is the fastest way to write 200 Mb of data, accumulated as a list into a file. >> >> > >> >> > Presently I am using this: >> >> > >> >> > with open('index.txt','w') as f: >> >> > f.write("".join(data)) >> >> > f.close() >> >> >> >> with open('index.txt','w') as f: >> >> for hunk in data: >> >> f.write(hunk) >> >> >> >> You don't need to f.close() - that's what the 'with' block guarantees. >> >> Iterating over data and writing each block separately means you don't >> >> have to first build up a 200MB string. After that, your performance is >> >> going to be mainly tied to the speed of your disk, not anything that >> >> Python can affect. >> >> >> >> ChrisA Your quoted text is becoming double spaced, because of bugs in the Google Groups client. Please either edit this before posting, or switch to a better newsreader, or use the mailing list: https://mail.python.org/mailman/listinfo/python-list Thanks! > Which is more fast? > Creating a 200 Mb string and then dumping into a file or dividing the 200 Mb string into chunks and then writing those chunks. Won't writing the chunks call more i/o operation? > When you're writing two hundred megabytes, the number of I/O operations is dominated by that. You have to write that many sectors, and nothing can change that. Joining your list of strings before writing incurs the cost of building up a single 200MB string, but even that is likely to be insignificant in the scheme of things (if you have the memory available, it won't take very long compared to the time it takes to write to the disk). Python will buffer its writes, so you don't have to worry about the details. It's going to do the right thing for you; you can concentrate on making your code look right. ChrisA From roy at panix.com Tue Jan 14 09:40:34 2014 From: roy at panix.com (Roy Smith) Date: Tue, 14 Jan 2014 09:40:34 -0500 Subject: Python Fast I/o References: <53affb01-0c5e-46e3-9ff7-27a529db6425@googlegroups.com> Message-ID: In article <53affb01-0c5e-46e3-9ff7-27a529db6425 at googlegroups.com>, Ayushi Dalmia wrote: > Which is more fast? > Creating a 200 Mb string and then dumping into a file or dividing the 200 Mb > string into chunks and then writing those chunks. Won't writing the chunks > call more i/o operation? This sounds like a simple experiment to try. Write it both ways, time each one, and report your results back to the group. From python.list at tim.thechases.com Tue Jan 14 09:18:33 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 14 Jan 2014 08:18:33 -0600 Subject: Python Fast I/o In-Reply-To: References: Message-ID: <20140114081833.7c11612d@bigbox.christie.dr> On 2014-01-14 05:50, Ayushi Dalmia wrote: > I need to write into a file for a project which will be evaluated > on the basis of time. What is the fastest way to write 200 Mb of > data, accumulated as a list into a file. > > Presently I am using this: > > with open('index.txt','w') as f: > f.write("".join(data)) > f.close() > > where data is a list of strings which I want to dump into the > index.txt file -- Most file-like objects should support a writelines() method which takes an iterable and should save you the trouble of joining all the content (and as Chris noted, you don't need the .close() since the with handles it) so the whole thing would condense to: with open('index.txt', 'w') as f: f.writelines(data) -tkc From ngangsia at gmail.com Tue Jan 14 10:26:10 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Tue, 14 Jan 2014 07:26:10 -0800 (PST) Subject: wx (not responding) Message-ID: When i run this code on my pc it actually runs but signals that the app is not responding. import wx class Example(wx.Frame): def __init__(self, *args, **kwargs): super(Example, self).__init__(*args, **kwargs) self.InitUI() def InitUI(self): menubar = wx.MenuBar() fileMenu = wx.Menu() fitem = fileMenu.Append(wx.ID_EXIT, 'QUIT', 'Quit application') menubar.Append(fileMenu, '&File') self.Bind(wx.EVT_MENU, self.OnQuit, fitem) self.SetSize((300, 200)) self.SetTitle('Simple menu') self.Center() self.Show(True) def OnQuit(self, e): self.Close() def main(): ex = wx.App() Example(None) ex.Mainloop() if __name__ == "__main__": main() From fpm at u.washington.edu Tue Jan 14 10:56:42 2014 From: fpm at u.washington.edu (Frank Miles) Date: Tue, 14 Jan 2014 15:56:42 +0000 (UTC) Subject: wx (not responding) References: Message-ID: On Tue, 14 Jan 2014 07:26:10 -0800, ngangsia akumbo wrote: > When i run this code on my pc it actually runs but signals that the app is not responding. [snip most of the code]- > def main(): > ex = wx.App() > Example(None) > ex.Mainloop() > > > if __name__ == "__main__": > main() When I tried to run it I got a "AttributeError: 'App' object has no attribute 'Mainloop' Not sure whether your wx version might have a 'Mainloop'. From larry.martell at gmail.com Tue Jan 14 11:23:02 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 14 Jan 2014 09:23:02 -0700 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Tue, Jan 14, 2014 at 7:26 AM, Chris Angelico wrote: > On Wed, Jan 15, 2014 at 1:18 AM, Larry Martell wrote: >> if you're interested in what the application is, this is data >> collected with an electron microscope from semiconductor wafers as >> they are being manufactured. The x and y are the position on the wafer >> that the data was collected, in microns. If 2 data points are >> collected within 1 micron of each other they need to be combined when >> being analyzed. > > As far as I'm concerned, you won geek cred the moment you said > "electron microscope", and "semiconductor wafers as they are being > manufactured" is just gravy. Thanks! You made my day. I showed this to my wife and she asked "Is that good?" > Do you actually mean here that the two points need to be within 1 > micron, or that data gets combined if it's nearby in *either* > coordinate? Either coordinate. From mailinglists at xgm.de Tue Jan 14 11:37:36 2014 From: mailinglists at xgm.de (Florian Lindner) Date: Tue, 14 Jan 2014 17:37:36 +0100 Subject: Encoding trouble when script called from application Message-ID: <11036720.dCfMmLrdqv@horus> Hello! I'm using python 3.2.3 on debian wheezy. My script is called from my mail delivery agent (MDA) maildrop (like procmail) through it's xfilter directive. Script works fine when used interactively, e.g. ./script.py < testmail but when called from maildrop it's producing an infamous UnicodeDecodeError: File "/home/flindner/flofify.py", line 171, in main mail = sys.stdin.read() File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] Exception for example is always like UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: ordinal not in range(128) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: ordinal not in range(128) UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: ordinal not in range(128) I read mail from stdin "mail = sys.stdin.read()" Environment when called is: locale.getpreferredencoding(): ANSI_X3.4-1968 environ["LANG"]: C System environment when using shell is: ~ % echo $LANG en_US.UTF-8 As far as I know when reading from stdin I don't need an decode(...) call, since stdin has a decoding. I also tried some decoding/encoding stuff but changed nothing. Any ideas to help me? Thanks! Florian From rosuav at gmail.com Tue Jan 14 11:37:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 03:37:42 +1100 Subject: efficient way to process data In-Reply-To: References: Message-ID: On Wed, Jan 15, 2014 at 3:23 AM, Larry Martell wrote: >> As far as I'm concerned, you won geek cred the moment you said >> "electron microscope", and "semiconductor wafers as they are being >> manufactured" is just gravy. > > Thanks! You made my day. I showed this to my wife and she asked "Is that good?" Heh! Geek language can be a bit weird at times. Of course, it's not a dream job if things like this get tantalizingly dangled in front of you and then taken away as you're given something less fun and more urgent to do... >> Do you actually mean here that the two points need to be within 1 >> micron, or that data gets combined if it's nearby in *either* >> coordinate? > > Either coordinate. Okay, so the code I put together earlier in the thread is correct. ChrisA From python at mrabarnett.plus.com Tue Jan 14 12:00:48 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Jan 2014 17:00:48 +0000 Subject: python-list@python.org In-Reply-To: <11036720.dCfMmLrdqv@horus> References: <11036720.dCfMmLrdqv@horus> Message-ID: <52D56D40.1060401@mrabarnett.plus.com> On 2014-01-14 16:37, Florian Lindner wrote: > Hello! > > I'm using python 3.2.3 on debian wheezy. My script is called from my mail delivery agent (MDA) maildrop (like procmail) through it's xfilter directive. > > Script works fine when used interactively, e.g. ./script.py < testmail but when called from maildrop it's producing an infamous UnicodeDecodeError: > > File "/home/flindner/flofify.py", line 171, in main > mail = sys.stdin.read() > File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode > return codecs.ascii_decode(input, self.errors)[0] > > Exception for example is always like > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: ordinal not in range(128) > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: ordinal not in range(128) > UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: ordinal not in range(128) > > I read mail from stdin "mail = sys.stdin.read()" > > Environment when called is: > > locale.getpreferredencoding(): ANSI_X3.4-1968 > environ["LANG"]: C > > System environment when using shell is: > > ~ % echo $LANG > en_US.UTF-8 > > As far as I know when reading from stdin I don't need an decode(...) call, since stdin has a decoding. I also tried some decoding/encoding stuff but changed nothing. > > Any ideas to help me? > When run from maildrop it thinks that the encoding of stdin is ASCII. From mal at python.org Tue Jan 14 12:05:59 2014 From: mal at python.org (M.-A. Lemburg) Date: Tue, 14 Jan 2014 18:05:59 +0100 Subject: ANN: Python Events Calendar - Please submit your 2014 events Message-ID: <52D56E77.8060601@python.org> [Please help spread the word by forwarding to other relevant mailing lists, user groups, etc. world-wide; thanks :-)] ________________________________________________________________________ ANNOUNCING Python Events Calendars - Please submit your 2014 events maintained by the Python Software Foundation (PSF) and a group of volunteers ________________________________________________________________________ INTRODUCTION As some of you may know, the PSF has put together a team of volunteers who are maintaining a central Python events calendar. We currently have two calendars in place: * Python Events Calendar - meant for conferences and larger gatherings focusing on Python or a related technology (in whole or in part) * Python User Group Calendar - meant for user group events and other smaller local events The calendars are displayed on http://pycon.org/ and in a smaller version in the sidebar of the http://python.org/ website. You can subscribe to the calendars using iCal and RSS feeds and also embed the calendar widgets on your sites. Please see our wiki page for details: https://wiki.python.org/moin/PythonEventsCalendar The calendars are open to the world-wide Python community, so you can have local user group events, as well as regional and international conference events added to the calendars. ________________________________________________________________________ NEWS Created in Oct 2012, the project has been proven to be a success as you can see in the past events listed in the calendars. We would like to encourage everyone to submit their 2014 events, so that the Python community can get a better overview over what's happening in Python land. ________________________________________________________________________ ADDING EVENTS If you want to have entries added to those calendars, please write to events at python.org and include the following information: * Name of the event * Type of the event (conference, bar camp, user group, etc) * Focus on Python and approximate size * URL * Location and country * Date and time (if relevant) For recurring events, please also include a description of the recurrence in a way that's compatible and supported by Google calendars. ________________________________________________________________________ MORE INFORMATION More information on the calendars, the URLs, feed links, IDs, embedding, etc. is available on the wiki: https://wiki.python.org/moin/PythonEventsCalendar Enjoy, -- Marc-Andre Lemburg Director Python Software Foundation http://www.python.org/psf/ From norman.elliott at gmail.com Tue Jan 14 12:06:00 2014 From: norman.elliott at gmail.com (Norman Elliott) Date: Tue, 14 Jan 2014 09:06:00 -0800 (PST) Subject: plotting slows down In-Reply-To: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> References: <4c51b5e8-e7b4-4a09-95d4-daefbfe27b28@googlegroups.com> Message-ID: <5809ea9f-401b-4011-907d-72addb3a2b26@googlegroups.com> On Monday, 13 January 2014 08:15:08 UTC, Norman Elliott wrote: > First let me say I have not done much python programming! > > I am running Python 2.7.3. > > I am trying to use python as a front end to a simple oscilloscope. > > Ultimately I intend to use it with my micropython board. > > > > At the moment I am just developing it. All it does is use a module I found called graphics.py to create a window and display randomly generated data. > > > > Each time it goes through the outer loop it gets slower and slower. > > I put in a small delay just so I could observe what is happening and for the first line it draws it takes about a second. If I set it to loop 20 times the final loop takes more than 6 seconds. > > Can anyone explain what I am doing wrong please? > > Here is the code: > > [code] > > #!/usr/bin/python > > from graphics import * > > import random > > import time > > > > xpos=1200 > > ypos=400 > > ypnt=ypos/2 > > pos=1 > > #setBackground("white") > > def main(): > > win = GraphWin("My Circle", xpos, ypos) > > # win.setBackGround('white') > > for y in range(1,5): > > cir2 = Circle(Point(xpos/2,20), 10) > > cir2.setFill("white") > > cir2.draw(win) > > message = Text(Point(win.getWidth()/2, 20), y) > > message.draw(win) > > j = random.randint(1,ypos) > > for x in range(1,xpos): > > updown = random.randint(0,1) > > if updown: > > j=j+1 > > else: > > j=j-1 > > if j <1: > > j=ypos/2 > > if j>ypos-1: > > j=ypos/2 > > win.plot(x,j,"red") > > time.sleep(.0001) > > > > main() > > time.sleep(5) > > [/code] Okay, maybe I misunderstood what it was doing. I have checked and I will do a find and replace of the tabs with 4 spaces in future. From ngangsia at gmail.com Tue Jan 14 12:27:07 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Tue, 14 Jan 2014 09:27:07 -0800 (PST) Subject: python adsl script Message-ID: <69acfb5b-4cb2-4751-a20d-ae25e39ec471@googlegroups.com> what about a python script that can retrieve my entire isp setting from my adsl router. Any ideas Also my grand mother forget her computer password, she can only login through the guest account. what about a script that can solve that problem. From denismfmcmahon at gmail.com Tue Jan 14 12:30:29 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 14 Jan 2014 17:30:29 +0000 (UTC) Subject: python adsl script References: <69acfb5b-4cb2-4751-a20d-ae25e39ec471@googlegroups.com> Message-ID: On Tue, 14 Jan 2014 09:27:07 -0800, ngangsia akumbo wrote: > what about a python script that can retrieve my entire isp setting from > my adsl router. > Any ideas This is probably possible using telnet, so it should be possible to do it over a socket interface, yes. > Also my grand mother forget her computer password, she can only login > through the guest account. what about a script that can solve that > problem. We are not your familiy's tech support group. Nor will we write your code from scratch for you. I suggest you learn to google. There are plenty of tools out there that can be used to reset passwords on various operating systems. -- Denis McMahon, denismfmcmahon at gmail.com From ngangsia at gmail.com Tue Jan 14 12:33:21 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Tue, 14 Jan 2014 09:33:21 -0800 (PST) Subject: wx (not responding) In-Reply-To: References: Message-ID: On Tuesday, January 14, 2014 4:56:42 PM UTC+1, cassiope wrote: > On Tue, 14 Jan 2014 07:26:10 -0800, ngangsia akumbo wrote: > Not sure whether your wx version might have a 'Mainloop'. I think is ok now thanks From stephane at wirtel.be Tue Jan 14 12:37:45 2014 From: stephane at wirtel.be (Stephane Wirtel) Date: Tue, 14 Jan 2014 18:37:45 +0100 Subject: python adsl script In-Reply-To: References: <69acfb5b-4cb2-4751-a20d-ae25e39ec471@googlegroups.com> Message-ID: +1 > On 14 janv. 2014, at 06:30 PM, Denis McMahon wrote: > >> On Tue, 14 Jan 2014 09:27:07 -0800, ngangsia akumbo wrote: >> >> what about a python script that can retrieve my entire isp setting from >> my adsl router. > >> Any ideas > > This is probably possible using telnet, so it should be possible to do it > over a socket interface, yes. > >> Also my grand mother forget her computer password, she can only login >> through the guest account. what about a script that can solve that >> problem. > > We are not your familiy's tech support group. Nor will we write your code > from scratch for you. > > I suggest you learn to google. There are plenty of tools out there that > can be used to reset passwords on various operating systems. > > -- > Denis McMahon, denismfmcmahon at gmail.com > -- > https://mail.python.org/mailman/listinfo/python-list From __peter__ at web.de Tue Jan 14 12:43:57 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 14 Jan 2014 18:43:57 +0100 Subject: Encoding trouble when script called from application References: <11036720.dCfMmLrdqv@horus> Message-ID: Florian Lindner wrote: > Hello! > > I'm using python 3.2.3 on debian wheezy. My script is called from my mail > delivery agent (MDA) maildrop (like procmail) through it's xfilter > directive. > > Script works fine when used interactively, e.g. ./script.py < testmail but > when called from maildrop it's producing an infamous UnicodeDecodeError: > > File "/home/flindner/flofify.py", line 171, in main > mail = sys.stdin.read() > File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode > return codecs.ascii_decode(input, self.errors)[0] > > Exception for example is always like > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: > ordinal not in range(128) UnicodeDecodeError: 'ascii' codec can't decode > byte 0xc3 in position 1176: ordinal not in range(128) UnicodeDecodeError: > 'ascii' codec can't decode byte 0x8c in position 846: ordinal not in > range(128) > > I read mail from stdin "mail = sys.stdin.read()" > > Environment when called is: > > locale.getpreferredencoding(): ANSI_X3.4-1968 > environ["LANG"]: C > > System environment when using shell is: > > ~ % echo $LANG > en_US.UTF-8 > > As far as I know when reading from stdin I don't need an decode(...) call, > since stdin has a decoding. I also tried some decoding/encoding stuff but > changed nothing. > > Any ideas to help me? I known nothing about maildrop, but found > add "import LANG" to .maildropfilter. in this thread: From fluttershy363 at gmail.com Tue Jan 14 14:11:20 2014 From: fluttershy363 at gmail.com (Lewis Wood) Date: Tue, 14 Jan 2014 11:11:20 -0800 (PST) Subject: Tkinter GUI Error In-Reply-To: References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> Message-ID: <3f7e442e-b86d-45c9-bd70-52c6abcca549@googlegroups.com> I cannot say how grateful I am to find such a community willing to help <3 Thanks to everyone posting, learned a lot of new stuff :) Never knew you could just bring a local var into a def block using global inside of the function. Again, thanks for taking your time to help out newbies to programming such as myself. From eneskristo at gmail.com Tue Jan 14 14:16:14 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Tue, 14 Jan 2014 11:16:14 -0800 (PST) Subject: On how to use cxFreeze Message-ID: <54c1b29e-873f-4a9b-8a5e-4ea9c17db9c4@googlegroups.com> For the first time in my life as a novice Python developer, I need to convert a python file to a .exe (AKA freeze it). Have been having a lot of problems in finding a proper guide, and have come here to ask for your help humbly. I am willing to provide any data if needed. Thank you! From miguelcoam at gmail.com Tue Jan 14 14:24:05 2014 From: miguelcoam at gmail.com (Mike) Date: Tue, 14 Jan 2014 11:24:05 -0800 (PST) Subject: Printer list value problem Message-ID: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> Hello, I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is: [........] user1 at example.com;user1;lastName;Name user2 at example.com;user2;lastName;Name [........] But when execute the script I view the print is only the last user [........] ca user2 at example.com displayName 'user2' sn 'lastName' cn 'Name' [........] And I need the next printer [........] ca user1 at example.com displayName 'User1' sn ''lastName" cn 'Name' ca user1 at example.com displayName 'User2' sn ''lastName" cn 'Name' [........] My script is [........] #!/usr/bin/python import csv with open ('users.csv', 'rb') as f: reader = csv.reader (f, delimiter=';' ) #delimiter tabulador for row in reader: mail = row [0] name = row [3] lastname = row [2] print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname) f.close() [........] Thanks. From noreply at eisenbits.com Tue Jan 14 14:33:50 2014 From: noreply at eisenbits.com (Staszek) Date: Tue, 14 Jan 2014 20:33:50 +0100 Subject: Python 3.x adoption Message-ID: Hi What's the problem with Python 3.x? It was first released in 2008, but web hosting companies still seem to offer Python 2.x rather. For example, Google App Engine only offers Python 2.7. What's wrong?... -- http://people.eisenbits.com/~stf/ http://www.eisenbits.com/ OpenPGP: 80FC 1824 2EA4 9223 A986 DB4E 934E FEA0 F492 A63B From python at mrabarnett.plus.com Tue Jan 14 14:32:49 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Jan 2014 19:32:49 +0000 Subject: Printer list value problem In-Reply-To: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> References: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> Message-ID: <52D590E1.4020306@mrabarnett.plus.com> On 2014-01-14 19:24, Mike wrote: > Hello, > I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is: > > [........] > user1 at example.com;user1;lastName;Name > user2 at example.com;user2;lastName;Name > [........] > > But when execute the script I view the print is only the last user > > [........] > ca user2 at example.com displayName 'user2' sn 'lastName' cn 'Name' > [........] > > And I need the next printer > > [........] > ca user1 at example.com displayName 'User1' sn ''lastName" cn 'Name' > ca user1 at example.com displayName 'User2' sn ''lastName" cn 'Name' > [........] > > My script is > > [........] > #!/usr/bin/python > import csv > with open ('users.csv', 'rb') as f: > > reader = csv.reader (f, delimiter=';' ) #delimiter tabulador > for row in reader: > > mail = row [0] > name = row [3] > lastname = row [2] > This line is indented the same amount as the 'for' loop, which means that it will be executed after the loop has finished. > print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname) > You don't need to close the file here because the 'with' statement will do that for you. > f.close() > [........] > > > Thanks. > From python.list at tim.thechases.com Tue Jan 14 14:38:11 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 14 Jan 2014 13:38:11 -0600 Subject: Printer list value problem In-Reply-To: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> References: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> Message-ID: <20140114133811.63ad5c08@bigbox.christie.dr> On 2014-01-14 11:24, Mike wrote: > Hello, > I confudsed,need printer the value of list (this is reaer from > csv) . The reader is ok, but my problem is in the print moment > because printer only the last value. For example my csv is: > > [........] > user1 at example.com;user1;lastName;Name > user2 at example.com;user2;lastName;Name > [........] > > But when execute the script I view the print is only the last user > with open ('users.csv', 'rb') as f: > > reader = csv.reader (f, delimiter=';' ) #delimiter tabulador > for row in reader: > > mail = row [0] > name = row [3] > lastname = row [2] > > print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname) This print needs to be at the same indentation as the previous bit. > f.close() This .close() is superfluous--the "with" takes care of that for you. I'd also unpack the row as I iterate to make it easier to read. That would make the final look something like with open("users.csv", "rb") as f: reader = csv.reader(f, delimiter=';') for mail, _, lastname, name in reader: print "ca {} displayName '{}' sn '{}'".format( mail, name, lastname) -tkc From skip at pobox.com Tue Jan 14 14:38:29 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 14 Jan 2014 13:38:29 -0600 Subject: Python 3.x adoption In-Reply-To: References: Message-ID: > What's the problem with Python 3.x? It was first released in 2008, but > web hosting companies still seem to offer Python 2.x rather. > > For example, Google App Engine only offers Python 2.7. > > What's wrong?... What makes you think anything's wrong? Major changes to any established piece of software takes a fairly long while to infiltrate. Lots of COBOL and Fortran 77 still running out there. I imagine there are still more than a few DOS and Windows 3.1 boxes as well. Why should adoption of Python 3.x be any different? Skip From rosuav at gmail.com Tue Jan 14 14:44:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 06:44:32 +1100 Subject: Python 3.x adoption In-Reply-To: References: Message-ID: On Wed, Jan 15, 2014 at 6:33 AM, Staszek wrote: > What's the problem with Python 3.x? It was first released in 2008, but > web hosting companies still seem to offer Python 2.x rather. > > For example, Google App Engine only offers Python 2.7. > > What's wrong?... There's nothing wrong with Python 3, but as Skip says, it takes time for people to migrate. Most cheap web hosts don't offer Python _at all_, but those that do have the choice of which version(s) to provide. It may be possible to call up either a 2.x or a 3.x by looking for "python" or "python3" - give it a try. ChrisA From miguelcoam at gmail.com Tue Jan 14 14:54:22 2014 From: miguelcoam at gmail.com (Mike) Date: Tue, 14 Jan 2014 11:54:22 -0800 (PST) Subject: Printer list value problem In-Reply-To: References: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> Message-ID: <75028f66-b36c-4b1d-b055-3beb05b66f8c@googlegroups.com> El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB escribi?: > On 2014-01-14 19:24, Mike wrote: > > > Hello, > > > I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is: > > > > > > [........] > > > user1 at example.com;user1;lastName;Name > > > user2 at example.com;user2;lastName;Name > > > [........] > > > > > > But when execute the script I view the print is only the last user > > > > > > [........] > > > ca user2 at example.com displayName 'user2' sn 'lastName' cn 'Name' > > > [........] > > > > > > And I need the next printer > > > > > > [........] > > > ca user1 at example.com displayName 'User1' sn ''lastName" cn 'Name' > > > ca user1 at example.com displayName 'User2' sn ''lastName" cn 'Name' > > > [........] > > > > > > My script is > > > > > > [........] > > > #!/usr/bin/python > > > import csv > > > with open ('users.csv', 'rb') as f: > > > > > > reader = csv.reader (f, delimiter=';' ) #delimiter tabulador > > > for row in reader: > > > > > > mail = row [0] > > > name = row [3] > > > lastname = row [2] > > > > > > > This line is indented the same amount as the 'for' loop, which means > > that it will be executed after the loop has finished. > > > > > print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname) > > > > > You don't need to close the file here because the 'with' statement will > > do that for you. > > > > > f.close() > > > [........] > > > > > > > > > Thanks. > > > Hello MRAB, I remove the "f.close" and after execute the script but still i have the same result (print the last row) Thanks From breamoreboy at yahoo.co.uk Tue Jan 14 15:03:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 14 Jan 2014 20:03:06 +0000 Subject: Printer list value problem In-Reply-To: <75028f66-b36c-4b1d-b055-3beb05b66f8c@googlegroups.com> References: <6139406d-9ccc-41b2-8aa8-7f6fd2431366@googlegroups.com> <75028f66-b36c-4b1d-b055-3beb05b66f8c@googlegroups.com> Message-ID: On 14/01/2014 19:54, Mike wrote: > El martes, 14 de enero de 2014 16:32:49 UTC-3, MRAB escribi?: >> On 2014-01-14 19:24, Mike wrote: >> >>> Hello, >> >>> I confudsed,need printer the value of list (this is reaer from csv) . The reader is ok, but my problem is in the print moment because printer only the last value. For example my csv is: >> >>> >> >>> [........] >> >>> user1 at example.com;user1;lastName;Name >> >>> user2 at example.com;user2;lastName;Name >> >>> [........] >> >>> >> >>> But when execute the script I view the print is only the last user >> >>> >> >>> [........] >> >>> ca user2 at example.com displayName 'user2' sn 'lastName' cn 'Name' >> >>> [........] >> >>> >> >>> And I need the next printer >> >>> >> >>> [........] >> >>> ca user1 at example.com displayName 'User1' sn ''lastName" cn 'Name' >> >>> ca user1 at example.com displayName 'User2' sn ''lastName" cn 'Name' >> >>> [........] >> >>> >> >>> My script is >> >>> >> >>> [........] >> >>> #!/usr/bin/python >> >>> import csv >> >>> with open ('users.csv', 'rb') as f: >> >>> >> >>> reader = csv.reader (f, delimiter=';' ) #delimiter tabulador >> >>> for row in reader: >> >>> >> >>> mail = row [0] >> >>> name = row [3] >> >>> lastname = row [2] >> >>> >> >> >> >> This line is indented the same amount as the 'for' loop, which means >> >> that it will be executed after the loop has finished. >> >> >> >>> print "ma {} displayName '{}' sn '{}'".format(mail,name,lastname) >> >>> >> >> You don't need to close the file here because the 'with' statement will >> >> do that for you. >> >> >> >>> f.close() >> >>> [........] >> >>> >> >>> >> >>> Thanks. >> >>> > > Hello MRAB, > I remove the "f.close" and after execute the script but still i have the same result (print the last row) > > Thanks > Your print statement needs to be inside the for loop, you currently have it after the loop has finished. Would you also please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From overhaalsgang_24_bob at me.com Tue Jan 14 15:04:42 2014 From: overhaalsgang_24_bob at me.com (BobAalsma) Date: Tue, 14 Jan 2014 12:04:42 -0800 (PST) Subject: fork seems to make urlopen into a black hole? Message-ID: <812aa8be-7a8d-4a15-86f1-deec17d68aad@googlegroups.com> A program took much too long to check some texts collected from web pages. As this could be made parallel easily, I put in fork. And the result seems to be that the program simply stops in the line with urlopen. Any suggestions? Relevant part: try: print 'urlopen by', kind_nummer, '- before' extern_adres = urlopen(adres).geturl() print 'urlopen by', kind_nummer, '- after' except IOError: tekst_string = 'URL "' + adres +'" geeft IO Error' print tekst_string, 'door', kind_nummer bloklijst_verslag.append(tekst_string + '\n') tekst_string = '\t**** Deze pagina wordt overgeslagen\n' bloklijst_verslag.append(tekst_string + '\n') adres = '' except: fout = sys.exc_info()[:2] tekst_string = 'URL "' + adres + '" geeft fout ' + fout print tekst_string, 'door', kind_nummer bloklijst_verslag.append(tekst_string + '\n') tekst_string = '\t**** Deze pagina wordt overgeslagen\n' bloklijst_verslag.append(tekst_string + '\n') adres = '' else: print 'urlopen by', kind_nummer, '- else' if extern_adres != adres: tekst_string = '\t**** redirect naar ' + extern_adres bloklijst_verslag.append(tekst_string + '\n') >From this block, the only response seen is the first print statement ("url open by .... - before") and then nothing else seems to happen in that child. This happens for all children: the expected number of children is reached and they all reach (only) this point. From rosuav at gmail.com Tue Jan 14 15:07:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 07:07:49 +1100 Subject: fork seems to make urlopen into a black hole? In-Reply-To: <812aa8be-7a8d-4a15-86f1-deec17d68aad@googlegroups.com> References: <812aa8be-7a8d-4a15-86f1-deec17d68aad@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 7:04 AM, BobAalsma wrote: > A program took much too long to check some texts collected from web pages. > As this could be made parallel easily, I put in fork. Rather than using the low-level fork() function, you may find it easier to manage things if you use the multiprocessing module. I don't know if it'll help in this specific case, but if nothing else, it'll be easier to see what's going on. ChrisA From dvkeeney at gmail.com Tue Jan 14 15:26:55 2014 From: dvkeeney at gmail.com (David) Date: Tue, 14 Jan 2014 12:26:55 -0800 (PST) Subject: setup.py install and compile errors Message-ID: How does a setup script conditionally change what modules are installed based on version? Background: I have a python2.x/3.x module that puts 3.3-only code in submodules. When the module imports those submodules using an older python version, the compiler raises SyntaxErrors in the submodule which show as import errors in the module, get caught and ignored. The features in the submodule won't be available, but they wont stop the module from functioning. The problem syntax to be masked is the 'yield from' expression. Problem: Thie above works, resulting in a functioning module under a range of python versions, but older versions want to compile all .py modules as part of setup.py install, and that produces ugly install messages, with stack-traces. I would like to avoid the ugliness. I can add python code to setup.py, before the setup(...) call, but it is unclear what will be available to that code, at that time. I can test for whether setup.py is being run in install mode using "if 'install' in sys.argv:", and delete the offending .py submodules, but can I assume that the dir holding setup.py is the current dir during install? Does the MANIFEST need to be altered, also, to match the changed file collection? Alternatively, I could alter the MANIFEST.in to add 'prune..' statements, but is that file even used as part of install? From ikorot01 at gmail.com Tue Jan 14 16:10:07 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 14 Jan 2014 13:10:07 -0800 Subject: dictionary with tuples Message-ID: Hi, ALL, C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> dict = {} >>> dict[(1,2)] = ('a','b') >>> dict[(3,4)] = ('c','d') >>> for (key1,key2),(value1,value2) in dict: ... print key1, " ", key2 ... print value1, " ", value2 ... Traceback (most recent call last): File "", line 1, in TypeError: 'int' object is not iterable >>> What am I doing wrong? Thank you. From larry.martell at gmail.com Tue Jan 14 16:15:43 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 14 Jan 2014 14:15:43 -0700 Subject: dictionary with tuples In-Reply-To: References: Message-ID: On Tue, Jan 14, 2014 at 2:10 PM, Igor Korot wrote: > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> dict = {} >>>> dict[(1,2)] = ('a','b') >>>> dict[(3,4)] = ('c','d') >>>> for (key1,key2),(value1,value2) in dict: > ... print key1, " ", key2 > ... print value1, " ", value2 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable >>>> > > What am I doing wrong? You need to iterate over dict.items() From python.list at tim.thechases.com Tue Jan 14 16:18:57 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 14 Jan 2014 15:18:57 -0600 Subject: dictionary with tuples In-Reply-To: References: Message-ID: <20140114151857.1ea6ac62@bigbox.christie.dr> On 2014-01-14 13:10, Igor Korot wrote: > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> dict = {} > >>> dict[(1,2)] = ('a','b') > >>> dict[(3,4)] = ('c','d') > >>> for (key1,key2),(value1,value2) in dict: > > What am I doing wrong? You should iterate over either dict.items() or dict.iteritems() Also, it's bad practice to shadow the builtin "dict()", so I'd choose another name: d = {} d[(1, 2)] = ('a', 'b') d[(3, 4)] = ('c', 'd') for (k1, k2), (v1, v2) in d.iteritems(): do_something(k1, k2, v1, v2) -tkc From python at mrabarnett.plus.com Tue Jan 14 16:21:56 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 14 Jan 2014 21:21:56 +0000 Subject: dictionary with tuples In-Reply-To: References: Message-ID: <52D5AA74.4080606@mrabarnett.plus.com> On 2014-01-14 21:10, Igor Korot wrote: > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> dict = {} >>>> dict[(1,2)] = ('a','b') >>>> dict[(3,4)] = ('c','d') >>>> for (key1,key2),(value1,value2) in dict: > ... print key1, " ", key2 > ... print value1, " ", value2 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable >>>> > > What am I doing wrong? > > Thank you. > When you iterate over a dict it yields the only the keys, not the keys and values. Try iterating over dict.items() instead. By the way, try not to use names such as 'dict' that are the names of built-in classes. From ybmess at nooos.fr.invalid Tue Jan 14 16:21:15 2014 From: ybmess at nooos.fr.invalid (YBM) Date: Tue, 14 Jan 2014 22:21:15 +0100 Subject: dictionary with tuples In-Reply-To: References: Message-ID: <52d5aa4c$0$2196$426a74cc@news.free.fr> Le 14/01/2014 22:10, Igor Korot a ?crit : > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> dict = {} >>>> dict[(1,2)] = ('a','b') >>>> dict[(3,4)] = ('c','d') >>>> for (key1,key2),(value1,value2) in dict: > ... print key1, " ", key2 > ... print value1, " ", value2 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable >>>> > > What am I doing wrong? for ... in dict: is a way to iterate through dictionnary items, what you want to do can be done so: for (key1,key2),(value1,value2) in dict.items(): From drsalists at gmail.com Tue Jan 14 16:26:59 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 14 Jan 2014 13:26:59 -0800 Subject: setup.py issue - some files are included as intended, but one is not In-Reply-To: References: Message-ID: On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg wrote: > Hi folks. > > I have a setup.py problem that's driving me nuts. Anyone? I've received 0 responses. > I have a treap.py file that tries to "import * from pyx_treap.so", and > failing that, it'll "import * from py_treap.py" (sans extensions of > course). Naturally, all 3 of these should be included - although in > the case of pyx_treap.so, it probably should be a .c that's included. > > It is also intended to include nest.py, which has a simple form. > > Well, treap.py, nest.py and pyx_treap.c are included fine, but I can't > seem to get py_treap.py to be included for some reason. > > I get no errors during "python setup.py sdist upload", but upon > "python $(which pip) install treap", I get: > $ sudo /usr/bin/python $(which pip) install treap > Downloading/unpacking treap > Running setup.py egg_info for package treap > > file py_treap.py (for module py_treap) not found > Installing collected packages: treap > Running setup.py install for treap > file py_treap.py (for module py_treap) not found > file py_treap.py (for module py_treap) not found > > file py_treap.py (for module py_treap) not found > file py_treap.py (for module py_treap) not found > Successfully installed treap > Cleaning up... > > And it's not successfully installed - py_treap.py is missing. The pyx > code does its job, so the problem is masked, other than the messages > above, and the absence of py_treap.py from > /usr/local/lib/python2.7/dist-packages > > I can clearly see py_treap.py in ./dist/treap-1.35.tar.gz - it's at > least getting packaged up that much. It's not listed in > /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/SOURCES.txt > , but I can see it in > /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/top_level.txt > . > > My setup.py is at: > http://stromberg.dnsalias.org/svn/treap/trunk/setup.py > > I've tried that setup.py and several variations on that theme, but > none seem to include py_treap.py . > > Please make some suggestions? How can I get py_treap.py included in > the pip install? > > Thanks! From fluttershy363 at gmail.com Tue Jan 14 16:27:29 2014 From: fluttershy363 at gmail.com (Lewis Wood) Date: Tue, 14 Jan 2014 13:27:29 -0800 (PST) Subject: Tkinter GUI Error In-Reply-To: <3f7e442e-b86d-45c9-bd70-52c6abcca549@googlegroups.com> References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> <3f7e442e-b86d-45c9-bd70-52c6abcca549@googlegroups.com> Message-ID: <95e61d6c-5626-4d29-9dda-98e1bcb38546@googlegroups.com> Also anyone know how to create an entry box for Tkinter where you can only enter in 2 digits? From davea at davea.name Tue Jan 14 16:32:39 2014 From: davea at davea.name (Dave Angel) Date: Tue, 14 Jan 2014 16:32:39 -0500 (EST) Subject: dictionary with tuples References: Message-ID: Igor Korot Wrote in message: > Hi, ALL, > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> dict = {} >>>> dict[(1,2)] = ('a','b') >>>> dict[(3,4)] = ('c','d') >>>> for (key1,key2),(value1,value2) in dict: > ... print key1, " ", key2 > ... print value1, " ", value2 > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is not iterable >>>> > > What am I doing wrong? > > Thank you. > Two things. You really shouldn't shadow a builtin with your own locals, though it hasn't hurt you this time. Next time pick a different name than dict. Your real problem is that you're trying to iterate over items, but forgot to use that method. The for loop line should end in dict.items () : You may be confused, since it's different in python 3.x -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From ethan at stoneleaf.us Tue Jan 14 16:32:01 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 14 Jan 2014 13:32:01 -0800 Subject: setup.py issue - some files are included as intended, but one is not In-Reply-To: References: Message-ID: <52D5ACD1.3000604@stoneleaf.us> On 01/14/2014 01:26 PM, Dan Stromberg wrote: > On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg wrote: >> Hi folks. >> >> I have a setup.py problem that's driving me nuts. > > Anyone? I've received 0 responses. I have no answer, but forwarding to Distutils (hopefully it's an appropriate topic ;) >> I have a treap.py file that tries to "import * from pyx_treap.so", and >> failing that, it'll "import * from py_treap.py" (sans extensions of >> course). Naturally, all 3 of these should be included - although in >> the case of pyx_treap.so, it probably should be a .c that's included. >> >> It is also intended to include nest.py, which has a simple form. >> >> Well, treap.py, nest.py and pyx_treap.c are included fine, but I can't >> seem to get py_treap.py to be included for some reason. >> >> I get no errors during "python setup.py sdist upload", but upon >> "python $(which pip) install treap", I get: >> $ sudo /usr/bin/python $(which pip) install treap >> Downloading/unpacking treap >> Running setup.py egg_info for package treap >> >> file py_treap.py (for module py_treap) not found >> Installing collected packages: treap >> Running setup.py install for treap >> file py_treap.py (for module py_treap) not found >> file py_treap.py (for module py_treap) not found >> >> file py_treap.py (for module py_treap) not found >> file py_treap.py (for module py_treap) not found >> Successfully installed treap >> Cleaning up... >> >> And it's not successfully installed - py_treap.py is missing. The pyx >> code does its job, so the problem is masked, other than the messages >> above, and the absence of py_treap.py from >> /usr/local/lib/python2.7/dist-packages >> >> I can clearly see py_treap.py in ./dist/treap-1.35.tar.gz - it's at >> least getting packaged up that much. It's not listed in >> /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/SOURCES.txt >> , but I can see it in >> /usr/local/lib/python2.7/dist-packages/treap-1.31.egg-info/top_level.txt >> . >> >> My setup.py is at: >> http://stromberg.dnsalias.org/svn/treap/trunk/setup.py >> >> I've tried that setup.py and several variations on that theme, but >> none seem to include py_treap.py . >> >> Please make some suggestions? How can I get py_treap.py included in >> the pip install? >> >> Thanks! From auriocus at gmx.de Tue Jan 14 16:33:23 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Tue, 14 Jan 2014 22:33:23 +0100 Subject: Tkinter GUI Error In-Reply-To: <95e61d6c-5626-4d29-9dda-98e1bcb38546@googlegroups.com> References: <1ab2aa93-1ba6-48b0-a5f4-5fb05cb523d1@googlegroups.com> <3f7e442e-b86d-45c9-bd70-52c6abcca549@googlegroups.com> <95e61d6c-5626-4d29-9dda-98e1bcb38546@googlegroups.com> Message-ID: Am 14.01.14 22:27, schrieb Lewis Wood: > Also anyone know how to create an entry box for Tkinter where you can only enter in 2 digits? > You must use a validator to achieve this. This is a more advanced topic though. A validator is a function that is called whenever the user keys something in - even by copy/pasting - and has to decide, whether this change is accepted or not. It is relatively easy to annoy your users if the validator is not written carefully. For instance, you must always accept th eempty string, otherwise the users won't be able to delete everything - very annoying behaviour. See for example this SO question http://stackoverflow.com/questions/4140437/python-tkinter-interactively-validating-entry-widget-content Christian From sadzak at gmail.com Tue Jan 14 16:48:39 2014 From: sadzak at gmail.com (Adnan Sadzak) Date: Tue, 14 Jan 2014 22:48:39 +0100 Subject: python adsl script In-Reply-To: <69acfb5b-4cb2-4751-a20d-ae25e39ec471@googlegroups.com> References: <69acfb5b-4cb2-4751-a20d-ae25e39ec471@googlegroups.com> Message-ID: Hi, You need to find out what communication type your router supports (most use telnet, ssh, or http). It is easy to implement solution using any of these protocols. If You have problems in implementation, maybe we can help You, but will not write code for You. For password..khm...as Denis says use google. You can start with some questions to yourself and google: What password? Bios, boot loader, OS...? No1 will do this for You and this is not list for that type of questions. Cheers On Tue, Jan 14, 2014 at 6:27 PM, ngangsia akumbo wrote: > what about a python script that can retrieve my entire isp setting from my > adsl router. > > Any ideas > > Also my grand mother forget her computer password, she can only login > through the guest account. what about a script that can solve that problem. > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From toby at tobiah.org Tue Jan 14 17:00:05 2014 From: toby at tobiah.org (Tobiah) Date: Tue, 14 Jan 2014 14:00:05 -0800 Subject: dictionary with tuples In-Reply-To: <52d5aa4c$0$2196$426a74cc@news.free.fr> References: <52d5aa4c$0$2196$426a74cc@news.free.fr> Message-ID: On 01/14/2014 01:21 PM, YBM wrote: > Le 14/01/2014 22:10, Igor Korot a ?crit : >> Hi, ALL, >> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python >> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit >> (Intel)] on win32 >> Type "help", "copyright", "credits" or "license" for more information. >>>>> dict = {} >>>>> dict[(1,2)] = ('a','b') >>>>> dict[(3,4)] = ('c','d') >>>>> for (key1,key2),(value1,value2) in dict: >> ... print key1, " ", key2 >> ... print value1, " ", value2 >> ... >> Traceback (most recent call last): >> File "", line 1, in >> TypeError: 'int' object is not iterable >>>>> >> >> What am I doing wrong? > > for ... in dict: > > is a way to iterate through dictionnary items, > > what you want to do can be done so: > > for (key1,key2),(value1,value2) in dict.items(): > > > But it's (key1, value1), (key2, value2) From tjreedy at udel.edu Tue Jan 14 17:05:22 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 14 Jan 2014 17:05:22 -0500 Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: On 1/14/2014 3:46 AM, Igor Korot wrote: > Hi, ALL, > I'm trying to process a file which has following lines: > > 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > However, I don't need all the protocol info. All I'm interested in is > the last field, which is length. To directly extract only the needed info: >>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30" >>> s[s.rindex(' ')+1:] '30' -- Terry Jan Reedy From tjreedy at udel.edu Tue Jan 14 17:07:15 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 14 Jan 2014 17:07:15 -0500 Subject: L[:] In-Reply-To: <1389696127.37654.YahooMailBasic@web163802.mail.gq1.yahoo.com> References: <1389696127.37654.YahooMailBasic@web163802.mail.gq1.yahoo.com> Message-ID: On 1/14/2014 5:42 AM, Albert-Jan Roskam wrote: > I also found that item assignment ([1] below) is much faster > than using the more standard (I think) .append ([2]). > # [1] > for idx,item in enumerate(L[:]): > if some_condition: > L[idx] = foobarify(item) [1] *is* the standard way to selectively replace items. > # [2] > L2 = [] > for idx,item in enumerate(L): > if some_condition: > L2.append(foobarify(item)) > else: > L2.append(item) -- Terry Jan Reedy From emile at fenx.com Tue Jan 14 17:13:20 2014 From: emile at fenx.com (emile) Date: Tue, 14 Jan 2014 14:13:20 -0800 Subject: What's correct Python syntax? In-Reply-To: References: Message-ID: On 01/14/2014 02:05 PM, Terry Reedy wrote: > On 1/14/2014 3:46 AM, Igor Korot wrote: >> Hi, ALL, >> I'm trying to process a file which has following lines: >> >> 192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, length 30 > >> However, I don't need all the protocol info. All I'm interested in is >> the last field, which is length. > > To directly extract only the needed info: > > >>> s="192.168.1.6 > 192.168.1.7: ICMP echo request, id 100, seq 200, > length 30" > >>> s[s.rindex(' ')+1:] > '30' Any particular reason to prefer that over: >>> s.split()[-1] '30' Is it a length of s and speed or rindex over build and toss the list kind of thing? Emile From emile at fenx.com Tue Jan 14 17:14:08 2014 From: emile at fenx.com (emile) Date: Tue, 14 Jan 2014 14:14:08 -0800 Subject: dictionary with tuples In-Reply-To: References: <52d5aa4c$0$2196$426a74cc@news.free.fr> Message-ID: On 01/14/2014 02:00 PM, Tobiah wrote: > On 01/14/2014 01:21 PM, YBM wrote: >> Le 14/01/2014 22:10, Igor Korot a ?crit : >>> Hi, ALL, >>> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python >>> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit >>> (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> dict = {} >>>>>> dict[(1,2)] = ('a','b') >>>>>> dict[(3,4)] = ('c','d') >>>>>> for (key1,key2),(value1,value2) in dict: >>> ... print key1, " ", key2 >>> ... print value1, " ", value2 >>> ... >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: 'int' object is not iterable >>>>>> >>> >>> What am I doing wrong? >> >> for ... in dict: >> >> is a way to iterate through dictionnary items, >> >> what you want to do can be done so: >> >> for (key1,key2),(value1,value2) in dict.items(): >> >> >> > > But it's (key1, value1), (key2, value2) No it isn't. :) Emile From mailinglists at xgm.de Tue Jan 14 20:25:34 2014 From: mailinglists at xgm.de (Florian Lindner) Date: Wed, 15 Jan 2014 02:25:34 +0100 Subject: python-list@python.org In-Reply-To: <52D56D40.1060401@mrabarnett.plus.com> References: <11036720.dCfMmLrdqv@horus> <52D56D40.1060401@mrabarnett.plus.com> Message-ID: <5496632.M1CKVtg2ju@horus> Am Dienstag, 14. Januar 2014, 17:00:48 schrieb MRAB: > On 2014-01-14 16:37, Florian Lindner wrote: > > Hello! > > > > I'm using python 3.2.3 on debian wheezy. My script is called from my mail delivery agent (MDA) maildrop (like procmail) through it's xfilter directive. > > > > Script works fine when used interactively, e.g. ./script.py < testmail but when called from maildrop it's producing an infamous UnicodeDecodeError: > > > > File "/home/flindner/flofify.py", line 171, in main > > mail = sys.stdin.read() > > File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode > > return codecs.ascii_decode(input, self.errors)[0] > > > > Exception for example is always like > > > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: ordinal not in range(128) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: ordinal not in range(128) > > UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: ordinal not in range(128) > > > > I read mail from stdin "mail = sys.stdin.read()" > > > > Environment when called is: > > > > locale.getpreferredencoding(): ANSI_X3.4-1968 > > environ["LANG"]: C > > > > System environment when using shell is: > > > > ~ % echo $LANG > > en_US.UTF-8 > > > > As far as I know when reading from stdin I don't need an decode(...) call, since stdin has a decoding. I also tried some decoding/encoding stuff but changed nothing. > > > > Any ideas to help me? > > > When run from maildrop it thinks that the encoding of stdin is ASCII. Well, true. But what encoding does maildrop actually gives me? It obviously does not inherit LANG or is called from the MTA that way. I also tried: inData = codecs.getreader('utf-8')(sys.stdin) mail = inData.read() Failed also. But I'm not exactly an encoding expert. Regards, Florian From steve+comp.lang.python at pearwood.info Tue Jan 14 20:27:36 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2014 01:27:36 GMT Subject: Chanelling Guido - dict subclasses Message-ID: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread discussion involving at least two PEPs, about bytes/str compatibility. But I don't want to talk about that. (Oh gods, I *really* don't want to talk about that...) In the midst of that discussion, Guido van Rossum made a comment about subclassing dicts: [quote] From: Guido van Rossum Date: Tue, 14 Jan 2014 12:06:32 -0800 Subject: Re: [Python-Dev] PEP 460 reboot Personally I wouldn't add any words suggesting or referring to the option of creation another class for this purpose. You wouldn't recommend subclassing dict for constraining the types of keys or values, would you? [end quote] https://mail.python.org/pipermail/python-dev/2014-January/131537.html This surprises me, and rather than bother Python-Dev (where it will likely be lost in the noise, and certain will be off-topic), I'm hoping there may be someone here who is willing to attempt to channel GvR. I would have thought that subclassing dict for the purpose of constraining the type of keys or values would be precisely an excellent use of subclassing. class TextOnlyDict(dict): def __setitem__(self, key, value): if not isinstance(key, str): raise TypeError super().__setitem__(key, value) # need to override more methods too But reading Guido, I think he's saying that wouldn't be a good idea. I don't get it -- it's not a violation of the Liskov Substitution Principle, because it's more restrictive, not less. What am I missing? -- Steven From ned at nedbatchelder.com Tue Jan 14 21:04:22 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 14 Jan 2014 21:04:22 -0500 Subject: Chanelling Guido - dict subclasses In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/14/14 8:27 PM, Steven D'Aprano wrote: > Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread > discussion involving at least two PEPs, about bytes/str compatibility. > But I don't want to talk about that. (Oh gods, I *really* don't want to > talk about that...) > > In the midst of that discussion, Guido van Rossum made a comment about > subclassing dicts: > > [quote] > From: Guido van Rossum > Date: Tue, 14 Jan 2014 12:06:32 -0800 > Subject: Re: [Python-Dev] PEP 460 reboot > > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subclassing dict for constraining the > types of keys or values, would you? > [end quote] > > https://mail.python.org/pipermail/python-dev/2014-January/131537.html > > This surprises me, and rather than bother Python-Dev (where it will > likely be lost in the noise, and certain will be off-topic), I'm hoping > there may be someone here who is willing to attempt to channel GvR. I > would have thought that subclassing dict for the purpose of constraining > the type of keys or values would be precisely an excellent use of > subclassing. > > > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I think he's saying that wouldn't be a good idea. I > don't get it -- it's not a violation of the Liskov Substitution > Principle, because it's more restrictive, not less. What am I missing? > > One problem with it is that there are lots of ways of setting values in the dict, and they don't use your __setitem__: >>> tod = TextOnlyDict() >>> tod.update({1: "haha"}) >>> This is what you're getting at with your "need to override more methods too", but it turns out to be a pain to override enough methods. I don't know if that is what Guido was getting at, I suspect he was talking at a more refined "principles of object design" level rather than "dicts don't happen to work that way" level. Also, I've never done it, but I understand that deriving from collections.MutableMapping avoids this problem. -- Ned Batchelder, http://nedbatchelder.com From ybmess at nooos.fr.invalid Tue Jan 14 21:24:21 2014 From: ybmess at nooos.fr.invalid (YBM) Date: Wed, 15 Jan 2014 03:24:21 +0100 Subject: dictionary with tuples In-Reply-To: References: <52d5aa4c$0$2196$426a74cc@news.free.fr> Message-ID: <52d5f156$0$2227$426a34cc@news.free.fr> Le 14/01/2014 23:00, Tobiah a ?crit : > On 01/14/2014 01:21 PM, YBM wrote: >> Le 14/01/2014 22:10, Igor Korot a ?crit : >>> Hi, ALL, >>> C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python >>> Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit >>> (Intel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> dict = {} >>>>>> dict[(1,2)] = ('a','b') >>>>>> dict[(3,4)] = ('c','d') >>>>>> for (key1,key2),(value1,value2) in dict: >>> ... print key1, " ", key2 >>> ... print value1, " ", value2 >>> ... >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: 'int' object is not iterable >>>>>> >>> >>> What am I doing wrong? >> >> for ... in dict: >> >> is a way to iterate through dictionnary items, >> >> what you want to do can be done so: >> >> for (key1,key2),(value1,value2) in dict.items(): >> >> >> > > But it's (key1, value1), (key2, value2) No. Try it. key1 key2 are the members of every tuple key. value1, value2 are the members of every tuple value. >>> d={ (1,2):('a','b'), (3,4):('c','d') } >>> for (key1,key2),(value1,value2) in d.items(): ... print key1,key2,value1,value2 ... 1 2 a b 3 4 c d From steve+comp.lang.python at pearwood.info Tue Jan 14 21:55:10 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 15 Jan 2014 02:55:10 GMT Subject: Python 3.x adoption References: Message-ID: <52d5f88e$0$29970$c3e8da3$5496439d@news.astraweb.com> On Tue, 14 Jan 2014 20:33:50 +0100, Staszek wrote: > Hi > > What's the problem with Python 3.x? Nothing. > It was first released in 2008, That was only five years ago. I know that to young kids today who change their iPhone every six months, five years sounds like a lot, but in the world of mature software, five years is a blink of the eye. People still use Fortran code that is 30 years old. I know of at least one person supporting a Python 1.5 system, which is about 15 years old. RedHat is still providing commercial support for Python 2.3, and their Python 2.7 commercial support won't end until 2023 or 2024. > but web hosting companies still seem to offer Python 2.x rather. > > For example, Google App Engine only offers Python 2.7. > > What's wrong?... Hosting companies are conservative. Just look at how many still offer old versions of PHP. These guys offer PHP 5.2 to 5.5: http://www.a2hosting.com/php-hosting WordPress will run on PHP 4.1! So it is no surprise that Python hosting companies still mostly provide 2.7. -- Steven From esj at harvee.org Tue Jan 14 22:07:55 2014 From: esj at harvee.org (Eric S. Johansson) Date: Tue, 14 Jan 2014 22:07:55 -0500 Subject: extracting string.Template substitution placeholders In-Reply-To: <52d394ad$0$29874$c3e8da3$5496439d@news.astraweb.com> References: <52d394ad$0$29874$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52D5FB8B.30407@harvee.org> On 1/13/2014 2:24 AM, Steven D'Aprano wrote: > On Sun, 12 Jan 2014 10:08:31 -0500, Eric S. Johansson wrote: > > > Now just walk the template for $ signs. Watch out for $$ which escapes > the dollar sign. Here's a baby parser: found a different way import string cmplxstr="""a simple $string a longer $string a $last line""" nst=string.Template(cmplxstr) identifiers = {} while True: try: result = nst.substitute(identifiers) except KeyError, error: print error identifiers[error[0]] = "x" else: break print "loop done" ------ at the end I only care about the keys in identifier which I fill in after user interaction. From python at mrabarnett.plus.com Tue Jan 14 22:30:12 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Jan 2014 03:30:12 +0000 Subject: Python 3.x adoption In-Reply-To: <52d5f88e$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5f88e$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52D600C4.7060605@mrabarnett.plus.com> On 2014-01-15 02:55, Steven D'Aprano wrote: > On Tue, 14 Jan 2014 20:33:50 +0100, Staszek wrote: > >> Hi >> >> What's the problem with Python 3.x? > > Nothing. > >> It was first released in 2008, > > That was only five years ago. > > I know that to young kids today who change their iPhone every six months, > five years sounds like a lot, but in the world of mature software, five > years is a blink of the eye. People still use Fortran code that is 30 > years old. I know of at least one person supporting a Python 1.5 system, > which is about 15 years old. RedHat is still providing commercial support > for Python 2.3, and their Python 2.7 commercial support won't end until > 2023 or 2024. > > >> but web hosting companies still seem to offer Python 2.x rather. >> >> For example, Google App Engine only offers Python 2.7. >> >> What's wrong?... > > Hosting companies are conservative. Just look at how many still offer old > versions of PHP. These guys offer PHP 5.2 to 5.5: > > http://www.a2hosting.com/php-hosting > > WordPress will run on PHP 4.1! > > So it is no surprise that Python hosting companies still mostly provide > 2.7. > Not to mention Windows XP, which is only now being dropped by Microsoft. From tjreedy at udel.edu Tue Jan 14 22:48:09 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 14 Jan 2014 22:48:09 -0500 Subject: Chanelling Guido - dict subclasses In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/14/2014 8:27 PM, Steven D'Aprano wrote: > In the midst of that discussion, Guido van Rossum made a comment about > subclassing dicts: > > [quote] > From: Guido van Rossum > Date: Tue, 14 Jan 2014 12:06:32 -0800 > Subject: Re: [Python-Dev] PEP 460 reboot > > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subclassing dict for constraining the > types of keys or values, would you? > [end quote] > > https://mail.python.org/pipermail/python-dev/2014-January/131537.html > > This surprises me, I was slightly surprised too. I understand not wanting to add a subclass to stdlib, but I believe this was about adding words to the doc. Perhaps he did not want to over-emphasize one particular possible subclass by putting the words in the doc. -- Terry Jan Reedy From python at mrabarnett.plus.com Tue Jan 14 22:49:26 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Jan 2014 03:49:26 +0000 Subject: python-list@python.org In-Reply-To: <5496632.M1CKVtg2ju@horus> References: <11036720.dCfMmLrdqv@horus> <52D56D40.1060401@mrabarnett.plus.com> <5496632.M1CKVtg2ju@horus> Message-ID: <52D60546.3010909@mrabarnett.plus.com> On 2014-01-15 01:25, Florian Lindner wrote: > Am Dienstag, 14. Januar 2014, 17:00:48 schrieb MRAB: >> On 2014-01-14 16:37, Florian Lindner wrote: >> > Hello! >> > >> > I'm using python 3.2.3 on debian wheezy. My script is called from my mail delivery agent (MDA) maildrop (like procmail) through it's xfilter directive. >> > >> > Script works fine when used interactively, e.g. ./script.py < testmail but when called from maildrop it's producing an infamous UnicodeDecodeError: >> > >> > File "/home/flindner/flofify.py", line 171, in main >> > mail = sys.stdin.read() >> > File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode >> > return codecs.ascii_decode(input, self.errors)[0] >> > >> > Exception for example is always like >> > >> > UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 869: ordinal not in range(128) >> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1176: ordinal not in range(128) >> > UnicodeDecodeError: 'ascii' codec can't decode byte 0x8c in position 846: ordinal not in range(128) >> > >> > I read mail from stdin "mail = sys.stdin.read()" >> > >> > Environment when called is: >> > >> > locale.getpreferredencoding(): ANSI_X3.4-1968 >> > environ["LANG"]: C >> > >> > System environment when using shell is: >> > >> > ~ % echo $LANG >> > en_US.UTF-8 >> > >> > As far as I know when reading from stdin I don't need an decode(...) call, since stdin has a decoding. I also tried some decoding/encoding stuff but changed nothing. >> > >> > Any ideas to help me? >> > >> When run from maildrop it thinks that the encoding of stdin is ASCII. > > Well, true. But what encoding does maildrop actually gives me? It obviously does not inherit LANG or is called from the MTA that way. I also tried: > locale.getpreferredencoding() said "ANSI_X3.4-1968", which is ASCII (ask Wikipedia if you want to know why it's called that!). > inData = codecs.getreader('utf-8')(sys.stdin) > mail = inData.read() > > Failed also. But I'm not exactly an encoding expert. > Try: sys.stdin = codecs.getreader('utf-8')(sys.stdin.detach()) From orgnut at yahoo.com Wed Jan 15 01:00:33 2014 From: orgnut at yahoo.com (Larry Hudson) Date: Tue, 14 Jan 2014 22:00:33 -0800 Subject: Fwd: What's correct Python syntax? In-Reply-To: References: Message-ID: On 01/14/2014 02:03 AM, Igor Korot wrote: [snip] > C:\Documents and Settings\Igor.FORDANWORK\Desktop\winpdb>python > Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit > (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> test = "I,like,my,chocolate" >>>> print test.split(',')[2,3] > Traceback (most recent call last): > File "", line 1, in > TypeError: list indices must be integers, not tuple > Try again... but use a colon not a comma, [2:3] Two additional comments: (1) test.split(',')[2:3] will give you ["my"] only. The slicing syntax starts with the first index and goes up to but NOT INCLUDING the second. In this case it is the same as the single index, [2]. You want either [2:4] or [2:], or even [2:500]. Any value >= the length of the list (or whatever sequence) is acceptable as the ending index in a slice. It's probably not a good idea to use a value like this, but it does work. And obviously, don't try to read with an out-of-bounds index, but it does work as the _ending_ index in a slice. (2) A comma-separated list of data items IS a tuple, even without the usual enclosing parenthesis. That is your error here -- [2,3] is the same as [(2,3)], which is a tuple. -=- Larry -=- From f at hop2it.be Wed Jan 15 02:00:48 2014 From: f at hop2it.be (F) Date: 15 Jan 2014 07:00:48 +0000 Subject: Chanelling Guido - dict subclasses References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: I can't speak for Guido but I think it is messy and unnatural and will lead to user frustration. As a user, I would expect a dict to take any hashable as key and any object as value when using one. I would probably just provide a __getitem__ method in a normal class in your case. This said I have overriden dict before, but my child class only added to dict, I didn't change it's underlying behaviour so you can use my class(es) as a vanilla dict everywhere, which enforcing types would have destroyed. On 01:27 15/01 , Steven D'Aprano wrote: >Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread >discussion involving at least two PEPs, about bytes/str compatibility. >But I don't want to talk about that. (Oh gods, I *really* don't want to >talk about that...) > >In the midst of that discussion, Guido van Rossum made a comment about >subclassing dicts: > > [quote] > From: Guido van Rossum > Date: Tue, 14 Jan 2014 12:06:32 -0800 > Subject: Re: [Python-Dev] PEP 460 reboot > > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subclassing dict for constraining the > types of keys or values, would you? > [end quote] > >https://mail.python.org/pipermail/python-dev/2014-January/131537.html > >This surprises me, and rather than bother Python-Dev (where it will >likely be lost in the noise, and certain will be off-topic), I'm hoping >there may be someone here who is willing to attempt to channel GvR. I >would have thought that subclassing dict for the purpose of constraining >the type of keys or values would be precisely an excellent use of >subclassing. > > >class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > >But reading Guido, I think he's saying that wouldn't be a good idea. I >don't get it -- it's not a violation of the Liskov Substitution >Principle, because it's more restrictive, not less. What am I missing? > > >-- >Steven > -- yrNews Usenet Reader for iOS http://appstore.com/yrNewsUsenetReader From __peter__ at web.de Wed Jan 15 03:40:33 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Jan 2014 09:40:33 +0100 Subject: Chanelling Guido - dict subclasses References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > In the midst of that discussion, Guido van Rossum made a comment about > subclassing dicts: > > [quote] > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subclassing dict for constraining the > types of keys or values, would you? > [end quote] > This surprises me, and rather than bother Python-Dev (where it will > likely be lost in the noise, and certain will be off-topic), I'm hoping > there may be someone here who is willing to attempt to channel GvR. I > would have thought that subclassing dict for the purpose of constraining > the type of keys or values would be precisely an excellent use of > subclassing. > > > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError Personally I feel dirty whenever I write Python code that defeats duck- typing -- so I would not /recommend/ any isinstance() check. I realize that this is not an argument... PS: I tried to read GvR's remark in context, but failed. It's about time to to revolt and temporarily install the FLUFL as our leader, long enough to revoke Guido's top-posting license, but not long enough to reintroduce the <> operator... From breamoreboy at yahoo.co.uk Wed Jan 15 04:10:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 15 Jan 2014 09:10:38 +0000 Subject: Chanelling Guido - dict subclasses In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 15/01/2014 01:27, Steven D'Aprano wrote: > Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread > discussion involving at least two PEPs, about bytes/str compatibility. > But I don't want to talk about that. (Oh gods, I *really* don't want to > talk about that...) + trillions > > In the midst of that discussion, Guido van Rossum made a comment about > subclassing dicts: > > [quote] > From: Guido van Rossum > Date: Tue, 14 Jan 2014 12:06:32 -0800 > Subject: Re: [Python-Dev] PEP 460 reboot > > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subclassing dict for constraining the > types of keys or values, would you? > [end quote] > > https://mail.python.org/pipermail/python-dev/2014-January/131537.html > > This surprises me, and rather than bother Python-Dev (where it will > likely be lost in the noise, and certain will be off-topic), I'm hoping > there may be someone here who is willing to attempt to channel GvR. I > would have thought that subclassing dict for the purpose of constraining > the type of keys or values would be precisely an excellent use of > subclassing. Exactly what I was thinking. > > > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I think he's saying that wouldn't be a good idea. I > don't get it -- it's not a violation of the Liskov Substitution > Principle, because it's more restrictive, not less. What am I missing? > > Couple of replies I noted from Ned Batchelder and Terry Reedy. Smacked bottom for Peter Otten, how dare he? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From pconnell at gmail.com Wed Jan 15 05:18:32 2014 From: pconnell at gmail.com (Phil Connell) Date: Wed, 15 Jan 2014 10:18:32 +0000 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: References: Message-ID: <20140115101832.GA7423@phconnel-ws.cisco.com> On Mon, Jan 06, 2014 at 06:56:00PM -0600, Skip Montanaro wrote: > So, I'm looking for a little guidance. It seems to me that futures, > coroutines, and/or the new Tulip/asyncio package might be my salvation, but > I'm having a bit of trouble seeing exactly how that would work. Let me > outline a simple hypothetical calculation. I'm looking for ways in which > these new facilities might improve the structure of my code. This instinct is exactly right -- the point of coroutines and tulip futures is to liberate you from having to daisy chain callbacks together. > > Let's say I have a dead simple GUI with two buttons labeled, "Do A" and "Do > B". Each corresponds to executing a particular activity, A or B, which take > some non-zero amount of time to complete (as perceived by the user) or > cancel (as perceived by the state of the running system - not safe to run A > until B is complete/canceled, and vice versa). The user, being the fickle > sort that he is, might change his mind while A is running, and decide to > execute B instead. (The roles can also be reversed.) If s/he wants to run > task A, task B must be canceled or allowed to complete before A can be > started. Logically, the code looks something like (I fear Gmail is going to > destroy my indentation): > > def do_A(): > when B is complete, _do_A() > cancel_B() > > def do_B(): > when A is complete, _do_B() > cancel_A() > > def _do_A(): > do the real A work here, we are guaranteed B is no longer running > > def _do_B(): > do the real B work here, we are guaranteed A is no longer running > > cancel_A and cancel_B might be no-ops, in which case they need to start up > the other calculation immediately, if one is pending. It strikes me that what you have two linear sequences of 'things to do': - 'Tasks', started in reaction to some event. - Cancellations, if a particular task happens to be running. So, a reasonable design is to have two long-running coroutines, one that executes your 'tasks' sequentially, and another that executes cancellations. These are both fed 'things to do' via a couple of queues populated in event callbacks. Something like (apologies for typos/non-working code): cancel_queue = asyncio.Queue() run_queue = asyncio.Queue() running_task = None running_task_name = "" def do_A(): cancel_queue.put_nowait("B") run_queue.put_nowait(("A", _do_A())) def do_B(): cancel_queue.put_nowait("A") run_queue.put_nowait(("B", _do_B())) def do_C(): run_queue.put_nowait(("C", _do_C())) @asyncio.coroutine def canceller(): while True: name = yield from cancel_queue.get() if running_task_name == name: running_task.cancel() @asyncio.coroutine def runner(): while True: name, coro = yield from run_queue.get() running_task_name = name running_task = asyncio.async(coro) yield from running_task def main(): ... cancel_task = asyncio.Task(canceller()) run_task = asyncio.Task(runner()) ... Cheers, Phil From menkomigen6 at gmail.com Wed Jan 15 05:37:05 2014 From: menkomigen6 at gmail.com (Paul Pittlerson) Date: Wed, 15 Jan 2014 02:37:05 -0800 (PST) Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> Message-ID: <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> I'm sorry if this is a bit late of a response, but here goes. Big thanks to Chris Angelico for his comprehensive reply, and yes, I do have some questions! > On Thursday, January 9, 2014 1:29:03 AM UTC+2, Chris Angelico wrote: > Those sorts of frameworks would be helpful if you need to scale to > infinity, but threads work fine when it's small. That's what I thought, but I was just asking if it would be like trivially easy to set up this stuff in some of those frameworks. I'm sticking to threads for now because the learning curve of twisted seems too steep to be worth it at the moment. > Absolutely! The thing to look at is MUDs and chat servers. Ultimately, > a multiplayer game is really just a chat room with a really fancy > front end. If you know of any open source projects or just instructional code of this nature in general I'll be interested to take a look. For example, you mentioned you had some similar projects of your own..? > The server shouldn't require interaction at all. It should accept any > number of clients (rather than getting the exact number that you > enter), and drop them off the list when they're not there. That's a > bit of extra effort but it's hugely beneficial. I get what you are saying, but I should mention that I'm just making a 2 player strategy game at this point, which makes sense of the limited number of connections. > One extremely critical point about your protocol. TCP is a stream - > you don't have message boundaries. You can't depend on one send() > becoming one recv() at the other end. It might happen to work when you > do one thing at a time on localhost, but it won't be reliable on the > internet or when there's more traffic. So you'll need to delimit > messages; I recommend you use one of two classic ways: either prefix > it with a length (so you know how many more bytes to receive), or > terminate it with a newline (which depends on there not being a > newline in the text). I don't understand. Can you show some examples of how to do this? > Another rather important point, in two halves. You're writing this for > Python 2, and you're writing with no Unicode handling. I strongly > recommend that you switch to Python 3 and support full Unicode. Good point, however the framework I'm using for graphics does not currently support python3. I could make the server scripts be in python3, but I don't think the potential confusion is worth it until the whole thing can be in the same version. > Note, by the way, that it's helpful to distinguish "data" and "text", > even in pseudo-code. It's impossible to send text across a socket - > you have to send bytes of data. If you keep this distinction clearly > in your head, you'll have no problem knowing when to encode and when > to decode. For what you're doing here, for instance, I would packetize > the bytes and then decode into text, and on sending, I'd encode text > (UTF-8 would be hands-down best here) and then packetize. There are > other options but that's how I'd do it. I'm not sure what you are talking about here. Would you care to elaborate on this please (it interests and confuses) ? I'm posting this on google groups, so I hope the formatting turns out ok :P thanks. From python.list at tim.thechases.com Wed Jan 15 06:03:25 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Jan 2014 05:03:25 -0600 Subject: Chanelling Guido - dict subclasses In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140115050325.190b1509@bigbox.christie.dr> On 2014-01-15 01:27, Steven D'Aprano wrote: > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I think he's saying that wouldn't be a good > idea. I don't get it -- it's not a violation of the Liskov > Substitution Principle, because it's more restrictive, not less. > What am I missing? Just as an observation, this seems almost exactly what anydbm does, behaving like a dict (whether it inherits from dict, or just duck-types like a dict), but with the limitation that keys/values need to be strings. -tkc From denismfmcmahon at gmail.com Wed Jan 15 06:11:10 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 15 Jan 2014 11:11:10 +0000 (UTC) Subject: Learning python networking References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> Message-ID: On Wed, 15 Jan 2014 02:37:05 -0800, Paul Pittlerson wrote: >> One extremely critical point about your protocol. TCP is a stream - you >> don't have message boundaries. You can't depend on one send() becoming >> one recv() at the other end. It might happen to work when you do one >> thing at a time on localhost, but it won't be reliable on the internet >> or when there's more traffic. So you'll need to delimit messages; I >> recommend you use one of two classic ways: either prefix it with a >> length (so you know how many more bytes to receive), or terminate it >> with a newline (which depends on there not being a newline in the >> text). > I don't understand. Can you show some examples of how to do this? How much do you understand about tcp/ip networking? because when trying to build something on top of tcp/ip, it's a good idea to understand the basics of tcp/ip first. A tcp/ip connection is just a pipe that you pour data (octets, more or less analagous to bytes or characters) into at one end, and it comes out at the other end. For your stream of octets (bytes / characters) to have any meaning to a higher level program, then the applications using the pipe at both ends have to understand that a message has some structure. The message structure might be to send an n character message length count (where in a simple protocol n would have to be a fixed number) followed by the specified number of characters. Assuming your maximum message length is 9999 characters: You could send the characters 9999 followed by 9999 characters of message content. The receiving end would receive 4 characters, convert them to the number 9999, and assume the next 9999 characters will be the message. Then it expects another 4 character number. You could send json encoded strings, in which case each message might start with the "{" character and end with the "}" character, but you would have to allow for the fact that "}" can also occur within a json encoded string. You might decide that each message is simply going to end with a specific character or character sequence. Whatever you choose, you need some way for the receiving application to distinguish between individual messages in the stream of octets / bytes / characters that is coming out of the pipe. -- Denis McMahon, denismfmcmahon at gmail.com From robin at reportlab.com Wed Jan 15 07:00:51 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 15 Jan 2014 12:00:51 +0000 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: <52D67873.2010502@chamonix.reportlab.co.uk> On 12/01/2014 07:50, wxjmfauth at gmail.com wrote: >>>> sys.version > 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>> s = 'Stra?e' >>>> assert len(s) == 6 >>>> assert s[5] == 'e' >>>> > > jmf > On my utf8 based system > robin at everest ~: > $ cat ooo.py > if __name__=='__main__': > import sys > s='A?B' > print('version_info=%s\nlen(%s)=%d' % (sys.version_info,s,len(s))) > robin at everest ~: > $ python ooo.py > version_info=sys.version_info(major=3, minor=3, micro=3, releaselevel='final', serial=0) > len(A?B)=3 > robin at everest ~: > $ so two 'characters' are 3 (or 2 or more) codepoints. If I want to isolate so called graphemes I need an algorithm even for python's unicode ie when it really matters, python3 str is just another encoding. -- Robin Becker From robin at reportlab.com Wed Jan 15 07:07:25 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 15 Jan 2014 12:07:25 +0000 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: <52D679FD.3060406@chamonix.reportlab.co.uk> On 13/01/2014 15:28, Chris Angelico wrote: .......... > > It's even worse than that, because adding 'nonlocal' is not a bugfix. > So to be committed to the repo, it has to be approved for either 2.7 > branch (which is in bugfix-only maintenance mode) or 2.8 branch (which > does not exist). Good luck. :) ....... fixing badly named variables is not a bug fix either, but that has happened in python 2.7. A micro change release changed compiler.consts.SC_GLOBAL_EXPLICT to compiler.consts.SC_GLOBAL_EXPLICIT this is a change of api for the consts module (if you regard exported variables as part of its api), but that didn't count for the developers. -- Robin Becker From robin at reportlab.com Wed Jan 15 07:07:25 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 15 Jan 2014 12:07:25 +0000 Subject: proposal: bring nonlocal to py2.x In-Reply-To: References: Message-ID: <52D679FD.3060406@chamonix.reportlab.co.uk> On 13/01/2014 15:28, Chris Angelico wrote: .......... > > It's even worse than that, because adding 'nonlocal' is not a bugfix. > So to be committed to the repo, it has to be approved for either 2.7 > branch (which is in bugfix-only maintenance mode) or 2.8 branch (which > does not exist). Good luck. :) ....... fixing badly named variables is not a bug fix either, but that has happened in python 2.7. A micro change release changed compiler.consts.SC_GLOBAL_EXPLICT to compiler.consts.SC_GLOBAL_EXPLICIT this is a change of api for the consts module (if you regard exported variables as part of its api), but that didn't count for the developers. -- Robin Becker From ned at nedbatchelder.com Wed Jan 15 07:13:36 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 15 Jan 2014 07:13:36 -0500 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: <52D67873.2010502@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> Message-ID: On 1/15/14 7:00 AM, Robin Becker wrote: > On 12/01/2014 07:50, wxjmfauth at gmail.com wrote: >>>>> sys.version >> 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] >>>>> s = 'Stra?e' >>>>> assert len(s) == 6 >>>>> assert s[5] == 'e' >>>>> >> >> jmf >> > > On my utf8 based system > > >> robin at everest ~: >> $ cat ooo.py >> if __name__=='__main__': >> import sys >> s='A?B' >> print('version_info=%s\nlen(%s)=%d' % (sys.version_info,s,len(s))) >> robin at everest ~: >> $ python ooo.py >> version_info=sys.version_info(major=3, minor=3, micro=3, >> releaselevel='final', serial=0) >> len(A?B)=3 >> robin at everest ~: >> $ > > > so two 'characters' are 3 (or 2 or more) codepoints. If I want to > isolate so called graphemes I need an algorithm even for python's > unicode ie when it really matters, python3 str is just another encoding. You are right that more than one codepoint makes up a grapheme, and that you'll need code to deal with the correspondence between them. But let's not muddy these already confusing waters by referring to that mapping as an encoding. In Unicode terms, an encoding is a mapping between codepoints and bytes. Python 3's str is a sequence of codepoints. -- Ned Batchelder, http://nedbatchelder.com From nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de Wed Jan 15 07:07:46 2014 From: nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de (Thomas Rachel) Date: Wed, 15 Jan 2014 13:07:46 +0100 Subject: Python 3 __bytes__ method In-Reply-To: References: Message-ID: Am 12.01.2014 01:24 schrieb Ethan Furman: > I must admit I'm not entirely clear how this should be used. Is anyone > using this now? If so, how? I am not, as I currently am using Py2, but if I would, I would do it e. g. for serialization of objects in order to send them over the line or to save them into a file. IOW, the same purpose as we havd on __str__ in Py2. Thomas From roegltd at gmail.com Wed Jan 15 07:13:56 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 15 Jan 2014 04:13:56 -0800 (PST) Subject: Question about object lifetime and access Message-ID: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Hi community i am beginner in Python and have possibly silly questions i could not figure out answers for. Below is the test application working with uwsgi to test json-rpc. ------------------------------------------------------------------------ from multiprocessing import Process from werkzeug.wrappers import Request, Response from werkzeug.serving import run_simple from jsonrpc import JSONRPCResponseManager, dispatcher p = "module is loaded" <------ (3) print(p) print(id(p)) @Request.application def application(request): print("server started") print(id(p)) # Dispatcher is dictionary {: callable} dispatcher["echo"] = lambda s: s <---- (1) dispatcher["add"] = lambda a, b: a + b <---- (2) print("request data ==> ", request.data) response = JSONRPCResponseManager.handle(request.data, dispatcher) return Response(response.json, mimetype='application/json') ------------------------------------------------------------------------ As program will grow new rpc method dispatchers will be added so there is idea to reduce initialization code at steps 1 and 2 by making them global objects created at module loading, like string p at step 3. Multithreading will be enabled in uwsgi and 'p' will be used for read only. Questions are: - what is the lifetime for global object (p in this example). - will the p always have value it got during module loading - if new thread will be created will p be accessible to it - if p is accessible to new thread will new thread initialize p value again? - is it guaranteed to have valid p content (set to "module is loaded") whenever application() function is called. - under what condition p is cleaned by gc. The rationale behind these question is to avoid object creation within application() whose content is same and do not change between requests calling application() function and thus to reduce script response time. Thanks in advance! From info at egenix.com Wed Jan 15 07:39:33 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Wed, 15 Jan 2014 13:39:33 +0100 Subject: ANN: Python Meeting =?UTF-8?B?RMO8c3NlbGRvcmYgLSAyMS4wMS4yMDE0?= Message-ID: <52D68185.8030001@egenix.com> [This announcement is in German since it targets a local user group meeting in D?sseldorf, Germany] ________________________________________________________________________ ANK?NDIGUNG Python Meeting D?sseldorf http://pyddf.de/ Ein Treffen von Python Enthusiasten und Interessierten in ungezwungener Atmosph?re. Dienstag, 21.01.2014, 18:00 Uhr Raum 1, 2.OG im B?rgerhaus Stadtteilzentrum Bilk D?sseldorfer Arcaden, Bachstr. 145, 40217 D?sseldorf Diese Nachricht ist auch online verf?gbar: http://www.egenix.com/company/news/Python-Meeting-Duesseldorf-2014-01-21 ________________________________________________________________________ NEUIGKEITEN * Bereits angemeldete Vortr?ge: Charlie Clark "Properties & Descriptors" Marc-Andre Lemburg "Webseiten Screenshots mit Python automatisieren" Charlie Clark "Einfache Test-Automatisierung mit tox" * Neue Videos Wir haben in den letzten Wochen eine ganze Reihe neuer Videos produziert und auf unseren YouTube-Kanal hochgeladen: PyDDF YouTube-Kanal: http://www.youtube.com/pyddf/ * Neuer Veranstaltungsraum: Wir treffen uns im B?rgerhaus in den D?sseldorfer Arcaden. Da beim letzten Mal einige Teilnehmer Schwierigkeiten hatten, den Raum zu finden, hier eine kurze Beschreibung: Das B?rgerhaus teilt sich den Eingang mit dem Schwimmbad und befindet sich an der Seite der Tiefgarageneinfahrt der D?sseldorfer Arcaden. ?ber dem Eingang steht ein gro?es ?Schwimm?'in Bilk? Logo. Hinter der T?r direkt links zu den zwei Aufz?gen, dann in den 2. Stock hochfahren. Der Eingang zum Raum 1 liegt direkt links, wenn man aus dem Aufzug kommt. Google Street View: http://bit.ly/11sCfiw ________________________________________________________________________ EINLEITUNG Das Python Meeting D?sseldorf ist eine regelm??ige Veranstaltung in D?sseldorf, die sich an Python Begeisterte aus der Region wendet: * http://pyddf.de/ Einen guten ?berblick ?ber die Vortr?ge bietet unser YouTube-Kanal, auf dem wir die Vortr?ge nach den Meetings ver?ffentlichen: * http://www.youtube.com/pyddf/ Veranstaltet wird das Meeting von der eGenix.com GmbH, Langenfeld, in Zusammenarbeit mit Clark Consulting & Research, D?sseldorf: * http://www.egenix.com/ * http://www.clark-consulting.eu/ ________________________________________________________________________ PROGRAMM Das Python Meeting D?sseldorf nutzt eine Mischung aus Open Space und Lightning Talks, wobei die Gewitter bei uns auch schon mal 20 Minuten dauern k?nnen ;-). Lightning Talks k?nnen vorher angemeldet werden, oder auch spontan w?hrend des Treffens eingebracht werden. Ein Beamer mit XGA Aufl?sung steht zur Verf?gung. Folien bitte als PDF auf USB Stick mitbringen. Lightning Talk Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ KOSTENBETEILIGUNG Das Python Meeting D?sseldorf wird von Python Nutzern f?r Python Nutzer veranstaltet. Um die Kosten zumindest teilweise zu refinanzieren, bitten wir die Teilnehmer um einen Beitrag in H?he von EUR 10,00 inkl. 19% Mwst, Sch?ler und Studenten zahlen EUR 5,00 inkl. 19% Mwst. Wir m?chten alle Teilnehmer bitten, den Betrag in bar mitzubringen. ________________________________________________________________________ ANMELDUNG Da wir nur f?r ca. 20 Personen Sitzpl?tze haben, m?chten wir bitten, sich per EMail anzumelden. Damit wird keine Verpflichtung eingegangen. Es erleichtert uns allerdings die Planung. Meeting Anmeldung bitte formlos per EMail an info at pyddf.de ________________________________________________________________________ WEITERE INFORMATIONEN Weitere Informationen finden Sie auf der Webseite des Meetings: http://pyddf.de/ Mit freundlichen Gr??en, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 15 2014) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.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 robin at reportlab.com Wed Jan 15 07:50:10 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 15 Jan 2014 12:50:10 +0000 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> Message-ID: <52D68402.6030407@chamonix.reportlab.co.uk> On 15/01/2014 12:13, Ned Batchelder wrote: ........ >> On my utf8 based system >> >> >>> robin at everest ~: >>> $ cat ooo.py >>> if __name__=='__main__': >>> import sys >>> s='A?B' >>> print('version_info=%s\nlen(%s)=%d' % (sys.version_info,s,len(s))) >>> robin at everest ~: >>> $ python ooo.py >>> version_info=sys.version_info(major=3, minor=3, micro=3, >>> releaselevel='final', serial=0) >>> len(A?B)=3 >>> robin at everest ~: >>> $ >> >> ........ > You are right that more than one codepoint makes up a grapheme, and that you'll > need code to deal with the correspondence between them. But let's not muddy > these already confusing waters by referring to that mapping as an encoding. > > In Unicode terms, an encoding is a mapping between codepoints and bytes. Python > 3's str is a sequence of codepoints. > Semantics is everything. For me graphemes are the endpoint (or should be); to get a proper rendering of a sequence of graphemes I can use either a sequence of bytes or a sequence of codepoints. They are both encodings of the graphemes; what unicode says is an encoding doesn't define what encodings are ie mappings from some source alphabet to a target alphabet. -- Robin Becker From rosuav at gmail.com Wed Jan 15 07:52:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 15 Jan 2014 23:52:44 +1100 Subject: Learning python networking In-Reply-To: <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 9:37 PM, Paul Pittlerson wrote: > I'm sorry if this is a bit late of a response, but here goes. > > Big thanks to Chris Angelico for his comprehensive reply, and yes, I do have some questions! Best way to learn! And the thread's not even a week old, this isn't late. Sometimes there've been responses posted to something from 2002... now THAT is thread necromancy!! >> On Thursday, January 9, 2014 1:29:03 AM UTC+2, Chris Angelico wrote: >> Those sorts of frameworks would be helpful if you need to scale to >> infinity, but threads work fine when it's small. > That's what I thought, but I was just asking if it would be like trivially easy to set up this stuff in some of those frameworks. I'm sticking to threads for now because the learning curve of twisted seems too steep to be worth it at the moment. I really don't know, never used the frameworks. But threads are fairly easy to get your head around. Let's stick with them. >> Absolutely! The thing to look at is MUDs and chat servers. Ultimately, >> a multiplayer game is really just a chat room with a really fancy >> front end. > If you know of any open source projects or just instructional code of this nature in general I'll be interested to take a look. For example, you mentioned you had some similar projects of your own..? > Here's something that I did up as a MUD-writing tutorial for Pike: http://rosuav.com/piketut.zip I may need to port that tutorial to Python at some point. In any case, it walks you through the basics. (Up to section 4, everything's the same, just different syntax for the different languages. Section 5 is Pike-specific.) >> The server shouldn't require interaction at all. It should accept any >> number of clients (rather than getting the exact number that you >> enter), and drop them off the list when they're not there. That's a >> bit of extra effort but it's hugely beneficial. > I get what you are saying, but I should mention that I'm just making a 2 player strategy game at this point, which makes sense of the limited number of connections. One of the fundamentals of the internet is that connections *will* break. A friend of mine introduced me to Magic: The Gathering via a program that couldn't handle drop-outs, and it got extremely frustrating - we couldn't get a game going. Build your server such that your clients can disconnect and reconnect, and you protect yourself against half the problem; allow them to connect and kick the other connection off, and you solve the other half. (Sometimes, the server won't know that the client has gone, so it helps to be able to kick like that.) It might not be an issue when you're playing around with localhost, and you could even get away with it on a LAN, but on the internet, it's so much more friendly to your users to let them connect multiple times like that. >> One extremely critical point about your protocol. TCP is a stream - >> you don't have message boundaries. You can't depend on one send() >> becoming one recv() at the other end. It might happen to work when you >> do one thing at a time on localhost, but it won't be reliable on the >> internet or when there's more traffic. So you'll need to delimit >> messages; I recommend you use one of two classic ways: either prefix >> it with a length (so you know how many more bytes to receive), or >> terminate it with a newline (which depends on there not being a >> newline in the text). > I don't understand. Can you show some examples of how to do this? Denis gave a decent explanation of the problem, with a few suggestions. One of the easiest to work with (and trust me, you will LOVE the ease of debugging this kind of system) is the line-based connection. You just run a loop like this: buffer = b'' def gets(): while '\n' not in buffer: data = sock.recv(1024) if not data: # Client is disconnected, handle it gracefully return None # or some other sentinel line, buffer = buffer.split(b'\n',1) return line.decode().replace('\r', '') You could put this into a class definition that wraps up all the details. The key here is that you read as much as you can, buffering it, and as soon as you have a newline, you return that. This works beautifully with the basic TELNET client, so it's easy to see what's going on. Its only requirement is that there be no newlines *inside* commands. The classic MUD structure guarantees that (if you want a paragraph of text, you have some marker that says "end of paragraph" - commonly a dot on a line of its own, which is borrowed from SMTP), and if you use json.dumps() then it'll use two characters "\\" and "n" to represent a newline, so that's safe too. The next easiest structure to work with is length-preceded, which Denis explained. Again, you read until you have a full packet, but instead of "while '\n' not in buffer", it would be "while len(buffer)> Another rather important point, in two halves. You're writing this for >> Python 2, and you're writing with no Unicode handling. I strongly >> recommend that you switch to Python 3 and support full Unicode. > Good point, however the framework I'm using for graphics does not currently support python3. I could make the server scripts be in python3, but I don't think the potential confusion is worth it until the whole thing can be in the same version. > Hmm. Maybe, but on the flip side, it might be better to first learn how to do things in Py3, and then work on making your code able to run in Py2. That way, you force yourself to get everything right for Py3, and then there's no big porting job to move. Apart from the fact that you have to learn two variants of the language, there's nothing stopping the server being Py3 while the client's in Py2. >> Note, by the way, that it's helpful to distinguish "data" and "text", >> even in pseudo-code. It's impossible to send text across a socket - >> you have to send bytes of data. If you keep this distinction clearly >> in your head, you'll have no problem knowing when to encode and when >> to decode. For what you're doing here, for instance, I would packetize >> the bytes and then decode into text, and on sending, I'd encode text >> (UTF-8 would be hands-down best here) and then packetize. There are >> other options but that's how I'd do it. > I'm not sure what you are talking about here. Would you care to elaborate on this please (it interests and confuses) ? Fundamentally, network protocols work with bytes. (Actually, they're often called 'octets' - and a good number of protocols work with *bits*, of which an octet is simply a group of eight.) They don't work with characters. But humans want to send text. I'll use these posts as an example. 1) Human types text into mail client, newsreader, or web browser. 2) Client wraps that text up somehow and sends it to a server. 3) Server sends it along to other servers. 4) Server sends stuff to another client. 5) Client unwraps the text and shows it to a human. For there to be viable communication, the text typed in step 1 has to be the same as the text shown in step 5. So we need to have some kind of system that says "This character that I see on my screen is represented by this byte or sequence of bytes". That's called an encoding. It's simply a mapping of characters to byte sequences. (There are other complexities, too, but I'll handwave those for the moment. For now, let's pretend that one character that you see on the screen - more properly termed a glyph - is represented by one stream of bytes.) The best way to handle this is Unicode, because it's fairly safe to assume that most people can handle it. So you design your protocol to use Unicode characters and UTF-8 encoding. That means that: * The character 'A' (LATIN CAPITAL LETTER A) is represented by code point U+0041 and byte sequence 0x41 * The character '?' (COPYRIGHT SIGN) is code point U+00A9 or 0xC2 0xA9 * '?' (WHITE SMILING FACE) is U+263A or 0xE2 0x98 0xBA * '?' (CUNEIFORM SIGN URU TIMES KI) is U+12345 or 0xF0 0x92 0x8D 0x85 (Tip: http://www.fileformat.info/ is a great place to play around with these sorts of things.) An agreement like this means that one human can type a white smiling face, his client will interpret it as U+263A, the email and news posts will contain E2 98 BA, and the human at the other end will see a white smiling face. There's more to it than that, at least with these posts, because not everyone uses UTF-8 (so the encoding has to be declared), but if you're creating a brand new protocol, you can simply mandate it. I strongly recommend UTF-8, by the way; it's compact for text that's mostly Latin characters, it's well known, and it covers the entire Unicode range (unlike, say, CP-1252 as used on Windows, or the ISO-8859-? series). Since you're working with JSON, you could choose to work with ASCII, as JSON has its own notation for incorporating non-ASCII characters in an ASCII stream. But I think it's probably better to use UTF-8. One of the huge advantages of Python 3 over Python 2 is that it forces you to think about this up-front. There is a stark divide between bytes and text. In Python 2, you can sorta pretend that ASCII text and bytes are the same thing, which often leads to programs that work perfectly until they get to a "weird character". Fact is, there are no weird characters. :) I recommend this talk by Ned Batchelder: http://nedbatchelder.com/text/unipain.html Watch it, comprehend it, and code with his Facts of Life and Pro Tips in mind, and you'll have no pain. > I'm posting this on google groups, so I hope the formatting turns out ok :P thanks. Your lines are coming out extremely long, but the biggest annoyance of GG (double-spaced replies) isn't happening. Thank you. ChrisA From ned at nedbatchelder.com Wed Jan 15 07:55:48 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 15 Jan 2014 07:55:48 -0500 Subject: Question about object lifetime and access In-Reply-To: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Message-ID: On 1/15/14 7:13 AM, Asaf Las wrote: > Hi community > > i am beginner in Python and have possibly silly questions i could not figure out answers for. > > Below is the test application working with uwsgi to test json-rpc. > ------------------------------------------------------------------------ > from multiprocessing import Process > from werkzeug.wrappers import Request, Response > from werkzeug.serving import run_simple > > from jsonrpc import JSONRPCResponseManager, dispatcher > > p = "module is loaded" <------ (3) > print(p) > print(id(p)) > > @Request.application > def application(request): > print("server started") > > print(id(p)) > > # Dispatcher is dictionary {: callable} > dispatcher["echo"] = lambda s: s <---- (1) > dispatcher["add"] = lambda a, b: a + b <---- (2) > > print("request data ==> ", request.data) > response = JSONRPCResponseManager.handle(request.data, dispatcher) > return Response(response.json, mimetype='application/json') > ------------------------------------------------------------------------ > > As program will grow new rpc method dispatchers will be added so there is idea to reduce initialization code at steps 1 and 2 by making them global objects created at module loading, like string p at step 3. > > Multithreading will be enabled in uwsgi and 'p' will be used for read only. The important concepts to understand are names and values. All values in Python work the same way: they live until no name refers to them. Also, any name can be assigned to (rebound) after it has been defined. This covers the details in more depth: http://nedbatchelder.com/text/names.html > > Questions are: > - what is the lifetime for global object (p in this example). The name p is visible in this module for as long as the program is running. The object you've assigned to p can be shorter-lived if p is reassigned. > - will the p always have value it got during module loading Depends if you reassign it. > - if new thread will be created will p be accessible to it If the thread is running code defined in this module, yes, that code will be able to access p in that thread. > - if p is accessible to new thread will new thread initialize p value again? No, the module is only imported once, so the statements at the top level of the module are only executed once. > - is it guaranteed to have valid p content (set to "module is loaded") whenever application() function is called. Yes, unless you reassign p. > - under what condition p is cleaned by gc. Names are not reclaimed by the garbage collector, values are. The value assigned to p can be reclaimed if you reassign the name p, and nothing else is referring to the value. > > The rationale behind these question is to avoid object creation within application() whose content is same and do not change between requests calling application() function and thus to reduce script response time. > > Thanks in advance! Welcome. -- Ned Batchelder, http://nedbatchelder.com From oscar.j.benjamin at gmail.com Wed Jan 15 07:58:26 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 15 Jan 2014 12:58:26 +0000 Subject: Trying to wrap my head around futures and coroutines In-Reply-To: References: <20140107022958.GA59457@cskk.homeip.net> <20140107024521.GA75679@cskk.homeip.net> Message-ID: <20140115125824.GC4952@gmail.com> On Mon, Jan 06, 2014 at 09:15:56PM -0600, Skip Montanaro wrote: > From the couple responses I've seen, I must have not made myself > clear. Let's skip specific hypothetical tasks. Using coroutines, > futures, or other programming paradigms that have been introduced in > recent versions of Python 3.x, can traditionally event-driven code be > written in a more linear manner so that the overall algorithms > implemented in the code are easier to follow? My code is not > multi-threaded, so using threads and locking is not really part of the > picture. In fact, I'm thinking about this now precisely because the > first sentence of the asyncio documentation mentions single-threaded > concurrent code: "This module provides infrastructure for writing > single-threaded concurrent code using coroutines, multiplexing I/O > access over sockets and other resources, running network clients and > servers, and other related primitives." > > I'm trying to understand if it's possible to use coroutines or objects > like asyncio.Future to write more readable code, that today would be > implemented using callbacks, GTK signals, etc. Hi Skip, I don't yet understand how asyncio works in complete examples (I'm not sure that many people do yet) but I have a loose idea of it so take the following with a pinch of salt and expect someone else to correct me later. :) With asyncio the idea is that you can run IO operations concurrently in the a single thread. Execution can switch between different tasks while each task can be written as a linear-looking generator function without the need for callbacks and locks. Execution switching is based on which task has avilable IO data. So the core switcher keeps track of a list of objects (open files, sockets etc.) and executes the task when something is available. >From the perspective of the task generator code what happens is that you yield to allow other code to execute while you wait for some IO e.g.: @asyncio.coroutine def task_A(): a1 = yield from futureA1() a2 = yield from coroutineA2(a1) # Indirectly yields from futures a3 = yield from futureA3(a2) return a3 At each yield statement you are specifying some operation that takes time. During that time other coroutine code is allowed to execute in this thread. If task_B has a reference to the future that task_A is waiting on then it can be cancelled with the Future.cancel() method. I think that you can also cancel with a reference to the task. So I think you can do something like @asyncio.coroutine def task_A(): # Cancel the other task and wait if ref_taskB is not None: ref_taskB.cancel() asyncio.wait([ref_taskB]) try: # Linear looking code with no callbacks a1 = yield from futureA1() a2 = yield from coroutineA2(a1) # Indirectly yields from futures a3 = yield from futureA3(a2) except CancelledError: stop_A() raise # Or return something... return a3 Then task_B() would have the reciprocal structure. The general form with more than just A or B would be to have a reference to the current task then you could factor out the cancellation code with context managers, decorators or something else. Oscar From rosuav at gmail.com Wed Jan 15 08:05:43 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 00:05:43 +1100 Subject: Question about object lifetime and access In-Reply-To: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 11:13 PM, Asaf Las wrote: > Questions are: > - what is the lifetime for global object (p in this example). > - will the p always have value it got during module loading > - if new thread will be created will p be accessible to it > - if p is accessible to new thread will new thread initialize p value again? > - is it guaranteed to have valid p content (set to "module is loaded") whenever application() function is called. > - under what condition p is cleaned by gc. Your global p is actually exactly the same as the things you imported. In both cases, you have a module-level name bound to some object. So long as that name references that object, the object won't be garbage collected, and from anywhere in the module, you can reference that name and you'll get that object. (Unless you have a local that shadows it. I'll assume you're not doing that.) How do you go about creating threads? Is it after initializing the module? If so, they'll share the same p and the same object that it's pointing to - nothing will be reinitialized. As long as you don't change what's in p, it'll have the same value ([1] - handwave) whenever application() is called. That's a guarantee. For your lambda functions, you could simply make them module-level functions. You could then give them useful names, too. But decide based on code readability rather than questions of performance. At this stage, you have no idea what's going to be fast or slow - wait till you have a program that's not fast enough, and then *profile it* to find the slow bits. Unless you're doing that, you're completely wasting your time trying to make something faster. Start with readable, idiomatic code, code that you could come back to in six months and be confident of understanding. Do whatever it takes to ensure that, and let performance take care of itself. Nine times out of ten, you won't even have a problem. In the past twelve months, I can think of exactly *one* time when I needed to improve an app's performance after I'd coded it the readable way, and there was just one part of the code that needed to be tweaked. (And it was more of an algorithmic change than anything else, so it didn't much hurt readability.) Remember the two rules of code optimization: 1. Don't. 2. (For experts only) Don't yet. Follow those and you'll save more time than you would gain by micro-optimizing. And your time is worth more than the computer's. ChrisA [1] Technically p doesn't "have a value" at all. It's a name that's bound to some object. You can rebind it to another object, you can mutate the object it's bound to (except that you've bound it to a string, which is immutable), or you can sever the connection (with 'del p'), but in simple terms, it's generally "near enough" to say that p has a value. From rosuav at gmail.com Wed Jan 15 08:19:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 00:19:19 +1100 Subject: proposal: bring nonlocal to py2.x In-Reply-To: <52D679FD.3060406@chamonix.reportlab.co.uk> References: <52D679FD.3060406@chamonix.reportlab.co.uk> Message-ID: On Wed, Jan 15, 2014 at 11:07 PM, Robin Becker wrote: > On 13/01/2014 15:28, Chris Angelico wrote: > .......... > >> >> It's even worse than that, because adding 'nonlocal' is not a bugfix. >> So to be committed to the repo, it has to be approved for either 2.7 >> branch (which is in bugfix-only maintenance mode) or 2.8 branch (which >> does not exist). Good luck. :) > > ....... > fixing badly named variables is not a bug fix either, but that has happened > in python 2.7. A micro change release changed > > compiler.consts.SC_GLOBAL_EXPLICT > > to > > compiler.consts.SC_GLOBAL_EXPLICIT > > this is a change of api for the consts module (if you regard exported > variables as part of its api), but that didn't count for the developers. Hmm. I'd say that one's arguable; that's clearly a misspelled name. It comes down to the release manager's decision on points like that. I would say that adding a new keyword and a whole pile of new semantics is a bit bigger than renaming one constant :) But yes, this could break code in a point release, and that's a potential issue. ChrisA From roegltd at gmail.com Wed Jan 15 08:14:59 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 15 Jan 2014 05:14:59 -0800 (PST) Subject: Question about object lifetime and access In-Reply-To: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Message-ID: Thanks a lot for detailed answer! i plan to assign object to name only when module loads, that means outside of function or class method. Then object will be accessed from functions only for read purpose. I have read somewhere that global objects are referenced from module namespace will never have reference count down to 0 even if they are not referenced from functions or class methods. Is this true? Does it mean that global objects are destroyed when interpreter exits or thread where it runs is terminated? On Wednesday, January 15, 2014 2:13:56 PM UTC+2, Asaf Las wrote: > Hi community > > > > i am beginner in Python and have possibly silly questions i could not figure out answers for. > > > > Below is the test application working with uwsgi to test json-rpc. > > ------------------------------------------------------------------------ > > from multiprocessing import Process > > from werkzeug.wrappers import Request, Response > > from werkzeug.serving import run_simple > > > > from jsonrpc import JSONRPCResponseManager, dispatcher > > > > p = "module is loaded" <------ (3) > > print(p) > > print(id(p)) > > > > @Request.application > > def application(request): > > print("server started") > > > > print(id(p)) > > > > # Dispatcher is dictionary {: callable} > > dispatcher["echo"] = lambda s: s <---- (1) > > dispatcher["add"] = lambda a, b: a + b <---- (2) > > > > print("request data ==> ", request.data) > > response = JSONRPCResponseManager.handle(request.data, dispatcher) > > return Response(response.json, mimetype='application/json') > > ------------------------------------------------------------------------ > > > > As program will grow new rpc method dispatchers will be added so there is idea to reduce initialization code at steps 1 and 2 by making them global objects created at module loading, like string p at step 3. > > > > Multithreading will be enabled in uwsgi and 'p' will be used for read only. > > > > Questions are: > > - what is the lifetime for global object (p in this example). > > - will the p always have value it got during module loading > > - if new thread will be created will p be accessible to it > > - if p is accessible to new thread will new thread initialize p value again? > > - is it guaranteed to have valid p content (set to "module is loaded") whenever application() function is called. > > - under what condition p is cleaned by gc. > > > > The rationale behind these question is to avoid object creation within application() whose content is same and do not change between requests calling application() function and thus to reduce script response time. > > > > Thanks in advance! From roegltd at gmail.com Wed Jan 15 08:25:54 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 15 Jan 2014 05:25:54 -0800 (PST) Subject: Question about object lifetime and access In-Reply-To: References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Message-ID: Thanks! On Wednesday, January 15, 2014 3:05:43 PM UTC+2, Chris Angelico wrote: > > > > Questions are: > > > - what is the lifetime for global object (p in this example). > > > - will the p always have value it got during module loading > > > - if new thread will be created will p be accessible to it > > > - if p is accessible to new thread will new thread initialize p value again? > > > - is it guaranteed to have valid p content (set to "module is loaded") whenever application() function is called. > > > - under what condition p is cleaned by gc. > > > > Your global p is actually exactly the same as the things you imported. > > In both cases, you have a module-level name bound to some object. So > > long as that name references that object, the object won't be garbage > > collected, and from anywhere in the module, you can reference that > > name and you'll get that object. (Unless you have a local that shadows > > it. I'll assume you're not doing that.) > > > > How do you go about creating threads? Is it after initializing the > > module? If so, they'll share the same p and the same object that it's > > pointing to - nothing will be reinitialized. > > > > As long as you don't change what's in p, it'll have the same value > > ([1] - handwave) whenever application() is called. That's a guarantee. > > > > For your lambda functions, you could simply make them module-level > > functions. You could then give them useful names, too. But decide > > based on code readability rather than questions of performance. At > > this stage, you have no idea what's going to be fast or slow - wait > > till you have a program that's not fast enough, and then *profile it* > > to find the slow bits. Unless you're doing that, you're completely > > wasting your time trying to make something faster. Start with > > readable, idiomatic code, code that you could come back to in six > > months and be confident of understanding. Do whatever it takes to > > ensure that, and let performance take care of itself. Nine times out > > of ten, you won't even have a problem. In the past twelve months, I > > can think of exactly *one* time when I needed to improve an app's > > performance after I'd coded it the readable way, and there was just > > one part of the code that needed to be tweaked. (And it was more of an > > algorithmic change than anything else, so it didn't much hurt > > readability.) Remember the two rules of code optimization: > > > > 1. Don't. > > 2. (For experts only) Don't yet. > > > > Follow those and you'll save more time than you would gain by > > micro-optimizing. And your time is worth more than the computer's. > > > > ChrisA > > > > [1] Technically p doesn't "have a value" at all. It's a name that's > > bound to some object. You can rebind it to another object, you can > > mutate the object it's bound to (except that you've bound it to a > > string, which is immutable), or you can sever the connection (with > > 'del p'), but in simple terms, it's generally "near enough" to say > > that p has a value. From frank at chagford.com Wed Jan 15 08:31:15 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 15 Jan 2014 15:31:15 +0200 Subject: Learning python networking References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmpb6yr-VpWypbJQn0a=pNjvNV2CchVBZaK+v_5JoSQOBg at mail.gmail.com... > You just run a loop like this: > > buffer = b'' > > def gets(): > while '\n' not in buffer: > data = sock.recv(1024) > if not data: > # Client is disconnected, handle it gracefully > return None # or some other sentinel > line, buffer = buffer.split(b'\n',1) > return line.decode().replace('\r', '') > I think you may have omitted a line there - def gets(): while '\n' not in buffer: data = sock.recv(1024) if not data: # Client is disconnected, handle it gracefully return None # or some other sentinel #--> buffer = buffer + data #--> line, buffer = buffer.split(b'\n',1) return line.decode().replace('\r', '') Also, as I am looking at it, I notice that the second line should say - while b'\n' not in buffer: I feel a bit guilty nitpicking, as you have provided a wonderfully comprehensive answer, but I wanted to make sure the OP did not get confused. Frank Millman From info at wingware.com Wed Jan 15 08:39:02 2014 From: info at wingware.com (Wingware) Date: Wed, 15 Jan 2014 08:39:02 -0500 Subject: ANN: Wing IDE 5.0.2 released Message-ID: <52D68F76.8050808@wingware.com> Hi, Wingware has released version 5.0.2 of Wing IDE, our integrated development environment designed specifically for the Python programming language. Wing IDE includes a professional quality code editor with vi, emacs, and other key bindings, auto-completion, call tips, refactoring, context-aware auto-editing, a powerful graphical debugger, version control, unit testing, search, and many other features. For details see http://wingware.com/ Changes in this minor release include: * Support for matplotlib with Anaconda * Support for Django 1.6 * Preference to auto-add EOL at end of files * Preference to disable mouse wheel font zoom * Fix code analysis in files containing \r EOLs * Fix typing in middle of toolbar search * Improve look of tabbed areas in dark color palettes * Fix problems with backspace at start of line * Fix VI mode : commands * Fix dragging tools back into main window * 30 other bug fixes For details see http://wingware.com/pub/wingide/5.0.2/CHANGELOG.txt New features in Wing 5 include: * Now runs native on OS X * Draggable tools and editors * Configurable toolbar and editor & project context menus * Optionally opens a different sets of files in each editor split * Lockable editor splits * Optional Python Turbo completion (context-appropriate completion on all non-symbol keys) * Sharable color palettes and syntax highlighting configurations * Auto-editing is on by default (except some operations that have a learning curve) * Named file sets * Sharable launch configurations * Asynchronous I/O in Debug Probe and Python Shell * Expanded and rewritten tutorial * Support for Python 3.4 and Django 1.6 For more information on what's new in Wing 5, see http://wingware.com/wingide/whatsnew Free trial: http://wingware.com/wingide/trial Downloads: http://wingware.com/downloads Feature matrix: 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 Advancing Software Development www.wingware.com From rosuav at gmail.com Wed Jan 15 09:07:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 01:07:51 +1100 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> Message-ID: On Thu, Jan 16, 2014 at 12:31 AM, Frank Millman wrote: > I think you may have omitted a line there - > > def gets(): > while '\n' not in buffer: > data = sock.recv(1024) > if not data: > # Client is disconnected, handle it gracefully > return None # or some other sentinel > #--> > buffer = buffer + data > #--> > line, buffer = buffer.split(b'\n',1) > return line.decode().replace('\r', '') Yes, indeed I did, thanks. Apart from using augmented assignment, that's exactly what I would have put there, if I'd actually taken a moment to test the code. > Also, as I am looking at it, I notice that the second line should say - > > while b'\n' not in buffer: Right again. Fortunately, Py3 would catch that one with a TypeError. See? This is why you should use Py3. :) > I feel a bit guilty nitpicking, as you have provided a wonderfully > comprehensive answer, but I wanted to make sure the OP did not get confused. No no, nitpicking is exactly what ensures that the end result is correct. If I got offended at you correcting my code, it would imply that I think myself perfect (or at least, that I consider you to be utterly incapable of noticing my errors), which is provably false :) One of the mind-set changes that I had to introduce at work was that people don't own code, the repository does - if you see an improvement to something I wrote, or I see an improvement to something you wrote, they're improvements to be committed, not turf wars to be battled over. Especially on something like this, please *do* catch other people's mistakes :) ChrisA From wxjmfauth at gmail.com Wed Jan 15 09:55:45 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 15 Jan 2014 06:55:45 -0800 (PST) Subject: =?ISO-8859-1?B?UmU6ICdTdHJh32UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> Message-ID: <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> Le mercredi 15 janvier 2014 13:13:36 UTC+1, Ned Batchelder a ?crit?: > > ... more than one codepoint makes up a grapheme ... No > In Unicode terms, an encoding is a mapping between codepoints and bytes. No jmf From davea at davea.name Wed Jan 15 10:11:42 2014 From: davea at davea.name (Dave Angel) Date: Wed, 15 Jan 2014 10:11:42 -0500 (EST) Subject: Question about object lifetime and access References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Message-ID: Asaf Las Wrote in message: > Hi community > Welcome. > > Multithreading will be enabled in uwsgi and 'p' will be used for read only. > > Questions are: > - what is the lifetime for global object (p in this example). The name will be visible in this module until the application shuts down or till you use del. > - will the p always have value it got during module loading The (str) object that you bind to it will survive till you del or reassign p. Reassignment can happen with a simple assignment statement or via an 'as' clause. The value of such a str object will never change because it's an immutable type. Convention is to use names that are all uppercase. And long, descriptive names are preferred over one-letter names, especially for long-lived ones. Don't worry, long names do not take longer. > - if new thread will be created will p be accessible to it It is accessible to all threads in the same process. It is also available to other modules via the import mechanism. But watch out for circular imports, which frequently cause bugs. > - if p is accessible to new thread will new thread initialize p value again? Module level code runs only once per process. > - is it guaranteed to have valid p content (set to "module is loaded") whenever application() function is called. Except with circular imports. > - under what condition p is cleaned by gc. Names are never garbage collected. See above for objects. > > The rationale behind these question is to avoid object creation within application() whose content is same and do not change between requests calling application() function and thus to reduce script response time. > Highly unlikely to matter, and it might slow down a program slightly rather than speed it up slightly. Get your program readable so you have a chance of catching bugs, pick your algorithms reasonably, and if it's not fast enough, measure, don't guess. > Thanks in advance! > > > > > -- DaveA ----Android NewsGroup Reader---- http://www.piaohong.tk/newsgroup From rosuav at gmail.com Wed Jan 15 10:14:38 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 02:14:38 +1100 Subject: =?UTF-8?B?UmU6ICdTdHJhw59lJyAoJ1N0cmFzc2UnKSBhbmQgUHl0aG9uIDI=?= In-Reply-To: <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> Message-ID: On Thu, Jan 16, 2014 at 1:55 AM, wrote: > Le mercredi 15 janvier 2014 13:13:36 UTC+1, Ned Batchelder a ?crit : > >> >> ... more than one codepoint makes up a grapheme ... > > No Yes. http://www.unicode.org/faq/char_combmark.html >> In Unicode terms, an encoding is a mapping between codepoints and bytes. > > No Yes. http://www.unicode.org/reports/tr17/ Specifically: "Character Encoding Form: a mapping from a set of nonnegative integers that are elements of a CCS to a set of sequences of particular code units of some specified width, such as 32-bit integers" Or are you saying that www.unicode.org is wrong about the definitions of Unicode terms? ChrisA From piet at vanoostrum.org Wed Jan 15 10:18:01 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 15 Jan 2014 16:18:01 +0100 Subject: setup.py issue - some files are included as intended, but one is not References: Message-ID: Dan Stromberg writes: > On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg wrote: >> Hi folks. >> >> I have a setup.py problem that's driving me nuts. > > Anyone? I've received 0 responses. I can't even install your code because there's a bug in it. m4_treap.m4 contains this instruction twice: ifdef(/*pyx*/,cp)if current is None: ifdef(/*pyx*/,cp)raise KeyError Which when generating pyx_treap.pyx (with *pyx* defined) expands to the syntactically incorrect cpif current is None: cpraise KeyError -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From rosuav at gmail.com Wed Jan 15 10:36:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 02:36:06 +1100 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 11:52 PM, Chris Angelico wrote: > One of the fundamentals of the internet is that connections *will* > break. A friend of mine introduced me to Magic: The Gathering via a > program that couldn't handle drop-outs, and it got extremely > frustrating - we couldn't get a game going. Build your server such > that your clients can disconnect and reconnect, and you protect > yourself against half the problem; allow them to connect and kick the > other connection off, and you solve the other half. Case in point, and a very annoying one: Phone queues do NOT handle drop-outs. There's no way to reconnect to the queue and resume your place, you have to start over from the back of the queue. I'm currently on hold to my ISP because of an outage, and the cordless phone ran out of battery 27 minutes into an estimated 30-minute wait time. (Though I suspect it'd be a lot longer than 30 minutes. Those wait times are notoriously inaccurate.) So now I'm waiting, AGAIN, and those previous 27 minutes of sitting around with their on-hold music playing through speakerphone were of no value whatsoever. I can't transfer to a different handset or connection, I have to just hope that this one will get through. With TCP-based servers, it's easy to do better than that - all you have to do is separate the connection state from the actual socket, and hang onto a "connection" for some period of time after its socket disconnects (say, 10-15 minutes). Your users will thank you! ChrisA From travisgriggs at gmail.com Wed Jan 15 10:43:17 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Wed, 15 Jan 2014 07:43:17 -0800 Subject: Python 3.x adoption In-Reply-To: References: Message-ID: <67875DC9-A6AF-4FB5-BB88-56F6F31B6755@gmail.com> Here we go again? On Jan 14, 2014, at 11:33 AM, Staszek wrote: > Hi > > What's the problem with Python 3.x? It was first released in 2008, but > web hosting companies still seem to offer Python 2.x rather. > > For example, Google App Engine only offers Python 2.7. > > What's wrong?... Maybe what it means is that Python3 is just fine, but Google App Engine isn?t seeing a lot of development/improvement lately, that it?s just in maintenance mode. Imagine that, Google not finishing/maintaining something. I wish amongst the periodic maelstroms of Python2 vs Python3 handwringing, people would look at the new project starts. When I work with someone?s old library that they?ve moved on from, I use python2 if I have to, but anytime I can, I use python3. Personally, I wish they?d start python4, sure would take the heat out of the 3 vs 2 debates. And maybe there?d be a program called twentyfour as a result. From rosuav at gmail.com Wed Jan 15 11:14:22 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 03:14:22 +1100 Subject: Python 3.x adoption In-Reply-To: <67875DC9-A6AF-4FB5-BB88-56F6F31B6755@gmail.com> References: <67875DC9-A6AF-4FB5-BB88-56F6F31B6755@gmail.com> Message-ID: On Thu, Jan 16, 2014 at 2:43 AM, Travis Griggs wrote: > Personally, I wish they?d start python4, sure would take the heat out of the 3 vs 2 debates. And maybe there?d be a program called twentyfour as a result. Learn All Current Versions of Python in Twenty-Four Hours? ChrisA From travisgriggs at gmail.com Wed Jan 15 11:28:49 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Wed, 15 Jan 2014 08:28:49 -0800 Subject: =?utf-8?Q?Re=3A_=27Stra=C3=9Fe=27_=28=27Strasse=27=29_and_Python?= =?utf-8?Q?_2?= In-Reply-To: <52D68402.6030407@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <52D68402.6030407@chamonix.reportlab.co.uk> Message-ID: <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> On Jan 15, 2014, at 4:50 AM, Robin Becker wrote: > On 15/01/2014 12:13, Ned Batchelder wrote: > ........ >>> On my utf8 based system >>> >>> >>>> robin at everest ~: >>>> $ cat ooo.py >>>> if __name__=='__main__': >>>> import sys >>>> s='A?B' >>>> print('version_info=%s\nlen(%s)=%d' % (sys.version_info,s,len(s))) >>>> robin at everest ~: >>>> $ python ooo.py >>>> version_info=sys.version_info(major=3, minor=3, micro=3, >>>> releaselevel='final', serial=0) >>>> len(A?B)=3 >>>> robin at everest ~: >>>> $ >>> >>> > ........ >> You are right that more than one codepoint makes up a grapheme, and that you'll >> need code to deal with the correspondence between them. But let's not muddy >> these already confusing waters by referring to that mapping as an encoding. >> >> In Unicode terms, an encoding is a mapping between codepoints and bytes. Python >> 3's str is a sequence of codepoints. >> > Semantics is everything. For me graphemes are the endpoint (or should be); to get a proper rendering of a sequence of graphemes I can use either a sequence of bytes or a sequence of codepoints. They are both encodings of the graphemes; what unicode says is an encoding doesn't define what encodings are ie mappings from some source alphabet to a target alphabet. But you?re talking about two levels of encoding. One runs on top of the other. So insisting that you be able to call them all encodings, makes the term pointless, because now it?s ambiguous as to what you?re referring to. Are you referring to encoding in the sense of representing code points with bytes? Or are you referring to what the unicode guys call ?forms?? For example, the NFC form of ??? is ?\u00F1?. ?nThe NFD form represents the exact same grapheme, but is ?\u006e\u0303?. You can call them encodings if you want, but I echo Ned?s sentiment that you keep that to yourself. Conventionally, they?re different forms, not different encodings. You can encode either form with an encoding, e.g. '\u00F1'.encode('utf8?) '\u00F1'.encode('utf16?) '\u006e\u0303'.encode('utf8?) '\u006e\u0303'.encode('utf16') From rosuav at gmail.com Wed Jan 15 11:31:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 03:31:03 +1100 Subject: Learning python networking In-Reply-To: <7B721FFF-5F01-4736-AC82-B5E71848F926@mac.com> References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> <7B721FFF-5F01-4736-AC82-B5E71848F926@mac.com> Message-ID: On Thu, Jan 16, 2014 at 3:25 AM, William Ray Wing wrote: > On Jan 15, 2014, at 7:52 AM, Chris Angelico wrote: >> One of the fundamentals of the internet is that connections *will* >> break. A friend of mine introduced me to Magic: The Gathering via a >> program that couldn't handle drop-outs, and it got extremely >> frustrating - we couldn't get a game going. Build your server such >> that your clients can disconnect and reconnect, and you protect >> yourself against half the problem; allow them to connect and kick the >> other connection off, and you solve the other half. > > But note VERY carefully that this can open HUGE security holes if not done with extreme care. > > Leaving a dangling connection (not session, TCP closes sessions) open is an invitation so bad things happening. Not sure what you mean here. I'm assuming an authentication system that stipulates one single active connection per authenticated user (if you reauthenticate with the same credentials, it'll disconnect the other one on the presumption that the connection's been lost). In terms of resource wastage, there's no difference between disconnecting now and letting it time out, and waiting the ten minutes (or whatever) and then terminating cleanly. Or do you mean another user gaining access? It's still governed by the same authentication. ChrisA From rosuav at gmail.com Wed Jan 15 11:32:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 03:32:16 +1100 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> <7B721FFF-5F01-4736-AC82-B5E71848F926@mac.com> Message-ID: On Thu, Jan 16, 2014 at 3:31 AM, Chris Angelico wrote: > I'm assuming an authentication system > that stipulates one single active connection per authenticated user Incidentally, in an environment where everything's trusted (LAN or localhost), the "authentication system" can be as simple as "type a user name". I've done systems like that; first line entered becomes the handle or key, and it does the same kick-off system on duplicate. ChrisA From wrw at mac.com Wed Jan 15 11:43:41 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 15 Jan 2014 11:43:41 -0500 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> <7B721FFF-5F01-4736-AC82-B5E71848F926@mac.com> Message-ID: <9CAF3375-B6C0-4B4A-A852-111ED74CFD68@mac.com> On Jan 15, 2014, at 11:31 AM, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 3:25 AM, William Ray Wing wrote: >> On Jan 15, 2014, at 7:52 AM, Chris Angelico wrote: >>> One of the fundamentals of the internet is that connections *will* >>> break. A friend of mine introduced me to Magic: The Gathering via a >>> program that couldn't handle drop-outs, and it got extremely >>> frustrating - we couldn't get a game going. Build your server such >>> that your clients can disconnect and reconnect, and you protect >>> yourself against half the problem; allow them to connect and kick the >>> other connection off, and you solve the other half. >> >> But note VERY carefully that this can open HUGE security holes if not done with extreme care. >> >> Leaving a dangling connection (not session, TCP closes sessions) open is an invitation so bad things happening. > > Not sure what you mean here. I'm assuming an authentication system > that stipulates one single active connection per authenticated user > (if you reauthenticate with the same credentials, it'll disconnect the > other one on the presumption that the connection's been lost). In > terms of resource wastage, there's no difference between disconnecting > now and letting it time out, and waiting the ten minutes (or whatever) > and then terminating cleanly. Or do you mean another user gaining > access? It's still governed by the same authentication. > I was assuming another user picking up the connection using sniffed credentials (and yes, despite all the work on ssh, not all man-in-the-middle attacks have been killed). -Bill > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From breamoreboy at yahoo.co.uk Wed Jan 15 11:46:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 15 Jan 2014 16:46:25 +0000 Subject: Python 3.x adoption In-Reply-To: References: <67875DC9-A6AF-4FB5-BB88-56F6F31B6755@gmail.com> Message-ID: On 15/01/2014 16:14, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 2:43 AM, Travis Griggs wrote: >> Personally, I wish they?d start python4, sure would take the heat out of the 3 vs 2 debates. And maybe there?d be a program called twentyfour as a result. > > Learn All Current Versions of Python in Twenty-Four Hours? > > ChrisA > Totally unfair, Steven D'Aprano amongst others would have a head start :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From john_ladasky at sbcglobal.net Wed Jan 15 11:51:28 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Wed, 15 Jan 2014 08:51:28 -0800 (PST) Subject: Chanelling Guido - dict subclasses In-Reply-To: References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <05ff1332-1776-4ac0-88b4-84f8fd323ce3@googlegroups.com> On Wednesday, January 15, 2014 12:40:33 AM UTC-8, Peter Otten wrote: > Personally I feel dirty whenever I write Python code that defeats duck- > typing -- so I would not /recommend/ any isinstance() check. While I am inclined to agree, I have yet to see a solution to the problem of flattening nested lists/tuples which avoids isinstance(). If anyone has written one, I would like to see it, and consider its merits. From robin at reportlab.com Wed Jan 15 11:55:31 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 15 Jan 2014 16:55:31 +0000 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <52D68402.6030407@chamonix.reportlab.co.uk> <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> Message-ID: <52D6BD83.9000804@chamonix.reportlab.co.uk> On 15/01/2014 16:28, Travis Griggs wrote: ........ of a sequence of graphemes I can use either a sequence of bytes or a sequence of codepoints. They are both encodings of the graphemes; what unicode says is an encoding doesn't define what encodings are ie mappings from some source alphabet to a target alphabet. > > But you?re talking about two levels of encoding. One runs on top of the other. So insisting that you be able to call them all encodings, makes the term pointless, because now it?s ambiguous as to what you?re referring to. Are you referring to encoding in the sense of representing code points with bytes? Or are you referring to what the unicode guys call ?forms?? > > For example, the NFC form of ??? is ?\u00F1?. ?nThe NFD form represents the exact same grapheme, but is ?\u006e\u0303?. You can call them encodings if you want, but I echo Ned?s sentiment that you keep that to yourself. Conventionally, they?re different forms, not different encodings. You can encode either form with an encoding, e.g. > > '\u00F1'.encode('utf8?) > '\u00F1'.encode('utf16?) > > '\u006e\u0303'.encode('utf8?) > '\u006e\u0303'.encode('utf16') > I think about these as encodings, because that's what they are mathematically, logically & practically. I can encode the target grapheme sequence as a sequence of bytes using a particular 'unicode encoding' eg utf8 or a sequence of code points. The fact that unicoders want to take over the meaning of encoding is not relevant. In my utf8 bash shell the python print() takes one encoding (python3 str) and translates that to the stdout encoding which happens to be utf8 and passes that to the shell which probably does a lot of work to render the result as graphical symbols (or graphemes). I'm not anti unicode, that's just an assignment of identity to some symbols. Coding the values of the ids is a separate issue. It's my belief that we don't need more than the byte level encoding to represent unicode. One of the claims made for python3 unicode is that it somehow eliminates the problems associated with other encodings eg utf8, but in fact they will remain until we force printers/designers to stop using complicated multi-codepoint graphemes. I suspect that won't happen. -- Robin Becker From rosuav at gmail.com Wed Jan 15 12:07:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 04:07:28 +1100 Subject: Learning python networking In-Reply-To: <9CAF3375-B6C0-4B4A-A852-111ED74CFD68@mac.com> References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> <7B721FFF-5F01-4736-AC82-B5E71848F926@mac.com> <9CAF3375-B6C0-4B4A-A852-111ED74CFD68@mac.com> Message-ID: On Thu, Jan 16, 2014 at 3:43 AM, William Ray Wing wrote: > I was assuming another user picking up the connection using sniffed credentials (and yes, despite all the work on ssh, not all man-in-the-middle attacks have been killed). If that can happen, then I would much prefer that it kick my connection off - at least that way, I have some chance of knowing it's happened. But I suspect that this sort of thing is way WAY out of the league of the OP's stated problem :) ChrisA From rosuav at gmail.com Wed Jan 15 12:08:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 04:08:42 +1100 Subject: Python 3.x adoption In-Reply-To: References: <67875DC9-A6AF-4FB5-BB88-56F6F31B6755@gmail.com> Message-ID: On Thu, Jan 16, 2014 at 3:46 AM, Mark Lawrence wrote: > On 15/01/2014 16:14, Chris Angelico wrote: >> >> On Thu, Jan 16, 2014 at 2:43 AM, Travis Griggs >> wrote: >>> >>> Personally, I wish they?d start python4, sure would take the heat out of >>> the 3 vs 2 debates. And maybe there?d be a program called twentyfour as a >>> result. >> >> >> Learn All Current Versions of Python in Twenty-Four Hours? >> >> ChrisA >> > > Totally unfair, Steven D'Aprano amongst others would have a head start :) Heh. I said "Current" specifically to cut out 1.5.2, and also to eliminate the need to worry about string exceptions and so on. But mainly just for the pun. ChrisA From sertorbe at gmail.com Wed Jan 15 12:02:08 2014 From: sertorbe at gmail.com (Sergio Tortosa Benedito) Date: Wed, 15 Jan 2014 18:02:08 +0100 Subject: Python declarative Message-ID: <1389805328.32401.6.camel@linux-fetk.site> Hi I'm developing a sort of language extension for writing GUI programs called guilang, right now it's written in Lua but I'm considreing Python instead (because it's more tailored to alone applications). My question it's if I can achieve this declarative-thing in python. Here's an example: Window "myWindow" { title="Hello world"; Button "myButton" { label="I'm a button"; onClick=exit } } print(myWindow.myButton.label) Of course it doesn't need to be 100% equal. Thanks in advance Sergio From rosuav at gmail.com Wed Jan 15 12:14:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 04:14:57 +1100 Subject: =?UTF-8?B?UmU6ICdTdHJhw59lJyAoJ1N0cmFzc2UnKSBhbmQgUHl0aG9uIDI=?= In-Reply-To: <52D6BD83.9000804@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <52D68402.6030407@chamonix.reportlab.co.uk> <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> <52D6BD83.9000804@chamonix.reportlab.co.uk> Message-ID: On Thu, Jan 16, 2014 at 3:55 AM, Robin Becker wrote: > I think about these as encodings, because that's what they are > mathematically, logically & practically. I can encode the target grapheme > sequence as a sequence of bytes using a particular 'unicode encoding' eg > utf8 or a sequence of code points. By that definition, you can equally encode it as a bitmapped image, or as a series of lines and arcs, and those are equally well "encodings" of the character. This is not the normal use of that word. http://en.wikipedia.org/wiki/Character_encoding ChrisA From gill.manish90 at gmail.com Wed Jan 15 12:12:16 2014 From: gill.manish90 at gmail.com (Manish) Date: Wed, 15 Jan 2014 09:12:16 -0800 (PST) Subject: Communicate between Python and Node.js Message-ID: <1ea934d2-d48b-4857-aa4a-f4d24a9d8552@googlegroups.com> I've been tasked to write a module that sends data from Django to a Node.js server running on the same machine. Some magic happens in node and I recv the results back, which are then rendered using Django templates. At first I thought to use the requests library to GET/POST data to node, but I googled around and it seems lots of people think TCP sockets are the way to go. I tried implementing my own using several examples I have found online. It *kind of* works. It seems like I get blocked while trying to receive data back in the recv() loop. I never reach the end. I'm not an expert in sockets/networking, but maybe I'm not wrong in guessing it is because of the non-blocking nature of Node.js ? A Stackoverflow post helped a little more in figuring things out (though I'm not sure if I'm correct here). Right now, I'm failing during connect() - I get "Operation now in progress". So my question is, how can I get recv() to work properly so that data is seamlessly passed back and forth between my Python script and the node server. Am I taking the right approach? Is there any better way? Relevant scripts: 1) http://bpaste.net/show/NI2z9RhbT3HVtLVWUKuq/ 2) http://bpaste.net/show/YlulEZBTDE5KS5ZvSyET/ Thanks! From robin at reportlab.com Wed Jan 15 12:28:53 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 15 Jan 2014 17:28:53 +0000 Subject: =?ISO-8859-1?Q?=27Stra=DFe=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <52D68402.6030407@chamonix.reportlab.co.uk> <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> <52D6BD83.9000804@chamonix.reportlab.co.uk> Message-ID: <52D6C555.6050202@chamonix.reportlab.co.uk> On 15/01/2014 17:14, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 3:55 AM, Robin Becker wrote: >> I think about these as encodings, because that's what they are >> mathematically, logically & practically. I can encode the target grapheme >> sequence as a sequence of bytes using a particular 'unicode encoding' eg >> utf8 or a sequence of code points. > > By that definition, you can equally encode it as a bitmapped image, or > as a series of lines and arcs, and those are equally well "encodings" > of the character. This is not the normal use of that word. > > http://en.wikipedia.org/wiki/Character_encoding > > ChrisA > Actually I didn't use the term 'character encoding', but that doesn't alter the argument. If I chose to embed the final graphemes as images encoded as bytes or lists of numbers that would still be still be an encoding; it just wouldn't be very easily usable (lots of typing). -- Robin Becker From rosuav at gmail.com Wed Jan 15 12:33:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 04:33:21 +1100 Subject: Python declarative In-Reply-To: <1389805328.32401.6.camel@linux-fetk.site> References: <1389805328.32401.6.camel@linux-fetk.site> Message-ID: On Thu, Jan 16, 2014 at 4:02 AM, Sergio Tortosa Benedito wrote: > Hi I'm developing a sort of language extension for writing GUI programs > called guilang, right now it's written in Lua but I'm considreing Python > instead (because it's more tailored to alone applications). My question > it's if I can achieve this declarative-thing in python. Here's an > example: > > Window "myWindow" { > title="Hello world"; > Button "myButton" { > label="I'm a button"; > onClick=exit > } > } > print(myWindow.myButton.label) Probably the easiest way to do that would be with dictionaries or function named arguments. It'd be something like this: myWindow = Window( title="Hello World", myButton=Button( label="I'm a button", onClick=exit ) ) print(myWindow.myButton.label) For this to work, you'd need a Window class that recognizes a number of keyword arguments (eg for title and other attributes), and then takes all other keyword arguments and turns them into its children. Possible, but potentially messy; if you happen to name your button "icon", it might be misinterpreted as an attempt to set the window's icon, and cause a very strange and incomprehensible error. The syntax you describe there doesn't allow any flexibility in placement. I don't know how you'd organize that; but what you could do is something like GTK uses: a Window contains exactly one child, which will usually be a layout manager. Unfortunately the Python GTK bindings don't allow such convenient syntax as you use here, so you'd need some sort of wrapper. But it wouldn't be hard to set up something like this: def clickme(obj): print("You clicked me!") obj.set_label("Click me again!") myWindow = Window( title="Hello World", signal_delete=exit ).add(Vbox(spacing=10) .add(Button(label="I'm a button!", signal_clicked=exit)) .add(Button(label="Click me", signal_clicked=clickme)) ) This is broadly similar to how I create a window using GTK with Pike, and it's easy to structure the code the same way the window is structured. If the number of helper classes you'd have to make gets daunting, you could possibly do this: myWindow = GTK(Gtk.Window, title="Hello World", signal_delete=exit ).add(GTK(Gtk.Vbox, spacing=10) .add(GTK(Gtk.Button, label="I'm a button!", signal_clicked=exit)) .add(GTK(Gtk.Button, label="Click me", signal_clicked=clickme)) ) so there's a single "GTK" class, which takes as its first positional argument a GTK object type to clone. This is all perfectly valid Python syntax, but I don't know of a convenient way to do this with the current modules, so it may require writing a small amount of wrapper code. ChrisA From cjwelborn at live.com Wed Jan 15 12:37:10 2014 From: cjwelborn at live.com (Christopher Welborn) Date: Wed, 15 Jan 2014 11:37:10 -0600 Subject: Python 3.x adoption In-Reply-To: References: Message-ID: On 01/14/2014 01:33 PM, Staszek wrote: > Hi > > What's the problem with Python 3.x? It was first released in 2008, but > web hosting companies still seem to offer Python 2.x rather. > > For example, Google App Engine only offers Python 2.7. > > What's wrong?... > My last two hosts have offered multiple versions of python. I upgraded to python 3.3 recently on my site. I guess its easier for some folks to offer such a thing, it just depends on their setup. My host also offered Django 1.5 almost immediately after its release, and the same with 1.6. They give the user options, and if they break their site by upgrading too early (without migrating code) it's the user's fault. -- - Christopher Welborn http://welbornprod.com From rosuav at gmail.com Wed Jan 15 12:40:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 04:40:03 +1100 Subject: Communicate between Python and Node.js In-Reply-To: <1ea934d2-d48b-4857-aa4a-f4d24a9d8552@googlegroups.com> References: <1ea934d2-d48b-4857-aa4a-f4d24a9d8552@googlegroups.com> Message-ID: On Thu, Jan 16, 2014 at 4:12 AM, Manish wrote: > At first I thought to use the requests library to GET/POST data to node, but I googled around and it seems lots of people think TCP sockets are the way to go. I tried implementing my own using several examples I have found online. It *kind of* works. It seems like I get blocked while trying to receive data back in the recv() loop. I never reach the end. I'm not an expert in sockets/networking, but maybe I'm not wrong in guessing it is because of the non-blocking nature of Node.js ? Do you need to use non-blocking sockets here? I think, from a quick skim of your code, that you'd do better with a blocking socket. Tip: Any time you have a sleep(1) call in your code, look to see if it's doing the wrong thing. In this case, I'm pretty sure it is. Sleeping for a second and then trying to read from a nonblocking socket seems like a messy way to just read until you have what you want. There's another thread happening at the moment about networking in Python. You may find it of interest. ChrisA From ian.g.kelly at gmail.com Wed Jan 15 13:32:19 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 15 Jan 2014 11:32:19 -0700 Subject: =?ISO-8859-1?B?UmU6ICdTdHJh32UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: <52D6BD83.9000804@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <52D68402.6030407@chamonix.reportlab.co.uk> <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> <52D6BD83.9000804@chamonix.reportlab.co.uk> Message-ID: On Wed, Jan 15, 2014 at 9:55 AM, Robin Becker wrote: > The fact that unicoders want to take over the meaning of encoding is not > relevant. A virus is a small infectious agent that replicates only inside the living cells of other organisms. In the context of computing however, that definition is completely false, and if you insist upon it when trying to talk about computers, you're only going to confuse people as to what you mean. Somehow, I haven't seen any biologists complaining that computer users want to take over the meaning of virus. From __peter__ at web.de Wed Jan 15 13:35:51 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Jan 2014 19:35:51 +0100 Subject: Chanelling Guido - dict subclasses References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> <05ff1332-1776-4ac0-88b4-84f8fd323ce3@googlegroups.com> Message-ID: John Ladasky wrote: > On Wednesday, January 15, 2014 12:40:33 AM UTC-8, Peter Otten wrote: >> Personally I feel dirty whenever I write Python code that defeats duck- >> typing -- so I would not /recommend/ any isinstance() check. > > While I am inclined to agree, I have yet to see a solution to the problem > of flattening nested lists/tuples which avoids isinstance(). If anyone > has written one, I would like to see it, and consider its merits. Well, you should always be able to find some property that discriminates what you want to treat as sequences from what you want to treat as atoms. (flatten() Adapted from a nine-year-old post by Nick Craig-Wood ) >>> def flatten(items, check): ... if check(items): ... for item in items: ... yield from flatten(item, check) ... else: ... yield items ... >>> items = [1, 2, (3, 4), [5, [6, (7,)]]] >>> print(list(flatten(items, check=lambda o: hasattr(o, "sort")))) [1, 2, (3, 4), 5, 6, (7,)] >>> print(list(flatten(items, check=lambda o: hasattr(o, "count")))) [1, 2, 3, 4, 5, 6, 7] The approach can of course break >>> items = ["foo", 1, 2, (3, 4), [5, [6, (7,)]]] >>> print(list(flatten(items, check=lambda o: hasattr(o, "count")))) Traceback (most recent call last): File "", line 1, in File "", line 4, in flatten File "", line 4, in flatten File "", line 4, in flatten File "", line 4, in flatten File "", line 4, in flatten File "", line 4, in flatten File "", line 4, in flatten File "", line 2, in flatten RuntimeError: maximum recursion depth exceeded and I'm the first to admit that the fix below looks really odd: >>> print(list(flatten(items, check=lambda o: hasattr(o, "count") and not hasattr(o, "split")))) ['foo', 1, 2, 3, 4, 5, 6, 7] In fact all of the following examples look more natural... >>> print(list(flatten(items, check=lambda o: isinstance(o, list)))) ['foo', 1, 2, (3, 4), 5, 6, (7,)] >>> print(list(flatten(items, check=lambda o: isinstance(o, (list, tuple))))) ['foo', 1, 2, 3, 4, 5, 6, 7] >>> print(list(flatten(items, check=lambda o: isinstance(o, (list, tuple)) or (isinstance(o, str) and len(o) > 1)))) ['f', 'o', 'o', 1, 2, 3, 4, 5, 6, 7] ... than the duck-typed variants because it doesn't matter for the problem of flattening whether an object can be sorted or not. But in a real-world application the "atoms" are more likely to have something in common that is required for the problem at hand, and the check for it with def check(obj): return not (obj is an atom) # pseudo-code may look more plausible. From phiwer at gmail.com Wed Jan 15 13:37:25 2014 From: phiwer at gmail.com (phiwer at gmail.com) Date: Wed, 15 Jan 2014 10:37:25 -0800 (PST) Subject: Python Scalability TCP Server + Background Game Message-ID: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> My problem is as follows: I'm developing an online game with the requirement of being able to handle thousands of requests every second. The frontend consists of web server(s) exposing a rest api. These web servers in turn communicate with a game server over TCP. When a message arrives at the game server, each client handler inserts the client message into a shared message queue, and then waits for the result from the game loop. When the game loop has informed the waiting handler that a result is ready, the handler returns the result to the client. Things to take note of: 1) The main game loop runs in a separate process, and the intention is to use a Queue from the multiprocess library. 2) The network layer of the game server runs a separate process as well, and my intention was to use gevent or tornado (http://nichol.as/asynchronous-servers-in-python). 3) The game server has a player limit of 50000. My requirement/desire is to be able to serve 50k requests per second (without any caching layer, although the game server will cache data), so people don't get a poor user experience during high peaks. 4) The game is not a real-time based game, but is catered towards the web. And now to my little problem. All high performance async TCP servers use greenlets (or similar light threads), but does not seem to be compatible with the multiprocess library. From what I've read, Python (largely due to GIL) does not seem suited for this type of task, compared to other languages where threading and IPC is not an issue. Due to this information, I have developed the initial server using netty in java. I would, however, rather develop the server using python, if possible. But if these limitations truly exist, then I'll go with java for the game server, and then use python for the frontend. Has anyone developed something similar, and if so, could you point me in the right direction, or perhaps I've missed something along the way? If one can solve the issue with IPC, it seems the high performance servers tested on this page, http://nichol.as/asynchronous-servers-in-python, only can handle roughly 8k requests per second before performance degrades. Does anyone know how Python high performance TCP servers compare to other language's TCP servers? Thanks for all replies! From eneskristo at gmail.com Wed Jan 15 15:16:56 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Wed, 15 Jan 2014 12:16:56 -0800 (PST) Subject: Bind event is giving me a bug. Message-ID: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> While working with tkinter in python 3.3, I had the following problem. def get_text(event): self.number_of_competitors = entered_text.get() try: self.number_of_competitors = int(self.number_of_competitors) except: pass if type(self.number_of_competitors) == int: root.destroy() else: label.config(text = "Enter the number of competitors. Please enter a number.") root = Tk() label = Label(root, text = "Enter the number of competitors.") label.pack(side = TOP) entered_text = Entry(root) entered_text.pack() Button(root, text = "Submit", command = get_text).pack() root.bind('', get_text) root.mainloop() This is a buggy part of the code. When I run it, instead of doing what it should do, it responds to all events BUT enter. I'm not sure if this error is on tkinters or my side. Please help! From wrw at mac.com Wed Jan 15 11:25:24 2014 From: wrw at mac.com (William Ray Wing) Date: Wed, 15 Jan 2014 11:25:24 -0500 Subject: Learning python networking In-Reply-To: References: <22d58d76-f2c2-4a1d-8049-3409ac4665d3@googlegroups.com> <9202d352-e065-4f2b-a9e0-e29ce5c68df6@googlegroups.com> Message-ID: <7B721FFF-5F01-4736-AC82-B5E71848F926@mac.com> On Jan 15, 2014, at 7:52 AM, Chris Angelico wrote: [megabyte] > One of the fundamentals of the internet is that connections *will* > break. A friend of mine introduced me to Magic: The Gathering via a > program that couldn't handle drop-outs, and it got extremely > frustrating - we couldn't get a game going. Build your server such > that your clients can disconnect and reconnect, and you protect > yourself against half the problem; allow them to connect and kick the > other connection off, and you solve the other half. (Sometimes, the > server won't know that the client has gone, so it helps to be able to > kick like that.) It might not be an issue when you're playing around > with localhost, and you could even get away with it on a LAN, but on > the internet, it's so much more friendly to your users to let them > connect multiple times like that. But note VERY carefully that this can open HUGE security holes if not done with extreme care. Leaving a dangling connection (not session, TCP closes sessions) open is an invitation so bad things happening. -Bill From __peter__ at web.de Wed Jan 15 15:59:05 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Jan 2014 21:59:05 +0100 Subject: Bind event is giving me a bug. References: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> Message-ID: eneskristo at gmail.com wrote: > While working with tkinter in python 3.3, I had the following problem. > root = Tk() > label = Label(root, text = "Enter the number of competitors.") > label.pack(side = TOP) > entered_text = Entry(root) > entered_text.pack() > Button(root, text = "Submit", command = get_text).pack() > root.bind('', get_text) Quoting http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/event-types.html """ Enter The user moved the mouse pointer into a visible part of a widget. (This is different than the enter key, which is a KeyPress event for a key whose name is actually 'return'.) """ So I think you want "", not "". > root.mainloop() > > This is a buggy part of the code. When I run it, instead of doing what it > should do, it responds to all events BUT enter. I'm not sure if this error > is on tkinters or my side. Please help! From rosuav at gmail.com Wed Jan 15 16:08:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 08:08:19 +1100 Subject: Python Scalability TCP Server + Background Game In-Reply-To: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> Message-ID: On Thu, Jan 16, 2014 at 5:37 AM, wrote: > 3) The game server has a player limit of 50000. My requirement/desire is to be able to serve 50k requests per second (without any caching layer, although the game server will cache data), so people don't get a poor user experience during high peaks. Quick smoke test. How big are your requests/responses? You mention REST, which implies they're going to be based on HTTP. I would expect you would have some idea of the rough size. Multiply that by 50,000, and see whether your connection can handle it. For instance, if you have a 100Mbit/s uplink, supporting 50K requests/sec means your requests and responses have to fit within about 256 bytes each, including all overhead. You'll need a gigabit uplink to be able to handle a 2KB request or response, and that's assuming perfect throughput. And is 2KB enough for you? ChrisA From python at mrabarnett.plus.com Wed Jan 15 16:10:42 2014 From: python at mrabarnett.plus.com (MRAB) Date: Wed, 15 Jan 2014 21:10:42 +0000 Subject: Bind event is giving me a bug. In-Reply-To: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> References: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> Message-ID: <52D6F952.2010309@mrabarnett.plus.com> On 2014-01-15 20:16, eneskristo at gmail.com wrote: > While working with tkinter in python 3.3, I had the following problem. > def get_text(event): > self.number_of_competitors = entered_text.get() > try: > self.number_of_competitors = int(self.number_of_competitors) A bare except like this is virtually never a good idea: > except: > pass > if type(self.number_of_competitors) == int: > root.destroy() > else: > label.config(text = "Enter the number of competitors. Please enter a number.") Something like this would be better: try: self.number_of_competitors = int(entered_text.get()) except ValueError: label.config(text="Enter the number of competitors. Please enter a number.") else: root.destroy() > root = Tk() > label = Label(root, text = "Enter the number of competitors.") > label.pack(side = TOP) > entered_text = Entry(root) > entered_text.pack() This will make it call 'get_text' when the button is clicked: > Button(root, text = "Submit", command = get_text).pack() This will make it call 'get_text' when the pointer enters the frame: > root.bind('', get_text) Did you mean '', i.e. the Return key? > root.mainloop() > > This is a buggy part of the code. When I run it, instead of doing what it should do, it responds to all events BUT enter. I'm not sure if this error is on tkinters or my side. Please help! > From eneskristo at gmail.com Wed Jan 15 16:19:26 2014 From: eneskristo at gmail.com (eneskristo at gmail.com) Date: Wed, 15 Jan 2014 13:19:26 -0800 (PST) Subject: Bind event is giving me a bug. In-Reply-To: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> References: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> Message-ID: Thank you, I thought Enter was Enter, but I still have this problem, when I press the Button, this appears: Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) TypeError: get_text() missing 1 required positional argument: 'event' Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) TypeError: get_text() missing 1 required positional argument: 'event' Should I make 2 functions, or is there a simpler solution? From __peter__ at web.de Wed Jan 15 16:25:31 2014 From: __peter__ at web.de (Peter Otten) Date: Wed, 15 Jan 2014 22:25:31 +0100 Subject: Bind event is giving me a bug. References: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> <52D6F952.2010309@mrabarnett.plus.com> Message-ID: MRAB wrote: > This will make it call 'get_text' when the button is clicked: > >> Button(root, text = "Submit", command = get_text).pack() ...and then produce a TypeError because of the missing `event` argument. To avoid that you can provide a default with def get_text(event=None): ... From cs at zip.com.au Wed Jan 15 16:42:42 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 16 Jan 2014 08:42:42 +1100 Subject: Chanelling Guido - dict subclasses In-Reply-To: <20140115050325.190b1509@bigbox.christie.dr> References: <20140115050325.190b1509@bigbox.christie.dr> Message-ID: <20140115214242.GA1218@cskk.homeip.net> On 15Jan2014 05:03, Tim Chase wrote: > On 2014-01-15 01:27, Steven D'Aprano wrote: > > class TextOnlyDict(dict): > > def __setitem__(self, key, value): > > if not isinstance(key, str): > > raise TypeError > > super().__setitem__(key, value) > > # need to override more methods too > > > > > > But reading Guido, I think he's saying that wouldn't be a good > > idea. I don't get it -- it's not a violation of the Liskov > > Substitution Principle, because it's more restrictive, not less. > > What am I missing? > > Just as an observation, this seems almost exactly what anydbm does, > behaving like a dict (whether it inherits from dict, or just > duck-types like a dict), but with the limitation that keys/values need > to be strings. I would expect anydbm to be duck typing: just implementing the mapping interface and directing the various methods directly to the DBM libraries. The comment in question was specificly about subclassing dict. There is a rule of thumb amongst the core devs and elder Python programmers that it is a bad idea to subclass the basic types which I have seen stated many times, but not explained in depth. Naively, I would have thought subclassing dict to constraint the key types for some special purpose seems like a fine idea. You'd need to override .update() as well and also the initialiser. Maybe it is harder than it seems. The other pitfall I can see is code that does an isinstance(.., dict) check for some reason; having discovered that it has a dict it may behave specially. Pickle? Who knows? Personally, if it is using isinstance instead of a direct type() check then I think it should expect to cope with subclasses. I've subclassed str() a number of times, most extensively as a URL object that is a str with a bunch of utility methods, and it seems to work well. I've subclassed dict a few times, most extensively as the in-memory representation of record in a multibackend data store which I use for a bunch of things. That is also working quite well. The benefit of subclassing dict is getting a heap of methods like iterkeys et al for free. A from-scratch mapping has a surprising number of methods involved. Cheers, -- Cameron Simpson BTW, don't bother flaming me. I can't read. - afdenis at lims03.lerc.nasa.gov (Stephen Dennison) From tjreedy at udel.edu Wed Jan 15 17:24:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Jan 2014 17:24:32 -0500 Subject: proposal: bring nonlocal to py2.x In-Reply-To: <52D679FD.3060406@chamonix.reportlab.co.uk> References: <52D679FD.3060406@chamonix.reportlab.co.uk> Message-ID: On 1/15/2014 7:07 AM, Robin Becker wrote: > On 13/01/2014 15:28, Chris Angelico wrote: > .......... >> >> It's even worse than that, because adding 'nonlocal' is not a bugfix. >> So to be committed to the repo, it has to be approved for either 2.7 >> branch (which is in bugfix-only maintenance mode) or 2.8 branch (which >> does not exist). Good luck. :) > ....... > fixing badly named variables is not a bug fix either, but that has > happened in python 2.7. A micro change release changed > > compiler.consts.SC_GLOBAL_EXPLICT > to > compiler.consts.SC_GLOBAL_EXPLICIT > > this is a change of api for the consts module (if you regard exported > variables as part of its api), A bug is generally a discrepancy between the doc the defines a version of the language and the code that implements that version. Yes, code fixes break code that depends on the bug, which is why tests should be run with bug-fix releases, and why some bug fixes are treated as enhancements and not back-ported. They also fix current and future code written to the specification. Since the compiler.consts submodule is not documented, I believe it was regarded as an internal module for use only by the pycodegen and symbols modules. The misspelling was introduced in the patch for http://bugs.python.org/issue999042 which also introduced SC_GLOBAL_IMPLICIT, correctly spelled. EXPLICT was fixed in all three modules by Antoine Pitrou in http://bugs.python.org/issue15212 In any case, I estimate the impact of backporting a major new feature like a new keyword to be at least 100000 times that of this spelling fix. > but that didn't count for the developers. If you are suggesting that developers casually violate out policy of only bug fixes in microreleases, that is unfair and false. It is mostly users who push at us to backport their favorite new feature. Antoine strongly supports and enforces the policy, as do I. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 15 17:58:05 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Jan 2014 17:58:05 -0500 Subject: Python declarative In-Reply-To: References: <1389805328.32401.6.camel@linux-fetk.site> Message-ID: On 1/15/2014 12:33 PM, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 4:02 AM, Sergio Tortosa Benedito > wrote: >> Hi I'm developing a sort of language extension for writing GUI programs >> called guilang, right now it's written in Lua but I'm considreing Python >> instead (because it's more tailored to alone applications). My question >> it's if I can achieve this declarative-thing in python. Here's an >> example: >> >> Window "myWindow" { >> title="Hello world"; >> Button "myButton" { >> label="I'm a button"; >> onClick=exit >> } >> } >> print(myWindow.myButton.label) > > Probably the easiest way to do that would be with dictionaries or > function named arguments. It'd be something like this: > > myWindow = Window( > title="Hello World", > myButton=Button( > label="I'm a button", > onClick=exit > ) > ) > print(myWindow.myButton.label) This is exactly what I was going to suggest. > For this to work, you'd need a Window class that recognizes a number > of keyword arguments (eg for title and other attributes), and then > takes all other keyword arguments and turns them into its children. I would make the required args positional-or-keyword, with or without a default. Something like (tested) class Window: def __init__(self, title, *kwds) # or title='Window title' self.title = title self.__dict__.update(kwds) class Button: def __init__(self, label, **kwds): self.label = label self.__dict__.update(kwds) >>> I'm a button > Possible, but potentially messy; if you happen to name your button > "icon", it might be misinterpreted as an attempt to set the window's > icon, and cause a very strange and incomprehensible error. Puns are always a problem with such interfaces. Validate the args as much as possible. An icon should be a bitmap of appropriate size. Optional args should perhaps all be widgets (instances of a Widget baseclass). -- Terry Jan Reedy From rosuav at gmail.com Wed Jan 15 18:09:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 10:09:47 +1100 Subject: Python declarative In-Reply-To: References: <1389805328.32401.6.camel@linux-fetk.site> Message-ID: On Thu, Jan 16, 2014 at 9:58 AM, Terry Reedy wrote: > class Window: > def __init__(self, title, *kwds) # or title='Window title' > self.title = title > self.__dict__.update(kwds) Does that want a second asterisk, matching the Button definition? >> Possible, but potentially messy; if you happen to name your button >> "icon", it might be misinterpreted as an attempt to set the window's >> icon, and cause a very strange and incomprehensible error. > > Puns are always a problem with such interfaces. Validate the args as much as > possible. An icon should be a bitmap of appropriate size. Optional args > should perhaps all be widgets (instances of a Widget baseclass). Yeah, but you'd still get back an error saying "icon should be a bitmap" where the real problem is "icon should be called something else". It might be worth explicitly adorning properties, or separating them into two categories. Since the keyword-named-children system has the other problem of being hard to lay out (how do you specify the order?), I'd look at keyword args for properties and something separate for children - either the layout I used above with .add(), which allows extra args as necessary, or something like this: myWindow = Window( title="Hello World", children=[Button( label="I'm a button", onClick=exit )] ) Or maybe allow "child=" as a shortcut, since a lot of widgets will have exactly one child. ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 15 19:02:42 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 00:02:42 GMT Subject: Question about object lifetime and access References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> Message-ID: <52d721a1$0$29970$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jan 2014 05:14:59 -0800, Asaf Las wrote: > I have read somewhere that global objects are referenced from module > namespace will never have reference count down to 0 even if they are not > referenced from functions or class methods. Is this true? Correct. The global name is a reference, so the reference count will be at least 1. In fact, referencing the name from a function or method doesn't increase the ref count: instance = 123.456789 # ref count of float is 1 def test(): print(instance) # This refers to the *name* "instance", not the float So the test() function cannot keep the float alive. If you reassign global instance, test() will see the new value, not the old, and 123.456789 is free to be garbage collected. This sounds more complicated than it actually is. In practice it works exactly as you expect global variables to work: py> test() 123.456789 py> instance = 98765.4321 py> test() 98765.4321 > Does it mean > that global objects are destroyed when interpreter exits or thread where > it runs is terminated? Certainly not! Global objects are no different from any other object. They are destroyed when their reference count falls to zero. In the case of global objects, that is *often* not until the interpreter exits, but it can be before hand. So long as the object is in use, it will be kept. When it is no longer in use, the garbage collector is free to destroy it. So long as *some* object or name holds a reference to it, it is considered to be in use. value = instance = 1.23456 # ref count 2 alist = [1, 2, 3, 4, 5, value] # ref count now 3 mydict = {"Key": alist} # ref count now 4 value = 42 # rebind a name, ref count of float now 3 mydict.clear() # ref count now 2 del instance # delete the name, ref count now 1 assert alist[5] == 1.23456 alist[5] = 0 # final reference gone, ref count is now 0 At this point the global object 1.23456 is free to be destroyed. (Note: some Python implementations don't do reference counting, e.g. Jython and IronPython use the Java and .Net garbage collectors respectively. In their case, the same rule applies: where there are no longer any references to an object, it will be garbage collected. The only difference is in how soon that occurs: in CPython, it will be immediate, in Jython or IronPython it will occur when the garbage collector runs.) -- Steven From tjreedy at udel.edu Wed Jan 15 19:27:35 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Jan 2014 19:27:35 -0500 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: <52D6BD83.9000804@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <52D68402.6030407@chamonix.reportlab.co.uk> <570A55FE-6640-4480-BF9A-3C2F8B9C1DC5@gmail.com> <52D6BD83.9000804@chamonix.reportlab.co.uk> Message-ID: On 1/15/2014 11:55 AM, Robin Becker wrote: > The fact that unicoders want to take over the meaning of encoding is not > relevant. I agree with you that 'encoding' should not be limited to 'byte encoding of a (subset of) unicode characters. For instance, .jpg and .png are byte encodings of images. In the other hand, it is common in human discourse to omit qualifiers in particular contexts. 'Computer virus' gets condensed to 'virus' in computer contexts. The problem with graphemes is that there is no fixed set of unicode graphemes. Which is to say, the effective set of graphemes is context-specific. Just limiting ourselves to English, 'fi' is usually 2 graphemes when printing to screen, but often just one when printing to paper. This is why the Unicode consortium punted 'graphemes' to 'application' code. > I'm not anti unicode, that's just an assignment of identity to some > symbols. Coding the values of the ids is a separate issue. It's my > belief that we don't need more than the byte level encoding to represent > unicode. One of the claims made for python3 unicode is that it somehow > eliminates the problems associated with other encodings eg utf8, The claim is true for the following problems of the way-too-numerous unicode byte encodings. Subseting: only a subset of characters can be encoded. Shifting: the meaning of a byte depends on a preceding shift character, which might be back as the beginning of the sequence. Varying size: the number of bytes to encode a character depends on the character. Both of the last two problems can turn O(1) operations into O(n) operations. 3.3+ eliminates all these problems. -- Terry Jan Reedy From steve+comp.lang.python at pearwood.info Wed Jan 15 19:32:25 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 00:32:25 GMT Subject: =?iso-8859-1?q?'Stra=DFe'?= ('Strasse') and Python 2 References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> Message-ID: <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 02:14:38 +1100, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 1:55 AM, wrote: >> Le mercredi 15 janvier 2014 13:13:36 UTC+1, Ned Batchelder a ?crit : >> >> >>> ... more than one codepoint makes up a grapheme ... >> >> No > > Yes. > http://www.unicode.org/faq/char_combmark.html > >>> In Unicode terms, an encoding is a mapping between codepoints and >>> bytes. >> >> No > > Yes. > http://www.unicode.org/reports/tr17/ > Specifically: > "Character Encoding Form: a mapping from a set of nonnegative integers > that are elements of a CCS to a set of sequences of particular code > units of some specified width, such as 32-bit integers" Technically Unicode talks about mapping code points and code *units*, but since code units are defined in terms of bytes, I think it is fair to cut out one layer of indirection and talk about mapping code points to bytes. For instance, UTF-32 uses 4-byte code units, and every code point U+0000 through U+10FFFF is mapped to a single code unit, which is always a four- byte quantity. UTF-8, on the other hand, uses single-byte code units, and maps code points to a variable number of code units, so UTF-8 maps code points to either 1, 2, 3 or 4 bytes. > Or are you saying that www.unicode.org is wrong about the definitions of > Unicode terms? No, I think he is saying that he doesn't know Unicode anywhere near as well as he thinks he does. The question is, will he cherish his ignorance, or learn from this thread? -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 15 19:38:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 00:38:21 GMT Subject: python-list@python.org References: <11036720.dCfMmLrdqv@horus> <52D56D40.1060401@mrabarnett.plus.com> Message-ID: <52d729fd$0$29970$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jan 2014 02:25:34 +0100, Florian Lindner wrote: > Am Dienstag, 14. Januar 2014, 17:00:48 schrieb MRAB: >> On 2014-01-14 16:37, Florian Lindner wrote: >> > Hello! >> > >> > I'm using python 3.2.3 on debian wheezy. My script is called from my >> > mail delivery agent (MDA) maildrop (like procmail) through it's >> > xfilter directive. >> > >> > Script works fine when used interactively, e.g. ./script.py < >> > testmail but when called from maildrop it's producing an infamous >> > UnicodeDecodeError: What's maildrop? When using third party libraries, it's often helpful to point to give some detail on what they are and where they are from. >> > File "/home/flindner/flofify.py", line 171, in main >> > mail = sys.stdin.read() What's the value of sys.stdin? If you call this from your script: print(sys.stdin) what do you get? Is it possible that the mysterious maildrop is messing stdin up? >> > File "/usr/lib/python3.2/encodings/ascii.py", line 26, in decode >> > return codecs.ascii_decode(input, self.errors)[0] >> > >> > Exception for example is always like >> > >> > UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position >> > 869: ordinal not in range(128) That makes perfect sense: byte 0x82 is not in the ASCII range. ASCII is limited to bytes values 0 through 127, and 0x82 is hex for 130. So the error message is telling you *exactly* what the problem is: your email contains a non-ASCII character, with byte value 0x82. How can you deal with this? (1) "Oh gods, I can't deal with this, I wish the whole world was America in 1965 (except even back then, there were English characters in common use that can't be represented in ASCII)! I'm going to just drop anything that isn't ASCII and hope it doesn't mangle the message *too* badly!" You need to set the error handler to 'ignore'. How you do that may depend on whether or not maildrop is monkeypatching stdin. (2) "Likewise, but instead of dropping the offending bytes, I'll replace them with something that makes it obvious that an error has occurred." Set the error handler to "replace". You'll still mangle the email, but it will be more obvious that you mangled it. (3) "ASCII? Why am I trying to read email as ASCII? That's not right. Email can contain arbitrary bytes, and is not limited to pure ASCII. I need to work out which encoding the email is using, but even that is not enough, since emails sometimes contain the wrong encoding information or invalid bytes. Especially spam, that's particularly poor. (What a surprise, that spammers don't bother to spend the time to get their code right?) Hmmm... maybe I ought to use an email library that actually gets these issues *right*?" What does the maildrop documentation say about encodings and/or malformed email? >> > I read mail from stdin "mail = sys.stdin.read()" >> > >> > Environment when called is: >> > >> > locale.getpreferredencoding(): ANSI_X3.4-1968 environ["LANG"]: C For a modern Linux system to be using the C encoding is not a good sign. It's not 1970 anymore. I would expect it should be using UTF-8. But I don't think that's relevant to your problem (although a mis-configured system may make it worse). >> > System environment when using shell is: >> > >> > ~ % echo $LANG >> > en_US.UTF-8 That's looking more promising. >> > As far as I know when reading from stdin I don't need an decode(...) >> > call, since stdin has a decoding. That depends on what stdin actually is. Please print it and show us. Also, can you do a visual inspection of the email that is failing? If it's spam, perhaps you can just drop it from the queue and deal with this issue later. >> > I also tried some decoding/encoding >> > stuff but changed nothing. Ah, but did you try the right stuff? (Randomly perturbing your code in the hope that the error will go away is not a winning strategy.) >> > Any ideas to help me? >> > >> When run from maildrop it thinks that the encoding of stdin is ASCII. > > Well, true. But what encoding does maildrop actually gives me? It > obviously does not inherit LANG or is called from the MTA that way. Who knows? What's maildrop? What does its documentation say about encodings? The fact that it is using ASCII apparently by default does not give me confidence that it knows how to deal with 8-bit emails, but I might be completely wrong. > I also tried: > > inData = codecs.getreader('utf-8')(sys.stdin) > mail = inData.read() > > Failed also. But I'm not exactly an encoding expert. Failed how? Please copy and paste your exact exception traceback, in full. Ultimately, dealing with email is a hard problem. So long as you only receive 7-bit ASCII mail, you don't realise how hard it is. But the people who write the mail libraries -- at least the good ones -- know just how hard it really is. You can have 8-bit emails with no encoding set, or the wrong encoding, or the right encoding but the contents then includes invalid bytes. It's not just spammers who get it wrong, legitimate programmers sending email also screw up. Email is worse than the 90/10 rule. 90% of the effort is needed to deal with 1% of the emails. (More if you have a really bad spam problem.) You should look at a good email library, like the one in the std lib which I believe gets most of these issues right. -- Steven From steve+comp.lang.python at pearwood.info Wed Jan 15 19:43:21 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 00:43:21 GMT Subject: =?iso-8859-1?q?'Stra=DFe'?= ('Strasse') and Python 2 References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> Message-ID: <52d72b29$0$29970$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jan 2014 12:00:51 +0000, Robin Becker wrote: > so two 'characters' are 3 (or 2 or more) codepoints. Yes. > If I want to isolate so called graphemes I need an algorithm even > for python's unicode Correct. Graphemes are language dependent, e.g. in Dutch "ij" is usually a single grapheme, in English it would be counted as two. Likewise, in Czech, "ch" is a single grapheme. The Latin form of Serbo-Croation has two two-letter graphemes, D? and Nj (it used to have three, but Dj is now written as ?). Worse, linguists sometimes disagree as to what counts as a grapheme. For instance, some authorities consider the English "sh" to be a separate grapheme. As a native English speaker, I'm not sure about that. Certainly it isn't a separate letter of the alphabet, but on the other hand I can't think of any words containing "sh" that should be considered as two graphemes "s" followed by "h". Wait, no, that's not true... compound words such as "glasshouse" or "disheartened" are counter examples. > ie when it really matters, python3 str is just another encoding. I'm not entirely sure how a programming language data type (str) can be considered a transformation. -- Steven From python.list at tim.thechases.com Wed Jan 15 19:48:39 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 15 Jan 2014 18:48:39 -0600 Subject: Python declarative In-Reply-To: References: <1389805328.32401.6.camel@linux-fetk.site> Message-ID: <20140115184839.0a35a9ae@bigbox.christie.dr> On 2014-01-16 10:09, Chris Angelico wrote: > myWindow = Window( > title="Hello World", > children=[Button( > label="I'm a button", > onClick=exit > )] > ) This also solves the problem that **kwargs are just a dict, which is inherently unordered. So with the previous scheme, you'd just get an unordered bag of controls that Python could then dump into your containing window as its dict-traversal algorithms saw fit. :-) -tkc From ben+python at benfinney.id.au Wed Jan 15 19:52:41 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Jan 2014 11:52:41 +1100 Subject: python-list@python.org References: <11036720.dCfMmLrdqv@horus> <52D56D40.1060401@mrabarnett.plus.com> <52d729fd$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7wvbxkbvdy.fsf@benfinney.id.au> Steven D'Aprano writes: > On Wed, 15 Jan 2014 02:25:34 +0100, Florian Lindner wrote: > >> On 2014-01-14 16:37, Florian Lindner wrote: > >> > I'm using python 3.2.3 on debian wheezy. My script is called from > >> > my mail delivery agent (MDA) maildrop (like procmail) through > >> > it's xfilter directive. > >> > > >> > Script works fine when used interactively, e.g. ./script.py < > >> > testmail but when called from maildrop it's producing an infamous > >> > UnicodeDecodeError: > > What's maildrop? When using third party libraries, it's often helpful to > point to give some detail on what they are and where they are from. It's not a library; as he says, it's an MDA program. It is from the Courier mail application . >From that, I understand Florian to be saying his Python program is invoked via command-line from some configuration directive for Maildrop. > What does the maildrop documentation say about encodings and/or > malformed email? I think this is the more likely line of enquiry to diagnose the problem. > For a modern Linux system to be using the C encoding is not a good > sign. That's true, but it's likely a configuration problem: the encoding needs to be set *and* obeyed at an administrative and user-profile level. > It's not 1970 anymore. I would expect it should be using UTF-8. But I > don't think that's relevant to your problem (although a mis-configured > system may make it worse). Since the MDA runs usually not as a system service, but rather at a user-specific level, I would expect some interaction of the host locale and the user-specific locale is the problem. > Who knows? What's maildrop? What does its documentation say about > encodings? I hope the original poster enjoys manpages, since that's how the program is documented . > The fact that it is using ASCII apparently by default does not give me > confidence that it knows how to deal with 8-bit emails, but I might be > completely wrong. I've found that the problem is often that Python is the party assuming that stdin and stdout are ASCII, largely because it hasn't been told otherwise. -- \ ?The greatest tragedy in mankind's entire history may be the | `\ hijacking of morality by religion.? ?Arthur C. Clarke, 1991 | _o__) | Ben Finney From rmorgan466 at gmail.com Wed Jan 15 20:09:40 2014 From: rmorgan466 at gmail.com (Rita) Date: Wed, 15 Jan 2014 20:09:40 -0500 Subject: data validation when creating an object Message-ID: I would like to do some data validation when its going to a class. class Foo(object): def __init__(self): pass I know its frowned upon to do work in the __init__() method and only declarations should be there. So, should i create a function called validateData(self) inside foo? I would call the object like this x=Foo() x.validateData() Is this the preferred way? Is there a way I can run validateData() automatically, maybe put it in __init__? Or are there other techniques people use for this sort of thing? -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Wed Jan 15 20:16:19 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Jan 2014 12:16:19 +1100 Subject: data validation when creating an object References: Message-ID: <7wr488buak.fsf@benfinney.id.au> Rita writes: > I would like to do some data validation when its going to a class. > > class Foo(object): > def __init__(self): > pass > > I know its frowned upon to do work in the __init__() method and only > declarations should be there. Who says it's frowned on to do work in the initialiser? Where are they saying it? That seems over-broad, I'd like to read the context of that advice. > So, should i create a function called validateData(self) inside foo? If you're going to create it, ?validate_data? would be a better name (because it's PEP 8 conformant). > I would call the object like this > > x=Foo() > x.validateData() You should also be surrounding the ?=? operator with spaces (PEP 8 again) for readability. > Is this the preferred way? Is there a way I can run validateData() > automatically, maybe put it in __init__? It depends entirely on what is being done in those functions. But in general, we tend not to write our functions small enough or focussed enough. So general advice would be that, if you think the function is going to be too long and/or doing too much, you're probably right :-) -- \ ?Nature hath given men one tongue but two ears, that we may | `\ hear from others twice as much as we speak.? ?Epictetus, | _o__) _Fragments_ | Ben Finney From cs at zip.com.au Wed Jan 15 20:25:42 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 16 Jan 2014 12:25:42 +1100 Subject: data validation when creating an object In-Reply-To: References: Message-ID: <20140116012542.GA5065@cskk.homeip.net> On 15Jan2014 20:09, Rita wrote: > I would like to do some data validation when its going to a class. > > class Foo(object): > def __init__(self): > pass > > I know its frowned upon to do work in the __init__() method and only > declarations should be there. This rule of thumb does not mean "do nothing". It may be perfetly vaid to open file or database connections in __init__, etc, depending on what the object is for. The post condition of __init__ is that the object is appropriately initialised. The definition of appropriate depends on you. Data validation is very much an appropriate thing to do in __init__. If it highly recommended to validate your inputs if that is feasible and easy at __init__ time. It is far better to get a ValueError exception (the usual exception for invalid values, which an invalid initialiser certainly is) at object creation time than at some less convenient time later during use. > So, should i create a function called validateData(self) inside foo? It might be a good idea to make a (probably private) method to check for validity and/or integrity, eg: def _is_valid(self): ... checks here, return True if ok ... because that would allow you to call this at arbitrary other times if you need to debug. However, I would also have obvious validity checks in __init__ itself on the supplied values. Eg: def __init__(self, size, lifetime): if size < 1: raise ValueError("size must be >= 1, received: %r" % (size,)) if lifetime <= 0: raise ValueError("lifetime must be > 0, received: %r" % (lifetime,)) Trivial, fast. Fails early. Note that the exception reports the receive value; very handy for simple errors like passing utterly the wrong thing (eg a filename when you wanted a counter, or something like that). Certainly also put a test of self._is_valid() at the bottom of __init__, at least during the debug phase. Provided _is_valid() is cheap and fast. For example, it would be appropriate to check that a filename was a string. It would probably (your call) be inappropriate to open the file or checksum its contents etc etc. Cheers, -- Cameron Simpson I distrust a research person who is always obviously busy on a task. - Robert Frosch, VP, GM Research From rosuav at gmail.com Wed Jan 15 20:26:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 12:26:20 +1100 Subject: =?UTF-8?B?UmU6ICdTdHJhw59lJyAoJ1N0cmFzc2UnKSBhbmQgUHl0aG9uIDI=?= In-Reply-To: <52d72b29$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52d72b29$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 16, 2014 at 11:43 AM, Steven D'Aprano wrote: > Worse, linguists sometimes disagree as to what counts as a grapheme. For > instance, some authorities consider the English "sh" to be a separate > grapheme. As a native English speaker, I'm not sure about that. Certainly > it isn't a separate letter of the alphabet, but on the other hand I can't > think of any words containing "sh" that should be considered as two > graphemes "s" followed by "h". Wait, no, that's not true... compound > words such as "glasshouse" or "disheartened" are counter examples. Digression: When I was taught basic English during my school days, my mum used Spalding's book and the 70 phonograms. 25 of them are single letters (Q is not a phonogram - QU is), and the others are mostly pairs (there are a handful of 3- and 4-letter phonograms). Not every instance of "s" followed by "h" is the phonogram "sh" - only the times when it makes the single sound "sh" (which it doesn't in "glasshouse" or "disheartened"). Thing is, you can't define spelling and pronunciation in terms of each other, because you'll always be bitten by corner cases. Everyone knows how "Thames" is pronounced... right? Well, no. There are (at least) two rivers of that name, the famous one in London p1[ and another one further north [2]. The obscure one is pronounced the way the word looks, the famous one isn't. And don't even get started on English family names... Majorinbanks, Meux and Cholmodeley, as lampshaded [3] in this song [4]! Even without names, though, there are the tricky cases and the ones where different localities pronounce the same word very differently; Unicode shouldn't have to deal with that by changing whether something's a single character or two. Considering that phonograms aren't even ligatures (though there is overlap, eg "Th"), it's much cleaner to leave them as multiple characters. ChrisA [1] https://en.wikipedia.org/wiki/River_Thames [2] Though it's better known as the Isis. https://en.wikipedia.org/wiki/The_Isis [3] http://tvtropes.org/pmwiki/pmwiki.php/Main/LampshadeHanging [4] http://www.stagebeauty.net/plays/th-arca2.html - "Mosh-banks", "Mow", and "Chumley" are the pronunciations used From breamoreboy at yahoo.co.uk Wed Jan 15 20:26:54 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 16 Jan 2014 01:26:54 +0000 Subject: data validation when creating an object In-Reply-To: References: Message-ID: On 16/01/2014 01:09, Rita wrote: > I would like to do some data validation when its going to a class. > > class Foo(object): > def __init__(self): > pass > > I know its frowned upon to do work in the __init__() method and only > declarations should be there. In the 10+ years that I've been using Python I don't ever recall seeing this, could we have a reference please. > > So, should i create a function called validateData(self) inside foo? > > I would call the object like this > > x=Foo() > x.validateData() > > Is this the preferred way? Is there a way I can run validateData() > automatically, maybe put it in __init__? Or are there other techniques > people use for this sort of thing? > > > -- > --- Get your facts first, then you can distort them as you please.-- > > -- 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 Wed Jan 15 20:38:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 12:38:51 +1100 Subject: Python declarative In-Reply-To: <20140115184839.0a35a9ae@bigbox.christie.dr> References: <1389805328.32401.6.camel@linux-fetk.site> <20140115184839.0a35a9ae@bigbox.christie.dr> Message-ID: On Thu, Jan 16, 2014 at 11:48 AM, Tim Chase wrote: > On 2014-01-16 10:09, Chris Angelico wrote: >> myWindow = Window( >> title="Hello World", >> children=[Button( >> label="I'm a button", >> onClick=exit >> )] >> ) > > This also solves the problem that **kwargs are just a dict, which is > inherently unordered. So with the previous scheme, you'd just get an > unordered bag of controls that Python could then dump into your > containing window as its dict-traversal algorithms saw fit. :-) Yeah, I don't really want my window layout to randomize every Python startup :) Actually... I'm really REALLY glad code like the previous version wasn't prevalent. It would have made for intense opposition to hash randomization - as I recall, the strongest voice against randomization was that tests would start to fail (IMO, a simple way to print a dictionary with its keys sorted would both solve that and provide an aesthetically-pleasing display). Imagine if someone spent hours crafting child object names in order to force the children to be added in the right order, and then along comes the new Python and it's all broken... But I still think it should be a method (as it is in GTK, not familiar enough with the others), as there's no way with the parameter system to (a) add children after object creation, or (b) specify parameters (GTK's boxes let you choose, per-child, whether they'll be expanded to fill any spare space - by default they all will, ie spare room is split between them, but often you want to choose one to be expanded and another not). PyGTK is mostly there, but since its .add() method returns None, chaining isn't possible. Method chaining like that is somewhat controversial... I would love to have some kind of syntax that says "and the value of this expression is the bit before the dot", but I have no idea what would be clean. ChrisA From tjreedy at udel.edu Wed Jan 15 20:44:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Jan 2014 20:44:32 -0500 Subject: Bind event is giving me a bug. In-Reply-To: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> References: <803c85f0-2f0f-4fc9-b043-710a77648546@googlegroups.com> Message-ID: On 1/15/2014 3:16 PM, eneskristo at gmail.com wrote: > While working with tkinter in python 3.3, I had the following problem. Please paste working code that people can experiment with. from tkinter import * > def get_text(event): If this were a method, (which the indent of the body suggests it once was) it would have to have a 'self' parameter, and you would have to bind a bound method. > self.number_of_competitors = entered_text.get() Since it is just a function, and has no 'self' parameter, this raises NameError. I condensed the function to try: int(entered_text.get()) root.destroy() except ValueError: label.config(text = "Enter the number of competitors. Please enter a number.") > try: > self.number_of_competitors = int(self.number_of_competitors) > except: Bare excepts are bad. > pass > if type(self.number_of_competitors) == int: > root.destroy() > else: > label.config(text = "Enter the number of competitors. Please enter a number.") > root = Tk() > label = Label(root, text = "Enter the number of competitors.") > label.pack(side = TOP) > entered_text = Entry(root) Since Entry only allows one line, I would have thought that it should take a command=func option invoked by \n. Instead, it seems to swallow newlines. > entered_text.pack() > Button(root, text = "Submit", command = get_text).pack() As near as I can tell, the Button button-press event in *not* bound to get_text but to a fixed event handler that calls get_text *without* an argument. > root.bind('', get_text) This does bind to an event so that it does call with an event arg. I just removed this and the window acts as it should. Since get_event ignores event, event=None should make it work either way. However, when I try that, the window disappears without being touched, as if \n is randomly generated internally. So I would say to skip this until you know more than I do. > root.mainloop() > > This is a buggy part of the code. When I run it, instead of doing what it should do, it responds to all events BUT enter. I'm not sure if this error is on tkinters or my side. Please help! -- Terry Jan Reedy From rosuav at gmail.com Wed Jan 15 20:46:52 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 12:46:52 +1100 Subject: data validation when creating an object In-Reply-To: <20140116012542.GA5065@cskk.homeip.net> References: <20140116012542.GA5065@cskk.homeip.net> Message-ID: On Thu, Jan 16, 2014 at 12:25 PM, Cameron Simpson wrote: > However, I would also have obvious validity checks in __init__ > itself on the supplied values. Eg: > > def __init__(self, size, lifetime): > if size < 1: > raise ValueError("size must be >= 1, received: %r" % (size,)) > if lifetime <= 0: > raise ValueError("lifetime must be > 0, received: %r" % (lifetime,)) > > Trivial, fast. Fails early. Note that the exception reports the > receive value; very handy for simple errors like passing utterly > the wrong thing (eg a filename when you wanted a counter, or something > like that). With code like this, passing a filename as the size will raise TypeError on Py3: >>> size = "test.txt" >>> size < 1 Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: str() < int() Yet another advantage of Py3 :) ChrisA From steve+comp.lang.python at pearwood.info Wed Jan 15 21:13:55 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 02:13:55 GMT Subject: Guessing the encoding from a BOM Message-ID: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> I have a function which guesses the likely encoding used by text files by reading the BOM (byte order mark) at the beginning of the file. A simplified version: def guess_encoding_from_bom(filename, default): with open(filename, 'rb') as f: sig = f.read(4) if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): return 'utf_16' elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): return 'utf_32' else: return default The idea is that you can call the function with a file name and a default encoding to return if one can't be guessed. I want to provide a default value for the default argument (a default default), but one which will unconditionally fail if you blindly go ahead and use it. E.g. I want to either provide a default: enc = guess_encoding_from_bom("filename", 'latin1') f = open("filename", encoding=enc) or I want to write: enc = guess_encoding_from_bom("filename") if enc == something: # Can't guess, fall back on an alternative strategy ... else: f = open("filename", encoding=enc) If I forget to check the returned result, I should get an explicit failure as soon as I try to use it, rather than silently returning the wrong results. What should I return as the default default? I have four possibilities: (1) 'undefined', which is an standard encoding guaranteed to raise an exception when used; (2) 'unknown', which best describes the result, and currently there is no encoding with that name; (3) None, which is not the name of an encoding; or (4) Don't return anything, but raise an exception. (But which exception?) Apart from option (4), here are the exceptions you get from blindly using options (1) through (3): py> 'abc'.encode('undefined') Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.3/encodings/undefined.py", line 19, in encode raise UnicodeError("undefined encoding") UnicodeError: undefined encoding py> 'abc'.encode('unknown') Traceback (most recent call last): File "", line 1, in LookupError: unknown encoding: unknown py> 'abc'.encode(None) Traceback (most recent call last): File "", line 1, in TypeError: encode() argument 1 must be str, not None At the moment, I'm leaning towards option (1). Thoughts? -- Steven From var.mail.daniel at gmail.com Wed Jan 15 19:50:53 2014 From: var.mail.daniel at gmail.com (Daniel da Silva) Date: Wed, 15 Jan 2014 19:50:53 -0500 Subject: Chanelling Guido - dict subclasses In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, Jan 14, 2014 at 8:27 PM, Steven D'Aprano < steve+comp.lang.python at pearwood.info> wrote: > > But reading Guido, I think he's saying that wouldn't be a good idea. I > don't get it -- it's not a violation of the Liskov Substitution > Principle, because it's more restrictive, not less. What am I missing? > Just to be pedantic, this *is* a violation of the Liskov Substution Principle. According to Wikipedia, the principle states: if S is a subtype of T, then > objects of type T may be replaced > with objects of type S (i.e., objects of type S may be *substituted* for > objects of type T) without altering any of the desirable properties of that > program (correctness, task performed, etc.) [0] Since S (TextOnlyDict) is more restrictive, it cannot be replaced for T (dict) because the program may be using non-string keys. Daniel -------------- next part -------------- An HTML attachment was scrubbed... URL: From rmorgan466 at gmail.com Wed Jan 15 22:01:19 2014 From: rmorgan466 at gmail.com (Rita) Date: Wed, 15 Jan 2014 22:01:19 -0500 Subject: data validation when creating an object In-Reply-To: References: <20140116012542.GA5065@cskk.homeip.net> Message-ID: Unfortunately, I couldn't find the reference but I know I read it somewhere. Even with a selective search I wasn't able to find it. I think I read it in context of module/class test case writing. I will keep your responses in mind therefore I will put logic in __init__ for data validation. thanks again for the responses. On Wed, Jan 15, 2014 at 8:46 PM, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 12:25 PM, Cameron Simpson wrote: > > However, I would also have obvious validity checks in __init__ > > itself on the supplied values. Eg: > > > > def __init__(self, size, lifetime): > > if size < 1: > > raise ValueError("size must be >= 1, received: %r" % (size,)) > > if lifetime <= 0: > > raise ValueError("lifetime must be > 0, received: %r" % > (lifetime,)) > > > > Trivial, fast. Fails early. Note that the exception reports the > > receive value; very handy for simple errors like passing utterly > > the wrong thing (eg a filename when you wanted a counter, or something > > like that). > > With code like this, passing a filename as the size will raise TypeError > on Py3: > > >>> size = "test.txt" > >>> size < 1 > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: str() < int() > > Yet another advantage of Py3 :) > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Wed Jan 15 22:35:43 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Jan 2014 22:35:43 -0500 Subject: Python declarative In-Reply-To: References: <1389805328.32401.6.camel@linux-fetk.site> Message-ID: On 1/15/2014 6:09 PM, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 9:58 AM, Terry Reedy wrote: >> class Window: >> def __init__(self, title, *kwds) # or title='Window title' >> self.title = title >> self.__dict__.update(kwds) > > Does that want a second asterisk, matching the Button definition? I must have changed to **kwds after copying. > >>> Possible, but potentially messy; if you happen to name your button >>> "icon", it might be misinterpreted as an attempt to set the window's >>> icon, and cause a very strange and incomprehensible error. >> >> Puns are always a problem with such interfaces. Validate the args as much as >> possible. An icon should be a bitmap of appropriate size. Optional args >> should perhaps all be widgets (instances of a Widget baseclass). > > Yeah, but you'd still get back an error saying "icon should be a > bitmap" where the real problem is "icon should be called something > else". One could say so in the message InterfaceError("The icon object must be a bitmap or else the non-bitmap object should be called something else.) > It might be worth explicitly adorning properties, or separating > them into two categories. Since the keyword-named-children system has > the other problem of being hard to lay out (how do you specify the > order?), I'd look at keyword args for properties and something > separate for children - either the layout I used above with .add(), > which allows extra args as necessary, or something like this: > > myWindow = Window( > title="Hello World", > children=[Button( > label="I'm a button", > onClick=exit > )] > ) > Or maybe allow "child=" as a shortcut, since a lot of widgets will > have exactly one child. -- Terry Jan Reedy From tjreedy at udel.edu Wed Jan 15 22:46:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 15 Jan 2014 22:46:45 -0500 Subject: data validation when creating an object In-Reply-To: References: Message-ID: On 1/15/2014 8:09 PM, Rita wrote: > I know its frowned upon to do work in the __init__() method and only > declarations should be there. Dear Python beginners: Don't believe the Python rules people write unless it is by one of the core developers or one of the other experts posting here. Even then, be skeptical. Even these people disagree on some guidelines. PS. The basic guideline is that your program should work correctly, and some people have disputed even that ;-) -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Jan 15 22:47:00 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Jan 2014 14:47:00 +1100 Subject: Guessing the encoding from a BOM References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7wlhygbnbf.fsf@benfinney.id.au> Steven D'Aprano writes: > enc = guess_encoding_from_bom("filename") > if enc == something: > # Can't guess, fall back on an alternative strategy > ... > else: > f = open("filename", encoding=enc) > > > If I forget to check the returned result, I should get an explicit > failure as soon as I try to use it, rather than silently returning the > wrong results. Yes, agreed. > What should I return as the default default? I have four possibilities: > > (1) 'undefined', which is an standard encoding guaranteed to > raise an exception when used; +0.5. This describes the outcome of the guess. > (2) 'unknown', which best describes the result, and currently > there is no encoding with that name; +0. This *better* describes the outcome, but I don't think adding a new name is needed nor very helpful. > (3) None, which is not the name of an encoding; or ?1. This is too much like a real result and doesn't adequately indicate the failure. > (4) Don't return anything, but raise an exception. (But > which exception?) +1. I'd like a custom exception class, sub-classed from ValueError. -- \ ?I love to go down to the schoolyard and watch all the little | `\ children jump up and down and run around yelling and screaming. | _o__) They don't know I'm only using blanks.? ?Emo Philips | Ben Finney From roy at panix.com Wed Jan 15 22:46:54 2014 From: roy at panix.com (Roy Smith) Date: Wed, 15 Jan 2014 22:46:54 -0500 Subject: Is it possible to get string from function? Message-ID: I realize the subject line is kind of meaningless, so let me explain :-) I've got some unit tests that look like: class Foo(TestCase): def test_t1(self): RECEIPT = "some string" def test_t2(self): RECEIPT = "some other string" def test_t3(self): RECEIPT = "yet a third string" and so on. It's important that the strings be mutually unique. In the example above, it's trivial to look at them and observe that they're all different, but in real life, the strings are about 2500 characters long, hex-encoded. It even turns out that a couple of the strings are identical in the first 1000 or so characters, so it's not trivial to do by visual inspection. So, I figured I would write a meta-test, which used introspection to find all the methods in the class, extract the strings from them (they are all assigned to a variable named RECEIPT), and check to make sure they're all different. Is it possible to do that? It is straight-forward using the inspect module to discover the methods, but I don't see any way to find what strings are assigned to a variable with a given name. Of course, that assignment doesn't even happen until the function is executed, so perhaps what I want just isn't possible? It turns out, I solved the problem with more mundane tools: grep 'RECEIPT = ' test.py | sort | uniq -c and I could have also solved the problem by putting all the strings in a dict and having the functions pull them out of there. But, I'm still interested in exploring if there is any way to do this with introspection, as an academic exercise. From roegltd at gmail.com Wed Jan 15 22:50:25 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 15 Jan 2014 19:50:25 -0800 (PST) Subject: Question about object lifetime and access In-Reply-To: <52d721a1$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <30012227-c0f5-4bbe-9e6c-d333cd5682a2@googlegroups.com> <52d721a1$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: First of all many thanks to all for their detailed answers on subject. I really appreciate it! > Correct. The global name is a reference, so the reference count will be > > at least 1. In fact, referencing the name from a function or method > doesn't increase the ref count: > -- > > Steven i have tried some tests, though accessing object from functions increase refcount but only temporary and only if object is used within function. i guess as soon as k is bound to string object latter's reference count will increase and function return results in unbound of k from object (according to output below). What is interesting if module namespace can be held accountable for 1 reference count what are remaining 3 references counted on string object referenced by 'p'? (CPython 3.3.2, windows 7, run from within eclipse/PyDev and same output on centos 6.5 for python v3.3.3) from sys import getrefcount p = "test script" print("refcnt before func() ", getrefcount(p)) def access_p1(): global p print("refcnt inside func1()", getrefcount(p)) def access_p2(): global p k = p print("refcnt inside func2()", getrefcount(p)) access_p1() access_p2() print("refcnt after func() ", getrefcount(p)) -------------------------------------------------------------- Output: refcnt before func() 4 refcnt inside func1() 4 refcnt inside func2() 5 refcnt after func() 4 From roy at panix.com Wed Jan 15 23:05:46 2014 From: roy at panix.com (Roy Smith) Date: Wed, 15 Jan 2014 23:05:46 -0500 Subject: data validation when creating an object References: Message-ID: Rita writes: >> I know its frowned upon to do work in the __init__() method and only >> declarations should be there. In article , Ben Finney wrote: > Who says it's frowned on to do work in the initialiser? Where are they > saying it? That seems over-broad, I'd like to read the context of that > advice. Weird, I was just having this conversation at work earlier this week. There are some people who advocate that C++ constructors should not do a lot of work and/or should be incapable of throwing exceptions. The pros and cons of that argument are largely C++ specific. Here's a Stack Overflow thread which covers most of the usual arguments on both sides: http://stackoverflow.com/questions/293967/how-much-work-should-be-done-in -a-constructor But, Python is not C++. I suspect the people who argue for __init__() not doing much are extrapolating a C++ pattern to other languages without fully understanding the reason why. That being said, I've been on a tear lately, trying to get our unit test suite to run faster. I came across one slow test which had an interesting twist. The class being tested had an __init__() method which read over 900,000 records from a database and took something like 5-10 seconds to run. Man, talk about heavy-weight constructors :-) From greg.ewing at canterbury.ac.nz Wed Jan 15 23:17:28 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 16 Jan 2014 17:17:28 +1300 Subject: Chanelling Guido - dict subclasses In-Reply-To: References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: Daniel da Silva wrote: > Just to be pedantic, this /is/ a violation of the Liskov Substution > Principle. According to Wikipedia, the principle states: > > if S is a subtype of T, then > objects of type T may be > replaced with objects of type S (i.e., objects of type S may > be /substituted/ for objects of type T) without altering any of the > desirable properties of that program Something everyone seems to miss when they quote the LSP is that what the "desirable properties of the program" are *depends on the program*. Whenever you create a subclass, there is always *some* difference between the behaviour of the subclass and the base class, otherwise there would be no point in having the subclass. Whether that difference has any bad consequences for the program depends on what the program does with the objects. So you can't just look at S and T in isolation and decide whether they satisfy the LSP or not. You need to consider them in context. In Python, there's a special problem with subclassing dicts in particular: some of the core interpreter code assumes a plain dict and bypasses the lookup of __getitem__ and __setitem__, going straight to the C-level implementations. If you tried to use a dict subclass in that context that overrode those methods, your overridden versions wouldn't get called. But if you never use your dict subclass in that way, there is no problem. Or if you don't override those particular methods, there's no problem either. If you're giving advice to someone who isn't aware of all the fine details, "don't subclass dict" is probably the safest thing to say. But there are legitimate use cases for it if you know what you're doing. The other issue is that people are often tempted to subclass dict in order to implement what isn't really a dict at all, but just a custom mapping type. The downside to that is that you end up inheriting a bunch of dict-specific methods that don't really make sense for your type. In that case it's usually better to start with a fresh class that *uses* a dict as part of its implementation, and only exposes the methods that are really needed. -- Greg From ben+python at benfinney.id.au Wed Jan 15 23:53:56 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Jan 2014 15:53:56 +1100 Subject: data validation when creating an object References: Message-ID: <7wha94bk7v.fsf@benfinney.id.au> Roy Smith writes: > Ben Finney wrote: > > > Who says it's frowned on to do work in the initialiser? Where are they > > saying it? That seems over-broad, I'd like to read the context of that > > advice. > > There are some people who advocate that C++ constructors should not do > a lot of work and/or should be incapable of throwing exceptions. The > pros and cons of that argument are largely C++ specific. [?] > > But, Python is not C++. I suspect the people who argue for __init__() > not doing much are extrapolating a C++ pattern to other languages > without fully understanding the reason why. Even simpler: They are mistaken in what the constructor is named, in Python. Python classes have the constructor, ?__new__?. I would agree with advice not to do anything but allocate the resources for a new instance in the constructor. Indeed, the constructor from ?object? does a good enough job that the vast majority of Python classes never need a custom constructor at all. (This is probably why many beginning programmers are confused about what the constructor is called: They've never seen a class with its own constructor!) Python instances have an initialiser, ?__init__?. That function is for setting up the specific instance for later use. This is commonly over-ridden and many classes define a custom initialiser, which normally does some amount of work. I don't think ?__init__? is subject to the conventions of a constructor, because *?__init__? is not a constructor*. -- \ ?Absurdity, n. A statement or belief manifestly inconsistent | `\ with one's own opinion.? ?Ambrose Bierce, _The Devil's | _o__) Dictionary_, 1906 | Ben Finney From rosuav at gmail.com Thu Jan 16 00:01:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 16:01:56 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thu, Jan 16, 2014 at 1:13 PM, Steven D'Aprano wrote: > if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): > return 'utf_16' > elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): > return 'utf_32' I'd swap the order of these two checks. If the file starts FF FE 00 00, your code will guess that it's UTF-16 and begins with a U+0000. ChrisA From ben+python at benfinney.id.au Thu Jan 16 00:02:10 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 16 Jan 2014 16:02:10 +1100 Subject: Dynamic generation of test cases for each input datum (was: Is it possible to get string from function?) References: Message-ID: <7wd2jsbju5.fsf@benfinney.id.au> Roy Smith writes: > I've got some unit tests that look like: > > class Foo(TestCase): > def test_t1(self): > RECEIPT = "some string" > > def test_t2(self): > RECEIPT = "some other string" > > def test_t3(self): > RECEIPT = "yet a third string" > > and so on. That looks like a poorly defined class. Are the test cases pretty much identical other than the data in those strings? If so, use a collection of strings and generate separate tests for each one dynamically. In Python 2 and 3, you can use the ?testscenarios? library for that purpose . In Python 3, the ?unittest? module has ?subtests? for the same purpose . > and I could have also solved the problem by putting all the strings in > a dict and having the functions pull them out of there. But, I'm still > interested in exploring if there is any way to do this with > introspection, as an academic exercise. Since I don't think your use case is best solved this way, I'll leave the academic exercise to someone else. -- \ ?? Nature ? is seen to do all things Herself and through | `\ herself of own accord, rid of all gods.? ?Titus Lucretius | _o__) Carus, c. 40 BCE | Ben Finney From roy at panix.com Thu Jan 16 00:05:07 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 00:05:07 -0500 Subject: data validation when creating an object References: Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > But, Python is not C++. I suspect the people who argue for __init__() > > not doing much are extrapolating a C++ pattern to other languages > > without fully understanding the reason why. > > Even simpler: They are mistaken in what the constructor is named, in > Python. > > Python classes have the constructor, ???__new__???. I would agree with > advice not to do anything but allocate the resources for a new instance > in the constructor. I've always found this distinction to be somewhat silly. C++ constructors are also really just initializers. Before your constructor is called, something else (operator new, at least for objects in the heap) has already allocated memory for the object. It's the constructor's job to initialize the data. That's really very much the same distinction as between __new__() and __init__(). From roy at panix.com Thu Jan 16 00:09:08 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 00:09:08 -0500 Subject: Dynamic generation of test cases for each input datum (was: Is it possible to get string from function?) References: Message-ID: In article , Ben Finney wrote: > Roy Smith writes: > > > I've got some unit tests that look like: > > > > class Foo(TestCase): > > def test_t1(self): > > RECEIPT = "some string" > > > > def test_t2(self): > > RECEIPT = "some other string" > > > > def test_t3(self): > > RECEIPT = "yet a third string" > > > > and so on. > > That looks like a poorly defined class. > > Are the test cases pretty much identical other than the data in those > strings? No, each test is quite different. The only thing they have in common is they all involve a string representation of a transaction receipt. I elided the actual test code in my example above because it wasn't relevant to my question. From rosuav at gmail.com Thu Jan 16 00:25:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 16:25:18 +1100 Subject: Is it possible to get string from function? In-Reply-To: References: Message-ID: On Thu, Jan 16, 2014 at 2:46 PM, Roy Smith wrote: > So, I figured I would write a meta-test, which used introspection to > find all the methods in the class, extract the strings from them (they > are all assigned to a variable named RECEIPT), and check to make sure > they're all different. In theory, it should be. You can disassemble the function and find the assignment. Check out Lib/dis.py - or just call it and process its output. Names of local variables are found in test_t1.__code__.co_names, the constants themselves are in test_1.__code__.co_consts, and then it's just a matter of matching up which constant got assigned to the slot represented by the name RECEIPT. But you might be able to shortcut it enormously. You say the strings are "about 2500 characters long, hex-encoded". What are the chances of having another constant, somewhere in the test function, that also happens to be roughly that long and hex-encoded? If the answer is "practically zero", then skip the code, skip co_names, and just look through co_consts. class TestCase: pass # not running this in the full environment class Foo(TestCase): def test_t1(self): RECEIPT = "some string" def test_t2(self): RECEIPT = "some other string" def test_t3(self): RECEIPT = "yet a third string" def test_oops(self): RECEIPT = "some other string" unique = {} for funcname in dir(Foo): if funcname.startswith("test_"): for const in getattr(Foo,funcname).__code__.co_consts: if isinstance(const, str) and const.endswith("string"): if const in unique: print("Collision!", unique[const], "and", funcname) unique[const] = funcname This depends on your RECEIPT strings ending with the word "string" - change the .endswith() check to be whatever it takes to distinguish your critical constants from everything else you might have. Maybe: CHARSET = set("0123456789ABCDEF") # or use lower-case letters, or both, according to your hex encoding if isinstance(const, str) and len(const)>2048 and set(const)<=CHARSET: Anything over 2KB with no characters outside of that set is highly likely to be what you want. Of course, this whole theory goes out the window if your test functions can reference another test's RECEIPT; though if you can guarantee that this is the *first* such literal (if RECEIPT="..." is the first thing the function does), then you could just add a 'break' after the unique[const]=funcname assignment and it'll check only the first - co_consts is ordered. An interesting little problem! ChrisA From ethan at stoneleaf.us Thu Jan 16 00:40:23 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Jan 2014 21:40:23 -0800 Subject: Guessing the encoding from a BOM In-Reply-To: <7wlhygbnbf.fsf@benfinney.id.au> References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> <7wlhygbnbf.fsf@benfinney.id.au> Message-ID: <52D770C7.5060906@stoneleaf.us> On 01/15/2014 07:47 PM, Ben Finney wrote: > Steven D'Aprano writes: >> >> (4) Don't return anything, but raise an exception. (But >> which exception?) > > +1. I'd like a custom exception class, sub-classed from ValueError. +1 -- ~Ethan~ From roy at panix.com Thu Jan 16 00:40:39 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 00:40:39 -0500 Subject: Is it possible to get string from function? References: Message-ID: In article , Chris Angelico wrote: > On Thu, Jan 16, 2014 at 2:46 PM, Roy Smith wrote: > > So, I figured I would write a meta-test, which used introspection to > > find all the methods in the class, extract the strings from them (they > > are all assigned to a variable named RECEIPT), and check to make sure > > they're all different. >> [...] > But you might be able to shortcut it enormously. You say the strings > are "about 2500 characters long, hex-encoded". What are the chances of > having another constant, somewhere in the test function, that also > happens to be roughly that long and hex-encoded? The chances are exactly zero. > If the answer is "practically zero", then skip the code, skip > co_names, and just look through co_consts. That sounds like it should work, thanks! > Of course, this whole theory goes out the > window if your test functions can reference another test's RECEIPT; No, they don't do that. From rosuav at gmail.com Thu Jan 16 00:47:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 16:47:59 +1100 Subject: Is it possible to get string from function? In-Reply-To: References: Message-ID: On Thu, Jan 16, 2014 at 4:40 PM, Roy Smith wrote: >> But you might be able to shortcut it enormously. You say the strings >> are "about 2500 characters long, hex-encoded". What are the chances of >> having another constant, somewhere in the test function, that also >> happens to be roughly that long and hex-encoded? > > The chances are exactly zero. > >> If the answer is "practically zero", then skip the code, skip >> co_names, and just look through co_consts. > > That sounds like it should work, thanks! > >> Of course, this whole theory goes out the >> window if your test functions can reference another test's RECEIPT; > > No, they don't do that. Awesome! Makes it easy then. ChrisA From cs at zip.com.au Thu Jan 16 01:29:31 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 16 Jan 2014 17:29:31 +1100 Subject: data validation when creating an object In-Reply-To: References: Message-ID: <20140116062931.GA20330@cskk.homeip.net> On 16Jan2014 12:46, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 12:25 PM, Cameron Simpson wrote: > > However, I would also have obvious validity checks in __init__ > > itself on the supplied values. Eg: > > > > def __init__(self, size, lifetime): > > if size < 1: > > raise ValueError("size must be >= 1, received: %r" % (size,)) > > if lifetime <= 0: > > raise ValueError("lifetime must be > 0, received: %r" % (lifetime,)) > > > > Trivial, fast. Fails early. Note that the exception reports the > > receive value; very handy for simple errors like passing utterly > > the wrong thing (eg a filename when you wanted a counter, or something > > like that). > > With code like this, passing a filename as the size will raise TypeError on Py3: I thought of this, but had already dispatched my message:-( I actually thought Py2 would give me a TypeError, but I see it doesn't. -- Cameron Simpson The significant problems we face cannot be solved at the same level of thinking we were at when we created them. - Albert Einstein From jeanpierreda at gmail.com Thu Jan 16 01:30:53 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Wed, 15 Jan 2014 22:30:53 -0800 Subject: Chanelling Guido - dict subclasses In-Reply-To: <05ff1332-1776-4ac0-88b4-84f8fd323ce3@googlegroups.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> <05ff1332-1776-4ac0-88b4-84f8fd323ce3@googlegroups.com> Message-ID: On Wed, Jan 15, 2014 at 8:51 AM, John Ladasky wrote: > On Wednesday, January 15, 2014 12:40:33 AM UTC-8, Peter Otten wrote: >> Personally I feel dirty whenever I write Python code that defeats duck- >> typing -- so I would not /recommend/ any isinstance() check. > > While I am inclined to agree, I have yet to see a solution to the problem of flattening nested lists/tuples which avoids isinstance(). If anyone has written one, I would like to see it, and consider its merits. As long as you're the one that created the nested list structure, you can choose to create a different structure instead, one which doesn't require typechecking values inside your structure. For example, os.walk has a similar kind of problem; it uses separate lists for the subdirectories and the rest of the files, rather than requiring you to check each child to see if it is a directory. It can do it this way because it doesn't need to preserve the interleaved order of directories and files, but there's other solutions for you if you do want to preserve that order. (Although they won't be as clean as they would be in a language with ADTs) -- Devin From steve at pearwood.info Thu Jan 16 01:45:38 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 06:45:38 GMT Subject: Guessing the encoding from a BOM References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52d78012$0$6599$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 16:01:56 +1100, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 1:13 PM, Steven D'Aprano > wrote: >> if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): >> return 'utf_16' >> elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): >> return 'utf_32' > > I'd swap the order of these two checks. If the file starts FF FE 00 00, > your code will guess that it's UTF-16 and begins with a U+0000. Good catch, thank you. -- Steven From steve at pearwood.info Thu Jan 16 01:55:16 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 06:55:16 GMT Subject: Guessing the encoding from a BOM References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52d78254$0$6599$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 14:47:00 +1100, Ben Finney wrote: > Steven D'Aprano writes: > >> enc = guess_encoding_from_bom("filename") if enc == something: >> # Can't guess, fall back on an alternative strategy ... >> else: >> f = open("filename", encoding=enc) >> >> >> If I forget to check the returned result, I should get an explicit >> failure as soon as I try to use it, rather than silently returning the >> wrong results. > > Yes, agreed. > >> What should I return as the default default? I have four possibilities: >> >> (1) 'undefined', which is an standard encoding guaranteed to >> raise an exception when used; > > +0.5. This describes the outcome of the guess. > >> (2) 'unknown', which best describes the result, and currently >> there is no encoding with that name; > > +0. This *better* describes the outcome, but I don't think adding a new > name is needed nor very helpful. And there is a chance -- albeit a small chance -- that someday the std lib will gain an encoding called "unknown". >> (4) Don't return anything, but raise an exception. (But >> which exception?) > > +1. I'd like a custom exception class, sub-classed from ValueError. Why ValueError? It's not really a "invalid value" error, it's more "my heuristic isn't good enough" failure. (Maybe the file starts with another sort of BOM which I don't know about.) If I go with an exception, I'd choose RuntimeError, or a custom error that inherits directly from Exception. Thanks to everyone for the feedback. -- Steven From cs at zip.com.au Thu Jan 16 01:36:54 2014 From: cs at zip.com.au (Cameron Simpson) Date: Thu, 16 Jan 2014 17:36:54 +1100 Subject: data validation when creating an object In-Reply-To: <7wha94bk7v.fsf@benfinney.id.au> References: <7wha94bk7v.fsf@benfinney.id.au> Message-ID: <20140116063654.GA23771@cskk.homeip.net> On 16Jan2014 15:53, Ben Finney wrote: > Roy Smith writes: > > Ben Finney wrote: > > > Who says it's frowned on to do work in the initialiser? Where are they > > > saying it? That seems over-broad, I'd like to read the context of that > > > advice. > > > > There are some people who advocate that C++ constructors should not do > > a lot of work and/or should be incapable of throwing exceptions. The > > pros and cons of that argument are largely C++ specific. [?] > > Even simpler: They are mistaken in what the constructor is named, in > Python. > Python classes have the constructor, ?__new__?. I would agree with > advice not to do anything but allocate the resources for a new instance > in the constructor. [...] > > Python instances have an initialiser, ?__init__?. That function is for > setting up the specific instance for later use. This is commonly > over-ridden and many classes define a custom initialiser, which normally > does some amount of work. > > I don't think ?__init__? is subject to the conventions of a constructor, > because *?__init__? is not a constructor*. 99% of the time this distinction is moot. When I call ClassName(blah,...), both the constructor and initialiser are called. Informally, there's a rule of thumb that making an object (allocate, construct and initialise) shouldn't be needlessly expensive. Beyond that, what happens depends on the use patterns. This rule of thumb will be what Rita's encountered, perhaps stated without any qualification regarding what's appropriate. Cheers, -- Cameron Simpson The problem with keeping an open mind is that my ideas all tend to fall out... - Bill Garrett From steve at pearwood.info Thu Jan 16 02:16:29 2014 From: steve at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 07:16:29 GMT Subject: Is it possible to get string from function? References: Message-ID: <52d7874d$0$6599$c3e8da3$5496439d@news.astraweb.com> On Wed, 15 Jan 2014 22:46:54 -0500, Roy Smith wrote: > I've got some unit tests that look like: > > class Foo(TestCase): > def test_t1(self): > RECEIPT = "some string" > > def test_t2(self): > RECEIPT = "some other string" > > def test_t3(self): > RECEIPT = "yet a third string" > > and so on. It's important that the strings be mutually unique. In the > example above, it's trivial to look at them and observe that they're all > different, but in real life, the strings are about 2500 characters long, > hex-encoded. It even turns out that a couple of the strings are > identical in the first 1000 or so characters, so it's not trivial to do > by visual inspection. Is the mapping of receipt string to test fixed? That is, is it important that test_t1 *always* runs with "some string", test_t2 "some other string", and so forth? If not, I'd start by pushing all those strings into a global list (or possible a class attribute. Then: LIST_OF_GIANT_STRINGS = [blah blah blah] # Read it from a file perhaps? assert len(LIST_OF_GIANT_STRINGS) == len(set(LIST_OF_GIANT_STRINGS)) Then, change each test case to: def test_t1(self): RECEIPT = random.choose(LIST_OF_GIANT_STRINGS) Even if two tests happen to pick the same string on this run, they are unlikely to pick the same string on the next run. If that's not good enough, if the strings *must* be unique, you can use a helper like this: def choose_without_replacement(alist): random.shuffle(alist) return alist.pop() class Foo(TestCase): def test_t1(self): RECEIPT = choose_without_replacement(LIST_OF_GIANT_STRINGS) All this assumes that you don't care which giant string matches which test method. If you do, then: DICT_OF_GIANT_STRINGS = { 'test_t1': ..., 'test_t2': ..., } # Again, maybe read them from a file. assert len(list(DICT_OF_GIANT_STRINGS.values())) == \ len(set(DICT_OF_GIANT_STRINGS.values())) You can probably build up the dict from the test class by inspection, e.g.: DICT_OF_GIANT_STRINGS = {} for name in Foo.__dict__: if name.startswith("test_"): key = name[5:] if key.startswith("t"): DICT_OF_GIANT_STRINGS[name] = get_giant_string(key) I'm sure you get the picture. Then each method just needs to know it's own name: class Foo(TestCase): def test_t1(self): RECEIPT = DICT_OF_GIANT_STRINGS["test_t1"] which I must admit is much easier to read than RECEIPT = "...2500 hex encoded characters..." -- Steven From ethan at stoneleaf.us Thu Jan 16 02:29:15 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 15 Jan 2014 23:29:15 -0800 Subject: Guessing the encoding from a BOM In-Reply-To: <52d78254$0$6599$c3e8da3$5496439d@news.astraweb.com> References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> <52d78254$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52D78A4B.9010100@stoneleaf.us> On 01/15/2014 10:55 PM, Steven D'Aprano wrote: > On Thu, 16 Jan 2014 14:47:00 +1100, Ben Finney wrote: >> >> +1. I'd like a custom exception class, sub-classed from ValueError. > > Why ValueError? It's not really a "invalid value" error, it's more "my > heuristic isn't good enough" failure. (Maybe the file starts with another > sort of BOM which I don't know about.) > > If I go with an exception, I'd choose RuntimeError, or a custom error > that inherits directly from Exception. From the docs [1]: ============================ exception RuntimeError Raised when an error is detected that doesn?t fall in any of the other categories. The associated value is a string indicating what precisely went wrong. It doesn't sound like RuntimeError is any more informative than Exception or AssertionError, and to my mind at least is usually close to catastrophic in nature [2]. I'd say a ValueError subclass because, while not an strictly an error, it is values you don't know how to deal with. But either that or plain Exception, just not RuntimeError. -- ~Ethan~ [1] http://docs.python.org/3/library/exceptions.html#RuntimeError [2] verified by a (very) brief grep of the sources From __peter__ at web.de Thu Jan 16 03:52:57 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Jan 2014 09:52:57 +0100 Subject: Is it possible to get string from function? References: Message-ID: Roy Smith wrote: > I realize the subject line is kind of meaningless, so let me explain :-) > > I've got some unit tests that look like: > > class Foo(TestCase): > def test_t1(self): > RECEIPT = "some string" > > def test_t2(self): > RECEIPT = "some other string" > > def test_t3(self): > RECEIPT = "yet a third string" > > and so on. It's important that the strings be mutually unique. In the > example above, it's trivial to look at them and observe that they're all > different, but in real life, the strings are about 2500 characters long, > hex-encoded. It even turns out that a couple of the strings are > identical in the first 1000 or so characters, so it's not trivial to do > by visual inspection. > > So, I figured I would write a meta-test, which used introspection to > find all the methods in the class, extract the strings from them (they > are all assigned to a variable named RECEIPT), and check to make sure > they're all different. > > Is it possible to do that? It is straight-forward using the inspect > module to discover the methods, but I don't see any way to find what > strings are assigned to a variable with a given name. Of course, that > assignment doesn't even happen until the function is executed, so > perhaps what I want just isn't possible? > > It turns out, I solved the problem with more mundane tools: > > grep 'RECEIPT = ' test.py | sort | uniq -c > > and I could have also solved the problem by putting all the strings in a > dict and having the functions pull them out of there. But, I'm still > interested in exploring if there is any way to do this with > introspection, as an academic exercise. Instead of using introspection you could make it explicit with a decorator: $ cat unique_receipt.py import functools import sys import unittest _receipts = {} def unique_receipt(receipt): def deco(f): if receipt in _receipts: raise ValueError( "Duplicate receipt {!r} in \n {} and \n {}".format( receipt, _receipts[receipt], f)) _receipts[receipt] = f @functools.wraps(f) def g(self): return f(self, receipt) return g return deco class Foo(unittest.TestCase): @unique_receipt("foo") def test_t1(self, RECEIPT): pass @unique_receipt("bar") def test_t2(self, RECEIPT): pass @unique_receipt("foo") def test_t3(self, RECEIPT): pass if __name__ == "__main__": unittest.main() $ python unique_receipt.py Traceback (most recent call last): File "unique_receipt.py", line 19, in class Foo(unittest.TestCase): File "unique_receipt.py", line 28, in Foo @unique_receipt("foo") File "unique_receipt.py", line 11, in deco receipt, _receipts[receipt], f)) ValueError: Duplicate receipt 'foo' in and From lightaiyee at gmail.com Thu Jan 16 04:41:25 2014 From: lightaiyee at gmail.com (Sam) Date: Thu, 16 Jan 2014 01:41:25 -0800 (PST) Subject: Building and accessing an array of dictionaries Message-ID: I would like to build an array of dictionaries. Most of the dictionary example on the net are for single dictionary. dict = {'a':'a','b':'b','c':'c'} dict2 = {'a':'a','b':'b','c':'c'} dict3 = {'a':'a','b':'b','c':'c'} arr = (dict,dict2,dict3) What is the syntax to access the value of dict3->'a'? Thank you. From rosuav at gmail.com Thu Jan 16 04:48:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 20:48:31 +1100 Subject: Building and accessing an array of dictionaries In-Reply-To: References: Message-ID: On Thu, Jan 16, 2014 at 8:41 PM, Sam wrote: > I would like to build an array of dictionaries. Most of the dictionary example on the net are for single dictionary. > > dict = {'a':'a','b':'b','c':'c'} > dict2 = {'a':'a','b':'b','c':'c'} > dict3 = {'a':'a','b':'b','c':'c'} > > arr = (dict,dict2,dict3) > > What is the syntax to access the value of dict3->'a'? Technically, that's a tuple of dictionaries, and you may want to use a list instead: lst = [dict, dict2, dict3] Like any other list or tuple, you can reference them by their indices: lst[2] is dict3 lst[2]['a'] is dict3['a'] Hope that helps! ChrisA From jpiitula at ling.helsinki.fi Thu Jan 16 04:52:12 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 16 Jan 2014 11:52:12 +0200 Subject: Building and accessing an array of dictionaries References: Message-ID: Sam writes: > I would like to build an array of dictionaries. Most of the > dictionary example on the net are for single dictionary. > > dict = {'a':'a','b':'b','c':'c'} > dict2 = {'a':'a','b':'b','c':'c'} > dict3 = {'a':'a','b':'b','c':'c'} > > arr = (dict,dict2,dict3) > > What is the syntax to access the value of dict3->'a'? This isn't a special case. arr[2] to get the dictionary arr[2]['a'] to get the value in the dictionary 'a' in arr[2] to find if there is such a key arr[2].get('a') to get the value or None if the key isn't there arr[2].get('a', 'd') to get a value even if the key isn't there help(dict.get) for key in arr[2]: # to iterate over the keys The exact same mechanisms are used no matter where you get the dictionary from. From jeanmichel at sequans.com Thu Jan 16 04:57:52 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Thu, 16 Jan 2014 10:57:52 +0100 (CET) Subject: Building and accessing an array of dictionaries In-Reply-To: Message-ID: <795848945.91031.1389866272911.JavaMail.root@sequans.com> ----- Original Message ----- > I would like to build an array of dictionaries. Most of the > dictionary example on the net are for single dictionary. > > dict = {'a':'a','b':'b','c':'c'} > dict2 = {'a':'a','b':'b','c':'c'} > dict3 = {'a':'a','b':'b','c':'c'} > > arr = (dict,dict2,dict3) > > What is the syntax to access the value of dict3->'a'? > > Thank you. > > -- > https://mail.python.org/mailman/listinfo/python-list > Hi, arr = (dict,dict2,dict3) builds a tuple. If you want to build a (ordered) List, which is the closest type to array (arrays don't exists in python), you may write myList = [dict, dict2, dict3] you can access 'a' by writing myList[2]['a'] Additionally: myList[0] -> 1st element myList[-1] -> last element myList[3:] -> list of elements of myList from the the 4th element to the last Accessing a list element or a dictionary value is done through the same operator []. That can be confusing at the very beginning, you'll get used to it eventually. 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 robin at reportlab.com Thu Jan 16 05:51:42 2014 From: robin at reportlab.com (Robin Becker) Date: Thu, 16 Jan 2014 10:51:42 +0000 Subject: =?UTF-8?B?J1N0cmHDn2UnICgnU3RyYXNzZScpIGFuZCBQeXRob24gMg==?= In-Reply-To: <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52D7B9BE.9020001@chamonix.reportlab.co.uk> On 16/01/2014 00:32, Steven D'Aprano wrote: >> >Or are you saying thatwww.unicode.org is wrong about the definitions of >> >Unicode terms? > No, I think he is saying that he doesn't know Unicode anywhere near as > well as he thinks he does. The question is, will he cherish his > ignorance, or learn from this thread? I assure you that I fully understand my ignorance of unicode. Until recently I didn't even know that the unicode in python 2.x is considered broken and that str in python 3.x is considered 'better'. I can say that having made a lot of reportlab work in both 2.7 & 3.3 I don't understand why the latter seems slower especially since we try to convert early to unicode/str as a desirable internal form. Probably I have some horrible error going on(eg one of the C extensions is working in 2.7 and not in 3.3). -stupidly yrs- Robin Becker From rosuav at gmail.com Thu Jan 16 05:58:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 16 Jan 2014 21:58:56 +1100 Subject: =?UTF-8?B?UmU6ICdTdHJhw59lJyAoJ1N0cmFzc2UnKSBhbmQgUHl0aG9uIDI=?= In-Reply-To: <52D7B9BE.9020001@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> <52D7B9BE.9020001@chamonix.reportlab.co.uk> Message-ID: On Thu, Jan 16, 2014 at 9:51 PM, Robin Becker wrote: > On 16/01/2014 00:32, Steven D'Aprano wrote: >>> >>> >Or are you saying thatwww.unicode.org is wrong about the definitions of >>> >Unicode terms? >> >> No, I think he is saying that he doesn't know Unicode anywhere near as >> well as he thinks he does. The question is, will he cherish his >> ignorance, or learn from this thread? > > > I assure you that I fully understand my ignorance of unicode. Until recently > I didn't even know that the unicode in python 2.x is considered broken and > that str in python 3.x is considered 'better'. Your wisdom, if I may paraphrase Master Foo, is that you know you are a fool. http://catb.org/esr/writings/unix-koans/zealot.html ChrisA From fomcl at yahoo.com Thu Jan 16 05:59:42 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Thu, 16 Jan 2014 02:59:42 -0800 (PST) Subject: Is it possible to get string from function? In-Reply-To: Message-ID: <1389869982.38511.YahooMailBasic@web163803.mail.gq1.yahoo.com> -------------------------------------------- On Thu, 1/16/14, Peter Otten <__peter__ at web.de> wrote: Subject: Re: Is it possible to get string from function? To: python-list at python.org Date: Thursday, January 16, 2014, 9:52 AM Roy Smith wrote: > I realize the subject line is kind of meaningless, so let me explain :-) > > I've got some unit tests that look like: > > class Foo(TestCase): >???def test_t1(self): >? ???RECEIPT = "some string" > >???def test_t2(self): >? ???RECEIPT = "some other string" > >???def test_t3(self): >? ???RECEIPT = "yet a third string" > > and so on.? It's important that the strings be mutually unique.? In the > example above, it's trivial to look at them and observe that they're all > different, but in real life, the strings are about 2500 characters long, > hex-encoded.? It even turns out that a couple of the strings are > identical in the first 1000 or so characters, so it's not trivial to do > by visual inspection. > > So, I figured I would write a meta-test, which used introspection to > find all the methods in the class, extract the strings from them (they > are all assigned to a variable named RECEIPT), and check to make sure > they're all different. > > Is it possible to do that?? It is straight-forward using the inspect > module to discover the methods, but I don't see any way to find what > strings are assigned to a variable with a given name.? Of course, that > assignment doesn't even happen until the function is executed, so > perhaps what I want just isn't possible? > > It turns out, I solved the problem with more mundane tools: > > grep 'RECEIPT = ' test.py | sort | uniq -c > > and I could have also solved the problem by putting all the strings in a > dict and having the functions pull them out of there.? But, I'm still > interested in exploring if there is any way to do this with > introspection, as an academic exercise. Instead of using introspection you could make it explicit with a decorator: $ cat unique_receipt.py import functools import sys import unittest _receipts = {} def unique_receipt(receipt): ? ? def deco(f): ? ? ? ? if receipt in _receipts: ? ? ? ? ? ? raise ValueError( ? ? ? ? ? ? ? ? "Duplicate receipt {!r} in \n? ? {} and \n? ? {}".format( ? ? ? ? ? ? ? ? ? ? receipt, _receipts[receipt], f)) ? ? ? ? _receipts[receipt] = f ? ? ? ? @functools.wraps(f) ? ? ? ? def g(self): ? ? ? ? ? ? return f(self, receipt) ? ? ? ? return g ? ? return deco class Foo(unittest.TestCase): ? ? @unique_receipt("foo") ? ? def test_t1(self, RECEIPT): ? ? ? ? pass ? ? @unique_receipt("bar") ? ? def test_t2(self, RECEIPT): ? ? ? ? pass ? ? @unique_receipt("foo") ? ? def test_t3(self, RECEIPT): ? ? ? ? pass if __name__ == "__main__": ? ? unittest.main() $ python unique_receipt.py Traceback (most recent call last): ? File "unique_receipt.py", line 19, in ? ? class Foo(unittest.TestCase): ? File "unique_receipt.py", line 28, in Foo ? ? @unique_receipt("foo") ? File "unique_receipt.py", line 11, in deco ? ? receipt, _receipts[receipt], f)) ValueError: Duplicate receipt 'foo' in ? ? and ? ? ============> Very cool approach. Question, though: what would be wrong with the following approach: import unittest class Test(unittest.TestCase): receipts = {} def unique_value(self, k, v): assert Test.receipts.get(k) is None, "Duplicate: %s" % v Test.receipts[k] = v def test_a(self): self.unique_value("large_value", "foo") def test_b(self): self.unique_value("large_value", "bar") # oh no, a duplicate! def test_c(self): self.unique_value("another_large_value", "blah") unittest.main() From nicholas.cole at gmail.com Thu Jan 16 06:13:51 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Thu, 16 Jan 2014 11:13:51 +0000 Subject: Python program distribution - a source of constant friction In-Reply-To: References: Message-ID: On Tue, Jan 7, 2014 at 12:09 AM, Nicholas Cole wrote: [SNIP] > Even so, things like that are harder to create than they > could be, or less prominently documented than one might have expected. > > Case in point: I have an application a friend/colleague of mine would like > to look at. I've no idea if he is running Debian or Redhat or FreeBSD or a > Mac. Assuming I've not used any C extensions, it is *possible* to create > something that will run on all of the above without any fuss at his end. It > just isn't nearly as easy as it could be, which must be a shame. > > Nicholas. In a spirit of trying to not only highlight problems, but start to solve them: https://pypi.python.org/pypi/ncdistribute/ Feedback is very welcome. Version 1 is a naive approach - it doesn't filter the included files at all, and will include all detected dependencies that are not part of the standard library. Best wishes, Nicholas From rmorgan466 at gmail.com Thu Jan 16 07:01:17 2014 From: rmorgan466 at gmail.com (Rita) Date: Thu, 16 Jan 2014 07:01:17 -0500 Subject: data validation when creating an object In-Reply-To: <20140116063654.GA23771@cskk.homeip.net> References: <7wha94bk7v.fsf@benfinney.id.au> <20140116063654.GA23771@cskk.homeip.net> Message-ID: Thanks everyone for the replies. On Thu, Jan 16, 2014 at 1:36 AM, Cameron Simpson wrote: > On 16Jan2014 15:53, Ben Finney wrote: > > Roy Smith writes: > > > Ben Finney wrote: > > > > Who says it's frowned on to do work in the initialiser? Where are > they > > > > saying it? That seems over-broad, I'd like to read the context of > that > > > > advice. > > > > > > There are some people who advocate that C++ constructors should not do > > > a lot of work and/or should be incapable of throwing exceptions. The > > > pros and cons of that argument are largely C++ specific. [?] > > > > Even simpler: They are mistaken in what the constructor is named, in > > Python. > > Python classes have the constructor, ?__new__?. I would agree with > > advice not to do anything but allocate the resources for a new instance > > in the constructor. [...] > > > > Python instances have an initialiser, ?__init__?. That function is for > > setting up the specific instance for later use. This is commonly > > over-ridden and many classes define a custom initialiser, which normally > > does some amount of work. > > > > I don't think ?__init__? is subject to the conventions of a constructor, > > because *?__init__? is not a constructor*. > > 99% of the time this distinction is moot. When I call ClassName(blah,...), > both the constructor and initialiser are called. > > Informally, there's a rule of thumb that making an object (allocate, > construct and initialise) shouldn't be needlessly expensive. Beyond > that, what happens depends on the use patterns. > > This rule of thumb will be what Rita's encountered, perhaps stated > without any qualification regarding what's appropriate. > > Cheers, > -- > Cameron Simpson > > The problem with keeping an open mind is that my ideas all tend to fall > out... > - Bill Garrett > -- > https://mail.python.org/mailman/listinfo/python-list > -- --- Get your facts first, then you can distort them as you please.-- -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Thu Jan 16 07:06:35 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 16 Jan 2014 14:06:35 +0200 Subject: 'StraÃYe' ('Strasse') and Python 2 References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> <52D7B9BE.9020001@chamonix.reportlab.co.uk> Message-ID: "Robin Becker" wrote in message news:52D7B9BE.9020001 at chamonix.reportlab.co.uk... > On 16/01/2014 00:32, Steven D'Aprano wrote: >>> >Or are you saying thatwww.unicode.org is wrong about the definitions >>> >of >>> >Unicode terms? >> No, I think he is saying that he doesn't know Unicode anywhere near as >> well as he thinks he does. The question is, will he cherish his >> ignorance, or learn from this thread? > > I assure you that I fully understand my ignorance of unicode. Until > recently I didn't even know that the unicode in python 2.x is considered > broken and that str in python 3.x is considered 'better'. > Hi Robin I am pretty sure that Steven was referring to the original post from jmfauth, not to anything that you wrote. May I say that I am delighted that you are putting in the effort to port ReportLab to python3, and I trust that you will get plenty of support from the gurus here in achieving this. Frank Millman From nfdisco at gmail.com Thu Jan 16 07:34:08 2014 From: nfdisco at gmail.com (Ernest =?iso-8859-1?Q?Adrogu=E9?=) Date: Thu, 16 Jan 2014 13:34:08 +0100 Subject: Unicode strings as arguments to exceptions Message-ID: <20140116123408.GA5524@doriath.local> Hi, There seems to be some inconsistency in the way exceptions handle Unicode strings. For instance, KeyError seems to not have a problem with them >>> raise KeyError('a') Traceback (most recent call last): File "", line 1, in KeyError: 'a' >>> raise KeyError(u'?') Traceback (most recent call last): File "", line 1, in KeyError: u'\xe4' On the other hand ValueError doesn't print anything. >>> raise ValueError('a') Traceback (most recent call last): File "", line 1, in ValueError: a >>> raise ValueError(u'?') Traceback (most recent call last): File "", line 1, in ValueError I'm using Python 2.7.6 on a Unix machine. From piet at vanoostrum.org Thu Jan 16 07:57:54 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Thu, 16 Jan 2014 13:57:54 +0100 Subject: Python 3.x adoption References: Message-ID: Travis Griggs writes: > Personally, I wish they?d start python4, sure would take the heat out of > the 3 vs 2 debates. And maybe there?d be a program called twentyfour as > a result. twelve would be sufficient, I would think. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From robin at reportlab.com Thu Jan 16 08:03:18 2014 From: robin at reportlab.com (Robin Becker) Date: Thu, 16 Jan 2014 13:03:18 +0000 Subject: =?ISO-8859-1?Q?=27Stra=C3Ye=27_=28=27Strasse=27=29_and_?= =?ISO-8859-1?Q?Python_2?= In-Reply-To: References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> <52D7B9BE.9020001@chamonix.reportlab.co.uk> Message-ID: <52D7D896.5040900@chamonix.reportlab.co.uk> On 16/01/2014 12:06, Frank Millman wrote: .......... >> I assure you that I fully understand my ignorance of unicode. Until >> recently I didn't even know that the unicode in python 2.x is considered >> broken and that str in python 3.x is considered 'better'. >> > > Hi Robin > > I am pretty sure that Steven was referring to the original post from > jmfauth, not to anything that you wrote. > unfortunately my ignorance remains even in the absence of criticism > May I say that I am delighted that you are putting in the effort to port > ReportLab to python3, and I trust that you will get plenty of support from > the gurus here in achieving this. ........ I have had a lot of support from the gurus thanks to all of them :) -- Robin Becker From steve+comp.lang.python at pearwood.info Thu Jan 16 09:07:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 14:07:59 GMT Subject: =?iso-8859-1?q?'Stra=DFe'?= ('Strasse') and Python 2 References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52d7e7be$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 10:51:42 +0000, Robin Becker wrote: > On 16/01/2014 00:32, Steven D'Aprano wrote: >>> >Or are you saying thatwww.unicode.org is wrong about the definitions >>> >of Unicode terms? >> No, I think he is saying that he doesn't know Unicode anywhere near as >> well as he thinks he does. The question is, will he cherish his >> ignorance, or learn from this thread? > > I assure you that I fully understand my ignorance of unicode. Robin, while I'm very happy to see that you have a good grasp of what you don't know, I'm afraid that you're misrepresenting me. You deleted the part of my post that made it clear that I was referring to our resident Unicode crank, JMF . > Until > recently I didn't even know that the unicode in python 2.x is considered > broken and that str in python 3.x is considered 'better'. No need for scare quotes. The unicode type in Python 2.x is less-good because: - it is not the default string type (you have to prefix the string with a u to get Unicode); - it is missing some functionality, e.g. casefold; - there are two distinct implementations, narrow builds and wide builds; - wide builds take up to four times more memory per string as needed; - narrow builds take up to two times more memory per string as needed; - worse, narrow builds have very naive (possibly even "broken") handling of code points in the Supplementary Multilingual Planes. The unicode string type in Python 3 is better because: - it is the default string type; - it includes more functionality; - starting in Python 3.3, it gets rid of the distinction between narrow and wide builds; - which reduces the memory overhead of strings by up to a factor of four in many cases; - and fixes the issue of SMP code points. > I can say that having made a lot of reportlab work in both 2.7 & 3.3 I > don't understand why the latter seems slower especially since we try to > convert early to unicode/str as a desirable internal form. *shrug* Who knows? Is it slower or does it only *seem* slower? Is the performance regression platform specific? Have you traded correctness for speed, that is, does 2.7 version break when given astral characters on a narrow build? Earlier in January, you commented in another thread that "I'm not sure if we have any non-bmp characters in the tests." If you don't, you should have some. There's all sorts of reasons why your code might be slower under 3.3, including the possibility of a non-trivial performance regression. If you can demonstrate a test case with a significant slowdown for real-world code, I'm sure that a bug report will be treated seriously. > Probably I > have some horrible error going on(eg one of the C extensions is working > in 2.7 and not in 3.3). Well that might explain a slowdown. But really, one should expect that moving from single byte strings to up to four-byte strings will have *some* cost. It's exchanging functionality for time. The same thing happened years ago, people used to be extremely opposed to using floating point doubles instead of singles because of performance. And, I suppose it is true that back when 64K was considered a lot of memory, using eight whole bytes per floating point number (let alone ten like the IEEE Extended format) might have seemed the height of extravagance. But today we use doubles by default, and if singles would be a tiny bit faster, who wants to go back to the bad old days of single precision? I believe the same applies to Unicode versus single-byte strings. -- Steven From steve+comp.lang.python at pearwood.info Thu Jan 16 09:16:00 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 16 Jan 2014 14:16:00 GMT Subject: Unicode strings as arguments to exceptions References: Message-ID: <52d7e9a0$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 13:34:08 +0100, Ernest Adrogu? wrote: > Hi, > > There seems to be some inconsistency in the way exceptions handle > Unicode strings. Yes. I believe the problem lies in the __str__ method. For example, KeyError manages to handle Unicode, although in an ugly way: py> str(KeyError(u'?')) "u'\\xe4'" Hence: py> raise KeyError(u'?') Traceback (most recent call last): File "", line 1, in KeyError: u'\xe4' While ValueError assumes ASCII and fails: py> str(ValueError(u'?')) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128) When displaying the traceback, the error is suppressed, hence: py> raise ValueError(u'?') Traceback (most recent call last): File "", line 1, in ValueError I believe this might be accepted as a bug report on ValueError. -- Steven From roy at panix.com Thu Jan 16 09:30:30 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 09:30:30 -0500 Subject: Is it possible to get string from function? References: <52d7874d$0$6599$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52d7874d$0$6599$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > Is the mapping of receipt string to test fixed? That is, is it important > that test_t1 *always* runs with "some string", test_t2 "some other > string", and so forth? Yes. From roy at panix.com Thu Jan 16 09:32:17 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 09:32:17 -0500 Subject: Unicode strings as arguments to exceptions References: <52d7e9a0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52d7e9a0$0$29999$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Thu, 16 Jan 2014 13:34:08 +0100, Ernest Adrogu?? wrote: > > > Hi, > > > > There seems to be some inconsistency in the way exceptions handle > > Unicode strings. > > Yes. I believe the problem lies in the __str__ method. For example, > KeyError manages to handle Unicode, although in an ugly way: > > py> str(KeyError(u'??')) > "u'\\xe4'" > > Hence: > > py> raise KeyError(u'??') > Traceback (most recent call last): > File "", line 1, in > KeyError: u'\xe4' > > > While ValueError assumes ASCII and fails: > > py> str(ValueError(u'??')) > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in > position 0: ordinal not in range(128) > > When displaying the traceback, the error is suppressed, hence: > > py> raise ValueError(u'??') > Traceback (most recent call last): > File "", line 1, in > ValueError > > > I believe this might be accepted as a bug report on ValueError. If you try to construct an instance of ValueError with an argument it can't handle, the obvious thing for it to do is raise ValueError :-) From __peter__ at web.de Thu Jan 16 09:50:06 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 16 Jan 2014 15:50:06 +0100 Subject: Is it possible to get string from function? References: <1389869982.38511.YahooMailBasic@web163803.mail.gq1.yahoo.com> Message-ID: Albert-Jan Roskam wrote: > On Thu, 1/16/14, Peter Otten <__peter__ at web.de> wrote: >> class Foo(unittest.TestCase): >> @unique_receipt("foo") >> def test_t1(self, RECEIPT): >> pass > Very cool approach. Question, though: what would be wrong > with the following approach: > > > import unittest > > class Test(unittest.TestCase): > > receipts = {} > > def unique_value(self, k, v): > assert Test.receipts.get(k) is None, "Duplicate: %s" % v > Test.receipts[k] = v > > def test_a(self): > self.unique_value("large_value", "foo") Nothing. From python.list at tim.thechases.com Thu Jan 16 10:24:01 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Jan 2014 09:24:01 -0600 Subject: =?UTF-8?B?J1N0cmHDn2Un?= ('Strasse') and Python 2 In-Reply-To: <52d7e7be$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> <52d7e7be$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140116092401.4cada9ac@bigbox.christie.dr> On 2014-01-16 14:07, Steven D'Aprano wrote: > The unicode type in Python 2.x is less-good because: > > - it is missing some functionality, e.g. casefold; Just for the record, str.casefold() wasn't added until 3.3, so earlier 3.x versions (such as the 3.2.3 that is the default python3 on Debian Stable) don't have it either. -tkc From robert.kern at gmail.com Thu Jan 16 10:46:10 2014 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 16 Jan 2014 15:46:10 +0000 Subject: data validation when creating an object In-Reply-To: References: Message-ID: On 2014-01-16 04:05, Roy Smith wrote: > Rita writes: >>> I know its frowned upon to do work in the __init__() method and only >>> declarations should be there. > > > In article , > Ben Finney wrote: > >> Who says it's frowned on to do work in the initialiser? Where are they >> saying it? That seems over-broad, I'd like to read the context of that >> advice. > > Weird, I was just having this conversation at work earlier this week. > > There are some people who advocate that C++ constructors should not do a > lot of work and/or should be incapable of throwing exceptions. The pros > and cons of that argument are largely C++ specific. Here's a Stack > Overflow thread which covers most of the usual arguments on both sides: > > http://stackoverflow.com/questions/293967/how-much-work-should-be-done-in > -a-constructor > > But, Python is not C++. I suspect the people who argue for __init__() > not doing much are extrapolating a C++ pattern to other languages > without fully understanding the reason why. I'm one of those people who tends to argue this, but my limited experience with C++ does not inform my opinion one way or the other. I prefer to keep my __init__() methods as dumb as possible to retain the flexibility to construct my objects in different ways. Sure, it's convenient to, say, pass a filename and have the __init__() open() it for me. But then I'm stuck with only being able to create this object with a true, named file on disk. I can't create it with a StringIO for testing, or by opening a file and seeking to a specific spot where the relevant data starts, etc. I can keep the flexibility and convenience by keeping __init__() dumb and relegating various smarter and more convenient ways to instantiate the object to classmethods. Which isn't to say that "smart" or "heavy" __init__()s don't have their place for some kinds of objects. I just think that dumb __init__()s should be the default. That said, what the OP asks about, validating data in the __init__() is perfectly fine, IMO. My beef isn't so much with the raw *amount* of stuff done but how much you can code yourself into a corner by making limiting assumptions. So from one of the "do nothing in your __init__()" crowd, I say "well, I didn't really mean *nothing*...." > That being said, I've been on a tear lately, trying to get our unit test > suite to run faster. I came across one slow test which had an > interesting twist. The class being tested had an __init__() method > which read over 900,000 records from a database and took something like > 5-10 seconds to run. Man, talk about heavy-weight constructors :-) Indeed. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From roy at panix.com Thu Jan 16 11:18:39 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 08:18:39 -0800 (PST) Subject: data validation when creating an object In-Reply-To: References: Message-ID: <6a2d342e-78b6-45b5-a8b4-9c5767edc8b1@googlegroups.com> On Thursday, January 16, 2014 10:46:10 AM UTC-5, Robert Kern wrote: > I prefer to keep my __init__() methods as dumb as possible to retain the > flexibility to construct my objects in different ways. Sure, it's convenient to, > say, pass a filename and have the __init__() open() it for me. But then I'm > stuck with only being able to create this object with a true, named file on > disk. I can't create it with a StringIO for testing, or by opening a file and > seeking to a specific spot where the relevant data starts, etc. I can keep the > flexibility and convenience by keeping __init__() dumb and relegating various > smarter and more convenient ways to instantiate the object to classmethods. There's two distinct things being discussed here. The idea of passing a file-like object vs. a filename gives you flexibility, that's for sure. But, that's orthogonal to how much work should be done in the constructor. Consider this class: class DataSlurper: def __init__(self): self.slurpee = None def attach_slurpee(self, slurpee): self.slurpee = slurpee def slurp(self): for line in self.slurpee: # whatever This exhibits the nice behavior you describe; you can pass it any iterable, not just a file, so you have a lot more flexibility. But, it's also exhibiting what many people call the "two-phase constructor" anti-pattern. When you construct an instance of this class, it's not usable until you call attach_slurpee(), so why not just do that in the constructor? From roy at panix.com Thu Jan 16 11:29:36 2014 From: roy at panix.com (Roy Smith) Date: Thu, 16 Jan 2014 08:29:36 -0800 (PST) Subject: Is it possible to get string from function? In-Reply-To: References: Message-ID: <06aa0ac8-dc0c-4c6a-a001-6c97230e00a5@googlegroups.com> On Thursday, January 16, 2014 5:59:42 AM UTC-5, Albert-Jan Roskam wrote: > what would be wrong with the following approach: > > import unittest > class Test(unittest.TestCase): > > receipts = {} > > def unique_value(self, k, v): > assert Test.receipts.get(k) is None, "Duplicate: %s" % v > Test.receipts[k] = v > > def test_a(self): > self.unique_value("large_value", "foo") > > def test_b(self): > self.unique_value("large_value", "bar") # oh no, a duplicate! > > def test_c(self): > self.unique_value("another_large_value", "blah") Although I didn't state it in my original post, we run these tests under nose in multi-process mode. Each process would have its own copy of the receipts dictionary. Yes, I know I can force all the tests in a class to be in the same process, but these are some of the slower tests in our suite, so we *want* them to run in parallel. From skip at pobox.com Thu Jan 16 11:44:16 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 16 Jan 2014 10:44:16 -0600 Subject: data validation when creating an object In-Reply-To: References: Message-ID: I suspect when best to validate inputs depends on when they come in, and what the cost is of having objects with invalid state. If the input is something that is passed along when the object is instantiated, you kind of have to validate in __init__ or __new__, right? Let's create a stupid example: class Point(object): def __init__(self, coordinates): self.x, self.y, self.z = coordinates That's kind of self-validating. If you pass something that doesn't quack like a three-element sequence, the program will crash. OTOH, Point("abc") will appear to work until you expect x, y and z to act like numbers. If you can't tolerate that, then a __new__ method allows you to validate arguments before creating a new Point instance. You might also allow one- or two-element tuples: def __new__(cls, coordinates): ... convert to tuple, then ... ... verify that all elements are numbers, then ... if len(coordinates) > 3: raise ValueError("Expect 1-, 2-, or 3-element tuple") if len(coordinates) < 2: coordinates += (0.0,) if len(coordinates) < 3: coordinates += (0.0,) return cls(coordinates) Validating in __new__ will allow you to catch problems sooner, and give you the option of returning some sort of sentinel instead of just raising an exception, though that is probably not generally good practice. This will catch Point("abc") quickly, with a stack trace pointing to the offending code. Of course, you might need to validate any other inputs which appear after instantiation: def move(self, xdelta=0.0, ydelta=0.0, zdelta=0.0): self.x += xdelta self.y += ydelta self.z += zdelta Whether you need more feedback than an exception might give you here is debatable, but there are likely plenty of situations where you need to explicitly validate user input before using it (think of accepting string data from the net which you plan to feed to your SQL database...). Those sorts of validation steps are beyond the scope of this thread, and probably much better handled by platforms further up the software stack (like Django or SQLAlchemy). Skip From urtizvereaxaxa at gmail.com Thu Jan 16 11:49:57 2014 From: urtizvereaxaxa at gmail.com (Xaxa Urtiz) Date: Thu, 16 Jan 2014 08:49:57 -0800 (PST) Subject: Python glob and raw string Message-ID: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> Hello everybody, i've got a little problem, i've made a script which look after some files in some directory, typically my folder are organized like this : [share] folder1 ->20131201 -->file1.xml -->file2.txt ->20131202 -->file9696009.tmp -->file421378932.xml etc.... so basically in the share i've got some folder (=folder1,folder2.....) and inside these folder i've got these folder whose name is the date (20131201,20131202,20131203 etc...) and inside them i want to find all the xml files. So, what i've done is to iterate over all the folder1/2/3 that i want and look, for each one, the xml file with that: for f in glob.glob(dir +r"\20140115\*.xml"): ->yield f dir is the folder1/2/3 everything is ok but i want to do something like that : for i in range(10,16): ->for f in glob.glob(dir +r"\201401{0}\*.xml".format(i)): -->yield f but the glob does not find any file.... (and of course there is some xml and the old way found them...) Any help would be appreciate :) From robert.kern at gmail.com Thu Jan 16 11:58:03 2014 From: robert.kern at gmail.com (Robert Kern) Date: Thu, 16 Jan 2014 16:58:03 +0000 Subject: data validation when creating an object In-Reply-To: <6a2d342e-78b6-45b5-a8b4-9c5767edc8b1@googlegroups.com> References: <6a2d342e-78b6-45b5-a8b4-9c5767edc8b1@googlegroups.com> Message-ID: On 2014-01-16 16:18, Roy Smith wrote: > On Thursday, January 16, 2014 10:46:10 AM UTC-5, Robert Kern wrote: > >> I prefer to keep my __init__() methods as dumb as possible to retain the >> flexibility to construct my objects in different ways. Sure, it's convenient to, >> say, pass a filename and have the __init__() open() it for me. But then I'm >> stuck with only being able to create this object with a true, named file on >> disk. I can't create it with a StringIO for testing, or by opening a file and >> seeking to a specific spot where the relevant data starts, etc. I can keep the >> flexibility and convenience by keeping __init__() dumb and relegating various >> smarter and more convenient ways to instantiate the object to classmethods. > > There's two distinct things being discussed here. > > The idea of passing a file-like object vs. a filename gives you flexibility, that's for sure. But, that's orthogonal to how much work should be done in the constructor. Consider this class: Where the two get conflated is that both lead to advice that looks the same (or at least can get interpreted the same by newbies who are trying to learn and don't have the experience to pick out the subtleties): "do nothing in __init__". That's why I am trying to clarify where this advice might be coming from and why at least one version of it may be valid. > class DataSlurper: > def __init__(self): > self.slurpee = None > > def attach_slurpee(self, slurpee): > self.slurpee = slurpee > > def slurp(self): > for line in self.slurpee: > # whatever > > This exhibits the nice behavior you describe; you can pass it any iterable, not just a file, so you have a lot more flexibility. But, it's also exhibiting what many people call the "two-phase constructor" anti-pattern. When you construct an instance of this class, it's not usable until you call attach_slurpee(), so why not just do that in the constructor? That's where my recommendation of classmethods come in. The result of __init__() should always be usable. It's just that its arguments may not be as convenient as you like because you pass in objects that are closer to the internal representation than you normally want to deal with (e.g. file objects instead of filenames). You make additional constructors (initializers, whatever) as classmethods to restore convenience. class DataSlurper: def __init__(self, slurpee): self.slurpee = slurpee @classmethod def fromfile(cls, filename): slurpee = open(filename) return cls(slurpee) @classmethod def fromurl(cls, url): slurpee = urllib.urlopen(url) return cls(slurpee) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From breamoreboy at yahoo.co.uk Thu Jan 16 12:01:52 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 16 Jan 2014 17:01:52 +0000 Subject: Building and accessing an array of dictionaries In-Reply-To: References: Message-ID: On 16/01/2014 09:48, Chris Angelico wrote: > On Thu, Jan 16, 2014 at 8:41 PM, Sam wrote: >> I would like to build an array of dictionaries. Most of the dictionary example on the net are for single dictionary. >> >> dict = {'a':'a','b':'b','c':'c'} >> dict2 = {'a':'a','b':'b','c':'c'} >> dict3 = {'a':'a','b':'b','c':'c'} >> >> arr = (dict,dict2,dict3) >> >> What is the syntax to access the value of dict3->'a'? > > Technically, that's a tuple of dictionaries For the benefit of lurkers, newbies or whatever it's the commas that make the tuple, not the brackets. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From bjourne at gmail.com Thu Jan 16 13:01:51 2014 From: bjourne at gmail.com (=?ISO-8859-1?Q?Bj=F6rn_Lindqvist?=) Date: Thu, 16 Jan 2014 19:01:51 +0100 Subject: Guessing the encoding from a BOM In-Reply-To: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: 2014/1/16 Steven D'Aprano : > def guess_encoding_from_bom(filename, default): > with open(filename, 'rb') as f: > sig = f.read(4) > if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): > return 'utf_16' > elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): > return 'utf_32' > else: > return default You might want to add the utf8 bom too: '\xEF\xBB\xBF'. > (4) Don't return anything, but raise an exception. (But > which exception?) I like this option the most because it is the most "fail fast". If you return 'undefined' the error might happen hours later or not at all in some cases. -- mvh/best regards Bj?rn Lindqvist From urtizvereaxaxa at gmail.com Thu Jan 16 13:03:00 2014 From: urtizvereaxaxa at gmail.com (Xaxa Urtiz) Date: Thu, 16 Jan 2014 10:03:00 -0800 (PST) Subject: Python glob and raw string In-Reply-To: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> References: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> Message-ID: <1d76e596-fa6e-44c2-aefd-391788a4fd0d@googlegroups.com> Le jeudi 16 janvier 2014 17:49:57 UTC+1, Xaxa Urtiz a ?crit?: > Hello everybody, i've got a little problem, i've made a script which look after some files in some directory, typically my folder are organized like this : > > > > [share] > > folder1 > > ->20131201 > > -->file1.xml > > -->file2.txt > > ->20131202 > > -->file9696009.tmp > > -->file421378932.xml > > etc.... > > so basically in the share i've got some folder (=folder1,folder2.....) and inside these folder i've got these folder whose name is the date (20131201,20131202,20131203 etc...) and inside them i want to find all the xml files. > > So, what i've done is to iterate over all the folder1/2/3 that i want and look, for each one, the xml file with that: > > > > > > for f in glob.glob(dir +r"\20140115\*.xml"): > > ->yield f > > > > dir is the folder1/2/3 everything is ok but i want to do something like that : > > > > > > for i in range(10,16): > > ->for f in glob.glob(dir +r"\201401{0}\*.xml".format(i)): > > -->yield f > > > > but the glob does not find any file.... (and of course there is some xml and the old way found them...) > > Any help would be appreciate :) I feel stupid, my mistake, it works : for i in range(1,16): ->for f in glob.glob(dir +r"\201401{0:02}\*.xml".format(i)): -->yield f From rosuav at gmail.com Thu Jan 16 13:06:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 05:06:16 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 17, 2014 at 5:01 AM, Bj?rn Lindqvist wrote: > 2014/1/16 Steven D'Aprano : >> def guess_encoding_from_bom(filename, default): >> with open(filename, 'rb') as f: >> sig = f.read(4) >> if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): >> return 'utf_16' >> elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): >> return 'utf_32' >> else: >> return default > > You might want to add the utf8 bom too: '\xEF\xBB\xBF'. I'd actually rather not. It would tempt people to pollute UTF-8 files with a BOM, which is not necessary unless you are MS Notepad. ChrisA From neilc at norwich.edu Thu Jan 16 13:14:30 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 16 Jan 2014 18:14:30 +0000 (UTC) Subject: Python glob and raw string References: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> Message-ID: On 2014-01-16, Xaxa Urtiz wrote: > Hello everybody, i've got a little problem, i've made a script > which look after some files in some directory, typically my > folder are organized like this : > > [share] > folder1 > ->20131201 > -->file1.xml > -->file2.txt > ->20131202 > -->file9696009.tmp > -->file421378932.xml > etc.... > so basically in the share i've got some folder > (=folder1,folder2.....) and inside these folder i've got these > folder whose name is the date (20131201,20131202,20131203 > etc...) and inside them i want to find all the xml files. > So, what i've done is to iterate over all the folder1/2/3 that > i want and look, for each one, the xml file with that: > > for f in glob.glob(dir +r"\20140115\*.xml"): > ->yield f > > dir is the folder1/2/3 everything is ok but i want to do > something like that : > > for i in range(10,16): > ->for f in glob.glob(dir +r"\201401{0}\*.xml".format(i)): > -->yield f > > but the glob does not find any file.... (and of course there is > some xml and the old way found them...) > Any help would be appreciate :) I've done this two different ways. The simple way is very similar to what you are now doing. It sucks because I have to manually maintain the list of subdirectories to traverse every time I create a new subdir. Here's the other way, using glob and isdir from os.path, adapted from actual production code. class Miner: def __init__(self, archive): # setup goes here; prepare to acquire the data self.descend(os.path.join(archive, '*')) def descend(self, path): for fname in glob.glob(os.path.join(path, '*')): if os.path.isdir(fname): self.descend(fname) else: self.process(fname) def process(self, path): # Do what I want done with an actual file path. # This is where I add to the data. In your case you might not want to process unless the path also looks like an xml file. mine = Miner('myxmldir') Hmmm... I might be doing too much in __init__. ;) -- Neil Cerutti From rosuav at gmail.com Thu Jan 16 13:19:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 05:19:47 +1100 Subject: Python glob and raw string In-Reply-To: References: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> Message-ID: On Fri, Jan 17, 2014 at 5:14 AM, Neil Cerutti wrote: > class Miner: > def __init__(self, archive): > # setup goes here; prepare to acquire the data > self.descend(os.path.join(archive, '*')) > > def descend(self, path): > for fname in glob.glob(os.path.join(path, '*')): > if os.path.isdir(fname): > self.descend(fname) > else: > self.process(fname) > > def process(self, path): > # Do what I want done with an actual file path. > # This is where I add to the data. > > In your case you might not want to process unless the path also > looks like an xml file. > > mine = Miner('myxmldir') > > Hmmm... I might be doing too much in __init__. ;) Hmm, why is it even a class? :) I guess you elided all the stuff that makes it impractical to just use a non-class function. ChrisA From neilc at norwich.edu Thu Jan 16 13:45:49 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 16 Jan 2014 18:45:49 +0000 (UTC) Subject: Python glob and raw string References: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> Message-ID: On 2014-01-16, Chris Angelico wrote: >> Hmmm... I might be doing too much in __init__. ;) > > Hmm, why is it even a class? :) I guess you elided all the > stuff that makes it impractical to just use a non-class > function. I didn't remove anything that makes it obviously class-worthy, just timestamp checking, and several dicts and sets to store data. The original version of that code is just a set of three functions, but the return result of that version was a single dict. Once the return value got complicated enough to require building up a class instance, it became a convenient place to hang the functions. -- Neil Cerutti From python.list at tim.thechases.com Thu Jan 16 13:50:12 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Jan 2014 12:50:12 -0600 Subject: Guessing the encoding from a BOM In-Reply-To: References: <52d74063$0$29970$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140116125012.06b6ae5c@bigbox.christie.dr> On 2014-01-17 05:06, Chris Angelico wrote: > > You might want to add the utf8 bom too: '\xEF\xBB\xBF'. > > I'd actually rather not. It would tempt people to pollute UTF-8 > files with a BOM, which is not necessary unless you are MS Notepad. If the intent is to just sniff and parse the file accordingly, I get enough of these junk UTF-8 BOMs at $DAY_JOB that I've had to create utility-openers much like Steven is doing here. It's particularly problematic for me in combination with csv.DictReader, where I go looking for $COLUMN_NAME and get KeyError exceptions because it wants me to ask for $UTF_BOM+$COLUMN_NAME for the first column. -tkc From vasishtha.spier at gmail.com Thu Jan 16 14:11:52 2014 From: vasishtha.spier at gmail.com (Harry Spier) Date: Thu, 16 Jan 2014 11:11:52 -0800 Subject: Converting folders of jpegs to single pdf per folder Message-ID: Dear list members, I have a directory that contains about a hundred subdirectories named J0001,J0002,J0003 . . . etc. Each of these subdirectories contains about a hundred JPEGs named P001.jpg, P002.jpg, P003.jpg etc. I need to write a python script that will cycle thru each directory and convert ALL JPEGs in each directory into a single PDF file and save these PDF files (one per directory) to an output file. Any pointers on how to do this with a Python script would be appreciated. Reading on the internet it appears that using ImageMagick wouldn't work because of using too much memory. Can this be done using the Python Image Library or some other library? Any sample code would also be appreciated. Thanks, Harry Spier -------------- next part -------------- An HTML attachment was scrubbed... URL: From fomcl at yahoo.com Thu Jan 16 14:37:29 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Thu, 16 Jan 2014 11:37:29 -0800 (PST) Subject: Guessing the encoding from a BOM In-Reply-To: Message-ID: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> -------------------------------------------- On Thu, 1/16/14, Chris Angelico wrote: Subject: Re: Guessing the encoding from a BOM To: Cc: "python-list at python.org" Date: Thursday, January 16, 2014, 7:06 PM On Fri, Jan 17, 2014 at 5:01 AM, Bj?rn Lindqvist wrote: > 2014/1/16 Steven D'Aprano : >> def guess_encoding_from_bom(filename, default): >>? ???with open(filename, 'rb') as f: >>? ? ? ???sig = f.read(4) >>? ???if sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): >>? ? ? ???return 'utf_16' >>? ???elif sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): >>? ? ? ???return 'utf_32' >>? ???else: >>? ? ? ???return default > > You might want to add the utf8 bom too: '\xEF\xBB\xBF'. I'd actually rather not. It would tempt people to pollute UTF-8 files with a BOM, which is not necessary unless you are MS Notepad. ===> Can you elaborate on that? Unless your utf-8 files will only contain ascii characters I do not understand why you would not want a bom utf-8. Btw, isn't "read_encoding_from_bom" a better function name than "guess_encoding_from_bom"? I thought the point of BOMs was that there would be no more need to guess? Thanks! Albert-Jan From mail at timgolden.me.uk Thu Jan 16 14:41:04 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 16 Jan 2014 19:41:04 +0000 Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: References: Message-ID: <52D835D0.5010506@timgolden.me.uk> On 16/01/2014 19:11, Harry Spier wrote: > > Dear list members, > > I have a directory that contains about a hundred subdirectories named > J0001,J0002,J0003 . . . etc. > Each of these subdirectories contains about a hundred JPEGs named > P001.jpg, P002.jpg, P003.jpg etc. > > I need to write a python script that will cycle thru each directory and > convert ALL JPEGs in each directory into a single PDF file and save > these PDF files (one per directory) to an output file. > > Any pointers on how to do this with a Python script would be > appreciated. Reading on the internet it appears that using ImageMagick > wouldn't work because of using too much memory. Can this be done using > the Python Image Library or some other library? Any sample code would > also be appreciated. The usual go-to library for PDF generation is ReportLab. I haven't used it for a long while but I'm quite certain it would have no problem including images. Do I take it that it's the PDF-generation side of things you're asking about? Or do you need help iterating over hundreds of directories and files? TJG From vasishtha.spier at gmail.com Thu Jan 16 14:50:59 2014 From: vasishtha.spier at gmail.com (vasishtha.spier at gmail.com) Date: Thu, 16 Jan 2014 11:50:59 -0800 (PST) Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: References: Message-ID: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> On Thursday, January 16, 2014 11:41:04 AM UTC-8, Tim Golden wrote: > On 16/01/2014 19:11, Harry Spier wrote: > > > > > > Dear list members, > > > > > > I have a directory that contains about a hundred subdirectories named > > > J0001,J0002,J0003 . . . etc. > > > Each of these subdirectories contains about a hundred JPEGs named > > > P001.jpg, P002.jpg, P003.jpg etc. > > > > > > I need to write a python script that will cycle thru each directory and > > > convert ALL JPEGs in each directory into a single PDF file and save > > > these PDF files (one per directory) to an output file. > > > > > > Any pointers on how to do this with a Python script would be > > > appreciated. Reading on the internet it appears that using ImageMagick > > > wouldn't work because of using too much memory. Can this be done using > > > the Python Image Library or some other library? Any sample code would > > > also be appreciated. > > > > The usual go-to library for PDF generation is ReportLab. I haven't used > > it for a long while but I'm quite certain it would have no problem > > including images. > > > > Do I take it that it's the PDF-generation side of things you're asking > > about? Or do you need help iterating over hundreds of directories and files? > > > > TJG Its mostly the PDF generating side I need but I haven't yet used the Python directory and file traversing functions so an example of this would also be useful especially showing how I could capture the directory name and use that as the name of the pdf file I'm creating from the directory contents. Thanks again, Harry From breamoreboy at yahoo.co.uk Thu Jan 16 15:01:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 16 Jan 2014 20:01:17 +0000 Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> Message-ID: On 16/01/2014 19:50, vasishtha.spier at gmail.com wrote: > On Thursday, January 16, 2014 11:41:04 AM UTC-8, Tim Golden wrote: >> On 16/01/2014 19:11, Harry Spier wrote: >> >>> >> >>> Dear list members, >> >>> >> >>> I have a directory that contains about a hundred subdirectories named >> >>> J0001,J0002,J0003 . . . etc. >> >>> Each of these subdirectories contains about a hundred JPEGs named >> >>> P001.jpg, P002.jpg, P003.jpg etc. >> >>> >> >>> I need to write a python script that will cycle thru each directory and >> >>> convert ALL JPEGs in each directory into a single PDF file and save >> >>> these PDF files (one per directory) to an output file. >> >>> >> >>> Any pointers on how to do this with a Python script would be >> >>> appreciated. Reading on the internet it appears that using ImageMagick >> >>> wouldn't work because of using too much memory. Can this be done using >> >>> the Python Image Library or some other library? Any sample code would >> >>> also be appreciated. >> >> >> >> The usual go-to library for PDF generation is ReportLab. I haven't used >> >> it for a long while but I'm quite certain it would have no problem >> >> including images. >> >> >> >> Do I take it that it's the PDF-generation side of things you're asking >> >> about? Or do you need help iterating over hundreds of directories and files? >> >> >> >> TJG > > Its mostly the PDF generating side I need but I haven't yet used the Python directory and file traversing functions so an example of this would also be useful especially showing how I could capture the directory name and use that as the name of the pdf file I'm creating from the directory contents. > > Thanks again, > Harry > I'm sorry that I can't help with your problem, but would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mail at timgolden.me.uk Thu Jan 16 15:07:59 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 16 Jan 2014 20:07:59 +0000 Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> Message-ID: <52D83C1F.1020500@timgolden.me.uk> On 16/01/2014 19:50, vasishtha.spier at gmail.com wrote: > On Thursday, January 16, 2014 11:41:04 AM UTC-8, Tim Golden wrote: > The usual go-to library for PDF generation is ReportLab. I haven't used >> >> it for a long while but I'm quite certain it would have no problem >> >> including images. >> >> >> >> Do I take it that it's the PDF-generation side of things you're asking >> >> about? Or do you need help iterating over hundreds of directories and files? >> >> >> >> TJG > > Its mostly the PDF generating side I need but I haven't yet used the Python directory and file traversing functions so an example of this would also be useful especially showing how I could capture the directory name and use that as the name of the pdf file I'm creating from the directory contents. > > Thanks again, > Harry > Here's a quick example. (And, by the way, please try to avoid the sort of double-spacing above, especially if you're coming from Google Groups which tends to produce such effects). This should walk down the Python directory, creating a text file for each directory. The textfile will contain the names of all the files in the directory. (NB this might create a lot of text files so run it inside some temp directory). import os root = "c:/temp" for dirpath, dirnames, filenames in os.walk(root): print("Looking at", dirpath) txt_filename = os.path.basename(dirpath) + ".txt" with open(txt_filename, "w") as f: f.write("\n".join(filenames)) TJG From mail at timgolden.me.uk Thu Jan 16 15:12:01 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 16 Jan 2014 20:12:01 +0000 Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: <52D83C1F.1020500@timgolden.me.uk> References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> <52D83C1F.1020500@timgolden.me.uk> Message-ID: <52D83D11.6020700@timgolden.me.uk> On 16/01/2014 20:07, Tim Golden wrote: > This should walk down the Python directory, s/the Python directory/some directory/ (Sorry, I initially had it walking os.path.dirname(sys.executable)) TJG From vasishtha.spier at gmail.com Thu Jan 16 15:20:40 2014 From: vasishtha.spier at gmail.com (vasishtha.spier at gmail.com) Date: Thu, 16 Jan 2014 12:20:40 -0800 (PST) Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> <52D83C1F.1020500@timgolden.me.uk> Message-ID: <0ffbcdd6-05c7-46c7-b5b1-25c4069aa955@googlegroups.com> On Thursday, January 16, 2014 12:12:01 PM UTC-8, Tim Golden wrote: > On 16/01/2014 20:07, Tim Golden wrote: > > > This should walk down the Python directory, > s/the Python directory/some directory/ > (Sorry, I initially had it walking os.path.dirname(sys.executable)) > TJG Thanks Tim thats very helpful. Sorry about the double lines. For some reason I wasn't getting the posts directly in my email and was using Google Groups. I've changed my subscription parameters and hopefully I'll get the replies directly. Cheers, Harry From travisgriggs at gmail.com Thu Jan 16 16:30:00 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Thu, 16 Jan 2014 13:30:00 -0800 Subject: =?windows-1252?Q?Re=3A_=27Stra=DFe=27_=28=27Strasse=27=29_and_Py?= =?windows-1252?Q?thon_2?= In-Reply-To: <52D7B9BE.9020001@chamonix.reportlab.co.uk> References: <30dfa6f1-61b2-49b8-bc65-5fd18d498c38@googlegroups.com> <52D67873.2010502@chamonix.reportlab.co.uk> <5d820037-44ad-4d8d-bb1b-4fb812fc876b@googlegroups.com> <52d72898$0$29970$c3e8da3$5496439d@news.astraweb.com> <52D7B9BE.9020001@chamonix.reportlab.co.uk> Message-ID: On Jan 16, 2014, at 2:51 AM, Robin Becker wrote: > I assure you that I fully understand my ignorance of ... Robin, don?t take this personally, I totally got what you meant. At the same time, I got a real chuckle out of this line. That beats ?army intelligence? any day. From naccttemha at gmail.com Thu Jan 16 17:24:40 2014 From: naccttemha at gmail.com (Nac Temha) Date: Fri, 17 Jan 2014 00:24:40 +0200 Subject: Python solve problem with string operation Message-ID: Hi everyone, I want to do operation with chars in the given string. Actually I want to grouping the same chars. For example; input : "344111133311222223377" operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) output: "34131237" How can I do without list, regular expression. just using string operations. Using an effective methods of python for this problem. Thanks, Best regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gordon at panix.com Thu Jan 16 17:30:27 2014 From: gordon at panix.com (John Gordon) Date: Thu, 16 Jan 2014 22:30:27 +0000 (UTC) Subject: Python solve problem with string operation References: Message-ID: In Nac Temha writes: > --047d7b6d95d0367a3d04f01de490 > Content-Type: text/plain; charset=ISO-8859-1 > Hi everyone, > I want to do operation with chars in the given string. Actually I want to > grouping the same chars. > For example; > input : "344111133311222223377" > operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) > output: "34131237" input = "344111133311222223377" output = [] previous_ch = None for ch in input: if ch != previous_ch: output.append(ch) previous_ch = ch print ''.join(output) -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From python.list at tim.thechases.com Thu Jan 16 17:44:56 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 16 Jan 2014 16:44:56 -0600 Subject: Python solve problem with string operation In-Reply-To: References: Message-ID: <20140116164456.1e21b687@bigbox.christie.dr> On 2014-01-17 00:24, Nac Temha wrote: > Hi everyone, > > I want to do operation with chars in the given string. Actually I > want to grouping the same chars. > > For example; > > input : "344111133311222223377" > operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) > output: "34131237" > > How can I do without list, regular expression. just using string > operations. Using an effective methods of python for this problem. I'm not sure what constitutes "just using string operations", but it's quite simple with stdlib tools: >>> from itertools import groupby >>> ''.join(k for k,v in groupby("344111133311222223377")) '34131237' -tkc From breamoreboy at yahoo.co.uk Thu Jan 16 17:48:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 16 Jan 2014 22:48:50 +0000 Subject: Python solve problem with string operation In-Reply-To: References: Message-ID: On 16/01/2014 22:30, John Gordon wrote: > In Nac Temha writes: > >> --047d7b6d95d0367a3d04f01de490 >> Content-Type: text/plain; charset=ISO-8859-1 > >> Hi everyone, > >> I want to do operation with chars in the given string. Actually I want to >> grouping the same chars. > >> For example; > >> input : "344111133311222223377" >> operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) >> output: "34131237" > > input = "344111133311222223377" > output = [] > previous_ch = None > for ch in input: > if ch != previous_ch: > output.append(ch) > previous_ch = ch > print ''.join(output) > Cheat, you've used a list :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From gordon at panix.com Thu Jan 16 17:58:44 2014 From: gordon at panix.com (John Gordon) Date: Thu, 16 Jan 2014 22:58:44 +0000 (UTC) Subject: Python solve problem with string operation References: Message-ID: In Mark Lawrence writes: > > input = "344111133311222223377" > > output = [] > > previous_ch = None > > for ch in input: > > if ch != previous_ch: > > output.append(ch) > > previous_ch = ch > > print ''.join(output) > > > Cheat, you've used a list :) Ack! I missed that the OP doesn't want to use lists. Well, let's try this instead: import sys input = "344111133311222223377" previous_ch = None for ch in input: if ch != previous_ch: sys.stdout.write(ch) previous_ch = ch sys.stdout.write('\n') -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From tjreedy at udel.edu Thu Jan 16 18:09:20 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Jan 2014 18:09:20 -0500 Subject: Unicode strings as arguments to exceptions In-Reply-To: <20140116123408.GA5524@doriath.local> References: <20140116123408.GA5524@doriath.local> Message-ID: On 1/16/2014 7:34 AM, Ernest Adrogu? wrote: > Hi, > > There seems to be some inconsistency in the way exceptions handle Unicode > strings. For instance, KeyError seems to not have a problem with them > >>>> raise KeyError('a') > Traceback (most recent call last): > File "", line 1, in > KeyError: 'a' >>>> raise KeyError(u'?') > Traceback (most recent call last): > File "", line 1, in > KeyError: u'\xe4' > > On the other hand ValueError doesn't print anything. > >>>> raise ValueError('a') > Traceback (most recent call last): > File "", line 1, in > ValueError: a >>>> raise ValueError(u'?') > Traceback (most recent call last): > File "", line 1, in > ValueError > > I'm using Python 2.7.6 on a Unix machine. Fixed at some point in 3.x. In 3.4b2: >>> ValueError(b'a') ValueError(b'a',) >>> ValueError('a') ValueError('a',) -- Terry Jan Reedy From tjreedy at udel.edu Thu Jan 16 18:48:00 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Jan 2014 18:48:00 -0500 Subject: Unicode strings as arguments to exceptions In-Reply-To: <52d7e9a0$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52d7e9a0$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/16/2014 9:16 AM, Steven D'Aprano wrote: > On Thu, 16 Jan 2014 13:34:08 +0100, Ernest Adrogu? wrote: > >> Hi, >> >> There seems to be some inconsistency in the way exceptions handle >> Unicode strings. > > Yes. I believe the problem lies in the __str__ method. For example, > KeyError manages to handle Unicode, although in an ugly way: > > py> str(KeyError(u'?')) > "u'\\xe4'" > > Hence: > > py> raise KeyError(u'?') > Traceback (most recent call last): > File "", line 1, in > KeyError: u'\xe4' > > > While ValueError assumes ASCII and fails: > > py> str(ValueError(u'?')) > Traceback (most recent call last): > File "", line 1, in > UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in > position 0: ordinal not in range(128) > > When displaying the traceback, the error is suppressed, hence: > > py> raise ValueError(u'?') > Traceback (most recent call last): > File "", line 1, in > ValueError > > I believe this might be accepted as a bug report on ValueError. Or a change might be rejected as a feature change or as a bugfix that might break existing code. We do change exception messages in new versions but do not normally do so in bugfix releases. http://bugs.python.org/issue1012952 is related but different. The issue there was that unicode(ValueError(u'?')) gave the same UnicodeEncodeError as str(ValueError(u'?')). That was fixed by giving exceptions a __unicode__ method, but that did not fix the traceback display issue above. http://bugs.python.org/issue6108 unicode(exception) and str(exception) should return the same message also seems related. The issue was raised what str should do if the unicode message had non-ascii chars. I did not read enough to find an answer. The same question would arise here. -- Terry Jan Reedy From rosuav at gmail.com Thu Jan 16 19:14:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 11:14:17 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> Message-ID: On Fri, Jan 17, 2014 at 6:37 AM, Albert-Jan Roskam wrote: > Can you elaborate on that? Unless your utf-8 files will only contain ascii characters I do not understand why you would not want a bom utf-8. It's completely unnecessary, and could cause problems (the BOM is actually whitespace, albeit zero-width, so it could effectively indent the first line of your source code). UTF-8 specifies the byte order as part of the protocol, so you don't need to mark it. ChrisA From pecore at pascolo.net Thu Jan 16 19:17:12 2014 From: pecore at pascolo.net (giacomo boffi) Date: Fri, 17 Jan 2014 01:17:12 +0100 Subject: Python solve problem with string operation References: Message-ID: <87eh47a2d3.fsf@pascolo.net> Nac Temha writes: > Hi everyone, > > I want to do operation with chars in the given string. Actually I want to > grouping the same chars. > > For example; > > input : "344111133311222223377" > operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) > output: "34131237" > > > > How can I do without list, regular expression. just using string operations. > Using an effective methods of python for this problem. % cat a.py def f(s,n): if s[n+1] == s[n]: return s[:n]+s[n+1:], n return s, n+1 i = "344111133311222223377" n = 0 while n+1 != len(i): i, n = f(i, n) print i % python a.py 34131237 % -- your instructor is a mean person From denismfmcmahon at gmail.com Thu Jan 16 19:30:16 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 17 Jan 2014 00:30:16 +0000 (UTC) Subject: Python solve problem with string operation References: Message-ID: On Fri, 17 Jan 2014 00:24:40 +0200, Nac Temha wrote: > Hi everyone, > > I want to do operation with chars in the given string. Actually I want > to grouping the same chars. > > For example; > > input : "344111133311222223377" > operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) > output: "34131237" > How can I do without list, regular expression. just using string > operations. Using an effective methods of python for this problem. You can do it on one line, but it looks really messy: output = ''.join([{x:input[x]for x in range(len(input))}[x]for x in range (len({x:input[x]for x in range(len(input))}))if(x==0 or {x:input[x]for x in range(len(input))}[x-1]!={x:input[x]for x in range(len(input))}[x])]) It looks much better if you do it in steps: a = {x:input[x]for x in range(len(input))} b = [a[n]for n in range(len(a))if(n==0 or a[n-1]!=a[n])]) output = ''.join(b) If you really want to do it using just 'string' ops: for i in range(len(input)): if (i==0): output=input[0] elif input[i]!=input[i-1]: output+=input[i] -- Denis McMahon, denismfmcmahon at gmail.com From pecore at pascolo.net Thu Jan 16 19:38:02 2014 From: pecore at pascolo.net (giacomo boffi) Date: Fri, 17 Jan 2014 01:38:02 +0100 Subject: Python solve problem with string operation References: <87eh47a2d3.fsf@pascolo.net> Message-ID: <877g9za1ed.fsf@pascolo.net> giacomo boffi writes: > % python a.py > 34131237 % cat a.py i="344111133311222223377";n=0 while n+1!=len(i):i,n=(i[:n]+i[n+1:],n) if i[n+1]==i[n] else (i,n+1) print i % python a.py 34131237 % -- for Nikos From lightaiyee at gmail.com Thu Jan 16 19:58:48 2014 From: lightaiyee at gmail.com (Sam) Date: Thu, 16 Jan 2014 16:58:48 -0800 (PST) Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? Message-ID: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> I would like to protect my python source code. It need not be foolproof as long as it adds inconvenience to pirates. Is it possible to protect python source code by compiling it to .pyc or .pyo? Does .pyo offer better protection? From tjreedy at udel.edu Thu Jan 16 20:00:07 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Jan 2014 20:00:07 -0500 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 12/6/2013 8:35 PM, Terry Reedy wrote: > On 12/6/2013 12:03 PM, Mark Lawrence wrote: >> Is it just me, or is this basically useless? >> >> >>> help(object) >> Help on class object in module builtins: >> >> class object >> | The most base type > > Given that this can be interpreted as 'least desirable', it could > definitely be improved. > >> Surely a few more words, > > How about something like. > > '''The default top superclass for all Python classes. > > Its methods are inherited by all classes unless overriden. > ''' > > When you have 1 or more concrete suggestions for the docstring, open a > tracker issue. At Mark's invitation, I have done so. http://bugs.python.org/issue20285 -- Terry Jan Reedy From lightaiyee at gmail.com Thu Jan 16 20:01:51 2014 From: lightaiyee at gmail.com (Sam) Date: Thu, 16 Jan 2014 17:01:51 -0800 (PST) Subject: Compiling main script into .pyc Message-ID: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> One thing I observe about python byte-code compiling is that the main script does not gets compiled into .pyc. Only imported modules are compiled into .pyc. May I know how can I compile the main script into .pyc? It is to inconvenience potential copy-cats. From lightaiyee at gmail.com Thu Jan 16 20:03:24 2014 From: lightaiyee at gmail.com (Sam) Date: Thu, 16 Jan 2014 17:03:24 -0800 (PST) Subject: Process datafeed in one MySql table and output to another MySql table Message-ID: I have a datafeed which is constantly sent to a MySql table. The table grows constantly as the data feeds in. I would like to write a python script which process the data in this table and output the processed data to another table in another MySql database in real-time. Which are the python libraries which are suitable for this purpose? Are there any useful sample code or project on the web that I can use as reference? Thank you. From ned at nedbatchelder.com Thu Jan 16 20:07:04 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 16 Jan 2014 20:07:04 -0500 Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? In-Reply-To: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: On 1/16/14 7:58 PM, Sam wrote: > I would like to protect my python source code. It need not be foolproof as long as it adds inconvenience to pirates. > > Is it possible to protect python source code by compiling it to .pyc or .pyo? Does .pyo offer better protection? > First, .pyc and .pyo are nearly identical: they are bytecode. The only difference is that .pyo has been "optimized", which in this case simply means that the docstrings and asserts are gone. It is not difficult to see what a Python program does by looking at the bytecode, and the standard library includes the dis module for disassembling it. How to protect your code depends an awful lot on what kinds of secrets are in the code, and how valuable those secrets are, and therefore how hard someone will work to get at them. -- Ned Batchelder, http://nedbatchelder.com From ben+python at benfinney.id.au Thu Jan 16 20:07:26 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 17 Jan 2014 12:07:26 +1100 Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: <7w61pjbelt.fsf@benfinney.id.au> Sam writes: > I would like to protect my python source code. Protect it from what? If there's some specific activity you want to prevent or restrict, please say what it is, since ?protect? is a rather loaded term. > It need not be foolproof as long as it adds inconvenience to pirates. I doubt your software will be at risk from pirates, which are raiders on the high seas. If you mean something more specific, please explain, because ?pirate? is an even more loaded term that doesn't explain. -- \ ?Instead of a trap door, what about a trap window? The guy | `\ looks out it, and if he leans too far, he falls out. Wait. I | _o__) guess that's like a regular window.? ?Jack Handey | Ben Finney From rosuav at gmail.com Thu Jan 16 20:09:51 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 12:09:51 +1100 Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? In-Reply-To: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: On Fri, Jan 17, 2014 at 11:58 AM, Sam wrote: > I would like to protect my python source code. It need not be foolproof as long as it adds inconvenience to pirates. > > Is it possible to protect python source code by compiling it to .pyc or .pyo? Does .pyo offer better protection? > The only difference between pyo and pyc is that the former is with optimization done. And neither of them offers any real security. Even if you compiled it down to machine code, you wouldn't do much to deter pirates. All you'd do is make it so they have to take your code as a whole instead of piece-meal. Fighting against piracy using technology is pretty much guaranteed to be a losing battle. How much time and effort can you put in, versus the whole rest of the world? And how much harassment will you permit on your legitimate users in order to slow down a few who want to rip you off? I've seen some programs - usually games - that put lots and lots of checks in (checksumming the program periodically and crashing if it's wrong, "calling home" and making sure the cryptographic hash of the binary matches what's on the server, etc, etc)... and they still get cracked within the first day. And then legitimate purchasers like me have to deal with the stupidities (single-player games calling home??), to the extent that it's actually more convenient to buy the game and then install a cracked version from a torrent, than to install the version you bought. And there's one particular game where I've done exactly that. It's just way too much fiddliness to try to make the legit version work. Distribute your code with a copyright notice, accept that a few people will rip you off, and have done with it. ChrisA From rhodri at wildebst.org.uk Thu Jan 16 20:05:41 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Fri, 17 Jan 2014 01:05:41 -0000 Subject: Python solve problem with string operation References: Message-ID: On Thu, 16 Jan 2014 22:24:40 -0000, Nac Temha wrote: > Hi everyone, > > I want to do operation with chars in the given string. Actually I want to > grouping the same chars. > > For example; > > input : "344111133311222223377" > operation-> (3)(44)(1111)(333)(11)(22222)(33)(77) > output: "34131237" > > > > How can I do without list, regular expression. just using string > operations. Using an effective methods of python for this problem. I almost convinced myself this was homework, you know. A hint as to why you might want such a thing would look a lot less suspicious :-) The simplest way to do this is probably using groupby: from itertools import groupby input = "344111133311222223377" output = "".join(k for k, _ in groupby(s)) print output -- Rhodri James *-* Wildebeest Herder to the Masses From steve+comp.lang.python at pearwood.info Thu Jan 16 20:18:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2014 01:18:39 GMT Subject: Guessing the encoding from a BOM References: Message-ID: <52d884ee$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 11:37:29 -0800, Albert-Jan Roskam wrote: > -------------------------------------------- On Thu, 1/16/14, Chris > Angelico wrote: > > Subject: Re: Guessing the encoding from a BOM To: > Cc: "python-list at python.org" Date: Thursday, > January 16, 2014, 7:06 PM > > On Fri, Jan 17, 2014 at 5:01 AM, > Bj?rn Lindqvist > wrote: > > 2014/1/16 Steven D'Aprano : > >> def guess_encoding_from_bom(filename, default): > >>? ???with open(filename, 'rb') > as f: > >>? ? ? ???sig = > f.read(4) > >>? ???if > sig.startswith((b'\xFE\xFF', b'\xFF\xFE')): > >>? ? ? ???return > 'utf_16' > >>? ???elif > sig.startswith((b'\x00\x00\xFE\xFF', b'\xFF\xFE\x00\x00')): > >>? ? ? ???return > 'utf_32' > >>? ???else: > >>? ? ? ???return > default > > > > You might want to add the utf8 bom too: > '\xEF\xBB\xBF'. > > I'd actually rather not. It would tempt people to pollute UTF-8 files > with a BOM, which is not necessary unless you are MS Notepad. > > > ===> Can you elaborate on that? Unless your utf-8 files will only > contain ascii characters I do not understand why you would not want a > bom utf-8. Because the UTF-8 signature -- it's not actually a Byte Order Mark -- is not really necessary. Unlike UTF-16 and UTF-32, there is no platform dependent ambiguity between Big Endian and Little Endian systems, so the UTF-8 stream of bytes is identical no matter what platform you are on. If the UTF-8 signature was just unnecessary, it wouldn't be too bad, but it's actually harmful. Pure-ASCII text encoded as UTF-8 is still pure ASCII, and so backwards compatible with old software that assumes ASCII. But the same pure-ASCII text encoded as UTF-8 with a signature looks like a binary file. > Btw, isn't "read_encoding_from_bom" a better function name than > "guess_encoding_from_bom"? I thought the point of BOMs was that there > would be no more need to guess? Of course it's a guess. If you see a file that starts with 0000FFFE, is that a UTF-32 text file, or a binary file that happens to start with two nulls followed by FFFE? -- Steven From ethan at stoneleaf.us Thu Jan 16 20:21:38 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 16 Jan 2014 17:21:38 -0800 Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? In-Reply-To: References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: <52D885A2.3070605@stoneleaf.us> On 01/16/2014 05:09 PM, Chris Angelico wrote: > On Fri, Jan 17, 2014 at 11:58 AM, Sam wrote: >> I would like to protect my python source code. It need not be foolproof as long as it adds inconvenience to pirates. >> >> Is it possible to protect python source code by compiling it to .pyc or .pyo? Does .pyo offer better protection? No and no. > Distribute your code with a copyright notice, accept that a few people > will rip you off, and have done with it. Yes. One of the nice things about Python is being able to fix bugs myself [1]. -- ~Ethan~ [1] Yes, I file upstream bug reports. :) From tim at thechases.com Thu Jan 16 20:40:05 2014 From: tim at thechases.com (Tim Chase) Date: Thu, 16 Jan 2014 19:40:05 -0600 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> Message-ID: <20140116194005.387a9125@bigbox.christie.dr> On 2014-01-17 11:14, Chris Angelico wrote: > UTF-8 specifies the byte order > as part of the protocol, so you don't need to mark it. You don't need to mark it when writing, but some idiots use it anyway. If you're sniffing a file for purposes of reading, you need to look for it and remove it from the actual data that gets returned from the file--otherwise, your data can see it as corruption. I end up with lots of CSV files from customers who have polluted it with Notepad or had Excel insert some UTF-8 BOM when exporting. This means my first column-name gets the BOM prefixed onto it when the file is passed to csv.DictReader, grr. -tkc From roegltd at gmail.com Thu Jan 16 20:36:42 2014 From: roegltd at gmail.com (Asaf Las) Date: Thu, 16 Jan 2014 17:36:42 -0800 (PST) Subject: Python solve problem with string operation In-Reply-To: References: Message-ID: <46ac774f-02c7-4dc7-993e-9880b22cbb73@googlegroups.com> inpu = "344111133311222223377" tstr = inpu[0] for k in range(1, len(inpu)): if inpu[k] != inpu[k-1] : tstr = tstr + inpu[k] print(tstr) From denismfmcmahon at gmail.com Thu Jan 16 21:07:58 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Fri, 17 Jan 2014 02:07:58 +0000 (UTC) Subject: Process datafeed in one MySql table and output to another MySql table References: Message-ID: On Thu, 16 Jan 2014 17:03:24 -0800, Sam wrote: > I have a datafeed which is constantly sent to a MySql table ... > Which are the python libraries which are suitable for this purpose? Are > there any useful sample code or project on the web that I can use as > reference? Did you search for mysql on the python docs website, or perhaps try googling "python mysql"? -- Denis McMahon, denismfmcmahon at gmail.com From jsf80238 at gmail.com Thu Jan 16 21:23:12 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Thu, 16 Jan 2014 19:23:12 -0700 Subject: Process datafeed in one MySql table and output to another MySql table In-Reply-To: References: Message-ID: > > I have a datafeed which is constantly sent to a MySql table. The table > grows constantly as the data feeds in. I would like to write a python > script which process the data in this table and output the processed data > to another table in another MySql database in real-time. > > Which are the python libraries which are suitable for this purpose? Are > there any useful sample code or project on the web that I can use as > reference? Thank you. > Is there a reason you do not want to move these rows with a mysql command? drop table if exists temp; insert into temp select * from source where ...; insert into target select * from temp; delete from source where id in (select id from temp); -------------- next part -------------- An HTML attachment was scrubbed... URL: From bgailer at gmail.com Thu Jan 16 21:56:02 2014 From: bgailer at gmail.com (bob gailer) Date: Thu, 16 Jan 2014 21:56:02 -0500 Subject: Compiling main script into .pyc In-Reply-To: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> Message-ID: <52D89BC2.4000602@gmail.com> On 1/16/2014 8:01 PM, Sam wrote: > One thing I observe about python byte-code compiling is that the main script does not gets compiled into .pyc. Only imported modules are compiled into .pyc. > > May I know how can I compile the main script into .pyc? Duh? Just import it! From ned at nedbatchelder.com Thu Jan 16 22:07:44 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 16 Jan 2014 22:07:44 -0500 Subject: Compiling main script into .pyc In-Reply-To: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> Message-ID: On 1/16/14 8:01 PM, Sam wrote: > One thing I observe about python byte-code compiling is that the main script does not gets compiled into .pyc. Only imported modules are compiled into .pyc. > > May I know how can I compile the main script into .pyc? It is to inconvenience potential copy-cats. > The standard library has the compileall module that can be used to create .pyc files from .py files, but as we've been discussing in another thread, you may not want .pyc files. -- Ned Batchelder, http://nedbatchelder.com From python at mrabarnett.plus.com Thu Jan 16 22:19:31 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Jan 2014 03:19:31 +0000 Subject: Compiling main script into .pyc In-Reply-To: <52D89BC2.4000602@gmail.com> References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> <52D89BC2.4000602@gmail.com> Message-ID: <52D8A143.4010206@mrabarnett.plus.com> On 2014-01-17 02:56, bob gailer wrote: > On 1/16/2014 8:01 PM, Sam wrote: >> One thing I observe about python byte-code compiling is that the main script does not gets compiled into .pyc. Only imported modules are compiled into .pyc. >> >> May I know how can I compile the main script into .pyc? > Duh? Just import it! > What if you want to just compile it? Importing will run it! From davea at davea.name Thu Jan 16 23:43:02 2014 From: davea at davea.name (Dave Angel) Date: Thu, 16 Jan 2014 23:43:02 -0500 (EST) Subject: Compiling main script into .pyc References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> <52D89BC2.4000602@gmail.com> <52D8A143.4010206@mrabarnett.plus.com> Message-ID: MRAB Wrote in message: > On 2014-01-17 02:56, bob gailer wrote: >> On 1/16/2014 8:01 PM, Sam wrote: >>> One thing I observe about python byte-code compiling is that the main script does not gets compiled into .pyc. Only imported modules are compiled into .pyc. >>> >>> May I know how can I compile the main script into .pyc? >> Duh? Just import it! >> > What if you want to just compile it? Importing will run it! > > Importing will only run the portion of the code not protected by if __name__ == "__main__": -- DaveA From tjreedy at udel.edu Thu Jan 16 23:45:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 16 Jan 2014 23:45:41 -0500 Subject: Compiling main script into .pyc In-Reply-To: <52D8A143.4010206@mrabarnett.plus.com> References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> <52D89BC2.4000602@gmail.com> <52D8A143.4010206@mrabarnett.plus.com> Message-ID: On 1/16/2014 10:19 PM, MRAB wrote: > On 2014-01-17 02:56, bob gailer wrote: >> On 1/16/2014 8:01 PM, Sam wrote: >>> One thing I observe about python byte-code compiling is that the main >>> script does not gets compiled into .pyc. Only imported modules are >>> compiled into .pyc. >>> >>> May I know how can I compile the main script into .pyc? >> Duh? Just import it! >> > What if you want to just compile it? Importing will run it! Write the main script as def main(): ... if __name__ == '__main__': main() The difference between merely compiling 'def main' and executing it is trivial. Or don't bother compiling and write main.py as one line: from realmain import start; start() -- Terry Jan Reedy From rustompmody at gmail.com Fri Jan 17 00:08:23 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 16 Jan 2014 21:08:23 -0800 (PST) Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> Message-ID: <32c1b684-1ff7-48c0-af7a-cd15235ea531@googlegroups.com> On Friday, January 17, 2014 7:10:05 AM UTC+5:30, Tim Chase wrote: > On 2014-01-17 11:14, Chris Angelico wrote: > > UTF-8 specifies the byte order > > as part of the protocol, so you don't need to mark it. > You don't need to mark it when writing, but some idiots use it > anyway. If you're sniffing a file for purposes of reading, you need > to look for it and remove it from the actual data that gets returned > from the file--otherwise, your data can see it as corruption. I end > up with lots of CSV files from customers who have polluted it with > Notepad or had Excel insert some UTF-8 BOM when exporting. This > means my first column-name gets the BOM prefixed onto it when the > file is passed to csv.DictReader, grr. And its part of the standard: Table 2.4 here http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf From steve+comp.lang.python at pearwood.info Fri Jan 17 00:11:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2014 05:11:18 GMT Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: <52d8bb75$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 16:58:48 -0800, Sam wrote: > I would like to protect my python source code. It need not be foolproof > as long as it adds inconvenience to pirates. What makes you think that "pirates" will be the least bit interested in your code? No offence intended, I'm sure you worked really, really hard to write it, but the internet has hundreds of gigabytes of free and open source software which is easily and legally available, not to mention easily available (legally or not) non-free software at a relatively cheap price. Chances are that your biggest problem will not be piracy, but getting anyone to care or even notice that your program exists. > Is it possible to protect python source code by compiling it to .pyc or > .pyo? Does .pyo offer better protection? Compiling to .pyc or .pyo will not give any protection from software piracy, since they can just copy the .pyc or .pyo file. It will give a tiny bit of protection from people reading your code, but any competent Python programmer ought to be able to use the dis module to read the byte code. Perhaps if you explain what your program is, and why you think it needs protection, we can give you some concrete advice. -- Steven From vasishtha.spier at gmail.com Fri Jan 17 00:42:17 2014 From: vasishtha.spier at gmail.com (vasishtha.spier at gmail.com) Date: Thu, 16 Jan 2014 21:42:17 -0800 (PST) Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> Message-ID: <96cfad0d-143f-4084-827f-a67006bf6db2@googlegroups.com> On Thursday, January 16, 2014 12:07:59 PM UTC-8, Tim Golden wrote: > > Here's a quick example. > This should walk down the Python directory, creating a text file for > each directory. The textfile will contain the names of all the files in > the directory. (NB this might create a lot of text files so run it > inside some temp directory). > > import os > root = "c:/temp" > for dirpath, dirnames, filenames in os.walk(root): > print("Looking at", dirpath) > txt_filename = os.path.basename(dirpath) + ".txt" > with open(txt_filename, "w") as f: > f.write("\n".join(filenames) > > TJG Thanks Tim. It worked like a charm and saved me weeks of work using a drag and drop utility. About 250 pdf files created of 50 to 100 pages each. Heres the code in case any one else can use it. ---------------- import os from reportlab.pdfgen import canvas from reportlab.lib.utils import ImageReader root = "C:\\Users\\Harry\\" try: n = 0 for dirpath, dirnames, filenames in os.walk(root): PdfOutputFileName = os.path.basename(dirpath) + ".pdf" c = canvas.Canvas(PdfOutputFileName) if n > 0 : for filename in filenames: LowerCaseFileName = filename.lower() if LowerCaseFileName.endswith(".jpg"): print(filename) filepath = os.path.join(dirpath, filename) print(filepath) im = ImageReader(filepath) imagesize = im.getSize() c.setPageSize(imagesize) c.drawImage(filepath,0,0) c.showPage() c.save() n = n + 1 print "PDF of Image directory created" + PdfOutputFileName except: print "Failed creating PDF" ------------------------- From cyclebelfast at gmail.com Fri Jan 17 01:07:07 2014 From: cyclebelfast at gmail.com (gmflanagan) Date: Thu, 16 Jan 2014 22:07:07 -0800 (PST) Subject: extracting string.Template substitution placeholders In-Reply-To: References: Message-ID: <075b7403-a7cb-42bd-9ae9-ff3e3f3844a5@googlegroups.com> On Sunday, January 12, 2014 3:08:31 PM UTC, Eric S. Johansson wrote: > As part of speech recognition accessibility tools that I'm building, I'm > > using string.Template. In order to construct on-the-fly grammar, I need > > to know all of the identifiers before the template is filled in. what is > > the best way to do this? > Try this: import string cmplxstr="""a simple $string a longer $string a $last line ${another} one""" def finditer(s): for match in string.Template.pattern.finditer(s): arg = match.group('braced') or match.group('named') if arg: yield arg if __name__ == '__main__': print set(finditer(cmplxstr)) From steve+comp.lang.python at pearwood.info Fri Jan 17 03:40:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2014 08:40:41 GMT Subject: Compiling main script into .pyc References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> <52D89BC2.4000602@gmail.com> <52D8A143.4010206@mrabarnett.plus.com> Message-ID: <52d8ec89$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 16 Jan 2014 23:43:02 -0500, Dave Angel wrote: > MRAB Wrote in message: >> On 2014-01-17 02:56, bob gailer wrote: >>> On 1/16/2014 8:01 PM, Sam wrote: >>>> One thing I observe about python byte-code compiling is that the main >>>> script does not gets compiled into .pyc. Only imported modules are >>>> compiled into .pyc. >>>> >>>> May I know how can I compile the main script into .pyc? >>> Duh? Just import it! >>> >> What if you want to just compile it? Importing will run it! >> >> >> > Importing will only run the portion of the code not protected by > > if __name__ == "__main__": Nevertheless, there is no need to run *any* of the code just to compile it. [steve at ando ~]$ cat sample.py print("Hello!") [steve at ando ~]$ ls sample.pyc ls: sample.pyc: No such file or directory [steve at ando ~]$ python -m compileall sample.py Compiling sample.py ... [steve at ando ~]$ ls sample.p* sample.py sample.pyc [steve at ando ~]$ python sample.pyc Hello! -- Steven From mail at timgolden.me.uk Fri Jan 17 03:53:21 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 17 Jan 2014 08:53:21 +0000 Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: <96cfad0d-143f-4084-827f-a67006bf6db2@googlegroups.com> References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> <96cfad0d-143f-4084-827f-a67006bf6db2@googlegroups.com> Message-ID: <52D8EF81.3010101@timgolden.me.uk> On 17/01/2014 05:42, vasishtha.spier at gmail.com wrote: > On Thursday, January 16, 2014 12:07:59 PM UTC-8, Tim Golden wrote: >> >> Here's a quick example. This should walk down the Python directory, >> creating a text file for each directory. The textfile will contain >> the names of all the files in the directory. (NB this might create >> a lot of text files so run it inside some temp directory). [.. snip sample code ...] > > Thanks Tim. It worked like a charm and saved me weeks of work using > a drag and drop utility. About 250 pdf files created of 50 to 100 > pages each. Heres the code in case any one else can use it. [snip] Glad it was helpful. And thanks for coming back with the solution: hopefully future searchers will find it useful. (And it's a great advert for how easy it is to do useful things in just a few lines of Python). TJG From lightaiyee at gmail.com Fri Jan 17 03:53:55 2014 From: lightaiyee at gmail.com (Sam) Date: Fri, 17 Jan 2014 00:53:55 -0800 (PST) Subject: Process datafeed in one MySql table and output to another MySql table In-Reply-To: References: Message-ID: <6dacfcba-e677-4c62-878e-c14c70d6b654@googlegroups.com> On Friday, January 17, 2014 10:07:58 AM UTC+8, Denis McMahon wrote: > On Thu, 16 Jan 2014 17:03:24 -0800, Sam wrote: > > > > > I have a datafeed which is constantly sent to a MySql table ... > > > > > Which are the python libraries which are suitable for this purpose? Are > > > there any useful sample code or project on the web that I can use as > > > reference? > > > > Did you search for mysql on the python docs website, or perhaps try > > googling "python mysql"? > I did. There were documentation but I was hoping to have more sample code. Preferably a similar project which I can use as reference. > > > -- > > Denis McMahon, denismfmcmahon at gmail.com From mail at timgolden.me.uk Fri Jan 17 04:01:52 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 17 Jan 2014 09:01:52 +0000 Subject: Converting folders of jpegs to single pdf per folder In-Reply-To: <96cfad0d-143f-4084-827f-a67006bf6db2@googlegroups.com> References: <0c648d2d-d8b3-4848-8b37-1e5e1ae40327@googlegroups.com> <96cfad0d-143f-4084-827f-a67006bf6db2@googlegroups.com> Message-ID: <52D8F180.8080200@timgolden.me.uk> On 17/01/2014 05:42, vasishtha.spier at gmail.com wrote: > try: > n = 0 > for dirpath, dirnames, filenames in os.walk(root): > PdfOutputFileName = os.path.basename(dirpath) + ".pdf" > c = canvas.Canvas(PdfOutputFileName) > if n > 0 : > for filename in filenames: > LowerCaseFileName = filename.lower() > if LowerCaseFileName.endswith(".jpg"): > print(filename) > filepath = os.path.join(dirpath, filename) > print(filepath) > im = ImageReader(filepath) > imagesize = im.getSize() > c.setPageSize(imagesize) > c.drawImage(filepath,0,0) > c.showPage() > c.save() > n = n + 1 > print "PDF of Image directory created" + PdfOutputFileName > > except: > print "Failed creating PDF" > ------------------------- One thing I would point out (assuming that this is your final code): your try-except is too broad, both in terms of the code it encloses and in terms of the exceptions it traps. As it stands, your code will drop straight out as soon as it hits an error, with the message "Failed creating PDF" -- which is what it would have done anyway, only you've removed the informative traceback which would have told you what went wrong! In the circumstances, you presumably want to attempt to recover from some failure (perhaps caused by a corrupt JPEG or a permissions issue) and continue to generate the remaning PDFs. In that case, you'd do better a structure of this sort: import logging logging.basicConfig() for d, ds, fs in os.walk("..."): # init pdf try: # create PDF except: logging.exception("Couldn't create PDF for %s", d) continue else: logging.info("Created PDF for %s", d) # write PDF If you could narrow down the range of exceptions you want to recover from, that would go in the "except:" clause, but in this situation you might not be in a position to do that. TJG From breamoreboy at yahoo.co.uk Fri Jan 17 04:10:32 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 09:10:32 +0000 Subject: Guessing the encoding from a BOM In-Reply-To: <20140116194005.387a9125@bigbox.christie.dr> References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: On 17/01/2014 01:40, Tim Chase wrote: > On 2014-01-17 11:14, Chris Angelico wrote: >> UTF-8 specifies the byte order >> as part of the protocol, so you don't need to mark it. > > You don't need to mark it when writing, but some idiots use it > anyway. If you're sniffing a file for purposes of reading, you need > to look for it and remove it from the actual data that gets returned > from the file--otherwise, your data can see it as corruption. I end > up with lots of CSV files from customers who have polluted it with > Notepad or had Excel insert some UTF-8 BOM when exporting. This > means my first column-name gets the BOM prefixed onto it when the > file is passed to csv.DictReader, grr. > > -tkc > My code that used to handle CSV files from M$ Money had to allow for a single NUL byte right at the end of the file. Thankfully I've now moved on to gnucash. Slight aside, any chance of changing the subject of this thread, or even ending the thread completely? Why? Every time I see it I picture Inspector Clouseau, "A BOM!!!" :) -- 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 Fri Jan 17 04:21:14 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 09:21:14 +0000 Subject: interactive help on the base object In-Reply-To: References: Message-ID: On 17/01/2014 01:00, Terry Reedy wrote: > On 12/6/2013 8:35 PM, Terry Reedy wrote: >> On 12/6/2013 12:03 PM, Mark Lawrence wrote: >>> Is it just me, or is this basically useless? >>> >>> >>> help(object) >>> Help on class object in module builtins: >>> >>> class object >>> | The most base type >> >> Given that this can be interpreted as 'least desirable', it could >> definitely be improved. >> >>> Surely a few more words, >> >> How about something like. >> >> '''The default top superclass for all Python classes. >> >> Its methods are inherited by all classes unless overriden. >> ''' >> >> When you have 1 or more concrete suggestions for the docstring, open a >> tracker issue. > > At Mark's invitation, I have done so. > http://bugs.python.org/issue20285 > Thanks, I've altered my will accordingly :) -- 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 Fri Jan 17 04:23:35 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 09:23:35 +0000 Subject: Process datafeed in one MySql table and output to another MySql table In-Reply-To: <6dacfcba-e677-4c62-878e-c14c70d6b654@googlegroups.com> References: <6dacfcba-e677-4c62-878e-c14c70d6b654@googlegroups.com> Message-ID: On 17/01/2014 08:53, Sam wrote: > On Friday, January 17, 2014 10:07:58 AM UTC+8, Denis McMahon wrote: >> On Thu, 16 Jan 2014 17:03:24 -0800, Sam wrote: >> >> >> >>> I have a datafeed which is constantly sent to a MySql table ... >> >> >> >>> Which are the python libraries which are suitable for this purpose? Are >> >>> there any useful sample code or project on the web that I can use as >> >>> reference? >> >> >> >> Did you search for mysql on the python docs website, or perhaps try >> >> googling "python mysql"? >> > > I did. There were documentation but I was hoping to have more sample code. Preferably a similar project which I can use as reference. > >> >> >> -- >> >> Denis McMahon, denismfmcmahon at gmail.com Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Fri Jan 17 04:25:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 09:25:20 +0000 Subject: extracting string.Template substitution placeholders In-Reply-To: <075b7403-a7cb-42bd-9ae9-ff3e3f3844a5@googlegroups.com> References: <075b7403-a7cb-42bd-9ae9-ff3e3f3844a5@googlegroups.com> Message-ID: On 17/01/2014 06:07, gmflanagan wrote: > On Sunday, January 12, 2014 3:08:31 PM UTC, Eric S. Johansson wrote: >> As part of speech recognition accessibility tools that I'm building, I'm >> >> using string.Template. In order to construct on-the-fly grammar, I need >> >> to know all of the identifiers before the template is filled in. what is >> >> the best way to do this? >> > > Try this: > > import string > cmplxstr="""a simple $string a longer $string a $last line ${another} one""" > > def finditer(s): > for match in string.Template.pattern.finditer(s): > arg = match.group('braced') or match.group('named') > if arg: > yield arg > > > if __name__ == '__main__': > print set(finditer(cmplxstr)) > Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Fri Jan 17 04:43:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 20:43:59 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence wrote: > Slight aside, any chance of changing the subject of this thread, or even > ending the thread completely? Why? Every time I see it I picture Inspector > Clouseau, "A BOM!!!" :) Special delivery, a berm! Were you expecting one? ChrisA From breamoreboy at yahoo.co.uk Fri Jan 17 04:47:33 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 09:47:33 +0000 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: On 17/01/2014 09:43, Chris Angelico wrote: > On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence wrote: >> Slight aside, any chance of changing the subject of this thread, or even >> ending the thread completely? Why? Every time I see it I picture Inspector >> Clouseau, "A BOM!!!" :) > > Special delivery, a berm! Were you expecting one? > > ChrisA > By coincidence I'm just off to collect a special delievry, of what I don't yet 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 Fri Jan 17 04:58:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 20:58:28 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: On Fri, Jan 17, 2014 at 8:47 PM, Mark Lawrence wrote: > On 17/01/2014 09:43, Chris Angelico wrote: >> >> On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence >> wrote: >>> >>> Slight aside, any chance of changing the subject of this thread, or even >>> ending the thread completely? Why? Every time I see it I picture >>> Inspector >>> Clouseau, "A BOM!!!" :) >> >> >> Special delivery, a berm! Were you expecting one? >> >> ChrisA >> > > By coincidence I'm just off to collect a special delievry, of what I don't > yet know. Did you write a script to buy you something for a dollar off eBay every day? Day six gets interesting, as I understand it. ChrisA From robin at reportlab.com Fri Jan 17 06:16:17 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 17 Jan 2014 11:16:17 +0000 Subject: doctests compatibility for python 2 & python 3 Message-ID: <52D91101.7000202@chamonix.reportlab.co.uk> I have some problems making some doctests for python2 code compatible with python3. The problem is that as part of our approach we are converting the code to use unicode internally. So we allow eihter byte strings or unicode in inputs, but we are trying to convert to unicode outputs. That makes doctests quite hard as def func(a): """ >>> func(u'aaa') 'aaa' """ return a fails in python2 whilst def func(a): """ >>> func(u'aaa') u'aaa' """ return a fails in python3. Aside from changing the tests so they look like """ >>> func(u'aaa')==u'aaa' True """ which make the test utility harder. If the test fails I don't see the actual outcome and expected I see expected True got False. Is there an easy way to make these kinds of tests work in python 2 & 3? -- Robin Becker From rosuav at gmail.com Fri Jan 17 06:24:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 22:24:18 +1100 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: <52D91101.7000202@chamonix.reportlab.co.uk> References: <52D91101.7000202@chamonix.reportlab.co.uk> Message-ID: On Fri, Jan 17, 2014 at 10:16 PM, Robin Becker wrote: > Aside from changing the tests so they look like > """ > >>> func(u'aaa')==u'aaa' > True > """ Do your test strings contain any non-ASCII characters? If not, you might be able to do this: def func(a): """ >>> str(func(u'aaa')) 'aaa' """ return a which should work in both. In Py3, the str() call will do nothing, and it'll compare correctly; in Py2, it'll convert it into a byte string, which will repr() without the 'u'. I don't think it's possible to monkey-patch unicode.__repr__ to not put the u'' prefix on, but if there is a way, that'd possibly be more convenient. ChrisA From rosuav at gmail.com Fri Jan 17 06:30:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 17 Jan 2014 22:30:46 +1100 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: References: <52D91101.7000202@chamonix.reportlab.co.uk> Message-ID: On Fri, Jan 17, 2014 at 10:24 PM, Chris Angelico wrote: > Do your test strings contain any non-ASCII characters? If not, you > might be able to do this: > > def func(a): > """ > >>> str(func(u'aaa')) > 'aaa' > """ > return a Actually, probably better than that: def func(a): """ >>> text(func(u'aaa')) 'aaa' """ return a try: class text(unicode): # Will throw NameError in Py3 def __repr__(self): return unicode.__repr__(self)[1:] except NameError: # Python 3 doesn't need this wrapper. text = str Little helper class that does what I don't think monkey-patching will do. I've tested this and it appears to work in both 2.7.4 and 3.4.0b2, but that doesn't necessarily mean that the repr of any given Unicode string will be exactly the same on both versions. It's likely to be better than depending on the strings being ASCII, though. ChrisA From steve+comp.lang.python at pearwood.info Fri Jan 17 06:41:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2014 11:41:24 GMT Subject: doctests compatibility for python 2 & python 3 References: Message-ID: <52d916e4$0$29999$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Jan 2014 11:16:17 +0000, Robin Becker wrote: > I have some problems making some doctests for python2 code compatible > with python3. The problem is that as part of our approach we are > converting the code to use unicode internally. So we allow eihter byte > strings or unicode in inputs, but we are trying to convert to unicode > outputs. Alas, I think you've run into one of the weaknesses of doctest. Don't get me wrong, I am a huge fan of doctest, but it is hard to write polyglot string tests with it, as you have discovered. However, you may be able to get 95% of the way by using print. def func(a): """ >>> print(func(u'aaa')) aaa """ return a ought to behave identically in both Python 2 and Python 3.3, provided you only print one object at a time. This ought to work with both ASCII and non-ASCII (at least in the BMP). -- Steven From robin at reportlab.com Fri Jan 17 07:12:35 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 17 Jan 2014 12:12:35 +0000 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: <52d916e4$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52d916e4$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52D91E33.9020608@chamonix.reportlab.co.uk> On 17/01/2014 11:41, Steven D'Aprano wrote: > def func(a): > """ > >>> print(func(u'aaa')) > aaa > """ > return a I think this approach seems to work if I turn the docstring into unicode def func(a): u""" >>> print(func(u'aaa\u020b')) aaa\u020b """ return a def _doctest(): import doctest doctest.testmod() if __name__ == "__main__": _doctest() If I leave the u off the docstring it goes wrong in python 2.7. I also tried to put an encoding onto the file and use the actual utf8 characters ie # -*- coding: utf-8 -*- def func(a): """ >>> print(func(u'aaa\u020b')) aaa?? """ return a def _doctest(): import doctest doctest.testmod() and that works in python3, but fails in python 2 with this > (py27) C:\code\hg-repos>python tdt1.py > C:\python\Lib\doctest.py:1531: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - in > terpreting them as being unequal > if got == want: > C:\python\Lib\doctest.py:1551: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - in > terpreting them as being unequal > if got == want: > ********************************************************************** > File "tdt1.py", line 4, in __main__.func > Failed example: > print(func(u'aaa\u020b')) > Expected: > aaa?? > Got: > aaa?? > ********************************************************************** > 1 items had failures: > 1 of 1 in __main__.func > ***Test Failed*** 1 failures. -- Robin Becker From robin at reportlab.com Fri Jan 17 07:14:51 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 17 Jan 2014 12:14:51 +0000 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: References: <52D91101.7000202@chamonix.reportlab.co.uk> Message-ID: <52D91EBB.2060606@chamonix.reportlab.co.uk> On 17/01/2014 11:30, Chris Angelico wrote: > On Fri, Jan 17, 2014 at 10:24 PM, Chris Angelico wrote: >> Do your test strings contain any non-ASCII characters? If not, you >> might be able to do this: >> >> def func(a): >> """ >> >>> str(func(u'aaa')) >> 'aaa' >> """ >> return a > > Actually, probably better than that: > > def func(a): > """ > >>> text(func(u'aaa')) > 'aaa' > """ > return a > > try: > class text(unicode): # Will throw NameError in Py3 > def __repr__(self): > return unicode.__repr__(self)[1:] > except NameError: > # Python 3 doesn't need this wrapper. > text = str > > Little helper class that does what I don't think monkey-patching will > do. I've tested this and it appears to work in both 2.7.4 and 3.4.0b2, > but that doesn't necessarily mean that the repr of any given Unicode > string will be exactly the same on both versions. It's likely to be > better than depending on the strings being ASCII, though. > > ChrisA > I tried this approach with a few more complicated outcomes and they fail in python2 or 3 depending on how I try to render the result in the doctest. -- Robin Becker From jeanmichel at sequans.com Fri Jan 17 07:25:22 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 17 Jan 2014 13:25:22 +0100 (CET) Subject: interactive help on the base object In-Reply-To: Message-ID: <845999372.306008.1389961522224.JavaMail.root@sequans.com> ----- Original Message ----- > On 17/01/2014 01:00, Terry Reedy wrote: > > On 12/6/2013 8:35 PM, Terry Reedy wrote: > >> On 12/6/2013 12:03 PM, Mark Lawrence wrote: > >>> Is it just me, or is this basically useless? > >>> > >>> >>> help(object) > >>> Help on class object in module builtins: > >>> > >>> class object > >>> | The most base type > >> > >> Given that this can be interpreted as 'least desirable', it could > >> definitely be improved. > >> > >>> Surely a few more words, > >> > >> How about something like. > >> > >> '''The default top superclass for all Python classes. > >> > >> Its methods are inherited by all classes unless overriden. > >> ''' > >> > >> When you have 1 or more concrete suggestions for the docstring, > >> open a > >> tracker issue. > > > > At Mark's invitation, I have done so. > > http://bugs.python.org/issue20285 > > > > Thanks, I've altered my will accordingly :) > > > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > > Mark Lawrence The issue is tagged 2.7. Is object the superclass of all classes in 2.7 ? I'm asking because in 2.5, it is not (old/new style). 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 mal at europython.eu Fri Jan 17 07:37:58 2014 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 17 Jan 2014 13:37:58 +0100 Subject: EuroPython has a new blog Message-ID: <52D92426.3070306@europython.eu> The EuroPython Society has setup a new blog for EuroPython in its efforts to provide more conference facilities for the EuroPython organization and to enhance the EuroPython attendee experience. http://blog.europython.eu/ There?s an RSS feed in case you want to subscribe to it: http://blog.europython.eu/rss The blog itself is hosted on Tumblr, so you can also follow the blog using your Tumblr account: log in, visit the blog and click ?Follow" in the upper right corner: http://www.tumblr.com/follow/europython If you?re looking for older blog entries, please check the EuroPython 2013 blog, which lists the entries for 2011-2013: https://ep2013.europython.eu/blog/ Enjoy, -- Marc-Andre Lemburg Director EuroPython Society http://www.europython-society.org/ From mal at europython.eu Fri Jan 17 07:38:53 2014 From: mal at europython.eu (M.-A. Lemburg) Date: Fri, 17 Jan 2014 13:38:53 +0100 Subject: EuroPython Society website now live Message-ID: <52D9245D.5010005@europython.eu> The EuroPython Society has created a new website to collect information on EuroPython, the society and its workings: http://www.europython-society.org/ For those who don?t know: the society is a Swedish non-profit organization which was formed in 2004 by the EuroPython organizers to put on EuroPython conferences. A new board was voted in at the EuroPython 2012 conference: https://ep2013.europython.eu/blog/2012/07/08/change-board-europython-society Given the size of EuroPython conferences, we?re working on formalizing the EuroPython selection process, providing resources and arranging with local teams to run EuroPython conferences: http://www.europython-society.org/cfp We consider the EuroPython Society the representation of the EuroPython attendees, so if you have questions, requests for improvements or other ideas on how to improve the series, please feel free to contact us: http://www.europython-society.org/contact You can also become members of the EuroPython Society at no charge and then vote at the general assembly of the society. Please visit our members page for more information: http://www.europython-society.org/members Enjoy, -- Marc-Andre Lemburg Director EuroPython Society http://www.europython-society.org/ From stephane at wirtel.be Fri Jan 17 07:41:53 2014 From: stephane at wirtel.be (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Fri, 17 Jan 2014 13:41:53 +0100 Subject: EuroPython has a new blog In-Reply-To: <52D92426.3070306@europython.eu> References: <52D92426.3070306@europython.eu> Message-ID: <2CFB57C1-E29A-4F60-A1C1-69F8B755EF25@wirtel.be> Hi Marc-Andr?, Cool for EuroPython, Good idea, I think we will use tumblr for a small blog for Python-FOSDEM. Stef On 17 Jan 2014, at 13:37, M.-A. Lemburg wrote: > The EuroPython Society has setup a new blog for EuroPython in its > efforts to provide more conference facilities for the EuroPython > organization and to enhance the EuroPython attendee experience. > > http://blog.europython.eu/ > > There?s an RSS feed in case you want to subscribe to it: > > http://blog.europython.eu/rss > > The blog itself is hosted on Tumblr, so you can also follow the blog > using your Tumblr account: log in, visit the blog and click ?Follow" in > the upper right corner: > > http://www.tumblr.com/follow/europython > > If you?re looking for older blog entries, please check the > EuroPython 2013 blog, which lists the entries for 2011-2013: > > https://ep2013.europython.eu/blog/ > > Enjoy, > -- > Marc-Andre Lemburg > Director > EuroPython Society > http://www.europython-society.org/ > -- > https://mail.python.org/mailman/listinfo/python-list From jeandupont115 at gmail.com Fri Jan 17 08:20:29 2014 From: jeandupont115 at gmail.com (Jean Dupont) Date: Fri, 17 Jan 2014 05:20:29 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program Message-ID: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> Dear all, I made a simple gui with tkinter. I can imagine there are things which I did which are "not optimal". So what I ask is to comment on my code preferable with snippets of code which show how to do improve my code. #!/usr/bin/env python import Tkinter import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) GPIO.setup(26,GPIO.OUT) GPIO.setup(24,GPIO.OUT) #hardware : connect 2 leds: #board-pin 26 on/off led; control with buttons #board-pin 24 led with pwm dimming and frequency; control via sliders top = Tkinter.Tk() top.geometry("600x400+310+290") var1 = DoubleVar() var2 = DoubleVar() i=0 p=GPIO.PWM(24,1) p.start(50) def btn_on_cmd(): text3.configure(bg = "#00FF00") text3.delete(0.1,END) text3.insert("0.1","ON ") GPIO.output(26,True) def btn_off_cmd(): text3.configure(bg = "#FF4000") text3.delete(0.1,END) text3.insert("0.1","OFF") GPIO.output(26, False) def timer0(): global i i=i+1 text1.delete(0.1,END) text1.insert(4.2,"Timer: " + str(i)) label1.configure(text=time.strftime("%H:%M:%S")) top.after(1000, timer0) def Set_PWM(var1): DC = float(var1) p.ChangeDutyCycle(DC) def Set_FREQ(var2): FR = float(var2) p.ChangeFrequency(FR) btn_on = Button(top, text ="On", command = btn_on_cmd) btn_on.place(x=10,y=100) btn_off = Button(top, text ="Off", command = btn_off_cmd) btn_off.place(x=100,y=100) text1 =Text(top, bg = "#009BFF", font=("Helvetica",14), height = 1, width = 15) text1.place(x=5,y=5) text3=Text(top, bg = "red", font=("Helvetica",12),height = 1, width = 4) text3.place(x=60,y=60) label1 = Label(top,relief=RAISED,bg = "#EFF980",font=("Helvetica",14),height = 1, width = 15) label1.place(x=5,y=350) label2= Label(top,relief=RAISED,bg = "#BFBFBF",font=("Helvetica",10),height = 1, text= "Freq (Hz)") label2.place(x=420,y=320) label3= Label(top,relief=RAISED,bg = "#BFBFBF",font=("Helvetica",10),height = 1, text= "DC %") label3.place(x=520,y=320) slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command = Set_PWM) slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command = Set_PWM) slider1.place(x=500,y=5) slider1.set(50) slider2 = Scale(top,variable = var2,length = 300,from_= 0.1, to = 50,resolution = 0.1,command = Set_FREQ) slider2.place(x=400,y=5) slider2.set(2) timer0() top.mainloop() GPIO.cleanup() thanks in advance jean From bieffe62 at gmail.com Fri Jan 17 09:22:11 2014 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Fri, 17 Jan 2014 06:22:11 -0800 (PST) Subject: Python declarative In-Reply-To: References: Message-ID: <9ccc7180-3ebd-4976-b2e3-3013ca6569b0@googlegroups.com> Some time ago I played with Tkinter trying a more declarative way of coding the GUI building part and I come out with this: top = Tk( 'top' ).add ( Frame( 'frame' ).add ( Pack( side = 'top' ), Frame ( 'panel1' ).add ( Pack( side='left'), Label ( 'label', text="Entry 1 : " ), Entry ( 'entry' ) ), Frame( 'panel2' ).add ( Pack( side='left'), Label ( 'label', text="Entry 2 : " ), Entry( 'entry' ) ), Pack( side = 'bottom' ), # packing change Button( 'button', text='Click Me' )) ) top.frame.button["command"] = functools.partial(button_cb, top) top.realize().mainloop() which, without changing the underlying plumbing, may also be written this way, which avoid nesting but still looks declarative-ish : top = Tk( 'top' ) top.add( Frame( 'frame' ) ) top.frame.add ( Pack( side = 'top' ), Frame ( 'panel1' ), Frame( 'panel2' ), Pack( side = 'bottom' ), # packing change Button( 'button', text='Click Me', command = functools.partial(button_cb, top) ) ) top.frame.panel1.add( Pack( side='left'), Label ( 'label', text="Entry 1 : " ), Entry ( 'entry' ) ) top.frame.panel2.add( Pack( side='left'), Label ( 'label', text="Entry 1 : " ), Entry( 'entry' ) ) top.realize().mainloop() The underlying plumbing for those two examples is just two classes amounting to about fifty lines of code, plus one-liner wrappers for each kind of widgets/geometry This just to tell you that yes, with python you can write declarative-looking code ... if you don't mind parenthesis :-) From jan at hapala.cz Fri Jan 17 09:24:16 2014 From: jan at hapala.cz (Jan Hapala) Date: Fri, 17 Jan 2014 06:24:16 -0800 (PST) Subject: python2.6 needed as an aptitude package as dependency Message-ID: <3a9aa7d1-7eb6-422c-99d6-4585a661e8bd@googlegroups.com> Hello, I need to install a program (MACS: http://liulab.dfci.harvard.edu/MACS/) for which I need to have Python2.6 installed. I do have two other Pythons installed but not this version. 1) So I tried apt-get install... python2.6 is not there as a package (I am running Linux Mint 15). 2) Okay, I added some repos to the /etc/apt/sources.list: deb http://packages.linuxmint.com/ debian main upstream import deb http://debian.linuxmint.com/latest testing main contrib non-free deb http://debian.linuxmint.com/latest/security testing/updates main contrib non-free deb http://debian.linuxmint.com/latest/multimedia testing main non-free I ran apt-get update... python2.6 not there 3) I downloaded python2.6 as a source tar and compiled it and installed with make altinstall... Python2.6 is installed. When I enter "python" in the command line and hit Tab, I can see there now all three versions of python. Still I get the same error: dpkg: dependency problems prevent configuration of macs: macs depends on python2.6; however: Package python2.6 is not installed. I will be grateful for your suggestions, Jan From sertorbe at gmail.com Fri Jan 17 09:47:47 2014 From: sertorbe at gmail.com (sertorbe at gmail.com) Date: Fri, 17 Jan 2014 06:47:47 -0800 (PST) Subject: Python declarative In-Reply-To: References: Message-ID: <89b6244f-5757-4489-abf8-4cc7ef8bcae0@googlegroups.com> El mi?rcoles, 15 de enero de 2014 18:02:08 UTC+1, Sergio Tortosa Benedito escribi?: > Hi I'm developing a sort of language extension for writing GUI programs > > called guilang, right now it's written in Lua but I'm considreing Python > > instead (because it's more tailored to alone applications). My question > > it's if I can achieve this declarative-thing in python. Here's an > > example: > > > > Window "myWindow" { > > title="Hello world"; > > Button "myButton" { > > label="I'm a button"; > > onClick=exit > > } > > } > > print(myWindow.myButton.label) > > > > Of course it doesn't need to be 100% equal. Thanks in advance > > > > Sergio Wow thank you very much, really. I wasn't expecting that much from everyone. BTW, sorry for no answering earlier , I'm receiving no e-mails from the list (I'll look later what happens). First, I don't like that all parenthesis, I like to differentiate which type of delimiter is, this is not so bad if using spaces but anyways it's a little more difficult.Second, In regard, to using something like myWindow=Window rather than Window "myWindow", at first I didn't liked it that much, but in the end it does tell the user that the attributes can be accesed just like anything else. Finally , the project I'm developing (guilang) it's toolkit-independent so I don't mind having to do some wrappers. Sergio From rosuav at gmail.com Fri Jan 17 09:43:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Jan 2014 01:43:11 +1100 Subject: python2.6 needed as an aptitude package as dependency In-Reply-To: <3a9aa7d1-7eb6-422c-99d6-4585a661e8bd@googlegroups.com> References: <3a9aa7d1-7eb6-422c-99d6-4585a661e8bd@googlegroups.com> Message-ID: On Sat, Jan 18, 2014 at 1:24 AM, Jan Hapala wrote: > I need to install a program (MACS: http://liulab.dfci.harvard.edu/MACS/) for which I need to have Python2.6 installed. > > I do have two other Pythons installed but not this version. Is one of those Pythons a 2.7? If so, MACS will probably run with that. The only problem is that the dpkg installer doesn't know that you have the right dependencies. This isn't a Python question, it's a Debian packaging one, but I happen to know one of the ways to deal with this: the 'equivs' system. Since you've now installed Python 2.6 from source, you do have it, so all you need to do is make a dummy package called (or providing) python2.6. http://www.debian.org/doc/manuals/apt-howto/ch-helpers.en.html I used this system at work for several packages where I wanted to run a newer version of something than the repos provided. Saved us a lot of hassle. ChrisA From __peter__ at web.de Fri Jan 17 10:17:57 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 17 Jan 2014 16:17:57 +0100 Subject: [newbie] advice and comment wanted on first tkinter program References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> Message-ID: Jean Dupont wrote: > Dear all, > I made a simple gui with tkinter. I can imagine there are things which I > did which are "not optimal". So what I ask is to comment on my code > preferable with snippets of code which show how to do improve my code. > #!/usr/bin/env python > import Tkinter > import time > import RPi.GPIO as GPIO > GPIO.setmode(GPIO.BOARD) > GPIO.setup(26,GPIO.OUT) > GPIO.setup(24,GPIO.OUT) > #hardware : connect 2 leds: > #board-pin 26 on/off led; control with buttons > #board-pin 24 led with pwm dimming and frequency; control via sliders > top = Tkinter.Tk() > top.geometry("600x400+310+290") > var1 = DoubleVar() > var2 = DoubleVar() > i=0 > p=GPIO.PWM(24,1) > p.start(50) > def btn_on_cmd(): > text3.configure(bg = "#00FF00") > text3.delete(0.1,END) > text3.insert("0.1","ON ") > GPIO.output(26,True) > def btn_off_cmd(): > text3.configure(bg = "#FF4000") > text3.delete(0.1,END) > text3.insert("0.1","OFF") > GPIO.output(26, False) > def timer0(): > global i > i=i+1 > text1.delete(0.1,END) > text1.insert(4.2,"Timer: " + str(i)) > label1.configure(text=time.strftime("%H:%M:%S")) > top.after(1000, timer0) > def Set_PWM(var1): > DC = float(var1) > p.ChangeDutyCycle(DC) > def Set_FREQ(var2): > FR = float(var2) > p.ChangeFrequency(FR) > btn_on = Button(top, text ="On", command = btn_on_cmd) > btn_on.place(x=10,y=100) > btn_off = Button(top, text ="Off", command = btn_off_cmd) > btn_off.place(x=100,y=100) > text1 =Text(top, bg = "#009BFF", font=("Helvetica",14), height = 1, width > = 15) > text1.place(x=5,y=5) > text3=Text(top, bg = "red", font=("Helvetica",12),height = 1, width = 4) > text3.place(x=60,y=60) > label1 = Label(top,relief=RAISED,bg = > "#EFF980",font=("Helvetica",14),height = 1, width = 15) > label1.place(x=5,y=350) > label2= Label(top,relief=RAISED,bg = > "#BFBFBF",font=("Helvetica",10),height = 1, text= "Freq (Hz)") > label2.place(x=420,y=320) > label3= Label(top,relief=RAISED,bg = > "#BFBFBF",font=("Helvetica",10),height = 1, text= "DC %") > label3.place(x=520,y=320) > slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command = > Set_PWM) > slider1 = Scale(top,variable = var1,length = 300,resolution = 1,command = > Set_PWM) slider1.place(x=500,y=5) > slider1.set(50) > slider2 = Scale(top,variable = var2,length = 300,from_= 0.1, to = > 50,resolution = 0.1,command = Set_FREQ) slider2.place(x=400,y=5) > slider2.set(2) > timer0() > top.mainloop() > GPIO.cleanup() > > > thanks in advance > jean First and foremost a program has to do what the author wants it to do. Everything else is secondary. You are likely to have such a program on your machine, so congrats :) However, the version you posted does not run, probably because you started to replace from Tkinter import * top = Tk() ... var1 = DoubleVar() with the -- better -- import Tkinter top = Tkinter.Tk() ... but stopped too early, so that the line var1 = DoubleVar will raise a NameError. The fix is mechanical: run the program, go to the line with the NameError and add the 'Tkinter.' prefix. Once you have done that you should take the time to find good variable names. var1? I have no idea what value that could hold until I've read the whole program. That's feasible here, but program size may grow over time, and can you still tell me what var1 means next week? I recommend names that reflect the problem domain, e. g. `var_dutycycle` or just `dutycycle`. Next you should consider grouping the code by topic -- not necessarily into functions; having a section that does the setup for the dutycycle data and widgets and one for the time etc., visually separated by one or two empty lines should be sufficient. If you're ambitious you should read up on the grid layout manager. I allows widget size to change depending on the window size. The Text widget can be used to write whole Editors (like IDLE) -- it does no harm here, but seems a bit heavyweight for just an On/Off display. I would go with a Label or Entry. What does a red widget with no text mean, by the way? On, off, or undefined? Personally, I like to start with a defined state. An easy way to achieve this is to call button_off_cmd() # or button_on_cmd() manually before your program enters the mainloop() -- just like you did with timer0(). PS: An easy way to get an idea of what a script does is to run it. I'd guess that by keeping the Rasperry-Pi-specific code in you are reducing the number of readers who can do that by a few orders of magnitude. I managed to get it to run with the following ad-hoc changes: $ diff -u raspberry_orig.py raspberry_mock.py --- raspberry_orig.py 2014-01-17 16:10:20.843334832 +0100 +++ raspberry_mock.py 2014-01-17 16:10:58.970855503 +0100 @@ -1,7 +1,36 @@ #!/usr/bin/env python import Tkinter +from Tkinter import * import time -import RPi.GPIO as GPIO + +try: + import RPi.GPIO as GPIO +except ImportError: + class Name(str): + def __repr__(self): + return self + + class GPIO: + def __init__(self, prefix): + self.prefix = prefix + def __getattr__(self, name): + if name in ["BOARD", "OUT"]: + return Name(name) + if name == "PWM": + return GPIO("PWM") + if name == "__call__": + def c(*args): + print "Initializing {}{}".format(self.prefix, args) + return self + return c + def f(*args): + print "Calling {}.{}{}".format(self.prefix, name, args) + return f + + GPIO = GPIO("GPIO") + + + GPIO.setmode(GPIO.BOARD) GPIO.setup(26,GPIO.OUT) GPIO.setup(24,GPIO.OUT) From invalid at invalid.invalid Fri Jan 17 10:27:02 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Jan 2014 15:27:02 +0000 (UTC) Subject: Python 3.x adoption References: Message-ID: On 2014-01-14, Staszek wrote: > What's the problem with Python 3.x? The problem with Python 3.x is Python 2.7. ;) > What's wrong?... Python 2.7 still does everything 99% of us need to do, and we're too lazy to switch. -- Grant Edwards grant.b.edwards Yow! We have DIFFERENT at amounts of HAIR -- gmail.com From steve+comp.lang.python at pearwood.info Fri Jan 17 10:27:38 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 17 Jan 2014 15:27:38 GMT Subject: doctests compatibility for python 2 & python 3 References: <52d916e4$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52d94bea$0$29999$c3e8da3$5496439d@news.astraweb.com> On Fri, 17 Jan 2014 12:12:35 +0000, Robin Becker wrote: > On 17/01/2014 11:41, Steven D'Aprano wrote: >> def func(a): >> """ >> >>> print(func(u'aaa')) >> aaa >> """ >> return a > > I think this approach seems to work if I turn the docstring into unicode > > def func(a): > u""" > >>> print(func(u'aaa\u020b')) > aaa\u020b > """ > return a Good catch! Without the u-prefix, the \u... is not interpreted as an escape sequence, but as a literal backslash-u. > If I leave the u off the docstring it goes wrong in python 2.7. I also > tried to put an encoding onto the file and use the actual utf8 > characters ie > > # -*- coding: utf-8 -*- > def func(a): > """ > >>> print(func(u'aaa\u020b')) > aaa?? > """ > return a There seems to be some mojibake in your post, which confuses issues. You refer to \u020b, which is LATIN SMALL LETTER I WITH INVERTED BREVE. At least, that's what it ought to be. But in your post, it shows up as the two character mojibake, ? followed by ? (BOX DRAWINGS DOUBLE UP AND RIGHT followed by LATIN SMALL LETTER I WITH DIAERESIS). It appears that your posting software somehow got confused and inserted the two characters which you would have got using cp-437 while claiming that they are UTF-8. (Your post is correctly labelled as UTF-8.) I'm confident that the problem isn't with my newsreader, Pan, because it is pretty damn good at getting encodings right, but also because your post shows the same mojibake in the email archive: https://mail.python.org/pipermail/python-list/2014-January/664771.html To clarify: you tried to show \u020B as a literal. As a literal, it ought to be the single character ? which is a lower case I with curved accent on top. The UTF-8 of that character is b'\xc8\x8b', which in the cp-437 code page is two characters ? ?. py> '\u020b'.encode('utf8').decode('cp437') '??' Hence, mojibake. > def _doctest(): > import doctest > doctest.testmod() > > and that works in python3, but fails in python 2 with this >> (py27) C:\code\hg-repos>python tdt1.py C:\python\Lib\doctest.py:1531: >> UnicodeWarning: Unicode equal comparison failed to convert both >> arguments to Unicode - in terpreting them as being unequal >> if got == want: >> C:\python\Lib\doctest.py:1551: UnicodeWarning: Unicode equal comparison >> failed to convert both arguments to Unicode - in terpreting them as >> being unequal I cannot replicate this specific exception. I think it may be a side- effect of you being on Windows. (I'm on Linux, and everything is UTF-8.) >> if got == want: >> ********************************************************************** >> File "tdt1.py", line 4, in __main__.func Failed example: >> print(func(u'aaa\u020b')) >> Expected: >> aaa?? >> Got: >> aaa?? The difficulty here is that it is damn near impossible to sort out which, if any, bits are mojibake inserted by your posting software, which by your editor, your terminal, which by Python, and which are artifacts of the doctest system. The usual way to debug these sorts of errors is to stick a call to repr() just before the print. print(repr(func(u'aaa\u020b'))) -- Steven From python.list at tim.thechases.com Fri Jan 17 11:15:38 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 17 Jan 2014 10:15:38 -0600 Subject: Python 3.x adoption In-Reply-To: References: Message-ID: <20140117101538.56fd2142@bigbox.christie.dr> On 2014-01-17 15:27, Grant Edwards wrote: > > What's wrong?... > > Python 2.7 still does everything 99% of us need to do, and we're too > lazy to switch. And in most distros, typing "python" invokes 2.x, and explicitly typing "python3" is almost 17% longer. We're a lazy bunch! :-) -tkc From robin at reportlab.com Fri Jan 17 11:17:27 2014 From: robin at reportlab.com (Robin Becker) Date: Fri, 17 Jan 2014 16:17:27 +0000 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: <52d94bea$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52d916e4$0$29999$c3e8da3$5496439d@news.astraweb.com> <52d94bea$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52D95797.8080807@chamonix.reportlab.co.uk> On 17/01/2014 15:27, Steven D'Aprano wrote: .......... >> >> # -*- coding: utf-8 -*- >> def func(a): >> """ >> >>> print(func(u'aaa\u020b')) >> aaa?? >> """ >> return a > > There seems to be some mojibake in your post, which confuses issues. > > You refer to \u020b, which is LATIN SMALL LETTER I WITH INVERTED BREVE. > At least, that's what it ought to be. But in your post, it shows up as > the two character mojibake, ? followed by ? (BOX DRAWINGS DOUBLE UP AND > RIGHT followed by LATIN SMALL LETTER I WITH DIAERESIS). It appears that > your posting software somehow got confused and inserted the two > characters which you would have got using cp-437 while claiming that they > are UTF-8. (Your post is correctly labelled as UTF-8.) > > I'm confident that the problem isn't with my newsreader, Pan, because it > is pretty damn good at getting encodings right, but also because your > post shows the same mojibake in the email archive: > > https://mail.python.org/pipermail/python-list/2014-January/664771.html > > To clarify: you tried to show \u020B as a literal. As a literal, it ought > to be the single character ? which is a lower case I with curved accent on > top. The UTF-8 of that character is b'\xc8\x8b', which in the cp-437 code > page is two characters ? ?. when I edit the file in vim with ut88 encoding I do see your ? as the literal. However, as you note I'm on windows and no amount of cajoling will get it to work reasonably so my printouts are broken. So on windows (py27) C:\code\hg-repos>python -c"print(u'aaa\u020b')" aaa?? on my linux $ python2 -c"print(u'aaa\u020b')" aaa? $ python2 tdt1.py /usr/lib/python2.7/doctest.py:1531: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal if got == want: /usr/lib/python2.7/doctest.py:1551: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal if got == want: ********************************************************************** File "tdt1.py", line 4, in __main__.func Failed example: print(func(u'aaa\u020b')) Expected: aaa? Got: aaa? ********************************************************************** 1 items had failures: 1 of 1 in __main__.func ***Test Failed*** 1 failures. robin at everest ~/tmp: $ cat tdt1.py # -*- coding: utf-8 -*- def func(a): """ >>> print(func(u'aaa\u020b')) aaa? """ return a def _doctest(): import doctest doctest.testmod() if __name__ == "__main__": _doctest() robin at everest ~/tmp: so the error persists with our without copying errors. Note that on my putty terminal I don't see the character properly (I see unknown glyph square box), but it copies OK. -- Robin Becker From breamoreboy at yahoo.co.uk Fri Jan 17 11:21:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 16:21:08 +0000 Subject: Python 3.x adoption In-Reply-To: <20140117101538.56fd2142@bigbox.christie.dr> References: <20140117101538.56fd2142@bigbox.christie.dr> Message-ID: On 17/01/2014 16:15, Tim Chase wrote: > On 2014-01-17 15:27, Grant Edwards wrote: >>> What's wrong?... >> >> Python 2.7 still does everything 99% of us need to do, and we're too >> lazy to switch. > > And in most distros, typing "python" invokes 2.x, and explicitly > typing "python3" is almost 17% longer. We're a lazy bunch! :-) > > -tkc > For the really lazy the obvious solution is to switch to Windows where it's simply "py -2" or "py -3". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From petef4+usenet at gmail.com Fri Jan 17 11:26:28 2014 From: petef4+usenet at gmail.com (Pete Forman) Date: Fri, 17 Jan 2014 16:26:28 +0000 Subject: Guessing the encoding from a BOM References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <32c1b684-1ff7-48c0-af7a-cd15235ea531@googlegroups.com> Message-ID: <86zjmufubv.fsf@gmail.com> Rustom Mody writes: > On Friday, January 17, 2014 7:10:05 AM UTC+5:30, Tim Chase wrote: >> On 2014-01-17 11:14, Chris Angelico wrote: >> > UTF-8 specifies the byte order >> > as part of the protocol, so you don't need to mark it. > >> You don't need to mark it when writing, but some idiots use it >> anyway. If you're sniffing a file for purposes of reading, you need >> to look for it and remove it from the actual data that gets returned >> from the file--otherwise, your data can see it as corruption. I end >> up with lots of CSV files from customers who have polluted it with >> Notepad or had Excel insert some UTF-8 BOM when exporting. This >> means my first column-name gets the BOM prefixed onto it when the >> file is passed to csv.DictReader, grr. > > And its part of the standard: > Table 2.4 here > http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf It would have been nice if there was an eighth encoding scheme defined there UTF-8NB which would be UTF-8 with BOM not allowed. -- Pete Forman From rosuav at gmail.com Fri Jan 17 11:33:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Jan 2014 03:33:44 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: <86zjmufubv.fsf@gmail.com> References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <32c1b684-1ff7-48c0-af7a-cd15235ea531@googlegroups.com> <86zjmufubv.fsf@gmail.com> Message-ID: On Sat, Jan 18, 2014 at 3:26 AM, Pete Forman wrote: > It would have been nice if there was an eighth encoding scheme defined > there UTF-8NB which would be UTF-8 with BOM not allowed. Or call that one UTF-8, and the one with the marker can be UTF-8-MS-NOTEPAD. ChrisA From rustompmody at gmail.com Fri Jan 17 11:30:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 17 Jan 2014 08:30:25 -0800 (PST) Subject: Guessing the encoding from a BOM In-Reply-To: <86zjmufubv.fsf@gmail.com> References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <32c1b684-1ff7-48c0-af7a-cd15235ea531@googlegroups.com> <86zjmufubv.fsf@gmail.com> Message-ID: On Friday, January 17, 2014 9:56:28 PM UTC+5:30, Pete Forman wrote: > Rustom Mody writes: > > On Friday, January 17, 2014 7:10:05 AM UTC+5:30, Tim Chase wrote: > >> On 2014-01-17 11:14, Chris Angelico wrote: > >> > UTF-8 specifies the byte order > >> > as part of the protocol, so you don't need to mark it. > >> You don't need to mark it when writing, but some idiots use it > >> anyway. If you're sniffing a file for purposes of reading, you need > >> to look for it and remove it from the actual data that gets returned > >> from the file--otherwise, your data can see it as corruption. I end > >> up with lots of CSV files from customers who have polluted it with > >> Notepad or had Excel insert some UTF-8 BOM when exporting. This > >> means my first column-name gets the BOM prefixed onto it when the > >> file is passed to csv.DictReader, grr. > > And its part of the standard: > > Table 2.4 here > > http://www.unicode.org/versions/Unicode5.0.0/ch02.pdf > It would have been nice if there was an eighth encoding scheme defined > there UTF-8NB which would be UTF-8 with BOM not allowed. If you or I break a standard then, well, we broke a standard. If Microsoft breaks a standard the standard is obliged to change. Or as the saying goes, everyone is equal though some are more equal. From urtizvereaxaxa at gmail.com Fri Jan 17 11:45:25 2014 From: urtizvereaxaxa at gmail.com (Xaxa Urtiz) Date: Fri, 17 Jan 2014 08:45:25 -0800 (PST) Subject: Python glob and raw string In-Reply-To: References: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> Message-ID: <78b3f119-4b8b-4c4c-b54e-c9078736869c@googlegroups.com> Le jeudi 16 janvier 2014 19:14:30 UTC+1, Neil Cerutti a ?crit?: > On 2014-01-16, Xaxa Urtiz <> wrote: > > > Hello everybody, i've got a little problem, i've made a script > > > which look after some files in some directory, typically my > > > folder are organized like this : > > > > > > [share] > > > folder1 > > > ->20131201 > > > -->file1.xml > > > -->file2.txt > > > ->20131202 > > > -->file9696009.tmp > > > -->file421378932.xml > > > etc.... > > > so basically in the share i've got some folder > > > (=folder1,folder2.....) and inside these folder i've got these > > > folder whose name is the date (20131201,20131202,20131203 > > > etc...) and inside them i want to find all the xml files. > > > So, what i've done is to iterate over all the folder1/2/3 that > > > i want and look, for each one, the xml file with that: > > > > > > for f in glob.glob(dir +r"\20140115\*.xml"): > > > ->yield f > > > > > > dir is the folder1/2/3 everything is ok but i want to do > > > something like that : > > > > > > for i in range(10,16): > > > ->for f in glob.glob(dir +r"\201401{0}\*.xml".format(i)): > > > -->yield f > > > > > > but the glob does not find any file.... (and of course there is > > > some xml and the old way found them...) > > > Any help would be appreciate :) > > > > I've done this two different ways. The simple way is very similar > > to what you are now doing. It sucks because I have to manually > > maintain the list of subdirectories to traverse every time I > > create a new subdir. > > > > Here's the other way, using glob and isdir from os.path, adapted > > from actual production code. > > > > class Miner: > > def __init__(self, archive): > > # setup goes here; prepare to acquire the data > > self.descend(os.path.join(archive, '*')) > > > > def descend(self, path): > > for fname in glob.glob(os.path.join(path, '*')): > > if os.path.isdir(fname): > > self.descend(fname) > > else: > > self.process(fname) > > > > def process(self, path): > > # Do what I want done with an actual file path. > > # This is where I add to the data. > > > > In your case you might not want to process unless the path also > > looks like an xml file. > > > > mine = Miner('myxmldir') > > > > Hmmm... I might be doing too much in __init__. ;) > > > > -- > > Neil Cerutti i only have 1 level of subdirectory, it's just in the case when i don't want to process all the date (otherwise i make a glob on '/*/*', no need to do any recursion. thanks for the answer ! From petef4+usenet at gmail.com Fri Jan 17 11:46:45 2014 From: petef4+usenet at gmail.com (Pete Forman) Date: Fri, 17 Jan 2014 16:46:45 +0000 Subject: Guessing the encoding from a BOM References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: <86vbxifte2.fsf@gmail.com> Chris Angelico writes: > On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence wrote: >> Slight aside, any chance of changing the subject of this thread, or even >> ending the thread completely? Why? Every time I see it I picture Inspector >> Clouseau, "A BOM!!!" :) > > Special delivery, a berm! Were you expecting one? Endian detection: Does my BOM look big in this? -- Pete Forman From rosuav at gmail.com Fri Jan 17 11:50:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Jan 2014 03:50:02 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <32c1b684-1ff7-48c0-af7a-cd15235ea531@googlegroups.com> <86zjmufubv.fsf@gmail.com> Message-ID: On Sat, Jan 18, 2014 at 3:30 AM, Rustom Mody wrote: > If you or I break a standard then, well, we broke a standard. > If Microsoft breaks a standard the standard is obliged to change. > > Or as the saying goes, everyone is equal though some are more equal. https://en.wikipedia.org/wiki/800_pound_gorilla Though Microsoft has been losing weight over the past decade or so, just as IBM before them had done (there was a time when IBM was *the* 800lb gorilla, pretty much, but definitely not now). In Unix/POSIX contexts, Linux might be playing that role - I've seen code that unwittingly assumes Linux more often than, say, assuming FreeBSD - but I haven't seen a huge amount of "the standard has to change, Linux does it differently", possibly because the areas of Linux-assumption are areas that aren't standardized anyway (eg additional socket options beyond the spec). The one area where industry leaders still heavily dictate to standards is the web. Fortunately, it usually still results in usable standards documents that HTML authors can rely on. Usually. *twiddles fingers* ChrisA From alister.ware at ntlworld.com Fri Jan 17 12:04:36 2014 From: alister.ware at ntlworld.com (Alister) Date: Fri, 17 Jan 2014 17:04:36 GMT Subject: Compiling main script into .pyc References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> Message-ID: On Thu, 16 Jan 2014 17:01:51 -0800, Sam wrote: > One thing I observe about python byte-code compiling is that the main > script does not gets compiled into .pyc. Only imported modules are > compiled into .pyc. > > May I know how can I compile the main script into .pyc? It is to > inconvenience potential copy-cats. if you want to stop casual programmers reading your code to see how you have achieved something don't bother. 1) your code is not that 'Clever'(Hopefully) 2) 'Clever' code is seldom worth copying * * 'Clever' code usually makes use of obscure functions, side effects & other features that make it difficult to follow & maintain just skim through www.thedailywtf.com for examples of 'Clever' code that should never have seen the light of day. if you have found a straight forward way to achive complex goal such that it is worth copying rest assured it will be copied no mater how hard you try to protect it. -- #define SIGILL 6 /* blech */ -- Larry Wall in perl.c from the perl source code From sdawal at gmail.com Fri Jan 17 12:18:18 2014 From: sdawal at gmail.com (San D) Date: Fri, 17 Jan 2014 09:18:18 -0800 (PST) Subject: Graph or Chart Software for Django Message-ID: <2a390ca5-baf3-4cbe-870f-7d6a6ab4b5a5@googlegroups.com> What is the best Graph or Chart software used with Django (libraries & products), preferably open source? Need something stable and robust, and used by many developers, so active on community channels. Thanks. From sdawal at gmail.com Fri Jan 17 12:22:18 2014 From: sdawal at gmail.com (San D) Date: Fri, 17 Jan 2014 09:22:18 -0800 (PST) Subject: Templating engines that work very well with Python/Django Message-ID: Can someone suggest a few templating engines that work really well with Django and help in coding efficiency? Where can I fin comparison of tempating engines I can find to know their pros and cons? Thanks. From glicerinu at gmail.com Fri Jan 17 12:26:43 2014 From: glicerinu at gmail.com (Marc Aymerich) Date: Fri, 17 Jan 2014 18:26:43 +0100 Subject: Graph or Chart Software for Django In-Reply-To: <2a390ca5-baf3-4cbe-870f-7d6a6ab4b5a5@googlegroups.com> References: <2a390ca5-baf3-4cbe-870f-7d6a6ab4b5a5@googlegroups.com> Message-ID: On Fri, Jan 17, 2014 at 6:18 PM, San D wrote: > What is the best Graph or Chart software used with Django (libraries & products), preferably open source? > > Need something stable and robust, and used by many developers, so active on community channels. what I use is a JS library called highcharts, the django-side are only views that dump some data in json format perhaps in django-users mailing list you'll be able to find better answers than here :) -- Marc From glicerinu at gmail.com Fri Jan 17 12:33:55 2014 From: glicerinu at gmail.com (Marc Aymerich) Date: Fri, 17 Jan 2014 18:33:55 +0100 Subject: Templating engines that work very well with Python/Django In-Reply-To: References: Message-ID: On Fri, Jan 17, 2014 at 6:22 PM, San D wrote: > Can someone suggest a few templating engines that work really well with Django and help in coding efficiency? > > Where can I fin comparison of tempating engines I can find to know their pros and cons? I believe the most widely used template engine in Django is "The Django template language" itself :) https://docs.djangoproject.com/en/dev/topics/templates/ However the cool kids are always talking about switching to jinja2, a simple google search like jinja2 django could be a good starting point for finding good comparatives between both. -- Marc From breamoreboy at yahoo.co.uk Fri Jan 17 12:38:39 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 17:38:39 +0000 Subject: Python glob and raw string In-Reply-To: <78b3f119-4b8b-4c4c-b54e-c9078736869c@googlegroups.com> References: <6d3dd7d7-6836-4b55-9d1c-9e70e18b66fd@googlegroups.com> <78b3f119-4b8b-4c4c-b54e-c9078736869c@googlegroups.com> Message-ID: On 17/01/2014 16:45, Xaxa Urtiz wrote: [masses of double spaced lines snipped] Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing in your posts, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ethan at stoneleaf.us Fri Jan 17 12:40:19 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 17 Jan 2014 09:40:19 -0800 Subject: Guessing the encoding from a BOM In-Reply-To: <86vbxifte2.fsf@gmail.com> References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> <86vbxifte2.fsf@gmail.com> Message-ID: <52D96B03.8060805@stoneleaf.us> On 01/17/2014 08:46 AM, Pete Forman wrote: > Chris Angelico writes: >> On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence wrote: >>> Slight aside, any chance of changing the subject of this thread, or even >>> ending the thread completely? Why? Every time I see it I picture Inspector >>> Clouseau, "A BOM!!!" :) >> >> Special delivery, a berm! Were you expecting one? > > Endian detection: Does my BOM look big in this? LOL! -- ~Ethan~ From roegltd at gmail.com Fri Jan 17 13:02:52 2014 From: roegltd at gmail.com (Asaf Las) Date: Fri, 17 Jan 2014 10:02:52 -0800 (PST) Subject: python2.6 needed as an aptitude package as dependency In-Reply-To: <3a9aa7d1-7eb6-422c-99d6-4585a661e8bd@googlegroups.com> References: <3a9aa7d1-7eb6-422c-99d6-4585a661e8bd@googlegroups.com> Message-ID: <33b7b1cd-46c8-42af-9eb4-8a3adbaa704e@googlegroups.com> On Friday, January 17, 2014 4:24:16 PM UTC+2, Jan Hapala wrote: > Hello, > I need to install a program (MACS: http://liulab.dfci.harvard.edu/MACS/) for which I need to have Python2.6 installed. > I do have two other Pythons installed but not this version. > I will be grateful for your suggestions, > Jan you can try install from source option explicitly specifying python version from command line. guess for altinstall it should be python2.6 python2.6 setup.py install --prefix /home/taoliu/ https://github.com/taoliu/MACS/blob/master/INSTALL.rst /Asaf From python.list at tim.thechases.com Fri Jan 17 13:43:28 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 17 Jan 2014 12:43:28 -0600 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: <20140117124328.164f2256@bigbox.christie.dr> On 2014-01-17 09:10, Mark Lawrence wrote: > Slight aside, any chance of changing the subject of this thread, or > even ending the thread completely? Why? Every time I see it I > picture Inspector Clouseau, "A BOM!!!" :) In discussions regarding BOMs, I regularly get the "All your base" meme from a couple years ago stuck in my head: "Somebody set us up the bomb!" (usually in reference to clients sending us files with the aforementioned superfluous UTF-8 BOMs in them) -tkc From invalid at invalid.invalid Fri Jan 17 15:02:47 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Jan 2014 20:02:47 +0000 (UTC) Subject: Python 3.x adoption References: Message-ID: On 2014-01-17, Tim Chase wrote: > On 2014-01-17 15:27, Grant Edwards wrote: >> > What's wrong?... >> >> Python 2.7 still does everything 99% of us need to do, and we're too >> lazy to switch. > > And in most distros, typing "python" invokes 2.x, and explicitly > typing "python3" is almost 17% longer. We're a lazy bunch! :-) And my touch typing accuracy/speed drops pretty noticably when I have to use the top row of keys... -- Grant Edwards grant.b.edwards Yow! Half a mind is a at terrible thing to waste! gmail.com From invalid at invalid.invalid Fri Jan 17 15:12:56 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Jan 2014 20:12:56 +0000 (UTC) Subject: Compiling main script into .pyc References: <61a24c80-12fd-4c7a-89ed-41e997b66545@googlegroups.com> <52D89BC2.4000602@gmail.com> <52D8A143.4010206@mrabarnett.plus.com> <52d8ec89$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-01-17, Steven D'Aprano wrote: > On Thu, 16 Jan 2014 23:43:02 -0500, Dave Angel wrote: > [steve at ando ~]$ cat sample.py > print("Hello!") > > [steve at ando ~]$ ls sample.pyc > ls: sample.pyc: No such file or directory > [steve at ando ~]$ python -m compileall sample.py > Compiling sample.py ... > [steve at ando ~]$ ls sample.p* > sample.py sample.pyc > [steve at ando ~]$ python sample.pyc > Hello! Cool! Now I can distribute my application as a pre-compiled "binary" just like I do for . [That was meant ironically, BTW] -- Grant Edwards grant.b.edwards Yow! I want EARS! I want at two ROUND BLACK EARS gmail.com to make me feel warm 'n secure!! From sg552 at hotmail.co.uk Fri Jan 17 15:22:51 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 17 Jan 2014 20:22:51 +0000 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: On 17/01/2014 18:43, Tim Chase wrote: > On 2014-01-17 09:10, Mark Lawrence wrote: >> Slight aside, any chance of changing the subject of this thread, or >> even ending the thread completely? Why? Every time I see it I >> picture Inspector Clouseau, "A BOM!!!" :) > > In discussions regarding BOMs, I regularly get the "All your base" > meme from a couple years ago stuck in my head: "Somebody set us up the > bomb!" ITYM "Somebody set up us the bomb". From invalid at invalid.invalid Fri Jan 17 15:53:55 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 17 Jan 2014 20:53:55 +0000 (UTC) Subject: Building and accessing an array of dictionaries References: Message-ID: On 2014-01-16, Mark Lawrence wrote: > On 16/01/2014 09:48, Chris Angelico wrote: >> On Thu, Jan 16, 2014 at 8:41 PM, Sam wrote: >>> I would like to build an array of dictionaries. Most of the dictionary example on the net are for single dictionary. >>> >>> dict = {'a':'a','b':'b','c':'c'} >>> dict2 = {'a':'a','b':'b','c':'c'} >>> dict3 = {'a':'a','b':'b','c':'c'} >>> >>> arr = (dict,dict2,dict3) >>> >>> What is the syntax to access the value of dict3->'a'? >> >> Technically, that's a tuple of dictionaries > > For the benefit of lurkers, newbies or whatever it's the commas that > make the tuple, not the brackets. In _that_ example, yes. There are other cases where it's the brackets (sort of): foo('a','b','c') # three separate string objects are passed foo(('a','b','c')) # a single tuple object is passed -- Grant Edwards grant.b.edwards Yow! Being a BALD HERO at is almost as FESTIVE as a gmail.com TATTOOED KNOCKWURST. From tjreedy at udel.edu Fri Jan 17 16:10:50 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Jan 2014 16:10:50 -0500 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: <52D91EBB.2060606@chamonix.reportlab.co.uk> References: <52D91101.7000202@chamonix.reportlab.co.uk> <52D91EBB.2060606@chamonix.reportlab.co.uk> Message-ID: On 1/17/2014 7:14 AM, Robin Becker wrote: > I tried this approach with a few more complicated outcomes and they fail > in python2 or 3 depending on how I try to render the result in the doctest. I never got how you are using doctests. There were certainly not meant for heavy-duty unit testing, but for testing combined with explanation. Section 26.2.3.7. (in 3.3) Warnings warns that they are fragile to even single char changes and suggests == as a workaround, as 'True' and 'False' will not change. So I would not reject that option. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jan 17 16:21:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Jan 2014 16:21:32 -0500 Subject: interactive help on the base object In-Reply-To: <845999372.306008.1389961522224.JavaMail.root@sequans.com> References: <845999372.306008.1389961522224.JavaMail.root@sequans.com> Message-ID: On 1/17/2014 7:25 AM, Jean-Michel Pichavant wrote: >>>> '''The default top superclass for all Python classes. >>> http://bugs.python.org/issue20285 > The issue is tagged 2.7. Is object the superclass of all classes in 2.7 ? 2.7 should say 'all new-style classes'. Thanks for noticing and reporting. -- Terry Jan Reedy From joshua at landau.ws Fri Jan 17 16:31:18 2014 From: joshua at landau.ws (Joshua Landau) Date: Fri, 17 Jan 2014 21:31:18 +0000 Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? In-Reply-To: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: On 17 January 2014 00:58, Sam wrote: > I would like to protect my python source code. It need not be foolproof as long as it adds inconvenience to pirates. > > Is it possible to protect python source code by compiling it to .pyc or .pyo? Does .pyo offer better protection? If you're worried about something akin to corporate espionage or some-such, I don't know of a better way than ShedSkin or Cython. Both of those will be far harder to snatch the source of. Cython will be particularly easy to use as it is largely compatible with Python codebases. I offer no opinions, however, on whether this is a task worth doing. I only suggest you consider the disadvantages and how they apply to your individual case. From tjreedy at udel.edu Fri Jan 17 16:40:42 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Jan 2014 16:40:42 -0500 Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> Message-ID: On 1/17/2014 8:20 AM, Jean Dupont wrote: > Dear all, > I made a simple gui with tkinter. I can imagine there are things which I > did which are "not optimal". So what I ask is to comment on my code > preferable with snippets of code which show how to do improve my code. > #!/usr/bin/env python > import Tkinter 1. import Tkinter as tk Besides saving a bit of writing and reading time later, this makes any future conversion to 3.x easier. import tkinter as tk 2. add a few spaces to demarcate blocks of code. > import time > import RPi.GPIO as GPIO 2. add a few spaces to demarcate blocks of code, such as here > GPIO.setmode(GPIO.BOARD) > GPIO.setup(26,GPIO.OUT) > GPIO.setup(24,GPIO.OUT) > #hardware : connect 2 leds: > #board-pin 26 on/off led; control with buttons > #board-pin 24 led with pwm dimming and frequency; control via sliders and here > top = Tkinter.Tk() > top.geometry("600x400+310+290") This looks strange somehow, but if it works... > label1 = Label(top,relief=RAISED,bg = > "#EFF980",font=("Helvetica",14),height = 1, width = 15) In calls, put spaces after , but not before and after =. For other suggestions, see http://www.python.org/dev/peps/pep-0008/ I suspect that the above is one line in your code and the bad wrapping a result of mis-spacing. The following is also one line, but easer to read as spaces separate argument chunks label1 = Label(top, relief=RAISED, bg="#EFF980", font=("Helvetica",14), height=1, width=15) and the wrapping, if any, does not break up an arg chunk. Some people advocate defining an App class, but Tk and tkinter, even though object method based, allow the straightforward imperative style you have used. I agree with Peter: "First and foremost a program has to do what the author wants it to do. Everything else is secondary." But a bit of styling will make reading and changing easier. -- Terry Jan Reedy From timothy.c.delaney at gmail.com Fri Jan 17 17:02:42 2014 From: timothy.c.delaney at gmail.com (Tim Delaney) Date: Sat, 18 Jan 2014 09:02:42 +1100 Subject: Is it possible to protect python source code by compiling it to .pyc or .pyo? In-Reply-To: References: <7bf45fc1-e1c4-44f2-812c-e11ffa2c8ef3@googlegroups.com> Message-ID: On 18 January 2014 08:31, Joshua Landau wrote: > On 17 January 2014 00:58, Sam wrote: > > I would like to protect my python source code. It need not be foolproof > as long as it adds inconvenience to pirates. > > > > Is it possible to protect python source code by compiling it to .pyc or > .pyo? Does .pyo offer better protection? > > If you're worried about something akin to corporate espionage or > some-such, I don't know of a better way than ShedSkin or Cython. Both > of those will be far harder to snatch the source of. Cython will be > particularly easy to use as it is largely compatible with Python > codebases. > Indeed - I've only had one time someone absolutely insisted that this be done (for trade secret reasons - there needed to be a good-faith attempt to prevent others from trivially getting the source). I pointed them at Pyrex (this was before Cython, or at least before it was dominant). They fully understood that it wouldn't stop a determined attacker - this was a place where a large number of the developers were used to working on bare metal. If you're going to do this, I strongly suggest only using Cython on code that needs to be obscured (and if applicable, performance-critical sections). I'm currently working with a system which works this way - edge scripts in uncompiled .py files, and inner code as compiled extensions. The .py files have been really useful for interoperability purposes e.g. I was able to verify yesterday that one of the scripts had a bug in its command-line parsing and I wasn't going insane after all. Also, remember that any extension can be imported and poked at (e.g. in the interactive interpreter). You'd be surprised just how much information you can get that way just using help, dir, print and some experimentation. The output I was parsing from one of the scripts was ambiguous, and it was one where most of the work was done in an extension. I was able to poke around using the interactive interpreter understand what it was doing and obtain the data in an unambiguous manner to verify against my parser. The only way to truly protect code is to not ship any version of it (compiled or otherwise), but have the important parts hosted remotely under your control (and do your best to ensure it doesn't become compromised). Tim Delaney -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Fri Jan 17 17:10:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Jan 2014 17:10:04 -0500 Subject: Python 3.x adoption In-Reply-To: References: Message-ID: On 1/17/2014 10:27 AM, Grant Edwards wrote: > On 2014-01-14, Staszek wrote: > >> What's the problem with Python 3.x? > > The problem with Python 3.x is Python 2.7. ;) Cute. >> What's wrong?... > > Python 2.7 still does everything 99% of us need to do, and we're too > lazy to switch. While '99' is rhetorical, the statement is accurate for many. The core devs do not expect such people* to switch until they think they would benefit, and even then, only to the version that has enough goodies. * except for authors of widely used libraries ;-), and even then, it ends up being a matter of whether such authors think they will benefit from having 3.x users. -- Terry Jan Reedy From beliavsky at aol.com Fri Jan 17 17:16:59 2014 From: beliavsky at aol.com (beliavsky at aol.com) Date: Fri, 17 Jan 2014 14:16:59 -0800 (PST) Subject: Python 3.x adoption In-Reply-To: References: Message-ID: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> On Tuesday, January 14, 2014 2:38:29 PM UTC-5, Skip Montanaro wrote: > > What's the problem with Python 3.x? It was first released in 2008, but > > > web hosting companies still seem to offer Python 2.x rather. > > > > > > For example, Google App Engine only offers Python 2.7. > > > > > > What's wrong?... > > > > What makes you think anything's wrong? Major changes to any > > established piece of software takes a fairly long while to infiltrate. > > Lots of COBOL and Fortran 77 still running out there. I don't think the Fortran analogy is valid. The Fortran standards after F77 are almost complete supersets of F77, and Fortran compiler vendors handle even the deleted parts of F77, knowing their customer base. Therefore you do not need to rewrite old Fortran code to use it with Fortran 95 or 2003 compilers, and you can easily mix old-style and modern Fortran. Later Fortran standards did not invalidate basic syntax such as print statements, as Python 3 did. Python 2 and 3 are incompatible in ways that do not apply to Fortran standards pre- and post- F77. From breamoreboy at yahoo.co.uk Fri Jan 17 17:51:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 17 Jan 2014 22:51:24 +0000 Subject: Python 3.x adoption In-Reply-To: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> Message-ID: On 17/01/2014 22:16, beliavsky at aol.com wrote: > On Tuesday, January 14, 2014 2:38:29 PM UTC-5, Skip Montanaro wrote: >>> What's the problem with Python 3.x? It was first released in 2008, but >> >>> web hosting companies still seem to offer Python 2.x rather. >> >>> >> >>> For example, Google App Engine only offers Python 2.7. >> >>> >> >>> What's wrong?... >> >> >> >> What makes you think anything's wrong? Major changes to any >> >> established piece of software takes a fairly long while to infiltrate. >> >> Lots of COBOL and Fortran 77 still running out there. > > I don't think the Fortran analogy is valid. > > Later Fortran standards did not invalidate basic syntax such as print statements, as Python 3 did. Python 2 and 3 are incompatible in ways that do not apply to Fortran standards pre- and post- F77. > A good choice to make, the capability to use "from __future__ import print_function", or whatever the actual thing is, has been available for years. 2to3 has been available for years, six was released at the end of June 2010 and there's now future, see http://python-future.org/ Admittedly there's a problem with the porting of code which mixes bytes and strings, but that's being addressed right now via PEPs 460, 461 and possibly others. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Fri Jan 17 18:03:45 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 17 Jan 2014 18:03:45 -0500 Subject: Python 3.x adoption In-Reply-To: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> Message-ID: On 1/17/2014 5:16 PM, beliavsky at aol.com wrote: > I don't think the Fortran analogy is valid. The appropriate analogy for the changes between Python 2.x and 3.x, which started about 1 and 2 decades after the original Python, are the changes between Fortran IV/66 and Fortran 77, also about 1 and 2 decades after the original Fortran. The latter two have a comparable number of differences. "In this revision of the standard [F77], a number of features were removed or altered in a manner that might invalidate previously standard-conforming programs. https://en.wikipedia.org/wiki/Fortran Not mentioned in the wiki article is the change in calling convention from call by value to call by reference (or maybe the opposite). I remember a program crashing because of this when I tried it with F77. Overall, there was more churn in Fortran up to F77 than there was in Python up to 3.0. > The Fortran standards after F77 are almost complete supersets of F77, and Fortran compiler vendors handle even the deleted parts of F77, knowing their customer base. Therefore you do not need to rewrite old Fortran code to use it with Fortran 95 or 2003 compilers, and you can easily mix old-style and modern Fortran. Later Fortran standards did not invalidate basic syntax such as print statements, as Python 3 did. Python 2 and 3 are incompatible in ways that do not apply to Fortran standards pre- and post- F77. Since 3.0, we have added new syntax ('yield from', u'' for instance) but I do not believe we have deleted or changed any syntax (I might have forgotten something minor) and I do not know of any proposal to do so (except to re-delete u'', which should only be used as a temporary crutch for 2&3 code). > Python 2 and 3 are incompatible in ways that do not apply to Fortran > standards pre- and post- F77. As stated above, I disagree with respect to pre-F77 and F77. Did you actually program in both, as I did? -- Terry Jan Reedy From python at mrabarnett.plus.com Fri Jan 17 18:12:20 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 17 Jan 2014 23:12:20 +0000 Subject: Python 3.x adoption In-Reply-To: References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> Message-ID: <52D9B8D4.1040003@mrabarnett.plus.com> On 2014-01-17 23:03, Terry Reedy wrote: [snip] > Since 3.0, we have added new syntax ('yield from', u'' for instance) but > I do not believe we have deleted or changed any syntax (I might have > forgotten something minor) and I do not know of any proposal to do so > (except to re-delete u'', which should only be used as a temporary > crutch for 2&3 code). > There was the removal of backticks. From rosuav at gmail.com Fri Jan 17 18:17:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Jan 2014 10:17:35 +1100 Subject: Python 3.x adoption In-Reply-To: <52D9B8D4.1040003@mrabarnett.plus.com> References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> <52D9B8D4.1040003@mrabarnett.plus.com> Message-ID: On Sat, Jan 18, 2014 at 10:12 AM, MRAB wrote: > On 2014-01-17 23:03, Terry Reedy wrote: > [snip] > >> Since 3.0, we have added new syntax ('yield from', u'' for instance) but >> I do not believe we have deleted or changed any syntax (I might have >> forgotten something minor) and I do not know of any proposal to do so >> (except to re-delete u'', which should only be used as a temporary >> crutch for 2&3 code). >> > There was the removal of backticks. Wasn't that removed _in_, not _since_, 3.0? ChrisA From piet at vanoostrum.org Fri Jan 17 18:19:55 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 18 Jan 2014 00:19:55 +0100 Subject: How to write this as a list comprehension? Message-ID: Hi, I am looking for an elegant way to write the following code as a list comprehension: labels = [] for then, name in mylist: _, mn, dy, _, _, _, wd, _, _ = localtime(then) labels.append(somefunc(mn, day, wd, name)) So mylist is a list of tuples, the first member of the tuple is a time (as epoch offset) and I neeed to apply a function on some fields of the localtime of it. I could define a auxiliary function like: def auxfunc(then, name): _, mn, dy, _, _, _, wd, _, _ = localtime(then) return somefunc(mn, day, wd, name) and then use [auxfunc(then, name) for then, name in mylist] or even [auxfunc(*tup) for tup in mylist] But defining the auxfunc takes away the elegance of a list comprehension. I would like to integrate the unpacking of localtime() and calling somefunc within the list comprehension, but I don't see a simple way to do that. somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)] (i.e. using a list comprehension on a one element list to do the variable shuffling) works but I don't find that very elegant. labels = [somefunc(mn, day, wd, name) for then, name in mylist for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] Python misses a 'where' or 'let'-like construction as in Haskell. Anybody has a more elegant solution? -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From drsalists at gmail.com Fri Jan 17 18:49:21 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 17 Jan 2014 15:49:21 -0800 Subject: How to write this as a list comprehension? In-Reply-To: References: Message-ID: On Fri, Jan 17, 2014 at 3:19 PM, Piet van Oostrum wrote: > Hi, > > I am looking for an elegant way to write the following code as a list > comprehension: > > labels = [] > for then, name in mylist: > _, mn, dy, _, _, _, wd, _, _ = localtime(then) > labels.append(somefunc(mn, day, wd, name)) My recomendation: Don't use a list comprehension. List comprehensions and generator expressions are great for quick little things, but become less readable when you have to string them over multiple physical lines. > labels = [somefunc(mn, day, wd, name) > for then, name in mylist > for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] From drsalists at gmail.com Fri Jan 17 19:43:18 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 17 Jan 2014 16:43:18 -0800 Subject: setup.py issue - some files are included as intended, but one is not In-Reply-To: References: Message-ID: On Wed, Jan 15, 2014 at 7:18 AM, Piet van Oostrum wrote: > Dan Stromberg writes: > >> On Sat, Jan 11, 2014 at 2:04 PM, Dan Stromberg wrote: >>> Hi folks. >>> >>> I have a setup.py problem that's driving me nuts. >> >> Anyone? I've received 0 responses. > > I can't even install your code because there's a bug in it. > > m4_treap.m4 contains this instruction twice: > > ifdef(/*pyx*/,cp)if current is None: > ifdef(/*pyx*/,cp)raise KeyError > > Which when generating pyx_treap.pyx (with *pyx* defined) expands to the syntactically incorrect > > cpif current is None: > cpraise KeyError Apologies. I'd fixed that in my source tree, but not checked it in. It's checked in now. From ben+python at benfinney.id.au Fri Jan 17 20:18:38 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 18 Jan 2014 12:18:38 +1100 Subject: Python 3.x adoption References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> Message-ID: <7wy52e9jf5.fsf@benfinney.id.au> Terry Reedy writes: > Since 3.0, we have added new syntax ('yield from', u'' for instance) > but I do not believe we have deleted or changed any syntax (I might > have forgotten something minor) I'm aware of the removal of ?`foo`? (use ?repr(foo)? instead), and removal of ?except ExcClass, exc_instance? (use ?except ExcClass as exc_instance? instead). -- \ ?For my birthday I got a humidifier and a de-humidifier. I put | `\ them in the same room and let them fight it out.? ?Steven Wright | _o__) | Ben Finney From ben+python at benfinney.id.au Fri Jan 17 20:27:39 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 18 Jan 2014 12:27:39 +1100 Subject: Python 3.x adoption References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> <7wy52e9jf5.fsf@benfinney.id.au> Message-ID: <7wtxd29j04.fsf@benfinney.id.au> Ben Finney writes: > Terry Reedy writes: > > > Since 3.0, we have added new syntax ('yield from', u'' for instance) > > but I do not believe we have deleted or changed any syntax (I might > > have forgotten something minor) > > I'm aware of the removal of ?`foo`? (use ?repr(foo)? instead), and > removal of ?except ExcClass, exc_instance? (use ?except ExcClass as > exc_instance? instead). Ah, you meant ?deleted or changed any Python 3 syntax?. No, I'm not aware of any such changes. -- \ ?I have never imputed to Nature a purpose or a goal, or | `\ anything that could be understood as anthropomorphic.? ?Albert | _o__) Einstein, unsent letter, 1955 | Ben Finney From john_ladasky at sbcglobal.net Fri Jan 17 20:51:17 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 17 Jan 2014 17:51:17 -0800 (PST) Subject: numpy.where() and multiple comparisons Message-ID: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> Hi folks, I am awaiting my approval to join the numpy-discussion mailing list, at scipy.org. I realize that would be the best place to ask my question. However, numpy is so widely used, I figure that someone here would be able to help. I like to use numpy.where() to select parts of arrays. I have encountered what I would consider to be a bug when you try to use where() in conjunction with the multiple comparison syntax of Python. Here's a minimal example: Python 3.3.2+ (default, Oct 9 2013, 14:50:09) [GCC 4.8.1] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> a = np.arange(10) >>> a array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>> b = np.where(a < 5) >>> b (array([0, 1, 2, 3, 4]),) >>> c = np.where(2 < a < 7) Traceback (most recent call last): File "", line 1, in ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() Defining b works as I want and expect. The array contains the indices (not the values) of a where a < 5. For my definition of c, I expect (array([3, 4, 5, 6]),). As you can see, I get a ValueError instead. I have seen the error message about "the truth value of an array with more than one element" before, and generally I understand how I (accidentally) provoke it. This time, I don't see it. In defining c, I expect to be stepping through a, one element at a time, just as I did when defining b. Does anyone understand why this happens? Is there a smart work-around? Thanks. From buzzard at invalid.invalid Fri Jan 17 21:16:28 2014 From: buzzard at invalid.invalid (duncan smith) Date: Sat, 18 Jan 2014 02:16:28 +0000 Subject: numpy.where() and multiple comparisons In-Reply-To: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> References: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> Message-ID: <52d9e408$0$29769$862e30e2@ngroups.net> On 18/01/14 01:51, John Ladasky wrote: > Hi folks, > > I am awaiting my approval to join the numpy-discussion mailing list, at scipy.org. I realize that would be the best place to ask my question. However, numpy is so widely used, I figure that someone here would be able to help. > > I like to use numpy.where() to select parts of arrays. I have encountered what I would consider to be a bug when you try to use where() in conjunction with the multiple comparison syntax of Python. Here's a minimal example: > > Python 3.3.2+ (default, Oct 9 2013, 14:50:09) > [GCC 4.8.1] on linux > Type "help", "copyright", "credits" or "license" for more information. >>>> import numpy as np >>>> a = np.arange(10) >>>> a > array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) >>>> b = np.where(a < 5) >>>> b > (array([0, 1, 2, 3, 4]),) >>>> c = np.where(2 < a < 7) > Traceback (most recent call last): > File "", line 1, in > ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() > > Defining b works as I want and expect. The array contains the indices (not the values) of a where a < 5. > > For my definition of c, I expect (array([3, 4, 5, 6]),). As you can see, I get a ValueError instead. I have seen the error message about "the truth value of an array with more than one element" before, and generally I understand how I (accidentally) provoke it. This time, I don't see it. In defining c, I expect to be stepping through a, one element at a time, just as I did when defining b. > > Does anyone understand why this happens? Is there a smart work-around? Thanks. > >>> a = np.arange(10) >>> c = np.where((2 < a) & (a < 7)) >>> c (array([3, 4, 5, 6]),) >>> Duncan From roy at panix.com Fri Jan 17 21:49:21 2014 From: roy at panix.com (Roy Smith) Date: Fri, 17 Jan 2014 21:49:21 -0500 Subject: Python 3.x adoption References: Message-ID: In article , Grant Edwards wrote: > On 2014-01-17, Tim Chase wrote: > > On 2014-01-17 15:27, Grant Edwards wrote: > >> > What's wrong?... > >> > >> Python 2.7 still does everything 99% of us need to do, and we're too > >> lazy to switch. > > > > And in most distros, typing "python" invokes 2.x, and explicitly > > typing "python3" is almost 17% longer. We're a lazy bunch! :-) > > And my touch typing accuracy/speed drops pretty noticably when I have > to use the top row of keys... This is why shells have the ability to create aliases, and also why command-line autocomplete was invented :-) From rustompmody at gmail.com Fri Jan 17 22:25:14 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 17 Jan 2014 19:25:14 -0800 (PST) Subject: How to write this as a list comprehension? In-Reply-To: References: Message-ID: <29e4c72c-f0aa-467d-a121-fb90f0ce1a1e@googlegroups.com> On Saturday, January 18, 2014 4:49:55 AM UTC+5:30, Piet van Oostrum wrote: > Hi, > I am looking for an elegant way to write the following code as a list > comprehension: > labels = [] > for then, name in mylist: > _, mn, dy, _, _, _, wd, _, _ = localtime(then) > labels.append(somefunc(mn, day, wd, name)) > So mylist is a list of tuples, the first member of the tuple is a time > (as epoch offset) and I neeed to apply a function on some fields of the > localtime of it. > I could define a auxiliary function like: > def auxfunc(then, name): > _, mn, dy, _, _, _, wd, _, _ = localtime(then) > return somefunc(mn, day, wd, name) > and then use > [auxfunc(then, name) for then, name in mylist] > or even > [auxfunc(*tup) for tup in mylist] > But defining the auxfunc takes away the elegance of a list comprehension. I would like to integrate the unpacking of localtime() and calling somefunc within the list comprehension, but I don't see a simple way to do that. > somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)] > (i.e. using a list comprehension on a one element list to do the variable shuffling) > works but I don't find that very elegant. > labels = [somefunc(mn, day, wd, name) > for then, name in mylist > for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] > Python misses a 'where' or 'let'-like construction as in Haskell. +1 Yes Ive often been bitten by the lack of a 'comprehension-let' Something like this is possible?? [somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name) in [localtime(then), name for then, name in mylist]] Some debugging of the structure will be necessary (if at all possible) I dont have your functions so cant do it From john_ladasky at sbcglobal.net Fri Jan 17 23:00:20 2014 From: john_ladasky at sbcglobal.net (John Ladasky) Date: Fri, 17 Jan 2014 20:00:20 -0800 (PST) Subject: numpy.where() and multiple comparisons In-Reply-To: <52d9e408$0$29769$862e30e2@ngroups.net> References: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> <52d9e408$0$29769$862e30e2@ngroups.net> Message-ID: <39d6bb6a-ce34-469e-8cb3-24a14331d6c5@googlegroups.com> On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote: > >>> a = np.arange(10) > >>> c = np.where((2 < a) & (a < 7)) > >>> c > (array([3, 4, 5, 6]),) Nice! Thanks! Now, why does the multiple comparison fail, if you happen to know? From phiwer at gmail.com Sat Jan 18 02:44:14 2014 From: phiwer at gmail.com (phiwer at gmail.com) Date: Fri, 17 Jan 2014 23:44:14 -0800 (PST) Subject: Python Scalability TCP Server + Background Game In-Reply-To: References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> Message-ID: <0ab89748-bce2-436f-a00b-41e8199430f6@googlegroups.com> > Quick smoke test. How big are your requests/responses? You mention > > REST, which implies they're going to be based on HTTP. I would expect > > you would have some idea of the rough size. Multiply that by 50,000, > > and see whether your connection can handle it. For instance, if you > > have a 100Mbit/s uplink, supporting 50K requests/sec means your > > requests and responses have to fit within about 256 bytes each, > > including all overhead. You'll need a gigabit uplink to be able to > > handle a 2KB request or response, and that's assuming perfect > > throughput. And is 2KB enough for you? > > > > ChrisA My assumption is that there will be mostly reads and some writes; maybe in the order of 80-20%. There is a time element in the game, which forces player's entity to update on-demand. This is part of the reason why I wanted the server to be able to handle so many reques, so that it could handle the read part without having any caching layer. Let me explain a bit more about the architecture, and possible remedies, to give you an idea: * On top are the web servers exposing a REST api. * At the bottom is the game. * Communication betweeen these layers is handled by a simple text protocol using TCP. The game has a tick function every now and then, which forwards the game's time. If a player enters the game, a message is sent to the game server (querying for player details), and if the game's tick is greater than the cached version of the player details, then the game updates the player details (and caches it). This design obviously has its flaws. One being that both reads/writes has to pass through the game server. One way to remedy this is by using a new layer, on top of the game, which would hold the cache. But then another problem arises, that of invalidating the cache when a new tick has been made. I'm leaning towards letting the cache layer check the current tick every now and then, and if new tick is available, update a local variable in the cache (which each new connection would check against). Any thoughts regarding this? There are some periods in the game, where many people will be online during the same tick, which could potentially cause the game to become slow at times, but maybe this should be accepted for the pleasure of making the game in python... :D A follow-up question (which is more to the point really): How does other python game development frameworks solve this issue? Do they not use greenlets for the network layer, to be able to use the shared Queue from multiprocess? Do they only use one process for both network and game operations? On a side note, I'm considering using 0MQ for the message layering between services (web-server <-> cache <-> game) on the back-end. Besides being a great message protocol, it also has built in queues which might be able to remedy the situation when many clients are requesting data. Anyone with experience with regards to this? (This problem can be boggled down multiple producer, single consumer, and then back to producer again). Thanks for all the replies. /Phil From rosuav at gmail.com Sat Jan 18 03:01:47 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Jan 2014 19:01:47 +1100 Subject: Python Scalability TCP Server + Background Game In-Reply-To: <0ab89748-bce2-436f-a00b-41e8199430f6@googlegroups.com> References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <0ab89748-bce2-436f-a00b-41e8199430f6@googlegroups.com> Message-ID: On Sat, Jan 18, 2014 at 6:44 PM, wrote: >> Quick smoke test. How big are your requests/responses? You mention >> >> REST, which implies they're going to be based on HTTP. I would expect >> >> you would have some idea of the rough size. Multiply that by 50,000, >> >> and see whether your connection can handle it. For instance, if you >> >> have a 100Mbit/s uplink, supporting 50K requests/sec means your >> >> requests and responses have to fit within about 256 bytes each, >> >> including all overhead. You'll need a gigabit uplink to be able to >> >> handle a 2KB request or response, and that's assuming perfect >> >> throughput. And is 2KB enough for you? >> >> >> >> ChrisA > > My assumption is that there will be mostly reads and some writes; maybe in the order of 80-20%. There is a time element in the game, which forces player's entity to update on-demand. This is part of the reason why I wanted the server to be able to handle so many reques, so that it could handle the read part without having any caching layer. > (You're using Google Groups, which means your replies are double-spaced and your new text is extremely long lines. Please fix this, either by the fairly manual job of fixing every post you make, or the simple method of switching to a better client. Thanks.) My point was just about the REST API, nothing else. You have to handle a request and a response for every API call. Whether they're reads or writes, you need to receive an HTTP request and send an HTTP response for each one. In order to support the 50k requests per second you hope for, you would have to handle 50k requests coming in and 50k responses going out. To do that, you would need - at a very VERY rough estimate - a maximum request size of 2KB and a gigabit internet connection (which is expensive). No further calculations are worth pursuing if you can't handle those requests and responses. (And small requests tend to be more expensive than large ones. Since you'll need a minimum of >SYN, ACK, >DATA, FIN, ACK in order to transmit and receive one single packet's worth of data each way, you're looking at roughly 8 packets minimum for a one-byte message and one-byte response. But at a very very rough estimate, 2KB each direction is the most you can sustain.) ChrisA From __peter__ at web.de Sat Jan 18 03:36:29 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Jan 2014 09:36:29 +0100 Subject: How to write this as a list comprehension? References: Message-ID: Piet van Oostrum wrote: > Hi, > > I am looking for an elegant way to write the following code as a list > comprehension: > > labels = [] > for then, name in mylist: > _, mn, dy, _, _, _, wd, _, _ = localtime(then) > labels.append(somefunc(mn, day, wd, name)) > > So mylist is a list of tuples, the first member of the tuple is a time > (as epoch offset) and I neeed to apply a function on some fields of the > localtime of it. > > I could define a auxiliary function like: > > def auxfunc(then, name): > _, mn, dy, _, _, _, wd, _, _ = localtime(then) > return somefunc(mn, day, wd, name) > > and then use > [auxfunc(then, name) for then, name in mylist] > > or even > [auxfunc(*tup) for tup in mylist] > > But defining the auxfunc takes away the elegance of a list comprehension. > I would like to integrate the unpacking of localtime() and calling > somefunc within the list comprehension, but I don't see a simple way to do > that. > > somefunc(mn, day, wd, name) for _, mn, dy, _, _, _, wd, _, _ in > [localtime(then)] (i.e. using a list comprehension on a one element list > to do the variable shuffling) works but I don't find that very elegant. > > labels = [somefunc(mn, day, wd, name) > for then, name in mylist > for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] > > Python misses a 'where' or 'let'-like construction as in Haskell. > > Anybody has a more elegant solution? Options I can think of: You could do it in two steps... time_name_pairs = ((localtime(then), name) for then, name in mylist) labels = [somefunc(t.tm_mon, t.tm_mday, t.tm_wday, name) for t, name in time_name_pairs] ...or you could inline the helper function... mon_mday_wday = operator.attrgetter("tm_mon", "tm_day", "tm_wday") labels = [somefunc(*mon_mday_wday(localtime(then)), name=name) for then, name in mylist] -- but both seem less readable than the classical for-loop. What would a list-comp with `let` or `where` look like? Would it win the beauty contest against the loop? From fomcl at yahoo.com Sat Jan 18 03:39:25 2014 From: fomcl at yahoo.com (Albert-Jan Roskam) Date: Sat, 18 Jan 2014 00:39:25 -0800 (PST) Subject: doctests compatibility for python 2 & python 3 In-Reply-To: Message-ID: <1390034365.84164.YahooMailBasic@web163801.mail.gq1.yahoo.com> -------------------------------------------- On Fri, 1/17/14, Terry Reedy wrote: Subject: Re: doctests compatibility for python 2 & python 3 To: python-list at python.org Date: Friday, January 17, 2014, 10:10 PM On 1/17/2014 7:14 AM, Robin Becker wrote: > I tried this approach with a few more complicated outcomes and they fail > in python2 or 3 depending on how I try to render the result in the doctest. I never got how you are using doctests. There were certainly not meant for heavy-duty unit testing, but for testing combined with explanation. Section 26.2.3.7. (in 3.3) Warnings warns that they are fragile to even single char changes and suggests == as a workaround, as 'True' and 'False' will not change. So I would not reject that option. =====> I used doctests in .txt files and I converted ALL of them when I wanted to make my code work for both Python 2 and 3. I tried to fix something like a dozen of them so they'd work in Python 2.7 and 3,3. but I found it just too cumbersome and time consuming. The idea of doctest is super elegant, but it is really only meant for testable documentation (maybe with sphinx). If you'd put all the (often boring, e.g. edge cases) test cases in docstrings, the .py file will look very cluttered. One thing that I missed in unittest was Ellipsis, but: https://pypi.python.org/pypi/gocept.testing/1.6.0 offers assertEllipsis and other useful stuff. Albert-Jan From __peter__ at web.de Sat Jan 18 03:50:00 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Jan 2014 09:50 +0100 Subject: numpy.where() and multiple comparisons References: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> <52d9e408$0$29769$862e30e2@ngroups.net> <39d6bb6a-ce34-469e-8cb3-24a14331d6c5@googlegroups.com> Message-ID: John Ladasky wrote: > On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote: > >> >>> a = np.arange(10) >> >>> c = np.where((2 < a) & (a < 7)) >> >>> c >> (array([3, 4, 5, 6]),) > > Nice! Thanks! > > Now, why does the multiple comparison fail, if you happen to know? 2 < a < 7 is equivalent to 2 < a and a < 7 Unlike `&` `and` cannot be overridden (*), so the above implies that the boolean value bool(2 < a) is evaluated. That triggers the error because the numpy authors refused to guess -- and rightly so, as both implementable options would be wrong in a common case like yours. (*) I assume overriding would collide with short-cutting of boolean expressions. From greg.ewing at canterbury.ac.nz Sat Jan 18 04:41:00 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 18 Jan 2014 22:41:00 +1300 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: Chris Angelico wrote: > On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence wrote: > >Every time I see it I picture Inspector >>Clouseau, "A BOM!!!" :) > > Special delivery, a berm! Were you expecting one? A berm? Is that anything like a shrubbery? -- Greg From piet at vanoostrum.org Sat Jan 18 05:00:36 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 18 Jan 2014 11:00:36 +0100 Subject: How to write this as a list comprehension? References: <29e4c72c-f0aa-467d-a121-fb90f0ce1a1e@googlegroups.com> Message-ID: Rustom Mody writes: > On Saturday, January 18, 2014 4:49:55 AM UTC+5:30, Piet van Oostrum wrote: [...] > >> Python misses a 'where' or 'let'-like construction as in Haskell. > > +1 > Yes Ive often been bitten by the lack of a 'comprehension-let' If it used only in a comprehension as in my example you can write instead of 'where vars = expr': for vars in [expr], unnecessarily construction a one element list. If there would be a syntax like: for vars = expr this could be avoided. > > Something like this is possible?? > > > [somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name) in > [localtime(then), name for then, name in mylist]] It works modulo some corrections in the parentheses: [somefunc(mn,day,wd,name) for (_, mn,dy,_,_,_,wd,_,_), name in [(localtime(then), name) for then, name in mylist]] but I find that hardly more elegant. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From rosuav at gmail.com Sat Jan 18 05:10:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 18 Jan 2014 21:10:57 +1100 Subject: Guessing the encoding from a BOM In-Reply-To: References: <1389901049.40172.YahooMailBasic@web163804.mail.gq1.yahoo.com> <20140116194005.387a9125@bigbox.christie.dr> Message-ID: On Sat, Jan 18, 2014 at 8:41 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> On Fri, Jan 17, 2014 at 8:10 PM, Mark Lawrence >> wrote: >> >> Every time I see it I picture Inspector >>> >>> Clouseau, "A BOM!!!" :) >> >> >> Special delivery, a berm! Were you expecting one? > > > A berm? Is that anything like a shrubbery? http://www.youtube.com/watch?v=GLDvtpSC_98 ChrisA From matej at ceplovi.cz Sat Jan 18 05:57:27 2014 From: matej at ceplovi.cz (MatÄ›j Cepl) Date: Sat, 18 Jan 2014 11:57:27 +0100 Subject: How to write this as a list comprehension? In-Reply-To: References: Message-ID: <20140118105728.209B042665@wycliff.ceplovi.cz> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2014-01-17, 23:19 GMT, you wrote: > But defining the auxfunc takes away the elegance of a list > comprehension. Au contraire! Remember, that brevity is the sister of talent. I would definitively vote for labels = [make_label(then, name) for then, name in mylist] (always use descriptive names of functions and variables; auxfunc is a short way to the hell) Beauty of the list comprehensions is that they show nicely what list is being processed, how it is filtered (if at all), and what we do with each element of the generated list. Anything you add to this simplicity is wrong. Whenever you start to feel you are missing some methods how to stuff more commands into a comprehension (or for example multiple embedded ones), you should start new function. The same rule applies here as with any other lambda function (because these are in fact lambda functions): the best way how to write lambda is to write algorithm somewhere on the side, describe what this function does in one word, then add `def` in front of that name, and use so created named function instead. Best, Mat?j -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS2l4X4J/vJdlkhKwRAjEgAJ4n1OuANYlVFzlgBZ0f1uMhO/t36gCfdFjE VmYDJ+F7aN0khzvlY50i0iA= =Trcc -----END PGP SIGNATURE----- From phiwer at gmail.com Sat Jan 18 06:54:03 2014 From: phiwer at gmail.com (phiwer at gmail.com) Date: Sat, 18 Jan 2014 03:54:03 -0800 (PST) Subject: Python Scalability TCP Server + Background Game In-Reply-To: References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <0ab89748-bce2-436f-a00b-41e8199430f6@googlegroups.com> Message-ID: > (You're using Google Groups, which means your replies are > > double-spaced and your new text is extremely long lines. Please fix > > this, either by the fairly manual job of fixing every post you make, > > or the simple method of switching to a better client. Thanks.) > > > > My point was just about the REST API, nothing else. You have to handle > > a request and a response for every API call. Whether they're reads or > > writes, you need to receive an HTTP request and send an HTTP response > > for each one. In order to support the 50k requests per second you hope > > for, you would have to handle 50k requests coming in and 50k responses > > going out. To do that, you would need - at a very VERY rough estimate > > - a maximum request size of 2KB and a gigabit internet connection > > (which is expensive). No further calculations are worth pursuing if > > you can't handle those requests and responses. > > > > (And small requests tend to be more expensive than large ones. Since > > you'll need a minimum of >SYN, ACK, >DATA, FIN, > > ACK in order to transmit and receive one single packet's > > worth of data each way, you're looking at roughly 8 packets minimum > > for a one-byte message and one-byte response. But at a very very rough > > estimate, 2KB each direction is the most you can sustain.) > > > > ChrisA Aha, thanks for the info. But the assumptions you are making does not answer the question. And the question you raise, although important, is more a financial one, not really relevant to the questions I posed. Regards, Phil From jaiprakash at wisepromo.com Sat Jan 18 06:54:17 2014 From: jaiprakash at wisepromo.com (Jaiprakash Singh) Date: Sat, 18 Jan 2014 03:54:17 -0800 (PST) Subject: python to enable javascript , tried selinium, ghost, pyQt4 already Message-ID: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> hi, can you please suggest me some method for study so that i can scrap a site having JavaScript behind it i have tried selenium, ghost, pyQt4, but it is slow and as a am working with thread it sinks my ram memory very fast. From alain at dpt-info.u-strasbg.fr Sat Jan 18 06:53:12 2014 From: alain at dpt-info.u-strasbg.fr (Alain Ketterlin) Date: Sat, 18 Jan 2014 12:53:12 +0100 Subject: How to write this as a list comprehension? References: Message-ID: <874n51qzfb.fsf@dpt-info.u-strasbg.fr> Piet van Oostrum writes: [...] > I could define a auxiliary function like: > > def auxfunc(then, name): > _, mn, dy, _, _, _, wd, _, _ = localtime(then) > return somefunc(mn, day, wd, name) > > and then use > [auxfunc(then, name) for then, name in mylist] [...] > labels = [somefunc(mn, day, wd, name) > for then, name in mylist > for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] > > Python misses a 'where' or 'let'-like construction as in Haskell. "let x = v in e" really is (lambda x:e)(v) In your case: [ (lambda na,ti : somefunc(ti[1],ti[2],ti[6],na))(name,localtime(then)) for then,name in mylist ] Warning: absolutely untested (not even syntax-checked). You may also use *localtime(...) and keep underscores. -- Alain. From roegltd at gmail.com Sat Jan 18 07:13:47 2014 From: roegltd at gmail.com (Asaf Las) Date: Sat, 18 Jan 2014 04:13:47 -0800 (PST) Subject: Python Scalability TCP Server + Background Game In-Reply-To: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> Message-ID: <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> On Wednesday, January 15, 2014 8:37:25 PM UTC+2, phi... at gmail.com wrote: > My problem is as follows: > .... > 2) The network layer of the game server runs a separate process as well, > and my intention was to use gevent or tornado (http://nichol.as/asynchronous- >servers-in-python). > 3) The game server has a player limit of 50000. My requirement/desire is to > be able to serve 50k requests per second > 4) The game is not a real-time based game, but is catered towards the web. > Due to this information, I have developed the initial server using netty in > java. I would, however, rather develop the server using python,... and then > use python for the frontend. ... do you have references to implementations where python was used as frontend for such traffic load? you can have a look to this group for numbers https://groups.google.com/forum/#!forum/framework-benchmarks Asaf From phiwer at gmail.com Sat Jan 18 07:40:05 2014 From: phiwer at gmail.com (phiwer at gmail.com) Date: Sat, 18 Jan 2014 04:40:05 -0800 (PST) Subject: Python Scalability TCP Server + Background Game In-Reply-To: <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> Message-ID: Den l?rdagen den 18:e januari 2014 kl. 13:13:47 UTC+1 skrev Asaf Las: > On Wednesday, January 15, 2014 8:37:25 PM UTC+2, phi... at gmail.com wrote: > > > My problem is as follows: > > > .... > > > 2) The network layer of the game server runs a separate process as well, > > > and my intention was to use gevent or tornado (http://nichol.as/asynchronous- > > >servers-in-python). > > > 3) The game server has a player limit of 50000. My requirement/desire is to > > > be able to serve 50k requests per second > > > 4) The game is not a real-time based game, but is catered towards the web. > > > Due to this information, I have developed the initial server using netty in > > > java. I would, however, rather develop the server using python,... and then > > > use python for the frontend. ... > > > > do you have references to implementations where python was used as frontend for such traffic load? > > > > you can have a look to this group for numbers > > https://groups.google.com/forum/#!forum/framework-benchmarks > > > > Asaf Yes I've looked at those charts, and that was one of the reasons why I decided to go with netty for the back-end (although I'm probing to see if python possibly could match in some way, which I haven't thought of yet...). With regards to front-end, I haven't fully decided upon which framework to use. It's easier to scale the front-end, however, given that the problem of locking game state is not present in this logical part of the architecture. From breamoreboy at yahoo.co.uk Sat Jan 18 08:19:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Jan 2014 13:19:24 +0000 Subject: Python Scalability TCP Server + Background Game In-Reply-To: References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> Message-ID: On 18/01/2014 12:40, phiwer at gmail.com wrote: [snip the stuff I can't help with] Here's the link you need to sort the problem with double spacing from google groups https://wiki.python.org/moin/GoogleGroupsPython -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From beliavsky at aol.com Sat Jan 18 08:27:19 2014 From: beliavsky at aol.com (beliavsky at aol.com) Date: Sat, 18 Jan 2014 05:27:19 -0800 (PST) Subject: Python 3.x adoption In-Reply-To: References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> Message-ID: <95e6f032-cd40-483b-a649-676d9a56808a@googlegroups.com> On Friday, January 17, 2014 6:03:45 PM UTC-5, Terry Reedy wrote: > On 1/17/2014 5:16 PM, beliavsky at aol.com wrote: > > Python 2 and 3 are incompatible in ways that do not apply to Fortran > > > standards pre- and post- F77. > > > > As stated above, I disagree with respect to pre-F77 and F77. Did you > > actually program in both, as I did? > > > > -- > > Terry Jan Reedy I should have written "F77 and post F77". I have programmed in Fortran 77, 90, and 95. From jeandupont314 at gmail.com Sat Jan 18 09:52:24 2014 From: jeandupont314 at gmail.com (Jean Dupont) Date: Sat, 18 Jan 2014 06:52:24 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> Message-ID: <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> Op vrijdag 17 januari 2014 22:40:42 UTC+1 schreef Terry Reedy: > On 1/17/2014 8:20 AM, Jean Dupont wrote: > > > Dear all, > > > I made a simple gui with tkinter. I can imagine there are things which I > > > did which are "not optimal". So what I ask is to comment on my code > > > preferable with snippets of code which show how to do improve my code. > > > #!/usr/bin/env python > > > import Tkinter > > > > 1. import Tkinter as tk > > > > Besides saving a bit of writing and reading time later, this makes any > > future conversion to 3.x easier. > > > > import tkinter as tk > > > > 2. add a few spaces to demarcate blocks of code. > > > > > import time > > > import RPi.GPIO as GPIO > > > > 2. add a few spaces to demarcate blocks of code, such as here > > > > > GPIO.setmode(GPIO.BOARD) > > > GPIO.setup(26,GPIO.OUT) > > > GPIO.setup(24,GPIO.OUT) > > > #hardware : connect 2 leds: > > > #board-pin 26 on/off led; control with buttons > > > #board-pin 24 led with pwm dimming and frequency; control via sliders > > > > and here > > > > > top = Tkinter.Tk() > > > top.geometry("600x400+310+290") > > > > This looks strange somehow, but if it works... > > > > > > > label1 = Label(top,relief=RAISED,bg = > > > "#EFF980",font=("Helvetica",14),height = 1, width = 15) > > > > In calls, put spaces after , but not before and after =. > > For other suggestions, see > > http://www.python.org/dev/peps/pep-0008/ > > > > I suspect that the above is one line in your code and the bad wrapping a > > result of mis-spacing. The following is also one line, but easer to read > > as spaces separate argument chunks > > > > label1 = Label(top, relief=RAISED, bg="#EFF980", font=("Helvetica",14), > > height=1, width=15) > > > > and the wrapping, if any, does not break up an arg chunk. > > > > Some people advocate defining an App class, but Tk and tkinter, even > > though object method based, allow the straightforward imperative style > > you have used. > > > > I agree with Peter: "First and foremost a program has to do what the > > author wants it to do. Everything else is secondary." But a bit of > > styling will make reading and changing easier. > > > > -- > > Terry Jan Reedy Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a bit weird: when asking for Python-help concerning raspberry pi code or problems, a lot of people don't seem to be interested in helping out, that's of course their choice, but maybe they don't seem to be aware the raspberry pi is often the motivation for starting to learn to program in Python. And as such such a reaction is a bit disappointing. kind regards, jean From oscar.j.benjamin at gmail.com Sat Jan 18 10:12:41 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 18 Jan 2014 15:12:41 +0000 Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> Message-ID: On 18 January 2014 14:52, Jean Dupont wrote: > > Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a bit weird: when asking for Python-help concerning raspberry pi code or problems, a lot of people don't seem to be interested in helping out, that's of course their choice, but maybe they don't seem to be aware the raspberry pi is often the motivation for starting to learn to program in Python. And as such such a reaction is a bit disappointing. Hi Jean, What makes you say that? Did you previously ask questions about Rasberry Pi code on this list? If you did I wouldn't have answered those questions because I've never used a Raspberry Pi and know nothing about them (except that they encourage using Python somehow). I think that there's actually a list that is specifically for Raspberry Pi Python questions that might be more helpful although I don't know what it is... Oscar From rustompmody at gmail.com Sat Jan 18 10:20:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 18 Jan 2014 07:20:11 -0800 (PST) Subject: How to write this as a list comprehension? In-Reply-To: References: Message-ID: On Saturday, January 18, 2014 2:06:29 PM UTC+5:30, Peter Otten wrote: > Options I can think of: > You could do it in two steps... > time_name_pairs = ((localtime(then), name) for then, name in mylist) > labels = [somefunc(t.tm_mon, t.tm_mday, t.tm_wday, name) > for t, name in time_name_pairs] > ...or you could inline the helper function... > mon_mday_wday = operator.attrgetter("tm_mon", "tm_day", "tm_wday") > labels = [somefunc(*mon_mday_wday(localtime(then)), name=name) > for then, name in mylist] > -- but both seem less readable than the classical for-loop. > What would a list-comp with `let` or `where` look like? Would it win the > beauty contest against the loop? For me this is neat [somefunc(mn,day,wd,name) for (then, name) in mylist let (_,mn,dy,_,_,_,wd,_,_) = localtime(then)] Others may not find it so! See it across > 1 line (as I guess it will come after being posted!) and its not so neat. From jpiitula at ling.helsinki.fi Sat Jan 18 11:00:45 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 18 Jan 2014 18:00:45 +0200 Subject: How to write this as a list comprehension? References: Message-ID: Rustom Mody writes: > On Saturday, January 18, 2014 2:06:29 PM UTC+5:30, Peter Otten wrote: > > > What would a list-comp with `let` or `where` look like? Would it > > win the beauty contest against the loop? > > For me this is neat > > [somefunc(mn,day,wd,name) for (then, name) in mylist let (_,mn,dy,_,_,_,wd,_,_) = localtime(then)] > > Others may not find it so! > > See it across > 1 line (as I guess it will come after being posted!) > and its not so neat. I would write that on three lines anyway, properly indented: [ somefunc(mn,day,wd,name) for (then, name) in mylist let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ] It could be made to use existing keywords: [ somefunc(mn,day,wd,name) for (then, name) in mylist with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ] From breamoreboy at yahoo.co.uk Sat Jan 18 11:15:42 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Jan 2014 16:15:42 +0000 Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> Message-ID: On 18/01/2014 15:12, Oscar Benjamin wrote: > On 18 January 2014 14:52, Jean Dupont wrote: >> >> Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a bit weird: when asking for Python-help concerning raspberry pi code or problems, a lot of people don't seem to be interested in helping out, that's of course their choice, but maybe they don't seem to be aware the raspberry pi is often the motivation for starting to learn to program in Python. And as such such a reaction is a bit disappointing. > > Hi Jean, > > What makes you say that? Did you previously ask questions about > Rasberry Pi code on this list? > > If you did I wouldn't have answered those questions because I've never > used a Raspberry Pi and know nothing about them (except that they > encourage using Python somehow). I think that there's actually a list > that is specifically for Raspberry Pi Python questions that might be > more helpful although I don't know what it is... > > > Oscar > As Python is meant to be cross platform i think it's pretty much irrelevant that Raspberry Pi is mentioned. It's far more likely that people don't respond as questions are asked about specific libraries which they haven't used. Neither does it help when considering Jean's last post that the final paragraph shows as one line in Thunderbird on Windows and over 60% is simply blank lines. No guesses as to how he's posting. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From piet at vanoostrum.org Sat Jan 18 12:40:22 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sat, 18 Jan 2014 18:40:22 +0100 Subject: How to write this as a list comprehension? References: <874n51qzfb.fsf@dpt-info.u-strasbg.fr> Message-ID: Alain Ketterlin writes: > Piet van Oostrum writes: > [...] >> Python misses a 'where' or 'let'-like construction as in Haskell. > > "let x = v in e" really is (lambda x:e)(v) > You are right, but it is a lot less readable IMHO. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From indarkumar59 at gmail.com Sat Jan 18 13:00:47 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Sat, 18 Jan 2014 10:00:47 -0800 (PST) Subject: Python Simple program Message-ID: Hello, I am a newbie. Can somebody help me write the code for following program? Write a program that takes student grades and prints out the GPA. The information is input, one student per line in the format: ... The number of students is not known in advance. You should prompt the user for more until they enter an empty line. The number of courses per student varies and is also not known in advance. You should read as many grades as are entered on the line. From denismfmcmahon at gmail.com Sat Jan 18 13:05:44 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 18 Jan 2014 18:05:44 +0000 (UTC) Subject: python to enable javascript , tried selinium, ghost, pyQt4 already References: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> Message-ID: On Sat, 18 Jan 2014 03:54:17 -0800, Jaiprakash Singh wrote: > can you please suggest me some method for study so that i can > scrap a site having JavaScript behind it Please expand upon the requirement, are you trying to: a) replace server side javascript with server side python, or b) replace client side javascript with server side python, or c) replace client side javascript with client side python, or d) something else? (c) is not possible (you can't guarantee that all clients will have python, or that there will be a mechanism for calling it from your webpages), (b) doesn't make a lot of sense (you'll be trading cpu in the client for cpu in the server + network bandwidth and latency). -- Denis McMahon, denismfmcmahon at gmail.com From rosuav at gmail.com Sat Jan 18 13:11:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 05:11:24 +1100 Subject: Python Simple program In-Reply-To: References: Message-ID: On Sun, Jan 19, 2014 at 5:00 AM, indar kumar wrote: > Hello, I am a newbie. Can somebody help me write the code for following program? > > > Write a program that takes student grades and prints out the GPA. The information is input, one student per line in the format: ... > The number of students is not known in advance. You should prompt the user for more until they enter an empty line. The number of courses per student varies and is also not known in advance. You should read as many grades as are entered on the line. No. This is homework, and you should do it yourself - otherwise you are cheating yourself, cheating on your course, and ultimately, cheating an employer by making him/her think you know how to do something when you don't. If you write the code yourself and then have questions, then by all means, bring those questions to us! We're happy to help you learn. But that's quite different from outright doing your homework for you. ChrisA From rosuav at gmail.com Sat Jan 18 13:13:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 05:13:57 +1100 Subject: python to enable javascript , tried selinium, ghost, pyQt4 already In-Reply-To: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> References: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> Message-ID: On Sat, Jan 18, 2014 at 10:54 PM, Jaiprakash Singh wrote: > hi, > > can you please suggest me some method for study so that i can scrap a site having JavaScript behind it > > > i have tried selenium, ghost, pyQt4, but it is slow and as a am working with thread it sinks my ram memory very fast. Do you mean "scrape"? You're trying to retrieve the displayed contents of a web page that uses JavaScript? If so, that's basically impossible without actually executing the JS code, which means largely replicating the web browser. ChrisA From roy at panix.com Sat Jan 18 13:27:28 2014 From: roy at panix.com (Roy Smith) Date: Sat, 18 Jan 2014 13:27:28 -0500 Subject: Python Simple program References: Message-ID: In article , indar kumar wrote: > Hello, I am a newbie. Can somebody help me write the code for following > program? > > > Write a program that takes student grades and prints out the GPA. The > information is input, one student per line in the format: > ... > The number of students is not known in advance. You should prompt the user > for more until they enter an empty line. The number of courses per student > varies and is also not known in advance. You should read as many grades as > are entered on the line. This sounds like a homework problem for a basic programming course. Rather than write your program for you, let me give you a few broad hints. You're going to need to call raw_imput() in a loop to read in your data, then use split() to break the line up into fields, and another loop to iterate over the individual grades. See what progress you can make with that, and if you get stuck, come back with whatever code you've written so far, and more specific questions. From roy at panix.com Sat Jan 18 13:30:20 2014 From: roy at panix.com (Roy Smith) Date: Sat, 18 Jan 2014 13:30:20 -0500 Subject: question about input() and/or raw_input() Message-ID: Pardon me for being cynical, but in the entire history of the universe, has anybody ever used input()/raw_input() for anything other than a homework problem? From breamoreboy at yahoo.co.uk Sat Jan 18 13:41:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 18 Jan 2014 18:41:41 +0000 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On 18/01/2014 18:30, Roy Smith wrote: > Pardon me for being cynical, but in the entire history of the universe, > has anybody ever used input()/raw_input() for anything other than a > homework problem? > Not me personally. I guess raw_input must have been used somewhere at some time for something, or it would have been scrapped in Python 3, not renamed to input. -- 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 Jan 18 13:49:19 2014 From: emile at fenx.com (Emile van Sebille) Date: Sat, 18 Jan 2014 10:49:19 -0800 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On 01/18/2014 10:30 AM, Roy Smith wrote: > Pardon me for being cynical, but in the entire history of the universe, > has anybody ever used input()/raw_input() for anything other than a > homework problem? Yes - routinely. Emile From indarkumar59 at gmail.com Sat Jan 18 13:49:35 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Sat, 18 Jan 2014 10:49:35 -0800 (PST) Subject: Python Simple program In-Reply-To: References: Message-ID: <60955b74-7bc8-4c72-94e1-849015985034@googlegroups.com> On Saturday, January 18, 2014 11:00:47 AM UTC-7, indar kumar wrote: > Hello, I am a newbie. Can somebody help me write the code for following program? > > > > > > Write a program that takes student grades and prints out the GPA. The information is input, one student per line in the format: ... > > The number of students is not known in advance. You should prompt the user for more until they enter an empty line. The number of courses per student varies and is also not known in advance. You should read as many grades as are entered on the line. Hello, I think I just need one loop not separate loops. One while loop should be enough. From __peter__ at web.de Sat Jan 18 14:05:57 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Jan 2014 20:05:57 +0100 Subject: question about input() and/or raw_input() References: Message-ID: Roy Smith wrote: > Pardon me for being cynical, but in the entire history of the universe, > has anybody ever used input()/raw_input() for anything other than a > homework problem? I use it for pointless throwaway tools, sometimes via the cmd module, sometimes directly. I like that you can add tab-completion. From roy at panix.com Sat Jan 18 14:07:16 2014 From: roy at panix.com (Roy Smith) Date: Sat, 18 Jan 2014 14:07:16 -0500 Subject: Python Simple program References: <60955b74-7bc8-4c72-94e1-849015985034@googlegroups.com> Message-ID: In article <60955b74-7bc8-4c72-94e1-849015985034 at googlegroups.com>, indar kumar wrote: > On Saturday, January 18, 2014 11:00:47 AM UTC-7, indar kumar wrote: > > Hello, I am a newbie. Can somebody help me write the code for following > > program? > > > > > > > > > > > > Write a program that takes student grades and prints out the GPA. The > > information is input, one student per line in the format: > > ... > > > > The number of students is not known in advance. You should prompt the user > > for more until they enter an empty line. The number of courses per student > > varies and is also not known in advance. You should read as many grades as > > are entered on the line. > > > > Hello, I think I just need one loop not separate loops. One while loop should > be enough. If you're going to accept multiple lines of input (one line per student), and multiple grades on each line, you're going to need two loops. One loop iterates over the students, the other loop iterates over the various grades for each student. Any program is going to have several phases. Generally, you: 1) Read in the data 2) Process the data in some way 3) Print out the results In your case, the processing will be converting the grades to numbers (here in the US, we generally assign grades as A=4, B=3, C=2, D=1, F=0, but that may differ where you are) and computing the average. But, start simple. Write the part of the program which accepts all the input first, and just prints it back out, so you know you read it in properly. Once you're sure you've got that working, move on to the next phase. I've been doing this for a long time, and that's still the way I attack any new problem. From grawburg at myglnc.com Sat Jan 18 13:49:04 2014 From: grawburg at myglnc.com (Grawburg) Date: Sat, 18 Jan 2014 13:49:04 -0500 Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> Message-ID: <54db489323dcb828a91b38d8e94108c7@myglnc.com> The Raspberry Pi is exactly what got me started with Python. I'm at medium-sized science museum and used the Pi, Python, & tkinter to introduce kids to programming & Linux this past summer. Jean, feel free to contact me off-line for my experience with all three. Brian Grawburg Wilson, NC -----Original Message----- > From: "Oscar Benjamin" > To: "Jean Dupont" > Cc: "Python List" > Date: 01/18/14 10:13 AM > Subject: Re: [newbie] advice and comment wanted on first tkinter program > > On 18 January 2014 14:52, Jean Dupont wrote: > > > > Thanks Peter and Terry Jan for the useful suggestions. One thing which I find a bit weird: when asking for Python-help concerning raspberry pi code or problems, a lot of people don't seem to be interested in helping out, that's of course their choice, but maybe they don't seem to be aware the raspberry pi is often the motivation for starting to learn to program in Python. And as such such a reaction is a bit disappointing. > > Hi Jean, > > What makes you say that? Did you previously ask questions about > Rasberry Pi code on this list? > > If you did I wouldn't have answered those questions because I've never > used a Raspberry Pi and know nothing about them (except that they > encourage using Python somehow). I think that there's actually a list > that is specifically for Raspberry Pi Python questions that might be > more helpful although I don't know what it is... > > > Oscar > -- > https://mail.python.org/mailman/listinfo/python-list -- The truth will set you free . . .but first it will infuriate you. From mheieis at alois.ca Sat Jan 18 14:22:02 2014 From: mheieis at alois.ca (Mark Heieis) Date: Sat, 18 Jan 2014 11:22:02 -0800 Subject: Porting c extension - PyBuffer_New() deprecated in python3. What's the replacement? In-Reply-To: References: <52D0DAD5.3020803@alois.ca> Message-ID: <52DAD45A.3030101@alois.ca> Stefan, Thank-you for the reply. I hadn't considered cpython, unfortunately the extension is too large a project to port at the moment. I ended up replacing the PyBuffer_New() segment with malloc() and passing back an object from PyByteArray_FromStringAndSize(). It seems to work. mrh. On 2014-01-11 01:10, Stefan Behnel wrote: > Mark Heieis, 11.01.2014 06:47: >> I need to convert the following existing c extension code to support Python 3. >> >> // --- existing code ------ >> >> // PyBuffer_New() deprecated in python3 >> if (!(pyBuf = PyBuffer_New(len))) >> { >> return NULL; >> } >> >> // should use memoryview object in python3 >> if (PyObject_AsWriteBuffer(pyBuf, &cbuf, &len)) >> { >> Py_DECREF(pyBuf); >> return NULL ; >> } >> >> // fill in cbuf >> ... >> >> return pyBuf ; >> >> //----------- >> >> I'm somewhat confounded in finding an equivalent (PyBuffer_New()) for >> creating a buffer of size len that has continuous memory in the c extension >> function for python3. cbuf is manipulated/filled in using c, after which >> the created pyBuf is then returned. So far, I haven't found much in the way >> of examples/doc for porting the deprecated Python-/C-level buffer API calls >> to the new C-level buffer API/memoryview object model. >> >> Any guidance or direction to existing doc/example is much appreciated. > If the extension isn't huge, you should consider rewriting it in Cython. > That can usually be done quite quickly - the main thing is to figure out > what the verbose C code actually does and write it down in much simpler > Python code. And it will make it easy to make the code portable and fast. > Also likely safer and more generic and versatile, because Cython covers > away a lot of the annoying boilerplate, ref-counting issues, type > conversions, etc. > > For your specific problem at hand, you could use Cython's memory views: > > http://docs.cython.org/src/userguide/memoryviews.html > > They allow you to convert the input value to a 1-dim char buffer (or > whatever you need, but you mentioned the old Py2 buffer interface, which > can't do much more) by saying > > cdef char[:] my_memview = some_python_object > > If you need to pass the unpacked buffer into C code, you can get the > address as "&my_memview[0]" (i.e. the address of the first item in the > buffer). Memory views themselves support fast slicing and indexing, so you > can efficiently work with them using the normal Python slicing/indexing syntax. > > In case what you actually receive are not arbitrary buffers but simple byte > strings or bytearray instances, you can even use the normal byte string > coercion in Cython and simply say > > cdef char* c_string = some_python_byte_string_object > > and then use that pointer to pass it on into C. > > I've written a string processing tutorial for Cython here: > > http://docs.cython.org/src/tutorial/strings.html > > These things may take a moment to learn, especially if you are used to > doing everything in excessive manual detail in C code, but once you are > through that, you should get things done much more quickly than when trying > to do them by hand. > > Stefan > > From richyokevin at gmail.com Sat Jan 18 15:51:25 2014 From: richyokevin at gmail.com (Kevin K) Date: Sat, 18 Jan 2014 12:51:25 -0800 (PST) Subject: Need help vectorizing code Message-ID: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> I have some code that I need help vectorizing. I want to convert the following to vector form, how can I? I want to get rid of the inner loop - apparently, it's possible to do so. X is an NxD matrix. y is a 1xD vector. def foo(X, y, mylambda, N, D, epsilon): ... for j in xrange(D): aj = 0 cj = 0 for i in xrange(N): aj += 2 * (X[i,j] ** 2) cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + w[j]*X[i,j])) ... If I call numpy.vectorize() on the function, it throws an error at runtime. Thanks From joshua at landau.ws Sat Jan 18 16:04:32 2014 From: joshua at landau.ws (Joshua Landau) Date: Sat, 18 Jan 2014 21:04:32 +0000 Subject: Need help vectorizing code In-Reply-To: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> References: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> Message-ID: On 18 January 2014 20:51, Kevin K wrote: > def foo(X, y, mylambda, N, D, epsilon): > ... > for j in xrange(D): > aj = 0 > cj = 0 > for i in xrange(N): > aj += 2 * (X[i,j] ** 2) > cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + w[j]*X[i,j])) Currently this just computes and throws away values... From richyokevin at gmail.com Sat Jan 18 16:18:47 2014 From: richyokevin at gmail.com (Kevin K) Date: Sat, 18 Jan 2014 13:18:47 -0800 (PST) Subject: Need help vectorizing code In-Reply-To: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> References: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> Message-ID: <6bd7e22e-cfc8-4a80-9f17-3cc3ff8bad67@googlegroups.com> I didn't paste the whole function, note the ... before and after. I do use the values. I want to get rid of one of the loops so that the computation becomes O(D). Assume vectors a and c should get populated during the compute, each being 1xD. Thanks On Saturday, January 18, 2014 12:51:25 PM UTC-8, Kevin K wrote: > I have some code that I need help vectorizing. > > I want to convert the following to vector form, how can I? I want to get rid of the inner loop - apparently, it's possible to do so. > > X is an NxD matrix. y is a 1xD vector. > > > > def foo(X, y, mylambda, N, D, epsilon): > > ... > > for j in xrange(D): > > aj = 0 > > cj = 0 > > for i in xrange(N): > > aj += 2 * (X[i,j] ** 2) > > cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + w[j]*X[i,j])) > > > > ... > > > > If I call numpy.vectorize() on the function, it throws an error at runtime. > > > > Thanks From timr at probo.com Sat Jan 18 16:13:26 2014 From: timr at probo.com (Tim Roberts) Date: Sat, 18 Jan 2014 13:13:26 -0800 Subject: Python declarative References: <89b6244f-5757-4489-abf8-4cc7ef8bcae0@googlegroups.com> Message-ID: sertorbe at gmail.com wrote: > >First, I don't like that all parenthesis, I like to differentiate >which type of delimiter is, this is not so bad if using spaces but >anyways it's a little more difficult. Second, In regard, to using >something like myWindow=Window rather than Window "myWindow", at >first I didn't liked it that much, but in the end it does tell the >user that the attributes can be accesed just like anything else. Well, this all depends on whether you want this code to BE Python code, or just to be READ BY Python code. That's a huge difference. If you want your layout to BE Python code, then you have little alternative except to use the suggestions offered. But if you simply want your scripts to be interpreted by a Python program, then you can do whatever you want. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From timr at probo.com Sat Jan 18 16:20:54 2014 From: timr at probo.com (Tim Roberts) Date: Sat, 18 Jan 2014 13:20:54 -0800 Subject: numpy.where() and multiple comparisons References: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> <52d9e408$0$29769$862e30e2@ngroups.net> <39d6bb6a-ce34-469e-8cb3-24a14331d6c5@googlegroups.com> Message-ID: Peter Otten <__peter__ at web.de> wrote: >John Ladasky wrote: > >> On Friday, January 17, 2014 6:16:28 PM UTC-8, duncan smith wrote: >> >>> >>> a = np.arange(10) >>> >>> c = np.where((2 < a) & (a < 7)) >>> >>> c >>> (array([3, 4, 5, 6]),) >> >> Nice! Thanks! >> >> Now, why does the multiple comparison fail, if you happen to know? > >2 < a < 7 > >is equivalent to > >2 < a and a < 7 > >Unlike `&` `and` cannot be overridden (*),,,, And just in case it isn't obvious to the original poster, the expression "2 < a" only works because the numpy.array class has an override for the "<" operator. Python natively has no idea how to compare an integer to a numpy.array object. Similarly, (2 < a) & (a > 7) works because numpy.array has an override for the "&" operator. So, that expression is compiled as numpy.array.__and__( numpy.array.__lt__(2, a), numpy.array.__lt__(a, 7) ) As Peter said, there's no way to override the "and" operator. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From tjreedy at udel.edu Sat Jan 18 16:33:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Jan 2014 16:33:18 -0500 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On 1/18/2014 1:30 PM, Roy Smith wrote: > Pardon me for being cynical, but in the entire history of the universe, > has anybody ever used input()/raw_input() for anything other than a > homework problem? Homework problems (and 'toy' programs, such as hangman), whether in a programming class or elsewhere, are one of the intended use cases of Python. How else would you get interactive input without the complexity of a gui? -- Terry Jan Reedy From denismfmcmahon at gmail.com Sat Jan 18 16:40:38 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 18 Jan 2014 21:40:38 +0000 (UTC) Subject: python to enable javascript , tried selinium, ghost, pyQt4 already References: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> Message-ID: On Sun, 19 Jan 2014 05:13:57 +1100, Chris Angelico wrote: > On Sat, Jan 18, 2014 at 10:54 PM, Jaiprakash Singh > wrote: >> hi, >> >> can you please suggest me some method for study so that i can >> scrap a site having JavaScript behind it >> >> >> i have tried selenium, ghost, pyQt4, but it is slow and as a am >> working with thread it sinks my ram memory very fast. > > Do you mean "scrape"? You're trying to retrieve the displayed contents > of a web page that uses JavaScript? If so, that's basically impossible > without actually executing the JS code, which means largely replicating > the web browser. Oh, you think he meant scrape? I thought he was trying to scrap (as in throw away / replace) an old javascript heavy website with something using python instead. -- Denis McMahon, denismfmcmahon at gmail.com From __peter__ at web.de Sat Jan 18 16:50:00 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 18 Jan 2014 22:50 +0100 Subject: Need help vectorizing code References: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> Message-ID: Kevin K wrote: > I have some code that I need help vectorizing. > I want to convert the following to vector form, how can I? I want to get > rid of the inner loop - apparently, it's possible to do so. X is an NxD > matrix. y is a 1xD vector. > > def foo(X, y, mylambda, N, D, epsilon): > ... > for j in xrange(D): > aj = 0 > cj = 0 > for i in xrange(N): > aj += 2 * (X[i,j] ** 2) > cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() > + w[j]*X[i,j])) > > ... > > If I call numpy.vectorize() on the function, it throws an error at > runtime. Maybe a = (2*X**2).sum(axis=0) c = no idea. Judging from the code y should be 1xN rather than 1xD. Also, should w.transpose()*X[i].transpose() be a vector or a scalar? If the latter, did you mean numpy.dot(w, X[i]) ? From indarkumar59 at gmail.com Sat Jan 18 17:21:42 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Sat, 18 Jan 2014 14:21:42 -0800 (PST) Subject: Can post a code but afraid of plagiarism Message-ID: Hi, I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public From roy at panix.com Sat Jan 18 17:27:08 2014 From: roy at panix.com (Roy Smith) Date: Sat, 18 Jan 2014 17:27:08 -0500 Subject: Can post a code but afraid of plagiarism References: Message-ID: In article , indar kumar wrote: > Hi, > > I want to show a code for review but afraid of plagiarism issues. Kindly, > suggest how can I post it for review here without masking it visible for > public You can't. This is a public forum. One of the reasons people are willing to answer basic questions is because they knew more than one person will benefit from the answer. From rosuav at gmail.com Sat Jan 18 17:32:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 09:32:36 +1100 Subject: python to enable javascript , tried selinium, ghost, pyQt4 already In-Reply-To: References: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 8:40 AM, Denis McMahon wrote: > On Sun, 19 Jan 2014 05:13:57 +1100, Chris Angelico wrote: > >> On Sat, Jan 18, 2014 at 10:54 PM, Jaiprakash Singh >> wrote: >>> hi, >>> >>> can you please suggest me some method for study so that i can >>> scrap a site having JavaScript behind it >>> >>> >>> i have tried selenium, ghost, pyQt4, but it is slow and as a am >>> working with thread it sinks my ram memory very fast. >> >> Do you mean "scrape"? You're trying to retrieve the displayed contents >> of a web page that uses JavaScript? If so, that's basically impossible >> without actually executing the JS code, which means largely replicating >> the web browser. > > Oh, you think he meant scrape? I thought he was trying to scrap (as in > throw away / replace) an old javascript heavy website with something > using python instead. I thought so too at first, but since we had another recent case of someone confusing the two words, and since "scrape" would make sense in this context, I figured it'd be worth asking the question. ChrisA From indarkumar59 at gmail.com Sat Jan 18 17:32:21 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Sat, 18 Jan 2014 14:32:21 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: @Roy Smith Can you help me privately because its an assignment and have to submit plagiarism free From roy at panix.com Sat Jan 18 17:35:13 2014 From: roy at panix.com (Roy Smith) Date: Sat, 18 Jan 2014 17:35:13 -0500 Subject: Can post a code but afraid of plagiarism References: Message-ID: In article , indar kumar wrote: > @Roy Smith > > Can you help me privately Sorry, no. From wegge at wegge.dk Sat Jan 18 17:38:37 2014 From: wegge at wegge.dk (Anders Wegge Keller) Date: 18 Jan 2014 23:38:37 +0100 Subject: Reference counting and the use of PYTHONDUMPREFS Message-ID: <871u04530y.fsf@huddi.jernurt.dk> During the final test of a bit of embedded python, I wanted to see if I had any hanging references. To my suprise, I ended up with a rather large amount, after running combinerefs.py. And even with the simplest[1] possible use of embedding, I end up with 13475 still-living references. If this is the expected case, then what are the possible benefit from running a process with the PYTHONDUMPREFS ebvironment variable set? My code would have to be hemorrhaging in a severe way, to show up on this background. Am I missing something here? The system in question is a Fedora 19 Linux, using the distribution's Python3 debug rpm. I've seen similar results with Python 2.6, just at a lesser scale. 1: #include #include int main (int argc, char **argv) { Py_Initialize(); Py_Finalize(); return EXIT_SUCCESS; } Compiled with: gcc pyleak.c -o pyleak `/usr/bin/python3.3dm-config --cflags` \ `/usr/bin/python3.3dm-config --ldflags` -- /Wegge Leder efter redundant peering af dk.*,linux.debian.* From rosuav at gmail.com Sat Jan 18 17:42:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 09:42:59 +1100 Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Sun, Jan 19, 2014 at 9:32 AM, indar kumar wrote: > @Roy Smith > > Can you help me privately because its an assignment and have to submit plagiarism free Are you sure the requirement precludes you posting your code? More likely, the rule is that you may not copy someone else's. When it's posted here, it'll have your name associated with it, so anyone checking for your code on the web will see that you posted it yourself. But please, before you post your code, fix your posts. You're using the buggiest client known to this list: Google Groups. Using a different means of posting is probably the best solution, but failing that, you could search the web for 'Google Groups Python' and find some useful instructions. (I'd like to see that you're able to find things based on web search results, because that's an important skill.) ChrisA From ben+python at benfinney.id.au Sat Jan 18 17:57:52 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 19 Jan 2014 09:57:52 +1100 Subject: Can post a code but afraid of plagiarism References: Message-ID: <7wlhycaoen.fsf@benfinney.id.au> indar kumar writes: > I want to show a code for review but afraid of plagiarism issues. Why? What solid basis do you have to fear someone plagiarising code that you want reviewed? There is already a vast amount of code licensed freely for anyone to use and derive from. What would make yours especially susceptible to copying? As you can tell, I strongly suspect your fears are ungrounded. You will benefit greatly by sharing your code here and likewise benefiting from others sharing here. > Kindly, suggest how can I post it for review here without masking it > visible for public No. This forum is for the benefit of everyone who reads it, and we all contribute on that basis. If you want private help, you'll need to find, and provide appropriate compensation to, someone who is willing to benefit only you. -- \ ?No matter how cynical you become, it's never enough to keep | `\ up.? ?Jane Wagner, via Lily Tomlin | _o__) | Ben Finney From ben+python at benfinney.id.au Sat Jan 18 17:59:23 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 19 Jan 2014 09:59:23 +1100 Subject: Can post a code but afraid of plagiarism References: Message-ID: <7wha90aoc4.fsf@benfinney.id.au> indar kumar writes: > Can you help me privately because its an assignment and have to submit > plagiarism free Then the point of the assignment is defeated by seeking help here. Hopefully your instructors also read this forum and are now aware you are seeking to subvert the anti-plagiarism rules. -- \ ?It is well to remember that the entire universe, with one | `\ trifling exception, is composed of others.? ?John Andrew Holmes | _o__) | Ben Finney From tjreedy at udel.edu Sat Jan 18 19:12:35 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 18 Jan 2014 19:12:35 -0500 Subject: 'and' is not exactly an 'operator' (was Re: numpy.where() and multiple comparisons) In-Reply-To: References: <5617a90f-3d9b-48b2-b449-9e5ef4c181e5@googlegroups.com> <52d9e408$0$29769$862e30e2@ngroups.net> <39d6bb6a-ce34-469e-8cb3-24a14331d6c5@googlegroups.com> Message-ID: On 1/18/2014 3:50 AM, Peter Otten wrote: > Unlike `&` `and` cannot be overridden (*), > (*) I assume overriding would collide with short-cutting of boolean > expressions. Yes. 'and' could be called a 'control-flow operator', but in Python it is not a functional operator. A functional binary operator expression like 'a + b' abbreviates a function call, without using (). In this case, it could be written 'operator.add(a,b)'. This function, or it internal equivalent, calls either a.__add__(b) or b.__radd__(a) or both. It is the overloading of the special methods that overrides the operator. The control flow expression 'a and b' cannot abbreviate a function call because Python calls always evaluate all arguments first. It is equivalent* to the conditional (control flow) *expression* (also not a function operator) 'a if not a else b'. Evaluation of either expression calls bool(a) and hence a.__bool__ or a.__len__. 'a or b' is equivalent* to 'a if a else b' * 'a (and/or) b' evaluates 'a' once, whereas 'a if (not/)a else b' evaluates 'a' twice. This is not equivalent when there are side-effects. Here is an example where this matters. input('enter a non-0 number :') or 1 -- Terry Jan Reedy From pydev at allsup.co Sat Jan 18 20:24:56 2014 From: pydev at allsup.co (John Allsup) Date: Sun, 19 Jan 2014 01:24:56 +0000 Subject: How to write this as a list comprehension? In-Reply-To: References: Message-ID: <52DB2968.2030000@allsup.co> Hi, I'd agree with the advice that it's not the best idea: readability sucks here, but consider the following: import time def somefunc(a,b,c,d): # dummy function return "{} - {} - {} : {}".format(a,b,c,d) l = [(time.time(),"name {}".format(n)) for n in range(100)] # dummy data # the line in question labels = [somefunc(*(lambda t,n: (t.tm_mon,t.tm_mday,t.tm_wday,n))(time.localtime(x[0]),x[1])) for x in l] print(labels) # just to see the result If you find that hard to decipher, the consider the maintainability of code you write that uses such comprehensions. You need to include comments that explain what this does, and it is easier to write a longhand version using .append() and variable assignments. I presume performance won't be an issue determining the right approach, since then you'd be using C or C++. John On 17/01/2014 23:49, Dan Stromberg wrote: > On Fri, Jan 17, 2014 at 3:19 PM, Piet van Oostrum wrote: >> Hi, >> >> I am looking for an elegant way to write the following code as a list >> comprehension: >> >> labels = [] >> for then, name in mylist: >> _, mn, dy, _, _, _, wd, _, _ = localtime(then) >> labels.append(somefunc(mn, day, wd, name)) > > My recomendation: Don't use a list comprehension. List comprehensions > and generator expressions are great for quick little things, but > become less readable when you have to string them over multiple > physical lines. > >> labels = [somefunc(mn, day, wd, name) >> for then, name in mylist >> for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] From indarkumar59 at gmail.com Sat Jan 18 21:23:01 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Sat, 18 Jan 2014 18:23:01 -0800 (PST) Subject: Help with simple code that has database defined Message-ID: <4ea55e83-cfcd-4aaf-824a-3e3bced921c2@googlegroups.com> I have to save students information in a database that is keeping continuously track of the information. Format is as follows: Information: Note: if this name already exists there in database, just update the information of that(name) e.g course,grade and date. Otherwise, add it. What I think: Database={} #First Created a dictionary that will keep track z = "Enter student name, course, grade and duration: " line = raw_input(z) while (line != "quit"): data = line.split() name = data[0] line = raw_input(z) This is just part because this is what I know how to do, for rest have no idea The output should be like this: {'alex': ['7', '8', '6'], 'john': ['9', '8', '7']}) Now as program will continuously prompt for input. If user enters ?quit? it would exit. Otherwise it keeps taking input. Now if there is already a name existing for example ?alex? and his course, grade and duration are 7,8,6. Now in next turn of input if user again enters the name as alex but different entries for him e.g 9,9,9 so it should replace the older info by new e.g. it should replace 7,8,6 for alex by 9,9,9 and if user enters a entirely new name that is not in dictionary then it should be added to dictionary for example nancy 6 6 6 is the input then output should be: {'alex': ['7', '8', '6'], 'john': ['9', '8', '7'],?nancy?:[?6?,?6?,?6?]}) Kindly help. From rosuav at gmail.com Sat Jan 18 21:46:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 13:46:27 +1100 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On Sun, Jan 19, 2014 at 8:33 AM, Terry Reedy wrote: > On 1/18/2014 1:30 PM, Roy Smith wrote: >> >> Pardon me for being cynical, but in the entire history of the universe, >> has anybody ever used input()/raw_input() for anything other than a >> homework problem? > > > Homework problems (and 'toy' programs, such as hangman), whether in a > programming class or elsewhere, are one of the intended use cases of Python. > How else would you get interactive input without the complexity of a gui? With the network :) I've written plenty of programs whose sole interaction is via sockets (telnet, HTTP, SMTP, whatever), or a database, or somesuch. But I've also written my share of interactive programs that use the console. Plenty of programs don't need the fanciness of a GUI, but need to prompt the user for stuff. If I write something for my brother (and only him), I'm inclined to spend less effort on the UI than I would for something of wide distribution, and console I/O is approximately zero effort. BTW, I'm assuming your mention of "input()/raw_input()" is covering Py3 and Py2, respectively. I have *never* used input() in live Py2 code, and never intend to. It's way too subtle. On those really rare occasions when you actually want to take something from the user and immediately eval it, the extra keystrokes for eval(raw_input()) are, IMO, a small price for the clarity. ChrisA From rustompmody at gmail.com Sat Jan 18 23:15:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 18 Jan 2014 20:15:25 -0800 (PST) Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote: > Pardon me for being cynical, but in the entire history of the universe, > has anybody ever used input()/raw_input() for anything other than a > homework problem? Similar 'cynicism' regarding print would be salutary for producing better programmers [If youve taught programming and had to deal with code strewn with prints...] From rosuav at gmail.com Sat Jan 18 23:21:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 15:21:36 +1100 Subject: question about input() and/or raw_input() In-Reply-To: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 3:15 PM, Rustom Mody wrote: > On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote: >> Pardon me for being cynical, but in the entire history of the universe, >> has anybody ever used input()/raw_input() for anything other than a >> homework problem? > > Similar 'cynicism' regarding print would be salutary for producing better programmers > > [If youve taught programming and had to deal with code strewn with prints...] Why, exactly? How ought a program to produce filterable output? ChrisA From rustompmody at gmail.com Sat Jan 18 23:43:39 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 18 Jan 2014 20:43:39 -0800 (PST) Subject: question about input() and/or raw_input() In-Reply-To: References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> Message-ID: <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> On Sunday, January 19, 2014 9:51:36 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jan 19, 2014 at 3:15 PM, Rustom Mody wrote: > > On Sunday, January 19, 2014 12:00:20 AM UTC+5:30, Roy Smith wrote: > >> Pardon me for being cynical, but in the entire history of the universe, > >> has anybody ever used input()/raw_input() for anything other than a > >> homework problem? > > Similar 'cynicism' regarding print would be salutary for producing better programmers > > [If youve taught programming and had to deal with code strewn with prints...] > Why, exactly? How ought a program to produce filterable output? Because these two pieces of code >>> def foo(x): print x+1 >>> def bar(x): return x+1 look identical (to a beginner at least) >>> foo(3) 4 >>> bar(3) 4 >>> And so if they see prints used cavalierly for demo purposes, they think the prints are also ok for production. As a professional programmer, you would of course understand - 'normal' code that does some processing and then some output should not have prints in the processing - web-serving (type of) code that has little other than heavy-duty printing should probably use a template engine of some sort In any case prints all over is a code-smell exacerbated by the way that manuals/examples need to be written From rosuav at gmail.com Sat Jan 18 23:59:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 15:59:58 +1100 Subject: question about input() and/or raw_input() In-Reply-To: <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody wrote: > Because these two pieces of code > >>>> def foo(x): print x+1 > >>>> def bar(x): return x+1 > > look identical (to a beginner at least) > >>>> foo(3) > 4 >>>> bar(3) > 4 >>>> As do these pieces of code: >>> def quux(x): return str(x+1) >>> def quux(x): return hex(x+1)[2:] But we don't decry hex or str because of it. Every function has its use and purpose. If someone uses the wrong tool for the job, s/he will have to figure that out at some point - it doesn't mean the tool is wrong. If you're not using the REPL, print is critical. Don't assume everyone uses interactive mode. ChrisA From workitharder at gmail.com Sun Jan 19 00:40:08 2014 From: workitharder at gmail.com (buck) Date: Sat, 18 Jan 2014 21:40:08 -0800 (PST) Subject: graphical python Message-ID: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python. How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects. I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python? Is this a dream I should give up on, and just do this project in coffeescript/d3? From steve+comp.lang.python at pearwood.info Sun Jan 19 01:24:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2014 06:24:24 GMT Subject: question about input() and/or raw_input() References: Message-ID: <52db6f98$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jan 2014 13:30:20 -0500, Roy Smith wrote: > Pardon me for being cynical, but in the entire history of the universe, > has anybody ever used input()/raw_input() for anything other than a > homework problem? Yes. They are excellent for interactive command line tools. -- Steven From steve+comp.lang.python at pearwood.info Sun Jan 19 01:31:30 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 19 Jan 2014 06:31:30 GMT Subject: Can post a code but afraid of plagiarism References: Message-ID: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sat, 18 Jan 2014 14:32:21 -0800, indar kumar wrote: > @Roy Smith > > Can you help me privately because its an assignment and have to submit > plagiarism free Then don't plagiarise. Plagiarism means YOU copy other people. You shouldn't get in trouble because other people copy you. Talk to your tutor or teacher and ask what the school's policy is about asking for external help on projects. Some schools will allow it if you explain what help you received. Some prohibit it all together. In general, we will help with questions about Python syntax and libraries, but we try not to write your code for you. If you make a good- faith attempt to solve the problem, and then ask for help, we shall try to assist. But as I said, you should find out what your school or university's policy is. -- Steven From jeanpierreda at gmail.com Sun Jan 19 01:45:26 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Sat, 18 Jan 2014 22:45:26 -0800 Subject: Can post a code but afraid of plagiarism In-Reply-To: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 18, 2014 at 10:31 PM, Steven D'Aprano wrote: > Plagiarism means YOU copy other people. You shouldn't get in trouble > because other people copy you. Normally, both the person copying and the person who gave away their work to be copied are punished. It simplifies figuring out who to punish, and discourages people from enabling cheaters. If one of their fellow students copied their assignment, they actually likely would be in trouble, and could be expelled or failed. -- Devin From simsonsjanis at gmail.com Sun Jan 19 02:07:21 2014 From: simsonsjanis at gmail.com (simsonsjanis at gmail.com) Date: Sat, 18 Jan 2014 23:07:21 -0800 (PST) Subject: Beginner Tutorials In-Reply-To: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> References: <2e694a98-8a50-472e-89a0-92212a00464b@googlegroups.com> Message-ID: On Friday, 18 January 2013 16:47:52 UTC+2, Rik wrote: > Hi, I've developed a website for beginners to Python. I'd appreciate any comments or criticism. It's still under development, and should be finished in the next few months. Oh, and it's free to use. > > > > www.usingpython.com code solutions should be collapsed by default, imho From giorgos.tzampanakis at gmail.com Sun Jan 19 02:58:46 2014 From: giorgos.tzampanakis at gmail.com (Giorgos Tzampanakis) Date: Sun, 19 Jan 2014 07:58:46 +0000 (UTC) Subject: python to enable javascript , tried selinium, ghost, pyQt4 already References: <91184b5c-aa05-42e1-81de-15252023a15b@googlegroups.com> Message-ID: On 2014-01-18, Jaiprakash Singh wrote: > hi, > > can you please suggest me some method for study so that i can > scrap a site having JavaScript behind it > > > i have tried selenium, ghost, pyQt4, but it is slow and as a am > working with thread it sinks my ram memory very fast. I have tried selenium in the past and I remember it working reasonably well. I am afraid you can't get around the slowness since you have to have a web browser running. -- Improve at backgammon rapidly through addictive quickfire position quizzes: http://www.bgtrain.com/ From ian.g.kelly at gmail.com Sun Jan 19 03:19:29 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Jan 2014 01:19:29 -0700 Subject: graphical python In-Reply-To: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> References: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> Message-ID: On Sat, Jan 18, 2014 at 10:40 PM, buck wrote: > I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python. > > How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects. > > I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python? > > Is this a dream I should give up on, and just do this project in coffeescript/d3? You should be able to do something without much fuss using HTML 5 and either Pyjamas (which compiles Python code to Javascript) or Brython (a more or less complete implementation of Python within Javascript). For example, see the clock demo on the Brython web page. Pyjamas is the more established and probably more stable of the two projects, but you should be aware that there are currently two active forks of Pyjamas and some controversy surrounding the project leadership. From rustompmody at gmail.com Sun Jan 19 03:26:34 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 19 Jan 2014 00:26:34 -0800 (PST) Subject: question about input() and/or raw_input() In-Reply-To: References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> Message-ID: <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> On Sunday, January 19, 2014 10:29:58 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody wrote: > > Because these two pieces of code > >>>> def foo(x): print x+1 > >>>> def bar(x): return x+1 > > look identical (to a beginner at least) > >>>> foo(3) > > 4 > >>>> bar(3) > > 4 > As do these pieces of code: > >>> def quux1(x): return str(x+1) > >>> def quux2(x): return hex(x+1)[2:] They do? >>> quux1(2.3) '3.3' >>> quux2(2.3) Traceback (most recent call last): File "", line 1, in File "", line 1, in quux2 TypeError: hex() argument can't be converted to hex If you want to give an irrelevant example at least give a correct one :D the difference between str and hex is an arcane difference (Ive never used hex) the difference between functions and procedures is absolutely basic. And python is worse than not just academic languages like haskell in this respect but even worse than C/Pascal etc. In Pascal, the difference between procedure and function is fundamental to the lang and is key to Pascal being good for academic purposes. In C, the difference is not so well marked but at least trivial code-examples found in books/the net wont run straight-off without some main-printf-etc boiler-plate. In python lots of easy to check examples run straight off -- convenient for programmers of course but a headache for teachers who are trying to set habits of minimal hygiene > But we don't decry hex or str because of it. Every function has its > use and purpose. If someone uses the wrong tool for the job, s/he will > have to figure that out at some point - it doesn't mean the tool is > wrong. > If you're not using the REPL, print is critical. Don't assume everyone > uses interactive mode. "Everyone uses interactive mode" is of course an unreasonable assumption "Everyone needs to learn (something or other at some time or other)" is not And print (especially in python) screws up the learning-curve tl;dr You are wearing 'professional programmer' hat I am wearing 'teacher' hat Not sure what hat Roy or Steven are wearing From sertorbe at gmail.com Sun Jan 19 05:27:38 2014 From: sertorbe at gmail.com (sertorbe at gmail.com) Date: Sun, 19 Jan 2014 02:27:38 -0800 (PST) Subject: Python declarative In-Reply-To: References: Message-ID: El mi?rcoles, 15 de enero de 2014 18:02:08 UTC+1, Sergio Tortosa Benedito escribi?: > Hi I'm developing a sort of language extension for writing GUI programs > > called guilang, right now it's written in Lua but I'm considreing Python > > instead (because it's more tailored to alone applications). My question > > it's if I can achieve this declarative-thing in python. Here's an > > example: > > > > Window "myWindow" { > > title="Hello world"; > > Button "myButton" { > > label="I'm a button"; > > onClick=exit > > } > > } > > print(myWindow.myButton.label) > > > > Of course it doesn't need to be 100% equal. Thanks in advance > > > > Sergio OK, thanks, maybe the to be read by python may be interesting .Anyway, I think I'll have to consider all the options I have right now (Lua,Python,A file readed by Python). Really, thanks, you are awesome. Sergio. From roegltd at gmail.com Sun Jan 19 05:30:27 2014 From: roegltd at gmail.com (Asaf Las) Date: Sun, 19 Jan 2014 02:30:27 -0800 (PST) Subject: python-daemon for Python v3 Message-ID: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> Hi Community Is there ported to Python v3 python-daemon package? https://pypi.python.org/pypi/python-daemon/ i am afraid it is not as simple as correction of relative path input feature and except clauses in mentioned package. Thanks Asaf From rosuav at gmail.com Sun Jan 19 05:39:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 19 Jan 2014 21:39:50 +1100 Subject: question about input() and/or raw_input() In-Reply-To: <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 7:26 PM, Rustom Mody wrote: > If you want to give an irrelevant example at least give a correct one :D > the difference between str and hex is an arcane difference (Ive never used hex) > the difference between functions and procedures is absolutely basic. They don't give the same result for every possible input, any more than your two do: >>> foo(1.234567890123456) 2.23456789012 >>> bar(1.234567890123456) 2.234567890123456 (Tested on 2.7.3 on Linux. YMMV.) There's no difference in Python between functions and procedures. It's all functions, and some of them implicitly return None. If there were a difference, what would this be? def none_if(value, predicate): if not predicate(value): return value Personally, I'm quite happy with Python and the print function. (Or statement, if you prefer. Same difference.) The most fundamental aspects of any program are input, output, and preferably some computation in between; and the most fundamental forms of input are the command line / console and the program's source, and the most basic output is the console. So the most basic and obvious program needs: 1) Access to the command-line arguments 2) The ability to read from the console 3) Some means of writing to the console. Not every program will need all that, but they'd be the most obvious and simplest methods of communication - especially since they're the three that are easiest to automate. How do you run a GUI program through automated testing? With difficulty. How do you run a stdio program through automated testing? Pipe it some input and compare its output to the standard. And that means people should be accustomed to using print, and sys.argv, and (raw_)input. Fortunately Python doesn't have ob_start() / ob_get_clean() to tempt people to use print when they should use return. So there's no problem. ChrisA From ben+python at benfinney.id.au Sun Jan 19 05:41:31 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sun, 19 Jan 2014 21:41:31 +1100 Subject: python-daemon for Python v3 References: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> Message-ID: <7w7g9w9rtw.fsf@benfinney.id.au> Asaf Las writes: > Is there ported to Python v3 python-daemon package? > > https://pypi.python.org/pypi/python-daemon/ Have a read through the archives for the ?python-daemon-devel? discussion forum , where we have had discussions about porting the library to Python 3. I'd be interested to know who wants us to keep Python 2 compatibility. If we can drop that, then a Python 3 version of the library would be much easier to maintain. We are also in need of an active maintainer for the ?python-lockfile? library which is commonly used with ?python-daemon?. -- \ ?Pinky, are you pondering what I'm pondering?? ?I think so, | `\ Brain, but if we give peas a chance, won't the lima beans feel | _o__) left out?? ?_Pinky and The Brain_ | Ben Finney From irmen.NOSPAM at xs4all.nl Sun Jan 19 06:13:16 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Sun, 19 Jan 2014 12:13:16 +0100 Subject: graphical python In-Reply-To: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> References: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> Message-ID: <52dbb34b$0$2844$e4fe514c@news.xs4all.nl> On 19-1-2014 6:40, buck wrote: > I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python. > > How would you go about this? Would something like this help http://ipython.org/notebook.html ? Irmen From roegltd at gmail.com Sun Jan 19 08:21:49 2014 From: roegltd at gmail.com (Asaf Las) Date: Sun, 19 Jan 2014 05:21:49 -0800 (PST) Subject: python-daemon for Python v3 In-Reply-To: References: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> Message-ID: <6675c240-adaf-40ea-bb73-6247f94b861e@googlegroups.com> On Sunday, January 19, 2014 12:41:31 PM UTC+2, Ben Finney wrote: > Have a read through the archives for the ?python-daemon-devel? > discussion forum > , > where we have had discussions about porting the library to Python 3. > I'd be interested to know who wants us to keep Python 2 compatibility. > If we can drop that, then a Python 3 version of the library would be > much easier to maintain. Thanks. i have not seen this, but different port. it is on github. yet got myself rid of errors during pip install, but was not sure about latter. > We are also in need of an active maintainer for the ?python-lockfile? > library which is commonly > used with ?python-daemon?. I would love to contribute but as a novice in Python, need time to make something valuable for community. /Asaf From oscar.j.benjamin at gmail.com Sun Jan 19 10:46:43 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sun, 19 Jan 2014 15:46:43 +0000 Subject: Need help vectorizing code In-Reply-To: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> References: <140f8aea-d3c5-4c0d-94f5-6aa064e353d1@googlegroups.com> Message-ID: On 18 January 2014 20:51, Kevin K wrote: > I have some code that I need help vectorizing. > I want to convert the following to vector form, how can I? I want to get rid of the inner loop - apparently, it's possible to do so. > X is an NxD matrix. y is a 1xD vector. > > def foo(X, y, mylambda, N, D, epsilon): > ... > for j in xrange(D): > aj = 0 > cj = 0 > for i in xrange(N): > aj += 2 * (X[i,j] ** 2) > cj += 2 * (X[i,j] * (y[i] - w.transpose()*X[i].transpose() + w[j]*X[i,j])) As Peter said the y[i] above suggests that y has the shape (1, N) or (N, 1) or (N,) but not (1, D). Is that an error? Should it actually be y[j]? You don't give the shape of w but I guess that it is (1, D) since you index it with j. That means that w.transpose() is (D, 1). But then X[i] has the shape (D,). Broadcasting those two shapes gives a shape of (D, D) for cj. OTOH if w has the shape (D, 1) then cj has the shape (1, D). Basically your description is insufficient for me to know what your code is doing in terms of all the array shapes. So I can't really offer a vectorisation of it. > > ... > > If I call numpy.vectorize() on the function, it throws an error at runtime. You've misunderstood what the numpy.vectorize function is for. The vectorize function is a convenient way of generating a function that can operate on arrays of arbitrary shape out of a function that operates only on scalar values. Oscar From invalid at invalid.invalid Sun Jan 19 11:14:48 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 19 Jan 2014 16:14:48 +0000 (UTC) Subject: question about input() and/or raw_input() References: Message-ID: On 2014-01-18, Terry Reedy wrote: > On 1/18/2014 1:30 PM, Roy Smith wrote: >> Pardon me for being cynical, but in the entire history of the universe, >> has anybody ever used input()/raw_input() for anything other than a >> homework problem? > > Homework problems (and 'toy' programs, such as hangman), whether in a > programming class or elsewhere, are one of the intended use cases of > Python. How else would you get interactive input without the complexity > of a gui? sys.stdin.readline() From invalid at invalid.invalid Sun Jan 19 11:22:49 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 19 Jan 2014 16:22:49 +0000 (UTC) Subject: Can post a code but afraid of plagiarism References: Message-ID: On 2014-01-18, indar kumar wrote: > I want to show a code for review but afraid of plagiarism issues. > Kindly, suggest how can I post it for review here without masking it > visible for public http://www.python.org/community/jobs/ I'm sure once you've agreed on contract and payment terms with whoever you hire to do your private code review they will arrange a private communications channel. From ethan at stoneleaf.us Sun Jan 19 11:14:22 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Jan 2014 08:14:22 -0800 Subject: question about input() and/or raw_input() In-Reply-To: <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> Message-ID: <52DBF9DE.80304@stoneleaf.us> On 01/19/2014 12:26 AM, Rustom Mody wrote: > On Sunday, January 19, 2014 10:29:58 AM UTC+5:30, Chris Angelico wrote: >> On Sun, Jan 19, 2014 at 3:43 PM, Rustom Mody wrote: >>> >> As do these pieces of code: >> >>--> def quux1(x): return str(x+1) >>--> def quux2(x): return hex(x+1)[2:] > > They do? > >--> quux1(2.3) > '3.3' > >--> quux2(2.3) > Traceback (most recent call last): > File "", line 1, in > File "", line 1, in quux2 > TypeError: hex() argument can't be converted to hex (Will be) fixed in 3.5 [1] :) -- ~Ethan~ [1] Which is to say, both will raise an exception. From rosuav at gmail.com Sun Jan 19 11:38:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 03:38:29 +1100 Subject: question about input() and/or raw_input() In-Reply-To: <52DBF9DE.80304@stoneleaf.us> References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> <52DBF9DE.80304@stoneleaf.us> Message-ID: On Mon, Jan 20, 2014 at 3:14 AM, Ethan Furman wrote: >>> --> def quux1(x): return str(x+1) >> --> quux1(2.3) >> '3.3' > > (Will be) fixed in 3.5 [1] :) > [1] Which is to say, both will raise an exception. Why would that raise? ChrisA From invalid at invalid.invalid Sun Jan 19 12:42:55 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 19 Jan 2014 17:42:55 +0000 (UTC) Subject: question about input() and/or raw_input() References: Message-ID: On 2014-01-19, Dennis Lee Bieber wrote: > On Sun, 19 Jan 2014 16:14:48 +0000 (UTC), Grant Edwards > declaimed the following: > >>On 2014-01-18, Terry Reedy wrote: >>> On 1/18/2014 1:30 PM, Roy Smith wrote: >>>> Pardon me for being cynical, but in the entire history of the universe, >>>> has anybody ever used input()/raw_input() for anything other than a >>>> homework problem? >>> >>> Homework problems (and 'toy' programs, such as hangman), whether in a >>> programming class or elsewhere, are one of the intended use cases of >>> Python. How else would you get interactive input without the complexity >>> of a gui? >> >>sys.stdin.readline() > > At which point a simple: > > nm = raw_input("Enter your name: ") > print "Hello, ", nm > > turns into (to duplicate the behavior WRT line endings, and to minimize the > new features the student is exposed to) > > import sys > > sys.stdout.write("Enter your name: ") > nm = sys.stdin.readline() > nm.strip() > sys.stdout.write("Hello, ") > sys.stdout.write(nm) > sys.stdout.write("\n") > sys.stdout.flush() The question was how to get input without using a GUI. I presented an answer. You then conflated "whether or not to use input" with "whether or not to use print" and proceeded to construct and knock down a very nice straw man. Kudos. import sys print "Enter your name: ", nm = sys.stdin.readline().strip() print "Hello, ", nm > Yes, a non-beginner would have been exposed to formatting operations > and been able to condense the three .write() calls into one... 1) I don't get why you jumped on the whole print vs. string formatting thing. We're not talking about print vs write. We're talking about whether or not people use input and raw_input. I've been writing Python programs for 15 years, and I've never used either input or raw_input. 2) I didn't claim that sys.stdin.readline() was as simple as using input. I didn't claim it was preferable. I merely presented it as a refutation to the argument that if you don't use input/raw_input then you have to use a GUI toolkit. -- Grant From rosuav at gmail.com Sun Jan 19 12:59:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 04:59:53 +1100 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On Mon, Jan 20, 2014 at 4:42 AM, Grant Edwards wrote: > 2) I didn't claim that sys.stdin.readline() was as simple as using > input. I didn't claim it was preferable. I merely presented it as > a refutation to the argument that if you don't use input/raw_input > then you have to use a GUI toolkit. I'd draw a subtle distinction here, btw. With sys.stdin.readline(), you're asking to read a line from standard input, but with (raw_)input(), you're asking to read one line from the console. If it's been redirected, that's going to be equivalent (modulo newline handling), but if not, it would make sense for (raw_)input() to call on GNU Readline, where sys.stdin.readline() shouldn't. Calling a method on a file-like object representing stdin feels lower level than "ask the user for input with this prompt" (which might well do more than that, too - eg it might flush sys.stdout). ChrisA From breamoreboy at yahoo.co.uk Sun Jan 19 13:07:44 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Jan 2014 18:07:44 +0000 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On 18/01/2014 18:41, Mark Lawrence wrote: > On 18/01/2014 18:30, Roy Smith wrote: >> Pardon me for being cynical, but in the entire history of the universe, >> has anybody ever used input()/raw_input() for anything other than a >> homework problem? >> > > Not me personally. I guess raw_input must have been used somewhere at > some time for something, or it would have been scrapped in Python 3, not > renamed to input. > Actually, to go off at a tangent, I'm just getting into GUIs via wxPython. I've discovered there are distinct advantages having to write endless lines of code just to get a piece of data. For example on a Sunday it helps pass the time between the two sessions of the Masters Snooker final being shown on TV. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Sun Jan 19 13:15:40 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 19 Jan 2014 18:15:40 +0000 (UTC) Subject: question about input() and/or raw_input() References: Message-ID: On 2014-01-19, Mark Lawrence wrote: > On 18/01/2014 18:41, Mark Lawrence wrote: >> On 18/01/2014 18:30, Roy Smith wrote: >>> Pardon me for being cynical, but in the entire history of the universe, >>> has anybody ever used input()/raw_input() for anything other than a >>> homework problem? >> >> Not me personally. I guess raw_input must have been used somewhere at >> some time for something, or it would have been scrapped in Python 3, not >> renamed to input. > > Actually, to go off at a tangent, I'm just getting into GUIs via > wxPython. I've discovered there are distinct advantages having to > write endless lines of code just to get a piece of data. For example > on a Sunday it helps pass the time between the two sessions of the > Masters Snooker final being shown on TV. Fair enough, but what do you do to pass the time _during_ Snooker being shown on TV? I can still remember the point in my first trip to the UK when I accidentally stumbled across darts on TV. Given the endless variety (and quantity) of pointless crap that people watch here in the US, I can't really explain why I was so baffled and amused by darts on TV -- but I was. -- Grant Edwards grant.b.edwards Yow! I want EARS! I want at two ROUND BLACK EARS gmail.com to make me feel warm 'n secure!! From ethan at stoneleaf.us Sun Jan 19 12:50:08 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Jan 2014 09:50:08 -0800 Subject: question about input() and/or raw_input() In-Reply-To: References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> <52DBF9DE.80304@stoneleaf.us> Message-ID: <52DC1050.1020700@stoneleaf.us> On 01/19/2014 08:38 AM, Chris Angelico wrote: > On Mon, Jan 20, 2014 at 3:14 AM, Ethan Furman wrote: >>>> --> def quux1(x): return str(x+1) >>> --> quux1(2.3) >>> '3.3' >> >> (Will be) fixed in 3.5 [1] :) >> [1] Which is to say, both will raise an exception. > > Why would that raise? Sorry, should have read that closer. It will not raise. The difference I was thinking of is: "%h" % 3.14 # this works vs. hex(3.14) # this raises In 3.5 both will raise. Apologies for the noise. -- ~Ethan~ From roy at panix.com Sun Jan 19 13:37:29 2014 From: roy at panix.com (Roy Smith) Date: Sun, 19 Jan 2014 13:37:29 -0500 Subject: question about input() and/or raw_input() References: Message-ID: In article , Grant Edwards wrote: > I can still remember the point in my first trip to the UK when I > accidentally stumbled across darts on TV. Given the endless variety > (and quantity) of pointless crap that people watch here in the US, I > can't really explain why I was so baffled and amused by darts on TV -- > but I was. What's so complicated? points = 501 for dart in throws(): if points - dart == 0 and dart.is_double(): raise YouWin if points - dart < 0: continue points -= dart beer.drink() From rosuav at gmail.com Sun Jan 19 13:41:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 05:41:34 +1100 Subject: question about input() and/or raw_input() In-Reply-To: <52DC1050.1020700@stoneleaf.us> References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> <52DBF9DE.80304@stoneleaf.us> <52DC1050.1020700@stoneleaf.us> Message-ID: On Mon, Jan 20, 2014 at 4:50 AM, Ethan Furman wrote: > The difference I was thinking of is: > > "%h" % 3.14 # this works > > vs. > > hex(3.14) # this raises > > In 3.5 both will raise. Now you have me *thoroughly* intrigued. It's not %h (incomplete format - h is a modifier), nor %H (unsupported format character). Do you mean %x? As of 3.4.0b2, that happily truncates a float: >>> "%x" % 3.14 '3' Is that changing in 3.5? Seems a relatively insignificant point, tbh! Anyway, no biggie. ChrisA From rosuav at gmail.com Sun Jan 19 13:43:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 05:43:08 +1100 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On Mon, Jan 20, 2014 at 5:37 AM, Roy Smith wrote: > What's so complicated? > > points = 501 > for dart in throws(): > if points - dart == 0 and dart.is_double(): > raise YouWin > if points - dart < 0: > continue > points -= dart > beer.drink() assert victory raise beer ChrisA From pascal.ortiz at gmail.com Sun Jan 19 13:46:41 2014 From: pascal.ortiz at gmail.com (candide) Date: Sun, 19 Jan 2014 10:46:41 -0800 (PST) Subject: =?windows-1252?Q?What=92s_wrong_with_scientific_Python=3F?= Message-ID: <638006c4-d3d4-4dde-9bde-73d09650e79c@googlegroups.com> http://cyrille.rossant.net/whats-wrong-with-scientific-python/ Any comments ? From phiwer at gmail.com Sun Jan 19 13:53:59 2014 From: phiwer at gmail.com (Philip Werner) Date: Sun, 19 Jan 2014 12:53:59 -0600 Subject: Python Scalability TCP Server + Background Game References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> Message-ID: On Sat, 18 Jan 2014 13:19:24 +0000, Mark Lawrence wrote: > On 18/01/2014 12:40, phiwer at gmail.com wrote: > > [snip the stuff I can't help with] > > Here's the link you need to sort the problem with double spacing from > google groups https://wiki.python.org/moin/GoogleGroupsPython Thanks for the link. I've, hopefully, solved the issue by switching to Pan instead of using google groups. :) Regards, Philip From rosuav at gmail.com Sun Jan 19 13:58:26 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 05:58:26 +1100 Subject: Python Scalability TCP Server + Background Game In-Reply-To: References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> Message-ID: On Mon, Jan 20, 2014 at 5:53 AM, Philip Werner wrote: > On Sat, 18 Jan 2014 13:19:24 +0000, Mark Lawrence wrote: > >> On 18/01/2014 12:40, phiwer at gmail.com wrote: >> >> [snip the stuff I can't help with] >> >> Here's the link you need to sort the problem with double spacing from >> google groups https://wiki.python.org/moin/GoogleGroupsPython > > Thanks for the link. I've, hopefully, solved the issue by switching > to Pan instead of using google groups. :) Looking a lot more normal and readable now. Thanks! Note that some people have experienced odd issues with Pan, possibly relating to having multiple instances running simultaneously. You may want to take care not to let it open up a duplicate copy of itself. ChrisA From breamoreboy at yahoo.co.uk Sun Jan 19 14:10:02 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Jan 2014 19:10:02 +0000 Subject: =?windows-1252?Q?What=92s_wrong_with_scientific_Pyth?= =?windows-1252?Q?on=3F?= In-Reply-To: <638006c4-d3d4-4dde-9bde-73d09650e79c@googlegroups.com> References: <638006c4-d3d4-4dde-9bde-73d09650e79c@googlegroups.com> Message-ID: On 19/01/2014 18:46, candide wrote: > > http://cyrille.rossant.net/whats-wrong-with-scientific-python/ > > Any comments ? > Not worth reading as doesn't seem to have anything new to say. As for Python 2 being obsolete, well I just give up :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Sun Jan 19 14:11:14 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sun, 19 Jan 2014 19:11:14 +0000 (UTC) Subject: question about input() and/or raw_input() References: Message-ID: On 2014-01-19, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> I can still remember the point in my first trip to the UK when I >> accidentally stumbled across darts on TV. Given the endless variety >> (and quantity) of pointless crap that people watch here in the US, I >> can't really explain why I was so baffled and amused by darts on TV -- >> but I was. > > What's so complicated? > > points = 501 > for dart in throws(): > if points - dart == 0 and dart.is_double(): > raise YouWin > if points - dart < 0: > continue > points -= dart > beer.drink() That looks like an algorithm for _playing_ darts. That I understand. I have two dartboards (one real, one electronic) and a coule decent sets of darts. It's watching darts on TV that I don't get. Actually, I don't really get watching any sort of sports on TV (even the ones I play). But there was just something about darts on TV that seemed particularly beyond the pale. -- Grant Edwards grant.b.edwards Yow! But they went to MARS at around 1953!! gmail.com From breamoreboy at yahoo.co.uk Sun Jan 19 14:17:30 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Jan 2014 19:17:30 +0000 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On 19/01/2014 18:15, Grant Edwards wrote: > On 2014-01-19, Mark Lawrence wrote: >> On 18/01/2014 18:41, Mark Lawrence wrote: >>> On 18/01/2014 18:30, Roy Smith wrote: >>>> Pardon me for being cynical, but in the entire history of the universe, >>>> has anybody ever used input()/raw_input() for anything other than a >>>> homework problem? >>> >>> Not me personally. I guess raw_input must have been used somewhere at >>> some time for something, or it would have been scrapped in Python 3, not >>> renamed to input. >> >> Actually, to go off at a tangent, I'm just getting into GUIs via >> wxPython. I've discovered there are distinct advantages having to >> write endless lines of code just to get a piece of data. For example >> on a Sunday it helps pass the time between the two sessions of the >> Masters Snooker final being shown on TV. > > Fair enough, but what do you do to pass the time _during_ Snooker > being shown on TV? > > I can still remember the point in my first trip to the UK when I > accidentally stumbled across darts on TV. Given the endless variety > (and quantity) of pointless crap that people watch here in the US, I > can't really explain why I was so baffled and amused by darts on TV -- > but I was. > Just no comparison, darts and snooker. This is excellent though http://www.youtube.com/watch?v=sHnBppccI0o -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Sun Jan 19 14:23:34 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Jan 2014 06:23:34 +1100 Subject: =?utf-8?Q?What=E2=80=99s?= wrong with scientific Python? References: <638006c4-d3d4-4dde-9bde-73d09650e79c@googlegroups.com> Message-ID: <7w38kjai89.fsf@benfinney.id.au> candide writes: > http://cyrille.rossant.net/whats-wrong-with-scientific-python/ > Any comments ? It's in need of a good summary. -- \ ?I have never imputed to Nature a purpose or a goal, or | `\ anything that could be understood as anthropomorphic.? ?Albert | _o__) Einstein, unsent letter, 1955 | Ben Finney From larry.martell at gmail.com Sun Jan 19 14:24:52 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 19 Jan 2014 12:24:52 -0700 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence wrote: > On 19/01/2014 18:15, Grant Edwards wrote: >> >> On 2014-01-19, Mark Lawrence wrote: >>> Actually, to go off at a tangent, I'm just getting into GUIs via >>> wxPython. I've discovered there are distinct advantages having to >>> write endless lines of code just to get a piece of data. For example >>> on a Sunday it helps pass the time between the two sessions of the >>> Masters Snooker final being shown on TV. >> >> >> Fair enough, but what do you do to pass the time _during_ Snooker >> being shown on TV? >> >> I can still remember the point in my first trip to the UK when I >> accidentally stumbled across darts on TV. Given the endless variety >> (and quantity) of pointless crap that people watch here in the US, I >> can't really explain why I was so baffled and amused by darts on TV -- >> but I was. >> > > Just no comparison, darts and snooker. This is excellent though > http://www.youtube.com/watch?v=sHnBppccI0o Now that we're way off on the tangent of what some people consider boring and others don't, I'm really looking forward to watching curling in the upcoming Olympics. From breamoreboy at yahoo.co.uk Sun Jan 19 14:29:26 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Jan 2014 19:29:26 +0000 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: On 19/01/2014 19:24, Larry Martell wrote: > On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence wrote: >> On 19/01/2014 18:15, Grant Edwards wrote: >>> >>> On 2014-01-19, Mark Lawrence wrote: >>>> Actually, to go off at a tangent, I'm just getting into GUIs via >>>> wxPython. I've discovered there are distinct advantages having to >>>> write endless lines of code just to get a piece of data. For example >>>> on a Sunday it helps pass the time between the two sessions of the >>>> Masters Snooker final being shown on TV. >>> >>> >>> Fair enough, but what do you do to pass the time _during_ Snooker >>> being shown on TV? >>> >>> I can still remember the point in my first trip to the UK when I >>> accidentally stumbled across darts on TV. Given the endless variety >>> (and quantity) of pointless crap that people watch here in the US, I >>> can't really explain why I was so baffled and amused by darts on TV -- >>> but I was. >>> >> >> Just no comparison, darts and snooker. This is excellent though >> http://www.youtube.com/watch?v=sHnBppccI0o > > Now that we're way off on the tangent of what some people consider > boring and others don't, I'm really looking forward to watching > curling in the upcoming Olympics. > Curling, now there's another good reason to allow Scottish independance :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From larry.martell at gmail.com Sun Jan 19 14:30:21 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 19 Jan 2014 12:30:21 -0700 Subject: python-daemon for Python v3 In-Reply-To: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> References: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 3:30 AM, Asaf Las wrote: > Hi Community > > Is there ported to Python v3 python-daemon package? > > https://pypi.python.org/pypi/python-daemon/ > > i am afraid it is not as simple as correction of relative path input > feature and except clauses in mentioned package. I use this technique for demonizing: http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ And has been ported to 3: http://www.jejik.com/files/examples/daemon3x.py From workitharder at gmail.com Sun Jan 19 14:30:09 2014 From: workitharder at gmail.com (buck) Date: Sun, 19 Jan 2014 11:30:09 -0800 (PST) Subject: graphical python In-Reply-To: References: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> Message-ID: On Sunday, January 19, 2014 12:19:29 AM UTC-8, Ian wrote: > On Sat, Jan 18, 2014 at 10:40 PM, buck wrote: > > > I'm trying to work through Skienna's algorithms handbook, and note that the author often uses graphical representations of the diagrams to help understand (and even debug) the algorithms. I'd like to reproduce this in python. > > > > > > How would you go about this? pyQt, pygame and pyglet immediately come to mind, but if I go that route the number of people that I can share my work with becomes quite limited, as compared to the portability of javascript projects. > > > > > > I guess my question really is: has anyone had success creating an interactive graphical project in the browser using python? > > > > > > Is this a dream I should give up on, and just do this project in coffeescript/d3? > > > > You should be able to do something without much fuss using HTML 5 and > > either Pyjamas (which compiles Python code to Javascript) or Brython > > (a more or less complete implementation of Python within Javascript). > > For example, see the clock demo on the Brython web page. > > > > Pyjamas is the more established and probably more stable of the two > > projects, but you should be aware that there are currently two active > > forks of Pyjamas and some controversy surrounding the project > > leadership. Thanks Ian. Have you personally used pyjs successfully? It's ominous that the examples pages are broken... I was impressed with the accuracy of the Brython implementation. I hope they're able to decrease the web weight in future versions. From ethan at stoneleaf.us Sun Jan 19 14:16:12 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 19 Jan 2014 11:16:12 -0800 Subject: question about input() and/or raw_input() In-Reply-To: References: <2b7f1a5d-4145-4f7d-be47-72d5eb207391@googlegroups.com> <07dc8493-fb43-47b4-b080-7bc1ae3d6681@googlegroups.com> <52663f72-8c61-4868-9887-7e980d90ec61@googlegroups.com> <52DBF9DE.80304@stoneleaf.us> <52DC1050.1020700@stoneleaf.us> Message-ID: <52DC247C.5040805@stoneleaf.us> On 01/19/2014 10:41 AM, Chris Angelico wrote: > On Mon, Jan 20, 2014 at 4:50 AM, Ethan Furman wrote: >> The difference I was thinking of is: >> >> "%h" % 3.14 # this works >> >> vs. >> >> hex(3.14) # this raises >> >> In 3.5 both will raise. > > Now you have me *thoroughly* intrigued. It's not %h (incomplete format > - h is a modifier), nor %H (unsupported format character). Do you mean > %x? As of 3.4.0b2, that happily truncates a float: > >>>> "%x" % 3.14 > '3' > > Is that changing in 3.5? Seems a relatively insignificant point, tbh! Argh. Yes, %x or %X. -- ~Ethan~ From denismfmcmahon at gmail.com Sun Jan 19 15:05:33 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 19 Jan 2014 20:05:33 +0000 (UTC) Subject: Help with simple code that has database defined References: <4ea55e83-cfcd-4aaf-824a-3e3bced921c2@googlegroups.com> Message-ID: On Sat, 18 Jan 2014 18:23:01 -0800, indar kumar wrote: > I have to save students information in a database that is keeping > continuously track of the information. Format is as follows: You probably need to use one of the database modules. > Note: if this name already exists there in database, just update the > information of that(name) e.g course,grade and date. Otherwise, add it. That sounds like an sql issue specific to your chosen database, not a python issue. > This is just part because this is what I know how to do, for rest have > no idea I suggest you get idea fast. Or ask your lecturers for advice. Or return the advance you were paid on this coding job, because you don't seem to have the skills to do it. -- Denis McMahon, denismfmcmahon at gmail.com From gheskett at wdtv.com Sun Jan 19 15:12:33 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 19 Jan 2014 15:12:33 -0500 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: <201401191512.34064.gheskett@wdtv.com> On Sunday 19 January 2014 15:11:52 Larry Martell did opine: > On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence wrote: > > On 19/01/2014 18:15, Grant Edwards wrote: > >> On 2014-01-19, Mark Lawrence wrote: > >>> Actually, to go off at a tangent, I'm just getting into GUIs via > >>> wxPython. I've discovered there are distinct advantages having to > >>> write endless lines of code just to get a piece of data. For > >>> example on a Sunday it helps pass the time between the two sessions > >>> of the Masters Snooker final being shown on TV. > >> > >> Fair enough, but what do you do to pass the time _during_ Snooker > >> being shown on TV? > >> > >> I can still remember the point in my first trip to the UK when I > >> accidentally stumbled across darts on TV. Given the endless variety > >> (and quantity) of pointless crap that people watch here in the US, I > >> can't really explain why I was so baffled and amused by darts on TV > >> -- but I was. > > > > Just no comparison, darts and snooker. This is excellent though > > http://www.youtube.com/watch?v=sHnBppccI0o > > Now that we're way off on the tangent of what some people consider > boring and others don't, I'm really looking forward to watching > curling in the upcoming Olympics. I have Larry, and the suspense is not good for those with high blood pressure. Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page Required reading: I've enjoyed just about as much of this as I can stand. A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From gheskett at wdtv.com Sun Jan 19 15:09:22 2014 From: gheskett at wdtv.com (Gene Heskett) Date: Sun, 19 Jan 2014 15:09:22 -0500 Subject: question about input() and/or raw_input() In-Reply-To: References: Message-ID: <201401191509.22272.gheskett@wdtv.com> On Sunday 19 January 2014 15:08:31 Roy Smith did opine: > In article , > > Grant Edwards wrote: > > I can still remember the point in my first trip to the UK when I > > accidentally stumbled across darts on TV. Given the endless variety > > (and quantity) of pointless crap that people watch here in the US, I > > can't really explain why I was so baffled and amused by darts on TV -- > > but I was. > > What's so complicated? > > points = 501 > for dart in throws(): > if points - dart == 0 and dart.is_double(): > raise YouWin > if points - dart < 0: > continue > points -= dart > beer.drink() Aren't you missing a fi there, or a next dart? ;-) Cheers, Gene -- "There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order." -Ed Howdershelt (Author) Genes Web page Required reading: Baseball is a skilled game. It's America's game - it, and high taxes. -- The Best of Will Rogers A pen in the hand of this president is far more dangerous than 200 million guns in the hands of law-abiding citizens. From ian.g.kelly at gmail.com Sun Jan 19 15:20:36 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Sun, 19 Jan 2014 13:20:36 -0700 Subject: graphical python In-Reply-To: References: <6ab6e315-78e1-4f14-9925-16bd9a4a0199@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 12:30 PM, buck wrote: > Thanks Ian. > Have you personally used pyjs successfully? > It's ominous that the examples pages are broken... I don't have any personal experience with either project. I don't know what's going on with pyjs.org currently, but the examples at the pyj.be fork seem to be in working order. From larry.martell at gmail.com Sun Jan 19 15:22:03 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 19 Jan 2014 13:22:03 -0700 Subject: question about input() and/or raw_input() In-Reply-To: <201401191512.34064.gheskett@wdtv.com> References: <201401191512.34064.gheskett@wdtv.com> Message-ID: On Sun, Jan 19, 2014 at 1:12 PM, Gene Heskett wrote: > On Sunday 19 January 2014 15:11:52 Larry Martell did opine: > >> On Sun, Jan 19, 2014 at 12:17 PM, Mark Lawrence > wrote: >> > On 19/01/2014 18:15, Grant Edwards wrote: >> >> On 2014-01-19, Mark Lawrence wrote: >> >>> Actually, to go off at a tangent, I'm just getting into GUIs via >> >>> wxPython. I've discovered there are distinct advantages having to >> >>> write endless lines of code just to get a piece of data. For >> >>> example on a Sunday it helps pass the time between the two sessions >> >>> of the Masters Snooker final being shown on TV. >> >> >> >> Fair enough, but what do you do to pass the time _during_ Snooker >> >> being shown on TV? >> >> >> >> I can still remember the point in my first trip to the UK when I >> >> accidentally stumbled across darts on TV. Given the endless variety >> >> (and quantity) of pointless crap that people watch here in the US, I >> >> can't really explain why I was so baffled and amused by darts on TV >> >> -- but I was. >> > >> > Just no comparison, darts and snooker. This is excellent though >> > http://www.youtube.com/watch?v=sHnBppccI0o >> >> Now that we're way off on the tangent of what some people consider >> boring and others don't, I'm really looking forward to watching >> curling in the upcoming Olympics. > > I have Larry, and the suspense is not good for those with high blood > pressure. Then don't watch the women: http://oglympics.com/2010/02/16/women-of-curling-fire-on-ice/ From charleshixsn at earthlink.net Sun Jan 19 16:26:03 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Sun, 19 Jan 2014 13:26:03 -0800 Subject: Documentation of dict views change request Message-ID: <52DC42EB.2010707@earthlink.net> Could it please be clearly documented that keys(), values(), and items() are not writeable. I agree that this is how they should be, but it would be still better if they were clearly documented as such. The labeling of them as dynamic, while true, was a bit confusing here. (I.e., it was talking about changing their value through other means of access rather than directly through the returned values.) P.S.: Is it reasonable to return the items() of a dict in order to pass a read only copy of the values? -- Charles Hixson From breamoreboy at yahoo.co.uk Sun Jan 19 16:41:25 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 19 Jan 2014 21:41:25 +0000 Subject: Documentation of dict views change request In-Reply-To: <52DC42EB.2010707@earthlink.net> References: <52DC42EB.2010707@earthlink.net> Message-ID: On 19/01/2014 21:26, Charles Hixson wrote: > Could it please be clearly documented that keys(), values(), and items() > are not writeable. I agree that this is how they should be, but it > would be still better if they were clearly documented as such. The > labeling of them as dynamic, while true, was a bit confusing here. > (I.e., it was talking about changing their value through other means of > access rather than directly through the returned values.) > > P.S.: Is it reasonable to return the items() of a dict in order to pass > a read only copy of the values? > Just raise an issue here http://bugs.python.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Sun Jan 19 16:40:58 2014 From: roy at panix.com (Roy Smith) Date: Mon, 20 Jan 2014 03:10:58 +0530 Subject: Documentation of dict views change request References: Message-ID: In article , Charles Hixson wrote: > Could it please be clearly documented that keys(), values(), and items() > are not writeable. We'll, technically, they are. >>> d = {'foo': 1, 'bar':2} >>> k = d.keys() >>> k ['foo', 'bar'] >>> k[0] = "some other key" >>> k ['some other key', 'bar'] Of course, this only changes the list that keys() returns, it doesn't affect the dictionary itself (which, I assume, is what you were really talking about). Think this one through. How *could* altering what keys() returns possibly affect the dict? If it did, that means you could do something like: some_dict.keys().append("some other key") what would that mean? You've added a key, but what's the corresponding value? I will admit, the picture becomes a bit fuzzier if you consider: some_dict.items().append(("some other key", 42)) which you could at least imagine would affect the underlying dict. From rosuav at gmail.com Sun Jan 19 16:56:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 08:56:42 +1100 Subject: Documentation of dict views change request In-Reply-To: References: Message-ID: On Mon, Jan 20, 2014 at 8:40 AM, Roy Smith wrote: > In article , > Charles Hixson wrote: > >> Could it please be clearly documented that keys(), values(), and items() >> are not writeable. > > We'll, technically, they are. > > Of course, this only changes the list that keys() returns, it doesn't > affect the dictionary itself (which, I assume, is what you were really > talking about). In Python 3, they return views, not lists. So they really are read-only. On Mon, Jan 20, 2014 at 8:26 AM, Charles Hixson wrote: > P.S.: Is it reasonable to return the items() of a dict in order to pass a > read only copy of the values? No, because it isn't a copy. At least, not in Python 3; if you're using Python 2, then the wording of your subject line is inaccurate, see above. >>> d = {"a":1,"b":2,"c":3} >>> i = d.items() >>> del d["b"] >>> list(i) [('a', 1), ('c', 3)] If you returned i from a function and expected it to be a copy, you'd be in for a nasty shock. Try the .copy() method for a shallow copy, or look up deepcopy if you need a recursive copy. ChrisA From piet at vanoostrum.org Sun Jan 19 17:06:05 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Sun, 19 Jan 2014 23:06:05 +0100 Subject: How to write this as a list comprehension? References: Message-ID: John Allsup writes: > Hi, > > I'd agree with the advice that it's not the best idea: readability sucks > here, but consider the following: > > > import time > > def somefunc(a,b,c,d): # dummy function > return "{} - {} - {} : {}".format(a,b,c,d) > l = [(time.time(),"name {}".format(n)) for n in range(100)] # dummy data > > # the line in question > labels = [somefunc(*(lambda t,n: > (t.tm_mon,t.tm_mday,t.tm_wday,n))(time.localtime(x[0]),x[1])) for x in > l] > > > print(labels) # just to see the result > > > If you find that hard to decipher, the consider the maintainability of > code you write that uses such comprehensions. You need to include > comments that explain what this does, and it is easier to write a > longhand version using .append() and variable assignments. I presume > performance won't be an issue determining the right approach, since then > you'd be using C or C++. I'll stay with labels = [somefunc(mn, day, wd, name) for then, name in mylist for _, mn, dy, _, _, _, wd, _, _ in [localtime(then)]] where (sic!) the last part means as much as where _, mn, dy, _, _, _, wd, _, _ = localtime(then) I find the list comprehension preferable because it makes it more clear that a new list is constructed from an existing list, something that is not as immediately clear with the append construction. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From tjreedy at udel.edu Sun Jan 19 18:22:07 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 19 Jan 2014 18:22:07 -0500 Subject: Documentation of dict views change request In-Reply-To: References: <52DC42EB.2010707@earthlink.net> Message-ID: On 1/19/2014 4:41 PM, Mark Lawrence wrote: > On 19/01/2014 21:26, Charles Hixson wrote: >> Could it please be clearly documented that keys(), values(), and items() >> are not writeable. I agree that this is how they should be, but it >> would be still better if they were clearly documented as such. The >> labeling of them as dynamic, while true, was a bit confusing here. >> (I.e., it was talking about changing their value through other means of >> access rather than directly through the returned values.) >> >> P.S.: Is it reasonable to return the items() of a dict in order to pass >> a read only copy of the values? >> > > Just raise an issue here http://bugs.python.org/ The relevant section is 4.10.1. Dictionary view objects? The objects returned by dict.keys(), dict.values() and dict.items() are view objects. The 'view object' are implicitly 'read-only' because no syntax is given to write to them, but ahead and propose adding 'read-only' to make the above explicitly say "read-only view objects". -- Terry Jan Reedy From self at gkayaalp.com Sun Jan 19 20:30:57 2014 From: self at gkayaalp.com (=?utf-8?B?R8O2a3R1xJ8=?= Kayaalp) Date: Mon, 20 Jan 2014 03:30:57 +0200 Subject: Python program distribution - a source of constant friction In-Reply-To: References: Message-ID: <20140120013057.GA9342@localhost> On Mon, Jan 06, 2014 at 11:39:13PM +0000, Nicholas Cole wrote: > This email is inspired by a YouTube video of a talk that Jessica McKellar Could you please share the link to the video please? > recently gave. I was struck by her analysis that it is hard to remain a > popular language (as Python currently is) and her call to action to address > friction points that make it hard for a non-Python audience to use Python > and applications developed in Python. > > Well, here is one. > > All of the early books one reads on Python compare it to Java or similar > languages. Write code once, is the promise, and as long as your target > computer has a Python interpreter, your code will run. For Java, I have to > say! this really does seem true. Once I have a Java environment installed, > Java applications work seamlessly. I download them, execute them, and, > unless they are very old and give themselves away by using a non-native set > of GUI widgets, I probably forget that I am running Java at all. > > But as we all know, Python isn't that simple. I'm not talking about the > problems of cross-platform GUIs or other such things. I'm taking about the > problem of distributing anything more complicated than a single-file > program to end users. > > I realise that I'm not really, either, taking about the much written > about Python packaging problem. I was going to berate the packaging > documentation for not really helping with the problem I have in mind, but I > realised that actually the kinds of packages that the Packaging Guide is > taking about are the kinds of things that developers and python-proficient > system administrators will be installing. > > But what about the end-user? The end-user who just wants a blob (he > doesn't care about what language it is in - he just wants to solve the > problem at hand with your shiny, cool, problem-solving application). He is > hopefully using a system on which Python comes as default. At most one > might get him to install a new Python interpreter and standard library, but > asking him to do more than that is simply asking more than he will do. > Will your code run or not? (i.e. without him having to learn what pip is!) > > There are tools that will package up binaries of python and create > something that will even run without an interpreter installed on the target > system. If only they were better documented, less fragile and worked > consistently with Python 3! Even then, I'm not sure this is the answer - > anything like that is bound to be a bit fragile and break one of the > attractive features of Python - that all things being equal, I don't need > to maintain development environments for every possible target platform to > get code to run. > > What would be nice is something much less complicated. Something , for > example, that just takes everything except the python interpreter from a > virtual environment, packs it up and turns it into a zip archive that > really will run on a user's python installation without any additional > steps. There are a couple of tools to do something close to this, but they > are hardly well signposted in the python documentation (in fact I only > found them with the help of this list), and even these tools need more than > a little experimentation to get right. No doubt even here some extra glue > or magic would be useful - what is the right thing to do when C modules are > needed? But at any rate, I think that some more thought in this area would > be very useful. > > And what about WSGI apps? I regard WSGI as one of the great features of > modern Python. But again, end users don't really want to have to learn all > about python and proxy servers running in front of special WSGI servers. > Most are not going to serve hundreds of thousands of users, but probably > do need a little more than one connection at a time. Even if the right > solution is to create these complicated setups, I defy anyone to find me a > page I could point a competent system administrator (but non-Python > developer) at and say, "here is my code, install it in this directory and > set up a webserver according to the instructions on this single web page > and everything will just work." > > We are even further away from saying, "Here is a special zip file. Make > sure you have a Python 3 interpreter ready and then just treat this file as > you would any other service on your system. Have it started by whatever > daemon manages services on your server, and it will all just work and be > able to handle a reasonable number of users with a reasonable level of > security and reliability. Of course, if you end up with more than a few > hundred users, you will need something more specialised." > > Python *packaging* looks as if it is getting sorted out. Pip is going to > be part of Python 3.4 and PyPI works very well. The instructions on the net > for packaging things for a Python audience are extremely good. Sending > python code to other python developers is extremely easy. > > But it is not easy to send code to non-python developers. The promise that > you can just get your users to install a Python interpreter and then give > them code to run on it is a worthy dream. Perhaps all the pieces to do > this all seamlessly exist already, but if so they need much better > documentation, somewhere that it is really easy to find it. > > IMHO, anyway. > > Nicholas > -- > https://mail.python.org/mailman/listinfo/python-list -- G?ktu? Kayaalp From rhodri at wildebst.org.uk Sun Jan 19 18:41:02 2014 From: rhodri at wildebst.org.uk (Rhodri James) Date: Sun, 19 Jan 2014 23:41:02 -0000 Subject: How to write this as a list comprehension? References: Message-ID: On Sat, 18 Jan 2014 16:00:45 -0000, Jussi Piitulainen wrote: > Rustom Mody writes: > >> On Saturday, January 18, 2014 2:06:29 PM UTC+5:30, Peter Otten wrote: >> >> > What would a list-comp with `let` or `where` look like? Would it >> > win the beauty contest against the loop? >> >> For me this is neat >> >> [somefunc(mn,day,wd,name) for (then, name) in mylist let >> (_,mn,dy,_,_,_,wd,_,_) = localtime(then)] >> >> Others may not find it so! Count me firmly in the "others" camp. It looks ugly, it flows appallingly badly as English, and its only going to get worse as you pile in more variables and expressions. -100 from me. >> See it across > 1 line (as I guess it will come after being posted!) >> and its not so neat. > > I would write that on three lines anyway, properly indented: > > [ somefunc(mn,day,wd,name) > for (then, name) in mylist > let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ] > > It could be made to use existing keywords: > > [ somefunc(mn,day,wd,name) > for (then, name) in mylist > with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ] Better, in that it's readable. It's still storing up trouble, though. Seriously, what's inelegant about this? def meaningful_name(then, name): _,mn,dy,_,_,_,wd,_,_ = localtime(then) return somefunc(mn, dy, wd, name) ... [meaningful_name(then, name) for (then, name) in mylist] I assume there's some good reason you didn't want somefunc() to do the localtime() itself? -- Rhodri James *-* Wildebeest Herder to the Masses From jeandupont314 at gmail.com Sun Jan 19 23:04:05 2014 From: jeandupont314 at gmail.com (Jean Dupont) Date: Sun, 19 Jan 2014 20:04:05 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> Message-ID: <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: > On 18 January 2014 14:52, Jean Dupont wrote: > > > > Thanks Peter and Terry Jan for the useful suggestions. One thing which I > >find a bit weird: when asking for Python-help concerning raspberry pi code > > or problems, a lot of people don't seem to be interested in helping out, > > that's of course their choice, but maybe they don't seem to be aware the > > raspberry pi is often the motivation for starting to learn to program in > >Python. And as such such a reaction is a bit disappointing. > Hi Jean, > What makes you say that? Did you previously ask questions about > Rasberry Pi code on this list? It was not about code but about python-coding in IDLE (that's the default on raspbian): I started a thread "[newbie] starting geany from within idle does not work" both here and in the raspberry pi forum. I just wondered why I never got an answer concerning that topic. > If you did I wouldn't have answered those questions because I've never > used a Raspberry Pi and know nothing about them (except that they > encourage using Python somehow). I think that there's actually a list > that is specifically for Raspberry Pi Python questions that might be > more helpful although I don't know what it is... Here is the url to that forum http://www.raspberrypi.org/forum/ kind regards, jean From roegltd at gmail.com Sun Jan 19 23:57:04 2014 From: roegltd at gmail.com (Asaf Las) Date: Sun, 19 Jan 2014 20:57:04 -0800 (PST) Subject: python-daemon for Python v3 In-Reply-To: References: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> Message-ID: <54f2f5ab-a1a9-4dd9-b0e9-41a24f354759@googlegroups.com> On Sunday, January 19, 2014 9:30:21 PM UTC+2, Larry.... at gmail.com wrote: > On Sun, Jan 19, 2014 at 3:30 AM, Asaf Las wrote: > I use this technique for demonizing: > http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ > And has been ported to 3: > http://www.jejik.com/files/examples/daemon3x.py Thanks! i have seen this code before. Did you encounter any problem with it before for long running tasks? Asaf From drsalists at gmail.com Mon Jan 20 00:21:44 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Sun, 19 Jan 2014 21:21:44 -0800 Subject: Can post a code but afraid of plagiarism In-Reply-To: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 18, 2014 at 10:31 PM, Steven D'Aprano wrote: > On Sat, 18 Jan 2014 14:32:21 -0800, indar kumar wrote: > >> @Roy Smith >> >> Can you help me privately because its an assignment and have to submit >> plagiarism free > > Then don't plagiarise. > > > Plagiarism means YOU copy other people. You shouldn't get in trouble > because other people copy you. I did a short time of teaching while I was in school. If three students all turned in the same assignment, they all got docked significantly. There was no "who copied off of whom?", it was "someone shared when they shouldn't have." From larry.martell at gmail.com Mon Jan 20 01:19:04 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 19 Jan 2014 23:19:04 -0700 Subject: python-daemon for Python v3 In-Reply-To: <54f2f5ab-a1a9-4dd9-b0e9-41a24f354759@googlegroups.com> References: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> <54f2f5ab-a1a9-4dd9-b0e9-41a24f354759@googlegroups.com> Message-ID: On Sun, Jan 19, 2014 at 9:57 PM, Asaf Las wrote: > On Sunday, January 19, 2014 9:30:21 PM UTC+2, Larry.... at gmail.com wrote: >> On Sun, Jan 19, 2014 at 3:30 AM, Asaf Las wrote: >> I use this technique for demonizing: >> http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ >> And has been ported to 3: >> http://www.jejik.com/files/examples/daemon3x.py > > Thanks! i have seen this code before. Did you encounter any problem with > it before for long running tasks? Nope, no problems at all. From rosuav at gmail.com Mon Jan 20 01:21:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 17:21:30 +1100 Subject: Can post a code but afraid of plagiarism In-Reply-To: References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg wrote: > I did a short time of teaching while I was in school. If three > students all turned in the same assignment, they all got docked > significantly. There was no "who copied off of whom?", it was > "someone shared when they shouldn't have." What a wonderful way to promote an attitude of "my code is MY CODE and should never leave my sight". What a delightful way of thinking to unleash on the world. ChrisA From rosuav at gmail.com Mon Jan 20 01:24:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 17:24:31 +1100 Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> Message-ID: On Mon, Jan 20, 2014 at 3:04 PM, Jean Dupont wrote: > I started a thread "[newbie] starting geany from within idle does not > work" both here and in the raspberry pi forum. I just wondered why I never > got an answer concerning that topic. I saw that thread. It looked like a R-Pi problem, not a Python one, so I didn't respond because I don't have an R-Pi. If you get no response on the R-Pi forum, you might want to see if you can duplicate the issue on a desktop computer - preferably on Win/Mac/Lin, as those are the platforms most people use. That, with exact steps to repro (which it looks like you gave for the R-Pi, though again I can't verify), would get some interest. ChrisA From roegltd at gmail.com Mon Jan 20 01:21:01 2014 From: roegltd at gmail.com (Asaf Las) Date: Sun, 19 Jan 2014 22:21:01 -0800 (PST) Subject: python-daemon for Python v3 In-Reply-To: References: <0fdbd07c-d792-4230-bc4c-f683110d87c4@googlegroups.com> <54f2f5ab-a1a9-4dd9-b0e9-41a24f354759@googlegroups.com> Message-ID: On Monday, January 20, 2014 8:19:04 AM UTC+2, Larry.... at gmail.com wrote: > Nope, no problems at all. Thanks! From bieffe62 at gmail.com Mon Jan 20 02:25:40 2014 From: bieffe62 at gmail.com (Francesco Bochicchio) Date: Sun, 19 Jan 2014 23:25:40 -0800 (PST) Subject: Python declarative In-Reply-To: <9ccc7180-3ebd-4976-b2e3-3013ca6569b0@googlegroups.com> References: <9ccc7180-3ebd-4976-b2e3-3013ca6569b0@googlegroups.com> Message-ID: Looking at my own code after four years, I just realized that most of parentheses can be avoided by redefining the += operators to be a synonym of the add method. Go figure, I guess that with age it _does_ come a little wisdom ... :-) Ciao ----- FB From ben+python at benfinney.id.au Mon Jan 20 02:39:44 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Jan 2014 18:39:44 +1100 Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85k3dvw18f.fsf@benfinney.id.au> Chris Angelico writes: > On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg wrote: > > I did a short time of teaching while I was in school. If three > > students all turned in the same assignment, they all got docked > > significantly. There was no "who copied off of whom?", it was > > "someone shared when they shouldn't have." > > What a wonderful way to promote an attitude of "my code is MY CODE and > should never leave my sight". What a delightful way of thinking to > unleash on the world. Teachers are asked to grade each student on how that student exercises the relevant skills. Sometimes the relevant skills include collaboration, in which case the students should be expected and encouraged to base their work directly on the work of others. In these cases, we would expect the teacher not to discourage sharing of information. But sometimes different skills are being examined, and the student should be exercising skills on their own without basing it directly on the work of others. In these cases, penalties for plagiarism are appropriate, would you agree? -- \ ?When I wake up in the morning, I just can't get started until | `\ I've had that first, piping hot pot of coffee. Oh, I've tried | _o__) other enemas...? ?Emo Philips | Ben Finney From alec.taylor6 at gmail.com Mon Jan 20 02:54:56 2014 From: alec.taylor6 at gmail.com (Alec Taylor) Date: Sun, 19 Jan 2014 23:54:56 -0800 (PST) Subject: Generating documentation for Python and JavaScript/AngularJS to the one doc server? Message-ID: <1afa20c5-1377-4651-a5bc-3f1ee4c62ed3@googlegroups.com> The advantages of this approach include: - Consistent docstring syntax everywhere - Centralsied documentation server; find all your docs in one place Search and jump-to-source from any documented function or class; in either language Are there any modules integrating with Sphinx or similar; which generate+put your JavaScript and Python documentation in one place? Thanks for all suggestions From rosuav at gmail.com Mon Jan 20 02:59:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 18:59:15 +1100 Subject: Can post a code but afraid of plagiarism In-Reply-To: <85k3dvw18f.fsf@benfinney.id.au> References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <85k3dvw18f.fsf@benfinney.id.au> Message-ID: On Mon, Jan 20, 2014 at 6:39 PM, Ben Finney wrote: > But sometimes different skills are being examined, and the student > should be exercising skills on their own without basing it directly on > the work of others. In these cases, penalties for plagiarism are > appropriate, would you agree? If Fred writes something and Bill copies it without acknowledging Fred's work, then Bill should be penalized. That much is clear. That aligns well with the requirement to see what each student can accomplish, and with standard copyright law (including open source, where requirement-to-acknowledge is a common part of both licensing and courtesy). But why should Fred be punished? What has he done wrong? If it can be proven that Fred wrote the code (granted, that's hard to prove, but providing each student with a git/hg repo to push code to every day would make it easier), he should be graded on that code and not on the fact that someone else ripped it off. When it's less clear who copied from whom, I can understand issuing across-the-board penalties in the interests of fairness (and because the effort of figuring out who wrote what isn't worth it), but I'd say it's a compromise for simplicity rather than justifiable punishment on someone who published code. ChrisA From indarkumar59 at gmail.com Mon Jan 20 02:55:59 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Sun, 19 Jan 2014 23:55:59 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Thanks all for help and positive comments. Actually, I tried to ask some questions but I was discouraged to do so saying that I was working on a project or some assignment. Truth be told I am stuck at one point and since I don't have experience with programming language, I have been working for it for two days but couldn't come up with some idea so posted some questions of the same format just to know whether there is particular method etc to do so. Hint would have been enough but I was strictly discouraged. You know the pain of working on assignment related to areas like socket programming and you even don't know how to use dictionaries and you are given only a week. Atleast I am trying to learn. The things that I am asking here are just basics on which my whole code would be building upon. But, as I said time is very less and have other courses also so wanted to know just the manipulation of dictionaries. If you allow me I can post a small part of that assignment, it just requires the manipulation with dictionary which I am not getting. I am not asking to write a code for me. But a small hint would get me out of trouble. From ben+python at benfinney.id.au Mon Jan 20 03:10:46 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Jan 2014 19:10:46 +1100 Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <85k3dvw18f.fsf@benfinney.id.au> Message-ID: <85fvojvzsp.fsf@benfinney.id.au> Chris Angelico writes: > If Fred writes something and Bill copies it without acknowledging > Fred's work, then Bill should be penalized. That much is clear. The situation is where a student is being examined for skills where it's appropriate to test the student's own skill with a reasonable level of isolation from the relevant work of others. So questions of plagiarism aren't relevant to that aspect. > But why should Fred be punished? What has he done wrong? Fred has, in your example, ignored the requirements to keep his own work on the assignment isolated from Bill. This is harmful to the assessment of both Bill and Fred, since the teacher has a severely lessened ability to determine both Bill's and Fred's individual competence levels at the skill being examined. So, to encourage both Bill and Fred to keep their work isolated and allow their levels of competence to be assessed with confidence, they both need to have disincentive to both copy work and allow their work to be copied. > When it's less clear who copied from whom, I can understand issuing > across-the-board penalties in the interests of fairness (and because > the effort of figuring out who wrote what isn't worth it), but I'd say > it's a compromise for simplicity rather than justifiable punishment on > someone who published code. Sure. Penalising both students ? or, more precisely, advertising such penalties from the start ? seems like a much more fair and effective measure than relying on the teacher to both detect the machinations of ingenious students and to determine who copied from whom. -- \ ?Read not to contradict and confute, nor to believe and take | `\ for granted ? but to weigh and consider.? ?Francis Bacon | _o__) | Ben Finney From ben+python at benfinney.id.au Mon Jan 20 03:17:35 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Jan 2014 19:17:35 +1100 Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Message-ID: <85bnz7vzhc.fsf@benfinney.id.au> indar kumar writes: > Hint would have been enough but I was strictly discouraged. You asked for private help, specifically to subvert the rules against plagiarism you're subject to. So no, I don't believe this modification of your request to be sincere. You asked for help cheating, and you were refused. Please take a hint, and do your assignment under the terms your teacher has set. -- \ ?Holy tintinnabulation, Batman!? ?Robin | `\ | _o__) | Ben Finney From rosuav at gmail.com Mon Jan 20 03:48:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 19:48:41 +1100 Subject: Can post a code but afraid of plagiarism In-Reply-To: <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Message-ID: On Mon, Jan 20, 2014 at 6:55 PM, indar kumar wrote: > Actually, I tried to ask some questions but I was discouraged to do so saying that I was working on a project or some assignment. Truth be told I am stuck at one point and since I don't have experience with programming language, I have been working for it for two days but couldn't come up with some idea so posted some questions of the same format just to know whether there is particular method etc to do so. Hint would have been enough but I was strictly discouraged. > Here's my policy on homework. Others may vary, but you'll find a lot will be broadly similar. When you take a course, you should be learning, not just passing. That means that getting someone else to do your work for you is completely wrong, so I won't help you. But if you've put down some code and it's not working, then by all means, ask for help with the details; it's easy if you have an error message you don't understand (you might be able to get that by Googling it), but a lot harder if you're getting output you don't understand, and then it can help a LOT to have an expert look at your code. You would need to post your code and exactly what you're seeing as wrong (exception traceback, or "expected this output, got this instead"); and if you make it clear up-front that it's homework and you're looking for hints rather than an answer-on-a-plate, I'm happy to help. What you will find, though, is that most requests are more of the nature of "please do my homework for me", so people are more likely to be annoyed than helpful when they see what's obviously homework. So you have a bit of an uphill battle just to get heard. But if you can show that you're here to learn - and showing that you've already written most of the code is a good way to do that - you can get help, and often a lot of it. ChrisA From rasmussen.bryan at gmail.com Mon Jan 20 04:19:54 2014 From: rasmussen.bryan at gmail.com (bryan rasmussen) Date: Mon, 20 Jan 2014 10:19:54 +0100 Subject: Can post a code but afraid of plagiarism In-Reply-To: References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Message-ID: >When you take a course, you should be learning, not just passing. That >means that getting someone else to do your work for you is completely >wrong, so I won't help you. I have decided to become an MBA. On Mon, Jan 20, 2014 at 9:48 AM, Chris Angelico wrote: > On Mon, Jan 20, 2014 at 6:55 PM, indar kumar > wrote: > > Actually, I tried to ask some questions but I was discouraged to do so > saying that I was working on a project or some assignment. Truth be told I > am stuck at one point and since I don't have experience with programming > language, I have been working for it for two days but couldn't come up with > some idea so posted some questions of the same format just to know whether > there is particular method etc to do so. Hint would have been enough but I > was strictly discouraged. > > > > Here's my policy on homework. Others may vary, but you'll find a lot > will be broadly similar. > > When you take a course, you should be learning, not just passing. That > means that getting someone else to do your work for you is completely > wrong, so I won't help you. But if you've put down some code and it's > not working, then by all means, ask for help with the details; it's > easy if you have an error message you don't understand (you might be > able to get that by Googling it), but a lot harder if you're getting > output you don't understand, and then it can help a LOT to have an > expert look at your code. You would need to post your code and exactly > what you're seeing as wrong (exception traceback, or "expected this > output, got this instead"); and if you make it clear up-front that > it's homework and you're looking for hints rather than an > answer-on-a-plate, I'm happy to help. > > What you will find, though, is that most requests are more of the > nature of "please do my homework for me", so people are more likely to > be annoyed than helpful when they see what's obviously homework. So > you have a bit of an uphill battle just to get heard. But if you can > show that you're here to learn - and showing that you've already > written most of the code is a good way to do that - you can get help, > and often a lot of it. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From alister.ware at ntlworld.com Mon Jan 20 04:17:15 2014 From: alister.ware at ntlworld.com (Alister) Date: Mon, 20 Jan 2014 09:17:15 GMT Subject: [newbie] advice and comment wanted on first tkinter program References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> Message-ID: On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: >> On 18 January 2014 14:52, Jean Dupont wrote: >> > >> > Thanks Peter and Terry Jan for the useful suggestions. One thing >> > which I >> >find a bit weird: when asking for Python-help concerning raspberry pi >> >code >> > or problems, a lot of people don't seem to be interested in helping >> > out, >> > that's of course their choice, but maybe they don't seem to be aware >> > the raspberry pi is often the motivation for starting to learn to >> > program in >> >Python. And as such such a reaction is a bit disappointing. >> Hi Jean, >> What makes you say that? Did you previously ask questions about >> Rasberry Pi code on this list? > It was not about code but about python-coding in IDLE (that's the > default on raspbian): > I started a thread "[newbie] starting geany from within idle does not > work" both here and in the raspberry pi forum. I just wondered why I > never got an answer concerning that topic. > >> If you did I wouldn't have answered those questions because I've never >> used a Raspberry Pi and know nothing about them (except that they >> encourage using Python somehow). I think that there's actually a list >> that is specifically for Raspberry Pi Python questions that might be >> more helpful although I don't know what it is... > Here is the url to that forum > > http://www.raspberrypi.org/forum/ > > kind regards, > jean Personally use Geany stand alone and not under idle, pressing F5 should save & run the code you are currently editing. Would running under idle give any other benefits? -- Cheese -- milk's leap toward immortality. -- Clifton Fadiman, "Any Number Can Play" From alister.ware at ntlworld.com Mon Jan 20 04:36:38 2014 From: alister.ware at ntlworld.com (Alister) Date: Mon, 20 Jan 2014 09:36:38 GMT Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Message-ID: On Sun, 19 Jan 2014 23:55:59 -0800, indar kumar wrote: > Thanks all for help and positive comments. Actually, I tried to ask some > questions but I was discouraged to do so saying that I was working on a > project or some assignment. Truth be told I am stuck at one point and > since I don't have experience with programming language, I have been > working for it for two days but couldn't come up with some idea so > posted some questions of the same format just to know whether there is > particular method etc to do so. Hint would have been enough but I was > strictly discouraged. You know the pain of working on assignment related > to areas like socket programming and you even don't know how to use > dictionaries and you are given only a week. Atleast I am trying to > learn. The things that I am asking here are just basics on which my > whole code would be building upon. But, as I said time is very less and > have other courses also so wanted to know just the manipulation of > dictionaries. > > If you allow me I can post a small part of that assignment, it just > requires the manipulation with dictionary which I am not getting. I am > not asking to write a code for me. But a small hint would get me out of > trouble. General advise is post the smallest section of code that demonstrates your problem (It does not even have to be you actual code if it demonstrates the same issue). It is also important to post the full trace back of any errors. you should also try to understand these trace backs yourself they will become easier as you progress with the language -- Your business will assume vast proportions. From robin at reportlab.com Mon Jan 20 05:07:35 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 20 Jan 2014 10:07:35 +0000 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: References: <52D91101.7000202@chamonix.reportlab.co.uk> <52D91EBB.2060606@chamonix.reportlab.co.uk> Message-ID: <52DCF567.8070805@chamonix.reportlab.co.uk> On 17/01/2014 21:10, Terry Reedy wrote: > On 1/17/2014 7:14 AM, Robin Becker wrote: > .......... > I never got how you are using doctests. There were certainly not meant for > heavy-duty unit testing, but for testing combined with explanation. Section > 26.2.3.7. (in 3.3) Warnings warns that they are fragile to even single char > changes and suggests == as a workaround, as 'True' and 'False' will not change. > So I would not reject that option. > I have used some 'robust' True/False equality tests and also tests which return None or a string indicating the expected and observed outcomes eg > > def equalStrings(a,b,enc='utf8'): > return a==b if type(a)==type(b) else asUnicode(a,enc)==asUnicode(b,enc) > > def eqCheck(r,x): > if r!=x: > print('Strings unequal\nexp: %s\ngot: %s' % (ascii(x),ascii(r))) of course I needed to import ascii from the future and the asUnicode function has to be different for python 3 and 2. Some of our code used doctests which are discovered by a file search. -- Robin Becker From robin at reportlab.com Mon Jan 20 05:07:35 2014 From: robin at reportlab.com (Robin Becker) Date: Mon, 20 Jan 2014 10:07:35 +0000 Subject: doctests compatibility for python 2 & python 3 In-Reply-To: References: <52D91101.7000202@chamonix.reportlab.co.uk> <52D91EBB.2060606@chamonix.reportlab.co.uk> Message-ID: <52DCF567.8070805@chamonix.reportlab.co.uk> On 17/01/2014 21:10, Terry Reedy wrote: > On 1/17/2014 7:14 AM, Robin Becker wrote: > .......... > I never got how you are using doctests. There were certainly not meant for > heavy-duty unit testing, but for testing combined with explanation. Section > 26.2.3.7. (in 3.3) Warnings warns that they are fragile to even single char > changes and suggests == as a workaround, as 'True' and 'False' will not change. > So I would not reject that option. > I have used some 'robust' True/False equality tests and also tests which return None or a string indicating the expected and observed outcomes eg > > def equalStrings(a,b,enc='utf8'): > return a==b if type(a)==type(b) else asUnicode(a,enc)==asUnicode(b,enc) > > def eqCheck(r,x): > if r!=x: > print('Strings unequal\nexp: %s\ngot: %s' % (ascii(x),ascii(r))) of course I needed to import ascii from the future and the asUnicode function has to be different for python 3 and 2. Some of our code used doctests which are discovered by a file search. -- Robin Becker From srikrishnamohan at gmail.com Mon Jan 20 05:44:18 2014 From: srikrishnamohan at gmail.com (km) Date: Mon, 20 Jan 2014 16:14:18 +0530 Subject: regex multiple patterns in order Message-ID: I am trying to find sub sequence patterns but constrained by the order in which they occur For example >>> p = re.compile('(CAA)+?(TCT)+?(TA)+?') >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') [('CAA', 'TCT', 'TA')] But I instead find only one instance of the CAA/TCT/TA in that order. How can I get 3 matches of CAA, followed by four matches of TCT followed by 2 matches of TA ? Well these patterns (CAA/TCT/TA) can occur any number of times and atleast once so I have to use + in the regex. Please let me know. Thanks! Regards, Krishna mohan -------------- next part -------------- An HTML attachment was scrubbed... URL: From piet at vanoostrum.org Mon Jan 20 06:02:40 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Mon, 20 Jan 2014 12:02:40 +0100 Subject: How to write this as a list comprehension? References: Message-ID: "Rhodri James" writes: > On Sat, 18 Jan 2014 16:00:45 -0000, Jussi Piitulainen > wrote: [...] >> I would write that on three lines anyway, properly indented: >> >> [ somefunc(mn,day,wd,name) >> for (then, name) in mylist >> let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ] >> >> It could be made to use existing keywords: >> >> [ somefunc(mn,day,wd,name) >> for (then, name) in mylist >> with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ] > > Better, in that it's readable. It's still storing up trouble, though. > > Seriously, what's inelegant about this? > > def meaningful_name(then, name): > _,mn,dy,_,_,_,wd,_,_ = localtime(then) > return somefunc(mn, dy, wd, name) > > ... > > [meaningful_name(then, name) for (then, name) in mylist] > > I assume there's some good reason you didn't want somefunc() to do the > localtime() itself? Actually in my use case somefunc(mn,day,wd,name) was an expression, not really a function call. I just presented it like that to make it a more generalised abstract case. So in my case that would introduce an additional function outside of the comprehension. Let me summarize what my problem really was: In a comprehension you generally need local name(s), which can only be introduced with the 'for' construction. But then the name(s) must be bound to an element of a sequence/iterator. There is no way to bind the name(s) to a single object other than putting that object in a one element sequence. I was just looking for a way to avoid that. Functional programming languages have a way to do this with the 'let' or 'where' construction which is missing in Python. Thanks everybody for your thoughts on this. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From jeanpierreda at gmail.com Mon Jan 20 06:09:42 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 20 Jan 2014 03:09:42 -0800 Subject: regex multiple patterns in order In-Reply-To: References: Message-ID: On Mon, Jan 20, 2014 at 2:44 AM, km wrote: > I am trying to find sub sequence patterns but constrained by the order in > which they occur > For example > >>>> p = re.compile('(CAA)+?(TCT)+?(TA)+?') >>>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') > [('CAA', 'TCT', 'TA')] > > But I instead find only one instance of the CAA/TCT/TA in that order. > How can I get 3 matches of CAA, followed by four matches of TCT followed by > 2 matches of TA ? > Well these patterns (CAA/TCT/TA) can occur any number of times and atleast > once so I have to use + in the regex. You want to include the '+' in the parens so that repetitions are included in the match, but you still want to group CAA etc. together; for that, you can use non-capturing groups. I don't see how TA could ever match two, though. It'd match once as-is, or thrice if you make the repetition greedy (get rid of the ?s). >>> p = re.compile('((?:CAA)+?)((?:TCT)+?)((?:TA)+?)') >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') [('CAACAACAA', 'TCTTCTTCTTCT', 'TA')] -- Devin From rosuav at gmail.com Mon Jan 20 06:10:46 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 20 Jan 2014 22:10:46 +1100 Subject: regex multiple patterns in order In-Reply-To: References: Message-ID: On Mon, Jan 20, 2014 at 9:44 PM, km wrote: >>>> p = re.compile('(CAA)+?(TCT)+?(TA)+?') >>>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') > [('CAA', 'TCT', 'TA')] > > But I instead find only one instance of the CAA/TCT/TA in that order. > How can I get 3 matches of CAA, followed by four matches of TCT followed by > 2 matches of TA ? > Well these patterns (CAA/TCT/TA) can occur any number of times and atleast > once so I have to use + in the regex. You're capturing the single instance, not the repeated one. It is matching against all three CAA units, but capturing just the first. Try this: >>> p = re.compile('((?:CAA)+)((?:TCT)+)((?:TA)+)') >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') [('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA')] This groups "CAA" with non-capturing parentheses (?:regex) and then captures that with the + around it. ChrisA From ben+python at benfinney.id.au Mon Jan 20 06:18:29 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 20 Jan 2014 22:18:29 +1100 Subject: regex multiple patterns in order References: Message-ID: <857g9ux5oa.fsf@benfinney.id.au> km writes: > I am trying to find sub sequence patterns but constrained by the order > in which they occur There are also specific resources for understanding and testing regex patterns, such as . > For example > > >>> p = re.compile('(CAA)+?(TCT)+?(TA)+?') > >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') > [('CAA', 'TCT', 'TA')] > > But I instead find only one instance of the CAA/TCT/TA in that order. Yes, because the grouping operator (the parens ?()?) in each case contains exactly ?CAA?, ?TCT?, ?TA?. If you want the repetitions to be part of the group, you need the repetition operator (in your case, ?+?) to be part of the group. > How can I get 3 matches of CAA, followed by four matches of TCT followed > by 2 matches of TA ? With a little experimenting I get: >>> p = re.compile('((?:CAA)+)?((?:TCT)+)?((?:TA)+)?') >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') [('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA'), ('', '', '')] Remember that you'll get no more than one group returned for each group you specify in the pattern. > Well these patterns (CAA/TCT/TA) can occur any number of times and > atleast once so I have to use + in the regex. Be aware that regex is not the solution to all parsing problems; for many parsing problems it is an attractive but inappropriate tool. You may need to construct a more specific parser for your needs. Even if it's possible with regex, the resulting pattern may be so complex that it's better to write it out more explicitly. -- \ ?To punish me for my contempt of authority, Fate has made me an | `\ authority myself.? ?Albert Einstein, 1930-09-18 | _o__) | Ben Finney From srikrishnamohan at gmail.com Mon Jan 20 06:27:39 2014 From: srikrishnamohan at gmail.com (km) Date: Mon, 20 Jan 2014 16:57:39 +0530 Subject: regex multiple patterns in order In-Reply-To: <857g9ux5oa.fsf@benfinney.id.au> References: <857g9ux5oa.fsf@benfinney.id.au> Message-ID: Aah! I understand now. Thank you Regards, Krishna Mohan On Mon, Jan 20, 2014 at 4:48 PM, Ben Finney wrote: > km writes: > > > I am trying to find sub sequence patterns but constrained by the order > > in which they occur > > There are also specific resources for understanding and testing regex > patterns, such as . > > > For example > > > > >>> p = re.compile('(CAA)+?(TCT)+?(TA)+?') > > >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') > > [('CAA', 'TCT', 'TA')] > > > > But I instead find only one instance of the CAA/TCT/TA in that order. > > Yes, because the grouping operator (the parens ?()?) in each case > contains exactly ?CAA?, ?TCT?, ?TA?. If you want the repetitions to be > part of the group, you need the repetition operator (in your case, ?+?) > to be part of the group. > > > How can I get 3 matches of CAA, followed by four matches of TCT followed > > by 2 matches of TA ? > > With a little experimenting I get: > > >>> p = re.compile('((?:CAA)+)?((?:TCT)+)?((?:TA)+)?') > >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') > [('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA'), ('', '', '')] > > Remember that you'll get no more than one group returned for each group > you specify in the pattern. > > > Well these patterns (CAA/TCT/TA) can occur any number of times and > > atleast once so I have to use + in the regex. > > Be aware that regex is not the solution to all parsing problems; for > many parsing problems it is an attractive but inappropriate tool. You > may need to construct a more specific parser for your needs. Even if > it's possible with regex, the resulting pattern may be so complex that > it's better to write it out more explicitly. > > -- > \ ?To punish me for my contempt of authority, Fate has made me an | > `\ authority myself.? ?Albert Einstein, 1930-09-18 | > _o__) | > Ben Finney > > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Mon Jan 20 06:47:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 20 Jan 2014 03:47:01 -0800 (PST) Subject: How to write this as a list comprehension? In-Reply-To: References: Message-ID: <1f617d4a-1fb5-4874-8fd3-96c0822899fe@googlegroups.com> On Monday, January 20, 2014 4:32:40 PM UTC+5:30, Piet van Oostrum wrote: > "Rhodri James" writes: > > On Sat, 18 Jan 2014 16:00:45 -0000, Jussi Piitulainen wrote: > [...] > >> I would write that on three lines anyway, properly indented: > >> [ somefunc(mn,day,wd,name) > >> for (then, name) in mylist > >> let (_,mn,dy,_,_,_,wd,_,_) = localtime(then) ] > >> It could be made to use existing keywords: > >> [ somefunc(mn,day,wd,name) > >> for (then, name) in mylist > >> with localtime(then) as (_,mn,dy,_,_,_,wd,_,_) ] > > Better, in that it's readable. It's still storing up trouble, though. > > Seriously, what's inelegant about this? > > def meaningful_name(then, name): > > _,mn,dy,_,_,_,wd,_,_ = localtime(then) > > return somefunc(mn, dy, wd, name) > > ... > > [meaningful_name(then, name) for (then, name) in mylist] > > I assume there's some good reason you didn't want somefunc() to do the > > localtime() itself? > Actually in my use case somefunc(mn,day,wd,name) was an expression, not > really a function call. I just presented it like that to make it a more > generalised abstract case. So in my case that would introduce an > additional function outside of the comprehension. Nice! Thanks One of things that people who decry comprehensions (and in general hi-level constructs) dont understand is this: One fundamental characteristic of increasing hi-level-ness of a programming language is increased *freedom-in-naming* structures. The 'structures' could be expressions, statements, or whatever is the thing of the programming language. A couple of examples will illustrate: 1. In most (imperative) programming languages when a computation is described as a function it must willy-nilly be named. In lambda-calculus thats an option. 2. In any hi-level programming language, if we have an expression like sqrt(b*b - 4*a*c) we can choose to 'chunk it out' in a variety of ways: 1. t = b*b - 4*a*c sqrt(t) 2. t1 = b*b t2 = 4*a*c t3 = t1 -t2 sqrt(t3) Or the original: sqrt(b*b - 4*a*c) The assembly language programmer has no such choice. He has to write (the equivalent of) t1 = b*b t2 = 4*a t3 = t2*c t4 = t1 - t3 sqrt(t4) Compared to a comprehension, a loop is in assembly-language category since the list being 'comprehended' is compelled to be named. And BTW thanks for the singleton list trick: Sure 'v=e' is way neater than 'for v in [e]' but the for is better than nothing From roy at panix.com Mon Jan 20 09:08:28 2014 From: roy at panix.com (Roy Smith) Date: Mon, 20 Jan 2014 09:08:28 -0500 Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Chris Angelico wrote: > On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg wrote: > > I did a short time of teaching while I was in school. If three > > students all turned in the same assignment, they all got docked > > significantly. There was no "who copied off of whom?", it was > > "someone shared when they shouldn't have." > > What a wonderful way to promote an attitude of "my code is MY CODE and > should never leave my sight". What a delightful way of thinking to > unleash on the world. That's a little harsh. Working in groups, and sharing code, are important parts of how software gets developed today. Those collaborative work habits should indeed be taught. But, school is also about evaluation of progress. At the end of the class, the teacher needs some objective way to figure out how much each student has learned and assign a grade. It's hard to do that if people aren't handing in assignments done individually. From roy at panix.com Mon Jan 20 09:52:59 2014 From: roy at panix.com (Roy Smith) Date: Mon, 20 Jan 2014 09:52:59 -0500 Subject: regex multiple patterns in order References: Message-ID: In article , Ben Finney wrote: > With a little experimenting I get: > > >>> p = re.compile('((?:CAA)+)?((?:TCT)+)?((?:TA)+)?') > >>> p.findall('CAACAACAATCTTCTTCTTCTTATATA') > [('CAACAACAA', 'TCTTCTTCTTCT', 'TATATA'), ('', '', '')] Perhaps a matter of style, but I would have left off the ?: markers and done this: p = re.compile('((CAA)+)((TCT)+)((TA)+)') m = p.match('CAACAACAATCTTCTTCTTCTTATATA') print m.groups() $ python r.py ('CAACAACAA', 'CAA', 'TCTTCTTCTTCT', 'TCT', 'TATATA', 'TA') The ?: says, "match this group, but don't save it". The advantage of that is you don't get unwanted groups in your match object. The disadvantage is they make the pattern more difficult to read. My personal opinion is I'd rather make the pattern easier to read and just ignore the extra matches in the output (in this case, I want groups 0, 2, and 4). I also left off the outer ?s, because I think this better represents the intent. The pattern '((CAA)+)?((TCT)+)?((TA)+)?' matches, for example, an empty string; I suspect that's not what was intended. > Be aware that regex is not the solution to all parsing problems; for > many parsing problems it is an attractive but inappropriate tool. You > may need to construct a more specific parser for your needs. Even if > it's possible with regex, the resulting pattern may be so complex that > it's better to write it out more explicitly. Oh, posh. You are correct; regex is not the solution to all parsing problems, but it is a powerful tool which people should be encouraged to learn. For some problems, it is indeed the correct tool, and this seems like one of them. Discouraging people from learning about regexes is an educational anti-pattern which I see distressingly often on this newsgroup. Several lives ago, I worked in a molecular biology lab writing programs to analyze DNA sequences. Here's a common problem: "Find all the places where GACGTC or TTCGAA (or any of a similar set of 100 or so short patterns appear". I can't think of an easier way to represent that in code than a regex. Sure, it'll be a huge regex, which may take a long time to compile, but one of the nice things about these sorts of problems) is that the patterns you are looking for tend not to change very often. For example, the problem I mention in the preceding paragraph is finding restriction sites, i.e. the locations where restriction enzymes will cut a strand of DNA. There's a finite set of commercially available restriction enzymes, and that list doesn't change from month to month (at this point, maybe even from year to year). For more details, see http://bioinformatics.oxfordjournals.org/content/4/4/459.abstract Executive summary: I wrote my own regex compiler which was optimized for the types of patterns this problem required. From neilc at norwich.edu Mon Jan 20 11:04:43 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 20 Jan 2014 16:04:43 +0000 (UTC) Subject: regex multiple patterns in order References: Message-ID: On 2014-01-20, Roy Smith wrote: > In article > , Ben > Finney wrote: >> Be aware that regex is not the solution to all parsing >> problems; for many parsing problems it is an attractive but >> inappropriate tool. You may need to construct a more specific >> parser for your needs. Even if it's possible with regex, the >> resulting pattern may be so complex that it's better to write >> it out more explicitly. > > Oh, posh. > > You are correct; regex is not the solution to all parsing > problems, but it is a powerful tool which people should be > encouraged to learn. For some problems, it is indeed the > correct tool, and this seems like one of them. Discouraging > people from learning about regexes is an educational > anti-pattern which I see distressingly often on this newsgroup. I use regular expressions regularly, for example, when editing text with gvim. But when I want to use them in Python I have to contend with the re module. I've never become comfortable with it. -- Neil Cerutti From rustompmody at gmail.com Mon Jan 20 11:11:49 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 20 Jan 2014 08:11:49 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Monday, January 20, 2014 7:38:28 PM UTC+5:30, Roy Smith wrote: > Chris Angelico wrote: > > On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg wrote: > > > I did a short time of teaching while I was in school. If three > > > students all turned in the same assignment, they all got docked > > > significantly. There was no "who copied off of whom?", it was > > > "someone shared when they shouldn't have." > > What a wonderful way to promote an attitude of "my code is MY CODE and > > should never leave my sight". What a delightful way of thinking to > > unleash on the world. > That's a little harsh. Working in groups, and sharing code, are > important parts of how software gets developed today. Those > collaborative work habits should indeed be taught. But, school is also > about evaluation of progress. At the end of the class, the teacher > needs some objective way to figure out how much each student has learned > and assign a grade. It's hard to do that if people aren't handing in > assignments done individually. This position is a repeat of the position on whether print is a good function for students to use: wearing teacher hat and professional programmer hat give very different desiderata. As an example of the need for multiple hats consider this scenario: You are interviewing a programmer for a java job. You ask the candidate to explain quicksort. Quick is the answer: java.util.lang.sort [Im using java as example because the sort in python is not so explicitly a quicksort] You would find this answer unacceptable (hopefully) On the other hand when that same programmer were on job, if instead of using java.util.lang.sort he spent his time implementing one, you would be equally peeved (hopefully!) Most people dont get that education is like a game: Some games -- meccano, lego -- can be explicitly educative but any game can be put to educational purpose. Now you can stymie the purpose by saying: "I find these rules arbitrary -- I refuse to play!" but that only obstructs the process until some other rules/games are created. And will be seen to be fruitless once you get that all education is more or less about bigger and smaller toys, ie unreality. "Dont copy" is standard rule in edu-institutes. It should be understood to be arbitrary and not some fundamental moral law, just as "Dont hand-touch the ball" is a rule in football but not basketball. Some people actually have fun making up new games -- a hybrid of football and basketball? More often people find it reasonable and fun to stay within the parameters of pre-existing rules. As for Dan's "Punish the whole coterie rather than only the copycats" rule: as a teacher I can say that fancy rules that are non-computable are worse than useless. So if this is more effective than the usual "punish the copier" rule -- all power to you. The only thing I would add is this: Please close the feedback loop; ie check whether the rules are serving their intended purpose. Typically one finds that beyond a point harsh rules are counterproductive. Probably related to the fact that if your driving cycle is entirely carrot-n-stick, the driven will become indistinguishable from mammals and repiles At the other end of the spectrum is the interesting anecdote in "Zen and the art of motorcycle maintenance." The author is teaching some course and decides to abolish exams. The students who most strongly revolt are bottom of the class -- ie those most likely to fail!! Some more on my blog http://blog.languager.org/2010/05/declaration-imperation-and-language.html From breamoreboy at yahoo.co.uk Mon Jan 20 11:16:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Jan 2014 16:16:36 +0000 Subject: regex multiple patterns in order In-Reply-To: References: Message-ID: On 20/01/2014 16:04, Neil Cerutti wrote: > On 2014-01-20, Roy Smith wrote: >> In article >> , Ben >> Finney wrote: >>> Be aware that regex is not the solution to all parsing >>> problems; for many parsing problems it is an attractive but >>> inappropriate tool. You may need to construct a more specific >>> parser for your needs. Even if it's possible with regex, the >>> resulting pattern may be so complex that it's better to write >>> it out more explicitly. >> >> Oh, posh. >> >> You are correct; regex is not the solution to all parsing >> problems, but it is a powerful tool which people should be >> encouraged to learn. For some problems, it is indeed the >> correct tool, and this seems like one of them. Discouraging >> people from learning about regexes is an educational >> anti-pattern which I see distressingly often on this newsgroup. > > I use regular expressions regularly, for example, when editing > text with gvim. But when I want to use them in Python I have to > contend with the re module. I've never become comfortable with > it. > You don't have to, there's always the "new" regex module that's been on pypi for years. Or are you saying that you'd like to use regex but other influences that are outside of your sphere of control prevent you from doing so? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From jeanpierreda at gmail.com Mon Jan 20 11:40:32 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Mon, 20 Jan 2014 08:40:32 -0800 Subject: regex multiple patterns in order In-Reply-To: References: Message-ID: On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote: > On 20/01/2014 16:04, Neil Cerutti wrote: >> I use regular expressions regularly, for example, when editing >> text with gvim. But when I want to use them in Python I have to >> contend with the re module. I've never become comfortable with >> it. >> > > You don't have to, there's always the "new" regex module that's been on pypi > for years. Or are you saying that you'd like to use regex but other > influences that are outside of your sphere of control prevent you from doing > so? I don't see any way in which someone uncomfortable with the re module would magically find themselves perfectly at home with the regex module. The regex module is the re module with some extra features (and complexity), is it not? -- Devin From neilc at norwich.edu Mon Jan 20 12:09:30 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 20 Jan 2014 17:09:30 +0000 (UTC) Subject: regex multiple patterns in order References: Message-ID: On 2014-01-20, Devin Jeanpierre wrote: > On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence > wrote: >> On 20/01/2014 16:04, Neil Cerutti wrote: >>> I use regular expressions regularly, for example, when >>> editing text with gvim. But when I want to use them in Python >>> I have to contend with the re module. I've never become >>> comfortable with it. >> >> You don't have to, there's always the "new" regex module >> that's been on pypi for years. Or are you saying that you'd >> like to use regex but other influences that are outside of >> your sphere of control prevent you from doing so? > > I don't see any way in which someone uncomfortable with the re > module would magically find themselves perfectly at home with > the regex module. The regex module is the re module with some > extra features (and complexity), is it not? It's a negative feedback loop. I'd have to use it more often than I do to get comfortable. There's no way a library, even a really good one, can compete with built-in syntax support. The BDFL must have wanted it to be this way. -- Neil Cerutti From rustompmody at gmail.com Mon Jan 20 12:06:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Mon, 20 Jan 2014 09:06:27 -0800 (PST) Subject: regex multiple patterns in order In-Reply-To: References: Message-ID: <00b9351f-588f-4aa1-9251-e33748f45532@googlegroups.com> On Monday, January 20, 2014 10:10:32 PM UTC+5:30, Devin Jeanpierre wrote: > On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote: > > On 20/01/2014 16:04, Neil Cerutti wrote: > >> I use regular expressions regularly, for example, when editing > >> text with gvim. But when I want to use them in Python I have to > >> contend with the re module. I've never become comfortable with > >> it. > > You don't have to, there's always the "new" regex module that's been on pypi > > for years. Or are you saying that you'd like to use regex but other > > influences that are outside of your sphere of control prevent you from doing > > so? > I don't see any way in which someone uncomfortable with the re module > would magically find themselves perfectly at home with the regex > module. The regex module is the re module with some extra features > (and complexity), is it not? I wonder whether the re/regex modules are at fault? Or is it that in a manual whose readability is otherwise exemplary the re pages are a bit painful eg reading http://docs.python.org/2/library/re.html#module-contents the first thing one reads is compile From breamoreboy at yahoo.co.uk Mon Jan 20 12:30:41 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Jan 2014 17:30:41 +0000 Subject: regex multiple patterns in order In-Reply-To: <00b9351f-588f-4aa1-9251-e33748f45532@googlegroups.com> References: <00b9351f-588f-4aa1-9251-e33748f45532@googlegroups.com> Message-ID: On 20/01/2014 17:06, Rustom Mody wrote: > On Monday, January 20, 2014 10:10:32 PM UTC+5:30, Devin Jeanpierre wrote: >> On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence wrote: >>> On 20/01/2014 16:04, Neil Cerutti wrote: >>>> I use regular expressions regularly, for example, when editing >>>> text with gvim. But when I want to use them in Python I have to >>>> contend with the re module. I've never become comfortable with >>>> it. >>> You don't have to, there's always the "new" regex module that's been on pypi >>> for years. Or are you saying that you'd like to use regex but other >>> influences that are outside of your sphere of control prevent you from doing >>> so? > >> I don't see any way in which someone uncomfortable with the re module >> would magically find themselves perfectly at home with the regex >> module. The regex module is the re module with some extra features >> (and complexity), is it not? > > I wonder whether the re/regex modules are at fault? > Or is it that in a manual whose readability is otherwise exemplary the re pages > are a bit painful > > eg reading http://docs.python.org/2/library/re.html#module-contents > the first thing one reads is compile > http://docs.python.org/3/library/re.html gives "re ? Regular expression operations" and http://docs.python.org/3/library/re.html#regular-expression-syntax gives "Regular Expression Syntax". Are you saying that the module contents should come before both of these? -- 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 Jan 20 12:33:46 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Jan 2014 17:33:46 +0000 Subject: regex multiple patterns in order In-Reply-To: References: Message-ID: On 20/01/2014 17:09, Neil Cerutti wrote: > On 2014-01-20, Devin Jeanpierre wrote: >> On Mon, Jan 20, 2014 at 8:16 AM, Mark Lawrence >> wrote: >>> On 20/01/2014 16:04, Neil Cerutti wrote: >>>> I use regular expressions regularly, for example, when >>>> editing text with gvim. But when I want to use them in Python >>>> I have to contend with the re module. I've never become >>>> comfortable with it. >>> >>> You don't have to, there's always the "new" regex module >>> that's been on pypi for years. Or are you saying that you'd >>> like to use regex but other influences that are outside of >>> your sphere of control prevent you from doing so? >> >> I don't see any way in which someone uncomfortable with the re >> module would magically find themselves perfectly at home with >> the regex module. The regex module is the re module with some >> extra features (and complexity), is it not? > > It's a negative feedback loop. I'd have to use it more often than > I do to get comfortable. There's no way a library, even a really > good one, can compete with built-in syntax support. The BDFL must > have wanted it to be this way. > Regex was originally scheduled to go into 3.3 and then 3.4 but not made it. I assume that it will again be targeted in the 3.5 release schedule. Three strikes and you're out is a BDFL plan? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mattwatson.mail at gmail.com Mon Jan 20 14:34:16 2014 From: mattwatson.mail at gmail.com (Matt Watson) Date: Mon, 20 Jan 2014 11:34:16 -0800 (PST) Subject: Diving in to Python - Best resources? Message-ID: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Getting in the habit of dropping in a google group for any new project - everyone tends to be so helpful. I work in the automotive sales industry(management) and find myself doing so many day to day tasks that could easily be automated. I'm a very tech saavy person, but after running in fear from a Javascript class in undergrad 8 years ago I haven't ever looked back. I simply had no interest because I saw no applications. Now that I have a solid career I see SO many applications for programming in my industry alone. Automating data movement/calculations from websites, spreadsheets, pricing, etc will be my primary use. I'm OK saying I didn't retain 1% of what I learned in the Javascript class, I've dabbled in HTML, I've tweaked code in Excel macros or AutoIt scripts, but I'd classify myself as a complete beginner in programming. Like a kid, I learn by tearing things apart and watching them tick. I have started the Code Academy on Python, but I'm not sure a constant IV dosage of adderall could keep my attention. I also run into exercises that absolutely lose me and I have to spend 30 minutes googling a solution because the lesson and hints are useless. My question to you guys is... for someone like me, what route would you take to learning Python? "Learn Python the Hard Way" sounds like a good route, but I prefer some testimony before I make a purchase. Again, I understand the details are the building blocks of programming, but I don't think I can handle writing 10 lines of true/false (boolean right?) calculations on Code Academy only for the next course to speak a foreign language to me. Any other methods you would suggest? I've even considered auditing a college class if I can find one for Python. Thanks in advance! From emile at fenx.com Mon Jan 20 14:50:05 2014 From: emile at fenx.com (Emile van Sebille) Date: Mon, 20 Jan 2014 11:50:05 -0800 Subject: Diving in to Python - Best resources? In-Reply-To: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: On 1/20/2014 11:34 AM, Matt Watson wrote: > My question to you guys is... for someone like me, what route would you take to learning Python? I'd work my way through the tutorial [1] then pick a work based project and start right in. Ask questions along the way. Emile [1] http://docs.python.org/2/tutorial/ From charleshixsn at earthlink.net Mon Jan 20 15:09:59 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 20 Jan 2014 12:09:59 -0800 Subject: 1st Sketch at at ReadOnly dict Message-ID: <52DD8297.9050504@earthlink.net> This is just a first sketch, and I haven't yet attempted to test it, so what I'm hoping for is criticisms on the general approach. ## Read Only dict class. # @note Instances can be created only from existing dicts. # @warning values within the RODict can be accessed, so if they hold # references to other items, they can be altered. class RODict: #Instance Variable Doc ## @var _ddict # This variable holds the reference to the dict. ## Class initializer. # @param ddict The data dictionary to which this is a read only # access. # @throws TypeError if ddict is not a dict. def __init__ (self, ddict = {}): if not isinstance(ddict, dict): raise TypeError("ddict must be a dict. It is " + repr(ddict)) self._ddict = ddict ## Test for containment. # @param key The item to be found. # @return True If key is in the instance, otherwise False. def __contains__(self, key): return key in self._ddict ## Pass along the __getitem call. def __getitem__(self, key): return self._ddict.__getitem__(key) ## Pass along the get call. def get (self, key, default = None): return self._ddict.get(key, default) ## Return a DictView of the items of the instance. def items(self): return self._ddict.items() ## Return a DictView of the keys of the instance. def keys(self): return self._ddict.keys() ## Return a DictView of the values of the instance. def values(self): return self._ddict.values() ## Return the length of the dict. def __len__(self): return len(self._ddict) -- Charles Hixson From bv8bv8bv8 at gmail.com Mon Jan 20 15:10:35 2014 From: bv8bv8bv8 at gmail.com (BV BV) Date: Mon, 20 Jan 2014 12:10:35 -0800 (PST) Subject: The Beauties of Islam Message-ID: <08e3c747-41d9-40e5-a458-4a3dad4cdc18@googlegroups.com> The Beauties of Islam At this time in Islam?s history, when the entire religion is being judged by the actions of a few, it is appropriate to step back from the glare of the media spotlight and examine the beauties that infuse the way of life known as Islam. There is greatness and splendour in Islam that is often overshadowed by actions that have no place in Islam or by people who speak about topics they only vaguely understand. Islam is a religion, a way of life that inspires Muslims to try harder, reach farther and act in a manner that is pleasing to those around them and most importantly pleasing to their Creator. The beauties of Islam are those things that are part of the religion and make Islam stand out. Islam answers all of humankind?s eternal questions. Where did I come from? Why am I here? Is this really all there is? It answers these questions with clarity and in a beautiful way. So then, let us begin our journey and discover and ponder over the beauties of Islam. 1. The answers to all your questions about life are in the Quran The Quran is a book detailing the glory of God and the wonder of His creation; it is also a testament to His Mercy and Justice. It is not a history book, a storybook, or a scientific textbook, although it does contain all of those genres and more. The Quran is God?s greatest gift to humanity ? it is a book like no other, for it contains the answers to the mysteries of life. It answers the questions and asks us to look beyond materialism and see that this life is little more than a transient stop on the way to everlasting life. Islam gives a clear aim and purpose to life. ?And I (God) created not the jinn and humankind, except to worship Me (Alone).? (Quran 51:56) Thus it is the most important book and Muslims have no doubt that it is exactly the same today as it was when it was first revealed to Prophet Muhammad, may God praise him. When we ask those most important questions, we want to be sure that the answers we receive are the truth. Knowing that the answers are coming from a book which is the unchanged Word of God, gives comfort and solace. When God revealed the Quran, He promised to preserve it. The words we read today are the same as those memorised and written down by the companions of Prophet Muhammad. ?It is We Who have sent down the remembrance (i.e. the Quran) and surely, We will guard it from corruption.? (Quran 15:9) 2. True Happiness can be found in Islam Rejoice and be happy, remain positive and be at peace. [1] This is what Islam teaches us, for all God?s commandments aim to bring happiness to the individual. The key to happiness is in understanding and worshipping God. This worship serves as a reminder of Him and keeps us always conscious of Him and hence we stay away from evil, committing injustices and oppression. It elevates us to being righteous and of good character. By following His commands, we lead a life that guides us to the best in all our affairs. When we lead such a meaningful life, then and only then are we able to see happiness all around us, at any given moment and even on the darkest of times. It is even there in the touch of a hand, in the smell of rain or newly mown grass, it is in a warm fire on a cold night or a cool breeze on a hot day. Simple pleasures can make our hearts truly happy because they are manifestations of God?s Mercy and Love. The nature of the human condition means that amongst great sorrow can be moments of joy and sometimes in moments of despair we can find an anchor in the things that bring us happiness. Prophet Muhammad said, ?Indeed amazing are the affairs of a believer! They are all for his benefit. If he is granted ease then he is thankful, and this is good for him. And if he is afflicted with a hardship, he perseveres, and this is good for him.? [2] 3. In Islam we can easily communicate with God at any time of day or night Every member of the human race is born innately knowing that God is One. However those who do not know how to communicate with God or establish a relationship with Him tend to find their existence puzzling and sometimes even distressing. Learning to communicate with God and worshiping Him gives life a whole new meaning. According to Islam, God is accessible at any time and in any place. We need only call on Him and He will answer the call. Prophet Muhammad advised us to call on God often. He told us that God said, ?I am just as My slave thinks I am, (i.e. I am able to do for him what he thinks I can do for him) and I am with him if He remembers Me. If he remembers Me in himself, I too, remember him in Myself; and if he remembers Me in a group of people, I remember him in a group that is better than they; and if he comes one span nearer to Me, I go one cubit nearer to him; and if he comes one cubit nearer to Me, I go a distance of two outstretched arms nearer to him; and if he comes to me walking, I go to him running.? [3] In the Quran God says, ?Remember Me and I will remember you?? (Quran2:152) Believers call on God in any language, at any time and in any place. They supplicate to Him, and give thanks. Muslims also pray in a more ritualised way five times every day and interestingly the Arabic word for prayer is ?salah?, which means a connection. Muslims are connected to God and can communicate with Him easily. We are never alone or far from God?s Mercy, Forgiveness and Love. 4. Islam gives us real peace The words Islam, Muslim and salaam (peace) all come from the Arabic root word ?Sa - la ? ma?. It denotes peace, security, and safety. When a person submits to the will of God he or she experiences an innate sense of security and peacefulness. Salaam is a descriptive word that entails more than tranquillity and calmness; it also encompasses the concepts of safety, security and submission. In fact, Islam in the complete sense means submission to the One God who grants us safety, security, peace and harmony. This is real peace. Muslims greet each other with the words ?Assalam Alaikum?. These Arabic words mean ?May God grant you protection and security (real and lasting peace)?. These brief Arabic words let Muslims know that they are among friends, not strangers. This greeting encourages believers to be a worldwide community unencumbered by tribal or nationalistic loyalties and bound together by peace and unity. Islam itself is inherently associated with inner peace and tranquillity. ?And those who believed (in the Oneness of God and His Messengers and whatever they brought) and did righteous deeds, will be made to enter Gardens under which rivers flow, - to dwell therein for ever (i.e. in Paradise), with the Permission of their Lord. Their greeting therein will be, salaam!? (Quran 14:23) 5. Islam allows us to know God The first principle and focal point of Islam is belief in one God, and the whole of the Quran is dedicated to this. It speaks directly about God and His Essence, Names, Attributes and Actions. Prayer connects us to God, however truly knowing and understanding the Names and Attributes of God is an important and unique opportunity, one that is only available in Islam. Those who do not make the effort to really know God may find the nature of their existence puzzling or even distressing. A Muslim is encouraged to remember God and be grateful to Him and a person can do this by contemplating and understanding God?s beautiful Names and Attributes. It is through this that we are able to know our Creator. ?God! (None has the right to be worshipped but He)! To Him belong the Best Names.? (Quran 20:8) ?And (all) the Most Beautiful Names belong to God, so call on Him by them, and leave the company of those who belie or deny (or utter impious speech against) His Names?? (Quran 7:180) 6. Islam teaches us how to care for the environment Islam recognises that human beings are the custodians of the earth and all that is on it, including vegetation, animals, oceans, rivers, deserts, and fertile land. God provides us with the things we need to survive successfully and flourish, but we are obligated to care for them and preserve them for future generations. In 1986 Prince Phillip the then president of the World Wildlife Fund invited the leaders of the world?s five major religions to meet in the Italian city of Assisi. They met to discuss how faith could help save the natural world, the environment. What follows is from the Muslim statement in the Assisi Declarations on Nature: Muslims say that Islam is the middle path and we will be answerable for how we have walked this path, how we have maintained balance and harmony in the whole of creation around us. It is these values which led Muhammad, the Prophet of Islam, to say: ?Whoever plants a tree and diligently looks after it until it matures and bears fruit is rewarded.? For all these reasons Muslims see themselves as having a responsibility towards the world and the environment, all of which are the creations of Allah. Unlike many other religions, Muslims do not have any specific festivals in which they give thanks for the harvest or the world. Instead they give thanks to Allah regularly for his creation. [4] 7. Islam is respect Another beautiful aspect of Islam is respect for humanity and the universe in which we live. Islam states clearly that it is the responsibility of each member of the human race to treat creation with respect, honour and dignity. The most deserving of respect is the Creator Himself and of course respect begins with loving and obeying His commandments. Total respect for God allows all the manners and high standards of morality that are inherent in Islam to flow into our lives and the lives of those around us. Because Islam binds respect to peace, love and compassion this involves respecting the honour, reputation and privacy of others. Respect involves staying completely away from the major sins of backbiting, lying, slander, and gossip. It means avoiding sins that will sow discord among the people or lead to destruction. Respect also includes loving for our brothers and sisters what we love for ourselves. It involves treating others the way we expect to be treated and the way we hope God will treat us ? with compassion, love and mercy. Major sins put a barrier between humanity and God?s Mercy and cause all the torment, misery and evil in this world and the hereafter. God commands us to stay away from sin and to strive against our own destructive character flaws. We live in an age where we often demand respect from others but may not respect those around us. One beauty of Islam is that it allows us to regain lost respect by submitting wholeheartedly to the will of God. However if we do not understand how and why we surrender to God?s will we cannot gain respect we want and need. Islam teaches us and God reminds us in the Quran that our sole purpose in life is to worship Him. 8. The Equality of men and women Quran states that all believers are equal and that only righteous deeds elevate one person above another. Believers therefore have an immense respect for pious men and women and Islamic history also tells us that both men and women served and showed righteousness in all areas. A woman, like a man, is obligated to worship God and fulfill the duties upon her. It is thus required that every woman testify that there is none deserving worship but God, and that Muhammad, may God praise him, is His Messenger; to pray; to give charity; to fast; and to perform the pilgrimage to God?s House if she has the means and ability to do so. It is also required that every woman to believe in God, His angels, His scriptures, His Messengers, the Last Day, and to believe in God?s decree. It is also required that every woman worship God as if she sees Him. ?And whoever does righteous good deeds, male or female, and is a (true) believer in the Oneness of God such will enter Paradise and not the least injustice, even to the size of a speck on the back of a date-stone, will be done to them.? (Quran 2:124) Islam however recognizes that equality does not mean that men and women are the same. It takes into account their differences in physiology, nature and temperament. It is not a question of superiority or inferiority, rather a question of natural abilities and having different roles in life. The laws of Islam are just and fair and take these aspects into consideration. Men have been assigned the duty to work and provide for their family and women have been assigned the role of motherhood and homemaking. Islam states however that that the roles are not exclusive nor are they inflexible. Women can work or serve society and men are able to take responsibility for their children or their household. It is interesting to note that where women choose to work the money they earn is their own however a man must provide financially for the whole family. 9. Humankind is able to regret past actions and reform Muslims believe that all members of humankind are able to reform; in addition they believe that the possibility of successful reform is greater than the probability of failure. This belief is derived from the fact that God has given humankind the means to reform, not once but over and over again right up until close to the Day of Judgement. God sent Messengers and Prophets to each and every nation. Some we know from the Quran and the traditions of Prophet Muhammad, others are known only to God. ?And for every community or nation there is a Messenger; when their Messenger comes, the matter will be judged between them with justice, and they will not be wronged.? (Quran 10:47) God does not hold any person responsible until he has been clearly shown the right way. ?...And We never punish until We have sent a Messenger. ? (Quran 17:15) At the same time we are responsible to search for the truth and upon finding it we should accept it and reform our lives accordingly. The past bad actions can be left behind. There is no sin that cannot be forgiven! ?Say, 'O My servants who have transgressed against themselves [by sinning], do not despair of the mercy of God. Indeed, God forgives all sins. Indeed, it is He who is the Forgiving, the Merciful.'? (Quran 39:53) A person should take advantage of God?s mercy by sincerely repenting for the past or if one is not a believer, by converting to the religion of Islam. Every person must work towards his salvation by combining faith, belief and action. 10. God loves beauty in all its forms Prophet Muhammad said, ?No one will enter Paradise who has an ant?s weight of pride in his heart.? A man said, ?What if a man likes his clothes to look good and his shoes to look good?? He said, ?God is beautiful and loves beauty. Pride means denying the truth and looking down on people.? [5] Beauty is the opposite of ugliness. The beauty that exists in creation attests to God?s beauty as well as His power. He who created beauty is the most entitled to beauty. And indeed Paradise is adorned with beauty beyond imagining. God is beautiful and this is why the greatest of all pleasures in Paradise is to look upon God?s Face. God says, ?[Some] faces, that Day, will be radiant; looking to their Lord.? (Quran 75: 22-23) He refers to His names as being the Most Beautiful: ?And the Most Beautiful Names belong to God, so call on Him by them...? (Quran 7:180) Noted Islamic scholar Ibn al-Qayyim, may Allah have mercy on him, had the following to say about beauty in Islam: ?God is to be acknowledged for beauty that bears no resemblance to anything else, and He is to be worshipped by means of the beauty which He loves in words, deeds and attitudes. He loves His slaves to beautify their tongues with the truth, to beautify their hearts with sincere devotion, love, repentance and trust in Him, to beautify their faculties with obedience, and to beautify their bodies by showing His blessings upon them in their clothing and by keeping them pure and free of any filth, dirt or impurity, by removing the hairs which should be removed, by circumcision, and by clipping the nails. Thus they recognize God through these qualities of beauty and seek to draw close to Him through beautiful words, deeds and attitudes. They acknowledge Him for the beauty which is His attribute and they worship Him through the beauty which He has prescribed and His religion.? [6] [1] Al Qarni, Aaidh Ibn Abdullah, (2003), Don?t be sad. International Islamic Publishing House, Saudi Arabia. [2] Saheeh Muslim [3] Saheeh Al-Bukhari, Saheeh Muslim [4]http://www.bbc.co.uk/schools/gcsebitesize/rs/environment/isstewardshiprev2.shtml [5] Saheeh Muslim [6] al-Fawaa?id (1/185) ------------------------------------------------- http://www.islamhouse.com/425320/en/en/articles/The_Beauties_of_Islam Thank you From __peter__ at web.de Mon Jan 20 15:52:57 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Jan 2014 21:52:57 +0100 Subject: 1st Sketch at at ReadOnly dict References: <52DD8297.9050504@earthlink.net> Message-ID: Charles Hixson wrote: > This is just a first sketch, and I haven't yet attempted to test it, so > what I'm hoping for is criticisms on the general approach. > > class RODict: > def __init__ (self, ddict = {}): Default values are evaluted just once when the method is created. Mutable default values mean trouble: >>> class D: ... def __init__(self, dict={}): ... self.dict = dict ... def __setitem__(self, key, value): ... self.dict[key] = value ... def __repr__(self): return repr(self.dict) ... >>> d1 = D() >>> d2 = D() >>> d1[1] = 42 >>> d2[2] = 42 >>> d1 {1: 42, 2: 42} >>> d2 {1: 42, 2: 42} > if not isinstance(ddict, dict): > raise TypeError("ddict must be a dict. It is " + > repr(ddict)) > self._ddict = ddict I think instead of the type check I would build a new dict from the argument. The usual initializers dict({1:2, 3:4}) dict([(1,2), (3,4)]) dict(a=1, b=2) should work with your read-only dict. > > ## Test for containment. > # @param key The item to be found. > # @return True If key is in the instance, otherwise False. Docstrings are usually prefered over comments like the above. > def __contains__(self, key): > return key in self._ddict Did you know http://docs.python.org/dev/library/collections.abc.html#collections.abc.Mapping Subclass from it to ensure that all the usuall methods are defined. From __peter__ at web.de Mon Jan 20 16:00:10 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 20 Jan 2014 22:00:10 +0100 Subject: 1st Sketch at at ReadOnly dict References: <52DD8297.9050504@earthlink.net> Message-ID: Peter Otten wrote: > Charles Hixson wrote: > >> This is just a first sketch, and I haven't yet attempted to test it, so >> what I'm hoping for is criticisms on the general approach. >> >> class RODict: > >> def __init__ (self, ddict = {}): > > Default values are evaluted just once when the method is created. Mutable > default values mean trouble: > >>>> class D: > ... def __init__(self, dict={}): > ... self.dict = dict > ... def __setitem__(self, key, value): > ... self.dict[key] = value > ... def __repr__(self): return repr(self.dict) > ... >>>> d1 = D() >>>> d2 = D() >>>> d1[1] = 42 >>>> d2[2] = 42 >>>> d1 > {1: 42, 2: 42} >>>> d2 > {1: 42, 2: 42} D'oh, that was just and instintive reaction. You may already know that... Of course it doesn't matter as long as no attempt is made to mutate the mutable value. From tjreedy at udel.edu Mon Jan 20 16:56:29 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 20 Jan 2014 16:56:29 -0500 Subject: Can post a code but afraid of plagiarism In-Reply-To: References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/20/2014 9:08 AM, Roy Smith wrote: > That's a little harsh. Working in groups, and sharing code, are > important parts of how software gets developed today. Those > collaborative work habits should indeed be taught. Until recently, teaching collaboration through group projects has had the problem of leeching. Asking group members to grade each other's participation and contributions does not work too well. My daughter ran into this problem in her first programming class where private-until-done 'group' work was too much her work. In her second class, there was discussion of each other's coding problems *in the class*, in front of the teacher, and she enjoyed that much more. It is now possible to run collaboration through software that records interaction. My daughter took a composition class where discussion and review of each other's work was recorded and contributed to each person's grade. But this was not collaborative writing, which would be another level of interaction, and one which is common beyond college classes. A programming class (probably best after the first) could use a real (meaning, used outside of classes) repository and tracker. *That* would better prepare people for later work, whether on a job or as an open-source volunteer. -- Terry Jan Reedy From rpi.baldum at gmail.com Mon Jan 20 17:09:46 2014 From: rpi.baldum at gmail.com (rpi.baldum at gmail.com) Date: Mon, 20 Jan 2014 14:09:46 -0800 (PST) Subject: matlabFunction Equivalent? Message-ID: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> Hey all, I'm new at Python, so if you see any mistakes feel free to let me know. I'm trying to take a symbolic expression and turn it into a variable equation or function. I think that just an expression of variables would be preferable. I have a range equation which I form using symbols and then take various derivatives of it. I then want to have these derivatives on hand to use for various functions, but short of using sub every time or just copy pasting from the console output (I don't want to do that), I can't find an efficient way to do this. Matlab had matlabFunction which was really handy, but I don't think Python has an equivalent. ######## import numpy as np import scipy as sp import sympy as sy import math as ma x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y z x_s y_s z_s theta theta_dot x_dot y_dot z_dot') rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5) rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) + theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - z_dot*z_s)/rho drho_dx = sy.diff(rho, x) drho_dy = sy.diff(rho, y) drho_dz = sy.diff(rho, z) #I then want drho_dx, etc to be variable expressions with x, y, z, etc as variables instead of symbols or numbers. I could do: x, y, z = 1200, 1300, 1400 #m drho_dx = subs([x, x], [y, y], [z, z]) #but this seems inefficient to do multiple times. Thoughts? From ralf at systemexit.de Mon Jan 20 17:25:56 2014 From: ralf at systemexit.de (Ralf Schmitt) Date: Mon, 20 Jan 2014 23:25:56 +0100 Subject: [ANN] pypiserver 1.1.5 - minimal private pypi server Message-ID: <87ha8y70jv.fsf@myhost.lan> Hi, I've just uploaded pypiserver 1.1.5 to the python package index. pypiserver is a minimal PyPI compatible server. It can be used to serve a set of packages and eggs to easy_install or pip. pypiserver is easy to install (i.e. just 'pip install pypiserver'). It doesn't have any external dependencies. https://pypi.python.org/pypi/pypiserver/ should contain enough information to easily get you started running your own PyPI server in a few minutes. The code is available on github: https://github.com/schmir/pypiserver I didn't announce the previous version, so here's the changelog for the last two versions: 1.1.5 (2014-01-20) ------------------ - only list devpi-server and proxypypi as alternatives - fix wheel file handling for certain wheels - serve wheel files as application/octet-stream - make pypiserver executable from wheel file - build universal wheel - remove scripts subdirectory - add --index-url cli parameter 1.1.4 (2014-01-03) ------------------ - make pypiserver compatible with pip 1.5 (https://github.com/schmir/pypiserver/pull/42) -- Cheers Ralf From breamoreboy at yahoo.co.uk Mon Jan 20 17:48:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 20 Jan 2014 22:48:48 +0000 Subject: matlabFunction Equivalent? In-Reply-To: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> References: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> Message-ID: On 20/01/2014 22:09, rpi.baldum at gmail.com wrote: > Hey all, > > I'm new at Python, so if you see any mistakes feel free to let me know. > > I'm trying to take a symbolic expression and turn it into a variable equation or function. I think that just an expression of variables would be preferable. > > I have a range equation which I form using symbols and then take various derivatives of it. I then want to have these derivatives on hand to use for various functions, but short of using sub every time or just copy pasting from the console output (I don't want to do that), I can't find an efficient way to do this. Matlab had matlabFunction which was really handy, but I don't think Python has an equivalent. > > ######## > import numpy as np > import scipy as sp > import sympy as sy > import math as ma > > x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y z x_s y_s z_s theta theta_dot x_dot y_dot z_dot') > > rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5) > > rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) + theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - z_dot*z_s)/rho > > drho_dx = sy.diff(rho, x) > > drho_dy = sy.diff(rho, y) > > drho_dz = sy.diff(rho, z) > > #I then want drho_dx, etc to be variable expressions with x, y, z, etc as variables instead of symbols or numbers. I could do: > > x, y, z = 1200, 1300, 1400 #m > > drho_dx = subs([x, x], [y, y], [z, z]) > > #but this seems inefficient to do multiple times. Thoughts? > There are references to MatlabFunction in code here https://github.com/scipy/scipy/tree/master/scipy/io/matlab but I haven't the faintest idea as to whether or not it does what you want, sorry :( -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From charleshixsn at earthlink.net Mon Jan 20 18:37:14 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 20 Jan 2014 15:37:14 -0800 Subject: 1st Sketch at at ReadOnly dict In-Reply-To: References: <52DD8297.9050504@earthlink.net> Message-ID: <52DDB32A.20206@earthlink.net> On 01/20/2014 12:52 PM, Peter Otten wrote: > Charles Hixson wrote: > >> This is just a first sketch, and I haven't yet attempted to test it, so >> what I'm hoping for is criticisms on the general approach. >> >> class RODict: >> def __init__ (self, ddict = {}): > Default values are evaluted just once when the method is created. Mutable > default values mean trouble: > >>>> class D: > ... def __init__(self, dict={}): > ... self.dict = dict > ... def __setitem__(self, key, value): > ... self.dict[key] = value > ... def __repr__(self): return repr(self.dict) > ... >>>> d1 = D() >>>> d2 = D() >>>> d1[1] = 42 >>>> d2[2] = 42 >>>> d1 > {1: 42, 2: 42} >>>> d2 > {1: 42, 2: 42} > >> if not isinstance(ddict, dict): >> raise TypeError("ddict must be a dict. It is " + >> repr(ddict)) >> self._ddict = ddict > I think instead of the type check I would build a new dict from the > argument. The usual initializers > > dict({1:2, 3:4}) > dict([(1,2), (3,4)]) > dict(a=1, b=2) > > should work with your read-only dict. > >> ## Test for containment. >> # @param key The item to be found. >> # @return True If key is in the instance, otherwise False. > Docstrings are usually prefered over comments like the above. > >> def __contains__(self, key): >> return key in self._ddict > Did you know > > http://docs.python.org/dev/library/collections.abc.html#collections.abc.Mapping > > Subclass from it to ensure that all the usuall methods are defined. > That link, http://docs.python.org/dev/library/collections.abc.html#collections.abc.Mapping , is a very good one. I hadn't realized that it separated Mapping from MutableMapping. It would be nice if there were some examples of it's usage around, though. I can't really tell how to use it. (E.g., it mixes in __contains__, but it doesn't show how to specify what you are testing for cotainment in. So it looks as if I need to specify everything anyway because I can't tell what might be implemented in some inappropriate way.) OTOH, it's a good list of what needs to be implemented. (I see that I left out implementation of eq and ne, which is pretty straightfoward, but apparently needed (unless it's automatically being handled by the mixin...which I can't tell). -- Charles Hixson From rosuav at gmail.com Mon Jan 20 18:49:09 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Jan 2014 10:49:09 +1100 Subject: Diving in to Python - Best resources? In-Reply-To: References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: On Tue, Jan 21, 2014 at 6:50 AM, Emile van Sebille wrote: > On 1/20/2014 11:34 AM, Matt Watson wrote: > >> My question to you guys is... for someone like me, what route would you >> take to learning Python? > > > I'd work my way through the tutorial [1] then pick a work based project and > start right in. Ask questions along the way. > > [1] http://docs.python.org/2/tutorial/ I'd agree, except that I'd use this link [2] instead, and a Python 3.x interpreter. Unless you have a good reason for writing Python 2 code and learning Python 2, skip it and go straight to Py3. ChrisA [2] http://docs.python.org/3/tutorial/ From rosuav at gmail.com Mon Jan 20 19:08:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Jan 2014 11:08:32 +1100 Subject: 1st Sketch at at ReadOnly dict In-Reply-To: <52DD8297.9050504@earthlink.net> References: <52DD8297.9050504@earthlink.net> Message-ID: On Tue, Jan 21, 2014 at 7:09 AM, Charles Hixson wrote: > # @note Instances can be created only from existing dicts. > > ## Class initializer. > # @param ddict The data dictionary to which this is a read only > # access. > # @throws TypeError if ddict is not a dict. > def __init__ (self, ddict = {}): > if not isinstance(ddict, dict): > raise TypeError("ddict must be a dict. It is " + > repr(ddict)) > self._ddict = ddict Instead of demanding that a dict (or dict subclass) be passed, why not simply pass all args on to dict() itself? Is there a reason this won't work? def __init__(self, *args, **kwargs): self._ddict = dict(*args, **kwargs) ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 20 19:47:41 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 21 Jan 2014 00:47:41 GMT Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52ddc3ad$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jan 2014 09:08:28 -0500, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg >> wrote: >> > I did a short time of teaching while I was in school. If three >> > students all turned in the same assignment, they all got docked >> > significantly. There was no "who copied off of whom?", it was >> > "someone shared when they shouldn't have." >> >> What a wonderful way to promote an attitude of "my code is MY CODE and >> should never leave my sight". What a delightful way of thinking to >> unleash on the world. > > That's a little harsh. Working in groups, and sharing code, are > important parts of how software gets developed today. Those > collaborative work habits should indeed be taught. But, school is also > about evaluation of progress. At the end of the class, the teacher > needs some objective way to figure out how much each student has learned > and assign a grade. It's hard to do that if people aren't handing in > assignments done individually. An objective way to figure out individual progress is easy. It's called an "exam" or "test". Admittedly, it's normally only practical for examinations to last no more than a day for senior students, and an hour or maximum two hours for junior students, and some subjects are more easily tested this way than others. But you can still examine a lot in a couple of hours. If you're interested in accurately measuring the learning of individual students, there is at least one pretty damning problem with assignments: just because student X puts his name on the paper doesn't mean student X wrote the paper. Assignments are effectively based on the honour system, and we know how well that works. For those with the money to spend, you need not do a lick of work to get an A. Perhaps that's why Harvard has just given up even trying to distinguish the students who learn things from those who don't? Forget George Bush's "Gentleman's C", Harvard now practically gives A's away to anyone who shows up (and pays the fees). http://qz.com/153694/the-most-commonly-awarded-grade-at-harvard-is-an-a/ Presumably they're protecting their business model. Students are customers, and if your customers are paying a small fortune to attend, they need to get something in return. Knowledge is good, but you can't put knowledge on a CV or frame it and put it on a wall. It would be interesting to think about the incentives which have lead to an over-reliance on take-home assignments rather than exams, as well as the pros and cons of one versus the other. Don't get me wrong, there are advantages to assignments as well, but I think that the total prohibition on collaboration is misguided. The question in my mind is how to encourage students to learn from each other rather than to merely mechanically copy from each other? Relevant: http://qz.com/157579/confession-of-an-ivy-league-teaching-assistant-heres-why-i-inflated-grades/ -- Steven From jcasale at activenetwerx.com Mon Jan 20 20:07:06 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 21 Jan 2014 01:07:06 +0000 Subject: Implementing append within a descriptor Message-ID: I have a caching non data descriptor that stores values in the implementing class instances __dict__. Something like: class Descriptor: def __init__(self, func, name=None, doc=None): self.__name__ = name or func.__name__ self.__module__ = func.__module__ self.__doc__ = doc or func.__doc__ self.func = func def __get__(self, obj, _=None): if obj is None: return self value = obj.__dict__.get(self.__name__, None) if value is None: value = self.func(obj) obj.__dict__[self.__name__] = value return value def __set__(self, obj, value): obj.__dict__[self.__name__] = value def __delete__(self, obj): if self.__name__ in obj.__dict__: del obj.__dict__[self.__name__] For the classes that decorate a method with this and accept list type data, I need to catch the following scenario (__set__ is reimplemented for the specific property by subclassing Descriptor): foo = MyClass() # This calls __set__ foo.some_property = [x for x in range(5)] # This bypasses __set__ obviously. foo.some_property.append(5) So re-implementing my own list class has the draw back for the user that he must create the data type is assigning directly. I want to avoid this. What workaround can I leverage to catch the append event so I can avoid the new data type? Thanks, jlc From rosuav at gmail.com Mon Jan 20 20:18:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Jan 2014 12:18:01 +1100 Subject: Implementing append within a descriptor In-Reply-To: References: Message-ID: On Tue, Jan 21, 2014 at 12:07 PM, Joseph L. Casale wrote: > foo = MyClass() > # This calls __set__ > foo.some_property = [x for x in range(5)] > # This bypasses __set__ obviously. > foo.some_property.append(5) > > So re-implementing my own list class has the draw back for the user that he must create the > data type is assigning directly. I want to avoid this. What workaround can I leverage to catch > the append event so I can avoid the new data type? You're going to have to subclass list if you want to intercept its methods. As I see it, there are two ways you could do that: when it's set, or when it's retrieved. I'd be inclined to do it in __set__, but either could work. In theory, you could make it practically invisible - just check to see if you're trying to __set__ a list, and if you are, set a magical list instead. ChrisA From charleshixsn at earthlink.net Mon Jan 20 22:30:23 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 20 Jan 2014 19:30:23 -0800 Subject: 1st Sketch at at ReadOnly dict In-Reply-To: References: <52DD8297.9050504@earthlink.net> Message-ID: <52DDE9CF.1010105@earthlink.net> On 01/20/2014 04:08 PM, Chris Angelico wrote: > On Tue, Jan 21, 2014 at 7:09 AM, Charles Hixson > wrote: >> # @note Instances can be created only from existing dicts. >> >> ## Class initializer. >> # @param ddict The data dictionary to which this is a read only >> # access. >> # @throws TypeError if ddict is not a dict. >> def __init__ (self, ddict = {}): >> if not isinstance(ddict, dict): >> raise TypeError("ddict must be a dict. It is " + >> repr(ddict)) >> self._ddict = ddict > Instead of demanding that a dict (or dict subclass) be passed, why not > simply pass all args on to dict() itself? Is there a reason this won't > work? > > def __init__(self, *args, **kwargs): > self._ddict = dict(*args, **kwargs) > > ChrisA It would work, as long as it would work for dict(), but I have been expecting to use it in situations where it would be useful to have a different access to the dict that would be writeable. So I didn't bother. (Well, and took steps to ensure that it was being used in the manner that I expected. So I'd know to change it if it were appropriate.) It *would* make it more difficult for the class to test it's creation arguments for sanity, though. (One could argue that allowing read only access to an empty dict is violating sanity, but I don't think in any dangerous way.) I do sometimes worry that using isinstance excessively is overly expensive. Perhaps I should wrap them with a test for debug mode. -- Charles Hixson From drsalists at gmail.com Mon Jan 20 23:14:08 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Mon, 20 Jan 2014 20:14:08 -0800 Subject: 1st Sketch at at ReadOnly dict In-Reply-To: <52DD8297.9050504@earthlink.net> References: <52DD8297.9050504@earthlink.net> Message-ID: On Mon, Jan 20, 2014 at 12:09 PM, Charles Hixson wrote: > class RODict: > #Instance Variable Doc > ## @var _ddict > # This variable holds the reference to the dict. > > ## Class initializer. > # @param ddict The data dictionary to which this is a read only > # access. > # @throws TypeError if ddict is not a dict. > def __init__ (self, ddict = {}): > if not isinstance(ddict, dict): > raise TypeError("ddict must be a dict. It is " + > repr(ddict)) > self._ddict = ddict When I see this isinstance, I think "Gee, that means none of the dict-like-objects I recently compared would work with this class." The comparison is at the URL below; all the things compared are trees that provide a dictionary-like interface, but also find_min, find_max and can iterate in key order. I don't think any of them inherit from dict, but they are all dict-like in a duck-typed sense: http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/ HTH From charleshixsn at earthlink.net Mon Jan 20 23:37:42 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Mon, 20 Jan 2014 20:37:42 -0800 Subject: 1st Sketch at at ReadOnly dict In-Reply-To: References: <52DD8297.9050504@earthlink.net> Message-ID: <52DDF996.5050003@earthlink.net> On 01/20/2014 08:14 PM, Dan Stromberg wrote: > On Mon, Jan 20, 2014 at 12:09 PM, Charles Hixson > wrote: > >> class RODict: >> #Instance Variable Doc >> ## @var _ddict >> # This variable holds the reference to the dict. >> >> ## Class initializer. >> # @param ddict The data dictionary to which this is a read only >> # access. >> # @throws TypeError if ddict is not a dict. >> def __init__ (self, ddict = {}): >> if not isinstance(ddict, dict): >> raise TypeError("ddict must be a dict. It is " + >> repr(ddict)) >> self._ddict = ddict > When I see this isinstance, I think "Gee, that means none of the > dict-like-objects I recently compared would work with this class." > > The comparison is at the URL below; all the things compared are trees > that provide a dictionary-like interface, but also find_min, find_max > and can iterate in key order. I don't think any of them inherit from > dict, but they are all dict-like in a duck-typed sense: > > http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/2014-01/ > > HTH > Well, it would mean you couldn't create instances of this class from them. I haven't yet specified the eq and ne methods, but they'd probably be something like: def ne(self, key): return self._ddict.ne(key) (I'd need to look up the precise names of the comparison routines. Perhaps it would be "__ne__" rather than "ne".) So if they'd work with a normal dict, they should work with this, for comparison. Note that this is a dict-alike, and therefore not in a predictable order. If the items were to be ordered, however, they would be in order by the value rather than by the key, as my use-case is most likely to want to access the items with the highest value most often. I may even decide to use a list of lists, but a dict yields simpler code, even if I suspect that lists might be more efficient. But the choice of list would mean I could use a tuple, which because it is standard would also tend to make things simpler. (It wouldn't, however, allow background updating, as dictviews do, and also RODict does, so I'd need to find some way to manage that...probably meaning that I'd need to regenerate them more often.) -- Charles Hixson From xeysxeys at gmail.com Tue Jan 21 03:00:53 2014 From: xeysxeys at gmail.com (xeysxeys at gmail.com) Date: Tue, 21 Jan 2014 00:00:53 -0800 (PST) Subject: Early retirement project? Message-ID: Well, I retired early, and I guess now I've got some spare time to learn about programming, which always seemed rather mysterious. I am using an old mac as my main computer, and it runs os x 10.4 is this too old? It fills my needs, and I am on a fixed income and can't really afford to buy another. I think python would be a good starter language, based on what I've read on the net. xeysxeys From johannes.schneider at galileo-press.de Tue Jan 21 03:07:22 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Tue, 21 Jan 2014 09:07:22 +0100 Subject: Imports in Python Message-ID: <52DE2ABA.6090303@galileo-press.de> Hi List, I remember some document explaining the python imports in detail somewhere, but I don't have any idea where it was. Even no idea if it was in the List or some blogbost. Does anybody of you have some suggestions where I can find those informations besides the official documentation? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From johannes.schneider at galileo-press.de Tue Jan 21 03:05:12 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Tue, 21 Jan 2014 09:05:12 +0100 Subject: matlabFunction Equivalent? In-Reply-To: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> References: <403d8fa2-171f-4f8e-8e77-f30ae57a3135@googlegroups.com> Message-ID: <52DE2A38.3060904@galileo-press.de> On 20.01.2014 23:09, rpi.baldum at gmail.com wrote: > Hey all, > > I'm new at Python, so if you see any mistakes feel free to let me know. > > I'm trying to take a symbolic expression and turn it into a variable equation or function. I think that just an expression of variables would be preferable. > > I have a range equation which I form using symbols and then take various derivatives of it. I then want to have these derivatives on hand to use for various functions, but short of using sub every time or just copy pasting from the console output (I don't want to do that), I can't find an efficient way to do this. Matlab had matlabFunction which was really handy, but I don't think Python has an equivalent. > > ######## > import numpy as np > import scipy as sp > import sympy as sy > import math as ma > > x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y z x_s y_s z_s theta theta_dot x_dot y_dot z_dot') > > rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5) > > rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) + theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - z_dot*z_s)/rho > > drho_dx = sy.diff(rho, x) > > drho_dy = sy.diff(rho, y) > > drho_dz = sy.diff(rho, z) > > #I then want drho_dx, etc to be variable expressions with x, y, z, etc as variables instead of symbols or numbers. I could do: > > x, y, z = 1200, 1300, 1400 #m > > drho_dx = subs([x, x], [y, y], [z, z]) > > #but this seems inefficient to do multiple times. Thoughts? > If you don not mind installing other programs, maybe you can have a look at sage (www.sagemath.org). That's a ComputerAlgebraSystem using python as its base and supporting most (all?) of the python syntax and moduls bg, Johannes -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From jeanpierreda at gmail.com Tue Jan 21 03:30:52 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Tue, 21 Jan 2014 00:30:52 -0800 Subject: Early retirement project? In-Reply-To: References: Message-ID: Congrats on the early retirement! It takes guts to decide to do that. :) Python can run on a mac 10.4. In the worst case you may have to download xcode and build Python from source, if there are no powerpc binaries available. That's pretty simple, though (./configure && make && make install). -- Devin On Tue, Jan 21, 2014 at 12:00 AM, wrote: > Well, I retired early, and I guess now I've got some spare time to learn about programming, which always seemed rather mysterious. I am using an old mac as my main computer, and it runs os x 10.4 is this too old? It fills my needs, and I am on a fixed income and can't really afford to buy another. I think python would be a good starter language, based on what I've read on the net. > > xeysxeys > -- > https://mail.python.org/mailman/listinfo/python-list From phiwer at gmail.com Tue Jan 21 04:59:32 2014 From: phiwer at gmail.com (Philip Werner) Date: Tue, 21 Jan 2014 03:59:32 -0600 Subject: Python Scalability TCP Server + Background Game References: <27bae268-20a6-4ac3-a0dc-bd5be04d1da1@googlegroups.com> <08f0a532-6828-4eef-ae9f-de8722edd11e@googlegroups.com> Message-ID: > Looking a lot more normal and readable now. Thanks! > > Note that some people have experienced odd issues with Pan, possibly > relating to having multiple instances running simultaneously. You may > want to take care not to let it open up a duplicate copy of itself. > > ChrisA Thanks for the heads up. It is buggy to say the least. Any other program on linux you may suggest? Regards, Philip From r.voigtlaender at gmail.com Tue Jan 21 05:20:48 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 02:20:48 -0800 (PST) Subject: use class in class Message-ID: <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> Hi, I have a problem using a class object within another class. It is about the line: self.openlist.append(Node(self.start, None, 0, 0)) If I use it in __init__ it works. If I use it in calcRoute(self) I get the following error: local variable 'node' referenced before assignment The error occures in AMap.calcRoute() Where is my mistake? Thanks Robert import numpy as np from matplotlib import pyplot as plt import matplotlib.cm as cm class Node(object): def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h class NewAMap(object): def __init__(self, size, start, target): self.size = size self.start = start self.target = target self.openlist = [] self.closedlist = set() self.EmptyValue = 0 self.clear() self.addStart(self.start) self.addTarget(self.target) #self.openlist.append(Node(self.start, None, 0, 0)) def clear(self): self.OccMap = np.zeros(shape=(self.size[0],self.size[1]),dtype=int) def display(self): print np.swapaxes(self.OccMap,0,1) self.PicMap = np.zeros(shape=(self.size[0],self.size[1]),dtype=(float,3)) for x in xrange(0,self.size[0]): for y in xrange(0,self.size[1]): if self.OccMap[x][y] == 0: self.PicMap[y][x]=(1,1,1) elif self.OccMap[x][y] == -1: self.PicMap[y][x]=(0,0,0) elif self.OccMap[x][y] == -2: self.PicMap[y][x]=(1,0,0) elif self.OccMap[x][y] == -3: self.PicMap[y][x]=(0,0,1) #print self.PicMap plt.imshow(self.PicMap, interpolation='nearest') plt.show() def addBlocked(self, blockposs): self.OccMap[blockposs[0]][blockposs[1]]=-1 def addStart(self, start): self.OccMap[start[0]][start[1]]=-2 def addTarget(self, target): self.OccMap[target[0]][target[1]]=-3 def calcRoute(self): self.openlist.append(Node(self.start, None, 0, 0)) for Node in self.openlist: print Node.pos, Node.parent, Node.g, Node.h, Node.f def main(): AMap = NewAMap((20,20),(1,12),(12,12)) for y in range(8,17): AMap.addBlocked((8,y)) AMap.calcRoute() AMap.display() if __name__ == '__main__': main() From oscar.j.benjamin at gmail.com Tue Jan 21 05:32:13 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 21 Jan 2014 10:32:13 +0000 Subject: Can post a code but afraid of plagiarism In-Reply-To: <52ddc3ad$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <52ddc3ad$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140121103211.GA2632@gmail.com> On Tue, Jan 21, 2014 at 12:47:41AM +0000, Steven D'Aprano wrote: > On Mon, 20 Jan 2014 09:08:28 -0500, Roy Smith wrote: > > > In article , > > Chris Angelico wrote: > > > >> On Mon, Jan 20, 2014 at 4:21 PM, Dan Stromberg > >> wrote: > >> > I did a short time of teaching while I was in school. If three > >> > students all turned in the same assignment, they all got docked > >> > significantly. There was no "who copied off of whom?", it was > >> > "someone shared when they shouldn't have." > >> > >> What a wonderful way to promote an attitude of "my code is MY CODE and > >> should never leave my sight". What a delightful way of thinking to > >> unleash on the world. > > > > That's a little harsh. Working in groups, and sharing code, are > > important parts of how software gets developed today. Those > > collaborative work habits should indeed be taught. But, school is also > > about evaluation of progress. At the end of the class, the teacher > > needs some objective way to figure out how much each student has learned > > and assign a grade. It's hard to do that if people aren't handing in > > assignments done individually. I agree that it is unfortunate but there's a bit of a balancing act with this. The problem is that there are two sometimes conflicting roles in education: teaching and assessing. When you set assignments the students will usually learn more if they work in groups. However at some point you need to try and assess how much they've individually learned. I find in practice that it's easy to tell when a student has copied someone else without really understanding what they're doing though. Of course if they just pay someone else to do it for them then there's not much you can do... > > An objective way to figure out individual progress is easy. It's called > an "exam" or "test". Admittedly, it's normally only practical for > examinations to last no more than a day for senior students, and an hour > or maximum two hours for junior students, and some subjects are more > easily tested this way than others. But you can still examine a lot in a > couple of hours. If you're interested in accurately measuring the > learning of individual students, there is at least one pretty damning > problem with assignments: just because student X puts his name on the > paper doesn't mean student X wrote the paper. Assignments are effectively > based on the honour system, and we know how well that works. For those > with the money to spend, you need not do a lick of work to get an A. The real problem with exams is that exam conditions are so unrepresentative of real work. How often do you use the internet, or documentation, or text books etc. in your own work? How often would you have to do something without having anyone at least to discuss the idea with? But yes it's absolutely necessary to have some exams or else the whole system is open to abuse. > > Perhaps that's why Harvard has just given up even trying to distinguish > the students who learn things from those who don't? Forget George Bush's > "Gentleman's C", Harvard now practically gives A's away to anyone who > shows up (and pays the fees). I think that's a little harsh. To say that the majority of students get an A- or better does not mean that they give A's to "anyone who shows up". I would expect that the majority of students at Harvard do a lot more than just show up. (I don't know much about Harvard specifically but this is true of most universities). > > http://qz.com/153694/the-most-commonly-awarded-grade-at-harvard-is-an-a/ > > Presumably they're protecting their business model. Students are > customers, and if your customers are paying a small fortune to attend, > they need to get something in return. Knowledge is good, but you can't > put knowledge on a CV or frame it and put it on a wall. > > It would be interesting to think about the incentives which have lead to > an over-reliance on take-home assignments rather than exams, as well as > the pros and cons of one versus the other. Don't get me wrong, there are > advantages to assignments as well, but I think that the total prohibition > on collaboration is misguided. The question in my mind is how to > encourage students to learn from each other rather than to merely > mechanically copy from each other? > > Relevant: > > http://qz.com/157579/confession-of-an-ivy-league-teaching-assistant-heres-why-i-inflated-grades/ I can definitely empathise with what she says. Once I started marking assignments it quickly became apparent that my standards were higher than those of other people. Every now and again I would mark a big assignment and get a deluge of grief from the students who had done badly. If it's a small assignment (say 5 students) then you can build something out of that and spend time preparing them for future assignments. If it's a big assignment (100+ students) then it's just a whole load of grief that no one really wants. The problem of students giving you grief doesn't really happen with exams because in that case if someone complains it's not you (the original marker) who has to talk to them and remark it. Where I work they have to fill out their feedback forms before they take the exam so they can't use that to complain about the exam being too hard or being marked too harshly. But what does happen is that if the average grades are too high you get in trouble for the exam being too easy. If the grade is too low you get in trouble since you've apparently done a bad job teaching. There's a conflict of interest right there (being both the teacher and the examiner) and it basically results in everything adjusting to the ability of the students rather than measuring it objectively. Also I don't know why the Harvard TA says that this isn't a problem in the UK. Here in the UK the government does it with national externally marked exams: http://www.theguardian.com/education/2012/may/01/gcse-alevels-easier-says-ofqual I would estimate that over the past ~50 years school standards for Maths and Physics in the UK have slipped by ~1 academic year. Perhaps that's why we make them do 4 years at university now... Oscar From rosuav at gmail.com Tue Jan 21 05:47:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Jan 2014 21:47:15 +1100 Subject: use class in class In-Reply-To: <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> References: <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> Message-ID: On Tue, Jan 21, 2014 at 9:20 PM, Robert Voigtl?nder wrote: > def calcRoute(self): > self.openlist.append(Node(self.start, None, 0, 0)) > for Node in self.openlist: print Node.pos, Node.parent, Node.g, Node.h, Node.f You're using the name Node to mean two different things. In the first line, you expect it to be the global name (which is the class), but on the second, you want to iterate over the node instances. That assigns to the name Node, which causes your problems. I recommend using a different name for the instances here, probably with a lower-case first letter. That would solve your problem _and_ make your code more readable. ChrisA From ben+python at benfinney.id.au Tue Jan 21 06:04:53 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 21 Jan 2014 22:04:53 +1100 Subject: Imports in Python References: <52DE2ABA.6090303@galileo-press.de> Message-ID: <8538khwq7e.fsf@benfinney.id.au> Johannes Schneider writes: > I remember some document explaining the python imports in detail > somewhere, but I don't have any idea where it was. Even no idea if it > was in the List or some blogbost. What kind of detail do you want? > Does anybody of you have some suggestions where I can find those > informations besides the official documentation? We'd need to know what information you want beyond what's in the official documentation . -- \ ?I have one rule to live by: Don't make it worse.? ?Hazel | `\ Woodcock | _o__) | Ben Finney From r.voigtlaender at gmail.com Tue Jan 21 06:11:27 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 03:11:27 -0800 (PST) Subject: use class in class In-Reply-To: References: <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> Message-ID: <4b31ea37-a099-4e3e-a87a-332c16a16cc1@googlegroups.com> > I recommend using a different name for the instances here, probably > > with a lower-case first letter. That would solve your problem _and_ > > make your code more readable. Thanks a lot! I was confused by the debuger gifing me the wrong line as containing the error. I changed it regarding your advide. And it works. Robert From r.voigtlaender at gmail.com Tue Jan 21 06:17:43 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 03:17:43 -0800 (PST) Subject: which data structure to use? Message-ID: Hi, which would be the best data structure to use for the following case? I have objects like this: class Node(object): def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h I need to build a "list" of these objects. The amount is unknown. On this list I need to regularly 1. check if a specific item - identified by Node.pos - is in the list. 2. find the object with the lowest Node.f attribute and update or remove it What would be a good approach. Using a list I always need to traverse the whole list to do one of the above actions. Thanks Robert From greg.ewing at canterbury.ac.nz Tue Jan 21 06:20:51 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 22 Jan 2014 00:20:51 +1300 Subject: Early retirement project? In-Reply-To: References: Message-ID: xeysxeys at gmail.com wrote: > I am using an old mac as my > main computer, and it runs os x 10.4 is this too old? Not at all! It's plenty powerful enough to run Python for educational purposes, and for some quite serious purposes as well. Also, Python is an excellent choice for learning programming. There's hardly any extraneous crud to learn before you can get started -- you just get right down to business. -- Greg From rosuav at gmail.com Tue Jan 21 06:27:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 21 Jan 2014 22:27:53 +1100 Subject: which data structure to use? In-Reply-To: References: Message-ID: On Tue, Jan 21, 2014 at 10:17 PM, Robert Voigtl?nder wrote: > 1. check if a specific item - identified by Node.pos - is in the list. > 2. find the object with the lowest Node.f attribute and update or remove it Are both those values constant once the Node is added? If so, the easiest way would be to maintain a dictionary mapping pos to the Node (or to a list of Nodes, if you can have multiple with the same pos), and probably heapq for the f values. But if they change, you'll have to update both data structures. If they change often, it's probably not worth maintaining index structures - just search for what you want, when you want it. And if you're working with a small list (say, less than a thousand items), performance isn't going to matter at all, so just do whatever looks cleanest in your code - probably you have that already. ChrisA From greg.ewing at canterbury.ac.nz Tue Jan 21 06:25:21 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Wed, 22 Jan 2014 00:25:21 +1300 Subject: Early retirement project? In-Reply-To: References: Message-ID: Devin Jeanpierre wrote: > Python can run on a mac 10.4. In the worst case you may have to > download xcode and build Python from source, There's even a Python that already comes with the system, although it's an oldish version (somewhere around 2.5, I think). -- Greg From ben+python at benfinney.id.au Tue Jan 21 06:34:08 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Tue, 21 Jan 2014 22:34:08 +1100 Subject: which data structure to use? References: Message-ID: <85y529vaa7.fsf@benfinney.id.au> Robert Voigtl?nder writes: > which would be the best data structure to use for the following case? First up, I want to compliment you on asking exactly the right question. Getting the data structure right or wrong can often shape the solution dramatically. > I have objects like this: > > class Node(object): > def __init__(self, pos, parent, g , h): > self.pos = pos > self.parent = parent > self.g = g > self.h = h > self.f = g+h It's important to note a distinction: The class ?Node? doesn't have attributes ?pos?, ?f?, ?g?, ?h?, etc. Those attributes are assigned to each instance when the instance is initialised. > I need to build a "list" of these objects. The amount is unknown. Any built-in Python collection type seems good so far. > On this list I need to regularly > > 1. check if a specific item - identified by Node.pos - is in the list. > 2. find the object with the lowest Node.f attribute and update or > remove it So, in neither of those cases is it correct to talk of ?Node.pos? or ?Node.f?, since those are attributes of the class, and the attribute names don't exist (unless there is other code which you're not showing us). They'll be attributes of a specific instance of the class in each case. > What would be a good approach. Using a list I always need to traverse > the whole list to do one of the above actions. If the ?pos? attribute is unique for all Node instances ? as implied by your ?indentified by? clause above ? then you could maintain a mapping from ?pos? values to the Node instances: nodes = dict() root_node = Node(pos='root', parent=None, g=object(), h=object()) nodes[root_node.pos] = root_node foo_node = Node(pos='foo', parent=root_node, g=object(), h=object()) nodes[foo_node.pos] = foo_node As for finding the node with the lowest value of an attribute, I'd recommend you just use brute force until you get concrete measurements showing that that specific operation is occupying too much time. Write the code correct and readable first, before trying to optimise what you don't need to yet. -- \ ?Value your freedom or you will lose it, teaches history. | `\ ?Don't bother us with politics,? respond those who don't want | _o__) to learn.? ?Richard Stallman, 2002 | Ben Finney From python.list at tim.thechases.com Tue Jan 21 06:38:01 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 21 Jan 2014 05:38:01 -0600 Subject: Early retirement project? In-Reply-To: References: Message-ID: <20140121053801.60f8cf11@bigbox.christie.dr> On 2014-01-21 00:00, xeysxeys at gmail.com wrote: > Well, I retired early, and I guess now I've got some spare time to > learn about programming, which always seemed rather mysterious. I > am using an old mac as my main computer, and it runs os x 10.4 is > this too old? It fills my needs, and I am on a fixed income and > can't really afford to buy another. I think python would be a good > starter language, based on what I've read on the net. It's certainly a great way to consume lots of hours :) Mac OS X 10.4 should come with an older version of Python out-of-the-box. The install media should also include XCode if you want to download the latest & greatest version of Python and install that from source instead. -tkc From oscar.j.benjamin at gmail.com Tue Jan 21 06:49:53 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 21 Jan 2014 11:49:53 +0000 Subject: which data structure to use? In-Reply-To: References: Message-ID: <20140121114951.GD2632@gmail.com> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl?nder wrote: > Hi, > > which would be the best data structure to use for the following case? > > I have objects like this: > > class Node(object): > def __init__(self, pos, parent, g , h): > self.pos = pos > self.parent = parent > self.g = g > self.h = h > self.f = g+h > > > I need to build a "list" of these objects. The amount is unknown. > On this list I need to regularly > > 1. check if a specific item - identified by Node.pos - is in the list. > 2. find the object with the lowest Node.f attribute and update or remove it > > > What would be a good approach. Using a list I always need to traverse the whole list to do one of the above actions. Is the order of the items in the list significant? If not you might try using a modification of this sorted dict recipe: http://code.activestate.com/recipes/576998-sorted-dictionary/ You would want to use node.pos as the key and node as the value but modify the _sorted_list so that it sorts keys according to Node.f. Strictly speaking the sorted dict above has an O(N) overhead for insertion and removal and O(NlogN) for creation. However these particular big-O's are handled quite efficiently by the sort(), list.insert() and list.remove() functions so it depends how big the list is. If that's not okay then you may want the sorteddict from the blist package on PyPI: http://stutzbachenterprises.com/blist/sorteddict.html That would give you O(logN) insertion/removal. The problem is that the sort key() function only gets to operate on the dict key not the value so you'd have to do something pretty funky to make it work. Perhaps: from blist import sorteddict def my_sorteddict(*args, **kwargs): # There's a good chance this doesn't work... def keyfunc(dictkey): return d[dictkey].f d = sorteddict(keyfunc, *args, **kwargs) return d Oscar From davea at davea.name Tue Jan 21 07:04:31 2014 From: davea at davea.name (Dave Angel) Date: Tue, 21 Jan 2014 07:04:31 -0500 (EST) Subject: use class in class References: <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> Message-ID: Robert Voigtl??nder Wrote in message: > Hi, > > I have a problem using a class object within another class. > It is about the line: > > self.openlist.append(Node(self.start, None, 0, 0)) > > If I use it in __init__ it works. If I use it in calcRoute(self) I get the following error: local variable 'node' referenced before assignment The error occures in AMap.calcRoute() > > Where is my mistake? Chris has addressed your coding error. Within a function/method, you really should use a name for just one purpose, and especially if one of the purposes is global. But you have a different problem as well. You're describing an exception by retyping one of its lines, rather than using copy/paste of the whole thing. The actual error message could not have said "node", as there's no such name in the method. > > > > > def calcRoute(self): > self.openlist.append(Node(self.start, None, 0, 0)) > for Node in self.openlist: print Node.pos, Node.parent, Node.g, Node.h, Node.f > -- DaveA From larry.martell at gmail.com Tue Jan 21 07:22:33 2014 From: larry.martell at gmail.com (Larry Martell) Date: Tue, 21 Jan 2014 05:22:33 -0700 Subject: Early retirement project? In-Reply-To: References: Message-ID: On Tue, Jan 21, 2014 at 1:30 AM, Devin Jeanpierre wrote: > Congrats on the early retirement! It takes guts to decide to do that. :) I thought it took money. From r.voigtlaender at gmail.com Tue Jan 21 08:38:34 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 05:38:34 -0800 (PST) Subject: which data structure to use? In-Reply-To: References: Message-ID: > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl???nder wrote: > > > I have objects like this: > > > > > > class Node(object): > > > def __init__(self, pos, parent, g , h): > > > self.pos = pos > > > self.parent = parent > > > self.g = g > > > self.h = h > > > self.f = g+h > > > > > > > > > I need to build a "list" of these objects. The amount is unknown. > > > On this list I need to regularly > > > > > > 1. check if a specific item - identified by Node.pos - is in the list. > > > 2. find the object with the lowest Node.f attribute and update or remove it > First thanks to all who responded. Although I only partially understand your answers as I am a Python starter. What's clear to me is the difference between object and instance of an object. Just didn't explain it well. Maybe I give some more info on what I need / want to do. I will also provide a working code example. Should have done this before. I would very much appreciate a working example of what you mean. Then I have a chance to understand it. :-) I would like to implement a class for a A* pathfinding algorithm. (there are ready libraries out there but I would like to learn it myself) This requires to maintain a list of nodes to be processed and nodes already processed. For new nodes I need to check if they are on one of the lists. I also need to regularly pick the node with the lowest value f from the list. Here some working code. For one function I sill need a solution. Any better solution is welcome. Thanks Robert --------------- class Node: def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h def isinlist(nodeToSeatch): for item in openlist: if item.pos == nodeToSeatch: return True return False def lowestF(): lowestF = '' for item in openlist: if item.f < lowestF: lowestF = item return lowestF def deleteItemWithPos(pos): ## need this function or different approach pass openlist=[] openlist.append(Node((1,1),None,1,5)) openlist.append(Node((1,2),(1,1),4,6)) openlist.append(Node((1,3),(1,2),9,10)) for item in openlist: print item.pos, item.f print isinlist((1,1)) print isinlist((1,5)) nextNode = lowestF() print nextNode.pos, nextNode.f From r.voigtlaender at gmail.com Tue Jan 21 08:43:31 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 05:43:31 -0800 (PST) Subject: which data structure to use? In-Reply-To: References: Message-ID: <24bc1648-e481-4639-ba7c-46e522b68760@googlegroups.com> Am Dienstag, 21. Januar 2014 14:38:34 UTC+1 schrieb Robert Voigtl?nder: > > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl???nder wrote: > > > > > > > > > I have objects like this: > > > > > > > > > > > > > > class Node(object): > > > > > > > def __init__(self, pos, parent, g , h): > > > > > > > self.pos = pos > > > > > > > self.parent = parent > > > > > > > self.g = g > > > > > > > self.h = h > > > > > > > self.f = g+h > > > > > > > > > > > > > > > > > > > > > I need to build a "list" of these objects. The amount is unknown. > > > > > > > On this list I need to regularly > > > > > > > > > > > > > > 1. check if a specific item - identified by Node.pos - is in the list. > > > > > > > 2. find the object with the lowest Node.f attribute and update or remove it > > > > > > > > > First thanks to all who responded. Although I only partially understand your answers as I am a Python starter. > > What's clear to me is the difference between object and instance of an object. Just didn't explain it well. > > > > Maybe I give some more info on what I need / want to do. I will also provide a working code example. Should have done this before. > > > > I would very much appreciate a working example of what you mean. Then I have a chance to understand it. :-) > > > > I would like to implement a class for a A* pathfinding algorithm. (there are ready libraries out there but I would like to learn it myself) This requires to maintain a list of nodes to be processed and nodes already processed. For new nodes I need to check if they are on one of the lists. I also need to regularly pick the node with the lowest value f from the list. > > > > Here some working code. For one function I sill need a solution. Any better solution is welcome. > > > > Thanks > > Robert Sorry - found a bug right after my post. Here the corrected version. class Node: def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h def isinlist(nodeToSeatch): for item in openlist: if item.pos == nodeToSeatch: return True return False def lowestF(): lowestF = '' for item in openlist: if item.f < lowestF: lowestF = item.f lowestFItem = item return lowestFItem def deleteItemWithPos(pos): ## need this function or different approach pass openlist=[] openlist.append(Node((1,1),None,1,5)) openlist.append(Node((1,2),(1,1),4,6)) openlist.append(Node((1,3),(1,2),9,10)) for item in openlist: print item.pos, item.f print isinlist((1,1)) print isinlist((1,5)) nextNode = lowestF() print nextNode.pos, nextNode.f From karanchawla53 at gmail.com Tue Jan 21 08:46:31 2014 From: karanchawla53 at gmail.com (abc79721) Date: Tue, 21 Jan 2014 05:46:31 -0800 (PST) Subject: Flushing out data from Popen buffer Message-ID: <6cb49455-e377-4150-89ba-7c3d1a9d0c87@googlegroups.com> I am working on a python script that reads data by tailing a file and then puts in a different file. The script works in a time bound manner and eventually flushes out the data from the buffer when the ENDTIME is reached. However there has been a mismatch in the source and target file in terms of size. Following is a snippet: self.read_size = 2048 self.tail_buffer = 2048 # start the file tail cmd = '%s -f -o %s %s' % (self.jtailcmd, offset, self.source_journal) self.logger.debug('[%s] starting FILETail' % self.getName()) try: self.jtail = popen2.Popen3(cmd, bufsize = self.tail_buffer) self.jtail.tochild.close() out = self.jtail.fromchild outfd = self.jtail.fromchild.fileno() flags = fcntl.fcntl(outfd, fcntl.F_GETFL) fcntl.fcntl(outfd, fcntl.F_SETFL, flags | os.O_NONBLOCK) except: message = '[%s] error reading file' % self.getName() self.logger.error(message) self.logger.error('[%s] %s: %s' % \ (self.getName(), sys.exc_info()[0], sys.exc_info()[1])) send_alert('AE', message) self.sleep(60) self.close_tail() self.close_ssh() And then eventually it flushes out the data: try: [i, o, e] = select.select([outfd], [], [], 1) if i: data = out.read(self.read_size) else: data = None except: message = '[%s] error reading file' % self.getName() self.logger.error(message) self.logger.error('[%s] %s: %s' % \ (self.getName(), sys.exc_info()[0], sys.exc_info()[1])) send_alert('AE', message) self.close_tail() self.close_ssh() self.sleep(60) break if data: if self.sshcat.poll() != -1: self.logger.error('[%s] connection error' % self.getName()) self.close_tail() self.close_ssh() break try: self.sshcat.tochild.writelines(data) self.sshcat.tochild.flush() except: message = '[%s] error writing remote file' % self.getName() While troubleshooting, I narrowed out the problem to tail_buffer size! By reducing the tail_buffer size , the script worked fine. I cant use subprocess(Python Version is 2.4.3) I do not want to rely on tail_buffer size. Ideally the script should be independent of it! Is there a way to flush data from the POPEN buffer ? From dan at tombstonezero.net Tue Jan 21 08:49:46 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Tue, 21 Jan 2014 13:49:46 +0000 (UTC) Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <52ddc3ad$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Tue, 21 Jan 2014 10:32:13 +0000, Oscar Benjamin wrote: > ... When you set assignments the students will usually learn more if > they work in groups. However at some point you need to try and assess > how much they've individually learned. I find in practice that it's > easy to tell when a student has copied someone else without really > understanding what they're doing though. Of course if they just pay > someone else to do it for them then there's not much you can do... I had a programming teacher in high school who encouraged us to work however we wanted, individually or in groups. There were two conditions: (1) each student had to turn in a complete assignment, and (2) he reserved the right to question anyone about anything they turned in. He observed us working in class enough to know whom to question. I know that a couple of students were busted early on; I don't know how it all turned out in the end. Dan From oscar.j.benjamin at gmail.com Tue Jan 21 08:59:06 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Tue, 21 Jan 2014 13:59:06 +0000 Subject: which data structure to use? In-Reply-To: References: Message-ID: <20140121135903.GG2632@gmail.com> On Tue, Jan 21, 2014 at 05:38:34AM -0800, Robert Voigtl?nder wrote: > > > On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl???nder wrote: > > > > > > I have objects like this: > > > > > > > > > > class Node(object): > > > > > def __init__(self, pos, parent, g , h): > > > > > self.pos = pos > > > > > self.parent = parent > > > > > self.g = g > > > > > self.h = h > > > > > self.f = g+h > > > > > > > > > > > > > > > I need to build a "list" of these objects. The amount is unknown. > > > > > On this list I need to regularly > > > > > > > > > > 1. check if a specific item - identified by Node.pos - is in the list. > > > > > 2. find the object with the lowest Node.f attribute and update or remove it > > > > > First thanks to all who responded. Although I only partially understand your answers as I am a Python starter. > What's clear to me is the difference between object and instance of an object. Just didn't explain it well. > > Maybe I give some more info on what I need / want to do. I will also provide a working code example. Should have done this before. > > I would very much appreciate a working example of what you mean. Then I have a chance to understand it. :-) > > I would like to implement a class for a A* pathfinding algorithm. (there are ready libraries out there but I would like to learn it myself) This requires to maintain a list of nodes to be processed and nodes already processed. For new nodes I need to check if they are on one of the lists. I also need to regularly pick the node with the lowest value f from the list. > > Here some working code. For one function I sill need a solution. Any better solution is welcome. > > Thanks > Robert > > --------------- > class Node: > def __init__(self, pos, parent, g , h): > self.pos = pos > self.parent = parent > self.g = g > self.h = h > self.f = g+h > > > def isinlist(nodeToSeatch): > for item in openlist: > if item.pos == nodeToSeatch: return True > return False > > > def lowestF(): > lowestF = '' > for item in openlist: > if item.f < lowestF: lowestF = item > return lowestF The function above is incorrect. I think it should be: def lowestF(): lowestF = '' for item in openlist: if item.f < lowestF: lowestF = item.f # Note the .f here return lowestF > > def deleteItemWithPos(pos): > ## need this function or different approach > pass def deleteItemWithPos(pos): for n, item in enumerate(openlist): if item.pos == pos: del openlist[n] return else: raise RuntimeError('Not in the list!') > > openlist=[] > openlist.append(Node((1,1),None,1,5)) > openlist.append(Node((1,2),(1,1),4,6)) > openlist.append(Node((1,3),(1,2),9,10)) > > for item in openlist: print item.pos, item.f > > print isinlist((1,1)) > print isinlist((1,5)) > > nextNode = lowestF() > print nextNode.pos, nextNode.f My first suggestion would be to use a dict instead of a list: class Node: def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h def isinlist(pos): return pos in opendict def lowestF(): return min(opendict.values(), key=lambda x: x.f) def deleteItemWithPos(pos): del opendict[pos] nodes = [ Node((1,1),None,1,5), Node((1,2),(1,1),4,6), Node((1,3),(1,2),9,10), ] opendict = {} for node in nodes: opendict[node.pos] = node for item in opendict.values(): print item.pos, item.f print isinlist((1,1)) print isinlist((1,5)) nextNode = lowestF() print nextNode.pos, nextNode.f The above is more efficient and simpler. It is still O(N) for the lowestF() function. Changing data structure could make that more efficient. Oscar From __peter__ at web.de Tue Jan 21 09:09:31 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Jan 2014 15:09:31 +0100 Subject: which data structure to use? References: Message-ID: Robert Voigtl?nder wrote: > >> On Tue, Jan 21, 2014 at 03:17:43AM -0800, Robert Voigtl???nder wrote: >> > >> > I have objects like this: >> >> > >> >> > class Node(object): >> >> > def __init__(self, pos, parent, g , h): >> >> > self.pos = pos >> >> > self.parent = parent >> >> > self.g = g >> >> > self.h = h >> >> > self.f = g+h >> >> > >> >> > >> >> > I need to build a "list" of these objects. The amount is unknown. >> >> > On this list I need to regularly >> >> > >> >> > 1. check if a specific item - identified by Node.pos - is in the list. >> >> > 2. find the object with the lowest Node.f attribute and update or >> > remove it >> > > > First thanks to all who responded. Although I only partially understand > your answers as I am a Python starter. What's clear to me is the > difference between object and instance of an object. Just didn't explain > it well. > > Maybe I give some more info on what I need / want to do. I will also > provide a working code example. Should have done this before. > > I would very much appreciate a working example of what you mean. Then I > have a chance to understand it. :-) > > I would like to implement a class for a A* pathfinding algorithm. (there > are ready libraries out there but I would like to learn it myself) This > requires to maintain a list of nodes to be processed and nodes already > processed. For new nodes I need to check if they are on one of the lists. > I also need to regularly pick the node with the lowest value f from the > list. > > Here some working code. For one function I sill need a solution. Any > better solution is welcome. > > Thanks > Robert > > --------------- > class Node: > def __init__(self, pos, parent, g , h): > self.pos = pos > self.parent = parent > self.g = g > self.h = h > self.f = g+h > > > def isinlist(nodeToSeatch): > for item in openlist: > if item.pos == nodeToSeatch: return True > return False > > > def lowestF(): > lowestF = '' > for item in openlist: > if item.f < lowestF: lowestF = item > return lowestF def lowestF(): return min(openlist, key=operator.attrgetter("f")) > def deleteItemWithPos(pos): > ## need this function or different approach > pass > > openlist=[] > openlist.append(Node((1,1),None,1,5)) > openlist.append(Node((1,2),(1,1),4,6)) > openlist.append(Node((1,3),(1,2),9,10)) > > for item in openlist: print item.pos, item.f > > print isinlist((1,1)) > print isinlist((1,5)) > > nextNode = lowestF() > print nextNode.pos, nextNode.f Here is an OO implementation of Chris Angelico's suggestion: import heapq class Node: def __init__(self, pos, parent, g , h): self.pos = pos self.parent = parent self.g = g self.h = h self.f = g+h def __str__(self): return "Node(pos={!r}, f={!r})".format(self.pos, self.f) class Nodes(): def __init__(self): self.lookup = {} self.heap = [] def add(self, node): self.lookup[node.pos] = node heapq.heappush(self.heap, (node.f, node)) def __iter__(self): return iter(self.lookup.values()) def __contains__(self, pos): return pos in self.lookup def lowest(self): return self.heap[0][1] def pop(self): f, node = heapq.heappop() del lookup[node.pos] return node nodes = Nodes() nodes.add(Node((1,1), None, 1, 5)) nodes.add(Node((1,2), (1,1), 4, 6)) nodes.add(Node((1,3), (1,2), 9, 10)) for node in nodes: print(node) print((1,1) in nodes) print((1,5) in nodes) print(nodes.lowest()) From __peter__ at web.de Tue Jan 21 09:19:54 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Jan 2014 15:19:54 +0100 Subject: which data structure to use? References: Message-ID: Peter Otten wrote: > def pop(self): > f, node = heapq.heappop() > del lookup[node.pos] > return node That should be def pop(self): f, node = heapq.heappop(self.heap) del self.lookup[node.pos] return node From kevinbercaw at gmail.com Tue Jan 21 09:44:13 2014 From: kevinbercaw at gmail.com (kevinbercaw at gmail.com) Date: Tue, 21 Jan 2014 06:44:13 -0800 (PST) Subject: import file without .py into another module Message-ID: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> I have a python script that accepts two arguments: sys.argv[1] is the full directory path to a config script. The script is python but does not have a .py extension! sys.argv[2] is the file name of the config script For example: mainScript.py ./ a15800 The config script sets variables that I want to be able to use in the main script. *** contents of "a15800": *** myVar = "hello" *** contents of "mainScript.py": *** def printVars(configModuleName): myVarName = ("%s.myVar" % configModuleName) print "myVarName = %s" % myVarName myVarValue = eval(myVarName) print "myVarValue = %s" % myVarValue if __name__ == '__main__': import sys import imp filePath = sys.argv[1] fileName = sys.argv[2] configModuleObject = imp.load_source(fileName, filePath) configModuleName = configModuleObject.__name__ print "configModuleName = %s" % configModuleName printVars(configModuleName) *** Output: *** >mainScript.py ./ a15800 configModuleName = a15800 myVarName = a15800.myVar Traceback (most recent call last): File "mainScript.py", line 27, in printVars(configModuleName) File "mainScript.py", line 15, in printVars myVarValue = eval(myVarName) File "", line 1, in NameError: name 'a15800' is not defined *** Question: *** How do I get the value of the config file variable "myVar"?? It seems it's interpreting the variable name as a string rather than a variable name. I don't see any python function stringToVariable. From python at mrabarnett.plus.com Tue Jan 21 10:06:16 2014 From: python at mrabarnett.plus.com (MRAB) Date: Tue, 21 Jan 2014 15:06:16 +0000 Subject: import file without .py into another module In-Reply-To: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> Message-ID: <52DE8CE8.9010608@mrabarnett.plus.com> On 2014-01-21 14:44, kevinbercaw at gmail.com wrote: > I have a python script that accepts two arguments: > sys.argv[1] is the full directory path to a config script. The script is python but does not have a .py extension! > sys.argv[2] is the file name of the config script > > For example: > mainScript.py ./ a15800 > > > The config script sets variables that I want to be able to use in the main script. > > *** contents of "a15800": *** > myVar = "hello" > > *** contents of "mainScript.py": *** > def printVars(configModuleName): > myVarName = ("%s.myVar" % configModuleName) > print "myVarName = %s" % myVarName > myVarValue = eval(myVarName) > print "myVarValue = %s" % myVarValue > > > if __name__ == '__main__': > import sys > import imp > filePath = sys.argv[1] > fileName = sys.argv[2] > configModuleObject = imp.load_source(fileName, filePath) > configModuleName = configModuleObject.__name__ > print "configModuleName = %s" % configModuleName > printVars(configModuleName) > > *** Output: *** >>mainScript.py ./ a15800 > configModuleName = a15800 > myVarName = a15800.myVar > Traceback (most recent call last): > File "mainScript.py", line 27, in > printVars(configModuleName) > File "mainScript.py", line 15, in printVars > myVarValue = eval(myVarName) > File "", line 1, in > NameError: name 'a15800' is not defined > > *** Question: *** > How do I get the value of the config file variable "myVar"?? It seems it's interpreting the variable name as a string rather than a variable name. I don't see any python function stringToVariable. > The line: configModuleObject = imp.load_source(fileName, filePath) imports the module and then binds it to the name configModuleObject, therefore: print configModuleObject.myVar From kevinbercaw at gmail.com Tue Jan 21 10:13:59 2014 From: kevinbercaw at gmail.com (kevinbercaw at gmail.com) Date: Tue, 21 Jan 2014 07:13:59 -0800 (PST) Subject: import file without .py into another module In-Reply-To: References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> Message-ID: <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> On Tuesday, January 21, 2014 10:06:16 AM UTC-5, MRAB wrote: > On 2014-01-21 14:44, wrote: > > > I have a python script that accepts two arguments: > > > sys.argv[1] is the full directory path to a config script. The script is python but does not have a .py extension! > > > sys.argv[2] is the file name of the config script > > > > > > For example: > > > mainScript.py ./ a15800 > > > > > > > > > The config script sets variables that I want to be able to use in the main script. > > > > > > *** contents of "a15800": *** > > > myVar = "hello" > > > > > > *** contents of "mainScript.py": *** > > > def printVars(configModuleName): > > > myVarName = ("%s.myVar" % configModuleName) > > > print "myVarName = %s" % myVarName > > > myVarValue = eval(myVarName) > > > print "myVarValue = %s" % myVarValue > > > > > > > > > if __name__ == '__main__': > > > import sys > > > import imp > > > filePath = sys.argv[1] > > > fileName = sys.argv[2] > > > configModuleObject = imp.load_source(fileName, filePath) > > > configModuleName = configModuleObject.__name__ > > > print "configModuleName = %s" % configModuleName > > > printVars(configModuleName) > > > > > > *** Output: *** > > >>mainScript.py ./ a15800 > > > configModuleName = a15800 > > > myVarName = a15800.myVar > > > Traceback (most recent call last): > > > File "mainScript.py", line 27, in > > > printVars(configModuleName) > > > File "mainScript.py", line 15, in printVars > > > myVarValue = eval(myVarName) > > > File "", line 1, in > > > NameError: name 'a15800' is not defined > > > > > > *** Question: *** > > > How do I get the value of the config file variable "myVar"?? It seems it's interpreting the variable name as a string rather than a variable name. I don't see any python function stringToVariable. > > > > > The line: > > > > configModuleObject = imp.load_source(fileName, filePath) > > > > imports the module and then binds it to the name configModuleObject, > > therefore: > > > > print configModuleObject.myVar Yep, I tried that right off as that's how I thought it would work, but it doesn't work. Traceback (most recent call last): File "mainScript.py", line 31, in print configModuleObject.myVar AttributeError: 'module' object has no attribute 'myVar' From r.voigtlaender at gmail.com Tue Jan 21 10:24:53 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 07:24:53 -0800 (PST) Subject: use class in class In-Reply-To: References: <8abb6a72-c258-4f08-a391-867d2680591d@googlegroups.com> Message-ID: <5af3e509-6d01-4b77-b832-0ebea77cddf9@googlegroups.com> > > copy/paste of the whole thing. The actual error message could not > > have said "node", as there's no such name in the method. > You are correct. I copied the error before I renamed node into Node. I have to be more consistent here. :-) The source for the error was still the same. From invalid at invalid.invalid Tue Jan 21 10:25:57 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Tue, 21 Jan 2014 15:25:57 +0000 (UTC) Subject: Early retirement project? References: Message-ID: On 2014-01-21, Larry Martell wrote: > On Tue, Jan 21, 2014 at 1:30 AM, Devin Jeanpierre > wrote: >> Congrats on the early retirement! It takes guts to decide to do that. :) > > I thought it took money. One or the other. If you've got money, it doesn't take guts. -- Grant Edwards grant.b.edwards Yow! I feel better about at world problems now! gmail.com From kevinbercaw at gmail.com Tue Jan 21 10:27:50 2014 From: kevinbercaw at gmail.com (kevinbercaw at gmail.com) Date: Tue, 21 Jan 2014 07:27:50 -0800 (PST) Subject: import file without .py into another module In-Reply-To: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> Message-ID: <4ba01a96-493f-4e1c-9cb7-0d46cd7ef103@googlegroups.com> On Tuesday, January 21, 2014 9:44:13 AM UTC-5, kevin... at gmail.com wrote: > I have a python script that accepts two arguments: > > sys.argv[1] is the full directory path to a config script. The script is python but does not have a .py extension! > > sys.argv[2] is the file name of the config script > > > > For example: > > mainScript.py ./ a15800 > > > > > > The config script sets variables that I want to be able to use in the main script. > > > > *** contents of "a15800": *** > > myVar = "hello" > > > > *** contents of "mainScript.py": *** > > def printVars(configModuleName): > > myVarName = ("%s.myVar" % configModuleName) > > print "myVarName = %s" % myVarName > > myVarValue = eval(myVarName) > > print "myVarValue = %s" % myVarValue > > > > > > if __name__ == '__main__': > > import sys > > import imp > > filePath = sys.argv[1] > > fileName = sys.argv[2] > > configModuleObject = imp.load_source(fileName, filePath) > > configModuleName = configModuleObject.__name__ > > print "configModuleName = %s" % configModuleName > > printVars(configModuleName) > > > > *** Output: *** > > >mainScript.py ./ a15800 > > configModuleName = a15800 > > myVarName = a15800.myVar > > Traceback (most recent call last): > > File "mainScript.py", line 27, in > > printVars(configModuleName) > > File "mainScript.py", line 15, in printVars > > myVarValue = eval(myVarName) > > File "", line 1, in > > NameError: name 'a15800' is not defined > > > > *** Question: *** > > How do I get the value of the config file variable "myVar"?? It seems it's interpreting the variable name as a string rather than a variable name. I don't see any python function stringToVariable. FYI - more info from interactive session, query configModuleObject and configModuleName using imp.find_module: >>> imp.find_module("configModuleObject") Traceback (most recent call last): File "", line 1, in ImportError: No module named configModuleObject >>> imp.find_module("a15800") (, 'a15800.pyc', ('.pyc', 'rb', 2)) >>> imp.find_module(configModuleName) (, 'a15800.pyc', ('.pyc', 'rb', 2)) From r.voigtlaender at gmail.com Tue Jan 21 10:33:20 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 07:33:20 -0800 (PST) Subject: which data structure to use? In-Reply-To: References: Message-ID: Am Dienstag, 21. Januar 2014 15:19:54 UTC+1 schrieb Peter Otten: > Peter Otten wrote: > > > > > def pop(self): > > > f, node = heapq.heappop() > > > del lookup[node.pos] > > > return node > > > > That should be > > > > def pop(self): > > f, node = heapq.heappop(self.heap) > > del self.lookup[node.pos] > > return node Hi Peter, this works great. I will try to find some info about the functionality you used and to understnad what you did. Maybe you can add a function to remove a node? Thanks for your support and all tthe swift answers. Robert From python.list at tim.thechases.com Tue Jan 21 10:36:20 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 21 Jan 2014 09:36:20 -0600 Subject: import file without .py into another module In-Reply-To: <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> Message-ID: <20140121093620.689d33fd@bigbox.christie.dr> On 2014-01-21 07:13, kevinbercaw at gmail.com wrote: >On Tuesday, January 21, 2014 10:06:16 AM UTC-5, MRAB wrote: >> configModuleObject = imp.load_source(fileName, filePath) >> >> imports the module and then binds it to the name >> configModuleObject, >> >> therefore: >> >> print configModuleObject.myVar > > Yep, I tried that right off as that's how I thought it would work, > but it doesn't work. Traceback (most recent call last): > File "mainScript.py", line 31, in > print configModuleObject.myVar > AttributeError: 'module' object has no attribute 'myVar' Check what you're passing for fileName/FilePath: >>> import imp >>> with open('demo.txt', 'wb') as f: ... f.write('x = 42\ny = "hello"\n') ... >>> d = imp.load_source('SomeName', 'demo.txt') >>> dir(d) ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'x', 'y'] >>> d.x 42 >>> d.y 'hello' >>> d.__name__ 'SomeName' -tkc From __peter__ at web.de Tue Jan 21 10:40:09 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Jan 2014 16:40:09 +0100 Subject: import file without .py into another module References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> Message-ID: kevinbercaw at gmail.com wrote: >> > How do I get the value of the config file variable "myVar"?? It seems >> > it's interpreting the variable name as a string rather than a variable >> > name. I don't see any python function stringToVariable. >> The line: >> >> configModuleObject = imp.load_source(fileName, filePath) >> imports the module and then binds it to the name configModuleObject, >> >> therefore: >> >> print configModuleObject.myVar > > Yep, I tried that right off as that's how I thought it would work, but it > doesn't work. Traceback (most recent call last): > File "mainScript.py", line 31, in > print configModuleObject.myVar > AttributeError: 'module' object has no attribute 'myVar' Try again with module = imp.load_source("made_up_name", "a15800") print module.myVar If the file "a15800" is not in the current working directory, give the complete path, e. g: module = imp.load_source("made_up_name", "/path/to/a15800") print module.myVar The first arg serves as the module's name which is used for caching to speed up repeated imports: >>> import imp >>> import sys >>> "made_up_name" in sys.modules False >>> module = imp.load_source("made_up_name", "a15800") >>> module.myVar 'hello' >>> "made_up_name" in sys.modules True >>> module From r.voigtlaender at gmail.com Tue Jan 21 10:37:47 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Tue, 21 Jan 2014 07:37:47 -0800 (PST) Subject: which data structure to use? In-Reply-To: References: Message-ID: > > > def pop(self): > > > f, node = heapq.heappop() > > > del lookup[node.pos] > > > return node > > That should be > > > def pop(self): > > > f, node = heapq.heappop(self.heap) > > del self.lookup[node.pos] > > return node > > Hi Peter, > this works great. I will try to find some info about the functionality you used and to understnad what you did. > Maybe you can add a function to remove a node? > Thanks for your support and all tthe swift answers. > > Robert Just realized what the pop function is for. I changed it from: def pop(self): to def pop(self,pos): and it works. Now I go on with trying to understand it. From josiah.carlson at gmail.com Tue Jan 21 10:44:00 2014 From: josiah.carlson at gmail.com (Josiah Carlson) Date: Tue, 21 Jan 2014 07:44:00 -0800 Subject: ANN: rom 0.25.0 - Redis object mapper for Python Message-ID: Hey everyone, Big change today: rom now supports fast prefix, suffix, and pattern match queries over your data. The method is based on the autocomplete process described in my book, Redis in Action The "rom" package is a Redis object mapper for Python. It sports an interface similar to Django's ORM, SQLAlchemy + Elixir, or Appengine's datastore. The changelog for recent releases can be seen below my signature. You can find the package at: https://www.github.com/josiahcarlson/rom https://pypi.python.org/pypi/rom And docs can be found at: http://pythonhosted.org/rom/ Please CC me on any replies if you have any questions or comments. Thank you, - Josiah #---------------------------------- 0.25.0 ----------------------------------- [changed] version numbers to account for bugfixes vs. feature updates. [added] columns can now be defined to allow for prefix and/or suffix queries. Enabling prefix queries also enables arbitrary pattern matching over your data. [fixed] in some cases, rom would allow the definition of multiple primary keys, of which only one would ever be used (inconsistently). This will now result in an error. [changed] defaulted to assume Lua is available on Redis, which has been released for over 15 months at this point. You can disable support via a call to rom._disable_lua_writes(). [added] the ability to cache and get the key that holds the result of a query, which can be used for pagination, etc. See: Query.cached_result() [warning] using rom versions of 0.23 with 0.25.0 when prefix and suffix indexes are enabled can result in improper results from prefix, suffix, and/or pattern queries, and can result in orphan data living in prefix or suffix indexes. Upgrade all of your clients! [changed] temporary keys for queries are now prefixed with the name of the model over which queries are being executed on. This should effect basically zero people, but can allow for query cleanup in the off chance of a failure during execution. #----------------------------- 0.23 (unreleased) ----------------------------- [changed] reduced number of round trips for single-filter queries by 1, thanks to https://github.com/MickeyKim for the report. #----------------------------------- 0.22 ------------------------------------ [fixed] size estimation for intersection ordering when filtering has now been fixed, thank you to https://github.com/MickeyKim for the report and the change (should improve performance). [fixed] an issue with some types when trying to update attributes has now been fixed, thank you to https://github.com/denisvolokh for the report. [changed] improved performance for simple numeric range queries of the form Model.get_by(attr=value) or Model.get_by(attr=(min, max)) by roughly a factor of 60x or better in some cases. Thank you to https://github.com/MickeyKim for the report on poor performance. #----------------------------------- 0.21 ------------------------------------ [fixed] upload for rom 0.20 was missing new columns.py, now fixed -------------- next part -------------- An HTML attachment was scrubbed... URL: From kevinbercaw at gmail.com Tue Jan 21 10:50:40 2014 From: kevinbercaw at gmail.com (kevinbercaw at gmail.com) Date: Tue, 21 Jan 2014 07:50:40 -0800 (PST) Subject: import file without .py into another module In-Reply-To: References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> Message-ID: On Tuesday, January 21, 2014 10:40:09 AM UTC-5, Peter Otten wrote: > kevin... at gmail.com wrote: > > > > >> > How do I get the value of the config file variable "myVar"?? It seems > > >> > it's interpreting the variable name as a string rather than a variable > > >> > name. I don't see any python function stringToVariable. > > > > >> The line: > > >> > > >> configModuleObject = imp.load_source(fileName, filePath) > > > > >> imports the module and then binds it to the name configModuleObject, > > >> > > >> therefore: > > >> > > >> print configModuleObject.myVar > > > > > > Yep, I tried that right off as that's how I thought it would work, but it > > > doesn't work. Traceback (most recent call last): > > > File "mainScript.py", line 31, in > > > print configModuleObject.myVar > > > AttributeError: 'module' object has no attribute 'myVar' > > > > Try again with > > > > module = imp.load_source("made_up_name", "a15800") > > print module.myVar > > > > If the file "a15800" is not in the current working directory, give the > > complete path, e. g: > > > > module = imp.load_source("made_up_name", "/path/to/a15800") > > print module.myVar > > > > The first arg serves as the module's name which is used for caching to speed > > up repeated imports: > > > > >>> import imp > > >>> import sys > > >>> "made_up_name" in sys.modules > > False > > >>> module = imp.load_source("made_up_name", "a15800") > > >>> module.myVar > > 'hello' > > >>> "made_up_name" in sys.modules > > True > > >>> module > > Thanks Peter Otten, that worked. I was not able to understand the documentation for imp.load_source correctly. Thanks so much! From rustompmody at gmail.com Tue Jan 21 11:00:29 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jan 2014 08:00:29 -0800 (PST) Subject: Diving in to Python - Best resources? In-Reply-To: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: On Tuesday, January 21, 2014 1:04:16 AM UTC+5:30, Matt Watson wrote: > Getting in the habit of dropping in a google group for any new project - > everyone tends to be so helpful. > I work in the automotive sales industry(management) and find myself > doing so many day to day tasks that could easily be automated. I'm a > very tech saavy person, but after running in fear from a Javascript > class in undergrad 8 years ago I haven't ever looked back. I simply > had no interest because I saw no applications. > Now that I have a solid career I see SO many applications for > programming in my industry alone. Automating data > movement/calculations from websites, spreadsheets, pricing, etc will > be my primary use.I'm OK saying I didn't retain 1% of what I > learned in the Javascript class, I've dabbled in HTML, I've tweaked > code in Excel macros or AutoIt scripts, but I'd classify myself as a > complete beginner in programming. It looks like 1. You are familiar with spreadsheets 2. Your work is spreadsheet-like Why not develop that into a bigger strength? Most people -- even those using spreadsheets -- dont seem to think of the spreadsheet macro language/VBA as a programming language but it is and it may well be all you need. This is written by one of the biggest names in programming languages today http://research.microsoft.com/en-us/um/people/simonpj/Papers/excel/excel.pdf From tjreedy at udel.edu Tue Jan 21 12:34:44 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Jan 2014 12:34:44 -0500 Subject: Early retirement project? In-Reply-To: <20140121053801.60f8cf11@bigbox.christie.dr> References: <20140121053801.60f8cf11@bigbox.christie.dr> Message-ID: On 1/21/2014 6:38 AM, Tim Chase wrote: > On 2014-01-21 00:00, xeysxeys at gmail.com wrote: >> Well, I retired early, and I guess now I've got some spare time to >> learn about programming, which always seemed rather mysterious. I >> am using an old mac as my main computer, and it runs os x 10.4 is >> this too old? It fills my needs, and I am on a fixed income and >> can't really afford to buy another. I think python would be a good >> starter language, based on what I've read on the net. > > It's certainly a great way to consume lots of hours :) > > Mac OS X 10.4 should come with an older version of Python > out-of-the-box. Someone else said that it comes with 2.5. That will be fine for many purposed. If you do use that, always make any classes you define a subclass of 'object' if nothing else. In other words, class MyClass(object): ... # instead of class MyClass: ... In Python 2, the second gives you an 'old-style' or 'classic' class. You do not need to learn about those. In Python 3, both forms give you new-style classes, which is what you should learn. There are a few other obsolete features to avoid, such as using strings for exceptions. > The install media should also include XCode if you > want to download the latest & greatest version of Python and install > that from source instead. If you can do that easily, I recommend starting with the latest Python 3, especially if you want to work with non-English (non-ascii) characters. -- Terry Jan Reedy From emile at fenx.com Tue Jan 21 12:52:19 2014 From: emile at fenx.com (emile) Date: Tue, 21 Jan 2014 09:52:19 -0800 Subject: Add followers at time of import Message-ID: Hi Ethan, How hard would it be to add a follower to a transaction (PO or Sales Order) at time of import if the account has that follower? IOW, Ron follows 'hilltop ranch' -- he'd like all activity linked to 'hilltop ranch' to include him as a follower. Right now, following the account doesn't notify about changes to documents, only changes to the account itself. Ask if that's not clear. Emile From mheieis at alois.ca Tue Jan 21 12:55:13 2014 From: mheieis at alois.ca (Mark Heieis) Date: Tue, 21 Jan 2014 09:55:13 -0800 Subject: autoconf tools and python3 3m 3dm Message-ID: <52DEB481.4040509@alois.ca> Hi, I've been migrating a python2 package+extension to python3. The problem I'm running into is with ./configure and which version it picks up or doesn't in this case. The default is python2 and works just fine as expected. However, when ./configure PYTHON=python3 is run, the problems occur. "./configure" picks python3 correctly and propagates that through to all of the makefiles created. Good so far. It defines all of the appropriate libs and include with the '3.3' extension. The yum installed python3, however, is denoted by a suffix 'dm', yielding an extension of '3.3dm' (Fedora 20) Building and installing from source, python has a suffix 'm', so the extension is '3.3m; In ./configure, PYTHON_VERSION is set by "$PYTHON -c 'import sys; print(sys.version[:3])'" which reports "3.3". PYTHON_VERSION is then used as the suffix to find all of the appropriate python directories, libraries, site-packages and includes. The same result is had if python3.3m or python3.3dm is used. Unfortunately, this isn't enough, as the python site packages are installed with naming ending in 'm' or 'dm', resulting in all of the makefiles failing because they can't find the libraries, include files, or site packages. I've kludged a solution by manually creating soft links in the lib and include directories which almost solves the problem: for example in /usr/lib64: lrwxrwxrwx. 1 root root 19 2013-12-18 15:02 libpython2.7.so -> libpython2.7.so.1.0 -r-xr-xr-x. 1 root root 1800480 2013-11-12 08:47 libpython2.7.so.1.0 lrwxrwxrwx 1 root root 21 2014-01-20 16:11 libpython3.3dm.so -> libpython3.3dm.so.1.0 -rwxr-xr-x 1 root root 3057640 2013-11-07 02:03 libpython3.3dm.so.1.0 lrwxrwxrwx 1 root root 20 2014-01-20 16:11 libpython3.3m.so -> libpython3.3m.so.1.0 -rwxr-xr-x 1 root root 2498992 2013-11-07 02:03 libpython3.3m.so.1.0 lrwxrwxrwx 1 root root 20 2014-01-20 16:37 libpython3.3.so -> libpython3.3m.so.1.0 -rwxr-xr-x 1 root root 6704 2013-11-07 02:03 libpython3.so This approach doesn't feel right to me. I don't think pythonX.Y-config would work either as one would need to know in advance specifically which one to call and there'd be extra work to extract the full version info, etc. ("$python3-config --includes" yields -I/usr/include/python3.3m -I/usr/include/python3.3m) Has anyone else come up against this? If so, what was the solution? BTW - anyone know what the 'm' and 'dm' suffixes indicate? TIA. From tjreedy at udel.edu Tue Jan 21 12:57:18 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Jan 2014 12:57:18 -0500 Subject: Diving in to Python - Best resources? In-Reply-To: References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: On 1/21/2014 11:00 AM, Rustom Mody wrote: > On Tuesday, January 21, 2014 1:04:16 AM UTC+5:30, Matt Watson wrote: >> Getting in the habit of dropping in a google group for any new project - >> everyone tends to be so helpful. > >> I work in the automotive sales industry(management) and find myself >> doing so many day to day tasks that could easily be automated. I'm a >> very tech saavy person, but after running in fear from a Javascript >> class in undergrad 8 years ago I haven't ever looked back. I simply >> had no interest because I saw no applications. > >> Now that I have a solid career I see SO many applications for >> programming in my industry alone. Automating data >> movement/calculations from websites, spreadsheets, pricing, etc will >> be my primary use.I'm OK saying I didn't retain 1% of what I >> learned in the Javascript class, I've dabbled in HTML, I've tweaked >> code in Excel macros or AutoIt scripts, but I'd classify myself as a >> complete beginner in programming. > > It looks like > 1. You are familiar with spreadsheets > 2. Your work is spreadsheet-like > > Why not develop that into a bigger strength? > > Most people -- even those using spreadsheets -- dont seem to think of > the spreadsheet macro language/VBA as a programming language but it > is Definitely. I once worked out how to do nonlinear regression with a spreadsheet, after doing it with Basic (and later C). > and it may well be all you need. This is written by one of the > biggest names in programming languages today > > http://research.microsoft.com/en-us/um/people/simonpj/Papers/excel/excel.pdf -- Terry Jan Reedy From ztepman at gmail.com Tue Jan 21 13:02:42 2014 From: ztepman at gmail.com (Ziv Tepman) Date: Tue, 21 Jan 2014 10:02:42 -0800 Subject: =?windows-1252?Q?Running_pywin32=2D218=2Ewin32=2Dpy2=2E7=2Eexe_=28win32_package_f?= =?windows-1252?Q?or_Python=29_results_in_error_=93The_file_exists=94?= Message-ID: I am trying to install the Python module "win32" but whenever I click on the exe file (pywin32-218.win32-py2.7.exe) I get the message "The file exists Could not create temporary file", and when I click OK, I get the message, "pywin32-218.win32-py2.7." I have chosen the appropriate build. How might I fix this error? Thanks! -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Jan 21 13:03:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 05:03:01 +1100 Subject: Add followers at time of import In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 4:52 AM, emile wrote: > Hi Ethan, > > How hard would it be to add a follower to a transaction (PO or Sales Order) > at time of import if the account has that follower? IOW, Ron follows > 'hilltop ranch' -- he'd like all activity linked to 'hilltop ranch' to > include him as a follower. Right now, following the account doesn't notify > about changes to documents, only changes to the account itself. > > Ask if that's not clear. I'm not entirely sure, but I think this might have been meant for somewhere other than python-list. Welcome to the club. ChrisA From breamoreboy at yahoo.co.uk Tue Jan 21 13:03:18 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 21 Jan 2014 18:03:18 +0000 Subject: which data structure to use? In-Reply-To: <24bc1648-e481-4639-ba7c-46e522b68760@googlegroups.com> References: <24bc1648-e481-4639-ba7c-46e522b68760@googlegroups.com> Message-ID: On 21/01/2014 13:43, Robert Voigtl?nder wrote: [double spaced google disease snipped] I'm pleased to see the regular contributors helping out as usual. In response would you please be kind enough to read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing that google inserts, thanks. -- 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 Tue Jan 21 13:10:22 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 21 Jan 2014 18:10:22 +0000 Subject: import file without .py into another module In-Reply-To: References: <6c68b312-4979-454f-b483-b4a39c64196b@googlegroups.com> <022c00a5-87ee-4b2a-a6f6-e23c8bda1e12@googlegroups.com> Message-ID: On 21/01/2014 15:50, kevinbercaw at gmail.com wrote: [snipped the double line spaced stuff courtesy of google] Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing that google inserts, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ethan at stoneleaf.us Tue Jan 21 13:30:12 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 21 Jan 2014 10:30:12 -0800 Subject: Add followers at time of import In-Reply-To: References: Message-ID: <52DEBCB4.9030503@stoneleaf.us> On 01/21/2014 10:03 AM, Chris Angelico wrote: > On Wed, Jan 22, 2014 at 4:52 AM, emile wrote: >> >> Ask if that's not clear. > > I'm not entirely sure, but I think this might have been meant for > somewhere other than python-list. Welcome to the club. And it's an elite club, too! Very few members. ;) -- ~Ethan~ From __peter__ at web.de Tue Jan 21 13:39:33 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 21 Jan 2014 19:39:33 +0100 Subject: which data structure to use? References: Message-ID: Robert Voigtl?nder wrote: > >> > > def pop(self): >> > > f, node = heapq.heappop() >> > > del lookup[node.pos] >> > > return node > >> > That should be >> >> > def pop(self): >> >> > f, node = heapq.heappop(self.heap) >> > del self.lookup[node.pos] >> > return node >> >> Hi Peter, >> this works great. I will try to find some info about the functionality >> you used and to understnad what you did. Maybe you can add a function to >> remove a node? Thanks for your support and all tthe swift answers. >> >> Robert > > Just realized what the pop function is for. I changed it from: > def pop(self): > to > def pop(self,pos): > > and it works. Unlikely. Are you sure that .heap and .lookup contents are still in sync with your modification? > Now I go on with trying to understand it. The pop() method as posted can only remove the "lowest" node. If contrary to your initial spec > 2. find the object with the lowest Node.f attribute and update or remove it you want to remove arbitrary nodes a heap may not be the appropriate data structure. The modified import operator #... class Nodes(): def __init__(self): self.lookup = {} def add(self, node): self.lookup[node.pos] = node def __iter__(self): return iter(self.lookup.itervalues()) def __contains__(self, pos): return pos in self.lookup def lowest(self): return min(self, key=operator.attrgetter("f")) def __delitem__(self, pos): del self.lookup[pos] nodes = Nodes() nodes.add(Node((1,1), None, 1, 5)) nodes.add(Node((1,2), (1,1), 4, 6)) nodes.add(Node((1,3), (1,2), 9, 10)) del nodes[1, 2] allows you to delete random nodes, but the lowest() method will slow down as it has to iterate over all dict values. One important caveat: both Nodes classes lead to data corruption if you modify a .pos attribute while the node is in a Nodes instance. The same goes for the first implementation and the .f attribute. From emile at fenx.com Tue Jan 21 13:44:32 2014 From: emile at fenx.com (emile) Date: Tue, 21 Jan 2014 10:44:32 -0800 Subject: Add followers at time of import In-Reply-To: References: Message-ID: On 01/21/2014 10:03 AM, Chris Angelico wrote: > On Wed, Jan 22, 2014 at 4:52 AM, emile wrote: >> Ask if that's not clear. > > I'm not entirely sure, but I think this might have been meant for > somewhere other than python-list. Welcome to the club. Aargh! -- I hate when that happens... Sorry. Emile From real-not-anti-spam-address at apple-juice.co.uk Tue Jan 21 13:44:04 2014 From: real-not-anti-spam-address at apple-juice.co.uk (D.M. Procida) Date: Tue, 21 Jan 2014 18:44:04 +0000 Subject: A day of free Python & Django talks & tutorials, Cardiff (UK) Message-ID: <1lfu6oq.1n9hhn42twvi6N%real-not-anti-spam-address@apple-juice.co.uk> Django Weekend Cardiff is completely sold out. Our open day remains open however, and you're invited to attend the numerous talks, tutorials and demonstrations in the programme. They'll all be held at Cardiff University. There are fifteen different sessions in the open day programme, on all kinds of subjects - from medicine to robotics - and at various levels of technical complexity. One of the key audiences for the open day is developers who want to learn more about Python and Django so if that's you, you're especially welcome. Another key audience is A-level science pupils and teachers, and we have a number of talks that have been devised with them in mind - so if you know any, please point them in our direction, as we'll be very pleased to see them. All the sessions are free, and refreshments will be provided. Registration is required so we know how many people to expect, and places in the tutorials will be limited. The sooner you register the better it is for us, because we have to plan catering, access and other practicalities - so please do it as soon as you can! Register: And finally, do pass on details of the open day to anyone else whom you think might be interested. Thanks, Daniele -- Django Weekend Cardiff, the first-ever Django conference in the UK Three days of Django/Python talks, tutorials and code sprints From ztepman at gmail.com Tue Jan 21 13:45:25 2014 From: ztepman at gmail.com (Ziv Tepman) Date: Tue, 21 Jan 2014 10:45:25 -0800 Subject: =?windows-1252?Q?Re=3A_Running_pywin32=2D218=2Ewin32=2Dpy2=2E7=2Eexe_=28win32_packa?= =?windows-1252?Q?ge_for_Python=29_results_in_error_=93The_file_exists=94?= In-Reply-To: References: Message-ID: A small correction to my prior message: I am trying to install the Python module "win32" but whenever I click on the exe file (pywin32-218.win32-py2.7.exe) I get the message "The file exists Could not create temporary file", and when I click OK, I get the message, "*Setup program invalid or damaged*." I have chosen the appropriate build. How might I fix this error? Thanks! On Tue, Jan 21, 2014 at 10:02 AM, Ziv Tepman wrote: > I am trying to install the Python module "win32" but whenever I click on > the exe file (pywin32-218.win32-py2.7.exe) I get the message "The file > exists Could not create temporary file", and when I click OK, I get the > message, "pywin32-218.win32-py2.7." I have chosen the appropriate build. > How might I fix this error? Thanks! > -------------- next part -------------- An HTML attachment was scrubbed... URL: From travisgriggs at gmail.com Tue Jan 21 14:04:40 2014 From: travisgriggs at gmail.com (Travis Griggs) Date: Tue, 21 Jan 2014 11:04:40 -0800 Subject: Python 3.x adoption In-Reply-To: <95e6f032-cd40-483b-a649-676d9a56808a@googlegroups.com> References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> <95e6f032-cd40-483b-a649-676d9a56808a@googlegroups.com> Message-ID: <2B6387D4-9737-4CAE-9C4F-E39E09D74165@gmail.com> Looks like the 2/3 topic has lain fallow for a couple of days, gotta keep it burning? I?m a relatively recent python convert, but been coding and talking to others about coding for many moons on this big blue orb. I think the industrial side of this debate has been talked up quite a bit. We have tools, we have the wall of shame/superpowers for libraries and projects. I think the desires of the core of people moving python forward are pretty clear to those of us that plug in. Move to 3. Period. We can debate, hate it, go on all day, but they?ve been pretty steady. I?ve had a bunch of interns around me lately though, wanting to get into python, and this is where I find the momentum really breaks down. If newcomers go to take an online course in python, they might try MIT?s Open Courseware (who doesn?t want to learn from the illustrious MIT after all?). They?ll be taught Python 2, not 3. Or they might try Code Academy. Again, they?ll be taught 2, not 3. If the newbie googles ?python reference?? top link will be python 2. So in my mind, the wall of superpowers/shame is no longer well aligned with where the real battlefront of adoption is at. The legacy of the internet caches and education sites are. Personally, I have no idea why an education site would favor a version that sooner or later they?re going to have to try and explain how super() works. The other area, I think, that puts a dent in perceived adoption is in alternate interpreters. Back in the day, everyone was making some branch of python (e.g. IronPython, Jython, Cython, PyPy, Stackless, etc). All of them did python 2. Very few are doing python 3. Some have been abandoned (as is the nature of research endeavors like these were), but there doesn?t seem to be the broad swath of people still building alternate python expressions, especially in python 3. Being a fan of JIT, I have big hopes for PyPy, I can?t figure out why they aren?t pitching their ?cutting edge? interpreter, for the ?cutting edge? version of python. There should be a wall of superpowers/shame for interpreters. From mu-- at melix.net Tue Jan 21 14:11:02 2014 From: mu-- at melix.net (=?ISO-8859-1?Q?M=FB?=) Date: Tue, 21 Jan 2014 20:11:02 +0100 Subject: Modifying the default argument of function Message-ID: <52dec646$0$2934$426a74cc@news.free.fr> Hi everybody, A friend of mine asked me a question about the following code: [code] def f(x=[2,3]): x.append(1) return x print(f()) print(f()) print(f()) [/code] The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1]. The function acts as if there were a global variable x, but the call of x results in an error (undefined variable). I don't understand why the successive calls of f() don't return the same value: indeed, I thought that [2,3] was the default argument of the function f, thus I expected the three calls of f() to be exactly equivalent. I'm don't know much about python, does anybody have a simple explanation please? -- M? --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From ckaynor at zindagigames.com Tue Jan 21 14:15:12 2014 From: ckaynor at zindagigames.com (Chris Kaynor) Date: Tue, 21 Jan 2014 11:15:12 -0800 Subject: Python 3.x adoption In-Reply-To: <2B6387D4-9737-4CAE-9C4F-E39E09D74165@gmail.com> References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> <95e6f032-cd40-483b-a649-676d9a56808a@googlegroups.com> <2B6387D4-9737-4CAE-9C4F-E39E09D74165@gmail.com> Message-ID: On Tue, Jan 21, 2014 at 11:04 AM, Travis Griggs wrote: > Being a fan of JIT, I have big hopes for PyPy, I can?t figure out why they > aren?t pitching their ?cutting edge? interpreter, for the ?cutting edge? > version of python. There should be a wall of superpowers/shame for > interpreters. A very quick look at the PyPy website shows they are working on a 3.x compatible version: http://doc.pypy.org/en/latest/release-pypy3-2.1.0-beta1.html. Its just still in beta. Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Tue Jan 21 14:19:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 06:19:12 +1100 Subject: Modifying the default argument of function In-Reply-To: <52dec646$0$2934$426a74cc@news.free.fr> References: <52dec646$0$2934$426a74cc@news.free.fr> Message-ID: On Wed, Jan 22, 2014 at 6:11 AM, M? wrote: > The function acts as if there were a global variable x, but the call of x > results in an error (undefined variable). I don't understand why the > successive calls of f() don't return the same value: indeed, I thought that > [2,3] was the default argument of the function f, thus I expected the three > calls of f() to be exactly equivalent. In a sense, there is. The default for the argument is simply an object like any other, and it's stored in one place. For cases where you want a mutable default that is "reset" every time, the most common idiom is this: def f(x=None): if x is None: x=[2,3] x.append(1) return x That will create a new list every time, with the same initial contents. ChrisA From steve at secretvolcanobase.org Tue Jan 21 14:19:53 2014 From: steve at secretvolcanobase.org (Steve Jones) Date: Tue, 21 Jan 2014 19:19:53 +0000 Subject: Modifying the default argument of function References: <52dec646$0$2934$426a74cc@news.free.fr> Message-ID: <20140121191953.6c8dae28@steves-laptop> On Tue, 21 Jan 2014 20:11:02 +0100 M? wrote: > Hi everybody, > > A friend of mine asked me a question about the following code: > > [code] > def f(x=[2,3]): > x.append(1) > return x > > print(f()) > print(f()) > print(f()) > [/code] > > The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1]. > > The function acts as if there were a global variable x, but the call of > x results in an error (undefined variable). I don't understand why the > successive calls of f() don't return the same value: indeed, I thought > that [2,3] was the default argument of the function f, thus I expected > the three calls of f() to be exactly equivalent. > > I'm don't know much about python, does anybody have a simple explanation > please? x is assigned to the list [2, 3] at the time the function is created not when the function is called, meaning that there's only ever 1 list created. When you call x.append this list is modified and the next time the function is called x still refers to this modified list. From emile at fenx.com Tue Jan 21 14:20:15 2014 From: emile at fenx.com (emile) Date: Tue, 21 Jan 2014 11:20:15 -0800 Subject: Modifying the default argument of function In-Reply-To: <52dec646$0$2934$426a74cc@news.free.fr> References: <52dec646$0$2934$426a74cc@news.free.fr> Message-ID: Function defs with mutable arguments hold a reference to the mutable container such that all invocations access the same changeable container. To get separate mutable default arguments, use: def f(x=None): if x is None: x=[2,3] Emile On 01/21/2014 11:11 AM, M? wrote: > Hi everybody, > > A friend of mine asked me a question about the following code: > > [code] > def f(x=[2,3]): > x.append(1) > return x > > print(f()) > print(f()) > print(f()) > [/code] > > The results are [2, 3, 1], [2, 3, 1, 1] and [2, 3, 1, 1, 1]. > > The function acts as if there were a global variable x, but the call of > x results in an error (undefined variable). I don't understand why the > successive calls of f() don't return the same value: indeed, I thought > that [2,3] was the default argument of the function f, thus I expected > the three calls of f() to be exactly equivalent. > > I'm don't know much about python, does anybody have a simple explanation > please? > From rosuav at gmail.com Tue Jan 21 14:25:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 06:25:17 +1100 Subject: Python 3.x adoption In-Reply-To: <2B6387D4-9737-4CAE-9C4F-E39E09D74165@gmail.com> References: <3f88a958-4f3f-476c-bc9f-1b38ac0d084b@googlegroups.com> <95e6f032-cd40-483b-a649-676d9a56808a@googlegroups.com> <2B6387D4-9737-4CAE-9C4F-E39E09D74165@gmail.com> Message-ID: On Wed, Jan 22, 2014 at 6:04 AM, Travis Griggs wrote: > I?ve had a bunch of interns around me lately though, wanting to get into python, and this is where I find the momentum really breaks down. If newcomers go to take an online course in python, they might try MIT?s Open Courseware (who doesn?t want to learn from the illustrious MIT after all?). They?ll be taught Python 2, not 3. > Courses are inherently laggy. I don't know how long it takes to write a course, get it approved, and then advertise it so you get some students, but I suspect it's a good while. I'd say that it's only since 3.3 (some would argue 3.2, others 3.4) that Py3 has been the clear winner in the new-application debate; give it a few more years before courses start teaching Py3. Of course, anyone who comes to a rapid communication venue like python-list can learn the state of the art (in the original sense), but if you want a degree in Comp Sci and you have to take X courses to get it, chances are you'll learn Py2 along the way. ChrisA From mu-- at melix.net Tue Jan 21 14:36:19 2014 From: mu-- at melix.net (=?UTF-8?B?TcO7?=) Date: Tue, 21 Jan 2014 20:36:19 +0100 Subject: Modifying the default argument of function In-Reply-To: References: <52dec646$0$2934$426a74cc@news.free.fr> Message-ID: <52decc31$0$2244$426a74cc@news.free.fr> Le 21/01/2014 20:19, Chris Angelico a ?crit : > On Wed, Jan 22, 2014 at 6:11 AM, M? wrote: >> The function acts as if there were a global variable x, but the call of x >> results in an error (undefined variable). I don't understand why the >> successive calls of f() don't return the same value: indeed, I thought that >> [2,3] was the default argument of the function f, thus I expected the three >> calls of f() to be exactly equivalent. > > In a sense, there is. The default for the argument is simply an object > like any other, and it's stored in one place. > > For cases where you want a mutable default that is "reset" every time, > the most common idiom is this: > > def f(x=None): > if x is None: x=[2,3] > x.append(1) > return x > > That will create a new list every time, with the same initial contents. > > ChrisA > Thank you, thanks everybody, These were clear and quick answers to my problem. I did not think of this possibility: the default argument is created once, but accessible only by the function, therefore is not a global variable, whereas it looks like if it were at first glance. -- M? --- Ce courrier ?lectronique ne contient aucun virus ou logiciel malveillant parce que la protection avast! Antivirus est active. http://www.avast.com From rosuav at gmail.com Tue Jan 21 14:46:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 06:46:16 +1100 Subject: Modifying the default argument of function In-Reply-To: <52decc31$0$2244$426a74cc@news.free.fr> References: <52dec646$0$2934$426a74cc@news.free.fr> <52decc31$0$2244$426a74cc@news.free.fr> Message-ID: On Wed, Jan 22, 2014 at 6:36 AM, M? wrote: > These were clear and quick answers to my problem. I did not think of this > possibility: the default argument is created once, but accessible only by > the function, therefore is not a global variable, whereas it looks like if > it were at first glance. You can actually poke at the function a bit and see what's happening. Try this in the interactive interpreter: >>> def f(x=[2,3]): x.append(1) return x >>> f() [2, 3, 1] >>> f() [2, 3, 1, 1] >>> f.__defaults__ ([2, 3, 1, 1],) The __defaults__ attribute of a function is a tuple of its parameter defaults. You can easily see there that the list has changed as you changed it in the function. You could check it with id() or is, too: >>> id(f.__defaults__[0]) 24529576 >>> id(f()) 24529576 >>> f() is f.__defaults__[0] True ChrisA From ethan at stoneleaf.us Tue Jan 21 13:53:43 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Tue, 21 Jan 2014 10:53:43 -0800 Subject: Diving in to Python - Best resources? In-Reply-To: References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: <52DEC237.5040306@stoneleaf.us> On 01/21/2014 08:00 AM, Rustom Mody wrote: > > Most people -- even those using spreadsheets -- dont seem to think of > the spreadsheet macro language/VBA as a programming language Ack, are you trying to put him off programming again?!? ;) Python us fun and a pleasure to use. VBA is not. (IMNSHO & YMMV) -- ~Ethan~ From cmpython at gmail.com Tue Jan 21 15:38:49 2014 From: cmpython at gmail.com (CM) Date: Tue, 21 Jan 2014 12:38:49 -0800 (PST) Subject: how to avoid spaghetti in Python? Message-ID: <346d0a59-0d8a-447e-a8a6-1198119002a9@googlegroups.com> I've been learning and using Python for a number of years now but never really go particularly disciplined about all good coding practices. I've definitely learned *some*, but I'm hoping this year to take a good step up in terms of refactoring, maintainability, and mostly just "de-spaghettizing" my approach to writing Python programs. But I could use some pointers. Of course, many pointers will be general programming advice that is common to all languages, and I get that, but I also think that it's possible certain bits of advice are particularly relevant to Python coders, and so I ask here. (Also because I know there are some great community people here who I'd enjoy getting their take on this). A few specific questions in this area... 1) One of my main "spaghetti problems" is something I don't know what to ever call. Basically it is that I sometimes have a "chain" of functions or objects that get called in some order and these functions may live in different modules and the flow of information may jump around quite a bit, sometimes through 4-5 different parts of the code, and along the way variables get modified (and those variables might be child objects of the whole class, or they may just be objects that exist only within functions' namespaces, or both). This is hard to debug and maintain. What would people recommend to manage this? A system of notes? A way to simplify the flow? And what is this problem called (if something other than just spaghetti code) so I can Google more about it? 2) A related question: Often I find there are two ways to update the value of an object, and I don't know what's best in which circumstances... To begin to explain, let's say the code is within a class that represents a Frame object in a GUI, like wxPython. Now let's say ALL the code is within this wxFrame class object. So, any object that is named with "self." prepended, like self.panel, or self.current_customer, or self.current_date, will be a child object of that frame class, and therefore is sort of "global" to the whole frame's namespace and can therefore be accessed from within any function in the class. So let's say I have a function called self.GetCurrentCustomer(). To actually get the name of the current customer into RAM, it goes into the database and uses some rule to get the current customer. NOW, the question is, which of these should I do? This: def GetCurrentCustomer(self): self.current_customer = #do some database stuff here.... Or this: def GetCurrentCustomer(self): current_customer = #do some database stuff here.... return current_customer And what difference does it make? In the first case, I am just updating the "global" object of the current_customer, so that any function can then use it. In the second case, I am only returning the current_customer to whatever function(s) call this GetCurrentCustomer() function. My hunch is the first way leads to spaghetti problems. But I want to understand what the best practices are in this regard. I have found in some cases the first method seemed handy, but I'm not sure what the best way of thinking about this is. 3) Generally, what are other tools or approaches you would use to organize well a good-sized project so to avoid fighting yourself later when you don't understand your own code and the flow of information through it? By good sized, say about 20,000 lines of Python code, or something like that. This is the sort of question that would be rejected on Stack Overflow, so I hope you can excuse my fishing for insight in a somewhat open/vague way. Thanks. From drsalists at gmail.com Tue Jan 21 15:54:32 2014 From: drsalists at gmail.com (Dan Stromberg) Date: Tue, 21 Jan 2014 12:54:32 -0800 Subject: Python 1.0 - release date? Message-ID: Does anyone know when Python 1.0 was released? I want to say August of 1993, but there are apparently those who disagree. Thanks. From rosuav at gmail.com Tue Jan 21 15:58:19 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 07:58:19 +1100 Subject: how to avoid spaghetti in Python? In-Reply-To: <346d0a59-0d8a-447e-a8a6-1198119002a9@googlegroups.com> References: <346d0a59-0d8a-447e-a8a6-1198119002a9@googlegroups.com> Message-ID: On Wed, Jan 22, 2014 at 7:38 AM, CM wrote: > 1) One of my main "spaghetti problems" is something I don't know what to ever call. Basically it is that I sometimes have a "chain" of functions or objects that get called in some order and these functions may live in different modules and the flow of information may jump around quite a bit, sometimes through 4-5 different parts of the code, and along the way variables get modified (and those variables might be child objects of the whole class, or they may just be objects that exist only within functions' namespaces, or both). This is hard to debug and maintain. > Rule of thumb: Every function should be able to be summarized in a single line. This isn't Python-specific, but in the case of Python, it's part of the recommendations for docstrings [1]. When one function calls another function calls another and so on, it's not a problem if each one can be adequately described: def is_positive(item): """Ascertain whether the item is deemed positive. Per business requirement XYZ123, items are deemed positive at 90% certainty, even though they are deemed negative at only 75%. """ return item.certainty >= 0.9 and item.state > 0 def count_positive(lst): """Return the number of deemed-positive items in lst.""" return sum((1 for item in lst if is_positive(item))) Each of these functions has a clear identity. (Okay, they're a little trivial for the sake of the example, but you can see how this would work.) Each one makes sense on its own, and it's obvious that one should be deferring to the other. If business requirement XYZ123 ever changes, count_positive's behaviour should change, ergo it calls on is_positive to make the decision. Rule of thumb: Anything that changes state should make sense. Neither of the above functions has any right to *modify* lst or item (except for stats, maybe - "time since last queried" could be reset). You mention "variables getting modified", and then go on to use some rather non-Pythonic terminology; I'm not entirely sure what you mean there, so I'll ignore it and just say something that may or may not have any relevance to your case: the function's one-line summary should normally make it clear whether state is to be changed or not. A function that queries something shouldn't usually change that state (except when you read from a stream; there's a bit of a grey area with retrieving the first element of a list, which shouldn't change the list, vs retrieving the top element of a stack/queue/heap, which possibly should, but then you'd call it "pop" to be clear). Tip: Adding one-line descriptions to all your functions is a great way to figure out (or force yourself to figure out) what your code's doing. Having someone *else* add one-line descriptions to all your functions is an awesome way to figure out where your function names are unclear :) I had someone go through one of my open source projects doing exactly that, and it was quite enlightening to see which of his docstrings were majorly incorrect. Several of them ended up triggering renames or code revamps to make something more intuitive. ChrisA [1] See PEP 257, http://www.python.org/dev/peps/pep-0257/ From charleshixsn at earthlink.net Tue Jan 21 16:00:30 2014 From: charleshixsn at earthlink.net (Charles Hixson) Date: Tue, 21 Jan 2014 13:00:30 -0800 Subject: http://bugs.python.org/user?@template=rego_progress broken? Message-ID: <52DEDFEE.5000801@earthlink.net> I have tried to register at http://bugs.python.org, and got as far as this page, where I am told: You will shortly receive an email to confirm your registration. To complete the registration process, visit the link indicated in the email. But it hasn't arrived after over a day. This case isn't too important, as I was just going to request a documentation change, but it happening may be more important than what I would have entered. -- Charles Hixson From andrea.crotti.0 at gmail.com Tue Jan 21 16:03:56 2014 From: andrea.crotti.0 at gmail.com (andrea crotti) Date: Tue, 21 Jan 2014 21:03:56 +0000 Subject: how to avoid spaghetti in Python? In-Reply-To: <346d0a59-0d8a-447e-a8a6-1198119002a9@googlegroups.com> References: <346d0a59-0d8a-447e-a8a6-1198119002a9@googlegroups.com> Message-ID: 2014/1/21 CM : > I've been learning and using Python for a number of years now but never really go particularly disciplined about all good coding practices. I've definitely learned *some*, but I'm hoping this year to take a good step up in terms of refactoring, maintainability, and mostly just "de-spaghettizing" my approach to writing Python programs. > It's not really a problem of Python, you just want to learn more about OO principles and good design practices, and about that there are hundreds of good books to read! > > A few specific questions in this area... > > 1) One of my main "spaghetti problems" is something I don't know what to ever call. Basically it is that I sometimes have a "chain" of functions or objects that get called in some order and these functions may live in different modules and the flow of information may jump around quite a bit, sometimes through 4-5 different parts of the code, and along the way variables get modified (and those variables might be child objects of the whole class, or they may just be objects that exist only within functions' namespaces, or both). This is hard to debug and maintain. What would people recommend to manage this? A system of notes? A way to simplify the flow? And what is this problem called (if something other than just spaghetti code) so I can Google more about it? > Just define clearly objects and methods and how they interact with each other in a logic way, and you won't have this problem anymore. > 2) A related question: Often I find there are two ways to update the value of an object, and I don't know what's best in which circumstances... To begin to explain, let's say the code is within a class that represents a Frame object in a GUI, like wxPython. Now let's say ALL the code is within this wxFrame class object. So, any object that is named with "self." prepended, like self.panel, or self.current_customer, or self.current_date, will be a child object of that frame class, and therefore is sort of "global" to the whole frame's namespace and can therefore be accessed from within any function in the class. So let's say I have a function called self.GetCurrentCustomer(). To actually get the name of the current customer into RAM, it goes into the database and uses some rule to get the current customer. NOW, the question is, which of these should I do? This: > > def GetCurrentCustomer(self): > self.current_customer = #do some database stuff here.... > > Or this: > > def GetCurrentCustomer(self): > current_customer = #do some database stuff here.... > return current_customer > > And what difference does it make? In the first case, I am just updating the "global" object of the current_customer, so that any function can then use it. In the second case, I am only returning the current_customer to whatever function(s) call this GetCurrentCustomer() function. > GetCurrentCustomer should be really get_current_customer if you don't want people screaming at you. And about the question it depends, is the database stuff going to be expensive? Do you need to have always a new value? And by the way if you're never actually using "self" in a method maybe it should be a function, or at least a classmethod instead. > My hunch is the first way leads to spaghetti problems. But I want to understand what the best practices are in this regard. I have found in some cases the first method seemed handy, but I'm not sure what the best way of thinking about this is. > > 3) Generally, what are other tools or approaches you would use to organize well a good-sized project so to avoid fighting yourself later when you don't understand your own code and the flow of information through it? By good sized, say about 20,000 lines of Python code, or something like that. > Good architecture and some meaningful directory structure is good enough, to navigate Emacs + ack and I'm already very productive even with bigger projects than that. From rosuav at gmail.com Tue Jan 21 16:12:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 08:12:20 +1100 Subject: Python 1.0 - release date? In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 7:54 AM, Dan Stromberg wrote: > Does anyone know when Python 1.0 was released? > > I want to say August of 1993, but there are apparently those who disagree. Wikipedia [1] says Jan 1994, but the cited link [2] doesn't actually give a date for 1.0. However, I did find a blog post by Guido [3] says Jan 26 1994, uncited but presumably authoritative, and digging through 'hg log' shows this: changeset: 1537:7ecd6380566c branch: legacy-trunk user: Guido van Rossum date: Wed Jan 26 17:55:41 1994 +0000 summary: Release of 1.0.0 I'd say that's probably when it happened. :) ChrisA [1] https://en.wikipedia.org/wiki/History_of_Python [2] http://www.python.org/download/releases/ (footnote 8 in the above) [3] http://python-history.blogspot.com.au/2009/01/brief-timeline-of-python.html From skip at pobox.com Tue Jan 21 16:21:09 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 21 Jan 2014 15:21:09 -0600 Subject: Python 1.0 - release date? In-Reply-To: References: Message-ID: > I want to say August of 1993, but there are apparently those who disagree. Misc/HISTORY says 26 January 1994: ======================================= ==> Release 1.0.0 (26 January 1994) <== ======================================= Actually, Misc/HISTORY has release headings going back as far as 0.9.0 (February 1991). Skip From rosuav at gmail.com Tue Jan 21 16:29:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 08:29:57 +1100 Subject: =?UTF-8?Q?Re=3A_Running_pywin32=2D218=2Ewin32=2Dpy2=2E7=2Eexe_=28win32_packa?= =?UTF-8?Q?ge_for_Python=29_results_in_error_=E2=80=9CThe_file_exists=E2=80=9D?= In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 5:45 AM, Ziv Tepman wrote: > I am trying to install the Python module "win32" but whenever I click on the > exe file (pywin32-218.win32-py2.7.exe) I get the message "The file exists > Could not create temporary file", and when I click OK, I get the message, > "Setup program invalid or damaged." I have chosen the appropriate build. How > might I fix this error? Thanks! Do you have a way to check that the file was downloaded correctly? Alternatively, just try redownloading it - maybe you got a broken file somehow. Since you're not talking about Python itself but about a specific module, it would help if you provided a link to the page you got it from, too. Thanks! :) ChrisA From jcasale at activenetwerx.com Tue Jan 21 17:52:42 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 21 Jan 2014 22:52:42 +0000 Subject: Implementing append within a descriptor In-Reply-To: References: Message-ID: > You're going to have to subclass list if you want to intercept its > methods. As I see it, there are two ways you could do that: when it's > set, or when it's retrieved. I'd be inclined to do it in __set__, but > either could work. In theory, you could make it practically invisible > - just check to see if you're trying to __set__ a list, and if you > are, set a magical list instead. Hey Chris, That actually is sufficient, assignment can be intercepted and retyped so an append will accomplish what I need. Thanks! jlc From roegltd at gmail.com Tue Jan 21 18:18:10 2014 From: roegltd at gmail.com (Asaf Las) Date: Tue, 21 Jan 2014 15:18:10 -0800 (PST) Subject: autoconf tools and python3 3m 3dm In-Reply-To: References: Message-ID: On Tuesday, January 21, 2014 7:55:13 PM UTC+2, Mark Heieis wrote: > Hi, > would work either as one would need to know in advance specifically > which one to call and there'd be extra work to extract the full version > info, etc. ("$python3-config --includes" yields > -I/usr/include/python3.3m -I/usr/include/python3.3m) > Has anyone else come up against this? If so, what was the solution? > BTW - anyone know what the 'm' and 'dm' suffixes indicate? > TIA. I use recommended approach as below: ./configure --prefix=/usr/local make && make altinstall and have base 2.6 came with CENTOS, 2.7 and 3.3 installed later and working without problem. see below [root at localhost etc]# which python3.3 /usr/local/bin/python3.3 [root at localhost etc]# which python2.7 /usr/local/bin/python2.7 [root at localhost etc]# which python /usr/bin/python From shane.konings at gmail.com Tue Jan 21 18:49:16 2014 From: shane.konings at gmail.com (Shane Konings) Date: Tue, 21 Jan 2014 15:49:16 -0800 (PST) Subject: Separate Address number and name Message-ID: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> I have the following sample from a data set and I am looking to split the address number and name into separate headings as seen below. FarmID Address 1 1067 Niagara Stone 2 4260 Mountainview 3 25 Hunter 4 1091 Hutchinson 5 5172 Green Lane 6 500 Glenridge 7 471 Foss 8 758 Niagara Stone 9 3836 Main 10 1025 York FarmID AddressNum AddressName 1 1067 Niagara Stone 2 4260 Mountainview 3 25 Hunter 4 1091 Hutchinson 5 5172 Green Lane 6 500 Glenridge 7 471 Foss 8 758 Niagara Stone 9 3836 Main 10 1025 York I have struggled with this for a while and know there must be a simple method to achieve this result. From wegge at wegge.dk Tue Jan 21 18:55:43 2014 From: wegge at wegge.dk (Anders Wegge Keller) Date: 22 Jan 2014 00:55:43 +0100 Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: <87r4803n5s.fsf@huddi.jernurt.dk> Shane Konings writes: > I have struggled with this for a while and know there must be a > simple method to achieve this result. There are several. But without seeing the code you have already written, it's har to help you improve it. -- /Wegge Leder efter redundant peering af dk.*,linux.debian.* From shane.konings at gmail.com Tue Jan 21 19:01:32 2014 From: shane.konings at gmail.com (Shane Konings) Date: Tue, 21 Jan 2014 16:01:32 -0800 (PST) Subject: Separate Address number and name In-Reply-To: <87r4803n5s.fsf@huddi.jernurt.dk> References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> <87r4803n5s.fsf@huddi.jernurt.dk> Message-ID: <23a0ec1e-bcc1-4251-9b0c-33be185969ff@googlegroups.com> > I don't have any code to split that part up. There is other information following the street name such as street suffix, city, province, postal code, etc. I have been able to split the rest of it up based on certain criteria but have had no luck with splitting up the street name from the street number. From steve+comp.lang.python at pearwood.info Tue Jan 21 19:01:44 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2014 00:01:44 GMT Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Message-ID: <52df0a68$0$29999$c3e8da3$5496439d@news.astraweb.com> Hi Indar, On Sun, 19 Jan 2014 23:55:59 -0800, indar kumar wrote: > If you allow me I can post a small part of that assignment, it just > requires the manipulation with dictionary which I am not getting. I am > not asking to write a code for me. But a small hint would get me out of > trouble. In all this discussion about plagiarism, we seem to have forgotten about you! Sorry about that. Yes, feel free to ask your question about manipulating dictionaries, and we will try to answer. The more general your question (in the sense of not being specific to your project), the less you need to worry about plagiarism. -- Steven From ben+python at benfinney.id.au Tue Jan 21 19:08:08 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 22 Jan 2014 11:08:08 +1100 Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: <85txcwvpxz.fsf@benfinney.id.au> Shane Konings writes: > I have the following sample from a data set and I am looking to split > the address number and name into separate headings as seen below. > > FarmID Address > 1 1067 Niagara Stone > 2 4260 Mountainview > 3 25 Hunter > 4 1091 Hutchinson > 5 5172 Green Lane > 6 500 Glenridge > 7 471 Foss > 8 758 Niagara Stone > 9 3836 Main > 10 1025 York If it is *always* the case that you just want to split the string on the first space (' ', U+0020) character, then this will do the job: >>> street_address = "1067 Niagara Stone" >>> (street_number, street_name) = street_address.split(' ', 1) >>> street_number '1067' >>> street_name 'Niagara Stone' But that's a very dubious assumption. Are you sure your data contains no examples like: PO Box 27 Unit 6, 52 Watford Avenue Lot D property 107 Sandusky Road etc.? What is your policy for dealing with data which isn't structured as you assume? -- \ ?All my life I've had one dream: to achieve my many goals.? | `\ ?Homer, _The Simpsons_ | _o__) | Ben Finney From shane.konings at gmail.com Tue Jan 21 19:06:56 2014 From: shane.konings at gmail.com (Shane Konings) Date: Tue, 21 Jan 2014 16:06:56 -0800 (PST) Subject: Separate Address number and name In-Reply-To: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: inHandler = open(inFile, 'r') outHandler = open(outFile, 'w') outHandler.write('ID\tAddress\tStreetNum&Name\tSufType\tDir\tCity\tProvince\tPostalCode\n') for line in inHandler: str = line.replace('FarmID\tAddress','') outHandler.write(str[0:-1]) str = str.replace(', ON', '\t ON\t') str = str.replace(' Rd,', '\t Rd\t \t') str = str.replace(' Rd ', '\t Rd\t \t') str = str.replace(' St,', '\t St\t \t') str = str.replace(' St ', '\t St\t \t') str = str.replace(' Ave', '\t Ave\t \t') str = str.replace(' Pky', '\t Pky\t \t') str = str.replace(' Lane, ', '\t Lane\t \t') str = str.replace(', Lane, , Rd,', ' Lane\t Rd\t') str = str.replace(' Dr', '\t Dr\t \t') str = str.replace(' Sq', '\t Sq\t \t') str = str.replace(' Pl', '\t Pl\t \t') str = str.replace('\t \tN,', '\tN\t') str = str.replace('\t \t N,', '\tN\t') str = str.replace(' , North ', ' N\t') str = str.replace(' ,S ', ' S\t') str = str.replace(' , South ', ' S\t') str = str.replace('\t \tE,', '\tE\t') str = str.replace(' , East ', ' E\t') str = str.replace('\t \tW,', '\tW\t') str = str.replace('\t \t West', '\tW\t') str = str.replace(',.', '.') str = str.replace(',', '\t') str = str.replace(',,', '\t') str = str.replace(', Service', ' Service') str = str.replace('\t \t\t', '\t\t') outHandler.write(str[1:]) inHandler.close() outHandler.close() That is the code i currently have. The following is a sample of the data. There are hundreds of lines that need to have an automated process of splitting the strings into headings to be imported into excel with theses headings ID Address StreetNum StreetName SufType Dir City Province PostalCode 1 1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 3 25 Hunter Rd, Grimsby, E, ON L3M 4A3 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 5 5172 Green Lane Rd, Lincoln, ON L0R 1B3 6 500 Glenridge Ave, East, St. Catharines, ON L2S 3A1 7 471 Foss Rd, Pelham, ON L0S 1C0 8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 9 3836 Main St, North, Lincoln, ON L0R 1S0 10 1025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0 From roegltd at gmail.com Tue Jan 21 19:08:23 2014 From: roegltd at gmail.com (Asaf Las) Date: Tue, 21 Jan 2014 16:08:23 -0800 (PST) Subject: Separate Address number and name In-Reply-To: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: <32b20aae-5888-4011-878b-a1762589b12b@googlegroups.com> On Wednesday, January 22, 2014 1:49:16 AM UTC+2, Shane Konings wrote: > I have the following sample from a data set and I am > looking to split the address number and name into separate headings >as seen below. > I have struggled with this for a while and know there must be a simple method to achieve this result. input = '''1 1067 Niagara Stone 2 4260 Mountainview 3 25 Hunter 4 1091 Hutchinson 5 5172 Green Lane 6 500 Glenridge 7 471 Foss 8 758 Niagara Stone 9 3836 Main 10 1025 York ''' tlist = input.splitlines() for k in tlist: print(k.split()) do with 'k' whatever you wish From roegltd at gmail.com Tue Jan 21 19:30:09 2014 From: roegltd at gmail.com (Asaf Las) Date: Tue, 21 Jan 2014 16:30:09 -0800 (PST) Subject: Modifying the default argument of function In-Reply-To: References: <52dec646$0$2934$426a74cc@news.free.fr> <52decc31$0$2244$426a74cc@news.free.fr> Message-ID: <5e78b144-5e3d-48c2-adb1-df64878b8bf2@googlegroups.com> On Tuesday, January 21, 2014 9:46:16 PM UTC+2, Chris Angelico wrote: > On Wed, Jan 22, 2014 at 6:36 AM, M? wrote: > > These were clear and quick answers to my problem. I did not think of this > > possibility: the default argument is created once, but accessible only by > > the function, therefore is not a global variable, whereas it looks like if > > it were at first glance. > You can actually poke at the function a bit and see what's happening. > Try this in the interactive interpreter: > >>> def f(x=[2,3]): > x.append(1) > return x > >>> f() > [2, 3, 1] > >>> f() > [2, 3, 1, 1] > >>> f.__defaults__ > ([2, 3, 1, 1],) > > The __defaults__ attribute of a function is a tuple of its parameter > defaults. You can easily see there that the list has changed as you > changed it in the function. You could check it with id() or is, too: > >>> id(f.__defaults__[0]) > 24529576 > >>> id(f()) > 24529576 > >>> f() is f.__defaults__[0] > True > ChrisA that reminds me C's static :-) def func(y, x = [1]): if y != 1 : func.__defaults__[0][0] = y print(func.__defaults__[0]) func(0) func(2) func(1) [0] [2] [2] p.s. Mu, thanks for question! From steve+comp.lang.python at pearwood.info Tue Jan 21 19:51:12 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2014 00:51:12 GMT Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52df15ff$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jan 2014 18:39:44 +1100, Ben Finney wrote: > But sometimes different skills are being examined, and the student > should be exercising skills on their own without basing it directly on > the work of others. In these cases, penalties for plagiarism are > appropriate, would you agree? How can anyone possibly agree without knowing what those penalties are, what the definition of plagiarism being used is, and how guilt or innocence is determined? According to some people in a much better position to judge, significant parts of academia has collectively gone mad over so-called plagiarism. "I started off researching the subject of plagiarism thinking that sensitivity on the issue was getting a little bit out of hand. What I found when I viewed actual guidelines and articles on the subject was just plain appalling. Academia has simply gone crazy on this subject; not figuratively crazy, but certifiably, clinically, sociopathically insane. I'm talking delusional, loss of contact with reality insanity." -- Professor Steven Dutch, University of Wisconsin http://www.uwgb.edu/dutchs/PSEUDOSC/PlagShame.HTM More here: http://www.uwgb.edu/dutchs/PSEUDOSC/PlagiarNonsense.HTM According to Dutch, the University of Phoenix academic guidelines includes *failing to give a page number* of an otherwise fully cited source as plagiarism. If you read nothing else, read the second link, as Dutch gives practical guidelines for distinguishing significant and unethical plagiarism from insignificant and normal borrowing and sharing. Let's take this word of advice from "Plagiarism Today": [quote] In the end, it comes down to the same tried and true system of always attributing any content that you use, no matter how small, and always showing respect for the words of others, even if you have permission to use them. [end quote] http://www.plagiarismtoday.com/2008/02/20/the-obama-plagiarism-scandal/ Do you notice the assumption made? Let me highlight it for you: THE WORDS OF OTHERS The hidden assumption here is that *words are property*, that they belong to whomever first publishes them. Having now written those few words, nobody else is permitted to use those same words in the same order without crediting me. Failure to credit me is a sin of the highest order, enough to get you kicked out of your university, your name blackened. Unless, of course, somebody else wrote those words before me, in which case *my ignorance* of that earlier usage does not diminish the magnitude of my sin. In that regard, plagiarism is rather like patent infringement. This attitude is part of the compartmentalisation of culture into walled gardens, where nothing can be done without the permission of the "intellectual property owner". This is dangerous enough when it comes to ordinary, regular language, but it is astonishingly harmful if applied to code. It goes against the principles of openness and freedom which the FOSS movement stands for. Code, for the most part, is extremely cliched. Very little code is original, and none of it is created in isolation. There are only so many ways to walk a list, or search a body of text for a word, or calculate the cosine of a float. You sometimes have the option of shuffling the order of operations around a bit, or changing variable names, or slight modifications of some algorithm. As a community, programmers may not always share code, but they share ideas, coding idioms and algorithms. The academic definition of plagiarism, if applied in its full and strictest form, would essentially make coding impossible. We do not know how strict the OP's college is about so-called plagiarism, whether they only intend to come down on outright copying of significant bodies of code, or whether they have a tendency to go after trivial borrowing of simple idioms or minor duplication of insignificant portions of the program. (If I walk a linked list using mynode = mynode.next, and you use the same variable names, is that an indication of copying?) Without knowing what the OP's college considers plagiarism, how can judge the OP's reaction to it? -- Steven From steve+comp.lang.python at pearwood.info Tue Jan 21 19:51:37 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 22 Jan 2014 00:51:37 GMT Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> Message-ID: <52df1619$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 20 Jan 2014 19:17:35 +1100, Ben Finney wrote: > indar kumar writes: > >> Hint would have been enough but I was strictly discouraged. > > You asked for private help, specifically to subvert the rules against > plagiarism you're subject to. > > So no, I don't believe this modification of your request to be sincere. > You asked for help cheating, and you were refused. Please take a hint, > and do your assignment under the terms your teacher has set. That is the harshest, least "good faith" interpretation of the OP's post I have ever read. It doesn't look to me like that attitude is intended to be welcoming to students who are trying to walk the narrow tightrope of being part of a community of programmers who value sharing and collaboration while avoiding running foul of overly strict academic rules about so-called plagiarism. -- Steven From wegge at wegge.dk Tue Jan 21 20:04:49 2014 From: wegge at wegge.dk (Anders Wegge Keller) Date: 22 Jan 2014 02:04:49 +0100 Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: <87mwio3jym.fsf@huddi.jernurt.dk> Shane Konings writes: ... > The following is a sample of the data. There are hundreds of lines > that need to have an automated process of splitting the strings into > headings to be imported into excel with theses headings > ID Address StreetNum StreetName SufType Dir City Province PostalCode > > > 1 1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0 > 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > 3 25 Hunter Rd, Grimsby, E, ON L3M 4A3 > 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > 5 5172 Green Lane Rd, Lincoln, ON L0R 1B3 > 6 500 Glenridge Ave, East, St. Catharines, ON L2S 3A1 > 7 471 Foss Rd, Pelham, ON L0S 1C0 > 8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > 9 3836 Main St, North, Lincoln, ON L0R 1S0 > 10 1025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0 The input doesn't look consistent to me. Is Dir supposed to be an optional value? If that is the only optional, it can be worked around. But if the missing direction (I'm guessing) is due to malformed input data, you have a hell of a job in front of you. What do you want to do with incomplete or malformed data? Try to parse it as a "best effort", or simply spew out an error message for an operator to look at? In the latter case, I suggest a stepwise approach: * Split input by ',' ->res0 * Split the first result by ' ' -> res -> Id = res[0] -> Address = res[1:] -> StreetNum = res[1] -> StreetName= res [2:] -> SufType = res[-1] * Check if res0[1] looks like a cardinal direction If so Dir = res0[1] Otherwise, croak or use the default direction. Insert an element in the list, so the remainder is shifted to match the following steps. -> City = res0[2] * Split res0[3] by ' ' -> respp respp[0] -> Province respp[1:] -> Postcode And put in som basic sanitation of the resulting values, before committing them as a parsed result. Provinces and post codes, should be easy enough to validate against a fixed list. -- /Wegge Leder efter redundant peering af dk.*,linux.debian.* From tjreedy at udel.edu Tue Jan 21 20:22:03 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Tue, 21 Jan 2014 20:22:03 -0500 Subject: http://bugs.python.org/user?@template=rego_progress broken? In-Reply-To: <52DEDFEE.5000801@earthlink.net> References: <52DEDFEE.5000801@earthlink.net> Message-ID: On 1/21/2014 4:00 PM, Charles Hixson wrote: > I have tried to register at http://bugs.python.org, and got as far as > this page, where I am told: > You will shortly receive an email to confirm your registration. To > complete the registration process, visit the link indicated in the email. > But it hasn't arrived after over a day. That happens occasionally, unknown why. I believe the usual advice is try again. > This case isn't too important, as I was just going to request a > documentation change, but it happening may be more important than what I > would have entered. You can post your request here for discussion. -- Terry Jan Reedy From notbob at nothome.com Tue Jan 21 21:19:57 2014 From: notbob at nothome.com (notbob) Date: 22 Jan 2014 02:19:57 GMT Subject: Diving in to Python - Best resources? References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: On 2014-01-20, Matt Watson wrote: > My question to you guys is... for someone like me, what route would > you take to learning Python? "Learn Python the Hard Way" sounds like > a good route, but I prefer some testimony before I make a > purchase. You sound a lot like myself, in that you are easily frustrated. I discovered long ago I'm NOT a programmer. I've dipped a toe into basic, html, C, bash script, lisp, etc, but have never gotten beyond the "pissed" and/or "bored-to-tears" level. Much of this is due to almost every single book/tutorial/howto/etc having either mistakes in the code or crippling omissions, requiring a 30 min search on the web, jes like you sed. I hate that! So, Learning Python the Hard way. I love it!! No mistakes. No omissions. Everthing explained. I'm about a doz lessons in and the author has me chuckling (he has a sense of humor) with pleased delight after I successfully complete a lesson. I also use the 2.7.6 Python Standard Library as a reference in case I wanna know more. I'm enrolled in an online python course starting in Mar and I'm hoping LPtHW will get me sufficiently primed. I think it will. I highly recommend it. nb From gordon at panix.com Tue Jan 21 21:46:15 2014 From: gordon at panix.com (John Gordon) Date: Wed, 22 Jan 2014 02:46:15 +0000 (UTC) Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: In <9fe1b47b-65ce-4063-9188-07b81cdba49f at googlegroups.com> Shane Konings writes: > I have the following sample from a data set and I am looking to split the address number and name into separate headings as seen below. > FarmID Address > 1 1067 Niagara Stone > 2 4260 Mountainview > 3 25 Hunter > 4 1091 Hutchinson > 5 5172 Green Lane > 6 500 Glenridge > 7 471 Foss > 8 758 Niagara Stone > 9 3836 Main > 10 1025 York > FarmID AddressNum AddressName > 1 1067 Niagara Stone > 2 4260 Mountainview > 3 25 Hunter > 4 1091 Hutchinson > 5 5172 Green Lane > 6 500 Glenridge > 7 471 Foss > 8 758 Niagara Stone > 9 3836 Main > 10 1025 York > I have struggled with this for a while and know there must be a simple > method to achieve this result. for line in input_lines: fields = line.split() farm_id = fields[0] address_num = fields[1] address_name = ' '.join(fields[2:]) -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From roegltd at gmail.com Tue Jan 21 21:51:54 2014 From: roegltd at gmail.com (Asaf Las) Date: Tue, 21 Jan 2014 18:51:54 -0800 (PST) Subject: Self healthcheck Message-ID: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> Hi When designing long running background process is it feasible to monitor object/memory leakage due to improper programming? If it could be possible to make module which monitor and record trends if alive objects then event can be generated and logged if noof "zombie" objects are to increase in longer run. Would the gc.count() serve for such purpose? Thanks Asaf From python.list at tim.thechases.com Tue Jan 21 22:03:42 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Tue, 21 Jan 2014 21:03:42 -0600 Subject: Separate Address number and name In-Reply-To: References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: <20140121210342.18eec37c@bigbox.christie.dr> On 2014-01-22 02:46, John Gordon wrote: > > FarmID AddressNum AddressName > > 1 1067 Niagara Stone > > 2 4260 Mountainview > > 3 25 Hunter > > 4 1091 Hutchinson > > > I have struggled with this for a while and know there must be a > > simple method to achieve this result. > > for line in input_lines: > fields = line.split() > farm_id = fields[0] > address_num = fields[1] > address_name = ' '.join(fields[2:]) Or, you can split of just the parts you need: for line in input_lines: farm_id, street_no, street_name = line.split(None, 2) It doesn't address the issues that Ben raised about the crazy formats you can find in addresses, but address-parsing is an twisty maze of passages all alike. -tkc From rustompmody at gmail.com Tue Jan 21 22:01:38 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 21 Jan 2014 19:01:38 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: <52df1619$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> <52df1619$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wednesday, January 22, 2014 6:21:37 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 20 Jan 2014 19:17:35 +1100, Ben Finney wrote: > > indar kumar writes: > >> Hint would have been enough but I was strictly discouraged. > > You asked for private help, specifically to subvert the rules against > > plagiarism you're subject to. > > So no, I don't believe this modification of your request to be sincere. > > You asked for help cheating, and you were refused. Please take a hint, > > and do your assignment under the terms your teacher has set. > That is the harshest, least "good faith" interpretation of the OP's post > I have ever read. It doesn't look to me like that attitude is intended to > be welcoming to students who are trying to walk the narrow tightrope of > being part of a community of programmers who value sharing and > collaboration while avoiding running foul of overly strict academic rules > about so-called plagiarism. I was working in a large sw-development company some years ago. One day unexpectedly I found I could not download any more the FOSS sw I regularly use. What happened?? Evidently a programmer had copied GPL code off the net, passed it off as his own, it had gone past the local company'a managers and been detected by the off-shore client-company. Evidently a dose of GPLd code is as salutary for the health of commercial sw companies as a polonium capsule is for humans. Hence the chaos. So treating Ben's strictures as *purely* academic is at least as harsh as the strictures themselves IOW plagiarism is not about some kind of morality but about following some rules -- which are usually quite arbitrary. Heck even different free licenses quarrel about what constitutes right and wrong. And as a consequence of all this, courses and entire degrees in IP are becoming fashionable From rosuav at gmail.com Tue Jan 21 22:08:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 22 Jan 2014 14:08:25 +1100 Subject: Self healthcheck In-Reply-To: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> Message-ID: On Wed, Jan 22, 2014 at 1:51 PM, Asaf Las wrote: > When designing long running background process > is it feasible to monitor object/memory leakage due > to improper programming? I assume you're talking about pure Python code, running under CPython. (If you're writing an extension module, say in C, there are completely different ways to detect reference leaks; and other Pythons will behave slightly differently.) There's no way to detect truly unreferenced objects, because they simply won't exist - not after a garbage collection run, and usually sooner than that. But if you want to find objects that you're somehow not using and yet still have live references to, you'll need to define "using" in a way that makes sense. Generally there aren't many ways that that can happen, so those few places are candidates for a weak reference system (maybe you map a name to the "master object" representing that thing, and you can recreate the master object from the disk, so when nothing else is referring to it, you can happily flush it out - that mapping is a good candidate for weak references). But for most programs, don't bother. CPython is pretty good at keeping track of its own references, so chances are you don't need to - and if you're seeing the process's memory usage going up, it's entirely possible you can neither detect nor correct the problem in Python code (eg heap fragmentation). ChrisA From roy at panix.com Tue Jan 21 22:46:52 2014 From: roy at panix.com (Roy Smith) Date: Tue, 21 Jan 2014 22:46:52 -0500 Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <662f9a05-e3d3-448f-836b-beb12132d43f@googlegroups.com> <52df1619$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Rustom Mody wrote: > I was working in a large sw-development company some years ago. > One day unexpectedly I found I could not download any more the FOSS sw > I regularly use. What happened?? > > Evidently a programmer had copied GPL code off the net, passed it off > as his own, it had gone past the local company'a managers and been > detected by the off-shore client-company. Evidently a dose of GPLd > code is as salutary for the health of commercial sw companies as a > polonium capsule is for humans. Absolutely. Most open-source code comes with license restrictions. "You are free to use this, but if you do, you are obligated to do these things..." Certainly, GPL comes with obligations. If one of your employees grabs some GPL stuff off the net and puts it into your product, you are now obligated to do those things. Those may be obligations you're not willing to commit to. From ashish.u.panchal at googlemail.com Wed Jan 22 00:48:51 2014 From: ashish.u.panchal at googlemail.com (Ashish Panchal) Date: Wed, 22 Jan 2014 11:18:51 +0530 Subject: Diving in to Python - Best resources? Message-ID: The best resource I think is documentation provided by python http://docs.python.org/ If You need to learn python from scratch http://docs.python.org/tut/tut.html If you need a book for reference http://diveintopython3.ep.io/ -------------- next part -------------- An HTML attachment was scrubbed... URL: From jeandupont314 at gmail.com Wed Jan 22 02:23:31 2014 From: jeandupont314 at gmail.com (Jean Dupont) Date: Tue, 21 Jan 2014 23:23:31 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> Message-ID: <18bc0910-752c-4a34-a02c-61d6f6735cbd@googlegroups.com> Op maandag 20 januari 2014 07:24:31 UTC+1 schreef Chris Angelico: > On Mon, Jan 20, 2014 at 3:04 PM, Jean Dupont wrote: > > I started a thread "[newbie] starting geany from within idle does not > > work" both here and in the raspberry pi forum. I just wondered why I never > > got an answer concerning that topic. > I saw that thread. It looked like a R-Pi problem, not a Python one, so > I didn't respond because I don't have an R-Pi. If you get no response > on the R-Pi forum, you might want to see if you can duplicate the > issue on a desktop computer - preferably on Win/Mac/Lin, as those are > the platforms most people use. That, with exact steps to repro (which > it looks like you gave for the R-Pi, though again I can't verify), > would get some interest. I did try to do the same on my linux desktop computer, but the problem is, it has another desktop environment (KDE4). In the rpi-environment it is possible (but it doesn't work) to change the default IDLE-editor by right-clicking the idle-icon and choosing geany in stead of leafpad, however the same can't be done in KDE4, I hoped to find a similar setting once running IDLE in Options-->Configure IDLE, but nothing there neither. I also looked unsuccessfuly in the .idlerc-directory for a config-file. Hence my initial question. kind regards, jean From roegltd at gmail.com Wed Jan 22 03:18:16 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 00:18:16 -0800 (PST) Subject: Self healthcheck In-Reply-To: References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> Message-ID: <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> On Wednesday, January 22, 2014 5:08:25 AM UTC+2, Chris Angelico wrote: > I assume you're talking about pure Python code, running under CPython. > (If you're writing an extension module, say in C, there are completely > different ways to detect reference leaks; and other Pythons will > behave slightly differently.) There's no way to detect truly > unreferenced objects, because they simply won't exist - not after a > garbage collection run, and usually sooner than that. But if you want > to find objects that you're somehow not using and yet still have live > references to, you'll need to define "using" in a way that makes > sense. Generally there aren't many ways that that can happen, so those > few places are candidates for a weak reference system (maybe you map a > name to the "master object" representing that thing, and you can > recreate the master object from the disk, so when nothing else is > referring to it, you can happily flush it out - that mapping is a good > candidate for weak references). > > But for most programs, don't bother. CPython is pretty good at keeping > track of its own references, so chances are you don't need to - and if > you're seeing the process's memory usage going up, it's entirely > possible you can neither detect nor correct the problem in Python code > (eg heap fragmentation). > ChrisA Hi Chris Yes the question was about CPython. But i am not after CPython leaks though detecting these would be good, but my own mistakes leading to accumulation of data in mutable structures. there will be few processes running python code standalone communicating across servers and every activity will be spread over time so i have to persistently keep record of activity and remove it later when activity is finished. In addition to checking objects directly i would like to analyze also app health indirectly via checking amount of data it holds. let say there is permanently 100 activities per second and typical object count figure is 1000 (in abstract units averaged over long enough time window), so i would check throughput and memory to see if my program is healthy in terms of leaking resources and generate log if it is not. Input to such module will be traffic events (whatever event significant to object creation). So i am looking for proper way to detect memory held by CPython app. And it would be good if memory can be deduced down to object/class name so blamed one could be identified and reported. Thanks Asaf From wxjmfauth at gmail.com Wed Jan 22 03:18:36 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 22 Jan 2014 00:18:36 -0800 (PST) Subject: Early retirement project? In-Reply-To: References: <20140121053801.60f8cf11@bigbox.christie.dr> Message-ID: <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Le mardi 21 janvier 2014 18:34:44 UTC+1, Terry Reedy a ?crit?: > On 1/21/2014 6:38 AM, Tim Chase wrote: > > > On 2014-01-21 00:00, xeysxeys at gmail.com wrote: > > >> Well, I retired early, and I guess now I've got some spare time to > > >> learn about programming, which always seemed rather mysterious. I > > >> am using an old mac as my main computer, and it runs os x 10.4 is > > >> this too old? It fills my needs, and I am on a fixed income and > > >> can't really afford to buy another. I think python would be a good > > >> starter language, based on what I've read on the net. > > > > > > It's certainly a great way to consume lots of hours :) > > > > > > Mac OS X 10.4 should come with an older version of Python > > > out-of-the-box. > > > > Someone else said that it comes with 2.5. That will be fine for many > > purposed. If you do use that, always make any classes you define a > > subclass of 'object' if nothing else. In other words, > > > > class MyClass(object): ... > > # instead of > > class MyClass: ... > > > > In Python 2, the second gives you an 'old-style' or 'classic' class. You > > do not need to learn about those. In Python 3, both forms give you > > new-style classes, which is what you should learn. > > > > There are a few other obsolete features to avoid, such as using strings > > for exceptions. > > > > > The install media should also include XCode if you > > > want to download the latest & greatest version of Python and install > > > that from source instead. > > > > If you can do that easily, I recommend starting with the latest Python > > 3, especially if you want to work with non-English (non-ascii) characters. > > In fact, Python just becomes the last tool I (would) recommend, especially for non-ascii users. jmf From indarkumar59 at gmail.com Wed Jan 22 03:36:17 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 00:36:17 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: So my question is if I am giving multiple inputs(a new device say for example) in a loop and creating a database(dictionary) for each new devices for example. I want subsequent devices to save their data(values only not keys) to the database of each of the already existing devices. How can I do that? Any hint?I have been stuck here for 3 days. From indarkumar59 at gmail.com Wed Jan 22 03:39:48 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 00:39:48 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <87b41752-af6e-4785-ad01-6749cff10edf@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Pleae give example also. I will be thankful. From nicholas.cole at gmail.com Wed Jan 22 03:43:39 2014 From: nicholas.cole at gmail.com (Nicholas Cole) Date: Wed, 22 Jan 2014 08:43:39 +0000 Subject: Self healthcheck In-Reply-To: <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> Message-ID: On Wednesday, 22 January 2014, Asaf Las wrote: > On Wednesday, January 22, 2014 5:08:25 AM UTC+2, Chris Angelico wrote: > > I assume you're talking about pure Python code, running under CPython. > > (If you're writing an extension module, say in C, there are completely > > different ways to detect reference leaks; and other Pythons will > > behave slightly differently.) There's no way to detect truly > > unreferenced objects, because they simply won't exist - not after a > > garbage collection run, and usually sooner than that. But if you want > > to find objects that you're somehow not using and yet still have live > > references to, you'll need to define "using" in a way that makes > > sense. Generally there aren't many ways that that can happen, so those > > few places are candidates for a weak reference system (maybe you map a > > name to the "master object" representing that thing, and you can > > recreate the master object from the disk, so when nothing else is > > referring to it, you can happily flush it out - that mapping is a good > > candidate for weak references). > > > > But for most programs, don't bother. CPython is pretty good at keeping > > track of its own references, so chances are you don't need to - and if > > you're seeing the process's memory usage going up, it's entirely > > possible you can neither detect nor correct the problem in Python code > > (eg heap fragmentation). > > ChrisA > > Hi Chris > > Yes the question was about CPython. But i am not after CPython leaks > though detecting these would be good, but my own mistakes leading to > accumulation of data in mutable structures. > there will be few processes running python code standalone communicating > across servers and every activity will be spread over time so > i have to persistently keep record of activity and remove it later when > activity is finished. In addition to checking objects directly i would > like to analyze also app health indirectly via checking amount of data > it holds. let say there is permanently 100 activities per second and > typical object count figure is 1000 (in abstract units averaged over long > enough time window), so i would check throughput and memory to see if my > program is healthy in terms of leaking resources and generate log if it > is not. > Input to such module will be traffic events (whatever event significant > to object creation). > So i am looking for proper way to detect memory held by CPython app. And > it would be good if memory can be deduced down to object/class name so > blamed one could be identified and reported. > > There are some good tools recommended here: http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended But in general: use weak references wherever possible would be my advice. They not only prevent cycles but will highlight the kinds of bug in your code that is likely to cause the sort of problem you are worried about. -------------- next part -------------- An HTML attachment was scrubbed... URL: From frank at chagford.com Wed Jan 22 03:56:30 2014 From: frank at chagford.com (Frank Millman) Date: Wed, 22 Jan 2014 10:56:30 +0200 Subject: Self healthcheck References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> Message-ID: "Asaf Las" wrote in message news:58c541ab-c6e1-45a8-b03a-8597ed7ecb48 at googlegroups.com... > > Yes the question was about CPython. But i am not after CPython leaks > though detecting these would be good, but my own mistakes leading to > accumulation of data in mutable structures. > there will be few processes running python code standalone communicating > across servers and every activity will be spread over time so > i have to persistently keep record of activity and remove it later when > activity is finished. I had a similar concern. My main worry, which turned out to be well-founded, was that I would create an object as a result of some user input, but when the user had finished with it, and in theory it could be garbage-collected, in practice it would not be due to some obscure circular reference somewhere. For short-running tasks this is not a cause for concern, but for a long-running server these can build up over time and end up causing a problem. My solution was to log every time an object was created, with some self-identifying piece of information, and then log when it was deleted, with the same identifier. After running the program for a while I could then analyse the log and ensure that each creation had a corresponding deletion. The tricky bit was logging the deletion. It is a known gotcha in Python that you cannot rely on the __del__ method, and indeed it can cause a circular reference in itself which prevents the object from being garbage-collected. I found a solution somewhere which explained the use of a 'delwatcher' class. This is how it works - class MainObject: def __init__(self, identifier): self._del = delwatcher('MainObject', identifier) class delwatcher: def __init__(self, obj_type, identifier): self.obj_type = obj_type self.identifier = identifier log('{}: id={} created'.format(self.obj_type, self.identifier)) def __del__(self): log('{}: id={} deleted'.format(self.obj_type, self.identifier)) In this case calling __del__() is safe, as no reference to the main object is held. If you do find that an object is not being deleted, it is then trial-and-error to find the problem and fix it. It is probably a circular reference HTH Frank Millman From r.voigtlaender at gmail.com Wed Jan 22 04:38:37 2014 From: r.voigtlaender at gmail.com (=?ISO-8859-1?Q?Robert_Voigtl=E4nder?=) Date: Wed, 22 Jan 2014 01:38:37 -0800 (PST) Subject: which data structure to use? In-Reply-To: References: Message-ID: <92c348a4-f172-47ba-8656-8427f4da0054@googlegroups.com> > Unlikely. Are you sure that .heap and .lookup contents are still in sync > with your modification? No it's not. Atfer having read about heapq it's clear why. Thanks for the hint. > allows you to delete random nodes, but the lowest() method will slow down as > it has to iterate over all dict values. Thanks a lot for the alternative class. I will go with two lists, each using one of the aproaches. In one list I always need to have only hte object with lowest .f. With the other list I may have to delete random nodes. So I can make perfect use of both classes. > One important caveat: both Nodes classes lead to data corruption if you > modify a .pos attribute while the node is in a Nodes instance. The same goes > for the first implementation and the .f attribute. That's fine. pos is static and identifies the node. Thanks again to all who responded. I learned a lot. From breamoreboy at yahoo.co.uk Wed Jan 22 05:08:19 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Jan 2014 10:08:19 +0000 Subject: Separate Address number and name In-Reply-To: References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: On 22/01/2014 00:06, Shane Konings wrote: > The following is a sample of the data. There are hundreds of lines that need to have an automated process of splitting the strings into headings to be imported into excel with theses headings > See here for code that could simplify your extire task http://www.python-excel.org/ -- 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 Jan 22 05:10:56 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Jan 2014 10:10:56 +0000 Subject: Early retirement project? In-Reply-To: <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: On 22/01/2014 08:18, wxjmfauth at gmail.com wrote: To my knowledge you are one of only two people who refuse to remove double line spacing from google. Just how bloody minded are you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From robin at reportlab.com Wed Jan 22 05:49:29 2014 From: robin at reportlab.com (Robin Becker) Date: Wed, 22 Jan 2014 10:49:29 +0000 Subject: any wheel experts here? Message-ID: <52DFA239.4010508@chamonix.reportlab.co.uk> I'm trying to use --plat-name in python33 setup.py bdist_wheel --plat-name=win-amd64 I have a patched distutils package on my path that does allow me to do cross platform builds with normal distutils setup.py. However, I noticed immediately that my allegedly amd64 build is saying things like running bdist_wheel running build running build_py copying src\reportlab\lib\hyphen.mashed -> build\lib.win32-3.3\reportlab\lib running build_ext installing to build\bdist.win32\wheel running install running install_lib creating build\bdist.win32\wheel creating build\bdist.win32\wheel\reportlab creating build\bdist.win32\wheel\reportlab\fonts and later on it crashes with Traceback (most recent call last): File "setup.py", line 541, in main() File "setup.py", line 530, in main ext_modules = EXT_MODULES, File "c:\ux\ExeBuilder\py33\distutils\core.py", line 148, in setup dist.run_commands() File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 929, in run_commands self.run_command(cmd) File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 948, in run_command cmd_obj.run() File "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line 207, in run archive_basename = self.get_archive_basename() File "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line 156, in get_archive_basename impl_tag, abi_tag, plat_tag = self.get_tag() File "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line 150, in get_tag assert tag == supported_tags[0] AssertionError so I guess that wheel doesn't support the idea of cross platform building on windows. Can anyone more on the bleeding edge confirm this? I can guess that somewhere in wheel the plat-name argument is not being passed on to distutils bdist, but in addition something about the platform name is causing the crash later on. -- Robin Becker From oscar.j.benjamin at gmail.com Wed Jan 22 06:01:32 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Wed, 22 Jan 2014 11:01:32 +0000 Subject: any wheel experts here? In-Reply-To: <52DFA239.4010508@chamonix.reportlab.co.uk> References: <52DFA239.4010508@chamonix.reportlab.co.uk> Message-ID: <20140122110129.GB2555@gmail.com> On Wed, Jan 22, 2014 at 10:49:29AM +0000, Robin Becker wrote: > I'm trying to use --plat-name in > > python33 setup.py bdist_wheel --plat-name=win-amd64 > > I have a patched distutils package on my path that does allow me to > do cross platform builds with normal distutils setup.py. > > However, I noticed immediately that my allegedly amd64 build is saying things like > > running bdist_wheel > running build > running build_py > copying src\reportlab\lib\hyphen.mashed -> build\lib.win32-3.3\reportlab\lib > running build_ext > installing to build\bdist.win32\wheel > running install > running install_lib > creating build\bdist.win32\wheel > creating build\bdist.win32\wheel\reportlab > creating build\bdist.win32\wheel\reportlab\fonts > > and later on it crashes with > > Traceback (most recent call last): > File "setup.py", line 541, in > main() > File "setup.py", line 530, in main > ext_modules = EXT_MODULES, > File "c:\ux\ExeBuilder\py33\distutils\core.py", line 148, in setup > dist.run_commands() > File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 929, in run_commands > self.run_command(cmd) > File "c:\ux\ExeBuilder\py33\distutils\dist.py", line 948, in run_command > cmd_obj.run() > File > "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line > 207, in run > archive_basename = self.get_archive_basename() > File > "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line > 156, in get_archive_basename > impl_tag, abi_tag, plat_tag = self.get_tag() > File > "C:\code\hg-repos\py33\lib\site-packages\wheel\bdist_wheel.py", line > 150, in get_tag > assert tag == supported_tags[0] > AssertionError > > so I guess that wheel doesn't support the idea of cross platform > building on windows. Can anyone more on the bleeding edge confirm > this? In principle the wheel format support any kind of cross-building. It's possible though that the current wheel library has a bug that prevents this somehow or that you've monkeypatched distutils/setuptools in such a way that isn't compatible with bdist_wheel. It may be that the bdist_wheel command itself does not support cross-building but the wheel format certainly does, and perhaps the wheel library does if you import it directly. > I can guess that somewhere in wheel the plat-name argument is not > being passed on to distutils bdist, but in addition something about > the platform name is causing the crash later on. Sounds reasonable. I don't know the answer or whether anyone else on this list will but you can definitely find the relevant developers at this mailing list: https://mail.python.org/mailman/listinfo/distutils-sig/ Oscar From lgabiot at hotmail.com Wed Jan 22 06:01:50 2014 From: lgabiot at hotmail.com (lgabiot) Date: Wed, 22 Jan 2014 12:01:50 +0100 Subject: Using a static library in a C extension for Python Message-ID: <52dfa51e$0$3621$426a74cc@news.free.fr> Hello, working on OS X 10.8.5 Python 2.7 I've written a simple C extension for Python that uses the cairo graphic library. It works well, and I can call it from Python with no problem. The only drawback is that I need to have the cairo library installed on my system (so it seems my extension calls dynamically the cairo library). I believe this because it doesn't work on a system where cairo is not installed. Is it possible to link statically cairo to my extension, so that even if cairo is not installed on a computer, the code will run? I guess I would need to modify the setup.py file using distutils to compile cairo statically into my .so file? Or am I completely wrong? If someone has a hint... thanks! From davea at davea.name Wed Jan 22 07:08:04 2014 From: davea at davea.name (Dave Angel) Date: Wed, 22 Jan 2014 07:08:04 -0500 (EST) Subject: [newbie] advice and comment wanted on first tkinter program References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> <18bc0910-752c-4a34-a02c-61d6f6735cbd@googlegroups.com> Message-ID: Jean Dupont Wrote in message: > Op maandag 20 januari 2014 07:24:31 UTC+1 schreef Chris Angelico: >> On Mon, Jan 20, 2014 at 3:04 PM, Jean Dupont wrote: >> > I started a thread "[newbie] starting geany from within idle does not >> > work" > I did try to do the same on my linux desktop computer, but the problem is, > it has another desktop environment (KDE4). In the rpi-environment it is > possible > (but it doesn't work) to change the default IDLE-editor by right-clicking > the idle-icon and choosing geany in stead of leafpad, however the same > can't be done > in KDE4, I hoped to find a similar setting once running IDLE in > Options-->Configure IDLE, but nothing there neither. I also looked > unsuccessfuly in the .idlerc-directory for a config-file. Hence my initial > question. > What does idle offer that Geary does not? Why not just run Geary from your terminal prompt? > -- DaveA From neilc at norwich.edu Wed Jan 22 08:34:27 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 22 Jan 2014 13:34:27 +0000 (UTC) Subject: Can post a code but afraid of plagiarism References: <52db7142$0$29999$c3e8da3$5496439d@news.astraweb.com> <52df15ff$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 2014-01-22, Steven D'Aprano wrote: > Do you notice the assumption made? Let me highlight it for you: > > THE WORDS OF OTHERS > > The hidden assumption here is that *words are property*, that > they belong to whomever first publishes them. Having now > written those few words, nobody else is permitted to use those > same words in the same order without crediting me. Failure to > credit me is a sin of the highest order, enough to get you > kicked out of your university, your name blackened. Unless, of > course, somebody else wrote those words before me, in which > case *my ignorance* of that earlier usage does not diminish the > magnitude of my sin. In that regard, plagiarism is rather like > patent infringement. >From The Cemetery Gates, The Smiths: You say, "Ere thrice the sun done salutation to to the dawn," and you claim these words as your own. But I've read well and I've heard them said one hundred times maybe less maybe more. [...] You say, "Ere long done do does did;" words which could only be your own, and then produce a text from whence it was ripped [...] When grading essays my wife is far more likely to detect the first case. > We do not know how strict the OP's college is about so-called > plagiarism, whether they only intend to come down on outright > copying of significant bodies of code, or whether they have a > tendency to go after trivial borrowing of simple idioms or > minor duplication of insignificant portions of the program. (If > I walk a linked list using mynode = mynode.next, and you use > the same variable names, is that an indication of copying?) > Without knowing what the OP's college considers plagiarism, how > can judge the OP's reaction to it? Obvious copying of another person's program, nearly verbatim, is most likely to be detected. Well, that and submitting one of the entrapment-purposed answers that are sometimes made availalbe here and elsewhere. -- Neil Cerutti From neilc at norwich.edu Wed Jan 22 08:39:56 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Wed, 22 Jan 2014 13:39:56 +0000 (UTC) Subject: Early retirement project? References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: On 2014-01-22, wxjmfauth at gmail.com wrote: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. Have a care, jmf. People unfamiliar with your opinions might take that seriously. -- Neil Cerutti From larry.martell at gmail.com Wed Jan 22 08:45:34 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 22 Jan 2014 06:45:34 -0700 Subject: Early retirement project? In-Reply-To: <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: On Wed, Jan 22, 2014 at 1:18 AM, wrote: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. That's right - only Americans should use Python! From rustompmody at gmail.com Wed Jan 22 08:56:06 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jan 2014 05:56:06 -0800 (PST) Subject: Early retirement project? In-Reply-To: References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: <208c0aac-7ed0-48cf-a43b-4c74691d95b4@googlegroups.com> On Wednesday, January 22, 2014 7:15:34 PM UTC+5:30, Larry wrote: > On Wed, Jan 22, 2014 at 1:18 AM, wrote: > > In fact, Python just becomes the last tool I (would) > > recommend, especially for non-ascii users. > That's right - only Americans should use Python! Of whom the firstest and worstest is Guido v Rossum From rustompmody at gmail.com Wed Jan 22 09:17:33 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jan 2014 06:17:33 -0800 (PST) Subject: any wheel experts here? In-Reply-To: References: <52DFA239.4010508@chamonix.reportlab.co.uk> Message-ID: <0c89048c-ae60-42b3-b737-a6d82ff8fe32@googlegroups.com> On Wednesday, January 22, 2014 4:31:32 PM UTC+5:30, Oscar Benjamin wrote: > Sounds reasonable. I don't know the answer or whether anyone else on this list > will but you can definitely find the relevant developers at this mailing list: > https://mail.python.org/mailman/listinfo/distutils-sig/ I believe the wheel/pip/virtualenv guys are on this list https://groups.google.com/forum/#!forum/python-virtualenv From breamoreboy at yahoo.co.uk Wed Jan 22 09:28:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Jan 2014 14:28:00 +0000 Subject: Early retirement project? In-Reply-To: <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: On 22/01/2014 08:18, wxjmfauth at gmail.com wrote: > > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. > https://www.youtube.com/watch?v=7aItpjF5vXc dedicated to jmf and his knowledge of unicode and Python. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From jeandupont115 at gmail.com Wed Jan 22 09:45:53 2014 From: jeandupont115 at gmail.com (Jean Dupont) Date: Wed, 22 Jan 2014 06:45:53 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> Message-ID: <45d3da88-7881-49be-b35f-b579350e12d3@googlegroups.com> Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister: > On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: > > > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: > >> On 18 January 2014 14:52, Jean Dupont wrote: > >> > > >> > Thanks Peter and Terry Jan for the useful suggestions. One thing > >> > which I > >> >find a bit weird: when asking for Python-help concerning raspberry pi > >> >code > >> > or problems, a lot of people don't seem to be interested in helping > >> > out, > >> > that's of course their choice, but maybe they don't seem to be aware > >> > the raspberry pi is often the motivation for starting to learn to > >> > program in > >> >Python. And as such such a reaction is a bit disappointing. > >> Hi Jean, > >> What makes you say that? Did you previously ask questions about > >> Rasberry Pi code on this list? > > It was not about code but about python-coding in IDLE (that's the > > default on raspbian): > > I started a thread "[newbie] starting geany from within idle does not > > work" both here and in the raspberry pi forum. I just wondered why I > > never got an answer concerning that topic. > > > >> If you did I wouldn't have answered those questions because I've never > >> used a Raspberry Pi and know nothing about them (except that they > >> encourage using Python somehow). I think that there's actually a list > >> that is specifically for Raspberry Pi Python questions that might be > >> more helpful although I don't know what it is... > > Here is the url to that forum > > > > http://www.raspberrypi.org/forum/ > > > > kind regards, > > jean > > Personally use Geany stand alone and not under idle, pressing F5 should > save & run the code you are currently editing. Would running under idle > give any other benefits? I don't know yet, but I just wanted to try out which of the following three I'd like best: 1. idle+leafpad 2. idle+geany 3. plain geany It's normal for a newbie to start with (1) as that is the default on raspbian, however I still don't understand why (2) does not work... kind regards, jean From denismfmcmahon at gmail.com Wed Jan 22 10:40:27 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 22 Jan 2014 15:40:27 +0000 (UTC) Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: On Tue, 21 Jan 2014 15:49:16 -0800, Shane Konings wrote: > I have the following sample from a data set and I am looking to split > the address number and name into separate headings as seen below. > > FarmID Address 1 1067 Niagara Stone 2 4260 Mountainview 3 25 Hunter 4 > 1091 Hutchinson 5 5172 Green Lane 6 500 Glenridge 7 471 Foss 8 758 > Niagara Stone 9 3836 Main 10 1025 York > > > FarmID AddressNum AddressName 1 1067 Niagara Stone 2 4260 > Mountainview 3 25 Hunter 4 1091 Hutchinson 5 > 5172 Green Lane 6 500 Glenridge 7 471 Foss > 8 758 Niagara Stone 9 3836 Main 10 1025 York > > I have struggled with this for a while and know there must be a simple > method to achieve this result. Unfortunately the vagaries of nntp, my client and the google nntp posting host are such that I can't discern the format of your data from your post. However, if as I think you have a text field that is always: <1 or more digits><1 or more spaces> where you want to capture the initial "1 or more digits" and "the rest" as 2 data elements then this should be possible with a simple re: (\d+)\s+(.*) If you have numeric id, whitespace, numeric addr bit, whitespace, the rest, then you may need something more like: (\d+)\s+(\d+)\s+(.*) The assumption is that it's not necessary to hold your hand through the whole looping through the input and applying the re to each line, then reading the captured bits and using them process. -- Denis McMahon, denismfmcmahon at gmail.com From alister.ware at ntlworld.com Wed Jan 22 10:43:21 2014 From: alister.ware at ntlworld.com (Alister) Date: Wed, 22 Jan 2014 15:43:21 GMT Subject: [newbie] advice and comment wanted on first tkinter program References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> <45d3da88-7881-49be-b35f-b579350e12d3@googlegroups.com> Message-ID: On Wed, 22 Jan 2014 06:45:53 -0800, Jean Dupont wrote: > Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister: >> On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: >> >> > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: >> >> On 18 January 2014 14:52, Jean Dupont >> >> wrote: >> >> > >> >> > Thanks Peter and Terry Jan for the useful suggestions. One thing >> >> > which I >> >> >find a bit weird: when asking for Python-help concerning raspberry >> Personally use Geany stand alone and not under idle, pressing F5 >> should save & run the code you are currently editing. Would running >> under idle give any other benefits? > I don't know yet, but I just wanted to try out which of the following > three I'd like best: > 1. idle+leafpad 2. idle+geany 3. plain geany > > It's normal for a newbie to start with (1) as that is the default on > raspbian, > however I still don't understand why (2) does not work... > When I play with my Pi I tend to use another computer for all my editing (sshfs is a quick & easy way for me to mount the necessary parts of the PI file system so I don't have to keep transferring files) -- People in general do not willingly read if they have anything else to amuse them. -- S. Johnson From roegltd at gmail.com Wed Jan 22 10:51:39 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 07:51:39 -0800 (PST) Subject: Self healthcheck In-Reply-To: References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> Message-ID: On Wednesday, January 22, 2014 10:43:39 AM UTC+2, Nicholas wrote: > There are some good tools recommended here:? > http://stackoverflow.com/questions/110259/which-python-memory-profiler-is-recommended > ?But in general: use weak references wherever possible would be > my advice. They not only prevent cycles but will highlight the > kinds of bug in your code that is likely to cause the sort of > problem you are worried about. Thanks! i will look into these! From roegltd at gmail.com Wed Jan 22 11:03:53 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 08:03:53 -0800 (PST) Subject: Self healthcheck In-Reply-To: References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> Message-ID: <9729ddaa-5976-4e53-8584-6198b47b6789@googlegroups.com> On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote: > > class MainObject: > def __init__(self, identifier): > self._del = delwatcher('MainObject', identifier) > class delwatcher: > def __init__(self, obj_type, identifier): > self.obj_type = obj_type > self.identifier = identifier > log('{}: id={} created'.format(self.obj_type, self.identifier)) > def __del__(self): > log('{}: id={} deleted'.format(self.obj_type, self.identifier)) > If you do find that an object is not being deleted, it is then > trial-and-error to find the problem and fix it. It is probably a circular > reference > > Frank Millman Thanks Frank. Good approach! One question - You could do: class MainObject: def __init__(self, identifier): self._del = delwatcher(self) then later class delwatcher: def __init__(self, tobject): self.obj_type = type(tobject) self.identifier = id(tobject) ... when creating delwatcher. Was there special reason to not to use them? is this because of memory is reused when objects are deleted and created again so same reference could be for objects created in different time slots? Thanks Asaf From roegltd at gmail.com Wed Jan 22 11:07:47 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 08:07:47 -0800 (PST) Subject: SIngleton from __defaults__ Message-ID: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Hi Inspired by "Modifying the default argument of function" https://groups.google.com/forum/#!topic/comp.lang.python/1xtFE6uScaI is it possible to create singleton using construct below : def singleton_provider(x = [None]): if singleton_provider.__defaults__[0][0] == None: singleton_provider.__defaults__[0][0] = SomeClass() return singleton_provider.__defaults__[0][0] and question - how to make it work in multithreaded app when multiple threads are racing to create it first? Thanks Asaf From rosuav at gmail.com Wed Jan 22 11:18:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 03:18:57 +1100 Subject: SIngleton from __defaults__ In-Reply-To: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > is it possible to create singleton using construct below : > > def singleton_provider(x = [None]): > if singleton_provider.__defaults__[0][0] == None: > singleton_provider.__defaults__[0][0] = SomeClass() > return singleton_provider.__defaults__[0][0] > Why not simply: def get_singleton(x = SomeClass()): return x Or even: singleton = SomeClass() ? Neither of the above provides anything above the last one, except for late creation. ChrisA From indarkumar59 at gmail.com Wed Jan 22 11:33:30 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 08:33:30 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Description of each of the commands: ? config ? Parameters: ? is the host's ARP cache timeout, in seconds ? Actions: ? Update simulator's configuration database. ? If already exists, its information should be updated. Otherwise, it should be added. ? Print ? connected.? ? Have the host send a gratuitous ARP request . ? If any other hosts have an outdated entry for the MAC or IP address, they should update their caches. ? If there are any responses to that request, that means that somebody else has this IP address. If that is the case, you should print: Error: detected IP address conflict. It will be disconnected. Then, you should ?disconnect? the host from the simulated network, in order to prevent further problems. You can implement this by removing it from the configuration database. ? Note: any ARP packets generated by the command should be printed in the previously specified format Sample Output: config Please enter PC1 01:01:01:01:01:01 192.168.0.1 200 PC1 connected. ARP request 01:01:01:01:01:01 FF:FF:FF:FF:FF:FF 192.168.0.1 192.168.0.1 From roegltd at gmail.com Wed Jan 22 11:37:36 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 08:37:36 -0800 (PST) Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > > Why not simply: > def get_singleton(x = SomeClass()): > return x > Or even: > singleton = SomeClass() > ? Neither of the above provides anything above the last one, except > for late creation. > > ChrisA Actually need was to have some interface to running independent threads to give same and once created object always. For first - SomeClass's object will be created whenever there will be call to get_singleton(). For second, again it is free to create it whenever someone (thread) wish. Hmmm, use case was to create persistent counter in multithreaded app accessing single file where incrementing integer is stored. When my imagination expanded it onto multiprocessing mess i ended up using sqlite access to DB in exclusive transaction mode. But this was not pythonic :-) Asaf From indarkumar59 at gmail.com Wed Jan 22 11:46:13 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 08:46:13 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <9f32fbc3-63f2-4b0f-b9b1-f25511be98b5@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public This is a gratuitous arp request http://wiki.wireshark.org/Gratuitous_ARP sent by PC1 is informing other hosts of its MAC and IP addresses. Any hosts already in existence have their caches updated as needed. The first config call has no other hosts to update, so all it does is create a dictionary entry with its host id as the key. Its cache table is created as an empty dictionary. Subsequent config call update all other hosts' cache tables. Each host has its own ARP cache table. From rustompmody at gmail.com Wed Jan 22 11:48:12 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jan 2014 08:48:12 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <0c2bb189-d031-45ac-9e98-d864cebdc57c@googlegroups.com> On Wednesday, January 22, 2014 2:06:17 PM UTC+5:30, indar kumar wrote: > So my question is if I am giving multiple inputs(a new device say > for example) in a loop and creating a database(dictionary) for each > new devices for example. I want subsequent devices to save their > data(values only not keys) to the database of each of the already > existing devices. How can I do that? Any hint?I have been stuck here > for 3 days. I suggest that for starters you forget about (real) DBMSes and just use some lightweight data storage. Some examples of these: 1. json 2. yaml 3. pickle 4. ini file [I like yaml best but it needs to be installed] Second I suggest you forget about your assignment/problem, and just practice getting python data structures -- mainly lists and dicts into your chosen format. Third forget about the above and just solve the problem with internal python data structures. Then come back here and ask! From indarkumar59 at gmail.com Wed Jan 22 11:50:58 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 08:50:58 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <825d1da9-87ad-4ec9-9144-ff4e09f5a823@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public I need to implement this with simple dictionarie. I know use of dictionaries, lists and tuples. But, I am not able to create a logic in a loop. I mean how the other hosts would get MAC and IP of subsequent hosts in each turn. From indarkumar59 at gmail.com Wed Jan 22 11:53:02 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 08:53:02 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Any link related to such type of problems or logic would be helpful From indarkumar59 at gmail.com Wed Jan 22 12:09:07 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 09:09:07 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <5e6ffc86-b008-4aa1-b176-006342ffee28@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Just one hint and I have made the design for whole code. Just stuck at this part From dihedral88888 at gmail.com Wed Jan 22 12:23:02 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Wed, 22 Jan 2014 09:23:02 -0800 (PST) Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: On Thursday, January 23, 2014 12:37:36 AM UTC+8, Asaf Las wrote: > On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > > > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > > > > > > Why not simply: > > > def get_singleton(x = SomeClass()): > > > return x > > > Or even: > > > singleton = SomeClass() > > > ? Neither of the above provides anything above the last one, except > > > for late creation. > > > > > > ChrisA > > > > Actually need was to have some interface to running independent threads > > to give same and once created object always. > > > > For first - SomeClass's object will be created whenever there will be > > call to get_singleton(). > > For second, again it is free to create it whenever someone (thread) > > wish. > > > > Hmmm, use case was to create persistent counter in multithreaded app > > accessing single file where incrementing integer is stored. > > When my imagination expanded it onto multiprocessing mess i ended up > > using sqlite access to DB in exclusive transaction mode. > > But this was not pythonic :-) > > > > Asaf In a high level language such as Python, functions and class initilizers are the first class objects. Don't you get the proof? Everyting OOP is equivalent to everything functional but it is much trivial to debug by the designer than the old grandma lisp. From dihedral88888 at gmail.com Wed Jan 22 12:31:04 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Wed, 22 Jan 2014 09:31:04 -0800 (PST) Subject: Using a static library in a C extension for Python In-Reply-To: <52dfa51e$0$3621$426a74cc@news.free.fr> References: <52dfa51e$0$3621$426a74cc@news.free.fr> Message-ID: <0510fa5b-41aa-4337-9e36-c851bc83426a@googlegroups.com> On Wednesday, January 22, 2014 7:01:50 PM UTC+8, lgabiot wrote: > Hello, > > > > working on OS X 10.8.5 > > Python 2.7 > > > > I've written a simple C extension for Python that uses the cairo graphic > > library. > > It works well, and I can call it from Python with no problem. > > The only drawback is that I need to have the cairo library installed on > > my system (so it seems my extension calls dynamically the cairo library). > > I believe this because it doesn't work on a system where cairo is not > > installed. > > > > Is it possible to link statically cairo to my extension, so that even if > > cairo is not installed on a computer, the code will run? > > > > I guess I would need to modify the setup.py file using distutils to > > compile cairo statically into my .so file? > > > > Or am I completely wrong? > > > > If someone has a hint... > > > > thanks! Check the C source code generated by Pyrex and check cython for what u want, but I did try that out in any mobile phone or flat panel programming. From denismfmcmahon at gmail.com Wed Jan 22 12:35:22 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 22 Jan 2014 17:35:22 +0000 (UTC) Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: On Tue, 21 Jan 2014 16:06:56 -0800, Shane Konings wrote: > The following is a sample of the data. There are hundreds of lines that > need to have an automated process of splitting the strings into headings > to be imported into excel with theses headings > > ID Address StreetNum StreetName SufType Dir City Province > PostalCode Ok, the following general method seems to work: First, use a regex to capture two numeric groups and the rest of the line separated by whitespace. If you can't find all three fields, you have unexpected data format. re.search( r"(\d+)\s+(\d+)\s+(.*)", data ) Second, split the rest of the line on a regex of comma + 0 or more whitespace. re.split( r",\s+", data ) Check that the rest of the line has 3 or 4 bits, otherwise you have an unexpected lack or excess of data fields. Split the first bit of the rest of the line into street name and suffix/ type. If you can't split it, use it as the street name and set the suffix/ type to blank. re.search( r"(.*)\s+(\w+)", data ) If there are 3 bits in rest of line, set direction to blank, otherwise set direction to the second bit. Set the city to the last but one bit of the rest of the line. Capture one word followed by two words in the last bit of the rest of the line, and use these as the province and postcode. re.search( r"(\w+)\s+(\w+\s+\w+)", data ) Providing none of the searches or the split errored, you should now have the data fields you need to write. The easiest way to write them might be to assemble them as a list and use the csv module. I'm assuming you're capable of working out from the help on the python re module what to use for each data, and how to access the captured results of a search, and the results of a split. I'm also assuming you're capable of working out how to use the csv module from the documentation. If you're not, then either go back and ask your lecturer for help, or tell your boss to hire a real programmer for his quick and easy coding jobs. -- Denis McMahon, denismfmcmahon at gmail.com From filippo.biolcati at googlemail.com Wed Jan 22 13:09:30 2014 From: filippo.biolcati at googlemail.com (Philip Red) Date: Wed, 22 Jan 2014 10:09:30 -0800 (PST) Subject: No overflow in variables? Message-ID: Hi everyone. First of all sorry if my english is not good. I have a question about something in Python I can not explain: in every programming language I know (e.g. C#) if you exceed the max-value of a certain type (e.g. a long-integer) you get an overflow. Here is a simple example in C#: static void Main(string[] args) { Int64 x = Int64.MaxValue; Console.WriteLine(x); // output: 9223372036854775807 x = x * 2; Console.WriteLine(x); // output: -2 (overflow) Console.ReadKey(); } Now I do the same with Python: x = 9223372036854775807 print(type(x)) # x = x * 2 # 18446744073709551614 print(x) # print(type(x)) and I get the right output without overflow and the type is always a 'int'. How does Python manages internally the types and their values? Where are they stored? Thank you for your help :) From larry.martell at gmail.com Wed Jan 22 13:18:55 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 22 Jan 2014 11:18:55 -0700 Subject: No overflow in variables? In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 11:09 AM, Philip Red wrote: > Hi everyone. First of all sorry if my english is not good. > I have a question about something in Python I can not explain: > in every programming language I know (e.g. C#) if you exceed the max-value of a certain type (e.g. a long-integer) you get an overflow. Here is a simple example in C#: > > static void Main(string[] args) > { > Int64 x = Int64.MaxValue; > Console.WriteLine(x); // output: 9223372036854775807 > x = x * 2; > Console.WriteLine(x); // output: -2 (overflow) > Console.ReadKey(); > } > > Now I do the same with Python: > > x = 9223372036854775807 > print(type(x)) # > x = x * 2 # 18446744073709551614 > print(x) # > print(type(x)) > > and I get the right output without overflow and the type is always a 'int'. > How does Python manages internally the types and their values? Where are they stored? > > Thank you for your help :) This may help you understand: http://www.python.org/dev/peps/pep-0237/ From davea at davea.name Wed Jan 22 13:26:36 2014 From: davea at davea.name (Dave Angel) Date: Wed, 22 Jan 2014 13:26:36 -0500 (EST) Subject: No overflow in variables? References: Message-ID: Philip Red Wrote in message: > Hi everyone. First of all sorry if my english is not good. > I have a question about something in Python I can not explain: > in every programming language I know (e.g. C#) if you exceed the max-value of a certain type (e.g. a long-integer) you get an overflow. Here is a simple example in C#: > > static void Main(string[] args) > { > Int64 x = Int64.MaxValue; > Console.WriteLine(x); // output: 9223372036854775807 > x = x * 2; > Console.WriteLine(x); // output: -2 (overflow) > Console.ReadKey(); > } > > Now I do the same with Python: > > x = 9223372036854775807 > print(type(x)) # > x = x * 2 # 18446744073709551614 > print(x) # > print(type(x)) > > and I get the right output without overflow and the type is always a 'int'. > How does Python manages internally the types and their values? Where are they stored? > > Thank you for your help :) > In python, every value is an object. Some, like lists, can grow over time, and there's no specific upper limit in size. Others, like int, or string, are immutable, so the constructor can calculate just how much space is needed. In java, and I believe in C#, they make a distinction between unboxed and boxed integers. The former are NOT objects, and have a specific upper bound, generally based on some power of 2. -- DaveA From piet at vanoostrum.org Wed Jan 22 13:28:57 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 22 Jan 2014 19:28:57 +0100 Subject: Early retirement project? References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: wxjmfauth at gmail.com writes: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. > > jmf In fact, Python 3 is one of the best programming tools for non-ASCII users. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From rosuav at gmail.com Wed Jan 22 13:26:14 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 05:26:14 +1100 Subject: No overflow in variables? In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 5:09 AM, Philip Red wrote: > Now I do the same with Python: > > x = 9223372036854775807 > print(type(x)) # > x = x * 2 # 18446744073709551614 > print(x) # > print(type(x)) > > and I get the right output without overflow and the type is always a 'int'. > How does Python manages internally the types and their values? Where are they stored? The Python integer type stores arbitrary precision. It's not a machine word, like the C# integer types (plural, or does it have only one? Either way), so it can store any integer you have RAM for. (Which means, no, Python cannot represent Graham's Number in an int. Sorry about that.) Internally, I believe CPython uses the GNU Multiprecision Library (GMP), which gives an efficient representation and operation format, scaling to infinity or thereabouts. You can go to any size of integer you like without there being any difference. There's a cost to that (even small integers are a bit slower to work with), but it's SO helpful to be able to work with arbitrarily large numbers that it's worth that cost. (Side note: In Python 2, small integers were represented by type 'int' and those too big to fit into a machine word were automatically promoted to type 'long'. Python 3 abolished 'int' and renamed 'long' to 'int', giving what you see here. I'm of the opinion that small-number arithmetic could be optimized by having small ints stored as machine words instead of as GMP objects (which could be done invisibly), but it may be that the complexity isn't worth it.) I first met arbitrary-precision arithmetic in REXX, back in the 1990s. It wasn't anything like as efficient as it is now, so for performance it was important to set the NUMERIC DIGITS setting to just what you need and no more. Today, thanks to GMP, any high level language should be able to offer the same as Python does; in fact, I'd consider infinite-precision integers to be among the fundamental and critical aspects of any modern high level language (along with object reference semantics, first-class arrays/mappings/functions/etc, native true Unicode strings, BSD socket services, and cross-platform support with a bare minimum of *ix/Win/Mac). There's just no point restricting it to a machine word, especially since "machine word" varies from machine to machine. Incidentally, if you specifically *want* wrap-around behaviour, you can perform modulo arithmetic. Store everything as unsigned, and after every operation, take the value modulo 2**64; then for display, if you need it to be signed, check if it's >= 2**63, and if so, subtract 2**64. (Or use 32, 31, and 32, or whatever word size you want.) That's a decent simulation of a simple twos-comp integer. ChrisA From filippo.biolcati at googlemail.com Wed Jan 22 13:32:04 2014 From: filippo.biolcati at googlemail.com (Philip Red) Date: Wed, 22 Jan 2014 10:32:04 -0800 (PST) Subject: No overflow in variables? In-Reply-To: References: Message-ID: <77843ceb-716e-4925-a183-f769c1b630ad@googlegroups.com> Thank you for your answers! From davea at davea.name Wed Jan 22 13:40:21 2014 From: davea at davea.name (Dave Angel) Date: Wed, 22 Jan 2014 13:40:21 -0500 (EST) Subject: Self healthcheck References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> <9729ddaa-5976-4e53-8584-6198b47b6789@googlegroups.com> Message-ID: Asaf Las Wrote in message: > On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote: >> >> class MainObject: >> def __init__(self, identifier): >> self._del = delwatcher('MainObject', identifier) >> class delwatcher: >> def __init__(self, obj_type, identifier): >> self.obj_type = obj_type >> self.identifier = identifier >> log('{}: id={} created'.format(self.obj_type, self.identifier)) >> def __del__(self): >> log('{}: id={} deleted'.format(self.obj_type, self.identifier)) >> If you do find that an object is not being deleted, it is then >> trial-and-error to find the problem and fix it. It is probably a circular >> reference >> >> Frank Millman > > Thanks Frank. Good approach! > > One question - You could do: > class MainObject: > def __init__(self, identifier): > self._del = delwatcher(self) > then later > > class delwatcher: > def __init__(self, tobject): > self.obj_type = type(tobject) > self.identifier = id(tobject) > ... > > when creating delwatcher. Was there special reason to not to use them? > is this because of memory is reused when objects are deleted > and created again so same reference could be for objects created > in different time slots? > I couldn't make sense of most of that. But an ID only uniquely corresponds to an object while that object still exists. The system may, and will, reuse iD's constantly. -- DaveA From filippo.biolcati at googlemail.com Wed Jan 22 13:48:01 2014 From: filippo.biolcati at googlemail.com (Philip Red) Date: Wed, 22 Jan 2014 10:48:01 -0800 (PST) Subject: No overflow in variables? In-Reply-To: References: Message-ID: <734002b1-c400-4f11-b7d7-71d701f6a773@googlegroups.com> Thank you ChrisA From ned at nedbatchelder.com Wed Jan 22 14:18:19 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 22 Jan 2014 14:18:19 -0500 Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: On 1/22/14 11:37 AM, Asaf Las wrote: > On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: >> On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: >> >> Why not simply: >> def get_singleton(x = SomeClass()): >> return x >> Or even: >> singleton = SomeClass() >> ? Neither of the above provides anything above the last one, except >> for late creation. >> >> ChrisA > > Actually need was to have some interface to running independent threads > to give same and once created object always. > > For first - SomeClass's object will be created whenever there will be > call to get_singleton(). No, the value for a function argument's default is computed once when the function is defined. Chris is right: get_singleton will always return the same object. > For second, again it is free to create it whenever someone (thread) > wish. Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. > > Hmmm, use case was to create persistent counter in multithreaded app > accessing single file where incrementing integer is stored. > When my imagination expanded it onto multiprocessing mess i ended up > using sqlite access to DB in exclusive transaction mode. > But this was not pythonic :-) > > Asaf > -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Wed Jan 22 14:19:20 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Wed, 22 Jan 2014 14:19:20 -0500 Subject: Can post a code but afraid of plagiarism In-Reply-To: <5e6ffc86-b008-4aa1-b176-006342ffee28@googlegroups.com> References: <5e6ffc86-b008-4aa1-b176-006342ffee28@googlegroups.com> Message-ID: On 1/22/14 12:09 PM, indar kumar wrote: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: >> Hi, >> >> >> >> I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public > > Just one hint and I have made the design for whole code. Just stuck at this part > You should collect all your thoughts and write one message, not six in 30 minutes. That's just pestering. -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Wed Jan 22 14:23:55 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 22 Jan 2014 19:23:55 +0000 Subject: awesome slugify and unicode Message-ID: I thought this blog might interest some of you http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From lgabiot at hotmail.com Wed Jan 22 14:22:52 2014 From: lgabiot at hotmail.com (lgabiot) Date: Wed, 22 Jan 2014 20:22:52 +0100 Subject: Using a static library in a C extension for Python In-Reply-To: <0510fa5b-41aa-4337-9e36-c851bc83426a@googlegroups.com> References: <52dfa51e$0$3621$426a74cc@news.free.fr> <0510fa5b-41aa-4337-9e36-c851bc83426a@googlegroups.com> Message-ID: <52e01a8c$0$2929$426a34cc@news.free.fr> Le 22/01/14 18:31, 88888 Dihedral a ?crit : > > Check the C source code generated > by Pyrex and check cython for what u > want, but I did try that out in any > mobile phone or flat panel > programming. > Thanks a lot for your answer. I didn't use Pyrex or other tool, but wrote myself the C python wrapping, using the Python C/API documentation (http://docs.python.org/2/c-api/). I then used the distutils tool (via a setup.py file) to build my extension. While there is several function in my C code, only one needed to be accessed by python. I'll check Cython then, but is there any tweaking of the setup.py file using distutils that will help me compile the extension with the cairo lib embedded into it? From roegltd at gmail.com Wed Jan 22 14:52:16 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 11:52:16 -0800 (PST) Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: On Wednesday, January 22, 2014 9:18:19 PM UTC+2, Ned Batchelder wrote: > Chris is right here, too: modules are themselves singletons, no matter > how many times you import them, they are only executed once, and the > same module object is provided for each import. > > Ned Batchelder, http://nedbatchelder.com Chris, Ned, many thanks for clarification! From sertorbe at gmail.com Wed Jan 22 15:38:44 2014 From: sertorbe at gmail.com (sertorbe at gmail.com) Date: Wed, 22 Jan 2014 12:38:44 -0800 (PST) Subject: Python declarative In-Reply-To: References: Message-ID: <6b23e98f-bbce-43e7-952b-a5198623cf89@googlegroups.com> El mi?rcoles, 15 de enero de 2014 18:02:08 UTC+1, Sergio Tortosa Benedito escribi?: > Hi I'm developing a sort of language extension for writing GUI programs > > called guilang, right now it's written in Lua but I'm considreing Python > > instead (because it's more tailored to alone applications). My question > > it's if I can achieve this declarative-thing in python. Here's an > > example: > > > > Window "myWindow" { > > title="Hello world"; > > Button "myButton" { > > label="I'm a button"; > > onClick=exit > > } > > } > > print(myWindow.myButton.label) > > > > Of course it doesn't need to be 100% equal. Thanks in advance > > > > Sergio Hi again, just wrote to announce that I'm going to rewrite guilang in Python. Again thanks you are all awesome :). From ethan at stoneleaf.us Wed Jan 22 15:26:30 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 22 Jan 2014 12:26:30 -0800 Subject: awesome slugify and unicode In-Reply-To: References: Message-ID: <52E02976.3060103@stoneleaf.us> On 01/22/2014 11:23 AM, Mark Lawrence wrote: > I thought this blog might interest some of you > http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html Thanks! -- ~Ethan~ From roy at panix.com Wed Jan 22 15:55:36 2014 From: roy at panix.com (Roy Smith) Date: Wed, 22 Jan 2014 15:55:36 -0500 Subject: No overflow in variables? References: Message-ID: In article , Chris Angelico wrote: > The Python integer type stores arbitrary precision. Which is not only really cool, but terribly useful for solving many Project Euler puzzles :-) From roegltd at gmail.com Wed Jan 22 16:10:30 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 13:10:30 -0800 (PST) Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: <48967ec6-e766-436f-848f-103b871cacec@googlegroups.com> On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > > is it possible to create singleton using construct below : > > > > def singleton_provider(x = [None]): > > if singleton_provider.__defaults__[0][0] == None: > > singleton_provider.__defaults__[0][0] = SomeClass() > > return singleton_provider.__defaults__[0][0] > > > > Why not simply: > def get_singleton(x = SomeClass()): > return x > Or even: > singleton = SomeClass() > ? Neither of the above provides anything above the last one, except > for late creation. > ChrisA Hi Chris Does it make sense to use former as template to make singleton from any class as below, so instead of addressing your second proposal using module name we can directly call this one supplying class candidate for singleness as argument to function? class whatever(): def __init__(self): self.one = 1 self.zero = 0 def singleton_provider(someclass, x = [None]): if singleton_provider.__defaults__[0][0] == None: singleton_provider.__defaults__[0][0] = someclass() return singleton_provider.__defaults__[0][0] print(id(singleton_provider(whatever))) Thanks Asaf From roegltd at gmail.com Wed Jan 22 16:16:53 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 13:16:53 -0800 (PST) Subject: Python declarative In-Reply-To: References: Message-ID: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> On Wednesday, January 15, 2014 7:02:08 PM UTC+2, Sergio Tortosa Benedito wrote: > Hi I'm developing a sort of language extension for writing GUI programs > called guilang, right now it's written in Lua but I'm considreing Python > instead (because it's more tailored to alone applications). My question > it's if I can achieve this declarative-thing in python. Here's an > example: > Window "myWindow" { > title="Hello world"; > Button "myButton" { > label="I'm a button"; > onClick=exit > } > } > print(myWindow.myButton.label) > Of course it doesn't need to be 100% equal. Thanks in advance > Sergio Hi Sergio i am novice in python, but let me suggest you something: it would be beneficial to use json text file to specify your gui so composite data structure can be created using json and then your program can construct window giving its content will be based on simple text file? You can add every parameter to json encoded window system once your window construction will be using as interpreter for that. JSON is very structured and quite presentable for such kind of things. What Gurus do think about this suggestion? /Asaf From greg.ewing at canterbury.ac.nz Wed Jan 22 16:54:12 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 23 Jan 2014 10:54:12 +1300 Subject: Early retirement project? In-Reply-To: <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> References: <20140121053801.60f8cf11@bigbox.christie.dr> <8af4a7da-fb44-409d-835a-0e332a7850be@googlegroups.com> Message-ID: wxjmfauth at gmail.com wrote: > In fact, Python just becomes the last tool I (would) > recommend, especially for non-ascii users. To the OP: Ignore wxjmfauth, he's our resident nutcase. -- Greg From greg.ewing at canterbury.ac.nz Wed Jan 22 17:09:13 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 23 Jan 2014 11:09:13 +1300 Subject: Using a static library in a C extension for Python In-Reply-To: <52e01a8c$0$2929$426a34cc@news.free.fr> References: <52dfa51e$0$3621$426a74cc@news.free.fr> <0510fa5b-41aa-4337-9e36-c851bc83426a@googlegroups.com> <52e01a8c$0$2929$426a34cc@news.free.fr> Message-ID: lgabiot wrote: > Le 22/01/14 18:31, 88888 Dihedral a ?crit : > >> Check the C source code generated >> by Pyrex ... >> > > Thanks a lot for your answer. We suspect that 88888 Dihedral is actually a bot, so you're *probably* wasting your time attempting to engage it in conversation. -- Greg From greg.ewing at canterbury.ac.nz Wed Jan 22 17:22:15 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 23 Jan 2014 11:22:15 +1300 Subject: No overflow in variables? In-Reply-To: References: Message-ID: Chris Angelico wrote: > (Which > means, no, Python cannot represent Graham's Number in an int. Sorry > about that.) This is probably a good thing. I'm told that any computer with enough RAM to hold Graham's number would, from entropy considerations alone, have enough mass to become a black hole. -- Greg From roegltd at gmail.com Wed Jan 22 17:34:12 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 14:34:12 -0800 (PST) Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: <59440b67-9c35-441d-87a8-a2cadc1af02f@googlegroups.com> On Wednesday, January 22, 2014 6:18:57 PM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:07 AM, Asaf Las wrote: > ChrisA and this one is about multiclass container function with multithreading support: import threading def provider(cls, x = [threading.Lock(), {}]): provider.__defaults__[0][0].acquire() if not cls.__name__ in provider.__defaults__[0][1]: provider.__defaults__[0][1][cls.__name__] = cls() provider.__defaults__[0][0].release() return provider.__defaults__[0][1][cls.__name__] class whatever(): def __init__(self): self.one = 1 self.zero = 0 class whatever1(): def __init__(self): self.one = 1 self.zero = 0 print(id(provider(whatever))) print(id(provider(whatever))) print(id(provider(whatever1))) print(id(provider(whatever1))) could be there some hidden faults i missed? /Asaf From auriocus at gmx.de Wed Jan 22 18:00:56 2014 From: auriocus at gmx.de (Christian Gollwitzer) Date: Thu, 23 Jan 2014 00:00:56 +0100 Subject: Using a static library in a C extension for Python In-Reply-To: <52dfa51e$0$3621$426a74cc@news.free.fr> References: <52dfa51e$0$3621$426a74cc@news.free.fr> Message-ID: Hi, Am 22.01.14 12:01, schrieb lgabiot: > Is it possible to link statically cairo to my extension, so that even if > cairo is not installed on a computer, the code will run? > > I guess I would need to modify the setup.py file using distutils to > compile cairo statically into my .so file? I've done it for a similar problem (linking HDF statically including its dependencies zlib and libjpeg), but I did write the Makefile by hand instead of using distutils. First, you need to compile a static version of cairo. I.e., you probably have got some libcairo.2.dylib or similar. This can't be used, you must end up with a libcairo.a archive, by passing "--disable-shared --enable-static" to the configure script. For this to work, the code must be position-independent ("--with-pic" in autoconf). This is a no-op on OSX, where all code is position-independent, but is important if you plan to port it to Linux. Then, during the linking step of your extension, you need to link against that statically compiled version of libcairo. In a Makefile, you would pass "-L/path/to/thelibrary -lcairo" to the compiler invocation for the linking step. I don't know distutils enough, but maybe you can either pass "LDFLAGS" to it to do this or directly point to that version of cairo. > Or am I completely wrong? I'm a big fan of static linkage in that case, too. There might be another issue with the license of the library. Cairo is both LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it seems to be accepted to link statically. It all depends on whether you plan to pass on the binary to another person. To circumvent this problem, it might be feasable to just install libcairo along with you extension. Then, the exact same version of python must be used on both computers. Since the extension loading mechanism completely relies on the OS dynamic linker, it is not possible to load an extension into a different version of python than it was built for. Sadly, nobody implemented a system like Tcl's stubs, where an array of function pointers gets passed to the extension. This system allows to load an extension into later versions of the host program. Christian From random832 at fastmail.us Wed Jan 22 18:13:31 2014 From: random832 at fastmail.us (random832 at fastmail.us) Date: Wed, 22 Jan 2014 18:13:31 -0500 Subject: No overflow in variables? In-Reply-To: References: Message-ID: <1390432411.32603.74159693.7CF8F57A@webmail.messagingengine.com> On Wed, Jan 22, 2014, at 13:26, Chris Angelico wrote: > The Python integer type stores arbitrary precision. It's not a machine > word, like the C# integer types (plural, or does it have only one? C# has the usual assortment of fixed-width integer types - though by default they throw exceptions on overflow instead of wrapping around - and a BigInteger type in the library. From steve+comp.lang.python at pearwood.info Wed Jan 22 19:01:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2014 00:01:20 GMT Subject: Can post a code but afraid of plagiarism References: Message-ID: <52e05bd0$0$29999$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Jan 2014 00:36:17 -0800, indar kumar wrote: > So my question is if I am giving multiple inputs(a new device say for > example) in a loop and creating a database(dictionary) for each new > devices for example. I want subsequent devices to save their data(values > only not keys) to the database of each of the already existing devices. > How can I do that? Any hint?I have been stuck here for 3 days. Short version: in your dict (database), instead of storing the value alone, store a list containing each of the values. Longer version: Here you have a dict as database: db = {} Here you get a key and value, and you add then to the db: # key is 23, value is "hello" if 23 in db: db[23].append("hello") else: db[23] = ["hello"] Later, you can see if the key already exists: if 23 in db: print("Key 23 already exists") Or you can add a second value value to the same key: if 23 in db: db[23].append("goodbye") else: db[23] = ["goodbye"] which can be written more succinctly as: db.setdefault(23, []).append("goodbye") Now you can check whether the key has been seen once or twice: if len(db[23]) == 1: print("key 23 has been seen only once") else: print("key 23 has been seen twice or more times") Does this answer your question? -- Steven From larry.martell at gmail.com Wed Jan 22 19:58:19 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 22 Jan 2014 17:58:19 -0700 Subject: Case insensitive exists()? Message-ID: I have the need to check for a files existence against a string, but I need to do case-insensitively. I cannot efficiently get the name of every file in the dir and compare each with my string using lower(), as I have 100's of strings to check for, each in a different dir, and each dir can have 100's of files in it. Does anyone know of an efficient way to do this? There's no switch for os.path that makes exists() check case-insensitively is there? From roy at panix.com Wed Jan 22 20:08:26 2014 From: roy at panix.com (Roy Smith) Date: Wed, 22 Jan 2014 20:08:26 -0500 Subject: Case insensitive exists()? References: Message-ID: In article , Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), > as I have 100's of strings to check for, each in a different dir, and > each dir can have 100's of files in it. I'm not quite sure what you're asking. Do you need to match the filename, or find the string in the contents of the file? I'm going to assume you're asking the former. One way or another, you need to iterate over all the directories and get all the filenames in each. The time to do that is going to totally swamp any processing you do in terms of converting to lower case and comparing to some set of strings. I would put all my strings into a set, then use os.walk() traverse the directories and for each path os.walk() returns, do "path.lower() in strings". From kwa at kuwata-lab.com Wed Jan 22 20:14:52 2014 From: kwa at kuwata-lab.com (Makoto Kuwata) Date: Thu, 23 Jan 2014 10:14:52 +0900 Subject: [ANN] Oktest.py 0.13.0 - a new style testing library Message-ID: Oktest 0.13.0 is released. https://pypi.python.org/pypi/Oktest/ Oktest is a new-style testing library for Python. ## unittest self.assertEqual(x, y) self.assertNotEqual(x, y) self.assertGreaterEqual(x, y) self.assertIsInstance(obj, cls) self.assertRegexpMatches(text, rexp) ## Oktest.py ok (x) == y ok (x) != y ok (x) >= y ok (obj).is_a(cls) ok (text).match(rexp) It is possible to assert WebOb/Werkzeug/Requests response object easily. ok (response).is_response(200).json({"status":"OK"}) Install $ easy_install oktest User's Guide http://www.kuwata-lab.com/oktest/oktest-py_users-guide.html Changes http://www.kuwata-lab.com/oktest/oktest-py_CHANGES.txt What's New ---------- * [enhance] `ok().is_response()' now supports Requests. Example:: import requests resp = requests.get('http://www.example.com/') ok (resp).is_response(200, 'text/html') * [enhance] (Experimental) Add 'oktest.web' module to help WSGI app testing. Example:: ## create WSGI application class App(object): def __call__(self, environ, start_response): status = '200 OK' headers = [('Content-Type', 'application/json')] body = [b'''{"message":"Hello!"}'''] # bytes, not unicode start_response(status, headers) return body app = App() ## test for app import unittest import oktest from oktest import test, ok, subject from oktest.web import WSGITest # !!!!! http = WSGITest(app) # !!!!! https = WSGITest(app, {'HTTPS': 'on'}) # !!!!! class AppTest(unittest.TestCase): with subject('GET /'): @test("Returns messaging JSON.") def _(self): resp = http.GET('/') # or http('GET', '/') ok (resp).is_response(200).json({"message": "Hello!"}) ## or status, headers, body = http.GET('/') # or http('GET', '/') ok (status) == '200 OK' ok (headers) == [('Content-Type', 'application/json')] ok (body) == [b'''{"message":"Hello!"}'''] if __name__ == '__main__': oktest.main() -- regars, makoto kuwata -------------- next part -------------- An HTML attachment was scrubbed... URL: From larry.martell at gmail.com Wed Jan 22 20:18:32 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 22 Jan 2014 18:18:32 -0700 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 6:08 PM, Roy Smith wrote: > In article , > Larry Martell wrote: > >> I have the need to check for a files existence against a string, but I >> need to do case-insensitively. I cannot efficiently get the name of >> every file in the dir and compare each with my string using lower(), >> as I have 100's of strings to check for, each in a different dir, and >> each dir can have 100's of files in it. > > I'm not quite sure what you're asking. Do you need to match the > filename, or find the string in the contents of the file? I'm going to > assume you're asking the former. Yes, match the file names. e.g. if my match string is "ABC" and there's a file named "Abc" then it would be match. > One way or another, you need to iterate over all the directories and get > all the filenames in each. The time to do that is going to totally > swamp any processing you do in terms of converting to lower case and > comparing to some set of strings. > > I would put all my strings into a set, then use os.walk() traverse the > directories and for each path os.walk() returns, do "path.lower() in > strings". The issue is that I run a database query and get back rows, each with a file path (each in a different dir). And I have to check to see if that file exists. Each is a separate search with no correlation to the others. I have the full path, so I guess I'll have to do dir name on it, then a listdir then compare each item with .lower with my string .lower. It's just that the dirs have 100's and 100's of files so I'm really worried about efficiency. From roy at panix.com Wed Jan 22 20:27:03 2014 From: roy at panix.com (Roy Smith) Date: Wed, 22 Jan 2014 20:27:03 -0500 Subject: Case insensitive exists()? References: Message-ID: In article , Larry Martell wrote: > The issue is that I run a database query and get back rows, each with > a file path (each in a different dir). And I have to check to see if > that file exists. Each is a separate search with no correlation to the > others. I have the full path, so I guess I'll have to do dir name on > it, then a listdir then compare each item with .lower with my string > .lower. It's just that the dirs have 100's and 100's of files so I'm > really worried about efficiency. Oh, my, this is a much more complicated problem than you originally described. Is the whole path case-insensitive, or just the last component? In other words, if the search string is "/foo/bar/my_file_name", do all of these paths match? /FOO/BAR/MY_FILE_NAME /foo/bar/my_file_name /FoO/bAr/My_FiLe_NaMe Can you give some more background as to *why* you're doing this? Usually, if a system considers filenames to be case-insensitive, that's something that's handled by the operating system itself. From python at mrabarnett.plus.com Wed Jan 22 20:27:48 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 23 Jan 2014 01:27:48 +0000 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: <52E07014.2010203@mrabarnett.plus.com> On 2014-01-23 00:58, Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), > as I have 100's of strings to check for, each in a different dir, and > each dir can have 100's of files in it. Does anyone know of an > efficient way to do this? There's no switch for os.path that makes > exists() check case-insensitively is there? > You don't say which OS. Filenames in Windows, for example, are already case-insensitive. Try writing it the simplest and cleanest way, without thinking about efficiency. If you discover that it really is too slow (you can always try a smaller test case initially), then you can think about how to speed it up. From ethan at stoneleaf.us Wed Jan 22 20:22:29 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 22 Jan 2014 17:22:29 -0800 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: <52E06ED5.2070608@stoneleaf.us> On 01/22/2014 04:58 PM, Larry Martell wrote: > > I have the need to check for a files existence against a string, but I > need to do case-insensitively. This should get you going. As it is, it will check the /entire/ string you send in even if it has path parts to it, and there are probably other idiosyncrasies that you may want to change to match your needs. --------------------------- def exists(filename, ci=False): from glob import glob search = filename if ci: new_search = [] for ch in filename: new_search.append('[%s%s]' % (ch.lower(), ch.upper())) search = ''.join(new_search) found = glob(search) return bool(found) --------------------------- -- ~Ethan~ From lgabiot at hotmail.com Wed Jan 22 21:12:27 2014 From: lgabiot at hotmail.com (lgabiot) Date: Thu, 23 Jan 2014 03:12:27 +0100 Subject: Using a static library in a C extension for Python In-Reply-To: References: <52dfa51e$0$3621$426a74cc@news.free.fr> <0510fa5b-41aa-4337-9e36-c851bc83426a@googlegroups.com> <52e01a8c$0$2929$426a34cc@news.free.fr> Message-ID: <52e07a8b$0$2041$426a34cc@news.free.fr> Le 22/01/14 23:09, Gregory Ewing a ?crit : > > We suspect that 88888 Dihedral is actually a bot, > so you're *probably* wasting your time attempting > to engage it in conversation. > Thanks, so that will be my first real experience of the Turing test!!! From lgabiot at hotmail.com Wed Jan 22 21:17:22 2014 From: lgabiot at hotmail.com (lgabiot) Date: Thu, 23 Jan 2014 03:17:22 +0100 Subject: Using a static library in a C extension for Python In-Reply-To: References: <52dfa51e$0$3621$426a74cc@news.free.fr> Message-ID: <52e07bb2$0$2119$426a34cc@news.free.fr> thanks a lot for your very precise answer! shortly, as I'm running out of time right now: I've got here a lot of informations, so I'll dig in the directions you gave me. It will be a good compiling exercise... (I'm really new at all this). From rosuav at gmail.com Wed Jan 22 21:20:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 13:20:54 +1100 Subject: Case insensitive exists()? In-Reply-To: <52E07014.2010203@mrabarnett.plus.com> References: <52E07014.2010203@mrabarnett.plus.com> Message-ID: On Thu, Jan 23, 2014 at 12:27 PM, MRAB wrote: > On 2014-01-23 00:58, Larry Martell wrote: >> >> I have the need to check for a files existence against a string, but I >> need to do case-insensitively. I cannot efficiently get the name of >> every file in the dir and compare each with my string using lower(), >> as I have 100's of strings to check for, each in a different dir, and >> each dir can have 100's of files in it. Does anyone know of an >> efficient way to do this? There's no switch for os.path that makes >> exists() check case-insensitively is there? >> > You don't say which OS. Filenames in Windows, for example, are already > case-insensitive. There are weird use-cases for case insensitive filename matching on a case sensitive file system. (For instance, a program that parses a playlist file created on Windows. I did that a while ago - had to map "Foobar.MID" to "FooBar.mid", matching case insensitively and retrieving the actual case used on the FS.) A good data structure is probably all you need. As Roy suggests, iterate once over the directories - for instance, create a dict mapping the .lower() of the filename to the original. Of course, then you have to worry about collisions... though you may be able to guarantee that they can't happen (in the above case, I was looking through a directory tree that was unzipped straight from the Windows collection, ergo no two filenames could differ only in case). Or maybe you *think* you can guarantee it, but due to a bug you can't. (Ever had a USB stick, formatted NTFS, with two files differing only in case? Windows XP behaves... oddly. And rather amusingly.) ChrisA From rosuav at gmail.com Wed Jan 22 21:29:06 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 13:29:06 +1100 Subject: Python declarative In-Reply-To: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: On Thu, Jan 23, 2014 at 8:16 AM, Asaf Las wrote: > i am novice in python, but let me suggest you something: > it would be beneficial to use json text file to specify > your gui so composite data structure can be created using > json and then your program can construct window giving > its content will be based on simple text file? > You can add every parameter to json encoded window system > once your window construction will be using as interpreter > for that. JSON is very structured and quite presentable for > such kind of things. > > What Gurus do think about this suggestion? JSON is better than XML for that, but in my opinion, both are unnecessary. Python code is easy to edit. (See [1] for more on Python and XML.) When you're writing compiled code, it makes good sense to drop out of code and use a simple text file when you can; but when your code *is* a simple text file, why go to the effort of making a JSON-based window builder? (Unless you already have one. GladeXML may well be exactly what you want, in which case, go ahead and use it. But personally, I don't.) JSON is a fantastic format for transmitting complex objects around the internet; it's compact (unlike XML), readable in many languages (like XML), easily readable by humans (UNLIKE XML!), and can represent all the most common data structures (subtly, XML can't technically do this). It's superb at what it does... but it doesn't do Python GUIs. For those, use Python itself. ChrisA [1] http://dirtsimple.org/2004/12/python-is-not-java.html From rosuav at gmail.com Wed Jan 22 21:33:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 13:33:16 +1100 Subject: Using a static library in a C extension for Python In-Reply-To: References: <52dfa51e$0$3621$426a74cc@news.free.fr> Message-ID: On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer wrote: > There might be another issue with the license of the library. Cairo is both > LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it > seems to be accepted to link statically. It all depends on whether you plan > to pass on the binary to another person. > To circumvent this problem, it might be feasable to just install libcairo > along with you extension. > > Then, the exact same version of python must be used on both computers. Since > the extension loading mechanism completely relies on the OS dynamic linker, > it is not possible to load an extension into a different version of python > than it was built for. If you can tie in with your OS's package manager, that would solve all of these problems. You get the OS-supplied Pythom and the OS-supplied libcairo; grabbing libcairo-dev (or, on my Debian system, libcairo2-dev to go with libcairo2) gets you what you need to build your extension; you then might even package your extension the same way, and then simply declare dependencies. Can save a HUGE amount of trouble. ChrisA From lgabiot at hotmail.com Wed Jan 22 21:32:37 2014 From: lgabiot at hotmail.com (lgabiot) Date: Thu, 23 Jan 2014 03:32:37 +0100 Subject: problem with sqlite3: cannot use < in a SQL query with (?) Message-ID: <52e07f45$0$3631$426a34cc@news.free.fr> Hello, I'm building an application using a simple sqlite3 database. At some point, I need to select rows (more precisely some fields in rows) that have the following property: their field max_level (an INT), should not exceed a value stored in a variable called threshold, where an int is stored (value 20000). (threshold needs to be set by the user, so I cannot hard code a value there). My database already exist on my drive (and of course the sqlite3 module is imported) I do the following: >>>conn = sqlite3.connect(mydb) # open the database that's OK >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE max_level<(?)", threshold) that doesn't work (throw an exception) if I do: >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE max_level<20000)") it works... I did similar operations on UPDATE instead of SELECT, and it works there. Maybe my mind is fried right now, but I can't figure out the solution... best regards. From lgabiot at hotmail.com Wed Jan 22 21:34:13 2014 From: lgabiot at hotmail.com (lgabiot) Date: Thu, 23 Jan 2014 03:34:13 +0100 Subject: problem with sqlite3: cannot use < in a SQL query with (?) In-Reply-To: <52e07f45$0$3631$426a34cc@news.free.fr> References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: <52e07fa5$0$3631$426a34cc@news.free.fr> > I did similar operations on UPDATE instead of SELECT, and it works there. > Maybe my mind is fried right now, but I can't figure out the solution... so maybe I should rename my post: cannot use =, < with (?) in SELECT WHERE query ? From rosuav at gmail.com Wed Jan 22 21:42:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 13:42:02 +1100 Subject: problem with sqlite3: cannot use < in a SQL query with (?) In-Reply-To: <52e07f45$0$3631$426a34cc@news.free.fr> References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: On Thu, Jan 23, 2014 at 1:32 PM, lgabiot wrote: >>>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE >>>> max_level<(?)", threshold) > that doesn't work (throw an exception) What exception, exactly? Was it telling you that an integer is not iterable, perhaps? If so, check your docs for conn.execute(). If not, can you post the exact exception, please? ChrisA From bgailer at gmail.com Wed Jan 22 21:51:09 2014 From: bgailer at gmail.com (bob gailer) Date: Wed, 22 Jan 2014 21:51:09 -0500 Subject: problem with sqlite3: cannot use < in a SQL query with (?) In-Reply-To: <52e07f45$0$3631$426a34cc@news.free.fr> References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: <52E0839D.6020908@gmail.com> On 1/22/2014 9:32 PM, lgabiot wrote: > Hello, > > I'm building an application using a simple sqlite3 database. > At some point, I need to select rows (more precisely some fields in > rows) that have the following property: their field max_level (an INT), > should not exceed a value stored in a variable called threshold, where > an int is stored (value 20000). > (threshold needs to be set by the user, so I cannot hard code a value > there). > > My database already exist on my drive (and of course the sqlite3 > module is imported) > > I do the following: > > >>>conn = sqlite3.connect(mydb) # open the database > that's OK > > >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE > max_level<(?)", threshold) > that doesn't work (throw an exception) PLEASE POST THE TRACEBACK! Also get rid of the() around the ?. > > if I do: > >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE > max_level<20000)") > it works... > > I did similar operations on UPDATE instead of SELECT, and it works there. > Maybe my mind is fried right now, but I can't figure out the solution... > > best regards. From bgailer at gmail.com Wed Jan 22 21:51:56 2014 From: bgailer at gmail.com (bob gailer) Date: Wed, 22 Jan 2014 21:51:56 -0500 Subject: problem with sqlite3: cannot use < in a SQL query with (?) In-Reply-To: <52e07f45$0$3631$426a34cc@news.free.fr> References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: <52E083CC.3090608@gmail.com> On 1/22/2014 9:32 PM, lgabiot wrote: > Hello, > > I'm building an application using a simple sqlite3 database. > At some point, I need to select rows (more precisely some fields in > rows) that have the following property: their field max_level (an INT), > should not exceed a value stored in a variable called threshold, where > an int is stored (value 20000). > (threshold needs to be set by the user, so I cannot hard code a value > there). > > My database already exist on my drive (and of course the sqlite3 > module is imported) > > I do the following: > > >>>conn = sqlite3.connect(mydb) # open the database > that's OK > > >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE > max_level<(?)", threshold) > that doesn't work (throw an exception) > > if I do: > >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE > max_level<20000)") > it works... > > I did similar operations on UPDATE instead of SELECT, and it works there. SO SHOW US THE UPDATE. "Similar" does not help. > Maybe my mind is fried right now, but I can't figure out the solution... > > best regards. From python.list at tim.thechases.com Wed Jan 22 22:05:58 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Wed, 22 Jan 2014 21:05:58 -0600 Subject: problem with sqlite3: cannot use < in a SQL query with (?) In-Reply-To: <52e07f45$0$3631$426a34cc@news.free.fr> References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: <20140122210558.13a4e361@bigbox.christie.dr> On 2014-01-23 03:32, lgabiot wrote: > >>>cursor = conn.execute("SELECT filename, filepath FROM files > >>>WHERE > max_level<(?)", threshold) > that doesn't work (throw an exception) That last argument should be a tuple, so unless "threshold" is a tuple, you would want to make it sql = "SELECT ... WHERE max_level < ?" cursor = conn.execute(sql, (threshold,)) -tkc From tjreedy at udel.edu Wed Jan 22 23:08:06 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 22 Jan 2014 23:08:06 -0500 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: On 1/22/2014 9:29 PM, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 8:16 AM, Asaf Las wrote: >> i am novice in python, but let me suggest you something: >> it would be beneficial to use json text file to specify >> your gui so composite data structure can be created using >> json and then your program can construct window giving >> its content will be based on simple text file? >> You can add every parameter to json encoded window system >> once your window construction will be using as interpreter >> for that. JSON is very structured and quite presentable for >> such kind of things. > JSON is better than XML for that, but in my opinion, both are > unnecessary. Python code is easy to edit. (See [1] for more on Python > and XML.) When you're writing compiled code, it makes good sense to > drop out of code and use a simple text file when you can; but when > your code *is* a simple text file, why go to the effort of making a > JSON-based window builder? (Unless you already have one. GladeXML may > well be exactly what you want, in which case, go ahead and use it. But > personally, I don't.) JSON is a fantastic format for transmitting > complex objects around the internet; it's compact (unlike XML), > readable in many languages (like XML), easily readable by humans > (UNLIKE XML!), and can represent all the most common data structures > (subtly, XML can't technically do this). It's superb at what it > does... but it doesn't do Python GUIs. For those, use Python itself. I would only use JSON if I wanted a declaration format that was independent of implementation languages, that could be read and turned into application objects by as least two languages. -- Terry Jan Reedy From larry.martell at gmail.com Wed Jan 22 23:24:54 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 22 Jan 2014 21:24:54 -0700 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 6:27 PM, Roy Smith wrote: > In article , > Larry Martell wrote: > >> The issue is that I run a database query and get back rows, each with >> a file path (each in a different dir). And I have to check to see if >> that file exists. Each is a separate search with no correlation to the >> others. I have the full path, so I guess I'll have to do dir name on >> it, then a listdir then compare each item with .lower with my string >> .lower. It's just that the dirs have 100's and 100's of files so I'm >> really worried about efficiency. > > Oh, my, this is a much more complicated problem than you originally > described. I try not to bother folks with simple problems ;-) > Is the whole path case-insensitive, or just the last component? In > other words, if the search string is "/foo/bar/my_file_name", do all of > these paths match? > > /FOO/BAR/MY_FILE_NAME > /foo/bar/my_file_name > /FoO/bAr/My_FiLe_NaMe Just the file name (the basename). > Can you give some more background as to *why* you're doing this? > Usually, if a system considers filenames to be case-insensitive, that's > something that's handled by the operating system itself. I can't say why it's happening. This is a big complicated system with lots of parts. There's some program that ftp's image files from an electron microscope and stores them on the file system with crazy names like: 2O_TOPO_1_2O_2UM_FOV_M1_FX-2_FY4_DX0_DY0_DZ0_SDX10_SDY14_SDZ0_RR1_TR1_Ver1.jpg And something (perhaps the same program, perhaps a different one) records this is a database. In some cases the name recorded in the db has different cases in some characters then how it was stored in the db, e.g.: 2O_TOPO_1_2O_2UM_Fov_M1_FX-2_FY4_DX0_DY0_DZ0_SDX10_SDY14_SDZ0_RR1_TR1_Ver1.jpg These only differ in "FOV" vs. "Fov" but that is just one example. I am writing something that is part of a django app, that based on some web entry from the user, I run a query, get back a list of files and have to go receive them and serve them up back to the browser. My script is all done and seem to be working, then today I was informed it was not serving up all the images. Debugging revealed that it was this case issue - I was matching with exists(). As I've said, coding a solution is easy, but I fear it will be too slow. Speed is important in web apps - users have high expectations. Guess I'll just have to try it and see. From larry.martell at gmail.com Wed Jan 22 23:25:31 2014 From: larry.martell at gmail.com (Larry Martell) Date: Wed, 22 Jan 2014 21:25:31 -0700 Subject: Case insensitive exists()? In-Reply-To: <52E07014.2010203@mrabarnett.plus.com> References: <52E07014.2010203@mrabarnett.plus.com> Message-ID: On Wed, Jan 22, 2014 at 6:27 PM, MRAB wrote: > On 2014-01-23 00:58, Larry Martell wrote: >> >> I have the need to check for a files existence against a string, but I >> need to do case-insensitively. I cannot efficiently get the name of >> every file in the dir and compare each with my string using lower(), >> as I have 100's of strings to check for, each in a different dir, and >> each dir can have 100's of files in it. Does anyone know of an >> efficient way to do this? There's no switch for os.path that makes >> exists() check case-insensitively is there? >> > You don't say which OS. Filenames in Windows, for example, are already > case-insensitive. Linux. > Try writing it the simplest and cleanest way, without thinking about > efficiency. If you discover that it really is too slow (you can always > try a smaller test case initially), then you can think about how to > speed it up. Yes, that's my plan. From rosuav at gmail.com Wed Jan 22 23:29:23 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 15:29:23 +1100 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 3:24 PM, Larry Martell wrote: > I am writing something that is part of a django app, that based on > some web entry from the user, I run a query, get back a list of files > and have to go receive them and serve them up back to the browser. My > script is all done and seem to be working, then today I was informed > it was not serving up all the images. Debugging revealed that it was > this case issue - I was matching with exists(). As I've said, coding a > solution is easy, but I fear it will be too slow. Speed is important > in web apps - users have high expectations. Guess I'll just have to > try it and see. Would it be a problem to rename all the files? Then you could simply lower() the input name and it'll be correct. ChrisA From rustompmody at gmail.com Wed Jan 22 23:33:43 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jan 2014 20:33:43 -0800 (PST) Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: On Thursday, January 23, 2014 8:35:58 AM UTC+5:30, Tim Chase wrote: > On 2014-01-23 03:32, lgabiot wrote: > > >>>cursor = conn.execute("SELECT filename, filepath FROM files > > >>>WHERE > > max_level<(?)", threshold) > > that doesn't work (throw an exception) > That last argument should be a tuple, so unless "threshold" > is a tuple, you would want to make it > sql = "SELECT ... WHERE max_level < ?" > cursor = conn.execute(sql, (threshold,)) Seeing this is becoming a faq I looked at the docs to see if the tuple second argument could do with some more emphasis I think it sure could; see http://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor The builtin connection.execute is even less helpful From rustompmody at gmail.com Wed Jan 22 23:37:37 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jan 2014 20:37:37 -0800 (PST) Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: On Thursday, January 23, 2014 10:03:43 AM UTC+5:30, Rustom Mody wrote: > The builtin connection.execute is even less helpful I meant help(conn.execute) From rosuav at gmail.com Wed Jan 22 23:41:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 15:41:42 +1100 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: On Thu, Jan 23, 2014 at 3:33 PM, Rustom Mody wrote: > On Thursday, January 23, 2014 8:35:58 AM UTC+5:30, Tim Chase wrote: >> On 2014-01-23 03:32, lgabiot wrote: >> > >>>cursor = conn.execute("SELECT filename, filepath FROM files >> > >>>WHERE >> > max_level<(?)", threshold) >> > that doesn't work (throw an exception) > >> That last argument should be a tuple, so unless "threshold" >> is a tuple, you would want to make it > >> sql = "SELECT ... WHERE max_level < ?" >> cursor = conn.execute(sql, (threshold,)) > > Seeing this is becoming a faq I looked at the docs to see if the tuple second > argument could do with some more emphasis > > I think it sure could; see > http://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor > > The builtin connection.execute is even less helpful I think it's fairly clear from the example that it has to be either a tuple or a dict. Looks fine to me. But I'm sure that, if you come up with better wording, a tracker issue would get the attention it deserves. ChrisA From hacktheplanet at gmail.com Thu Jan 23 00:23:57 2014 From: hacktheplanet at gmail.com (Agility) Date: Wed, 22 Jan 2014 21:23:57 -0800 Subject: Diving in to Python - Best resources? References: <39adb03e-95b8-4049-bfbc-f7c5fce2d08f@googlegroups.com> Message-ID: <2014012221235760000-hacktheplanet@gmailcom> If you are already a Perl programmer, this link could be useful! https://wiki.python.org/moin/PerlPhrasebook A From frank at chagford.com Thu Jan 23 00:36:53 2014 From: frank at chagford.com (Frank Millman) Date: Thu, 23 Jan 2014 07:36:53 +0200 Subject: Self healthcheck References: <0d1fc1a7-c585-45ba-8c1a-0cc468712a48@googlegroups.com> <58c541ab-c6e1-45a8-b03a-8597ed7ecb48@googlegroups.com> <9729ddaa-5976-4e53-8584-6198b47b6789@googlegroups.com> Message-ID: "Asaf Las" wrote in message news:9729ddaa-5976-4e53-8584-6198b47b6789 at googlegroups.com... > On Wednesday, January 22, 2014 10:56:30 AM UTC+2, Frank Millman wrote: >> >> class MainObject: >> def __init__(self, identifier): >> self._del = delwatcher('MainObject', identifier) >> class delwatcher: >> def __init__(self, obj_type, identifier): >> self.obj_type = obj_type >> self.identifier = identifier >> log('{}: id={} created'.format(self.obj_type, self.identifier)) >> def __del__(self): >> log('{}: id={} deleted'.format(self.obj_type, self.identifier)) >> If you do find that an object is not being deleted, it is then >> trial-and-error to find the problem and fix it. It is probably a circular >> reference >> >> Frank Millman > > Thanks Frank. Good approach! > > One question - You could do: > class MainObject: > def __init__(self, identifier): > self._del = delwatcher(self) > then later > > class delwatcher: > def __init__(self, tobject): > self.obj_type = type(tobject) > self.identifier = id(tobject) > ... > > when creating delwatcher. Was there special reason to not to use them? > is this because of memory is reused when objects are deleted > and created again so same reference could be for objects created > in different time slots? > I read Dave's reply, and he is correct in saying that id's are frequently re-used in python. However, in this particular case, I think you are right, it is safe to use the id to identify the object. An id can only be re-used if the original object is deleted, and that is the whole point of this exercise. We expect to see the id come up in a 'created' message, and then the same id appear in a 'deleted' message. If this happens, we are not concerned if the same id reappears in a subsequent 'created' message. Frank From rustompmody at gmail.com Thu Jan 23 00:35:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Wed, 22 Jan 2014 21:35:46 -0800 (PST) Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote: > I think it's fairly clear from the example that it has to be either a > tuple or a dict. Looks fine to me. yes 'from the example' and only from there! From rosuav at gmail.com Thu Jan 23 00:42:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 16:42:00 +1100 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Message-ID: On Thu, Jan 23, 2014 at 4:35 PM, Rustom Mody wrote: > On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote: >> I think it's fairly clear from the example that it has to be either a >> tuple or a dict. Looks fine to me. > > yes 'from the example' and only from there! The fact that there's only one parameter that's supposed to handle all of that also strongly suggests that it's a tuple. ChrisA From roegltd at gmail.com Thu Jan 23 02:18:24 2014 From: roegltd at gmail.com (Asaf Las) Date: Wed, 22 Jan 2014 23:18:24 -0800 (PST) Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> Message-ID: <408998ad-918d-454c-b37e-41921cdd0e3d@googlegroups.com> On Thursday, January 23, 2014 6:41:42 AM UTC+2, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:33 PM, Rustom Mody wrote: > I think it's fairly clear from the example that it has to be either a > tuple or a dict. Looks fine to me. But I'm sure that, if you come up > with better wording, a tracker issue would get the attention it > deserves. > ChrisA It looks like tuple, but i could be wrong: from python-3.3.3.tar.bz2\Python-3.3.3\Modules\_sqlite\cursor.c PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* args) { ... if (multiple) { /* executemany() */ if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) { goto error; } /Asaf From wxjmfauth at gmail.com Thu Jan 23 02:18:42 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 22 Jan 2014 23:18:42 -0800 (PST) Subject: awesome slugify and unicode In-Reply-To: References: Message-ID: <59461353-d450-471f-ae28-84f686543a57@googlegroups.com> Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a ?crit?: > I thought this blog might interest some of you > > http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > > > This is not "unicode", only string manipulations. The same work could be done with, let say, cp1252. The difference lies in the repertoires of characters to be handled. A better way is to work with normalization() and/or with methods like .translate() with dedicated tables; the hard task being the creation of these tables. Shortly, very naive. jmf From laurent.gabiot at gmail.com Thu Jan 23 02:37:22 2014 From: laurent.gabiot at gmail.com (lgabiot) Date: Thu, 23 Jan 2014 08:37:22 +0100 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Message-ID: <52E0C6B2.1000407@hotmail.com> Thanks to all, that was indeed the tuple issue! the correct code is: >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE max_level References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Message-ID: <52E0C6B2.1000407@hotmail.com> Thanks to all, that was indeed the tuple issue! the correct code is: >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE max_level References: <52dfa51e$0$3621$426a74cc@news.free.fr> Message-ID: <52E0C78F.1030504@hotmail.com> Le 23/01/14 03:33, Chris Angelico a ?crit : > On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer wrote: >> There might be another issue with the license of the library. Cairo is both >> LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it >> seems to be accepted to link statically. It all depends on whether you plan >> to pass on the binary to another person. >> To circumvent this problem, it might be feasable to just install libcairo >> along with you extension. >> >> Then, the exact same version of python must be used on both computers. Since >> the extension loading mechanism completely relies on the OS dynamic linker, >> it is not possible to load an extension into a different version of python >> than it was built for. > > If you can tie in with your OS's package manager, that would solve all > of these problems. You get the OS-supplied Pythom and the OS-supplied > libcairo; grabbing libcairo-dev (or, on my Debian system, > libcairo2-dev to go with libcairo2) gets you what you need to build > your extension; you then might even package your extension the same > way, and then simply declare dependencies. Can save a HUGE amount of > trouble. > > ChrisA > thank you very much for your answer, I'll work on your informations. From lgabiot at hotmail.com Thu Jan 23 02:41:03 2014 From: lgabiot at hotmail.com (lgabiot) Date: Thu, 23 Jan 2014 08:41:03 +0100 Subject: Using a static library in a C extension for Python In-Reply-To: References: <52dfa51e$0$3621$426a74cc@news.free.fr> Message-ID: <52E0C78F.1030504@hotmail.com> Le 23/01/14 03:33, Chris Angelico a ?crit : > On Thu, Jan 23, 2014 at 10:00 AM, Christian Gollwitzer wrote: >> There might be another issue with the license of the library. Cairo is both >> LGPL and MPL. For LGPL, only dynamic linking is without doubt, for MPL it >> seems to be accepted to link statically. It all depends on whether you plan >> to pass on the binary to another person. >> To circumvent this problem, it might be feasable to just install libcairo >> along with you extension. >> >> Then, the exact same version of python must be used on both computers. Since >> the extension loading mechanism completely relies on the OS dynamic linker, >> it is not possible to load an extension into a different version of python >> than it was built for. > > If you can tie in with your OS's package manager, that would solve all > of these problems. You get the OS-supplied Pythom and the OS-supplied > libcairo; grabbing libcairo-dev (or, on my Debian system, > libcairo2-dev to go with libcairo2) gets you what you need to build > your extension; you then might even package your extension the same > way, and then simply declare dependencies. Can save a HUGE amount of > trouble. > > ChrisA > thank you very much for your answer, I'll work on your informations. From rosuav at gmail.com Thu Jan 23 02:47:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 18:47:35 +1100 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: <408998ad-918d-454c-b37e-41921cdd0e3d@googlegroups.com> References: <52e07f45$0$3631$426a34cc@news.free.fr> <408998ad-918d-454c-b37e-41921cdd0e3d@googlegroups.com> Message-ID: On Thu, Jan 23, 2014 at 6:18 PM, Asaf Las wrote: > if (!PyArg_ParseTuple(args, "OO", &operation, &second_argument)) { > goto error; > } That part just asks for "any object" as the second argument. Also, that part is handling executemany(). Later on, the execute() handler looks for an optional second arg, and then looks for an iterator from it. But as a general rule, I'd advise reading the docs rather than the source, unless you're trying to figure out whether some other iterable will work. For the most part, just follow the examples and use a tuple. ChrisA From indarkumar59 at gmail.com Thu Jan 23 02:46:36 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 23:46:36 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <4c3009ee-bf97-4d93-83e6-0bc4b2a90e82@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Thanks for kind help. I have following nested dictionary hosts={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]} How can I print a particular tuple from this table? What I am trying to do is input1=raw_input("Please enter id of host and IP that you want to be resolved") z=input1.split() print("PC3 resolved"+' '+z[1]+' to'+hosts[z[0]][3] z[1]) #z[1] is ip entered and [z[0]][3] z[1] is the particular location of value(MAC) associated with IP that I want to print. But failed to do so. How can I print that. Please guide From dan at tombstonezero.net Thu Jan 23 02:51:30 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Thu, 23 Jan 2014 07:51:30 +0000 (UTC) Subject: Case insensitive exists()? References: Message-ID: On Wed, 22 Jan 2014 18:18:32 -0700, Larry Martell wrote: > The issue is that I run a database query and get back rows, each with > a file path (each in a different dir). And I have to check to see if > that file exists. Each is a separate search with no correlation to the > others. I have the full path, so I guess I'll have to do dir name on > it, then a listdir then compare each item with .lower with my string > .lower. It's just that the dirs have 100's and 100's of files so I'm > really worried about efficiency. Okay, so it's not Python, and I have the benefit of having read all of the other answers, but what about calling "locate" [0] with the "-i" flag? or writing some sort of Python/ctypes wrapper around the part of locate that searches the database? Dan [0] http://savannah.gnu.org/projects/findutils/ From indarkumar59 at gmail.com Thu Jan 23 02:57:02 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Wed, 22 Jan 2014 23:57:02 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public I just need to print first element of tuple not the whole From breamoreboy at yahoo.co.uk Thu Jan 23 04:04:09 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Jan 2014 09:04:09 +0000 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: <52E0C6B2.1000407@hotmail.com> References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> <52E0C6B2.1000407@hotmail.com> Message-ID: On 23/01/2014 07:37, lgabiot wrote: > Thanks to all, > > that was indeed the tuple issue! > the correct code is: > >>>cursor = conn.execute("SELECT filename, filepath FROM files WHERE > max_level > as was pointed out by many. > > Sorry for missing such a silly point (well, a comma in fact). I'll learn > to read more seriously the doc, but I was really confused (I spent more > than one hour trying so many combinations, reading the doc, books I > have, etc... before posting, and I was stuck) > > but the basis for my blindness was more a lack of grasp of the > fundamentals: how to declare a one element tuple. > Because I tried to write (threshold) being convinced it was a tuple... > > I need to remember at all times: https://wiki.python.org/moin/TupleSyntax > > best regards. > No, you need to remember how to type xyz into your favourite search engine. For this case xyz would be something like "python single element tuple". -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From christian at python.org Thu Jan 23 04:14:34 2014 From: christian at python.org (Christian Heimes) Date: Thu, 23 Jan 2014 10:14:34 +0100 Subject: No overflow in variables? In-Reply-To: References: Message-ID: On 22.01.2014 19:26, Chris Angelico wrote: > Internally, I believe CPython uses the GNU Multiprecision Library > (GMP), which gives an efficient representation and operation format, > scaling to infinity or thereabouts. You can go to any size of integer > you like without there being any difference. There's a cost to that > (even small integers are a bit slower to work with), but it's SO > helpful to be able to work with arbitrarily large numbers that it's > worth that cost. Small correction: Python isn't using GMP. Python uses its own implementation. From breamoreboy at yahoo.co.uk Thu Jan 23 04:14:48 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Jan 2014 09:14:48 +0000 Subject: awesome slugify and unicode In-Reply-To: <59461353-d450-471f-ae28-84f686543a57@googlegroups.com> References: <59461353-d450-471f-ae28-84f686543a57@googlegroups.com> Message-ID: On 23/01/2014 07:18, wxjmfauth at gmail.com wrote: > Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a ?crit : >> I thought this blog might interest some of you >> >> http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html >> >> My fellow Pythonistas, ask not what our language can do for you, ask >> >> what you can do for our language. >> > > This is not "unicode", only string manipulations. > The same work could be done with, let say, cp1252. > The difference lies in the repertoires of characters > to be handled. > > A better way is to work with normalization() and/or > with methods like .translate() with dedicated > tables; the hard task being the creation of these tables. > > Shortly, very naive. > > jmf > You'll have to excuse my ignorance of this stuff. How do I express the following in cp1252? def test_musical_notes(): txt = "Is ? ? ? ? a melody or just noise?" assert slugify(txt) == "Is-a-melody-or-just-noise" assert slugify_unicode(txt) == "Is-a-melody-or-just-noise" -- 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 Thu Jan 23 04:36:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 20:36:18 +1100 Subject: No overflow in variables? In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 8:14 PM, Christian Heimes wrote: > On 22.01.2014 19:26, Chris Angelico wrote: >> Internally, I believe CPython uses the GNU Multiprecision Library >> (GMP), which gives an efficient representation and operation format, >> scaling to infinity or thereabouts. You can go to any size of integer >> you like without there being any difference. There's a cost to that >> (even small integers are a bit slower to work with), but it's SO >> helpful to be able to work with arbitrarily large numbers that it's >> worth that cost. > > Small correction: Python isn't using GMP. Python uses its own > implementation. Okay, wasn't sure. I've seen others that use GMP (including Pike, which can also use arbitrary-precision floats if you wish). Wrong in the specifics, right in the concept. Thanks for the correction. ChrisA From laurent.gabiot at gmail.com Thu Jan 23 04:45:07 2014 From: laurent.gabiot at gmail.com (lgabiot) Date: Thu, 23 Jan 2014 10:45:07 +0100 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> <52E0C6B2.1000407@hotmail.com> Message-ID: <52E0E4A3.2010205@hotmail.com> Le 23/01/14 10:04, Mark Lawrence a ?crit : > No, you need to remember how to type xyz into your favourite search > engine. For this case xyz would be something like "python single > element tuple". > No big deal, but I don't think you are correct. Problem was that for me I "knew" (it was erroneous of course) that (element) was a python single element tuple... so there was no need for me to look for something I "knew". Once I understood that what I "knew" was wrong (that is after reading the answers to my first post), I did type xyz in my favourite search engine, which led me to the link I posted in my answer... From lgabiot at hotmail.com Thu Jan 23 04:45:07 2014 From: lgabiot at hotmail.com (lgabiot) Date: Thu, 23 Jan 2014 10:45:07 +0100 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> <52E0C6B2.1000407@hotmail.com> Message-ID: <52E0E4A3.2010205@hotmail.com> Le 23/01/14 10:04, Mark Lawrence a ?crit : > No, you need to remember how to type xyz into your favourite search > engine. For this case xyz would be something like "python single > element tuple". > No big deal, but I don't think you are correct. Problem was that for me I "knew" (it was erroneous of course) that (element) was a python single element tuple... so there was no need for me to look for something I "knew". Once I understood that what I "knew" was wrong (that is after reading the answers to my first post), I did type xyz in my favourite search engine, which led me to the link I posted in my answer... From roegltd at gmail.com Thu Jan 23 04:46:11 2014 From: roegltd at gmail.com (Asaf Las) Date: Thu, 23 Jan 2014 01:46:11 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Thursday, January 23, 2014 9:57:02 AM UTC+2, indar kumar wrote: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > I just need to print first element of tuple not the whole in hierarchies do steps level by level, that will make things much easier: hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}], 'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]} print(hosts['PC2']) print(hosts['PC2'][3]) print(hosts['PC2'][3]['192.168.0.2']) print(hosts['PC2'][3]['192.168.0.2'][1]) From indarkumar59 at gmail.com Thu Jan 23 05:10:28 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Thu, 23 Jan 2014 02:10:28 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <84183d3c-e1ff-4925-8f6a-03776a984741@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Thank You I have found this forum very helping...GOD BLESS YOU ALL From rustompmody at gmail.com Thu Jan 23 05:23:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 23 Jan 2014 02:23:22 -0800 (PST) Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: <52E0E4A3.2010205@hotmail.com> References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> <52E0C6B2.1000407@hotmail.com> <52E0E4A3.2010205@hotmail.com> Message-ID: <1e0994c4-7c0f-4faa-9838-9e5665d80825@googlegroups.com> On Thursday, January 23, 2014 3:15:07 PM UTC+5:30, lgabiot wrote: > Le 23/01/14 10:04, Mark Lawrence a ?crit : > > No, you need to remember how to type xyz into your favourite search > > engine. For this case xyz would be something like "python single > > element tuple". > No big deal, but I don't think you are correct. > Problem was that for me I "knew" (it was erroneous of course) that > (element) was a python single element tuple... so there was no need for > me to look for something I "knew". > Once I understood that what I "knew" was wrong (that is after reading > the answers to my first post), I did type xyz in my favourite search > engine, which led me to the link I posted in my answer... Singleton tuples are a common gotcha in python Follows from the world-wide shortage in parenthesis From tjreedy at udel.edu Thu Jan 23 05:43:26 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jan 2014 05:43:26 -0500 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Message-ID: On 1/23/2014 12:35 AM, Rustom Mody wrote: > On Thursday, January 23, 2014 10:11:42 AM UTC+5:30, Chris Angelico wrote: >> I think it's fairly clear from the example that it has to be either a >> tuple or a dict. Looks fine to me. > > yes 'from the example' and only from there! 'parameters' is a single parameter, which could be called 'seq_dict'. Let(seq_dict) must equal the number of replacements. A dict with extra pairs raises. A list instead of a tuple does work, but not an iterable, so 'sequence'. A dict subclass works, but a UserDict is treated as a sequence. ----------- import sqlite3 con = sqlite3.connect(":memory:") cur = con.cursor() cur.execute("create table people (name_last, age)") who = "Yeltsin" age = 72 s = (who, age) d = {'who':who, 'age':age} class D(dict): pass dD = D(d) from collections import UserDict dU = UserDict(d) # This is the qmark style: cur.execute("insert into people values (?, ?)", s) # And this is the named style: cur.execute("select * from people where name_last=:who and age=:age", dU) print(cur.fetchone()) -------------- >>> Traceback (most recent call last): File "C:\Programs\Python34\tem.py", line 23, in cur.execute("select * from people where name_last=:who and age=:age", dU) File "C:\Programs\Python34\lib\collections\__init__.py", line 883, in __getitem__ raise KeyError(key) KeyError: 0 Replacing dU in the last call with s works! http://bugs.python.org/issue20364 -- Terry Jan Reedy From wxjmfauth at gmail.com Thu Jan 23 05:41:47 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 23 Jan 2014 02:41:47 -0800 (PST) Subject: awesome slugify and unicode In-Reply-To: References: <59461353-d450-471f-ae28-84f686543a57@googlegroups.com> Message-ID: <1e0aeb33-23b6-4af1-8447-38dc4473d09f@googlegroups.com> Le jeudi 23 janvier 2014 10:14:48 UTC+1, Mark Lawrence a ?crit?: > On 23/01/2014 07:18, wxjmfauth at gmail.com wrote: > > > Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a ?crit : > > >> I thought this blog might interest some of you > > >> > > >> http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html > > >> > > >> My fellow Pythonistas, ask not what our language can do for you, ask > > >> > > >> what you can do for our language. > > >> > > > > > > This is not "unicode", only string manipulations. > > > The same work could be done with, let say, cp1252. > > > The difference lies in the repertoires of characters > > > to be handled. > > > > > > A better way is to work with normalization() and/or > > > with methods like .translate() with dedicated > > > tables; the hard task being the creation of these tables. > > > > > > Shortly, very naive. > > > > > > jmf > > > > > > > You'll have to excuse my ignorance of this stuff. How do I express the > > following in cp1252? > > > > def test_musical_notes(): > > txt = "Is ? ? ? ? a melody or just noise?" > > assert slugify(txt) == "Is-a-melody-or-just-noise" > > assert slugify_unicode(txt) == "Is-a-melody-or-just-noise" > > > > -- > > My fellow Pythonistas, ask not what our language can do for you, ask > > what you can do for our language. > > I wrote: The same work could be done with, let say, cp1252. Understand: The same work (string manipulation) ... Would something like this not be more informative? >>> "Is ? ? ? ? a melody or just noise?".encode('ascii', 'replace').decode('ascii') 'Is ? ? ? ? a melody or just noise?' >>> >>> cp1252 analogy. >>> 'abc???'.encode('cp1252').decode('ascii', 'replace').encode('ascii', 'replace').decode('ascii') 'abc???' >>> Again, not a "unicode" question, more "how to handle strings in a judicious way?" jmf From rosuav at gmail.com Thu Jan 23 05:49:04 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 23 Jan 2014 21:49:04 +1100 Subject: awesome slugify and unicode In-Reply-To: <1e0aeb33-23b6-4af1-8447-38dc4473d09f@googlegroups.com> References: <59461353-d450-471f-ae28-84f686543a57@googlegroups.com> <1e0aeb33-23b6-4af1-8447-38dc4473d09f@googlegroups.com> Message-ID: On Thu, Jan 23, 2014 at 9:41 PM, wrote: >>>> "Is ? ? ? ? a melody or just noise?".encode('ascii', 'replace').decode('ascii') > 'Is ? ? ? ? a melody or just noise?' >>>> >>>> > > cp1252 analogy. > >>>> 'abc???'.encode('cp1252').decode('ascii', 'replace').encode('ascii', 'replace').decode('ascii') > 'abc???' >>>> > > Again, not a "unicode" question, more "how to handle strings in a judicious way?" I don't want a cp1252 analogy, I want the exact same thing implemented in cp1252. You said the same work could be done there. That work includes dealing with musical notes. How are you going to do that? ChrisA From oscar.j.benjamin at gmail.com Thu Jan 23 05:56:10 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 23 Jan 2014 10:56:10 +0000 Subject: any wheel experts here? In-Reply-To: <0c89048c-ae60-42b3-b737-a6d82ff8fe32@googlegroups.com> References: <52DFA239.4010508@chamonix.reportlab.co.uk> <0c89048c-ae60-42b3-b737-a6d82ff8fe32@googlegroups.com> Message-ID: <20140123105605.GB2300@gmail.com> On Wed, Jan 22, 2014 at 06:17:33AM -0800, Rustom Mody wrote: > On Wednesday, January 22, 2014 4:31:32 PM UTC+5:30, Oscar Benjamin wrote: > > Sounds reasonable. I don't know the answer or whether anyone else on this list > > will but you can definitely find the relevant developers at this mailing list: > > https://mail.python.org/mailman/listinfo/distutils-sig/ > > I believe the wheel/pip/virtualenv guys are on this list > > https://groups.google.com/forum/#!forum/python-virtualenv Maybe in some kind of quantum superposition they can be on both mailing lists at once! Oscar From steve+comp.lang.python at pearwood.info Thu Jan 23 07:06:46 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 23 Jan 2014 12:06:46 GMT Subject: Case insensitive exists()? References: Message-ID: <52e105d6$0$29999$c3e8da3$5496439d@news.astraweb.com> On Wed, 22 Jan 2014 17:58:19 -0700, Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. Reading on, I see that your database assumes case-insensitive file names, while your file system is case-sensitive. Suggestions: (1) Move the files onto a case-insensitive file system. Samba, I believe, can duplicate the case-insensitive behaviour of NTFS even on ext3 or ext4 file systems. (To be pedantic, NTFS can also optionally be case- sensitive, although that it rarely used.) So if you stick the files on a samba file share set to case-insensitivity, samba will behave the way you want. (Although os.path.exists won't, you'll have to use nt.path.exists instead.) (2) Normalize the database and the files. Do a one-off run through the files on disk, lowercasing the file names, followed by a one-off run through the database, doing the same. (Watch out for ambiguous names like "Foo" and "FOO".) Then you just need to ensure new files are always named in lowercase. Also, keep in mind that just because os.path.exists reports a file exists *right now*, doesn't mean it will still exist a millisecond later when you go to use it. Consider avoiding os.path.exists altogether, and just trying to open the file. (Although I see you still have the problem that you don't know *which* directory the file will be found in. > I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), as > I have 100's of strings to check for, each in a different dir, and each > dir can have 100's of files in it. Does anyone know of an efficient way > to do this? There's no switch for os.path that makes exists() check > case-insensitively is there? Try nt.path.exists, although I'm not certain it will do what you want since it probably assumes the file system is case-insensitive. It really sounds like you have a hard problem to solve here. I strongly recommend that you change the problem, by renaming the files, or at least moving them into a consistent location, rather than have to repeatedly search multiple directories. Good luck! -- Steven From list at qtrac.plus.com Thu Jan 23 07:20:31 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 23 Jan 2014 04:20:31 -0800 (PST) Subject: SQLite + FTS (full text search) Message-ID: Hi, On my Debian stable 64-bit system, SQLite3 has FTS (full text search) enabled (although at version 3 rather than the recommended version 4): Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 Type "copyright", "credits" or "license()" for more information. >>> import sqlite3 >>> con = sqlite3.connect(":memory:") >>> cur = con.execute("pragma compile_options") >>> for row in cur: print(row) ... ('ENABLE_FTS3',) ... But on Windows when I use the official Python 3.3 32-bit binary from www.python.org this is not enabled. My guess is that on Debian, the packagers install a full SQLite 3 and the Python package uses that. But on Windows I think the Python packagers bundle their own SQLite (quite rightly since it might not already be installed). I'd like the Windows binary to include SQLite 3 with FTS4 support, but I don't know how much work that involves or if it would make the Python .msi file too big? Anyway, I guess if anyone else is interested in this they could perhaps reply to indicate this? If you're curious about the feature, it is documented here: http://www.sqlite.org/fts3.html From dihedral88888 at gmail.com Thu Jan 23 07:21:08 2014 From: dihedral88888 at gmail.com (88888 Dihedral) Date: Thu, 23 Jan 2014 04:21:08 -0800 (PST) Subject: Using a static library in a C extension for Python In-Reply-To: <52e01a8c$0$2929$426a34cc@news.free.fr> References: <52dfa51e$0$3621$426a74cc@news.free.fr> <0510fa5b-41aa-4337-9e36-c851bc83426a@googlegroups.com> <52e01a8c$0$2929$426a34cc@news.free.fr> Message-ID: On Thursday, January 23, 2014 3:22:52 AM UTC+8, lgabiot wrote: > Le 22/01/14 18:31, 88888 Dihedral a ?crit : > > > > > > > > Check the C source code generated > > > by Pyrex and check cython for what u > > > want, but I did try that out in any > > > mobile phone or flat panel > > > programming. > > > > > > > Thanks a lot for your answer. > > > > I didn't use Pyrex or other tool, but wrote myself the C python > > wrapping, using the Python C/API documentation > > (http://docs.python.org/2/c-api/). I then used the distutils tool (via a > > setup.py file) to build my extension. > > While there is several function in my C code, only one needed to be > > accessed by python. > > > > I'll check Cython then, but is there any tweaking of the setup.py file > > using distutils that will help me compile the extension with the cairo > > lib embedded into it? There are some design concerns in writing python scripts that might be modified for fast execution speeds in some platforms. Well, reducing basic operation overheads in well factored critical parts does help in getting the desired results faster. From python.list at tim.thechases.com Thu Jan 23 07:36:34 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 23 Jan 2014 06:36:34 -0600 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Message-ID: <20140123063634.2ad5169e@bigbox.christie.dr> On 2014-01-23 05:43, Terry Reedy wrote: > A list instead of a tuple does work, but not an iterable, so > 'sequence'. In the OP's case using sqlite drivers, this is true. However, I maintain some old 2.4 code that uses a correspondingly ancient version of mx.ODBC which requires a tuple and raises an exception on any other iterable. So I always use a tuple out of habit, even if it would be easier to just use some other iterable. -tkc From python.list at tim.thechases.com Thu Jan 23 07:48:42 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 23 Jan 2014 06:48:42 -0600 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: <20140123064842.47fb9256@bigbox.christie.dr> On 2014-01-22 17:58, Larry Martell wrote: > I have the need to check for a files existence against a string, > but I need to do case-insensitively. I cannot efficiently get the > name of every file in the dir and compare each with my string using > lower(), as I have 100's of strings to check for, each in a > different dir, and each dir can have 100's of files in it. Does > anyone know of an efficient way to do this? There's no switch for > os.path that makes exists() check case-insensitively is there? Is it possible to rephrase the problem in terms of a different algorithm that can be made case-insensitive? Something like from_db = set( row[0].upper() for row in db.execute( "select filename from tblfoo where ..." ).fetchall() ) from_fs = dict( (fname.upper(), os.path.join(pth, fname)) for pth, dirs, files in os.walk(ROOT) for fname in files ) common_filenames = from_db & set(from_fs) for fname in common_filenames: print from_fs[fname] -tkc From breamoreboy at yahoo.co.uk Thu Jan 23 08:18:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Jan 2014 13:18:08 +0000 Subject: awesome slugify and unicode In-Reply-To: <1e0aeb33-23b6-4af1-8447-38dc4473d09f@googlegroups.com> References: <59461353-d450-471f-ae28-84f686543a57@googlegroups.com> <1e0aeb33-23b6-4af1-8447-38dc4473d09f@googlegroups.com> Message-ID: On 23/01/2014 10:41, wxjmfauth at gmail.com wrote: > Le jeudi 23 janvier 2014 10:14:48 UTC+1, Mark Lawrence a ?crit : >> On 23/01/2014 07:18, wxjmfauth at gmail.com wrote: >> >>> Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a ?crit : >> >>>> I thought this blog might interest some of you >> >>>> >> >>>> http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html >> >>>> >> >>>> My fellow Pythonistas, ask not what our language can do for you, ask >> >>>> >> >>>> what you can do for our language. >> >>>> >> >>> >> >>> This is not "unicode", only string manipulations. >> >>> The same work could be done with, let say, cp1252. >> >>> The difference lies in the repertoires of characters >> >>> to be handled. >> >>> >> >>> A better way is to work with normalization() and/or >> >>> with methods like .translate() with dedicated >> >>> tables; the hard task being the creation of these tables. >> >>> >> >>> Shortly, very naive. >> >>> >> >>> jmf >> >>> >> >> >> >> You'll have to excuse my ignorance of this stuff. How do I express the >> >> following in cp1252? >> >> >> >> def test_musical_notes(): >> >> txt = "Is ? ? ? ? a melody or just noise?" >> >> assert slugify(txt) == "Is-a-melody-or-just-noise" >> >> assert slugify_unicode(txt) == "Is-a-melody-or-just-noise" >> >> >> >> -- >> >> My fellow Pythonistas, ask not what our language can do for you, ask >> >> what you can do for our language. >> >> > > I wrote: The same work could be done with, let say, cp1252. > Understand: The same work (string manipulation) ... > Would something like this not be more informative? > >>>> "Is ? ? ? ? a melody or just noise?".encode('ascii', 'replace').decode('ascii') > 'Is ? ? ? ? a melody or just noise?' >>>> >>>> > > cp1252 analogy. > >>>> 'abc???'.encode('cp1252').decode('ascii', 'replace').encode('ascii', 'replace').decode('ascii') > 'abc???' >>>> > > Again, not a "unicode" question, more "how to handle strings in a judicious way?" > > jmf > Now I'm really confused. I thought that the musical notes I've shown above are represented as unicode characters. So I'd like to see how you jmf would represent them in cp1252. Instead you give me an example showing a simple string manipulation which simply strips the characters that I want to see, then an even simpler example, clearly not what I've asked for. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From jcasale at activenetwerx.com Thu Jan 23 08:23:40 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Thu, 23 Jan 2014 13:23:40 +0000 Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: > But on Windows when I use the official Python 3.3 32-bit binary from > www.python.org this is not enabled. For an unobtrusive way [1] to gain this, see apsw. For what it's worth, I prefer this package over the built in module. Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] ... IPython 2.0.0-dev -- An enhanced Interactive Python. ... In [1]: import apsw In [2]: c = apsw.Connection(':memory:') In [3]: for x in c.cursor().execute('pragma compile_options'): print(x) ('ENABLE_FTS3',) ('ENABLE_FTS3_PARENTHESIS',) ('ENABLE_FTS4',) ('ENABLE_RTREE',) ('THREADSAFE=1',) hth, jlc [1] See the sqlite mailing list for a way to replace the dll, while I have done it I also have tested it thoroughly. From roegltd at gmail.com Thu Jan 23 08:24:06 2014 From: roegltd at gmail.com (Asaf Las) Date: Thu, 23 Jan 2014 05:24:06 -0800 (PST) Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: On Thursday, January 23, 2014 2:20:31 PM UTC+2, Mark Summerfield wrote: > Hi, > On my Debian stable 64-bit system, SQLite3 has FTS (full text search) > enabled (although at version 3 rather than the recommended version 4): > > Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 > Type "copyright", "credits" or "license()" for more information. > >>> import sqlite3 > >>> con = sqlite3.connect(":memory:") > >>> cur = con.execute("pragma compile_options") > >>> for row in cur: > print(row) > ... > ('ENABLE_FTS3',) > ... > But on Windows when I use the official Python 3.3 32-bit binary > from www.python.org this is not enabled. > > My guess is that on Debian, the packagers install a full SQLite 3 > and the Python package uses that. But on Windows I think the Python > packagers bundle their own SQLite (quite rightly since it might not > already be installed). > > I'd like the Windows binary to include SQLite 3 with FTS4 support, > but I don't know how much work that involves or if it would make > the Python .msi file too big? > > Anyway, I guess if anyone else is interested in this they > could perhaps reply to indicate this? > If you're curious about the feature, it is documented here: > > http://www.sqlite.org/fts3.html It is compile time option. http://www.sqlite.org/compile.html#enable_fts3 you have to build it with this option enabled. From johannes.schneider at galileo-press.de Thu Jan 23 08:36:17 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Thu, 23 Jan 2014 14:36:17 +0100 Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> Message-ID: <52E11AD1.4080305@galileo-press.de> On 22.01.2014 20:18, Ned Batchelder wrote: > On 1/22/14 11:37 AM, Asaf Las wrote: > Chris is right here, too: modules are themselves singletons, no matter > how many times you import them, they are only executed once, and the > same module object is provided for each import. I'm not sure, if this is the whole truth. think about this example: cat bla.py a = 10 cat foo.py from bla import a def stuff(): return a cat bar.py from foo import stuff print stuff() a = 5 print stuff() from bla import * print a python bar.py 10 10 10 here the a is coming from bla and is known in the global namespace. But the value differs in stuff() and before/after the import statement. So the instance of the module differs -> it cannot be a singelton. bg, Johannes -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From breamoreboy at yahoo.co.uk Thu Jan 23 08:39:08 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Jan 2014 13:39:08 +0000 Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: On 23/01/2014 13:24, Asaf Las wrote: > On Thursday, January 23, 2014 2:20:31 PM UTC+2, Mark Summerfield wrote: >> Hi, >> On my Debian stable 64-bit system, SQLite3 has FTS (full text search) >> enabled (although at version 3 rather than the recommended version 4): >> >> Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 >> Type "copyright", "credits" or "license()" for more information. >>>>> import sqlite3 >>>>> con = sqlite3.connect(":memory:") >>>>> cur = con.execute("pragma compile_options") >>>>> for row in cur: >> print(row) >> ... >> ('ENABLE_FTS3',) >> ... >> But on Windows when I use the official Python 3.3 32-bit binary >> from www.python.org this is not enabled. >> >> My guess is that on Debian, the packagers install a full SQLite 3 >> and the Python package uses that. But on Windows I think the Python >> packagers bundle their own SQLite (quite rightly since it might not >> already be installed). >> >> I'd like the Windows binary to include SQLite 3 with FTS4 support, >> but I don't know how much work that involves or if it would make >> the Python .msi file too big? >> >> Anyway, I guess if anyone else is interested in this they >> could perhaps reply to indicate this? >> If you're curious about the feature, it is documented here: >> >> http://www.sqlite.org/fts3.html > > It is compile time option. > http://www.sqlite.org/compile.html#enable_fts3 > you have to build it with this option enabled. > As an option can be represented in a single bit then presumably the Windows msi file only needs an extra bit to allow for this, or have I missed something? While I'm at it what is this "compile time" thingy, being on Windows I'm not used to seeing such terminology? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roegltd at gmail.com Thu Jan 23 08:49:40 2014 From: roegltd at gmail.com (Asaf Las) Date: Thu, 23 Jan 2014 05:49:40 -0800 (PST) Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: <3af7cde2-5160-4943-9acb-b74df26ea78f@googlegroups.com> On Thursday, January 23, 2014 3:39:08 PM UTC+2, Mark Lawrence wrote: > On 23/01/2014 13:24, Asaf Las wrote: > As an option can be represented in a single bit then presumably the > Windows msi file only needs an extra bit to allow for this, or have I > missed something? While I'm at it what is this "compile time" thingy, > being on Windows I'm not used to seeing such terminology? > Mark Lawrence Oh i am poor in terminology :-) from what i have seen in sqlite page i guess this option should included into list of defines for win ide or into compiler command line option or can be put directly onto header file as #define SQLITE_ENABLE_FTS3 to enable FTS am i wrong? From solipsis at pitrou.net Thu Jan 23 09:09:19 2014 From: solipsis at pitrou.net (Antoine Pitrou) Date: Thu, 23 Jan 2014 14:09:19 +0000 (UTC) Subject: SQLite + FTS (full text search) References: Message-ID: Hi, Mark Summerfield qtrac.plus.com> writes: > > My guess is that on Debian, the packagers install a full SQLite 3 and the Python package uses that. But on > Windows I think the Python packagers bundle their own SQLite (quite rightly since it might not already be installed). > > I'd like the Windows binary to include SQLite 3 with FTS4 support, but I don't know how much work that > involves or if it would make the Python .msi file too big? You can create a feature request on http://bugs.python.org Regards Antoine. From rosuav at gmail.com Thu Jan 23 09:13:00 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jan 2014 01:13:00 +1100 Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 12:39 AM, Mark Lawrence wrote: >> >> It is compile time option. >> http://www.sqlite.org/compile.html#enable_fts3 >> you have to build it with this option enabled. >> > > As an option can be represented in a single bit then presumably the Windows > msi file only needs an extra bit to allow for this, or have I missed > something? While I'm at it what is this "compile time" thingy, being on > Windows I'm not used to seeing such terminology? The implication of a compile-time switch is that it completely changes the code that gets compiled. For instance, Python 3.4 can be compiled with/out debugging support (which will slow down execution but enable certain features), with/out IPv6, and so on. Python 3.2 could also be compiled "narrow" or "wide" with regard to Unicode handling (internal representation UTF-16 or UTF-32). Each such change could make a huge difference to the size of the .msi file, but more importantly, a huge change to functionality. In the case of something like this, I'd guess that the compile-time switch would control the presence or absence of the code; at an absolute minimum, that would mean that disabling it makes for a smaller binary, but since it's an option I'd guess that there's more to it (maybe the presence of the feature has a performance penalty even if you don't use it). On Windows, where you're accustomed to downloading a ready-made binary, all compile-time choices were made for you at the time the binary was built. That's what compile time means - when Python (or SQLite) was turned from C source code into i386 or amd64 opcodes and packaged up into an exe and an msi. (In fact, one of the compile-time choices is the architecture - whether you build a 32-bit or 64-bit binary, whether you aim it at an Intel Itanium chip, etc, etc, etc. Generally, code runs only if the architecture is correct, though there are a few compatibility cases (i386 running on amd64, for instance).) The only real difference between Windows and Linux here is that it's customary for Linux systems to have C compilers readily available, where Windows generally forces you to think more about getting one. I can simply type "sudo apt-get build-dep python" on my Debian system and it'll go fetch a C compiler and all the necessary bits and bobs for building Python from source. (In fact, I did exactly that recently, as part of setting up a buildbot.) On Windows you would have to download the right compiler (probably some version of MS Visual Studio Express, if you want to replicate the python.org binaries), manually fetch any libraries you need, etc. It's more of a social difference than a technical one, but it does mean that your average Linux user is more likely to understand "Type ./configure --with-some-cool-feature to enable SomeCoolFeature" than your average Windows user is. ChrisA From skip at pobox.com Thu Jan 23 09:16:42 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 23 Jan 2014 08:16:42 -0600 Subject: datetime as subclass of date Message-ID: This took my by surprise just now: >>> import datetime >>> now = datetime.datetime.now() >>> isinstance(now, datetime.datetime) True >>> isinstance(now, datetime.time) False >>> isinstance(now, datetime.date) True >>> issubclass(datetime.datetime, datetime.date) True I'd never paid any attention to the relationship between the datetime, time, and date classes of the datetime module before now, but have an application where, for backwards compatibility, date objects must be mapped to datetime objects with a time of midnight. That wasn't working, because I was asking if a datetime instance was an instance of a date. Which, it turns out, it is. Skip From vincent at vincentdavis.net Thu Jan 23 09:23:19 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 23 Jan 2014 08:23:19 -0600 Subject: generate De Bruijn sequence memory and string vs lists Message-ID: For reference, Wikipedia entry for De Bruijn sequence http://en.wikipedia.org/wiki/De_Bruijn_sequence At the above link is a python algorithm for generating De Brujin sequences. It works fine but outputs a list of integers [0, 0, 0, 1, 0, 1, 1, 1] and I would prefer a string '00010111'. This can be accomplished by changing the last line from; return sequence to return ''.join([str(i) for i in sequence]) See de_bruijn_1 Below. The other option would be to manipulate strings directly (kind of). I butchered the original algorithm to do this. See de_bruijn_2 below. But it is much slower and ungly. I am wanting to make a few large De Bruijin sequences. hopefully on the order of de_bruijn(4, 50) to de_bruijn(4, 100) (wishful thinking?). I don't know the limits (memory or time) for the current algorithms. I think I am will hit the memory mazsize limit at about 4^31. The system I will be using has 64GB RAM. The size of a De Brujin sequence is k^n My questions; 1, de_bruijn_2 is ugly, any suggestions to do it better? 2, de_bruijn_2 is significantly slower than de_bruijn_1. Speedups? 3, Any thought on which is more memory efficient during computation. #### 1 #### def de_bruijn_1(k, n): """ De Bruijn sequence for alphabet size k (0,1,2...k-1) and subsequences of length n. From wikipedia Sep 22 2013 """ a = [0] * k * n sequence = [] def db(t, p,): if t > n: if n % p == 0: for j in range(1, p + 1): sequence.append(a[j]) else: a[t] = a[t - p] db(t + 1, p) for j in range(int(a[t - p]) + 1, k): a[t] = j db(t + 1, t) db(1, 1) #return sequence #original return ''.join([str(i) for i in sequence]) d1 = de_bruijn_1(4, 8) #### 2 #### def de_bruijn_2(k, n): global sequence a = '0' * k * n sequence = '' def db(t, p): global sequence global a if t > n: if n % p == 0: for j in range(1, p + 1): sequence = sequence + a[j] else: a = a[:t] + a[t - p] + a[t+1:] db(t + 1, p) for j in range(int(a[t - p]) + 1, k): a = a[:t] + str(j) + a[t+1:] db(t + 1, t) return sequence db(1, 1) return sequence d2 = de_bruijn_2(4, 8) Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From list at qtrac.plus.com Thu Jan 23 09:39:58 2014 From: list at qtrac.plus.com (Mark Summerfield) Date: Thu, 23 Jan 2014 06:39:58 -0800 (PST) Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: On Thursday, 23 January 2014 14:09:19 UTC, Antoine Pitrou wrote: > Hi, > > > > Mark Summerfield qtrac.plus.com> writes: > > > > > > My guess is that on Debian, the packagers install a full SQLite 3 and the > > Python package uses that. But on > > > Windows I think the Python packagers bundle their own SQLite (quite > > rightly since it might not already be installed). > > > > > > I'd like the Windows binary to include SQLite 3 with FTS4 support, but I > > don't know how much work that > > > involves or if it would make the Python .msi file too big? > > You can create a feature request on http://bugs.python.org > > Regards > > Antoine. Good point. I've now done that: http://bugs.python.org/issue20366 From invalid at invalid.invalid Thu Jan 23 09:58:24 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 23 Jan 2014 14:58:24 +0000 (UTC) Subject: Case insensitive exists()? References: Message-ID: On 2014-01-23, Larry Martell wrote: > I have the need to check for a files existence against a string, but I > need to do case-insensitively. I cannot efficiently get the name of > every file in the dir and compare each with my string using lower(), > as I have 100's of strings to check for, each in a different dir, and > each dir can have 100's of files in it. Does anyone know of an > efficient way to do this? There's no switch for os.path that makes > exists() check case-insensitively is there? If you're on Unix, you could use os.popen() to run a find command using -iname. -- Grant Edwards grant.b.edwards Yow! I'm DESPONDENT ... I at hope there's something gmail.com DEEP-FRIED under this miniature DOMED STADIUM ... From rustompmody at gmail.com Thu Jan 23 10:00:46 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 23 Jan 2014 07:00:46 -0800 (PST) Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> Message-ID: On Thursday, January 23, 2014 4:13:26 PM UTC+5:30, Terry Reedy wrote: > http://bugs.python.org/issue20364 Thanks for that! I would have preferred a slightly louder warning with respect to singleton tuples given that: 1. Singleton tuple syntax is not consistent with other-length tuples 2. This inconsistency is somewhat alleviated by the fact that in a classic format ('%') expression, the second argument can be a single element when the format string has only one %-spec -- so one inconsistency to correct another 3. conn.execute's parameters, apparently very analogous to the '%' -- even more so given the standard sql-injection advisory -- is not consistent with 2 above Still the suggested doc-fix is much better than the current almost undocumented situation -- so thanks again! From ayushidalmia2604 at gmail.com Thu Jan 23 10:15:18 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Thu, 23 Jan 2014 07:15:18 -0800 (PST) Subject: Initialise dictionary of dictionary Message-ID: I need to initialise a dictionary of dictionary with float values. I do not know the size of the dictionary beforehand. How can we do that in Python From rustompmody at gmail.com Thu Jan 23 10:23:47 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 23 Jan 2014 07:23:47 -0800 (PST) Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: On Thursday, January 23, 2014 7:09:08 PM UTC+5:30, Mark Lawrence wrote: > On 23/01/2014 13:24, Asaf Las wrote: > > It is compile time option. > > http://www.sqlite.org/compile.html#enable_fts3 > > you have to build it with this option enabled. > As an option can be represented in a single bit then presumably the > Windows msi file only needs an extra bit to allow for this, or have I > missed something? While I'm at it what is this "compile time" thingy, > being on Windows I'm not used to seeing such terminology? On intel processors, in the cr0 register there is a bit called the PE (protection enable) bit. Turn it off and you have 1M memory Turn it on and you will have GBs and more. A wee little bit more than a single bit dont you think? :D From python.list at tim.thechases.com Thu Jan 23 10:30:23 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 23 Jan 2014 09:30:23 -0600 Subject: Initialise dictionary of dictionary In-Reply-To: References: Message-ID: <20140123093023.54334fe5@bigbox.christie.dr> On 2014-01-23 07:15, Ayushi Dalmia wrote: > I need to initialise a dictionary of dictionary with float values. > I do not know the size of the dictionary beforehand. How can we do > that in Python -- Either d = {} or, if you want from collections import defaultdict d = defaultdict(float) print(d["Hello"]) If you really do want a dict-of-dict that defaults to floats, you can do d = defaultdict(lambda: defaultdict(float)) print(d[3141]["Hello"]) -tkc From davea at davea.name Thu Jan 23 10:34:15 2014 From: davea at davea.name (Dave Angel) Date: Thu, 23 Jan 2014 10:34:15 -0500 (EST) Subject: Initialise dictionary of dictionary References: Message-ID: Ayushi Dalmia Wrote in message: > I need to initialise a dictionary of dictionary with float values. I do not know the size of the dictionary beforehand. How can we do that in Python > Do what? There's no concept of pre-initializing a dictionary, and there's no specific limit to its eventual size. Unsure of what the floats have to do with it. Perhaps you meant float KEYS. -- DaveA From python.list at tim.thechases.com Thu Jan 23 10:41:05 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Thu, 23 Jan 2014 09:41:05 -0600 Subject: Initialise dictionary of dictionary In-Reply-To: References: Message-ID: <20140123094105.268ecdf7@bigbox.christie.dr> On 2014-01-23 10:34, Dave Angel wrote: > Unsure of what the floats have to do with it. Perhaps you meant > float KEYS. using floats for keys can be dangerous, as small rounding errors in math can produce keys different enough that they're not found by an exact-match lookup. But yeah, the original problem specification was rather wanting in detail. I tried my best at interpreting it, for whatever that may be worth. -tkc From oscar.j.benjamin at gmail.com Thu Jan 23 10:43:41 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Thu, 23 Jan 2014 15:43:41 +0000 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: <20140123154338.GC3553@gmail.com> On Wed, Jan 22, 2014 at 09:24:54PM -0700, Larry Martell wrote: > > I am writing something that is part of a django app, that based on > some web entry from the user, I run a query, get back a list of files > and have to go receive them and serve them up back to the browser. My > script is all done and seem to be working, then today I was informed > it was not serving up all the images. Debugging revealed that it was > this case issue - I was matching with exists(). As I've said, coding a > solution is easy, but I fear it will be too slow. Speed is important > in web apps - users have high expectations. Guess I'll just have to > try it and see. How long does it actually take to serve a http request? I would expect it to be orders of magnitudes slower than calling os.listdir on a directory containing hundreds of files. Here on my Linux system there are 2000+ files in /usr/bin. Calling os.listdir takes 1.5 milliseconds (warm cache): $ python -m timeit -s 'import os' 'os.listdir("/usr/bin")' 1000 loops, best of 3: 1.42 msec per loop Converting those to upper case takes a further .5 milliseconds: $ python -m timeit -s 'import os' 'map(str.upper, os.listdir("/usr/bin"))' 1000 loops, best of 3: 1.98 msec per loop Checking a string against that list takes .05 milliseconds: $ python -m timeit -s 'import os' \ '"WHICH" in map(str.upper, os.listdir("/usr/bin"))' 1000 loops, best of 3: 2.03 msec per loop Oscar From davea at davea.name Thu Jan 23 11:18:41 2014 From: davea at davea.name (Dave Angel) Date: Thu, 23 Jan 2014 11:18:41 -0500 (EST) Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Vincent Davis Wrote in message: > (something about your message seems to make it unquotable) 64gig is 4^18, so you can forget about holding a string of size 4^50 If memory size is your issue, why not make the function a generator, by replacing the append with a yield? -- DaveA From davea at davea.name Thu Jan 23 11:56:33 2014 From: davea at davea.name (Dave Angel) Date: Thu, 23 Jan 2014 11:56:33 -0500 (EST) Subject: SIngleton from __defaults__ References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <52E11AD1.4080305@galileo-press.de> Message-ID: Johannes Schneider Wrote in message: > On 22.01.2014 20:18, Ned Batchelder wrote: >> On 1/22/14 11:37 AM, Asaf Las wrote: >> Chris is right here, too: modules are themselves singletons, no matter >> how many times you import them, they are only executed once, and the >> same module object is provided for each import. > > I'm not sure, if this is the whole truth. > > think about this example: > > cat bla.py > a = 10 > > cat foo.py > from bla import a > > def stuff(): > return a > > cat bar.py > from foo import stuff > print stuff() > a = 5 > print stuff() > > from bla import * > print a > > python bar.py > 10 > 10 > 10 > > here the a is coming from bla and is known in the global namespace. But > the value differs in stuff() and before/after the import statement. So > the instance of the module differs -> it cannot be a singelton. > You're using 3 different variables here, each global to its own module. If you really want to access the same object, you need to reference it as bla.a. And ditch the from deal. A from x import y. statement produces a new binding to the same object. But since the object in your example is immutable, the only way it can seem to change is by rebinding. If several names are bound to the same object, rebinding one has no effect on the others. -- DaveA From vincent at vincentdavis.net Thu Jan 23 12:20:59 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 23 Jan 2014 11:20:59 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 10:18 AM, Dave Angel wrote: > If memory size is your issue, why not make the function a > generator, by replacing the append with a yield? > ?One more thought on the generator. I have an idea for how to use the generator but I still need 1, chucks of size n de_brujin(k, n) and the ordering the same ordering as found in ?de_brujin(k, n). I am not really sure how to modify the algorithm to do that. Any ideas? I won't have time to think hard about that until later. Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Jan 23 12:31:31 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 23 Jan 2014 18:31:31 +0100 Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Vincent Davis wrote: > For reference, Wikipedia entry for De Bruijn sequence > http://en.wikipedia.org/wiki/De_Bruijn_sequence > > At the above link is a python algorithm for generating De Brujin > sequences. It works fine but outputs a list of integers [0, 0, 0, 1, 0, 1, > 1, 1] and I would prefer a string '00010111'. This can be accomplished by > changing the last line from; > return sequence > to > return ''.join([str(i) for i in sequence]) > See de_bruijn_1 Below. > > The other option would be to manipulate strings directly (kind of). > I butchered the original algorithm to do this. See de_bruijn_2 below. But > it is much slower and ungly. > > I am wanting to make a few large De Bruijin sequences. hopefully on the > order of de_bruijn(4, 50) to de_bruijn(4, 100) (wishful thinking?). I > don't know the limits (memory or time) for the current algorithms. I think > I am will hit the memory mazsize limit at about 4^31. The system I will be > using has 64GB RAM. > The size of a De Brujin sequence is k^n > > My questions; > 1, de_bruijn_2 is ugly, any suggestions to do it better? > 2, de_bruijn_2 is significantly slower than de_bruijn_1. Speedups? > 3, Any thought on which is more memory efficient during computation. > > #### 1 #### > def de_bruijn_1(k, n): > """ > De Bruijn sequence for alphabet size k (0,1,2...k-1) > and subsequences of length n. > From wikipedia Sep 22 2013 > """ > a = [0] * k * n > sequence = [] > def db(t, p,): > if t > n: > if n % p == 0: > for j in range(1, p + 1): > sequence.append(a[j]) > else: > a[t] = a[t - p] > db(t + 1, p) > for j in range(int(a[t - p]) + 1, k): > a[t] = j > db(t + 1, t) > db(1, 1) > #return sequence #original > return ''.join([str(i) for i in sequence]) > > d1 = de_bruijn_1(4, 8) > > #### 2 #### > def de_bruijn_2(k, n): > global sequence > a = '0' * k * n > sequence = '' > def db(t, p): > global sequence > global a > if t > n: > if n % p == 0: > for j in range(1, p + 1): > sequence = sequence + a[j] > else: > a = a[:t] + a[t - p] + a[t+1:] > db(t + 1, p) > for j in range(int(a[t - p]) + 1, k): > a = a[:t] + str(j) + a[t+1:] > db(t + 1, t) > return sequence > db(1, 1) > return sequence > > d2 = de_bruijn_2(4, 8) You could change de_bruijn_1() to use `bytearray`s instead of `list`s: # Python 2 def debruijn(k, n): a = k * n * bytearray([0]) sequence = bytearray() append = sequence.append # factor out method lookup def db(t, p,): if t > n: if n % p == 0: for j in xrange(1, p + 1): append(a[j]+48) # add 48 to convert to ascii else: a[t] = a[t - p] db(t + 1, p) for j in xrange(a[t - p] + 1, k): a[t] = j db(t + 1, t) db(1, 1) return sequence From __peter__ at web.de Thu Jan 23 13:02:55 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 23 Jan 2014 19:02:55 +0100 Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Peter Otten wrote: > You could change de_bruijn_1() to use `bytearray`s instead of `list`s: > > # Python 2 > def debruijn(k, n): > a = k * n * bytearray([0]) > sequence = bytearray() > append = sequence.append # factor out method lookup > def db(t, p,): > if t > n: > if n % p == 0: > for j in xrange(1, p + 1): > append(a[j]+48) # add 48 to convert to ascii > else: > a[t] = a[t - p] > db(t + 1, p) > for j in xrange(a[t - p] + 1, k): > a[t] = j > db(t + 1, t) > db(1, 1) > return sequence I just noted that the first Python loop can be eliminated: def debruijn(k, n): a = k * n * bytearray([0]) sequence = bytearray() extend = sequence.extend # factor out method lookup def db(t, p): if t > n: if n % p == 0: extend(a[1: p+1]) else: a[t] = a[t - p] db(t + 1, p) for j in xrange(a[t - p] + 1, k): a[t] = j db(t + 1, t) db(1, 1) return sequence.translate(_mapping) From vincent at vincentdavis.net Thu Jan 23 12:10:41 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 23 Jan 2014 11:10:41 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On 1/23/14, 10:18 AM, Dave Angel wrote: > (something about your message seems to make it unquotable) Not sure why the message was not quotable. I sent it using gmail. On 1/23/14, 10:18 AM, Dave Angel wrote: > 64gig is 4^18, so you can forget about holding a string of size 4^50 I guess I will have to buy more memory or be happy with less, 4**17 would be ok. On 1/23/14, 10:18 AM, Dave Angel wrote: > If memory size is your issue, why not make the function a > generator, by replacing the append with a yield? I plan to use the sequence as an index to count occurrences of sequences of length n. A generator is equivalent to using itertools.permutations (i think that the right itertool). My thought is that I don't have to store each individual (sub)sequence since the De Brujin sequence contains all of them. i.e. it is a compact representation of every sequence generated by itertools.permutations. Vincent Davis On Thu, Jan 23, 2014 at 10:18 AM, Dave Angel wrote: > > Vincent Davis Wrote in message: > > > (something about your message seems to make it unquotable) > > 64gig is 4^18, so you can forget about holding a string of size 4^50 > > If memory size is your issue, why not make the function a > generator, by replacing the append with a yield? > > > -- > DaveA > > -- > https://mail.python.org/mailman/listinfo/python-list -------------- next part -------------- An HTML attachment was scrubbed... URL: From denismfmcmahon at gmail.com Thu Jan 23 13:11:30 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Thu, 23 Jan 2014 18:11:30 +0000 (UTC) Subject: Separate Address number and name References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Message-ID: On Wed, 22 Jan 2014 17:35:22 +0000, Denis McMahon wrote: > On Tue, 21 Jan 2014 16:06:56 -0800, Shane Konings wrote: >> The following is a sample of the data. > A mechanism using regexes Just to follow up, using regexes I transformed the sample data that I believe is as follows: inputData = [ "1 1067 Niagara Stone Rd, W, Niagara-On-The-Lake, ON L0S 1J0", "2 4260 Mountainview Rd, Lincoln, ON L0R 1B2", "3 25 Hunter Rd, Grimsby, E, ON L3M 4A3", "4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0", "5 5172 Green Lane Rd, Lincoln, ON L0R 1B3", "6 500 Glenridge Ave, East, St. Catharines, ON L2S 3A1", "7 471 Foss Rd, Pelham, ON L0S 1C0", "8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0", "9 3836 Main St, North, Lincoln, ON L0R 1S0", "10 1025 York Rd, W, Niagara-On-The-Lake, ON L0S 1P0" ] Into the following: 1,1067,Niagara Stone,Rd,W,Niagara-On-The-Lake,ON,L0S 1J0 2,4260,Mountainview,Rd,,Lincoln,ON,L0R 1B2 3,25,Hunter,Rd,Grimsby,E,ON,L3M 4A3 4,1091,Hutchinson,Rd,,Haldimand,ON,N0A 1K0 5,5172,Green Lane,Rd,,Lincoln,ON,L0R 1B3 6,500,Glenridge,Ave,East,St. Catharines,ON,L2S 3A1 7,471,Foss,Rd,,Pelham,ON,L0S 1C0 8,758,Niagara Stone,Rd,,Niagara-On-The-Lake,ON,L0S 1J0 9,3836,Main,St,North,Lincoln,ON,L0R 1S0 10,1025,York,Rd,W,Niagara-On-The-Lake,ON,L0S 1P0 Which should then read into Excel as CSV just fine. One final question though, why are you using excel to manipulate data that looks as if it would be better held in and manipulated by a database? -- Denis McMahon, denismfmcmahon at gmail.com From larry.martell at gmail.com Thu Jan 23 14:02:24 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 23 Jan 2014 12:02:24 -0700 Subject: Case insensitive exists()? In-Reply-To: References: Message-ID: On Wed, Jan 22, 2014 at 9:29 PM, Chris Angelico wrote: > On Thu, Jan 23, 2014 at 3:24 PM, Larry Martell wrote: >> I am writing something that is part of a django app, that based on >> some web entry from the user, I run a query, get back a list of files >> and have to go receive them and serve them up back to the browser. My >> script is all done and seem to be working, then today I was informed >> it was not serving up all the images. Debugging revealed that it was >> this case issue - I was matching with exists(). As I've said, coding a >> solution is easy, but I fear it will be too slow. Speed is important >> in web apps - users have high expectations. Guess I'll just have to >> try it and see. > > Would it be a problem to rename all the files? Then you could simply > lower() the input name and it'll be correct. So it turned out that in the django model definition for this object there was code that was doing some character mapping that was causing this. That code was added to 'fix' another problem, but the mapping strings were not qualified enough and it was doing some unintended mapping. Changing those strings to be more specific fixed my problem. Thanks to all for the replies. From vincent at vincentdavis.net Thu Jan 23 14:50:17 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 23 Jan 2014 13:50:17 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 12:02 PM, Peter Otten <__peter__ at web.de> wrote: > > I just noted that the first Python loop can be eliminated: > > def debruijn(k, n): > a = k * n * bytearray([0]) > sequence = bytearray() > extend = sequence.extend # factor out method lookup > def db(t, p): > if t > n: > if n % p == 0: > extend(a[1: p+1]) > else: > a[t] = a[t - p] > db(t + 1, p) > for j in xrange(a[t - p] + 1, k): > a[t] = j > db(t + 1, t) > db(1, 1) > return sequence.translate(_mapping) I am not really sure what _mapping should be. The code above does not run because NameError: global name '_mapping' is not defined I tried to get the bytearray ? ? sequence to convert to ascii but don't know how to. Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Jan 23 15:10:06 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 23 Jan 2014 21:10:06 +0100 Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Vincent Davis wrote: > On Thu, Jan 23, 2014 at 12:02 PM, Peter Otten <__peter__ at web.de> wrote: >> >> I just noted that the first Python loop can be eliminated: Oops, I forgot to paste import string def chars(a, b): return "".join(map(chr, range(a, b))) _mapping = string.maketrans(chars(0, 10), chars(48, 58)) >> def debruijn(k, n): >> a = k * n * bytearray([0]) >> sequence = bytearray() >> extend = sequence.extend # factor out method lookup >> def db(t, p): >> if t > n: >> if n % p == 0: >> extend(a[1: p+1]) >> else: >> a[t] = a[t - p] >> db(t + 1, p) >> for j in xrange(a[t - p] + 1, k): >> a[t] = j >> db(t + 1, t) >> db(1, 1) >> return sequence.translate(_mapping) > > > I am not really sure what _mapping should be. The code above does not run > because > NameError: global name '_mapping' is not defined > I tried to get the bytearray > ? ? > sequence to convert to ascii but don't know how to. It does the same as adding 48 to every byte in the first variant: >>> import string >>> def chars(a, b): ... return "".join(map(chr, range(a, b))) ... >>> _mapping = string.maketrans(chars(0, 10), chars(48, 58)) >>> b = bytearray(range(10)) >>> b bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t') >>> b.translate(_mapping) bytearray(b'0123456789') The disadvantage of this approach is that it produces a new bytearray, i. e. it increases the peak amount of memory used by the function significantly. From breamoreboy at yahoo.co.uk Thu Jan 23 15:36:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Jan 2014 20:36:31 +0000 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On 23/01/2014 20:10, Peter Otten wrote: > Vincent Davis wrote: > >> On Thu, Jan 23, 2014 at 12:02 PM, Peter Otten <__peter__ at web.de> wrote: >>> >>> I just noted that the first Python loop can be eliminated: > > > Oops, I forgot to paste > > import string > def chars(a, b): > return "".join(map(chr, range(a, b))) > _mapping = string.maketrans(chars(0, 10), chars(48, 58)) > FTR string.maketrans is gone from Python 3.2+. Quoting from http://docs.python.org/dev/whatsnew/3.2.html#porting-to-python-3-2 "The previously deprecated string.maketrans() function has been removed in favor of the static methods bytes.maketrans() and bytearray.maketrans(). This change solves the confusion around which types were supported by the string module. Now, str, bytes, and bytearray each have their own maketrans and translate methods with intermediate translation tables of the appropriate type." -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From vincent at vincentdavis.net Thu Jan 23 15:51:03 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 23 Jan 2014 14:51:03 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 2:36 PM, Mark Lawrence wrote: > FTR string.maketrans is gone from Python 3.2+. Quoting from > http://docs.python.org/dev/whatsnew/3.2.html#porting-to-python-3-2 "The > previously deprecated string.maketrans() function has been removed in favor > of the static methods bytes.maketrans() and bytearray.maketrans(). This > change solves the confusion around which types were supported by the string > module. Now, str, bytes, and bytearray each have their own maketrans and > translate methods with intermediate translation tables of the appropriate > type." > ?Thanks for pointing this out Mark, ?I will soon be running this on 3.3+ Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From __peter__ at web.de Thu Jan 23 16:15:26 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 23 Jan 2014 22:15:26 +0100 Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Vincent Davis wrote: > On Thu, Jan 23, 2014 at 2:36 PM, Mark Lawrence > wrote: > >> FTR string.maketrans is gone from Python 3.2+. Quoting from >> http://docs.python.org/dev/whatsnew/3.2.html#porting-to-python-3-2 "The >> previously deprecated string.maketrans() function has been removed in >> favor of the static methods bytes.maketrans() and bytearray.maketrans(). >> This change solves the confusion around which types were supported by the >> string module. Now, str, bytes, and bytearray each have their own >> maketrans and translate methods with intermediate translation tables of >> the appropriate type." >> > > ?Thanks for pointing this out Mark, ?I will soon be running this on 3.3+ Well, my first post in this thread head this suspicious comment: > # Python 2 > def debruijn(k, n): In hindsight I have no idea what I was trying to say ;) Anyway, as a special service to Mark and Vincent here's an updated version that might work on both Python 2 and 3 (there's no test but the ad-hoc demo in the if __name__ == "__main__" block): [debruijn is Vincents original code, debruijn_bytes my modified version] $ cat debruijn_compat.py def debruijn(k, n): """ De Bruijn sequence for alphabet size k (0,1,2...k-1) and subsequences of length n. From wikipedia Sep 22 2013 """ a = [0] * k * n sequence = [] def db(t, p,): if t > n: if n % p == 0: for j in range(1, p + 1): sequence.append(a[j]) else: a[t] = a[t - p] db(t + 1, p) for j in range(int(a[t - p]) + 1, k): a[t] = j db(t + 1, t) db(1, 1) return ''.join(map(str, sequence)) _mapping = bytearray(b"?")*256 _mapping[:10] = b"0123456789" def debruijn_bytes(k, n): a = k * n * bytearray([0]) sequence = bytearray() extend = sequence.extend def db(t, p): if t > n: if n % p == 0: extend(a[1: p+1]) else: a[t] = a[t - p] db(t + 1, p) for j in range(a[t - p] + 1, k): a[t] = j db(t + 1, t) db(1, 1) return sequence.translate(_mapping).decode("ascii") if __name__ == "__main__": d1 = debruijn(4, 8) d2 = debruijn_bytes(4, 8) print(d1[:50]) print(d2[:50]) assert d1 == d2 $ python debruijn_compat.py 00000000100000002000000030000001100000012000000130 00000000100000002000000030000001100000012000000130 $ python3 debruijn_compat.py 00000000100000002000000030000001100000012000000130 00000000100000002000000030000001100000012000000130 $ python -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, 8)' 10 loops, best of 3: 53.5 msec per loop $ python -m timeit -s 'from debruijn_compat import debruijn_bytes as d' 'd(4, 8)' 10 loops, best of 3: 22.2 msec per loop $ python3 -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, 8)' 10 loops, best of 3: 68 msec per loop $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' 'd(4, 8)' 10 loops, best of 3: 21.7 msec per loop From indarkumar59 at gmail.com Thu Jan 23 16:15:06 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Thu, 23 Jan 2014 13:15:06 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]} Hi, I want to print a value before a particular value inside of a list associated with a key inside main dictionary(hosts) not the one inside nested dictionary. Forexample, I want the user to input ip e.g. 192.168.0.2 and then search through dictionary print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note that host id(e.g.PC2) is not known user just inputs IP. From emile at fenx.com Thu Jan 23 16:28:54 2014 From: emile at fenx.com (Emile van Sebille) Date: Thu, 23 Jan 2014 13:28:54 -0800 Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On 1/23/2014 1:15 PM, indar kumar wrote: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: >> Hi, >> >> >> >> I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public > > hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]} > > > Hi, > I want to print a value before a particular value inside of a list associated with a key inside main dictionary(hosts) not the one inside nested dictionary. > > Forexample, > I want the user to input ip e.g. 192.168.0.2 and then search through dictionary print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note that host id(e.g.PC2) is not known user just inputs IP. > Like this?: >>> hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', ... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}], ... 'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', ... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), ... '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]} >>> >>> searchfor = '192.168.0.1' >>> >>> print [ ii[0] for ii in hosts.values() if ii[1] == searchfor ] ['01:01:01:01:01:01'] From indarkumar59 at gmail.com Thu Jan 23 16:34:24 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Thu, 23 Jan 2014 13:34:24 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Just the value e.g.01:01:01:01:01:01 not the list From emile at fenx.com Thu Jan 23 16:49:30 2014 From: emile at fenx.com (Emile van Sebille) Date: Thu, 23 Jan 2014 13:49:30 -0800 Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: On 1/23/2014 1:34 PM, indar kumar wrote: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: >> Hi, >> >> >> >> I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public > > Just the value e.g.01:01:01:01:01:01 not the list > It may be time for you to work your way through the tutorial. Emile From breamoreboy at yahoo.co.uk Thu Jan 23 16:57:23 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 23 Jan 2014 21:57:23 +0000 Subject: The potential for a Python 2.8. Message-ID: http://regebro.wordpress.com/2014/01/23/the-potential-for-a-python-2-8/ I pretty much agree with the author. In fact, the sooner this whole ludicrous idea of Python 2.8 has been buried under a massive avalanche or cremated in a sizeable volcano, then the better for the future of Python development. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From indarkumar59 at gmail.com Thu Jan 23 16:56:21 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Thu, 23 Jan 2014 13:56:21 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <3cdf480e-e527-4c76-b87a-b6a34c9195fb@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Can I do the following to just get the value as string not the type list? searchfor = '192.168.0.2' z=[ii[0] for ii in hosts.values() if ii[1] == searchfor] >>> str1 = ''.join(z) >>> str1 From ben+python at benfinney.id.au Thu Jan 23 17:14:38 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 24 Jan 2014 09:14:38 +1100 Subject: datetime as subclass of date References: Message-ID: <85r47yfir5.fsf@benfinney.id.au> Skip Montanaro writes: > [?] I was asking [Python] if a datetime instance was an instance of a > date. Which, it turns out, it is. Yep. Makes sense, since ?datetime? can do everything ?date? can do, and is conceptually a subset of the same concept. The same is not true of the ?time? type from that module, by the way; it does not represent a specific point on the timeline. So ?datetime? inheriting from ?time? wouldn't make sense. Just in case anyone was wondering. -- \ ?There is something wonderful in seeing a wrong-headed majority | `\ assailed by truth.? ?John Kenneth Galbraith, 1989-07-28 | _o__) | Ben Finney From vincent at vincentdavis.net Thu Jan 23 17:55:01 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Thu, 23 Jan 2014 16:55:01 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On Thu, Jan 23, 2014 at 3:15 PM, Peter Otten <__peter__ at web.de> wrote: > $ python -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, 8)' > 10 loops, best of 3: 53.5 msec per loop > $ python -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 8)' > 10 loops, best of 3: 22.2 msec per loop > $ python3 -m timeit -s 'from debruijn_compat import debruijn as d' 'd(4, > 8)' > 10 loops, best of 3: 68 msec per loop > $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 8)' > 10 loops, best of 3: 21.7 msec per loop > Excellent Peter! I have a question, the times reported don't make sense to me, for example $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' 'd(4, 8)' 100 loops, best of 3: 10.2 msec per loop This took ~4 secs (stop watch) which is much more that 10*.0102 Why is this? $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' 'd(4, 11)' 10 loops, best of 3: 480 msec per loop? This took ~20 secs vs .480*10 d(4, 14) takes about 24 seconds (one run) Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From garyfallidis at gmail.com Thu Jan 23 16:53:51 2014 From: garyfallidis at gmail.com (Eleftherios Garyfallidis) Date: Thu, 23 Jan 2014 16:53:51 -0500 Subject: Dipy 0.7.1 is now available for download! Message-ID: Dear all, We are very happy to announce another major release of Diffusion Imaging in Python (Dipy). http://dipy.org Here we list some of the major new features: *0.7.1 *(Thursday, 16 Jan 2014) *Reconstruction* * Constrained Spherical Deconvolution (CSD). * Simple Harmonic Oscillator based Reconstruction and Estimation (SHORE). * Sharpening Deconvolution Transform (SDT). * Signal-to-noise ratio estimation. * RESTORE fitting for DTI. * Westin's Tensor maps. *Tracking* * Enabled automated seeding in masks. * Streamline filtering through specific ROIs using `target`. *Segmentation* * Brain and foreground extraction using median_otsu. *Visualization* * Streamtube visualization. * Simultaneous peaks and ODF visualization. *Connectivity * * Connectivity matrices and density maps. *Parallel processing* * Parallel processing is possible for all reconstruction models using `peaks_from_model`. *Data access* * Access to more publicly available datasets directly through Dipy functions. *Installation* * Installing Dipy is now easier and more universal. * Available with pip, easy_install, neurodebian and other methods. http://dipy.org/installation.html *Overall* * 3x more tutorials than previous release. http://dipy.org/examples_index.html * 2x more contributors from the previous release. http://dipy.org/developers.html Yours sincerely, On behalf of all Dipy developers Eleftherios Garyfallidis -------------- next part -------------- An HTML attachment was scrubbed... URL: From tjreedy at udel.edu Thu Jan 23 19:10:17 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jan 2014 19:10:17 -0500 Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <52E11AD1.4080305@galileo-press.de> Message-ID: > Johannes Schneider Wrote in > message: >> On 22.01.2014 20:18, Ned Batchelder wrote: >>> On 1/22/14 11:37 AM, Asaf Las wrote: >>> Chris is right here, too: modules are themselves singletons, no matter >>> how many times you import them, they are only executed once, and the >>> same module object is provided for each import. >> >> I'm not sure, if this is the whole truth. >> >> think about this example: >> >> cat bla.py >> a = 10 >> >> cat foo.py >> from bla import a This makes a a global in foo, bound to 10 >> def stuff(): >> return a This a refers to the global a in foo. >> cat bar.py >> from foo import stuff >> print stuff() >> a = 5 This bar.a is irrelevant to the behavior of stuff. >> print stuff() >> >> from bla import * >> print a >> >> python bar.py >> 10 foo.a == 10 >> 10 foo.a == 10 >> 10 bla.a == 10 >> here the a is coming from bla Twice and is known in the global namespace. There is no global namespace outside of modules. >> the value differs in stuff() No it does not. and before/after the import statement. foo.a does not change. bar.a is never used. >> So the instance of the module differs Nope. Each of the three module instances is constant. The bindings within each could change, but there are no rebinding in the code above. -- Terry Jan Reedy From roy at panix.com Thu Jan 23 19:10:23 2014 From: roy at panix.com (Roy Smith) Date: Thu, 23 Jan 2014 19:10:23 -0500 Subject: datetime as subclass of date References: Message-ID: In article , Ben Finney wrote: > Skip Montanaro writes: > > > [???] I was asking [Python] if a datetime instance was an instance of a > > date. Which, it turns out, it is. > > Yep. Makes sense, since ???datetime??? can do everything ???date??? can do, and > is conceptually a subset of the same concept. That's reasonable, but given that, it's weird that date(2014, 1, 23) == datetime(2014, 1, 23) is False. You would think it should be True, in the same way that 1 + 0j == 1 is True. From tjreedy at udel.edu Thu Jan 23 19:42:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jan 2014 19:42:41 -0500 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On 1/23/2014 4:57 PM, Mark Lawrence wrote: > http://regebro.wordpress.com/2014/01/23/the-potential-for-a-python-2-8/ > > I pretty much agree with the author. Except for one paragraph, which I consider a disservice to readers. "Does that mean a Python 2.8 can not happen? No, it can. If the Python "core developers decide that Python 3 was a dead end, then obviously a "Python 2.8 will happen. But that is a big if, and it certainly isn?t "going to happen anytime soon. This will never happen. Python 3 is the escape from several dead-ends in Python 2. The biggest in impact is the use of un-accented latin chars as text in a global, unicode world. "The other way it can happen if somebody forks Python 2, and makes a "Python 2.8. It will have to be released under another name, though, "but should ?Psnakes 2.8? become a big success, this may also change "the core developers minds. Not mine, and I am sure many if not all others. I believe Python 3 is already more successful than my first Python, 1.3, was. Python 3 is the bugfix for several design bugs in Python 1 and 2. The idea that we would we *ever* unfix those bugs is ludicrous. > In fact, the sooner this whole > ludicrous idea of Python 2.8 has been buried under a massive avalanche > or cremated in a sizeable volcano, then the better for the future of > Python development. Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. Developers informally said 'No 2.8'. People would not believe that. So developers formally said 'No 2.8'. They even inverted the purpose of PEP to make the formal announcement visible and permanent. And a few people still do not want to believe it. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jan 23 19:59:31 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jan 2014 19:59:31 -0500 Subject: SQLite + FTS (full text search) In-Reply-To: References: Message-ID: On 1/23/2014 8:24 AM, Asaf Las wrote: > On Thursday, January 23, 2014 2:20:31 PM UTC+2, Mark Summerfield wrote: >> Hi, >> On my Debian stable 64-bit system, SQLite3 has FTS (full text search) >> enabled (although at version 3 rather than the recommended version 4): >> >> Python 3.2.3 (default, Feb 20 2013, 14:44:27) [GCC 4.7.2] on linux2 >> Type "copyright", "credits" or "license()" for more information. >>>>> import sqlite3 >>>>> con = sqlite3.connect(":memory:") >>>>> cur = con.execute("pragma compile_options") >>>>> for row in cur: >> print(row) >> ... >> ('ENABLE_FTS3',) >> ... >> But on Windows when I use the official Python 3.3 32-bit binary >> from www.python.org this is not enabled. On 64 bit 3.4.0b2, the output is ('THREADSAFE=1',) >> My guess is that on Debian, the packagers install a full SQLite 3 >> and the Python package uses that. But on Windows I think the Python >> packagers bundle their own SQLite (quite rightly since it might not >> already be installed). >> >> I'd like the Windows binary to include SQLite 3 with FTS4 support, >> but I don't know how much work that involves or if it would make >> the Python .msi file too big? >> >> Anyway, I guess if anyone else is interested in this they >> could perhaps reply to indicate this? >> If you're curious about the feature, it is documented here: >> >> http://www.sqlite.org/fts3.html > > It is compile time option. > http://www.sqlite.org/compile.html#enable_fts3 > you have to build it with this option enabled. If one clones the hg.python.org/cpython repository and runs Tools/buildbots/external.bat with minimal svn installed, it copies sqlite3 source into sqlite-3.8.1 with files shell.c sqlite3.c # 5 mb sqlite3.h sqlite3ext.h If that is everything needed for FTS and if pcbuild/ _sqlite3 and sqlite3 project files were altered to change the compile option and anything else needed ... then you would have FTS on Windows. -- Terry Jan Reedy From rosuav at gmail.com Thu Jan 23 20:00:02 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jan 2014 12:00:02 +1100 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 11:42 AM, Terry Reedy wrote: > Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. > Developers informally said 'No 2.8'. People would not believe that. So > developers formally said 'No 2.8'. They even inverted the purpose of PEP to > make the formal announcement visible and permanent. And a few people still > do not want to believe it. Can I get a new version of Java 1.1.8 please? I want it to include all the cool features that I want from the newer versions, but it has to still run all my existing code. I'm not going to put in any effort to actually _make_ this, I want you to do it for me. Actually, the Java versioning system was enough of a mess that, to this day, I don't know what version(s) my old Java code would and wouldn't run on. So glad to have moved away from that. At least with Python, semantic versioning [1] means everyone knows what everyone's talking about. Python 2.8 has to be broadly compatible with 2.7 and doesn't have to be compatible with 3.3. (Which, incidentally, is at odds with some people's idea of a 2.8, which would be incompatible with both. I'm not sure what that would be called - e.1? sqrt(8).0? Something else?) The noise asking for a 2.8 isn't going to die down any time soon. It'll flare up again every time there's a significant event in the 2.7's end of life: when it goes into source-only support, when its python.org support ends entirely, when Debian's next version won't ship it, when Red Hat's ditto ditto, when it's no longer possible to get it from Ubuntu's repositories, etc, etc, etc. And no amount of "There will be no 2.8 unless you make it yourself!" will change that. That's my prediction. ChrisA [1] Not sure if Python's actually stated that http://semver.org/ principles are guaranteed to be followed, but they're certainly approximated to From tjreedy at udel.edu Thu Jan 23 20:03:08 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jan 2014 20:03:08 -0500 Subject: sqlite3 docbug (was problem with sqlite3) In-Reply-To: <20140123063634.2ad5169e@bigbox.christie.dr> References: <52e07f45$0$3631$426a34cc@news.free.fr> <1f13ee0c-5cb5-4627-9f38-2058a8235083@googlegroups.com> <20140123063634.2ad5169e@bigbox.christie.dr> Message-ID: On 1/23/2014 7:36 AM, Tim Chase wrote: > On 2014-01-23 05:43, Terry Reedy wrote: >> A list instead of a tuple does work, but not an iterable, so >> 'sequence'. > > In the OP's case using sqlite drivers, this is true. However, I > maintain some old 2.4 code that uses a correspondingly ancient version > of mx.ODBC which requires a tuple and raises an exception on any other > iterable. So I always use a tuple out of habit, even if it would be > easier to just use some other iterable. I would check 2.7 behavior before changing the 2.7 doc. -- Terry Jan Reedy From davea at davea.name Thu Jan 23 20:08:16 2014 From: davea at davea.name (Dave Angel) Date: Thu, 23 Jan 2014 20:08:16 -0500 (EST) Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Vincent Davis Wrote in message: > I didn't really study the code, and the fact that there's a nested function could mess it up. But if it were a straightforward function with exactly one append, , then replacing the append with a yield would produce the string one character at a time. -- DaveA From tjreedy at udel.edu Thu Jan 23 20:11:51 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 23 Jan 2014 20:11:51 -0500 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On 1/23/2014 8:00 PM, Chris Angelico wrote: > The noise asking for a 2.8 isn't going to die down any time soon. I suspect you meant "isn't going to die completely" > It'll flare up again every time there's a significant event in the > 2.7's end of life: when it goes into source-only support, when its > python.org support ends entirely, when Debian's next version won't > ship it, when Red Hat's ditto ditto, when it's no longer possible to > get it from Ubuntu's repositories, etc, etc, etc. And no amount of > "There will be no 2.8 unless you make it yourself!" will change that. > > That's my prediction. Sadly, mine too. Maybe the flareup peaks will gradually become lower. Or maybe they will not be discussed so much on python-list. -- Terry Jan Reedy From rosuav at gmail.com Thu Jan 23 20:16:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jan 2014 12:16:29 +1100 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 12:11 PM, Terry Reedy wrote: > On 1/23/2014 8:00 PM, Chris Angelico wrote: > >> The noise asking for a 2.8 isn't going to die down any time soon. > > I suspect you meant "isn't going to die completely" Sorry, yeah. "die off" is the expression I should have used. Presumably it *will* die down in between the renewals, otherwise we wouldn't recognize the renewals. >> It'll flare up again every time there's a significant event in the >> 2.7's end of life: when it goes into source-only support, when its >> python.org support ends entirely, when Debian's next version won't >> ship it, when Red Hat's ditto ditto, when it's no longer possible to >> get it from Ubuntu's repositories, etc, etc, etc. And no amount of >> "There will be no 2.8 unless you make it yourself!" will change that. >> >> That's my prediction. > > Sadly, mine too. Maybe the flareup peaks will gradually become lower. Or > maybe they will not be discussed so much on python-list. Maybe. I suspect that python-list and/or python-dev will see at least some of the traffic, though - when (say) Debian-next is stated as no longer shipping with any Python 2.7, there'll be a bunch of Debian users coming along asking why there won't be a 2.8, and repeat for any other major distribution in place of Debian. ChrisA From tharanga.abeyseela at gmail.com Thu Jan 23 20:44:24 2014 From: tharanga.abeyseela at gmail.com (Tharanga Abeyseela) Date: Fri, 24 Jan 2014 12:44:24 +1100 Subject: Elementree and insert new element if it is not present Message-ID: Hi, I have the following xml,a nd i need to add Description element if it is not present. xxxXWorld's Fastest Indian, The xxxThe World's Fastest Indian The World's Fastest Indian World's Fastest Indian, The here is my function. def insert_description(root,type): for child in root.findall('.//{ http://schemas.microsoft.com/xxx/2011/06/13/ingest}%s' % type): title=child.find('.//{ http://schemas.microsoft.com/xxx/2011/06/13/ingestion}Title').text try: if child.find('Description') is None: new_desc = ET.Element('Description') new_desc.text = title child.insert(1, new_desc) except: pass root is the xm lfile, type includes (movies,shows,dramas etc) But this will add the description without checking the "Description" is exist. i have a problem with the following statement. (i guess) if child.find('Description') is None: what i'm doing wrong here, appreciate your help Regards, Tharanga -------------- next part -------------- An HTML attachment was scrubbed... URL: From python at mrabarnett.plus.com Thu Jan 23 21:05:39 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 24 Jan 2014 02:05:39 +0000 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: <52E1CA73.7030506@mrabarnett.plus.com> On 2014-01-24 01:00, Chris Angelico wrote: > On Fri, Jan 24, 2014 at 11:42 AM, Terry Reedy wrote: >> Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. >> Developers informally said 'No 2.8'. People would not believe that. So >> developers formally said 'No 2.8'. They even inverted the purpose of PEP to >> make the formal announcement visible and permanent. And a few people still >> do not want to believe it. > > Can I get a new version of Java 1.1.8 please? I want it to include all > the cool features that I want from the newer versions, but it has to > still run all my existing code. I'm not going to put in any effort to > actually _make_ this, I want you to do it for me. > > Actually, the Java versioning system was enough of a mess that, to > this day, I don't know what version(s) my old Java code would and > wouldn't run on. So glad to have moved away from that. At least with > Python, semantic versioning [1] means everyone knows what everyone's > talking about. Python 2.8 has to be broadly compatible with 2.7 and > doesn't have to be compatible with 3.3. (Which, incidentally, is at > odds with some people's idea of a 2.8, which would be incompatible > with both. I'm not sure what that would be called - e.1? sqrt(8).0? > Something else?) > [snip] Python 2.8j? From roy at panix.com Thu Jan 23 21:22:42 2014 From: roy at panix.com (Roy Smith) Date: Thu, 23 Jan 2014 21:22:42 -0500 Subject: The potential for a Python 2.8. References: Message-ID: In article , MRAB wrote: > On 2014-01-24 01:00, Chris Angelico wrote: > > On Fri, Jan 24, 2014 at 11:42 AM, Terry Reedy wrote: > >> Burying 'Python 2.8' was the purpose of PEP 404. It is kind of bizarre. > >> Developers informally said 'No 2.8'. People would not believe that. So > >> developers formally said 'No 2.8'. They even inverted the purpose of PEP to > >> make the formal announcement visible and permanent. And a few people still > >> do not want to believe it. > > > > Can I get a new version of Java 1.1.8 please? I want it to include all > > the cool features that I want from the newer versions, but it has to > > still run all my existing code. I'm not going to put in any effort to > > actually _make_ this, I want you to do it for me. > > > > Actually, the Java versioning system was enough of a mess that, to > > this day, I don't know what version(s) my old Java code would and > > wouldn't run on. So glad to have moved away from that. At least with > > Python, semantic versioning [1] means everyone knows what everyone's > > talking about. Python 2.8 has to be broadly compatible with 2.7 and > > doesn't have to be compatible with 3.3. (Which, incidentally, is at > > odds with some people's idea of a 2.8, which would be incompatible > > with both. I'm not sure what that would be called - e.1? sqrt(8).0? > > Something else?) > > > [snip] > Python 2.8j? You're imagining things. From rosuav at gmail.com Thu Jan 23 21:28:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jan 2014 13:28:05 +1100 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> Python 2.8j? > > You're imagining things. Get real... s'not gonna happen. ChrisA From roy at panix.com Thu Jan 23 21:34:43 2014 From: roy at panix.com (Roy Smith) Date: Thu, 23 Jan 2014 21:34:43 -0500 Subject: The potential for a Python 2.8. References: Message-ID: In article , Chris Angelico wrote: > On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: > >> Python 2.8j? > > > > You're imagining things. > > Get real... s'not gonna happen. > I wouldn't bet on that. The situation keeps getting tensor and tensor. From rosuav at gmail.com Thu Jan 23 21:39:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jan 2014 13:39:34 +1100 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 1:34 PM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> >> Python 2.8j? >> > >> > You're imagining things. >> >> Get real... s'not gonna happen. >> > I wouldn't bet on that. The situation keeps getting tensor and tensor. I can't complain, really. This was a perfectly rational discussion until I suggested "e.1". ChrisA From tharanga.abeyseela at gmail.com Thu Jan 23 22:10:26 2014 From: tharanga.abeyseela at gmail.com (Tharanga Abeyseela) Date: Fri, 24 Jan 2014 14:10:26 +1100 Subject: Elementree and insert new element if it is not present - FIXED Message-ID: manged to fix it. need to add the namespace when checking the condition. Thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: From indarkumar59 at gmail.com Thu Jan 23 22:15:51 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Thu, 23 Jan 2014 19:15:51 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <62acd633-3b45-4c4f-9e1c-1df56a11d28d@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Thanks config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200']} What if I want to search for a particular value inside the lists of all keys except one that user inputs and also want to print that value. Forexample, user gets prompt to enter following four parameters prompt1= "Enter " After user has input I have added this information into above dictionary(config_database) but I also need to check if this ip is not already assigned to a PC other than the one which user inputs. So how to search for particular value inside the lists associated with keys other than inside that one which user inputs(because obviously then it would match so just want to skip its own entry) and print that value. From ayushidalmia2604 at gmail.com Fri Jan 24 00:42:39 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Thu, 23 Jan 2014 21:42:39 -0800 (PST) Subject: Initialise dictionary of dictionary In-Reply-To: References: Message-ID: Thank you so much Tim. This is precisely what I wanted to do! On Thursday, January 23, 2014 9:00:23 PM UTC+5:30, Tim Chase wrote: > On 2014-01-23 07:15, Ayushi Dalmia wrote: > > > I need to initialise a dictionary of dictionary with float values. > > > I do not know the size of the dictionary beforehand. How can we do > > > that in Python -- > > > > Either > > > > d = {} > > > > or, if you want > > > > from collections import defaultdict > > d = defaultdict(float) > > print(d["Hello"]) > > > > If you really do want a dict-of-dict that defaults to floats, you can > > do > > > > d = defaultdict(lambda: defaultdict(float)) > > print(d[3141]["Hello"]) > > > > -tkc From rustompmody at gmail.com Fri Jan 24 00:57:01 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 23 Jan 2014 21:57:01 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: <62acd633-3b45-4c4f-9e1c-1df56a11d28d@googlegroups.com> References: <62acd633-3b45-4c4f-9e1c-1df56a11d28d@googlegroups.com> Message-ID: <77341c7d-7416-45e4-a71c-78ced6d0b03f@googlegroups.com> On Friday, January 24, 2014 8:45:51 AM UTC+5:30, indar kumar wrote: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > > > Hi, > > > > > > > > > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public > > > > Thanks > > > > config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200']} > > > > What if I want to search for a particular value inside the lists of all keys except one that user inputs and also want to print that value. > > > > Forexample, user gets prompt to enter following four parameters > > prompt1= "Enter " > > > > After user has input I have added this information into above dictionary(config_database) but I also need to check if this ip is not already assigned to a PC other than the one which user inputs. So how to search for particular value inside the lists associated with keys other than inside that one which user inputs(because obviously then it would match so just want to skip its own entry) and print that value. Does this suggest some ideas to you?? >>> config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200']} >>> {pc:config_database[pc][1] for pc in config_database.keys()} {'PC2': '192.168.0.2', 'PC3': '192.168.0.3', 'PC1': '192.168.0.1'} Or even simpler >>> {pc:config_database[pc][1] for pc in config_database} {'PC2': '192.168.0.2', 'PC3': '192.168.0.3', 'PC1': '192.168.0.1'} From ben+python at benfinney.id.au Fri Jan 24 01:54:26 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 24 Jan 2014 17:54:26 +1100 Subject: datetime as subclass of date References: Message-ID: <85lhy5g999.fsf@benfinney.id.au> Roy Smith writes: > Ben Finney wrote: > > > Makes sense, since ?datetime? can do everything ?date? can do, and > > is conceptually a subset of the same concept. > > That's reasonable, but given that, it's weird that date(2014, 1, 23) == > datetime(2014, 1, 23) is False. You would think it should be True, in > the same way that 1 + 0j == 1 is True. Hmm. It does make sense to me that ?datetime.date(2014, 1, 23) == datetime.datetime(2014, 1, 23)?. I can come up with rationalisations for why it isn't, but they're not satisfactory. I also don't consider it a bug, though. I'm conflicted :-) -- \ ?Those who write software only for pay should go hurt some | `\ other field.? ?Erik Naggum, in _gnu.misc.discuss_ | _o__) | Ben Finney From indarkumar59 at gmail.com Fri Jan 24 02:14:13 2014 From: indarkumar59 at gmail.com (indar kumar) Date: Thu, 23 Jan 2014 23:14:13 -0800 (PST) Subject: Can post a code but afraid of plagiarism In-Reply-To: References: Message-ID: <14e7775c-2a79-46eb-8f25-d9ac7fc1eb01@googlegroups.com> On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: > Hi, > > > > I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public Yes now I want to search for an ip that user has input but skipping the key which user has input. e.g. user entered PC1 and 192.168.0.1. Now I want to scan through config_database to see if this ip is already in it. But PC1 192.168.0.1 is added to config_database before searching so I want to skip PC1 key during searching so that I can see if this Ip is not already associated with any other host. From steve+comp.lang.python at pearwood.info Fri Jan 24 03:13:44 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 24 Jan 2014 08:13:44 GMT Subject: Can post a code but afraid of plagiarism References: <62acd633-3b45-4c4f-9e1c-1df56a11d28d@googlegroups.com> Message-ID: <52e220b8$0$29999$c3e8da3$5496439d@news.astraweb.com> On Thu, 23 Jan 2014 19:15:51 -0800, indar kumar wrote: > What if I want to search for a particular value inside the lists of all > keys except one that user inputs and also want to print that value. Then go right ahead and do so. You are learning Python, so this should be covered in your course. Did you follow the advice to work through the Python tutorial? http://docs.python.org/2/tutorial/ http://docs.python.org/3/tutorial/ depending on whether you are using Python 2 or 3. This is supposed to be your work, not ours. Start by writing down how you would solve this problem as a human being: for each key: if the key is the one the user inputted, skip this key otherwise: get all the lists for this key for each list: search for the value Now change that to Python code. Don't just ask us to solve the problem for you. -- Steven From johannes.schneider at galileo-press.de Fri Jan 24 03:20:37 2014 From: johannes.schneider at galileo-press.de (Johannes Schneider) Date: Fri, 24 Jan 2014 09:20:37 +0100 Subject: SIngleton from __defaults__ In-Reply-To: References: <26ff768d-349c-48cd-a46f-25343807e18a@googlegroups.com> <52E11AD1.4080305@galileo-press.de> Message-ID: <52E22255.4020701@galileo-press.de> thnx guys. On 24.01.2014 01:10, Terry Reedy wrote: >> Johannes Schneider Wrote in >> message: >>> On 22.01.2014 20:18, Ned Batchelder wrote: >>>> On 1/22/14 11:37 AM, Asaf Las wrote: >>>> Chris is right here, too: modules are themselves singletons, no matter >>>> how many times you import them, they are only executed once, and the >>>> same module object is provided for each import. >>> >>> I'm not sure, if this is the whole truth. >>> >>> think about this example: >>> >>> cat bla.py >>> a = 10 >>> >>> cat foo.py >>> from bla import a > > This makes a a global in foo, bound to 10 > >>> def stuff(): >>> return a > > This a refers to the global a in foo. > >>> cat bar.py >>> from foo import stuff >>> print stuff() >>> a = 5 > > This bar.a is irrelevant to the behavior of stuff. > >>> print stuff() >>> >>> from bla import * >>> print a >>> >>> python bar.py >>> 10 > > foo.a == 10 > >>> 10 > > foo.a == 10 > >>> 10 > > bla.a == 10 > >>> here the a is coming from bla > > Twice > > and is known in the global namespace. > > There is no global namespace outside of modules. > >>> the value differs in stuff() > > No it does not. > > and before/after the import statement. > > foo.a does not change. bar.a is never used. > >>> So the instance of the module differs > > Nope. Each of the three module instances is constant. The bindings > within each could change, but there are no rebinding in the code above. > -- Johannes Schneider Webentwicklung johannes.schneider at galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Gesch?ftsf?hrer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn From __peter__ at web.de Fri Jan 24 03:23:36 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Jan 2014 09:23:36 +0100 Subject: generate De Bruijn sequence memory and string vs lists References: Message-ID: Vincent Davis wrote: > Excellent Peter! > I have a question, the times reported don't make sense to me, for example > $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 8)' > 100 loops, best of 3: 10.2 msec per loop > This took ~4 secs (stop watch) which is much more that 10*.0102 Why is > this? Look at the output, it's "100 loops" 100 * 10 msec == 1 sec together with "best of 3" you are already at 3 sec, minimum as it is the "best" run. Then, how do you think Python /knows/ that it has to repeat the code 10 times on my "slow" and 100 times on your "fast" machine? It runs the bench once, then 10, then 100, then 1000 times -- until there's a run that takes 0.2 secs or more. The total expected minimum time without startup overhead is then +----calibration------+ +-measurement--+ (1 + 10 + 100) * 10msec + 3 * 100 * 10msec or about 4 secs. > $ python3 -m timeit -s 'from debruijn_compat import debruijn_bytes as d' > 'd(4, 11)' > 10 loops, best of 3: 480 msec per loop? > This took ~20 secs vs .480*10 >>> .480*(1 + 10 + 3*10) 19.68 > d(4, 14) takes about 24 seconds (one run) This is left as an exercise ;) From greg.ewing at canterbury.ac.nz Fri Jan 24 03:29:18 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 24 Jan 2014 21:29:18 +1300 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: Vincent Davis wrote: > I plan to use the sequence as an index to count occurrences of sequences > of length n. If all you want is a mapping between a sequence of length n and compact representation of it, there's a much simpler way: just convert it to a base-k integer, where k is the size of the alphabet. The resulting integer won't be any larger than an index into the de Bruijn sequence would be, and you can easily recover the original sequence from its encoding without needing any kind of lookup table. -- Greg From frank at chagford.com Fri Jan 24 04:21:12 2014 From: frank at chagford.com (Frank Millman) Date: Fri, 24 Jan 2014 11:21:12 +0200 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmokZUHta7Y3x_=6eUjKpv2Td2iaqro1su7NuLo+gfzwag at mail.gmail.com... > On Thu, Jan 23, 2014 at 8:16 AM, Asaf Las wrote: >> i am novice in python, but let me suggest you something: >> it would be beneficial to use json text file to specify >> your gui so composite data structure can be created using >> json and then your program can construct window giving >> its content will be based on simple text file? >> You can add every parameter to json encoded window system >> once your window construction will be using as interpreter >> for that. JSON is very structured and quite presentable for >> such kind of things. >> >> What Gurus do think about this suggestion? > > JSON is better than XML for that, but in my opinion, both are > unnecessary. Python code is easy to edit. (See [1] for more on Python > and XML.) When you're writing compiled code, it makes good sense to > drop out of code and use a simple text file when you can; but when > your code *is* a simple text file, why go to the effort of making a > JSON-based window builder? (Unless you already have one. GladeXML may > well be exactly what you want, in which case, go ahead and use it. But > personally, I don't.) JSON is a fantastic format for transmitting > complex objects around the internet; it's compact (unlike XML), > readable in many languages (like XML), easily readable by humans > (UNLIKE XML!), and can represent all the most common data structures > (subtly, XML can't technically do this). It's superb at what it > does... but it doesn't do Python GUIs. For those, use Python itself. > I find that I am using JSON and XML more and more in my project, so I thought I would explain what I am doing to see if others think this is an acceptable approach or if I have taken a wrong turn. I have various data structures, some simple, some more complex, of which I have many instances. I want to serialise and store them in a database. This has two benefits. Firstly, I just have to write one piece of python code that interprets and deals with each structure, so it avoids duplicate code. Secondly, I can design a gui that exposes the structures to non-programmers, giving them the ability to modify them or create new ones. Simple structures can be expressed in JSON. I use XML to represent the more complex ones. I will give two examples, one simple and one complex. I store database metadata in the database itself. I have a table that defines each table in the database, and I have a table that defines each column. Column definitions include information such as data type, allow null, allow amend, maximum length, etc. Some columns require that the value is constrained to a subset of allowable values (e.g. 'title' must be one of 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint, but I have added some additional features which can't be handled by that. So I have a column in my column-definition table called 'choices', which contains a JSON'd list of allowable choices. It is actually more complex than that, but this will suffice for a simple example. For my more complex example, I should explain that my project involves writing a generalised business/accounting system. Anyone who has worked on these knows that you quickly end up with hundreds of database tables storing business data, and hundreds of forms allowing users to CRUD the data (create/read/update/delete). Each form is unique, and yet they all share a lot of common characteristics. I have abstracted the contents of a form sufficiently that I can represent at least 90% of it in XML. This is not just the gui, but all the other elements - the tables required, any input parameters, any output parameters, creating any variables to be used while entering the form, any business logic to be applied at each point, etc. Each form definition is stored as gzip'd XML in a database, and linked to the menu system. There is just one python program that responds to the selection of a menu option, retrieves the form from the database, unpacks it and runs it. Incidentally, I would take issue with the comment that 'JSON is easily readable by humans (UNLIKE XML)'. Here is a more complete example of my 'choices' definition. [true, true, [["admin", "System administrator", [], []], ["ind", "Individual", [["first_name", true], ["surname", true]], [["first_name", " "], ["surname", ""]]], ["comp", "Company", [["comp_name", true], ["reg_no", true], ["vat_no", false]], [["comp_name", ""]]]]] You can read it, but what does it mean? This is what it would look like if I stored it in XML - More verbose - sure. Less human-readable - I don't think so. Also, intuitively one would think it would take much longer to process the XML version compared with the JSON version. I have not done any benchmarks, but I use lxml, and I am astonished at the speed. Admittedly a typical form-processor spends most of its time waiting for user input. Even so, for my purposes, I have never felt the slightest slowdown caused by XML. Comments welcome. Frank Millman From wxjmfauth at gmail.com Fri Jan 24 04:33:26 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 24 Jan 2014 01:33:26 -0800 (PST) Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: Le vendredi 24 janvier 2014 01:42:41 UTC+1, Terry Reedy a ?crit?: > > > > This will never happen. Python 3 is the escape from several dead-ends in > > Python 2. The biggest in impact is the use of un-accented latin chars as > > text in a global, unicode world. > > > Three days of discussion on how to make the next release more "ascii" compatible. I put "ascii" in quotes, because the efforts to define "ascii" were more laughable. jmf From hottrack88 at gmail.com Fri Jan 24 04:44:02 2014 From: hottrack88 at gmail.com (hottrack88 at gmail.com) Date: Fri, 24 Jan 2014 01:44:02 -0800 (PST) Subject: Single Object Detection and Tracking Steps Message-ID: <7c985507-406a-4a79-9ddc-fdb02574ff52@googlegroups.com> I am doing single object detection and tracking in a video file using python & opencv2. As far I know the steps are, Video to frame conversion Grayscale conversion Thresholding After phase 3, I got sequence of binary images. My questions are: How to identify (detect) whether the object is moving or not? How to get(track) the object moving coordinates(x,y position)? Which method should I use for these? I got confused with the words like SIFT feature, Kalman filter, Particle filter, optical flow filter etc. Please help me by giving next upcoming steps details. Thanks in advance. From rustompmody at gmail.com Fri Jan 24 04:53:40 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 24 Jan 2014 01:53:40 -0800 (PST) Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: <39e1dd33-2162-40ea-8676-d27c8360aff3@googlegroups.com> On Friday, January 24, 2014 2:51:12 PM UTC+5:30, Frank Millman wrote: > Incidentally, I would take issue with the comment that 'JSON is easily > readable by humans (UNLIKE XML)'. Here is a more complete example of my > 'choices' definition. > [true, true, [["admin", "System administrator", [], []], ["ind", > "Individual", [["first_name", true], ["surname", true]], [["first_name", " > "], ["surname", ""]]], ["comp", "Company", [["comp_name", true], ["reg_no", > true], ["vat_no", false]], [["comp_name", ""]]]]] > You can read it, but what does it mean? > This is what it would look like if I stored it in XML - > More verbose - sure. Less human-readable - I don't think so. > Also, intuitively one would think it would take much longer to process the > XML version compared with the JSON version. I have not done any benchmarks, > but I use lxml, and I am astonished at the speed. Admittedly a typical > form-processor spends most of its time waiting for user input. Even so, for > my purposes, I have never felt the slightest slowdown caused by XML. > Comments welcome. Of json/XML/yml I prefer yml because it has the terseness of json and the structuredness of xml -- well almost The flipside is that pyyaml needs to be installed unlike json. But then you are installing lxml anyway From kvxdelta at gmail.com Fri Jan 24 05:05:04 2014 From: kvxdelta at gmail.com (theguy) Date: Fri, 24 Jan 2014 02:05:04 -0800 (PST) Subject: Need Help with Programming Science Project Message-ID: I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. I so far have three different authors in the program and have already put in the example text but for some reason, the program always leans toward one specific author, Suzanne Collins, no matter what insane number I try to put in or how much I tinker with the coding. I would post the code, but I don't know if it's fine to put it here, as it contains pieces from books. I do believe that would go against copyright laws. If I can figure out a way to put it in without the bits from the stories, then I'll do so, but as of now, any help is appreciated. I understand I'm not exactly making it easy since I'm not putting up any code, but I'm kind of desperate for help here, as I can't seem to find anybody or anything else helpful in any way. Thank you. From __peter__ at web.de Fri Jan 24 06:07:35 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 24 Jan 2014 12:07:35 +0100 Subject: Need Help with Programming Science Project References: Message-ID: theguy wrote: > I have a science project that involves designing a program which can > examine a bit of text with the author's name given, then figure out who > the author is if another piece of example text without the name is given. > I so far have three different authors in the program and have already put > in the example text but for some reason, the program always leans toward > one specific author, Suzanne Collins, no matter what insane number I try > to put in or how much I tinker with the coding. I would post the code, but > I don't know if it's fine to put it here, as it contains pieces from > books. I do believe that would go against copyright laws. If I can figure > out a way to put it in without the bits from the stories, then I'll do so, > but as of now, any help is appreciated. I understand I'm not exactly mak > ing it easy since I'm not putting up any code, but I'm kind of desperate > for help here, as I can't seem to find anybody or anything else helpful > in any way. Thank you. If I were to speculate what your program might look like: text_samples = { "Suzanne Collins": "... some text by collins ...", "J. K. Rowling": "... some text by rowling ...", #... } unknown = "... sample text by unknown author ..." def calc_match(text1, text2): import random return random.random() guessed_author = None guessed_match = None for author, text in text_samples.items(): match = calc_match(unknown, text) print(author, match) if guessed_author is None or match > guessed_match: guessed_author = author guessed_match = match print("The author is", guessed_author) The important part in this script are not the text samples or the loop to determine the best match -- it's the algorithm used to determine how good two texts match. In the above example that algorithm is encapsulated in the calc_match() function and it's really bad, it gives you random numbers between 0 and 1. For us to help you it should be sufficient when you post the analog of this function in your code together with a description in plain english of how it is meant to calculate the similarity between two texts. Alternatavely, instead of the copyrighted texts grab text samples from project gutenberg with expired copyright. Make sure that the resulting post is as short as possible -- long text samples don't make the post clearer than short ones. From rosuav at gmail.com Fri Jan 24 06:18:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 24 Jan 2014 22:18:01 +1100 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: On Fri, Jan 24, 2014 at 8:21 PM, Frank Millman wrote: > I find that I am using JSON and XML more and more in my project, so I > thought I would explain what I am doing to see if others think this is an > acceptable approach or if I have taken a wrong turn. Please don't take this the wrong way, but the uses of JSON and XML that you describe are still completely inappropriate. Python does not need this sort of thing. > I store database metadata in the database itself. I have a table that > defines each table in the database, and I have a table that defines each > column. Column definitions include information such as data type, allow > null, allow amend, maximum length, etc. Some columns require that the value > is constrained to a subset of allowable values (e.g. 'title' must be one of > 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint, > but I have added some additional features which can't be handled by that. So > I have a column in my column-definition table called 'choices', which > contains a JSON'd list of allowable choices. It is actually more complex > than that, but this will suffice for a simple example. This is MySQL-style of thinking, that a database is a thing that's interpreted by an application. The better way to do it is to craft a check constraint; I don't know what features you're trying to use that can't be handled by that, but (at least in PostgreSQL) I've never had anything that can't be expressed that way. With the simple example you give, incidentally, it might be better to use an enumeration rather than a CHECK constraint, but whichever way. > For my more complex example, I should explain that my project involves > writing a generalised business/accounting system. Anyone who has worked on > these knows that you quickly end up with hundreds of database tables storing > business data, and hundreds of forms allowing users to CRUD the data > (create/read/update/delete). Each form is unique, and yet they all share a > lot of common characteristics. I have abstracted the contents of a form > sufficiently that I can represent at least 90% of it in XML. This is not > just the gui, but all the other elements - the tables required, any input > parameters, any output parameters, creating any variables to be used while > entering the form, any business logic to be applied at each point, etc. Each > form definition is stored as gzip'd XML in a database, and linked to the > menu system. There is just one python program that responds to the selection > of a menu option, retrieves the form from the database, unpacks it and runs > it. Write your rendering engine as a few simple helper functions, and then put all the rest in as code instead of XML. The easiest way to go about it is to write three forms, from scratch, and then look at the common parts and figure out which bits can go into helper functions. You'll find that you can craft a powerful system with just a little bit of code, if you build it right, and it'll mean _less_ library code than you currently have as XML. If you currently represent 90% of it in XML, then you could represent 90% of it with simple calls to helper functions, which is every bit as readable (probably more so), and much *much* easier to tweak. Does your XML parsing engine let you embed arbitrary expressions into your code? Can you put a calculated value somewhere? With Python, everything's code, so there's no difference between saying "foo(3)" and saying "foo(1+2)". > Incidentally, I would take issue with the comment that 'JSON is easily > readable by humans (UNLIKE XML)'. Here is a more complete example of my > 'choices' definition. > > [true, true, [["admin", "System administrator", [], []], ["ind", > "Individual", [["first_name", true], ["surname", true]], [["first_name", " > "], ["surname", ""]]], ["comp", "Company", [["comp_name", true], ["reg_no", > true], ["vat_no", false]], [["comp_name", ""]]]]] > > You can read it, but what does it mean? > > This is what it would look like if I stored it in XML - > > > > > > > > > > > > > > > > > > > > > > > > > > > > > More verbose - sure. Less human-readable - I don't think so. Well, that's because you elided all the names in the JSON version. Of course that's not a fair comparison. :) Here's how I'd render that XML in JSON. I assume that this is stored in a variable, database field, or whatever, named "choices", and so I skip that first-level name. {"use_subtypes":true, "use_displaynames":true, "choice":[ {"code":"admin", "descr":"System administrator", "subtype_columns":[], "displaynames":[]}, {"code":"ind", "descr":"Individual", "subtype_columns":[ {"col_name":"first_name", "required":true}, {"col_name":"surname", "required":true} ], "displaynames":[ {"col_name":"first_name", "separator":" "}, {"col_name":"surname", "separator":""} ] }, {"code":"comp", "descr":"Company", "subtype_columns":[ {"col_name":"comp_name", "required":true}, {"col_name":"reg_no", "required":true}, {"col_name":"vat_no", "required":false} ], "displaynames":[ {"col_name":"comp_name", "separator":""} ] } ]} You can mix and match the two styles to get the readability level you need. I think the "col_name" and "required" tags are probably better omitted, which would make the JSON block look like this: {"use_subtypes":true, "use_displaynames":true, "choice":[ {"code":"admin", "descr":"System administrator", "subtype_columns":[], "displaynames":[]}, {"code":"ind", "descr":"Individual", "subtype_columns":[ ["first_name", "required"], ["surname", "required"] ], "displaynames":[ ["first_name", " "] ["surname", ""] ] }, {"code":"comp", "descr":"Company", "subtype_columns":[ ["comp_name", "required"] ["reg_no", "required"] ["vat_no", "optional"] ], "displaynames":[ ["comp_name", ""] ] } ]} Note that instead of "true" or "false", I've simply used "required" or "optional". Easy readability without excessive verbosity. And you could probably make "required" the default, so you just have [["comp_name"], ["reg_no"], ["vat_no", "optional"]] for the last block. Now, here's the real killer. You can take this JSON block and turn it into Python code like this: choices = ... block of JSON ... And now it's real code. It's that simple. You can't do that with XML. And once it's code, you can add functionality to it to improve readability even more. > Also, intuitively one would think it would take much longer to process the > XML version compared with the JSON version. I have not done any benchmarks, > but I use lxml, and I am astonished at the speed. Admittedly a typical > form-processor spends most of its time waiting for user input. Even so, for > my purposes, I have never felt the slightest slowdown caused by XML. On this, I absolutely agree. You will almost never see a performance difference between any of the above. Don't pick based on performance - pick based on what makes sense and is readable. The pure-code version might suffer terribly (interpreted Python with several levels of helper functions, each one having its overhead - though personally, I expect it'd be comparable to the others), but you would still do better with it, because the difference will be on the scale of microseconds. I've built GUIs in a number of frameworks, including building frameworks myself. I've built a system for creating CRUD databases. (It's still in use, incidentally, though only on our legacy OS/2 systems. One of the costs of writing in REXX rather than Python, but I didn't know Python back in the early 1990s when I wrote Hudson.) Frameworks that boast that it doesn't take code to use them tend to suffer from the Inner-Platform Effect [1] [2] if they get sufficiently powerful, and it quickly becomes necessary to drop to code somewhere. (Or, if they DON'T get powerful enough to hit the IPE, they overly restrain what you can do with them. That's fine if all you want is simple, but what if 99.9% of what you want fits into the framework and 0.1% simply can't be done?) With Hudson, I handled the "easy bits" with a single program (basic table view display with some options, database/table selection, etc, etc), and then dropped to actual GUI code to handle the custom parts (the main form for displaying one record; optionally the Search dialog, though a basic one was provided "for free"), with a library of handy functions available to call on. Okay, I did a terrible job of the "library" part back in those days - some of them were copied and pasted into each file :| - but the concept is there. In Gypsum (a current project, MUD client for Linux/Windows/Mac OS), all GUI work is done through GTK. But there are a few parts that get really clunky, like populating a Table layout, so I made a helper function that creates a table based on a list of lists: effectively, a 2D array of cell values, where a cell could have a string (becomes a label), a widget (gets placed there), or nothing (the label/widget to the left spans this cell too). That doesn't cover _every_ possible use-case (there's no way to span multiple rows), but if I need something it can't do, I'm writing code already right there, so I can just use the Table methods directly. There was actually one extremely common sub-case where even my GTK2Table function got clunky, so I made a second level of wrapper that takes a simple list of elements and creates a 2D array of elements, with labels right-justified. Once again, if I'm doing the same thing three times, it's a prime candidate for a helper. The cool thing about doing everything in code is that you can create helpers at the scope where they're most needed. To build the character sheet module for Gypsum (one of its uses is Dungeons and Dragons), I had to build up a more complex and repetitive GUI than most, so I ended up making a handful of helpers that existed right there in the charsheet module. (A couple of them have since been promoted to global; GTK2Table mentioned above started out in charsheet.) Anyone reading code anywhere _else_ in the project doesn't need to understand those functions; but they improve readability in that module enormously. That's something that's fundamentally impossible in an interpreted/structured system like an XML GUI - at least, impossible without some horrible form of inner-platform effect. Python code is more readable than most data structures you could come up with, because you don't have to predict everything in advance. ChrisA [1] http://en.wikipedia.org/wiki/Inner-platform_effect [2] http://thedailywtf.com/Articles/The_Inner-Platform_Effect.aspx From roegltd at gmail.com Fri Jan 24 07:04:09 2014 From: roegltd at gmail.com (Asaf Las) Date: Fri, 24 Jan 2014 04:04:09 -0800 (PST) Subject: Python declarative In-Reply-To: References: Message-ID: <9275822c-8371-4479-bab3-3c18cd5cb098@googlegroups.com> On Wednesday, January 15, 2014 7:02:08 PM UTC+2, Sergio Tortosa Benedito wrote: > Hi I'm developing a sort of language extension for writing GUI programs > called guilang, right now it's written in Lua but I'm considreing Python > instead (because it's more tailored to alone applications). My question > it's if I can achieve this declarative-thing in python. Here's an > example: > Window "myWindow" { > title="Hello world"; > Button "myButton" { > label="I'm a button"; > onClick=exit > } > } > print(myWindow.myButton.label) > Of course it doesn't need to be 100% equal. Thanks in advance > Sergio you can also encode widget event handler function names into same text file and module names where functions are written so they will be called by string name. The only thing will be left - creation of those module(s).py and writing functions there and of course the subject of your project interpreter/mapper/creator of encoded text to graphical primitives. For convenience text encoding can retain properties of widget library you will choose. or you can/should also create derived widgets with some predefined look and feel and properties to make encoding simpler and typing faster. From frank at chagford.com Fri Jan 24 07:49:16 2014 From: frank at chagford.com (Frank Millman) Date: Fri, 24 Jan 2014 14:49:16 +0200 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmo+EuY439wB0C8or+ZAcYeNR844HAKwL3i2+55dDE8LNA at mail.gmail.com... > On Fri, Jan 24, 2014 at 8:21 PM, Frank Millman wrote: >> I find that I am using JSON and XML more and more in my project, so I >> thought I would explain what I am doing to see if others think this is an >> acceptable approach or if I have taken a wrong turn. > > Please don't take this the wrong way, but the uses of JSON and XML > that you describe are still completely inappropriate. Python does not > need this sort of thing. > Chris, I really am very grateful for your detailed response. There is much food for thought there and I will have to read it a few times to glean as much as possible from it. Here are some initial thoughts. 1. I don't really understand how your system actually works! You mention Python code and helper functions, but I cannot picture the overall structure of the program. I don't know if it is possible to provide a siimple example, but it would certainly help. 2. I am not sure if you have created this to make it easy for *you* to create forms, or for others. And if the latter, must they be programmers? One of my goals is to allow non-programmers to modify forms and even create them from scratch. I did mention that one benefit of my approach is that I can design a gui that allows this, but I don't get the sense that your's does. 3. Thanks for the links to the Inner Platform Effect. I had not heard of it, but I recognise the symptoms, and I realise that I am skirting close to it in some areas. 4. You are right that some things cannot be totally abstracted, and can only be handled by code. My approach is as follows. If at least 80% of the structure can be handled without resorting to code, I think it is worthwhile, and I think I have more than achieved that. Of the balance, if at least 80% of requirements are 'standard', I can write the standard functions in Python, and create an XML tag that will cause the function to be invoked at run-time. The 'designer' still does not have to worry about Python. For the remainder, I have created an XML tag called 'pyfunc' that provides a path to a custom-written function. For this, a Python programmer will be required. So far I have only made use of this in my 'form designer', which is quite complex as it has to take the XML definition and 'explode' it into a number of in-memory tables so that it can be presented in gui form. However, the average user is not going to get their hands that dirty. Thanks again Frank From frank at chagford.com Fri Jan 24 08:06:00 2014 From: frank at chagford.com (Frank Millman) Date: Fri, 24 Jan 2014 15:06:00 +0200 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <39e1dd33-2162-40ea-8676-d27c8360aff3@googlegroups.com> Message-ID: "Rustom Mody" wrote in message news:39e1dd33-2162-40ea-8676-d27c8360aff3 at googlegroups.com... > On Friday, January 24, 2014 2:51:12 PM UTC+5:30, Frank Millman wrote: > Comments welcome. > > Of json/XML/yml I prefer yml because it has the terseness of json and the > structuredness of xml -- well almost > > The flipside is that pyyaml needs to be installed unlike json. > But then you are installing lxml anyway Thanks for that, Rustom. I had a quick look and I like it. Probably too big a change for me to consider at the moment, but at least I am now aware of it. Frank From vincent at vincentdavis.net Fri Jan 24 08:20:49 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 24 Jan 2014 07:20:49 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 2:29 AM, Gregory Ewing wrote: > If all you want is a mapping between a sequence of > length n and compact representation of it, there's > a much simpler way: just convert it to a base-k > integer, where k is the size of the alphabet. > > The resulting integer won't be any larger than an > index into the de Bruijn sequence would be, and > you can easily recover the original sequence from > its encoding without needing any kind of lookup > table. > ?True, ?the "all you want is a mapping" is not quite true. I actually plan to plot frequency (the number of times an observed sub sequence overlaps a value in the De Bruijn sequence) The way the sub sequences overlap is important to me and I don't see a way go from base-k (or any other base) to the index location in the De Bruijn sequence. i.e. a decoding algorithm. Vincent Davis 720-301-3003 -------------- next part -------------- An HTML attachment was scrubbed... URL: From vincent at vincentdavis.net Fri Jan 24 08:08:10 2014 From: vincent at vincentdavis.net (Vincent Davis) Date: Fri, 24 Jan 2014 07:08:10 -0600 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: On Fri, Jan 24, 2014 at 2:23 AM, Peter Otten <__peter__ at web.de> wrote: > Then, how do you think Python /knows/ that it has to repeat the code 10 > times on my "slow" and 100 times on your "fast" machine? It runs the bench > once, then 10, then 100, then 1000 times -- until there's a run that takes > 0.2 secs or more. The total expected minimum time without startup overhead > is then > ?Ah, I did not know about the calibration. That and I did not notice the 100 on my machine vs 10 on yours.? Vincent Davis -------------- next part -------------- An HTML attachment was scrubbed... URL: From burak.arslan at arskom.com.tr Fri Jan 24 08:40:07 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Fri, 24 Jan 2014 15:40:07 +0200 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: <52E26D37.8060508@arskom.com.tr> On 01/24/14 11:21, Frank Millman wrote: > I store database metadata in the database itself. I have a table that > defines each table in the database, and I have a table that defines each > column. Column definitions include information such as data type, allow > null, allow amend, maximum length, etc. Some columns require that the value > is constrained to a subset of allowable values (e.g. 'title' must be one of > 'Mr', 'Mrs', etc.). I know that this can be handled by a 'check' constraint, > but I have added some additional features which can't be handled by that. So > I have a column in my column-definition table called 'choices', which > contains a JSON'd list of allowable choices. It is actually more complex > than that, but this will suffice for a simple example. I wonder whether your use cases can be fully handled by Xml Schema standard. It's quite robust and easy to use. You are already doing validation at the app level so I don't think it'd be much of a problem for you to adopt it. e.g. >>> from spyne.model import * >>> class C(ComplexModel): ... title = Unicode(values=['Mr', 'Mrs', 'Ms']) ... >>> from lxml import etree >>> from spyne.util.xml import get_validation_schema >>> schema = get_validation_schema([C], 'some_ns') >>> doc1 = etree.fromstring('Mr') >>> print schema.validate(doc1) True >>> doc2 = etree.fromstring('xyz') >>> print schema.validate(doc2) False >>> print schema.error_log :1:0:ERROR:SCHEMASV:SCHEMAV_CVC_ENUMERATION_VALID: Element '{some_ns}title': [facet 'enumeration'] The value 'xyz' is not an element of the set {'Mr', 'Mrs', 'Ms'}. :1:0:ERROR:SCHEMASV:SCHEMAV_CVC_DATATYPE_VALID_1_2_1: Element '{some_ns}title': 'xyz' is not a valid value of the atomic type '{some_ns}C_titleType'. >>> Also, if you need conversion between various serialization formats and Python object hierarchies, I put together an example for you: https://gist.github.com/plq/8596519 I hope these help. Best, Burak From rosuav at gmail.com Fri Jan 24 08:55:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 00:55:27 +1100 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: On Fri, Jan 24, 2014 at 11:49 PM, Frank Millman wrote: > > "Chris Angelico" wrote in message > news:CAPTjJmo+EuY439wB0C8or+ZAcYeNR844HAKwL3i2+55dDE8LNA at mail.gmail.com... >> On Fri, Jan 24, 2014 at 8:21 PM, Frank Millman wrote: >>> I find that I am using JSON and XML more and more in my project, so I >>> thought I would explain what I am doing to see if others think this is an >>> acceptable approach or if I have taken a wrong turn. >> >> Please don't take this the wrong way, but the uses of JSON and XML >> that you describe are still completely inappropriate. Python does not >> need this sort of thing. >> > > Chris, I really am very grateful for your detailed response. There is much > food for thought there and I will have to read it a few times to glean as > much as possible from it. Thanks for taking it the right way :) If I thought you were doing a terrible job, I'd just archive the thread and move on. The detailed response means I think you're very close to the mark, but could improve. :) > Here are some initial thoughts. > > 1. I don't really understand how your system actually works! You mention > Python code and helper functions, but I cannot picture the overall structure > of the program. I don't know if it is possible to provide a siimple example, > but it would certainly help. Yeah, it was a bit vague. Unfortunately I haven't actually built any complex UI in Python, ever, so I'll have to use C, C++, REXX, or Pike, for the example. In C, it would be using the OS/2 APIs, not very useful to anyone else. In C++, either Borland's ancient "Object Windows Library", or the Win32 APIs - either way, not particularly helpful. REXX you probably don't even know as a language, and you're unlikely to know any of the GUI libraries I've used - GpfRexx, VREXX, VX-REXX, VisPro REXX, DrRexx, or a handful of others. So the best bet is Pike, where I've used GTK, which is also available for Python - but there are distinct differences. (Oh, I've also used DBExpert, which is a superb example of how frustrating it can be to try to create a complex GUI in a "look how easy, it's just drag and drop, no code needed" system. But that's more arcane stuff from the 1990s that you most likely don't know, and definitely don't need to know.) So, here's some code from Gypsum. Firstly, here's a simple window layout (not strictly what I had in Gypsum): mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0) ->add(GTK2.Label("About Gypsum: big long multi-line string")) ->add(GTK2.HbuttonBox() ->add(GTK2.Button("Close")) ->add(GTK2.Button("Foobar")) ) ); The window has a simple structure. It contains a vertical box, which contains a label and a horizontal button box; the latter contains two buttons. (The real about dialog has only one button, making it a poor example. I've no idea what clicking Foobar on an about dialog should do.) There's a nested structure to it, and it's all code. (It's actually all one single expression. The add() methods return the parent object, so they chain nicely.) This gives maximum flexibility, but it gets repetitive at times, especially when I do up the character sheet. Here's a screenshot of just the first page: http://rosuav.com/charsheet.png (That's how it appears on Windows, since I'm currently testing it for support there. It also has to work - and look right - on Linux and Mac OS.) It's particularly complicated when laying out a table, because the table is so powerful and flexible. GTK2.Table(6,2,0) ->attach(GTK2.Label((["label":"Keyword","xalign":1.0])),0,1,0,1,GTK2.Fill,GTK2.Fill,5,0) ->attach_defaults(win->kwd=GTK2.Entry(),1,2,0,1) ->attach(GTK2.Label((["label":"Name","xalign":1.0])),0,1,1,2,GTK2.Fill,GTK2.Fill,5,0) ->attach_defaults(win->name=GTK2.Entry(),1,2,1,2) ->attach(GTK2.Label((["label":"Host name","xalign":1.0])),0,1,2,3,GTK2.Fill,GTK2.Fill,5,0) ->attach_defaults(win->hostname=GTK2.Entry(),1,2,2,3) ->attach(GTK2.Label((["label":"Port","xalign":1.0])),0,1,3,4,GTK2.Fill,GTK2.Fill,5,0) ->attach_defaults(win->port=GTK2.Entry(),1,2,3,4) ->attach(GTK2.Label((["label":"Auto-log","xalign":1.0])),0,1,4,5,GTK2.Fill,GTK2.Fill,5,0) ->attach_defaults(win->logfile=GTK2.Entry(),1,2,4,5) ->attach(win->use_ka=GTK2.CheckButton("Use keep-alive"),1,2,5,6,GTK2.Fill,GTK2.Fill,5,0) //No separate label Horribly repetitive, and requires care to ensure that the left/right/top/bottom boundaries are correct in all cases. Technically it's possible for widgets to span rows or columns, and even to overlap, but that's extremely rare compared to the common case of just "lay these things out in a grid". (Though spanning columns was easy enough to implement, so I did it.) Here's the version with the first helper function: GTK2Table(({ ({"Keyword",win->kwd=GTK2.Entry()}), ({"Name",win->name=GTK2.Entry()}), ({"Host name",win->hostname=GTK2.Entry()}), ({"Port",win->port=GTK2.Entry()}), ({"Auto-log",win->logfile=GTK2.Entry()}), ({"",win->use_ka=GTK2.CheckButton("Use keep-alive")}), }),(["xalign":1.0])) I have to create a blank label in there to keep the positioning right (the previous version simply didn't attach anything in that slot), but that's a small price to pay. The readability has gone up hugely. And yet, there's still a little more that can be done, as I realized when I found myself duplicating the above structure a few times. two_column(({ "Keyword",win->kwd=GTK2.Entry(), "Name",win->name=GTK2.Entry(), "Host name",win->hostname=GTK2.Entry(), "Port",win->port=GTK2.Entry(), "Auto-log",win->logfile=GTK2.Entry(), "",win->use_ka=GTK2.CheckButton("Use keep-alive"), })) This is something that I could give to a non-programmer and expect him to be able to edit, as it's about as clear as the equivalent JSON or XML would be; there could be a few more tweaks done, perhaps, but it's pretty readable like that. A non-programmer could, for instance, put the "Auto-log" line above the "Host name", simply by reordering the lines of code; it would do exactly what he expects. There's as much fragility/rigidity in this as there is in any other structured system (eg if you leave out a comma, this won't work - same with JSON or XML). In the specific case of the character sheet, I frequently create entry fields (GTK2.Entry()) that are bound to specific data attributes. So in any context where it's legal to write GTK2.Entry(), you can instead write ef("some_name") and it'll make a properly bound entry field. And if it's a numeric field, num("some_name") will shrink the default size and center the text in it as well, which is what people expect of the numeric fields. Shorthand for the common cases. And then there are complex cases like the weapon stats block - it needs its keyword, name, damage roll, enchantment bonus, etc, etc, all laid out nicely; and there might be three of those weapon blocks. So that's broken out into a function. The thing is, if your XML window structure has enough power... well, that's more part of the next two points: > 2. I am not sure if you have created this to make it easy for *you* to > create forms, or for others. And if the latter, must they be programmers? > One of my goals is to allow non-programmers to modify forms and even create > them from scratch. I did mention that one benefit of my approach is that I > can design a gui that allows this, but I don't get the sense that your's > does. > > 3. Thanks for the links to the Inner Platform Effect. I had not heard of it, > but I recognise the symptoms, and I realise that I am skirting close to it > in some areas. If your XML window structure has enough power, it'll be nearly impossible for a non-programmer to make anything but the most trivial changes to it. (Changing a literal string is usually easy enough. Any decent system will make _that_ possible, at least.) If a non-programmer can truly create a form from scratch, that's a sign that the forms are extremely simple and, if you'll excuse the pun, formulaic; and if that's the case, it should be possible to make a really easy-to-use helper function like my two_column() above. Challenge: Without knowing anything about Pike, or the connect dialog, add another check box called "Passive mode" called win->passive and positioned just after the hostname and port. Like the other check box, it doesn't need a separate label. Can you do it? Could someone who knows enough to edit XML do it? I suspect probably they could. There's some boilerplate to copy and paste (same in XML or code), there's some readable text strings (names, labels, types), and there's punctuation that makes decent sense. > 4. You are right that some things cannot be totally abstracted, and can only > be handled by code. My approach is as follows. If at least 80% of the > structure can be handled without resorting to code, I think it is > worthwhile, and I think I have more than achieved that. Of the balance, if > at least 80% of requirements are 'standard', I can write the standard > functions in Python, and create an XML tag that will cause the function to > be invoked at run-time. The 'designer' still does not have to worry about > Python. That's nice in theory, but it means you have to plan everything out. That also means you have to predict your names etc, and then deprecate old names if you ever find that you made a mistake. When you start with code, you have the flexibility of looking at actual existing forms and deciding what should be broken out for simplicity. > For the remainder, I have created an XML tag called 'pyfunc' that > provides a path to a custom-written function. For this, a Python programmer > will be required. So far I have only made use of this in my 'form designer', > which is quite complex as it has to take the XML definition and 'explode' it > into a number of in-memory tables so that it can be presented in gui form. > However, the average user is not going to get their hands that dirty. That's what I meant when I said a "drop to code" system. Depending on how smooth the boundary is, that could be either horribly clunky or reasonably clean; the clean one usually requires a lot of work. On the flip side, if your GUI creation is *all* code, there's no boundary at all, and no work. My system starts by writing an absolute minimum of code and forcing the form designer to do more work, and then progressively adds code *that is actually useful* and makes the form design work easier. Trying to do it all in XML means you have to first predict what will be needed, and that inevitably means writing a whole lot of code that isn't, as it turns out, useful. That's an up-front cost before you can do anything, plus you can't get rid of any of it later without first making sure no forms are using those tags. Ultimately, a full-featured GUI is going to require that its form designer understand the underlying system anyway (in my case that's GTK), because nothing will change that; and if your forms designers have to understand how GTK works, they probably have to understand how to write GTK-using code. At very least, the basics of code (names, structure, etc) will be critical, and that's true of any GUI builder. DBExpert required that you think about all that sort of thing, and that's as close as I've ever seen to a pure "no code needed, build a UI to view a database table" system. So... instead of fighting that, embrace it! Let it truly be code. The structure (your XML interpreter) is code that has a maintenance cost. The less of that you have, the less it takes to make changes. And as a rule of thumb, less code means less bugs; and less development prior to usage means less bugs, too. Let real-world usage guide your code, and you'll spend less time building stuff you don't need. ChrisA From neilc at norwich.edu Fri Jan 24 09:12:25 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Fri, 24 Jan 2014 14:12:25 +0000 (UTC) Subject: Elementree and insert new element if it is not present - FIXED References: Message-ID: On 2014-01-24, Tharanga Abeyseela wrote: > manged to fix it. need to add the namespace when checking the > condition. I wish there was a rule that if your xml doesn't need a namespace it doesn't use one. They are a pain when there's just one useless namespace. But maybe I'm just naive. -- Neil Cerutti From piet at vanoostrum.org Fri Jan 24 09:13:54 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Fri, 24 Jan 2014 15:13:54 +0100 Subject: Can post a code but afraid of plagiarism References: <3cdf480e-e527-4c76-b87a-b6a34c9195fb@googlegroups.com> Message-ID: indar kumar writes: > On Saturday, January 18, 2014 3:21:42 PM UTC-7, indar kumar wrote: >> Hi, >> >> >> >> I want to show a code for review but afraid of plagiarism issues. >> Kindly, suggest how can I post it for review here without masking it >> visible for public > > Can I do the following to just get the value as string not the type list? > > searchfor = '192.168.0.2' > z=[ii[0] for ii in hosts.values() if ii[1] == searchfor] >>>> str1 = ''.join(z) >>>> str1 If you want to extract an element of a list use indexing, like mylist[0]. If you don't know these things or can't find this out yourself, you have a serious lack of knowledge about Python, or maybe about programming, and it is time to learn that first. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From breamoreboy at yahoo.co.uk Fri Jan 24 10:04:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 24 Jan 2014 15:04:50 +0000 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On 24/01/2014 09:33, wxjmfauth at gmail.com wrote: [double spacing snipped for the 10**infinity time] > Le vendredi 24 janvier 2014 01:42:41 UTC+1, Terry Reedy a ?crit : >> This will never happen. Python 3 is the escape from several dead-ends in >> Python 2. The biggest in impact is the use of un-accented latin chars as >> text in a global, unicode world. > > Three days of discussion on how to make the next release > more "ascii" compatible. > > I put "ascii" in quotes, because the efforts to define > "ascii" were more laughable. > > jmf > Oh dear of dear, looks as if another bad batch has been sold, please change your dealer immediately. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From invalid at invalid.invalid Fri Jan 24 10:36:55 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Fri, 24 Jan 2014 15:36:55 +0000 (UTC) Subject: The potential for a Python 2.8. References: Message-ID: On 2014-01-24, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> >> Python 2.8j? >> > >> > You're imagining things. >> >> Get real... s'not gonna happen. >> > I wouldn't bet on that. The situation keeps getting tensor and > tensor. I have a feeling there's a pun there based on the worlds "real" and "tensor", but I don't have the math skills required to figure it out. -- Grant Edwards grant.b.edwards Yow! If I pull this SWITCH at I'll be RITA HAYWORTH!! gmail.com Or a SCIENTOLOGIST! From rosuav at gmail.com Fri Jan 24 10:57:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 02:57:35 +1100 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On Sat, Jan 25, 2014 at 2:36 AM, Grant Edwards wrote: > On 2014-01-24, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >>> >> Python 2.8j? >>> > >>> > You're imagining things. >>> >>> Get real... s'not gonna happen. >>> >> I wouldn't bet on that. The situation keeps getting tensor and >> tensor. > > I have a feeling there's a pun there based on the worlds "real" and > "tensor", but I don't have the math skills required to figure it out. MRAB suggested "2.8j", which looks like another system of version number (where you go 2.8, then 2.8a, 2.8b, etc etc), but is a pun on the notation for imaginary/complex numbers. Hence Roy said "imagining" things. I tried to call him back to "real" numbers (ones that don't involve the letter j), and Roy remarked in a way that mentioned tensors [1], which can represent complex numbers, but I've never dug into all that myself, so I'll let him explain in more detail. I then said (though you didn't quote me) that this was a "rational" discussion until I suggested a version number involving e, which is an irrational number (2.71828...), as is sqrt(8) which I also mentioned at the same time (2.8284...). I just violated [2]. Sorry. ChrisA [1] http://en.wikipedia.org/wiki/Tensor [2] http://tvtropes.org/pmwiki/pmwiki.php/Main/DontExplainTheJoke From skip at pobox.com Fri Jan 24 11:03:15 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 24 Jan 2014 10:03:15 -0600 Subject: datetime as subclass of date In-Reply-To: <85lhy5g999.fsf@benfinney.id.au> References: <85lhy5g999.fsf@benfinney.id.au> Message-ID: One thing that always reinforced my notion that issubclass(datetime.datetime, datetime.date) should be False is that the presence of of date and time methods gives me a mental image of delegation, not inheritance. That is, it "feels" like a datetime object is the aggregation of a date object and a time object, not a specialized date object with some added time machinery mixed in. Skip From mcepl at redhat.com Fri Jan 24 11:28:41 2014 From: mcepl at redhat.com (=?UTF-8?Q?Mat=C4=9Bj?= Cepl) Date: Fri, 24 Jan 2014 17:28:41 +0100 Subject: Python declarative In-Reply-To: =?UTF-8?Q?=3CCAPTjJmo=2BEuY439wB0C8or=2BZAcYeNR844HAKwL3i2?= =?UTF-8?Q?=2B55dDE8LNA=40mail=2Egmail=2Ecom=3E?= References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: <20140124162842.0E73240FC2@wycliff.ceplovi.cz> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2014-01-24, 11:18 GMT, you wrote: > Write your rendering engine as a few simple helper functions, > and then put all the rest in as code instead of XML. The > easiest way to go about it is to write three forms, from > scratch, and then look at the common parts and figure out > which bits can go into helper functions. Perhaps what's missing is full acknowledgment that Python has dual-inheritance and thus it can have mixin classes (which seems to me to be the only useful use of dual inheritance). You know you can have mixins in Python, right? Also, I wrote my share of XML parsing/writing code, but more and more I am persuaded that if the answer is ?XML? then there is some wrong with the question. Python is a way more expressive language than XML, so it is almost always more useful to write in Python, than to pass any problems to XML. Mat?j -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS4pS54J/vJdlkhKwRApdcAJ48PRgDz6ccnq1YFD9zx8EDDH3JjgCghU2x 3CV+D0LvquzgYRux2GslZ0E= =Y3/F -----END PGP SIGNATURE----- From rosuav at gmail.com Fri Jan 24 11:33:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 03:33:27 +1100 Subject: Python declarative In-Reply-To: <20140124162842.0E73240FC2@wycliff.ceplovi.cz> References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <20140124162842.0E73240FC2@wycliff.ceplovi.cz> Message-ID: On Sat, Jan 25, 2014 at 3:28 AM, Mat?j Cepl wrote: > On 2014-01-24, 11:18 GMT, you wrote: >> Write your rendering engine as a few simple helper functions, >> and then put all the rest in as code instead of XML. The >> easiest way to go about it is to write three forms, from >> scratch, and then look at the common parts and figure out >> which bits can go into helper functions. > > Perhaps what's missing is full acknowledgment that Python has > dual-inheritance and thus it can have mixin classes (which seems > to me to be the only useful use of dual inheritance). You know > you can have mixins in Python, right? Hmm, I've never really felt the need to work that way. Usually it's functions I want, not classes; but if they're classes, then generally they're just to add a couple of methods, or change the construction args, so single inheritance is plenty. (I created a MultiLineEntryField class as a thin wrapper around TextView, adding get_text() and set_text() with the same signatures as GTK2.Entry()'s methods of the same names. That wouldn't apply to anything else, so a mixin wouldn't help much.) But sure. If you want mixins, go for it. ChrisA From roegltd at gmail.com Fri Jan 24 11:31:21 2014 From: roegltd at gmail.com (Asaf Las) Date: Fri, 24 Jan 2014 08:31:21 -0800 (PST) Subject: Class and instance related questions. Message-ID: Hi Is there way to get list of instances of particular class through class itself? via metaclass or any other method? Another question - if class is object is it possible to delete it? If it is possible then how instances of that class will behave? Thanks Asaf From rosuav at gmail.com Fri Jan 24 11:37:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 03:37:29 +1100 Subject: Class and instance related questions. In-Reply-To: References: Message-ID: On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: > Hi > > Is there way to get list of instances of particular > class through class itself? via metaclass or any other method? Not automatically, but you can make a class that keeps track of its instances with a weak reference system. > Another question - if class is object is it possible > to delete it? If it is possible then how instances > of that class will behave? It's possible to unbind the name, but every instance retains a reference to its class, so the class itself won't disappear until there are no instances left of it. ChrisA From tjreedy at udel.edu Fri Jan 24 12:17:33 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Jan 2014 12:17:33 -0500 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On 1/24/2014 10:57 AM, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 2:36 AM, Grant Edwards wrote: >> On 2014-01-24, Roy Smith wrote: >>> In article , >>> Chris Angelico wrote: >>> >>>> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >>>>>> Python 2.8j? >>>>> >>>>> You're imagining things. >>>> >>>> Get real... s'not gonna happen. >>>> >>> I wouldn't bet on that. The situation keeps getting tensor and >>> tensor. >> >> I have a feeling there's a pun there based on the worlds "real" and >> "tensor", but I don't have the math skills required to figure it out. > > MRAB suggested "2.8j", which looks like another system of version > number (where you go 2.8, then 2.8a, 2.8b, etc etc), but is a pun on > the notation for imaginary/complex numbers. Hence Roy said "imagining" > things. I tried to call him back to "real" numbers (ones that don't > involve the letter j), and Roy remarked in a way that mentioned > tensors [1], which can represent complex numbers, but I've never dug > into all that myself, so I'll let him explain in more detail. I then > said (though you didn't quote me) that this was a "rational" > discussion until I suggested a version number involving e, which is > an irrational number (2.71828...), as is sqrt(8) which I also > mentioned at the same time (2.8284...). > > I just violated [2]. Sorry. > > ChrisA > > [1] http://en.wikipedia.org/wiki/Tensor > [2] http://tvtropes.org/pmwiki/pmwiki.php/Main/DontExplainTheJoke In this case, the explanation is as funny as the joke. -- Terry Jan Reedy From rosuav at gmail.com Fri Jan 24 12:30:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 04:30:41 +1100 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: On Sat, Jan 25, 2014 at 4:17 AM, Terry Reedy wrote: > In this case, the explanation is as funny as the joke. I have to agree. But hey, it passes the time... ChrisA From sertorbe at gmail.com Fri Jan 24 13:51:42 2014 From: sertorbe at gmail.com (sertorbe at gmail.com) Date: Fri, 24 Jan 2014 10:51:42 -0800 (PST) Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <20140124162842.0E73240FC2@wycliff.ceplovi.cz> Message-ID: <04a40097-a1ad-4a85-afb2-6f44ff155281@googlegroups.com> Hi again , I'm sorry I dind't reply earlier I still hav enot added myself to the list (I'm doing this trhough google groups). Thanks Asaf, but I don't like having the code and the GUI separated. First,I'm not aiming to not programmers (or people qho don't want to be one) because they may be able to write the layout but not the actual program's function so there's no reason to do that. Second, I wouldn't like to have code and GUI separated since it's a hassle when try to change something like the name. XML and JSON are pretty cool but they serve for loading info which can vary to a fixed engine not for when that info does not change, and that's even more true when you are speaking about an interpreted language. I've been reasearching a bit myself and this is what I got: a way of having a nice syntax in python itself (no external files, no new language...) with metaclasses, so the same example which was used in Lua (and I think in original's python syntax) would look like this with metaclasses and classes: class myWindow(Window): title="Hello World" class myButton(Button): label="Hello World" It's just like what I was looking for, with the added benefit that functions can be defined right there. It has it's own problems (like having to access variables from the global scope), but I think they are either solvable or minor. Sergio From roegltd at gmail.com Fri Jan 24 15:32:05 2014 From: roegltd at gmail.com (Asaf Las) Date: Fri, 24 Jan 2014 12:32:05 -0800 (PST) Subject: Class and instance related questions. In-Reply-To: References: Message-ID: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> Hi Chris Thanks for answers On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: > > Hi > > Is there way to get list of instances of particular > > class through class itself? via metaclass or any other method? > Not automatically, but you can make a class that keeps track of its > instances with a weak reference system. By "not automatically" do you mean there is no way to get references to instances of class via python's provided methods or attributes for class object at time the class object is created? And usage of weak reference was suggested only to allow class instances garbage collected if for example class static container attribute will be used as class instance reference storage? > > Another question - if class is object is it possible > > to delete it? If it is possible then how instances > > of that class will behave? > > It's possible to unbind the name, but every instance retains a > reference to its class, so the class itself won't disappear until > there are no instances left of it. > > ChrisA That is interesting. Is it also reference count mechanism or something else? Thanks Asaf From rosuav at gmail.com Fri Jan 24 15:45:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 07:45:30 +1100 Subject: Class and instance related questions. In-Reply-To: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> References: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> Message-ID: On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: > On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: >> On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: >> > Hi >> > Is there way to get list of instances of particular >> > class through class itself? via metaclass or any other method? >> Not automatically, but you can make a class that keeps track of its >> instances with a weak reference system. > > By "not automatically" do you mean there is no way to get references to instances of class via python's provided methods or attributes for class > object at time the class object is created? Correct. > And usage of weak reference was suggested only to allow class instances > garbage collected if for example class static container attribute will be > used as class instance reference storage? Weak references mean that the objects will be disposed of as normal, but that you'll know that they've gone. >> > Another question - if class is object is it possible >> > to delete it? If it is possible then how instances >> > of that class will behave? >> >> It's possible to unbind the name, but every instance retains a >> reference to its class, so the class itself won't disappear until >> there are no instances left of it. >> >> ChrisA > > That is interesting. Is it also reference count mechanism or something else? Yes. [1] ChrisA [1] Within the bounds of the question asked, I think a simple "Yes" is more useful here than a long and detailed explanation of the many Pythons and how not all of them refcount at all. Consider this footnote my apology to the experts who would otherwise feel that I'm majorly misleading the OP. Sorry. From roegltd at gmail.com Fri Jan 24 16:03:04 2014 From: roegltd at gmail.com (Asaf Las) Date: Fri, 24 Jan 2014 13:03:04 -0800 (PST) Subject: Class and instance related questions. In-Reply-To: References: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> Message-ID: <7f93cb3d-576c-4929-a815-2a5ea4fcf732@googlegroups.com> On Friday, January 24, 2014 10:45:30 PM UTC+2, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: > > On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: > >> On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: > >> > Hi > >> > Is there way to get list of instances of particular > >> > class through class itself? via metaclass or any other method? > >> Not automatically, but you can make a class that keeps track of its > >> instances with a weak reference system. > > By "not automatically" do you mean there is no way to get references > > to instances of class via python's provided methods or attributes for class > > object at time the class object is created? > > Correct. > > > And usage of weak reference was suggested only to allow class instances > > garbage collected if for example class static container attribute will be > > used as class instance reference storage? > Weak references mean that the objects will be disposed of as normal, > but that you'll know that they've gone. > > >> > Another question - if class is object is it possible > >> > to delete it? If it is possible then how instances > >> > of that class will behave? > > >> It's possible to unbind the name, but every instance retains a > >> reference to its class, so the class itself won't disappear until > >> there are no instances left of it. > >> ChrisA > > > That is interesting. Is it also reference count mechanism or something else? > > Yes. [1] > > ChrisA > > [1] Within the bounds of the question asked, I think a simple "Yes" is > more useful here than a long and detailed explanation of the many > Pythons and how not all of them refcount at all. Consider this > footnote my apology to the experts who would otherwise feel that I'm > majorly misleading the OP. Sorry. Chris, i like answers which open doors to my curiosity :-) yet i should spend my credits very carefully :-) Thanks Asaf From giorgos.tzampanakis at gmail.com Fri Jan 24 16:03:44 2014 From: giorgos.tzampanakis at gmail.com (Giorgos Tzampanakis) Date: Fri, 24 Jan 2014 21:03:44 +0000 (UTC) Subject: Single Object Detection and Tracking Steps References: <7c985507-406a-4a79-9ddc-fdb02574ff52@googlegroups.com> Message-ID: On 2014-01-24, hottrack88 at gmail.com wrote: > I am doing single object detection and tracking in a video file using > python & opencv2. As far I know the steps are, > > Video to frame conversion > Grayscale conversion > Thresholding > After phase 3, I got sequence of binary images. > > My questions are: > > How to identify (detect) whether the object is moving or not? > How to get(track) the object moving coordinates(x,y position)? > Which method should I use for these? > I got confused with the words like SIFT feature, Kalman filter, Particle > filter, optical flow filter etc. Please help me by giving next upcoming > steps details. > > Thanks in advance. I assume this is homework, so better ask other students. -- Improve at backgammon rapidly through addictive quickfire position quizzes: http://www.bgtrain.com/ From rosuav at gmail.com Fri Jan 24 16:18:08 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 08:18:08 +1100 Subject: Class and instance related questions. In-Reply-To: <7f93cb3d-576c-4929-a815-2a5ea4fcf732@googlegroups.com> References: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> <7f93cb3d-576c-4929-a815-2a5ea4fcf732@googlegroups.com> Message-ID: On Sat, Jan 25, 2014 at 8:03 AM, Asaf Las wrote: > Chris, i like answers which open doors to my curiosity :-) > yet i should spend my credits very carefully :-) Trust me, there is no limit to what you can learn when you have that kind of curiosity! Ask more questions and you'll get more details. Around here, we have all sorts of experts (several core Python developers hang out here, at least one of whom posts fairly frequently), and a good number of us have a decade or two of experience in programming, having used a large number of languages, and we've all settled on Python as being in some way important to us. It's always interesting to get a discussion going with people whose non-Python expertise differs - a couple of us (self included) here are very familiar with REXX, some know Ruby (self NOT included), or lisp, or go, or anything else under the sun. And then there are those of us who'll quote Alice in Wonderland, or the Thomas the Tank Engine books, or abstract philosophy, or Gilbert and Sullivan, or Discworld (I think I've seen that one quoted? I'm not personally familiar, so I can't say for sure), or Firefly, or Real Genius, or ... or ...., you get the idea :) So you get to learn about all sorts of other nerdy interests for free! ChrisA From roegltd at gmail.com Fri Jan 24 17:08:52 2014 From: roegltd at gmail.com (Asaf Las) Date: Fri, 24 Jan 2014 14:08:52 -0800 (PST) Subject: Class and instance related questions. In-Reply-To: References: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> <7f93cb3d-576c-4929-a815-2a5ea4fcf732@googlegroups.com> Message-ID: On Friday, January 24, 2014 11:18:08 PM UTC+2, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 8:03 AM, Asaf Las wrote: > > Chris, i like answers which open doors to my curiosity :-) > > yet i should spend my credits very carefully :-) > Trust me, there is no limit to what you can learn when you have that > kind of curiosity! Ask more questions and you'll get more details. > Around here, we have all sorts of experts (several core Python > developers hang out here, at least one of whom posts fairly > frequently), and a good number of us have a decade or two of > experience in programming, having used a large number of languages, > and we've all settled on Python as being in some way important to us. > It's always interesting to get a discussion going with people whose > non-Python expertise differs - a couple of us (self included) here are > very familiar with REXX, some know Ruby (self NOT included), or lisp, > or go, or anything else under the sun. And then there are those of us > who'll quote Alice in Wonderland, or the Thomas the Tank Engine books, > or abstract philosophy, or Gilbert and Sullivan, or Discworld (I think > I've seen that one quoted? I'm not personally familiar, so I can't say > for sure), or Firefly, or Real Genius, or ... or ...., you get the > idea :) So you get to learn about all sorts of other nerdy interests > for free! > ChrisA I appreciate your kind words! Thanks Asaf From bgailer at gmail.com Fri Jan 24 18:42:58 2014 From: bgailer at gmail.com (bob gailer) Date: Fri, 24 Jan 2014 18:42:58 -0500 Subject: Can post a code but afraid of plagiarism In-Reply-To: <14e7775c-2a79-46eb-8f25-d9ac7fc1eb01@googlegroups.com> References: <14e7775c-2a79-46eb-8f25-d9ac7fc1eb01@googlegroups.com> Message-ID: <52E2FA82.8060302@gmail.com> I had offered to provide some off-line tutoring. My reaction is exactly what you are saying - he needs to learn the basics. The code he sent me (after much asking to see some code) was buggy, and a lot of it were the various suggestions we all made. I feel for indar. He is in over his head. I recommend we stop trying to respond to all his requests. From davea at davea.name Fri Jan 24 18:58:43 2014 From: davea at davea.name (Dave Angel) Date: Fri, 24 Jan 2014 18:58:43 -0500 (EST) Subject: Class and instance related questions. References: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> <7f93cb3d-576c-4929-a815-2a5ea4fcf732@googlegroups.com> Message-ID: Asaf Las Wrote in message: > On Friday, January 24, 2014 10:45:30 PM UTC+2, Chris Angelico wrote: >> On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: >> > On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: >> >> >> It's possible to unbind the name, but every instance retains a >> >> reference to its class, so the class itself won't disappear until >> >> there are no instances left of it. >> >> ChrisA >> >> > That is interesting. Is it also reference count mechanism or something else? >> >> Yes. [1] >> >> ChrisA >> >> [1] Within the bounds of the question asked, I think a simple "Yes" is >> more useful here than a long and detailed explanation of the many >> Pythons and how not all of them refcount at all. Consider this >> footnote my apology to the experts who would otherwise feel that I'm >> majorly misleading the OP. Sorry. > > Chris, i like answers which open doors to my curiosity :-) > yet i should spend my credits very carefully :-) > Rather than dwelling on reference counting, which is just one mechanism for identifying and disposing of objects, it's usually more fruitful to consider what it means to be unreferenced. The usual term is "reachable. " If an object cannot be reached by following some chain of references, starting from a small list of kernel items, then it should be freed. The cheap way of noticing some such objects is by noticing the reference count go to zero. That's not enough, however, so you also need to periodically run a sweep type of garbage collector. See if you can guess why reference count alone is inadequate. The CPython system uses both of these, but other implementations do not. I believe that I've heard that the jython system does nothing at all, just letting the Java runtime handle it. -- DaveA From bgailer at gmail.com Fri Jan 24 18:38:19 2014 From: bgailer at gmail.com (bob gailer) Date: Fri, 24 Jan 2014 18:38:19 -0500 Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: <52E2F96B.4070606@gmail.com> On 1/24/2014 5:05 AM, theguy wrote: > I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. I so far have three different authors in the program and have already put in the example text but for some reason, the program always leans toward one specific author, Suzanne Collins, no matter what insane number I try to put in or how much I tinker with the coding. I would post the code, but I don't know if it's fine to put it here, as it contains pieces from books. I do believe that would go against copyright laws. AFAIK copyright laws apply to reproducing something for profit. I doubt that posting it here will matter. In any case do post your code; you could trim the fat out of the text if you need to, From rosuav at gmail.com Fri Jan 24 19:34:10 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 11:34:10 +1100 Subject: Need Help with Programming Science Project In-Reply-To: <52E2F96B.4070606@gmail.com> References: <52E2F96B.4070606@gmail.com> Message-ID: On Sat, Jan 25, 2014 at 10:38 AM, bob gailer wrote: > On 1/24/2014 5:05 AM, theguy wrote: >> >> I have a science project that involves designing a program which can >> examine a bit of text with the author's name given, then figure out who the >> author is if another piece of example text without the name is given. I so >> far have three different authors in the program and have already put in the >> example text but for some reason, the program always leans toward one >> specific author, Suzanne Collins, no matter what insane number I try to put >> in or how much I tinker with the coding. I would post the code, but I don't >> know if it's fine to put it here, as it contains pieces from books. I do >> believe that would go against copyright laws. > > AFAIK copyright laws apply to reproducing something for profit. I doubt that > posting it here will matter. Incorrect; posting not-for-profit can still be a violation of copyright. But as Peter said, the text itself isn't critical. Post with placeholder text, as he suggested, and we can look at the code. ChrisA From roy at panix.com Fri Jan 24 19:56:23 2014 From: roy at panix.com (Roy Smith) Date: Fri, 24 Jan 2014 19:56:23 -0500 Subject: The potential for a Python 2.8. References: Message-ID: In article , Grant Edwards wrote: > On 2014-01-24, Roy Smith wrote: > > In article , > > Chris Angelico wrote: > > > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: > >> >> Python 2.8j? > >> > > >> > You're imagining things. > >> > >> Get real... s'not gonna happen. > >> > > I wouldn't bet on that. The situation keeps getting tensor and > > tensor. > > I have a feeling there's a pun there based on the worlds "real" and > "tensor", but I don't have the math skills required to figure it out. You must be pretty weak in math, then. This really isn't that complex. [some of you who hang out on panix know where this is heading...] From ben+python at benfinney.id.au Fri Jan 24 19:59:50 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 25 Jan 2014 11:59:50 +1100 Subject: Need Help with Programming Science Project References: <52E2F96B.4070606@gmail.com> Message-ID: <85d2jgg9kp.fsf@benfinney.id.au> bob gailer writes: > On 1/24/2014 5:05 AM, theguy wrote: > > I would post the code, but I don't know if it's fine to put it here, > > as it contains pieces from books. I do believe that would go against > > copyright laws. > AFAIK copyright laws apply to reproducing something for profit. That's a common misconception that has never been true. Copyright is a legal monopoly in a work, reserving a large set of actions to the copyright holders. Without license from the copyright holders, or an exemption under the law, you cannot legally perform those actions. Paying money may sometimes help one acquire a license to perform some reserved actions (though frequently the license is severely restricted, and frequently the license you need isn't available for any price). But ?I'm not seeking a profit? nor ?I didn't get any money for it? are never grounds for copyright exemptions under any jurisdiction I've ever heard of. -- \ ?People are very open-minded about new things, as long as | `\ they're exactly like the old ones.? ?Charles F. Kettering | _o__) | Ben Finney From python.list at tim.thechases.com Fri Jan 24 20:07:33 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Fri, 24 Jan 2014 19:07:33 -0600 Subject: The potential for a Python 2.8. In-Reply-To: References: Message-ID: <20140124190733.0c14d6c1@bigbox.christie.dr> On 2014-01-24 19:56, Roy Smith wrote: > In article , > Grant Edwards wrote: > > > On 2014-01-24, Roy Smith wrote: > > > In article > > > , Chris > > > Angelico wrote: > > > > > >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith > > >> wrote: > > >> >> Python 2.8j? > > >> > > > >> > You're imagining things. > > >> > > >> Get real... s'not gonna happen. > > >> > > > I wouldn't bet on that. The situation keeps getting tensor and > > > tensor. > > > > I have a feeling there's a pun there based on the worlds "real" > > and "tensor", but I don't have the math skills required to figure > > it out. > > You must be pretty weak in math, then. This really isn't that > complex. No need to be so irrational about things! -tkc From tjreedy at udel.edu Fri Jan 24 20:08:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Jan 2014 20:08:41 -0500 Subject: Class and instance related questions. In-Reply-To: References: <2c8035fe-7514-4598-9497-c2f90f9291c2@googlegroups.com> Message-ID: On 1/24/2014 3:45 PM, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 7:32 AM, Asaf Las wrote: >> On Friday, January 24, 2014 6:37:29 PM UTC+2, Chris Angelico wrote: >>> On Sat, Jan 25, 2014 at 3:31 AM, Asaf Las wrote: >>>> Hi >>>> Is there way to get list of instances of particular >>>> class through class itself? via metaclass or any other method? >>> Not automatically, but you can make a class that keeps track of its >>> instances with a weak reference system. >> >> By "not automatically" do you mean there is no way to get references to instances of class via python's provided methods or attributes for class >> object at time the class object is created? > > Correct. This depends on exactly the meaning of your question. CPython has a gc module which has this method. gc.get_objects() Returns a list of all objects tracked by the collector, excluding the list returned. In a fresh 3.4.0 Idle shell, the list has about 15000 objects in about 150 classes. (A substantial fraction of the classes, at least, are Idle classes used in the user process.) Numbers and strings are not tracked. I believe instances of python-coded classes always are. So you can brute force search all tracked instances for instances of a class you code in Python, but this in not 'through [the] class itself'. If you plan ahead, it seems better to use a class attribute such as _instances = weakref.WeakSet() to contain them and add them in the __init__ method. -- Terry Jan Reedy From tjreedy at udel.edu Fri Jan 24 20:10:10 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 24 Jan 2014 20:10:10 -0500 Subject: Need Help with Programming Science Project In-Reply-To: References: <52E2F96B.4070606@gmail.com> Message-ID: On 1/24/2014 7:34 PM, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 10:38 AM, bob gailer wrote: >> On 1/24/2014 5:05 AM, theguy wrote: >>> >>> I have a science project that involves designing a program which can >>> examine a bit of text with the author's name given, then figure out who the >>> author is if another piece of example text without the name is given. I so >>> far have three different authors in the program and have already put in the >>> example text but for some reason, the program always leans toward one >>> specific author, Suzanne Collins, no matter what insane number I try to put >>> in or how much I tinker with the coding. I would post the code, but I don't >>> know if it's fine to put it here, as it contains pieces from books. I do >>> believe that would go against copyright laws. >> >> AFAIK copyright laws apply to reproducing something for profit. I doubt that >> posting it here will matter. > > Incorrect; posting not-for-profit can still be a violation of > copyright. But as Peter said, the text itself isn't critical. Post > with placeholder text, as he suggested, and we can look at the code. In the US, short quotations are allowed for 'fair use'. -- Terry Jan Reedy From roy at panix.com Fri Jan 24 20:38:53 2014 From: roy at panix.com (Roy Smith) Date: Fri, 24 Jan 2014 20:38:53 -0500 Subject: Need Help with Programming Science Project References: <52E2F96B.4070606@gmail.com> Message-ID: In article , Ben Finney wrote: > bob gailer writes: > > > On 1/24/2014 5:05 AM, theguy wrote: > > > I would post the code, but I don't know if it's fine to put it here, > > > as it contains pieces from books. I do believe that would go against > > > copyright laws. > > > AFAIK copyright laws apply to reproducing something for profit. > > That's a common misconception that has never been true. > > > > Copyright is a legal monopoly in a work, reserving a large set of > actions to the copyright holders. Without license from the copyright > holders, or an exemption under the law, you cannot legally perform those > actions. [The rest of this post is based on my "I am not a lawyer" understanding of the law. Also, this is based on US copyright law; things may be different elsewhere, and I haven't the foggiest idea what law applies to an international forum such as this] On the other hand (where Ben Finney's post is the first hand), there is the Fair Use Doctrine (FUD), which grants certain exemptions. The US Copyright Office has a page (http://www.copyright.gov/fls/fl102.html) about this. As a real-life example, I believe I can safely invoke the FUD to quote the leading paragraphs from today's New York Times and New York Post articles about the same event and give their Fleish-Kincaid Reading Ease and Grade Level scores, if I was comparing the writing style of the two newspapers: ---------------------------------------------- NY Times: The crime gripped the public???s imagination, for both its magnitude and its moxie: In the predawn hours of Dec. 11, 1978, a group of masked gunmen seized about $6 million in cash and jewels from a cargo building at Kennedy International Airport. Reading Ease Score: 56.6 Grade Level: 10.6 ---------------------------------------------- NY Post: On Dec. 11, 1978, armed mobsters stole $5 million in cash and nearly $1 million in jewels from a Lufthansa airlines vault at JFK Airport, in what would be for decades the biggest-ever heist on US soil. Reading Ease Score: 76.2 Grade Level: 7.3 ---------------------------------------------- The scores above were computed by http://www.readability-score.com/ In my opinion, this meets all of the requirements of the FUD. I'm quoting short passages, and using them to critique the writing styles of the two papers. In the OP's case, he's analyzing published works as input to a text analysis algorithm. In my personal opinion, posting samples of those texts, for the purpose of discussing how his algorithm works, would be well within the bounds of Fair Use. From invalid at invalid.invalid Fri Jan 24 21:24:31 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Sat, 25 Jan 2014 02:24:31 +0000 (UTC) Subject: The potential for a Python 2.8. References: Message-ID: On 2014-01-25, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> On 2014-01-24, Roy Smith wrote: >> > In article , >> > Chris Angelico wrote: >> > >> >> On Fri, Jan 24, 2014 at 1:22 PM, Roy Smith wrote: >> >> >> Python 2.8j? >> >> > >> >> > You're imagining things. >> >> >> >> Get real... s'not gonna happen. >> >> >> > I wouldn't bet on that. The situation keeps getting tensor and >> > tensor. >> >> I have a feeling there's a pun there based on the worlds "real" and >> "tensor", but I don't have the math skills required to figure it out. > > You must be pretty weak in math, then. It was more of reading problem. I completely failed to notice the "j" and the "imagining". Now I get it. > This really isn't that complex. I refuse to become a vector for the spread of these bad puns. -- Grant From kvxdelta at gmail.com Fri Jan 24 21:42:41 2014 From: kvxdelta at gmail.com (kvxdelta at gmail.com) Date: Fri, 24 Jan 2014 18:42:41 -0800 (PST) Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: Alright. I have the code here. Now, I just want to note that the code was not designed to work "quickly" or be very well-written. It was rushed, as I only had a few days to finish the work, and by the time I wrote the program, I hadn't worked with Python (which I never had TOO much experience with anyways) for a while. (About a year, maybe?) It was a bit foolish to take up the project, but here's the code anyways: #D.J. Machale - Pendragon #Pendragon: Book Six - The Rivers of Zadaa #Page 98 #The sample sentences for this author. I put each sentence into a seperate variable because I knew no other way to divide the sentence. I also removed spaces so they wouldn't be counted. djmachale_1 = 'WheretonowIaskedLoor' djmachale_2 = 'ToaplacewherewewillnotbedisturbedbyBatuorRokadorsheanswered' djmachale_3 = 'WelefttheroomfollowingLoorthroughthetwistingtunnelthatIhadwalkedthroughseveraltimesbeforeonvisitingtoZadaa' djmachale_4 = 'Shortlyweleftthesmallertunneltoenterthehugecavernthatonceheldanundergroundriver' djmachale_5 = 'WhenSpaderandIwerefirstheretherewasafour-storywaterfallononesideoftheimmensecavernthatfedadeepragingriver' djmachale_6 = 'Nowtherewasonlyadribbleofwaterthatfellfromarockymouthintoapathetictrickleofastreamatthebottomofthemostlydryriverbed' djmachale_7 = 'WhathappenedhereAlderasked' djmachale_8 = 'ThereisalottotellLooranswered' djmachale_9 = 'Later' djmachale_10 = 'Alderacceptedthat' djmachale_11 = 'Hewasaneasyguy' djmachale_12 = 'Loorledustotheopeningthatwasoncehiddenbehindthewaterfallbutwasnowinplainsight' djmachale_13 = 'Weclimbedafewstonestairssteppedthroughtheportalandenteredaroomthatheldthewater-controldeviceIhavedescribedtoyoubefore' djmachale_14 = 'Toremindyouguysthisthinglookedlikeoneofthosegiantpipe-organsthatyouseeinchurch' djmachale_15 = 'Butthesepipesranhorizontallydisappearingintotherockwalloneithersideoftheroom' djmachale_16 = 'Therewasaplatforminfrontofitthatheldanamazingarrayofswitchesandvalves' djmachale_17 = 'WhenIfirstcameheretherewasaRokadorengineeronthatplatformfeverishlyworkingthecontrolslikeanexpert' djmachale_18 = 'Ihadnoideawhatthedevicedidotherthanknowingithadsomethingtodowithcontrollingtheflowofwaterfromtherivers' djmachale_19 = 'Theguyhadmapsanddiagramsthathereferredtowhilehequicklymadeadjustmentsandtoggledswitches' djmachale_20 = 'Nowtheplatformwasempty' #djmwords contains the amount of words in each sentence #djmwords_total is the total word count between all the samples djmwords = [6, 15, 22, 17, 26, 29, 5, 8, 1, 3, 5, 19, 25, 18, 16, 17, 20, 25, 18, 5] djmwords_total = sum(djmwords) avgWORDS_per_SENTENCE_DJMACHALE = (djmwords_total/20) #Each variable becomes the total number of letters in each sentence djmachale_1 = len(djmachale_1) djmachale_2 = len(djmachale_2) djmachale_3 = len(djmachale_3) djmachale_4 = len(djmachale_4) djmachale_5 = len(djmachale_5) djmachale_6 = len(djmachale_6) djmachale_7 = len(djmachale_7) djmachale_8 = len(djmachale_8) djmachale_9 = len(djmachale_9) djmachale_10 = len(djmachale_10) djmachale_11 = len(djmachale_11) djmachale_12 = len(djmachale_12) djmachale_13 = len(djmachale_13) djmachale_14 = len(djmachale_14) djmachale_15 = len(djmachale_15) djmachale_16 = len(djmachale_16) djmachale_17 = len(djmachale_17) djmachale_18 = len(djmachale_18) djmachale_19 = len(djmachale_19) djmachale_20 = len(djmachale_20) #DJMACHALE_TOTAL is the total letter count between all the samples DJ_Machale = [djmachale_1, djmachale_2, djmachale_3, djmachale_4, djmachale_5, djmachale_6, djmachale_7, djmachale_8, djmachale_9, djmachale_10, djmachale_11, djmachale_12, djmachale_13, djmachale_14, djmachale_15, djmachale_16, djmachale_17, djmachale_18, djmachale_19, djmachale_20] DJMACHALE_TOTAL = (djmachale_1+djmachale_2+djmachale_3+djmachale_4+djmachale_5+djmachale_6+djmachale_7+djmachale_8+djmachale_9+djmachale_10+djmachale_11+djmachale_12+djmachale_13+djmachale_14+djmachale_15+djmachale_16+djmachale_17+djmachale_18+djmachale_19+djmachale_20) avgLETTERS_per_SENTENCE_DJMACHALE = (DJMACHALE_TOTAL/20) avgLETTERS_per_WORD_DJMACHALE = (DJMACHALE_TOTAL/djmwords_total) #---------------------------------------------------------------------------------------------------------------------------------------------------------------------- #Suzanne Collins - The Hunger Games #The Hunger Games #Page 103 suzannecollins_1 = 'AsIstridetowardtheelevatorIflingmybowtoonesideandmyquivertotheother' suzannecollins_2 = 'IbrushpastthegapingAvoxeswhoguardtheelevatorsandhitthenumbertwelvebuttonwithmyfist' suzannecollins_3 = 'ThedoorsslidetogetherandIzipupward' suzannecollins_4 = 'Iactuallymakeitbacktomyfloorbeforethetearsstartrunningdownmycheeks' suzannecollins_5 = 'IcanheartheotherscallingmefromthesittingroombutIflydownthehallintomyroomboltthedoorandflingmyselfontomybed' suzannecollins_6 = 'ThenIreallybegintosob' suzannecollins_7 = 'NowIvedoneit' suzannecollins_8 = 'NowIveruinedeverything' suzannecollins_9 = 'IfIdevenstoodaghostofachanceitvanishedwhenIsentthatarrowflyingattheGamemakers' suzannecollins_10 = 'Whatwilltheydotomenow' suzannecollins_11 = 'Arrestme' suzannecollins_12 = 'Executeme' suzannecollins_13 = 'CutmytongueandturnintoanAvoxsoIcanwaitonthefutretributesofPanem' suzannecollins_14 = 'WhatwasIthinkingshootingattheGamemakers' suzannecollins_15 = 'OfcourseIwasntIwasshootingatthatapplebecauseIwassoangryatbeingignored' suzannecollins_16 = 'Iwasnttryingtokilloneofthem' suzannecollins_17 = 'IfIweretheydbedead' suzannecollins_18 = 'Ohwhatdoesitmatter' suzannecollins_19 = 'ItsnotlikeIwasgoingtowintheGamesanyway' suzannecollins_20 = 'Whocareswhattheydotome' suzcwords = [19, 19, 8, 16, 6, 4, 4, 20, 7, 2, 2, 19, 8, 18, 8, 6, 5, 11, 7] suzcwords_total = (19+19+8+16+6+4+4+20+7+2+2+19+8+18+8+6+5+11+7) avgWORDS_per_SENTENCE_SUZANNECOLLINS = (suzcwords_total/20) suzannecollins_1 = len(suzannecollins_1) suzannecollins_2 = len(suzannecollins_2) suzannecollins_3 = len(suzannecollins_3) suzannecollins_4 = len(suzannecollins_4) suzannecollins_5 = len(suzannecollins_5) suzannecollins_6 = len(suzannecollins_6) suzannecollins_7 = len(suzannecollins_7) suzannecollins_8 = len(suzannecollins_8) suzannecollins_9 = len(suzannecollins_9) suzannecollins_10 = len(suzannecollins_10) suzannecollins_11 = len(suzannecollins_11) suzannecollins_12 = len(suzannecollins_12) suzannecollins_13 = len(suzannecollins_13) suzannecollins_14 = len(suzannecollins_14) suzannecollins_15 = len(suzannecollins_15) suzannecollins_16 = len(suzannecollins_16) suzannecollins_17 = len(suzannecollins_17) suzannecollins_18 = len(suzannecollins_18) suzannecollins_19 = len(suzannecollins_19) suzannecollins_20 = len(suzannecollins_20) Suzanne_Collins = [suzannecollins_1, suzannecollins_2, suzannecollins_3, suzannecollins_4, suzannecollins_5, suzannecollins_6, suzannecollins_7, suzannecollins_8, suzannecollins_9, suzannecollins_10, suzannecollins_11, suzannecollins_12, suzannecollins_13, suzannecollins_14, suzannecollins_15, suzannecollins_16, suzannecollins_17, suzannecollins_18, suzannecollins_19, suzannecollins_20] SUZANNECOLLINS_TOTAL = (suzannecollins_1+suzannecollins_2+suzannecollins_3+suzannecollins_4+suzannecollins_5+suzannecollins_6+suzannecollins_7+suzannecollins_8+suzannecollins_9+suzannecollins_10+suzannecollins_11+suzannecollins_12+suzannecollins_13+suzannecollins_14+suzannecollins_15+suzannecollins_16+suzannecollins_17+suzannecollins_18+suzannecollins_19+suzannecollins_20) avgLETTERS_per_SENTENCE_SUZANNECOLLINS = (SUZANNECOLLINS_TOTAL/20) avgLETTERS_per_WORD_SUZANNECOLLINS = (SUZANNECOLLINS_TOTAL/suzcwords_total) #----------------------------------------------------------------------------------------------------------------------------------------- #Richard Peck - The Last Safe Place on Earth #The Last Safe Place on Earth #Page 1-2 richardpeck_1 = 'HalloweensaweekandahalfawayHomecomingtheweekendafter' richardpeck_2 = 'ItsthattimeofyearandcominghomeImthinkingWhatagreateveningtobegoingsomewherewithagirlmyarmdrapedoverhersoftshoulderthetwoofusscuffingthroughtheleaves' richardpeck_3 = 'ImseeinggirlseverywhereIlooksomeofthemrealmostnot' richardpeck_4 = 'Iseegirlsintheshapesthetreetrunksmakeandintheformationsoftheclouds' richardpeck_5 = 'Iseealotofgirlsthisfall' richardpeck_6 = 'Imnotobsessed' richardpeck_7 = 'Imintenthgrade' richardpeck_8 = 'SoIwascominghomeonfoot' richardpeck_9 = 'Therewereacoupleofbooksinmybackpack' richardpeck_10 = 'OnewasRayBradburysFahrenheit451whichweweresupposedtobereadingforMrsLenkysclass' richardpeck_11 = 'Iplannedtobuckledownonschoolworkandreallyhitthebooksnextyearsenioryearatthelatest' richardpeck_12 = 'MeanwhileIwastakingeverydayasitcametryingtogetatoeholdonhighschool' richardpeck_13 = 'ButthefactisIdidntreallythinkhighschoolwashappeninguntilIfoundagirl' richardpeck_14 = 'ItwasapostcardeveningalongTranquilyLanetheactualnameofourstreet' richardpeck_15 = 'Thehazewaslikebonfiresmoke,thoughwecantburnleaveswithinthevillagelimits' richardpeck_16 = 'Itwasared-and-goldworldwithpurpleeveningcomingon' richardpeck_17 = 'OurhouseisthebigwhitebrickwiththegreenshutterslikeahouseonaChristmascard' richardpeck_18 = 'Weusedtoliveinthewesternsuburbs' richardpeck_19 = 'ButwhenDianaandIwereinsixthgradethejuniorhighouttherehadacoupleofknifefightsthatmadethenews' richardpeck_20 = 'Thegangsweremovinginsowemovedout' richwords = [11, 36, 12, 17, 8, 3, 4, 7, 9 , 17, 19, 17, 17, 14, 15, 12, 18, 9, 23, 9] richwords_total = (11+36+12+17+8+3+4+7+9+17+19+17+17+14+15+12+18+9+23+9) avgWORDS_per_SENTENCE_RICHARDPECK = (richwords_total/20) richardpeck_1 = len(richardpeck_1) richardpeck_2 = len(richardpeck_2) richardpeck_3 = len(richardpeck_3) richardpeck_4 = len(richardpeck_4) richardpeck_5 = len(richardpeck_5) richardpeck_6 = len(richardpeck_6) richardpeck_7 = len(richardpeck_7) richardpeck_8 = len(richardpeck_8) richardpeck_9 = len(richardpeck_9) richardpeck_10 = len(richardpeck_10) richardpeck_11 = len(richardpeck_11) richardpeck_12 = len(richardpeck_12) richardpeck_13 = len(richardpeck_13) richardpeck_14 = len(richardpeck_14) richardpeck_15 = len(richardpeck_15) richardpeck_16 = len(richardpeck_16) richardpeck_17 = len(richardpeck_17) richardpeck_18 = len(richardpeck_18) richardpeck_19 = len(richardpeck_19) richardpeck_20 = len(richardpeck_20) Richard_Peck = [richardpeck_1, richardpeck_2, richardpeck_3, richardpeck_4, richardpeck_5, richardpeck_6, richardpeck_7, richardpeck_8, richardpeck_9, richardpeck_10, richardpeck_11, richardpeck_12, richardpeck_13, richardpeck_14, richardpeck_15, richardpeck_16, richardpeck_17, richardpeck_18, richardpeck_19, richardpeck_20] RICHARDPECK_TOTAL = (richardpeck_1+richardpeck_2+richardpeck_3+richardpeck_4+richardpeck_5+richardpeck_6+richardpeck_7+richardpeck_8+richardpeck_9+richardpeck_10+richardpeck_11+richardpeck_12+richardpeck_13+richardpeck_14+richardpeck_15+richardpeck_16+richardpeck_17+richardpeck_18+richardpeck_19+richardpeck_20) avgLETTERS_per_SENTENCE_RICHARDPECK = (RICHARDPECK_TOTAL/20) avgLETTERS_per_WORD_RICHARDPECK = (RICHARDPECK_TOTAL/richwords_total) #--------------------------------------------------------------------------------------------------------- #EXAMPLE SLOT example1 = 'Wepulledthefilmfortheten-thirtynewstohearhowtheWarriorshaddoneagainsttheLakeVillaVikinsontheVikingshomefield' example2 = 'WedlostbutitwascloseandC.E.andIwentbacktotheDracula' example3 = 'Itwasgettinglatewhenthephonerang' example4 = 'DeepinhispopcornworldDaddidntanswerit' example5 = 'Ipickedupinthedenanditwasawoman' example6 = 'IwavedatC.E.toturndownthesoundsbecausethewomanwascrying' example7 = 'Whoisthis' example8 = 'ItwasMrsCunningham' example9 = 'Icantfindmydaughtershesaid' example10 = 'IcantfindPace' example11 = 'SheshereIsaid' example12 = 'Shesupstairswithmysister' example13 = 'AmomentofsilencethenandMrsCunninghamsvoiceshuddered' example14 = 'IssheYoutellhertostayrightthereImcomingover' example15 = 'SoweneverdidseehowtheDraculafilmended' example16 = 'HeyPaceIsaidupthestairs' example17 = 'Yourmomscomingover' example18 = 'ThisbroughteverybodytothefronthallPacefirst' example19 = 'DianawasbehindherandMominherrobeandMarnieinherpajamas' example20 = 'BeforeDrandMrsCunninghamgothereDadwasinthefronthalltooinhisapron' examplewords = [25, 15, 8, 9, 11, 14, 3, 4, 6, 4, 4, 5, 10, 7, 4, 9, 14, 17] examplewords_total = sum(examplewords) avgWORDS_per_SENTENCE_EXAMPLE = (examplewords_total/20) example1 = len(example1) example2 = len(example2) example3 = len(example3) example4 = len(example4) example5 = len(example5) example6 = len(example6) example7 = len(example7) example8 = len(example8) example9 = len(example9) example10 = len(example10) example11 = len(example11) example12 = len(example12) example13 = len(example13) example14 = len(example14) example15 = len(example15) example16 = len(example16) example17 = len(example17) example18 = len(example18) example19 = len(example19) example20 = len(example20) example = [example1, example2, example3, example4, example5, example6, example7, example8, example9, example10, example11, example12, example13, example14, example15, example16, example17, example18, example19, example20] EXAMPLE_TOTAL = (example1+example2+example3+example4+example5+example6+example7+example8+example9+example10+example11+example12+example13+example14+example15+example16+example17+example18+example19+example20) avgLETTERS_per_SENTENCE_EXAMPLE = (EXAMPLE_TOTAL/20) avgLETTERS_per_WORD_EXAMPLE = (EXAMPLE_TOTAL/examplewords_total) #------------------------------------------------------------------------------------------------------------------------------ #Tests for similarities and prints (displays) the author whom the program believes to have written the example text #I used a scoreboard system of sorts to determine which author was most similar to the example. Each time the program finds a match to one in each of the tests, it adds a point to that author here. DJMachalePossibility = 0 SuzanneCollinsPossibility = 0 RichardPeckPossibility = 0 #Matches average letters/sentence in example with most likely author #I attempted to find the closest value by subtracting the example's value from each of the authors. The author with the smallest distance from the example would be marked up one point. avgLPS_DJ_EXAMPLE = (avgLETTERS_per_SENTENCE_DJMACHALE-avgLETTERS_per_SENTENCE_EXAMPLE) avgLPS_SUZC_EXAMPLE = (avgLETTERS_per_SENTENCE_SUZANNECOLLINS-avgLETTERS_per_SENTENCE_EXAMPLE) avgLPS_RICH_EXAMPLE = (avgLETTERS_per_SENTENCE_RICHARDPECK-avgLETTERS_per_SENTENCE_EXAMPLE) LPS_Comparisons = [avgLPS_DJ_EXAMPLE, avgLPS_SUZC_EXAMPLE, avgLPS_RICH_EXAMPLE] avgLPS_Match = min(LPS_Comparisons) if avgLPS_Match == avgLPS_DJ_EXAMPLE: DJMachalePossibility = (DJMachalePossibility+1) if avgLPS_Match == avgLPS_SUZC_EXAMPLE: SuzanneCollinsPossibility = (SuzanneCollinsPossibility+1) if avgLPS_Match == avgLPS_RICH_EXAMPLE: RichardPeckPossibility = (RichardPeckPossibility+1) #Matches average words/sentence in example with most likely author avgWPS_DJ_EXAMPLE = (avgWORDS_per_SENTENCE_DJMACHALE-avgWORDS_per_SENTENCE_EXAMPLE) avgWPS_SUZC_EXAMPLE = (avgWORDS_per_SENTENCE_SUZANNECOLLINS-avgWORDS_per_SENTENCE_EXAMPLE) avgWPS_RICH_EXAMPLE = (avgWORDS_per_SENTENCE_RICHARDPECK-avgWORDS_per_SENTENCE_EXAMPLE) WPS_Comparisons = [avgWPS_DJ_EXAMPLE, avgWPS_SUZC_EXAMPLE, avgWPS_RICH_EXAMPLE] avgWPS_Match = min(WPS_Comparisons) if avgWPS_Match == avgWPS_DJ_EXAMPLE: DJMachalePossibility = (DJMachalePossibility+1) if avgWPS_Match == avgWPS_SUZC_EXAMPLE: SuzanneCollinsPossibility = (SuzanneCollinsPossibility+1) if avgWPS_Match == avgWPS_RICH_EXAMPLE: RichardPeckPossibility = (RichardPeckPossibility+1) #Matches average letters/word in example with most likely author avgLPW_DJ_EXAMPLE = (avgLETTERS_per_WORD_DJMACHALE-avgLETTERS_per_WORD_EXAMPLE) avgLPW_SUZC_EXAMPLE = (avgLETTERS_per_WORD_SUZANNECOLLINS-avgLETTERS_per_WORD_EXAMPLE) avgLPW_RICH_EXAMPLE = (avgLETTERS_per_WORD_RICHARDPECK-avgLETTERS_per_WORD_EXAMPLE) LPW_Comparisons = [avgLPW_DJ_EXAMPLE, avgLPW_SUZC_EXAMPLE, avgLPW_SUZC_EXAMPLE] avgLPW_Match = min(LPW_Comparisons) if avgLPW_Match == avgLPW_DJ_EXAMPLE: DJMachalePossibility = (DJMachalePossibility+1) if avgLPW_Match == avgLPW_SUZC_EXAMPLE: SuzanneCollinsPossibility = (SuzanneCollinsPossibility+1) if avgLPW_Match == avgLPW_RICH_EXAMPLE: RichardPeckPossibility = (RichardPeckPossibility+1) AUTHOR_SCOREBOARD = [DJMachalePossibility, SuzanneCollinsPossibility, RichardPeckPossibility] #The author with the most points on them would be considered the program's guess. Match = max(AUTHOR_SCOREBOARD) print AUTHOR_SCOREBOARD if Match == DJMachalePossibility: print "The author should be D.J. Machale." if Match == SuzanneCollinsPossibility: print "The author should be Suzanne Collins." if Match == RichardPeckPossibility: print "The author should be Richard Peck." ------------------------------------------------------------------------------ Hopefully, there won't be any copyright issues. Like someone said, this should be fair use. The problem I'm having is that it always gives Suzanne Collins, no matter what example is put in. I'm really sorry that the code isn't very clean. Like I said, it was rushed and I have little experience. I'm just desperate for help as it's a bit too late to change projects, so I have to stick with this. Also, if it's of any importance, I have to be able to remove or add any of the "average letters per word/average letters per sentence/average words per sentence things" to test the program at different levels of strictness. I would GREATLY appreciate any help with this. Thank you! From rustompmody at gmail.com Fri Jan 24 22:06:55 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 24 Jan 2014 19:06:55 -0800 (PST) Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: On Saturday, January 25, 2014 8:12:41 AM UTC+5:30, kvxd... at gmail.com wrote: > Alright. I have the code here. Now, I just want to note that the code was not designed to work "quickly" or be very well-written. It was rushed, as I only had a few days to finish the work, and by the time I wrote the program, I hadn't worked with Python (which I never had TOO much experience with anyways) for a while. (About a year, maybe?) It was a bit foolish to take up the project, but here's the code anyways: Ewwww! If you (or anyone with basic python experience) rewrites that code, it will become 1/50th the size and all that you call 'code' will reside in data files. That can mean one of json, xml, yml, ini, pickle, ini, csv etc If you need further help in understanding/choosing, post back From steve+comp.lang.python at pearwood.info Fri Jan 24 23:37:34 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Jan 2014 04:37:34 GMT Subject: Trying to understand this moji-bake Message-ID: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> I have an unexpected display error when dealing with Unicode strings, and I cannot understand where the error is occurring. I suspect it's not actually a Python issue, but I thought I'd ask here to start. Using Python 3.3, if I print a unicode string from the command line, it displays correctly. I'm using the KDE 3.5 Konsole application, with the encoding set to the default (which ought to be UTF-8, I believe, although I'm not completely sure). This displays correctly: [steve at ando ~]$ python3.3 -c "print(u'??????')" ?????? Likewise for Python 3.2: [steve at ando ~]$ python3.2 -c "print('??????')" ?????? But using Python 2.7, I get a really bad case of moji-bake: [steve at ando ~]$ python2.7 -c "print u'??????'" ??????????? However, interactively it works fine: [steve at ando ~]$ python2.7 -E Python 2.7.2 (default, May 18 2012, 18:25:10) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print u'??????' ?????? This occurs on at least two different machines, one using Centos and the other Debian. Anyone have any idea what's going on? I can replicate the display error using Python 3 like this: py> s = '??????' py> print(s.encode('utf-8').decode('latin-1')) ??????????? but I'm not sure why it's happening at the command line. Anyone have any ideas? -- Steven From kvxdelta at gmail.com Fri Jan 24 23:58:50 2014 From: kvxdelta at gmail.com (theguy) Date: Fri, 24 Jan 2014 20:58:50 -0800 (PST) Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: <1eeb0e4b-ff9a-4b5e-86ec-773ca98fbf1b@googlegroups.com> On Friday, January 24, 2014 7:06:55 PM UTC-8, Rustom Mody wrote: > On Saturday, January 25, 2014 8:12:41 AM UTC+5:30, kvxd... at gmail.com wrote: > > > Alright. I have the code here. Now, I just want to note that the code was not designed to work "quickly" or be very well-written. It was rushed, as I only had a few days to finish the work, and by the time I wrote the program, I hadn't worked with Python (which I never had TOO much experience with anyways) for a while. (About a year, maybe?) It was a bit foolish to take up the project, but here's the code anyways: > > > > > > > > Ewwww! > > > > If you (or anyone with basic python experience) rewrites that code, it will become > > 1/50th the size and all that you call 'code' will reside in data files. > > > > That can mean one of json, xml, yml, ini, pickle, ini, csv etc > > > > If you need further help in understanding/choosing, post back I know. I'm kind of ashamed of the code, but it does the job I need it to up to a certain point, where it for some reason continually gives me Suzanne Collins as the author. It always gives three points to her name in the AUTHOR_SCOREBOARD list. The code, though, is REALLY bad. I'm trying to simply get it to do the things needed for the program. If I could get it to actually calculate the "points" for AUTHOR_SCOREBOARD properly, then all my problems would be solved. Luckily, I'm not being graded on the elegance or conciseness of my code. Thank you for the constructive criticism, though I am really seeking help with my little problem involving that dang scoreboard. Thank you. From greg.ewing at canterbury.ac.nz Sat Jan 25 00:11:38 2014 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Sat, 25 Jan 2014 18:11:38 +1300 Subject: generate De Bruijn sequence memory and string vs lists In-Reply-To: References: Message-ID: <52E3478A.6040504@canterbury.ac.nz> Vincent Davis wrote: > True, the "all you want is a mapping" is not quite true. I actually > plan to plot frequency (the number of times an observed sub sequence > overlaps a value in the De Bruijn sequence) The way the sub sequences > overlap is important to me and I don't see a way go from base-k (or any > other base) to the index location in the De Bruijn sequence. i.e. > a decoding algorithm. So the order or position in which the subsequences appear in the de Bruijn sequence is important? Can you explain more about what you're trying to do? Maybe give a scaled-down example? Whatever it is, it seems like there should be a more efficient way than materialising the whole umpteen-gigabyte sequence. -- Greg From cs at zip.com.au Sat Jan 25 00:08:23 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 25 Jan 2014 16:08:23 +1100 Subject: Trying to understand this moji-bake In-Reply-To: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <20140125050823.GA62643@cskk.homeip.net> On 25Jan2014 04:37, Steven D'Aprano wrote: > I have an unexpected display error when dealing with Unicode strings, and > I cannot understand where the error is occurring. I suspect it's not > actually a Python issue, but I thought I'd ask here to start. > > Using Python 3.3, if I print a unicode string from the command line, it > displays correctly. I'm using the KDE 3.5 Konsole application, with the > encoding set to the default (which ought to be UTF-8, I believe, although > I'm not completely sure). There are at least 2 layers: the encoding python is using for transcription to the terminal and the decoding the terminal is making of the byte stream to decide what to display. The former can be printed with: import sys print(sys.stdout.encoding) The latter depends on your desktop settings and KDE settings I guess. I would hope the Konsole will decide based on your environment settings. Running the shell command: locale will print the settings derived from that. Provided your environment matches that which invoked the Konsole, that should be informative. But I expect the Konsole is decoding using UTF-8 because so much else works for you already. I would point out that you could perhaps debug with something like this: python2.7 ..... | od -c which will print the output bytes. By printing to the terminal, you're letting the terminal's decoding get in your way. It is fine for seeing correct/incorrect results, but not so fine for seeing the bytes causing them. > This displays correctly: > [steve at ando ~]$ python3.3 -c "print(u'??????')" > ?????? > > > Likewise for Python 3.2: > [steve at ando ~]$ python3.2 -c "print('??????')" > ?????? > > But using Python 2.7, I get a really bad case of moji-bake: > [steve at ando ~]$ python2.7 -c "print u'??????'" > ??????????? > > However, interactively it works fine: [...] Debug by printing sys.stdout.encoding at this point. I do recall getting different output encodings depending on how Python was invoked; I forget the pattern, but I also remember writing some ghastly hack to work around it, which I can't find at the moment... Also see "man python2.7" in particular the PYTHONIOENCODING environment variable. That might let you exert more control. Cheers, -- Cameron Simpson ASCII n s. [from the greek] Those people who, at certain times of the year, have no shadow at noon; such are the inhabitatants of the torrid zone. - 1837 copy of Johnson's Dictionary From rosuav at gmail.com Sat Jan 25 01:08:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 17:08:56 +1100 Subject: Trying to understand this moji-bake In-Reply-To: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Jan 25, 2014 at 3:37 PM, Steven D'Aprano wrote: > But using Python 2.7, I get a really bad case of moji-bake: > > [steve at ando ~]$ python2.7 -c "print u'??????'" > ??????????? What's 2.7's default source code encoding? I thought it was ascii, but maybe it's assuming (in the absence of a magic cookie) that it's Latin-1. ChrisA From davea at davea.name Sat Jan 25 01:38:42 2014 From: davea at davea.name (Dave Angel) Date: Sat, 25 Jan 2014 01:38:42 -0500 (EST) Subject: Need Help with Programming Science Project References: Message-ID: kvxdelta at gmail.com Wrote in message: > Alright. I have the code here. Now, I just want to note that the code was not designed to work "quickly" or be very well-written. It was rushed, as I only had a few days to finish the work, and by the time I wrote the program, I hadn't worked with Python (which I never had TOO much experience with anyways) for a while. (About a year, maybe?) It was a bit foolish to take up the project, but here's the code anyways: ......... > > > LPW_Comparisons = [avgLPW_DJ_EXAMPLE, avgLPW_SUZC_EXAMPLE, avgLPW_SUZC_EXAMPLE] > avgLPW_Match = min(LPW_Comparisons) > > if avgLPW_Match == avgLPW_DJ_EXAMPLE: > DJMachalePossibility = (DJMachalePossibility+1) > > if avgLPW_Match == avgLPW_SUZC_EXAMPLE: > SuzanneCollinsPossibility = (SuzanneCollinsPossibility+1) > > if avgLPW_Match == avgLPW_RICH_EXAMPLE: > RichardPeckPossibility = (RichardPeckPossibility+1) > > AUTHOR_SCOREBOARD = [DJMachalePossibility, SuzanneCollinsPossibility, RichardPeckPossibility] > > #The author with the most points on them would be considered the program's guess. > Match = max(AUTHOR_SCOREBOARD) > > print AUTHOR_SCOREBOARD > > if Match == DJMachalePossibility: > print "The author should be D.J. Machale." > > if Match == SuzanneCollinsPossibility: > print "The author should be Suzanne Collins." > > if Match == RichardPeckPossibility: > print "The author should be Richard Peck." > > > ------------------------------------------------------------------------------ > Hopefully, there won't be any copyright issues. Like someone said, this should be fair use. The problem I'm having is that it always gives Suzanne Collins, no matter what example is put in. I'm really sorry that the code isn't very clean. Like I said, it was rushed and I have little experience. I'm just desperate for help as it's a bit too late to change projects, so I have to stick with this. Also, if it's of any importance, I have to be able to remove or add any of the "average letters per word/average letters per sentence/average words per sentence things" to test the program at different levels of strictness. I would GREATLY appreciate any help with this. Thank you! > 1. When you calculate averages, you should be using floating point divide. avg = float (a) / b 2. When you subtract two values, you need an abs, because otherwise min () will hone in on the negative values. 3. Realize that having Match agree with more than one is not that unlikely. 4. If you want to vary what you call strictness, you're really going to need to learn about functions. -- DaveA From seaspeak at gmail.com Sat Jan 25 01:37:37 2014 From: seaspeak at gmail.com (seaspeak at gmail.com) Date: Fri, 24 Jan 2014 22:37:37 -0800 (PST) Subject: should I transfer 'iterators' between functions? Message-ID: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> take the following as an example, which could work well. But my concern is, will list 'l' be deconstructed after function return? and then iterator point to nowhere? def test(): l = [1, 2, 3, 4, 5, 6, 7, 8] return iter(l) def main(): for i in test(): print(i) From rosuav at gmail.com Sat Jan 25 01:43:58 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 17:43:58 +1100 Subject: should I transfer 'iterators' between functions? In-Reply-To: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> References: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> Message-ID: On Sat, Jan 25, 2014 at 5:37 PM, wrote: > take the following as an example, which could work well. > But my concern is, will list 'l' be deconstructed after function return? and then iterator point to nowhere? > > def test(): > l = [1, 2, 3, 4, 5, 6, 7, 8] > return iter(l) > def main(): > for i in test(): > print(i) Perfectly safe. Python guarantees that nothing can ever point to "nowhere"; everything that might be looking for something else will hold a reference to it, so the thing referred to will hang around. ChrisA From steve+comp.lang.python at pearwood.info Sat Jan 25 01:45:30 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 25 Jan 2014 06:45:30 GMT Subject: should I transfer 'iterators' between functions? References: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> Message-ID: <52e35d89$0$29999$c3e8da3$5496439d@news.astraweb.com> On Fri, 24 Jan 2014 22:37:37 -0800, seaspeak wrote: > take the following as an example, which could work well. But my concern > is, will list 'l' be deconstructed after function return? and then > iterator point to nowhere? That would be a pretty awful bug for Python, since it would like lead to a core dump. But no, it works fine, as you can see by trying it at the interactive interpreter: py> def test(): ... L = [1, 2, 4, 8, 16] ... return iter(L) ... py> py> for i in test(): ... print(i) ... 1 2 4 8 16 In fact, we don't even need a function to see the same effect: py> L = [1, 2, 4, 8, 16] py> it = iter(L) py> del L py> L = "something else" py> for i in it: ... print(i) ... 1 2 4 8 16 Python keeps track of when objects are in use, and does not destroy them so long as it is in use. In the meantime, you can exit the function, unbind (delete) the variable, re-assign to something else, whatever, and you should never get a core dump. (I've only ever seen a single core dump in Python in 15+ years.) -- Steven From frank at chagford.com Sat Jan 25 02:18:44 2014 From: frank at chagford.com (Frank Millman) Date: Sat, 25 Jan 2014 09:18:44 +0200 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: "Chris Angelico" wrote in message news:CAPTjJmpi-kvJAVs2gK+nH5n6q3REkJaKR=CZeRfzUgDk8_VLGw at mail.gmail.com... > On Fri, Jan 24, 2014 at 11:49 PM, Frank Millman > wrote: >> > [...] I have realised that we unlikely to come to an agreement on this in the near future, as our philosophies are completely different. You have stated that your objective is to express as much as possible in Python code. I have stated that my objective is to express as little as possible in Python code. We would have to resolve that difference of opinion first, before discussing our respective approaches in detail, and that is way beyond the scope of this thread. As a brief example of my approach, here is how I would write your simple 'About' box. Here is your version - mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0) ->add(GTK2.Label("About Gypsum: big long multi-line string")) ->add(GTK2.HbuttonBox() ->add(GTK2.Button("Close")) ->add(GTK2.Button("Foobar")) ) ); Here is my version -
Currently I do not have a widget for a multi-line label, so I just show three separate lines. If I ever needed one, it would not take long to create. I took two screenshots, but I don't know the best way to upload and share them. I found a site called tinypic, which works, but the screen is cluttered with a lot of other stuff. Still, it shows what I want. First, here is the screen as rendered in Internet Explorer (it works in other browsers as well - even on my smart phone, though I have not done any optimising for mobile devices yet) - http://tinypic.com/r/ip15xx/5 Second, here is the screen designer, showing a portion of the screen definition - one of the buttons. As you can see, the designer does not have to worry about XML at all - http://tinypic.com/r/1j7sdh/5 I am not claiming that I am 'right', or that this is a perfect solution. It is just 'where I am' right now, after quite a long period of evolution, and it is achieving a large portion of what I am aiming for, so I will press on with my current approach for now. Hopefully it will not take *too* long before I am in a position to release something, and then I will be very interested in any feedback. Thanks for the interesting discussion. Frank From greg.ewing at canterbury.ac.nz Sat Jan 25 02:25:20 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 25 Jan 2014 20:25:20 +1300 Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: theguy wrote: > I so far have > three different authors in the program and have already put in the example > text but for some reason, the program always leans toward one specific > author, Suzanne Collins, no matter what insane number I try to put in or how > much I tinker with the coding. It's obvious what's happening here: all the other authors have heavily borrowed from Suzanne Collins. You've created a plagiarism detector! :-) -- Greg From rosuav at gmail.com Sat Jan 25 02:33:57 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 25 Jan 2014 18:33:57 +1100 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: On Sat, Jan 25, 2014 at 6:18 PM, Frank Millman wrote: > I have realised that we unlikely to come to an agreement on this in the near > future, as our philosophies are completely different. > > You have stated that your objective is to express as much as possible in > Python code. > > I have stated that my objective is to express as little as possible in > Python code. Ah but the question is *why* you want to minimize code. I write everything in code because it minimizes unnecessary coding - yes, that's right, I maximize code to minimize code :) - because all that code that isn't written also isn't debugged, isn't maintained, and isn't placing unnecessary restrictions on anything. What's the advantage of doing it in XML? Your GUI builder is all very well, but it could as easily write Python code as XML, so it doesn't give a strong incentive for XML. And personally, I think it's more likely to be a waste of effort, too, but that's more because a good GUI builder takes a *ton* of effort to build. That's time that has to be spent up-front, before you have experience with the system, before you _can get_ experience with the system - and, see above, it's code that has to be debugged and maintained. Every framework has to justify itself. Just "it lets people not write code" isn't enough unless not-writing-code can justify the costs. ChrisA From greg.ewing at canterbury.ac.nz Sat Jan 25 02:30:56 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Sat, 25 Jan 2014 20:30:56 +1300 Subject: Need Help with Programming Science Project In-Reply-To: <1eeb0e4b-ff9a-4b5e-86ec-773ca98fbf1b@googlegroups.com> References: <1eeb0e4b-ff9a-4b5e-86ec-773ca98fbf1b@googlegroups.com> Message-ID: theguy wrote: > If I could get it to actually > calculate the "points" for AUTHOR_SCOREBOARD properly, then all my problems > would be solved. Have you tried getting it to print out the values it's getting for the scores, and comparing them with what you calculate by hand? -- Greg From thrinaxodon at spammersdevonian.thrinaxodon Sat Jan 25 03:36:16 2014 From: thrinaxodon at spammersdevonian.thrinaxodon (Thrinass) Date: Sat, 25 Jan 2014 03:36:16 -0500 Subject: THRINAXODON BLOWS THE SMOKE HARD! Message-ID: ============== >BREAKING NEWS ============== > The New York Times, Thrinaxodon, PhD =================== > According to U.S. dictator Obama, the U.S. has recently legalized weed to brainwash it's citizens. Millions of Americans hate the new move, they don't want OUR KIDS GROWING UP IN A WORLD RULLED BY WEED! Thrinaxodon was mad at the move, staying in New Zealand to get away from the shit, Thrinaxodon said, "My homeland America has legalized a drug! WTF? Obama has already done enough crimes against humanity, but brainwashing our Star Trek: Next Generation is now the new goal of the Obama regime? WTF?" > ============================ > Obama said, "I`m doing this for my people, fellow Americans by brainwashing our Star Trek: Next Generation for my BRAND NEW FEMA CAMPS!" > Thrinaxodon said, "Bullshit! Communist regimes are better than the Obama regime!" ============================ > Who knows what will happen to our sons and grandsons. > ====================================== EVIDENCE THAT HUMANS LIVED IN THE DEVONIAN: https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/6f501c469c7af24f# https://groups.google.com/group/sci.bio.paleontology/browse_thread/thread/3aad75c16afb0b82# ==================================== http://thrinaxodon.wordpress.com/ =================================== THRINAXODON ONLY HAD THIS TO SAY: "I..I...I...Can't believe it. This completely disproved Darwinian orthodoxy." =================================== THE BASTARDS AT THE SMITHSONIAN, AND THE LEAKEY FOUNDATION ARE ERODING WITH FEAR. =========================== THESE ASSHOLES ARE GOING TO DIE: THOMAS AQUINAS; ALDOUS HUXLEY; BOB CASANVOVA; SkyEyes; DAVID IAIN GRIEG; MARK ISAAK; JOHN HARSHAM; RICHARD NORMAN; DR. DOOLITTLE; CHARLES DARWIN; MARK HORTON; ERIK SIMPSON; HYPATIAB7; PAUL J. GANS; JILLERY; WIKI TRIK; THRINAXODON; PETER NYIKOS; RON OKIMOTO; JOHN S. WILKINS =========================== THRINAXODON WAS SCOURING ANOTHER DEVONIAN FOSSIL BED, AND FOUND A HUMAN SKULL, AND A HUMAN FEMUR. HE ANALYSED THE FINDS, AND SAW THAT THEY WERE NOT NORMAL ROCKS. THESE WERE FOSSILIZED BONES. THEY EVEN HAD TOOTH MARKS ON THEM. SO, THRINAXODON BROUGHT THEM TO THE LEAKEY FOUNDATION, THEY UTTERLY DISMISSED IT, AND SAID, "We want to keep people thinking that humans evolved 2 Ma." THRINAXODON BROUGHT HIS SWORD, AND SAID, "SCIENCE CORRECTS ITSELF." RICHARD LEAKEY SAID, "That is a myth, for people to believe in science." THRINAXODON PLANS TO BRING DOOM TO SCIENCE, ITSELF. ============================ THRINAXODON IS NOW ON TWITTER. -- Thrinaxodon, The Ultimate Defender of USENET From __peter__ at web.de Sat Jan 25 03:56:09 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 25 Jan 2014 09:56:09 +0100 Subject: Trying to understand this moji-bake References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > I have an unexpected display error when dealing with Unicode strings, and > I cannot understand where the error is occurring. I suspect it's not > actually a Python issue, but I thought I'd ask here to start. I suppose it is a Python issue -- where Python fails to guess an encoding it usually falls back to ascii. > But using Python 2.7, I get a really bad case of moji-bake: > > [steve at ando ~]$ python2.7 -c "print u'??????'" > ??????????? > > > However, interactively it works fine: > > [steve at ando ~]$ python2.7 -E > Python 2.7.2 (default, May 18 2012, 18:25:10) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> print u'??????' > ?????? You can provoke it with exec: >>> exec "print u'??????'" ??????????? >>> exec u"print u'??????'" ?????? >>> exec "# -*- coding: utf-8 -*-\nprint u'??????'" ?????? > This occurs on at least two different machines, one using Centos and the > other Debian. > > Anyone have any idea what's going on? I can replicate the display error > using Python 3 like this: > > py> s = '??????' > py> print(s.encode('utf-8').decode('latin-1')) > ??????????? > > but I'm not sure why it's happening at the command line. Anyone have any > ideas? It is probably burried in the C code -- after a few indirections I lost track :( From wxjmfauth at gmail.com Sat Jan 25 04:24:06 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Sat, 25 Jan 2014 01:24:06 -0800 (PST) Subject: Trying to understand this moji-bake In-Reply-To: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <42dab079-6766-4efd-aa64-33fdce2d3178@googlegroups.com> Le samedi 25 janvier 2014 05:37:34 UTC+1, Steven D'Aprano a ?crit?: > I have an unexpected display error when dealing with Unicode strings, and > > I cannot understand where the error is occurring. I suspect it's not > > actually a Python issue, but I thought I'd ask here to start. > > > > Using Python 3.3, if I print a unicode string from the command line, it > > displays correctly. I'm using the KDE 3.5 Konsole application, with the > > encoding set to the default (which ought to be UTF-8, I believe, although > > I'm not completely sure). This displays correctly: > > > > [steve at ando ~]$ python3.3 -c "print(u'??????')" > > ?????? > > > > > > Likewise for Python 3.2: > > > > [steve at ando ~]$ python3.2 -c "print('??????')" > > ?????? > > > > > > But using Python 2.7, I get a really bad case of moji-bake: > > > > [steve at ando ~]$ python2.7 -c "print u'??????'" > > ??????????? > > > > > > However, interactively it works fine: > > > > [steve at ando ~]$ python2.7 -E > > Python 2.7.2 (default, May 18 2012, 18:25:10) > > [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 > > Type "help", "copyright", "credits" or "license" for more information. > > >>> print u'??????' > > ?????? > > > > > > This occurs on at least two different machines, one using Centos and the > > other Debian. > > > > Anyone have any idea what's going on? I can replicate the display error > > using Python 3 like this: > > > > py> s = '??????' > > py> print(s.encode('utf-8').decode('latin-1')) > > ??????????? > > > > but I'm not sure why it's happening at the command line. Anyone have any > > ideas? > > > The basic problem is neither Python, nor the system (OS), nor the terminal, nor the GUI console. The basic problem is that all these elements [*] are not "speaking" the same language. The second problem lies in Python itsself. Python attempts to solve this problem by doing its own "cooking" based on the elements, I pointed above [*], with the side effect the situation may just become more confused and/or just not properly working (sys.std***.encoding, print, GUI/terminal, souce coding, ...) The third problem is more *x specific. In many cases, the Python "distribution" is tweaked in such a way to make it working on a specific *x-version/distribution (sys.getdefaultencoding(), site.py, sitecustomize.py) and finally resulting in a non properly working Python. Fourth problem. GUI applications supposed to mimick the "real" terminal by doing and adding their own "recipes". Fifth problem. The user who has to understand all this stuff. n-th problem, ... jmf PS I already understood all this stuff ten years ago! From justinpmullins at gmail.com Sat Jan 25 05:02:15 2014 From: justinpmullins at gmail.com (justinpmullins at gmail.com) Date: Sat, 25 Jan 2014 02:02:15 -0800 (PST) Subject: Help with my 8-year old son's first program. I'm stuck! Message-ID: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> My son is learning Python and I know nothing about computers. He's written a simple calculator program that doesn't work. For the life of me, I can't see why. Any help gratefully received. Here's his code: def a(): import sys print("welcome to the calculation") print("please type a number") one = int(sys.stdin.readline()) print("type d for division,") print("type m for multiplication,") print("type s for subtraction,") print("and type p for plus") op = (sys.stdin.readline()) print("%s selected" % op) print("please enter another number") two = int(sys.stdin.readline()) if op == str(d): out == one / two print("the answer is %s" % out) elif op == "m": out == one * two print("the answer is %s" % out) elif op == "s": out == one - two print("the answer is %s" % out) elif op == "p": out == one + two print("the answer is %s" % out) else: print("huh") Where is he going wrong? Many thanks in advance From airween at gmail.com Sat Jan 25 05:24:33 2014 From: airween at gmail.com (Ervin =?utf-8?Q?Heged=C3=BCs?=) Date: Sat, 25 Jan 2014 11:24:33 +0100 Subject: Help with my 8-year old son's first program. I'm stuck! In-Reply-To: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> References: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> Message-ID: <20140125102432.GC2643@arxnet.hu> Hello, On Sat, Jan 25, 2014 at 02:02:15AM -0800, justinpmullins at gmail.com wrote: > My son is learning Python and I know nothing about computers. :) > He's written a simple calculator program that doesn't work. For the life of me, I can't see why. > Any help gratefully received. Here's his code: > def a(): > import sys > print("welcome to the calculation") > print("please type a number") > one = int(sys.stdin.readline()) > print("type d for division,") > print("type m for multiplication,") > print("type s for subtraction,") > print("and type p for plus") > op = (sys.stdin.readline()) > print("%s selected" % op) > print("please enter another number") > two = int(sys.stdin.readline()) > if op == str(d): > out == one / two > print("the answer is %s" % out) > elif op == "m": > out == one * two > print("the answer is %s" % out) > elif op == "s": > out == one - two > print("the answer is %s" % out) > elif op == "p": > out == one + two > print("the answer is %s" % out) > else: > print("huh") > > Where is he going wrong? what's your error message? First, you have to put an interpreter in first line - if you're on Linux/Unix: #!/usr/bin/python or some kind of that. I don't know what's the expected on Windows :(. Second, you defined a funcfion, called "a", and if you want to see how does it work, you must call that (after you define it): def a(): ... ... a() Third, at the first statement (if op == str(d)) you're referencing for an undefined variable (d), I think you would put `if op == "d":', instad of that. Good luck, Ervin -- I ? UTF-8 From justinpmullins at gmail.com Sat Jan 25 05:32:44 2014 From: justinpmullins at gmail.com (justinpmullins at gmail.com) Date: Sat, 25 Jan 2014 02:32:44 -0800 (PST) Subject: Help with my 8-year old son's first program. I'm stuck! In-Reply-To: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> References: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> Message-ID: <5dce8685-9d73-4519-99e4-d79d62fd0bf4@googlegroups.com> PS: At the first statement, we've also tried op == "d": But that doesn't work either. On Saturday, January 25, 2014 10:02:15 AM UTC, justinp... at gmail.com wrote: > My son is learning Python and I know nothing about computers. > > He's written a simple calculator program that doesn't work. For the life of me, I can't see why. > > Any help gratefully received. Here's his code: > > def a(): > > import sys > > print("welcome to the calculation") > > print("please type a number") > > one = int(sys.stdin.readline()) > > print("type d for division,") > > print("type m for multiplication,") > > print("type s for subtraction,") > > print("and type p for plus") > > op = (sys.stdin.readline()) > > print("%s selected" % op) > > print("please enter another number") > > two = int(sys.stdin.readline()) > > if op == str(d): > > out == one / two > > print("the answer is %s" % out) > > elif op == "m": > > out == one * two > > print("the answer is %s" % out) > > elif op == "s": > > out == one - two > > print("the answer is %s" % out) > > elif op == "p": > > out == one + two > > print("the answer is %s" % out) > > else: > > print("huh") > > > > Where is he going wrong? > > Many thanks in advance From __peter__ at web.de Sat Jan 25 05:41:20 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 25 Jan 2014 11:41:20 +0100 Subject: Help with my 8-year old son's first program. I'm stuck! References: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> Message-ID: justinpmullins at gmail.com wrote: > My son is learning Python and I know nothing about computers. > He's written a simple calculator program that doesn't work. Normally you are supposed to explain what you or your son expect and what you get instead. If Python ends with an error you should paste that into your message, e. g.: Traceback (most recent call last): File "calculator.py", line 29, in a() File "calculator.py", line 14, in a if op == str(d): NameError: global name 'd' is not defined Also, we need to know if you are using Python 2 or Python 3. Sometimes even the exact version is important. You can find it out with $ python3 -V Python 3.2.2 > For the life > of me, I can't see why. Any help gratefully received. Here's his code: > def a(): > import sys > print("welcome to the calculation") > print("please type a number") > one = int(sys.stdin.readline()) > print("type d for division,") > print("type m for multiplication,") > print("type s for subtraction,") > print("and type p for plus") > op = (sys.stdin.readline()) > print("%s selected" % op) > print("please enter another number") > two = int(sys.stdin.readline()) > if op == str(d): The name d is defined nowhere in your script. That line should be if op == "d": similar to the `elif`s that follow. > out == one / two You want to assign to out but you are actually comparing out to one / two. Change the line (and similar lines below) to a single =, e. g. out = one / two > print("the answer is %s" % out) > elif op == "m": > out == one * two > print("the answer is %s" % out) > elif op == "s": > out == one - two > print("the answer is %s" % out) > elif op == "p": > out == one + two > print("the answer is %s" % out) > else: > print("huh") Change the above line to print("Unknown op=%r" % op) and add a function invocation a() > Where is he going wrong? > Many thanks in advance When you run the script with my modifications $ python3 calculator.py welcome to the calculation please type a number 10 type d for division, type m for multiplication, type s for subtraction, and type p for plus m m selected please enter another number 20 Unknown op='m\n' you see that what you supposed to be an "m" is actually an "m" followed by a newline. The readline() method reads a line including the final newline. You can remove that by changing the line op = (sys.stdin.readline()) to op = sys.stdin.readline().strip() but a more straightforward approach would be to replace all occurences of sys.stdin.readline() with input() # if you are using Python 3 or raw_input() # if yo are using Python 2. From matej at ceplovi.cz Sat Jan 25 06:23:58 2014 From: matej at ceplovi.cz (Matěj Cepl) Date: Sat, 25 Jan 2014 12:23:58 +0100 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: [This message has also been posted to gmane.comp.python.general.] -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 2014-01-25, 07:18 GMT, Frank Millman wrote: > I have stated that my objective is to express as little as > possible in Python code. Yes, and I believe that it is very wrong. But anyway, if you are so passionate about GUI-via-XML, what?s wrong with Glade (http://www.pygtk.org/pygtk2reference/class-gladexml.html)? You have editors for that XML etc. Mat?j -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iD8DBQFS457O4J/vJdlkhKwRAlA7AJ9nTl4v+FoiNZb3NLaSsIZMd2HO5wCeNYwe EVLDNqlw3YaQtloF1RGWP8Y= =AloI -----END PGP SIGNATURE----- From denismfmcmahon at gmail.com Sat Jan 25 06:31:08 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 25 Jan 2014 11:31:08 +0000 (UTC) Subject: Need Help with Programming Science Project References: <1eeb0e4b-ff9a-4b5e-86ec-773ca98fbf1b@googlegroups.com> Message-ID: On Fri, 24 Jan 2014 20:58:50 -0800, theguy wrote: > I know. I'm kind of ashamed of the code, but it does the job I need it > to up to a certain point OK, well first of all take a step back and look at the problem. You have n exemplars, each from a known author. You analyse each exemplar, and determine some statistics for it. You then take your unknown sample, determine the same statistics for the unknown sample. Finally, you compare each exemplar's stats with the sample's stats to try and find a best match. So, perhaps you want a dictionary of { author: statistics }, and a function to analyse a piece of text, which might call other functions to get eg avg words / sentence, avg letters / sentence, avg word length, and the sd in each, and the short word ratio (words <= 3 chars vs words >= 4 chars) and some other statistics. Given the statistics for each exemplar, you might store these in your dictionary as a tuple. this isn't python, it's a description of an algorithm, it just looks a bit pythonic: # tuple of weightings applied to different stats stat_weightings = ( 1.0, 1.3, 0.85, ...... ) def get_some_stat( t ): # calculate some numerical statistic on a block of text # return it def analyse( f ): text = read_file( f ) return ( get_some_stat( text ), ...... ) exemplars = {} for exemplar_file in exemplar_files: exemplar_data[author] = analyse( exemplar_file ) sample_data = analyse( sample_file ) scores = {} tmp = 0 x = 0 # score for a piece of work is sum of ( diff of stat * weighting ) # for all the stats, lower score = closer match for author in keys( exemplar_data ): for i in len( exemplar_data[ author ] ): tmp = tmp + sqrt( exemplar_data[ author ][ i ] - sample_data[ i ] ) * stat_weightings( i ) scores[ author ] = tmp if tmp > x: x = tmp names = [] for author in keys( scores ): if scores[ author ] < x: x = scores[ author ] names = [ author ] elif scores[ author ] == x: names.append( [ author ] ) print "the best matching author(s) is/are: ", names Then all you have to do is find enough ways to calculate stats, and the magic coefficients to use in the stat_weightings -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Sat Jan 25 06:35:00 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 25 Jan 2014 11:35:00 +0000 (UTC) Subject: Help with my 8-year old son's first program. I'm stuck! References: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> Message-ID: On Sat, 25 Jan 2014 02:02:15 -0800, justinpmullins wrote: > def a(): > import sys print("welcome to the calculation") print("please type a > number") > one = int(sys.stdin.readline()) print("type d for division,") > print("type m for multiplication,") print("type s for subtraction,") > print("and type p for plus") > op = (sys.stdin.readline()) print("%s selected" % op) print ("please > enter another number") > two = int(sys.stdin.readline()) > if op == str(d): > out == one / two print("the answer is %s" % out) > elif op == "m": > out == one * two print("the answer is %s" % out) > elif op == "s": > out == one - two print("the answer is %s" % out) > elif op == "p": > out == one + two print("the answer is %s" % out) > else: > print("huh") a() is a function, but I can see nothing in the code that invokes the function a() Ignore the comment about needing to define the type of file on the first line on linux, it's a red herring. You only need to do that (and possibly chmod the file) on a *nix system if you want to execute it directly as a command, rather than by calling the interpreter on it. I suspect that if you remove the line: "def a():" and un-indent the rest of the text, the program will run just fine. -- Denis McMahon, denismfmcmahon at gmail.com From ned at nedbatchelder.com Sat Jan 25 07:55:10 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 25 Jan 2014 07:55:10 -0500 Subject: should I transfer 'iterators' between functions? In-Reply-To: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> References: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> Message-ID: On 1/25/14 1:37 AM, seaspeak at gmail.com wrote: > take the following as an example, which could work well. > But my concern is, will list 'l' be deconstructed after function return? and then iterator point to nowhere? > > def test(): > l = [1, 2, 3, 4, 5, 6, 7, 8] > return iter(l) > def main(): > for i in test(): > print(i) > > The two things to understand here are names, and values. When you leave the function test, the name l goes away, because it is a locally scoped name. It referred to a value, your list. But values have reference counts, and are not reclaimed until their reference count drops to zero. Your function is returning a value, a listiterator, and that listiterator refers to the list, so the list won't be reclaimed. Names have scopes but no types. Values have types, but no scope. They live as long as they are referred to by something. This is covered in more detail here: http://nedbatchelder.com/text/names.html -- Ned Batchelder, http://nedbatchelder.com From ned at nedbatchelder.com Sat Jan 25 07:56:34 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Sat, 25 Jan 2014 07:56:34 -0500 Subject: should I transfer 'iterators' between functions? In-Reply-To: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> References: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> Message-ID: On 1/25/14 1:37 AM, seaspeak at gmail.com wrote: > take the following as an example, which could work well. > But my concern is, will list 'l' be deconstructed after function return? and then iterator point to nowhere? > > def test(): > l = [1, 2, 3, 4, 5, 6, 7, 8] > return iter(l) > def main(): > for i in test(): > print(i) > > One more thing: there's no need to call iter() explicitly here. Much more common than returning an iterator from a function is to return an iterable. Your code will work exactly the same if you just remove the iter() call: def test(): l = [1, 2, 3, 4, 5, 6, 7, 8] return l def main(): for i in test(): print(i) -- Ned Batchelder, http://nedbatchelder.com From __peter__ at web.de Sat Jan 25 08:32:18 2014 From: __peter__ at web.de (Peter Otten) Date: Sat, 25 Jan 2014 14:32:18 +0100 Subject: should I transfer 'iterators' between functions? References: <6ad4232c-a8d9-4195-9edd-65c0e35923a7@googlegroups.com> Message-ID: Ned Batchelder wrote: > On 1/25/14 1:37 AM, seaspeak at gmail.com wrote: >> take the following as an example, which could work well. >> But my concern is, will list 'l' be deconstructed after function return? >> and then iterator point to nowhere? >> >> def test(): >> l = [1, 2, 3, 4, 5, 6, 7, 8] >> return iter(l) >> def main(): >> for i in test(): >> print(i) >> >> > > One more thing: there's no need to call iter() explicitly here. Much > more common than returning an iterator from a function is to return an > iterable. Your code will work exactly the same if you just remove the > iter() call: > > def test(): > l = [1, 2, 3, 4, 5, 6, 7, 8] > return l > def main(): > for i in test(): > print(i) For that specific client code, yes. In the general case the difference matters. Iteration over an iterable starts at the beginning while iteration over an iterator starts at the current item: >>> def main(): ... items = test() ... print(list(zip(items, items))) ... >>> def test(): return range(6) # an iterable ... >>> main() [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5)] >>> def test(): return iter(range(6)) # an iterator ... >>> main() [(0, 1), (2, 3), (4, 5)] From justinpmullins at gmail.com Sat Jan 25 10:58:40 2014 From: justinpmullins at gmail.com (justinpmullins at gmail.com) Date: Sat, 25 Jan 2014 07:58:40 -0800 (PST) Subject: Help with my 8-year old son's first program. I'm stuck! In-Reply-To: References: <453f851d-815d-4bdd-b591-71cafc95084f@googlegroups.com> Message-ID: Thanks Peter, that did the trick. You've got here a very happy 8-year old and a mighty relieved 46-year old!! On Saturday, January 25, 2014 10:41:20 AM UTC, Peter Otten wrote: > justinpmullins at gmail.com wrote: > > > > > My son is learning Python and I know nothing about computers. > > > He's written a simple calculator program that doesn't work. > > > > Normally you are supposed to explain what you or your son expect and what > > you get instead. If Python ends with an error you should paste that into > > your message, e. g.: > > > > Traceback (most recent call last): > > File "calculator.py", line 29, in > > a() > > File "calculator.py", line 14, in a > > if op == str(d): > > NameError: global name 'd' is not defined > > > > Also, we need to know if you are using Python 2 or Python 3. Sometimes even > > the exact version is important. You can find it out with > > > > $ python3 -V > > Python 3.2.2 > > > > > For the life > > > of me, I can't see why. Any help gratefully received. Here's his code: > > > > > def a(): > > > import sys > > > print("welcome to the calculation") > > > print("please type a number") > > > one = int(sys.stdin.readline()) > > > print("type d for division,") > > > print("type m for multiplication,") > > > print("type s for subtraction,") > > > print("and type p for plus") > > > op = (sys.stdin.readline()) > > > print("%s selected" % op) > > > print("please enter another number") > > > two = int(sys.stdin.readline()) > > > if op == str(d): > > > > The name d is defined nowhere in your script. That line should be > > > > if op == "d": > > > > similar to the `elif`s that follow. > > > > > out == one / two > > > > You want to assign to out but you are actually comparing out to one / two. > > Change the line (and similar lines below) to a single =, e. g. > > out = one / two > > > > > print("the answer is %s" % out) > > > elif op == "m": > > > out == one * two > > > print("the answer is %s" % out) > > > elif op == "s": > > > out == one - two > > > print("the answer is %s" % out) > > > elif op == "p": > > > out == one + two > > > print("the answer is %s" % out) > > > else: > > > print("huh") > > > > Change the above line to > > > > print("Unknown op=%r" % op) > > > > and add a function invocation > > > > a() > > > > > Where is he going wrong? > > > Many thanks in advance > > > > When you run the script with my modifications > > > > $ python3 calculator.py > > welcome to the calculation > > please type a number > > 10 > > type d for division, > > type m for multiplication, > > type s for subtraction, > > and type p for plus > > m > > m > > selected > > please enter another number > > 20 > > Unknown op='m\n' > > > > you see that what you supposed to be an "m" is actually an "m" followed by a > > newline. The readline() method reads a line including the final newline. > > You can remove that by changing the line > > > > op = (sys.stdin.readline()) > > > > to > > > > op = sys.stdin.readline().strip() > > > > but a more straightforward approach would be to replace all occurences of > > > > sys.stdin.readline() > > > > with > > > > input() # if you are using Python 3 > > > > or > > > > raw_input() # if yo are using Python 2. From rustompmody at gmail.com Sat Jan 25 11:15:08 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Jan 2014 08:15:08 -0800 (PST) Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: <2ebec4b9-66dd-4ddc-94a5-1b431e7b0edf@googlegroups.com> On Saturday, January 25, 2014 8:12:20 PM UTC+5:30, Dennis Lee Bieber wrote: > > Heck, at the very least turn all those xxxx_99 variables into single > lists.... The posted code looks like something from 1968 K&K BASIC. Yes thats correct. My suggestion of data-files is a second step. A first step is just converting to using internal (python) data structures. [And not 1968 BASIC scalars!] From ppearson at nowhere.invalid Sat Jan 25 12:56:20 2014 From: ppearson at nowhere.invalid (Peter Pearson) Date: 25 Jan 2014 17:56:20 GMT Subject: Trying to understand this moji-bake References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, 25 Jan 2014 17:08:56 +1100, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 3:37 PM, Steven D'Aprano > wrote: >> But using Python 2.7, I get a really bad case of moji-bake: >> >> [steve at ando ~]$ python2.7 -c "print u'??????'" >> ??????????? > > What's 2.7's default source code encoding? I thought it was ascii, but > maybe it's assuming (in the absence of a magic cookie) that it's > Latin-1. > > ChrisA I seem to be getting the same behavior as Steven: $ python2.7 -c "print u'??????'" ???????????? $ python2.7 -c "import sys; print(sys.stdout.encoding)" UTF-8 $ locale LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE=C LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= $ python2.7 -c "import sys; print(sys.stdin.encoding)" UTF-8 Also, my GNOME Terminal 3.4.1.1 character encoding is "Unicode (UTF-8)". HTH -- To email me, substitute nowhere->spamcop, invalid->net. From edzeame at gmail.com Sat Jan 25 14:00:41 2014 From: edzeame at gmail.com (Max Cuban) Date: Sat, 25 Jan 2014 11:00:41 -0800 Subject: Pls help me...I want to save data to my database but I am unable to Message-ID: This is my first programming pet project. I have the following script that extracts links from specific sites and display them on the web(via django). The script work fine but I'm unable to save any stuff in my database. Hence if I run the code, I get the output I want but then it always extracts only new content. I will rather want to have the content scrapped earlier saved to the database so that on subsequent run, it only scrap and append ONLY new links to the list. [ ] Any help will be appreciated. [] # Create your views here. from django.template.loader import get_template from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.shortcuts import render_to_response from django.template import Context from bs4 import BeautifulSoup import urllib2, sys import urlparse import re from datetime import date, datetime from listing.models import jobLinks def businessghana(): site = "http://www.businessghana.com/portal/jobs" hdr = {'User-Agent' : 'Mozilla/5.0'} req = urllib2.Request(site, headers=hdr) jobpass = urllib2.urlopen(req) soup = BeautifulSoup(jobpass) for tag in soup.find_all('a', href = True): tag['href'] = urlparse.urljoin(' http://www.businessghana.com/portal/', tag['href']) return map(str, soup.find_all('a', href = re.compile('.getJobInfo'))) def tonaton(): site = "http://tonaton.com/en/job-vacancies-in-ghana" hdr = {'User-Agent' : 'Mozilla/5.0'} req = urllib2.Request(site, headers=hdr) jobpass = urllib2.urlopen(req) soup = BeautifulSoup(jobpass) result = [] # next two lines make all the links in the soup absolute for tag in soup.find_all('a', href=True): tag['href'] = urlparse.urljoin('http://www.tonaton.com', tag['href']) # assign all 'h2' tags to 'jobs'. The 'h2'tag contains the required links jobs = soup.find_all('h2') # Loop through the 'h2' tags and extract all the links for h2 in soup.find_all('h2'): n = h2.next_element if n.name == 'a': result.append(str(n)) return result def jobscomgh(): site = "http://jobs.com.gh" hdr = {'User-Agent' : 'Mozilla/5.0'} req = urllib2.Request(site, headers=hdr) jobpass = urllib2.urlopen(req) soup = BeautifulSoup(jobpass) return map(str, soup.find_all('a', href = re.compile('.display-job'))) businessghana_links = businessghana() tonaton_links = tonaton() jobscomgh_links = jobscomgh() def all_links(): return (businessghana_links + tonaton_links + jobscomgh_links) def save_new_links(all_links): current_links = jobLinks.objects.all() for i in all_links: if i not in current_links: jobLinks.objects.create(url=i) def this_week_links(all_links): return jobLinks.objects.filter(date__gte = datetime.timedelta(days=-7)) save_new_links(all_links) this_week_links(all_links) def display_links(request): name = all_links() paginator = Paginator(name, 25) page = request.GET.get('page') try: name = paginator.page(page) except PageNotAnInteger: name = paginator.page(1) except EmptyPage: name = paginator.page(paginator.num_pages) return render_to_response('jobs.html', {'name' : name}) -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Sat Jan 25 14:13:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Jan 2014 06:13:49 +1100 Subject: Trying to understand this moji-bake In-Reply-To: References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 26, 2014 at 4:56 AM, Peter Pearson wrote: > $ python2.7 -c "import sys; print(sys.stdin.encoding)" > UTF-8 This isn't from stdin, though, it's about the interpretation of the bytes of source code without a magic cookie. According to PEP 263 [1], the default encoding should have become "ascii" as of Python 2.5. That's what puzzles me. ChrisA [1] http://www.python.org/dev/peps/pep-0263/ From rosuav at gmail.com Sat Jan 25 14:22:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Jan 2014 06:22:44 +1100 Subject: Pls help me...I want to save data to my database but I am unable to In-Reply-To: References: Message-ID: On Sun, Jan 26, 2014 at 6:00 AM, Max Cuban wrote: > This is my first programming pet project. I have the following script that > extracts links from specific sites and display them on the web(via django). > The script work fine but I'm unable to save any stuff in my database. > > Hence if I run the code, I get the output I want but then it always extracts > only new content. I will rather want to have the content scrapped earlier > saved to the database so that on subsequent run, it only scrap and append > ONLY new links to the list. At what point are you saving anything to the database? I'm not seeing it. This may be a consequence of there being simply too much code for the post - when you have a problem, try to post the smallest amount of code necessary to demonstrate that problem. If your problem is saving stuff to the database, create a project that simulates generating links (maybe just hard-codes a dozen of them), and tries to save them. Often, the exercise of making the small version actually shows you where the problem is, right there; and if it doesn't, it's much easier for us to see and help you. In this case, after reading your opening paragraph, the very first thing I did was to scan your code for a "commit" operation - but I couldn't find one, and I can't find any database work. BTW, the word you want here is "scrape" (other tenses "scraping" and "scraped"). Scrapping ("scrap", "scrapped" - pronounced with a short 'a' sound like "flapping") is destruction and disposal - "the wreckers are scrapping hundreds of smashed cars". Scraping (pronounced with a long 'a' sound like "trading" [1]) is running a tool over something to clean something else off - "every winter, car owners spend innumerable hours scraping ice off their windscreens" - and this is the word that's been picked up for "screen scraping" and related terms. Hope that helps! ChrisA [1] I could go into detail about single and double consonants if anyone's curious, but I don't think it'd help) From oscar.j.benjamin at gmail.com Sat Jan 25 16:15:12 2014 From: oscar.j.benjamin at gmail.com (Oscar Benjamin) Date: Sat, 25 Jan 2014 21:15:12 +0000 Subject: Trying to understand this moji-bake In-Reply-To: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 25 January 2014 04:37, Steven D'Aprano wrote: > > But using Python 2.7, I get a really bad case of moji-bake: > > [steve at ando ~]$ python2.7 -c "print u'??????'" > ??????????? > > However, interactively it works fine: > > [steve at ando ~]$ python2.7 -E > Python 2.7.2 (default, May 18 2012, 18:25:10) > [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> print u'??????' > ?????? > > This occurs on at least two different machines, one using Centos and the > other Debian. Same for me. It's to do with using a u literal: $ python2.7 -c "print('??????')" ?????? $ python2.7 -c "print(u'??????')" ???????????? $ python2.7 -c "print(repr('??????'))" '\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6' $ python2.7 -c "print(repr(u'??????'))" u'\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6' $ python2.7 Python 2.7.5+ (default, Sep 19 2013, 13:49:51) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> b='\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6' >>> print(b) ?????? >>> s=u'\xc3\xb1\xc3\xb8\xce\xbb\xcf\x80\xd0\xb9\xd0\xb6' >>> print(s) ???????????? >>> print(s.encode('latin-1')) ?????? >>> import sys >>> sys.getdefaultencoding() 'ascii' It works in the interactive prompt: >>> s = '??????' >>> print(s) ?????? >>> s = u'??????' >>> print(s) ?????? But the interactive prompt has an associated encoding: >>> import sys >>> sys.stdout.encoding 'UTF-8' If I put it into a utf-8 file with no encoding declared I get a SyntaxError: $ cat tmp.py s = u'??????' print(s) oscar at tonis-laptop:~$ python2.7 tmp.py File "tmp.py", line 1 SyntaxError: Non-ASCII character '\xc3' in file tmp.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details If I add the encoding declaration it works: oscar at tonis-laptop:~$ vim tmp.py oscar at tonis-laptop:~$ cat tmp.py # -*- coding: utf-8 -*- s = u'??????' print(s) oscar at tonis-laptop:~$ python2.7 tmp.py ?????? oscar at tonis-laptop:~$ So I'd say that your original example should be a SyntaxError with Python 2.7 but instead it implicitly uses latin-1. Oscar From edzeame at gmail.com Sat Jan 25 16:22:14 2014 From: edzeame at gmail.com (Max Cuban) Date: Sat, 25 Jan 2014 13:22:14 -0800 Subject: Pls help me...I want to save scraped data automatically to my database(cleaner version) Message-ID: I have asked this question earlier but this should make more sense than the earlier version and I don't want anyone who could potentially helped to be put off by the initial mess even if I updated it with my cleaner version as a reply I want to save the links scraped to be save in my database so that on subsequent run, it only scrapes and append only new links to the list. This is my code below but at the end of the day my database is empty. What changes can I make to overcome this? Thanks in advance from django.template.loader import get_template from django.shortcuts import render_to_response from bs4 import BeautifulSoup import urllib2, sys import urlparse import re from listing.models import jobLinks #this function extract the links def businessghana(): site = "http://www.businessghana.com/portal/jobs" hdr = {'User-Agent' : 'Mozilla/5.0'} req = urllib2.Request(site, headers=hdr) jobpass = urllib2.urlopen(req) soup = BeautifulSoup(jobpass) for tag in soup.find_all('a', href = True): tag['href'] = urlparse.urljoin(' http://www.businessghana.com/portal/', tag['href']) return map(str, soup.find_all('a', href = re.compile('.getJobInfo'))) # result from businssghana() saved to a variable to make them iterable as a list all_links = businessghana() #this function should be saving the links to the database unless the link already exist def save_new_links(all_links): current_links = jobLinks.objects.all() for i in all_links: if i not in current_links: jobLinks.objects.create(url=i) # I called the above function here hoping that it will save to database save_new_links(all_links) # return my httpResponse with this function def display_links(request): name = all_links() return render_to_response('jobs.html', {'name' : name}) My django models.py looks like this: from django.db import models class jobLinks(models.Model): links = models.URLField() pub_date = models.DateTimeField('date retrieved') def __unicode__(self): return self.links -------------- next part -------------- An HTML attachment was scrubbed... URL: From lgabiot at hotmail.com Sat Jan 25 20:59:14 2014 From: lgabiot at hotmail.com (lgabiot) Date: Sun, 26 Jan 2014 02:59:14 +0100 Subject: Can't get sqlite3.Row working: keyword lookup doesn't work Message-ID: <52e46bf3$0$2378$426a34cc@news.free.fr> Hello, using Python 2.7.6 I try to access a sqlite database using keyword lookup instead of position (much more easy to maintain code), but it always fail, with the error: Index must be int or string I have created the database, populated it, and here is the code that tries to retrieve the information: with sqlite3.connect(mydbPath) as db: # open the database db.row_factory = sqlite3.Row cursor = db.cursor() cursor.execute("SELECT * FROM files") for row in cursor.fetchall(): print(row.keys()) print(row["filename"]) result is: ['filename', 'filepath', 'filetag', 'PROJECT', 'SCENE', 'TAKE', 'TAPE', 'CIRCLED', 'FILE_UID', 'UBITS', 'TOTAL_FILES', 'FAMILY_UID', 'track_1', 'track_2', 'track_3', 'track_4', 'track_5', 'track_6', 'track_7', 'track_8', 'track_9', 'track_10', 'track_11', 'track_12', 'NOTE', 'duration', 'BWF_ORIGINATION_DATE', 'TIMECODE_FLAG', 'TIMECODE_RATE', 'FILE_SAMPLE_RATE', 'AUDIO_BIT_DEPTH', 'DIGITIZER_SAMPLE_RATE', 'TIMESTAMP_SAMPLE_RATE', 'TIMESTAMP_SINCE_MIDNIGHT', 'is_Short', 'is_MS', 'is_renamed_MS', 'WF_created', 'max_level', 'is_silent', 'is_silent_moved', 'silent_path', 'is_WS', 'is_WS_copied', 'CSV_made', 'is_cantar', 'is_sound_devices', 'exist'] error => Index must be int or string What is wrong? thanks a lot. From steve+comp.lang.python at pearwood.info Sat Jan 25 21:04:40 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jan 2014 02:04:40 GMT Subject: Trying to understand this moji-bake References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52e46d38$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Jan 2014 17:08:56 +1100, Chris Angelico wrote: > On Sat, Jan 25, 2014 at 3:37 PM, Steven D'Aprano > wrote: >> But using Python 2.7, I get a really bad case of moji-bake: >> >> [steve at ando ~]$ python2.7 -c "print u'??????'" ??????????? > > What's 2.7's default source code encoding? I thought it was ascii, but > maybe it's assuming (in the absence of a magic cookie) that it's > Latin-1. I think that's it! Python 2.7 ought to raise a SyntaxError, since there's no source encoding declared, while Python 3.3 defaults to UTF-8 which is the same as my terminal. If there's a bug, it is that Python 2.7 doesn't raise SyntaxError when called with -c and there are non-ASCII literals in the source. Instead, it seems to be defaulting to Latin-1, hence the moji- bake. Thanks to everyone who responded! -- Steven From rosuav at gmail.com Sat Jan 25 21:08:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Jan 2014 13:08:30 +1100 Subject: Trying to understand this moji-bake In-Reply-To: <52e46d38$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> <52e46d38$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 26, 2014 at 1:04 PM, Steven D'Aprano wrote: > If there's a bug, it is that Python 2.7 doesn't > raise SyntaxError when called with -c and there are non-ASCII literals in > the source. Instead, it seems to be defaulting to Latin-1, hence the moji- > bake. That might well be a bug! I was reading the PEP, which was pretty clear about it needing to be ASCII by default. It's not so clear about -c but I would expect it to do the same. ChrisA From steve+comp.lang.python at pearwood.info Sat Jan 25 21:33:32 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jan 2014 02:33:32 GMT Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> Message-ID: <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sat, 25 Jan 2014 09:18:44 +0200, Frank Millman wrote: > I have realised that we unlikely to come to an agreement on this in the > near future, as our philosophies are completely different. > > You [Chris Angelo] have stated that your objective is to express as > much as possible in Python code. > > I have stated that my objective is to express as little as possible in > Python code. Interesting perspective. > We would have to resolve that difference of opinion first, before > discussing our respective approaches in detail, and that is way beyond > the scope of this thread. > > As a brief example of my approach, here is how I would write your simple > 'About' box. > > Here is your version - > > mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0) > ->add(GTK2.Label("About Gypsum: big long multi-line string")) > ->add(GTK2.HbuttonBox() > ->add(GTK2.Button("Close")) > ->add(GTK2.Button("Foobar")) > ) > ); That's not Python code, but it's reasonably concise and readable. (By the way, what language is it?) The meaning is fairly obvious, and it's all pretty simple. I'd like to see a more human readable GUI designer language: # hypothetical code in a DSL for creating GUI elements create new window mainwindow with mainwindow add vbox at 0,0 add label "About Gypsum: big long multi-line string" add hbuttonbox add button "Close" add button "Foobar" but what you've got there is okay. Seven lines of readable code. > Here is my version - > >
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Thirty. Seven. Lines. Of. XML. You've got to be kidding me. How can you *possibly* prefer that? First rule of XML: it is not human-writable. It's barely human-readable. It's a *document* interchange language which happens to use mostly human- readable elements, which is not the same thing at all. It's designed to be machine written. Using XML for *data* is abusive to both the XML design goals and to the poor schmuck who has to read your config file. Using XML *as a programming language* is not just abuse, it's getting into grievous bodily harm territory. Here's a simple programming expression, familiar to most people, common to hundreds of programming languages: 3+4*5 Here it is written as XML: 345 Source: http://www.ibm.com/developerworks/xml/library/x-sbxml/index.html More here: http://www.codinghorror.com/blog/2008/05/xml-the-angle-bracket-tax.html http://myarch.com/why-xml-is-bad-for-humans/ If you expect a human being to routinely *read*, let alone *write*, XML in preference to some real programming language, that is a horrible, horrible thing. Using XML as an internal, machine-generated, format not intended for humans is not too bad. Anything else is abusive. -- Steven From breamoreboy at yahoo.co.uk Sat Jan 25 21:45:59 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Jan 2014 02:45:59 +0000 Subject: Python declarative In-Reply-To: <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 26/01/2014 02:33, Steven D'Aprano wrote: > Here's a simple programming expression, familiar to most people, common > to hundreds of programming languages: > > 3+4*5 > > Here it is written as XML: > > 345 > > Source: > http://www.ibm.com/developerworks/xml/library/x-sbxml/index.html > > More here: > > http://www.codinghorror.com/blog/2008/05/xml-the-angle-bracket-tax.html > http://myarch.com/why-xml-is-bad-for-humans/ > > If you expect a human being to routinely *read*, let alone *write*, XML > in preference to some real programming language, that is a horrible, > horrible thing. Using XML as an internal, machine-generated, format not > intended for humans is not too bad. Anything else is abusive. > If I worked as a consultant I'd much prefer the XML version as I'd be able to charge much more on the grounds that I'd done much more, hoping that the people paying didn't bother with design reviews or the like :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From tjreedy at udel.edu Sat Jan 25 22:31:58 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sat, 25 Jan 2014 22:31:58 -0500 Subject: Trying to understand this moji-bake In-Reply-To: References: <52e33f8d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/25/2014 2:13 PM, Chris Angelico wrote: > On Sun, Jan 26, 2014 at 4:56 AM, Peter Pearson wrote: >> $ python2.7 -c "import sys; print(sys.stdin.encoding)" >> UTF-8 > > This isn't from stdin, though, it's about the interpretation of the > bytes of source code without a magic cookie. > > According to PEP 263 [1], the default encoding should have become > "ascii" as of Python 2.5. That's what puzzles me. I believe it is actually (but unofficially) latin-1 so that latin-1 accented chars can be used in identifiers even though only ascii is officially supported. -- Terry Jan Reedy From rosuav at gmail.com Sat Jan 25 22:38:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Jan 2014 14:38:42 +1100 Subject: Python declarative In-Reply-To: <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 26, 2014 at 1:33 PM, Steven D'Aprano wrote: >> Here is your version - >> >> mainwindow = GTK2.Window(0)->add(GTK2.Vbox(0,0) >> ->add(GTK2.Label("About Gypsum: big long multi-line string")) >> ->add(GTK2.HbuttonBox() >> ->add(GTK2.Button("Close")) >> ->add(GTK2.Button("Foobar")) >> ) >> ); > > That's not Python code, but it's reasonably concise and readable. (By the > way, what language is it?) The meaning is fairly obvious, and it's all > pretty simple. It's Pike, and the above example is pure Pike without any of my own helpers. If you fire up Pike's interactive mode and type two commands "GTK2.setup_gtk();" and "start backend" first, you can paste that in and it'll create you a window. (It won't DO anything, but it'll sit there looking like a window.) It tends to get a little verbose after a while (hence the need for helper functions to combat the complexity), but the advantage of this system is that it took me absolutely zero code. I didn't have to write any framework. > I'd like to see a more human readable GUI designer > language: > > # hypothetical code in a DSL for creating GUI elements > create new window mainwindow > with mainwindow > add vbox at 0,0 > add label "About Gypsum: big long multi-line string" > add hbuttonbox > add button "Close" > add button "Foobar" > > but what you've got there is okay. Seven lines of readable code. Sure. That would make reasonable sense, as a DSL. And, in fact, if I were making a Python GUI, I would want to add something that would let me do it that way - at least compared to PyGTK, which insists on every box getting a temporary name, since the add() methods don't chain. But that's a cost, that has to be written. I'm happy with the no-code version to start with. Now, with something as complicated as the character sheet, well, that's different. I think if I did all the charsheet code as pure no-helpers Pike, it would be a dozen pages of code and indented about fifty tabs. At that point, it's worth putting some effort into taming the beast :) Here's an actual example from the charsheet: GTK2.Hbox(0,10)->add(GTK2Table(({ ({"Name",ef("name",12),0,0,"Char level",num("level",8)}), ({"Race",ef("race",8),"HD",ef("race_hd"),"Experience",num("xp",8)}), ({"Class",ef("class1",12),"Level",num("level1"),"To next lvl",calc("`+(@enumerate(level,1000,1000))-xp")}), ({"Class",ef("class2",12),"Level",num("level2"),"Size",select("size",sizes)}), ({"Class",ef("class3",12),"Level",num("level3"), "Grapple",calc(grapple_formula,"grapple","string") }), ({"Class",ef("class4",12),"Level",num("level4")}), }))->set_col_spacings(4)) ->add(GTK2.Frame("Wealth")->add(GTK2Table(({ ({"Platinum",num("wealth_plat",7)}), ({"Gold",num("wealth_gold",7)}), ({"Silver",num("wealth_silver",7)}), ({"Copper",num("wealth_copper",7)}), ({"Total gp",calc("(wealth_plat*1000+wealth_gold*100+wealth_silver*10+wealth_copper)/100")}), })))) It's a mix of basic Pike and GTK functions (GTK2.Frame is one of the standard widgets) and helpers (num, ef, and calc) that return widgets, maybe with child widgets. GTK2Table takes an array and plops everything into it at appropriate locations. I use that function *everywhere* in the charsheet - mainly because I was porting from a spreadsheet, but D&D character sheets are inherently tabular. (Note that I've reformatted this a bit from the original, and it might be disrupted a bit by the email/newsgroup format. In the original, this is all a few tabs in, but as long as your editor isn't wrapping the lines, it's pretty readable.) At what point is it a DSL rather than just "Pike code with helper functions"? This is particularly true with Python code; it wouldn't be hard to make a DSL that's derived from Python. (By the way, your translation "add a vbox at 0,0" isn't accurate; the 0,0 are parameters to the Vbox itself, being the homogenous flag (if it's nonzero, it forces its children to the same height and/or width, but 0 means each child gets what it asks for) and the padding (0 puts children hard up against one another, nonzero puts that much room between them). A window has only a single child, which occupies its entire space; that's why it's conventional to add a layout manager as the one child, and then add multiple children to that. Means the window needn't care about the minutiae of child positioning. But if you call that "add a vbox 0,0", that'd work fine; and if you're making a DSL, I'd make 0,0 the defaults and say "add a vbox padding 10" if I want to override.) The only problem with your DSL as I see it is that it doesn't mark the beginning and end of child widget layouts. This needs to be a tree. But Python already has a notation for that: indent! So if the two buttons are indented, they'll be inside the hbuttonbox (which is a type of horizontal box), which is within the vertical box (again, indent everything that's inside it), which is within the main window. Of course, then you need to work out how to attach code to buttons, but let's leave that aside... mainly because it's a nightmare to do in XML, but pretty easy (if a little tedious in large quantities) in code. :) ChrisA From rosuav at gmail.com Sat Jan 25 23:06:15 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Jan 2014 15:06:15 +1100 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 26, 2014 at 1:45 PM, Mark Lawrence wrote: > If I worked as a consultant I'd much prefer the XML version as I'd be able > to charge much more on the grounds that I'd done much more, hoping that the > people paying didn't bother with design reviews or the like :) And that's very true. If someone wants something infinitely customizeable, the best solution might be an empty file with a shebang at the top - but that's hardly something you can charge oodles for. This is where soft-coding comes from. http://thedailywtf.com/Articles/Soft_Coding.aspx The business logic examples given there are best served by hard code. Suppose you need to calculate this-value plus that-value times other-value; is there any difference between writing that in Python (ugh, that's hard code!) and putting the formula in a config file, where it'll get parsed and evaluated (oh, that's a config file, that's fine)? As you'll see in my other post, there's a formula evaluator routine there; it takes a string of code and compiles it: (wealth_plat*1000+wealth_gold*100+wealth_silver*10+wealth_copper)/100 It's straight code, and it's embedded. If ever the rules change, I can edit the code. For instance, here's the D&D Fourth Edition version of that: (wealth_plat*10000+wealth_gold*100+wealth_silver*10+wealth_copper)/100 Should the value of a platinum coin be moved out into a config file? Maybe. MAYBE. Should the value of a silver piece be? Definitely not! There's no use-case for silver pieces being worth anything other than ten copper. If and when there is one, the code can simply be edited. There is no value in soft-coding this formula. Code isn't something to be afraid of. It's just text files like any other. After all, Python code is a config file for /usr/bin/python, so if you want to change what Python does, just edit its config file! ChrisA From rustompmody at gmail.com Sat Jan 25 23:47:27 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sat, 25 Jan 2014 20:47:27 -0800 (PST) Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sunday, January 26, 2014 9:36:15 AM UTC+5:30, Chris Angelico wrote: > Code isn't something to be afraid of. It's just text files like any > other. After all, Python code is a config file for /usr/bin/python, so > if you want to change what Python does, just edit its config file! Windows stores configuration in the registry -- by fiat Linux (posix) stores configuration in /etc + ~/.files -- by convention Which do you think is preferable? From rosuav at gmail.com Sun Jan 26 00:23:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sun, 26 Jan 2014 16:23:32 +1100 Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sun, Jan 26, 2014 at 3:47 PM, Rustom Mody wrote: > On Sunday, January 26, 2014 9:36:15 AM UTC+5:30, Chris Angelico wrote: >> Code isn't something to be afraid of. It's just text files like any >> other. After all, Python code is a config file for /usr/bin/python, so >> if you want to change what Python does, just edit its config file! > > Windows stores configuration in the registry -- by fiat > Linux (posix) stores configuration in /etc + ~/.files -- by convention > > Which do you think is preferable? Not exclusively, in either case. Many many things are config files of various sorts. The terms of the GPL specifically state that a GPL'd language does not enforce that code written in it is GPL'd, because it's just (to the GPL code) data files. Plenty of Windows programs store config files outside the registry. ChrisA From frank at chagford.com Sun Jan 26 01:03:18 2014 From: frank at chagford.com (Frank Millman) Date: Sun, 26 Jan 2014 08:03:18 +0200 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: "Steven D'Aprano" wrote in message news:52e473fc$0$29999$c3e8da3$5496439d at news.astraweb.com... > On Sat, 25 Jan 2014 09:18:44 +0200, Frank Millman wrote: > >> I have realised that we unlikely to come to an agreement on this in the >> near future, as our philosophies are completely different. >> >> You [Chris Angelo] have stated that your objective is to express as >> much as possible in Python code. >> >> I have stated that my objective is to express as little as possible in >> Python code. > > Interesting perspective. > [...] I did not really want to continue this, but I have to respond to that. There is a sub-context within which I made my statement. Here is a quote from one of my earlier posts - > Each form definition is stored as gzip'd XML in a database, and linked to > the > menu system. There is just one python program that responds to the > selection > of a menu option, retrieves the form from the database, unpacks it and > runs it. I do not expect anyone to read or edit the XML - it is just a storage format. I am sure it could be done in JSON or YAML as well. One objective is to make it easy for non-programmers to modify forms and create new ones. I showed a screenshot earlier that illustrated a 'button' definition. Frank From __peter__ at web.de Sun Jan 26 03:05:25 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 26 Jan 2014 09:05:25 +0100 Subject: Can't get sqlite3.Row working: keyword lookup doesn't work References: <52e46bf3$0$2378$426a34cc@news.free.fr> Message-ID: lgabiot wrote: > using Python 2.7.6 > > I try to access a sqlite database using keyword lookup instead of > position (much more easy to maintain code), but it always fail, with the > error: > Index must be int or string > > I have created the database, populated it, and here is the code that > tries to retrieve the information: > > with sqlite3.connect(mydbPath) as db: # open the database > db.row_factory = sqlite3.Row > cursor = db.cursor() > cursor.execute("SELECT * FROM files") > > for row in cursor.fetchall(): > print(row.keys()) > print(row["filename"]) > > > result is: > > ['filename', 'filepath', 'filetag', 'PROJECT', 'SCENE', 'TAKE', 'TAPE', [...] > 'is_cantar', 'is_sound_devices', 'exist'] > > error => Index must be int or string Please remember to cut and past the traceback next time. > What is wrong? My crystal ball says that you have a from __future__ import unicode_literals statement at the beginning of the module. If I'm right try row[b"filename"] From rustompmody at gmail.com Sun Jan 26 03:05:02 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 26 Jan 2014 00:05:02 -0800 (PST) Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <3683cd10-592b-4a3d-ba77-b963a1aa2282@googlegroups.com> On Sunday, January 26, 2014 10:53:32 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jan 26, 2014 at 3:47 PM, Rustom Mody wrote: > > On Sunday, January 26, 2014 9:36:15 AM UTC+5:30, Chris Angelico wrote: > >> Code isn't something to be afraid of. It's just text files like any > >> other. After all, Python code is a config file for /usr/bin/python, so > >> if you want to change what Python does, just edit its config file! > > Windows stores configuration in the registry -- by fiat > > Linux (posix) stores configuration in /etc + ~/.files -- by convention > > Which do you think is preferable? > Not exclusively, in either case. Many many things are config files of > various sorts. The terms of the GPL specifically state that a GPL'd > language does not enforce that code written in it is GPL'd, because > it's just (to the GPL code) data files. Ok so you are being careful and hedging your bets!! [And Ive no idea what the gpl has to do with this] If you see the 'Principle of Least Power here: http://www.w3.org/DesignIssues/Principles.html there is a spectrum of power from narrow data format to universal data format to Turing complete programming language. And a strong case is made for minimizing the 'power' in any application. By decreeing things about the registry, windows solves many problems that create unnecessary headaches for developers, packagers, uses with the laissez-faire approach of 'put whatever you like in /etc.' This follows from the principle: "Anything goes" applied to /etc means messes go in. Its harder to push messes into a dictat-ed registry Steven's link http://www.codinghorror.com/blog/2008/05/xml-the-angle-bracket-tax.html linked to http://nothing-more.blogspot.in/2004/10/where-xml-goes-astray.html explains what the real problem is: Xml, originally a document format, is nowadays used as a data-format. This conduces to humongous messing, first for the xml-library writers, and thence to the users of those libraries because library messes inevitably leak past abstraction barriers to cause user-programmer headaches. tl;dr Frank's principle: "Express little as possible in " is correct. "And therefore XML is the solution" is bad logic [Unless == "java" !] From frank at chagford.com Sun Jan 26 04:12:57 2014 From: frank at chagford.com (Frank Millman) Date: Sun, 26 Jan 2014 11:12:57 +0200 Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> <3683cd10-592b-4a3d-ba77-b963a1aa2282@googlegroups.com> Message-ID: "Rustom Mody" wrote in message news:3683cd10-592b-4a3d-ba77-b963a1aa2282 at googlegroups.com... > > Xml, originally a document format, is nowadays used as a data-format. > This conduces to humongous messing, first for the xml-library writers, and > thence to the users of those libraries because library messes inevitably > leak past abstraction barriers to cause user-programmer headaches. > > tl;dr > Frank's principle: "Express little as possible in " > is correct. > "And therefore XML is the solution" > is bad logic > [Unless == "java" !] If that is the case, what is 'good logic'? JSON or YAML? It does not make much difference which format I use. However, I will say that I found it a useful discipline to create an xml schema to describe my form definition, for two reasons. Firstly, I was hand-crafting my form definitions initially, and as I added features it became unwieldy. Forcing myself to create the schema highlighted a lot of anomalies and I ended up with a much cleaner structure as a result. Secondly, it has picked up a lot of errors in the resulting documents which would otherwise have generated hard-to-find runtime exceptions. Frank From ngangsia at gmail.com Sun Jan 26 05:46:54 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 26 Jan 2014 02:46:54 -0800 (PST) Subject: Python with 3d cartoon Message-ID: Is it possible to write cartoon with 3D images using python? If yes , please locate me some resources. thank From breamoreboy at yahoo.co.uk Sun Jan 26 05:55:34 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Jan 2014 10:55:34 +0000 Subject: Python with 3d cartoon In-Reply-To: References: Message-ID: On 26/01/2014 10:46, ngangsia akumbo wrote: > Is it possible to write cartoon with 3D images using python? > > If yes , please locate me some resources. thank > What have you done to locate resources for yourself? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ngangsia at gmail.com Sun Jan 26 05:58:23 2014 From: ngangsia at gmail.com (ngangsia akumbo) Date: Sun, 26 Jan 2014 02:58:23 -0800 (PST) Subject: Python with 3d cartoon In-Reply-To: References: Message-ID: <54b848b2-f843-49c1-a22b-eda55e12b299@googlegroups.com> On Sunday, January 26, 2014 11:55:34 AM UTC+1, Mark Lawrence wrote: > On 26/01/2014 10:46, ngangsia akumbo wrote: > > > > What have you done to locate resources for yourself? I have searched but not found something very clear. That is why i asked. From steve+comp.lang.python at pearwood.info Sun Jan 26 07:05:29 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jan 2014 12:05:29 GMT Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52e4fa09$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jan 2014 15:06:15 +1100, Chris Angelico wrote: > Code isn't something to be afraid of. Not according to the Laundry series by Charles Stross. The protagonist of the series was "recruited" to the Laundry after the computer program he was working on almost summoned Nyarlathotep the Crawling Chaos Elder God to Wolverhampton. -- Steven From steve+comp.lang.python at pearwood.info Sun Jan 26 07:21:18 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jan 2014 12:21:18 GMT Subject: Python declarative References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52e4fdbd$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jan 2014 08:03:18 +0200, Frank Millman wrote: > I do not expect anyone to read or edit the XML - it is just a storage > format. I am sure it could be done in JSON or YAML as well. But that's not what you originally said. You stated: "here is how I would write your simple 'About' box" and compared your XML to actual code written by Chris. As I said in my previous post, if the XML is intended as a purely internal document, written by and read by your application, it's not so bad. (But then XML is intended for document *exchange*, i.e. from one application to another. If your XML is just used *internally*, with no interchange needed, why not use a more efficient internal format? XML's strength is that it is a well-known standard that allows application A to interchange documents with application B. But it's weaknesses include, it is neither efficient like a custom-designed binary format, not human-editable. It seems to me that if I were in your position, I would have the GUI designer generate source code in some language directly, rather than XML. Ah, wait! An idea strikes... if your GUI designer generates XML, you could then have a plug-in system to convert the XML to source code in whatever languages the plug-in supports. So that's a possible good use for XML as an intermediate language. > One objective is to make it easy for non-programmers to modify forms and > create new ones. I showed a screenshot earlier that illustrated a > 'button' definition. The idea of drag-and-drop GUI designers is hardly new. I was using one back in 1986 or '88, Apple's Hypercard. Now that was a user-friendly programming language/environment/toolkit. -- Steven From python.list at tim.thechases.com Sun Jan 26 08:49:37 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 26 Jan 2014 07:49:37 -0600 Subject: Python with 3d cartoon In-Reply-To: References: Message-ID: <20140126074937.01979618@bigbox.christie.dr> On 2014-01-26 02:46, ngangsia akumbo wrote: > Is it possible to write cartoon with 3D images using python? > > If yes , please locate me some resources. thank Check out Blender which can be scripted using Python. -tkc From lgabiot at hotmail.com Sun Jan 26 09:29:11 2014 From: lgabiot at hotmail.com (lgabiot) Date: Sun, 26 Jan 2014 15:29:11 +0100 Subject: Can't get sqlite3.Row working: keyword lookup doesn't work In-Reply-To: References: <52e46bf3$0$2378$426a34cc@news.free.fr> Message-ID: <52E51BB7.1020801@hotmail.com> Le 26/01/14 09:05, Peter Otten a ?crit : > Please remember to cut and past the traceback next time. > >> What is wrong? > > My crystal ball says that you have a > > from __future__ import unicode_literals > > statement at the beginning of the module. If I'm right try > > row[b"filename"] Thanks a lot for your answer! your crystal ball was completely right, indeed I use the __future__ import, and the b'' fixed everything. Three days I was trying to get this... From rustompmody at gmail.com Sun Jan 26 09:36:25 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Sun, 26 Jan 2014 06:36:25 -0800 (PST) Subject: Python declarative In-Reply-To: References: <8fde6d34-47c5-49a1-a6d0-9ffe3df2d401@googlegroups.com> <52e473fc$0$29999$c3e8da3$5496439d@news.astraweb.com> <3683cd10-592b-4a3d-ba77-b963a1aa2282@googlegroups.com> Message-ID: <60ae30a5-ad55-4243-9fb4-f0c278269631@googlegroups.com> On Sunday, January 26, 2014 2:42:57 PM UTC+5:30, Frank Millman wrote: > "Rustom Mody" wrote: > > Xml, originally a document format, is nowadays used as a data-format. > > This conduces to humongous messing, first for the xml-library writers, and > > thence to the users of those libraries because library messes inevitably > > leak past abstraction barriers to cause user-programmer headaches. > > tl;dr > > Frank's principle: "Express little as possible in " > > is correct. > > "And therefore XML is the solution" > > is bad logic > > [Unless == "java" !] > If that is the case, what is 'good logic'? JSON or YAML? > It does not make much difference which format I use. However, I will say > that I found it a useful discipline to create an xml schema to describe my > form definition, for two reasons. > Firstly, I was hand-crafting my form definitions initially, and as I added > features it became unwieldy. Forcing myself to create the schema highlighted > a lot of anomalies and I ended up with a much cleaner structure as a result. > Secondly, it has picked up a lot of errors in the resulting documents which > would otherwise have generated hard-to-find runtime exceptions. There are json/yaml 'schema'* validators if you want eg https://github.com/alecthomas/voluptuous http://rx.codesimply.com/ * if you want to call them that! From martin.schoon at gmail.com Sun Jan 26 11:35:08 2014 From: martin.schoon at gmail.com (Martin =?UTF-8?Q?Sch=C3=B6=C3=B6n?=) Date: 26 Jan 2014 16:35:08 GMT Subject: SiafOO? Message-ID: Today I stumbled upon www.siafoo.net when looking for tutorials on reStructured Text today. It looks like it could be good place to hang out to pick up programming skills (I am not in the positions help others, yet), is it? /Martin From blakesadams at gmail.com Sun Jan 26 11:59:56 2014 From: blakesadams at gmail.com (Blake Adams) Date: Sun, 26 Jan 2014 08:59:56 -0800 (PST) Subject: re Questions Message-ID: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Im pretty new to Python and understand most of the basics of Python re but am stumped by a unexpected matching dynamics. If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following: re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_']. Why does this happen? Thanks in advance Blake From breamoreboy at yahoo.co.uk Sun Jan 26 12:06:19 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Jan 2014 17:06:19 +0000 Subject: SiafOO? In-Reply-To: References: Message-ID: On 26/01/2014 16:35, Martin Sch??n wrote: > Today I stumbled upon www.siafoo.net when looking for > tutorials on reStructured Text today. > > It looks like it could be good place to hang out to > pick up programming skills (I am not in the positions > help others, yet), is it? > > /Martin > "Have an unfortunate situation where you need to fit as much as you can in one expression?". "You've just saved a line of code and a variable name (for the function)." Not my cup of tea, but thank you anyway, YMMV. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From larry.martell at gmail.com Sun Jan 26 12:06:59 2014 From: larry.martell at gmail.com (Larry Martell) Date: Sun, 26 Jan 2014 10:06:59 -0700 Subject: re Questions In-Reply-To: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On Sun, Jan 26, 2014 at 9:59 AM, Blake Adams wrote: > Im pretty new to Python and understand most of the basics of Python re but am stumped by a unexpected matching dynamics. > > If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following: > > re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_']. > > Why does this happen? Because the characters \ ] ^ and _ are between Z and a in the ASCII character set. You need to do this: re.findall('[A-Za-z0-9_]','^;z %C\@0~_') From rosuav at gmail.com Sun Jan 26 12:08:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 04:08:01 +1100 Subject: re Questions In-Reply-To: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On Mon, Jan 27, 2014 at 3:59 AM, Blake Adams wrote: > If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following: > > re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_']. > > Why does this happen? Because \w is not the same as [A-z0-9_]. Quoting from the docs: """ \w For Unicode (str) patterns:Matches Unicode word characters; this includes most characters that can be part of a word in any language, as well as numbers and the underscore. If the ASCII flag is used, only [a-zA-Z0-9_] is matched (but the flag affects the entire regular expression, so in such cases using an explicit [a-zA-Z0-9_] may be a better choice).For 8-bit (bytes) patterns:Matches characters considered alphanumeric in the ASCII character set; this is equivalent to [a-zA-Z0-9_]. """ If you're working with a byte string, then you're close, but A-z is quite different from A-Za-z. The set [A-z] is equivalent to [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] (that's a literal backslash in there, btw), so it'll also catch several non-alphabetic characters. With a Unicode string, it's quite distinctly different. Either way, \w means "word characters", though, so just go ahead and use it whenever you want word characters :) ChrisA From roy at panix.com Sun Jan 26 12:15:14 2014 From: roy at panix.com (Roy Smith) Date: Sun, 26 Jan 2014 12:15:14 -0500 Subject: re Questions References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > The set [A-z] is equivalent to > [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] I'm inclined to suggest the regex compiler should issue a warning for this. I've never seen a character range other than A-Z, a-z, or 0-9. Well, I suppose A-F or a-f if you're trying to match hex digits (and some variations on that for octal). But, I can't imagine any example where somebody wrote A-z and it wasn't an error. From blakesadams at gmail.com Sun Jan 26 12:15:16 2014 From: blakesadams at gmail.com (Blake Adams) Date: Sun, 26 Jan 2014 09:15:16 -0800 (PST) Subject: re Questions In-Reply-To: References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On Sunday, January 26, 2014 12:06:59 PM UTC-5, Larry.... at gmail.com wrote: > On Sun, Jan 26, 2014 at 9:59 AM, Blake Adams wrote: > > > Im pretty new to Python and understand most of the basics of Python re but am stumped by a unexpected matching dynamics. > > > > > > If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following: > > > > > > re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_']. > > > > > > Why does this happen? > > > > Because the characters \ ] ^ and _ are between Z and a in the ASCII > > character set. > > > > You need to do this: > > > > re.findall('[A-Za-z0-9_]','^;z %C\@0~_') Got it that makes sense. Thanks for the quick reply Larry From blakesadams at gmail.com Sun Jan 26 12:15:51 2014 From: blakesadams at gmail.com (Blake Adams) Date: Sun, 26 Jan 2014 09:15:51 -0800 (PST) Subject: re Questions In-Reply-To: References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On Sunday, January 26, 2014 12:08:01 PM UTC-5, Chris Angelico wrote: > On Mon, Jan 27, 2014 at 3:59 AM, Blake Adams wrote: > > > If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following: > > > > > > re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_']. > > > > > > Why does this happen? > > > > Because \w is not the same as [A-z0-9_]. Quoting from the docs: > > > > """ > > \w For Unicode (str) patterns:Matches Unicode word characters; this > > includes most characters that can be part of a word in any language, > > as well as numbers and the underscore. If the ASCII flag is used, only > > [a-zA-Z0-9_] is matched (but the flag affects the entire regular > > expression, so in such cases using an explicit [a-zA-Z0-9_] may be a > > better choice).For 8-bit (bytes) patterns:Matches characters > > considered alphanumeric in the ASCII character set; this is equivalent > > to [a-zA-Z0-9_]. > > """ > > > > If you're working with a byte string, then you're close, but A-z is > > quite different from A-Za-z. The set [A-z] is equivalent to > > [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] (that's > > a literal backslash in there, btw), so it'll also catch several > > non-alphabetic characters. With a Unicode string, it's quite > > distinctly different. Either way, \w means "word characters", though, > > so just go ahead and use it whenever you want word characters :) > > > > ChrisA Thanks Chris From rosuav at gmail.com Sun Jan 26 12:25:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 04:25:29 +1100 Subject: re Questions In-Reply-To: References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On Mon, Jan 27, 2014 at 4:15 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> The set [A-z] is equivalent to >> [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] > > I'm inclined to suggest the regex compiler should issue a warning for > this. > > I've never seen a character range other than A-Z, a-z, or 0-9. Well, I > suppose A-F or a-f if you're trying to match hex digits (and some > variations on that for octal). But, I can't imagine any example where > somebody wrote A-z and it wasn't an error. I've used a variety of character ranges, certainly more than the 4-5 you listed, but I agree that A-z is extremely likely to be an error. However, I've sometimes used a regex (bytes mode) to find, say, all the ASCII printable characters - [ -~] - and I wouldn't want that precluded. It's a bit tricky trying to figure out which are likely to be errors and which are not, so I'd be inclined to keep things as they are. No warnings. ChrisA From breamoreboy at yahoo.co.uk Sun Jan 26 12:30:47 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Jan 2014 17:30:47 +0000 Subject: re Questions In-Reply-To: References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On 26/01/2014 17:15, Blake Adams wrote: > On Sunday, January 26, 2014 12:08:01 PM UTC-5, Chris Angelico wrote: >> On Mon, Jan 27, 2014 at 3:59 AM, Blake Adams wrote: >> >>> If I want to set up a match replicating the '\w' pattern I would assume that would be done with '[A-z0-9_]'. However, when I run the following: >> >>> >> >>> re.findall('[A-z0-9_]','^;z %C\@0~_') it matches ['^', 'z', 'C', '\\', '0', '_']. I would expect the match to be ['z', 'C', '0', '_']. >> >>> >> >>> Why does this happen? >> >> >> >> Because \w is not the same as [A-z0-9_]. Quoting from the docs: >> >> >> >> """ >> >> \w For Unicode (str) patterns:Matches Unicode word characters; this >> >> includes most characters that can be part of a word in any language, >> >> as well as numbers and the underscore. If the ASCII flag is used, only >> >> [a-zA-Z0-9_] is matched (but the flag affects the entire regular >> >> expression, so in such cases using an explicit [a-zA-Z0-9_] may be a >> >> better choice).For 8-bit (bytes) patterns:Matches characters >> >> considered alphanumeric in the ASCII character set; this is equivalent >> >> to [a-zA-Z0-9_]. >> >> """ >> >> >> >> If you're working with a byte string, then you're close, but A-z is >> >> quite different from A-Za-z. The set [A-z] is equivalent to >> >> [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] (that's >> >> a literal backslash in there, btw), so it'll also catch several >> >> non-alphabetic characters. With a Unicode string, it's quite >> >> distinctly different. Either way, \w means "word characters", though, >> >> so just go ahead and use it whenever you want word characters :) >> >> >> >> ChrisA > > Thanks Chris > I'm pleased to see that your question has been answered. Now would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Jan 26 12:39:20 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Jan 2014 17:39:20 +0000 Subject: re Questions In-Reply-To: References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: On 26/01/2014 17:25, Chris Angelico wrote: > On Mon, Jan 27, 2014 at 4:15 AM, Roy Smith wrote: >> In article , >> Chris Angelico wrote: >> >>> The set [A-z] is equivalent to >>> [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] >> >> I'm inclined to suggest the regex compiler should issue a warning for >> this. >> >> I've never seen a character range other than A-Z, a-z, or 0-9. Well, I >> suppose A-F or a-f if you're trying to match hex digits (and some >> variations on that for octal). But, I can't imagine any example where >> somebody wrote A-z and it wasn't an error. > > I've used a variety of character ranges, certainly more than the 4-5 > you listed, but I agree that A-z is extremely likely to be an error. > However, I've sometimes used a regex (bytes mode) to find, say, all > the ASCII printable characters - [ -~] - and I wouldn't want that > precluded. It's a bit tricky trying to figure out which are likely to > be errors and which are not, so I'd be inclined to keep things as they > are. No warnings. > > ChrisA > I suggest a single warning is always given "Regular expressions can be fickle. Have you considered using string methods?". My apologies to regex fans if they're currently choking over their tea, coffee, cocoa, beer, scotch, saki, ouzo or whatever :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mickverdu at gmail.com Sun Jan 26 13:47:11 2014 From: mickverdu at gmail.com (mick verdu) Date: Sun, 26 Jan 2014 10:47:11 -0800 (PST) Subject: Lists inside dictionary and how to look for particular value Message-ID: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> z={ 'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200'] } My solution: z=raw_input("Enter Host, Mac, ip and time") t=z.split() t[0]=z[1:] for key in dic: if t[2] in dic[key]: del dic[t[0]] else: dic[t[0]] = t[1:] What I really want to achieve is: How to search for a particular value inside list. First, I want the user to input hostname and ip. e.g. PC1 and 192.168.0.1, then need to find out if 192.168.0.1 has already been assigned to some host in dictionary. In this case I would need to skip for search inside list of user input host. Forexample, if user inputs PC1 and 192.168.0.1 i would like to skip searching in above PC1's values. So it should detect matching only with different hosts and skip its own name. If i input PC4 and 192.168.0.1 then it should detect conflict with PC1. So PC4 would be deleted(As soon as user inputs new host it is saved in above database then if conflict with others deleted) From python.list at tim.thechases.com Sun Jan 26 14:41:41 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 26 Jan 2014 13:41:41 -0600 Subject: re Questions In-Reply-To: References: <3f568767-e13a-4c7d-a4fb-85caca2adf6e@googlegroups.com> Message-ID: <20140126134141.127e4ef9@bigbox.christie.dr> On 2014-01-26 12:15, Roy Smith wrote: > > The set [A-z] is equivalent to > > [ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz] > > I'm inclined to suggest the regex compiler should issue a warning > for this. > > I've never seen a character range other than A-Z, a-z, or 0-9. > Well, I suppose A-F or a-f if you're trying to match hex digits > (and some variations on that for octal). But, I can't imagine any > example where somebody wrote A-z and it wasn't an error. I'd not object to warnings on that one literal "A-z" set, but I've done some work with VINs? where the allowable character-set is A-Z and digits, minus letters that can be hard to distinguish visually (I/O/Q), so I've used ^[A-HJ-NPR-Z0-9]{17}$ as a first-pass filter for VINs that were entered (often scanned, but occasionally hand-keyed). In some environments, I've been able to intercept I/O/Q and remap them accordingly to 1/0/0 to do the disambiguation for the user. So I'd not want to see other character-classes touched, as they can be perfectly legit. -tkc ? http://en.wikipedia.org/wiki/Vehicle_Identification_Number From __peter__ at web.de Sun Jan 26 14:44:21 2014 From: __peter__ at web.de (Peter Otten) Date: Sun, 26 Jan 2014 20:44:21 +0100 Subject: Lists inside dictionary and how to look for particular value References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: mick verdu wrote: > z={ 'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], > 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], > 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200'] } > > My solution: > > z=raw_input("Enter Host, Mac, ip and time") > t=z.split() > t[0]=z[1:] > for key in dic: > if t[2] in dic[key]: > del dic[t[0]] > else: > dic[t[0]] = t[1:] > > > What I really want to achieve is: > > > How to search for a particular value inside list. First, I want the user > to input hostname and ip. e.g. PC1 and 192.168.0.1, then need to find out > if 192.168.0.1 has already been assigned to some host in dictionary. In > this case I would need to skip for search inside list of user input host. > > Forexample, if user inputs PC1 and 192.168.0.1 i would like to skip > searching in above PC1's values. So it should detect matching only with > different hosts and skip its own name. > > If i input PC4 and 192.168.0.1 then it should detect conflict with PC1. So > PC4 would be deleted(As soon as user inputs new host it is saved in above > database then if conflict with others deleted) You are making the problem unnecessarily complex. For the example scenario start with a dict that maps host to ip: host2ip = { "PC1": "192.168.0.1", "PC2": "192.168.0.2", "PC3": "192.168.0.3", } host, ip = raw_input("Enter host and ip: ").split() if host not in host2ip: print "adding", host host2ip[host] = ip else: old_ip = host2ip[host] if old_ip == ip: print "no changes necessary" else: print "updating ip for", host, "from", old_ip, "to", ip host2ip[host] = ip Then proceed and come up with an unambiguous description of what to do with mac and time in plain english, and add or modify data structures as necessary. From python.list at tim.thechases.com Sun Jan 26 15:00:43 2014 From: python.list at tim.thechases.com (Tim Chase) Date: Sun, 26 Jan 2014 14:00:43 -0600 Subject: Lists inside dictionary and how to look for particular value In-Reply-To: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: <20140126140043.04d8aba3@bigbox.christie.dr> On 2014-01-26 10:47, mick verdu wrote: > z={ 'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], > 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], > 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200'] } > > My solution: > > z=raw_input("Enter Host, Mac, ip and time") > t=z.split() > t[0]=z[1:] ^ First, I don't think that this is doing what you want it to. I suspect you want something like data = {} while True: z = raw_input("Enter Host, Mac, IP and Time") try: host, mac, ip, time = z.split() except ValueError: print("Could not parse. Quitting") break existing = get_existing(data, mac, ip) if existing: print("%s/%s already exists as %s" % ( mac, ip, existing) else: data[host] = [mac, ip, time] > How to search for a particular value inside list. First, I want the > user to input hostname and ip. e.g. PC1 and 192.168.0.1, then need > to find out if 192.168.0.1 has already been assigned to some host > in dictionary. In this case I would need to skip for search inside > list of user input host. You have two main choices, depending on the size of the data and how frequently you're running the queries: 1) you can search through the entire dataset every time for any sort of match. If the list is reasonably small or you're not throwing thousands of queries-per-second at it, this is insignificant and can be pretty straight-forward: def get_existing(data, mac, ip): for hostname, (m, i, _) in data.items(): if mac == m or ip = i: return hostname return None 2) You can maintain separate data structures for the reverse-mapping. This has a much faster lookup time at the cost of more space and maintaining the reverse mappings. The whole thing might look more like ip_to_hostname = {} mac_to_hostname = {} data = {} while True: z = raw_input("Enter Host, MAC, IP and Time") try: host, mac, ip, time = z.split()[:4] except ValueError: print("Could not parse. Quitting") break if mac in mac_to_hostname: print("MAC already exists as %s" % mac_to_hostname[mac]) elif ip in ip_to_hostname: print("IP already exists as %s" % ip_to_hostname[ip]) # elif host in data: # mac2, ip2, _ = data[host] # if (mac, ip) != (mac2, ip2): # print("Hostname already entered (%s/%s)" % (mac2, ip2)) else: data[host] = [mac, ip, time] ip_to_hostname[ip] = host mac_to_hostname[mac] = host -tkc From mickverdu at gmail.com Sun Jan 26 15:20:16 2014 From: mickverdu at gmail.com (mick verdu) Date: Sun, 26 Jan 2014 12:20:16 -0800 (PST) Subject: Lists inside dictionary and how to look for particular value In-Reply-To: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: <510d7811-729f-4cf5-b563-8094745293b3@googlegroups.com> @Peter Otten: I have lists for keys. What I want is if host already exists it would overwrite otherwise add to database. And if host doesn't exist it will first add this host to database and then compare its IP with IPs of rest of hosts. If ip matches with any of the other hosts, it will delete the host that it just added now.I know it doesn't make sense but I need to do it. From denismfmcmahon at gmail.com Sun Jan 26 15:25:06 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sun, 26 Jan 2014 20:25:06 +0000 (UTC) Subject: Lists inside dictionary and how to look for particular value References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: On Sun, 26 Jan 2014 10:47:11 -0800, mick verdu wrote: > z={ 'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], > 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': > ['01:01:01:01:01:01', '192.168.0.1', '200'] } > > My solution: > > z=raw_input("Enter Host, Mac, ip and time") > t=z.split() > t[0]=z[1:] > for key in dic: > if t[2] in dic[key]: > del dic[t[0]] > else: > dic[t[0]] = t[1:] > > > What I really want to achieve is: > > > How to search for a particular value inside list. First, I want the user > to input hostname and ip. e.g. PC1 and 192.168.0.1, then need to find > out if 192.168.0.1 has already been assigned to some host in dictionary. > In this case I would need to skip for search inside list of user input > host. > > Forexample, if user inputs PC1 and 192.168.0.1 i would like to skip > searching in above PC1's values. So it should detect matching only with > different hosts and skip its own name. > > If i input PC4 and 192.168.0.1 then it should detect conflict with PC1. > So PC4 would be deleted(As soon as user inputs new host it is saved in > above database then if conflict with others deleted) Can we step back a few stages. What are you writing this software for? The network management at the level you're trying to observe happens for the most part automatically at the ip stack / network hardware level. Do you think this database of which ip maps to which MAC is actually going to have some human use? If so, what? Or is this some sort of homework exercise as part of a programming course? -- Denis McMahon, denismfmcmahon at gmail.com From mickverdu at gmail.com Sun Jan 26 15:28:14 2014 From: mickverdu at gmail.com (mick verdu) Date: Sun, 26 Jan 2014 12:28:14 -0800 (PST) Subject: Lists inside dictionary and how to look for particular value In-Reply-To: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: I have programming course and trying to learn things. This is of no human use. I am just following exercises. Just have to do steps as asked. From laurent.gabiot at gmail.com Sun Jan 26 09:29:11 2014 From: laurent.gabiot at gmail.com (lgabiot) Date: Sun, 26 Jan 2014 15:29:11 +0100 Subject: Can't get sqlite3.Row working: keyword lookup doesn't work In-Reply-To: References: <52e46bf3$0$2378$426a34cc@news.free.fr> Message-ID: <52E51BB7.1020801@hotmail.com> Le 26/01/14 09:05, Peter Otten a ?crit : > Please remember to cut and past the traceback next time. > >> What is wrong? > > My crystal ball says that you have a > > from __future__ import unicode_literals > > statement at the beginning of the module. If I'm right try > > row[b"filename"] Thanks a lot for your answer! your crystal ball was completely right, indeed I use the __future__ import, and the b'' fixed everything. Three days I was trying to get this... From none at mailinator.com Sun Jan 26 16:20:25 2014 From: none at mailinator.com (mm0fmf) Date: Sun, 26 Jan 2014 21:20:25 +0000 Subject: Lists inside dictionary and how to look for particular value In-Reply-To: References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: On 26/01/2014 20:28, mick verdu wrote: > I have programming course and trying to learn things. This is of no human use. I am just following exercises. Just have to do steps as asked. > A slightly OT observation... Mick, consider using more meaningful names than t,z etc. You know what they stand for now and you will remember them whilst you work on this task. But if you revisit the code in a few weeks, months etc. you'll have a hard job remembering what they stood for. From matt.s.marotta at gmail.com Sun Jan 26 16:46:21 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Sun, 26 Jan 2014 13:46:21 -0800 (PST) Subject: Unwanted Spaces and Iterative Loop Message-ID: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> I have been working on a python script that separates mailing addresses into different components. Here is my code: inFile = "directory" outFile = "directory" inHandler = open(inFile, 'r') outHandler = open(outFile, 'w') outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") for line in inHandler: str = line.replace("FarmID\tAddress", " ") outHandler.write(str[0:-1]) str = str.replace(" ","\t", 1) str = str.replace(" Rd,","\tRd\t\t") str = str.replace(" Rd","\tRd\t") str = str.replace("Ave,","\tAve\t\t") str = str.replace("Ave ","\tAve\t\t") str = str.replace("St ","\tSt\t\t") str = str.replace("St,","\tSt\t\t") str = str.replace("Dr,","\tDr\t\t") str = str.replace("Lane,","\tLane\t\t") str = str.replace("Pky,","\tPky\t\t") str = str.replace(" Sq,","\tSq\t\t") str = str.replace(" Pl,","\tPl\t\t") str = str.replace("\tE,","E\t") str = str.replace("\tN,","N\t") str = str.replace("\tS,","S\t") str = str.replace("\tW,","W\t") str = str.replace(",","\t") str = str.replace(" ON","ON\t") outHandler.write(str) inHandler.close() The text file that this manipulates has 91 addresses, so I'll just paste 5 of them in here to get the idea: FarmID Address 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 3 25 Hunter Rd, Grimsby, ON L3M 4A3 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 My issue is that in the output file, there is a space before each city and each postal code that I do not want there. Furthermore, the FarmID is being added on to the end of the postal code under the original address column for each address. This also is not supposed to be happening, and I am having trouble designing an iterative loop to remove/prevent that from happening. Any help is greatly appreciated! From breamoreboy at yahoo.co.uk Sun Jan 26 17:20:36 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sun, 26 Jan 2014 22:20:36 +0000 Subject: Unwanted Spaces and Iterative Loop In-Reply-To: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> Message-ID: On 26/01/2014 21:46, matt.s.marotta at gmail.com wrote: > I have been working on a python script that separates mailing addresses into different components. > > Here is my code: > > inFile = "directory" > outFile = "directory" > inHandler = open(inFile, 'r') > outHandler = open(outFile, 'w') > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") > for line in inHandler: > str = line.replace("FarmID\tAddress", " ") > outHandler.write(str[0:-1]) > > str = str.replace(" ","\t", 1) > str = str.replace(" Rd,","\tRd\t\t") > str = str.replace(" Rd","\tRd\t") > str = str.replace("Ave,","\tAve\t\t") > str = str.replace("Ave ","\tAve\t\t") > str = str.replace("St ","\tSt\t\t") > str = str.replace("St,","\tSt\t\t") > str = str.replace("Dr,","\tDr\t\t") > str = str.replace("Lane,","\tLane\t\t") > str = str.replace("Pky,","\tPky\t\t") > str = str.replace(" Sq,","\tSq\t\t") > str = str.replace(" Pl,","\tPl\t\t") > > str = str.replace("\tE,","E\t") > str = str.replace("\tN,","N\t") > str = str.replace("\tS,","S\t") > str = str.replace("\tW,","W\t") > str = str.replace(",","\t") > str = str.replace(" ON","ON\t") > > > outHandler.write(str) > inHandler.close() > > The text file that this manipulates has 91 addresses, so I'll just paste 5 of them in here to get the idea: > > FarmID Address > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > 3 25 Hunter Rd, Grimsby, ON L3M 4A3 > 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > > My issue is that in the output file, there is a space before each city and each postal code that I do not want there. > > Furthermore, the FarmID is being added on to the end of the postal code under the original address column for each address. This also is not supposed to be happening, and I am having trouble designing an iterative loop to remove/prevent that from happening. > > Any help is greatly appreciated! > Make your life easier by using the csv module to read and write your data, the write using the excel-tab dialect, see http://docs.python.org/3/library/csv.html#module-csv -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From luis.marsano at gmail.com Sun Jan 26 17:30:21 2014 From: luis.marsano at gmail.com (Luis Marsano) Date: Sun, 26 Jan 2014 17:30:21 -0500 Subject: Help: python 3.3.3 (AMD64) scripts fail as non-admin user on Windows Server 2012 R2 Message-ID: I've installed python for all users with full permissions to all users (see picture). Python runs for all users. However, scripts only work when I run as Administrator. Running a script always results in an "ImportError: cannot import name" error. Here, for example, is the output of "pip -h" run as an unprivileged user: pip : Traceback (most recent call last): At line:1 char:1 + pip -h 2>&1 | Out-File -FilePath pip.txt + ~~~~~~~~~~~ + CategoryInfo : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError File "C:\Open\Python33\lib\runpy.py", line 160, in _run_module_as_main "__main__", fname, loader, pkg_name) File "C:\Open\Python33\lib\runpy.py", line 73, in _run_code exec(code, run_globals) File "C:\Open\Python33\Scripts\pip.exe\__main__.py", line 5, in ImportError: cannot import name main I get regular output when I run "pip -h" as Administrator: Usage: pip [options] Commands: install Install packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. search Search PyPI for packages. wheel Build wheels from your requirements. zip DEPRECATED. Zip individual packages. unzip DEPRECATED. Unzip individual packages. bundle DEPRECATED. Create pybundles. help Show help for commands. General Options: -h, --help Show help. -v, --verbose Give more output. Option is additive, and can be used up to 3 times. -V, --version Show version and exit. -q, --quiet Give less output. --log-file Path to a verbose non-appending log, that only logs failures. This log is active by default at C:\Users\Safe Administrator\pip\pip.log. --log Path to a verbose appending log. This log is inactive by default. --proxy Specify a proxy in the form [user:passwd@]proxy.server:port. --timeout Set the socket timeout (default 15 seconds). --exists-action Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup. --cert Path to alternate CA bundle. I can't figure out the issue: please help! -------------- next part -------------- A non-text attachment was scrubbed... Name: permissions.png Type: image/png Size: 24672 bytes Desc: not available URL: From greg.ewing at canterbury.ac.nz Sun Jan 26 18:08:47 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Mon, 27 Jan 2014 12:08:47 +1300 Subject: Lists inside dictionary and how to look for particular value In-Reply-To: <510d7811-729f-4cf5-b563-8094745293b3@googlegroups.com> References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> <510d7811-729f-4cf5-b563-8094745293b3@googlegroups.com> Message-ID: mick verdu wrote: > What I want is if host already exists it would > overwrite otherwise add to database. And if host doesn't exist it will first > add this host to database and then compare its IP with IPs of rest of hosts. > If ip matches with any of the other hosts, it will delete the host that it > just added now. It sounds like you should be maintaining two dictionaries: hostname --> IP (+ other host-related data) IP --> hostname Given a (newhost, newip) pair, first look for newip in the IP --> hostname dictionary. If it's there and the old hostname equals newhost, you're finished. If it's there with a different hostname, first delete that entry from IP --> hostname, and also delete the old hostname from hostname --> IP. Now add tne new entry to both dictionaries. -- Greg From python at mrabarnett.plus.com Sun Jan 26 18:28:37 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sun, 26 Jan 2014 23:28:37 +0000 Subject: Unwanted Spaces and Iterative Loop In-Reply-To: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> Message-ID: <52E59A25.10304@mrabarnett.plus.com> On 2014-01-26 21:46, matt.s.marotta at gmail.com wrote: > I have been working on a python script that separates mailing addresses into different components. > > Here is my code: > > inFile = "directory" > outFile = "directory" > inHandler = open(inFile, 'r') > outHandler = open(outFile, 'w') Shouldn't you be writing a '\n' at the end of the line? > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") > for line in inHandler: This is being done on every single line of the file: > str = line.replace("FarmID\tAddress", " ") > outHandler.write(str[0:-1]) > > str = str.replace(" ","\t", 1) > str = str.replace(" Rd,","\tRd\t\t") > str = str.replace(" Rd","\tRd\t") > str = str.replace("Ave,","\tAve\t\t") > str = str.replace("Ave ","\tAve\t\t") > str = str.replace("St ","\tSt\t\t") > str = str.replace("St,","\tSt\t\t") > str = str.replace("Dr,","\tDr\t\t") > str = str.replace("Lane,","\tLane\t\t") > str = str.replace("Pky,","\tPky\t\t") > str = str.replace(" Sq,","\tSq\t\t") > str = str.replace(" Pl,","\tPl\t\t") > > str = str.replace("\tE,","E\t") > str = str.replace("\tN,","N\t") > str = str.replace("\tS,","S\t") > str = str.replace("\tW,","W\t") > str = str.replace(",","\t") > str = str.replace(" ON","ON\t") > > > outHandler.write(str) > inHandler.close() > > The text file that this manipulates has 91 addresses, so I'll just paste 5 of them in here to get the idea: > > FarmID Address > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > 3 25 Hunter Rd, Grimsby, ON L3M 4A3 > 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > > My issue is that in the output file, there is a space before each city and each postal code that I do not want there. > You could try splitting on '\t', stripping the leading and trailing whitespace on each part, and then joining them together again with '\t'. (Make sure that you also write the '\n' at the end of line.) > Furthermore, the FarmID is being added on to the end of the postal code under the original address column for each address. This also is not supposed to be happening, and I am having trouble designing an iterative loop to remove/prevent that from happening. > > Any help is greatly appreciated! > As Mark said, you could also use the CSV module. From jsf80238 at gmail.com Sun Jan 26 18:44:16 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 26 Jan 2014 16:44:16 -0700 Subject: Unwanted Spaces and Iterative Loop In-Reply-To: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> Message-ID: > > > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") > > ... > FarmID Address > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > 3 25 Hunter Rd, Grimsby, ON L3M 4A3 > 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > > You are wanting to produce tab-separated output, with an "Address" field plus the Address split into fields for Street Number, Street Name, Suffix Type, Direction? The four lines you have pasted are examples of your input? If yes, "Direction" is a single letter? -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Jan 26 18:53:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 26 Jan 2014 23:53:17 GMT Subject: Help: python 3.3.3 (AMD64) scripts fail as non-admin user on Windows Server 2012 R2 References: Message-ID: <52e59fec$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jan 2014 17:30:21 -0500, Luis Marsano wrote: > I've installed python for all users with full permissions to all users > (see picture). > Python runs for all users. > However, scripts only work when I run as Administrator. Running a script > always results in an "ImportError: cannot import name" error. Here, for > example, is the output of "pip -h" run as an unprivileged user: This does not appear to be a Python problem. This appears to be a generic Windows permissions problem. My guess is that you've made sure that the Python .exe is executable by all users, but the standard library files are only readable by the Administrator user. -- Steven From mickverdu at gmail.com Sun Jan 26 18:54:39 2014 From: mickverdu at gmail.com (mick verdu) Date: Sun, 26 Jan 2014 15:54:39 -0800 (PST) Subject: Lists inside dictionary and how to look for particular value In-Reply-To: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> Message-ID: <58821aa9-8b98-458f-a775-f79d741505cb@googlegroups.com> ThanK you. It solved my problem. Can someone tell me how can i print particular value inside list of key. I know how to print J['PC2'][1] means will print IP. but I want the user to input some element and I will print element just before that element. e.g. if user inputs 192.168.0.2, program will print 02:02:02:02:02:02. If user inputs 192.168.0.1 I will print 01:01:01:01:01:01. From matt.s.marotta at gmail.com Sun Jan 26 18:56:01 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Sun, 26 Jan 2014 15:56:01 -0800 (PST) Subject: Unwanted Spaces and Iterative Loop In-Reply-To: References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> Message-ID: <2fa1fd26-7a0c-4718-ae39-3fbed8537df3@googlegroups.com> On Sunday, 26 January 2014 18:44:16 UTC-5, Jason Friedman wrote: > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") > > > > ... > ? > FarmID ?Address > > 1 ? ? ? 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > > 2 ? ? ? 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > > 3 ? ? ? 25 Hunter Rd, Grimsby, ON L3M 4A3 > > 4 ? ? ? 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > > > ?You are wanting to produce tab-separated output, with an "Address" field plus the Address split into fields for Street Number, Street Name, Suffix Type, Direction? > > > > The four lines you have pasted are examples of your input? ?If yes, "Direction" is a single letter? Yes to your first question. Yes, the four lines I have pasted are examples of input. Direction is a single letter (there are some records that are `King St. E,`). I have solved the problem with the spaces, but still cannot figure out the iterative loop to get rid of the farm ID in the address column that isn`t split. From skip at pobox.com Sun Jan 26 19:31:49 2014 From: skip at pobox.com (Skip Montanaro) Date: Sun, 26 Jan 2014 18:31:49 -0600 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: My son sent me a link to an essay about highlighting program data instead of keywords: https://medium.com/p/3a6db2743a1e/ I think this might have value, especially if to could bounce back and forth between both schemes. Is anyone aware of tools like this for Python? Bonus points for pointers to an Emacs implementation. Thanks, Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Sun Jan 26 19:40:26 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Jan 2014 00:40:26 GMT Subject: Unwanted Spaces and Iterative Loop References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> Message-ID: <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jan 2014 13:46:21 -0800, matt.s.marotta wrote: > I have been working on a python script that separates mailing addresses > into different components. > > Here is my code: > > inFile = "directory" > outFile = "directory" > inHandler = open(inFile, 'r') > outHandler = open(outFile, 'w') Are you *really* opening the same file for reading and writing at the same time? Even if your operating system allows that, surely it's not a good idea. You might get away with it for small files, but at some point you're going to run into weird, hard-to-diagnose bugs. > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir \tCity\tProvince\tPostalCode") This looks like a CSV file using tabs as the separator. You really ought to use the csv module. http://docs.python.org/3/library/csv.html http://docs.python.org/2/library/csv.html http://pymotw.com/2/csv/ > for line in inHandler: > str = line.replace("FarmID\tAddress", " ") > outHandler.write(str[0:-1]) > str = str.replace(" ","\t", 1) > str = str.replace(" Rd,","\tRd\t\t") > str = str.replace(" Rd","\tRd\t") > str = str.replace("Ave,","\tAve\t\t") > str = str.replace("Ave","\tAve\t\t") > str = str.replace("St ","\tSt\t\t") > str = str.replace("St,","\tSt\t\t") > str = str.replace("Dr,","\tDr\t\t") [snip additional string manipulations] > str = str.replace(",","\t") > str = str.replace(" ON","ON\t") > outHandler.write(str) Aiy aiy aiy, what a mess! I get a headache just trying to understand it! The first question that comes to mind is that you appear to be writing each input line *twice*, first after a very minimal set of string manipulations (you convert the literal string "FarmID\tAddress" to a space, then write the whole line out), the second time after a whole mess of string replacements. Why? If the sample data you show below is accurate, I *think* what you are trying to do is simply suppress the header line. The first line in the input file is: FarmID Address and rather than write that you want to write a space. I don't know why you want the output file to begin with a space, but this would be better: for line in inHandler: line = line.strip() # Remove any leading and trailing whitespace, # including the trailing newline. Later, we'll add a newline # back in. if line == "FarmID\tAddress": outHandler.write(" ") # Write a mysterious space. continue # And skip to the next line. # Now process the non-header lines. Now, as far as the non-header lines, you do a whole lot of complex string manipulations, replacing chunks of text with or without tabs or commas to the same text with or without tabs but in a different order. The logic of these manipulations completely escape me: what are you actually trying to do here? I *strongly* suggest that you don't try to implement your program logic in the form of string manipulations. According to your sample data, your data looks like this: 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 i.e. farmId TAB address COMMA district COMMA postcode It is much better to pull the line apart into named components, manipulate the components directly, then put it back together in the order you want. This makes the code more understandable, and easier to change if you ever need to change things. for line in inHandler: line = line.strip() if line == "FarmID\tAddress": outHandler.write(" ") # Write a mysterious space. continue # Now process the non-header lines. farmid, address = line.split("\t") farmid = farmid.strip() address, district, postcode = address.split(",") address = address.strip() district = district.strip() postcode = postcode.strip() # Now process the fields however you like. parts_of_address = address.split(" ") street_number = parts_of_address[0] # first part street_type = parts_of_address[-1] # last part street_name = parts_of_address[1:-1] # everything else street_name = " ".join(street_name) and so on for the post code. Then, at the very end, assemble the parts you want to write out, join them with tabs, and write: fields = [farmid, street_number, street_name, street_type, ... ] outHandler.write("\t".join(fields)) outHandler.write("\n") Or use the csv module to do the actual writing. It will handle escaping anything that needs escaping, newlines, tabs, etc. -- Steven From tjreedy at udel.edu Sun Jan 26 19:46:27 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Sun, 26 Jan 2014 19:46:27 -0500 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: On 1/26/2014 7:31 PM, Skip Montanaro wrote: > My son sent me a link to an essay about highlighting program data > instead of keywords: > > https://medium.com/p/3a6db2743a1e/ What it is doing is color coding user-supplied identifiers, with different color for each one. I found that confusing to read. The only use I can see for this is to track the usage of a particular name, but that would be better done by just highlighting one name at a time. > I think this might have value, especially if to could bounce back and > forth between both schemes. Is anyone aware of tools like this for > Python? Bonus points for pointers to an Emacs implementation. -- Terry Jan Reedy From rosuav at gmail.com Sun Jan 26 19:51:20 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 11:51:20 +1100 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: On Mon, Jan 27, 2014 at 11:46 AM, Terry Reedy wrote: > The only use I can see for this is to track the usage of a particular name, > but that would be better done by just highlighting one name at a time. In SciTE, I can put the cursor on a word and hit Ctrl-F3 to find other instances of that word. If that's not enough, following it up with Ctrl-Home, F3 will find the first instance of it, and if the program follows the Define-Before-Use principle, that'll be the definition. That's usually enough. ChrisA From rosuav at gmail.com Sun Jan 26 19:52:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 11:52:25 +1100 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: On Mon, Jan 27, 2014 at 11:51 AM, Chris Angelico wrote: > On Mon, Jan 27, 2014 at 11:46 AM, Terry Reedy wrote: >> The only use I can see for this is to track the usage of a particular name, >> but that would be better done by just highlighting one name at a time. > > In SciTE, I can put the cursor on a word and hit Ctrl-F3 to find other > instances of that word. If that's not enough, following it up with > Ctrl-Home, F3 will find the first instance of it, and if the program > follows the Define-Before-Use principle, that'll be the definition. > That's usually enough. > > ChrisA That said, though, I grew up without syntax highlighting of any sort, and didn't think it particularly important; but now that I have editors with all those sorts of features, I do find them handy. So it's possible that a system like this would be of value if once the programmer gets used to it. ChrisA From matt.s.marotta at gmail.com Sun Jan 26 20:15:20 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Sun, 26 Jan 2014 17:15:20 -0800 (PST) Subject: Unwanted Spaces and Iterative Loop In-Reply-To: <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> On Sunday, 26 January 2014 19:40:26 UTC-5, Steven D'Aprano wrote: > On Sun, 26 Jan 2014 13:46:21 -0800, matt.s.marotta wrote: > > > > > I have been working on a python script that separates mailing addresses > > > into different components. > > > > > > Here is my code: > > > > > > inFile = "directory" > > > outFile = "directory" > > > inHandler = open(inFile, 'r') > > > outHandler = open(outFile, 'w') > > > > Are you *really* opening the same file for reading and writing at the > > same time? > > > > Even if your operating system allows that, surely it's not a good idea. > > You might get away with it for small files, but at some point you're > > going to run into weird, hard-to-diagnose bugs. > > > > > > > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir > > \tCity\tProvince\tPostalCode") > > > > This looks like a CSV file using tabs as the separator. You really ought > > to use the csv module. > > > > http://docs.python.org/3/library/csv.html > > http://docs.python.org/2/library/csv.html > > > > http://pymotw.com/2/csv/ > > > > > > > for line in inHandler: > > > str = line.replace("FarmID\tAddress", " ") > > > outHandler.write(str[0:-1]) > > > str = str.replace(" ","\t", 1) > > > str = str.replace(" Rd,","\tRd\t\t") > > > str = str.replace(" Rd","\tRd\t") > > > str = str.replace("Ave,","\tAve\t\t") > > > str = str.replace("Ave","\tAve\t\t") > > > str = str.replace("St ","\tSt\t\t") > > > str = str.replace("St,","\tSt\t\t") > > > str = str.replace("Dr,","\tDr\t\t") > > [snip additional string manipulations] > > > str = str.replace(",","\t") > > > str = str.replace(" ON","ON\t") > > > outHandler.write(str) > > > > > > Aiy aiy aiy, what a mess! I get a headache just trying to understand it! > > > > The first question that comes to mind is that you appear to be writing > > each input line *twice*, first after a very minimal set of string > > manipulations (you convert the literal string "FarmID\tAddress" to a > > space, then write the whole line out), the second time after a whole mess > > of string replacements. Why? > > > > If the sample data you show below is accurate, I *think* what you are > > trying to do is simply suppress the header line. The first line in the > > input file is: > > > > FarmID Address > > > > and rather than write that you want to write a space. I don't know why > > you want the output file to begin with a space, but this would be better: > > > > for line in inHandler: > > line = line.strip() # Remove any leading and trailing whitespace, > > # including the trailing newline. Later, we'll add a newline > > # back in. > > if line == "FarmID\tAddress": > > outHandler.write(" ") # Write a mysterious space. > > continue # And skip to the next line. > > # Now process the non-header lines. > > > > > > Now, as far as the non-header lines, you do a whole lot of complex string > > manipulations, replacing chunks of text with or without tabs or commas to > > the same text with or without tabs but in a different order. The logic of > > these manipulations completely escape me: what are you actually trying to > > do here? > > > > I *strongly* suggest that you don't try to implement your program logic > > in the form of string manipulations. According to your sample data, your > > data looks like this: > > > > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > > > > i.e. > > > > farmId TAB address COMMA district COMMA postcode > > > > It is much better to pull the line apart into named components, > > manipulate the components directly, then put it back together in the > > order you want. This makes the code more understandable, and easier to > > change if you ever need to change things. > > > > for line in inHandler: > > line = line.strip() > > if line == "FarmID\tAddress": > > outHandler.write(" ") # Write a mysterious space. > > continue > > # Now process the non-header lines. > > farmid, address = line.split("\t") > > farmid = farmid.strip() > > address, district, postcode = address.split(",") > > address = address.strip() > > district = district.strip() > > postcode = postcode.strip() > > # Now process the fields however you like. > > parts_of_address = address.split(" ") > > street_number = parts_of_address[0] # first part > > street_type = parts_of_address[-1] # last part > > street_name = parts_of_address[1:-1] # everything else > > street_name = " ".join(street_name) > > > > and so on for the post code. Then, at the very end, assemble the parts > > you want to write out, join them with tabs, and write: > > > > fields = [farmid, street_number, street_name, street_type, ... ] > > outHandler.write("\t".join(fields)) > > outHandler.write("\n") > > > > > > Or use the csv module to do the actual writing. It will handle escaping > > anything that needs escaping, newlines, tabs, etc. > > > > > > > > -- > > Steven I`m not reading and writing to the same file, I just changed the actual paths to directory. This is for a school assignment, and we haven`t been taught any of the stuff you`re talking about. Although I appreciate your help, everything needs to stay as is and I just need to create the loop to get rid of the farmID from the end of the postal codes. From steve+comp.lang.python at pearwood.info Sun Jan 26 20:29:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Jan 2014 01:29:17 GMT Subject: Highlighting program variables instead of keywords? References: Message-ID: <52e5b66d$0$29999$c3e8da3$5496439d@news.astraweb.com> On Sun, 26 Jan 2014 18:31:49 -0600, Skip Montanaro wrote: > My son sent me a link to an essay about highlighting program data > instead of keywords: > > https://medium.com/p/3a6db2743a1e/ > > I think this might have value, especially if to could bounce back and > forth between both schemes. Hmmm, I'm not convinced, but then I wasn't convinced by syntax highlighting either until I had used it for a while. (I still think it's a nice-to-have rather than a must-have.) Seems to me that beyond a dozen or so variables, the colours won't be distinctive enough to get much benefit. Especially if similar names get similar colours, e.g. the name "handle_process" and the typo "handle_prosess" will be barely distinguishable. In a well-designed program, most variables will appear in a fairly limited number of places, possibly in only a single function or method, so in even a fairly small project you might have a few dozen distinct variables, each of which might appear only three or five times. > Is anyone aware of tools like this for > Python? Bonus points for pointers to an Emacs implementation. Sorry, can't help you. -- Steven From rosuav at gmail.com Sun Jan 26 20:51:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 12:51:30 +1100 Subject: Highlighting program variables instead of keywords? In-Reply-To: <52e5b66d$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e5b66d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Mon, Jan 27, 2014 at 12:29 PM, Steven D'Aprano wrote: > Hmmm, I'm not convinced, but then I wasn't convinced by syntax > highlighting either until I had used it for a while. (I still think it's > a nice-to-have rather than a must-have.) It's definitely just a nice-to-have. I've built miniature text editors into various programs (including two MUD clients, for the purpose of editing files on the server), and haven't bothered with the level of sophistication required for smart-indent, much less syntax highlighting. (I'll occasionally put in an auto-indent - hit enter and it indents to the same level as the previous line - but not even always that, and definitely not "hey, that line has more ( than ) so I'll indent an extra level", which is a *hugely* helpful feature when I'm doing main coding (it catches errors, as well as saving time on indentation), but one I can do without if it means I can knock together an editor in a tenth the time.) > Seems to me that beyond a dozen or so variables, the colours won't be > distinctive enough to get much benefit. Especially if similar names get > similar colours, e.g. the name "handle_process" and the typo > "handle_prosess" will be barely distinguishable. In a well-designed > program, most variables will appear in a fairly limited number of places, > possibly in only a single function or method, so in even a fairly small > project you might have a few dozen distinct variables, each of which > might appear only three or five times. Hmm. Would similar names get similar colours? I would guess that a naive approach would just go sequentially through the file, but if it's smart enough to recognize similarity, it'd be nice if it could then be smart enough to make them contrast. The more similar the words, the less similar the colours, and vice versa. Or at very least, sort all the words alphabetically, and then distribute them in some binary flip-flop method that will tend to put the ones with the same start further apart. (That would catch typos anywhere other than the beginning of the name.) Oh. Yes, they will get similar colours. Just re-read the page: """ Variable names with similar prefixes will be assigned similar colors. We collect all the custom names and order them alphabetically, then distributing them evenly along a spectrum. This way we make sure we use as distinct colors as possible. """ IMO this is a flawed design decision. The purpose of the color is to add information, not to replicate what's already there. (And it's using the simplistic method I described, of simply sorting alphabetically to determine similarity. There are other ways of distinguishing, but they're a lot more complicated.) If it's smart enough to recognize the difference between local and global names, that would be useful. Might not be so useful in JS, but definitely in Python. It would take a bit of smartness, but most editors these days have to be able to fully parse the language anyway. Hmm. Actually, this might be a plausible idea just on its own: never mind about distinguishing specific names, just create a highlight class for each of "local name" (including function parameters), "global name, read-only", and "global name, assigned to in this function", and possibly non-local (read-only and assigned) as well. If you suddenly see that the name 'len' has changed from being "global name, read-only" to "local name", you'll know instantly that you just shadowed a built-in (probably unintentionally and in a way likely to cause bugs). Do any editors currently offer this? ChrisA From skip at pobox.com Sun Jan 26 20:46:43 2014 From: skip at pobox.com (Skip Montanaro) Date: Sun, 26 Jan 2014 19:46:43 -0600 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: > What it is doing is color coding user-supplied identifiers, with different > color for each one. I found that confusing to read. I think it would take some time to get used to, and I don't think it would be the only way I'd like to view my program. I think an interactive pylint (or pyflakes or frosty) type capability would be useful, highlighting a subset of the messages it produces, like variables which were assigned but never used, or using undefined variables. It might be best supported by actually running the checker in the background, then using its messages to direct where to highlight suspect bits of code. Skip From rosuav at gmail.com Sun Jan 26 20:56:01 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 12:56:01 +1100 Subject: Unwanted Spaces and Iterative Loop In-Reply-To: <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> Message-ID: On Mon, Jan 27, 2014 at 12:15 PM, wrote: > I`m not reading and writing to the same file, I just changed the actual paths to directory. For next time, say "directory1" and "directory2" to preserve the fact that they're different. Though if they're file names, I'd use "file1" and "file2" - calling them "directory" implies that they are, well, directories :) ChrisA From matt.s.marotta at gmail.com Sun Jan 26 20:58:47 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Sun, 26 Jan 2014 17:58:47 -0800 (PST) Subject: Unwanted Spaces and Iterative Loop In-Reply-To: References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> Message-ID: On Sunday, 26 January 2014 20:56:01 UTC-5, Chris Angelico wrote: > On Mon, Jan 27, 2014 at 12:15 PM, wrote: > > > I`m not reading and writing to the same file, I just changed the actual paths to directory. > > > > For next time, say "directory1" and "directory2" to preserve the fact > > that they're different. Though if they're file names, I'd use "file1" > > and "file2" - calling them "directory" implies that they are, well, > > directories :) > > > > ChrisA Thanks, but any chance you could help me out with my question of removing the FarmID from the postal code? From jsf80238 at gmail.com Sun Jan 26 21:00:35 2014 From: jsf80238 at gmail.com (Jason Friedman) Date: Sun, 26 Jan 2014 19:00:35 -0700 Subject: Unwanted Spaces and Iterative Loop In-Reply-To: <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> Message-ID: > > I`m not reading and writing to the same file, I just changed the actual > paths to directory. > > This is for a school assignment, and we haven`t been taught any of the > stuff you`re talking about. Although I appreciate your help, everything > needs to stay as is and I just need to create the loop to get rid of the > farmID from the end of the postal codes. > -- > https://mail.python.org/mailman/listinfo/python-list > If you are allowed to use if/then this seems to work: inFile = "data" outFile = "processed" inHandler = open(inFile, 'r') outHandler = open(outFile, 'w') for line in inHandler: if line.startswith("FarmID"): outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode\n") else: line = line.replace(" ","\t", 1) line = line.replace(" Rd,","\tRd\t\t") line = line.replace(" Rd","\tRd\t") line = line.replace("Ave,","\tAve\t\t") line = line.replace("Ave ","\tAve\t\t") line = line.replace("St ","\tSt\t\t") line = line.replace("St,","\tSt\t\t") line = line.replace("Dr,","\tDr\t\t") line = line.replace("Lane,","\tLane\t\t") line = line.replace("Pky,","\tPky\t\t") line = line.replace(" Sq,","\tSq\t\t") line = line.replace(" Pl,","\tPl\t\t") line = line.replace("\tE,","E\t") line = line.replace("\tN,","N\t") line = line.replace("\tS,","S\t") line = line.replace("\tW,","W\t") line = line.replace(",","\t") line = line.replace(" ON","ON\t") outHandler.write(line) inHandler.close() -------------- next part -------------- An HTML attachment was scrubbed... URL: From ben+python at benfinney.id.au Sun Jan 26 21:08:10 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Mon, 27 Jan 2014 13:08:10 +1100 Subject: Highlighting program variables instead of keywords? References: <52e5b66d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85bnyydvn9.fsf@benfinney.id.au> Steven D'Aprano writes: > Hmmm, I'm not convinced, but then I wasn't convinced by syntax > highlighting either until I had used it for a while. (I still think > it's a nice-to-have rather than a must-have.) I wouldn't rate syntax highlighting a must-have. But I do think it's significantly more difficult to work with an editor that doesn't highlight the syntax of the code. > Seems to me that beyond a dozen or so variables, the colours won't be > distinctive enough to get much benefit. A more severe problem with the suggestion is that human cognition is only capable of attending to a limited number of differences at once, and so this kind of attention-drawing is a limited resource. Drawing attention to some aspects is at the expense of reduced attention to other aspects. The significant benefit of syntax highlighting is that it reduces the difficulty to read the text and see what will be obvious to the compiler: the structure of each statement and block. So spending the limited resource of differential attention to colours is valuable to help with this difficult aspect of reading code. So I strongly disagree with the statement ?But as it stands, we highlight the obvious (like the word function) and leave most of the content in black.? Once you have attention on it, the word ?function? is obvious. But the whole motivation of highlighting syntax using different colours is to get that differential attention in the first place. The difference between tokens *isn't* so obvious when glancing at the code without those colours. That said, the motivation in highlighting different names differently is a good one, too. I would like to have the benefit described in the article: having different names easily distinguished in the code. But I don't think that should come at the expense of significantly reducing the ease of quickly distinguishing the syntactical structure. -- \ ?We must find our way to a time when faith, without evidence, | `\ disgraces anyone who would claim it.? ?Sam Harris, _The End of | _o__) Faith_, 2004 | Ben Finney From roy at panix.com Sun Jan 26 21:54:30 2014 From: roy at panix.com (Roy Smith) Date: Sun, 26 Jan 2014 21:54:30 -0500 Subject: Highlighting program variables instead of keywords? References: Message-ID: In article , Chris Angelico wrote: > That said, though, I grew up without syntax highlighting of any sort, > and didn't think it particularly important; but now that I have > editors with all those sorts of features, I do find them handy. Same here, except I'd replace "find them handy" with "totally addicted to". From matt.s.marotta at gmail.com Sun Jan 26 22:07:31 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Sun, 26 Jan 2014 19:07:31 -0800 (PST) Subject: Unwanted Spaces and Iterative Loop In-Reply-To: References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> Message-ID: On Sunday, 26 January 2014 21:00:35 UTC-5, Jason Friedman wrote: > I`m not reading and writing to the same file, I just changed the actual paths to directory. > > > > This is for a school assignment, and we haven`t been taught any of the stuff you`re talking about. ?Although I appreciate your help, everything needs to stay as is and I just need to create the loop to get rid of the farmID from the end of the postal codes. > > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > If you are allowed to use if/then this seems to work: > > > > inFile = "data" > > outFile = "processed" > inHandler = open(inFile, 'r') > outHandler = open(outFile, 'w') > > for line in inHandler: > ? ? if line.startswith("FarmID"): > ? ? ? ? outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode\n") > > ? ? else: > ? ? ? ? line = line.replace(" ","\t", 1) > ? ? ? ? line = line.replace(" Rd,","\tRd\t\t") > > ? ? ? ? line = line.replace(" Rd","\tRd\t") > ? ? ? ? line = line.replace("Ave,","\tAve\t\t") > ? ? ? ? line = line.replace("Ave ","\tAve\t\t") > > ? ? ? ? line = line.replace("St ","\tSt\t\t") > ? ? ? ? line = line.replace("St,","\tSt\t\t") > ? ? ? ? line = line.replace("Dr,","\tDr\t\t") > > ? ? ? ? line = line.replace("Lane,","\tLane\t\t") > ? ? ? ? line = line.replace("Pky,","\tPky\t\t") > > ? ? ? ? line = line.replace(" Sq,","\tSq\t\t") > ? ? ? ? line = line.replace(" Pl,","\tPl\t\t") > > > > ? ? ? ? line = line.replace("\tE,","E\t") > ? ? ? ? line = line.replace("\tN,","N\t") > ? ? ? ? line = line.replace("\tS,","S\t") > > ? ? ? ? line = line.replace("\tW,","W\t") > ? ? ? ? line = line.replace(",","\t") > ? ? ? ? line = line.replace(" ON","ON\t") > > > > ? ? ? ? outHandler.write(line) > inHandler.close() Unfortunately this did not work - the columns get messed up and there is no column for the full address. From noone at all.net Sun Jan 26 22:42:58 2014 From: noone at all.net (me) Date: 27 Jan 2014 03:42:58 GMT Subject: buggy python interpretter or am I missing something here? Message-ID: I'm writing a linux daemon in python 2.x to process batches of GPS/GIS data and I'm running into something that seems to break the expected program flow in a REALLY BAD WAY. Consider the attached template script and execute it with the -h option. It is falling through to the except: clause even though try to manually exit with sys.exit(0). However, if I insert a "raise" into the except clause then the sys.exit(0) executes properly. See the attached code and output from when I run it. Not interested in work-arounds. I want to understand why it doesn't work as expected. Thanks! TCdaemon.py ---- #! /usr/bin/python import sys # ------------------------------------------------------------------------------ defaultparams={ \ "basedir": "/process", \ "inpipe": "/tmp/TCdaemonIN", \ "maxjobs":8, \ "outpipe": "/tmp/TCdaemonOUT", \ "ZZZ": 0 } # ------------------------------------------------------------------------------ def parse_args(a,d): l=len(a) idx=1 try: while (idx School assignment is to create a tab separated output with the original given addresses in one column and then the addresses split into other columns (ex, columns for city, postal code, street suffix). Here is my code: inHandler = open(inFile, 'r') outHandler = open(outFile, 'w') outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") for line in inHandler: str = line.replace("FarmID\tAddress", " ") outHandler.write(str[0:-1]) str = str.replace(" ","\t", 1) str = str.replace(" Rd, ","\tRd\t\t") str = str.replace("Rd ","\tRd\t\t") str = str.replace("Ave, ","\tAve\t\t") str = str.replace("Ave ","\tAve\t\t") str = str.replace("St ","\tSt\t\t") str = str.replace("St, ","\tSt\t\t") str = str.replace("Dr, ","\tDr\t\t") str = str.replace("Lane, ","\tLane\t\t") str = str.replace("Pky, ","\tPky\t\t") str = str.replace(" Sq, ","\tSq\t\t") str = str.replace(" Pl, ","\tPl\t\t") str = str.replace("\tE, ","E\t") str = str.replace("\tN, ","N\t") str = str.replace("\tS, ","S\t") str = str.replace("\tW, ","W\t") str = str.replace(",\t","\t\t") str = str.replace(", ON ","\tON\t") outHandler.write(str) inHandler.close() outHandler.close() Here is some sample addresses, there are over 100: FarmID Address 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 3 25 Hunter Rd, Grimsby, ON L3M 4A3 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 5 5172 Green Lane Rd, Lincoln, ON L0R 1B3 6 500 Glenridge Ave, St. Catharines, ON L2S 3A1 7 471 Foss Rd, Pelham, ON L0S 1C0 8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 9 3836 Main St, Lincoln, ON L0R 1S0 I have everything worked out, except that the final output places the farmID at the end of postal code as seen in the example below (notice the brackets showing where the farmID is placed): FarmID Address StreetNum StreetName SufType Dir City Province PostalCode 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0(1) 1067 Niagara Stone Rd Niagara-On-The-Lake ON L0S 1J0 Any ideas on how to fix this? Keep in mind as well that the farmID will have 2 characters at a certain point. From gary.herron at islandtraining.com Mon Jan 27 00:04:57 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 26 Jan 2014 21:04:57 -0800 Subject: buggy python interpretter or am I missing something here? In-Reply-To: References: Message-ID: <52E5E8F9.7000001@islandtraining.com> On 01/26/2014 07:42 PM, me wrote: > I'm writing a linux daemon in python 2.x to process batches of GPS/GIS > data and I'm running into something that seems to break the expected > program flow in a REALLY BAD WAY. > > Consider the attached template script and execute it with the -h option. > It is falling through to the except: clause even though try to manually > exit with sys.exit(0). However, if I insert a "raise" into the except > clause then the sys.exit(0) executes properly. > > See the attached code and output from when I run it. > > Not interested in work-arounds. I want to understand why it doesn't work > as expected. > > Thanks! > > TCdaemon.py ---- > > #! /usr/bin/python > > import sys > > > # > ------------------------------------------------------------------------------ > > defaultparams={ \ > "basedir": "/process", \ > "inpipe": "/tmp/TCdaemonIN", \ > "maxjobs":8, \ > "outpipe": "/tmp/TCdaemonOUT", \ > "ZZZ": 0 > } > > # > ------------------------------------------------------------------------------ > > def parse_args(a,d): > l=len(a) > idx=1 > try: > while (idx if (a[idx]=="-#"): > idx=idx+1 > d["maxjobs"]=int(a[idx]) > elif (a[idx]=="-d"): > idx=idx+1 > d["basedir"]=a[idx] > elif (a[idx]=="-h"): > print "help goes here" > sys.exit(0) > elif (a[idx]=="-i"): > idx=idx+1 > d["inpipe"]=a[idx] > elif (a[idx]=="-o"): > idx=idx+1 > d["outpipe"]=a[idx] > idx=idx+1 > except: > # raise # -- WTF!!!??? required for -h to not fall through to > here? > print "%s: error in command line - %s"%(a[0],a[idx:]) > sys.exit(1) Never *ever* have a bare except like that. If it gets invoked, you have no idea why. A simple typo like ixd instead of idx or a(idx) instead of a[idx] would raise an exception but give you no idea why. Do try: ... except Exception,e: print e at the absolute minimum. (Python 3 syntax would differ slightly, but the advice is the same.) Perhaps printing a traceback along with the exception would help. Add traceback.print_exc() Gary Herron > > > # > ------------------------------------------------------------------------------ > # > ------------------------------------------------------------------------------ > # > ------------------------------------------------------------------------------ > > if (__name__=="__main__"): > print defaultparams > parse_args(sys.argv,defaultparams) > print defaultparams > > > > > > output.txt --- > [@blackbox new]$ ./TCdaemon.py -h > {'ZZZ': 0, 'basedir': '/process', 'outpipe': '/tmp/TCdaemonOUT', > 'maxjobs': 8, 'inpipe': '/tmp/TCdaemonIN'} > help goes here > ./TCdaemon.py: error in command line - ['-h'] > [@blackbox new]$ echo $? > 1 > [@blackbox new]$ > [@blackbox new]$ > [@blackbox new]$ # editing to add "raise" at line 40 > [@blackbox new]$ > [@blackbox new]$ > [@blackbox new]$ > [@blackbox new]$ ./TCdaemon.py -h > {'ZZZ': 0, 'basedir': '/process', 'outpipe': '/tmp/TCdaemonOUT', > 'maxjobs': 8, 'inpipe': '/tmp/TCdaemonIN'} > help goes here > [@blackbox new]$ echo $? > 0 > [@blackbox new]$ > > From davea at davea.name Mon Jan 27 00:24:11 2014 From: davea at davea.name (Dave Angel) Date: Mon, 27 Jan 2014 00:24:11 -0500 (EST) Subject: Remove unwanted characters from column References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> Message-ID: matt.s.marotta at gmail.com Wrote in message: > School assignment is to create a tab separated output with the original given addresses in one column and then the addresses split into other columns (ex, columns for city, postal code, street suffix). > > Here is my code: > > inHandler = open(inFile, 'r') > outHandler = open(outFile, 'w') > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") > for line in inHandler: > str = line.replace("FarmID\tAddress", " ") > outHandler.write(str[0:-1]) > > str = str.replace(" ","\t", 1) > str = str.replace(" Rd, ","\tRd\t\t") > str = str.replace("Rd ","\tRd\t\t") > str = str.replace("Ave, ","\tAve\t\t") > str = str.replace("Ave ","\tAve\t\t") > str = str.replace("St ","\tSt\t\t") > str = str.replace("St, ","\tSt\t\t") > str = str.replace("Dr, ","\tDr\t\t") > str = str.replace("Lane, ","\tLane\t\t") > str = str.replace("Pky, ","\tPky\t\t") > str = str.replace(" Sq, ","\tSq\t\t") > str = str.replace(" Pl, ","\tPl\t\t") > > str = str.replace("\tE, ","E\t") > str = str.replace("\tN, ","N\t") > str = str.replace("\tS, ","S\t") > str = str.replace("\tW, ","W\t") > str = str.replace(",\t","\t\t") > str = str.replace(", ON ","\tON\t") > > outHandler.write(str) > > inHandler.close() > outHandler.close() > > > Here is some sample addresses, there are over 100: > > FarmID Address > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > 3 25 Hunter Rd, Grimsby, ON L3M 4A3 > 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > 5 5172 Green Lane Rd, Lincoln, ON L0R 1B3 > 6 500 Glenridge Ave, St. Catharines, ON L2S 3A1 > 7 471 Foss Rd, Pelham, ON L0S 1C0 > 8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > 9 3836 Main St, Lincoln, ON L0R 1S0 > > > > I have everything worked out, except that the final output places the farmID at the end of postal code as seen in the example below (notice the brackets showing where the farmID is placed): > > FarmID Address StreetNum StreetName SufType Dir City Province PostalCode > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0(1) 1067 Niagara Stone Rd Niagara-On-The-Lake ON L0S 1J0 > > Any ideas on how to fix this? Keep in mind as well that the farmID will have 2 characters at a certain point. > Your specific concern is triggered by having two writes in the loop. Get rid of the first and you're marginally closer. But really, you've got much bigger troubles. All those unrestricted replace calls are not at all robust. But maybe you'll get away with it for a school assignment if the test data is very limited. Better would be to treat it like a parsing problem, figuring what delimiter rule applies to each field, and building a list Then use str.join to build the line for the outHandler. -- DaveA From davea at davea.name Mon Jan 27 00:36:20 2014 From: davea at davea.name (Dave Angel) Date: Mon, 27 Jan 2014 00:36:20 -0500 (EST) Subject: buggy python interpretter or am I missing something here? References: Message-ID: me Wrote in message: > I'm writing a linux daemon in python 2.x to process batches of GPS/GIS > data and I'm running into something that seems to break the expected > program flow in a REALLY BAD WAY. > > Consider the attached template script and execute it with the -h option. > It is falling through to the except: clause even though try to manually > exit with sys.exit(0). However, if I insert a "raise" into the except > clause then the sys.exit(0) executes properly. > > See the attached code and output from when I run it. > > Not interested in work-arounds. I want to understand why it doesn't work > as expected. > sys.exit() raises an exception, and you're deliberately eating that exception. > > ------------------------------------------------------------------------------ > > def parse_args(a,d): > l=len(a) > idx=1 > try: > while (idx if (a[idx]=="-#"): > idx=idx+1 > d["maxjobs"]=int(a[idx]) > elif (a[idx]=="-d"): > idx=idx+1 > d["basedir"]=a[idx] > elif (a[idx]=="-h"): > print "help goes here" > sys.exit(0) > elif (a[idx]=="-i"): > idx=idx+1 > d["inpipe"]=a[idx] > elif (a[idx]=="-o"): > idx=idx+1 > d["outpipe"]=a[idx] > idx=idx+1 > except: Bare except is almost never a good idea. It's going to intercept the exit exception, plus control C, syntax errors and others. Which you'd have known if you printed the exception code. If you're going to catch an exception, be specific. Otherwise expect the unexpected. There is a hierarchy of exception classes, so you could catch a fairly generic class. But you do need to distinguish. -- DaveA From noone at all.net Mon Jan 27 01:02:00 2014 From: noone at all.net (me) Date: 27 Jan 2014 06:02:00 GMT Subject: buggy python interpretter or am I missing something here? References: Message-ID: <52e5f658$0$29583$862e30e2@ngroups.net> On Mon, 27 Jan 2014 00:36:20 -0500, Dave Angel wrote: > sys.exit() raises an exception, and you're deliberately eating > that exception. > I can buy that sys.exit (may) be throwing an exception...My point of contention isn't that I may be throwing one, but why would a subsequent "raise" in the except: clause cause the point of program execution to jump back up to the sys.exit(0) and then function correctly. This seems to be a violation of the programming semantics of python as I understand them...coming from an old fart c++ programmer where bare catch() is totally acceptable and common form. > > Bare except is almost never a good idea. It's going to intercept > the exit exception, plus control C, syntax errors and others. > Which you'd have known if you printed the exception code. > > > If you're going to catch an exception, be specific. Otherwise > expect the unexpected. > > > There is a hierarchy of exception classes, so you could catch a > fairly generic class. But you do need to distinguish. I'll take your point of "almost a never good idea" under consideration and agree that if I was writing something for production use I'd be more comprehensive, but I really don't care what exceptions are raised at this point ... until I've tested with bunches of input data and see that it does break and under what circumstances. But...it still doesn't explain why/how a raise in the except: clause can recover the point of program execution back to the sys.exit(0) that threw the exception. Are you saying that the programming semantics of try/except are different in python than they are in c++? My expectation being that when an exception occurs program control jumps to the except: and then continues below without ever going back to the code that threw the exception in the first place...because that's exactly what it appears to be doing? Are except: clauses in python more synonymous with the old BASIC "GOSUB" or "ON ERROR GOSUB" statement rather than following the c++ semantics? kind regards From noone at all.net Mon Jan 27 01:17:41 2014 From: noone at all.net (me) Date: 27 Jan 2014 06:17:41 GMT Subject: buggy python interpretter or am I missing something here? References: Message-ID: <52e5fa05$0$29727$862e30e2@ngroups.net> On Sun, 26 Jan 2014 21:04:57 -0800, Gary Herron wrote: > > Never *ever* have a bare except like that. If it gets invoked, you have > no idea why. A simple typo like ixd instead of idx or a(idx) instead > of a[idx] would raise an exception but give you no idea why. > > Do > try: > ... > except Exception,e: > print e > at the absolute minimum. > (Python 3 syntax would differ slightly, but the advice is the same.) > > Perhaps printing a traceback along with the exception would help. Add > traceback.print_exc() So here's the clencher without debating the merits bare except: since a bare catch(...) is totally acceptable in the c++ world. When I have except: by itself the program fails...but simply adding the "except Exception,e: " causes the program to work correctly. To me that signifies an undefined behavior of the python specification, or at least bad behavior of the python interpreter I'm using. If you can syntactically use a bare except: without generating an invalid syntax error then it should have a well defined and predictable outcome. If in fact the "except Exception, e:" is what's required then a bare except shouldn't be considered valid syntax at all, right? kind regards From tjreedy at udel.edu Mon Jan 27 01:21:41 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Jan 2014 01:21:41 -0500 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52E5E8F9.7000001@islandtraining.com> References: <52E5E8F9.7000001@islandtraining.com> Message-ID: On 1/27/2014 12:04 AM, Gary Herron wrote: > Do > try: > ... > except Exception,e: > print e > at the absolute minimum. > (Python 3 syntax would differ slightly, but the advice is the same.) The 'python 3' syntax except Exception as e: works in 2.7 and perhaps 2.6. So use it unless you need compatibility with even earlier versions. -- Terry Jan Reedy From larry at hastings.org Mon Jan 27 01:21:51 2014 From: larry at hastings.org (Larry Hastings) Date: Sun, 26 Jan 2014 22:21:51 -0800 Subject: [RELEASED] Python 3.4.0b3 Message-ID: <52E5FAFF.1080901@hastings.org> On behalf of the Python development team, I'm quite pleased to announce the third beta release of Python 3.4. This is a preview release, and its use is not recommended for production settings. Python 3.4 includes a range of improvements of the 3.x series, including hundreds of small improvements and bug fixes. Major new features and changes in the 3.4 release series include: * PEP 428, a "pathlib" module providing object-oriented filesystem paths * PEP 435, a standardized "enum" module * PEP 436, a build enhancement that will help generate introspection information for builtins * PEP 442, improved semantics for object finalization * PEP 443, adding single-dispatch generic functions to the standard library * PEP 445, a new C API for implementing custom memory allocators * PEP 446, changing file descriptors to not be inherited by default in subprocesses * PEP 450, a new "statistics" module * PEP 451, standardizing module metadata for Python's module import system * PEP 453, a bundled installer for the *pip* package manager * PEP 454, a new "tracemalloc" module for tracing Python memory allocations * PEP 456, a new hash algorithm for Python strings and binary data * PEP 3154, a new and improved protocol for pickled objects * PEP 3156, a new "asyncio" module, a new framework for asynchronous I/O Python 3.4 is now in "feature freeze", meaning that no new features will be added. The final release is projected for mid-March 2014. To download Python 3.4.0b3 visit: http://www.python.org/download/releases/3.4.0/ Please consider trying Python 3.4.0b3 with your code and reporting any new issues you notice to: http://bugs.python.org/ Enjoy! -- Larry Hastings, Release Manager larry at hastings.org (on behalf of the entire python-dev team and 3.4's contributors) From tjreedy at udel.edu Mon Jan 27 01:30:06 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Jan 2014 01:30:06 -0500 Subject: Highlighting program variables instead of keywords? In-Reply-To: <52e5b66d$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e5b66d$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/26/2014 8:29 PM, Steven D'Aprano wrote: > On Sun, 26 Jan 2014 18:31:49 -0600, Skip Montanaro wrote: > >> My son sent me a link to an essay about highlighting program data >> instead of keywords: >> >> https://medium.com/p/3a6db2743a1e/ >> >> I think this might have value, especially if to could bounce back and >> forth between both schemes. > > Hmmm, I'm not convinced, but then I wasn't convinced by syntax > highlighting either until I had used it for a while. (I still think it's > a nice-to-have rather than a must-have.) When my fingers get a bit fumbly, I find it more useful. When I do not hit ' or " solidly, or type a mismatch 'something", having the string literal color continue is a handy clue. So is 'it' not getting the keyword color that if would. -- Terry Jan Reedy From tjreedy at udel.edu Mon Jan 27 01:37:04 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Mon, 27 Jan 2014 01:37:04 -0500 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: On 1/26/2014 8:46 PM, Skip Montanaro wrote: > I think an interactive pylint (or pyflakes or frosty) type capability > would be useful, highlighting a subset of the messages it produces, > like variables which were assigned but never used, or using undefined > variables. It might be best supported by actually running the checker > in the background, then using its messages to direct where to > highlight suspect bits of code. One of my long-term goals for Idle is an extension that would run user-installed code analyzers over the contents of an edit window, with the output sent to an OutputWindow. Using the contents of the latter to mark things in the editor window is an interesting idea. That is already done for SyntaxErrors and traceback file:line references. -- Terry Jan Reedy From noone at all.net Mon Jan 27 01:42:21 2014 From: noone at all.net (me) Date: 27 Jan 2014 06:42:21 GMT Subject: buggy python interpretter or am I missing something here? References: <52E5E8F9.7000001@islandtraining.com> Message-ID: <52e5ffcd$0$29510$862e30e2@ngroups.net> On Mon, 27 Jan 2014 01:21:41 -0500, Terry Reedy wrote: > On 1/27/2014 12:04 AM, Gary Herron wrote: > >> Do >> try: >> ... >> except Exception,e: >> print e >> at the absolute minimum. >> (Python 3 syntax would differ slightly, but the advice is the same.) > > The 'python 3' syntax > except Exception as e: > works in 2.7 and perhaps 2.6. So use it unless you need compatibility > with even earlier versions. My point of contention isn't so much about what specific syntax I should be using as much as it is about being allowed to use a syntax that gives erroneous results without triggering a syntax violation. If the bare except: clause is syntactically legal then it should yield deterministic results based on a well defined language specification, right? It's looking very much like "except:" is undefined behaviour. kind regards From zachary.ware+pylist at gmail.com Mon Jan 27 01:47:13 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 27 Jan 2014 00:47:13 -0600 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e5f658$0$29583$862e30e2@ngroups.net> References: <52e5f658$0$29583$862e30e2@ngroups.net> Message-ID: On Mon, Jan 27, 2014 at 12:02 AM, me wrote: > On Mon, 27 Jan 2014 00:36:20 -0500, Dave Angel wrote: > >> sys.exit() raises an exception, and you're deliberately eating >> that exception. >> > > I can buy that sys.exit (may) be throwing an exception...My point of > contention isn't that I may be throwing one, but why would a subsequent > "raise" in the except: clause cause the point of program execution to > jump back up to the sys.exit(0) and then function correctly. You've missed the point here. sys.exit() *does* raise an exception: SystemExit, a subclass of BaseException. In fact, you can implement sys.exit in pure Python like so: def exit(status): raise SystemExit(status) Your bare 'except:' catches that SystemExit along with any other possible exception; the bare 'raise' in the except clause just re-raises the same SystemExit, which then does what you meant for it to do in the first place. Exception classes form a hierarchy, with BaseException being the base (obviously :)), "except:" is really just shorthand for "except BaseException:", and is very rarely a good idea. Deriving from BaseException are SystemExit, KeyboardInterrupt, and Exception. SystemExit is the exception raised by sys.exit(), which if left unhandled, the interpreter takes as a sign to shut down gracefully. KeyboardInterrupt is raised by Ctrl+C, or (more accurately, if I'm not mistaken) by sending SIGINT to the process. Exception is the base class for all other exceptions, such as TypeError, ValueError, OSError, etc., and is what you actually want to catch if you really don't care what exception is raised but want to handle it (though in most cases, you either should care, or should at least report what the exception was, preferably with a traceback...which is easiest to do by not trying to catch the exception at all). I would suggest skimming through the Python tutorial and/or language reference if you haven't before, there's a lot of good information in there that will make your life with Python much easier. And, please take this positively, but from your posted code it's fairly apparent that Python is not your native tongue :). For instance, you don't need the backslashes in your defaultparams assignment; the parser knows it needs to keep looking on subsequent lines when it hasn't found the closing '}' yet. Also, you can iterate over a (sys.argv) in a for loop, replacing 'l', 'idx', and the while loop; something like for arg in a: if arg == '-h': print help # help being defined elsewhere... elif arg == '-hh': # no really, print help print 'help' And the big one, argument parsing is a solved problem in Python. Check out the argparse module in the standard library (or if you're using an older version of Python, try either optparse or getopt. It's really a thrice-solved problem ;)). I hope I've been of some help, -- Zach From noone at all.net Mon Jan 27 01:46:03 2014 From: noone at all.net (me) Date: 27 Jan 2014 06:46:03 GMT Subject: buggy python interpretter or am I missing something here? References: Message-ID: <52e600ab$0$29542$862e30e2@ngroups.net> In any case, thanks for the answers guys. I'm satisfied that the except: syntax yields undefined behavior, and in my mind it shouldn't be syntactically allowed then. Updating to Exception,e or Exception as e fixes the problem. From zachary.ware+pylist at gmail.com Mon Jan 27 01:55:17 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 27 Jan 2014 00:55:17 -0600 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e600ab$0$29542$862e30e2@ngroups.net> References: <52e600ab$0$29542$862e30e2@ngroups.net> Message-ID: On Mon, Jan 27, 2014 at 12:46 AM, me wrote: > > In any case, thanks for the answers guys. I'm satisfied that the except: > syntax yields undefined behavior, and in my mind it shouldn't be > syntactically allowed then. It's not undefined, though; it is explicitly defined. See my other message, and here are a couple other places to skim through: http://docs.python.org/2/tutorial/errors.html and http://docs.python.org/2/library/exceptions.html -- Zach From gary.herron at islandtraining.com Mon Jan 27 02:03:51 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 26 Jan 2014 23:03:51 -0800 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e5fa05$0$29727$862e30e2@ngroups.net> References: <52e5fa05$0$29727$862e30e2@ngroups.net> Message-ID: <52E604D7.4070608@islandtraining.com> On 01/26/2014 10:17 PM, me wrote: > On Sun, 26 Jan 2014 21:04:57 -0800, Gary Herron wrote: > >> Never *ever* have a bare except like that. If it gets invoked, you have >> no idea why. A simple typo like ixd instead of idx or a(idx) instead >> of a[idx] would raise an exception but give you no idea why. >> >> Do >> try: >> ... >> except Exception,e: >> print e >> at the absolute minimum. >> (Python 3 syntax would differ slightly, but the advice is the same.) >> >> Perhaps printing a traceback along with the exception would help. Add >> traceback.print_exc() > > So here's the clencher without debating the merits bare except: since a > bare catch(...) is totally acceptable in the c++ world. > > When I have except: by itself the program fails...but simply adding the > "except Exception,e: " causes the program to work correctly. Doubtful. We've been doing this kind of stuff for decades without hitting your supposed bug. Much more likely is that you've misinterpreted the results. Ii don't know how, but I'm quite confident that you have. Your contention that the raise goes back to the sys.exit() is certainly a mis-interpretation also. The re-raise of the original exception is now an uncaught exception, and the interpreter's response to an uncaught exception is to kill the program. Nearly the same result as the sys.exit(), but via a different pathway. > > To me that signifies an undefined behavior of the python specification, > or at least bad behavior of the python interpreter I'm using. If you can > syntactically use a bare except: without generating an invalid syntax > error then it should have a well defined and predictable outcome. It is well defined. Slow down a bit, rerun your two tests, show is the code *and* the results, and we'll get to the bottom of this. > > If in fact the "except Exception, e:" is what's required then a bare > except shouldn't be considered valid syntax at all, right? Bare excepts are perfectly legal valid syntax and have their uses, however it's just extremely dangerous programming to allow a simple typo (or any of an infinite number of possible errors) in your try section to masquerade as a "error in command line" (to quote your print at that point). Python's dynamic typing makes bare except extremely dangerous. In Python, unlike C, any number of typos can be syntactically correct, but meaningless, exception-raising actions at run time. Things like misspelling a variable/function name, substituting a comma for a decimal point, indexing something that is not indexable, applying a function to the wrong parameters or wrong number of parameters, ... All these are *not* syntax errors (as they would be in C), but will cause a run-time exception -- and you'd never know why with that bare except blindly catching them all and claiming "command line error". Gary Herron > > kind regards From gary.herron at islandtraining.com Mon Jan 27 02:12:18 2014 From: gary.herron at islandtraining.com (Gary Herron) Date: Sun, 26 Jan 2014 23:12:18 -0800 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e600ab$0$29542$862e30e2@ngroups.net> References: <52e600ab$0$29542$862e30e2@ngroups.net> Message-ID: <52E606D2.40606@islandtraining.com> On 01/26/2014 10:46 PM, me wrote: > In any case, thanks for the answers guys. I'm satisfied that the except: > syntax yields undefined behavior, and in my mind it shouldn't be > syntactically allowed then. > > Updating to Exception,e or Exception as e fixes the problem. > That's an irksome habit you have there, this jumping to (incorrect) conclusions so quickly. We'd like to get to the bottom of this. (And correct your mis-interpretations while we're at it :-) But we need to see your test *and* the results. Gary Herron From noone at all.net Mon Jan 27 02:17:43 2014 From: noone at all.net (me) Date: 27 Jan 2014 07:17:43 GMT Subject: buggy python interpretter or am I missing something here? References: <52e5f658$0$29583$862e30e2@ngroups.net> Message-ID: <52e60817$0$29774$862e30e2@ngroups.net> On Mon, 27 Jan 2014 00:47:13 -0600, Zachary Ware wrote: > You've missed the point here. sys.exit() *does* raise an exception: > SystemExit, a subclass of BaseException. In fact, you can implement > sys.exit in pure Python like so: > > def exit(status): > raise SystemExit(status) > > Your bare 'except:' catches that SystemExit along with any other > possible exception; the bare 'raise' in the except clause just re-raises > the same SystemExit, which then does what you meant for it to do in the > first place. Well that does change things a bit and makes perfect sense now. Thx! > And, please take this positively, but from your posted code it's fairly > apparent that Python is not your native tongue :). Correct. The barbarians invaded my homeland and forced me to speak their wicked incantations. I'm a c/c++ guy through and through with a sprinkling of the ancient tongues like algol, LSI-11 and Z80 assembler, fortran-4, etc. My python stuff is all rapid application development for personal projects. If I need to do anything serious I take the time to do it in C+ +. > For instance, you > don't need the backslashes in your defaultparams assignment; the parser > knows it needs to keep looking on subsequent lines when it hasn't found > the closing '}' yet. It's the intendation specific requirements that throw me. I haven't seen such a hork since RPG. ;^) > Also, you can iterate over a (sys.argv) in a for > loop, replacing 'l', 'idx', and the while loop; something like > > for arg in a: > if arg == '-h': > print help # help being defined elsewhere... > elif arg == '-hh': > # no really, print help print 'help' Understood, except that some parameters take multiple elements...thus why I manually reference the indexes. > And the big one, argument parsing is a solved problem in Python. Check > out the argparse module in the standard library (or if you're using an > older version of Python, try either optparse or getopt. It's really a > thrice-solved problem ;)). Yup. Every language and platform has multiple arg parsing libraries. Didn't feel like taking the time to research any since most of my python ramblings are usually pyQT4 bindings to QT4 gui and postgresql apps. > > I hope I've been of some help, Pointing out that sys.exit() raises a low level exception was the point I was missing. Thx! From noone at all.net Mon Jan 27 02:20:55 2014 From: noone at all.net (me) Date: 27 Jan 2014 07:20:55 GMT Subject: buggy python interpretter or am I missing something here? References: <52e5fa05$0$29727$862e30e2@ngroups.net> Message-ID: <52e608d7$0$29681$862e30e2@ngroups.net> On Sun, 26 Jan 2014 23:03:51 -0800, Gary Herron wrote: found the part I was missing based on another response. Didn't realize that sys.exit() triggered an instance of "BaseException" and that explains the weird behavior. thx! From ethan at stoneleaf.us Mon Jan 27 02:08:06 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Jan 2014 23:08:06 -0800 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e5ffcd$0$29510$862e30e2@ngroups.net> References: <52E5E8F9.7000001@islandtraining.com> <52e5ffcd$0$29510$862e30e2@ngroups.net> Message-ID: <52E605D6.9090506@stoneleaf.us> On 01/26/2014 10:42 PM, me wrote: > > My point of contention isn't so much about what specific syntax I should > be using as much as it is about being allowed to use a syntax that gives > erroneous results without triggering a syntax violation. If the bare > except: clause is syntactically legal then it should yield deterministic > results based on a well defined language specification, right? It's > looking very much like "except:" is undefined behaviour. There is nothing undefined about it. `except:` catches everything. Occasionally there is a good reason to do it that way, but under typical circumstances you tell 'except' which exceptions you are prepared to deal with. -- ~Ethan~ From noone at all.net Mon Jan 27 02:30:06 2014 From: noone at all.net (me) Date: 27 Jan 2014 07:30:06 GMT Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> Message-ID: <52e60afe$0$29498$862e30e2@ngroups.net> On Sun, 26 Jan 2014 23:12:18 -0800, Gary Herron wrote: > On 01/26/2014 10:46 PM, me wrote: >> In any case, thanks for the answers guys. I'm satisfied that the >> except: >> syntax yields undefined behavior, and in my mind it shouldn't be >> syntactically allowed then. >> >> Updating to Exception,e or Exception as e fixes the problem. >> >> > That's an irksome habit you have there, this jumping to (incorrect) > conclusions so quickly. We'd like to get to the bottom of this. (And > correct your mis-interpretations while we're at it :-) But we need to > see your test *and* the results. > > Gary Herron Problem solved. I understand what was happening now with the "raise" following the bare except: Since this code is for a personal research project I'm not as concerned about code quality as I would be if I was getting paid to write production code...and if it was production code I'd only prototype a proof-of-concept in python and then rewrite in c++. The project is to take advantage of all 16 CPU cores to process A LOT of GPS data for a 3d map-making and visualization project. Now my bottleneck may end up being the python global lock when doing concurrent processing...but we'll see. From georg at python.org Mon Jan 27 02:36:46 2014 From: georg at python.org (Georg Brandl) Date: Mon, 27 Jan 2014 08:36:46 +0100 Subject: [RELEASED] Python 3.3.4 release candidate 1 Message-ID: <52E60C8E.1050908@python.org> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On behalf of the Python development team, I'm reasonably happy to announce the Python 3.3.4 release candidate 1. Python 3.3.4 includes several security fixes and over 120 bug fixes compared to the Python 3.3.3 release. This release fully supports OS X 10.9 Mavericks. In particular, this release fixes an issue that could cause previous versions of Python to crash when typing in interactive mode on OS X 10.9. Python 3.3 includes a range of improvements of the 3.x series, as well as easier porting between 2.x and 3.x. In total, almost 500 API items are new or improved in Python 3.3. For a more extensive list of changes in the 3.3 series, see http://docs.python.org/3.3/whatsnew/3.3.html and for the detailed changelog of 3.3.4, see http://docs.python.org/3.3/whatsnew/changelog.html To download Python 3.3.4 rc1 visit: http://www.python.org/download/releases/3.3.4/ This is a preview release, please report any bugs to http://bugs.python.org/ The final version is scheduled to be released in two weeks' time, on or about the 10th of February. Enjoy! - -- Georg Brandl, Release Manager georg at python.org (on behalf of the entire python-dev team and 3.3's contributors) -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iEYEARECAAYFAlLmDI4ACgkQN9GcIYhpnLAr6wCePRbHF80k5goV4RUDBA5FfkwF rLUAnRg0RpL/b6apv+Dt2/sgnUd3hTPA =Z4Ss -----END PGP SIGNATURE----- From ethan at stoneleaf.us Mon Jan 27 02:17:29 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Sun, 26 Jan 2014 23:17:29 -0800 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e600ab$0$29542$862e30e2@ngroups.net> References: <52e600ab$0$29542$862e30e2@ngroups.net> Message-ID: <52E60809.6050308@stoneleaf.us> On 01/26/2014 10:46 PM, me wrote: > > [...] I'm satisfied that the except: syntax yields > undefined behavior, and in my mind it shouldn't be > syntactically allowed then. Two points: 1) Python is not C++ 2) You asked for help; you received it. Coming back with an attitude of "Python must be broken, I'll work around it" is going to quickly lose you the support of those willing to help again. From noone at all.net Mon Jan 27 02:44:41 2014 From: noone at all.net (me) Date: 27 Jan 2014 07:44:41 GMT Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> Message-ID: <52e60e69$0$29774$862e30e2@ngroups.net> On Sun, 26 Jan 2014 23:17:29 -0800, Ethan Furman wrote: > On 01/26/2014 10:46 PM, me wrote: >> >> [...] I'm satisfied that the except: syntax yields undefined behavior, >> and in my mind it shouldn't be >> syntactically allowed then. > > Two points: > > 1) Python is not C++ > > 2) You asked for help; you received it. Coming back > with an attitude of "Python must be broken, I'll work around it" > is going to quickly lose you the support of those willing to help > again. Whatever...lighten up dude! From jeandupont115 at gmail.com Mon Jan 27 03:23:13 2014 From: jeandupont115 at gmail.com (Jean Dupont) Date: Mon, 27 Jan 2014 00:23:13 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> <45d3da88-7881-49be-b35f-b579350e12d3@googlegroups.com> Message-ID: <251d166b-4fd3-4781-9a47-c4438eecd61c@googlegroups.com> Op woensdag 22 januari 2014 16:43:21 UTC+1 schreef Alister: > On Wed, 22 Jan 2014 06:45:53 -0800, Jean Dupont wrote: > > > Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister: > >> On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: > >> > >> > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: > >> >> On 18 January 2014 14:52, Jean Dupont > >> >> wrote: > >> >> > > >> >> > Thanks Peter and Terry Jan for the useful suggestions. One thing > >> >> > which I > >> >> >find a bit weird: when asking for Python-help concerning raspberry > >> Personally use Geany stand alone and not under idle, pressing F5 > >> should save & run the code you are currently editing. Would running > >> under idle give any other benefits? > > I don't know yet, but I just wanted to try out which of the following > > three I'd like best: > > 1. idle+leafpad 2. idle+geany 3. plain geany > > > > It's normal for a newbie to start with (1) as that is the default on > > raspbian, > > however I still don't understand why (2) does not work... > > > When I play with my Pi I tend to use another computer for all my editing > (sshfs is a quick & easy way for me to mount the necessary parts of the > PI file system so I don't have to keep transferring files) Thanks for the suggestion, I'm going to try it out kind regards, jean From jeandupont115 at gmail.com Mon Jan 27 03:28:03 2014 From: jeandupont115 at gmail.com (Jean Dupont) Date: Mon, 27 Jan 2014 00:28:03 -0800 (PST) Subject: [newbie] advice and comment wanted on first tkinter program In-Reply-To: <45d3da88-7881-49be-b35f-b579350e12d3@googlegroups.com> References: <79c02d3e-cf6f-4aaa-bf71-4614a272e88d@googlegroups.com> <2ffb1f76-7e51-46db-bc4a-de2c3efc90ba@googlegroups.com> <7aebab9e-d176-4927-9264-1d0b755f768c@googlegroups.com> <45d3da88-7881-49be-b35f-b579350e12d3@googlegroups.com> Message-ID: Op woensdag 22 januari 2014 15:45:53 UTC+1 schreef Jean Dupont: > Op maandag 20 januari 2014 10:17:15 UTC+1 schreef Alister: > > On Sun, 19 Jan 2014 20:04:05 -0800, Jean Dupont wrote: > > > > > Op zaterdag 18 januari 2014 16:12:41 UTC+1 schreef Oscar Benjamin: > > >> On 18 January 2014 14:52, Jean Dupont wrote: > > >> > > > >> > Thanks Peter and Terry Jan for the useful suggestions. One thing > > >> > which I > > >> >find a bit weird: when asking for Python-help concerning raspberry pi > > >> >code > > >> > or problems, a lot of people don't seem to be interested in helping > > >> > out, > > >> > that's of course their choice, but maybe they don't seem to be aware > > >> > the raspberry pi is often the motivation for starting to learn to > > >> > program in > > >> >Python. And as such such a reaction is a bit disappointing. > > >> Hi Jean, > > >> What makes you say that? Did you previously ask questions about > > >> Rasberry Pi code on this list? > > > It was not about code but about python-coding in IDLE (that's the > > > default on raspbian): > > > I started a thread "[newbie] starting geany from within idle does not > > > work" both here and in the raspberry pi forum. I just wondered why I > > > never got an answer concerning that topic. > > > > > >> If you did I wouldn't have answered those questions because I've never > > >> used a Raspberry Pi and know nothing about them (except that they > > >> encourage using Python somehow). I think that there's actually a list > > >> that is specifically for Raspberry Pi Python questions that might be > > >> more helpful although I don't know what it is... > > > Here is the url to that forum > > > > > > http://www.raspberrypi.org/forum/ > > > > > > kind regards, > > > jean > > > > Personally use Geany stand alone and not under idle, pressing F5 should > > save & run the code you are currently editing. Would running under idle > > give any other benefits? > I don't know yet, but I just wanted to try out which of the following three I'd like best: > 1. idle+leafpad > 2. idle+geany > 3. plain geany > > It's normal for a newbie to start with (1) as that is the default on raspbian, > however I still don't understand why (2) does not work... I finally found out where I was wrong: leafpad is _not_ the default choice in IDLE, IDLE has its own built in editor and IDLE does not allow to use another editor. The confusion stemmed from the properties I got when right clicking on the IDLE-icon on the raspbian desktop, which shows "Open with" and then suggests the default choice is Leafpad and Geany as a second choice, it has however nothin to do with IDLE as such. kind regards, jean From mail at timgolden.me.uk Mon Jan 27 03:40:56 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Mon, 27 Jan 2014 08:40:56 +0000 Subject: Help: python 3.3.3 (AMD64) scripts fail as non-admin user on Windows Server 2012 R2 In-Reply-To: References: Message-ID: <52E61B98.7000609@timgolden.me.uk> On 26/01/2014 22:30, Luis Marsano wrote: > I've installed python for all users with full permissions to all users > (see picture). > Python runs for all users. > However, scripts only work when I run as Administrator. > Running a script always results in an "ImportError: cannot import name" error. As Steven's pointed out, this looks more like a Windows permissions issue. However, it would still be worth identifying what's going on, as I haven't run Python on a 2012 box (and I doubt if many other people have either). I'm getting a VM run up to try it out but that will take a while. It may be that some hardened security is preventing Python from reading its own files. Could you, please, do the simplest of imports which fails, and post the traceback from the console in its entirety? (In other words, something like this): """ Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import willnotimport Traceback (most recent call last): File "", line 1, in ImportError: No module named 'willnotimport' >>> """ It would be good to know whether *anything* imports, ie whether stdlib imports work, or whether it's just user-installed modules. Thanks TJG From __peter__ at web.de Mon Jan 27 03:45:24 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Jan 2014 09:45:24 +0100 Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60afe$0$29498$862e30e2@ngroups.net> Message-ID: me wrote: Not me, you ;) > Since this code is for a personal research project I'm not as concerned > about code quality as I would be if I was getting paid to write > production code...and if it was production code I'd only prototype a > proof-of-concept in python and then rewrite in c++. Another way to improve code quality is to write less code yourself and instead to rely on well-tested libraries: import argparse parser = argparse.ArgumentParser() parser.add_argument("-d", "--basedir", default="/process") parser.add_argument("-i", "--inpipe", default="/tmp/TCdaemonIN") parser.add_argument("-#", "--maxjobs", type=int, default=8) parser.add_argument("-o", "--outpipe", default="/tmp/TCdaemonOUT") print parser.parse_args() Seriously, code quality doesn't magically improve by a switch of language. You may make fewer newbie errors in C++, but once you get over the instinctive "Ducktype and unit tests? I'll do it with these three undebuggable templates and get type checks for free from the compiler." the simpler and often more concise Python solutions will start to pay off. From __peter__ at web.de Mon Jan 27 03:54:49 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Jan 2014 09:54:49 +0100 Subject: Lists inside dictionary and how to look for particular value References: <4ef4e919-2db6-4ded-9894-fd3872c3d17c@googlegroups.com> <58821aa9-8b98-458f-a775-f79d741505cb@googlegroups.com> Message-ID: mick verdu wrote: > ThanK you. It solved my problem. > Can someone tell me how can i print particular value inside list of key. > > I know how to print J['PC2'][1] means will print IP. but I want the user > to input some element and I will print element just before that element. > > e.g. if user inputs 192.168.0.2, program will print 02:02:02:02:02:02. > If user inputs 192.168.0.1 I will print 01:01:01:01:01:01. IP_INDEX = 1 MAC_INDEX = 0 record = J["PC2"] def is_ip(s): return "." in s def is_mac(s): return ":" in s s = raw_input("Enter MAC or IP: " if is_mac(s): print record[IP_INDEX] elif is_ip(s): print record[MAC_INDEX] else: print "not a MAC or IP" You can of course replace the is_ip() and is_mac() implementation with better ones. From rosuav at gmail.com Mon Jan 27 04:01:33 2014 From: rosuav at gmail.com (Chris Angelico) Date: Mon, 27 Jan 2014 20:01:33 +1100 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e60e69$0$29774$862e30e2@ngroups.net> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> Message-ID: On Mon, Jan 27, 2014 at 6:44 PM, me wrote: > On Sun, 26 Jan 2014 23:17:29 -0800, Ethan Furman wrote: > >> On 01/26/2014 10:46 PM, me wrote: >>> >>> [...] I'm satisfied that the except: syntax yields undefined behavior, >>> and in my mind it shouldn't be >>> syntactically allowed then. >> >> Two points: >> >> 1) Python is not C++ >> >> 2) You asked for help; you received it. Coming back >> with an attitude of "Python must be broken, I'll work around it" >> is going to quickly lose you the support of those willing to help >> again. > > > Whatever...lighten up dude! When you use a language, you should be working with it, not fighting against it. It doesn't do to complain that REXX ought to have IEEE floating-point semantics, or that 8086 assembly language really would benefit from a native hashtable type. Python works a certain way, and part of that is its use of exceptions - which are integral to the language, rather than being (as in C++) somewhat tacked-on. Assuming that anything that isn't the way you expect it is inherently broken, and saying so on a mailing list, is a good way to alienate those who are offering you help for no reimbursement... and "lighten up dude" doesn't help. ChrisA From noone at all.net Mon Jan 27 04:32:43 2014 From: noone at all.net (me) Date: 27 Jan 2014 09:32:43 GMT Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> Message-ID: <52e627bb$0$29811$862e30e2@ngroups.net> On Mon, 27 Jan 2014 20:01:33 +1100, Chris Angelico wrote: > On Mon, Jan 27, 2014 at 6:44 PM, me wrote: >> On Sun, 26 Jan 2014 23:17:29 -0800, Ethan Furman wrote: >> >>> On 01/26/2014 10:46 PM, me wrote: >>>> >>>> [...] I'm satisfied that the except: syntax yields undefined >>>> behavior, >>>> and in my mind it shouldn't be >>>> syntactically allowed then. >>> >>> Two points: >>> >>> 1) Python is not C++ >>> >>> 2) You asked for help; you received it. Coming back >>> with an attitude of "Python must be broken, I'll work around it" >>> is going to quickly lose you the support of those willing to >>> help again. >> >> >> Whatever...lighten up dude! > > When you use a language, you should be working with it, not fighting > against it. It doesn't do to complain that REXX ought to have IEEE > floating-point semantics, or that 8086 assembly language really would > benefit from a native hashtable type. Python works a certain way, and > part of that is its use of exceptions - which are integral to the > language, rather than being (as in C++) somewhat tacked-on. Assuming > that anything that isn't the way you expect it is inherently broken, and > saying so on a mailing list, is a good way to alienate those who are > offering you help for no reimbursement... and "lighten up dude" doesn't > help. > > ChrisA You feel better now that you too have vented? I had a productive discussion with a couple of top level posters who helped me solve my problem and they receive appropriate kuddos. Now it seems that some lonely individuals who maybe just want some attention are coming out of the woodwork. The thread is done so lets give it a rest. The condescending attitude about proper USENET tech help is just as annoying as perhaps my "opinions" seem. If someone is so sensitive as to not be able to discuss a technical matter without making it personal or seeing it as an attack against their religion then I neither want nor need their input. There are plenty of technical resources in the world that don't require idol worship. Regards From lele at metapensiero.it Mon Jan 27 05:08:35 2014 From: lele at metapensiero.it (Lele Gaifax) Date: Mon, 27 Jan 2014 11:08:35 +0100 Subject: Highlighting program variables instead of keywords? References: Message-ID: <87txcp4tzw.fsf@nautilus.nautilus> Skip Montanaro writes: > I think this might have value, especially if to could bounce back and forth > between both schemes. Is anyone aware of tools like this for Python? Bonus > points for pointers to an Emacs implementation. There has been a recent thread on some emacs group about this. Dunno how far it has gone wrt Python support, but the following mode appeared in MELPA archives in the last couple of days: https://github.com/ankurdave/color-identifiers-mode hth, 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 alister.ware at ntlworld.com Mon Jan 27 07:19:35 2014 From: alister.ware at ntlworld.com (Alister) Date: Mon, 27 Jan 2014 12:19:35 GMT Subject: buggy python interpretter or am I missing something here? References: <52e5f658$0$29583$862e30e2@ngroups.net> <52e60817$0$29774$862e30e2@ngroups.net> Message-ID: O > My python stuff is all rapid application development for personal > projects. If I need to do anything serious I take the time to do it in > C+ > +. Many people "Prototype" in python & then re-factor into a compiled language later if needed (often it turns out there is not really any need :-) ) > > It's the intendation specific requirements that throw me. I haven't > seen such a hork since RPG. ;^) > But i bet you almost certainly indent your C++ cod in a similar manor on a voluntary basis, don't worry you will soon get used to it & quite probably start to like it. -- Hempstone's Question: If you have to travel on the Titanic, why not go first class? From neilc at norwich.edu Mon Jan 27 07:56:13 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Mon, 27 Jan 2014 12:56:13 +0000 (UTC) Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> Message-ID: On 2014-01-27, me wrote: > The thread is done so lets give it a rest. The condescending > attitude about proper USENET tech help is just as annoying as > perhaps my "opinions" seem. If someone is so sensitive as to > not be able to discuss a technical matter without making it > personal or seeing it as an attack against their religion then > I neither want nor need their input. There are plenty of > technical resources in the world that don't require idol > worship. Oh, it's all right. I'm sure that we can handle this situation maturely, just like the responsible adults that we are. Isn't that right, Mr... Poopy-Pants? -- Neil Cerutti From matt.s.marotta at gmail.com Mon Jan 27 08:32:08 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Mon, 27 Jan 2014 05:32:08 -0800 (PST) Subject: Remove unwanted characters from column In-Reply-To: References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> Message-ID: <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> On Monday, 27 January 2014 00:24:11 UTC-5, Dave Angel wrote: > matt.s.marotta at gmail.com Wrote in message: > > > School assignment is to create a tab separated output with the original given addresses in one column and then the addresses split into other columns (ex, columns for city, postal code, street suffix). > > > > > > Here is my code: > > > > > > inHandler = open(inFile, 'r') > > > outHandler = open(outFile, 'w') > > > outHandler.write("FarmID\tAddress\tStreetNum\tStreetName\tSufType\tDir\tCity\tProvince\tPostalCode") > > > for line in inHandler: > > > str = line.replace("FarmID\tAddress", " ") > > > outHandler.write(str[0:-1]) > > > > > > str = str.replace(" ","\t", 1) > > > str = str.replace(" Rd, ","\tRd\t\t") > > > str = str.replace("Rd ","\tRd\t\t") > > > str = str.replace("Ave, ","\tAve\t\t") > > > str = str.replace("Ave ","\tAve\t\t") > > > str = str.replace("St ","\tSt\t\t") > > > str = str.replace("St, ","\tSt\t\t") > > > str = str.replace("Dr, ","\tDr\t\t") > > > str = str.replace("Lane, ","\tLane\t\t") > > > str = str.replace("Pky, ","\tPky\t\t") > > > str = str.replace(" Sq, ","\tSq\t\t") > > > str = str.replace(" Pl, ","\tPl\t\t") > > > > > > str = str.replace("\tE, ","E\t") > > > str = str.replace("\tN, ","N\t") > > > str = str.replace("\tS, ","S\t") > > > str = str.replace("\tW, ","W\t") > > > str = str.replace(",\t","\t\t") > > > str = str.replace(", ON ","\tON\t") > > > > > > outHandler.write(str) > > > > > > inHandler.close() > > > outHandler.close() > > > > > > > > > Here is some sample addresses, there are over 100: > > > > > > FarmID Address > > > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > > > 2 4260 Mountainview Rd, Lincoln, ON L0R 1B2 > > > 3 25 Hunter Rd, Grimsby, ON L3M 4A3 > > > 4 1091 Hutchinson Rd, Haldimand, ON N0A 1K0 > > > 5 5172 Green Lane Rd, Lincoln, ON L0R 1B3 > > > 6 500 Glenridge Ave, St. Catharines, ON L2S 3A1 > > > 7 471 Foss Rd, Pelham, ON L0S 1C0 > > > 8 758 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0 > > > 9 3836 Main St, Lincoln, ON L0R 1S0 > > > > > > > > > > > > I have everything worked out, except that the final output places the farmID at the end of postal code as seen in the example below (notice the brackets showing where the farmID is placed): > > > > > > FarmID Address StreetNum StreetName SufType Dir City Province PostalCode > > > 1 1067 Niagara Stone Rd, Niagara-On-The-Lake, ON L0S 1J0(1) 1067 Niagara Stone Rd Niagara-On-The-Lake ON L0S 1J0 > > > > > > Any ideas on how to fix this? Keep in mind as well that the farmID will have 2 characters at a certain point. > > > > > > > Your specific concern is triggered by having two writes in the loop. > > > > Get rid of the first and you're marginally closer. > > > > But really, you've got much bigger troubles. All those > > unrestricted replace calls are not at all robust. But maybe > > you'll get away with it for a school assignment if the test data > > is very limited. > > > > Better would be to treat it like a parsing problem, figuring what > > delimiter rule applies to each field, and building a list Then > > use str.join to build the line for the outHandler. > > > > > > -- > > DaveA The code that I used is the proper way that we were supposed to complete the assignment. All I need now is an 'if...then' statement to get rid of the unwanted FarmID at the end of the addresses. I just don't know what will come after the 'if' part. From breamoreboy at yahoo.co.uk Mon Jan 27 08:32:06 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 13:32:06 +0000 Subject: Unwanted Spaces and Iterative Loop In-Reply-To: References: <988fec60-228a-4427-b07e-b4327c7e02ae@googlegroups.com> <52e5aafa$0$29999$c3e8da3$5496439d@news.astraweb.com> <0503362d-7f14-441f-9291-75711eddd283@googlegroups.com> Message-ID: On 27/01/2014 01:58, matt.s.marotta at gmail.com wrote: > On Sunday, 26 January 2014 20:56:01 UTC-5, Chris Angelico wrote: >> On Mon, Jan 27, 2014 at 12:15 PM, wrote: >> >>> I`m not reading and writing to the same file, I just changed the actual paths to directory. >> >> >> >> For next time, say "directory1" and "directory2" to preserve the fact >> >> that they're different. Though if they're file names, I'd use "file1" >> >> and "file2" - calling them "directory" implies that they are, well, >> >> directories :) >> >> >> >> ChrisA > > Thanks, but any chance you could help me out with my question of removing the FarmID from the postal code? > Any chance that you could read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above? -- 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 Jan 27 08:38:46 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 13:38:46 +0000 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: On 27/01/2014 01:46, Skip Montanaro wrote: >> What it is doing is color coding user-supplied identifiers, with different >> color for each one. I found that confusing to read. > > I think it would take some time to get used to, and I don't think it > would be the only way I'd like to view my program. > > I think an interactive pylint (or pyflakes or frosty) type capability > would be useful, highlighting a subset of the messages it produces, > like variables which were assigned but never used, or using undefined > variables. It might be best supported by actually running the checker > in the background, then using its messages to direct where to > highlight suspect bits of code. > > Skip > Pydev uses pylint interactively, must have saved me hours by flagging up (potential) problems up as I type. -- 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 Jan 27 08:48:24 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 13:48:24 +0000 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e60817$0$29774$862e30e2@ngroups.net> References: <52e5f658$0$29583$862e30e2@ngroups.net> <52e60817$0$29774$862e30e2@ngroups.net> Message-ID: On 27/01/2014 07:17, me wrote: > My python stuff is all rapid application development for personal > projects. If I need to do anything serious I take the time to do it in C+ > +. > For me at least you'll fit in extremely well here with a sense of humour like that. -- 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 Jan 27 08:55:50 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 13:55:50 +0000 Subject: [RELEASED] Python 3.3.4 release candidate 1 In-Reply-To: <52E60C8E.1050908@python.org> References: <52E60C8E.1050908@python.org> Message-ID: On 27/01/2014 07:36, Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm reasonably happy to announce the > Python 3.3.4 release candidate 1. > "Reasonably" happy? Is there a smiley missing there, or what? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From steve+comp.lang.python at pearwood.info Mon Jan 27 08:54:20 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Jan 2014 13:54:20 GMT Subject: Remove unwanted characters from column References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> Message-ID: <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jan 2014 05:32:08 -0800, matt.s.marotta wrote: > The code that I used is the proper way that we were supposed to complete > the assignment. All I need now is an 'if...then' statement to get rid > of the unwanted FarmID at the end of the addresses. I just don't know > what will come after the 'if' part. Show us what you do know. If you don't know the "if", what about the "then"? if .... : do what? What do you intend to do inside the if? Under what circumstances would you do it? If you can answer those questions in English, then we can help you write code to do it. -- Steven From steve+comp.lang.python at pearwood.info Mon Jan 27 08:56:02 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Jan 2014 13:56:02 GMT Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> Message-ID: <52e66572$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jan 2014 09:32:43 +0000, some guy who calls himself "me" wrote: > On Mon, 27 Jan 2014 20:01:33 +1100, Chris Angelico wrote: > >> On Mon, Jan 27, 2014 at 6:44 PM, me wrote: >>> On Sun, 26 Jan 2014 23:17:29 -0800, Ethan Furman wrote: >>> >>>> On 01/26/2014 10:46 PM, me wrote: >>>>> >>>>> [...] I'm satisfied that the except: syntax yields undefined >>>>> behavior, >>>>> and in my mind it shouldn't be >>>>> syntactically allowed then. >>>> >>>> Two points: >>>> >>>> 1) Python is not C++ >>>> >>>> 2) You asked for help; you received it. Coming back >>>> with an attitude of "Python must be broken, I'll work around >>>> it" is going to quickly lose you the support of those willing >>>> to help again. >>> >>> >>> Whatever...lighten up dude! >> >> When you use a language, you should be working with it, not fighting >> against it. It doesn't do to complain that REXX ought to have IEEE >> floating-point semantics, or that 8086 assembly language really would >> benefit from a native hashtable type. Python works a certain way, and >> part of that is its use of exceptions - which are integral to the >> language, rather than being (as in C++) somewhat tacked-on. Assuming >> that anything that isn't the way you expect it is inherently broken, >> and saying so on a mailing list, is a good way to alienate those who >> are offering you help for no reimbursement... and "lighten up dude" >> doesn't help. >> >> ChrisA > > You feel better now that you too have vented? I had a productive > discussion with a couple of top level posters who helped me solve my > problem and they receive appropriate kuddos. Now it seems that some > lonely individuals who maybe just want some attention are coming out of > the woodwork. A word to the wise: Chris is one of the most frequent and helpful posters here. So is Ethan. Both of them know what they're talking about, so when they give you advice, you could do a lot worse than to listen. Some examples of "a lot worse": you could arrogantly dismiss them by saying "whatever". Or you could make assumptions about their personal lives ("lonely individuals"). [Aside: you seem to be making a habit of jumping to wrong conclusions based on incorrect and illogical interpretations of minimal evidence. That's a poor habit to get into, and especially poor for a programmer.] > The thread is done so lets give it a rest. The condescending attitude > about proper USENET tech help is just as annoying as perhaps my > "opinions" seem. If someone is so sensitive as to not be able to > discuss a technical matter without making it personal or seeing it as an > attack against their religion then I neither want nor need their input. > There are plenty of technical resources in the world that don't require > idol worship. What does idol worship have to do with anything? Oh wait, do you think Ethan and Chris are pissed off because you're not genuflecting at Python's awesomeness? That's another comically wrong conclusion. -- Steven From matt.s.marotta at gmail.com Mon Jan 27 09:23:13 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Mon, 27 Jan 2014 06:23:13 -0800 (PST) Subject: Remove unwanted characters from column In-Reply-To: <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> On Monday, 27 January 2014 08:54:20 UTC-5, Steven D'Aprano wrote: > On Mon, 27 Jan 2014 05:32:08 -0800, matt.s.marotta wrote: > > > > > The code that I used is the proper way that we were supposed to complete > > > the assignment. All I need now is an 'if...then' statement to get rid > > > of the unwanted FarmID at the end of the addresses. I just don't know > > > what will come after the 'if' part. > > > > Show us what you do know. If you don't know the "if", what about the > > "then"? > > > > > > if .... : > > do what? > > > > > > What do you intend to do inside the if? Under what circumstances would > > you do it? > > > > If you can answer those questions in English, then we can help you write > > code to do it. > > > > > > -- > > Steven If the farmID < 10: remove one character from the address column Elif farmID > 10: remove two characters from the address column From breamoreboy at yahoo.co.uk Mon Jan 27 09:34:01 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 14:34:01 +0000 Subject: Remove unwanted characters from column In-Reply-To: <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> Message-ID: On 27/01/2014 14:23, matt.s.marotta at gmail.com wrote: > On Monday, 27 January 2014 08:54:20 UTC-5, Steven D'Aprano wrote: >> On Mon, 27 Jan 2014 05:32:08 -0800, matt.s.marotta wrote: >> >> >> >>> The code that I used is the proper way that we were supposed to complete >> >>> the assignment. All I need now is an 'if...then' statement to get rid >> >>> of the unwanted FarmID at the end of the addresses. I just don't know >> >>> what will come after the 'if' part. >> >> >> >> Show us what you do know. If you don't know the "if", what about the >> >> "then"? >> >> >> >> >> >> if .... : >> >> do what? >> >> >> >> >> >> What do you intend to do inside the if? Under what circumstances would >> >> you do it? >> >> >> >> If you can answer those questions in English, then we can help you write >> >> code to do it. >> >> >> >> >> >> -- >> >> Steven > > If the farmID < 10: > remove one character from the address column > Elif farmID > 10: > remove two characters from the address column > Would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Jan 27 09:38:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 14:38:05 +0000 Subject: EncodedFile/StreamRecoder Message-ID: I'd never heard of these and personally have no use for them, but came across them here http://bugs.python.org/issue20405#msg209430 and thought they might be of use to some of you. Quoting from the message:- "The purpose of EncodedFile/StreamRecoder was to convert an externally used encoding to a standard internal one - mainly to allow programs that didn't want to use Unicode for processing to still benefit from the codecs that come with Python. E.g. the example at the end of codecs.py allows using Latin-1 within the application, while talking to the console using UTF-8." -- 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 Mon Jan 27 09:57:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 01:57:32 +1100 Subject: Remove unwanted characters from column In-Reply-To: <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> Message-ID: On Tue, Jan 28, 2014 at 1:23 AM, wrote: > If the farmID < 10: > remove one character from the address column > Elif farmID > 10: > remove two characters from the address column What if farmID == 10? ChrisA From matt.s.marotta at gmail.com Mon Jan 27 10:03:36 2014 From: matt.s.marotta at gmail.com (matt.s.marotta at gmail.com) Date: Mon, 27 Jan 2014 07:03:36 -0800 (PST) Subject: Remove unwanted characters from column In-Reply-To: References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> Message-ID: <948612d7-8e69-46d0-9fab-707b762a48a7@googlegroups.com> On Monday, 27 January 2014 09:57:32 UTC-5, Chris Angelico wrote: > On Tue, Jan 28, 2014 at 1:23 AM, wrote: > > > If the farmID < 10: > > remove one character from the address column > > Elif farmID > 10: > > remove two characters from the address column > > What if farmID == 10? > > ChrisA Ok, sorry this is how it should be. If the FarmID < 10: remove one character from the address column If the FarmID > 9: remove two characters from the address column My issue is I can't figure out what statement to use to define FarmID. From rosuav at gmail.com Mon Jan 27 10:19:59 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 02:19:59 +1100 Subject: Remove unwanted characters from column In-Reply-To: <948612d7-8e69-46d0-9fab-707b762a48a7@googlegroups.com> References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> <04d509f9-54fa-4ba5-bb6e-24ce60e12523@googlegroups.com> <52e6650c$0$29999$c3e8da3$5496439d@news.astraweb.com> <9b121fe6-9ed8-4adf-af24-80166f348c7d@googlegroups.com> <948612d7-8e69-46d0-9fab-707b762a48a7@googlegroups.com> Message-ID: On Tue, Jan 28, 2014 at 2:03 AM, wrote: > On Monday, 27 January 2014 09:57:32 UTC-5, Chris Angelico wrote: >> On Tue, Jan 28, 2014 at 1:23 AM, wrote: >> >> > If the farmID < 10: >> > remove one character from the address column >> > Elif farmID > 10: >> > remove two characters from the address column >> >> What if farmID == 10? >> >> ChrisA > > Ok, sorry this is how it should be. > > If the FarmID < 10: > remove one character from the address column > > If the FarmID > 9: > remove two characters from the address column > > My issue is I can't figure out what statement to use to define FarmID. More commonly, that would be written as if farmID < 10: # remove one character else: # remove two characters Though this still suffers from the limitation of not handling 100 or 1000, so you might want to look at len(str(farmID)) instead. ChrisA From denismfmcmahon at gmail.com Mon Jan 27 10:22:57 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Mon, 27 Jan 2014 15:22:57 +0000 (UTC) Subject: Remove unwanted characters from column References: <8d703876-ba90-492d-a558-a5a9bb8023c7@googlegroups.com> Message-ID: On Sun, 26 Jan 2014 19:49:01 -0800, matt.s.marotta wrote: > School assignment is to create a tab separated output with the original > given addresses in one column and then the addresses split into other > columns (ex, columns for city, postal code, street suffix). If you're trying to create fixed width output from variable width fields, format specifiers may be better to use than tabs. The problem with tabs is that columns end up misaligned when the data fields in a column contain a mixture of items of less length than the tab spacing and items of greater length than the tab spacing, unless you can work out the tab spacing and adjust accordingly. For example, my code which uses the re module to separate the various record components and a format specifier to print the text and html versions (and csvwriter for the csv) them creates the outputs seen here: http://www.sined.co.uk/tmp/farms.txt http://www.sined.co.uk/tmp/farms.csv http://www.sined.co.uk/tmp/farms.htm -- Denis McMahon, denismfmcmahon at gmail.com From rantingrickjohnson at gmail.com Mon Jan 27 10:33:52 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 27 Jan 2014 07:33:52 -0800 (PST) Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e627bb$0$29811$862e30e2@ngroups.net> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> Message-ID: <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> On Monday, January 27, 2014 3:32:43 AM UTC-6, me wrote: > On Mon, 27 Jan 2014 20:01:33 +1100, Chris Angelico wrote: > > [snip chris reply] > > You feel better now that you too have vented? I had a > productive discussion with a couple of top level posters > who helped me solve my problem and they receive > appropriate kuddos. Now it seems that some lonely > individuals who maybe just want some attention are coming > out of the woodwork. You can kindly ignore Chris, he is just one of our well known *resident* "lonely individuals", seeking attention yet again! And his constant blabbing about and idol worship of REXX is more annoying than all of xah lee post combined, however, i do just enjoy watching him "casually" weaving in those examples as though he does not have an agenda to push. @Chris: Two can play at this game! From ethan at stoneleaf.us Mon Jan 27 10:31:49 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Mon, 27 Jan 2014 07:31:49 -0800 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: <52E67BE5.7030702@stoneleaf.us> On 01/26/2014 06:54 PM, Roy Smith wrote: > Chris Angelico wrote: >> >> That said, though, I grew up without syntax highlighting of any sort, >> and didn't think it particularly important; but now that I have >> editors with all those sorts of features, I do find them handy. > > Same here, except I'd replace "find them handy" with "totally addicted > to". +1000 -- ~Ethan~ From wrw at mac.com Mon Jan 27 09:52:40 2014 From: wrw at mac.com (William Ray Wing) Date: Mon, 27 Jan 2014 09:52:40 -0500 Subject: [RELEASED] Python 3.3.4 release candidate 1 In-Reply-To: References: <52E60C8E.1050908@python.org> Message-ID: <5C436A25-F474-442E-A0F2-9A2DB55EBE4B@mac.com> On Jan 27, 2014, at 8:55 AM, Mark Lawrence wrote: > On 27/01/2014 07:36, Georg Brandl wrote: >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA1 >> >> On behalf of the Python development team, I'm reasonably happy to announce the >> Python 3.3.4 release candidate 1. >> > > "Reasonably" happy? Is there a smiley missing there, or what? :) > > -- > My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. > > Mark Lawrence I'm guessing it is an editorial comment about Mac users/developers. But maybe I'm being defensive... ;-) -Bill From rosuav at gmail.com Mon Jan 27 10:53:37 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 02:53:37 +1100 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> Message-ID: On Tue, Jan 28, 2014 at 2:33 AM, Rick Johnson wrote: > You can kindly ignore Chris, he is just one of our well > known *resident* "lonely individuals", seeking attention yet > again! And his constant blabbing about and idol worship of REXX is > more annoying than all of xah lee post combined, however, i > do just enjoy watching him "casually" weaving in those > examples as though he does not have an agenda to push. > > @Chris: Two can play at this game! Heh. If you'd said Pike instead of REXX, I might have believed you :) I've said more about Pike than is perhaps appropriate, but of late, I've actually not been the one to most often quote REXX code. Actually, REXX as a language has been majorly left behind. Back in the early 1990s it was blessed with support for non-English text in the form of DBCS (at least, the OS/2 REXX implementation was - don't know how standard that was), but then nobody ever went in and made it all Unicode instead, so now we have a bytes-only language. Has its coolnesses, but far too much of it is done with language magic (eg the PARSE statement - there's no way to interact with that, no way to make anything dynamic, so even though it is, in many ways, much cleaner than C's sscanf or Perl's regular expressions, it's just plain impossible to extend). Still, it was my first taste of arbitrary-precision arithmetic, and for that (and plenty more) I am well appreciative. Frankly, I don't "idol worship" *any* language. There is not a single language that I've ever used which has no flaws. And I can't think of any language with which I have no fundamental disagreements on major design points. (Note that there's a difference between those two. Flaws are objective (and I'm not talking about bugs, I'm talking about stuff where the author agrees that it's wrong but it's too late to change now), design disagreements are personal. For instance, I personally believe that disallowing assignment-as-expression cuts out more value than it gains by preventing bugs (as we've seen lately, people can just get it wrong the other way, comparing as a statement), but I respect Guido's decision on that and don't see it as a problem to be fought. A lot of Python's worst flaws were fixed in 3.x (input() -> eval(), print as a statement, etc), but there are still a few oddities that can't easily be fixed. They don't stop the language from being useful and awesome. ChrisA From breamoreboy at yahoo.co.uk Mon Jan 27 11:22:38 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 16:22:38 +0000 Subject: buggy python interpretter or am I missing something here? In-Reply-To: References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> Message-ID: On 27/01/2014 15:53, Chris Angelico wrote: > Frankly, I don't "idol worship" *any* language. I worship English because it's so easy to learn. Ducks and runs :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From zachary.ware+pylist at gmail.com Mon Jan 27 11:23:49 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Mon, 27 Jan 2014 10:23:49 -0600 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e60817$0$29774$862e30e2@ngroups.net> References: <52e5f658$0$29583$862e30e2@ngroups.net> <52e60817$0$29774$862e30e2@ngroups.net> Message-ID: On Mon, Jan 27, 2014 at 1:17 AM, me wrote: > It's the intendation specific requirements that throw me. I haven't seen > such a hork since RPG. ;^) Best I can tell, the only thing RPG and Python have in common is the fact that they're "programming languages", though I'm being a little generous to RPG there. I'll note that RPG (IV) is the only language I've ever been formally trained in, unfortunately. I've mostly forgotten it though, so that's a plus :) Python's significant indentation is really quite nice and intuitive. The basic rule of thumb is if a line ends in a colon, the next line needs to be indented one more level. If you're continuing the same logical block, keep the same indention level. When a logical block is finished (whether by a raise, continue, break, or return statement, or just by "falling off the end" of the block), indent the next line one level less. Parentheses () (and brackets [] and braces {}) create what amounts to a 'virtual line', \n characters are basically ignored until the closing parenthesis is found (as long as they aren't in a non-triple-quoted string literal). As long as you don't try to mix tabs and spaces for your indentation (either is fine on its own, but spaces are generally preferred), it's very straightforward and allows you to better see the flow of the program with no question as to whether there is anything hidden within a block. I've been using C more in the past two weeks than I really expected to all this year, and have been bitten more than once by missing braces. Indenting intentionally is just a much cleaner, clearer way to do things (in my opinion, of course). >> Also, you can iterate over a (sys.argv) in a for >> loop, replacing 'l', 'idx', and the while loop; something like >> >> for arg in a: >> if arg == '-h': >> print help # help being defined elsewhere... >> elif arg == '-hh': >> # no really, print help >> print 'help' > > Understood, except that some parameters take multiple elements...thus why > I manually reference the indexes. Try this on for size, then: a_iter = iter(a) for arg in a_iter: print('current', arg) if arg == '-#': print('next', next(a_iter)) > Yup. Every language and platform has multiple arg parsing libraries. > Didn't feel like taking the time to research any since most of my python > ramblings are usually pyQT4 bindings to QT4 gui and postgresql apps. As with most modules in the standard library, I would bet you can get started using argparse in probably 15 minutes or less. The online documentation of the language and standard library is already quite good, and there is constant effort going into improving it. You might also want to play around with the 'help()' function in the interactive interpreter, it may have answered your original question without ever having had to ask here: >>> help(sys.exit) Help on built-in function exit in module sys: exit(...) exit([status]) Exit the interpreter by raising SystemExit(status). If the status is omitted or None, it defaults to zero (i.e., success). If the status is numeric, it will be used as the system exit status. If it is another kind of object, it will be printed and the system exit status will be one (i.e., failure). > Pointing out that sys.exit() raises a low level exception was the point I > was missing. Thx! You're welcome, I'm glad I could help :) As a general reply to the 'attitude' portion of this thread: "mutual respect" is the name of the game here. If you show respect (whether you've already received it or not), you're likely to receive respect. If not, don't be surprised by heated responses. This applies equally to everyone, I'm not pointing fingers at anyone in particular. Regards, -- Zach From dan at tombstonezero.net Mon Jan 27 11:38:43 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Mon, 27 Jan 2014 16:38:43 +0000 (UTC) Subject: buggy python interpretter or am I missing something here? References: <52e5f658$0$29583$862e30e2@ngroups.net> <52e60817$0$29774$862e30e2@ngroups.net> Message-ID: On Mon, 27 Jan 2014 10:23:49 -0600, Zachary Ware wrote: >> Understood, except that some parameters take multiple elements...thus >> why I manually reference the indexes. > > Try this on for size, then: > > a_iter = iter(a) > for arg in a_iter: > print('current', arg) > if arg == '-#': > print('next', next(a_iter)) And check out add_argument's "nargs" option: http://docs.python.org/3/library/argparse.html#nargs HTH, Dan From breamoreboy at yahoo.co.uk Mon Jan 27 11:45:18 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Mon, 27 Jan 2014 16:45:18 +0000 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e60817$0$29774$862e30e2@ngroups.net> References: <52e5f658$0$29583$862e30e2@ngroups.net> <52e60817$0$29774$862e30e2@ngroups.net> Message-ID: On 27/01/2014 07:17, me wrote: > It's the intendation specific requirements that throw me. I haven't seen > such a hork since RPG. ;^) > Programming with a rocket propelled grenade is vastly superior to programming in C++. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From torriem at gmail.com Mon Jan 27 12:52:40 2014 From: torriem at gmail.com (Michael Torrie) Date: Mon, 27 Jan 2014 10:52:40 -0700 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e627bb$0$29811$862e30e2@ngroups.net> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> Message-ID: <52E69CE8.5090408@gmail.com> On 01/27/2014 02:32 AM, me wrote: > You feel better now that you too have vented? Sorry but the emotional intent you're reading in to Chris's post is completely misplaced. I don't know why you chose to be offended by it. Chris's comments about C++ are accurate, but not intended to be a personal affront to you. They are just statements of fact. From raedtjr at gmail.com Mon Jan 27 14:40:32 2014 From: raedtjr at gmail.com (raedtjr at gmail.com) Date: Mon, 27 Jan 2014 11:40:32 -0800 (PST) Subject: Run python script with CMD error Message-ID: Hi everyone; Im new with python and i just installed it and added it to the path.I have already a script that i want to execute(run) but every time i do this commend python > client.py in CMD to execute it,i got this error. Any solutions please? > File ", line 29 except Exception, e: ^ SyntaxError: invalid syntax From __peter__ at web.de Mon Jan 27 14:52:31 2014 From: __peter__ at web.de (Peter Otten) Date: Mon, 27 Jan 2014 20:52:31 +0100 Subject: Run python script with CMD error References: Message-ID: raedtjr at gmail.com wrote: > Hi everyone; > > > Im new with python and i just installed it and added it to the path.I have > already a script that i want to execute(run) but every time i do this > commend python > >> client.py > > in CMD to execute it,i got this error. Any solutions please? > >> File ", line 29 except Exception, e: ^ SyntaxError: invalid syntax It is important for us to know the version of Python you are using. In Python 3 the above line has to be written except Exception as e: If the script was not written by you instead of fixing all the incompatibilities that may occur you should download and install Python 2.7 and run the script with that. From joel.goldstick at gmail.com Mon Jan 27 14:55:24 2014 From: joel.goldstick at gmail.com (Joel Goldstick) Date: Mon, 27 Jan 2014 14:55:24 -0500 Subject: Run python script with CMD error In-Reply-To: References: Message-ID: Look at lines around 29 On Jan 27, 2014 2:45 PM, wrote: > Hi everyone; > > > Im new with python and i just installed it and added it to the path.I have > already a script that i want to execute(run) but every time i do this > commend python > > > client.py > > in CMD to execute it,i got this error. Any solutions please? > > > File ", line 29 except Exception, e: ^ SyntaxError: invalid syntax > -- > https://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From raedtjr at gmail.com Mon Jan 27 15:00:16 2014 From: raedtjr at gmail.com (FalaG) Date: Mon, 27 Jan 2014 12:00:16 -0800 (PST) Subject: Run python script with CMD error In-Reply-To: References: Message-ID: I m using Python 3.3 and the script is not written by me therefore i'm gonna try to install 2.7 instead and i will let you know the result. Thank you Peter From rantingrickjohnson at gmail.com Mon Jan 27 15:22:22 2014 From: rantingrickjohnson at gmail.com (Rick Johnson) Date: Mon, 27 Jan 2014 12:22:22 -0800 (PST) Subject: buggy python interpretter or am I missing something here? In-Reply-To: References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> Message-ID: <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> On Monday, January 27, 2014 9:53:37 AM UTC-6, Chris Angelico wrote: > Heh. If you'd said Pike instead of REXX, I might have > believed you :) I've said more about Pike than is perhaps > appropriate, but of late, I've actually not been the one > to most often quote REXX code. Yes in my haste to inject a jab at you i pulled the trigger before fully retracting the gun from my holster... OUCH! It was indeed "Pike" that i meant. But, although you *do* mention it quite a lot, i don't think mentioning any language should be off topic because heck, someone could learn something new. > [snip] > For instance, I personally believe that disallowing > assignment-as-expression cuts out more value than it gains > by preventing bugs (as we've seen lately, people can just > get it wrong the other way, comparing as a statement), I myself wish for such a Python feature -- but alas, we are but slaves to whims of the dutch! > but I respect Guido's decision on that and don't see it as > a problem to be fought. A lot of Python's worst flaws were > fixed in 3.x (input() -> eval(), print as a statement, > etc), I agree that those are flaws, but not enough of a flaw to break code. "input" is only used by neophytes, so who cares about breaking that one, but "print" is almost everywhere! But let's go back to "input" for a bit... Why do we even need an "input" function anyway if all it is going to do is read from stdin? Would not $stdin.read have been better choice? Or simply "read" if you're a global namespace pollution fanboy! Heck, if you're going to have a function for writing strings to $stdout, and also, you're going to have a function for reading strings from $stdin, then you need to recognize the diametric relation between these functions, and as such, your first design consideration should be to maintain a consistency between them input (reads a string from stdin) print (writes a string to stdout) It is my strong believe that defining an "input" method that "magically" evals the input string is just plain evil. Why you ask? Because doing so injects superfluous magic whist simultaneously blinding the noob to the fact that strings are the mutually inclusive love interest of both "Mrs.Input" and "Mr.Output". From rosuav at gmail.com Mon Jan 27 15:29:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 07:29:03 +1100 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> Message-ID: On Tue, Jan 28, 2014 at 7:22 AM, Rick Johnson wrote: > maintain a consistency between them > > input (reads a string from stdin) > print (writes a string to stdout) > > It is my strong believe that defining an "input" method that > "magically" evals the input string is just plain evil. Fortunately, as of Python 3, that parallel is maintained. ChrisA From steve+comp.lang.python at pearwood.info Mon Jan 27 17:25:43 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 27 Jan 2014 22:25:43 GMT Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> Message-ID: <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jan 2014 12:22:22 -0800, Rick Johnson wrote: > "input" is only used by neophytes, so who cares about breaking that one, > but "print" is almost everywhere! Heh heh heh, how very "Ranting Rick" to think that a function for listening to input is unimportant, while a function for spraying output all over the place is vital. > But let's go back to "input" for a bit... > > Why do we even need an "input" function anyway if all it is going to do > is read from stdin? That's not all it does. For example, it handles backspacing, so that typing H E L O O BACKSPACE BACKSPACE L O gives "HELLO" rather than "HELOO\x7f\x7fO". Of course, somebody as awesome as Rick will have never made a mistake in his life, but for the rest of us mere mortals, that feature alone makes a dedicated input function worthwhile. But there's more! On systems with readline, not only does input handle backspacing, but it handles all sorts of editing functionality, such as arrow keys and various editing commands. So typing A LEFT-ARROW B gives "BA" rather than "A\x1b[DB". input also provides visual feedback while you type, an optional prompt, handling of newlines, buffering, and possibly more. -- Steven From vito.detullio at gmail.com Mon Jan 27 19:50:10 2014 From: vito.detullio at gmail.com (Vito De Tullio) Date: Tue, 28 Jan 2014 01:50:10 +0100 Subject: Highlighting program variables instead of keywords? References: Message-ID: Skip Montanaro wrote: > My son sent me a link to an essay about highlighting program data instead > of keywords: > > https://medium.com/p/3a6db2743a1e/ > > I think this might have value, especially if to could bounce back and > forth between both schemes. Is anyone aware of tools like this for Python? AFAIK kdevelop support this. http://kdevelop.org/sites/kdevelop.org/files/photos/kdev_python_1.png -- By ZeD From nimbiotics at gmail.com Mon Jan 27 22:44:31 2014 From: nimbiotics at gmail.com (Mario R. Osorio) Date: Mon, 27 Jan 2014 19:44:31 -0800 (PST) Subject: Need help with pushing technology ... and a bit more ... Message-ID: <9ac44ebf-07a8-4ef7-b97d-a575735e2a1c@googlegroups.com> Background: =========== We are studying the possibility of creating a system that will have the following entities: Customer(s) (appCustomer) Service Provider(s) (appProviders) and Manager(s) Server(s) appCustomers will have all appServices available to them and appServices will have at least one appManager and zero to many appServers. Each one of these entities will run an application on android, ios and windoze phone at least, as well as (hopefully) linux, osx and windoze (these last three are needed for appManagers) An appCustomer will use either an application or a given web site to request services via HTTP from the available appProviders. Our system should immediately upon receiving this order, notify all involved appManagers and appServers, report back to appCustomer who got notified of his/her request. appManagers and appServers will interact with the system via applications in order to notify appCustomer/appManager(s) of any progress in serving the appService, until its completion. All notification must be logged so that anyone involved in a given appService can check all activity and, for example, to allow appManagers to supervise the completion of a given appService request. Reading the previous explanation I notice this is pretty much your common ?Purchase Order System? except we need real time, bullet proof communications between all players, along with the possibility of SMS and mail capabilities as well as logs for all communication media. Our system is to go live immediately with one (paying) customer representing around 100 appCustomers. We are expecting the live system to produce anywhere between 500 to 2000 notifications per day which is not a lot but (expected) growth will be exponential and might reach about a million notifications in about a year or two. Observations: ============= I'd like to keep this project python/C/C++ only, or at least as much as possible. I'm not a seasoned python/C/C++ programmer though; but I'm in l.o.v.e. with python and C and C++. I understand even less about communications and I know I have to use some way to push all notifications, but I have not been able to find a solution that will work on all needed platforms (android, ios, windows phone, linux, osx and windows). I wouldn't mind using two or three different push technologies if that was the case but: Questions: ========== Isn't there a better way to push notifications? Do I forcibly have to use a service such as ?Urban Airship?, ?Pushwoosh?, ?Amazon SNS?, ?Windows Azure Notification Hubs?, ?Pushover?, ?Prowl? or ?Notify My Android??? Would it be possible to build our own push service by using a combination of telnet, xmlrpc, websockets or xmpp along with twisted, tornado or gevent; living along with django and possible mezzanine in my ?perfect python world?? Am I asking too much or am I so lost I don't even make sense? I've been reading about all these topics/products in the las couple of days and every line I read seems to get me the more confused... When I was initially involved in this idea I thought it was all about finding a nice library for a good real time communications protocol (https://groups.google.com/forum/#!topic/django-users/vZQ3C4DS73g) but, as I said before; I know nothing about communications and in spite of all the good intentions of those answering that post; I am yet to make sense of everything. I do not ask for a solution to my situation but at least some light as to what might be a good path to follow ? I will make sure you confess a solution once I figure out what are you talking about :) I will really appreciate and and all comments, ideas and recommendations ? even epithets! Thanks a lot in advanced! Mario R. Osorio From no-reply at thanks.com Mon Jan 27 23:01:15 2014 From: no-reply at thanks.com (john pierce) Date: Mon, 27 Jan 2014 22:01:15 -0600 Subject: Help with my 8-year old son's first program. I'm stuck Message-ID: <52e72b8e$0$34974$c3e8da3$460562f1@news.astraweb.com> First, forget about the def a() statement. def is for defining a function and this is not a function. Second, research the difference between == (logical test) and = (assignment operator). Third, take a look at the length of "op" just after the readline(). You can add a line that says print(len(op)) right after the readline to see what's goingon. There's a new line character in there. Try using op = op.strip() before you do all the if statements. That will remove the trailing newline, and change the first test back to op == "d". Hope this helps. John >PS: At the first statement, we've also tried >op == "d": >But that doesn't work either. >On Saturday, January 25, 2014 10:02:15 AM UTC, justinp... at gmail.com wrote: >> My son is learning Python and I know nothing about computers. >> >> He's written a simple calculator program that doesn't work. For the life of me, I can't see why. >> --------------= Posted using GrabIt =---------------- ------= Binary Usenet downloading made easy =--------- -= Get GrabIt for free from http://www.shemes.com/ =- From yiitest123 at gmail.com Tue Jan 28 00:19:52 2014 From: yiitest123 at gmail.com (yiitest123 at gmail.com) Date: Mon, 27 Jan 2014 21:19:52 -0800 (PST) Subject: Web service in Python Message-ID: I installed rapidsms in local for send messages. The application tested with local server. Now i would like to store the incoming messages in another database via a php application. Means when a message received in rapidsms (Django-Python) app, i want to call a php application function and store message in php app database. For this which method is best? Thanks From wxjmfauth at gmail.com Tue Jan 28 02:19:03 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Mon, 27 Jan 2014 23:19:03 -0800 (PST) Subject: Highlighting program variables instead of keywords? In-Reply-To: References: Message-ID: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> Different, but a little bit related. The work which is done actually on the possibility (not implemented but alreay realized) to colorize (style") the different graphemes of a glyph is very interesting. Python with its absurd Flexible String Representation just become a no go for the kind of task. (Should not be too complicate to understand.) jmf From dieter at handshake.de Tue Jan 28 02:21:34 2014 From: dieter at handshake.de (dieter) Date: Tue, 28 Jan 2014 08:21:34 +0100 Subject: Web service in Python References: Message-ID: <87wqhko9kx.fsf@handshake.de> yiitest123 at gmail.com writes: > I installed rapidsms in local for send messages. The application tested with local server. Now i would like to store the incoming messages in another database via a php application. Means when a message received in rapidsms (Django-Python) app, i want to call a php application function and store message in php app database. For this which method is best? As you describe your wishes (the description could be a bit more precise), the web service would not be in Python but in PHP. When your PHP application would provide a SOAP/WSDL webservice, then you could use a Python webservice client, e.g. "suds", to interface with such a webservice. When your PHP application would provide a REST webservice, other Python libraries ("urllib", "json", ...) could be used. Details much depend on the kind of webservice provided by the PHP application. In typical case, I find the approach a bit convoluted. In those cases, the Python application would directly store the messages in the database - not send them to a second web service for storing. But, there are cases where the approach may make sense - e.g. when there is already such a second web service (which just needs to be used). From wuwei23 at gmail.com Tue Jan 28 02:31:46 2014 From: wuwei23 at gmail.com (alex23) Date: Tue, 28 Jan 2014 17:31:46 +1000 Subject: Need Help with Programming Science Project In-Reply-To: References: Message-ID: On 24/01/2014 8:05 PM, theguy wrote: > I have a science project that involves designing a program which can examine a bit of text with the author's name given, then figure out who the author is if another piece of example text without the name is given. This sounds like exactly the sort of thing NLTK was made for. Here's an example of using it for this requirement: http://www.aicbt.com/authorship-attribution/ From ikorot01 at gmail.com Tue Jan 28 03:26:40 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 28 Jan 2014 00:26:40 -0800 Subject: Enable unicode Message-ID: Hi, ALL, In here: http://stackoverflow.com/questions/21397035/set-utf8-on-mysql, I got a suggestion to enable "use_unicode". Problem is I'm developing on Windows and it's not that I can recompile my python. I'm using Python2.7 on Windows XP. Any pointer on how do I enable "use_unicode"? Thank you. From rosuav at gmail.com Tue Jan 28 03:35:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 19:35:49 +1100 Subject: Enable unicode In-Reply-To: References: Message-ID: On Tue, Jan 28, 2014 at 7:26 PM, Igor Korot wrote: > Hi, ALL, > In here: http://stackoverflow.com/questions/21397035/set-utf8-on-mysql, > I got a suggestion to enable "use_unicode". > Problem is I'm developing on Windows and it's not that I can recompile > my python. > I'm using Python2.7 on Windows XP. > > Any pointer on how do I enable "use_unicode"? Before you go any further: MySQL has a broken interpretation of "utf8" that allows only a subset of the full Unicode range. Instead, use "utf8mb4", which is what the rest of the world calls UTF-8. As far as I know, you can just switch in utf8mb4 everywhere that you're currently using utf8 and it'll work. According to [1] the use_unicode flag is a keyword parameter to connect(). As much as possible, I'd recommend using those parameters rather than explicitly executing SQL statements to reconfigure the connection - it's clearer, and the local client might want to reconfigure itself in response to the change too. Be aware that MySQL has a number of issues with Unicode and sorting (or at least, it did the last time I checked, which was a while ago now), not to mention other problems with its default MyISAM format. You may want to consider PostgreSQL instead. ChrisA [1] http://mysql-python.sourceforge.net/MySQLdb.html From breamoreboy at yahoo.co.uk Tue Jan 28 03:39:05 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Tue, 28 Jan 2014 08:39:05 +0000 Subject: Highlighting program variables instead of keywords? In-Reply-To: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> References: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> Message-ID: On 28/01/2014 07:19, wxjmfauth at gmail.com wrote: > Different, but a little bit related. The work > which is done actually on the possibility (not > implemented but alreay realized) to colorize (style") > the different graphemes of a glyph is very interesting. > > Python with its absurd Flexible String Representation > just become a no go for the kind of task. > > (Should not be too complicate to understand.) > > jmf > This guy has surely exceeded his "three strikes and you're out" limit? Please, please somebody do something about it, he's driving me insane with this continuous drivel. No thread appears to be safe from him jumping in with this nonsense. -- 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 Jan 28 04:00:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 20:00:42 +1100 Subject: Enable unicode In-Reply-To: References: Message-ID: On Tue, Jan 28, 2014 at 7:56 PM, Igor Korot wrote: > Hi, Chris, Hi! I'm hoping it was oversight that led to this email coming to me personally instead of to the list, and hoping that you won't mind me responding on-list. > On Tue, Jan 28, 2014 at 12:35 AM, Chris Angelico wrote: >> On Tue, Jan 28, 2014 at 7:26 PM, Igor Korot wrote: >>> Hi, ALL, >>> In here: http://stackoverflow.com/questions/21397035/set-utf8-on-mysql, >>> I got a suggestion to enable "use_unicode". >>> Problem is I'm developing on Windows and it's not that I can recompile >>> my python. >>> I'm using Python2.7 on Windows XP. >>> >>> Any pointer on how do I enable "use_unicode"? >> >> Before you go any further: MySQL has a broken interpretation of "utf8" >> that allows only a subset of the full Unicode range. Instead, use >> "utf8mb4", which is what the rest of the world calls UTF-8. As far as >> I know, you can just switch in utf8mb4 everywhere that you're >> currently using utf8 and it'll work. > > So instead of using 'utf8' just use 'utf8mb4'? Yes, that's right. Unless utf8mb4 isn't supported, in which case try utf8 and see if you can use the full range (something might be translating it for you, which would probably be a good thing). >> According to [1] the use_unicode flag is a keyword parameter to >> connect(). As much as possible, I'd recommend using those parameters >> rather than explicitly executing SQL statements to reconfigure the >> connection - it's clearer, and the local client might want to >> reconfigure itself in response to the change too. > > Is it supported on all versions of MySQLDB? No idea! I don't use MySQLDB, so just give it a shot and see if it works. >> Be aware that MySQL has a number of issues with Unicode and sorting >> (or at least, it did the last time I checked, which was a while ago >> now), not to mention other problems with its default MyISAM format. >> You may want to consider PostgreSQL instead. > > I'm not using MyISAM, only InnoDB. ;-) That's good, but it doesn't cover everything. You may find that non-ASCII strings get mis-sorted. I strongly prefer PostgreSQL for anything where I actually care about the data I'm storing. And yes, that's everything that I store. So I don't use MySQL anywhere any more :) > So, how do I properly write the connection lines? I've no idea - I don't actually use MySQLDB, I just looked at the docs :) But try adding use_unicode=True to your connect() call. ChrisA From ikorot01 at gmail.com Tue Jan 28 04:20:20 2014 From: ikorot01 at gmail.com (Igor Korot) Date: Tue, 28 Jan 2014 01:20:20 -0800 Subject: Enable unicode In-Reply-To: References: Message-ID: Hi, Chris, On Tue, Jan 28, 2014 at 1:00 AM, Chris Angelico wrote: > On Tue, Jan 28, 2014 at 7:56 PM, Igor Korot wrote: >> Hi, Chris, > > Hi! I'm hoping it was oversight that led to this email coming to me > personally instead of to the list, and hoping that you won't mind me > responding on-list. Sorry about that. I keep forgetting that gmail web mail is stupid and does not use the list address on "Reply". Does not happen to other list, only this one. > >> On Tue, Jan 28, 2014 at 12:35 AM, Chris Angelico wrote: >>> On Tue, Jan 28, 2014 at 7:26 PM, Igor Korot wrote: >>>> Hi, ALL, >>>> In here: http://stackoverflow.com/questions/21397035/set-utf8-on-mysql, >>>> I got a suggestion to enable "use_unicode". >>>> Problem is I'm developing on Windows and it's not that I can recompile >>>> my python. >>>> I'm using Python2.7 on Windows XP. >>>> >>>> Any pointer on how do I enable "use_unicode"? >>> >>> Before you go any further: MySQL has a broken interpretation of "utf8" >>> that allows only a subset of the full Unicode range. Instead, use >>> "utf8mb4", which is what the rest of the world calls UTF-8. As far as >>> I know, you can just switch in utf8mb4 everywhere that you're >>> currently using utf8 and it'll work. >> >> So instead of using 'utf8' just use 'utf8mb4'? > > Yes, that's right. Unless utf8mb4 isn't supported, in which case try > utf8 and see if you can use the full range (something might be > translating it for you, which would probably be a good thing). So you mean just try it in the python console and see if it works? > >>> According to [1] the use_unicode flag is a keyword parameter to >>> connect(). As much as possible, I'd recommend using those parameters >>> rather than explicitly executing SQL statements to reconfigure the >>> connection - it's clearer, and the local client might want to >>> reconfigure itself in response to the change too. >> >> Is it supported on all versions of MySQLDB? > > No idea! I don't use MySQLDB, so just give it a shot and see if it works. Problem is it might work on my machine, but the person I'm working with/for might have earlier version of the driver. That's actually why I asked on SO - is it supported on all versions of MySQLDB. > >>> Be aware that MySQL has a number of issues with Unicode and sorting >>> (or at least, it did the last time I checked, which was a while ago >>> now), not to mention other problems with its default MyISAM format. >>> You may want to consider PostgreSQL instead. >> >> I'm not using MyISAM, only InnoDB. ;-) > > That's good, but it doesn't cover everything. You may find that > non-ASCII strings get mis-sorted. > > I strongly prefer PostgreSQL for anything where I actually care about > the data I'm storing. And yes, that's everything that I store. So I > don't use MySQL anywhere any more :) Hehe. Originally the software was written for SQLite. Then mySQL support was added and now the new script should be made based on the existing one and this new script will be used in a web based app - Django + jQuery/jQWidgets. The person is not a developer, rather have a management background so he is going with the market trend, which is currently mySQL for web app. ;-) I'd very much prefer to use SQLite as the data we use are text of the different length which is more suitable for SQLite. But.... > >> So, how do I properly write the connection lines? > > I've no idea - I don't actually use MySQLDB, I just looked at the docs > :) But try adding use_unicode=True to your connect() call. OK, will do, thx. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Tue Jan 28 04:32:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Tue, 28 Jan 2014 20:32:27 +1100 Subject: Enable unicode In-Reply-To: References: Message-ID: On Tue, Jan 28, 2014 at 8:20 PM, Igor Korot wrote: >>> So instead of using 'utf8' just use 'utf8mb4'? >> >> Yes, that's right. Unless utf8mb4 isn't supported, in which case try >> utf8 and see if you can use the full range (something might be >> translating it for you, which would probably be a good thing). > > So you mean just try it in the python console and see if it works? Yep. Play around with four categories of character: ASCII, Latin-1, Basic Multilingual Plane, and Supplementary Multilingual Plane. They correspond to codepoints <128, <256, <65536, and <1114112. >>> Is it supported on all versions of MySQLDB? >> >> No idea! I don't use MySQLDB, so just give it a shot and see if it works. > > Problem is it might work on my machine, but the person I'm working > with/for might have earlier version of the driver. > That's actually why I asked on SO - is it supported on all versions of MySQLDB. Try it on yours, try it on theirs; or dig through the docs to see when it was added. Hard to say without knowing exactly what version your client is using. >> I strongly prefer PostgreSQL for anything where I actually care about >> the data I'm storing. And yes, that's everything that I store. So I >> don't use MySQL anywhere any more :) > > Hehe. > Originally the software was written for SQLite. > Then mySQL support was added and now the new script should be made > based on the existing one and this new script will be used in a web > based app - Django + jQuery/jQWidgets. > The person is not a developer, rather have a management background so > he is going with the market trend, which is currently mySQL for web > app. ;-) > I'd very much prefer to use SQLite as the data we use are text of the > different length which is more suitable for SQLite. But.... Market trend is deceptive AND meaningless. Yes, there's a general notion that low-grade web servers will give you Apache, MySQL, and PHP, while not offering anything else; but that's like saying that a dirt-cheap car comes with a radio and no CD player, ergo you should be listening to the radio even in a car that has (or could have) a CD player. The reason cheap web hosts offer MySQL is because lots of people ask for it, and the reason people ask for it is because lots of hosts offer it. There's no other reason. If you're the expert and he's of management background, then it's your job to sell the technically superior option despite his initial gut feeling... be an advocate, not an automaton. :) And hopefully he'll respect your skills enough to listen to your advice. I don't have much experience with SQLite, but I would suspect that "text of different lengths" should be able to be handled equally cleanly by any database engine - at least the major ones. You may want to look into whether you use VARCHAR, TEXT, or some other data type, but it should work just fine. ChrisA From duxbuz at gmail.com Tue Jan 28 04:32:54 2014 From: duxbuz at gmail.com (duxbuz at gmail.com) Date: Tue, 28 Jan 2014 01:32:54 -0800 (PST) Subject: Coordinates TK and Turtle Message-ID: <2f14feba-7766-4dc5-bd69-504da9724359@googlegroups.com> Hello I have some weird results when I run my code which is meant to display a canvas and a turtle and some text with the turtles coordinates. Basically the turtle coordinates do not seem to correspond with the TK create_text coordinates. t1.goto(100,100) canvas_id = cv1.create_text(t1.xcor(), t1.ycor(), font=("Purisa",12),anchor="nw") cv1.insert(canvas_id, 0, t1.pos()) I end up with this output: http://i1025.photobucket.com/albums/y319/duxbuz/coord-issues_zps1fca6d2b.jpg Could anyone help please? Thanks From max at alcyone.com Tue Jan 28 04:19:20 2014 From: max at alcyone.com (Erik Max Francis) Date: Tue, 28 Jan 2014 01:19:20 -0800 Subject: ANN: EmPy 3.3.2 released (Python 3.x compatibility) Message-ID: Summary A powerful and robust templating system for Python. Overview EmPy is a system for embedding Python expressions and statements in template text; it takes an EmPy source file, processes it, and produces output. This is accomplished via expansions, which are special signals to the EmPy system and are set off by a special prefix (by default the at sign, '@'). EmPy can expand arbitrary Python expressions and statements in this way, as well as a variety of special forms. Textual data not explicitly delimited in this way is sent unaffected to the output, allowing Python to be used in effect as a markup language. Also supported are callbacks via hooks, recording and playback via diversions, and dynamic, chainable filters. The system is highly configurable via command line options and embedded commands. Expressions are embedded in text with the '@(...)' notation; variations include conditional expressions with '@(...?...!...)' and the ability to handle thrown exceptions with '@(...$...)'. As a shortcut, simple variables and expressions can be abbreviated as '@variable', '@object.attribute', '@function(arguments)', '@sequence' [index], and combinations. Full-fledged statements are embedded with '@{...}'. Control flow in terms of conditional or repeated expansion is available with '@[...]'. A '@' followed by a whitespace character (including a newline) expands to nothing, allowing string concatenations and line continuations. Comments are indicated with '@#' and consume the rest of the line, up to and including the trailing newline. '@%' indicate "significators," which are special forms of variable assignment intended to specify per-file identification information in a format which is easy to parse externally. Context name and line number changes can be done with '@?' and '@!' respectively. '@<...>' markups are customizeable by the user and can be used for any desired purpose. Escape sequences analogous to those in C can be specified with '@\...', and finally a '@@' sequence expands to a single literal at sign. Getting the software The current version of empy is 3.3.2. The latest version of the software is available in a tarball here: http://www.alcyone.com/software/empy/empy-latest.tar.gz. The official URL for this Web site is http://www.alcyone.com/software/empy/. Requirements EmPy should work with any version of Python from 2.4 onward, including 3.x. License This code is released under the LGPL. .... Release history [since 3.3] - 3.3.2; 2014 Jan 24. Additional fix for source compatibility between 2.x and 3.0. - 3.3.1; 2014 Jan 22. Source compatibility for 2.x and 3.0; 1.x and Jython compatibility dropped. -- Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis Sitting in the den and / Looking at the phone as if it owed / Owed me a favor -- Blu Cantrell From steve+comp.lang.python at pearwood.info Tue Jan 28 06:16:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jan 2014 11:16:27 GMT Subject: Highlighting program variables instead of keywords? References: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> Message-ID: <52e7918b$0$29999$c3e8da3$5496439d@news.astraweb.com> On Mon, 27 Jan 2014 23:19:03 -0800, wxjmfauth wrote: > Different, but a little bit related. The work which is done actually on > the possibility (not implemented but alreay realized) to colorize > (style") the different graphemes of a glyph is very interesting. > > Python with its absurd Flexible String Representation just become a no > go for the kind of task. > > (Should not be too complicate to understand.) No, not complicated at all. Water is wet, therefore the FSR is rubbish. Athens is the capital of Greece, therefor the FSR is rubbish. 1+1 = 2, therefore the FSR is rubbish. The South American Potoo is a member of the Nyctibiidae family, therefore the FSR is rubbish. We get the point, thank you. -- Steven From p-santoro at sbcglobal.net Tue Jan 28 06:13:06 2014 From: p-santoro at sbcglobal.net (Peter) Date: Tue, 28 Jan 2014 06:13:06 -0500 Subject: uninstalling python27 killed vim (actual issue was more complicated and involves Mercurial) Message-ID: <52E790C2.2080309@sbcglobal.net> I'm posting this information to help others who are transitioning from Python 2.x to Python 3.x and are using Vim and Mercurial on Windows. BACKGROUND Old workstation configuration: 32-bit Windows XP/SP3, Python 2.7.6 and 3.3.3, Mercurial 2.8.2, PATH contained Python before Mercurial, dual boot with Slackware 14.0 New workstation configuration: 64-bit Windows 7/SP1, 64-bit Python 3.3.3, 64-bit Mercurial 2.8.2, PATH contained Python before Mercurial, dual boot with Slackware64 14.1 Early last year, I ported dozens of Python 2.7 tools that I wrote to automate various development tasks to Python 3 (via 2to3 script and testing). After the ports were completed, I had my colleagues replace their Python2 installations with Python3. We quickly uncovered/fixed a few issues (mostly related to Unicode) that I missed in my initial testing. We've been happily running the Python3 versions for months now, but I've been reluctant to remove Python27 from my old (soon to be retired) workstation. PROBLEM Yesterday, I finally decided to say goodbye to Python27 on Windows and uninstalled it from my old workstation. A little while later, I noticed that vim no longer worked. Gvim.exe silently failed and vim.exe failed with the following error: ImportError: No module named site After reading the relevant vim documentation (http://vimdoc.sourceforge.net/htmldoc/if_pyth.html#python-dynamic) and doing a few Google searches, I decided to run vim under windbg to see what was actually going on. Windbg showed that vim loaded the python27.dll from my Mercurial installation just before exiting. A quick look inside Mercurial's library.zip file showed that the site.py module was not included. OK, so now things were starting to make sense. WORKAROUND I took Mercurial out of the PATH, which returned vim to working order. I then wrote the following two line hg.bat script and copied it to a directory include in the PATH: @echo off "C:\Program Files\Mercurial\hg.exe" %* With this workaround, both vim and hg appear to be once again working on the old workstation. 64-BIT WINDOWS As the vim for Windows package I installed is a 32-bit application, I didn't have this issue on 64-bit Windows using 64-bit Mercurial. However, I believe the same issue would occur if 32-bit Mercurial is used on 64-bit Windows. Hopefully this information is useful to other Python, Vim, and Mercurial users. Peter Santoro From kevingloveruk at gmail.com Tue Jan 28 06:45:32 2014 From: kevingloveruk at gmail.com (kevingloveruk at gmail.com) Date: Tue, 28 Jan 2014 03:45:32 -0800 (PST) Subject: Wikipedia XML Dump Message-ID: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> Hi I have downloaded and unzipped the xml dump of Wikipedia (40+GB). I want to use Python and the SAX module (running under Windows 7) to carry out off-line phrase-searches of Wikipedia and to return a count of the number of hits for each search. Typical phrase-searches might be "of the dog" and "dog's". I have some limited prior programming experience (from many years ago) and I am currently learning Python from a course of YouTube tutorials. Before I get much further, I wanted to ask: Is what I am trying to do actually feasible? Are there any example programs or code snippets that would help me? Any advice or guidance would be gratefully received. Best regards, Kevin Glover From __peter__ at web.de Tue Jan 28 06:56:15 2014 From: __peter__ at web.de (Peter Otten) Date: Tue, 28 Jan 2014 12:56:15 +0100 Subject: Coordinates TK and Turtle References: <2f14feba-7766-4dc5-bd69-504da9724359@googlegroups.com> Message-ID: duxbuz at gmail.com wrote: > Hello > > I have some weird results when I run my code which is meant to display a > canvas and a turtle and some text with the turtles coordinates. > > Basically the turtle coordinates do not seem to correspond with the TK > create_text coordinates. > > > t1.goto(100,100) > > canvas_id = cv1.create_text(t1.xcor(), t1.ycor(), > font=("Purisa",12),anchor="nw") > > cv1.insert(canvas_id, 0, t1.pos()) > > I end up with this output: > http://i1025.photobucket.com/albums/y319/duxbuz/coord- issues_zps1fca6d2b.jpg > > Could anyone help please? The image you provide suggests (x, y) --> (x, -y), but a quick look into the source reveals that it is a little more complex: >>> print inspect.getsource(turtle._Screen._write) def _write(self, pos, txt, align, font, pencolor): """Write txt at pos in canvas with specified font and color. Return text item and x-coord of right bottom corner of text's bounding box.""" x, y = pos x = x * self.xscale y = y * self.yscale anchor = {"left":"sw", "center":"s", "right":"se" } item = self.cv.create_text(x-1, -y, text = txt, anchor = anchor[align], fill = pencolor, font = font) x0, y0, x1, y1 = self.cv.bbox(item) self.cv.update() return item, x1-1 Rather than repeating the above calculation in your own code I suggest that you use turtle.write() >>> import turtle >>> turtle = turtle.getturtle() >>> turtle.goto(100, 100) >>> turtle.write("Hello, world!") From chris at simplistix.co.uk Tue Jan 28 03:33:01 2014 From: chris at simplistix.co.uk (Chris Withers) Date: Tue, 28 Jan 2014 08:33:01 +0000 Subject: MailingLogger 3.8.0 Released! Message-ID: <52E76B3D.5020803@simplistix.co.uk> I'm pleased to announce a new release of Mailinglogger. Mailinglogger provides two handlers for the standard python logging framework that enable log entries to be emailed either as the entries are logged or as a summary at the end of the running process. The handlers have the following features: - customisable and dynamic subject lines for emails sent - emails sent with a configurable headers for easy filtering - flood protection to ensure the number of emails sent is not excessive - support for SMTP servers that require authentication - fully documented and tested This release adds flood limiting to the SummarisingLogger, ensuring that emails it sends aren't bigger than MTAs are prepared to handle. Full docs can be found here: http://packages.python.org/mailinglogger/ For more information, please see: http://www.simplistix.co.uk/software/python/mailinglogger or http://pypi.python.org/pypi/mailinglogger cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk From ben+python at benfinney.id.au Tue Jan 28 10:47:04 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Wed, 29 Jan 2014 02:47:04 +1100 Subject: Enable unicode References: Message-ID: <85zjmgcdmv.fsf@benfinney.id.au> Igor Korot writes: > On Tue, Jan 28, 2014 at 1:00 AM, Chris Angelico wrote: > > Hi! I'm hoping it was oversight that led to this email coming to me > > personally instead of to the list, and hoping that you won't mind me > > responding on-list. > > Sorry about that. > I keep forgetting that gmail web mail is stupid and does not use the > list address on "Reply". The ?reply? command is for replying only to the article author So that is working correctly. > Does not happen to other list, only this one. Many mailing lists are misconfigured, breaking the ?reply? command so it doesn't do what it's meant to (and you lose the facility to reply only to the author of the message). Instead, for replying to a list, you need the ?reply to list? command . Sadly, it appears GMail does not have this command; you may want to use a better mail client which implements this feature. -- \ ?I must say that I find television very educational. The minute | `\ somebody turns it on, I go to the library and read a book.? | _o__) ?Groucho Marx | Ben Finney From rustompmody at gmail.com Tue Jan 28 11:06:18 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jan 2014 08:06:18 -0800 (PST) Subject: Enable unicode In-Reply-To: References: Message-ID: <1f12d4d6-a9c5-444c-b7f6-1f14bbf13b50@googlegroups.com> On Tuesday, January 28, 2014 2:50:20 PM UTC+5:30, Igor Korot wrote: > Hi, Chris, > On Tue, Jan 28, 2014 at 1:00 AM, Chris Angelico wrote: > > On Tue, Jan 28, 2014 at 7:56 PM, Igor Korot wrote: > >> Hi, Chris, > > Hi! I'm hoping it was oversight that led to this email coming to me > > personally instead of to the list, and hoping that you won't mind me > > responding on-list. > Sorry about that. > I keep forgetting that gmail web mail is stupid and does not use the > list address on "Reply". > Does not happen to other list, only this one. In gmail: Gear-icon -> Settings -> Default-reply behavior select all From steve+comp.lang.python at pearwood.info Tue Jan 28 11:09:17 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 28 Jan 2014 16:09:17 GMT Subject: uninstalling python27 killed vim (actual issue was more complicated and involves Mercurial) References: Message-ID: <52e7d62d$0$29999$c3e8da3$5496439d@news.astraweb.com> On Tue, 28 Jan 2014 06:13:06 -0500, Peter wrote: > I'm posting this information to help others who are transitioning from > Python 2.x to Python 3.x and are using Vim and Mercurial on Windows. [...] Thank you Peter for posting your experiences here! We need more of these sorts of informational posts. Regards, -- Steven From rosuav at gmail.com Tue Jan 28 11:29:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Wed, 29 Jan 2014 03:29:32 +1100 Subject: Enable unicode In-Reply-To: <1f12d4d6-a9c5-444c-b7f6-1f14bbf13b50@googlegroups.com> References: <1f12d4d6-a9c5-444c-b7f6-1f14bbf13b50@googlegroups.com> Message-ID: On Wed, Jan 29, 2014 at 3:06 AM, Rustom Mody wrote: >> Sorry about that. >> I keep forgetting that gmail web mail is stupid and does not use the >> list address on "Reply". >> Does not happen to other list, only this one. > > In gmail: Gear-icon -> Settings -> Default-reply behavior select all That's an imperfect solution, but it's the one I use. You then have to remember to delete the individual sender's address, or that person will get a duplicate copy. ChrisA From info at egenix.com Tue Jan 28 11:47:39 2014 From: info at egenix.com (eGenix Team: M.-A. Lemburg) Date: Tue, 28 Jan 2014 17:47:39 +0100 Subject: ANN: eGenix pyOpenSSL Distribution 0.13.3.1.0.1.6 Message-ID: <52E7DF2B.8060200@egenix.com> ________________________________________________________________________ ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.3.1.0.1.6 An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenSSL - available for Windows, Mac OS X and Unix platforms This announcement is also available on our web-site for online reading: http://www.egenix.com/company/news/eGenix-pyOpenSSL-Distribution-0.13.3.1.0.1.6.html ________________________________________________________________________ INTRODUCTION The eGenix.com pyOpenSSL Distribution includes everything you need to get started with SSL in Python. It comes with an easy-to-use installer that includes the most recent OpenSSL library versions in pre-compiled form, making your application independent of OS provided OpenSSL libraries: http://www.egenix.com/products/python/pyOpenSSL/ pyOpenSSL is an open-source Python add-on that allows writing SSL/TLS- aware network applications as well as certificate management tools: https://launchpad.net/pyopenssl/ OpenSSL is an open-source implementation of the SSL/TLS protocol: http://www.openssl.org/ ________________________________________________________________________ NEWS This new release of the eGenix.com pyOpenSSL Distribution updates the included pyOpenSSL and OpenSSL versions: New in the eGenix pyOpenSSL Distribution ---------------------------------------- * Updated pyOpenSSL to the upstream trunk revision 171 (pyOpenSSL version 0.13.1+). * Added work-around for compiling pyOpenSSL trunk revision 171 on Windows with OpenSSL 1.0.0 and later. * Included support for TLS 1.1 and 1.2 in pyOpenSSL (rev 171). Please see the TLS support section in the documentation for details. http://www.egenix.com/products/python/pyOpenSSL/doc/#TLS_support * Added SSL.OP_NO_COMPRESSION and SSL.OP_SINGLE_ECDH_USE context options to be able to address the CRIME attack and allow for more secure elliptic curve Diffie-Hellman key exchange setups. * Added HTML Sphinx documentation from the pyOpenSSL trunk version to the package. An online version is available from our website: http://www.egenix.com/products/python/pyOpenSSL/doc/pyopenssl.html * Updated the included CA bundles to the latest Mozilla 2014-01-28 version. * Included ca-bundle*.crt files now have the same modification date as the Mozilla certdata.txt file from which they were generated. * Restored compatibility of the ca_bundle module with Python 2.4. * Enhanced the included https_client.py example to show case OpenSSL best practices: - server name parsing (RFC 2818 support will follow in one of the next releases) - SNI (support for TLS extension to support multiple SSL sites on a single host) - setup secure default SSL options - setup secure default SSL cipher suite - use TLS 1.0 - 1.2 only - disable SSL compression negotiation (prevent CRIME attack) New in OpenSSL -------------- * Updated included OpenSSL libraries from OpenSSL 1.0.1e to 1.0.1f. See http://www.openssl.org/news/news.html and http://www.openssl.org/news/vulnerabilities.html for a complete list of changes, most important: - CVE-2013-4353: A carefully crafted invalid TLS handshake could crash OpenSSL with a NULL pointer exception. A malicious server could use this flaw to crash a connecting client. - CVE-2013-6450: A flaw in DTLS handling can cause an application using OpenSSL and DTLS to crash. - CVE-2013-6449: A flaw in OpenSSL can cause an application using OpenSSL to crash when using TLS version 1.2. As always, we provide binaries that include both pyOpenSSL and the necessary OpenSSL libraries for all supported platforms: Windows x86 and x64, Linux x86 and x64, Mac OS X PPC, x86 and x64. We've also added egg-file distribution versions of our eGenix.com pyOpenSSL Distribution for Windows, Linux and Mac OS X to the available download options. These make setups using e.g. zc.buildout and other egg-file based installers a lot easier. ________________________________________________________________________ DOWNLOADS The download archives and instructions for installing the package can be found at: http://www.egenix.com/products/python/pyOpenSSL/ ________________________________________________________________________ UPGRADING Before installing this version of pyOpenSSL, please make sure that you uninstall any previously installed pyOpenSSL version. Otherwise, you could end up not using the included OpenSSL libs. _______________________________________________________________________ SUPPORT Commercial support for these packages is available from eGenix.com. Please see http://www.egenix.com/services/support/ for details about our support offerings. ________________________________________________________________________ MORE INFORMATION For more information about the eGenix pyOpenSSL Distribution, licensing and download instructions, please visit our web-site or write to sales at egenix.com. Enjoy, -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Jan 28 2014) >>> Python Projects, Consulting and Support ... http://www.egenix.com/ >>> mxODBC.Zope/Plone.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 rustompmody at gmail.com Tue Jan 28 12:11:08 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jan 2014 09:11:08 -0800 (PST) Subject: Wikipedia XML Dump In-Reply-To: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> References: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> Message-ID: <03d8894a-417c-4445-aeb5-f0b1003ca5eb@googlegroups.com> On Tuesday, January 28, 2014 5:15:32 PM UTC+5:30, Kevin Glover wrote: > Hi > I have downloaded and unzipped the xml dump of Wikipedia (40+GB). I want to use Python and the SAX module (running under Windows 7) to carry out off-line phrase-searches of Wikipedia and to return a count of the number of hits for each search. Typical phrase-searches might be "of the dog" and "dog's". > I have some limited prior programming experience (from many years ago) and I am currently learning Python from a course of YouTube tutorials. Before I get much further, I wanted to ask: > Is what I am trying to do actually feasible? Cant really visualize what youve got... When you 'download' wikipedia what do you get? One 40GB file? A zillion files? Some other database format? Another point: sax is painful to use compared to full lxml (dom) But then sax is the only choice when files cross a certain size Thats why the above question Also you may want to explore nltk From skip at pobox.com Tue Jan 28 13:15:09 2014 From: skip at pobox.com (Skip Montanaro) Date: Tue, 28 Jan 2014 12:15:09 -0600 Subject: Wikipedia XML Dump In-Reply-To: <03d8894a-417c-4445-aeb5-f0b1003ca5eb@googlegroups.com> References: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> <03d8894a-417c-4445-aeb5-f0b1003ca5eb@googlegroups.com> Message-ID: > Another point: > sax is painful to use compared to full lxml (dom) > But then sax is the only choice when files cross a certain size > Thats why the above question No matter what the choice of XML parser, I suspect you'll want to convert it to some other form for processing. Skip From ester.lopezberga at gmail.com Tue Jan 28 12:32:11 2014 From: ester.lopezberga at gmail.com (Ester Lopez) Date: Tue, 28 Jan 2014 18:32:11 +0100 Subject: boost-python: exposing constructor with an array of other class as argument Message-ID: Hello there, I have two different classes that I want to expose using boost-python, but the constructor of the second class takes and array of the first one as argument and I can't figure out how to do it. This is the definition of the classes: class INT96{ public: uint64_t value[3]; INT96(){}; INT96(uint64_t x0, uint64_t x1, uint64_t x2); ... }; template class Xi_CW{ protected: INT96 A[k]; public: Xi_CW(INT96 (&A)[k]); ... }; And my attempt to expose them using boost-python: using namespace boost::python; typedef Xi_CW<4> Xi_CW4; BOOST_PYTHON_MODULE(xis) { class_("INT96", init()) [...] ; class_("Xi_CW4", init()) [...] ; } Which results in a "no known conversion error". I've tried several other possibilities but so far no luck... Any idea how should I do it? Thanks Ester From jcasale at activenetwerx.com Tue Jan 28 13:43:52 2014 From: jcasale at activenetwerx.com (Joseph L. Casale) Date: Tue, 28 Jan 2014 18:43:52 +0000 Subject: Documenting descriptors Message-ID: <072470ceac084ad18ca124dd19d34566@exch.activenetwerx.com> I am documenting a few classes with Sphinx that utilize methods decorated with custom descriptors. These properties return data when called and Sphinx is content with a :returns: and :rtype: markup in the properties doc string. They also accept input, but parameter (not really applicable) nor var markup is accepted as valid? Anyone know the trick here? Thanks, jlc From ned at nedbatchelder.com Tue Jan 28 14:38:46 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Tue, 28 Jan 2014 14:38:46 -0500 Subject: Highlighting program variables instead of keywords? In-Reply-To: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> References: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> Message-ID: On 1/28/14 2:19 AM, wxjmfauth at gmail.com wrote: > Different, but a little bit related. The work > which is done actually on the possibility (not > implemented but alreay realized) to colorize (style") > the different graphemes of a glyph is very interesting. > > Python with its absurd Flexible String Representation > just become a no go for the kind of task. > > (Should not be too complicate to understand.) > > jmf > JMF, seriously, stop it. You've convinced no one because you have no convincing arguments. It's obnoxious to continue to make this claim. Stop it. Please. If you want to try to convince someone, convince me. Write to me offline: ned at nedbatchelder.com -- Ned Batchelder, http://nedbatchelder.com From denismfmcmahon at gmail.com Tue Jan 28 14:55:04 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Tue, 28 Jan 2014 19:55:04 +0000 (UTC) Subject: ANN: eGenix pyOpenSSL Distribution 0.13.3.1.0.1.6 References: Message-ID: On Tue, 28 Jan 2014 17:47:39 +0100, eGenix Team: M.-A. Lemburg wrote: > It comes with an easy-to-use installer that includes the most recent > OpenSSL library versions in pre-compiled form Hmm, well it all sounds very good, but how would I know that the pre- compiled library doesn't contain a backdoor that sends copies of all the plaintext to the NSA? -- Denis McMahon, denismfmcmahon at gmail.com From fabiofz at gmail.com Tue Jan 28 15:05:17 2014 From: fabiofz at gmail.com (Fabio Zadrozny) Date: Tue, 28 Jan 2014 18:05:17 -0200 Subject: PyDev 3.3.3 Released Message-ID: Hi All, PyDev 3.3.3 has been released Details on PyDev: http://pydev.org Details on its development: http://pydev.blogspot.com LiClipse (PyDev standalone with goodies such as support for Django Templates, Kivy Language, Mako Templates, Html, Javascript, etc): http://brainwy.github.io/liclipse/ What is PyDev? --------------------------- PyDev is a plugin that enables users to use Eclipse for Python, Jython and IronPython development -- making Eclipse a first class Python IDE -- It comes with many goodies such as code completion, syntax highlighting, syntax analysis, code analysis, refactor, debug, etc. Release Highlights: ------------------------------- * **Important**: PyDev requires Eclipse 3.8 or 4.3 onwards and Java 7! For older versions, keep using PyDev 2.x (see LiClipse: http://brainwy.github.io/liclipse for a PyDev standalone with all requirements bundled). * **Code Completion**: - Compiled modules are now indexed and shown in the context-insensitive code-completion. - In an empty file, a code-completion request will show options related to creating modules (press Ctrl+Space twice to show only those templates). * **Performance**: - Building (indexing) of Python files is **much** faster. - Code completion does not get slown down by other analysis done in the background due to shell synchronization. * **Interactive Console**: - The interactive console now has tab-completion (so, tab can be used to show completions such as in IPython). * **Debugger**: - **Locals are now properly changed in the debugger** -- along with set next statement and auto-reloading this can make a debug session much more enjoyable! - Added a way to skip functions on a step-in on functions with **#@DontTrace** comments: - **Makes it possible to skip a lot of boilerplate code on a debug session!** - Can be enabled/disabled in the debugger preferences; - Ctrl+1 in a line with a method shows option to add **#@DontTrace** comment (if enabled in the preferences). - Debugging Stackless is much improved, especially for versions of Stackless released from 2014 onwards (special thanks to Anselm Kruis who improved stackless itself for this integration to work properly). - Reload during a debug session is improved and more stable: - Only updates what it can in-place or adds new attributes; - Shows what's being patched in the console output; - New hooks are provided for clients which may want to extend the reload; - See: Auto Reload in Debugger: http://pydev.org/manual_adv_debugger_auto_reload.html for more details. * **General**: - Compiled modules are now indexed, so, **fix import with Ctrl+1 now works with itertools, PyQt and other 'forced builtins'**. - When diffing a Python file, the PyDev comparison (with proper syntax highlighting) is now the default. - When finding a definition in a .pyd file, if there's a related .pyx in the same location, it's opened. - Running unit-tests will not try to import files that are in folders that don't have an __init__.py file. - Alt+Shift+O can be used to toggle mark occurrences. - Ctrl+3 not bound by default anymore on PyDev so that it does not conflict with the Eclipse Ctrl+3 (Ctrl+/ can be used instead). - Fixed recursion issue when finding file in pydev package explorer. - When configuring the interpreter, links are not followed when resolving entries for the PYTHONPATH. - It's possible to launch a directory containing a __main__.py file executable. - Fixed issues when creating django project without any existing project in the workspace. - Fixed deadlock on code-completion. - __pycache__ folders are hidden by default. * **Organize imports**: - When saving a file, if automatically organizing imports, don't remove unused imports even if that option is checked. - When saving a file, if automatically organizing imports, and nothing changes, don't change the buffer (so, no undo command is created). - @NoMove can be used in an import so that the import organizer doesn't mess with it. * **Refactoring**: - Fixed error when moving resource in PYTHONPATH to a dir out of the PYTHONPATH. - On a search make sure we search only python files, not dlls (which could give OutOfMemory errors and make the search considerably slower). - Multiple fixes on the rename module refactoring. Cheers, -- Fabio Zadrozny ------------------------------------------------------ Software Developer LiClipse http://brainwy.github.io/liclipse PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From ganea.ionut.iulian at gmail.com Tue Jan 28 15:24:17 2014 From: ganea.ionut.iulian at gmail.com (ganea.ionut.iulian at gmail.com) Date: Tue, 28 Jan 2014 12:24:17 -0800 (PST) Subject: Pyro4 - reading files Message-ID: <2e810b96-cc98-48af-b651-4c5b866aff49@googlegroups.com> Hello there. I am currently working on a project involving the use of Pyro4. I have a scenario. We have the pc named A, and a pc named B. On pc B lies a python script, that includes pyro, and a method for reading files. On pc A, we create an instance to the pyro object on pc B. And we call the method for reading files. I want to read a file that lies on pc B, from pc A using the method of the pyro object i just created. Is it possible? Thank you. From torriem at gmail.com Tue Jan 28 16:09:43 2014 From: torriem at gmail.com (Michael Torrie) Date: Tue, 28 Jan 2014 14:09:43 -0700 Subject: Highlighting program variables instead of keywords? In-Reply-To: References: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> Message-ID: <52E81C97.7060204@gmail.com> On 01/28/2014 12:38 PM, Ned Batchelder wrote: > JMF, seriously, stop it. You've convinced no one because you have no > convincing arguments. > > It's obnoxious to continue to make this claim. Stop it. Please. > > If you want to try to convince someone, convince me. Write to me > offline: ned at nedbatchelder.com JMF, maybe if you'd actually try to write a program in Python that does what you are talking about with "colorizing graphemes," (whatever that means) then you can talk. Sounds to me like you don't even use Python at all, for unicode or anything else. From kevingloveruk at gmail.com Tue Jan 28 17:31:16 2014 From: kevingloveruk at gmail.com (Kevin Glover) Date: Tue, 28 Jan 2014 14:31:16 -0800 (PST) Subject: Wikipedia XML Dump In-Reply-To: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> References: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> Message-ID: <7500190f-18a6-42b2-a77a-982672ce1644@googlegroups.com> Thanks for the comments, guys. The Wikipedia download is a single XML document, 43.1GB. Any further thoughts? Kevin From burak.arslan at arskom.com.tr Tue Jan 28 17:47:47 2014 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Wed, 29 Jan 2014 00:47:47 +0200 Subject: Wikipedia XML Dump In-Reply-To: <7500190f-18a6-42b2-a77a-982672ce1644@googlegroups.com> References: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> <7500190f-18a6-42b2-a77a-982672ce1644@googlegroups.com> Message-ID: <52E83393.1000701@arskom.com.tr> hi, On 01/29/14 00:31, Kevin Glover wrote: > Thanks for the comments, guys. The Wikipedia download is a single XML document, 43.1GB. Any further thoughts? > > in that case, http://lxml.de/tutorial.html#event-driven-parsing seems to be your only option. hth, burak From euguess at gmail.com Tue Jan 28 20:39:17 2014 From: euguess at gmail.com (Eugene Sajine) Date: Tue, 28 Jan 2014 17:39:17 -0800 (PST) Subject: Development infrastructure - need python packaging gurus help, please Message-ID: <85b8c2d8-8702-4ad8-8272-b3c1ea751db8@googlegroups.com> Hi! I'm trying to create a development infrastructure that would allow for simple and unified ways of sharing, *deploying* and *reusing* the code within private entity. I can see that pip with virtual environments and requirements.txt is very similar to dependency management provided by maven or apache ivy. But there seems to be a disconnect between the egg carrying the possibility to be importable and executable, but in the same time considered to be deprecated format which is not fully supported by pip and virtualenv and wheel not having those basic questions answered... Here is what i'm trying to achieve: 1. I want to be able to specify the set of dependencies for the project i'm currently developing and make them available for the import. Think java jar - having it in class path allows for the code reuse (import packages provided) as well as for the execution. 2. I want to be able to put the newly created project in a form of artifact in a some central location from which it can be taken to be imported or executed or included into "class path". Again think java jar. If i have it in some location i can use ivy or maven to manage the dependencies and provide it to me upon request 3. I want to be able to deploy the program and execute it. So the problem with all this as i see it: The importable and executable format is egg, but it is deprecated! Sane dependency management is pip and virtualenv, but they don't support eggs fully (pip install --egg is having the disclaimer that it s not working ok sometimes) wheel is pretty much unusable for anything other then installing into the virtualenv. Am i missing something? Thanks in advance, Eugene From wuwei23 at gmail.com Tue Jan 28 20:39:48 2014 From: wuwei23 at gmail.com (alex23) Date: Wed, 29 Jan 2014 11:39:48 +1000 Subject: Wikipedia XML Dump In-Reply-To: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> References: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> Message-ID: On 28/01/2014 9:45 PM, kevingloveruk at gmail.com wrote: > I have downloaded and unzipped the xml dump of Wikipedia (40+GB). I want to use Python and the SAX module (running under Windows 7) to carry out off-line phrase-searches of Wikipedia and to return a count of the number of hits for each search. Typical phrase-searches might be "of the dog" and "dog's". > > I have some limited prior programming experience (from many years ago) and I am currently learning Python from a course of YouTube tutorials. Before I get much further, I wanted to ask: > > Is what I am trying to do actually feasible? Rather than parsing through 40GB+ every time you need to do a search, you should get better performance using an XML database which will allow you to do queries directly on the xml data. http://basex.org/ is one such db, and comes with a Python API: http://docs.basex.org/wiki/Clients From rustompmody at gmail.com Tue Jan 28 20:52:48 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Tue, 28 Jan 2014 17:52:48 -0800 (PST) Subject: Wikipedia XML Dump In-Reply-To: References: <9ec53bc0-f2da-46f4-ad58-2c9a75653dbf@googlegroups.com> <7500190f-18a6-42b2-a77a-982672ce1644@googlegroups.com> Message-ID: On Wednesday, January 29, 2014 4:17:47 AM UTC+5:30, Burak Arslan wrote: > hi, > On 01/29/14 00:31, Kevin Glover wrote: > > Thanks for the comments, guys. The Wikipedia download is a single XML document, 43.1GB. Any further thoughts? > in that case, http://lxml.de/tutorial.html#event-driven-parsing seems to > be your only option. Further thoughts?? Just a combo of what Burak and Skip said: I'd explore a thin veneer of even-driven lxml to get from 40 GB monolithic xml to something (more) digestible to nltk From dkcombs at panix.com Tue Jan 28 22:09:20 2014 From: dkcombs at panix.com (David Combs) Date: Wed, 29 Jan 2014 03:09:20 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <20131212213602.806ef8fd2626ca6f34bc83d6@gmx.net> <20131216213225.2006b30246e3a08ee241a191@gmx.net> Message-ID: In article <20131216213225.2006b30246e3a08ee241a191 at gmx.net>, Wolfgang Keller wrote: >> > And ever after that experience, I avoided all languages that were >> > even remotely similar to C, such as C++, Java, C#, Javascript, PHP >> > etc. >> >> I think that's disappointing, for two reasons. Firstly, C syntax isn't >> that terrible. > >It's not just the abysmally appalling, hideously horrifying syntax. At >about everything about C is just *not* "made for human beings" imho. > >It's just an un-language that gets at about everything wrong. Sort of >like Microsoft's products. > >Sincerely, > >Wolfgang > I don't see how you could create a better high-level LOW-LEVEL language. And that pointer "*" syntax is really ingenious. (After all, the guys who created it and those who first used it (at Bell Labs) WERE all geniuses!) David From dkcombs at panix.com Tue Jan 28 22:17:38 2014 From: dkcombs at panix.com (David Combs) Date: Wed, 29 Jan 2014 03:17:38 +0000 (UTC) Subject: Experiences/guidance on teaching Python as a first programming language References: <52afb7e7$0$29976$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article , Neil Cerutti wrote: >On 2013-12-17, Steven D'Aprano > wrote: >> I would really like to see good quality statistics about bugs >> per program written in different languages. I expect that, for >> all we like to make fun of COBOL, it probably has few bugs per >> unit-of-useful-work-done than the equivalent written in C. > >I can't think of a reference, but I to recall that >bugs-per-line-of-code is nearly constant; it is not language >dependent. So, unscientifically, the more work you can get done >in a line of code, then the fewer bugs you'll have per amount of >work done. > >-- >Neil Cerutti > Makes no sense to me. I can't imagine that errors per 100 lines is anywhere near as high with a language that has garbage collection and type checking as with one that has neither. David From cs at zip.com.au Tue Jan 28 22:48:02 2014 From: cs at zip.com.au (Cameron Simpson) Date: Wed, 29 Jan 2014 14:48:02 +1100 Subject: Enable unicode In-Reply-To: <85zjmgcdmv.fsf@benfinney.id.au> References: <85zjmgcdmv.fsf@benfinney.id.au> Message-ID: <20140129034802.GA85744@cskk.homeip.net> On 29Jan2014 02:47, Ben Finney wrote: > Igor Korot writes: > > On Tue, Jan 28, 2014 at 1:00 AM, Chris Angelico wrote: > > > Hi! I'm hoping it was oversight that led to this email coming to me > > > personally instead of to the list, and hoping that you won't mind me > > > responding on-list. > > > > Sorry about that. > > I keep forgetting that gmail web mail is stupid and does not use the > > list address on "Reply". [...] > Instead, for replying to a list, you need the ?reply to list? command > . Sadly, it appears > GMail does not have this command; you may want to use a better mail > client which implements this feature. For example, choose and use a real desktop mail client and connect to GMail's IMAP interface. At least then you can pick something with the feature set you want. -- Cameron Simpson From ayushidalmia2604 at gmail.com Wed Jan 29 00:25:54 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Tue, 28 Jan 2014 21:25:54 -0800 (PST) Subject: Large Two Dimensional Array Message-ID: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> Hello, I am trying to implement IBM Model 1. In that I need to create a matrix of 50000*50000 with double values. Currently I am using dict of dict but it is unable to support such high dimensions and hence gives memory error. Any help in this regard will be useful. I understand that I cannot store the matrix in the RAM but what is the most efficient way to do this? From ayushidalmia2604 at gmail.com Wed Jan 29 00:42:58 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Tue, 28 Jan 2014 21:42:58 -0800 (PST) Subject: Large Two Dimensional Array In-Reply-To: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> References: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> Message-ID: On Wednesday, January 29, 2014 10:55:54 AM UTC+5:30, Ayushi Dalmia wrote: > Hello, > > > > I am trying to implement IBM Model 1. In that I need to create a matrix of 50000*50000 with double values. Currently I am using dict of dict but it is unable to support such high dimensions and hence gives memory error. Any help in this regard will be useful. I understand that I cannot store the matrix in the RAM but what is the most efficient way to do this? Also, the matrix indices are words and not integers. I donot want to map. From mickverdu at gmail.com Wed Jan 29 01:26:56 2014 From: mickverdu at gmail.com (mick verdu) Date: Tue, 28 Jan 2014 22:26:56 -0800 (PST) Subject: Eclipse IDE printing values automatically Message-ID: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> I am using Pydev 2.8 on Eclipse IDE. It is printing some values that haven't been printed with print command. How to deal with this problem? From david.froger at inria.fr Wed Jan 29 01:39:56 2014 From: david.froger at inria.fr (David Froger) Date: Wed, 29 Jan 2014 07:39:56 +0100 Subject: Large Two Dimensional Array In-Reply-To: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> References: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> Message-ID: <20140129063956.4899.15625@fl-58186.rocq.inria.fr> Quoting Ayushi Dalmia (2014-01-29 06:25:54) > Hello, > > I am trying to implement IBM Model 1. In that I need to create a matrix of 50000*50000 with double values. Currently I am using dict of dict but it is unable to support such high dimensions and hence gives memory error. Any help in this regard will be useful. I understand that I cannot store the matrix in the RAM but what is the most efficient way to do this? > -- > https://mail.python.org/mailman/listinfo/python-list Hello, I would suggest using h5py [1] or PyTables [2] to store data on disk (both are based on HDF5 [3]), and manipulate data in RAM as NumPy [4] arrays. [1] www.h5py.org [2] www.pytables.org [3] www.hdfgroup.org/HDF5 [4] www.numpy.org From dieter at handshake.de Wed Jan 29 02:07:36 2014 From: dieter at handshake.de (dieter) Date: Wed, 29 Jan 2014 08:07:36 +0100 Subject: Development infrastructure - need python packaging gurus help, please References: <85b8c2d8-8702-4ad8-8272-b3c1ea751db8@googlegroups.com> Message-ID: <87k3djxo3r.fsf@handshake.de> Eugene Sajine writes: > ... > Here is what i'm trying to achieve: > 1. I want to be able to specify the set of dependencies for the project i'm currently developing and make them available for the import. Think java jar - having it in class path allows for the code reuse (import packages provided) as well as for the execution. > 2. I want to be able to put the newly created project in a form of artifact in a some central location from which it can be taken to be imported or executed or included into "class path". Again think java jar. If i have it in some location i can use ivy or maven to manage the dependencies and provide it to me upon request > 3. I want to be able to deploy the program and execute it. You may have a look at "zc.buildout" - it may support your development needs. Once the development is complete, a so called "meta-egg" may be used to describe the finished program. A "meta-egg" does not have (significant amounts of) code but essentially states dependencies of other eggs. From ayushidalmia2604 at gmail.com Wed Jan 29 02:12:53 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Tue, 28 Jan 2014 23:12:53 -0800 (PST) Subject: Large Two Dimensional Array In-Reply-To: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> References: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> Message-ID: On Wednesday, January 29, 2014 10:55:54 AM UTC+5:30, Ayushi Dalmia wrote: > Hello, > > > > I am trying to implement IBM Model 1. In that I need to create a matrix of 50000*50000 with double values. Currently I am using dict of dict but it is unable to support such high dimensions and hence gives memory error. Any help in this regard will be useful. I understand that I cannot store the matrix in the RAM but what is the most efficient way to do this? Thanks David! From breamoreboy at yahoo.co.uk Wed Jan 29 04:21:03 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 29 Jan 2014 09:21:03 +0000 Subject: Eclipse IDE printing values automatically In-Reply-To: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> References: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> Message-ID: On 29/01/2014 06:26, mick verdu wrote: > I am using Pydev 2.8 on Eclipse IDE. It is printing some values that haven't been printed with print command. How to deal with this problem? > There are some very smart people on this list, but unless you give them details of what you've tried and precisely what went wrong how can we help? What does your code look like? Are you debugging, running a file via CTRL+F11 and seeing the output on the Pydev console, what? Slight aside, why 2.8, 3.3.3 has just been released? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From mal at python.org Wed Jan 29 05:20:36 2014 From: mal at python.org (M.-A. Lemburg) Date: Wed, 29 Jan 2014 11:20:36 +0100 Subject: ANN: Python Events Calendar - Now with Twitter feed Message-ID: <52E8D5F4.4010501@python.org> [Please help spread the word by forwarding to other relevant mailing lists, user groups, etc. world-wide; thanks :-)] ________________________________________________________________________ ANNOUNCING Python Events Calendars - Now with Twitter feed maintained by the Python Software Foundation (PSF) and a group of volunteers ________________________________________________________________________ INTRODUCTION As some of you may know, the PSF has put together a team of volunteers who are maintaining a central Python events calendar. We currently have two calendars in place: * Python Events Calendar - meant for conferences and larger gatherings focusing on Python or a related technology (in whole or in part) * Python User Group Calendar - meant for user group events and other smaller local events The calendars are displayed on http://pycon.org/ and in a smaller version in the sidebar of the http://python.org/ website. You can subscribe to the calendars using iCal and RSS feeds and also embed the calendar widgets on your sites. Please see our wiki page for details: https://wiki.python.org/moin/PythonEventsCalendar The calendars are open to the world-wide Python community, so you can have local user group events, as well as regional and international conference events added to the calendars. ________________________________________________________________________ NEWS We have now created a Twitter feed for the calendars, which you can follow to get updates on all newly added events: https://twitter.com/pythonevents The tweets come with links to the event listings, which you can add to your own Google calendars with a single click. ________________________________________________________________________ ADDING EVENTS If you want to have entries added to those calendars, please write to events at python.org and include the following information: * Name of the event * Type of the event (conference, bar camp, user group, etc) * Focus on Python and approximate size * URL * Location and country * Date and time (if relevant) For recurring events, please also include a description of the recurrence in a way that's compatible and supported by Google calendars. ________________________________________________________________________ MORE INFORMATION More information on the calendars, the URLs, feed links, IDs, embedding, etc. is available on the wiki: https://wiki.python.org/moin/PythonEventsCalendar Enjoy, -- Marc-Andre Lemburg Director Python Software Foundation http://www.python.org/psf/ From piet at vanoostrum.org Wed Jan 29 08:30:59 2014 From: piet at vanoostrum.org (Piet van Oostrum) Date: Wed, 29 Jan 2014 14:30:59 +0100 Subject: Highlighting program variables instead of keywords? References: <0a2dc12e-43b2-4a49-8349-5e5e2b91886b@googlegroups.com> Message-ID: Ned Batchelder writes: > On 1/28/14 2:19 AM, wxjmfauth at gmail.com wrote: >> Different, but a little bit related. The work >> which is done actually on the possibility (not >> implemented but alreay realized) to colorize (style") >> the different graphemes of a glyph is very interesting. >> >> Python with its absurd Flexible String Representation >> just become a no go for the kind of task. >> >> (Should not be too complicate to understand.) >> >> jmf >> > > JMF, seriously, stop it. You've convinced no one because you have no > convincing arguments. > > It's obnoxious to continue to make this claim. Stop it. Please. > > If you want to try to convince someone, convince me. Write to me > offline: ned at nedbatchelder.com > > -- > Ned Batchelder, http://nedbatchelder.com > I seriously think jmf has a mental disorder. So these reactions won't do anything useful. Just ignore. -- Piet van Oostrum WWW: http://pietvanoostrum.com/ PGP key: [8DAE142BE17999C4] From denismfmcmahon at gmail.com Wed Jan 29 11:32:19 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 29 Jan 2014 16:32:19 +0000 (UTC) Subject: Large Two Dimensional Array References: <416b8336-90c3-4d24-bd84-7af3ff5c299f@googlegroups.com> Message-ID: On Tue, 28 Jan 2014 21:25:54 -0800, Ayushi Dalmia wrote: > Hello, > > I am trying to implement IBM Model 1. In that I need to create a matrix > of 50000*50000 with double values. Currently I am using dict of dict but > it is unable to support such high dimensions and hence gives memory > error. Any help in this regard will be useful. I understand that I > cannot store the matrix in the RAM but what is the most efficient way to > do this? This looks to me like a table with columns: word1 (varchar 20) | word2 (varchar 20) | connection (double) might be your best solution, but it's going a huge table (2G5 rows) The primary key is going to be the combination of all 3 columns (or possibly the combination of word1 and word2) and you want indexes on word1 and word2, which will slow down populating the table, but speed up searching it, and I assume that searching is going to be a much more frequent operation than populating. Also, creating a database has the additional advantage that next time you want to use the program for a conversion between two languages that you've previously built the data for, the data already exists in the database, so you don't need to build it again. I imagine you would have either one table for each language pair, or one table for each conversion (treating a->b and b->a as two separate conversions). I'm also guessing that varchar 20 is long enough to hold any of your 50,000 words in either language, that value might need adjusting otherwise. -- Denis McMahon, denismfmcmahon at gmail.com From denismfmcmahon at gmail.com Wed Jan 29 11:34:28 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Wed, 29 Jan 2014 16:34:28 +0000 (UTC) Subject: Eclipse IDE printing values automatically References: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> Message-ID: On Tue, 28 Jan 2014 22:26:56 -0800, mick verdu wrote: > I am using Pydev 2.8 on Eclipse IDE. It is printing some values that > haven't been printed with print command. How to deal with this problem? There's no print statement in the code you included to demonstrate the problem, which is probably why the data you expect to be printed isn't being printed. -- Denis McMahon, denismfmcmahon at gmail.com From andrew.svetlov at gmail.com Wed Jan 29 11:55:04 2014 From: andrew.svetlov at gmail.com (Andrew Svetlov) Date: Wed, 29 Jan 2014 18:55:04 +0200 Subject: [python-committers] [RELEASED] Python 3.3.4 release candidate 1 In-Reply-To: <52E60C8E.1050908@python.org> References: <52E60C8E.1050908@python.org> Message-ID: Would you to accept fixes for http://bugs.python.org/issue20434 and http://bugs.python.org/issue20437 before 3.3.4 final? On Mon, Jan 27, 2014 at 9:36 AM, Georg Brandl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On behalf of the Python development team, I'm reasonably happy to announce the > Python 3.3.4 release candidate 1. > > Python 3.3.4 includes several security fixes and over 120 bug fixes compared to > the Python 3.3.3 release. > > This release fully supports OS X 10.9 Mavericks. In particular, this release > fixes an issue that could cause previous versions of Python to crash when typing > in interactive mode on OS X 10.9. > > Python 3.3 includes a range of improvements of the 3.x series, as well as easier > porting between 2.x and 3.x. In total, almost 500 API items are new or improved > in Python 3.3. For a more extensive list of changes in the 3.3 series, see > > http://docs.python.org/3.3/whatsnew/3.3.html > > and for the detailed changelog of 3.3.4, see > > http://docs.python.org/3.3/whatsnew/changelog.html > > To download Python 3.3.4 rc1 visit: > > http://www.python.org/download/releases/3.3.4/ > > This is a preview release, please report any bugs to > > http://bugs.python.org/ > > The final version is scheduled to be released in two weeks' time, on or about > the 10th of February. > > Enjoy! > > - -- > Georg Brandl, Release Manager > georg at python.org > (on behalf of the entire python-dev team and 3.3's contributors) > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v2.0.22 (GNU/Linux) > > iEYEARECAAYFAlLmDI4ACgkQN9GcIYhpnLAr6wCePRbHF80k5goV4RUDBA5FfkwF > rLUAnRg0RpL/b6apv+Dt2/sgnUd3hTPA > =Z4Ss > -----END PGP SIGNATURE----- > _______________________________________________ > python-committers mailing list > python-committers at python.org > https://mail.python.org/mailman/listinfo/python-committers -- Thanks, Andrew Svetlov From skip at pobox.com Wed Jan 29 12:29:28 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 29 Jan 2014 11:29:28 -0600 Subject: pytz question: GMT vs. UTC Message-ID: According ato the pytz doc (http://pytz.sourceforge.net/): "?UTC? is Universal Time, also known as Greenwich Mean Time or GMT in the United Kingdom." If they are equal, why don't timezone objects created from those two strings compare equal? >>> pytz.timezone("UTC") == pytz.timezone("GMT") False (I'm revealing my complete ignorance of timezone manipulation by asking this question.) Thx, Skip From jeanmichel at sequans.com Wed Jan 29 12:41:04 2014 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Wed, 29 Jan 2014 18:41:04 +0100 (CET) Subject: Pyro4 - reading files In-Reply-To: <2e810b96-cc98-48af-b651-4c5b866aff49@googlegroups.com> Message-ID: <363856038.2434030.1391017264302.JavaMail.root@sequans.com> ----- Original Message ----- > Hello there. > > I am currently working on a project involving the use of Pyro4. > > I have a scenario. > > We have the pc named A, and a pc named B. > > On pc B lies a python script, that includes pyro, and a method for > reading files. > > On pc A, we create an instance to the pyro object on pc B. And we > call the method for reading files. > > I want to read a file that lies on pc B, from pc A using the method > of the pyro object i just created. > > Is it possible? > > Thank you. Hi, Yes, read http://pythonhosted.org/Pyro4/tutorials.html If you plan to transfer large files between PCS, make sure you read http://pythonhosted.org/Pyro4/tipstricks.html before, as other solutions may be better suited. 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 rosuav at gmail.com Wed Jan 29 12:47:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Jan 2014 04:47:32 +1100 Subject: pytz question: GMT vs. UTC In-Reply-To: References: Message-ID: On Thu, Jan 30, 2014 at 4:29 AM, Skip Montanaro wrote: > According ato the pytz doc (http://pytz.sourceforge.net/): > > "?UTC? is Universal Time, also known as Greenwich Mean Time or GMT in > the United Kingdom." > > If they are equal, why don't timezone objects created from those two > strings compare equal? > >>>> pytz.timezone("UTC") == pytz.timezone("GMT") > False There are some technical differences between UTC and GMT, which almost never come up, and which I very much doubt are significant here (does pytz care about leap seconds?). But what I'm seeing - at least in the version of pytz that I picked up by typing 'sudo pip install pytz' on Debian Wheezy - is that the two are different types. UTC seems to be a special case, while GMT is like the others. That may be why they're not comparing equal, even though all operations might happen to produce the same results. ChrisA From ben+python at benfinney.id.au Wed Jan 29 13:45:53 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 30 Jan 2014 05:45:53 +1100 Subject: pytz question: GMT vs. UTC References: Message-ID: <85vbx2d3tq.fsf@benfinney.id.au> Skip Montanaro writes: > According ato the pytz doc (http://pytz.sourceforge.net/): > > "?UTC? is Universal Time, also known as Greenwich Mean Time or GMT in > the United Kingdom." This is inaccurate, and I'd like to see it corrected in the documentation. UTC is neither UT nor GMT. GMT is not precisely defined, which makes it unsuitable for keeping precise time in a computer system. > If they are equal, why don't timezone objects created from those two > strings compare equal? > > >>> pytz.timezone("UTC") == pytz.timezone("GMT") > False Python is correct, the timezones are not the same. See and . From the former: Saying "GMT" often implies either UTC or UT1 when used within informal or casual contexts. In technical contexts, usage of "GMT" is avoided; the unambiguous terminology "UTC" or "UT1" is preferred. > (I'm revealing my complete ignorance of timezone manipulation by > asking this question.) Treat GMT like any other locale-specific timezone, and convert to/from it as late/early as possible (like a locale-specific encoding). Treat UTC as the canonical timezone for keeping all timestamp values in (like Unicode for text). -- \ ?Reality must take precedence over public relations, for nature | `\ cannot be fooled.? ?Richard P. Feynman | _o__) | Ben Finney From invalid at invalid.invalid Wed Jan 29 14:02:53 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Wed, 29 Jan 2014 19:02:53 +0000 (UTC) Subject: pytz question: GMT vs. UTC References: Message-ID: On 2014-01-29, Skip Montanaro wrote: > According ato the pytz doc (http://pytz.sourceforge.net/): > > "UTC is Universal Time, also known as Greenwich Mean Time or GMT in > the United Kingdom." > > If they are equal, The question is _are_ they equal? There is an exact defintion for what "UTC" is, and there's another exact definition of what UT1 is (more about this later). Civil timezones are defined as offsets from UTC. It seems that "GMT" no longer has an exact definition (at least from a metrologist's perspective) can be used to mean either UTC or UT1. UTC and UT1 can differ by up to 1 second. Leap seconds are occasionally added to UTC to keep it from drifting more than 1 second from UT1. >From a metrology point of view, what was originally called "GMT" (solar time at 0 degrees longtitude) is now called "UT1". So some people rightly claim that "GMT" means UT1. But nobody actually _uses_ UT1 (except metrologists and astronomers). All civil time is based on UTC: the official time in Greenwich (except during BST) is not UT1, it's UTC. So some other people rightly claim that "GMT" refers to UTC. In a software libary context, I would say that GMT should mean UTC and they ought to be considered equal and should always produce identical results. In a metrology context, people saying "GMT" probably ought to be smacked across the knuckes with a 12-inch platinum-iridium ruler and asked to try again until they specify either UTC or UT1 (or some other precisely defined UT-flavor). http://en.wikipedia.org/wiki/Universal_Time -- Grant Edwards grant.b.edwards Yow! A dwarf is passing out at somewhere in Detroit! gmail.com From storchaka at gmail.com Wed Jan 29 14:12:18 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Wed, 29 Jan 2014 21:12:18 +0200 Subject: [RELEASED] Python 3.3.4 release candidate 1 In-Reply-To: References: <52E60C8E.1050908@python.org> Message-ID: 29.01.14 18:55, Andrew Svetlov ???????(??): > Would you to accept fixes for http://bugs.python.org/issue20434 and > http://bugs.python.org/issue20437 before 3.3.4 final? And http://bugs.python.org/issue20440. From mickverdu at gmail.com Wed Jan 29 15:23:43 2014 From: mickverdu at gmail.com (mick verdu) Date: Wed, 29 Jan 2014 12:23:43 -0800 (PST) Subject: Eclipse IDE printing values automatically In-Reply-To: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> References: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> Message-ID: <583ab407-7831-45d7-b15d-46b30a6cccf1@googlegroups.com> Thanks for reply. I am running file via ctrl+F11 and seeing output on pyDev Console. My code has got nested dictionaries, lists and tuples. What you want to see? From breamoreboy at yahoo.co.uk Wed Jan 29 15:44:45 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Wed, 29 Jan 2014 20:44:45 +0000 Subject: Eclipse IDE printing values automatically In-Reply-To: <583ab407-7831-45d7-b15d-46b30a6cccf1@googlegroups.com> References: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> <583ab407-7831-45d7-b15d-46b30a6cccf1@googlegroups.com> Message-ID: On 29/01/2014 20:23, mick verdu wrote: > > Thanks for reply. > I am running file via ctrl+F11 and seeing output on pyDev Console. My code has got nested dictionaries, lists and tuples. What you want to see? > Two things, code and context. See here for how to go about this http://sscce.org/ -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From skip at pobox.com Wed Jan 29 16:52:05 2014 From: skip at pobox.com (Skip Montanaro) Date: Wed, 29 Jan 2014 15:52:05 -0600 Subject: UTC "timezone" causing brain explosions Message-ID: Following up on my earlier note about UTC v. GMT, I am having some trouble grokking attempts to convert a datetime into UTC. Consider these three values: >>> import pytz >>> UTC = pytz.timezone("UTC") >>> UTC >>> LOCAL_TZ = pytz.timezone("America/Chicago") >>> LOCAL_TZ >>> now = datetime.datetime.now() >>> now datetime.datetime(2014, 1, 29, 15, 39, 35, 263666) All well and good, right? The variable "now" is a naive datetime object. I happen to be sitting in a chair in the city of Chicago, so let's call it what it is, a datetime in the America/Chicago timezone: >>> s = LOCAL_TZ.localize(now) >>> s datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=) That looks good to me. Now, let's normalize it to UTC: >>> t = UTC.normalize(s) >>> t datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=) >>> t.hour 15 WTF? Why isn't the t.hour == 21? Okay, let's see what GMT does for us: >>> GMT = pytz.timezone("GMT") >>> u = GMT.normalize(s) >>> u datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=) >>> u.hour 21 That looks correct, but I don't understand why I don't get hour==21 out of the UTC.normalize call. It's like it's a no-op. Skip From ethan at stoneleaf.us Wed Jan 29 17:21:00 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Wed, 29 Jan 2014 14:21:00 -0800 Subject: UTC "timezone" causing brain explosions In-Reply-To: References: Message-ID: <52E97ECC.4050104@stoneleaf.us> On 01/29/2014 01:52 PM, Skip Montanaro wrote: > Following up on my earlier note about UTC v. GMT, I am having some > trouble grokking attempts to convert a datetime into UTC. > > Okay, let's see what GMT does for us: > >>>> GMT = pytz.timezone("GMT") >>>> u = GMT.normalize(s) >>>> u > datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=) >>>> u.hour > 21 > > That looks correct, but I don't understand why I don't get hour==21 > out of the UTC.normalize call. It's like it's a no-op. Having not examined the code, I can't tell you why UTC is different. I can say that .astimezone seems to work in all cases: --> GMT --> UTC --> LOCAL_TZ = pytz.timezone("America/Los_Angeles") --> now = datetime.datetime.now() --> s = LOCAL_TZ.localize(now) --> s datetime.datetime(2014, 1, 29, 14, 9, 56, 494967, tzinfo=) --> s.astimezone(UTC) datetime.datetime(2014, 1, 29, 22, 9, 56, 494967, tzinfo=) --> s.astimezone(GMT) datetime.datetime(2014, 1, 29, 22, 9, 56, 494967, tzinfo=) -- ~Ethan~ From ben+python at benfinney.id.au Wed Jan 29 17:44:58 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 30 Jan 2014 09:44:58 +1100 Subject: UTC "timezone" causing brain explosions References: Message-ID: <85eh3qcsr9.fsf@benfinney.id.au> Skip Montanaro writes: > Following up on my earlier note about UTC v. GMT, I am having some > trouble grokking attempts to convert a datetime into UTC. For what it's worth, you're not alone. Time zones are a hairy beast to manage, made all the more difficult because national politicians continually fiddle with them which means they can't just be a built-in part of the Python standard library. > Consider these three values: > > >>> import pytz > >>> UTC = pytz.timezone("UTC") > >>> UTC > > >>> LOCAL_TZ = pytz.timezone("America/Chicago") > >>> LOCAL_TZ > > >>> now = datetime.datetime.now() > >>> now > datetime.datetime(2014, 1, 29, 15, 39, 35, 263666) > > All well and good, right? Not really :-) You avoid the pain if you never create naive datetime values in the first place. Instead, specify the timezone for the value you're creating:: >>> now = datetime.datetime.now(tz=LOCAL_TZ) >>> now datetime.datetime(2014, 1, 29, 16, 35, 7, 900526, tzinfo=) That way the value will respond correctly to requests to convert it to whatever timezone you specify:: >>> MELBOURNE = pytz.timezone("Australia/Melbourne") >>> now.astimezone(MELBOURNE) datetime.datetime(2014, 1, 30, 9, 35, 7, 900526, tzinfo=) >>> now.astimezone(UTC) datetime.datetime(2014, 1, 29, 22, 35, 7, 900526, tzinfo=) >>> now.astimezone(LOCAL_TZ) datetime.datetime(2014, 1, 29, 16, 35, 7, 900526, tzinfo=) -- \ ?We tend to scoff at the beliefs of the ancients. But we can't | `\ scoff at them personally, to their faces, and this is what | _o__) annoys me.? ?Jack Handey | Ben Finney From clp2 at rebertia.com Wed Jan 29 17:52:49 2014 From: clp2 at rebertia.com (Chris Rebert) Date: Wed, 29 Jan 2014 14:52:49 -0800 Subject: UTC "timezone" causing brain explosions In-Reply-To: References: Message-ID: On Wed, Jan 29, 2014 at 1:52 PM, Skip Montanaro wrote: > Following up on my earlier note about UTC v. GMT, I am having some > trouble grokking attempts to convert a datetime into UTC. Consider > these three values: > >>>> import pytz >>>> UTC = pytz.timezone("UTC") >>>> LOCAL_TZ = pytz.timezone("America/Chicago") >>>> LOCAL_TZ > >>>> now = datetime.datetime.now() >>>> now > datetime.datetime(2014, 1, 29, 15, 39, 35, 263666) > > All well and good, right? The variable "now" is a naive datetime > object. I happen to be sitting in a chair in the city of Chicago, so > let's call it what it is, a datetime in the America/Chicago timezone: > >>>> s = LOCAL_TZ.localize(now) >>>> s > datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo= 'America/Chicago' CST-1 day, 18:00:00 STD>) > > That looks good to me. Now, let's normalize it to UTC: I don't think .normalize() doesn't do what you think it does; it's related to timezones with DST. I believe you want datetime.astimezone() instead. >>>> t = UTC.normalize(s) >>>> t > datetime.datetime(2014, 1, 29, 15, 39, 35, 263666, tzinfo=) >>>> t.hour > 15 > > WTF? Why isn't the t.hour == 21? Because you didn't actually perform a proper timezone conversion: >>> t = s.astimezone(UTC) >>> t datetime.datetime(2014, 1, 29, 21, 39, 35, 263666, tzinfo=) >>> t.hour == 21 True > That looks correct, but I don't understand why I don't get hour==21 > out of the UTC.normalize call. It's like it's a no-op. It is indeed a no-op: "You can take shortcuts when dealing with the UTC side of timezone conversions. normalize() and localize() are not really necessary when there are no daylight savings time transitions to deal with." -- http://pytz.sourceforge.net Cheers, Chris From shangonichols at sbcglobal.net Wed Jan 29 18:26:04 2014 From: shangonichols at sbcglobal.net (shangonichols at sbcglobal.net) Date: Wed, 29 Jan 2014 23:26:04 +0000 Subject: =?utf-8?Q?Python_shell_wont_open_IDLE_or_an_exisiting_.py_files?= Message-ID: <774101.57561.bm@smtp216.mail.gq1.yahoo.com> I am on Windows 8, Python 3.3.4 and 3.3.3 and all previous versions exhibit the same problem on my Windows 8 PC. This problem occurred out of nowhere overnight. It was working fine for months until today. > I tried to open a file and nothing happened. If I tried to open a .py file > (any .py file) from an existing instance of IDLE, it briefly flashed up a > new window and then closed both the new window and the existing window > (normally it opens the requested in a new window leaving the existing window > untouched). > > If I launch the Python GUI it opens a Python Shell fine. But as soon as I > try to open a file (including a "new" file), it closes the Shell. > > I rebooted the machine. Same problem. > > I repaired the Python installation and rebooted. Same problem. > > I uninstalled Python. Rebooted. Deleted the Python33 directory entirely. > Rebooted. Installed Python. Rebooted. Same problem. > > Everything else on the system appears to be working just fine. > > Any ideas what the problem might be or how else I might go about fixing > things? Sent from Windows Mail -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Wed Jan 29 19:28:16 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Jan 2014 11:28:16 +1100 Subject: pytz question: GMT vs. UTC In-Reply-To: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> Message-ID: On Thu, Jan 30, 2014 at 11:17 AM, Dennis Lee Bieber wrote: > On Wed, 29 Jan 2014 19:02:53 +0000 (UTC), Grant Edwards > declaimed the following: > > >>to be smacked across the knuckes with a 12-inch platinum-iridium ruler > > Under what temperature/pressure conditions is that ruler? STP, of course. And the smack must be administered in exactly 1G environment, to ensure proper impact. ChrisA From irmen.NOSPAM at xs4all.nl Wed Jan 29 19:31:02 2014 From: irmen.NOSPAM at xs4all.nl (Irmen de Jong) Date: Thu, 30 Jan 2014 01:31:02 +0100 Subject: Pyro4 - reading files In-Reply-To: <2e810b96-cc98-48af-b651-4c5b866aff49@googlegroups.com> References: <2e810b96-cc98-48af-b651-4c5b866aff49@googlegroups.com> Message-ID: <52e99d45$0$2829$e4fe514c@news.xs4all.nl> On 28-1-2014 21:24, ganea.ionut.iulian at gmail.com wrote: > Hello there. > > I am currently working on a project involving the use of Pyro4. > > I have a scenario. > > We have the pc named A, and a pc named B. > > On pc B lies a python script, that includes pyro, and a method for reading files. > > On pc A, we create an instance to the pyro object on pc B. And we call the method for reading files. > > I want to read a file that lies on pc B, from pc A using the method of the pyro object i just created. > > Is it possible? > > Thank you. > Sure, and what you are describing, tells me that you have implemented the solution already... :-) Interesting might still be that Pyro4 provides some basic stuff by default to get a very basic file transfer feature; see the getfile method exposed by the built-in Flame object: http://pythonhosted.org/Pyro4/flame.html You can of course implement this yourself by simply adding a method to your own Pyro object that reads the required file and just returns the file contents, like you would write any normal python method. That being said, please be aware of the following: - Pyro is not an efficient choice for transferring large amounts of file data. If you have performance considerations, it may be better to select a different means of file transfer (such as ftp or rsync or whatever) - Security implications because you are providing remote access to local file data. Again, you might want to select a different way to transfer your files instead that by itself provides a means of securing access to the files (or you'll have to program it yourself as part of your Pyro solution) Irmen From python at mrabarnett.plus.com Wed Jan 29 21:40:12 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Jan 2014 02:40:12 +0000 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> Message-ID: <52E9BB8C.80000@mrabarnett.plus.com> On 2014-01-30 01:50, Dennis Lee Bieber wrote: > On Thu, 30 Jan 2014 11:28:16 +1100, Chris Angelico > declaimed the following: > >>On Thu, Jan 30, 2014 at 11:17 AM, Dennis Lee Bieber >> wrote: >>> On Wed, 29 Jan 2014 19:02:53 +0000 (UTC), Grant Edwards >>> declaimed the following: >>> >>> >>>>to be smacked across the knuckes with a 12-inch platinum-iridium ruler >>> >>> Under what temperature/pressure conditions is that ruler? >> >>STP, of course. And the smack must be administered in exactly 1G >>environment, to ensure proper impact. >> > How cruel... I suspect the smack at 0degC is much more painful than one > at room temperature > It's the 21st century; you should be making use of Unicode: 0?C. From rosuav at gmail.com Wed Jan 29 22:27:54 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Jan 2014 14:27:54 +1100 Subject: pytz question: GMT vs. UTC In-Reply-To: <52E9BB8C.80000@mrabarnett.plus.com> References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: >> How cruel... I suspect the smack at 0degC is much more painful >> than one >> at room temperature >> > It's the 21st century; you should be making use of Unicode: 0?C. I started to read that and thought you were going to advocate the use of 0?K... ChrisA From tjreedy at udel.edu Wed Jan 29 22:38:15 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Wed, 29 Jan 2014 22:38:15 -0500 Subject: Python shell wont open IDLE or an exisiting .py files In-Reply-To: <774101.57561.bm@smtp216.mail.gq1.yahoo.com> References: <774101.57561.bm@smtp216.mail.gq1.yahoo.com> Message-ID: On 1/29/2014 6:26 PM, shangonichols at sbcglobal.net wrote: > I am on Windows 8, Python 3.3.4 and 3.3.3 and all previous versions > exhibit the same problem on my Windows 8 PC. This problem occurred out > of nowhere overnight. It was working fine for months until today. Try the following, which I believe I said before. 1. Start the normal console interpreter 'Python (command interpreter)' in the Start Menu. 2. In the interpreter, type >>> import idlelib.idle 3. Open a file. If Idle quits, 4. If Idle quits, look in the console for an exception message. 5. If you do not understand it, *copy and paste the entire message* here. 6. If the Python console also closes, report here. > > I tried to open a file and nothing happened. If I tried to open a > .py file > > (any .py file) from an existing instance of IDLE, it briefly flashed up a > > new window and then closed both the new window and the existing window > > (normally it opens the requested in a new window leaving the existing > window > > untouched). This much I understood. > > If I launch the Python GUI it opens a Python Shell fine. But as soon as I > > try to open a file (including a "new" file), it closes the Shell. This I do not. What is 'Python GUI'? What is 'Python Shell'? > > I rebooted the machine. Same problem. > > > > I repaired the Python installation and rebooted. Same problem. > > > > I uninstalled Python. Rebooted. Deleted the Python33 directory entirely. > > Rebooted. Installed Python. Rebooted. Same problem. > > > > Everything else on the system appears to be working just fine. > > > > Any ideas what the problem might be or how else I might go about fixing > > things? > > > > Sent from Windows Mail > > > -- Terry Jan Reedy From ben+python at benfinney.id.au Wed Jan 29 23:16:52 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Thu, 30 Jan 2014 15:16:52 +1100 Subject: Python shell wont open IDLE or an exisiting .py files References: <774101.57561.bm@smtp216.mail.gq1.yahoo.com> Message-ID: <85a9eecde3.fsf@benfinney.id.au> Terry Reedy writes: > On 1/29/2014 6:26 PM, shangonichols at sbcglobal.net wrote: > > > If I launch the Python GUI it opens a Python Shell fine. But as > > > soon as I try to open a file (including a "new" file), it closes > > > the Shell. > > This I do not. What is 'Python GUI'? What is 'Python Shell'? Those are (part of) the names of menu entries created by the Python installer for MS Windows. I am not sure exactly what programs they invoke. -- \ ?? whoever claims any right that he is unwilling to accord to | `\ his fellow-men is dishonest and infamous.? ?Robert G. | _o__) Ingersoll, _The Liberty of Man, Woman and Child_, 1877 | Ben Finney From greg.ewing at canterbury.ac.nz Thu Jan 30 00:13:54 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 30 Jan 2014 18:13:54 +1300 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > On Mon, 27 Jan 2014 12:22:22 -0800, Rick Johnson wrote: > >>Why do we even need an "input" function anyway if all it is going to do >>is read from stdin? > > That's not all it does. > > For example, it handles backspacing, so that typing H E L O O BACKSPACE > BACKSPACE L O gives "HELLO" rather than "HELOO\x7f\x7fO". No, it doesn't -- that's handled at a lower level. Any other method of reading from stdin, as long as it hasn't been redirected away from the console, has the same behaviour. I typed some backspaces in the input to each of the following experiments, and they didn't end up in the data: >>> import sys >>> x = sys.stdin.readline() HELLO >>> x 'HELLO\n' >>> import os >>> f = os.fdopen(0) >>> y = f.readline() adsxx >>> y 'adsxx\n' So input() really is a pure convenience function. (That doesn't mean it's not worth having, though!) -- Greg From gordon at panix.com Thu Jan 30 00:39:42 2014 From: gordon at panix.com (John Gordon) Date: Thu, 30 Jan 2014 05:39:42 +0000 (UTC) Subject: Eclipse IDE printing values automatically References: <9da6b40b-bf80-4886-b958-c7b90a08e4d4@googlegroups.com> <583ab407-7831-45d7-b15d-46b30a6cccf1@googlegroups.com> Message-ID: In <583ab407-7831-45d7-b15d-46b30a6cccf1 at googlegroups.com> mick verdu writes: > Thanks for reply. > I am running file via ctrl+F11 and seeing output on pyDev Console. > My code has got nested dictionaries, lists and tuples. What you want to see? One thing you could try is to track down exactly which line(s) are causing the unwanted output. Add some print statements to your code, say one print every fifty lines or so. Or perhaps just one print statement at the top of each function. Make each message different so you can tell them apart in the output. When the unwanted output appears, take note of which of your print statements appears above and below it. Then you can add more print statements in between those two, until you have narrowed down exactly what line of code is causing the output. Then, if you still can't tell why it is happening, post that line of code here and maybe we can help. Or, if your program is short enough, you can just post the whole thing here. Be sure to give an example of the unwanted output, and tell us exactly how the program is being executed. If the program uses input files, be sure to give us those too. -- John Gordon Imagine what it must be like for a real medical doctor to gordon at panix.com watch 'House', or a real serial killer to watch 'Dexter'. From deathweasel at gmail.com Thu Jan 30 00:56:16 2014 From: deathweasel at gmail.com (Jessica Ross) Date: Wed, 29 Jan 2014 21:56:16 -0800 (PST) Subject: Try-except-finally paradox Message-ID: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> I found something like this in a StackOverflow discussion. >>> def paradox(): ... try: ... raise Exception("Exception raised during try") ... except: ... print "Except after try" ... return True ... finally: ... print "Finally" ... return False ... return None ... >>> return_val = paradox() Except after try Finally >>> return_val False I understand most of this. What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? From ian.g.kelly at gmail.com Thu Jan 30 01:23:47 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Wed, 29 Jan 2014 23:23:47 -0700 Subject: Try-except-finally paradox In-Reply-To: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: On Jan 29, 2014 11:01 PM, "Jessica Ross" wrote: > > I found something like this in a StackOverflow discussion. > >>> def paradox(): > ... try: > ... raise Exception("Exception raised during try") > ... except: > ... print "Except after try" > ... return True > ... finally: > ... print "Finally" > ... return False > ... return None > ... > >>> return_val = paradox() > Except after try > Finally > >>> return_val > False > > I understand most of this. > What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? The docs don't seem to specify what happens in this case, but this behavior is intuitive to me. If the except suite had raised an exception instead of returning, the return in the finally would suppress that. The generalized rule appears to be that the control flow specification executed later overrides the earlier. -------------- next part -------------- An HTML attachment was scrubbed... URL: From robotsondrugs at gmail.com Thu Jan 30 01:33:44 2014 From: robotsondrugs at gmail.com (Andrew Berg) Date: Thu, 30 Jan 2014 00:33:44 -0600 Subject: Try-except-finally paradox In-Reply-To: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: <52E9F248.9010001@gmail.com> On 2014.01.29 23:56, Jessica Ross wrote: > I found something like this in a StackOverflow discussion. >>>> def paradox(): > ... try: > ... raise Exception("Exception raised during try") > ... except: > ... print "Except after try" > ... return True > ... finally: > ... print "Finally" > ... return False > ... return None > ... >>>> return_val = paradox() > Except after try > Finally >>>> return_val > False > > I understand most of this. > What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? > My guess would be that the interpreter doesn't let the finally block get skipped under any circumstances, so the return value gets set to True, but then it forces the finally block to be run before returning, which changes the return value to False. -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 10.0 From greg.ewing at canterbury.ac.nz Thu Jan 30 01:44:31 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Thu, 30 Jan 2014 19:44:31 +1300 Subject: pytz question: GMT vs. UTC In-Reply-To: References: Message-ID: Grant Edwards wrote: > smacked across the knuckes with a 12-inch platinum-iridium ruler Imperial or Scottish inches? -- Greg From wxjmfauth at gmail.com Thu Jan 30 01:59:09 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Wed, 29 Jan 2014 22:59:09 -0800 (PST) Subject: Try-except-finally paradox In-Reply-To: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: <17d88e10-c8ae-4bec-a370-8c797073caab@googlegroups.com> Le jeudi 30 janvier 2014 06:56:16 UTC+1, Jessica Ross a ?crit?: > I found something like this in a StackOverflow discussion. > > >>> def paradox(): > > ... try: > > ... raise Exception("Exception raised during try") > > ... except: > > ... print "Except after try" > > ... return True > > ... finally: > > ... print "Finally" > > ... return False > > ... return None > > ... > > >>> return_val = paradox() > > Except after try > > Finally > > >>> return_val > > False > > > > I understand most of this. > > What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? ======== The paradox is, in my mind, that the fct paradox() is programmed to be paradoxal. Compare with: >>> def noparadox(i): ... try: ... a = 1 / i ... print('Process') ... except ZeroDivisionError: ... print("ZeroDivisionError") ... a = '?' ... except Exception: ... print("Exception") ... a = '?' ... finally: ... print("Finally") ... return a ... >>> noparadox(2) Process Finally 0.5 >>> noparadox(0) ZeroDivisionError Finally '?' >>> noparadox('asdf') Exception Finally '?' >>> jmf From wxjmfauth at gmail.com Thu Jan 30 03:45:20 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 30 Jan 2014 00:45:20 -0800 (PST) Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: Le jeudi 30 janvier 2014 04:27:54 UTC+1, Chris Angelico a ?crit?: > On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: > > >> How cruel... I suspect the smack at 0degC is much more painful > > >> than one > > >> at room temperature > > >> > > > It's the 21st century; you should be making use of Unicode: 0?C. > > > > I started to read that and thought you were going to advocate the use of 0?K... > > ====== The temperature unit is the "Kelvin", not the "Degree Kelvin". One writes: 0 K, 275.15 K It can also be the "Degree Celsius", not the "Celsius". One writes: -273.15 ?C, 0 ?C >>> import unicodedata as ud >>> for c in '\u2109\u212a\u2103\u00b0': ... print(ud.name(c)) ... DEGREE FAHRENHEIT KELVIN SIGN DEGREE CELSIUS DEGREE SIGN >>> jmf From tjreedy at udel.edu Thu Jan 30 04:37:34 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Jan 2014 04:37:34 -0500 Subject: Python shell wont open IDLE or an exisiting .py files In-Reply-To: <85a9eecde3.fsf@benfinney.id.au> References: <774101.57561.bm@smtp216.mail.gq1.yahoo.com> <85a9eecde3.fsf@benfinney.id.au> Message-ID: On 1/29/2014 11:16 PM, Ben Finney wrote: > Terry Reedy writes: > >> On 1/29/2014 6:26 PM, shangonichols at sbcglobal.net wrote: >>> > If I launch the Python GUI it opens a Python Shell fine. But as >>> > soon as I try to open a file (including a "new" file), it closes >>> > the Shell. >> >> This I do not. What is 'Python GUI'? What is 'Python Shell'? > > Those are (part of) the names of menu entries created by the Python > installer for MS Windows. I am not sure exactly what programs they > invoke. One entry is 'IDLE (Python GUI)'. I have never seen Idle referred to as 'Python GUI' as the later is non-specific and could refer to wxpython or pyqt or some other Python GUI. Idle open a window called Python x.y.z Shell (until recently just Shell). The other menu entry is 'Python (Command line)' and I am guessing that the paragraph above has nothing to do with this entry. -- Terry Jan Reedy From tjreedy at udel.edu Thu Jan 30 04:44:39 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Thu, 30 Jan 2014 04:44:39 -0500 Subject: buggy python interpretter or am I missing something here? In-Reply-To: References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 1/30/2014 12:13 AM, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Mon, 27 Jan 2014 12:22:22 -0800, Rick Johnson wrote: >> >>> Why do we even need an "input" function anyway if all it is going to do >>> is read from stdin? >> >> That's not all it does. What else it does is print a prompt before reading and to strip off the trailing newline. >> For example, it handles backspacing, so that typing H E L O O >> BACKSPACE BACKSPACE L O gives "HELLO" rather than "HELOO\x7f\x7fO". > > No, it doesn't -- that's handled at a lower level. > Any other method of reading from stdin, as long > as it hasn't been redirected away from the console, > has the same behaviour. > > I typed some backspaces in the input to each of the > following experiments, and they didn't end up in the > data: > > >>> import sys > >>> x = sys.stdin.readline() > HELLO > >>> x > 'HELLO\n' > >>> import os > >>> f = os.fdopen(0) > >>> y = f.readline() > adsxx > >>> y > 'adsxx\n' > > So input() really is a pure convenience function. > (That doesn't mean it's not worth having, though!) It is equivalent to def input(prompt): sys.stdout.write(prompt) return sys.stdin.read()[:-1] There was once an eval around the return, but that was determined to be a bad idea. -- Terry Jan Reedy From christian at python.org Thu Jan 30 04:49:11 2014 From: christian at python.org (Christian Heimes) Date: Thu, 30 Jan 2014 10:49:11 +0100 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On 30.01.2014 04:27, Chris Angelico wrote: > On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: >>> How cruel... I suspect the smack at 0degC is much more painful >>> than one >>> at room temperature >>> >> It's the 21st century; you should be making use of Unicode: 0?C. > > I started to read that and thought you were going to advocate the use of 0?K... It's 0 K. The SI-unit 'Kelvin' has no degree (although Lord Kelvin was a professor). *g* From rosuav at gmail.com Thu Jan 30 05:10:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Thu, 30 Jan 2014 21:10:45 +1100 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On Thu, Jan 30, 2014 at 8:49 PM, Christian Heimes wrote: > On 30.01.2014 04:27, Chris Angelico wrote: >> On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: >>>> How cruel... I suspect the smack at 0degC is much more painful >>>> than one >>>> at room temperature >>>> >>> It's the 21st century; you should be making use of Unicode: 0?C. >> >> I started to read that and thought you were going to advocate the use of 0?K... > > It's 0 K. The SI-unit 'Kelvin' has no degree (although Lord Kelvin was a > professor). *g* That thing. I knew that, honest I did. My brain's just not working properly at the moment, something to do with consecutive hours awake. But later on I'll be 0K. ChrisA From wxjmfauth at gmail.com Thu Jan 30 05:10:41 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Thu, 30 Jan 2014 02:10:41 -0800 (PST) Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: <527005d3-ea72-43b0-9aba-c716540ef0b4@googlegroups.com> Le jeudi 30 janvier 2014 10:49:11 UTC+1, Christian Heimes a ?crit?: > On 30.01.2014 04:27, Chris Angelico wrote: > > > On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: > > >>> How cruel... I suspect the smack at 0degC is much more painful > > >>> than one > > >>> at room temperature > > >>> > > >> It's the 21st century; you should be making use of Unicode: 0?C. > > > > > > I started to read that and thought you were going to advocate the use of 0?K... > > > > It's 0 K. The SI-unit 'Kelvin' has no degree (although Lord Kelvin was a > > professor). *g* Glad, that you read (received?) my previous post! From mal at europython.eu Thu Jan 30 05:29:35 2014 From: mal at europython.eu (M.-A. Lemburg) Date: Thu, 30 Jan 2014 11:29:35 +0100 Subject: Work on Call for Participation for EuroPython 2015 has started Message-ID: <52EA298F.6010009@europython.eu> [Please help spread the word by forwarding to other relevant mailing lists, user groups, etc.; thanks :-)] The EuroPython Society (EPS) has started work on preparing the Call for Participation (CFP) for organizing the EuroPython 2015 conference: http://www.europython-society.org/ For 2015, we are setting up a new structure for the conference organization, which is focused on local and distributed work groups that are closely integrated with the EuroPython Society. We hope to greatly reduce the work load for the local teams, attract community members that want to get involved and to streamline the whole process of transitioning from one location to the next, making the conference organization a lot easier for everyone. If you are interested in potentially signing up as local team or participating in the work groups, please subscribe to one of our communication channels: * Tumblr http://www.tumblr.com/follow/europythonsociety * RSS http://www.europython-society.org/rss * Twitter https://twitter.com/europythons * EuroPython Mailing List https://mail.python.org/mailman/listinfo/europython We are aiming for end of February as announcement date for the CFP 2015. Enjoy, -- Marc-Andre Lemburg Director EuroPython Society http://www.europython-society.org/ From ayushidalmia2604 at gmail.com Thu Jan 30 05:50:26 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Thu, 30 Jan 2014 02:50:26 -0800 (PST) Subject: fseek In Compressed Files Message-ID: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Hello, I need to randomly access a bzip2 or gzip file. How can I set the offset for a line and later retreive the line from the file using the offset. Pointers in this direction will help. From __peter__ at web.de Thu Jan 30 06:28:32 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Jan 2014 12:28:32 +0100 Subject: fseek In Compressed Files References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: Ayushi Dalmia wrote: > I need to randomly access a bzip2 or gzip file. How can I set the offset > for a line and later retreive the line from the file using the offset. > Pointers in this direction will help. with gzip.open(filename) as f: f.seek(some_pos) print(f.readline()) f.seek(some_pos) print(f.readline()) seems to work as expected. Can you tell a bit more about your usecase (if it isn't covered by that basic example)? From thibault.langlois at gmail.com Thu Jan 30 06:36:53 2014 From: thibault.langlois at gmail.com (Thibault Langlois) Date: Thu, 30 Jan 2014 03:36:53 -0800 (PST) Subject: 1 > 0 == True -> False Message-ID: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Hello, $ python Python 2.7.4 (default, Sep 26 2013, 03:20:26) [GCC 4.7.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1 > 0 == True False >>> (1 > 0) == True True >>> 1 > (0 == True) True >>> What am I missing here ? T. From thomas at mlynarczyk-webdesign.de Thu Jan 30 06:44:29 2014 From: thomas at mlynarczyk-webdesign.de (Thomas Mlynarczyk) Date: Thu, 30 Jan 2014 12:44:29 +0100 Subject: 1 > 0 == True -> False In-Reply-To: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: Thibault Langlois schrieb: >>>> 1 > 0 == True > False > What am I missing here ? This, perhaps: http://www.primozic.net/nl/chaining-comparison-operators-in-python/ Greetings, Thomas -- Ce n'est pas parce qu'ils sont nombreux ? avoir tort qu'ils ont raison! (Coluche) From jpiitula at ling.helsinki.fi Thu Jan 30 06:46:48 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 Jan 2014 13:46:48 +0200 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: Thibault Langlois writes: > Hello, > > $ python > Python 2.7.4 (default, Sep 26 2013, 03:20:26) > [GCC 4.7.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> 1 > 0 == True > False > >>> (1 > 0) == True > True > >>> 1 > (0 == True) > True > >>> > > What am I missing here ? One or both of the following: >>> 0 == True False >>> True and False False >>> 1 > 0 True Or the fact that (1 > 0 == True) means ((1 > 0) and (0 == True)), where each expression in such a chain is evaluated once, though in this case it really does not matter since 0 is a literal. Hm, I don't know if the evaluation short-circuits. I think not, but I've never needed to know, and I don't need to know now. From python at mrabarnett.plus.com Thu Jan 30 06:51:53 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Jan 2014 11:51:53 +0000 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: <52EA3CD9.9050800@mrabarnett.plus.com> On 2014-01-30 08:45, wxjmfauth at gmail.com wrote: > Le jeudi 30 janvier 2014 04:27:54 UTC+1, Chris Angelico a ?crit : >> On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: >> >> >> How cruel... I suspect the smack at 0degC is much more painful >> >> >> than one >> >> >> at room temperature >> >> >> >> >> > It's the 21st century; you should be making use of Unicode: 0?C. >> >> >> >> I started to read that and thought you were going to advocate the use of 0?K... >> >> > > ====== > > The temperature unit is the "Kelvin", not the "Degree Kelvin". > One writes: 0 K, 275.15 K > Not that long ago I saw a science fiction film in which one of the "scientists" said "degrees Kelvin". The rest of the "science" was somewhat dubious too... > It can also be the "Degree Celsius", not the "Celsius". > One writes: -273.15 ?C, 0 ?C > > > >>>> import unicodedata as ud >>>> for c in '\u2109\u212a\u2103\u00b0': > ... print(ud.name(c)) > ... > DEGREE FAHRENHEIT > KELVIN SIGN > DEGREE CELSIUS > DEGREE SIGN >>>> > From davea at davea.name Thu Jan 30 06:55:32 2014 From: davea at davea.name (Dave Angel) Date: Thu, 30 Jan 2014 06:55:32 -0500 (EST) Subject: fseek In Compressed Files References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: Ayushi Dalmia Wrote in message: > Hello, > > I need to randomly access a bzip2 or gzip file. How can I set the offset for a line and later retreive the line from the file using the offset. Pointers in this direction will help. > Start with the zlib module. Note that it doesn't handle all possible compression types, like compress and pack. I don't imagine that seeking to a line in a compressed text file would be any easier than a non compressed one. Try using gzip.open in a text mode to get a handle, then loop through it line by line. If you save all the offsets in a list, you should subsequently be able to seek to a remembered offset. But realize it'll be horribly slow, compared to a non compressed one. Consider using readlines and referencing the lines from there. Or building a temp file if too big for ram. If this is not enough, tell us your Python version and your os, and show what you've tried and what went wrong. -- DaveA From davea at davea.name Thu Jan 30 07:05:15 2014 From: davea at davea.name (Dave Angel) Date: Thu, 30 Jan 2014 07:05:15 -0500 (EST) Subject: Try-except-finally paradox References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: Jessica Ross Wrote in message: > I found something like this in a StackOverflow discussion. >>>> def paradox(): > ... try: > ... raise Exception("Exception raised during try") > ... except: > ... print "Except after try" > ... return True > ... finally: > ... print "Finally" > ... return False > ... return None > ... >>>> return_val = paradox() > Except after try > Finally >>>> return_val > False > > I understand most of this. > What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? > The finally has to happen before any return inside the try or the except. And once you're in the finally clause you'll finish it before resuming the except clause. Since it has a return, that will happen before the other returns. The one in the except block will never get reached. It's the only reasonable behavior., to my mind. -- DaveA From __peter__ at web.de Thu Jan 30 07:04:52 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Jan 2014 13:04:52 +0100 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: Jussi Piitulainen wrote: > Thibault Langlois writes: > >> Hello, >> >> $ python >> Python 2.7.4 (default, Sep 26 2013, 03:20:26) >> [GCC 4.7.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> 1 > 0 == True >> False >> >>> (1 > 0) == True >> True >> >>> 1 > (0 == True) >> True >> >>> >> >> What am I missing here ? > > One or both of the following: > > >>> 0 == True > False > >>> True and False > False > >>> 1 > 0 > True > > Or the fact that (1 > 0 == True) means ((1 > 0) and (0 == True)), > where each expression in such a chain is evaluated once, though in > this case it really does not matter since 0 is a literal. > > Hm, I don't know if the evaluation short-circuits. I think not, but > I've never needed to know, and I don't need to know now. It is easy to check though: >>> def zero(): ... print("zero") ... return 0 ... >>> def one(): ... print("one") ... return 1 ... >>> def true(): ... print("true") ... return True ... >>> one() > zero() == true() one zero true False >>> zero() > one() == true() zero one False So yes, evaluation does short-curcuit. From jpiitula at ling.helsinki.fi Thu Jan 30 07:08:44 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 Jan 2014 14:08:44 +0200 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: Peter Otten writes: > Jussi Piitulainen wrote: > > > Thibault Langlois writes: > > > >> Hello, > >> > >> $ python > >> Python 2.7.4 (default, Sep 26 2013, 03:20:26) > >> [GCC 4.7.3] on linux2 > >> Type "help", "copyright", "credits" or "license" for more information. > >> >>> 1 > 0 == True > >> False > >> >>> (1 > 0) == True > >> True > >> >>> 1 > (0 == True) > >> True > >> >>> > >> > >> What am I missing here ? > > > > One or both of the following: > > > > >>> 0 == True > > False > > >>> True and False > > False > > >>> 1 > 0 > > True > > > > Or the fact that (1 > 0 == True) means ((1 > 0) and (0 == True)), > > where each expression in such a chain is evaluated once, though in > > this case it really does not matter since 0 is a literal. > > > > Hm, I don't know if the evaluation short-circuits. I think not, but > > I've never needed to know, and I don't need to know now. > > It is easy to check though: > > >>> def zero(): > ... print("zero") > ... return 0 > ... > >>> def one(): > ... print("one") > ... return 1 > ... > >>> def true(): > ... print("true") > ... return True > ... > >>> one() > zero() == true() > one > zero > true > False > >>> zero() > one() == true() > zero > one > False > > So yes, evaluation does short-curcuit. Now I'm experiencing a mild form of information overload. Thanks anyway :) My guess was wrong. Now that I think of it, I've implemented a parser and evaluator once with this kind of chaining, and it may well have short-circuited. From jldunn2000 at gmail.com Thu Jan 30 07:39:36 2014 From: jldunn2000 at gmail.com (loial) Date: Thu, 30 Jan 2014 04:39:36 -0800 (PST) Subject: Add directory to sys.path based on variable Message-ID: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> I want to add a path to sys.path based upon a variable Can I do that? Hardcodeing the path works fine, but I want to set it based upon a variable. I know I can set PYTHONPATH, but just wondering if I can add a directory on the fly to sys.path using a variable From mail at timgolden.me.uk Thu Jan 30 07:42:49 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 30 Jan 2014 12:42:49 +0000 Subject: Add directory to sys.path based on variable In-Reply-To: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> References: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> Message-ID: <52EA48C9.1010100@timgolden.me.uk> On 30/01/2014 12:39, loial wrote: > I want to add a path to sys.path based upon a variable > > Can I do that? > > Hardcodeing the path works fine, but I want to set it based upon a > variable. > > I know I can set PYTHONPATH, but just wondering if I can add a > directory on the fly to sys.path using a variable Certainly: import sys newpath = "c:/users/tim/modules" sys.path.append(newpath) TJG From davea at davea.name Thu Jan 30 07:49:19 2014 From: davea at davea.name (Dave Angel) Date: Thu, 30 Jan 2014 07:49:19 -0500 (EST) Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: Thibault Langlois Wrote in message: > Hello, > > $ python > Python 2.7.4 (default, Sep 26 2013, 03:20:26) > [GCC 4.7.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> 1 > 0 == True > False >>>> (1 > 0) == True > True >>>> 1 > (0 == True) > True >>>> > > What am I missing here ? > > T. > You tell us. You supply only half the question, what it does, without saying what you expected or needed. I expect you're either confused about comparison chaining or about what happens when you compare objects of different types. Doing an ordered comparison between two types is undefined by default, and not guaranteed to even give the same result between builds. So the following may give different results on your 2.7.4 than on mine. 5 < "abc" Python 3 fixes that by throwing an exception. TypeError: unorderable types This should solve it, since the first and third expression would seem to be undefined. Unfortunately there's yet another wrinkle. For hysterical reasons, True and False are instances of class bool, which is derived from int. So for comparison purposes False==0 and True==1. But in my opinion, you should never take advantage of this, except when entering obfuscation contests. -- DaveA From rosuav at gmail.com Thu Jan 30 08:02:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 00:02:18 +1100 Subject: Try-except-finally paradox In-Reply-To: References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: On Thu, Jan 30, 2014 at 11:05 PM, Dave Angel wrote: > The finally has to happen before any return inside the try or the > except. And once you're in the finally clause you'll finish it > before resuming the except clause. Since it has a return, that > will happen before the other returns. The one in the except block > will never get reached. > > It's the only reasonable behavior., to my mind. It's arguable that putting a return inside a finally is unreasonable behaviour, but that's up to the programmer. A finally clause can be used to do what might be done in C++ with a destructor: "no matter how this function/block exits, do this as you unwind the stack". In C++, I might open a file like this: void func() { ofstream output("output.txt"); // do a whole lot of stuff ... // at the close brace, output.~output() will be called, which will close the file } In Python, the equivalent would be: def func(): try: output = open("output.txt", "w") # do a whole lot of stuff ... finally: output.close() (Actually, the Python equivalent would be to use a 'with' clause for brevity, but 'with' uses try/finally under the covers, so it comes to the same thing.) The concept of the finally clause is: "Whether execution runs off the end, hits a return statement, or throws an exception, I need you do this before anything else happens". Having a return statement inside 'finally' as well as in 'try' is a bit of a corner case, since you're now saying "Before you finish this function and return something, I need you to return something else", which doesn't usually make sense. If you think Python's behaviour is confusing, first figure out what you would expect to happen in this situation :) ChrisA From python at mrabarnett.plus.com Thu Jan 30 08:11:52 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Jan 2014 13:11:52 +0000 Subject: Try-except-finally paradox In-Reply-To: References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: <52EA4F98.2050509@mrabarnett.plus.com> On 2014-01-30 13:02, Chris Angelico wrote: > On Thu, Jan 30, 2014 at 11:05 PM, Dave Angel wrote: >> The finally has to happen before any return inside the try or the >> except. And once you're in the finally clause you'll finish it >> before resuming the except clause. Since it has a return, that >> will happen before the other returns. The one in the except block >> will never get reached. >> >> It's the only reasonable behavior., to my mind. > > It's arguable that putting a return inside a finally is unreasonable > behaviour, but that's up to the programmer. A finally clause can be > used to do what might be done in C++ with a destructor: "no matter how > this function/block exits, do this as you unwind the stack". In C++, I > might open a file like this: > > void func() > { > ofstream output("output.txt"); > // do a whole lot of stuff ... > // at the close brace, output.~output() will be called, which will > close the file > } > > In Python, the equivalent would be: > > def func(): > try: > output = open("output.txt", "w") > # do a whole lot of stuff ... > finally: > output.close() > > (Actually, the Python equivalent would be to use a 'with' clause for > brevity, but 'with' uses try/finally under the covers, so it comes to > the same thing.) The concept of the finally clause is: "Whether > execution runs off the end, hits a return statement, or throws an > exception, I need you do this before anything else happens". Having a > return statement inside 'finally' as well as in 'try' is a bit of a > corner case, since you're now saying "Before you finish this function > and return something, I need you to return something else", which > doesn't usually make sense. If you think Python's behaviour is > confusing, first figure out what you would expect to happen in this > situation :) > One of the reasons that the 'with' statement was added was to prevent the mistake that you've just done. ;-) What if the file can't be opened? From rosuav at gmail.com Thu Jan 30 08:19:27 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 00:19:27 +1100 Subject: Try-except-finally paradox In-Reply-To: <52EA4F98.2050509@mrabarnett.plus.com> References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> <52EA4F98.2050509@mrabarnett.plus.com> Message-ID: On Fri, Jan 31, 2014 at 12:11 AM, MRAB wrote: > One of the reasons that the 'with' statement was added was to prevent > the mistake that you've just done. ;-) > > What if the file can't be opened? Yeah, whoops. The open shouldn't be inside try/finally. def func(): output = open("output.txt", "w") try: # do a whole lot of stuff ... finally: output.close() But my point still stands, I believe :) ChrisA From artomishka at yahoo.co.uk Thu Jan 30 08:26:16 2014 From: artomishka at yahoo.co.uk (Peter Clark) Date: Thu, 30 Jan 2014 13:26:16 +0000 (GMT) Subject: end quote help for a newbie Message-ID: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> There is probably an easy solution to this?? but I have not found it. Trying to terminate a literal in a print statement (from the tutorial). The literal should be enclosed in double quotes ? ? the initial double quote seems to be OK (if I use a different character it flags it) but the ending is flagged as invalid syntax.? I have tried changing my keyboard from UK to USA, without any effect, and tried adding a space after the final double quote, thanks for any assistance, peter -------------- next part -------------- An HTML attachment was scrubbed... URL: From ayushidalmia2604 at gmail.com Thu Jan 30 08:34:57 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Thu, 30 Jan 2014 05:34:57 -0800 (PST) Subject: fseek In Compressed Files In-Reply-To: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: <78213f6b-3311-4487-a611-ecd3de33a168@googlegroups.com> On Thursday, January 30, 2014 4:20:26 PM UTC+5:30, Ayushi Dalmia wrote: > Hello, > > > > I need to randomly access a bzip2 or gzip file. How can I set the offset for a line and later retreive the line from the file using the offset. Pointers in this direction will help. This is what I have done: import bz2 import sys from random import randint index={} data=[] f=open('temp.txt','r') for line in f: data.append(line) filename='temp1.txt.bz2' with bz2.BZ2File(filename, 'wb', compresslevel=9) as f: f.writelines(data) prevsize=0 list1=[] offset={} with bz2.BZ2File(filename, 'rb') as f: for line in f: words=line.strip().split(' ') list1.append(words[0]) offset[words[0]]= prevsize prevsize = sys.getsizeof(line)+prevsize data=[] count=0 with bz2.BZ2File(filename, 'rb') as f: while count<20: y=randint(1,25) print y print offset[str(y)] count+=1 f.seek(int(offset[str(y)])) x= f.readline() data.append(x) f=open('b.txt','w') f.write(''.join(data)) f.close() where temp.txt is the posting list file which is first written in a compressed format and then read later. I am trying to build the index for the entire wikipedia dump which needs to be done in a space and time optimised way. The temp.txt is as follows: 1 456 t0b3c0i0e0:784 t0b2c0i0e0:801 t0b2c0i0e0 2 221 t0b1c0i0e0:774 t0b1c0i0e0:801 t0b2c0i0e0 3 455 t0b7c0i0e0:456 t0b1c0i0e0:459 t0b2c0i0e0:669 t0b10c11i3e0:673 t0b1c0i0e0:678 t0b2c0i1e0:854 t0b1c0i0e0 4 410 t0b4c0i0e0:553 t0b1c0i0e0:609 t0b1c0i0e0 5 90 t0b1c0i0e0 6 727 t0b2c0i0e0 7 431 t0b2c0i1e0 8 532 t0b1c0i0e0:652 t0b1c0i0e0:727 t0b2c0i0e0 9 378 t0b1c0i0e0 10 666 t0b2c0i0e0 11 405 t0b1c0i0e0 12 702 t0b1c0i0e0 13 755 t0b1c0i0e0 14 781 t0b1c0i0e0 15 593 t0b1c0i0e0 16 725 t0b1c0i0e0 17 989 t0b2c0i1e0 18 221 t0b1c0i0e0:402 t0b1c0i0e0:842 t0b1c0i0e0 19 405 t0b1c0i0e0 20 200 t0b1c0i0e0:300 t0b1c0i0e0:398 t0b1c0i0e0:649 t0b1c0i0e0 21 66 t0b1c0i0e0 22 30 t0b1c0i0e0 23 126 t0b1c0i0e0:895 t0b1c0i0e0 24 355 t0b1c0i0e0:374 t0b1c0i0e0:378 t0b1c0i0e0:431 t0b3c0i0e0:482 t0b1c0i0e0:546 t0b3c0i0e0:578 t0b1c0i0e0 25 198 t0b1c0i0e0 From python at mrabarnett.plus.com Thu Jan 30 08:35:50 2014 From: python at mrabarnett.plus.com (MRAB) Date: Thu, 30 Jan 2014 13:35:50 +0000 Subject: end quote help for a newbie In-Reply-To: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> References: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> Message-ID: <52EA5536.50606@mrabarnett.plus.com> On 2014-01-30 13:26, Peter Clark wrote: > There is probably an easy solution to this ? but I have not found it. > Trying to terminate a literal in a print statement (from the tutorial). > The literal should be enclosed in double quotes ? ? > the initial double quote seems to be OK (if I use a different character > it flags it) but the ending is flagged as invalid syntax. I have tried > changing my keyboard from UK to USA, without any effect, and tried > adding a space after the final double quote, > What are you trying to put between the quotes? From skip at pobox.com Thu Jan 30 08:36:03 2014 From: skip at pobox.com (Skip Montanaro) Date: Thu, 30 Jan 2014 07:36:03 -0600 Subject: end quote help for a newbie In-Reply-To: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> References: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> Message-ID: Not sure if this is exactly what you're asking, but perhaps you want triple quotes? >>> print "now is the time for all good men ..." now is the time for all good men ... >>> print '''now is the time for "all good men" ...''' now is the time for "all good men" ... It's not easy to visually distinguish two apostrophes from a double quote in all fonts, so I've explicitly written this using rich text and highlighted the Python session snippet in Courier. Skip -------------- next part -------------- An HTML attachment was scrubbed... URL: From thibault.langlois at gmail.com Thu Jan 30 08:40:48 2014 From: thibault.langlois at gmail.com (Thibault Langlois) Date: Thu, 30 Jan 2014 05:40:48 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> On Thursday, January 30, 2014 12:49:19 PM UTC, Dave Angel wrote: > Thibault Langlois Wrote in message: > > > Hello, > > > > > > $ python > > > Python 2.7.4 (default, Sep 26 2013, 03:20:26) > > > [GCC 4.7.3] on linux2 > > > Type "help", "copyright", "credits" or "license" for more information. > > >>>> 1 > 0 == True > > > False > > >>>> (1 > 0) == True > > > True > > >>>> 1 > (0 == True) > > > True > > >>>> > > > > > > What am I missing here ? > > > > > > T. > > > > > > > You tell us. You supply only half the question, what it does, > > without saying what you expected or needed. > > > > I expect you're either confused about comparison chaining or about > > what happens when you compare objects of different types. > > > > > > Doing an ordered comparison between two types is undefined by > > default, and not guaranteed to even give the same result between > > builds. So the following may give different results on your > > 2.7.4 than on mine. > > 5 < "abc" > > > > Python 3 fixes that by throwing an exception. TypeError: > > unorderable types > > > > This should solve it, since the first and third expression would > > seem to be undefined. Unfortunately there's yet another wrinkle. > > > > > > For hysterical reasons, True and False are instances of class > > bool, which is derived from int. So for comparison purposes > > False==0 and True==1. But in my opinion, you should never take > > advantage of this, except when entering obfuscation > > contests. > > > > > > -- > > DaveA You are right. I should have given some context. I am looking at this from the perspective of the teacher that has to explain idiosyncrasies of the language to inexperienced students. There are two aspects in this example. 1. the equivalence of True/False with integers 1/0 which have pro and cons. 2. the chaining rules of operators. I agree that it may make sense in some cases like x > y > z but when operators are mixed it leads to counter intuitive cases as the one I pointed out. The recommendations to student are 1) do not assume True == 1 and do not use operator chaining. From 11msccssbashir at seecs.edu.pk Thu Jan 30 08:34:04 2014 From: 11msccssbashir at seecs.edu.pk (Sadia Bashir) Date: Thu, 30 Jan 2014 18:34:04 +0500 Subject: Convert NTP timestamp from NTP packet to System time and date format Message-ID: Hello everyone; I want to write NTP client which sends and receives NTP packet to NTP server and should read the value from one of the four offsets and convert it to user readable local or GMT time format, I specifically want to know which offsets should I read in order to get correct timestamp from the packet. Any suggestion or help will be appreciated. -- *Sadia* -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jan 30 08:49:03 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 00:49:03 +1100 Subject: fseek In Compressed Files In-Reply-To: <78213f6b-3311-4487-a611-ecd3de33a168@googlegroups.com> References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> <78213f6b-3311-4487-a611-ecd3de33a168@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 12:34 AM, Ayushi Dalmia wrote: > where temp.txt is the posting list file which is first written in a compressed format and then read later. Unless you specify otherwise, a compressed file is likely to have sub-byte boundaries. It might not be possible to seek to a specific line. What you could do, though, is explicitly compress each line, then write out separately-compressed blocks. You can then seek to any one that you want, read it, and decompress it. But at this point, you're probably going to do better with a database; PostgreSQL, for instance, will automatically compress any content that it believes it's worthwhile to compress (as long as it's in a VARCHAR field or similar and the table hasn't been configured to prevent that, yada yada). All you have to do is tell Postgres to store this, retrieve that, and it'll worry about the details of compression and decompression. As an added benefit, you can divide the text up and let it do the hard work of indexing, filtering, sorting, etc. I suspect you'll find that deploying a database is a much more efficient use of your development time than recreating all of that. ChrisA From rosuav at gmail.com Thu Jan 30 08:55:44 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 00:55:44 +1100 Subject: 1 > 0 == True -> False In-Reply-To: <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 12:40 AM, Thibault Langlois wrote: > The recommendations to student are 1) do not assume True == 1 and do not use operator chaining. Not "do not use", but "do not misuse". Python's operator chaining is awesome for bounds checking: if 3 < x < 20: print("x is between 3 and 20, exclusive") You can even, since it short-circuits, do crazy stuff like: x = random.randrange(30) if int(input("Min: ")) < x < int(input("Max: ")): print("It's within those bounds.") It won't ask for a maximum if it's already failed to be within the minimum. (Okay, don't do this one. Not good code. Heh.) But don't use operator chaining when you don't mean it to behave that way. That's all! ChrisA From rosuav at gmail.com Thu Jan 30 09:02:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 01:02:35 +1100 Subject: Convert NTP timestamp from NTP packet to System time and date format In-Reply-To: References: Message-ID: On Fri, Jan 31, 2014 at 12:34 AM, Sadia Bashir <11msccssbashir at seecs.edu.pk> wrote: > Hello everyone; > > I want to write NTP client which sends and receives NTP packet to NTP server > and should read the value from one of the four offsets and convert it to > user readable local or GMT time format, I specifically want to know which > offsets should I read in order to get correct timestamp from the packet. > Any suggestion or help will be appreciated. > Any time you're looking at network protocols, the one obvious place to look is the RFCs. Just do a web search for 'rfc ntp' to find the relevant ones. In my case, the search results pulled up a couple of good-looking hits from ietf.org (the Internet Engineering Task Force - those guys are the authority on this sort of matter), plus the Wikipedia article for NTP, with a section "Relevant RFCs", which would make good reading. Enjoy! Networking's awesome fun. ChrisA From jldunn2000 at gmail.com Thu Jan 30 09:03:39 2014 From: jldunn2000 at gmail.com (loial) Date: Thu, 30 Jan 2014 06:03:39 -0800 (PST) Subject: Add directory to sys.path based on variable In-Reply-To: References: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> Message-ID: <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com> Ok, that works fine with the apth hard coded, but I want to do something like the code below. i.e I am trying to dynamically add a path that is relative to the path of the current executing python script. In this case the import fails. import sys import os from os.path import * scriptpath=os.path.dirname(sys.argv[0]) otherscriptspath=printerpath.replace("scripts","otherscripts") sys.path.append(otherscriptspath) from AuditUpdate import * From roy at panix.com Thu Jan 30 09:08:58 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 09:08:58 -0500 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: In article <3dcdc95d-5e30-46d3-b558-afedf9723c7c at googlegroups.com>, Thibault Langlois wrote: > You are right. I should have given some context. > I am looking at this from the perspective of the teacher that has to explain > idiosyncrasies of the language to inexperienced students. > There are two aspects in this example. > 1. the equivalence of True/False with integers 1/0 which have pro and cons. > 2. the chaining rules of operators. I agree that it may make sense in some > cases like x > y > z but when operators are mixed it leads to counter > intuitive cases as the one I pointed out. > > The recommendations to student are 1) do not assume True == 1 and do not use > operator chaining. Better than that, do what I do. 1) Assume that you don't have the full operator precedence table memorized and just parenthesize everything. 2) In cases where the expression is so simple, you couldn't possibly be wrong, see rule #1. From rosuav at gmail.com Thu Jan 30 09:09:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 01:09:56 +1100 Subject: Add directory to sys.path based on variable In-Reply-To: <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com> References: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 1:03 AM, loial wrote: > In this case the import fails. > > import sys > import os > from os.path import * Not sure why you need that, since you're explicitly naming "os.path.dirname". The base "import os" shoul cover that for you. > scriptpath=os.path.dirname(sys.argv[0]) > otherscriptspath=printerpath.replace("scripts","otherscripts") > sys.path.append(otherscriptspath) Try adding here: print(sys.argv[0]) print(otherscriptspath) See what they tell you. Is sys.argv[0] what you think it is? Is the resulting path what you expect? ChrisA From zachary.ware+pylist at gmail.com Thu Jan 30 09:13:17 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 30 Jan 2014 08:13:17 -0600 Subject: end quote help for a newbie In-Reply-To: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> References: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> Message-ID: On Thu, Jan 30, 2014 at 7:26 AM, Peter Clark wrote: > There is probably an easy solution to this ? but I have not found it. > > Trying to terminate a literal in a print statement (from the tutorial). > > The literal should be enclosed in double quotes ? ? > > the initial double quote seems to be OK (if I use a different character it > flags it) but the ending is flagged as invalid syntax. I have tried > changing my keyboard from UK to USA, without any effect, and tried adding a > space after the final double quote, Which version of Python are you using? Make sure you're using the same version of interpreter and tutorial. 'print' was one of the big changes between Python 2 and Python 3 (in Python 2 it was a statement, while in Python 3 it is a function), so a tutorial written with Python 2 in mind will have some issues if you're using Python 3. If you've already checked that, try copying and pasting your entire interpreter session into a reply here, and we'll be more able to figure out what's going on. Hope this helps, -- Zach From mail at timgolden.me.uk Thu Jan 30 09:14:18 2014 From: mail at timgolden.me.uk (Tim Golden) Date: Thu, 30 Jan 2014 14:14:18 +0000 Subject: Add directory to sys.path based on variable In-Reply-To: <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com> References: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com> Message-ID: <52EA5E3A.7080801@timgolden.me.uk> On 30/01/2014 14:03, loial wrote: > Ok, that works fine with the apth hard coded, but I want to do something like the code below. i.e I am trying to dynamically add a path that is relative to the path of the current executing python script. > > In this case the import fails. > > import sys > import os > from os.path import * > > scriptpath=os.path.dirname(sys.argv[0]) > otherscriptspath=printerpath.replace("scripts","otherscripts") > sys.path.append(otherscriptspath) > > from AuditUpdate import * Well, adding a path to sys.path and then importing is generally considered a safe bet. So it's more likely that somewhere inside your path manipulation something's going wrong. You've presumably not cut-and-pasted that code from the console (since you've got an undefined "printerparth" on the 6th line). But why not scatter some print()s and os.listdir()s around, eg: import os, sys print(sys.path) print(sys.argv[0]) scriptpath=os.path.dirname(sys.argv[0]) print(scriptpath) otherscriptpath = scriptpath.replace("xxx", "yyy") print(otherscriptpath) print(os.listdir(otherscriptpath)) ... and so on. Somewhere in there, I imagine something won't be as you expect. Feel free to come back here if you need more help. TJG From rosuav at gmail.com Thu Jan 30 09:18:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 01:18:29 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith wrote: > Better than that, do what I do. > > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. Or: 1a) Assume that you don't have the full operator precedence table memorized and just look it up, for whichever language you're working with today. :) Usually the precedence table will also remind me of operator chaining, and whether the integer division and modulo operators are backward (compare REXX and Python with their % and // operators), and anything else that needs concern. ChrisA From jldunn2000 at gmail.com Thu Jan 30 09:26:59 2014 From: jldunn2000 at gmail.com (loial) Date: Thu, 30 Jan 2014 06:26:59 -0800 (PST) Subject: Add directory to sys.path based on variable In-Reply-To: References: <08cb4673-c926-487e-a101-299ed899239a@googlegroups.com> <7fcdfee3-c52a-4840-8033-920d23d3d7e3@googlegroups.com> Message-ID: <5c7a3ef4-3048-47a7-81a1-41bad721f77c@googlegroups.com> Idiot that I am...I was not calling the script with the full path ! Thanks for your help From jeanpierreda at gmail.com Thu Jan 30 09:41:31 2014 From: jeanpierreda at gmail.com (Devin Jeanpierre) Date: Thu, 30 Jan 2014 06:41:31 -0800 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: On Thu, Jan 30, 2014 at 6:08 AM, Roy Smith wrote: > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. > > 2) In cases where the expression is so simple, you couldn't possibly be > wrong, see rule #1. Also, assume you don't have the function definition syntax memorized, and just define functions. And assume you don't know Python, so just hire someone else to write your code instead. -- Devin From steve+comp.lang.python at pearwood.info Thu Jan 30 09:40:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Jan 2014 14:40:59 GMT Subject: end quote help for a newbie References: Message-ID: <52ea647b$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Jan 2014 13:26:16 +0000, Peter Clark wrote: > There is probably an easy solution to this?? but I have not found it. > > Trying to terminate a literal in a print statement (from the tutorial). I don't understand the problem. Perhaps if you show us what you have tried, and the error you get? Please copy and paste both your code and the full error, from the first line starting with "Traceback" and ending with the error message. Regardless of using print or not, you terminate strings with a matching quotation mark. If you start the string with a double-quote, you terminate it with the same double-quote. If you use a single-quote, the same applies. These two are okay: "Double quote" "Single quote" But not this: "Mixed quotes' 'Mixed quotes" > The literal should be enclosed in double quotes ? ? What editor are you using? If you are typing your code in Microsoft Office, you're going to have a bad time. At the very least, you need to turn "Smart Quotes" off. Python will not accept curly quotes such as ?? or ?? or any of the various other quotation marks, only plain old typewriter quotation marks ' and " (actually, these are foot and inch marks, but everyone treats them as if they were quotation marks). > the initial double quote seems to be OK (if I use a different character > it flags it) but the ending is flagged as invalid syntax.? I have tried > changing my keyboard from UK to USA, without any effect, and tried > adding a space after the final double quote, UK or USA keyboard won't make any difference. You need to use an ordinary text editor (or better still, a programmer's text editor) but not a word processor such as Word. If you must use Word, disable "Smart Quotes". That will avoid at least one source of problems. -- Steven From thibault.langlois at gmail.com Thu Jan 30 09:46:18 2014 From: thibault.langlois at gmail.com (Thibault Langlois) Date: Thu, 30 Jan 2014 06:46:18 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: <5ebb3d58-c23e-4938-924d-df7121ca1d04@googlegroups.com> On Thursday, January 30, 2014 2:08:58 PM UTC, Roy Smith wrote: > In article <3dcdc95d-5e30-46d3-b558-afedf9723c7c at googlegroups.com>, > > Thibault Langlois wrote: > > > > > You are right. I should have given some context. > > > I am looking at this from the perspective of the teacher that has to explain > > > idiosyncrasies of the language to inexperienced students. > > > There are two aspects in this example. > > > 1. the equivalence of True/False with integers 1/0 which have pro and cons. > > > 2. the chaining rules of operators. I agree that it may make sense in some > > > cases like x > y > z but when operators are mixed it leads to counter > > > intuitive cases as the one I pointed out. > > > > > > The recommendations to student are 1) do not assume True == 1 and do not use > > > operator chaining. > > > > Better than that, do what I do. > > > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > > > > 2) In cases where the expression is so simple, you couldn't possibly be > > wrong, see rule #1. Agreed ! From roy at panix.com Thu Jan 30 09:49:17 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 09:49:17 -0500 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: In article , Chris Angelico wrote: > On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith wrote: > > Better than that, do what I do. > > > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > > Or: > > 1a) Assume that you don't have the full operator precedence table > memorized and just look it up, for whichever language you're working > with today. :) It's faster to just stick in some extra parens. Not to mention that it makes the code more clear for everybody reading it later. Operator precedence is a tricky thing. In part, because it's somewhat arbitrary, and in part because it changes from language to language. Using "extra" parens to make my meaning clear (to both the compiler and other humans who read the code in the future) is a simple technique which works in all languages. From jpiitula at ling.helsinki.fi Thu Jan 30 09:56:19 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 Jan 2014 16:56:19 +0200 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: Roy Smith writes: > In article <3dcdc95d-5e30-46d3-b558-afedf9723c7c at googlegroups.com>, > Thibault Langlois wrote: > > > You are right. I should have given some context. I am looking at > > this from the perspective of the teacher that has to explain > > idiosyncrasies of the language to inexperienced students. > > > > There are two aspects in this example. > > 1. the equivalence of True/False with integers 1/0 which have pro > > and cons. > > 2. the chaining rules of operators. I agree that it may make sense > > in some cases like x > y > z but when operators are mixed it leads > > to counter intuitive cases as the one I pointed out. > > > > The recommendations to student are 1) do not assume True == 1 and > > do not use operator chaining. > > Better than that, do what I do. > > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. > > 2) In cases where the expression is so simple, you couldn't possibly > be wrong, see rule #1. There's nothing to parenthesize in x <= y < z = w, unless you mean something rather weird that is not equivalent anyway (and may not be compatible with avoiding assumptions like True == 1). There's not much to remember: the comparison operators are a semantically coherent class (as far as I can see) and have the same precedence level somewhere between proper operators (let's call them that) and and and or and if else[1]. Ok, I'm not quite sure how the two branches of a conditional expression combine. Rather than find out, use parentheses, yes: (x + 1) if c else x == x + (1 if c else 0) == x + bool(c) I agree about using parentheses when in doubt, but there is some room here for more education and less doubt. Python gets these right. [1] Sorry... From rosuav at gmail.com Thu Jan 30 10:02:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 02:02:21 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 1:49 AM, Roy Smith wrote: > In article , > Chris Angelico wrote: > >> On Fri, Jan 31, 2014 at 1:08 AM, Roy Smith wrote: >> > Better than that, do what I do. >> > >> > 1) Assume that you don't have the full operator precedence table >> > memorized and just parenthesize everything. >> >> Or: >> >> 1a) Assume that you don't have the full operator precedence table >> memorized and just look it up, for whichever language you're working >> with today. :) > > It's faster to just stick in some extra parens. Not to mention that it > makes the code more clear for everybody reading it later. That won't protect you from getting modulo and truncating-division mixed up. :) > Operator precedence is a tricky thing. In part, because it's somewhat > arbitrary, and in part because it changes from language to language. > Using "extra" parens to make my meaning clear (to both the compiler and > other humans who read the code in the future) is a simple technique > which works in all languages. It's not arbitrary, but there are differences from language to language. Yes, parens can help, but I would strongly advocate NOT using them where it's utterly unambiguous: x = (2*3)+4 # Pointless! Whether your language works with * before + (the sane way, doing what we expect from algebra) or purely left to right (the insane way, but some languages do do that), the parens are superfluous. Don't use 'em! But if you work with both PHP and any other language that has a ?: operator, parenthesizing any nesting of them will avoid a PHP stupidity. Not that that's really any sort of argument here, though. ChrisA From storchaka at gmail.com Thu Jan 30 10:02:58 2014 From: storchaka at gmail.com (Serhiy Storchaka) Date: Thu, 30 Jan 2014 17:02:58 +0200 Subject: fseek In Compressed Files In-Reply-To: References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: 30.01.14 13:28, Peter Otten ???????(??): > Ayushi Dalmia wrote: > >> I need to randomly access a bzip2 or gzip file. How can I set the offset >> for a line and later retreive the line from the file using the offset. >> Pointers in this direction will help. > > with gzip.open(filename) as f: > f.seek(some_pos) > print(f.readline()) > f.seek(some_pos) > print(f.readline()) > > seems to work as expected. Can you tell a bit more about your usecase (if it > isn't covered by that basic example)? I don't recommend to seek backward in compressed file. This is very inefficient operation. From steve+comp.lang.python at pearwood.info Thu Jan 30 10:09:03 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 30 Jan 2014 15:09:03 GMT Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > 1) Assume that you don't have the full operator precedence table > memorized and just parenthesize everything. Oh really? Do you actually write stuff like this? b = ((2*a) + 1) if (b >= (-1)): ... I would hope not. > 2) In cases where the expression is so simple, you couldn't possibly be > wrong, see rule #1. Or, you can avoid superstitious responses *wink* (1) Learn the operator precedences to the best of your ability. It's not hard, most of it works just like the precedences you're used to from maths class (remember that?) or in the most intuitively useful way. E.g. `1 + x == 2` does the useful thing of calculating 1 + x before testing for equality, rather than the stupid thing of calculating x == 2 first then adding it to 1. (2) When in doubt, use parentheses. (3) When the expression is complex, a few extra parentheses can help make it easier to understand. "Seven, plus or minus two" is (roughly) the number of distinct items the human short- term memory can hold. Grouping terms together can help reduce the distinct number of items the reader needs to keep in short-term memory. E.g. `x+1 > 0 and y >= 5` is potentially as many as 9 distinct items to keep in short-term memory. But bracketing some terms as in `(x+1 > 0) and (y >= 5)` can reduce that down to as few as two items. (4) But too many parens obscure the meaning of the expression too. Aim for a good balance, neither too few nor too many. Your judgement of the right number of parens is a skill, which will come with experience. -- Steven From mailman at hanez.org Thu Jan 30 10:03:30 2014 From: mailman at hanez.org (Johannes Findeisen) Date: Thu, 30 Jan 2014 16:03:30 +0100 Subject: Convert NTP timestamp from NTP packet to System time and date format In-Reply-To: References: Message-ID: <20140130160330.093452ce@hanez.org> On Thu, 30 Jan 2014 18:34:04 +0500 Sadia Bashir wrote: > Hello everyone; > > I want to write NTP client which sends and receives NTP packet to NTP > server and should read the value from one of the four offsets and convert > it to user readable local or GMT time format, I specifically want to know > which offsets should I read in order to get correct timestamp from the > packet. > Any suggestion or help will be appreciated. Maybe this lib is of interest to you: https://pypi.python.org/pypi/ntplib/ It does all the NTP stuff for you. If you want to implement that stuff by yourself just take a look at the code of ntplib, it should explain what you want. Regards, Johannes From invalid at invalid.invalid Thu Jan 30 10:21:35 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 30 Jan 2014 15:21:35 +0000 (UTC) Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On 2014-01-30, wxjmfauth at gmail.com wrote: > The temperature unit is the "Kelvin", not the "Degree Kelvin". > One writes: 0 K, 275.15 K And remember to say "Kelvins" not "Kelvin" when speaking about temperatures other than 1 K. -- Grant Edwards grant.b.edwards Yow! BELA LUGOSI is my at co-pilot ... gmail.com From invalid at invalid.invalid Thu Jan 30 10:23:24 2014 From: invalid at invalid.invalid (Grant Edwards) Date: Thu, 30 Jan 2014 15:23:24 +0000 (UTC) Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On 2014-01-30, Christian Heimes wrote: > On 30.01.2014 04:27, Chris Angelico wrote: >> On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: >>>> How cruel... I suspect the smack at 0degC is much more painful >>>> than one >>>> at room temperature >>>> >>> It's the 21st century; you should be making use of Unicode: 0??C. >> >> I started to read that and thought you were going to advocate the use of 0??K... > > It's 0 K. The SI-unit 'Kelvin' has no degree (although Lord Kelvin was a > professor). And he did have a degree. -- Grant Edwards grant.b.edwards Yow! Wait ... is this a FUN at THING or the END of LIFE in gmail.com Petticoat Junction?? From larry.martell at gmail.com Thu Jan 30 10:28:18 2014 From: larry.martell at gmail.com (Larry Martell) Date: Thu, 30 Jan 2014 10:28:18 -0500 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On Thu, Jan 30, 2014 at 10:23 AM, Grant Edwards wrote: > On 2014-01-30, Christian Heimes wrote: >> On 30.01.2014 04:27, Chris Angelico wrote: >>> On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: >>>>> How cruel... I suspect the smack at 0degC is much more painful >>>>> than one >>>>> at room temperature >>>>> >>>> It's the 21st century; you should be making use of Unicode: 0??C. >>> >>> I started to read that and thought you were going to advocate the use of 0??K... >> >> It's 0 K. The SI-unit 'Kelvin' has no degree (although Lord Kelvin was a >> professor). > > And he did have a degree. I heard he was a very cold individual. From zachary.ware+pylist at gmail.com Thu Jan 30 10:31:28 2014 From: zachary.ware+pylist at gmail.com (Zachary Ware) Date: Thu, 30 Jan 2014 09:31:28 -0600 Subject: end quote help for a newbie In-Reply-To: <1391093552.89290.YahooMailNeo@web133104.mail.ir2.yahoo.com> References: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> <1391093552.89290.YahooMailNeo@web133104.mail.ir2.yahoo.com> Message-ID: Please reply to the list, rather than to me directly. You can use "Reply to List" if you have that option, or "Reply to All" to make sure you include the list. On Thu, Jan 30, 2014 at 8:52 AM, Peter Clark wrote: > I do not know how to dump the screen - it will not let me select anything > with the mouse cursor, so here is my (typed in) reproduction: Since it looks like you're probably using Windows Command Prompt, you can right click anywhere in that window, click "Mark", and highlight a rectangle containing what you want and hit the Enter key. Note that it doesn't go by lines, only the rectangle you highlight will be copied! (Yes, it is horribly annoying :) Thank you for taking the time to type it all out! > Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 > bit (In > tel) on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print "xyz" > File "(stdin)", line 1 > print "xyz" > ^ > SyntaxError: invalid syntax This right here confirms what I thought: you're using Python 3 with a Python 2 tutorial. 'print' in Python 3 is a function just like 'input' or 'open', so you have to use it like this instead: >>> print("xyz") xyz >>>> print '''xyz" . . .''' > File "(stdin)", line 1 > print '''xyz''' > ^ > SyntaxError: invalid syntax >>>> print '''xyz" . . .'' (note - not appearing on >>>> screen - this is 2 single quotes) > ... ''' > File "(stdin)", line 2 > ''' > ^ > SyntaxError: invalid syntax >>>> > > I do not see anywhere a definition of which version the tutorial relates to, > but I downloaded it from the Python site on 19th January 2014. The Python website provides docs for every current version of Python, and the community is currently in the midst of a very long transition from version 2.7 to 3.x, so both versions are considered "current". In fact, most links to the Python documentation will link to the 2.7 version to maintain compatibility. Here's a link to the Python 3 version of the tutorial, which should work much better for you! http://docs.python.org/3/tutorial/ You can also find the docs in your Python installation: find Python 3.3 in your start menu, and choose "Python Manuals". This will open the same docs as are found online, in standard Windows help file format. Click the "Tutorial" link on the first page of that, and you should have the right tutorial to work from. Hope this helps, and welcome to Python! -- Zach > > peter. > > On Thursday, 30 January 2014, 16:13, Zachary Ware > wrote: > > On Thu, Jan 30, 2014 at 7:26 AM, Peter Clark wrote: > >> There is probably an easy solution to this ? but I have not found it. >> >> Trying to terminate a literal in a print statement (from the tutorial). >> >> The literal should be enclosed in double quotes ? ? >> >> the initial double quote seems to be OK (if I use a different character it >> flags it) but the ending is flagged as invalid syntax. I have tried >> changing my keyboard from UK to USA, without any effect, and tried adding >> a >> space after the final double quote, > > > Which version of Python are you using? Make sure you're using the > same version of interpreter and tutorial. 'print' was one of the big > changes between Python 2 and Python 3 (in Python 2 it was a statement, > while in Python 3 it is a function), so a tutorial written with Python > 2 in mind will have some issues if you're using Python 3. > > If you've already checked that, try copying and pasting your entire > interpreter session into a reply here, and we'll be more able to > figure out what's going on. > > Hope this helps, > > -- > Zach > From rustompmody at gmail.com Thu Jan 30 10:34:05 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 30 Jan 2014 07:34:05 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <31aff593-6cf5-4bac-876f-645bbb2a0679@googlegroups.com> On Thursday, January 30, 2014 8:39:03 PM UTC+5:30, Steven D'Aprano wrote: > On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > Oh really? Do you actually write stuff like this? > b = ((2*a) + 1) > if (b >= (-1)): > ... > I would hope not. > > 2) In cases where the expression is so simple, you couldn't possibly be > > wrong, see rule #1. > Or, you can avoid superstitious responses *wink* > (1) Learn the operator precedences to the best of your ability. It's > not hard, most of it works just like the precedences you're used > to from maths class (remember that?) or in the most intuitively > useful way. > E.g. `1 + x == 2` does the useful thing of calculating 1 + x > before testing for equality, rather than the stupid thing of > calculating x == 2 first then adding it to 1. > (2) When in doubt, use parentheses. > (3) When the expression is complex, a few extra parentheses can > help make it easier to understand. "Seven, plus or minus two" > is (roughly) the number of distinct items the human short- > term memory can hold. Grouping terms together can help reduce > the distinct number of items the reader needs to keep in > short-term memory. > E.g. `x+1 > 0 and y >= 5` is potentially as many as 9 distinct > items to keep in short-term memory. But bracketing some terms > as in `(x+1 > 0) and (y >= 5)` can reduce that down to as few > as two items. > (4) But too many parens obscure the meaning of the expression too. Aim > for a good balance, neither too few nor too many. Your judgement > of the right number of parens is a skill, which will come with > experience. (5) use APL -- all ordinary operators group right to left and at the same precedence level From ayushidalmia2604 at gmail.com Thu Jan 30 10:37:59 2014 From: ayushidalmia2604 at gmail.com (Ayushi Dalmia) Date: Thu, 30 Jan 2014 07:37:59 -0800 (PST) Subject: fseek In Compressed Files In-Reply-To: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: On Thursday, January 30, 2014 4:20:26 PM UTC+5:30, Ayushi Dalmia wrote: > Hello, > > > > I need to randomly access a bzip2 or gzip file. How can I set the offset for a line and later retreive the line from the file using the offset. Pointers in this direction will help. We are not allowed to use databases! I need to do this without database. From stephane at wirtel.be Thu Jan 30 11:00:00 2014 From: stephane at wirtel.be (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Thu, 30 Jan 2014 17:00:00 +0100 Subject: [ANN] Last news from Python FOSDEM 2014 Message-ID: <58BB703E-A03A-42C3-A9AA-107718EC5456@wirtel.be> Python @ FOSDEM 2014 #################### Hi all, Last news about the Python devroom at FOSDEM 2014 [1] Schedule ======== There is a last change in the schedule, "PyPy: a fast Python Virtual Machine" will replace "Web Scraping 101 in Python". Yasoob can't be present in Belgium :/ +----------+--------------------------------------------------------------+----------------------+ | TimeSlot | Talk | Speaker | +==========+==============================================================+======================+ | 09:00 | Logic Programming in Python | Pierre Carbonnelle | +----------+--------------------------------------------------------------+----------------------+ | 09:30 | Introduction to py.test fixtures | Floris Bruynooghe | +----------+--------------------------------------------------------------+----------------------+ | 10:00 | openpyxl | Eric Gazoni | +----------+--------------------------------------------------------------+----------------------+ | 10:30 | Introducing the Eve REST API Framework | Nicola Iarocci | +----------+--------------------------------------------------------------+----------------------+ | 11:00 | Stack switching for fun and profit | Sa?l Ibarra Corretg? | +----------+--------------------------------------------------------------+----------------------+ | 11:30 | SQLAlchemy Drill | Erik Janssens | +----------+--------------------------------------------------------------+----------------------+ | 12:00 | Some recipes with Alembic | Claude Huchet | +----------+--------------------------------------------------------------+----------------------+ | 12:30 | Post-mortem Debugging and Web Development | Alessandro Molina | +----------+--------------------------------------------------------------+----------------------+ | 14:00 | The next generation Python Software Foundation (PSF) | Marc-Andre Lemburg | +----------+--------------------------------------------------------------+----------------------+ | 14:30 | How PyPy makes your code run fast | Romain Guillebert | +----------+--------------------------------------------------------------+----------------------+ | 15:00 | Using All These Cores: Transactional Memory under the hood | Armin Rigo | +----------+--------------------------------------------------------------+----------------------+ | 15:30 | A deep dive into PEP3156, the new asyncio module | Sa?l Ibarra Corretg? | +----------+--------------------------------------------------------------+----------------------+ | 16:00 | Concurrent pr ogramming with Python and my little experiment | Benoit Chesneau | +----------+--------------------------------------------------------------+----------------------+ | 16:30 | Integrating Python and C using CFFI | Floris Bruynooghe | +----------+--------------------------------------------------------------+----------------------+ | 17:00 | PyPy : a fast Python Virtual Machine | Romain Guillebert | +----------+--------------------------------------------------------------+----------------------+ | 17:30 | Generators, or how to step to the infinite and beyond | Andrea Crotti | +----------+--------------------------------------------------------------+----------------------+ Sponsors ======== We are glad to announce you that we have a lot of awesome sponsors for the event. Gold ---- Affinitic Built on expertise achieved over more than 10 years in the development and implementation of web solutions Affinitic is your ideal partner through every stage of your project: from its conception and analysis to its final implementation, not forgetting vital training support.The strength competence, quality and safety of our developments are based on our skill in the domain of open source software and our active presence in communities of developers. http://www.affinitic.be Python Software Foundation The Python Software Foundation (PSF) is a 501(c)(3) non-profit corporation that holds the intellectual property rights behind the Python programming language. We manage the open source licensing for Python version 2.1 and later and own and protect the trademarks associated with Python.We also run the North Ameri can PyCon conference annually, support other Python conferences around the world, and fund Python related development with our grants program and by funding special projects. http://www.python.org/psf Silver ------ Github GitHub is the best way to build software together.Whether it's your company's app, your favorite open source library, or a weekend side project, GitHub helps everyone work together better by providing tools for easier collaboration and code sharing.Catch up on what happened while you were out or ask for help on a tricky chunk of code.Manage and contribute to projects from all your devices.The best part is you can keep using all of your favorite tools.Start collaborating on code today?open source project hosting is free! http://github.com AFPy L'association "A.F.P.Y.", Association Francophone Python, a pour but la vulgarisation aupr?s d'un public francophone du langage de programmation python et de ses applications. http://www.afpy.org Eyepea Open Source VoIP System Integrator. Eyepea is a VoIP (Voice over IP) system integrator building solutions around Open Source platforms such as Asterisk, sipX, OpenSIPS etc. http://www.eyepea.eu Friday Beer Event ================= While coming over to Brussels to attend FOSDEM, don't miss this great opportunity to taste some of the finest beer in Belgium (and hence in the world). Further information about the Friday Beer Event [2] Dinner ====== The next *Aperos Python Belgium* [3] will take place on saturday, February 1st in Brussels, during the FOSDEM conference that take place at ULB from 1st to 2nd February. In addition to the regulars or AFPyro , we are also pleased to meet the attendees of FOSDEM [1] using Python. As usual, you can come just for drinking and sharing one (or many) drinks or if you wish, you can also register for the meal that follows, in a near place, at *Chez L?on* for 20:30, rue des Bouchers 18, B-1000 Brussels. Meeting from 18:45, on first floor of Delirium cafe, Impasse De La Fid?lit? 4, 1000 Brussels. If you are a FOSDEM attendee, you can meet us at the Python stand, 1st floor of K Building, from 18h to go to Delirium cafe together. Please sign up in order to book the place: http://doodle.com/mn3yck6n3xxidsim Further information about the next AFPyros in Belgium: *Aperos Python Belgium* [3] Stand ===== This edition will have a stand for the Python Community. There will be the Python Software Foundation, the Association Francophone of Python and the goodies. It's the opportunity to support the Python Community! Goodies ======= This year, you will have the opportunities to buy a t-shirt, a mug of the event. Some stickers will be available of your laptop ;-) Please, share this post ! You can follow us via our Twitter account [4]. Stephane Wirtel for Python-FOSDEM [5], for the Python Community. [1] http://fosdem.org/2014 [2] https://fosdem.org/2014/practical/beerevent/ [3] http://afpyro.afpy.org/dates/2014/2014_02_01.html [4] https://twitter.com/PythonFOSDEM [5] http://python-fosdem.org From stephane.wirtel at gmail.com Thu Jan 30 10:59:24 2014 From: stephane.wirtel at gmail.com (=?utf-8?q?St=C3=A9phane?= Wirtel) Date: Thu, 30 Jan 2014 16:59:24 +0100 Subject: [ANN] Last news from Python FOSDEM 2014 Message-ID: <362DA8A9-B8B7-45E8-9C5E-09DF3B4F3ED9@gmail.com> Python @ FOSDEM 2014 #################### Hi all, Last news about the Python devroom at FOSDEM 2014 [1] Schedule ======== There is a last change in the schedule, "PyPy: a fast Python Virtual Machine" will replace "Web Scraping 101 in Python". Yasoob can't be present in Belgium :/ +----------+--------------------------------------------------------------+----------------------+ | TimeSlot | Talk | Speaker | +==========+==============================================================+======================+ | 09:00 | Logic Programming in Python | Pierre Carbonnelle | +----------+--------------------------------------------------------------+----------------------+ | 09:30 | Introduction to py.test fixtures | Floris Bruynooghe | +----------+--------------------------------------------------------------+----------------------+ | 10:00 | openpyxl | Eric Gazoni | +----------+--------------------------------------------------------------+----------------------+ | 10:30 | Introducing the Eve REST API Framework | Nicola Iarocci | +----------+--------------------------------------------------------------+----------------------+ | 11:00 | Stack switching for fun and profit | Sa?l Ibarra Corretg? | +----------+--------------------------------------------------------------+----------------------+ | 11:30 | SQLAlchemy Drill | Erik Janssens | +----------+--------------------------------------------------------------+----------------------+ | 12:00 | Some recipes with Alembic | Claude Huchet | +----------+--------------------------------------------------------------+----------------------+ | 12:30 | Post-mortem Debugging and Web Development | Alessandro Molina | +----------+--------------------------------------------------------------+----------------------+ | 14:00 | The next generation Python Software Foundation (PSF) | Marc-Andre Lemburg | +----------+--------------------------------------------------------------+----------------------+ | 14:30 | How PyPy makes your code run fast | Romain Guillebert | +----------+--------------------------------------------------------------+----------------------+ | 15:00 | Using All These Cores: Transactional Memory under the hood | Armin Rigo | +----------+--------------------------------------------------------------+----------------------+ | 15:30 | A deep dive into PEP3156, the new asyncio module | Sa?l Ibarra Corretg? | +----------+--------------------------------------------------------------+----------------------+ | 16:00 | Concurrent pr ogramming with Python and my little experiment | Benoit Chesneau | +----------+--------------------------------------------------------------+----------------------+ | 16:30 | Integrating Python and C using CFFI | Floris Bruynooghe | +----------+--------------------------------------------------------------+----------------------+ | 17:00 | PyPy : a fast Python Virtual Machine | Romain Guillebert | +----------+--------------------------------------------------------------+----------------------+ | 17:30 | Generators, or how to step to the infinite and beyond | Andrea Crotti | +----------+--------------------------------------------------------------+----------------------+ Sponsors ======== We are glad to announce you that we have a lot of awesome sponsors for the event. Gold ---- Affinitic Built on expertise achieved over more than 10 years in the development and implementation of web solutions Affinitic is your ideal partner through every stage of your project: from its conception and analysis to its final implementation, not forgetting vital training support.The strength competence, quality and safety of our developments are based on our skill in the domain of open source software and our active presence in communities of developers. http://www.affinitic.be Python Software Foundation The Python Software Foundation (PSF) is a 501(c)(3) non-profit corporation that holds the intellectual property rights behind the Python programming language. We manage the open source licensing for Python version 2.1 and later and own and protect the trademarks associated with Python.We also run the North Ameri can PyCon conference annually, support other Python conferences around the world, and fund Python related development with our grants program and by funding special projects. http://www.python.org/psf Silver ------ Github GitHub is the best way to build software together.Whether it's your company's app, your favorite open source library, or a weekend side project, GitHub helps everyone work together better by providing tools for easier collaboration and code sharing.Catch up on what happened while you were out or ask for help on a tricky chunk of code.Manage and contribute to projects from all your devices.The best part is you can keep using all of your favorite tools.Start collaborating on code today?open source project hosting is free! http://github.com AFPy L'association "A.F.P.Y.", Association Francophone Python, a pour but la vulgarisation aupr?s d'un public francophone du langage de programmation python et de ses applications. http://www.afpy.org Eyepea Open Source VoIP System Integrator. Eyepea is a VoIP (Voice over IP) system integrator building solutions around Open Source platforms such as Asterisk, sipX, OpenSIPS etc. http://www.eyepea.eu Friday Beer Event ================= While coming over to Brussels to attend FOSDEM, don't miss this great opportunity to taste some of the finest beer in Belgium (and hence in the world). Further information about the Friday Beer Event [2] Dinner ====== The next *Aperos Python Belgium* [3] will take place on saturday, February 1st in Brussels, during the FOSDEM conference that take place at ULB from 1st to 2nd February. In addition to the regulars or AFPyro , we are also pleased to meet the attendees of FOSDEM [1] using Python. As usual, you can come just for drinking and sharing one (or many) drinks or if you wish, you can also register for the meal that follows, in a near place, at *Chez L?on* for 20:30, rue des Bouchers 18, B-1000 Brussels. Meeting from 18:45, on first floor of Delirium cafe, Impasse De La Fid?lit? 4, 1000 Brussels. If you are a FOSDEM attendee, you can meet us at the Python stand, 1st floor of K Building, from 18h to go to Delirium cafe together. Please sign up in order to book the place: http://doodle.com/mn3yck6n3xxidsim Further information about the next AFPyros in Belgium: *Aperos Python Belgium* [3] Stand ===== This edition will have a stand for the Python Community. There will be the Python Software Foundation, the Association Francophone of Python and the goodies. It's the opportunity to support the Python Community! Goodies ======= This year, you will have the opportunities to buy a t-shirt, a mug of the event. Some stickers will be available of your laptop ;-) Please, share this post ! You can follow us via our Twitter account [4]. Stephane Wirtel for Python-FOSDEM [5], for the Python Community. [1] http://fosdem.org/2014 [2] https://fosdem.org/2014/practical/beerevent/ [3] http://afpyro.afpy.org/dates/2014/2014_02_01.html [4] https://twitter.com/PythonFOSDEM [5] http://python-fosdem.org From __peter__ at web.de Thu Jan 30 11:21:28 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Jan 2014 17:21:28 +0100 Subject: fseek In Compressed Files References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: Serhiy Storchaka wrote: > 30.01.14 13:28, Peter Otten ???????(??): >> Ayushi Dalmia wrote: >> >>> I need to randomly access a bzip2 or gzip file. How can I set the offset >>> for a line and later retreive the line from the file using the offset. >>> Pointers in this direction will help. >> >> with gzip.open(filename) as f: >> f.seek(some_pos) >> print(f.readline()) >> f.seek(some_pos) >> print(f.readline()) >> >> seems to work as expected. Can you tell a bit more about your usecase (if >> it isn't covered by that basic example)? > > I don't recommend to seek backward in compressed file. This is very > inefficient operation. Do you know an efficient way to implement random access for a bzip2 or gzip file? From roy at panix.com Thu Jan 30 12:32:31 2014 From: roy at panix.com (Roy Smith) Date: 30 Jan 2014 12:32:31 -0500 Subject: Another surprise from the datetime module Message-ID: I was astounded just now to discover that datetime.timedelta doesn't have a replace() method (at least not in Python 2.7). Is there some fundamental reason why it shouldn't, or is this just an oversight? My immediate use case was wanting to print a timedelta without the fractions of seconds. The most straight-forward is: print td.replace(microseconds=0) but that doesn't work. Yes, I know I can use strftime, but (as I've mentioned before :-)), that requires dragging up the reference page to figure out what grotty little format string I need. The brute-force print timedelta(seconds=int(td.total_seconds())) is easier than that, but plain old replace() would be even easier. From breamoreboy at yahoo.co.uk Thu Jan 30 12:42:26 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 30 Jan 2014 17:42:26 +0000 Subject: 1 > 0 == True -> False In-Reply-To: <5ebb3d58-c23e-4938-924d-df7121ca1d04@googlegroups.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <5ebb3d58-c23e-4938-924d-df7121ca1d04@googlegroups.com> Message-ID: On 30/01/2014 14:46, Thibault Langlois wrote: > On Thursday, January 30, 2014 2:08:58 PM UTC, Roy Smith wrote: >> In article <3dcdc95d-5e30-46d3-b558-afedf9723c7c at googlegroups.com>, >> >> Thibault Langlois wrote: >> >> >> >>> You are right. I should have given some context. >> >>> I am looking at this from the perspective of the teacher that has to explain >> >>> idiosyncrasies of the language to inexperienced students. >> >>> There are two aspects in this example. >> >>> 1. the equivalence of True/False with integers 1/0 which have pro and cons. >> >>> 2. the chaining rules of operators. I agree that it may make sense in some >> >>> cases like x > y > z but when operators are mixed it leads to counter >> >>> intuitive cases as the one I pointed out. >> >>> >> >>> The recommendations to student are 1) do not assume True == 1 and do not use >> >>> operator chaining. >> >> >> >> Better than that, do what I do. >> >> >> >> 1) Assume that you don't have the full operator precedence table >> >> memorized and just parenthesize everything. >> >> >> >> 2) In cases where the expression is so simple, you couldn't possibly be >> >> wrong, see rule #1. > > Agreed ! > Pleased to see that as always plenty of helpful responses here. In return would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Thu Jan 30 13:03:17 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 30 Jan 2014 18:03:17 +0000 Subject: Another surprise from the datetime module In-Reply-To: References: Message-ID: On 30/01/2014 17:32, Roy Smith wrote: > I was astounded just now to discover that datetime.timedelta doesn't > have a replace() method (at least not in Python 2.7). Is there some > fundamental reason why it shouldn't, or is this just an oversight? > > My immediate use case was wanting to print a timedelta without the > fractions of seconds. The most straight-forward is: > > print td.replace(microseconds=0) > > but that doesn't work. Yes, I know I can use strftime, but (as I've > mentioned before :-)), that requires dragging up the reference page to > figure out what grotty little format string I need. The brute-force > > print timedelta(seconds=int(td.total_seconds())) > > is easier than that, but plain old replace() would be even easier. > datetime.timedelta doesn't have a strftime method either. AttributeError: 'datetime.timedelta' object has no attribute 'strftime' -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From sg552 at hotmail.co.uk Thu Jan 30 13:12:38 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 30 Jan 2014 18:12:38 +0000 Subject: Try-except-finally paradox In-Reply-To: References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: On 30/01/2014 06:33, Andrew Berg wrote: > On 2014.01.29 23:56, Jessica Ross wrote: >> I found something like this in a StackOverflow discussion. >>>>> def paradox(): >> ... try: >> ... raise Exception("Exception raised during try") >> ... except: >> ... print "Except after try" >> ... return True >> ... finally: >> ... print "Finally" >> ... return False >> ... return None >> ... >>>>> return_val = paradox() >> Except after try >> Finally >>>>> return_val >> False >> >> I understand most of this. >> What I don't understand is why this returns False rather than True. >> Does the finally short-circuit the return in the except block? >> > My guess would be that the interpreter doesn't let the finally block > get skipped under any circumstances, so the return value gets set to > True, but then it forces the finally block to be run before returning, > which changes the return value to False. Mine too. We can check that the interpreter gets as far as evaluating the return value in the except block: >>> def paradox2(): try: raise Exception("Raise") except: print("Except") return [print("Return"), True][1] finally: print("Finally") return False return None >>> ret = paradox2() Except Return Finally >>> ret False From neilc at norwich.edu Thu Jan 30 13:36:34 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Thu, 30 Jan 2014 18:36:34 +0000 (UTC) Subject: Another surprise from the datetime module References: Message-ID: On 2014-01-30, Roy Smith wrote: > I was astounded just now to discover that datetime.timedelta > doesn't have a replace() method (at least not in Python 2.7). > Is there some fundamental reason why it shouldn't, or is this > just an oversight? > > My immediate use case was wanting to print a timedelta without > the fractions of seconds. The most straight-forward is: > > print td.replace(microseconds=0) That would be nice. In the meantime, this works for your use case: td -= td % timedelta(seconds=1) -- Neil Cerutti From davea at davea.name Thu Jan 30 13:46:59 2014 From: davea at davea.name (Dave Angel) Date: Thu, 30 Jan 2014 13:46:59 -0500 (EST) Subject: fseek In Compressed Files References: <68316d1a-e52e-48b5-87df-7119f46ebabc@googlegroups.com> Message-ID: Ayushi Dalmia Wrote in message: > On Thursday, January 30, 2014 4:20:26 PM UTC+5:30, Ayushi Dalmia wrote: >> Hello, >> >> >> >> I need to randomly access a bzip2 or gzip file. How can I set the offset for a line and later retreive the line from the file using the offset. Pointers in this direction will help. > > We are not allowed to use databases! I need to do this without database. > Why do you reply to your own message? Makes it hard for people to make sense of your post. Have you any answers to earlier questions? How big is this file, what python version, do you care about performance, code you've tried, ... -- DaveA From roy at panix.com Thu Jan 30 13:46:18 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 10:46:18 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> Message-ID: <975026c8-d9a7-4a70-940e-a580bbedbf66@googlegroups.com> On Thursday, January 30, 2014 9:56:19 AM UTC-5, Jussi Piitulainen wrote: > There's nothing to parenthesize in x <= y < z = w Hmm.... >>> x <= y < z = w File "", line 1 SyntaxError: can't assign to comparison I don't think any number of parentheses will help that :-) From ethan at stoneleaf.us Thu Jan 30 13:30:21 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 30 Jan 2014 10:30:21 -0800 Subject: Try-except-finally paradox In-Reply-To: References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: <52EA9A3D.2080404@stoneleaf.us> On 01/30/2014 10:12 AM, Rotwang wrote: > On 30/01/2014 06:33, Andrew Berg wrote: >> On 2014.01.29 23:56, Jessica Ross wrote: >>> >>> I found something like this in a StackOverflow discussion. >>> --> def paradox(): >>> ... try: >>> ... raise Exception("Exception raised during try") >>> ... except: >>> ... print "Except after try" >>> ... return True >>> ... finally: >>> ... print "Finally" >>> ... return False >>> ... return None >>> ... >>> --> return_val = paradox() >>> Except after try >>> Finally >>> --> return_val >>> False >>> >>> I understand most of this. >>> What I don't understand is why this returns False rather than True. >>> Does the finally short-circuit the return in the except block? >>> >> My guess would be that the interpreter doesn't let the finally block >> get skipped under any circumstances, so the return value gets set to >> True, but then it forces the finally block to be run before returning, >> which changes the return value to False. > > Mine too. We can check that the interpreter gets as far as evaluating the return value in the except block: > > --> def paradox2(): > try: > raise Exception("Raise") > except: > print("Except") > return [print("Return"), True][1] > finally: > print("Finally") > return False > return None > > --> ret = paradox2() > Except > Return > Finally > --> ret > False And just to be thorough, if the finally block doesn't have a return: --> def paradox3(): try: raise Exception("Raise") except: print("Except") return [print("Return"), True][1] finally: print("Finally") return None --> print(paradox3()) Except Return Finally True -- ~Ethan~ From roy at panix.com Thu Jan 30 13:53:42 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 10:53:42 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > > > 1) Assume that you don't have the full operator precedence table > > memorized and just parenthesize everything. > > Oh really? Do you actually write stuff like this? > > b = ((2*a) + 1) Well, OK, I exaggerated a bit. Multiplication binds stronger than addition in any language I've ever used, so I assume I know that one. But not much beyond that. > if (b >= (-1)): No, I wouldn't use either set of parens their either. But, if I have any doubt at all, I rather than look it up, I just put parens. And my threshold for doubt is pretty low. From roy at panix.com Thu Jan 30 13:56:42 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 10:56:42 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > E.g. `x+1 > 0 and y >= 5` is potentially as many as 9 distinct > items to keep in short-term memory. But bracketing some terms > as in `(x+1 > 0) and (y >= 5)` can reduce that down to as few > as two items. Yes, that's probably how I would write that, although, this is even simpler: (x > -1) and (y >= 5) From rosuav at gmail.com Thu Jan 30 14:03:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 06:03:42 +1100 Subject: 1 > 0 == True -> False In-Reply-To: <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: > On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > >> E.g. `x+1 > 0 and y >= 5` is potentially as many as 9 distinct >> items to keep in short-term memory. But bracketing some terms >> as in `(x+1 > 0) and (y >= 5)` can reduce that down to as few >> as two items. > > Yes, that's probably how I would write that, although, this is even simpler: > > (x > -1) and (y >= 5) Be careful; that's not the same thing. ChrisA From artomishka at yahoo.co.uk Thu Jan 30 14:27:00 2014 From: artomishka at yahoo.co.uk (Peter Clark) Date: Thu, 30 Jan 2014 19:27:00 +0000 (GMT) Subject: end quote help for a newbie In-Reply-To: References: <1391088376.73476.YahooMailNeo@web133103.mail.ir2.yahoo.com> <1391093552.89290.YahooMailNeo@web133104.mail.ir2.yahoo.com> Message-ID: <1391110020.83595.YahooMailNeo@web133106.mail.ir2.yahoo.com> Thank-you.? Please no-one reply to this post.? I just want to put on record my complete p-offed-ness, that having spent 10 days sorting out and hypertexting a library of documentation, I now have to start all over. Please do not respond, I am sure it is all my fault. Please do not respond - it will only prolong the agony. Long live the Norwegian blue. peter On Thursday, 30 January 2014, 17:31, Zachary Ware wrote: Please reply to the list, rather than to me directly.? You can use "Reply to List" if you have that option, or "Reply to All" to make sure you include the list. On Thu, Jan 30, 2014 at 8:52 AM, Peter Clark wrote: > I do not know how to dump the screen - it will not let me select anything > with the mouse cursor, so here is my (typed in) reproduction: Since it looks like you're probably using Windows Command Prompt, you can right click anywhere in that window, click "Mark", and highlight a rectangle containing what you want and hit the Enter key.? Note that it doesn't go by lines, only the rectangle you highlight will be copied! (Yes, it is horribly annoying :) Thank you for taking the time to type it all out! > Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40)? [MSC v.1600 32 > bit (In > tel) on win32 > Type "help", "copyright", "credits" or "license" for more information. >>>> print "xyz" >? ? ? File "(stdin)", line 1 >? ? ? ? print "xyz" >? ? ? ? ? ? ? ? ? ? ? ? ^ > SyntaxError: invalid syntax This right here confirms what I thought: you're using Python 3 with a Python 2 tutorial.? 'print' in Python 3 is a function just like 'input' or 'open', so you have to use it like this instead: ? >>> print("xyz") ? xyz >>>> print '''xyz"? . . .''' >? ? ? File "(stdin)", line 1 >? ? ? ? print '''xyz''' >? ? ? ? ? ? ? ? ? ? ? ? ? ^ > SyntaxError: invalid syntax >>>> print '''xyz"? . . .''? ? ? ? ? ? ? ? ? ? (note - not appearing on >>>> screen - this is 2 single quotes) > ... ''' >? ? File "(stdin)", line 2 >? ? ? ? ''' >? ? ? ? ? ^ > SyntaxError: invalid syntax >>>> > > I do not see anywhere a definition of which version the tutorial relates to, > but I downloaded it from the Python site on 19th January 2014. The Python website provides docs for every current version of Python, and the community is currently in the midst of a very long transition from version 2.7 to 3.x, so both versions are considered "current". In fact, most links to the Python documentation will link to the 2.7 version to maintain compatibility.? Here's a link to the Python 3 version of the tutorial, which should work much better for you! http://docs.python.org/3/tutorial/ You can also find the docs in your Python installation: find Python 3.3 in your start menu, and choose "Python Manuals".? This will open the same docs as are found online, in standard Windows help file format.? Click the "Tutorial" link on the first page of that, and you should have the right tutorial to work from. Hope this helps, and welcome to Python! -- Zach > > peter. > > On Thursday, 30 January 2014, 16:13, Zachary Ware > wrote: > > On Thu, Jan 30, 2014 at 7:26 AM, Peter Clark wrote: > >> There is probably an easy solution to this ? but I have not found it. >> >> Trying to terminate a literal in a print statement (from the tutorial). >> >> The literal should be enclosed in double quotes ? ? >> >> the initial double quote seems to be OK (if I use a different character it >> flags it) but the ending is flagged as invalid syntax.? I have tried >> changing my keyboard from UK to USA, without any effect, and tried adding >> a >> space after the final double quote, > > > Which version of Python are you using?? Make sure you're using the > same version of interpreter and tutorial.? 'print' was one of the big > changes between Python 2 and Python 3 (in Python 2 it was a statement, > while in Python 3 it is a function), so a tutorial written with Python > 2 in mind will have some issues if you're using Python 3. > > If you've already checked that, try copying and pasting your entire > interpreter session into a reply here, and we'll be more able to > figure out what's going on. > > Hope this helps, > > -- > Zach > -------------- next part -------------- An HTML attachment was scrubbed... URL: From sg552 at hotmail.co.uk Thu Jan 30 14:25:14 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Thu, 30 Jan 2014 19:25:14 +0000 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On 30/01/2014 12:49, Dave Angel wrote: > [...] > > For hysterical reasons, True and False are instances of class > bool, which is derived from int. So for comparison purposes > False==0 and True==1. But in my opinion, you should never take > advantage of this, except when entering obfuscation > contests. Really? I take advantage of it quite a lot. For example, I do things like this: 'You have scored %i point%s' % (score, 's'*(score != 1)) From ethan at stoneleaf.us Thu Jan 30 14:22:17 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Thu, 30 Jan 2014 11:22:17 -0800 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> Message-ID: <52EAA669.4030300@stoneleaf.us> On 01/30/2014 11:03 AM, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: >> >> Yes, that's probably how I would write that, although, this is even simpler: >> >> (x > -1) and (y >= 5) > > Be careful; that's not the same thing. How so? -- ~Ethan~ From rosuav at gmail.com Thu Jan 30 14:48:21 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 06:48:21 +1100 Subject: 1 > 0 == True -> False In-Reply-To: <52EAA669.4030300@stoneleaf.us> References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> <52EAA669.4030300@stoneleaf.us> Message-ID: Fri, Jan 31, 2014 at 6:22 AM, Ethan Furman wrote: > On 01/30/2014 11:03 AM, Chris Angelico wrote: > >> On Fri, Jan 31, 2014 at 5:56 AM, Roy Smith wrote: >>> >>> >>> Yes, that's probably how I would write that, although, this is even >>> simpler: >>> >>> (x > -1) and (y >= 5) >> >> >> Be careful; that's not the same thing. > > > How so? > Well, if x is an integer, then they're the same. If it's floating point, I think they're the same, but don't quote me on that. But for arbitrary types, there's no way of knowing what x+1 will result in. ChrisA From davea at davea.name Thu Jan 30 15:08:41 2014 From: davea at davea.name (Dave Angel) Date: Thu, 30 Jan 2014 15:08:41 -0500 (EST) Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: Rotwang Wrote in message: > On 30/01/2014 12:49, Dave Angel wrote: >> [...] >> >> For hysterical reasons, True and False are instances of class >> bool, which is derived from int. So for comparison purposes >> False==0 and True==1. But in my opinion, you should never take >> advantage of this, except when entering obfuscation >> contests. > > Really? I take advantage of it quite a lot. For example, I do things > like this: > > 'You have scored %i point%s' % (score, 's'*(score != 1)) > I also did that kind of thing when computer resources were more precious the program readability. Like in 73 when my satellite navigation system had to fit in 2k code and 1.5k data. Here I'd probably do something like 'You have scored {} {}' .format (score, 'point' if score==1 else 'points') -- DaveA From rosuav at gmail.com Thu Jan 30 15:15:48 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 07:15:48 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 7:08 AM, Dave Angel wrote: >> 'You have scored %i point%s' % (score, 's'*(score != 1)) >> > > Here I'd probably do something like > > 'You have scored {} {}' .format (score, 'point' if score==1 else > 'points') Bah, what's the fun in that? 'You have scored %i point%.*s' % (score, score!=1, 's') BTW, the layout of the original bugs me slightly: >> 'You have scored %i point%s' % (score, 's'*(score != 1)) I don't like having spaces around != and none around *. I'd either squash the != up or space out the *: 'You have scored %i point%s' % (score, 's'*(score!=1)) 'You have scored %i point%s' % (score, 's' * (score != 1)) Operators should always have at least as much space around them as more tightly-binding operators, IMO. In this instance, it'd be reasonable to squash the != and space the *, or to squash both, or to space both, but not the "backward" spacing of the original :) But that's just my opinion. ChrisA From jpiitula at ling.helsinki.fi Thu Jan 30 15:14:33 2014 From: jpiitula at ling.helsinki.fi (Jussi Piitulainen) Date: 30 Jan 2014 22:14:33 +0200 Subject: 1 > 0 == True -> False References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <975026c8-d9a7-4a70-940e-a580bbedbf66@googlegroups.com> Message-ID: Roy Smith writes: > On Thursday, January 30, 2014 9:56:19 AM UTC-5, Jussi Piitulainen wrote: > > > There's nothing to parenthesize in x <= y < z = w > > Hmm.... > > >>> x <= y < z = w > File "", line 1 > SyntaxError: can't assign to comparison > > I don't think any number of parentheses will help that :-) Er, sorry about that. Here: >>> x <= y < z == w Traceback (most recent call last): File "", line 1, in NameError: name 'x' is not defined Much better :) From rosuav at gmail.com Thu Jan 30 15:25:25 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 07:25:25 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <975026c8-d9a7-4a70-940e-a580bbedbf66@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 7:14 AM, Jussi Piitulainen wrote: >> I don't think any number of parentheses will help that :-) > > Er, sorry about that. Here: > >>>> x <= y < z == w > Traceback (most recent call last): > File "", line 1, in > NameError: name 'x' is not defined > > Much better :) See, you still all think the solution is with parentheses and stuff. It's not. The solution is with apostrophes - look! >>> 'x' <= 'y < z == w' True Now it works! ChrisA From ian.g.kelly at gmail.com Thu Jan 30 15:28:07 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 30 Jan 2014 13:28:07 -0700 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On Thu, Jan 30, 2014 at 1:08 PM, Dave Angel wrote: > Rotwang Wrote in message: >> Really? I take advantage of it quite a lot. For example, I do things >> like this: >> >> 'You have scored %i point%s' % (score, 's'*(score != 1)) >> > > I also did that kind of thing when computer resources > were more > precious the program readability. Like in 73 when my satellite > navigation system had to fit in 2k code and 1.5k > data. > > Here I'd probably do something like > > 'You have scored {} {}' .format (score, 'point' if score==1 else > 'points') Of course if you're at all concerned about i18n then the proper way to do it would be: ngettext("You have scored %d point", "You have scored %d points", score) % score From rosuav at gmail.com Thu Jan 30 15:38:49 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 07:38:49 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly wrote: > Of course if you're at all concerned about i18n then the proper way to > do it would be: > > ngettext("You have scored %d point", "You have scored %d points", score) % score Ugh, so much duplication! We can totally do better than that. ngettext(*(lambda x,s: (x,x+'s',s))("You have scored %d point",score)) Much better! Incidentally, in creating the above abomination, I found that I can't do this: >>> print(*(lambda x: (x,x+'s'))("You have scored %d point"),score) SyntaxError: only named arguments may follow *expression But I can do this: >>> print(score,*(lambda x: (x,x+'s'))("You have scored %d point")) 1 You have scored %d point You have scored %d points Why is tuple unpacking limited to the last argument? Is it just for the parallel with the function definition, where anything following it is keyword-only? ChrisA From ian.g.kelly at gmail.com Thu Jan 30 16:17:24 2014 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Thu, 30 Jan 2014 14:17:24 -0700 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On Jan 30, 2014 1:40 PM, "Chris Angelico" wrote: > > On Fri, Jan 31, 2014 at 7:28 AM, Ian Kelly wrote: > > Of course if you're at all concerned about i18n then the proper way to > > do it would be: > > > > ngettext("You have scored %d point", "You have scored %d points", score) % score > > Ugh, so much duplication! We can totally do better than that. > > ngettext(*(lambda x,s: (x,x+'s',s))("You have scored %d point",score)) > > Much better! > > > Incidentally, in creating the above abomination, I found that I can't do this: > > >>> print(*(lambda x: (x,x+'s'))("You have scored %d point"),score) > SyntaxError: only named arguments may follow *expression > > But I can do this: > > >>> print(score,*(lambda x: (x,x+'s'))("You have scored %d point")) > 1 You have scored %d point You have scored %d points > > Why is tuple unpacking limited to the last argument? Is it just for > the parallel with the function definition, where anything following it > is keyword-only? Lack of a convincing use case, and the position of the following arguments would then be dependent upon the length of the tuple, which in many cases could result in subtle bugs. -------------- next part -------------- An HTML attachment was scrubbed... URL: From rosuav at gmail.com Thu Jan 30 16:31:56 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 08:31:56 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 8:17 AM, Ian Kelly wrote: >> Why is tuple unpacking limited to the last argument? Is it just for >> the parallel with the function definition, where anything following it >> is keyword-only? > > Lack of a convincing use case, and the position of the following arguments > would then be dependent upon the length of the tuple, which in many cases > could result in subtle bugs. Okay. Just seemed an odd restriction; I can unpack an iterable into a function's args (great!), I can have other args before that tuple (handy!), but I can't have any after. ChrisA From cmpython at gmail.com Thu Jan 30 17:04:00 2014 From: cmpython at gmail.com (CM) Date: Thu, 30 Jan 2014 14:04:00 -0800 (PST) Subject: Statement evals as False in my IDE and True elsewhere Message-ID: This is puzzling. (Using Python 2.5, WinXP, Boa Constructor 0.6.1 definitely running the code through Python 2.5) If I run these lines in my program, through my IDE (Boa Constructor), fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] fake_result = not all(i == '[omitted]' for i in fake_data) print 'This is fake result: ', fake_result I get this result: >>> This is fake result: False BUT, if I run those *exact same lines* (copied and pasted) in the Python 2.5 shell within Boa Constructor, or with IDLE with Python 2.5, I get: >>> This is fake result: True ...which is what it seems like it should evaluate to, right? What the heck is going on? How is this even possible? There is nothing that I know of in my code to cause this change, but perhaps there is. Otherwise I am at a total loss. Thanks, Che M From roy at panix.com Thu Jan 30 17:09:31 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 14:09:31 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> Message-ID: On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > `(x+1 > 0) and (y >= 5)` Me: > this is even simpler: > (x > -1) and (y >= 5) On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote: > Be careful; that's not the same thing. In what way? I'm assuming x is some numeric type. And further assuming it's not some humungous floating point value, so we run into precision issues. From __peter__ at web.de Thu Jan 30 17:14:57 2014 From: __peter__ at web.de (Peter Otten) Date: Thu, 30 Jan 2014 23:14:57 +0100 Subject: Statement evals as False in my IDE and True elsewhere References: Message-ID: CM wrote: > This is puzzling. (Using Python 2.5, WinXP, Boa Constructor 0.6.1 > definitely running the code through Python 2.5) > > If I run these lines in my program, through my IDE (Boa Constructor), > > fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] > fake_result = not all(i == '[omitted]' for i in fake_data) > print 'This is fake result: ', fake_result > > I get this result: > >>>> > This is fake result: False > > BUT, if I run those *exact same lines* (copied and pasted) in the Python > 2.5 shell within Boa Constructor, or with IDLE with Python 2.5, I get: > >>>> > This is fake result: True > > ...which is what it seems like it should evaluate to, right? What the > heck is going on? How is this even possible? There is nothing that I > know of in my code to cause this change, but perhaps there is. Otherwise > I am at a total loss. Hint: >>> def demo(): ... fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] ... fake_result = not all(i == '[omitted]' for i in fake_data) ... print 'This is fake result: ', fake_result ... >>> demo() This is fake result: True >>> from numpy import all >>> demo() This is fake result: False From rosuav at gmail.com Thu Jan 30 17:29:12 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 09:29:12 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> <7b41606f-4027-4470-b158-62f81b4e945c@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 9:09 AM, Roy Smith wrote: > On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: >> `(x+1 > 0) and (y >= 5)` > > Me: >> this is even simpler: >> (x > -1) and (y >= 5) > > On Thursday, January 30, 2014 2:03:42 PM UTC-5, Chris Angelico wrote: >> Be careful; that's not the same thing. > > In what way? I'm assuming x is some numeric type. And further assuming it's not some humungous floating point value, so we run into precision issues. Now you're changing the problem domain :) Like I said, if it's an integer, you definitely will get the same result from each of the above; but that doesn't mean the expressions are equivalent. They just might happen to produce the same result for values within some particular domain. (I wouldn't even be 100% confident that it's valid for any numeric type, though I can't think of any float values that it would break on, and complex and int are unorderable anyway.) ChrisA From rosuav at gmail.com Thu Jan 30 17:25:31 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 09:25:31 +1100 Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: References: Message-ID: On Fri, Jan 31, 2014 at 9:04 AM, CM wrote: > fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] > fake_result = not all(i == '[omitted]' for i in fake_data) > print 'This is fake result: ', fake_result Trying to get my head around this. You want to see if all the values in fake_data are '[omitted]' or not? That is to say, if there's anything that isn't '[omitted]'? Not sure that that's a normal thing to be asking, but that's what your code appears to do. What happens if you try this? fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] fake_result = set(fake_data)>{'[omitted]'} In theory, that should do the exact same thing as your code (returning True if there's anything in fake_data that is not '[omitted]'). The other thing to try is peppering your code with print statements. Divide the work up into pieces - show the entire loop and what happens - print out everything you can imagine. See where the difference begins between inside and outside the IDE. Once you find that, you'll have a clue as to what's wrong. ChrisA From glicerinu at gmail.com Thu Jan 30 17:46:57 2014 From: glicerinu at gmail.com (Marc Aymerich) Date: Thu, 30 Jan 2014 23:46:57 +0100 Subject: Why this throws an UnboundLocalError ? Message-ID: Dear all, I have a very simple module glic3 at e4200:# cat globalstate.py GLOBAL = 0 def update(): GLOBAL += 1 however it doesn't work!! glic3 at e4200:# python Python 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import globalstate >>> globalstate.update() Traceback (most recent call last): File "", line 1, in File "globalstate.py", line 4, in update GLOBAL += 1 UnboundLocalError: local variable 'GLOBAL' referenced before assignment And I don't know why :( Anyone ? Thanks!! -- Marc From cmpython at gmail.com Thu Jan 30 17:48:55 2014 From: cmpython at gmail.com (CM) Date: Thu, 30 Jan 2014 14:48:55 -0800 (PST) Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: References: Message-ID: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> On Thursday, January 30, 2014 5:14:57 PM UTC-5, Peter Otten wrote: > Hint: > > >>> def demo(): > ... fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] > ... fake_result = not all(i == '[omitted]' for i in fake_data) > ... print 'This is fake result: ', fake_result > > >>> demo() > This is fake result: True > > >>> from numpy import all > >>> demo() > This is fake result: False That's brilliant, thanks! Now I'm just a bit unsure of what to do about it. First, I don't actually have the line "from numpy import all" in that module's code, although I have imports of numpy; I think it is getting brought in through Matplotlib's pylab module, which I do import in that module. In any case, what's the most Pythonic way to deal with this? My first thought was to create the old all function and rename it so there would be no conflict: (both of what follows taken from answers here: http://stackoverflow.com/questions/18774388/re-import-aliased-shadowed-python-built-in-methods) builtin_all = __builtins__.all but I got the error: AttributeError: 'dict' object has no attribute 'all' So I wound up doing this: from __builtin__ import * which fixed the problem...but seems less than optimal, because what if I wanted to have numpy's all still in play? Again, thanks for restoring my faith in causality, Che M From rosuav at gmail.com Thu Jan 30 17:53:18 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 09:53:18 +1100 Subject: Why this throws an UnboundLocalError ? In-Reply-To: References: Message-ID: On Fri, Jan 31, 2014 at 9:46 AM, Marc Aymerich wrote: > GLOBAL = 0 > > def update(): > GLOBAL += 1 If you assign to a name, Python makes it local, unless you explicitly tell it that you want it to be global: def update(): global GLOBAL GLOBAL += 1 But be aware that the ALL_CAPS name conventionally means a constant. Since you're changing its value, it's not constant (wow! :) ), so using a name of GLOBAL is a bad idea. (Also, obviously, you want to name it appropriately to what you're doing, but I assume you called it this as part of cutting down your example. For which, by the way, thank you. You posted a complete example, and the full traceback, and the Python version and platform. That's everything that we need to help you - it's such a luxury!!) ChrisA From breamoreboy at yahoo.co.uk Thu Jan 30 17:53:55 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Thu, 30 Jan 2014 22:53:55 +0000 Subject: Why this throws an UnboundLocalError ? In-Reply-To: References: Message-ID: On 30/01/2014 22:46, Marc Aymerich wrote: > Dear all, > > I have a very simple module > > glic3 at e4200:# cat globalstate.py > GLOBAL = 0 > > def update(): > GLOBAL += 1 > > > however it doesn't work!! > > glic3 at e4200:# python > Python 2.7.3 (default, Aug 1 2012, 05:14:39) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import globalstate >>>> globalstate.update() > Traceback (most recent call last): > File "", line 1, in > File "globalstate.py", line 4, in update > GLOBAL += 1 > UnboundLocalError: local variable 'GLOBAL' referenced before assignment > > > And I don't know why :( > Anyone ? > > Thanks!! > You must tell the update function that GLOBAL is global. -- 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 Thu Jan 30 17:55:35 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 09:55:35 +1100 Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> References: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 9:48 AM, CM wrote: > builtin_all = __builtins__.all > > but I got the error: > > AttributeError: 'dict' object has no attribute 'all' Try using square brackets notation instead. Apparently your __builtins__ is a dictionary, not a module, though I don't know why (probably something to do with numpy, which I've never actually used). But try this: builtin_all = __builtins__["all"] It might work. ChrisA From ned at nedbatchelder.com Thu Jan 30 17:56:17 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Thu, 30 Jan 2014 17:56:17 -0500 Subject: Why this throws an UnboundLocalError ? In-Reply-To: References: Message-ID: On 1/30/14 5:46 PM, Marc Aymerich wrote: > Dear all, > > I have a very simple module > > glic3 at e4200:# cat globalstate.py > GLOBAL = 0 > > def update(): > GLOBAL += 1 > > > however it doesn't work!! > > glic3 at e4200:# python > Python 2.7.3 (default, Aug 1 2012, 05:14:39) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import globalstate >>>> globalstate.update() > Traceback (most recent call last): > File "", line 1, in > File "globalstate.py", line 4, in update > GLOBAL += 1 > UnboundLocalError: local variable 'GLOBAL' referenced before assignment > > > And I don't know why :( > Anyone ? > > Thanks!! > Assignment statements in functions implicitly make local names. If you want to assign a new value to a global name in a function, you have to use a global statement: def update(): global GLOBAL GLOBAL += 1 -- Ned Batchelder, http://nedbatchelder.com From cmpython at gmail.com Thu Jan 30 18:00:34 2014 From: cmpython at gmail.com (CM) Date: Thu, 30 Jan 2014 15:00:34 -0800 (PST) Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: References: Message-ID: <5673ebd0-89b6-485c-8ccb-f62bf15f513a@googlegroups.com> On Thursday, January 30, 2014 5:25:31 PM UTC-5, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 9:04 AM, CM wrote: > > > fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] > > > fake_result = not all(i == '[omitted]' for i in fake_data) > > > print 'This is fake result: ', fake_result > > > > Trying to get my head around this. You want to see if all the values > in fake_data are '[omitted]' or not? That is to say, if there's > anything that isn't '[omitted]'? Not sure that that's a normal thing > to be asking, but that's what your code appears to do. That's what I want, yes. It probably sure isn't a normal thing to be asking, and I wouldn't be surprised if I am approaching it the wrong way. Essentially, if ALL the items in that list are '[omitted]', I must not process the list, but if even one of them is something other than '[omitted]', I need to process it. If there is a more Pythonic / better way to approach that, I'd like to know it. > In theory, that should do the exact same thing as your code (returning > True if there's anything in fake_data that is not '[omitted]'). Yes, as you saw and as Peter showed, that the builtin all was shadowed by numpy's all. I wouldn't have thought of that, but it makes sense now. These sorts of shadowing problems are so rare for me that I never think about that possibility. From cmpython at gmail.com Thu Jan 30 18:02:42 2014 From: cmpython at gmail.com (CM) Date: Thu, 30 Jan 2014 15:02:42 -0800 (PST) Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: References: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> Message-ID: > Try using square brackets notation instead. Apparently your > __builtins__ is a dictionary, not a module, though I don't know why > (probably something to do with numpy, which I've never actually used). > > But try this: > builtin_all = __builtins__["all"] > > It might work. Yes, it does. Thanks! Che M From spammers at will.thrinaxodon Thu Jan 30 18:04:47 2014 From: spammers at will.thrinaxodon (CHAIRMAN THRINAXODON OF THE COMMUNIST PARTY OF CANADA) Date: Thu, 30 Jan 2014 18:04:47 -0500 Subject: HOW EVOLUTIONISTS MISUSE SCIENCE Message-ID: http://www.talkorigins.org/ > Vs > http://www.trueorigin.org/ > WHICH ONE'S TRUE? > This one!: http://www.trueorigin.org/ -- Thrinaxodon, The Ultimate Defender of USENET From __peter__ at web.de Thu Jan 30 18:08:08 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Jan 2014 00:08:08 +0100 Subject: Statement evals as False in my IDE and True elsewhere References: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> Message-ID: CM wrote: > On Thursday, January 30, 2014 5:14:57 PM UTC-5, Peter Otten wrote: > >> Hint: >> >> >>> def demo(): >> ... fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] >> ... fake_result = not all(i == '[omitted]' for i in fake_data) >> ... print 'This is fake result: ', fake_result >> >> >>> demo() >> This is fake result: True >> >> >>> from numpy import all >> >>> demo() >> This is fake result: False > > That's brilliant, thanks! Now I'm just a bit unsure of what to do about > it. First, I don't actually have the line "from numpy import all" in that > module's code, although I have imports of numpy; I think it is getting > brought in through Matplotlib's pylab module, which I do import in that > module. > > In any case, what's the most Pythonic way to deal with this? My first > thought was to create the old all function and rename it so there would be > no conflict: > > (both of what follows taken from answers here: > http://stackoverflow.com/questions/18774388/re-import-aliased-shadowed- python-built-in-methods) > > builtin_all = __builtins__.all > > but I got the error: > > AttributeError: 'dict' object has no attribute 'all' > > So I wound up doing this: > > from __builtin__ import * > > which fixed the problem...but seems less than optimal, because what if I > wanted to have numpy's all still in play? import numpy # you can now use numpy's all as numpy.all(...) del all # remove numpy's all from your module's global namespace and # thus make the builtin visible again From rosuav at gmail.com Thu Jan 30 18:25:41 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 10:25:41 +1100 Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: <5673ebd0-89b6-485c-8ccb-f62bf15f513a@googlegroups.com> References: <5673ebd0-89b6-485c-8ccb-f62bf15f513a@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 10:00 AM, CM wrote: > Essentially, if ALL the items in that list are '[omitted]', I must not process the list, but if even one of them is something other than '[omitted]', I need to process it. Okay. The set example that I gave will work, then - as long as all items are hashable (if they're strings, they are). Up to you which one's more readable. In any case, that could do with a supporting comment. My first suspicion was that it ought to be written as: fake_result = '[omitted]' not in fake_data and that it was calculating the wrong thing. But it is doing what you think it is. ChrisA From joshua at landau.ws Thu Jan 30 18:36:29 2014 From: joshua at landau.ws (Joshua Landau) Date: Thu, 30 Jan 2014 23:36:29 +0000 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On 30 January 2014 20:38, Chris Angelico wrote: > > Why is tuple unpacking limited to the last argument? Is it just for > the parallel with the function definition, where anything following it > is keyword-only? You're not the first person to ask that: http://www.python.org/dev/peps/pep-0448/ If you're able and willing to implement it, I believe the support is there. The primary reason I know of for its non-inclusion was that it was first proposed (with code) during a feature freeze. From rosuav at gmail.com Thu Jan 30 19:01:53 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 11:01:53 +1100 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 10:36 AM, Joshua Landau wrote: > On 30 January 2014 20:38, Chris Angelico wrote: >> >> Why is tuple unpacking limited to the last argument? Is it just for >> the parallel with the function definition, where anything following it >> is keyword-only? > > You're not the first person to ask that: > http://www.python.org/dev/peps/pep-0448/ > > If you're able and willing to implement it, I believe the support is > there. The primary reason I know of for its non-inclusion was that it > was first proposed (with code) during a feature freeze. Ah, okay. Glad it's not a fundamentally hard concept. I don't know that I want to dig into actually implementing that, just now, but I've added myself as nosy on bug 2292 (which is where the patch is being discussed, and is referenced in the PEP). I don't have a major use-case for it in Python, though I've used the equivalent Pike feature all over the place (it's done as @args where args is an array, and it's equivalent to listing the args - pretty much the same as *args in Python) - it's handy, even though it's almost never really crucial. It's perhaps telling that the only time I can recall running into this with Python is in making some deliberately bad code :D ChrisA From sg552 at hotmail.co.uk Thu Jan 30 19:10:07 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 31 Jan 2014 00:10:07 +0000 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On 30/01/2014 23:36, Joshua Landau wrote: > On 30 January 2014 20:38, Chris Angelico wrote: >> >> Why is tuple unpacking limited to the last argument? Is it just for >> the parallel with the function definition, where anything following it >> is keyword-only? > > You're not the first person to ask that: > http://www.python.org/dev/peps/pep-0448/ On a vaguely-related note, does anyone know why iterable unpacking in calls was removed in Python 3? I mean things like def f(x, (y, z)): return (x, y), z I don't have a use case in mind, I was just wondering. From ben+python at benfinney.id.au Thu Jan 30 19:21:34 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Jan 2014 11:21:34 +1100 Subject: Removal of iterable unpacking in function calls (was: 1 > 0 == True -> False) References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: <85zjmdatm9.fsf_-_@benfinney.id.au> Rotwang writes: > On a vaguely-related note, does anyone know why iterable unpacking in > calls was removed in Python 3? This is explained in the PEP which described its removal , especially . -- \ ?My, your, his, hers, ours, theirs, its. I'm, you're, he's, | `\ she's, we're, they're, it's.? ?anonymous, alt.sysadmin.recovery | _o__) | Ben Finney From cs at zip.com.au Thu Jan 30 19:06:31 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 31 Jan 2014 11:06:31 +1100 Subject: Another surprise from the datetime module In-Reply-To: References: Message-ID: <20140131000631.GA69776@cskk.homeip.net> On 30Jan2014 18:36, Neil Cerutti wrote: > On 2014-01-30, Roy Smith wrote: > > I was astounded just now to discover that datetime.timedelta > > doesn't have a replace() method (at least not in Python 2.7). > > Is there some fundamental reason why it shouldn't, or is this > > just an oversight? > > > > My immediate use case was wanting to print a timedelta without > > the fractions of seconds. The most straight-forward is: > > > > print td.replace(microseconds=0) > > That would be nice. > > In the meantime, this works for your use case: > > td -= td % timedelta(seconds=1) Hmm. I do not like the replace() as suggested. Firstly, replace is a verb, and I would normally read td.replace(microseconds=0) as an instruction to modify td in place. Traditionally, such methods in python return None. So you would need: td.replace(microseconds=0) print td Then, if the intent is to modify td in place, I would far prefer a system of properties on timedelta objects, eg: # print the microseconds part print td.microseconds # set the microseconds part to zero td.microseconds = 0 # print the modified timedelta print td Also, clearly, such a system needs definition: is "microseconds" the sub-millisecond fraction or the sub-second fraction, expressed in microsecond units? Alternatively, if td.replace() is intened to return a new timedelta with the specified properties, perhaps another factory would be cleaner: td2 = datetime.timedelta(td, microseconds=0) with a bunch of optional parameters like microseconds for modifying the initial value (used at call, as above). Finally, how much of Roy's original wish is addressable by format strings to print with a specified precision? No good for arithmetic, but perhaps ok for presentation. Cheers, -- Cameron Simpson I knew I was a real biker when I pulled up beside a car at a stoplight and the people inside locked all the doors. From joshua at landau.ws Thu Jan 30 19:32:41 2014 From: joshua at landau.ws (Joshua Landau) Date: Fri, 31 Jan 2014 00:32:41 +0000 Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On 31 January 2014 00:10, Rotwang wrote: > > On a vaguely-related note, does anyone know why iterable unpacking in calls > was removed in Python 3? I mean things like > > def f(x, (y, z)): > return (x, y), z > > I don't have a use case in mind, I was just wondering. http://www.python.org/dev/peps/pep-3113/ From sg552 at hotmail.co.uk Thu Jan 30 19:32:09 2014 From: sg552 at hotmail.co.uk (Rotwang) Date: Fri, 31 Jan 2014 00:32:09 +0000 Subject: Removal of iterable unpacking in function calls In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Message-ID: On 31/01/2014 00:21, Ben Finney wrote: > Rotwang writes: > >> On a vaguely-related note, does anyone know why iterable unpacking in >> calls was removed in Python 3? > > This is explained in the PEP which described its removal > , especially > . Ah, I had not seen that. Thanks. From ben+python at benfinney.id.au Thu Jan 30 19:35:14 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Jan 2014 11:35:14 +1100 Subject: Another surprise from the datetime module References: <20140131000631.GA69776@cskk.homeip.net> Message-ID: <85vbx1aszh.fsf@benfinney.id.au> Cameron Simpson writes: > Hmm. I do not like the replace() as suggested. > > Firstly, replace is a verb, and I would normally read > td.replace(microseconds=0) as an instruction to modify td in place. > Traditionally, such methods in python return None. I agree with this objection. A method that is named ?replace?, yet does not modify the object, is badly named. However, the existing ?replace? methods ?datetime.date.replace?, ?datetime.datetime.replace?, ?datetime.time.replace? already work this way: they create a new value and return it, without modifying the original object. So, if ?datetime.timedelta.replace? were to be implemented (I'm not convinced it is needed), it should have that same behaviour. -- \ ?I tell you the truth: this generation will certainly not pass | `\ away until all these things [the end of the world] have | _o__) happened.? ?Jesus Christ, c. 30 CE, as quoted in Matthew 24:34 | Ben Finney From cs at zip.com.au Thu Jan 30 21:01:40 2014 From: cs at zip.com.au (Cameron Simpson) Date: Fri, 31 Jan 2014 13:01:40 +1100 Subject: Another surprise from the datetime module In-Reply-To: <85vbx1aszh.fsf@benfinney.id.au> References: <85vbx1aszh.fsf@benfinney.id.au> Message-ID: <20140131020140.GA91965@cskk.homeip.net> On 31Jan2014 11:35, Ben Finney wrote: > Cameron Simpson writes: > > Hmm. I do not like the replace() as suggested. > > > > Firstly, replace is a verb, and I would normally read > > td.replace(microseconds=0) as an instruction to modify td in place. > > Traditionally, such methods in python return None. > > I agree with this objection. A method that is named ?replace?, yet does > not modify the object, is badly named. > > However, the existing ?replace? methods ?datetime.date.replace?, > ?datetime.datetime.replace?, ?datetime.time.replace? already work this > way: they create a new value and return it, without modifying the > original object. Ah. -- Cameron Simpson DRM: the functionality of refusing to function. - Richard Stallman From ben+python at benfinney.id.au Thu Jan 30 21:26:29 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Jan 2014 13:26:29 +1100 Subject: Improving support for timezones in Python (was: UTC "timezone" causing brain explosions) References: <85eh3qcsr9.fsf@benfinney.id.au> Message-ID: <85txckj38q.fsf@benfinney.id.au> Ben Finney writes: > Time zones are a hairy beast to manage, made all the more difficult > because national politicians continually fiddle with them which means > they can't just be a built-in part of the Python standard library. PyCon 2013 had a good talk on calendaring and timezone issues (video at ). The speaker, Lennart Regebro, maintains a library for getting the local timezone , and is currently working on a PEP to improve timezone support directly in the standard library . He also reinforces the message that UTC is the canonical timezone for storing and manipulating timestamp values, and we should be converting to/from those canonical values as early/late as possible in our programs. -- \ ?Reality must take precedence over public relations, for nature | `\ cannot be fooled.? ?Richard P. Feynman | _o__) | Ben Finney From rosuav at gmail.com Thu Jan 30 21:35:36 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 13:35:36 +1100 Subject: Improving support for timezones in Python (was: UTC "timezone" causing brain explosions) In-Reply-To: <85txckj38q.fsf@benfinney.id.au> References: <85eh3qcsr9.fsf@benfinney.id.au> <85txckj38q.fsf@benfinney.id.au> Message-ID: On Fri, Jan 31, 2014 at 1:26 PM, Ben Finney wrote: > He also reinforces the message that UTC is the canonical timezone for > storing and manipulating timestamp values, and we should be converting > to/from those canonical values as early/late as possible in our programs. Call it a "UTC Sandwich", like Ned Batchelder's "Unicode Sandwich". It's a good idea for the same reason. ChrisA From rustompmody at gmail.com Thu Jan 30 22:33:53 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 30 Jan 2014 19:33:53 -0800 (PST) Subject: 1 > 0 == True -> False In-Reply-To: References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> <3dcdc95d-5e30-46d3-b558-afedf9723c7c@googlegroups.com> <52ea6b0f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Friday, January 31, 2014 12:23:42 AM UTC+5:30, Roy Smith wrote: > On Thursday, January 30, 2014 10:09:03 AM UTC-5, Steven D'Aprano wrote: > > On Thu, 30 Jan 2014 09:08:58 -0500, Roy Smith wrote: > > > 1) Assume that you don't have the full operator precedence table > > > memorized and just parenthesize everything. > > Oh really? Do you actually write stuff like this? > > b = ((2*a) + 1) > Well, OK, I exaggerated a bit. Multiplication binds stronger than addition > in any language I've ever used, so I assume I know that one. But not much > beyond that. Not in APL. And horners rule is one touted advantage of that ax? + bx? + cx + d = d + xc + x?b + x?a = d + x(c + xb + x?a) = d + x(c + x(b + xa) Now APL by precedence rules - add and multiply are same precedence - multiply denoted with ? - all grouping right to left We have last equal to d + x?c + x?b + x?a > > if (b >= (-1)): > No, I wouldn't use either set of parens their either. But, if I have any doubt at all, I rather than look it up, I just put parens. And my threshold for doubt is pretty low. APL: b ? ?1 ie ? is part of the constant and - is not ad-hoc overloaded I wont talk of the if because that will spoil the fun And this is a unicode experiment! From steve+comp.lang.python at pearwood.info Thu Jan 30 22:53:27 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Jan 2014 03:53:27 GMT Subject: Another surprise from the datetime module References: <20140131000631.GA69776@cskk.homeip.net> Message-ID: <52eb1e37$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Jan 2014 11:35:14 +1100, Ben Finney wrote: > Cameron Simpson writes: > >> Hmm. I do not like the replace() as suggested. >> >> Firstly, replace is a verb, and I would normally read >> td.replace(microseconds=0) as an instruction to modify td in place. >> Traditionally, such methods in python return None. > > I agree with this objection. A method that is named ?replace?, yet does > not modify the object, is badly named. py> 'badly named'.replace('badly', 'well') 'well named' "replace" is a perfectly reasonable name for a method which performs a replacement, whether it replaces in place (for mutable objects) or makes a copy with replacement (for immutable objects). What else would you call it? py> ('well named'. ... make_a_copy_while_simultaneously_performing_a_replacement_on_the_copy ... ('well', 'excessively long') ... ) 'excessively long named' While explicit is better than implicit, sometimes you can be *too* explicit. If timedelta objects were mutable, then I would expect that you would just write the fields directly: td.microseconds = 0 rather than mess about with a replace method. -- Steven From roy at panix.com Thu Jan 30 22:58:10 2014 From: roy at panix.com (Roy Smith) Date: Thu, 30 Jan 2014 22:58:10 -0500 Subject: Another surprise from the datetime module References: <20140131000631.GA69776@cskk.homeip.net> <52eb1e37$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52eb1e37$0$29972$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > "replace" is a perfectly reasonable name for a method which performs a > replacement, whether it replaces in place (for mutable objects) or makes > a copy with replacement (for immutable objects). What else would you call > it? I suppose that by (imperfect) analogy to list.sort() and sorted(list), it might make more sense to call it replaced(). But, it's too late for any of that now. The other three classes in the module have replace(), so that's the obvious name to use for the fourth class. From dan at tombstonezero.net Thu Jan 30 23:04:15 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 31 Jan 2014 04:04:15 +0000 (UTC) Subject: Another surprise from the datetime module References: <20140131000631.GA69776@cskk.homeip.net> Message-ID: On Fri, 31 Jan 2014 11:35:14 +1100, Ben Finney wrote: > However, the existing ?replace? methods ?datetime.date.replace?, > ?datetime.datetime.replace?, ?datetime.time.replace? already work this > way: they create a new value and return it, without modifying the > original object. That's how str.replace works, too. *sigh* Dan From dan at tombstonezero.net Thu Jan 30 23:08:46 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 31 Jan 2014 04:08:46 +0000 (UTC) Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On Thu, 30 Jan 2014 15:21:35 +0000, Grant Edwards wrote: > On 2014-01-30, wxjmfauth at gmail.com wrote: > >> The temperature unit is the "Kelvin", not the "Degree Kelvin". >> One writes: 0 K, 275.15 K > > And remember to say "Kelvins" not "Kelvin" when speaking about > temperatures other than 1 K. And -1 K.? *wink* ? http://meta.stackoverflow.com/questions/165244/is-negative-one-plural notwithstanding From steve+comp.lang.python at pearwood.info Thu Jan 30 23:06:59 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Jan 2014 04:06:59 GMT Subject: buggy python interpretter or am I missing something here? References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52eb2162$0$29972$c3e8da3$5496439d@news.astraweb.com> On Thu, 30 Jan 2014 18:13:54 +1300, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Mon, 27 Jan 2014 12:22:22 -0800, Rick Johnson wrote: >> >>>Why do we even need an "input" function anyway if all it is going to do >>>is read from stdin? >> >> That's not all it does. >> >> For example, it handles backspacing, so that typing H E L O O BACKSPACE >> BACKSPACE L O gives "HELLO" rather than "HELOO\x7f\x7fO". > > No, it doesn't -- that's handled at a lower level. Any other method of > reading from stdin, as long as it hasn't been redirected away from the > console, has the same behaviour. > > I typed some backspaces in the input to each of the following > experiments, and they didn't end up in the data: > > >>> import sys > >>> x = sys.stdin.readline() > HELLO > >>> x > 'HELLO\n' > >>> import os > >>> f = os.fdopen(0) > >>> y = f.readline() > adsxx > >>> y > 'adsxx\n' Very interesting. I admit I don't actually understand the way stdin works. Can you explain what's going on here then? import sys, os import tty, termios, fcntl def getch(): """Get a single character from standard input. Does not echo to the screen. This will block waiting for a keypress. """ fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(fd) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch And in use: >>> [getch() for i in range(14)] ['H', 'e', 'l', 'l', 'l', '\x7f', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'] where I type "Helll BACKSPACE o SPACE World!" At what point do the arrow keys and other readline or readline-like features get handled? -- Steven From steve+comp.lang.python at pearwood.info Thu Jan 30 23:37:16 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Jan 2014 04:37:16 GMT Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: <52eb287c$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Jan 2014 04:08:46 +0000, Dan Sommers wrote about temperatures: > And -1 K. You josh, but there are negative temperatures in Kelvin. They're hotter than infinitely hot. http://en.wikipedia.org/wiki/Negative_temperature -- Steven From ben+python at benfinney.id.au Thu Jan 30 23:40:06 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Fri, 31 Jan 2014 15:40:06 +1100 Subject: Another surprise from the datetime module References: <20140131000631.GA69776@cskk.homeip.net> <52eb1e37$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <85k3dgix21.fsf@benfinney.id.au> Steven D'Aprano writes: > On Fri, 31 Jan 2014 11:35:14 +1100, Ben Finney wrote: > > > Cameron Simpson writes: > >> Firstly, replace is a verb, and I would normally read > >> td.replace(microseconds=0) as an instruction to modify td in place. > >> Traditionally, such methods in python return None. > > > > I agree with this objection. A method that is named ?replace?, yet > > does not modify the object, is badly named. > > [?] What else would you call it? I'd call it ?substitute?, and keep thinking until I came up with something better. I wouldn't think very hard, though, because the existing usage of ?foo.replace? for a create-new-object-with-different-values method is fairly well established in the Python built-in types and standard library. Local expectations do, past some threshold, override general expectations for the meaning of a term. -- \ ?Everyone is entitled to their own opinions, but they are not | `\ entitled to their own facts.? ?US Senator Pat Moynihan | _o__) | Ben Finney From britt.jonathan89 at gmail.com Thu Jan 30 23:53:51 2014 From: britt.jonathan89 at gmail.com (britt.jonathan89 at gmail.com) Date: Thu, 30 Jan 2014 20:53:51 -0800 (PST) Subject: Would Python be suitable for a sports statistics website? Message-ID: <1a7a822f-569b-4ead-9421-f1dcc5d4656e@googlegroups.com> First off I wanted to apologize for the lack of specificity in my subject title. I am a relative newbie to programming and need some advice. I tried StackOverflow but was sort of turned away for not having code in my post. I have been assigned by an internship with my university's athletic department, to create a statistics website to be used by sports media during games. What this means is that the statistics are generated by a stats computer into an XML file and I am wanting to parse this XML file and place it on the web quickly. Not necessarily in real-time but in a matter of a couple of seconds. I'd like to make a clean, simple website to start off with that displays these statistics. I've been playing around with Javascript and jQuery and as a beginning programmer have really been in over my head. What I want to do is start completely over and actually try to learn a language before diving in. My question is, would Python be a suitable language for developing a website / web application that performs these tasks? I've been researching Python and it is the language I am most interested in learning. I've been messing around with IDLE and have really enjoyed the syntax. I've also been reading about Django / Tornado etc. Thank you all so much for your time. From tjreedy at udel.edu Fri Jan 31 00:05:19 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 00:05:19 -0500 Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: References: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> Message-ID: On 1/30/2014 5:55 PM, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 9:48 AM, CM wrote: >> builtin_all = __builtins__.all >> >> but I got the error: >> >> AttributeError: 'dict' object has no attribute 'all' > > Try using square brackets notation instead. Apparently your > __builtins__ is a dictionary, not a module, though I don't know why For technical reasons Guido once explained and I have fogotten, it depends on whether you are in main module or an imported module -- and maybe the Python version. -- Terry Jan Reedy From rosuav at gmail.com Fri Jan 31 00:07:50 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 16:07:50 +1100 Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: References: <13a1aca8-a246-4618-925f-05ebf6c2e950@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 4:05 PM, Terry Reedy wrote: > On 1/30/2014 5:55 PM, Chris Angelico wrote: >> >> On Fri, Jan 31, 2014 at 9:48 AM, CM wrote: >>> >>> builtin_all = __builtins__.all >>> >>> but I got the error: >>> >>> AttributeError: 'dict' object has no attribute 'all' >> >> >> Try using square brackets notation instead. Apparently your >> __builtins__ is a dictionary, not a module, though I don't know why > > > For technical reasons Guido once explained and I have fogotten, it depends > on whether you are in main module or an imported module -- and maybe the > Python version. Ah, okay. Anyway, the error message makes it clear. I love clear error messages. ChrisA From kushal.kumaran at gmail.com Fri Jan 31 00:07:41 2014 From: kushal.kumaran at gmail.com (Kushal Kumaran) Date: Fri, 31 Jan 2014 10:37:41 +0530 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52eb2162$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> <52eb2162$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52eb2fa9.2d38320a.35b7.058a@mx.google.com> Steven D'Aprano writes: > On Thu, 30 Jan 2014 18:13:54 +1300, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >>> On Mon, 27 Jan 2014 12:22:22 -0800, Rick Johnson wrote: >>> >>>>Why do we even need an "input" function anyway if all it is going to do >>>>is read from stdin? >>> >>> That's not all it does. >>> >>> For example, it handles backspacing, so that typing H E L O O BACKSPACE >>> BACKSPACE L O gives "HELLO" rather than "HELOO\x7f\x7fO". >> >> No, it doesn't -- that's handled at a lower level. Any other method of >> reading from stdin, as long as it hasn't been redirected away from the >> console, has the same behaviour. >> >> I typed some backspaces in the input to each of the following >> experiments, and they didn't end up in the data: >> >> >>> import sys >> >>> x = sys.stdin.readline() >> HELLO >> >>> x >> 'HELLO\n' >> >>> import os >> >>> f = os.fdopen(0) >> >>> y = f.readline() >> adsxx >> >>> y >> 'adsxx\n' > > > Very interesting. I admit I don't actually understand the way stdin > works. Can you explain what's going on here then? > > import sys, os > import tty, termios, fcntl > > def getch(): > """Get a single character from standard input. > > Does not echo to the screen. This will block waiting for a keypress. > """ > fd = sys.stdin.fileno() > old_settings = termios.tcgetattr(fd) > try: > tty.setraw(fd) > ch = sys.stdin.read(1) > finally: > termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) > return ch > > > And in use: > >>>> [getch() for i in range(14)] > ['H', 'e', 'l', 'l', 'l', '\x7f', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'] > > > where I type "Helll BACKSPACE o SPACE World!" > > > At what point do the arrow keys and other readline or readline-like > features get handled? > They can be handled by the in-kernel tty driver, when you're using a tty set in "cooked" mode. This driver can be configured by the termios functions, which invoke various ioctls on the terminal devices. Or you can set the tty to "raw" mode, and the keystrokes are passed on to the application, which can do all sorts of interpretation (for example if you're using the readline library, or a curses app). W. Richard Stevens covers this in much detail in APUE, but you can preserve your sanity by being ignorant of the details of tty handling. -- regards, kushal -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 489 bytes Desc: not available URL: From tjreedy at udel.edu Fri Jan 31 00:09:19 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 00:09:19 -0500 Subject: Statement evals as False in my IDE and True elsewhere In-Reply-To: <5673ebd0-89b6-485c-8ccb-f62bf15f513a@googlegroups.com> References: <5673ebd0-89b6-485c-8ccb-f62bf15f513a@googlegroups.com> Message-ID: On 1/30/2014 6:00 PM, CM wrote: > On Thursday, January 30, 2014 5:25:31 PM UTC-5, Chris Angelico wrote: >> On Fri, Jan 31, 2014 at 9:04 AM, CM wrote: >> >>> fake_data = ['n/a', 'n/a', 'n/a', 'n/a', '[omitted]', '12'] >> >>> fake_result = not all(i == '[omitted]' for i in fake_data) >> Trying to get my head around this. You want to see if all the values >> in fake_data are '[omitted]' or not? That is to say, if there's >> anything that isn't '[omitted]'? Not sure that that's a normal thing >> to be asking, but that's what your code appears to do. > > That's what I want, yes. It probably sure isn't a normal thing to be asking, and I wouldn't be surprised if I am approaching it the wrong way. Essentially, if ALL the items in that list are '[omitted]', I must not process the list, but if even one of them is something other than '[omitted]', I need to process it. > > If there is a more Pythonic / better way to approach that, I'd like to know it. not all(x) == any(not x), so... any(i != '[omitted]' for i in fake_data) While nothing you import should *ever* mask a builtin, this would also solve the all problem -- Terry Jan Reedy From scottwd80 at gmail.com Fri Jan 31 00:12:19 2014 From: scottwd80 at gmail.com (scottwd80 at gmail.com) Date: Thu, 30 Jan 2014 21:12:19 -0800 (PST) Subject: Help with some python homework... Message-ID: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Here is the question that was asked and below that I'll paste the code I have so far. Any pointers would be great. Please keep in mind this is only my second week with python (or any programming for that matter) so I have no idea what I'm doing. How would you code this? Anyways, any help is GREATLY APPRECIATED! I'd kind of like to figure it out with % rather than subtracting everything also, but doesn't really matter either way. **If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again, what time do I get home for breakfast?** seconds = 1 hours = seconds / (60*60) seconds = seconds - hours*60*60 minutes = seconds / 60 seconds = seconds - minutes *60 time_left_house = 6 * hours + 52 * minutes miles_run_easy_pace = 2 * (8 * minutes + 15 * seconds) miles_run_fast_pace = 3 * (7 * minutes + 12 * seconds) total_time_run = miles_run_easy_pace + miles_run_fast_pace + time_left_house print total_time_run, "Total time run: " , hours, 'Hours: ', minutes, 'Minutes: ', seconds, 'Seconds: ' FYI, i'm using python 2.7.6 From tjreedy at udel.edu Fri Jan 31 00:26:05 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 00:26:05 -0500 Subject: Try-except-finally paradox In-Reply-To: References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: On 1/30/2014 7:05 AM, Dave Angel wrote: > Jessica Ross Wrote in message: >> I found something like this in a StackOverflow discussion. >>>>> def paradox(): >> ... try: >> ... raise Exception("Exception raised during try") >> ... except: >> ... print "Except after try" >> ... return True >> ... finally: >> ... print "Finally" >> ... return False >> ... return None >> ... >>>>> return_val = paradox() >> Except after try >> Finally >>>>> return_val >> False >> >> I understand most of this. >> What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? >> > > The finally has to happen before any return inside the try or the > except. And once you're in the finally clause you'll finish it > before resuming the except clause. Since it has a return, that > will happen before the other returns. The one in the except block > will never get reached. > > It's the only reasonable behavior., to my mind. Checking with the disassembled code, it appears that the except return happens first and is then caught and the value over-written 2 0 SETUP_FINALLY 45 (to 48) 3 SETUP_EXCEPT 16 (to 22) 3 6 LOAD_GLOBAL 0 (Exception) 9 LOAD_CONST 1 ('Exception raised during try') 12 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 15 RAISE_VARARGS 1 18 POP_BLOCK 19 JUMP_FORWARD 22 (to 44) 4 >> 22 POP_TOP 23 POP_TOP 24 POP_TOP 5 25 LOAD_GLOBAL 1 (print) 28 LOAD_CONST 2 ('Except after try') 31 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 34 POP_TOP 6 35 LOAD_CONST 3 (True) 38 RETURN_VALUE 39 POP_EXCEPT 40 JUMP_FORWARD 1 (to 44) 43 END_FINALLY >> 44 POP_BLOCK 45 LOAD_CONST 0 (None) 8 >> 48 LOAD_GLOBAL 1 (print) 51 LOAD_CONST 4 ('Finally') 54 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 57 POP_TOP 9 58 LOAD_CONST 5 (False) 61 RETURN_VALUE 62 END_FINALLY 10 63 LOAD_CONST 0 (None) 66 RETURN_VALUE -- Terry Jan Reedy From rosuav at gmail.com Fri Jan 31 00:30:11 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 16:30:11 +1100 Subject: Help with some python homework... In-Reply-To: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 4:12 PM, wrote: > **If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again, what time do I get home for breakfast?** > > > > seconds = 1 > hours = seconds / (60*60) > seconds = seconds - hours*60*60 > minutes = seconds / 60 > seconds = seconds - minutes *60 > > time_left_house = 6 * hours + 52 * minutes > > miles_run_easy_pace = 2 * (8 * minutes + 15 * seconds) > > miles_run_fast_pace = 3 * (7 * minutes + 12 * seconds) > > > total_time_run = miles_run_easy_pace + miles_run_fast_pace + time_left_house Thanks for being up-front about it being homework. I'll give you one broad hint, and see if you can figure it out from there. Your beginning work is not actually achieving anything useful. To make your next steps work, what you actually want is two very simple assignments that will mean that "6 * hours" comes out as the number of seconds in six hours. Then, when you've added all the different pieces together, you'll have a final time that's measured in seconds - and since that final time includes the time_left_house, it's actually going to be the number of seconds since midnight. This is actually an excellent way to represent time (number of seconds since some "beginning point" aka epoch). There's then just one last step: Convert it into hours, minutes, and seconds, for display. You have most of the code for doing that. So, work on this in two parts. In the first part, make your program calculate how many seconds after midnight you'll get home. (The correct answer there is 27006, according to my calculations. Of course, you need to have a program that produces the correct answer, not just the answer.) Then work out how to make that display as hh:mm:ss. I think you can probably get it from there - you're already a lot of the way toward it. But if not, you know where to find us :) ChrisA From jsandvik at gmail.com Fri Jan 31 00:05:22 2014 From: jsandvik at gmail.com (Jeff Sandvik) Date: Thu, 30 Jan 2014 21:05:22 -0800 Subject: Would Python be suitable for a sports statistics website? In-Reply-To: <1a7a822f-569b-4ead-9421-f1dcc5d4656e@googlegroups.com> References: <1a7a822f-569b-4ead-9421-f1dcc5d4656e@googlegroups.com> Message-ID: <3E3D40D9-512B-4E1C-99D9-0ED28889A72F@gmail.com> Python is definitely suitable for that sort of task. Django is good for this sort of thing, but I?d also like to mention using Flask (http://flask.pocoo.org), especially if you are a beginner. I use it for some of my work, and you could potentially get your project up and running that much quicker since it is a fairly light-weight web framework. The only thing is you?ll be missing out on some of the more convenient features that Django introduces. On Jan 30, 2014, at 8:53 PM, britt.jonathan89 at gmail.com wrote: > First off I wanted to apologize for the lack of specificity in my subject title. I am a relative newbie to programming and need some advice. I tried StackOverflow but was sort of turned away for not having code in my post. > > I have been assigned by an internship with my university's athletic department, to create a statistics website to be used by sports media during games. What this means is that the statistics are generated by a stats computer into an XML file and I am wanting to parse this XML file and place it on the web quickly. Not necessarily in real-time but in a matter of a couple of seconds. I'd like to make a clean, simple website to start off with that displays these statistics. > > I've been playing around with Javascript and jQuery and as a beginning programmer have really been in over my head. What I want to do is start completely over and actually try to learn a language before diving in. > > My question is, would Python be a suitable language for developing a website / web application that performs these tasks? I've been researching Python and it is the language I am most interested in learning. I've been messing around with IDLE and have really enjoyed the syntax. I've also been reading about Django / Tornado etc. Thank you all so much for your time. > > -- > https://mail.python.org/mailman/listinfo/python-list From scottwd80 at gmail.com Fri Jan 31 01:24:01 2014 From: scottwd80 at gmail.com (sjud9227) Date: Thu, 30 Jan 2014 22:24:01 -0800 (PST) Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Message-ID: <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> On Thursday, January 30, 2014 10:30:11 PM UTC-7, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 4:12 PM, wrote: > > > **If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again, what time do I get home for breakfast?** > > > > > > > > > > > > seconds = 1 > > > hours = seconds / (60*60) > > > seconds = seconds - hours*60*60 > > > minutes = seconds / 60 > > > seconds = seconds - minutes *60 > > > > > > time_left_house = 6 * hours + 52 * minutes > > > > > > miles_run_easy_pace = 2 * (8 * minutes + 15 * seconds) > > > > > > miles_run_fast_pace = 3 * (7 * minutes + 12 * seconds) > > > > > > > > > total_time_run = miles_run_easy_pace + miles_run_fast_pace + time_left_house > > > > Thanks for being up-front about it being homework. I'll give you one > > broad hint, and see if you can figure it out from there. > > > > Your beginning work is not actually achieving anything useful. To make > > your next steps work, what you actually want is two very simple > > assignments that will mean that "6 * hours" comes out as the number of > > seconds in six hours. Then, when you've added all the different pieces > > together, you'll have a final time that's measured in seconds - and > > since that final time includes the time_left_house, it's actually > > going to be the number of seconds since midnight. This is actually an > > excellent way to represent time (number of seconds since some > > "beginning point" aka epoch). There's then just one last step: Convert > > it into hours, minutes, and seconds, for display. You have most of the > > code for doing that. > > > > So, work on this in two parts. In the first part, make your program > > calculate how many seconds after midnight you'll get home. (The > > correct answer there is 27006, according to my calculations. Of > > course, you need to have a program that produces the correct answer, > > not just the answer.) Then work out how to make that display as > > hh:mm:ss. > > > > I think you can probably get it from there - you're already a lot of > > the way toward it. But if not, you know where to find us :) > > > > ChrisA Thank you so much Chris. However, i'm still a little confused. Doesn't assigning seconds/(60*60) mean that calculating 6*hours will give me 6 hours in seconds? Also, why calculate how many seconds from midnight? wouldn't it just be from the time that you left the house at 6:52? Also, for the life of me I cannot figure out how to make everything display in hh:mm:ss. I realize I'm asking a lot especially do to the fact it's homework but, we are allowed help in class I just don't have class again until next Tuesday. Plus I really do want to learn not just get the answers. From dan at tombstonezero.net Fri Jan 31 01:28:58 2014 From: dan at tombstonezero.net (Dan Sommers) Date: Fri, 31 Jan 2014 06:28:58 +0000 (UTC) Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <52eb287c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, 31 Jan 2014 04:37:16 +0000, Steven D'Aprano wrote: > On Fri, 31 Jan 2014 04:08:46 +0000, Dan Sommers wrote about temperatures: > >> And -1 K. > > You josh, but there are negative temperatures in Kelvin. They're hotter > than infinitely hot. > > http://en.wikipedia.org/wiki/Negative_temperature That's what I get for stopping with an undergraduate degree in physics. Thanks for the link; I learned something interesting today. ObPython: My program retrieves temperatures (in Kelvins) from an external device (the details of which I am not at liberty to discuss) and stores them in the cloud (because that's where all the cool kids store data these days), and there's something really weird going on. Here's my code and the output, filtered through http://sscce.org/: $ cat ./program.py import cloudstorageinterface temperature1 = cloudstorageinterface.get_a_temperature() temperature2 = cloudstorageinterface.get_a_temperature() print('temperature1 is', temperature1, 'K') print('temperature2 is', temperature2, 'K') if temperature2 > temperature1: print('temperature2 is hotter than temperature1') if temperature2 < temperature1: print('temperature1 is hotter than temperature2') if temperature2 == temperature1: print("this can't happen") $ python ./program.py temperature1 is -100 K temperature2 is 100 K temperature2 is hotter than temperature1 But everyone knows that -100K is hotter than 100K. I tried converting to UTC, but that didn't help. What am I missing? From rosuav at gmail.com Fri Jan 31 01:38:05 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 17:38:05 +1100 Subject: Help with some python homework... In-Reply-To: <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 5:24 PM, sjud9227 wrote: > Thank you so much Chris. However, i'm still a little confused. Doesn't assigning seconds/(60*60) mean that calculating 6*hours will give me 6 hours in seconds? Also, why calculate how many seconds from midnight? wouldn't it just be from the time that you left the house at 6:52? Also, for the life of me I cannot figure out how to make everything display in hh:mm:ss. I realize I'm asking a lot especially do to the fact it's homework but, we are allowed help in class I just don't have class again until next Tuesday. Plus I really do want to learn not just get the answers. First things first: You're using Google Groups, so your lines are unwrapped and your quoted text is double spaced. Please fix this every time you post (which requires some fiddling around) or switch to a client that works. I recommend using the mailing list instead: https://mail.python.org/mailman/listinfo/python-list Now then. What is your initial seconds? With the code you posted, it's 1, which means you get nothing at all after dividing by (60*60), so you just have a big ol' zero. What you need to do is convert hours into seconds. Is that going to mean multiplying by a big number or multiplying by a very small number? Think about it as something completely separate from programming. What number will you be multiplying by? Now code that. You can calculate the total number of seconds of your run. You can calculate the number of seconds from midnight until 6:52AM. Add the two together and you get the number of seconds from midnight until you get home. The final step, formatting, is pretty straight-forward. Let's suppose I have a number of seconds, say 40000. That represents some number of hours, some number of minutes, and some number of seconds. How many complete hours are there in 40000 seconds? How many seconds are left over? And out of those left-over seconds, how many minutes can you make? How many seconds are left after the minutes are taken out? These questions are all answered by division and modulo operations. You can actually solve this completely separately from the other part of the problem; try answering it for the figure I gave (40000 seconds), then try it for a few other numbers, and see how it goes. ChrisA From rosuav at gmail.com Fri Jan 31 01:42:30 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 17:42:30 +1100 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <52eb287c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Jan 31, 2014 at 5:28 PM, Dan Sommers wrote: > ObPython: My program retrieves temperatures (in Kelvins) from an > external device (the details of which I am not at liberty to discuss) > and stores them in the cloud (because that's where all the cool kids > store data these days), and there's something really weird going on. > > > $ python ./program.py > temperature1 is -100 K > temperature2 is 100 K > temperature2 is hotter than temperature1 > > But everyone knows that -100K is hotter than 100K. I tried converting > to UTC, but that didn't help. What am I missing? I'm sorry, you have completely misunderstood the problem here. You are storing data in the cloud, which means you're representing everything with water. It is therefore fundamentally illogical to use any temperature outside the range [273.15K, 373.15K], because otherwise your cloud will freeze or boil, and either way, it'll crash badly. Plus, converting to UTC? Puh-leeze. You should be using kilogram meters per second. ChrisA From scottwd80 at gmail.com Fri Jan 31 01:48:18 2014 From: scottwd80 at gmail.com (sjud9227) Date: Thu, 30 Jan 2014 22:48:18 -0800 (PST) Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: <74e3a5ed-40b7-4a89-aebb-205f76d0c451@googlegroups.com> On Thursday, January 30, 2014 11:38:05 PM UTC-7, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 5:24 PM, sjud9227 wrote: > > > Thank you so much Chris. However, i'm still a little confused. Doesn't assigning seconds/(60*60) mean that calculating 6*hours will give me 6 hours in seconds? Also, why calculate how many seconds from midnight? wouldn't it just be from the time that you left the house at 6:52? Also, for the life of me I cannot figure out how to make everything display in hh:mm:ss. I realize I'm asking a lot especially do to the fact it's homework but, we are allowed help in class I just don't have class again until next Tuesday. Plus I really do want to learn not just get the answers. > > > > First things first: You're using Google Groups, so your lines are > > unwrapped and your quoted text is double spaced. Please fix this every > > time you post (which requires some fiddling around) or switch to a > > client that works. I recommend using the mailing list instead: > > > > https://mail.python.org/mailman/listinfo/python-list > > > > Now then. > > > > What is your initial seconds? With the code you posted, it's 1, which > > means you get nothing at all after dividing by (60*60), so you just > > have a big ol' zero. > > > > What you need to do is convert hours into seconds. Is that going to > > mean multiplying by a big number or multiplying by a very small > > number? Think about it as something completely separate from > > programming. What number will you be multiplying by? Now code that. > > > > You can calculate the total number of seconds of your run. You can > > calculate the number of seconds from midnight until 6:52AM. Add the > > two together and you get the number of seconds from midnight until you > > get home. > > > > The final step, formatting, is pretty straight-forward. Let's suppose > > I have a number of seconds, say 40000. That represents some number of > > hours, some number of minutes, and some number of seconds. How many > > complete hours are there in 40000 seconds? How many seconds are left > > over? And out of those left-over seconds, how many minutes can you > > make? How many seconds are left after the minutes are taken out? These > > questions are all answered by division and modulo operations. You can > > actually solve this completely separately from the other part of the > > problem; try answering it for the figure I gave (40000 seconds), then > > try it for a few other numbers, and see how it goes. > > > > ChrisA Ok cool, I'll try this. Thank you again! Will def sign up for the mailing list too. From greg.ewing at canterbury.ac.nz Fri Jan 31 01:59:30 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 31 Jan 2014 19:59:30 +1300 Subject: buggy python interpretter or am I missing something here? In-Reply-To: <52eb2162$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <52e600ab$0$29542$862e30e2@ngroups.net> <52e60e69$0$29774$862e30e2@ngroups.net> <52e627bb$0$29811$862e30e2@ngroups.net> <25077ddb-e33d-4c5e-93c8-91d5d079ee8b@googlegroups.com> <0c9b382d-e6e5-490f-93e4-2837b3187cf7@googlegroups.com> <52e6dce7$0$29999$c3e8da3$5496439d@news.astraweb.com> <52eb2162$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > Can you explain what's going on here then? > > import sys, os > import tty, termios, fcntl > > def getch(): > """Get a single character from standard input. > > Does not echo to the screen. This will block waiting for a keypress. > """ > fd = sys.stdin.fileno() > old_settings = termios.tcgetattr(fd) > try: > tty.setraw(fd) > ch = sys.stdin.read(1) > finally: > termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) > return ch In Unix, normally line editing of terminal input is done by the tty device driver in the kernel. (In the old days it would have been talking to a real device connected by a serial line; nowadays it's more likely to be a "pseudo tty", which is a kind of funky pipe that looks like a tty from one end.) The tty driver can operate in a number of modes. In "cooked" mode it buffers up a line of input, handles backspacing and other editing, and a few other things like turning ctrl-C into an interrupt signal. In "raw" mode, it doesn't buffer anything and passes all characters straight on to the user process. The above code is temporarily putting the tty driver into raw mode, reading one character, and then putting it back the way it was. I'm not sure exactly what happens when Python is configured to use the readline library; probably something in the file object detects when it's being attached to a tty and interposes readline, which then puts the tty into raw mode and does its own thing. I have even less idea what happens on Windows. The console there seems to have an API all of its own. (The Unix philosophy is "everything is a file"; on Windows it seems to be "only files are files, everything else is some other weird thing of its own.") -- Greg From rustompmody at gmail.com Fri Jan 31 02:02:22 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Thu, 30 Jan 2014 23:02:22 -0800 (PST) Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: <76cf36f8-d0fb-4063-87c5-392ef8a76c8d@googlegroups.com> On Thursday, January 30, 2014 2:15:20 PM UTC+5:30, jmf wrote: > Le jeudi 30 janvier 2014 04:27:54 UTC+1, Chris Angelico a ?crit?: > > On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: > > >> How cruel... I suspect the smack at 0degC is much more painful > > >> than one > > > It's the 21st century; you should be making use of Unicode: 0?C. > > I started to read that and thought you were going to advocate the use of 0?K... > ====== > The temperature unit is the "Kelvin", not the "Degree Kelvin". > One writes: 0 K, 275.15 K OMG! OMG!! That is an ASCII K and not a unicode ? Now poor jmf will suffer the fire and brimstone of hell without diacr?tic?l marks From rasmus-berntsson at live.se Fri Jan 31 02:10:28 2014 From: rasmus-berntsson at live.se (Ralle) Date: Thu, 30 Jan 2014 23:10:28 -0800 (PST) Subject: Python (windows)packet sniffer ARP Message-ID: Hello I am wondering if it possible to create a packet sniffer in windows using python that only sniffs for ARP packets. From greg.ewing at canterbury.ac.nz Fri Jan 31 03:17:42 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 31 Jan 2014 21:17:42 +1300 Subject: Help with some python homework... In-Reply-To: <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: sjud9227 wrote: > Doesn't > assigning seconds/(60*60) mean that calculating 6*hours will give me 6 hours > in seconds? No, it's giving you 6 seconds in hours. (That should give you a clue as to what you should have done instead. :-) Also, I don't know what you were trying to do with these two statements: seconds = seconds - hours*60*60 seconds = seconds - minutes *60 but they don't belong there at all. If you simply take them out, that part of the program is almost right. > Also, why calculate how many seconds from midnight? Because the question asked "what time do I get home?", not "how long did it take me to get home?". You're already calculating "what time do I get home" with: total_time_run = miles_run_easy_pace + miles_run_fast_pace + time_left_house except that 'total_time_run' would be better called something like 'time_got_home'. > Also, for the life of > me I cannot figure out how to make everything display in hh:mm:ss. Here are a few hints: 1. Consider that if you take a number of seconds and divide it by the number of seconds in an hour, the quotient is the number of hours, and the remainder is the number of minutes and seconds left over, expressed in seconds. 2. If you then divide the remainder from (1) by the number of seconds in a minute, the quotient is the number of minutes, and the remainder is the number of seconds. 3. Python has the following operators for performing integer division: a // b gives the quotient of dividing a by b a % b gives the remainder (I recommend using '//' rather than just '/', because in some versions of Python, a/b does floating point division even if a and b are both integers, and that's not what you want here.) -- Greg From rosuav at gmail.com Fri Jan 31 03:30:24 2014 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 31 Jan 2014 19:30:24 +1100 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: On Fri, Jan 31, 2014 at 7:17 PM, Gregory Ewing wrote: > sjud9227 wrote: >> >> Doesn't >> assigning seconds/(60*60) mean that calculating 6*hours will give me 6 >> hours >> in seconds? > > No, it's giving you 6 seconds in hours. (That should > give you a clue as to what you should have done > instead. :-) > > ... > > a // b gives the quotient of dividing a by b > > a % b gives the remainder > > (I recommend using '//' rather than just '/', because > in some versions of Python, a/b does floating point > division even if a and b are both integers, and that's > not what you want here.) OP is using 2.7.6, so short of a __future__ directive, that won't actually give 6 seconds in hours (though it will try to), and // is unnecessary. ChrisA From breamoreboy at yahoo.co.uk Fri Jan 31 04:59:00 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Jan 2014 09:59:00 +0000 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> Message-ID: On 31/01/2014 04:08, Dan Sommers wrote: > On Thu, 30 Jan 2014 15:21:35 +0000, Grant Edwards wrote: > >> On 2014-01-30, wxjmfauth at gmail.com wrote: >> >>> The temperature unit is the "Kelvin", not the "Degree Kelvin". >>> One writes: 0 K, 275.15 K >> >> And remember to say "Kelvins" not "Kelvin" when speaking about >> temperatures other than 1 K. > > And -1 K.? *wink* > > ? http://meta.stackoverflow.com/questions/165244/is-negative-one-plural > notwithstanding > Does that -1 allow for the wind chill factor or not? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From seaspeak at gmail.com Fri Jan 31 05:16:36 2014 From: seaspeak at gmail.com (seaspeak at gmail.com) Date: Fri, 31 Jan 2014 02:16:36 -0800 (PST) Subject: how to iterate all sub-element in a list Message-ID: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> a list like L = [[1, 2], [3, 4, 5], [6]], which has random numbers of list, which has random numbers. How do I get another list m = [1, 2, 3, 4, 5, 6] in a succinct way? ( or iterate them) I should provide my own solution, but I really can't come out with one. From wxjmfauth at gmail.com Fri Jan 31 05:17:00 2014 From: wxjmfauth at gmail.com (wxjmfauth at gmail.com) Date: Fri, 31 Jan 2014 02:17:00 -0800 (PST) Subject: pytz question: GMT vs. UTC In-Reply-To: <76cf36f8-d0fb-4063-87c5-392ef8a76c8d@googlegroups.com> References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <76cf36f8-d0fb-4063-87c5-392ef8a76c8d@googlegroups.com> Message-ID: <068f40de-8d6a-4262-889c-9d79371d68fd@googlegroups.com> Le vendredi 31 janvier 2014 08:02:22 UTC+1, Rustom Mody a ?crit?: > On Thursday, January 30, 2014 2:15:20 PM UTC+5:30, jmf wrote: > > > Le jeudi 30 janvier 2014 04:27:54 UTC+1, Chris Angelico a ?crit?: > > > > On Thu, Jan 30, 2014 at 1:40 PM, MRAB wrote: > > > > >> How cruel... I suspect the smack at 0degC is much more painful > > > > >> than one > > > > > It's the 21st century; you should be making use of Unicode: 0?C. > > > > I started to read that and thought you were going to advocate the use of 0?K... > > > > > ====== > > > > > The temperature unit is the "Kelvin", not the "Degree Kelvin". > > > One writes: 0 K, 275.15 K > > > > OMG! OMG!! > > That is an ASCII K and not a unicode ? > > > > Now poor jmf will suffer the fire and brimstone of hell without > > diacr?tic?l marks ==== I'm aware of what I did. 1) You wrote: "That is an ASCII K and not a unicode ?". This is a non sense. You are opposing ascii and unicode, the reperoire of the ascii chars and the repertoire of the Unicode chars. In unicode, the are two "K"'s, one for the letter and one for the Kelvin unit, see my previous post. 2) I used the letter "K" for commodity. Btw, I'm also aware the 'KELVIN SIGN' is not availaible in many fonts. 3) If you wish to discuss the typographical aspect in that story, one can discuss the kind of space which should separate the number and the unit ('SPACE', 'SOFT HYPHEN', 'NARROW NO-BREAK SPACE', 'HAIR SPACE', ...). My "lazy" white space can also be considered as a mistake. 4) What is definitively wrong is to claim : "It's the 21st century; you should be making use of Unicode: 0?C." The 'DEGREE SIGN' and "Unicode" are two different things. It exists in many coding schemes. cs = ['iso-8859-1', 'iso-8859-2', 'cp437', 'cp850', 'cp1252', 'cp857',\ 'iso-8859-15'] for c in cs: c, '\u00b0'.encode(c, 'replace').decode(c) >>> cs = ['iso-8859-1', 'iso-8859-2', 'cp437', 'cp850', 'cp1252', 'cp857',\ ... 'iso-8859-15'] >>> for c in cs: ... c, '\u00b0'.encode(c, 'replace').decode(c) ... ('iso-8859-1', '?') ('iso-8859-2', '?') ('cp437', '?') ('cp850', '?') ('cp1252', '?') ('cp857', '?') ('iso-8859-15', '?') >>> 5) Not unicode. The "?" is available as "direct (Shift) key" on many European keyboards. 6) Finally and for the record : "n Kelvin" and not "n Degree Kelvin". jmf From skip at pobox.com Fri Jan 31 05:29:27 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 Jan 2014 04:29:27 -0600 Subject: how to iterate all sub-element in a list In-Reply-To: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> References: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> Message-ID: Google for "python flatten list." This question comes up frequently, though I'm not sure if that's because it's a common homework problem or because people are unaware of the += operator (or extend method) for lists, and so build lists-of-lists when they could just build them flat in the first place. Skip From seaspeak at gmail.com Fri Jan 31 05:42:45 2014 From: seaspeak at gmail.com (seaspeak at gmail.com) Date: Fri, 31 Jan 2014 02:42:45 -0800 (PST) Subject: how to iterate all sub-element in a list In-Reply-To: References: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> Message-ID: <600f2d6b-8068-453c-b21f-b23d0b13ff62@googlegroups.com> Skip Montanaro? 2014?1?31????UTC+8??6?29?27???? > Google for "python flatten list." > > > > This question comes up frequently, though I'm not sure if that's > > because it's a common homework problem or because people are unaware > > of the += operator (or extend method) for lists, and so build > > lists-of-lists when they could just build them flat in the first > > place. > > > > Skip thanks. a keyword is all I need. It is not homework. It is a common problem I guess. From __peter__ at web.de Fri Jan 31 05:48:13 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Jan 2014 11:48:13 +0100 Subject: how to iterate all sub-element in a list References: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> Message-ID: seaspeak at gmail.com wrote: > a list like L = [[1, 2], [3, 4, 5], [6]], which has > random numbers of list, which has random numbers. > > How do I get another list m = [1, 2, 3, 4, 5, 6] in a succinct way? ( or > iterate them) I should provide my own solution, but I really can't come > out with one. sum(L, []) list(itertools.chain.from_iterable(L)) but as a learning experience you should do this at least once with two nested for loops, then again with a single for loop and list.extend(). From greg.ewing at canterbury.ac.nz Fri Jan 31 05:46:36 2014 From: greg.ewing at canterbury.ac.nz (Gregory Ewing) Date: Fri, 31 Jan 2014 23:46:36 +1300 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: Chris Angelico wrote: > OP is using 2.7.6, so short of a __future__ directive, that won't > actually give 6 seconds in hours Oops, yes, you're right! (I always use future division these days, so I tend to forget about that.) > and // is unnecessary. It's still a good habit to get into, though, since it will continue to work in 3.x, and in 2.x it makes the intent of the code clear without having to know whether from __future__ import division is in effect. -- Greg From glicerinu at gmail.com Fri Jan 31 06:05:17 2014 From: glicerinu at gmail.com (Marc Aymerich) Date: Fri, 31 Jan 2014 12:05:17 +0100 Subject: Why this throws an UnboundLocalError ? In-Reply-To: References: Message-ID: On Thu, Jan 30, 2014 at 11:53 PM, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 9:46 AM, Marc Aymerich wrote: >> GLOBAL = 0 >> >> def update(): >> GLOBAL += 1 > > If you assign to a name, Python makes it local, unless you explicitly > tell it that you want it to be global: > > def update(): > global GLOBAL > GLOBAL += 1 > > But be aware that the ALL_CAPS name conventionally means a constant. > Since you're changing its value, it's not constant (wow! :) ), so > using a name of GLOBAL is a bad idea. (Also, obviously, you want to > name it appropriately to what you're doing, but I assume you called it > this as part of cutting down your example. For which, by the way, > thank you. You posted a complete example, and the full traceback, and > the Python version and platform. That's everything that we need to > help you - it's such a luxury!!) > Thank you very much guys! and for the additional tips Chris. :) I can't believe, all these years using Python and never encountered a situation where I needed to use global ! -- Marc From robertcwatson at yahoo.com Fri Jan 31 06:07:39 2014 From: robertcwatson at yahoo.com (Robert Watson) Date: Fri, 31 Jan 2014 06:07:39 -0500 Subject: webbrowser module bug? Message-ID: Sorry. Experiencing same problem in Python 2.6.4 on Ubuntu 10.04 (actually, Puppy Linux 5.2.8 which is based on Ubuntu Lucid) If anyone happens to see this and knows what was settled on as the best workaround, please email me a link to it or something at robertcwatson at yahoo.com. Robert "DocSalvage" Watson 2014-01-31 -------------- next part -------------- An HTML attachment was scrubbed... URL: From rustompmody at gmail.com Fri Jan 31 07:12:11 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 31 Jan 2014 04:12:11 -0800 (PST) Subject: how to iterate all sub-element in a list In-Reply-To: References: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> Message-ID: On Friday, January 31, 2014 4:18:13 PM UTC+5:30, Peter Otten wrote: > seaspeak wrote: > > a list like L = [[1, 2], [3, 4, 5], [6]], which has > > random numbers of list, which has random numbers. > > How do I get another list m = [1, 2, 3, 4, 5, 6] in a succinct way? ( or > > iterate them) I should provide my own solution, but I really can't come > > out with one. > sum(L, []) > list(itertools.chain.from_iterable(L)) > but as a learning experience you should do this at least once with two > nested for loops, then again with a single for loop and list.extend(). And then again with a double comprehension: [y for x in L for y in x] From rosuav at gmail.com Fri Jan 31 08:36:42 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 00:36:42 +1100 Subject: Why this throws an UnboundLocalError ? In-Reply-To: References: Message-ID: On Fri, Jan 31, 2014 at 10:05 PM, Marc Aymerich wrote: > I can't believe, all these years using Python and never encountered a > situation where I needed to use global ! That might be an indication of good code design :) ChrisA From neilc at norwich.edu Fri Jan 31 08:51:34 2014 From: neilc at norwich.edu (Neil Cerutti) Date: Fri, 31 Jan 2014 13:51:34 +0000 (UTC) Subject: Help with some python homework... References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Message-ID: On 2014-01-31, scottwd80 at gmail.com wrote: > Here is the question that was asked and below that I'll paste > the code I have so far. > > **If I leave my house at 6:52 am and run 1 mile at an easy pace > (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 > mile at easy pace again, what time do I get home for > breakfast?** That depends on the directions in which you run. Also, you are fast! But seriously, my advice is to find the answer the old fashioned way first, with pencil and paper. Then you'll have two things you don't now: 1. A correct answer to test your program's answer with. 2. A general idea of how to solve the problem. It's often a mistake to start writing code. Eventually you'll be able to go directly from problem to code more often, but it will take practice. -- Neil Cerutti From steve+comp.lang.python at pearwood.info Fri Jan 31 09:24:39 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 31 Jan 2014 14:24:39 GMT Subject: webbrowser module bug? References: Message-ID: <52ebb227$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Jan 2014 06:07:39 -0500, Robert Watson wrote: > Sorry. Experiencing same problem in Python 2.6.4 on Ubuntu 10.04 > (actually, Puppy Linux 5.2.8 which is based on Ubuntu Lucid) > > If anyone happens to see this and knows what was settled on as the best > workaround, please email me a link to it or something at > robertcwatson at yahoo.com. > > Robert "DocSalvage" Watson I'm reminded of the story of the guy who goes to the doctor. The doctor says, "Good morning, so what seems to be the problem?" The guy replies "You're the doctor, you tell me." You might have a bit more success asking for help with a bug if you tell us what bug it is. -- Steven From rosuav at gmail.com Fri Jan 31 09:44:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 01:44:39 +1100 Subject: webbrowser module bug? In-Reply-To: <52ebb227$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <52ebb227$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Feb 1, 2014 at 1:24 AM, Steven D'Aprano wrote: > On Fri, 31 Jan 2014 06:07:39 -0500, Robert Watson wrote: > >> Sorry. Experiencing same problem in Python 2.6.4 on Ubuntu 10.04 >> (actually, Puppy Linux 5.2.8 which is based on Ubuntu Lucid) >> >> If anyone happens to see this and knows what was settled on as the best >> workaround, please email me a link to it or something at >> robertcwatson at yahoo.com. >> >> Robert "DocSalvage" Watson > > > I'm reminded of the story of the guy who goes to the doctor. The doctor > says, "Good morning, so what seems to be the problem?" > > The guy replies "You're the doctor, you tell me." > I think, in this case, he had previously been consulting with Dr Hu, pediatrician, and now he just walked into a police box and didn't realize he wasn't talking to the right person. Either the post lacks content, or it ought to have been sent to a completely different list, or both. ChrisA From breamoreboy at yahoo.co.uk Fri Jan 31 09:48:46 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Jan 2014 14:48:46 +0000 Subject: how to iterate all sub-element in a list In-Reply-To: <600f2d6b-8068-453c-b21f-b23d0b13ff62@googlegroups.com> References: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> <600f2d6b-8068-453c-b21f-b23d0b13ff62@googlegroups.com> Message-ID: On 31/01/2014 10:42, seaspeak at gmail.com wrote: > Skip Montanaro? 2014?1?31????UTC+8??6?29?27???? >> Google for "python flatten list." >> >> >> >> This question comes up frequently, though I'm not sure if that's >> >> because it's a common homework problem or because people are unaware >> >> of the += operator (or extend method) for lists, and so build >> >> lists-of-lists when they could just build them flat in the first >> >> place. >> >> >> >> Skip > thanks. a keyword is all I need. > It is not homework. It is a common problem I guess. > I'm pleased to see that you have answers. In return would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. -- 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 Fri Jan 31 09:50:31 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Jan 2014 14:50:31 +0000 Subject: pytz question: GMT vs. UTC In-Reply-To: <068f40de-8d6a-4262-889c-9d79371d68fd@googlegroups.com> References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <76cf36f8-d0fb-4063-87c5-392ef8a76c8d@googlegroups.com> <068f40de-8d6a-4262-889c-9d79371d68fd@googlegroups.com> Message-ID: On 31/01/2014 10:17, wxjmfauth at gmail.com wrote: Is the double line spacing that you still use despite being asked not to ASCII or unicode? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From roy at panix.com Fri Jan 31 09:55:46 2014 From: roy at panix.com (Roy Smith) Date: Fri, 31 Jan 2014 09:55:46 -0500 Subject: Would Python be suitable for a sports statistics website? References: <1a7a822f-569b-4ead-9421-f1dcc5d4656e@googlegroups.com> Message-ID: In article <1a7a822f-569b-4ead-9421-f1dcc5d4656e at googlegroups.com>, britt.jonathan89 at gmail.com wrote: > I have been assigned by an internship with my university's athletic > department, to create a statistics website to be used by sports media during > games. What this means is that the statistics are generated by a stats > computer into an XML file and I am wanting to parse this XML file and place > it on the web quickly. Not necessarily in real-time but in a matter of a > couple of seconds. I'd like to make a clean, simple website to start off with > that displays these statistics. > > I've been playing around with Javascript and jQuery and as a beginning > programmer have really been in over my head. What I want to do is start > completely over and actually try to learn a language before diving in. My first thought is that this is a really ambitious project for a beginning programmer. My second thought is that maybe you want to bypass most of the work by having a mostly static site (which you can build with any number of Content Management Systems, even something like WordPress). Then, have a process which takes the XML, parses it (you would use Python's lxml library), and produces a HTML file containing the formatted scores. You could then include you HTML in the static site by way of an iframe, or something like that. From roy at panix.com Fri Jan 31 10:00:36 2014 From: roy at panix.com (Roy Smith) Date: Fri, 31 Jan 2014 10:00:36 -0500 Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <52eb287c$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: In article <52eb287c$0$29972$c3e8da3$5496439d at news.astraweb.com>, Steven D'Aprano wrote: > On Fri, 31 Jan 2014 04:08:46 +0000, Dan Sommers wrote about temperatures: > > > And -1 K. > > > You josh, but there are negative temperatures in Kelvin. They're hotter > than infinitely hot. > > http://en.wikipedia.org/wiki/Negative_temperature Negative Kelvins also have meaning as relative measurements. "The framzit is changing temperature at a rate of -3.6 K per gigafortnight" From roy at panix.com Fri Jan 31 10:04:31 2014 From: roy at panix.com (Roy Smith) Date: Fri, 31 Jan 2014 10:04:31 -0500 Subject: pytz question: GMT vs. UTC References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <76cf36f8-d0fb-4063-87c5-392ef8a76c8d@googlegroups.com> <068f40de-8d6a-4262-889c-9d79371d68fd@googlegroups.com> Message-ID: In article , Mark Lawrence wrote: > On 31/01/2014 10:17, wxjmfauth at gmail.com wrote: > > Is the double line spacing that you still use despite being asked not to > ASCII or unicode? It's not actually double line spacing. It's single spaced using UNICODE DOUBLE COMBINING LINEFEED WITH QUOTE MARKER as line terminators. From skip at pobox.com Fri Jan 31 09:57:15 2014 From: skip at pobox.com (Skip Montanaro) Date: Fri, 31 Jan 2014 08:57:15 -0600 Subject: Why this throws an UnboundLocalError ? In-Reply-To: References: Message-ID: > That might be an indication of good code design :) Or he got lucky and all his previous globals were mutable. :) Skip From robert.kern at gmail.com Fri Jan 31 10:08:27 2014 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 31 Jan 2014 15:08:27 +0000 Subject: pytz question: GMT vs. UTC In-Reply-To: References: <3g6je9h7fp29pebi7aa04tigc50hm3vepj@4ax.com> <52E9BB8C.80000@mrabarnett.plus.com> <76cf36f8-d0fb-4063-87c5-392ef8a76c8d@googlegroups.com> <068f40de-8d6a-4262-889c-9d79371d68fd@googlegroups.com> Message-ID: On 2014-01-31 15:04, Roy Smith wrote: > In article , > Mark Lawrence wrote: > >> On 31/01/2014 10:17, wxjmfauth at gmail.com wrote: >> >> Is the double line spacing that you still use despite being asked not to >> ASCII or unicode? > > It's not actually double line spacing. It's single spaced using UNICODE > DOUBLE COMBINING LINEFEED WITH QUOTE MARKER as line terminators. >>> len('\n\n>') 3 Clearly, the FSR is broken beyond repair. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco From betz.mark at gmail.com Fri Jan 31 10:32:42 2014 From: betz.mark at gmail.com (Mark Betz) Date: Fri, 31 Jan 2014 07:32:42 -0800 (PST) Subject: Python (windows)packet sniffer ARP In-Reply-To: References: Message-ID: On Friday, January 31, 2014 2:10:28 AM UTC-5, Ralle wrote: > Hello > > > > I am wondering if it possible to create a packet sniffer in windows using python that only sniffs for ARP packets. A couple of links to get you started: http://www.winpcap.org/ http://code.google.com/p/winpcapy/ From ycui at outlook.com Fri Jan 31 10:14:42 2014 From: ycui at outlook.com (Frank Cui) Date: Fri, 31 Jan 2014 12:14:42 -0300 Subject: Python (windows)packet sniffer ARP In-Reply-To: References: , Message-ID: > Date: Fri, 31 Jan 2014 07:32:42 -0800 > Subject: Re: Python (windows)packet sniffer ARP > From: betz.mark at gmail.com > To: python-list at python.org > > On Friday, January 31, 2014 2:10:28 AM UTC-5, Ralle wrote: > > Hello > > > > > > > > I am wondering if it possible to create a packet sniffer in windows using python that only sniffs for ARP packets. > > A couple of links to get you started: > > http://www.winpcap.org/ > http://code.google.com/p/winpcapy/ > -- > https://mail.python.org/mailman/listinfo/python-list Try scapy Frank -------------- next part -------------- An HTML attachment was scrubbed... URL: From elchino at cnn.cn Fri Jan 31 11:03:10 2014 From: elchino at cnn.cn (ElChino) Date: Fri, 31 Jan 2014 17:03:10 +0100 Subject: Python (windows)packet sniffer ARP References: Message-ID: "Mark Betz" wrote: >> I am wondering if it possible to create a packet sniffer in windows using python that only sniffs for ARP packets. > > A couple of links to get you started: The OP could use Impacket's libpcap bindings. With one of the examples, it's easy: python examples/sniff.py ether proto 0x0806 The excellent Impacket/Pcapy is here: http://oss.coresecurity.com/pcapy/ (but it seems down now). --gv From seaspeak at gmail.com Fri Jan 31 11:23:41 2014 From: seaspeak at gmail.com (seaspeak at gmail.com) Date: Fri, 31 Jan 2014 08:23:41 -0800 (PST) Subject: how to iterate all sub-element in a list In-Reply-To: References: <412b4d42-acba-4609-bd6d-e4d5c32db035@googlegroups.com> <600f2d6b-8068-453c-b21f-b23d0b13ff62@googlegroups.com> Message-ID: <578fc71b-d06c-47fd-ba65-564864239202@googlegroups.com> Mark Lawrence? 2014?1?31????UTC+8??10?48?46???? > I'm pleased to see that you have answers. In return would you please read and action this https://wiki.python.org/moin/GoogleGroupsPython to prevent us seeing the double line spacing above, thanks. > My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. > Mark Lawrence My bad, I replied in a hurry with my mobile. From rpucci2 at cox.net Fri Jan 31 12:01:38 2014 From: rpucci2 at cox.net (rpucci2 at cox.net) Date: Fri, 31 Jan 2014 12:01:38 -0500 Subject: Python shell wont open idle or an exisiting py file Message-ID: <24EAA33389A147D8BC08B029E2209E16@UserPC> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import idlelib.idle Exception in Tkinter callback Traceback (most recent call last): File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ return self.func(*args) File "C:\Python33\lib\idlelib\EditorWindow.py", line 927, in open_recent_file self.io.open(editFile=fn_closure) File "C:\Python33\lib\idlelib\IOBinding.py", line 183, in open flist.open(filename) File "C:\Python33\lib\idlelib\FileList.py", line 36, in open edit = self.EditorWindow(self, filename, key) File "C:\Python33\lib\idlelib\PyShell.py", line 126, in __init__ EditorWindow.__init__(self, *args) File "C:\Python33\lib\idlelib\EditorWindow.py", line 287, in __init__ if io.loadfile(filename): File "C:\Python33\lib\idlelib\IOBinding.py", line 242, in loadfile self.updaterecentfileslist(filename) File "C:\Python33\lib\idlelib\IOBinding.py", line 523, in updaterecentfileslist self.editwin.update_recent_files_list(filename) File "C:\Python33\lib\idlelib\EditorWindow.py", line 915, in update_recent_files_list menu.delete(0, END) # clear, and rebuild: File "C:\Python33\lib\tkinter\__init__.py", line 2778, in delete if 'command' in self.entryconfig(i): File "C:\Python33\lib\tkinter\__init__.py", line 2788, in entryconfigure return self._configure(('entryconfigure', index), cnf, kw) File "C:\Python33\lib\tkinter\__init__.py", line 1247, in _configure self.tk.call(_flatten((self._w, cmd)))): UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 10: invalid start byte This is the error message. -------------- next part -------------- An HTML attachment was scrubbed... URL: From bv8bv8bv8 at gmail.com Fri Jan 31 13:21:25 2014 From: bv8bv8bv8 at gmail.com (BV BV) Date: Fri, 31 Jan 2014 10:21:25 -0800 (PST) Subject: New facts about the pyramids: a new miracle of the Qur'an Message-ID: <9b8c17d3-1b61-4ef3-ba53-870a0eec687e@googlegroups.com> New facts about the pyramids: a new miracle of the Qur'an Last scientific discovery stated the following: French and U.S. researchers assert that the huge stones used by the Pharaohs to build the pyramids are just clay that has been heated at high temperatures... http://www.kaheel7.com/ar/images/stories/pyr-0.jpg Will the pyramids that we know as one of the Seven Wonders survive in the world? Did scientists find an answer to the puzzle of how the pyramids were built in ancient Egypt? Are some people still believe that the Jinn are the builders of these pyramids? Is it possible to believe that creatures from outer space built the pyramids of Egypt? ... These speculations filled the world and lasted for several centuries, but the new discovery made by scientists from France and America will change the scientists` look forever. It will also give a simple scientific explanation to the mystery of building the pyramids, but more odd is that this mystery has been in the Qur'an fourteen centuries ago!!! It was believed that the pharaohs have carved the stones but the question here is: How come all the stones are so identical that you cannot find a distance between one stone and another? And where are the equipments and chisels that were used in carving those stones? Until now, they have not been found? This discovery confirms that the scientists were wrong when they thought that the pyramids were built of stones. The nearest answer to logic and truth is to say that the civilization of the pharaohs was built on the clay!! http://www.kaheel7.com/ar/images/stories/pyr-1.jpg This is a picture from top of Cheops the Great ` pyramid, as we can notice this pyramid was the highest building in the world with a height up to 146 meters. Millions of stones were used in the construction: each stone weighs several tons. It is an enormous work that gives evidence to the powers the Pharaohs reached before 4500 years ago. New scientific facts One of the scientific facts that the great pyramid with the height of 146 meters was the highest building in the world for the last 4500 years and continued until the nineteenth century, The new theory proposed by French Professor Joseph Davidovits, the director of Geopolymer Institute asserts that the pyramids were built mainly of mud and that clay was used as a mean to move the stones on special railway. The research suggests that the mud and other materials were taken from the Nile`s soil and these materials were put together in tight stone molds .Then they were heated at a high temperature, leading to the interaction of these materials and forming them into stones-like volcanoes stones, which were formed millions of years ago. Scientist Davidovits affirms that the stones which were used to build the pyramids were mainly from limestone, clay and water. The tests made by using Nanotechnology (the branch of engineering that deals with things smaller than 100 nanometers) proved the existence of large quantities of water in these rocks; such quantities do not exist in natural stones. Furthermore,there is also consistency in the internal structure of stones which confirms that it is unreasonable that these stones were brought, then were carved in this way. The most realistic possibility is that they poured the clay in molds to make identical stones just as today as we pour plastic tools in templates so all the pieces are quite equal and similar. Electronic microscope was used to analyze samples of the pyramids stones. The result was closer to the opinion of Prof. Davidovits and the quartz crystals appeared clearly as a result of heating the mud. He stated that we don`t have in the nature like these stones which his confirms they were made by the Pharaohs. The analysis by Mini E scale indicated the presence of silicon dioxide too. This is another proof that the stones are not natural. http://kaheel7.com/userimages/pyramids_02.JPG The picture shows Professor Michel Barsoum standing next to the Great Pyramid. He stress that these stones were poured into molds of clay! This what he proved in his researches after results of long experiments that these stones are not natural. Pro. Michel Barsoum confirmed after Electronic microscope analysis that they are a result of a quick interaction between clay, limestone and water at high temperatures. Davidovits famous book entitled "Ils ont bati les pyramides" ,published in France in 2002, has resolved all problems and puzzles which were told about the way that the pyramids were built. Moreover, he put a simple geometric construction mechanism of mud. It was very convincing to many researchers in this field of science. Some researches emphasized that furnaces or stoves were used in ancient times to make ceramics and statues. The common use of fire was to build status of clay, mixed with metals and natural materials. After that, they lit a fire until the statue solidifies and takes the shape of real rocks. Many civilizations used the heated clay for making stones, statues and tools. All researches confirmed the this method used by the pharaohs in high buildings such as pyramids. They made wooden rails that went round the pyramid in a spiral way like the grapes tabernacle which grows around itself and ascends to the top. Other researches reach the same result Other analysis using X-ray proved existence of air bubbles in the samples taken from the pyramids which were formed during the pouring stones from mud and evaporation of water from mud. Furthermore, these bubbles do not exist in natural stones and this adds new evidence that the stones are made of clay and limestone not older than 4700 years. Mario Collepardi, an Italian Prof. studied the architecture of the pyramids, emphasized that the Pharaohs brought the limestone dust available a lot in their area, mixed it with normal soil. Then they added water from the river Nile and lit fire to a temperature up to 900 degrees Celsius. This heat gave the stone strength and a shape similar to natural rocks. The new idea does not cost a lot of effort because workers will not carry and raise any stones, all they have to do is to make the templates in which they pour mud and transfer mud from the ground and raise them in small containers. Each worker carries a container with mud to fill the templates. Then comes the process of lighting fire until the stone is shaped and stayed in place making sure by this way that there are no spaces between the stone and the other. Using this method helped in keeping the pyramids safe for thousands of years. http://kaheel7.com/userimages/pyramids_03.JPG The picture shows two adjacent stones of the pyramid's stones. We can notice the small oval cavity between them which is referred to by the arrow. It is a proof that the stones had been poured from mud in the rock template because this cavity was formed during casting stones, not as a result of erosion. It is originally out of these stones. The Scientific fact corresponds with the Quran After all these facts, we can reach to this result, which is: the technique used in the Age of the Pharaohs to build massive buildings such as pyramids, was mainly using the normal mud available near the River Nile. Then mixing it with water, placing it in templates and finally lighting the fire until it solidifies and stones are shaped the way we see today. This technique remained hidden as a secret until 1981, when that scientist put his theory. Then in 2006, other scientists proved the validity of the theory, beyond any doubt, by laboratory analysis, this technique was entirely unknown at the time of Quran. But what does the Quran say? Let`s my brothers and sisters consider and praise Allah, Almighty. After Pharaoh has become an oppressor and declared himself as a God of Egypt!! What did he say to his people, consider this:"Fir'aun (Pharaoh) said: "O chiefs! I know not that you have an il?h (a god) other than me."( AlQassas : 38). To that extreme extent, his challenge and arrogance reached. However, the Pharaoh did not stop, he wanted to challenge God`s power and build a high monument in order to climb it to see who is Allah Almighty. Therefore, the Pharaoh wanted to prove to his people, the ones who were like him, that Moses (peace be upon him) is not honest, and that the Pharaoh is the only God of the universe!! The pharaoh asked Haman, his deputy and partner, to build a huge monument to prove to the people that God does not exist. Here Pharaoh resorted to the technique used at that time in construction which was lighting fire on stones in order to pour the needed stones for the monument. The Pharaoh said after that: "So kindle for me (a fire), O H?m?n, to bake (bricks out of) clay, and set up for me a Sarh (a lofty tower, or palace) in order that I may look at (or look for) the Il?h (God) of M?s? (Moses); and verily, I think that he [M?s? (Moses)] is one of the liars."( AlQassas : 38). But what was the result? Look and think of the fate of the Pharaoh, Haman and their soldiers, the Almighty says: (And he and his hosts were arrogant in the land, without right, and they thought that they would never return to us * So We seized him and his hosts, and we threw them all into the sea (and drowned them). So behold (O Muhammad (peace be upon him)) what was the end of the Z?lim?n [wrong-doers, polytheists and those who disbelieved in the Oneness of their Lord (All?h), or rejected the advice of His Messenger M?s? (Moses) (peace be upon him]. .( AlQassas : 39-40). One might ask, is the monument the same as the Pyramid? We say it is not often. The monument is high as a tower or high lighthouse used in order to ascend to high altitude. Allah punished the Pharaoh and destroyed him. Allah Almighty also destroyed his monument to be a verse for the ones who comes after him. This monument that he build to challenge God was destroyed and we do not find it anywhere. The story of the Pharaoh and his black fate was told by Allah in this verse: "And we destroyed completely all the great works and buildings which Fir'aun (Pharaoh) and his people erected." ( Al Aaraf: 137 ). Already some scattered stones were found buried by sand during thousands of years. http://kaheel7.com/userimages/pyramids_04444.JPG The picture shows one of the three pyramids at Giza with the top still covered by a layer of mud. This layer is from the same stone used in building; which indicates that clay was fully used in building the pyramids. This " Pharaonic technology" was perhap a secret of the strength of the pharaonic civilization and kept on as a secret not mentioned even in manuscripts and inscriptions. Therefore, the Qur'an tells us about one of the hidden secrets that cannot be known only to Allah, and this is strong evidence that the Koran is the book of Allah! The miracle 1. This researcher and other dozens of researchers confirm that clay is the building material of the pyramids, and these buildings are the highest buildings, known from ancient history to the modern era. All these facts confirm that the Quran verse is true and consistent with science and one of the verses of the scientific miracles. 2. The technology of making stones from mud using heat, was not known at the time of revelation of the Qur'an and the Prophet Muhammad (peace be upon him) did not have any knowledge about the way of building the pyramids. Accordingly, this verse is to be considered a great scientific discovery as it linked between the mud and heat as a means of building in the Age of the Pharaohs. On the account of this fact, it led us to know that construction at that time was based on this method. This scientific fact has not been recognized only a few years ago by using very advanced technologies! 3. This miracle is an evidence of full consistency between the Qur'an and science and truthfulness of Allah Almighty when He said about his book: "Do they not then consider the Qur'an carefully? Had it been from other than All?h, they would surely have found therein many a contradiction."(Al Nisaa:82) The verse is a response to the atheists who claim that the Quran was written by Mohammed (peace be upon him), as how can he predict such a matter as the pyramids are far from his time and he never see it before! 4. he certain facts confirm that the Greatest Pyramid in Giza or the so-called pyramid of Cheops was the highest building on earth for 4500 years. It was the Pharaohs famous buildings or monuments. Allah destroyed the monuments and buildings built by the Pharaoh, who claimed divinity, whereas pyramids which were built by other Pharaohs were saved by Allah and kept as a witness of truthfulness of the Book of Allah, the Almighty! 5. In the verse "And we destroyed completely all the great works and buildings which Fir'aun (Pharaoh) and his people erected." Look at the word (erected) which indicates the technique used in ancient Egypt to put the rocks on top of each other! In Arabic language we find the word in "Al Qamoos Al Muhid" dictionary: (erected) build an arbor, (erected the grape arbor: raise the plant on wood, (erected) the house: build the house, put the roof. The result: the word (erected) refers to putting the wood to raise stones up. That what scientists and researchers say today: the Pharaohs used the wooden rails to raise mud by climbing in a spiral way around the building just like a pergola, which wrap around the pillar upon which it is based on in a spiral way. http://kaheel7.com/userimages/pyramids_05.JPG The drawing shows the way of building the pyramids through the placing wooden rails in a spiral way in order to transfer mud to make stones, wrapping around the pyramid up just like the bowers grape that wrap around and climb. Allah Almighty used the word (erected) to indicate the geometrical mechanism of constructing buildings and monuments. Mostly destroyed by Allah, leaving only the pyramids to be evidence of the truthfulness of the Qur'an 6. This miracle is an answer to those who claim that our greatest prophet (peace be upon him) took the Sciences and stories from the Bible or from Monk 'Buhira" or the priest "Waraqa bin Nawfal", because the technical construction by mud was not mentioned in the holly Book "AlTorah".On the contrary, any reader of "Torah" comes to a conclusion that stones were brought in from places far from the Pyramids and were natural stones not related to mud. This is what prevented some western scientists from recognition of this scientific discovery because it contradicts the holly book. 7. The research presented by Professor Davidovits invalidated all biblical (The holly book of Torah) claims that thousands of workers have worked for many years in these pyramids. It also invalidates the idea that stones were brought from distant places to build the pyramids. Therefore, we are looking at physical evidence that the Torah story contradicts science. It means that there is a big difference between the Holly book of Torah and scientific facts, and this shows that the current copy of Torah is written by humans, not from Allah Almighty. This fact was confirmed by the Quran: " Do they not then consider the Qur'?n carefully? Had it been from other than All?h, they would surely have found therein many a contradiction. (Al Nisaa: 82). It also indicates that the Quran is from Allah Almighty because it always matches science! Some questions to those who are skeptics of message of Islam 1. How did Prophet Mohammad peace be upon him know about the presence of high buildings Pharaohs build in their time? And if he has derived his information from the Torah, he would have come to the same information mentioned in the Torah. Where did he come up with the idea of architecture at all? 2. How was the Prophet Mohammad (peace be upon him) aware that technique of clay was used in construction in the Ages of Pharaohs? And what made him talk such historical and metaphysical issues as it would not provide anything to him in his massage. If the Prophet wrote the Quran (as some people claim) it would have been better that he tells them about Arab Legends which are the closet to people to accept his massage! 3. How did Prophet Mohammad (peace be upon him) know that the Pharaoh Claim divinity? And that he build monuments? And how did he learn that these monuments have been destroyed? And only the remains are left as an evidence of their existence in the past. Allah Almighty says: (And those are their dwellings, which have not been inhabited after them except a little. And verily! We have been the inheritors.)(Al Qassas :58) 4. Is it possible If Prophet Muhammad (peace be upon him) wrote the Quran to say such a thing: "Do they not travel in the land, and see what was the end of those before them? They were superior to them in strength, and they tilled the earth and populated it in greater numbers than these (pagans) have done: and there came to them their Messengers with clear proofs. Surely, All?h wronged them not, but they used to wrong themselves." (Al Room: 9) Allah Almighty makes contemplating through these pyramids and other ancient monuments remain a mean of realizing Allah`s power and fate of arrogant people who challenge Allah. These facts are physical proofs reflected in Allah`s holly book that shows the truthfulness of this book, one might say: The theory of building the pyramids by mud had not become a scientific fact, so how do you explain the Quran with such theory, and I say: this theory did not come from a nowhere but it was a result of scientific and laboratory analysis and does not contradict reality. It matches the Quran. However the science develops, it will not discover facts, and only the ones which match the Quran, in order these facts are means of seeing miracles of Allah in his book. He said: "We will show them Our Signs in the universe, and in their own selves, until it becomes manifest to them that this (the Qur'?n) is the truth. Is it not sufficient in regard to your Lord that He is a Witness over all things? (Fusselat: 53.). -------------------- References: 1- http://www.signonsandiego.com/uniontrib/20080508/news_1c08pyramid.html 2- http://www.signonsandiego.com/uniontrib/20080508/news_1c08pyramid.html 3- http://www.davidovits.info/78/davidovits-pyramid-theory-worldwide 4- http://www.geopolymer.org/news/cutting-edge-analysis-proves-davidovits'-pyramid-theory 5- http://www.timesonline.co.uk/article/0,,13509-2480751,00.html 6- http://www.nytimes.com/2006/12/01/science/01pyramid.html?ref=science 7- http://www.welt.de/data/2006/11/30/1129891.html 8- http://www.livescience.com/history/070518_bts_barsoum_pyramids.html 9- http://www.piramidasunca.ba/en/index.php/STONE-BLOCKS-FROM-THE-BOSNIAN-PYRAMIDS-ANALIZED-RESULT-ANCIENT-CONCRETE.html 10- http://dsc.discovery.com/news/2006/12/08/pyramids_arc.html?category=archaeology&guid=20061208120000 11- http://www.newscientist.com/channel/being-human/mg19225812.900-concrete-evidence-in-gizas-pyramids.html 12- Herodotus, The Histories, Oxford University Press, 1998 13- Davidovits, J. and Morris, M, The Pyramids, Dorset Press, 1988 14- Pyramids were built with concrete rather than rocks, scientists claim, http://www.timesonline.co.uk/tol/news/world/europe/article656117.ece, December 1, 2006 15- Concrete evidence in Giza's pyramids, http://www.newscientist.com/channel/being-human/mg19225812.900-concrete-evidence-in-gizas-pyramids.html 16- http://dsc.discovery.com/news/2006/12/08/pyramids_arc.html?category=archaeology&guid=20061208120000 17- http://www.materials.drexel.edu/Pyramids/ 18- MIT Class Explores Controversial Pyramid Theory With Scale Model, http://www.azom.com/default.asp, April 3rd,2008. 19- http://www.romanconcrete.com/index.htm 20- http://www.sciencedaily.com/releases/2006/12/061209122918.htm 21- The Enigma of the Construction of the Giza Pyramids Solved?, Scientific British Laboratory, Daresbury, SRS Synchrotron Radiation Source, 2004. 22- http://www.boston.com/news/local/articles/2008/04/22/a_new_angle_on_pyramids/?page=1 23- http://www.geopolymer.org/archaeology/pyramids/are-pyramids-made-out-of-concrete-1 24- http://www.geopolymer.org/archaeology/pyramids/pyramids-2-the-evidences 25- Barsoum, M. W., Ganguly, A. and Hug, G. Microstructural Evidence of Reconstituted Limestone Blocks in the Great Pyramids of Egypt, Journal of the American Ceramic Society 89 (12), 2006. http://kaheel7.com/eng/index.php/unseen-miracles/442-new-facts-about-the-pyramids-a-new-miracle-of-the-quran Thank you From breamoreboy at yahoo.co.uk Fri Jan 31 14:33:37 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Jan 2014 19:33:37 +0000 Subject: __init__ is the initialiser Message-ID: From http://docs.python.org/3/reference/datamodel.html#object.__init__ which states:- " Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class has an __init__() method, the derived class?s __init__() method, if any, must explicitly call it to ensure proper initialization of the base class part of the instance; for example: BaseClass.__init__(self, [args...]). As a special constraint on constructors, no value may be returned; doing so will cause a TypeError to be raised at runtime. " Should the wording of the above be changed to clearly reflect that we have an initialiser here and that __new__ is the constructor? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From __peter__ at web.de Fri Jan 31 14:51:06 2014 From: __peter__ at web.de (Peter Otten) Date: Fri, 31 Jan 2014 20:51:06 +0100 Subject: Python shell wont open idle or an exisiting py file References: <24EAA33389A147D8BC08B029E2209E16@UserPC> Message-ID: rpucci2 at cox.net wrote: > Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 > bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more > information. >>>> import idlelib.idle > Exception in Tkinter callback > Traceback (most recent call last): > File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ > return self.func(*args) > File "C:\Python33\lib\idlelib\EditorWindow.py", line 927, in > open_recent_file > self.io.open(editFile=fn_closure) > File "C:\Python33\lib\idlelib\IOBinding.py", line 183, in open > flist.open(filename) > File "C:\Python33\lib\idlelib\FileList.py", line 36, in open > edit = self.EditorWindow(self, filename, key) > File "C:\Python33\lib\idlelib\PyShell.py", line 126, in __init__ > EditorWindow.__init__(self, *args) > File "C:\Python33\lib\idlelib\EditorWindow.py", line 287, in __init__ > if io.loadfile(filename): > File "C:\Python33\lib\idlelib\IOBinding.py", line 242, in loadfile > self.updaterecentfileslist(filename) > File "C:\Python33\lib\idlelib\IOBinding.py", line 523, in > updaterecentfileslist > self.editwin.update_recent_files_list(filename) > File "C:\Python33\lib\idlelib\EditorWindow.py", line 915, in > update_recent_files_list > menu.delete(0, END) # clear, and rebuild: > File "C:\Python33\lib\tkinter\__init__.py", line 2778, in delete > if 'command' in self.entryconfig(i): > File "C:\Python33\lib\tkinter\__init__.py", line 2788, in entryconfigure > return self._configure(('entryconfigure', index), cnf, kw) > File "C:\Python33\lib\tkinter\__init__.py", line 1247, in _configure > self.tk.call(_flatten((self._w, cmd)))): > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 10: > invalid start byte > > This is the error message. What happens if you rename $HOME/.idlerc/recent-files.lst (to an arbitrary name, just to keep it around for further debugging if the file indeed triggers the problem)? From ned at nedbatchelder.com Fri Jan 31 14:52:15 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 31 Jan 2014 14:52:15 -0500 Subject: __init__ is the initialiser In-Reply-To: References: Message-ID: On 1/31/14 2:33 PM, Mark Lawrence wrote: > From http://docs.python.org/3/reference/datamodel.html#object.__init__ > which states:- > > " > Called when the instance is created. The arguments are those passed to > the class constructor expression. If a base class has an __init__() > method, the derived class?s __init__() method, if any, must explicitly > call it to ensure proper initialization of the base class part of the > instance; for example: BaseClass.__init__(self, [args...]). As a special > constraint on constructors, no value may be returned; doing so will > cause a TypeError to be raised at runtime. > " > > Should the wording of the above be changed to clearly reflect that we > have an initialiser here and that __new__ is the constructor? > I'm torn about that. The fact is, that for 95% of the reasons you want to say "constructor", the thing you're describing is __init__. Most classes have __init__, only very very few have __new__. The sense that __new__ is the constructor is the one borrowed from C++ and Java: you don't have an instance of your type until the constructor has returned. This is why __init__ is not a constructor: the self passed into __init__ is already an object of your class. But that distinction isn't useful in most programs. The thing most people mean by "constructor" is "the method that gets invoked right at the beginning of the object's lifetime, where you can add code to initialize it properly." That describes __init__. Insisting that __init__ is not a constructor makes about as much sense as insisting that "Python has no variables" just because they work differently than in C. Python has variables, and it has constructors. We don't have to be tied to C++ semantics of the word "constructor" any more than we have to tied to its semantics of the word "variable" or "for". Why can't we call __init__ the constructor and __new__ the allocator? -- Ned Batchelder, http://nedbatchelder.com From breamoreboy at yahoo.co.uk Fri Jan 31 15:17:21 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Jan 2014 20:17:21 +0000 Subject: __init__ is the initialiser In-Reply-To: References: Message-ID: On 31/01/2014 19:52, Ned Batchelder wrote: > On 1/31/14 2:33 PM, Mark Lawrence wrote: >> From http://docs.python.org/3/reference/datamodel.html#object.__init__ >> which states:- >> >> " >> Called when the instance is created. The arguments are those passed to >> the class constructor expression. If a base class has an __init__() >> method, the derived class?s __init__() method, if any, must explicitly >> call it to ensure proper initialization of the base class part of the >> instance; for example: BaseClass.__init__(self, [args...]). As a special >> constraint on constructors, no value may be returned; doing so will >> cause a TypeError to be raised at runtime. >> " >> >> Should the wording of the above be changed to clearly reflect that we >> have an initialiser here and that __new__ is the constructor? >> > > I'm torn about that. The fact is, that for 95% of the reasons you want > to say "constructor", the thing you're describing is __init__. Most > classes have __init__, only very very few have __new__. > > The sense that __new__ is the constructor is the one borrowed from C++ > and Java: you don't have an instance of your type until the constructor > has returned. This is why __init__ is not a constructor: the self > passed into __init__ is already an object of your class. > > But that distinction isn't useful in most programs. The thing most > people mean by "constructor" is "the method that gets invoked right at > the beginning of the object's lifetime, where you can add code to > initialize it properly." That describes __init__. > > Insisting that __init__ is not a constructor makes about as much sense > as insisting that "Python has no variables" just because they work > differently than in C. Python has variables, and it has constructors. > We don't have to be tied to C++ semantics of the word "constructor" any > more than we have to tied to its semantics of the word "variable" or "for". > > Why can't we call __init__ the constructor and __new__ the allocator? > To clarify the situation I think we should call __new__ "the thing that instanciates an instance of a class" and __init__ "the thing that isn't actually needed as you can add attributes to an instance anywhere in your code" :) -- 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 Fri Jan 31 15:28:28 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 07:28:28 +1100 Subject: __init__ is the initialiser In-Reply-To: References: Message-ID: On Sat, Feb 1, 2014 at 7:17 AM, Mark Lawrence wrote: > To clarify the situation I think we should call __new__ "the thing that > instanciates an instance of a class" and __init__ "the thing that isn't > actually needed as you can add attributes to an instance anywhere in your > code" :) With a typical class layout, you have something like this: class Foo: def __init__(self, some, other, args): self.stuff=some+other, other+args def roll(self, arg): ret,keep=self.stuff self.stuff=keep,arg return ret This has an invariant: it always has a two-item tuple in self.stuff. The job of __init__ is to get the class invariants straight. Before it's called, you can't safely call anything else, because all those other parts of the class are written on the assumption that __init__ will be called first. This is a fairly common way of laying out a class, and it fits pretty much any language. So what is __new__ and what is __init__? The former is the thing you rarely need, and when you do, you can go fiddle with the docs if necessary; the latter is the most obvious place to guarantee invariants. Whatever you call them, they'll both be called before pretty much anything else in the class is, barring weirdnesses, which is something you cannot depend on with other methods. Yes, you can add attributes anywhere, but you shouldn't need this: f = Foo() f.setup(12,23,34) Instead, use this: f = Foo(12,23,34) And then there's no way to accidentally muck something up and have a Foo that breaks its invariants. ChrisA From ethan at stoneleaf.us Fri Jan 31 14:43:32 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 11:43:32 -0800 Subject: __init__ is the initialiser In-Reply-To: References: Message-ID: <52EBFCE4.8050704@stoneleaf.us> On 01/31/2014 11:33 AM, Mark Lawrence wrote: > From http://docs.python.org/3/reference/datamodel.html#object.__init__ which states:- > > " > Called when the instance is created. The arguments are those passed to the class constructor expression. If a base class > has an __init__() method, the derived class?s __init__() method, if any, must explicitly call it to ensure proper > initialization of the base class part of the instance; for example: BaseClass.__init__(self, [args...]). As a special > constraint on constructors, no value may be returned; doing so will cause a TypeError to be raised at runtime. > " > > Should the wording of the above be changed to clearly reflect that we have an initialiser here and that __new__ is the > constructor? I would say yes. Go ahead and create an issue if one doesn't already exist. Thanks. -- ~Ethan~ From python at mrabarnett.plus.com Fri Jan 31 15:48:10 2014 From: python at mrabarnett.plus.com (MRAB) Date: Fri, 31 Jan 2014 20:48:10 +0000 Subject: __init__ is the initialiser In-Reply-To: References: Message-ID: <52EC0C0A.7010508@mrabarnett.plus.com> On 2014-01-31 19:52, Ned Batchelder wrote: > On 1/31/14 2:33 PM, Mark Lawrence wrote: >> From http://docs.python.org/3/reference/datamodel.html#object.__init__ >> which states:- >> >> " >> Called when the instance is created. The arguments are those passed to >> the class constructor expression. If a base class has an __init__() >> method, the derived class?s __init__() method, if any, must explicitly > >> call it to ensure proper initialization of the base class part of the >> instance; for example: BaseClass.__init__(self, [args...]). As a special >> constraint on constructors, no value may be returned; doing so will >> cause a TypeError to be raised at runtime. >> " >> >> Should the wording of the above be changed to clearly reflect that we >> have an initialiser here and that __new__ is the constructor? >> > > I'm torn about that. The fact is, that for 95% of the reasons you want > to say "constructor", the thing you're describing is __init__. Most > classes have __init__, only very very few have __new__. > > The sense that __new__ is the constructor is the one borrowed from C++ > and Java: you don't have an instance of your type until the constructor > has returned. This is why __init__ is not a constructor: the self > passed into __init__ is already an object of your class. > > But that distinction isn't useful in most programs. The thing most > people mean by "constructor" is "the method that gets invoked right at > the beginning of the object's lifetime, where you can add code to > initialize it properly." That describes __init__. > > Insisting that __init__ is not a constructor makes about as much sense > as insisting that "Python has no variables" just because they work > differently than in C. Python has variables, and it has constructors. > We don't have to be tied to C++ semantics of the word "constructor" any > more than we have to tied to its semantics of the word "variable" or "for". > > Why can't we call __init__ the constructor and __new__ the allocator? > The advantage of calling it the "initialiser" is that it explains why it's called "__init__". From ethan at stoneleaf.us Fri Jan 31 15:41:42 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 12:41:42 -0800 Subject: __init__ is the initialiser In-Reply-To: References: Message-ID: <52EC0A86.7060102@stoneleaf.us> On 01/31/2014 11:52 AM, Ned Batchelder wrote: > On 1/31/14 2:33 PM, Mark Lawrence wrote: >> From http://docs.python.org/3/reference/datamodel.html#object.__init__ >> which states:- >> >> " >> Called when the instance is created. The arguments are those passed to >> the class constructor expression. If a base class has an __init__() >> method, the derived class?s __init__() method, if any, must explicitly >> call it to ensure proper initialization of the base class part of the >> instance; for example: BaseClass.__init__(self, [args...]). As a special >> constraint on constructors, no value may be returned; doing so will >> cause a TypeError to be raised at runtime. >> " >> >> Should the wording of the above be changed to clearly reflect that we >> have an initialiser here and that __new__ is the constructor? >> > > I'm torn about that. The fact is, that for 95% of the reasons you want to say "constructor", the thing you're > describing is __init__. Most classes have __init__, only very very few have __new__. My problem is with the first sentence, as it makes it sound like there is no __new__ and everything you need is in __init__. Figuring out how __new__ and __init__ were tied together took a long time because of that. > Why can't we call __init__ the constructor and __new__ the allocator? I'm not so much concerned about the names (although I like those names ;) as I am about the prose. If that first line was something like: Called after the instance has been created but before it is returned. I think that would be much clearer. -- ~Ethan~ From ethan at stoneleaf.us Fri Jan 31 15:57:32 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 12:57:32 -0800 Subject: __init__ is the initialiser In-Reply-To: <52EC0C0A.7010508@mrabarnett.plus.com> References: <52EC0C0A.7010508@mrabarnett.plus.com> Message-ID: <52EC0E3C.5070900@stoneleaf.us> On 01/31/2014 12:48 PM, MRAB wrote: > On 2014-01-31 19:52, Ned Batchelder wrote: >> >> Why can't we call __init__ the constructor and __new__ the allocator? > > The advantage of calling it the "initialiser" is that it explains why > it's called "__init__". Hm, yes, good point. Also, __init__ initializes so it is a good choice. Ignore the names comment in my previous post. -- ~Ethan~ From inpost at gmail.com Fri Jan 31 13:33:53 2014 From: inpost at gmail.com (e-letter) Date: Fri, 31 Jan 2014 18:33:53 +0000 Subject: scipy error invalid path Message-ID: Readers, Used the community edition service of activepython web site to install python27. Within the 'bin' directory, received the following error: $ ./easy_install-2.7 scipy Searching for scipy Reading https://pypi.python.org/simple/scipy/ Best match: scipy 0.13.2 Downloading https://pypi.python.org/packages/source/s/scipy/scipy-0.13.2.zip#md5=9befa30e546fba762a0c1695a509f731 Processing scipy-0.13.2.zip Writing /tmp/easy_install-Ef9P39/scipy-0.13.2/setup.cfg Running scipy-0.13.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-Ef9P39/scipy-0.13.2/egg-dist-tmp-6SO8yB /path/to/.local/lib/python2.7/site-packages/numpy/distutils/system_info.py:564: UserWarning: Specified path /home/apy/atlas/lib is invalid. warnings.warn('Specified path %s is invalid.' % d) There is no directory in the host computer with this home directory name. How to solve please? From ned at nedbatchelder.com Fri Jan 31 17:44:30 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 31 Jan 2014 17:44:30 -0500 Subject: __init__ is the initialiser In-Reply-To: <52EC0E3C.5070900@stoneleaf.us> References: <52EC0C0A.7010508@mrabarnett.plus.com> <52EC0E3C.5070900@stoneleaf.us> Message-ID: On 1/31/14 3:57 PM, Ethan Furman wrote: > On 01/31/2014 12:48 PM, MRAB wrote: >> On 2014-01-31 19:52, Ned Batchelder wrote: >>> >>> Why can't we call __init__ the constructor and __new__ the allocator? >> >> The advantage of calling it the "initialiser" is that it explains why >> it's called "__init__". > > Hm, yes, good point. Also, __init__ initializes so it is a good > choice. Ignore the names comment in my previous post. These days, when teaching Python, I'd say, "__init__ is an initializer, or constructor." -- Ned Batchelder, http://nedbatchelder.com From cs at zip.com.au Fri Jan 31 17:45:07 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 1 Feb 2014 09:45:07 +1100 Subject: __init__ is the initialiser In-Reply-To: <52EC0E3C.5070900@stoneleaf.us> References: <52EC0E3C.5070900@stoneleaf.us> Message-ID: <20140131224507.GA5454@cskk.homeip.net> On 31Jan2014 12:57, Ethan Furman wrote: > On 01/31/2014 12:48 PM, MRAB wrote: > >On 2014-01-31 19:52, Ned Batchelder wrote: > >>Why can't we call __init__ the constructor and __new__ the allocator? > > > >The advantage of calling it the "initialiser" is that it explains why > >it's called "__init__". > > Hm, yes, good point. Also, __init__ initializes so it is a good choice. Ignore the names comment in my previous post. On this basis, would it suffice to change the opening sentence from: Called when the instance is created. to Called to initialise a new instance immediately after creation. ? This seems succinct while getting both "initialise" and "new" into the line, which makes it clear that there is a separate and earlier "new" step. (Conveniently overridable with __new__ :-) Cheers, -- Cameron Simpson Don't have awk? Use this simple sh emulation: #!/bin/sh echo 'Awk bailing out!' >&2 exit 2 - Tom Horsley From breamoreboy at yahoo.co.uk Fri Jan 31 17:46:22 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Fri, 31 Jan 2014 22:46:22 +0000 Subject: scipy error invalid path In-Reply-To: References: Message-ID: On 31/01/2014 18:33, e-letter wrote: > Readers, > > Used the community edition service of activepython web site to install > python27. Within the 'bin' directory, received the following error: > > $ ./easy_install-2.7 scipy > Searching for scipy > Reading https://pypi.python.org/simple/scipy/ > Best match: scipy 0.13.2 > Downloading https://pypi.python.org/packages/source/s/scipy/scipy-0.13.2.zip#md5=9befa30e546fba762a0c1695a509f731 > Processing scipy-0.13.2.zip > Writing /tmp/easy_install-Ef9P39/scipy-0.13.2/setup.cfg > Running scipy-0.13.2/setup.py -q bdist_egg --dist-dir > /tmp/easy_install-Ef9P39/scipy-0.13.2/egg-dist-tmp-6SO8yB > /path/to/.local/lib/python2.7/site-packages/numpy/distutils/system_info.py:564: > UserWarning: Specified path /home/apy/atlas/lib is invalid. > warnings.warn('Specified path %s is invalid.' % d) > > There is no directory in the host computer with this home directory > name. How to solve please? > This is a warning and not an error so I'd assume that scipy has been successfully installed. Have you checked this? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence From ben+python at benfinney.id.au Fri Jan 31 18:05:07 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Feb 2014 10:05:07 +1100 Subject: __init__ is the initialiser References: Message-ID: <858utviwgs.fsf@benfinney.id.au> Ned Batchelder writes: > On 1/31/14 2:33 PM, Mark Lawrence wrote: > > From http://docs.python.org/3/reference/datamodel.html#object.__init__ > > [?] > > Should the wording of the above be changed to clearly reflect that > > we have an initialiser here and that __new__ is the constructor? > > I'm torn about that. The fact is, that for 95% of the reasons you want > to say "constructor", the thing you're describing is __init__. I assume the ?95%? figure is made up. Whose wants are you divining, here? > Most classes have __init__, only very very few have __new__. Yes, this is true, and I agree it is a major factor in the confusion: the term ?constructor? is commonly encountered in discussion of classes, and in Python, the method ?__init__? is commonly encountered. It is a natural mistake to think Python names its constructor ?__init__?, since most classes don't define ?__new__?. > The sense that __new__ is the constructor is the one borrowed from C++ > and Java: you don't have an instance of your type until the > constructor has returned. This is why __init__ is not a constructor: > the self passed into __init__ is already an object of your class. A more salient reason, I think, is that ?constructor? entails that the function will return the instance. This is another important reason why ?__init__? is not a constructor: it does not return the instance. > But that distinction isn't useful in most programs. The thing most > people mean by "constructor" is "the method that gets invoked right at > the beginning of the object's lifetime, where you can add code to > initialize it properly." That describes __init__. Here we disagree. I think the meaning ?? and that returns the new instance? is entailed in the meaning of ?constructor?. > Why can't we call __init__ the constructor and __new__ the allocator? Because those terms already have meanings, and ?__new__? fits the meaning of ?constructor? better. -- \ ?This world in arms is not spending money alone. It is spending | `\ the sweat of its laborers, the genius of its scientists, the | _o__) hopes of its children.? ?Dwight Eisenhower, 1953-04-16 | Ben Finney From cs at zip.com.au Fri Jan 31 18:18:29 2014 From: cs at zip.com.au (Cameron Simpson) Date: Sat, 1 Feb 2014 10:18:29 +1100 Subject: __init__ is the initialiser In-Reply-To: <858utviwgs.fsf@benfinney.id.au> References: <858utviwgs.fsf@benfinney.id.au> Message-ID: <20140131231829.GA39751@cskk.homeip.net> On 01Feb2014 10:05, Ben Finney wrote: > Ned Batchelder writes: > > Why can't we call __init__ the constructor and __new__ the allocator? > > Because those terms already have meanings, and ?__new__? fits the > meaning of ?constructor? better. +1 on not giving new conflicting meanings to terms already well defined in practice. Better just to make in clear in the __init__ docs that there is a separate construction step. -- Cameron Simpson On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Babbage From ned at nedbatchelder.com Fri Jan 31 18:43:16 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 31 Jan 2014 18:43:16 -0500 Subject: __init__ is the initialiser In-Reply-To: <858utviwgs.fsf@benfinney.id.au> References: <858utviwgs.fsf@benfinney.id.au> Message-ID: On 1/31/14 6:05 PM, Ben Finney wrote: > Ned Batchelder writes: > >> On 1/31/14 2:33 PM, Mark Lawrence wrote: >>> From http://docs.python.org/3/reference/datamodel.html#object.__init__ >>> [?] >>> Should the wording of the above be changed to clearly reflect that >>> we have an initialiser here and that __new__ is the constructor? >> >> I'm torn about that. The fact is, that for 95% of the reasons you want >> to say "constructor", the thing you're describing is __init__. > > I assume the ?95%? figure is made up. Whose wants are you divining, here? > >> Most classes have __init__, only very very few have __new__. > > Yes, this is true, and I agree it is a major factor in the confusion: > the term ?constructor? is commonly encountered in discussion of classes, > and in Python, the method ?__init__? is commonly encountered. It is a > natural mistake to think Python names its constructor ?__init__?, since > most classes don't define ?__new__?. > >> The sense that __new__ is the constructor is the one borrowed from C++ >> and Java: you don't have an instance of your type until the >> constructor has returned. This is why __init__ is not a constructor: >> the self passed into __init__ is already an object of your class. > > A more salient reason, I think, is that ?constructor? entails that the > function will return the instance. This is another important reason why > ?__init__? is not a constructor: it does not return the instance. > >> But that distinction isn't useful in most programs. The thing most >> people mean by "constructor" is "the method that gets invoked right at >> the beginning of the object's lifetime, where you can add code to >> initialize it properly." That describes __init__. > > Here we disagree. I think the meaning ?? and that returns the new > instance? is entailed in the meaning of ?constructor?. > >> Why can't we call __init__ the constructor and __new__ the allocator? > > Because those terms already have meanings, and ?__new__? fits the > meaning of ?constructor? better. > You say these terms already have meanings, and that constructor means a function that returns the new instance. Then your word "constructor" isn't the same as C++'s word "constructor"? Those don't return the instance. Neither do Java constructors. In terms of the code developers actually write in __init__, it looks an awful lot like a C++ or Java constructor, and serves precisely the same purpose. The fact that the underlying mechanisms are slightly different seems like an odd reason to force a difference in names. My point is that often the same word in two different programming languages won't have a precise mapping. "Variable" is a common example. Python ints are different than C ints, yet we call them both ints. C and Java and Python all have "for" statements. We didn't insist on a different keyword just because the semantics are different. There are enormous differences between Python functions, C functions, Java functions, and Haskell functions. But they serve similar roles in the programmer's toolkit, and we use the same name for them. I'm not hoping to change any official terminology. I just think that calling __init__ anything other than a constructor is confusing pedantry. It is a constructor, and Python constructors work differently than those in C++ and Java. -- Ned Batchelder, http://nedbatchelder.com From ben+python at benfinney.id.au Fri Jan 31 18:47:42 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Feb 2014 10:47:42 +1100 Subject: __init__ is the initialiser References: <52EC0E3C.5070900@stoneleaf.us> <20140131224507.GA5454@cskk.homeip.net> Message-ID: <85ob2rhfxd.fsf@benfinney.id.au> Cameron Simpson writes: > > On 01/31/2014 12:48 PM, MRAB wrote: > > >The advantage of calling it the "initialiser" is that it explains > > >why it's called "__init__". > > On this basis, would it suffice to change the opening sentence from: > Called when the instance is created. > > to > Called to initialise a new instance immediately after creation. > > ? > > This seems succinct while getting both "initialise" and "new" into the > line, which makes it clear that there is a separate and earlier "new" > step. (Conveniently overridable with __new__ :-) It leaves a naive reader (who isn't yet familiar with the convention for special names in Python) with the false implication that ?__init__? is usually called *manually*. I would prefer it to be clear that ?__init__? is called automatically, *during* the constructor's operation. So, instead of: Called when the instance is created. I suggest: Called automatically by the constructor ?__new__? during instance creation, to initialise the new instance. -- \ ?Why doesn't Python warn that it's not 100% perfect? Are people | `\ just supposed to ?know? this, magically?? ?Mitya Sirenef, | _o__) comp.lang.python, 2012-12-27 | Ben Finney From ben+python at benfinney.id.au Fri Jan 31 18:59:37 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Feb 2014 10:59:37 +1100 Subject: __init__ is the initialiser References: <858utviwgs.fsf@benfinney.id.au> Message-ID: <85k3dfhfdi.fsf@benfinney.id.au> Ned Batchelder writes: > On 1/31/14 6:05 PM, Ben Finney wrote: > > Here we disagree. I think the meaning ?? and that returns the new > > instance? is entailed in the meaning of ?constructor?. > > [?] > > You say these terms already have meanings, and that constructor means > a function that returns the new instance. Then your word "constructor" > isn't the same as C++'s word "constructor"? Those don't return the > instance. Neither do Java constructors. In terms of the code > developers actually write in __init__, it looks an awful lot like a > C++ or Java constructor, and serves precisely the same purpose. These are good points, thanks for raising them. -- \ Lucifer: ?Just sign the Contract, sir, and the Piano is yours.? | `\ Ray: ?Sheesh! This is long! Mind if I sign it now and read it | _o__) later?? ?http://www.achewood.com/ | Ben Finney From ethan at stoneleaf.us Fri Jan 31 19:13:52 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 16:13:52 -0800 Subject: __init__ is the initialiser In-Reply-To: References: <858utviwgs.fsf@benfinney.id.au> Message-ID: <52EC3C40.7080402@stoneleaf.us> On 01/31/2014 03:43 PM, Ned Batchelder wrote: > On 1/31/14 6:05 PM, Ben Finney wrote: >> Ned Batchelder writes: > > I'm not hoping to change any official terminology. I just think that calling __init__ anything other than a constructor > is confusing pedantry. It is a constructor, and Python constructors work differently than those in C++ and Java. And I would say the opposite. __init__ is not creating anything, which is what I think of when speaking of a constructor. I'd be willing to yield the point that Python has a pair of methods that make up the constructor (an allocator and an initializer), but I found calling __init__ the constructor very confusing. -- ~Ethan~ From ethan at stoneleaf.us Fri Jan 31 19:13:08 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 16:13:08 -0800 Subject: __init__ is the initialiser In-Reply-To: <85ob2rhfxd.fsf@benfinney.id.au> References: <52EC0E3C.5070900@stoneleaf.us> <20140131224507.GA5454@cskk.homeip.net> <85ob2rhfxd.fsf@benfinney.id.au> Message-ID: <52EC3C14.8080806@stoneleaf.us> On 01/31/2014 03:47 PM, Ben Finney wrote: > > I would prefer it to be clear that ?__init__? is called automatically, > *during* the constructor's operation. So, instead of: > > Called when the instance is created. > > I suggest: > > Called automatically by the constructor ?__new__? during instance > creation, to initialise the new instance. But __new__ does not call __init__, type does [1]. -- ~Ethan~ [1] And I seem to think pickle does, too, but I'm not sure. From breamoreboy at yahoo.co.uk Fri Jan 31 19:51:28 2014 From: breamoreboy at yahoo.co.uk (Mark Lawrence) Date: Sat, 01 Feb 2014 00:51:28 +0000 Subject: __init__ is the initialiser In-Reply-To: <52EC3C40.7080402@stoneleaf.us> References: <858utviwgs.fsf@benfinney.id.au> <52EC3C40.7080402@stoneleaf.us> Message-ID: On 01/02/2014 00:13, Ethan Furman wrote: > On 01/31/2014 03:43 PM, Ned Batchelder wrote: >> On 1/31/14 6:05 PM, Ben Finney wrote: >>> Ned Batchelder writes: >> >> I'm not hoping to change any official terminology. I just think that >> calling __init__ anything other than a constructor >> is confusing pedantry. It is a constructor, and Python constructors >> work differently than those in C++ and Java. > > And I would say the opposite. __init__ is not creating anything, which > is what I think of when speaking of a constructor. I'd be willing to > yield the point that Python has a pair of methods that make up the > constructor (an allocator and an initializer), but I found calling > __init__ the constructor very confusing. > > -- > ~Ethan~ Here's what help says. Python 3.4.0b2 (v3.4.0b2:ba32913eb13e, Jan 5 2014, 16:23:43) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> help(object.__new__) Help on built-in function __new__: __new__(...) T.__new__(S, ...) -> a new object with type S, a subtype of T >>> help(object.__init__) Help on wrapper_descriptor: __init__(...) x.__init__(...) initializes x; see help(type(x)) for signature -- 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 Fri Jan 31 19:57:32 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 11:57:32 +1100 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: On Sat, Feb 1, 2014 at 11:42 AM, Scott W Dunning wrote: > Also, any help on how to get the hours and seconds into double digits that would be cool too. 00:00:00 Once you can divide the number of seconds into hours, minutes, and seconds, you can format them like this: time = "%02d:%02d:%02d" % (hours, minutes, seconds) I'll give you that one for free because I don't think it's particularly critical to your course, but it will look better that way :) Look up the string formatting features of Python in the docs. ChrisA From roy at panix.com Fri Jan 31 20:10:46 2014 From: roy at panix.com (Roy Smith) Date: Fri, 31 Jan 2014 20:10:46 -0500 Subject: __init__ is the initialiser References: <858utviwgs.fsf@benfinney.id.au> Message-ID: In article , Ethan Furman wrote: > I found calling __init__ the constructor very confusing. I've heard many people say this, and it's always sort of befuddled me. In C++, a constructor is really an initializer too. By the time C++'s Foo::Foo() or Python's Foo.__init__() get called, memory has already been allocated, so I would say the object has been constructed. Yet, C++ people are perfectly happy calling this "thing that takes some allocated hunk of memory and sets its attributes to useful values" a constructor[1], and Python people are not. [1] Well, they really call it a ctor, but I chalk that up to the same sort of silliness that makes pythonistas pronounce "__" as "dunder" :-) From rosuav at gmail.com Fri Jan 31 20:34:29 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 12:34:29 +1100 Subject: Help with some python homework... In-Reply-To: <2B1086E7-5E5F-4227-8F9E-92A37D2DE1D2@cox.net> References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> <2B1086E7-5E5F-4227-8F9E-92A37D2DE1D2@cox.net> Message-ID: On Sat, Feb 1, 2014 at 12:14 PM, Scott W Dunning wrote: > Thanks Chris! > > Also, before I forget what is the difference between / and //? I remember something about floor division? In Python 2, the / operator by default is "floor division". 5 divided by 2 is 2. When you divide two integers, you get back an integer. In Python 3, the / operator is "sorta kinda real number division", in that it does what you're more likely to expect: 5 divided by 2 is 2.5. You'll get back a floating point number instead of an integer. You can ask Python 2 to give you the Python 3 behaviour by putting this at the top of your script: from __future__ import division Regardless of whether you're on Py2 without the future directive, Py2 with the future directive, or Py3, you can use the // operator to get the behaviour of floor division. Since that behaviour is exactly what you want when you're working with modulo, it may be worth getting into the habit of using it. But then again, it may not. You'll have other changes to make when you move to Python 3, so you can just figure it out then. (Incidentally, if there's nothing keeping you on Python 2, you may want to move sooner rather than later. There are lots of awesome features in Python 3 that will never be added to Python 2.) > Also, I think I found out through a little trial and error that I had two different hours, mins, and sec so I had to use one uppercase and one lower case. Is that frowned upon? And should I have come up with a different name instead? > > SECONDS = 1 > MINUTES = 60 * SECONDS > HOURS = 60 * MINUTES Well, an ALL_UPPERCASE_NAME is generally a constant, which is how you're using them here. So in this specific instance, what you've done is fine. But don't treat this as a way to get yourself a few more variable names; if you'd done these ones in lower case and the other ones in caps, it would have been extremely confusing to an experienced Python programmer. For some style tips that a lot of Python programs follow, check out PEP 8: http://www.python.org/dev/peps/pep-0008/ Formally, this is the style guide for the Python standard library, but it's a fairly sensible set of rules, and a lot of projects follow them. Some of the rules are widely adopted elsewhere, others (like the insistence on spaces rather than tabs - everyone agrees that you should use one OR the other, but plenty of people advocate tabs above spaces) less so; take your pick which bits you follow, but all of it is worth a read. > time_left_house = 6 * HOURS + 52 * MINUTES > > miles_run_easy_pace = 2 * (8 * MINUTES + 15 * SECONDS) > > miles_run_fast_pace = 3 * (7 * MINUTES + 12 * SECONDS) > > time_returned_home = miles_run_easy_pace + miles_run_fast_pace + time_left_house > > hours = time_returned_home // HOURS > part_hour = time_returned_home % HOURS > minutes = part_hour // MINUTES > seconds = part_hour % MINUTES > > print "Time returned home:", hours,":", minutes,":", seconds,?am" Looks fairly good. This is where you could use the formatting notation I gave you above: print "Time returned home: %02d:%02d:%02d am" % (hours, minutes, seconds) And then, since you're using print with a single string argument, get in the habit of putting parentheses around it: print("Time returned home: %02d:%02d:%02d am" % (hours, minutes, seconds)) This syntax (one string argument, parens around it) is common to both Python 2's print statement and Python 3's print function (as with division, you can ask Python 2 to give you a print function if you wish). So, is the program giving you the result you expect? That's really the key. If it is, then you (probably!) have a working program! ChrisA From python at mrabarnett.plus.com Fri Jan 31 20:41:26 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 01 Feb 2014 01:41:26 +0000 Subject: __init__ is the initialiser In-Reply-To: References: <858utviwgs.fsf@benfinney.id.au> Message-ID: <52EC50C6.1030608@mrabarnett.plus.com> On 2014-02-01 01:10, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> I found calling __init__ the constructor very confusing. > > I've heard many people say this, and it's always sort of befuddled me. > > In C++, a constructor is really an initializer too. By the time C++'s > Foo::Foo() or Python's Foo.__init__() get called, memory has already > been allocated, so I would say the object has been constructed. Yet, > C++ people are perfectly happy calling this "thing that takes some > allocated hunk of memory and sets its attributes to useful values" a > constructor[1], and Python people are not. > You could argue that construction is not complete until the instance has been initialised. In the case of C++, all you have is the initialiser, so doesn't really matter, but Python has __new__ and __init__, so it _does_ matter. > [1] Well, they really call it a ctor, but I chalk that up to the same > sort of silliness that makes pythonistas pronounce "__" as "dunder" :-) > From tjreedy at udel.edu Fri Jan 31 20:45:49 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 20:45:49 -0500 Subject: Python shell wont open idle or an exisiting py file In-Reply-To: References: <24EAA33389A147D8BC08B029E2209E16@UserPC> Message-ID: On 1/31/2014 2:51 PM, Peter Otten wrote: > rpucci2 at cox.net wrote: > >> Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:18:40) [MSC v.1600 32 >> bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more >> information. >>>>> import idlelib.idle >> Exception in Tkinter callback >> Traceback (most recent call last): >> File "C:\Python33\lib\tkinter\__init__.py", line 1475, in __call__ >> return self.func(*args) >> File "C:\Python33\lib\idlelib\EditorWindow.py", line 927, in >> open_recent_file >> self.io.open(editFile=fn_closure) >> File "C:\Python33\lib\idlelib\IOBinding.py", line 183, in open >> flist.open(filename) >> File "C:\Python33\lib\idlelib\FileList.py", line 36, in open >> edit = self.EditorWindow(self, filename, key) >> File "C:\Python33\lib\idlelib\PyShell.py", line 126, in __init__ >> EditorWindow.__init__(self, *args) >> File "C:\Python33\lib\idlelib\EditorWindow.py", line 287, in __init__ >> if io.loadfile(filename): >> File "C:\Python33\lib\idlelib\IOBinding.py", line 242, in loadfile >> self.updaterecentfileslist(filename) >> File "C:\Python33\lib\idlelib\IOBinding.py", line 523, in >> updaterecentfileslist >> self.editwin.update_recent_files_list(filename) >> File "C:\Python33\lib\idlelib\EditorWindow.py", line 915, in >> update_recent_files_list >> menu.delete(0, END) # clear, and rebuild: >> File "C:\Python33\lib\tkinter\__init__.py", line 2778, in delete >> if 'command' in self.entryconfig(i): >> File "C:\Python33\lib\tkinter\__init__.py", line 2788, in entryconfigure >> return self._configure(('entryconfigure', index), cnf, kw) >> File "C:\Python33\lib\tkinter\__init__.py", line 1247, in _configure >> self.tk.call(_flatten((self._w, cmd)))): >> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 10: >> invalid start byte >> This is the error message. > What happens if you rename > > $HOME/.idlerc/recent-files.lst For me, on Win7, $HOME is C:/Users/Terry > (to an arbitrary name, just to keep it around for further debugging if the > file indeed triggers the problem)? Or try the following in the console with the file name changed, but without the first line wrapped with open('C:/Users/Terry/.idlerc/recent-files.lst', encoding='utf-8') as f: for n, line in enumerate(f): print(n, line, end='') There was a (non-obvious) bug, recently fixed in http://bugs.python.org/issue19020 which caused this seemingly bogus error message when an entry in recent-files.list contained a directory or file name beginning with '0'. H:\HP_Documents\0PythonWork\AirplaneKinematics\accel2.py caused this message UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 14: invalid start byte If your file has such a line, either delete it or upgrade to 3.3.4 (rc1, final soon) or 3.4.0 (rc1 due soon). -- Terry Jan Reedy From rosuav at gmail.com Fri Jan 31 20:52:39 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 12:52:39 +1100 Subject: Python shell wont open idle or an exisiting py file In-Reply-To: References: <24EAA33389A147D8BC08B029E2209E16@UserPC> Message-ID: On Sat, Feb 1, 2014 at 12:45 PM, Terry Reedy wrote: > H:\HP_Documents\0PythonWork\AirplaneKinematics\accel2.py > caused this message > UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 14: > invalid start byte So... something's interpreting \0 as codepoint U+0000 (which it shouldn't), storing that in "UTF-8" as 0xC0 0x80 (which it shouldn't), and then giving it to Python to decode. That's a weird little combination bug right there. ChrisA From roy at panix.com Fri Jan 31 20:53:42 2014 From: roy at panix.com (Roy Smith) Date: Fri, 31 Jan 2014 20:53:42 -0500 Subject: __init__ is the initialiser References: <858utviwgs.fsf@benfinney.id.au> Message-ID: In article , MRAB wrote: > You could argue that construction is not complete until the instance > has been initialised. In the case of C++, all you have is the > initialiser, so doesn't really matter, but Python has __new__ and > __init__, so it _does_ matter. C++ has operator new (which you can override) and the constructor. From ben+python at benfinney.id.au Fri Jan 31 21:10:21 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Feb 2014 13:10:21 +1100 Subject: __init__ is the initialiser References: <52EC0E3C.5070900@stoneleaf.us> <20140131224507.GA5454@cskk.homeip.net> <85ob2rhfxd.fsf@benfinney.id.au> <52EC3C14.8080806@stoneleaf.us> Message-ID: <85eh3nh9bm.fsf@benfinney.id.au> Ethan Furman writes: > On 01/31/2014 03:47 PM, Ben Finney wrote: > > I suggest: > > > > Called automatically by the constructor ?__new__? during > > instance creation, to initialise the new instance. > > But __new__ does not call __init__, type does [1]. My apologies, you're right and that's made clear at . Try: object.__init__(self[, ?]) Called automatically after the constructor ?__new__?, during instance creation, to initialise the new instance. -- \ ?Software patents provide one more means of controlling access | `\ to information. They are the tool of choice for the internet | _o__) highwayman.? ?Anthony Taylor | Ben Finney From ben+python at benfinney.id.au Fri Jan 31 21:13:49 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Feb 2014 13:13:49 +1100 Subject: __init__ is the initialiser References: <52EC0E3C.5070900@stoneleaf.us> <20140131224507.GA5454@cskk.homeip.net> <85ob2rhfxd.fsf@benfinney.id.au> <52EC3C14.8080806@stoneleaf.us> <85eh3nh9bm.fsf@benfinney.id.au> Message-ID: <85a9ebh95u.fsf@benfinney.id.au> Ben Finney writes: > My apologies, you're right and that's made clear at > . And that's a URL to my local filesystem. Clearly it's time for me to step away from the discussion for a while :-) -- \ ?I went to the cinema, it said ?Adults: $5.00, Children $2.50?. | `\ So I said ?Give me two boys and a girl.?? ?Steven Wright | _o__) | Ben Finney From tjreedy at udel.edu Fri Jan 31 21:28:02 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 21:28:02 -0500 Subject: __init__ is the initialiser In-Reply-To: <52EC0A86.7060102@stoneleaf.us> References: <52EC0A86.7060102@stoneleaf.us> Message-ID: On 1/31/2014 3:41 PM, Ethan Furman wrote: > On 01/31/2014 11:52 AM, Ned Batchelder wrote: >> On 1/31/14 2:33 PM, Mark Lawrence wrote: >>> From http://docs.python.org/3/reference/datamodel.html#object.__init__ >>> which states:- >>> >>> " >>> Called when the instance is created. The arguments are those passed to >>> the class constructor expression. If a base class has an __init__() >>> method, the derived class?s __init__() method, if any, must explicitly >>> call it to ensure proper initialization of the base class part of the >>> instance; for example: BaseClass.__init__(self, [args...]). As a special >>> constraint on constructors, no value may be returned; doing so will >>> cause a TypeError to be raised at runtime. >>> " >>> >>> Should the wording of the above be changed to clearly reflect that we >>> have an initialiser here and that __new__ is the constructor? Construct a house: Clear and grade house site. Bring in power and water. Built temporary structures. Built foundation. Built house on foundation. For most classes, __new__ stops with the foundation -- the bare object object (with the class name slapped onto it). A *house* is not constructed until the house is constructed on top of the foundation. >> I'm torn about that. The fact is, that for 95% of the reasons you >> want to say "constructor", the thing you're >> describing is __init__. Right: __init__ usually does the stuff that makes the object an instance of a particular class rather than just a bare bones object. In English, constructing a 'something' includes constructing the features that make the object a 'something' rather than something else. >>> Most classes have __init__, only very very few have __new__. *Every* class has .__new__. Mutable builtins and almost all user classes inherit .__new__ from object. Every class also has .__init__, but it is mainly inherited from object by immutable builtins. >>> tuple.__init__ User classes lacking .__init__ usually inherit it from something other than object. So objects are constructed by first calling .__new__ and then passing the result to .__init__. The Python 3 doc should say so. > My problem is with the first sentence, as it makes it sound like there > is no __new__ and everything you need is in __init__. .__new__ allocates a bare object and initializes immutable builtins. Figuring out how > __new__ and __init__ were tied together took a long time because of that. > >> Why can't we call __init__ the constructor and __new__ the allocator? -- Terry Jan Reedy From ethan at stoneleaf.us Fri Jan 31 21:35:39 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 18:35:39 -0800 Subject: __init__ is the initialiser In-Reply-To: References: <858utviwgs.fsf@benfinney.id.au> Message-ID: <52EC5D7B.5030700@stoneleaf.us> On 01/31/2014 05:10 PM, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> I found calling __init__ the constructor very confusing. > > I've heard many people say this, and it's always sort of befuddled me. I have never learned C++, so I don't know its screwy semantics. ;) Nor Java, for that matter. -- ~Ethan~ From ben+python at benfinney.id.au Fri Jan 31 21:38:18 2014 From: ben+python at benfinney.id.au (Ben Finney) Date: Sat, 01 Feb 2014 13:38:18 +1100 Subject: __init__ is the initialiser References: <52EC0A86.7060102@stoneleaf.us> Message-ID: <8561ozh811.fsf@benfinney.id.au> Terry Reedy writes: > User classes lacking .__init__ usually inherit it from something other > than object. So objects are constructed by first calling .__new__ and > then passing the result to .__init__. The Python 3 doc should say so. That matches my understanding, and I agree the docs should (somehow) say that clearly. -- \ ?He may look like an idiot and talk like an idiot but don't let | `\ that fool you. He really is an idiot.? ?Groucho Marx | _o__) | Ben Finney From tjreedy at udel.edu Fri Jan 31 21:40:32 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 21:40:32 -0500 Subject: __init__ is the initialiser In-Reply-To: <52EC3C14.8080806@stoneleaf.us> References: <52EC0E3C.5070900@stoneleaf.us> <20140131224507.GA5454@cskk.homeip.net> <85ob2rhfxd.fsf@benfinney.id.au> <52EC3C14.8080806@stoneleaf.us> Message-ID: On 1/31/2014 7:13 PM, Ethan Furman wrote: > On 01/31/2014 03:47 PM, Ben Finney wrote: >> >> I would prefer it to be clear that ?__init__? is called automatically, >> *during* the constructor's operation. So, instead of: >> >> Called when the instance is created. >> >> I suggest: >> >> Called automatically by the constructor ?__new__? during instance >> creation, to initialise the new instance. > > But __new__ does not call __init__, type does [1]. If the class is an instance of type, it is type.__call__, >>> tuple.__call__ I presume it is basically something like this: class type: def __call__(self, *args, **kwds): instance = self.__new__(cls, *args, **kwds) self.__init__(instance, *args, **kwds) return instance .__new__ and .__init__ are the plugins used by the true class instance constructor. -- Terry Jan Reedy From self at gkayaalp.com Fri Jan 31 20:58:19 2014 From: self at gkayaalp.com (=?utf-8?B?R8O2a3R1xJ8=?= Kayaalp) Date: Sat, 01 Feb 2014 03:58:19 +0200 Subject: Try-except-finally paradox In-Reply-To: (Terry Reedy's message of "Fri, 31 Jan 2014 00:26:05 -0500") References: <9314ac52-a2be-4382-94ef-2c291f32be1a@googlegroups.com> Message-ID: <87bnyroapw.fsf@gkayaalp.com> Terry Reedy writes: I do not have any information on the topic, but I *imagine* that the when RETURN_VALUE opcode is evaluated within the context of an except block, it triggers a check for whether a corresponding finally block exists and should it exist, it is triggered, much like a callback. So, my *imaginary* algorithm works like this: return: if within an except block EB: if EB has a correspoinding final block FB run FB else do return else do return In Jessica's example, as the finally block executes a RETURN_VALUE opcode, and as this is *probably* a jump to the caller, the rest of the code does not get a chance to be executed. As I have said earlier, I by no means assert the truth of this idea I've explained here, but it seems quite reasonable to me. gk > On 1/30/2014 7:05 AM, Dave Angel wrote: >> Jessica Ross Wrote in message: >>> I found something like this in a StackOverflow discussion. >>>>>> def paradox(): >>> ... try: >>> ... raise Exception("Exception raised during try") >>> ... except: >>> ... print "Except after try" >>> ... return True >>> ... finally: >>> ... print "Finally" >>> ... return False >>> ... return None >>> ... >>>>>> return_val = paradox() >>> Except after try >>> Finally >>>>>> return_val >>> False >>> >>> I understand most of this. >>> What I don't understand is why this returns False rather than True. Does the finally short-circuit the return in the except block? >>> >> >> The finally has to happen before any return inside the try or the >> except. And once you're in the finally clause you'll finish it >> before resuming the except clause. Since it has a return, that >> will happen before the other returns. The one in the except block >> will never get reached. >> >> It's the only reasonable behavior., to my mind. > > Checking with the disassembled code, it appears that the except return > happens first and is then caught and the value over-written > > 2 0 SETUP_FINALLY 45 (to 48) > 3 SETUP_EXCEPT 16 (to 22) > > 3 6 LOAD_GLOBAL 0 (Exception) > 9 LOAD_CONST 1 ('Exception raised during try') > 12 CALL_FUNCTION 1 (1 positional, 0 keyword pair) > 15 RAISE_VARARGS 1 > 18 POP_BLOCK > 19 JUMP_FORWARD 22 (to 44) > > 4 >> 22 POP_TOP > 23 POP_TOP > 24 POP_TOP > > 5 25 LOAD_GLOBAL 1 (print) > 28 LOAD_CONST 2 ('Except after try') > 31 CALL_FUNCTION 1 (1 positional, 0 keyword pair) > 34 POP_TOP > > 6 35 LOAD_CONST 3 (True) > 38 RETURN_VALUE > 39 POP_EXCEPT > 40 JUMP_FORWARD 1 (to 44) > 43 END_FINALLY > >> 44 POP_BLOCK > 45 LOAD_CONST 0 (None) > > 8 >> 48 LOAD_GLOBAL 1 (print) > 51 LOAD_CONST 4 ('Finally') > 54 CALL_FUNCTION 1 (1 positional, 0 keyword pair) > 57 POP_TOP > > 9 58 LOAD_CONST 5 (False) > 61 RETURN_VALUE > 62 END_FINALLY > > 10 63 LOAD_CONST 0 (None) > 66 RETURN_VALUE > > > > > -- > Terry Jan Reedy From python at mrabarnett.plus.com Fri Jan 31 21:54:55 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 01 Feb 2014 02:54:55 +0000 Subject: Python shell wont open idle or an exisiting py file In-Reply-To: References: <24EAA33389A147D8BC08B029E2209E16@UserPC> Message-ID: <52EC61FF.4060204@mrabarnett.plus.com> On 2014-02-01 01:52, Chris Angelico wrote: > On Sat, Feb 1, 2014 at 12:45 PM, Terry Reedy wrote: >> H:\HP_Documents\0PythonWork\AirplaneKinematics\accel2.py >> caused this message >> UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 14: >> invalid start byte > > So... something's interpreting \0 as codepoint U+0000 (which it > shouldn't), storing that in "UTF-8" as 0xC0 0x80 (which it shouldn't), > and then giving it to Python to decode. That's a weird little > combination bug right there. > I think that some years ago I heard about a variation on UTF-8 (Microsoft?) where codepoint U+0000 is encoded as 0xC0 0x80 so that the null byte can be used as the string terminator. I had a look on Wikipedia found this: http://en.wikipedia.org/wiki/Null-terminated_string From steve+comp.lang.python at pearwood.info Fri Jan 31 21:52:52 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Feb 2014 02:52:52 GMT Subject: Dunder [was Re: __init__ is the initialiser] References: <858utviwgs.fsf@benfinney.id.au> Message-ID: <52ec6183$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Jan 2014 20:10:46 -0500, Roy Smith wrote: > In article , > Ethan Furman wrote: > >> I found calling __init__ the constructor very confusing. > > I've heard many people say this, and it's always sort of befuddled me. > > In C++, a constructor is really an initializer too. By the time C++'s > Foo::Foo() or Python's Foo.__init__() get called, memory has already > been allocated, so I would say the object has been constructed. Yet, > C++ people are perfectly happy calling this "thing that takes some > allocated hunk of memory and sets its attributes to useful values" a > constructor[1], and Python people are not. > > [1] Well, they really call it a ctor, but I chalk that up to the same > sort of silliness that makes pythonistas pronounce "__" as "dunder" :-) I see your smiley, but the comparison is ridiculous. "Constructor" is three syllables; "ctor" isn't readily pronounceable in English at all, rather like Cthulhu. (I can't think of any standard English words with a "CT" in them at all, let alone at the start of the word). The best I can come up with is "KUH TOR" or possibly "SEE TOR", both of which are clumsy, and only save a single syllable. On the other hand, "double leading and trailing underscore" is ten syllables. "Dunder" is two, a significant saving, and it's a readily pronounceable word in English (and probably Dutch). There's nothing silly about abbreviating "double leading and trailing underscore" as dunder. -- Steven From ned at nedbatchelder.com Fri Jan 31 21:56:12 2014 From: ned at nedbatchelder.com (Ned Batchelder) Date: Fri, 31 Jan 2014 21:56:12 -0500 Subject: __init__ is the initialiser In-Reply-To: References: <52EC0A86.7060102@stoneleaf.us> Message-ID: On 1/31/14 9:28 PM, Terry Reedy wrote: >>>> Most classes have __init__, only very very few have __new__. > > *Every* class has .__new__. Mutable builtins and almost all user classes > inherit .__new__ from object. Every class also has .__init__, but it is > mainly inherited from object by immutable builtins. > >>> tuple.__init__ > > User classes lacking .__init__ usually inherit it from something other > than object. So objects are constructed by first calling .__new__ and > then passing the result to .__init__. The Python 3 doc should say so. Sorry, I wasn't clear. I meant (as many have understood) that most user-defined classes define __init__, and that very very few define __new__. -- Ned Batchelder, http://nedbatchelder.com From python at mrabarnett.plus.com Fri Jan 31 22:04:11 2014 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 01 Feb 2014 03:04:11 +0000 Subject: Dunder [was Re: __init__ is the initialiser] In-Reply-To: <52ec6183$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <858utviwgs.fsf@benfinney.id.au> <52ec6183$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52EC642B.3070101@mrabarnett.plus.com> On 2014-02-01 02:52, Steven D'Aprano wrote: > On Fri, 31 Jan 2014 20:10:46 -0500, Roy Smith wrote: > >> In article , >> Ethan Furman wrote: >> >>> I found calling __init__ the constructor very confusing. >> >> I've heard many people say this, and it's always sort of befuddled me. >> >> In C++, a constructor is really an initializer too. By the time C++'s >> Foo::Foo() or Python's Foo.__init__() get called, memory has already >> been allocated, so I would say the object has been constructed. Yet, >> C++ people are perfectly happy calling this "thing that takes some >> allocated hunk of memory and sets its attributes to useful values" a >> constructor[1], and Python people are not. >> >> [1] Well, they really call it a ctor, but I chalk that up to the same >> sort of silliness that makes pythonistas pronounce "__" as "dunder" :-) > > > I see your smiley, but the comparison is ridiculous. > > "Constructor" is three syllables; "ctor" isn't readily pronounceable in > English at all, rather like Cthulhu. (I can't think of any standard > English words with a "CT" in them at all, let alone at the start of the > word). The best I can come up with is "KUH TOR" or possibly "SEE TOR", > both of which are clumsy, and only save a single syllable. > So you've never used the word "ctenoid"? How strange! :-) (adj. - Resembling a comb; having projections like the teeth of a comb.) > On the other hand, "double leading and trailing underscore" is ten > syllables. "Dunder" is two, a significant saving, and it's a readily > pronounceable word in English (and probably Dutch). There's nothing silly > about abbreviating "double leading and trailing underscore" as dunder. > From denismfmcmahon at gmail.com Fri Jan 31 22:02:49 2014 From: denismfmcmahon at gmail.com (Denis McMahon) Date: Sat, 1 Feb 2014 03:02:49 +0000 (UTC) Subject: Help with some python homework... References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Message-ID: On Thu, 30 Jan 2014 21:12:19 -0800, scottwd80 wrote: > Here is the question that was asked and below that I'll paste the code I > have so far. The following is a reasonably but not highly obfuscated short solution to the problem set in python 2.7. With a bit of luck, after each lesson of your course, you'll be able to understand a bit more of how it works. M=60;H=M*60 def s(h,m,s): return h*H+m*M+s def hms(s): return (int(s/H),int((s%H)/M),s%M) (a,b,c)=hms(s(6,52,0)+3*s(0,7,12)+2*s(0,8,15)) print "{:02d}:{:02d}:{:02d}".format(a,b,c) When you can write a short paragraph describing what each line of the program does, you'll be on your way to understanding a few of the structures, syntaxes and mechanisms of python. Or you could show it to your lecturer or a TA and say it was suggested that you ask her or him to work through it with you. -- Denis McMahon, denismfmcmahon at gmail.com From tjreedy at udel.edu Fri Jan 31 22:16:59 2014 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 31 Jan 2014 22:16:59 -0500 Subject: __init__ is the initialiser In-Reply-To: <52EC3C40.7080402@stoneleaf.us> References: <858utviwgs.fsf@benfinney.id.au> <52EC3C40.7080402@stoneleaf.us> Message-ID: On 1/31/2014 7:13 PM, Ethan Furman wrote: > On 01/31/2014 03:43 PM, Ned Batchelder wrote: >> On 1/31/14 6:05 PM, Ben Finney wrote: >>> Ned Batchelder writes: >> >> I'm not hoping to change any official terminology. I just think that >> calling __init__ anything other than a constructor >> is confusing pedantry. It is a constructor, and Python constructors >> work differently than those in C++ and Java. > > And I would say the opposite. __init__ is not creating anything, As you pointed out in a different response, Python has one default, two-phase constructor. type.__call__. Typically, .__new__ allocates a generic object (with one customization as to class). .__init__ creates, from that mostly generic object, a customized instance of class C with the minimal attributes needed to be an instance of C, with value specific to the instance. Creating a painting on canvas has two similar phases. Prepare a generic blank canvas stretched on a frame and coated with a white undercoat. Paint a particular picture. Would you say that the second step is not creating anything? -- Terry Jan Reedy From rosuav at gmail.com Fri Jan 31 22:36:45 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 14:36:45 +1100 Subject: Python shell wont open idle or an exisiting py file In-Reply-To: <52EC61FF.4060204@mrabarnett.plus.com> References: <24EAA33389A147D8BC08B029E2209E16@UserPC> <52EC61FF.4060204@mrabarnett.plus.com> Message-ID: On Sat, Feb 1, 2014 at 1:54 PM, MRAB wrote: > I think that some years ago I heard about a variation on UTF-8 > (Microsoft?) where codepoint U+0000 is encoded as 0xC0 0x80 so that the > null byte can be used as the string terminator. > > I had a look on Wikipedia found this: > > http://en.wikipedia.org/wiki/Null-terminated_string Yeah, it's a common abuse of UTF-8. It's a violation of spec, but an understandable one. However, I don't understand why the first part - why should \0 become U+0000 but (presumably) the \a later on (...cs\accel...) doesn't become U+0007, etc? ChrisA From steve+comp.lang.python at pearwood.info Fri Jan 31 22:42:24 2014 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Feb 2014 03:42:24 GMT Subject: __init__ is the initialiser References: Message-ID: <52ec6d1f$0$29972$c3e8da3$5496439d@news.astraweb.com> On Fri, 31 Jan 2014 14:52:15 -0500, Ned Batchelder wrote: > Why can't we call __init__ the constructor and __new__ the allocator? __new__ constructs the object, and __init__ initialises it. What's wrong with calling them the constructor and initialiser? Is this such a difficult concept that the average programmer can't learn it? I've met people who have difficulty with OOP principles, at least at first. But once you understand the idea of objects, it isn't that hard to understand the idea that: - first, the object has to be created, or constructed, or allocated if you will; - only then can it be initialised. Thus, two methods. __new__ constructs (creates, allocates) a new object; __init__ initialises it after the event. (In hindsight, it was probably a mistake for Python to define two create- an-object methods, although I expect it was deemed necessary for historical reasons. Most other languages make do with a single method, Objective-C being an exception with "alloc" and "init" methods.) Earlier in this post, you wrote: > But that distinction [between __new__ and __init__] isn't useful in > most programs. Well, I don't know about that. I guess it depends on what sort of objects you're creating. If you're creating immutable objects, then the distinction is vital. If you're subclassing from immutable built-ins, of which there are a few, the distinction may be important. If you're using the object-pool design pattern, the distinction is also vital. It's not *rare* to care about these things. > The thing most people mean by "constructor" is "the method that gets > invoked right at the beginning of the object's lifetime, where you can > add code to initialize it properly." That describes __init__. "Most people". I presume you've done a statistically valid survey then *wink* It *better* describes __new__, because it is *not true* that __init__ gets invoked "right at the beginning of the object's lifetime". Before __init__ is invoked, the object's lifetime has already begun, inside the call to __new__. Excluding metaclass shenanigans, the object lifetime goes: Prior to the object existing: - static method __new__ called on the class[1] - __new__ creates the object[2] <=== start of object lifetime Within the object's lifetime: - the rest of the __new__ method runs, which may perform arbitrarily complex manipulations of the object; - __new__ exits, returning the object - __init__ runs So __init__ does not occur *right at the beginning*, and it is completely legitimate to write your classes using only __new__. You must use __new__ for immutable objects, and you may use __new__ for mutable ones. __init__ may be used by convention, but it is entirely redundant. I do not buy the argument made by some people that Python ought to follow whatever (possibly inaccurate or misleading) terminology other languages use. Java and Ruby have the exact same argument passing conventions as Python, but one calls it "call by value" and the other "call by reference", and neither is the same meaning of "call by value/reference" as used by Pascal, C, Visual Basic, or other languages. So which terminology should Python use? Both C++ and Haskell have "functors", but they are completely different things. What Python calls a class method, Java calls a static method. We could go on for days, just listing differences in terminology. In Python circles, using "constructor" for __new__ and "initialiser" for __init__ are well-established. In the context of Python, they make good sense: __new__ creates ("constructs") the object, and __init__ _init_ialises it. Missing the opportunity to link the method name __init__ to *initialise* would be a mistake. We can decry the fact that computer science has not standardised on a sensible set of names for concepts, but on the other hand since the semantics of languages differ slightly, it would be more confusing to try to force all languages to use the same words for slightly different concepts. The reality is, if you're coming to Python from another language, you're going to have to learn a whole lot of new stuff anyway, so having to learn a few language-specific terms is just a small incremental cost. And if you have no idea about other languages, then it is no harder to learn that __new__ / __init__ are the constructor/initialiser than it would be to learn that they are the allocator/constructor or preformulator/ postformulator. I care about using the right terminology that will cause the least amount of cognitive dissonance to users' understanding of Python, not whether they have to learn new terminology, and in the context of Python's object module, "constructor" and "initialiser" best describe what __new__ and __init__ do. [1] Yes, despite being declared with a "cls" parameter, __new__ is actually hard-coded as a static method. [2] By explicitly or implicitly calling object.__new__. -- Steven From ethan at stoneleaf.us Fri Jan 31 22:30:46 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 19:30:46 -0800 Subject: __init__ is the initialiser In-Reply-To: References: <858utviwgs.fsf@benfinney.id.au> <52EC3C40.7080402@stoneleaf.us> Message-ID: <52EC6A66.8030108@stoneleaf.us> On 01/31/2014 07:16 PM, Terry Reedy wrote: > On 1/31/2014 7:13 PM, Ethan Furman wrote: >> On 01/31/2014 03:43 PM, Ned Batchelder wrote: >>> On 1/31/14 6:05 PM, Ben Finney wrote: >>>> Ned Batchelder writes: >>> >>> I'm not hoping to change any official terminology. I just think that >>> calling __init__ anything other than a constructor >>> is confusing pedantry. It is a constructor, and Python constructors >>> work differently than those in C++ and Java. >> >> And I would say the opposite. __init__ is not creating anything, > > As you pointed out in a different response, Python has one default, two-phase constructor. type.__call__. Typically, > .__new__ allocates a generic object (with one customization as to class). .__init__ creates, from that mostly generic > object, a customized instance of class C with the minimal attributes needed to be an instance of C, with value specific > to the instance. > > Creating a painting on canvas has two similar phases. Prepare a generic blank canvas stretched on a frame and coated > with a white undercoat. Paint a particular picture. Would you say that the second step is not creating anything? Very nicely put. Considering the discussion that this topic has engendered, you will hopefully agree that the current docs could use a little improvement. :) -- ~Ethan~ From ethan at stoneleaf.us Fri Jan 31 21:45:19 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 18:45:19 -0800 Subject: __init__ is the initialiser In-Reply-To: References: <52EC0A86.7060102@stoneleaf.us> Message-ID: <52EC5FBF.5090705@stoneleaf.us> On 01/31/2014 06:28 PM, Terry Reedy wrote: > > Construct a house: > Clear and grade house site. > Bring in power and water. > Built temporary structures. > Built foundation. > Built house on foundation. > > For most classes, __new__ stops with the foundation -- the bare object object (with the class name slapped onto it). A > *house* is not constructed until the house is constructed on top of the foundation. On the ground programming has the dividing line at: immutable objects --> everything done in __new__ mutable objects --> everything done in __init__ Typically, immutable objects are not created in Python code because, well, it's really dang hard (__slots__, anyone?), but one still needs to understand how __new__ and __init__ go together to do the more interesting stuff (such as having __new__ return a dynamically selected subclass, which still needs to be (or not be) __init__ed). -- ~Ethan~ From rustompmody at gmail.com Fri Jan 31 23:02:10 2014 From: rustompmody at gmail.com (Rustom Mody) Date: Fri, 31 Jan 2014 20:02:10 -0800 (PST) Subject: __init__ is the initialiser In-Reply-To: References: <858utviwgs.fsf@benfinney.id.au> <52EC3C40.7080402@stoneleaf.us> Message-ID: Not any direct comments on this... Just some thoughts around a couple of questions 1. Declarative and Imperative Terminology 2. Is OOP declarative or imperative 1. Python is an imperative language. It does a good amount of functional stuff. Are its terms neutral? Look at sort sort -- imperative sorted -- functional By contrast in scheme one would have something like sort -- functional sort! -- imperative Or haskell sort -- functional unsafePerformSort -- imperative If the simple term corresponds to the standard and therefore default, this shows a fundamental difference in world-views 2. Is OOP functional, imperative or neutral? In theory it is neutral: If we only ever make and use value-objects (ie immutable objects) then it is used declaratively If we have mutable objects then OOP is being used imperatively So much for the theory. In practice (in the words of Neal Ford): OOP tries to encapsulate moving parts, FP tries to minimize the moving parts IOW it seems (to me) OOP is almost always used as a clover-leaf on wanton state-change ie. imperativeness. This comes from the fact that while objects in programming languages may pretend neutrality, philosphically objects and values are fundamentally opposed: Objects belong to 'this world' -- born change live die Values belong to the platonic world -- 3 was 3 even without an exsting universe In hhttp://research.microsoft.com/en-us/um/people/gurevich/opera/123.pdf (first few pages) Yuri Gurevich gives an entertaining account of how kids learning math are platonically indoctrinated. What most dyed-in-the-wool imperative programmers dont get is that when we take a task that humans perform in 'this world' and abstract it effectively into a program that a machine can (at least partly) perform, this is only possible if we build a model of the action. And models are intrinsically abstract entities ie platonic. IOW to modify the standard dictum of philosophy: "No philosophy is bad philosophy" we have "Imperative programmers are bad functional programmers" What has this to do with how constructors are named? Both 'constructor' and 'initializer' have (to my ears) an imperative sound though initializer is perhaps more so -- evokes a picture of a life-story -- a saga! Constructor less so This may be factored in to the choice of terminology From rosuav at gmail.com Fri Jan 31 23:35:17 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 15:35:17 +1100 Subject: __init__ is the initialiser In-Reply-To: <52ec6d1f$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <52ec6d1f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Feb 1, 2014 at 2:42 PM, Steven D'Aprano wrote: > I've met people who have difficulty with OOP principles, at least at > first. But once you understand the idea of objects, it isn't that hard to > understand the idea that: > > - first, the object has to be created, or constructed, or allocated > if you will; > > - only then can it be initialised. > > Thus, two methods. __new__ constructs (creates, allocates) a new object; > __init__ initialises it after the event. Yes, but if you think in terms of abstractions, they're both just steps in the conceptual process of "creating the object". If I ask GTK to create me a Button, I don't care how many steps it has to go through of allocating memory, allocating other resources, etc, etc, etc. All I want is to be able to write: foobar = Button("Foo Bar") and, at the end of it, to have a Button that I can toss onto a window. That's the job of a constructor - to give me an object in a state that I can depend on. (And this is completely independent of language. Modulo trivialities like semicolons, adorned names, etc, etc, I would expect that this be valid in any object oriented GUI toolkit in any object oriented language.) The difference between __new__ and __init__ is important when you write either method, but not when you use the class. It's like writing other dunder methods. You care about the distinction between __add__ and __radd__ when you write the methods, but in all other code, all that matters is that it does what you want: three = Three() four = three + 1 four == 1 + three The two methods could have been done as a single method, __construct__, in which you get passed a cls instead of a self, and you call self=super().__construct__() and then initialize stuff. It would then be obvious that this is "the constructor". So maybe it's best to talk about the two methods collectively as "the constructor", and then let people call the two parts whatever they will. I do like the idea of calling __init__ the initializer. The downside of calling __new__ the constructor is that it'll encourage C++ and Java programmers to override it and get themselves confused, when really they should have been writing __init__ and having an easy time of it. So, current best suggestion is "allocator" for that? Not entirely sure that's right, but it's not terrible. I'm +1 on __init__ being documented as the initializer, and +0 on "allocator" for __new__. ChrisA From bouncingcats at gmail.com Fri Jan 31 22:17:58 2014 From: bouncingcats at gmail.com (David) Date: Sat, 1 Feb 2014 14:17:58 +1100 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> <2B1086E7-5E5F-4227-8F9E-92A37D2DE1D2@cox.net> Message-ID: On 1 February 2014 12:34, Chris Angelico wrote: > On Sat, Feb 1, 2014 at 12:14 PM, Scott W Dunning wrote: > >> Also, I think I found out through a little trial and error that I had two different hours, mins, and sec so I had to use one uppercase and one lower case. Is that frowned upon? And should I have come up with a different name instead? >> >> SECONDS = 1 >> MINUTES = 60 * SECONDS >> HOURS = 60 * MINUTES What is actually being defined here are constants to be used for scaling or conversion of some quantity (a time) into different units. So in this situation would I define the conversion constant with an upper case name like this: SECONDS_PER_MINUTE = 60 and I would use it like this seconds = minutes * SECONDS_PER_MINUTE where "seconds" and "minutes" are the names holding the numeric data. That line has the extra benefit that it is clear to me why the units are seconds on both sides of the equals sign (because on the right hand side the minute-units cancel thus: m*s/m=s), whereas this is much less clear to me in Scott's line. Scott's message quoted above did not reach me, only Chris's quote of it, so I say: Scott once you begin a discussion on a mailing list like this one, please make sure that every reply you make goes to "python-list at python.org" and not to the individual. That way we can all participate in the discussion, that is best for everyone especially you. From swdunning at cox.net Fri Jan 31 19:07:45 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 31 Jan 2014 17:07:45 -0700 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Message-ID: You guys are awesome! I think I was over complicating things for one. Plus I was looking at some code I wrote for another problem that asked to put in the number of seconds to calculate the problem and I didn?t need some of the things I added to this problem. Anyways, you guys have given me a lot of help and I think I can get it now. I?ll post what I got when I?m done so you guys can help with unnecessary code if needed or just to see how you helped. On Jan 31, 2014, at 6:51 AM, Neil Cerutti wrote: > On 2014-01-31, scottwd80 at gmail.com wrote: >> Here is the question that was asked and below that I'll paste >> the code I have so far. >> >> **If I leave my house at 6:52 am and run 1 mile at an easy pace >> (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 >> mile at easy pace again, what time do I get home for >> breakfast?** > > That depends on the directions in which you run. Also, you are > fast! > > But seriously, my advice is to find the answer the old fashioned > way first, with pencil and paper. Then you'll have two things you > don't now: > > 1. A correct answer to test your program's answer with. > 2. A general idea of how to solve the problem. > > It's often a mistake to start writing code. Eventually you'll be > able to go directly from problem to code more often, but it will > take practice. > > -- > Neil Cerutti > > -- > https://mail.python.org/mailman/listinfo/python-list From swdunning at cox.net Fri Jan 31 19:35:50 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 31 Jan 2014 17:35:50 -0700 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> Message-ID: So, this is what I came up with. It works, which is good but it?s a little different from a few things you guys had mentioned. For one, I got the correct time by calculating the number of time run and converting that into seconds then back out to hr:mn:sc. I didn?t calculate from midnight. That seemed more complicated to me because I?d have to figure the number of seconds from midnight to 6:52am then do the calculations for number of seconds run until I got home, then I got kind of lost. Also, before I forget what is the difference between / and //? I remember somthing about floor division? Not sure what that means though. Is it like a % where it gives the remainder after dividing? Thanks again. Code below. Also, I think I found out through a little trial and error that I had two different hours, mins, and sec so I had to use one uppercase and one lower case. Is that frowned upon? And should I have come up with a different name instead? SECONDS = 1 MINUTES = 60 * SECONDS HOURS = 60 * MINUTES time_left_house = 6 * HOURS + 52 * MINUTES miles_run_easy_pace = 2 * (8 * MINUTES + 15 * SECONDS) miles_run_fast_pace = 3 * (7 * MINUTES + 12 * SECONDS) time_returned_home = miles_run_easy_pace + miles_run_fast_pace + time_left_house hours = time_returned_home // HOURS part_hour = time_returned_home % HOURS minutes = part_hour // MINUTES seconds = part_hour % MINUTES print "Time returned home:", hours,":", minutes,":", seconds,"am" On Jan 31, 2014, at 6:51 AM, Neil Cerutti wrote: > On 2014-01-31, scottwd80 at gmail.com wrote: >> Here is the question that was asked and below that I'll paste >> the code I have so far. >> >> **If I leave my house at 6:52 am and run 1 mile at an easy pace >> (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 >> mile at easy pace again, what time do I get home for >> breakfast?** > > That depends on the directions in which you run. Also, you are > fast! > > But seriously, my advice is to find the answer the old fashioned > way first, with pencil and paper. Then you'll have two things you > don't now: > > 1. A correct answer to test your program's answer with. > 2. A general idea of how to solve the problem. > > It's often a mistake to start writing code. Eventually you'll be > able to go directly from problem to code more often, but it will > take practice. > > -- > Neil Cerutti > > -- > https://mail.python.org/mailman/listinfo/python-list From swdunning at cox.net Fri Jan 31 19:42:15 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 31 Jan 2014 17:42:15 -0700 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: Also, any help on how to get the hours and seconds into double digits that would be cool too. 00:00:00 On Jan 31, 2014, at 1:30 AM, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 7:17 PM, Gregory Ewing > wrote: >> sjud9227 wrote: >>> >>> Doesn't >>> assigning seconds/(60*60) mean that calculating 6*hours will give me 6 >>> hours >>> in seconds? >> >> No, it's giving you 6 seconds in hours. (That should >> give you a clue as to what you should have done >> instead. :-) >> >> ... >> >> a // b gives the quotient of dividing a by b >> >> a % b gives the remainder >> >> (I recommend using '//' rather than just '/', because >> in some versions of Python, a/b does floating point >> division even if a and b are both integers, and that's >> not what you want here.) > > OP is using 2.7.6, so short of a __future__ directive, that won't > actually give 6 seconds in hours (though it will try to), and // is > unnecessary. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From swdunning at cox.net Fri Jan 31 19:46:43 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 31 Jan 2014 17:46:43 -0700 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: <690AFB89-A912-4834-BFAE-8740FB6BE926@cox.net> Also, can any of you reccommend sites that may have little ?projects? that I could work on to help me learn python better? On Jan 31, 2014, at 1:30 AM, Chris Angelico wrote: > On Fri, Jan 31, 2014 at 7:17 PM, Gregory Ewing > wrote: >> sjud9227 wrote: >>> >>> Doesn't >>> assigning seconds/(60*60) mean that calculating 6*hours will give me 6 >>> hours >>> in seconds? >> >> No, it's giving you 6 seconds in hours. (That should >> give you a clue as to what you should have done >> instead. :-) >> >> ... >> >> a // b gives the quotient of dividing a by b >> >> a % b gives the remainder >> >> (I recommend using '//' rather than just '/', because >> in some versions of Python, a/b does floating point >> division even if a and b are both integers, and that's >> not what you want here.) > > OP is using 2.7.6, so short of a __future__ directive, that won't > actually give 6 seconds in hours (though it will try to), and // is > unnecessary. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From swdunning at cox.net Fri Jan 31 20:14:31 2014 From: swdunning at cox.net (Scott W Dunning) Date: Fri, 31 Jan 2014 18:14:31 -0700 Subject: Help with some python homework... In-Reply-To: References: <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com> Message-ID: <2B1086E7-5E5F-4227-8F9E-92A37D2DE1D2@cox.net> Thanks Chris! So, this is what I came up with. It works, which is good but it?s a little different from a few things you guys had mentioned. For one, I got the correct time by calculating the number of time run and converting that into seconds then back out to hr:mn:sc. I didn?t calculate from midnight. That seemed more complicated to me because I?d have to figure the number of seconds from midnight to 6:52am then do the calculations for number of seconds run until I got home, then I got kind of lost. Also, before I forget what is the difference between / and //? I remember something about floor division? Not sure what that means though. Is it like a % where it gives the remainder after dividing? Thanks again. Code below. Also, I think I found out through a little trial and error that I had two different hours, mins, and sec so I had to use one uppercase and one lower case. Is that frowned upon? And should I have come up with a different name instead? SECONDS = 1 MINUTES = 60 * SECONDS HOURS = 60 * MINUTES time_left_house = 6 * HOURS + 52 * MINUTES miles_run_easy_pace = 2 * (8 * MINUTES + 15 * SECONDS) miles_run_fast_pace = 3 * (7 * MINUTES + 12 * SECONDS) time_returned_home = miles_run_easy_pace + miles_run_fast_pace + time_left_house hours = time_returned_home // HOURS part_hour = time_returned_home % HOURS minutes = part_hour // MINUTES seconds = part_hour % MINUTES print "Time returned home:", hours,":", minutes,":", seconds,?am" On Jan 31, 2014, at 5:57 PM, Chris Angelico wrote: > On Sat, Feb 1, 2014 at 11:42 AM, Scott W Dunning wrote: >> Also, any help on how to get the hours and seconds into double digits that would be cool too. 00:00:00 > > Once you can divide the number of seconds into hours, minutes, and > seconds, you can format them like this: > > time = "%02d:%02d:%02d" % (hours, minutes, seconds) > > I'll give you that one for free because I don't think it's > particularly critical to your course, but it will look better that way > :) Look up the string formatting features of Python in the docs. > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list From rosuav at gmail.com Fri Jan 31 23:05:34 2014 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 1 Feb 2014 15:05:34 +1100 Subject: Dunder [was Re: __init__ is the initialiser] In-Reply-To: <52ec6183$0$29972$c3e8da3$5496439d@news.astraweb.com> References: <858utviwgs.fsf@benfinney.id.au> <52ec6183$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Sat, Feb 1, 2014 at 1:52 PM, Steven D'Aprano wrote: > "Constructor" is three syllables; "ctor" isn't readily pronounceable in > English at all, rather like Cthulhu. (I can't think of any standard > English words with a "CT" in them at all, let alone at the start of the > word). The best I can come up with is "KUH TOR" or possibly "SEE TOR", > both of which are clumsy, and only save a single syllable. May I tactfully suggest that searching the abstract of a dictionary for the letters 'ct' would be a useful action here. Actually, you could collect a compact list of words containing "ct", and maybe even concoct a paragraph of text that conflicts with the theory that this is a rare conjunction of characters. Hopefully this will convict you of the correctness of what I am saying - though it does not at all deduct from your main point to the effect that few or no English words would be depicted *starting* with these letters. I mean no disrespect to you, Steven, but in dissecting your words, I expect myself to exactly demonstrate the imperfect (I won't say "incorrect", as I don't have a doctorate in this) information here, to ensure that it does not infect the structure of python-list. We are all persons of intellect, and we know how to interact without getting intractable; all I want to do is offer an introduction to the results of grep|less, not to give a lecture. I apologize if this comes across harshly, but the neglect of manners may be a consequence of my nocturnal exertions of late, with the objective of removing all obstructions to converting to Linux before I'm an octogenarian. [1] Let us make a pact to view matters from each other's perspective, as we picture a more practical projection of life, with a reasonable prospect of rejecting unpleasantness and resurrecting the on-topic discussions that we might otherwise have. In retrospect, I perhaps shouldn't have started writing this, and it may be time to impose sanctions on me for not being more selective in my use o English; this is becoming a spectacular flop, a spectre to haunt me. Strictly between ourselves, wordplay is a subject which (I suspect) is unattractive to many, but it would be uncharacteristic of me to refrain. I leave the final verdict up to you: are you the victims of a horrible plot, or will your vindictive anger be turned aside? Ahem. I'd probably pronounce it "k'tor", like your first option but with a really short schwa in there; or - more likely - I'd spell it "ctor" and pronounce it "constructor". ChrisA [1] Okay, that one's really pushing it. From ethan at stoneleaf.us Fri Jan 31 23:55:15 2014 From: ethan at stoneleaf.us (Ethan Furman) Date: Fri, 31 Jan 2014 20:55:15 -0800 Subject: __init__ is the initialiser In-Reply-To: References: <52ec6d1f$0$29972$c3e8da3$5496439d@news.astraweb.com> Message-ID: <52EC7E33.1060706@stoneleaf.us> On 01/31/2014 08:35 PM, Chris Angelico wrote: > On Sat, Feb 1, 2014 at 2:42 PM, Steven D'Aprano wrote: >> >> Thus, two methods. __new__ constructs (creates, allocates) a new object; >> __init__ initialises it after the event. > > Yes, but if you think in terms of abstractions, they're both just > steps in the conceptual process of "creating the object". > So maybe it's best to talk about the two methods collectively as > "the constructor", and then let people call the two parts whatever > they will. > I do like the idea of calling __init__ the initializer. The downside > of calling __new__ the constructor is that it'll encourage C++ and > Java programmers to override it and get themselves confused Why do we worry so about other languages? If and when I go to learn C++ or Lisp, I do not expect their devs to be worrying about making their terminology match Python's. Part of the effort is in learning what the terms mean, what the ideology is, the differences, the similarities, etc., etc.. -- ~Ethan~ From michael at stroeder.com Fri Jan 31 12:23:22 2014 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 31 Jan 2014 18:23:22 +0100 Subject: ANN: python-ldap 2.4.14 Message-ID: Find a new release of python-ldap: http://pypi.python.org/pypi/python-ldap/2.4.14 python-ldap provides an object-oriented API to access LDAP directory servers from Python programs. It mainly wraps the OpenLDAP 2.x libs for that purpose. Additionally it contains modules for other LDAP-related stuff (e.g. processing LDIF, LDAP URLs and LDAPv3 schema). Project's web site: http://www.python-ldap.org/ Ciao, Michael. ---------------------------------------------------------------- Released 2.4.14 2014-01-31 Changes since 2.4.13: Lib/ * Added ldap.controls.openldap.SearchNoOpControl * New method ldap.async.AsyncSearchHandler.afterFirstResult() for doing something right after successfully receiving but before processing first result * Better log data written when invoking ldap.LDAPLock.acquire() and ldap.LDAPLock.release() * LDAPObject and friends now pass `desc' to ldap.LDAPLock() which results in better logging * ldapobject.ReconnectLDAPObject now uses internal class-wide lock for serializing reconnects * Method signature of ReconnectLDAPObject.reconnect() changed to be able to call it with separate retry_max and retry_delay values Modules/ * Added support for retrieving negotiated TLS version/cipher with LDAPObject.get_option() with the help of upcoming OpenLDAP libs