Twisted 13.0.0 released
On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 13.0. Among the 70 tickets closed, we can see: * A new Introduction to Deferreds document that you can find here: http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html * A fix in twisted.web.template where attributes were not quoted properly, risking HTML injection. * Support for unicode domain names in twisted.names SRVConnector and Name classes, after a 12.3 regression. * A workaround for platform limitations when trying to schedule events far in the future. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/13.0/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-13.0.0.tar.bz2 or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-13.0.0.win32-py2.7.msi Thanks to the supporters of Twisted via the Software Freedom Conservancy and to the many contributors for this release. -- Thomas -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Call for papers for Dyla'13: 7th Workshop on Dynamic Languages and Applications @ECOOP
Call for Papers === Dyla'13, 7th Workshop on Dynamic Languages and Applications Colocated with ECOOP, ECMFA and ECSA In-cooperation with SIGPLAN and SIGSOFT 1–5 July, Montpellier, France http://rmod.lille.inria.fr/web/pier/Events/Dyla13 !! Important dates - Submission deadline: *April 19th* - Notification: mid-May - Workshop: July 1st - Ecoop early registration: mid-May !! Abstract The advent of Java and C# has been a major breakthrough in the adoption of some important object-oriented language characteristics. This breakthrough turned academic features like interfaces, garbage collection, and meta-programming into technologies generally accepted by industry. Nevertheless, the massive adoption of these languages now also gives rise to a growing awareness of their limitations. A number of reactions from industry testify this: invokedynamic bytecode instruction has been included in latest Java virtual machine release; the dynamic language runtime (DLR) is gaining popularity; C# adopted dynamic as a valid static type. Gartner prognoses further growth (http://blogs.gartner.com/mark_driver/2008/12/10) of dynamic languages. Researchers and practitioners struggle with static type systems, overly complex abstract grammars, simplistic concurrency mechanisms, limited reflection capabilities, and the absence of higher-order language constructs such as delegation, closures and continuations. Dynamic languages such as Ruby, Python, JavaScript and Lua are a step forward in addressing these problems while getting more and more popular. Making these languages mainstream requires practitioners to look back and pick mechanisms up in existing dynamic languages such as Lisp, Scheme, Smalltalk and Self. Practitioners also need to further explore discover new dynamic approaches in the context of new challenging fields such as pervasive computing. The goal of this workshop is to act as a forum where practitioners can discuss new advances in the design, implementation and application of dynamically typed languages that, sometimes radically, diverge from the statically typed class-based mainstream. Another objective is to discuss new as well as older forgotten languages and features in this context. Topics of interest include, but are not limited to: - programming language extensions - programming environment extensions - executing environments - static and dynamic analyses - optional type-checking - meta-object protocols - reserve engineering - domain-specific languages/tooling - testing environments - live programming !! Targeted audience The expected audience of this workshop is practitioners and researchers sharing the same interest in dynamically typed languages. Lua, Python, Ruby, Scheme and Smalltalk are gaining a significant popularity both in industry and academia. Nevertheless, each community has the tendency to only look at what it produces. Broadening the scope of each community is the goal of the workshop. To achieve this goal we will form a PC with leading persons from all languages mentioned above, fostering participation from all targeted communities. !! Workshop Format and Submission Information The workshop will have a demo-oriented style. The idea is to allow participants to demonstrate new and interesting features and discuss what they feel is relevant for the dynamic-language community. To participate to the workshop, you can either - submit (before __April 19th 2013__) an article (ACM Tighter Alternate style http://www.acm.org/sigs/publications/proceedings-templates) describing your presentation and/or tool. Articles whose length ranges from 2 to 15 pages will be carefully reviewed by a program committee including but not limited to the organizers. Each accepted paper will be presented for 20 to 30 minutes and be published to the ACM Digital Library (at the option of each author) and the workshop's web site. The submission website is http://www.easychair.org/conferences/?conf=dyla2013. - or give a 10-minute lightning demo of your work. A dedicated session will be allocated for this, provided there is ample time available. A session on pair programming is also planned. People will then get a chance to share their technologies by interacting with other participants. !! Program committee - Carl Friedrich Bolz, Heinrich-Heine-Universität Düsseldorf, Germany (http://cfbolz.de) - Camillo Bruni, Inria Lille-Nord Europe, France (http://rmod.lille.inria.fr/web/pier/team/bruni) - Adrian Kuhn, University of British Columbia, Canada (https://www.cs.ubc.ca/people/adrian-kuhn) - Lukas Renggli, Google, Switzerland (http://www.lukas-renggli.ch/) - Juan Pablo Sandoval Alcocer, University of Chile (http://users.dcc.uchile.cl/~jsandova/) - Bastian Steinert, Hasso-Plattner-Institute, Germany (http://www.bastiansteinert.org) - Veronica Uquillas Gomez, Vrije Universiteit Brussel, Belgium (http://soft.vub.ac.be/~vuquilla/) - Simon Urli, University of
How to choose between ORMs?
SQLalchemy and Storm are a few of the popular ORMs out there. Personally I have been using web2py's DAL. Other than form generator availability, 'print as raw SQL', multiple primary keys, widgets*, `check` conditions and compatibility with OracleDB, Postgres, SQLite and some of the NoSQL systems; what else should I be looking for? Thanks for all suggestions, Alec Taylor *not sure if widgets should be a requirement; by widgets I mean annotation of db schema to specify which widget to use with the form generator PS: Will likely use this ORM with: Flask, Bottle or Twisted Matrix -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 4/3/2013 1:32 AM, Steven D'Aprano wrote: On Wed, 03 Apr 2013 14:31:03 +1100, Neil Hodgson wrote: Sorting a million string list (all the file paths on a particular computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so we're out of the 'not noticeable by humans' range. Perhaps this is still a 'micro-benchmark' - I'd just like to avoid adding email access to get this over the threshold. What system *and* what compiler and compiler options. Unless 3.2 and 3.3 are both compiler with the same compiler and settings, we do not know the source of the difference. I cannot confirm this performance regression. On my laptop (Debian Linux, not Windows), I can sort a million file names in approximately 1.2 seconds in both Python 3.2 and 3.3. There is no meaningful difference in speed between the two versions. I am guessing that Neil's undisclosed system (that I can see) is Windows, since other benchmarks have been more different on Windows than on *nix. Given that we *know* that the 3.2 and 3.3 distribution are compiled with different compilers and run with different C runtimes, it is possible that some of the difference is from that and not from python at all. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 3:03 PM, Neil Hodgson nhodg...@iinet.net.au wrote: rusi wrote: Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can. In my personal experience, it's calculators. I put command-line calculators into *everything*... often in the form of more general executors, and thus restricted to admins, but it's still a calculator. For some reason, the ability to type calc 1+2 and get back 3 is very satisfying to me. You know, in case I ever forget what one plus two makes. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 4:32 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 14:31:03 +1100, Neil Hodgson wrote: Sorting a million string list (all the file paths on a particular computer) went from 0.4 seconds with Python 3.2 to 0.78 with 3.3 so we're out of the 'not noticeable by humans' range. Perhaps this is still a 'micro-benchmark' - I'd just like to avoid adding email access to get this over the threshold. I cannot confirm this performance regression. On my laptop (Debian Linux, not Windows), I can sort a million file names in approximately 1.2 seconds in both Python 3.2 and 3.3. There is no meaningful difference in speed between the two versions. I'd be curious to know the sorts of characters used. Given that it's probably a narrow-vs-wide Python difference we're talking here, the actual distribution of codepoints may well make a difference. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Chris Angelico: I'd be curious to know the sorts of characters used. Given that it's probably a narrow-vs-wide Python difference we're talking here, the actual distribution of codepoints may well make a difference. I was going to upload it but then I thought of potential client -confidentiality problems and the need to audit a list that long. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Terry Jan Reedy: What system *and* what compiler and compiler options. Unless 3.2 and 3.3 are both compiler with the same compiler and settings, we do not know the source of the difference. The version signatures are: 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] The machine is running Windows 8 64-bit (the Python installations are 32-bit though) and the processor is an i3 2350M running at 2.3 GHz. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 5:29 PM, Neil Hodgson nhodg...@iinet.net.au wrote: Chris Angelico: I'd be curious to know the sorts of characters used. Given that it's probably a narrow-vs-wide Python difference we're talking here, the actual distribution of codepoints may well make a difference. I was going to upload it but then I thought of potential client -confidentiality problems and the need to audit a list that long. Hmm. I was about to say Can you just do a quick collections.Counter() of the string widths in 3.3, as an easy way of seeing which ones use BMP or higher characters, but I can't find a simple way to query a string's width. Can't see it as a method of the string object, nor in the string or sys modules. It ought to be easy enough at the C level - just look up the two bits representing 'kind' - but I've not found it exposed to Python. Is there anything? ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico ros...@gmail.com wrote: Hmm. I was about to say Can you just do a quick collections.Counter() of the string widths in 3.3, as an easy way of seeing which ones use BMP or higher characters, but I can't find a simple way to query a string's width. Can't see it as a method of the string object, nor in the string or sys modules. It ought to be easy enough at the C level - just look up the two bits representing 'kind' - but I've not found it exposed to Python. Is there anything? 4 if max(map(ord, s)) 0x else 2 if max(map(ord, s)) 0xff else 1 -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico ros...@gmail.com wrote: Hmm. I was about to say Can you just do a quick collections.Counter() of the string widths in 3.3, as an easy way of seeing which ones use BMP or higher characters, but I can't find a simple way to query a string's width. Can't see it as a method of the string object, nor in the string or sys modules. It ought to be easy enough at the C level - just look up the two bits representing 'kind' - but I've not found it exposed to Python. Is there anything? 4 if max(map(ord, s)) 0x else 2 if max(map(ord, s)) 0xff else 1 Yeah, that's iterating over the whole string (twice, if it isn't width 4). The system already knows what the size is, I was hoping for an uber-quick inspection of the string header. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Time zone changing while Win app is running
On Tue, 02 Apr 2013 17:04:12 -0700, CM wrote: To summarize the issue: In an application, I have been using Python's datetime module to get the current time. But it seems that, at least with Windows (XP), whatever time zone your computer is set to when you start the application, that's what datetime will use--the time zone will *not* be updated in the application when you update it manually with Windows. So, if you change the time zone (say, after traveling with your laptop), all datetimes will be incorrect as compared to your system clock. I am not the maintainer of the datetime module, but based purely on what you have said, I would consider that a bug. I suggest you report it as an issue on the Python bug tracker. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Reran the programs taking a bit more care with the encoding of the file. This had no effect on the speeds. There are only a small amount of paths that don't fit into ASCII: ASCII 1076101 Latin1 218 BMP 113 Astral 0 # encoding:utf-8 import codecs, os, time from os.path import join, getsize with codecs.open(filelist.txt, r, utf-8) as f: paths = f.read().split(\n) bucket = [0,0,0,0] for p in paths: b = 0 maxChar = max([ord(ch) for ch in p]) if maxChar = 65536: b = 3 elif maxChar = 256: b = 2 elif maxChar = 128: b = 1 bucket[b] = bucket[b] + 1 print(ASCII, bucket[0]) print(Latin1, bucket[1]) print(BMP, bucket[2]) print(Astral, bucket[3]) Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, 03 Apr 2013 18:24:25 +1100, Chris Angelico wrote: On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico ros...@gmail.com wrote: Hmm. I was about to say Can you just do a quick collections.Counter() of the string widths in 3.3, as an easy way of seeing which ones use BMP or higher characters, but I can't find a simple way to query a string's width. Can't see it as a method of the string object, nor in the string or sys modules. It ought to be easy enough at the C level - just look up the two bits representing 'kind' - but I've not found it exposed to Python. Is there anything? 4 if max(map(ord, s)) 0x else 2 if max(map(ord, s)) 0xff else 1 Yeah, that's iterating over the whole string (twice, if it isn't width 4). Then don't write it as a one-liner :-P n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 Here's another way: (sys.getsizeof(s) - sys.getsizeof(''))/len(s) should work. There's probably also a way to do it using ctypes. The system already knows what the size is, I was hoping for an uber-quick inspection of the string header. I'm not sure that I would want strings to have a method reporting this, but it might be nice to have a function in the inspect module to do so. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 6:53 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Here's another way: (sys.getsizeof(s) - sys.getsizeof(''))/len(s) should work. Hmm, I had been under the impression that there was a certain base length below which strings all had the same size. Yes, that also works; though again, it's something that can be directly queried, at the C level. There's probably also a way to do it using ctypes. The system already knows what the size is, I was hoping for an uber-quick inspection of the string header. I'm not sure that I would want strings to have a method reporting this, but it might be nice to have a function in the inspect module to do so. Yeah, that's why I also looked in 'sys'; 'inspect' might well be a good place for it, too. But it seems such a function doesn't exist, which is what I was asking. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Apr 3, 12:37 pm, Neil Hodgson nhodg...@iinet.net.au wrote: Reran the programs taking a bit more care with the encoding of the file. This had no effect on the speeds. There are only a small amount of paths that don't fit into ASCII: ASCII 1076101 Latin1 218 BMP 113 Astral 0 # encoding:utf-8 import codecs, os, time from os.path import join, getsize with codecs.open(filelist.txt, r, utf-8) as f: paths = f.read().split(\n) bucket = [0,0,0,0] for p in paths: b = 0 maxChar = max([ord(ch) for ch in p]) if maxChar = 65536: b = 3 elif maxChar = 256: b = 2 elif maxChar = 128: b = 1 bucket[b] = bucket[b] + 1 print(ASCII, bucket[0]) print(Latin1, bucket[1]) print(BMP, bucket[2]) print(Astral, bucket[3]) Neil Can you please try one more experiment Neil? Knock off all non-ASCII strings (paths) from your dataset and try again. [It should take little more than converting your above code to a filter: if b == 0: print if b 0: ignore ] -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
This FSR is wrong by design. A naive way to embrace Unicode. jmf -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting USB volume serial number from inserted device on OSX
Apologies. The main app is in python, and I would like to know any alternative methods to do this in Python on OS X. Doesn't have to use the OS X APIs. I'll try elsewhere too though. Thanks On 3 April 2013 00:37, Ned Deily n...@acm.org wrote: In article CAEH=cXV0DJa6CCZ4T1RvL2L1g7D_mdDF4=52vugcm5mwt18...@mail.gmail.com, Sven sven...@gmail.com wrote: I am using Python 2.7 with pyobjc on Lion and NSNotification center to monitor any inserted USB volumes. This works fine. [...] Since your question really is about OS X APIs and not Python or even PyObjC, you're more likely to get a meaningful answer elsewhere. Try StackOverflow or one of the OS X lists. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list -- ./Sven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Roy Smith: On the other hand, how long did it take you to do the directory tree walk required to find those million paths? I'll bet a long longer than 0.78 seconds, so this gets lost in the noise. About 2 minutes. But that's just getting an example data set. Other data sets may be loaded more quickly from databases or files or be created by processing. Reading the example data from a file takes around the same time as sorting. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
rusi: Can you please try one more experiment Neil? Knock off all non-ASCII strings (paths) from your dataset and try again. Results are the same 0.40 (well, 0.001 less but I don't think the timer is that accurate) for Python 3.2 and 0.78 for Python 3.3. Neil -- http://mail.python.org/mailman/listinfo/python-list
Make python 3.3 the default one and not 2.7
Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . Thx in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
D. Xenakis gouzounakis at hotmail.com writes: Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . Thx in advance. Check out the post at http://stackoverflow.com/questions/4664646/how-to-change-default-python-version-on-windows-xp . Especially the part about changing the registry. The Python.File entry mentioned there also has the information about the IDLE version to use. Best, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 04/03/2013 04:22 AM, Neil Hodgson wrote: rusi: Can you please try one more experiment Neil? Knock off all non-ASCII strings (paths) from your dataset and try again. Results are the same 0.40 (well, 0.001 less but I don't think the timer is that accurate) for Python 3.2 and 0.78 for Python 3.3. Neil That would seem to imply that the speed regression on your data is NOT caused by the differing size encodings. Perhaps it is the difference in MSC compiler version, or other changes made between 3.2 and 3.3 Of course, I can't then explain why Steven didn't get the same results. Perhaps the difference between 32bit Python and 64 on Windows? Or perhaps you have significantly more (or significantly fewer) collisions than Steven did. Before I saw this message, I was thinking of suggesting that you supply a key= parameter to sort, specifying as a key the Unicode character 65536 higher than the one supplied. That way all the keys to be sorted would be 32 bits in size. If this made the timings change noticeably, it could be a big clue. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
On 04/03/2013 04:44 AM, D. Xenakis wrote: Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . Thx in advance. That was one of the choices you were presented with during the install. It defaults to making the newly installed one the default, but there was a checkbox or something. (It's been years since I did a Windows install, so I don't really remember) Anyway, if Wolfgang's link doesn't do it for you, consider re-installing 3.3. It should just go on top of the existing one, and the only change should be that it would then become the default one. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Solution found! Qpython+ will work on kindle fire (without live connection)
+ To: tu...@python.org tu...@python.org Sent: Monday, 1 April 2013 9:18 AM Subject: [Tutor] is there a simple stand alone python app I can use on my Kindle fire? Hello, I'm enjoying learning python, and would like to be able to study and practice on the go, using my kindle fire reader. (wifi enabled). Amazon does have an app, Qpython lite, but requires a live wifi connection to the internet to run. I'm looking for a simple python app, stand alone that i can run on my kindle, without an internet connection, just to practice while i learn. (Just a simple terminal, and text editor, and python? like ubuntu offers.) I've tried downloading portable python, and couldnt' get it to run ('can't run in DOS mode?'), I've tried downloading ubuntu to my kindle and couldn't, and tried downloading the whole 2.7 python app, but couldn't get it to run. I tried to root my kindle, but as I'm inexperienced in things tech, i'm not sure if I was successful, and not sure how this helps (if I was successful.) I have both windows 7 and ubuntu (dual boot) on my laptop, and can connect my kindle to the laptop via usb cable. I have accept downloads from other applications enabled on my kindle. On my kindle I have 'better terminal emulator pro' , ES file explorer, and droidedit. Any help is appreciated, I'm willing to follow step by step instructions to get python running on my kindle. I will supply any other details required. My kindle fire specs are : Model D01400 The Kindle Fire features a 7” display module from LG Display. The display is dual-sourced between LG Display and E Ink Holdings. The display touchscreen appears to be conventional capacitive glass on glass and the control IC on the touchscreen is from a previously unseen source. Meanwhile, the OMAP4430 applications processor from Texas Instruments is a dual-core RM Cortex-A9, 1GHz processor with IVA 3 Hardware Accelerator, SGX540 3D Graphic Core, 1080P 2D, 720P 3D and is produced in 45nm process geometry. Other key features include a 8GB eMMC NAND Flash Memory, 4Gbits of low power DDR2, a 3.7V battery with 4400mAh capacity (or about 16 Wh), and a module from Jorjin, which is based on Texas Instruments’ WL1270. ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor-- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Dave Angel: That would seem to imply that the speed regression on your data is NOT caused by the differing size encodings. Perhaps it is the difference in MSC compiler version, or other changes made between 3.2 and 3.3 Its not caused by there actually being different size encodings but that the code is checking encoding size 2-4 times for each character. Back in 3.2 the comparison loop looked like: while (len1 0 len2 0) { Py_UNICODE c1, c2; c1 = *s1++; c2 = *s2++; if (c1 != c2) return (c1 c2) ? -1 : 1; len1--; len2--; } For 3.3 this has changed to for (i = 0; i len1 i len2; ++i) { Py_UCS4 c1, c2; c1 = PyUnicode_READ(kind1, data1, i); c2 = PyUnicode_READ(kind2, data2, i); if (c1 != c2) return (c1 c2) ? -1 : 1; } with PyUnicode_READ being #define PyUnicode_READ(kind, data, index) \ ((Py_UCS4) \ ((kind) == PyUnicode_1BYTE_KIND ? \ ((const Py_UCS1 *)(data))[(index)] : \ ((kind) == PyUnicode_2BYTE_KIND ? \ ((const Py_UCS2 *)(data))[(index)] : \ ((const Py_UCS4 *)(data))[(index)] \ ) \ )) There are either 1 or 2 kind checks in each call to PyUnicode_READ and 2 calls to PyUnicode_READ inside the loop. A compiler may decide to move the kind checks out of the loop and specialize the loop but MSVC 2010 appears to not do so. The assembler (32-bit build) for each PyUnicode_READ looks like mov ecx, DWORD PTR _kind1$[ebp] cmp ecx, 1 jne SHORT $LN17@unicode_co@2 lea ecx, DWORD PTR [ebx+eax] movzx edx, BYTE PTR [ecx+edx] jmp SHORT $LN16@unicode_co@2 $LN17@unicode_co@2: cmp ecx, 2 jne SHORT $LN15@unicode_co@2 movzx edx, WORD PTR [ebx+edi] jmp SHORT $LN16@unicode_co@2 $LN15@unicode_co@2: mov edx, DWORD PTR [ebx+esi] $LN16@unicode_co@2: The kind1/kind2 variables aren't even going into registers and at least one test+branch and a jump are executed for every character. Two tests for 2 and 4 byte kinds. len1 and len2 don't get to go into registers either. Here's the full assembler output for unicode_compare: ; COMDAT _unicode_compare _TEXT SEGMENT _kind2$ = -20 ; size = 4 _kind1$ = -16 ; size = 4 _len2$ = -12; size = 4 _len1$ = -8 ; size = 4 _data2$ = -4; size = 4 _unicode_compare PROC ; COMDAT ; _str1$ = ecx ; _str2$ = eax ; 10417: { pushebp mov ebp, esp sub esp, 20 ; 0014H pushebx pushesi mov esi, eax ; 10418: int kind1, kind2; ; 10419: void *data1, *data2; ; 10420: Py_ssize_t len1, len2, i; ; 10421: ; 10422: kind1 = PyUnicode_KIND(str1); mov eax, DWORD PTR [ecx+16] mov edx, eax shr edx, 2 and edx, 7 pushedi mov DWORD PTR _kind1$[ebp], edx ; 10423: kind2 = PyUnicode_KIND(str2); mov edx, DWORD PTR [esi+16] mov edi, edx shr edi, 2 and edi, 7 mov DWORD PTR _kind2$[ebp], edi ; 10424: data1 = PyUnicode_DATA(str1); testal, 32 ; 0020H je SHORT $LN9@unicode_co@2 testal, 64 ; 0040H je SHORT $LN7@unicode_co@2 lea ebx, DWORD PTR [ecx+24] jmp SHORT $LN10@unicode_co@2 $LN7@unicode_co@2: lea ebx, DWORD PTR [ecx+36] jmp SHORT $LN10@unicode_co@2 $LN9@unicode_co@2: mov ebx, DWORD PTR [ecx+36] $LN10@unicode_co@2: ; 10425: data2 = PyUnicode_DATA(str2); testdl, 32 ; 0020H je SHORT $LN13@unicode_co@2 testdl, 64 ; 0040H je SHORT $LN11@unicode_co@2 lea edx, DWORD PTR [esi+24] jmp SHORT $LN30@unicode_co@2 $LN11@unicode_co@2: lea eax, DWORD PTR [esi+36] mov DWORD PTR _data2$[ebp], eax mov edx, eax jmp SHORT $LN14@unicode_co@2 $LN13@unicode_co@2: mov edx, DWORD PTR [esi+36] $LN30@unicode_co@2: mov DWORD PTR _data2$[ebp], edx $LN14@unicode_co@2: ; 10426: len1 = PyUnicode_GET_LENGTH(str1); mov edi, DWORD PTR [ecx+8] ; 10427: len2 = PyUnicode_GET_LENGTH(str2); mov ecx, DWORD PTR [esi+8] ; 10428: ; 10429: for (i = 0; i len1 i len2; ++i) { xor eax, eax mov DWORD PTR _len1$[ebp], edi mov DWORD
Twisted 13.0.0 released
On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 13.0. Among the 70 tickets closed, we can see: * A new Introduction to Deferreds document that you can find here: http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html * A fix in twisted.web.template where attributes were not quoted properly, risking HTML injection. * Support for unicode domain names in twisted.names SRVConnector and Name classes, after a 12.3 regression. * A workaround for platform limitations when trying to schedule events far in the future. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/13.0/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-13.0.0.tar.bz2 or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-13.0.0.win32-py2.7.msi Thanks to the supporters of Twisted via the Software Freedom Conservancy and to the many contributors for this release. -- Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 03/04/2013 09:08, jmfauth wrote: This FSR is wrong by design. A naive way to embrace Unicode. jmf The hole you're digging for yourself is getting bigger and bigger and I'm loving it :) -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 04/03/2013 07:05 AM, Neil Hodgson wrote: Dave Angel: That would seem to imply that the speed regression on your data is NOT caused by the differing size encodings. Perhaps it is the difference in MSC compiler version, or other changes made between 3.2 and 3.3 Its not caused by there actually being different size encodings but that the code is checking encoding size 2-4 times for each character. Back in 3.2 the comparison loop looked like: while (len1 0 len2 0) { Py_UNICODE c1, c2; c1 = *s1++; c2 = *s2++; if (c1 != c2) return (c1 c2) ? -1 : 1; len1--; len2--; } For 3.3 this has changed to for (i = 0; i len1 i len2; ++i) { Py_UCS4 c1, c2; c1 = PyUnicode_READ(kind1, data1, i); c2 = PyUnicode_READ(kind2, data2, i); if (c1 != c2) return (c1 c2) ? -1 : 1; } with PyUnicode_READ being #define PyUnicode_READ(kind, data, index) \ ((Py_UCS4) \ ((kind) == PyUnicode_1BYTE_KIND ? \ ((const Py_UCS1 *)(data))[(index)] : \ ((kind) == PyUnicode_2BYTE_KIND ? \ ((const Py_UCS2 *)(data))[(index)] : \ ((const Py_UCS4 *)(data))[(index)] \ ) \ )) There are either 1 or 2 kind checks in each call to PyUnicode_READ and 2 calls to PyUnicode_READ inside the loop. A compiler may decide to move the kind checks out of the loop and specialize the loop but MSVC 2010 appears to not do so. I don't know how good MSC's template logic is, but it seems this would be a good case for an explicit template, typed on the 'kind's values. Or are all C++ features disabled when compiling Python? Failing that, just code up 9 cases, and do a switch on the kinds. I'm also puzzled. I thought that the sort algorithm used a hash of all the items to be sorted, and only reverted to a raw comparison of the original values when the hash collided. Is that not the case? Or is the code you post here only used when the hash collides? The assembler (32-bit build) for each PyUnicode_READ looks like movecx, DWORD PTR _kind1$[ebp] cmpecx, 1 jneSHORT $LN17@unicode_co@2 leaecx, DWORD PTR [ebx+eax] movzxedx, BYTE PTR [ecx+edx] jmpSHORT $LN16@unicode_co@2 $LN17@unicode_co@2: cmpecx, 2 jneSHORT $LN15@unicode_co@2 movzxedx, WORD PTR [ebx+edi] jmpSHORT $LN16@unicode_co@2 $LN15@unicode_co@2: movedx, DWORD PTR [ebx+esi] $LN16@unicode_co@2: It appears that the compiler is keeping the three pointers in three separate registers (eax, esi and edi) even though those are 3 aliases for the same pointer. This is preventing it from putting other values in those registers. It'd probably do better if the C code manipulated the pointers, rather than using an index i each time. But if it did, perhaps gcc would generate worse code. If I were coding the assembler by hand (Intel only), I'd be able to avoid the multiple cmp operations, simply by comparing first to 2, then doing a jne and a ja. I dunno whether the compiler would notice if I coded the equivalent in C. (make both comparisons to 2, one for less, and one for more) The kind1/kind2 variables aren't even going into registers and at least one test+branch and a jump are executed for every character. Two tests for 2 and 4 byte kinds. len1 and len2 don't get to go into registers either. Here's the full assembler output for unicode_compare: ;COMDAT _unicode_compare _TEXTSEGMENT _kind2$ = -20; size = 4 _kind1$ = -16; size = 4 _len2$ = -12; size = 4 _len1$ = -8; size = 4 _data2$ = -4; size = 4 _unicode_compare PROC; COMDAT ; _str1$ = ecx ; _str2$ = eax ; 10417: { pushebp movebp, esp subesp, 20; 0014H pushebx pushesi movesi, eax ; 10418: int kind1, kind2; ; 10419: void *data1, *data2; ; 10420: Py_ssize_t len1, len2, i; ; 10421: ; 10422: kind1 = PyUnicode_KIND(str1); moveax, DWORD PTR [ecx+16] movedx, eax shredx, 2 andedx, 7 pushedi movDWORD PTR _kind1$[ebp], edx ; 10423: kind2 = PyUnicode_KIND(str2); movedx, DWORD PTR [esi+16] movedi, edx shredi, 2 andedi, 7 movDWORD PTR _kind2$[ebp], edi ; 10424: data1 = PyUnicode_DATA(str1); testal, 32; 0020H jeSHORT $LN9@unicode_co@2 testal, 64; 0040H jeSHORT $LN7@unicode_co@2 leaebx, DWORD PTR [ecx+24] jmpSHORT $LN10@unicode_co@2 $LN7@unicode_co@2: leaebx, DWORD PTR [ecx+36] jmpSHORT $LN10@unicode_co@2 $LN9@unicode_co@2: movebx, DWORD PTR
Re: Tkinter
On Tue, Apr 2, 2013 at 10:04 PM, Renato Barbosa Pim Pereira renato.barbosa.pim.pere...@gmail.com wrote: Thanks for the advices, I need now one scrollbar to roll under screen, I created the scrollbar but cant roll, please help me on this. http://pastebin.com/L6XWY6cm You need to bind your scrollbar to a particular action. It does not roll because you never told it what 'rolling' should do. That said, you need to bind your scrollbar command to a widget that actually supports scrolling. According to [1], your options are the Listbox, Text, Canvas, and Entry widgets. What that means is that you will need to replace your Frame widget with a Canvas widget (or embed a Canvas in your Frame, although with your existing code that latter approach does not serve much purpose). Then bind your scrollbar command to the xview method of your Canvas instance (or the yview method of your Canvas instance if you want to scroll vertically). HTH, Jason [1] http://effbot.org/zone/tkinter-scrollbar-patterns.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
On 03/04/2013 09:44, D. Xenakis wrote: Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . Thx in advance. Not quite answering your question but are you aware of http://docs.python.org/3/using/windows.html#launcher ? -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating a dictionary from a .txt file
On 2013-04-01, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Mon, 01 Apr 2013 11:41:03 +, Neil Cerutti wrote: I tried searching for Frost*, an interesting artist I recently learned about. Interesting artist -- is that another term for wanker? *wink* hee-hee. It depends on how much of a hankering you have for pretentious progressive synth-rock. His name, in combination with a similarly named rap artist, breaks most search tools. As far as I'm concerned, anyone in the 21st century who names themselves or their work (a movie, book, programming language, etc.) something which breaks search tools is just *begging* for obscurity, and we ought to respect their wishes. I do think it's something he did on purpose. The asterisk, I believe, symbolizes the exclusive genius of his fans. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: How to choose between ORMs?
In article mailman.35.1364969706.3114.python-l...@python.org, Alec Taylor alec.tayl...@gmail.com wrote: SQLalchemy and Storm are a few of the popular ORMs out there. Personally I have been using web2py's DAL. Other than form generator availability, 'print as raw SQL', multiple primary keys, widgets*, `check` conditions and compatibility with OracleDB, Postgres, SQLite and some of the NoSQL systems; what else should I be looking for? Depending on what you're doing, schema discovery (aka introspection, reflection, etc) may or may not be important to you. And it should come with a nice shrubbery. -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
I tried to reinstall python 3.3 but there was not change :(. I selected to run all component from my PC. I'll give it a try with those registries. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
In article 1f2dnfpbhy54embmnz2dnuvz_osdn...@westnet.com.au, Neil Hodgson nhodg...@iinet.net.au wrote: Roy Smith: On the other hand, how long did it take you to do the directory tree walk required to find those million paths? I'll bet a long longer than 0.78 seconds, so this gets lost in the noise. About 2 minutes. But that's just getting an example data set. Other data sets may be loaded more quickly from databases or files or be created by processing. Reading the example data from a file takes around the same time as sorting. Fair enough. In fact, given that reading the file from disk is O(n) and sorting it is O(n log n), at some point, the sort will totally swamp the input time. Your original example just happened to be one of the unusual cases where the sort time is not the rate limiting factor in the overall process. I remember reading somewhere that more CPU cycles in the entire history of computing have been spend doing sorting than anything else. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
In article mailman.37.1364970149.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Wed, Apr 3, 2013 at 3:03 PM, Neil Hodgson nhodg...@iinet.net.au wrote: rusi wrote: Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can. In my personal experience, it's calculators. I put command-line calculators into *everything*... often in the form of more general executors, and thus restricted to admins, but it's still a calculator. For some reason, the ability to type calc 1+2 and get back 3 is very satisfying to me. You know, in case I ever forget what one plus two makes. I discovered recently that Spotlight (the OSX built-in search engine) can do this. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Thu, Apr 4, 2013 at 12:28 AM, Roy Smith r...@panix.com wrote: In article mailman.37.1364970149.3114.python-l...@python.org, Chris Angelico ros...@gmail.com wrote: On Wed, Apr 3, 2013 at 3:03 PM, Neil Hodgson nhodg...@iinet.net.au wrote: rusi wrote: Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can. In my personal experience, it's calculators. I put command-line calculators into *everything*... often in the form of more general executors, and thus restricted to admins, but it's still a calculator. For some reason, the ability to type calc 1+2 and get back 3 is very satisfying to me. You know, in case I ever forget what one plus two makes. I discovered recently that Spotlight (the OSX built-in search engine) can do this. Good feature, not surprising. Google Search has had that feature for a while, and it just feels right to be able to look up information the same way regardless of its source. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Thu, Apr 4, 2013 at 12:25 AM, Roy Smith r...@panix.com wrote: Fair enough. In fact, given that reading the file from disk is O(n) and sorting it is O(n log n), at some point, the sort will totally swamp the input time. But given the much larger fixed cost of disk access, that might take an awful lot of strings... ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Threading within a GUI and OpenCV
Hey, I'm fairly new to python, and have had no experience with threading. Iv made a small GUI App using the kivy module and OpenCV, i have currently got a button that when pressed runs a function that records from my webcam for 20 seconds. However i have two other buttons, that when pressed i want to stop the recording. However when the button to record has been pressed the App freezes until the recording function has finished. I have read that threading can be used to run a function as a deamon? so that other functions can be ran simultaneously? I was just wondering if this would be the way to go, or if there are alternative routes? A snippet from my code can be seen at (http://pastebin.com/9uFRjkgV) with a failed attempt of using threading! Any help would be appreciated. Thanks, Sam -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
In article 515be00e$0$29891$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 18:24:25 +1100, Chris Angelico wrote: On Wed, Apr 3, 2013 at 6:06 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Wed, Apr 3, 2013 at 12:52 AM, Chris Angelico ros...@gmail.com wrote: Hmm. I was about to say Can you just do a quick collections.Counter() of the string widths in 3.3, as an easy way of seeing which ones use BMP or higher characters, but I can't find a simple way to query a string's width. Can't see it as a method of the string object, nor in the string or sys modules. It ought to be easy enough at the C level - just look up the two bits representing 'kind' - but I've not found it exposed to Python. Is there anything? 4 if max(map(ord, s)) 0x else 2 if max(map(ord, s)) 0xff else 1 Yeah, that's iterating over the whole string (twice, if it isn't width 4). Then don't write it as a one-liner :-P n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it I'm reasonably sure all() is smart enough to stop at the first False value. (sys.getsizeof(s) - sys.getsizeof(''))/len(s) I wouldn't trust getsizeof() to return exactly what you're looking for. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 02/04/2013 10:28, Neil Hodgson wrote: jmfauth: 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] [0.8343414906182101, 0.8336184057396241, 0.8330473419738562] 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit [1.3840254166697845, 1.3933888932429768, 1.391664674507438] That's a larger performance decrease than the 64-bit version. Reported the issue as http://bugs.python.org/issue17615 Neil FTR this has been closed as fixed see http://bugs.python.org/issue17615#msg185862 -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Mixin way?
I have some classes that have shared behaviours, for example in our scenario an object can be visited, where something that is visitable would have some behaviour like --8---cut here---start-8--- class Visitable(Mixin): FIELDS = { 'visits': [], 'unique_visits': 0, } def record_view(self, who, when): self.visits += {'who': who, 'when': when} self.unique_visits += 1 --8---cut here---end---8--- Where the Mixin class simply initialises the attributes: --8---cut here---start-8--- class Mixin(object): def __init__(self, **kwargs): for key, val in self.FIELDS.items(): setattr(self, key, val) for key, val in kwargs.items(): if key in self.FIELDS: setattr(self, key, val) --8---cut here---end---8--- So now I'm not sure how to use it though. One way would be multiple subclasses class MyObjectBase(object): pass class MyObj(MyObjectBase, Visitable): pass for example. This solution is probably easy, but at the same time disturbing because MyObjectBase is semantically quite different from Visitable, so subclassing from both seems wrong.. The other solution (which is what is partially done now) is to use another class attribute: class ObjectWithMixin(CouchObject): MIXINS = [Visitable] and then do all the smart things needed: - at object construction time - when setting attributes and so on.. This solution is more complicated to implement but maybe is more flexible and more correct, what do you think? -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
Τη Τετάρτη, 3 Απριλίου 2013 12:43:43 μ.μ. UTC+3, ο χρήστης Wolfgang Maier έγραψε: D. Xenakis gouzounakis at hotmail.com writes: Hi there, i installed python 2.7 (windows 32bit version) from http://www.enthought.com/products/epd_free.php and after that i installed official 3.3 version too. So now i got two python folders like this.. c:/Python27 and c:/Python33 . My problem is that when im trying to execute a .py file, the 2.7 version interpreter launces. In addition if i right click and select Edit with IDLE, again version 2.7 interpreter opens. How can i make python 3.3 the default one, as i need this cause i have PyQt4 installed there and so it does not work with 2.7 . Thx in advance. Check out the post at http://stackoverflow.com/questions/4664646/how-to-change-default-python-version-on-windows-xp . Especially the part about changing the registry. The Python.File entry mentioned there also has the information about the IDLE version to use. Best, Wolfgang I changed this too Python.CompiledFile to my 33 version. Should i not touch this key? -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Thu, Apr 4, 2013 at 12:43 AM, Roy Smith r...@panix.com wrote: This has to inspect the entire string, no? I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it I'm reasonably sure all() is smart enough to stop at the first False value. Probably, but it still has to scan the body of the string. It'd not be too bad if it's all astral, but if it's all BMP, it has to scan the whole string. In the max() case, it has to scan the whole string anyway, as there's no other way to determine the maximum. I'm thinking here of this function: http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/width.html It's implemented as a simple lookup into the header. (Pike strings, like PEP 393 strings, are stored in the most compact way possible - 1, 2, or 4 bytes per character - with a conceptually similar header structure.) Is this something that would be worth having available? Should I post an issue about it? ChrisA more for self-ref than anyone else's: source of Pike's String.width(): http://pike-git.lysator.liu.se/gitweb.cgi?p=pike.git;a=blob;f=src/builtin.cmod;hb=HEAD#l1077 -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
D. Xenakis gouzounakis at hotmail.com writes: The Python.File entry mentioned there also has the information about the IDLE version to use. Best, Wolfgang I changed this too Python.CompiledFile to my 33 version. Should i not touch this key? The [.CompiledFile\shell\open\command] sets the python version used for running pre-compiled .pyc files. Likewise, [.NoConFile\shell\open\command] sets it for .pyw files (intended to be run not from a console window - hence the name of the entry). Usually, you will want to have all of them point to the same Python version. Best, Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Sorting [was Re: Performance of int/long in Python 3]
On Wed, 03 Apr 2013 07:52:42 -0400, Dave Angel wrote: I thought that the sort algorithm used a hash of all the items to be sorted, and only reverted to a raw comparison of the original values when the hash collided. Is that not the case? Or is the code you post here only used when the hash collides? Sorting does not require that the elements being sorted are hashable. If I have understood the implementation here: http://hg.python.org/releasing/3.3.1/file/2ab2a09901f9/Objects/listobject.c sorting in Python only requires that objects implement the less-than comparison. py class Funny: ... def __init__(self, x): ... self.x = x ... def __lt__(self, other): ... return self.x other.x ... def __gt__(self, x): ... raise AttributeError ... __le__ = __ge__ = __eq__ = __ne__ = __gt__ ... py L = [Funny(i) for i in range(10)] py random.shuffle(L) py [f.x for f in L] [8, 5, 7, 0, 9, 2, 3, 6, 1, 4] py [f.x for f in sorted(L)] [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] but if I change Funny.__lt__ to also raise, sorting fails. I seem to recall that sort relies only on operator is a language promise, but I can't seem to find it documented anywhere official. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n 0x: return 4 if n 0xFF: return 2 return 1 I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it It's not astral crap. People use it, and they'll use it more in the future. Just because you don't, doesn't give you leave to make disparaging remarks about it. Honestly, it's really painful to see how history repeats itself: Bah humbug, why do we need to support the SMP astral crap? The Unicode BMP is more than enough for everybody. Bah humbug, why do we need to support Unicode crap? Latin1 is more than enough for everybody. Bah humbug, why do we need to support Latin1 crap? ASCII is more than enough for everybody. Bah humbug, why do we need to support ASCII crap? Uppercase A-Z is more than enough for everybody. Seriously. Go back long enough, to the telegraph days, and you have people arguing that there was no need for upper and lower case letters. I'm reasonably sure all() is smart enough to stop at the first False value. Yes, all() and any() are guaranteed to be short-circuit functions. They will stop as soon as they see a False or a True value respectively. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Sorting [was Re: Performance of int/long in Python 3]
In article 515c400e$0$29966$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: I seem to recall that sort relies only on operator is a language promise, but I can't seem to find it documented anywhere official. That's pretty typical for sort implementations in all languages. Except for those which rely on less than and equal to :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Thu, 04 Apr 2013 01:17:28 +1100, Chris Angelico wrote: Probably, but it still has to scan the body of the string. It'd not be too bad if it's all astral, but if it's all BMP, it has to scan the whole string. In the max() case, it has to scan the whole string anyway, as there's no other way to determine the maximum. I'm thinking here of this function: http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/ width.html It's implemented as a simple lookup into the header. (Pike strings, like PEP 393 strings, are stored in the most compact way possible - 1, 2, or 4 bytes per character - with a conceptually similar header structure.) Is this something that would be worth having available? Should I post an issue about it? I'm not really sure why I would want to know, apart from pure intellectual curiosity, but sure, post a feature request. Be sure to mention that Pike supports this feature. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixin way?
On Wed, 03 Apr 2013 15:04:51 +0100, andrea crotti wrote: I have some classes that have shared behaviours, for example in our scenario an object can be visited, where something that is visitable would have some behaviour like [snip mixins] By the way, it's a common convention to name mixin classes as SpamMixin. So now I'm not sure how to use it though. One way would be multiple subclasses class MyObjectBase(object): pass class MyObj(MyObjectBase, Visitable): pass for example. What's the purpose of MyObjectBase? Either your example is too simple, or it actually has no purpose, and you should simply write: class MyObj(object, VisitableMixin): # code goes here instead of having one extra layer in the inheritance hierarchy. This solution is probably easy, but at the same time disturbing because MyObjectBase is semantically quite different from Visitable, so subclassing from both seems wrong.. Not really. From what you describe, this seems to be exactly the use-case for mixins. Yes, mixins are by definition somewhat of an abuse of Object- Oriented concepts. Mixins don't so much represent a type of thing as a convenient bundle of encapsulated behaviour and/or state. E.g. MyObj represents some sort of MyObj thing (or at least it *should*, if your OO classes are well-planned), but Visitable(Mixin) does not represent a thing at all. But here's a way to look at it to justify the concept of mixins. Think of regular classes and subclasses as representing trees of descent, like biological groups: Animal - Mammal - Rodent - Porcupine Animal - Monotreme - Echidna Then mixins represent convergent evolution of some trait: Animal - Mammal - Rodent + QuillsMixin - Porcupine Animal - Monotreme + QuillsMixin - Echidna The other solution (which is what is partially done now) is to use another class attribute: class ObjectWithMixin(CouchObject): MIXINS = [Visitable] and then do all the smart things needed: - at object construction time - when setting attributes and so on.. This solution is more complicated to implement but maybe is more flexible and more correct, what do you think? I think that's worse. You seem to have *almost* stumbled onto the design pattern known as composition or delegation, only not quite. Normal class-based design models a is-a relationship. Lassie is a Dog, so we would do: lassie = Dog() Composition models a has-a relationship. For example, both cars and boats have engines, so we might be tempted to use a mixin: class Car(EngineMixin): pass class Boat(EngineMixin): pass which isn't an awful solution. But a conceptually cleaner solution might be to do this: class Car: def __init__(self): self.engine = Engine() def go(self): print Fasten your seat belt self.engine.start() self.handbrake = False self.change_gear(drive) self.accelerate() class Boat: def __init__(self): self.engine = Engine() def go(self): ... and then both cars and boats can *delegate* behaviour to the engine object. So, if you think of Visitable as a gadget that can be strapped onto your MyObj as a component, then composition is probably a better design. But if you think of Visitable as a mere collection of behaviour and state, then a mixin is probably a better design. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Apr 3, 6:43 pm, Roy Smith r...@panix.com wrote: This has to inspect the entire string, no? I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it Astral crap? CRAP? Verily sir I am offended! You dont play with Mahjong characters? How crude! You dont know about cuneiform? How illiterate! You dont compose poetry with Egyptian hieroglyphs? How rude! Shavian has not reformed you? How backward! In short you are a complete philistine No… On second thoughts I take that back. For all we know philistine may be one of the blessings of the Unicode gods? So following the ilustrious example of jmf, I shall pronounce upon you the ultimate curse: You are American! -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixin way?
2013/4/3 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info [snip] So, if you think of Visitable as a gadget that can be strapped onto your MyObj as a component, then composition is probably a better design. But if you think of Visitable as a mere collection of behaviour and state, then a mixin is probably a better design. Well I can explain better the situation to make it more clear. We are using CouchDb and so far it has been (sigh) a brutal manipulation of dictionaries everywhere, with code duplication and so on. Now I wanted to encapsulate all the entities in the DB in proper objects, so I have a CouchObject: class CouchObject(object) : Encapsulate an object which has the ability to be saved to a couch database. #: list of fields that get filled in automatically if not passed in AUTO = ['created_datetime', 'doc_type', '_id', '_rev'] #: dictionary with some extra fields with default values if not # passed in the constructor the default value gets set to the attribute DEFAULTS = {} REQUIRED = [] OPTIONAL = [] TO_RESOLVE = [] MIXINS = [] Where every subclass can redefine these attributes to get something done automatically by the constructor for convenience. Now however there is a lot of behaviour shared between them, so I want to encapsulate it out in different places. I think the MIXINS as I would use it is the normal composition pattern, the only difference is that the composition is done per class and not per object (again for lazyness reasons), right? Probably subclassing might be fine as well, and makes it simpler, but I don't like too much to do subclass from multiple classes... -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 5:52 AM, Dave Angel da...@davea.name wrote: I'm also puzzled. I thought that the sort algorithm used a hash of all the items to be sorted, and only reverted to a raw comparison of the original values when the hash collided. Is that not the case? Or is the code you post here only used when the hash collides? I think you are mistaken, because I don't see how that could work. If the hashes of two items are different then you can assume they are not equal, but sorting requires a partial ordering comparison, not simply an equality comparison. You cannot determine which item is less or greater than the other from the hash values alone. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n 0x: return 4 if n 0xFF: return 2 return 1 That's an incorrect implementation, as it would return 2 at the first non-Latin-1 BMP character, even if there were SMP characters later in the string. It's only safe to short-circuit return 4, not 2 or 1. -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, Apr 3, 2013 at 1:53 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: (sys.getsizeof(s) - sys.getsizeof(''))/len(s) s = '\x80\x81\x82\x83\x84\x85' len(s) 6 import sys sys.getsizeof(s) 43 sys.getsizeof(s) - sys.getsizeof('') 18 (sys.getsizeof(s) - sys.getsizeof('')) / len(s) 3.0 I didn't know there was a 3-byte-width representation. :-) More seriously, it fails because '' is ASCII and s is not, and the overhead for the two strings is different. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to choose between ORMs?
Pick the one you learn and know. Sent from my iPhone On Apr 3, 2013, at 2:17 AM, Alec Taylor alec.tayl...@gmail.com wrote: SQLalchemy and Storm are a few of the popular ORMs out there. Personally I have been using web2py's DAL. Other than form generator availability, 'print as raw SQL', multiple primary keys, widgets*, `check` conditions and compatibility with OracleDB, Postgres, SQLite and some of the NoSQL systems; what else should I be looking for? Thanks for all suggestions, Alec Taylor *not sure if widgets should be a requirement; by widgets I mean annotation of db schema to specify which widget to use with the form generator PS: Will likely use this ORM with: Flask, Bottle or Twisted Matrix -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 04/03/2013 09:10 AM, rusi wrote: On Apr 3, 6:43 pm, Roy Smith r...@panix.com wrote: This has to inspect the entire string, no? I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it Astral crap? CRAP? Verily sir I am offended! You dont play with Mahjong characters? How crude! You dont know about cuneiform? How illiterate! You dont compose poetry with Egyptian hieroglyphs? How rude! Shavian has not reformed you? How backward! In short you are a complete philistine No… On second thoughts I take that back. For all we know philistine may be one of the blessings of the Unicode gods? So following the ilustrious example of jmf, I shall pronounce upon you the ultimate curse: You are American! LOL! -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixin way?
On 2013-04-03, andrea crotti andrea.crott...@gmail.com wrote: Well I can explain better the situation to make it more clear. We are using CouchDb and so far it has been (sigh) a brutal manipulation of dictionaries everywhere, with code duplication and so on. Now I wanted to encapsulate all the entities in the DB in proper objects, so I have a CouchObject: class CouchObject(object) : Encapsulate an object which has the ability to be saved to a couch database. #: list of fields that get filled in automatically if not passed in AUTO = ['created_datetime', 'doc_type', '_id', '_rev'] #: dictionary with some extra fields with default values if not # passed in the constructor the default value gets set to the attribute DEFAULTS = {} REQUIRED = [] OPTIONAL = [] TO_RESOLVE = [] MIXINS = [] Where every subclass can redefine these attributes to get something done automatically by the constructor for convenience. Hopefully someone with experience with them can help you further, but this seems like a job for a metaclass. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Wed, 03 Apr 2013 10:38:20 -0600, Ian Kelly wrote: On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n 0x: return 4 if n 0xFF: return 2 return 1 That's an incorrect implementation, as it would return 2 at the first non-Latin-1 BMP character, even if there were SMP characters later in the string. It's only safe to short-circuit return 4, not 2 or 1. Doh! I mean, well done sir, you have successfully passed my little test! -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 04/03/2013 12:30 PM, Ian Kelly wrote: On Wed, Apr 3, 2013 at 5:52 AM, Dave Angel da...@davea.name wrote: I'm also puzzled. I thought that the sort algorithm used a hash of all the items to be sorted, and only reverted to a raw comparison of the original values when the hash collided. Is that not the case? Or is the code you post here only used when the hash collides? I think you are mistaken, because I don't see how that could work. If the hashes of two items are different then you can assume they are not equal, but sorting requires a partial ordering comparison, not simply an equality comparison. You cannot determine which item is less or greater than the other from the hash values alone. You are of course correct. The particular data that Neil had provided might well have had many duplicates, but that won't be the typical case, so there's not much point in doing an unordered hash. I guess I was confusing it with the key= argument for modifying sort order, where the key function might replace a slow-to-compare data type with something faster. -- DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: Python install Win 7 Problem
On 2013-04-02, balasubramanian Achuthan balasu...@gmail.com wrote: Try using Activestate python. The free version would suffice your needs and it comes with a clean install. I have been travelling and have not had time to read this thread in detail so this may be old hat but on Windows (at work) I simply install Python(x,y) https://code.google.com/p/pythonxy/ /Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python install Win 7 Problem
On 4/3/2013 1:51 PM, Martin Schöön wrote: On 2013-04-02, balasubramanian Achuthan balasu...@gmail.com wrote: Try using Activestate python. The free version would suffice your needs and it comes with a clean install. I have been travelling and have not had time to read this thread in detail so this may be old hat but on Windows (at work) I simply install Python(x,y) https://code.google.com/p/pythonxy/ Only available for 2.x -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE printing problem
On 4/3/2013 12:24 PM, Joe Hill wrote: On 4/3/2013 12:24 PM, Joe Hill wrote: I attempted to print about 10 pages of documentation from the help files using IDLE. On all the pages the side of each page was missing about 1/4 inch of text. You neglected to say what you actually did to have a problem. I tried the following with the font set to the default Courier. help(tuple) a page and a half of help text print to Canon inkjet or HP Laserjet 5 Everything printed, with longest lines just fitting within the margins. Am I missing a setting? Is this a known problem? Will it do the same with lines of code? Printing depends on font, font size, OS printer driver, and printer. I suspect Idle just sends print command to tk text widget. Its 'print dialog' is as primitive as possible: the only choice is to print to the default printer or not; no printer choice, no page setup. Tk, in turn, should just put the text in a temporary file and turn it over to the OS printer driver. Using W7, 64 bit. PY 3.3. It worked just fine when I pasted the text in Word 2010. I am sure it is has more knowledge about the vagaries of printing. You might try a single page (with max length lines) after Word prints to see if it left the printer in a better state. -- http://mail.python.org/mailman/listinfo/python-list
Re: Time zone changing while Win app is running
2013-04-03 14:41:13.124000 WRONG ^ (That carrot is supposed to be pointing to the 4 in 14, which should be 18.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Time zone changing while Win app is running
On Apr 3, 7:37 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Tue, 02 Apr 2013 17:04:12 -0700, CM wrote: To summarize the issue: In an application, I have been using Python's datetime module to get the current time. But it seems that, at least with Windows (XP), whatever time zone your computer is set to when you start the application, that's what datetime will use--the time zone will *not* be updated in the application when you update it manually with Windows. So, if you change the time zone (say, after traveling with your laptop), all datetimes will be incorrect as compared to your system clock. I am not the maintainer of the datetime module, but based purely on what you have said, I would consider that a bug. I suggest you report it as an issue on the Python bug tracker. Thanks, I submitted an issue about it. On 2.7.3, on Windows, it's easy to demonstrate: (Actual time = 2:40pm; tz = Eastern U.S.) import datetime print datetime.datetime.now() 2013-04-03 14:40:03.124000 RIGHT (Now change time zone to UTC, for example. Now clock reads 6:41pm.) import datetime print datetime.datetime.now() 2013-04-03 14:41:13.124000 WRONG ^ -- http://mail.python.org/mailman/listinfo/python-list
Distributing a Python program hell
I'm struggling with radio hams who are trying to get my antique Teletype program running. I hate having to write instructions like this: Installation instructions (Windows): Download and install Python 2.7 (32-bit) if not already installed. (Python 2.6 or 2.7 is required; pyserial will not work correctly on older versions, and feedparser is not supported in 3.x versions.) Install the Python module setuptools from the Python Package Index. (Needed by other installers. Has a Windows installer.) Install the Python module feedparser from Google Code. (Unpack ZiP file, run setup.py install) Install the Python module pyserial from SourceForge. (Windows installer, but 32-bit only) Install the Python module pygooglevoice from Google Code. (Requires 7Zip to unpack the .tar.gz file. Then setup.py install) Download BaudotRSS from SourceForge. (ZIP file, put in your chosen directory for this program.) Run: python baudotrss.py --help I'm thinking of switching to Go. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Make python 3.3 the default one and not 2.7
thx solved -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributing a Python program hell
On Wed, Apr 3, 2013 at 1:41 PM, John Nagle na...@animats.com wrote: I'm struggling with radio hams who are trying to get my antique Teletype program running. I hate having to write instructions like this: Installation instructions (Windows): You should check out pyInstaller or py2exe or cx_Freeze. -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributing a Python program hell
On 2013-04-03, John Nagle na...@animats.com wrote: I'm struggling with radio hams who are trying to get my antique Teletype program running. I hate having to write instructions like this: Installation instructions (Windows): Download and install Python 2.7 (32-bit) if not already installed. (Python 2.6 or 2.7 is required; pyserial will not work correctly on older versions, and feedparser is not supported in 3.x versions.) Install the Python module setuptools from the Python Package Index. (Needed by other installers. Has a Windows installer.) Install the Python module feedparser from Google Code. (Unpack ZiP file, run setup.py install) Install the Python module pyserial from SourceForge. (Windows installer, but 32-bit only) Install the Python module pygooglevoice from Google Code. (Requires 7Zip to unpack the .tar.gz file. Then setup.py install) Download BaudotRSS from SourceForge. (ZIP file, put in your chosen directory for this program.) Run: python baudotrss.py --help I'm thinking of switching to Go. Python programs can be distributed as binary-like packages, e.g., www.py2exe.org. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributing a Python program hell
On 2013-04-03, Neil Cerutti ne...@norwich.edu wrote: On 2013-04-03, John Nagle na...@animats.com wrote: I'm struggling with radio hams who are trying to get my antique Teletype program running. I hate having to write instructions like this: [...] Python programs can be distributed as binary-like packages, e.g., www.py2exe.org. I'd second the recommendation for for py2exe. It's been a couple years since I used it, but for 6-7 years before that I used it regularly to distribute about a half-dozen different wxPython apps to Windows users, and it worked very nicely. It sometimes requires some effort to get the configuration tweaked right and then adjusted so the result works on a variety of Windows versions, but in the end it always worked great. I usually used one of the various free self-installer generators to bundle up the .exe file(s) produced by py2exe along with whatever else was needed to go with them and make them simple to install. [I've forgotten which ones I used, but they all do basically the same thing.] I did all my development on Linux. When I boot over to Windows (on a VM, generally) I had Cygwin installed and just ran a make to do all the executable creation and bundling via command-line calls to py2exe and self-installer utilities. -- Grant Edwards grant.b.edwardsYow! It's a hole all the at way to downtown Burbank! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE printing problem
On 4/3/2013 2:50 PM, Joe Hill wrote: On Wed, 03 Apr 2013 14:40:38 -0400, Terry Jan Reedy tjre...@udel.edu wrote: On 4/3/2013 12:24 PM, Joe Hill wrote: I attempted to print about 10 pages of documentation from the help files using IDLE. On all the pages the side of each page was missing about 1/4 inch of text. You neglected to say what you actually did to have a problem. Text that I needed to make sense of the page did not print from the help file. Characters were missing on the right side on every long line on every page. I got that already. Until you say what you did, in enough detail to reproduce your actions, I cannot comment further. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Twisted-Python] Twisted 13.0.0 released
On Apr 3, 2013, at 4:11 AM, Thomas Hervé the...@free.fr wrote: On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 13.0. Thank you Thomas for managing yet another excellent release! Among the 70 tickets closed, we can see: * A new Introduction to Deferreds document that you can find here: http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html * A fix in twisted.web.template where attributes were not quoted properly, risking HTML injection. * Support for unicode domain names in twisted.names SRVConnector and Name classes, after a 12.3 regression. * A workaround for platform limitations when trying to schedule events far in the future. This is a great list. And we have even more great stuff in the pipeline. Everybody get to work on 13.1 ;-). -glyph -- http://mail.python.org/mailman/listinfo/python-list
Re: Time zone changing while Win app is running
On 4/3/2013 2:46 PM, CM wrote: On Apr 3, 7:37 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: On Tue, 02 Apr 2013 17:04:12 -0700, CM wrote: To summarize the issue: In an application, I have been using Python's datetime module to get the current time. But it seems that, at least with Windows (XP), whatever time zone your computer is set to when you start the application, that's what datetime will use--the time zone will *not* be updated in the application when you update it manually with Windows. So, if you change the time zone (say, after traveling with your laptop), all datetimes will be incorrect as compared to your system clock. I am not the maintainer of the datetime module, but based purely on what you have said, I would consider that a bug. I don't. Do you really want every time function slowed by re-initializing the timezone? I suggest you report it as an issue on the Python bug tracker. I do believe that time.tzget can now be make to work now on Windows, and that would be a proper tracker issue. Thanks, I submitted an issue about it. On 2.7.3, on Windows, it's easy to demonstrate: (Actual time = 2:40pm; tz = Eastern U.S.) import datetime print datetime.datetime.now() 2013-04-03 14:40:03.124000 RIGHT (Now change time zone to UTC, for example. Now clock reads 6:41pm.) import datetime Without a restart, this is a no=op. print datetime.datetime.now() 2013-04-03 14:41:13.124000 WRONG As I said on the issue, passing a tz arg to now() will give the answer for any timezone on earth. A user-friendly app displaying times should let users choose. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Thu, Apr 4, 2013 at 4:43 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 10:38:20 -0600, Ian Kelly wrote: On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n 0x: return 4 if n 0xFF: return 2 return 1 That's an incorrect implementation, as it would return 2 at the first non-Latin-1 BMP character, even if there were SMP characters later in the string. It's only safe to short-circuit return 4, not 2 or 1. Doh! I mean, well done sir, you have successfully passed my little test! Try this: def str_width(s): width=1 for ch in map(ord,s): if ch 0x: return 4 if cn 0xFF: width=2 return width ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On Thu, Apr 4, 2013 at 2:07 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Thu, 04 Apr 2013 01:17:28 +1100, Chris Angelico wrote: Probably, but it still has to scan the body of the string. It'd not be too bad if it's all astral, but if it's all BMP, it has to scan the whole string. In the max() case, it has to scan the whole string anyway, as there's no other way to determine the maximum. I'm thinking here of this function: http://pike.lysator.liu.se/generated/manual/modref/ex/7.2_3A_3A/String/ width.html It's implemented as a simple lookup into the header. (Pike strings, like PEP 393 strings, are stored in the most compact way possible - 1, 2, or 4 bytes per character - with a conceptually similar header structure.) Is this something that would be worth having available? Should I post an issue about it? I'm not really sure why I would want to know, apart from pure intellectual curiosity, but sure, post a feature request. Be sure to mention that Pike supports this feature. http://bugs.python.org/issue17629 opened. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: [Twisted-Python] Twisted 13.0.0 released
Yay! Thanks, Thomas and everyone who contributed to this release :) On Wed, Apr 3, 2013 at 1:11 PM, Thomas Hervé the...@free.fr wrote: On behalf of Twisted Matrix Laboratories, I am pleased to announce the release of Twisted 13.0. Among the 70 tickets closed, we can see: * A new Introduction to Deferreds document that you can find here: http://twistedmatrix.com/documents/13.0.0/core/howto/defer-intro.html * A fix in twisted.web.template where attributes were not quoted properly, risking HTML injection. * Support for unicode domain names in twisted.names SRVConnector and Name classes, after a 12.3 regression. * A workaround for platform limitations when trying to schedule events far in the future. For more information, see the NEWS file here: http://twistedmatrix.com/Releases/Twisted/13.0/NEWS.txt Download it now from: http://pypi.python.org/packages/source/T/Twisted/Twisted-13.0.0.tar.bz2or http://pypi.python.org/packages/2.7/T/Twisted/Twisted-13.0.0.win32-py2.7.msi Thanks to the supporters of Twisted via the Software Freedom Conservancy and to the many contributors for this release. -- Thomas ___ Twisted-Python mailing list twisted-pyt...@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python -- cheers lvh -- http://mail.python.org/mailman/listinfo/python-list
Serpent, a serializer based on ast.literal_eval. Now also with Java and .net implementations
Hi, I've made serpent, a serializer based around ast.literal_eval(). You can find it on Pypi: http://pypi.python.org/pypi/serpent Serpent takes a Python object tree and turns it into a serialized form that can be safely read back by ast.literal_eval(). This avoids security issues that other serialization protocols such as pickle have. It also has a few other nice properties such as the readability of the serialized data. I also wrote a Java and a .NET implementation so that you can easily exchange data between the different ecosystemens. The library works with Python 2.6+ (including 3.x), IronPython 2.7, Jython 2.7, Java 1.6, .NET 3.5, or newer versions. A little bit of documentation can be found on serpent's Pypi page, including a little demo program and its output. The full source and the Java/.NET versions are not available from Pypi obviously, but a download link for them is provided in the description. 'FAQ': - Why not use XML? Answer: because XML. - Why not use JSON? Answer: because JSON is quite limited in the number of datatypes it supports, and you can't use comments in a JSON file. - Why not use pickle? Answer: because pickle has security problems. - Why not use repr()/ast.literal_eval()? See above; serpent is a superset of this and provides more convenience. Serpent provides automatic serialization mappings for some types other than the builtin primitive types. repr() can't serialize these to literals that ast.literal_eval() understands. - Why not a binary format? Answer: because binary isn't readable. - But I don't care about readability. Answer: too bad, ast.literal_eval() wants a literal string. - But I want better performance. Answer: ok, maybe you shouldn't use serpent in this case. Find an efficient binary protocol (protobuf?) - Why only Python, Java and .NET, but no bindings for insert-favorite-language-here? Answer: I don't speak that language. Maybe you could port serpent yourself? Serpent on Pypi:http://pypi.python.org/pypi/serpent Cheers Irmen de Jong -- http://mail.python.org/mailman/listinfo/python-list
Your message to bind-users awaits moderator approval
Your mail to 'bind-users' with the subject Delivery reports about your e-mail Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: https://lists.isc.org/mailman/confirm/bind-users/09343741199629285eb8ad1c851fa8c74f8e4d17 -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE printing problem
On 4/3/2013 5:16 PM, Joe Hill wrote: On Wed, 03 Apr 2013 16:20:20 -0400, Terry Jan Reedy tjre...@udel.edu wrote: On 4/3/2013 2:50 PM, Joe Hill wrote: On Wed, 03 Apr 2013 14:40:38 -0400, Terry Jan Reedy tjre...@udel.edu wrote: On 4/3/2013 12:24 PM, Joe Hill wrote: I attempted to print about 10 pages of documentation from the help files using IDLE. On all the pages the side of each page was missing about 1/4 inch of text. You neglected to say what you actually did to have a problem. Text that I needed to make sense of the page did not print from the help file. Characters were missing on the right side on every long line on every page. I got that already. Until you say what you did, in enough detail to reproduce your actions, I cannot comment further. I Open IDLE and click on Help and select the second option which is Documentation - select Glossary. The three options I see are 1) 'About Idle', 2) 'Idle help', which brings as a 2 page doc starting [See the end of this file for ** TIPS **, and 3) Python Docs - F1. On Windows, this third option brings up Windows Help opened to the windows-help version of the docs, which are also available online in a browser. In either case, Glossary is one of the docs. We have left IDLE so your problem has nothing to do with IDLE. On Windows, one can open the same doc from the Start menu by selecting Python x.y / Python Docs. I then click on the Print icon at the top of the Help/Documentation screen - then let er rip. The word/line wrap on the screen is ok and the printed output is not. The word wrap on the screen adjusts to the window width. With the window too wide for the printer, I selected about five paragraphs, printed the selection, and the text was properly re-wrapped for printing with nothing lost, as if the display window had been narrowed. Windows obvious knows how wide the virtual window is for the particular combination of font (about 14 pt proportional sans serif) and printer. Apparently it is mis-calculating for your font and printer combination. This was all unexpected outcomes. I appreciate your help and that perhaps a fix can be found for everyone. Mine is a very standard setup W7 Ult, 64bit and an Epson printer (WP-4020) I have 64 bit Win7 pro with Canon and HP printers. The help window with a sheet+? icon in the upper left is Microsoft's program. The only thing I can suggest is to check for updated drivers, and make sure you have the correct driver. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
On 03/04/2013 22:55, Chris Angelico wrote: On Thu, Apr 4, 2013 at 4:43 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 10:38:20 -0600, Ian Kelly wrote: On Wed, Apr 3, 2013 at 9:02 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n 0x: return 4 if n 0xFF: return 2 return 1 That's an incorrect implementation, as it would return 2 at the first non-Latin-1 BMP character, even if there were SMP characters later in the string. It's only safe to short-circuit return 4, not 2 or 1. Doh! I mean, well done sir, you have successfully passed my little test! Try this: def str_width(s): width=1 for ch in map(ord,s): if ch 0x: return 4 if cn 0xFF: width=2 return width ChrisA Given the quality of some code posted here recently this patch can't be accepted until there are some unit tests :) -- If you're using GoogleCrap™ please read this http://wiki.python.org/moin/GoogleGroupsPython. Mark Lawrence -- http://mail.python.org/mailman/listinfo/python-list
Re: Data storage Py 3.3
On 4-4-2013 0:33, Joe Hill wrote: IDLE wants to use Python33 as the data storage folder - with exe files etc. Typically the 'default data storage' is in 'last used' directory or most programs even have a browse setting that one can quickly set and reset. What do people here generally do? When I installed 3.3, (W7- 64) I selected the first option for paths etc. and everything seems to just run fine j Don't store your files in the Python33 directory even though it is idle's default suggestion. I have my Python code sitting in appropriate subdirectories of a 'Projects' folder somewhere (on a different drive on my Windows system, or just a subfolder in my homedirectory on my Linux VM). I don't use idle myself, but you can simply browse to the appropriate folder and file location. Idle will remember that location for the next time you use the file dialog. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
Neil Hodgson, replying to self: The assembler (32-bit build) for each PyUnicode_READ looks like Don't have 64-bit MSVC 2010 set up but the code from 64-bit MSVC 2012 is better since there are an extra 8 registers in 64-bit mode: ; 10431: c1 = PyUnicode_READ(kind1, data1, i); cmp rsi, 1 jne SHORT $LN17@unicode_co lea rax, QWORD PTR [r9+rcx] movzx r8d, BYTE PTR [rax+rbx] jmp SHORT $LN16@unicode_co $LN17@unicode_co: cmp rsi, 2 jne SHORT $LN15@unicode_co movzx r8d, WORD PTR [r9+r11] jmp SHORT $LN16@unicode_co $LN15@unicode_co: mov r8d, DWORD PTR [r9+r10] $LN16@unicode_co: All the variables used in the loop are now in registers but the tests and branches are the same. This lines up with 64-bit being better than 32-bit on Windows but not as good as Python 3.2 or Unix. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
In article aa3b500f-bebf-4d77-9855-3d90b07ea...@y7g2000pbu.googlegroups.com, rusi rustompm...@gmail.com wrote: On Apr 3, 6:43 pm, Roy Smith r...@panix.com wrote: This has to inspect the entire string, no? I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it Astral crap? CRAP? Verily sir I am offended! [...] You are American! This is true. But, to be fair, in the (I don't have the exact number here) roughly 200 million records in our recent big data import job, I found exactly FOUR strings with astral characters. Which boiled down to two versions of each of two different song titles. One had a Unicode Character 'BALLOON' (U+1F388). The other had some heart symbol (sorry, I don't remember the exact code point). These hardly seem a matter of national pride. And, if you don't believe there is astral crap, how do you explain U+1F4A9? -- http://mail.python.org/mailman/listinfo/python-list
Re: Performance of int/long in Python 3
In article 515c448c$0$29966$c3e8da3$54964...@news.astraweb.com, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: On Wed, 03 Apr 2013 09:43:06 -0400, Roy Smith wrote: [...] n = max(map(ord, s)) 4 if n 0x else 2 if n 0xff else 1 This has to inspect the entire string, no? Correct. A more efficient implementation would be: def char_size(s): for n in map(ord, s): if n 0x: return 4 if n 0xFF: return 2 return 1 I posted (essentially) this a few days ago: if all(ord(c) = 0x for c in s): return it's all bmp else: return it's got astral crap in it It's not astral crap. People use it, and they'll use it more in the future. Just because you don't, doesn't give you leave to make disparaging remarks about it. Honestly, it's really painful to see how history repeats itself: Bah humbug, why do we need to support the SMP astral crap? The Unicode BMP is more than enough for everybody. Come on, guys. It was a joke. I'm the guy who was complaining that my database doesn't support non-BMP, remember? -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorating functions without losing their signatures
On Wednesday, April 3, 2013 3:05:31 AM UTC+2, Rotwang wrote: After thinking about it for a while I've come up with the following abomination Alas, there is actually no good way to implement this feature in pure Python without abominations. Internally the decorator module does something similar to what you are doing. However, instead of cooking up yourself your custom solution, it is probably better if you stick to the decorator module which has been used in production for several years and has hundreds of thousands of downloads. I am not claiming that it is bug free, but it is stable, bug reports come very rarely and it works for all versions of Python from 2.5 to 3.3. -- http://mail.python.org/mailman/listinfo/python-list
question about csv.DictReader
Hello, I have the following python script (some of lines are wrapped): #! /usr/bin/env python import csv def dict_test_1(): csv test program # Open the file Holdings_EXA.csv HOLDING_FILE = 'Holdings_EXA.csv' try: csv_file = open(HOLDING_FILE, 'rt') except IOError: print('Problem opening {0}\nExiting').format(HOLDING_FILE) exit() # create a dictionary reader try: csv_reader = csv.DictReader(csv_file) except NameError: print('Cannot find file {0} to create a dictionary reader \nExiting').format(HOLDING_FILE) exit() # Print the keys in each row i_row = 1 for row in csv_reader: print ('There are {0} keys in row {1}').format(len(row.keys()), i_row) print ('The keys in row {0} are \n{1}').format(i_row, row.keys()) i_row += 1 dict_test_1() Here are the lines in file Holdings_EXA.csv: Please note that the first field in the first row is Holdings Holdings,Weighting,Type,Ticker,Style,First Bought,Shares Owned,Shares Change,Sector,Price,Day Change,Day high/low,Volume,52-Wk high/low,Country,3-Month Return,1-Year Return,3-Year Return,5-Year Return,Market Cap Mil,Currency,Morningstar Rating,YTD Return,P/E,Maturity Date,Coupon %,Yield to Maturity Nestle SA,1.91,EQUITY,NESN,Large Core,1999-12-31,3732276,197810,Consumer Defensive,67.65,-,67.75-67.35,1211531,67.75-53.8,Switzerland,10.42,21.25,10.5,8.84,213475.59,CHF,2,12.92,21.69,-,-,- HSBC Holdings PLC,1.75,EQUITY,HSBA,Large Value,1999-12-31,21120203,1711934,Financial Services,733.3,-1.4|-0,738.8-731,7839724,739.9-501.2,United Kingdom,14.51,37.17,3.88,2.77,132694.66,GBP,3,13.93,15.55,-,-,- Novartis AG,1.33,EQUITY,NOVN,Large Core,2003-06-30,2669523,206851,Healthcare,65.95,0.5|0.01,66-65.4,1121549,66-48.29,Switzerland,15.1,36.5,6.16,8.53,158671.66,CHF,4,16.7,17.76,-,-,- Roche Holding AG,1.31,EQUITY,ROG,Large Growth,2003-05-31,817830,59352,Healthcare,214.8,1.4|0.01,215.2-213.1,684173,220.4-148.4,Switzerland,17.45,37.95,7.78,4.09,34000,CHF,3,18.09,19.05,-,-,- Finally, here are the results of running the script: norm@lima:~/python/overlap$ python dict_test_1.py There are 27 keys in row 1 The keys in row 1 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 2 The keys in row 2 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 3 The keys in row 3 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 4 The keys in row 4 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] norm@lima:~/python/overlap$ Can anyone explain the presence of the characters \xref\xbb\xbf before the first field contents Holdings ? Thanks, Norm -- http://mail.python.org/mailman/listinfo/python-list
In defence of 80-char lines
Although PEP 8 is only compulsory for the Python standard library, many users like to stick to PEP 8 for external projects. http://www.python.org/dev/peps/pep-0008/ With perhaps one glaring exception: many people hate, or ignore, PEP 8's recommendation to limit lines to 80 characters. (Strictly speaking, 79 characters.) Here is a good defence of 80 char lines: http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorating functions without losing their signatures
On 03/04/2013 02:05, Rotwang wrote: [...] After thinking about it for a while I've come up with the following abomination: import inspect def sigwrapper(sig): if not isinstance(sig, inspect.Signature): sig = inspect.signature(sig) def wrapper(f): ps = 'args = []\n\t\t' ks = 'kwargs = {}\n\t\t' for p in sig.parameters.values(): if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD): ps = '%sargs.append(%s)\n\t\t' % (ps, p.name) elif p.kind == p.VAR_POSITIONAL: ps = '%sargs.extend(%s)\n\t\t' % (ps, p.name) elif p.kind == p.KEYWORD_ONLY: ks = '%skwargs[%r] = %s\n\t\t' % (ks, p.name, p.name) elif p.kind == p.VAR_KEYWORD: ks = '%skwargs.update(%s)\n\t\t' % (ks, p.name) loc = {'wrapped': f} defstring = ('def wrapouter(wrapped = wrapped):' '\n\tdef wrapinner%s:' '\n\t\t%s%sreturn wrapped(*args, **kwargs)' '\n\treturn wrapinner' % (sig, ps, ks)) exec(defstring, f.__globals__, loc) return loc['wrapouter']() return wrapper Oops! Earlier I found out the hard way that this fails when the decorated function has arguments called 'args' or 'kwargs'. Here's a modified version that fixes said bug, but presumably not the many others I haven't noticed yet: def sigwrapper(sig): if not isinstance(sig, inspect.Signature): sig = inspect.signature(sig) n = 0 while True: pn = 'p_%i' % n kn = 'k_%i' % n if pn not in sig.parameters and kn not in sig.parameters: break n += 1 ps = '%s = []\n\t\t' % pn ks = '%s = {}\n\t\t' % kn for p in sig.parameters.values(): if p.kind in (p.POSITIONAL_ONLY, p.POSITIONAL_OR_KEYWORD): ps = '%s%s.append(%s)\n\t\t' % (ps, pn, p.name) elif p.kind == p.VAR_POSITIONAL: ps = '%s%s.extend(%s)\n\t\t' % (ps, pn, p.name) elif p.kind == p.KEYWORD_ONLY: ks = '%s%s[%r] = %s\n\t\t' % (ks, kn, p.name, p.name) elif p.kind == p.VAR_KEYWORD: ks = '%s%s.update(%s)\n\t\t' % (ks, kn, p.name) defstring = ('def wrapouter(wrapped = wrapped):' '\n\tdef wrapinner%s:' '\n\t\t%s%sreturn wrapped(*%s, **%s)' '\n\treturn wrapinner' % (sig, ps, ks, pn, kn)) def wrapper(f): loc = {'wrapped': f} exec(defstring, f.__globals__, loc) return loc['wrapouter']() return wrapper -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorating functions without losing their signatures
On 03/04/2013 05:15, Steven D'Aprano wrote: On Wed, 03 Apr 2013 02:05:31 +0100, Rotwang wrote: Hi all, Here's a Python problem I've come up against and my crappy solution. Hopefully someone here can suggest something better. I want to decorate a bunch of functions with different signatures; [...] After thinking about it for a while I've come up with the following abomination: [...] It seems to work, but I don't like it. Does anyone know of a better way of doing the same thing? Wait until Python 3.4 or 3.5 (or Python 4000?) when functools.wraps automatically preserves the function signature? Alas, I think this is a hard problem to solve with current Python. You might like to compare your solution with that of Michele Simionato's decorator module: http://micheles.googlecode.com/hg/decorator/documentation.html See this for some other ideas: http://numericalrecipes.wordpress.com/2009/05/25/signature-preserving- function-decorators/ Good luck! Thanks. It'll take me a while to fully absorb the links, but it looks like both are similarly based on abusing the exec function. Thanks to Jan too. -- http://mail.python.org/mailman/listinfo/python-list
Re: In defence of 80-char lines
While I agree that not having a line take up hundreds of characters is a good thing, 80 is really arbitrary in 2013 and having any self-imposed hard limit is silly. When you put a single 4- or 5-character word on a new line because you don't want to go over 80 (or 120 or whatever), the code is /less/ readable. A better guideline is to make new lines as necessary to make things more readable rather than blindly stick to some hard limit and say it's more readable just because. Also, IMO, 80 is far too limiting and I find 120-130 much better. Then again, I like small font sizes and avoid lower resolution screens like the plague. -- CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1 -- http://mail.python.org/mailman/listinfo/python-list
Windows printing problem (was re; IDLE printing problem_
On 4/3/2013 6:26 PM, Joe Hill wrote: In light of the fact that this is a new problem and has only occurred in Python - I shall just regard that as either a feature or flaw... Based on what you have said, the problem IS NOT OCCURRING IN PYTHON. It is occurring in the Microsoft HTML help viewer. -- http://mail.python.org/mailman/listinfo/python-list
Re: Data storage Py 3.3
On 4/3/2013 6:53 PM, Irmen de Jong wrote: On 4-4-2013 0:33, Joe Hill wrote: IDLE wants to use Python33 as the data storage folder - with exe files etc. Typically the 'default data storage' is in 'last used' directory or most programs even have a browse setting that one can quickly set and reset. What do people here generally do? When I installed 3.3, (W7- 64) I selected the first option for paths etc. and everything seems to just run fine I have a c:\Programs folder where I put multiple versions of python and selected other programs whose directories I might want to visit. Don't store your files in the Python33 directory even though it is idle's default suggestion. I once did that, but then I had to move stuff when the Python x.y directory became obsolete. It was also a problem when I wanted to test a file with more than one python version. I have my Python code sitting in appropriate subdirectories of a 'Projects' folder somewhere (on a different drive on my Windows system, or just a subfolder in my homedirectory on my Linux VM). I have a file tem.py in my miscellaneous python directory. When I am writing possibly throwaway code, I open it from the recent files list, empty the old code, and go. I can always save as another name if I want to keep the code. tem.py is almost always on the list because I use it frequently. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decorating functions without losing their signatures
On 04/04/2013 02:18, Michele Simionato wrote: On Wednesday, April 3, 2013 3:05:31 AM UTC+2, Rotwang wrote: After thinking about it for a while I've come up with the following abomination Alas, there is actually no good way to implement this feature in pure Python without abominations. Internally the decorator module does something similar to what you are doing. However, instead of cooking up yourself your custom solution, it is probably better if you stick to the decorator module which has been used in production for several years and has hundreds of thousands of downloads. I am not claiming that it is bug free, but it is stable, bug reports come very rarely and it works for all versions of Python from 2.5 to 3.3. Thanks, I'll check it out. Looking at the link Steven provided, I didn't see an easy way to add additional keyword-only arguments to a function's signature, though (but then I've yet to figure out how the FunctionMaker class works). -- http://mail.python.org/mailman/listinfo/python-list
Re: In defence of 80-char lines
On 04/03/2013 09:59 PM, Andrew Berg wrote: While I agree that not having a line take up hundreds of characters is a good thing, 80 is really arbitrary in 2013 and having any self-imposed hard limit is silly. When you put a single 4- or 5-character word on a new line because you don't want to go over 80 (or 120 or whatever), the code is /less/ readable. A better guideline is to make new lines as necessary to make things more readable rather than blindly stick to some hard limit and say it's more readable just because. Also, IMO, 80 is far too limiting and I find 120-130 much better. Then again, I like small font sizes and avoid lower resolution screens like the plague. I have to agree. To some degree, it's a matter of taste: for me, 80c limit looks ugly to the extreme, at least in Django; but 140+ looks even uglier, and the longer line is, the uglier it looks. The optimal size for Django code is a 105 char soft limit -- by soft limit I mean that under 105 it's always one line, 105-110 I decide on a case-by-case basis and over 110 is always split. So my preference is: 105 120-130 140 80 140+ The trade-off is that on one hand, the code is more readable when a single line is a single operation, from a cognitive standpoint, when you're thinking about the logic of the function as a whole, or a subset of a function if it's too long (which it shouldn't be, right?) On the other hand, even if your monitor is wide, you probably still want to fit in the browser window and the terminal window, and as the blog author rightly notes, really long lines do get harder to read. Again, I mostly work with Django and I suspect if I worked in regular Python I would possibly gravitate towards 95-100 limit. I find the blog author's point about fitting more text nonsensical: you can obviously fit more text PER LINE if lines are longer! And you can quite easily fit two 120-130 wide gvim screens on a modern monitor with room to spare. I'm sure eyesight acuity also figures into this: I prefer to work without glasses -- otherwise my eyes get tired after a couple of hours; but this means I can't see code on my second monitor. If I could, I might have preferred having browser and terminal on one monitor and Gvim with slightly longer width limits than I use now. -m -- Lark's Tongue Guide to Python: http://lightbird.net/larks/ The Bible is literature, not dogma. George Santayana -- http://mail.python.org/mailman/listinfo/python-list
Re: question about csv.DictReader
On 04/04/2013 02:26, Norman Clerman wrote: Hello, I have the following python script (some of lines are wrapped): #! /usr/bin/env python import csv def dict_test_1(): csv test program # Open the file Holdings_EXA.csv HOLDING_FILE = 'Holdings_EXA.csv' try: csv_file = open(HOLDING_FILE, 'rt') except IOError: print('Problem opening {0}\nExiting').format(HOLDING_FILE) exit() # create a dictionary reader try: csv_reader = csv.DictReader(csv_file) except NameError: print('Cannot find file {0} to create a dictionary reader \nExiting').format(HOLDING_FILE) exit() # Print the keys in each row i_row = 1 for row in csv_reader: print ('There are {0} keys in row {1}').format(len(row.keys()), i_row) print ('The keys in row {0} are \n{1}').format(i_row, row.keys()) i_row += 1 dict_test_1() Here are the lines in file Holdings_EXA.csv: Please note that the first field in the first row is Holdings Holdings,Weighting,Type,Ticker,Style,First Bought,Shares Owned,Shares Change,Sector,Price,Day Change,Day high/low,Volume,52-Wk high/low,Country,3-Month Return,1-Year Return,3-Year Return,5-Year Return,Market Cap Mil,Currency,Morningstar Rating,YTD Return,P/E,Maturity Date,Coupon %,Yield to Maturity Nestle SA,1.91,EQUITY,NESN,Large Core,1999-12-31,3732276,197810,Consumer Defensive,67.65,-,67.75-67.35,1211531,67.75-53.8,Switzerland,10.42,21.25,10.5,8.84,213475.59,CHF,2,12.92,21.69,-,-,- HSBC Holdings PLC,1.75,EQUITY,HSBA,Large Value,1999-12-31,21120203,1711934,Financial Services,733.3,-1.4|-0,738.8-731,7839724,739.9-501.2,United Kingdom,14.51,37.17,3.88,2.77,132694.66,GBP,3,13.93,15.55,-,-,- Novartis AG,1.33,EQUITY,NOVN,Large Core,2003-06-30,2669523,206851,Healthcare,65.95,0.5|0.01,66-65.4,1121549,66-48.29,Switzerland,15.1,36.5,6.16,8.53,158671.66,CHF,4,16.7,17.76,-,-,- Roche Holding AG,1.31,EQUITY,ROG,Large Growth,2003-05-31,817830,59352,Healthcare,214.8,1.4|0.01,215.2-213.1,684173,220.4-148.4,Switzerland,17.45,37.95,7.78,4.09,34000,CHF,3,18.09,19.05,-,-,- Finally, here are the results of running the script: norm@lima:~/python/overlap$ python dict_test_1.py There are 27 keys in row 1 The keys in row 1 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 2 The keys in row 2 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 3 The keys in row 3 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] There are 27 keys in row 4 The keys in row 4 are ['Style', 'Day Change', 'Coupon %', 'Yield to Maturity', 'P/E', 'Type', 'Weighting', 'Price', '3-Month Return', 'Volume', '\xef\xbb\xbfHoldings', 'Ticker', 'Shares Change', 'Shares Owned', 'YTD Return', '5-Year Return', 'Market Cap Mil', 'Country', '3-Year Return', 'Day high/low', 'Maturity Date', '1-Year Return', 'Sector', 'Morningstar Rating', 'Currency', '52-Wk high/low', 'First Bought'] norm@lima:~/python/overlap$ Can anyone explain the presence of the characters \xref\xbb\xbf before the first field contents Holdings ? Microsoft Windows indicates that a text file contains text encoded as UTF-8 by including a signature at its start. (Does the file also have \r\n line endings? Presumably it was created on a Windows system.) Try opening the file with the utf-8-sig encoding instead; this will drop the signature if present. -- http://mail.python.org/mailman/listinfo/python-list
Re: question about csv.DictReader
On 2013-04-03 18:26, Norman Clerman wrote: Can anyone explain the presence of the characters \xref\xbb\xbf before the first field contents Holdings ? (you mean \xef, not \xref) This is a byte-order-mark (BOM), which you can read about at [1]. In this case, it denotes the file as UTF-8 encoded. Certain programs insert these, though it's more important with UTF-16 or UTF-32 encodings where the byte-order and endian'ness actually matters. I believe Notepad and Visual Studio on Win32 were both offenders when it came to inserting unbidden BOMs. -tkc [1] http://en.wikipedia.org/wiki/Byte_order_mark -- http://mail.python.org/mailman/listinfo/python-list
Python 3.3 Tkinter Fullscreen - Taskbar not Hiding
Hi, I am working with Tkinter, and I have set up some simple code to run: import tkinter import re from tkinter import * global master master = Tk() # Start game Launcher def FormGUI(): master.title(GAME TITLE) SW = master.winfo_screenwidth() / 3.2 SH = master.winfo_screenheight() / 3.2 master.geometry(500x300+%d+%d % (SW, SH)) Label(master,text=game:\nGAME TITLE).pack() Button(master, text=Start game, command=DestroyStart, takefocus=1).pack() master.wm_state(zoom) # Destroy the GUI launcher window upon player starting the game. def DestroyStart(): global master master.destroy() master = Tk() ReformGui() # Form the game's GUI window in full screen. def ReformGui(): master.title(GAME TITLE) SW = master.winfo_screenwidth() SH = master.winfo_screenheight() master.geometry(%dx%d+0+0 % (SW,SH)) master.attributes(-fullscreen, 1) master.configure(bg=black) Label(master, text=\GAME TESTING TEXT\, background=black, foreground=white).pack() FormGUI() master.mainloop() # END OF CODE Everything in this code runs appropriately. The main goal of this code is to open up two windows, one with fixed dimensions, the other with full-screen enabled. My problem is that with the code above, the full-screen window opens up properly, however my taskbar shows over the full-screen. Until I click on the full-screen window, the taskbar will not be hidden. Am I doing something wrong, or is there a better way to create a full-screen window in Tkinter with the taskbar hidden? Note: Removing the 'import re' code above fixes the taskbar problem, however the re module is apparently needed as I can't run the program properly as an executable. Importing re fixes this problem. I'm running this program under Windows. -- http://mail.python.org/mailman/listinfo/python-list
Re: In defence of 80-char lines
I also tend to prefer a maximum between 110 and 120 characters. I find continuation lines confusing, and when you use some third-party tools, such as wxPython, for example, the boilerplate code leads to some long lines. I would hate to have to break up this line, for instance: self.mainLabel.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = FreeSans)) Especially if it's already indented a few levels to begin with. With most of your code in classes, you already got most of it indented two levels right off the bat. -- http://mail.python.org/mailman/listinfo/python-list
Re: In defence of 80-char lines
On Apr 4, 6:36 am, Steven D'Aprano steve +comp.lang.pyt...@pearwood.info wrote: Although PEP 8 is only compulsory for the Python standard library, many users like to stick to PEP 8 for external projects. http://www.python.org/dev/peps/pep-0008/ http://blog.languager.org/2012/10/layout-imperative-in-functional.htmlith perhaps one glaring exception: many people hate, or ignore, PEP 8's recommendation to limit lines to 80 characters. (Strictly speaking, 79 characters.) Here is a good defence of 80 char lines: http://wrongsideofmemphis.com/2013/03/25/80-chars-per-line-is-great/ The exchange on hacker news linked from there makes for a nice read -- tnx. I had a blog article http://blog.languager.org/2012/10/layout-imperative-in-functional.html on this subject. It started from a python discussion, though its more relevant to Haskell. What does not so easily come out there is that the wide-line code samples I posted which read ok to me were not to some readers. So I moved it to gist, but even there some would get the horizontal scroll bar. Reading it 'raw' seems to remove the problem -- though I can hardly promise that for all devices. So from this POV the point that was made was opposite to the one I was trying to make =) The discussion that followed on haskell cafe http://www.haskell.org/pipermail/haskell-cafe/2012-October/104224.html made a number of interesting points about pros and cons of long lines. -- http://mail.python.org/mailman/listinfo/python-list
Re: Time zone changing while Win app is running
I am not the maintainer of the datetime module, but based purely on what you have said, I would consider that a bug. I don't. Do you really want every time function slowed by re-initializing the timezone? It depends; do you know what re-initializing entails and how costly that would be? I don't. The way I was thinking of it is, if the documentation for datetime.datetime.now() is (to begin), Return the current local date and time. ...then, at least in the cases in which one changes one's system timezone during a running Python instance*, the docs are just not accurate for this method. (*which is not such a corner case given laptops that travel with us across them--often this timezone crossing is fundamental to one's work with that laptop) I do believe that time.tzget can now be make to work now on Windows, and that would be a proper tracker issue. Can you elaborate on how this would help my case? (Now change time zone to UTC, for example. Now clock reads 6:41pm.) import datetime Without a restart, this is a no=op. Whoops, thanks; I just copied and pasted it twice. As I said on the issue, passing a tz arg to now() will give the answer for any timezone on earth. A user-friendly app displaying times should let users choose. Are you saying that the app should require that the user enter their current time zone into the whenever they change time zones (in addition to their changing it in the Windows system clock)? And then using that tz in every call to datetime.datetime.now()? Thanks. -- http://mail.python.org/mailman/listinfo/python-list