Re: GUI toolkit(s) status
wxjmfa...@gmail.com writes: Today, there are simply no more valid and working GUI toolkit running out of the box. Tkinter still works for me. What's the problem? -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI toolkit(s) status
On Thu, Nov 20, 2014 at 7:25 PM, Paul Rubin no.email@nospam.invalid wrote: wxjmfa...@gmail.com writes: Today, there are simply no more valid and working GUI toolkit running out of the box. Tkinter still works for me. What's the problem? Ignore jmf. Most of us didn't even see his post, for one reason or another, and even when his posts were getting through, the signal-to-noise ratio was denormal. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI toolkit(s) status
Am 20.11.14 09:40, schrieb Chris Angelico: On Thu, Nov 20, 2014 at 7:25 PM, Paul Rubin no.email@nospam.invalid wrote: wxjmfa...@gmail.com writes: Today, there are simply no more valid and working GUI toolkit running out of the box. Tkinter still works for me. What's the problem? Ignore jmf. He is trolling, but in this point he is right, unfortunately: neither Tcl nor Tk support Unicode outside the BMP. Full Unicode support is a big todo item on the wishlist for Tcl 9, for Tk nobody really knows. We are lacking manpower and people with specialized knowledge. Apple is a moving target, they pulled the rug from under Tk's feet twice over the past 10 years. Nobody knows if Tk will continue to exist on the mac if Cocoa is withdrawn some day and replaced by a new and completely different windowing framework. Python has largely replaced Tcl as the first-choice scripting language, and that also does not help to attract people working on Tcl/Tk. Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: GUI toolkit(s) status
On Thu, Nov 20, 2014 at 8:04 PM, Christian Gollwitzer aurio...@gmx.de wrote: Am 20.11.14 09:40, schrieb Chris Angelico: Ignore jmf. He is trolling, but in this point he is right, unfortunately: neither Tcl nor Tk support Unicode outside the BMP. Full Unicode support is a big todo item on the wishlist for Tcl 9, for Tk nobody really knows. We are lacking manpower and people with specialized knowledge. Apple is a moving target, they pulled the rug from under Tk's feet twice over the past 10 years. Nobody knows if Tk will continue to exist on the mac if Cocoa is withdrawn some day and replaced by a new and completely different windowing framework. Python has largely replaced Tcl as the first-choice scripting language, and that also does not help to attract people working on Tcl/Tk. This is what happens when someone spends most of his time trolling. When the signal-to-noise ratio is sufficiently low, it's just not worth reading his posts. And even when he does have a decent point to make, he couches it in such exaggerated language that it's hard to take him seriously. But I agree about the issues with tkinter. So, let's see. Shall we wait for Tcl/Tk Unicode support? Recommend people switch to PyGTK? To PyQt? To wxPython? To something else? Personally, I'm quite happy with GTK2 (though that's with Pike, not Python), and it does have full Unicode support; but there are some issues with the interface that make it feel a bit clunky. Every other windowing toolkit has its own flaws. Even if one of them were to be blessed into the stdlib (which would remove the whole but it's an external dependency problem), there's still no perfect option, and every toolkit will have its staunch supporters. If Python were starting from scratch today with the first-ever stdlib GUI toolkit, as a Python 3 feature, I would expect that full Unicode support be a hard requirement. But since tkinter already exists, there's no point stripping it out, and blessing another one means making a choice. I don't see there's enough to choose between the top three or four options. If I'm going to build a Python GUI app, I'll probably use PyGTK, and if you do, you're free to use PyQt. I don't think this is a problem. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
python 2.7 and unicode (one more time)
Hello, My application is using gettext module to do the translation stuff. Translated messages are unicode on both python 2 and 3 (with python2.7 I had to explicitely asked for unicode). A problem arises when formatting those messages before logging them. For example: log.debug(%s: %s % (header, _(will return an unicode string))) Indeed on python2.7, %s: %s is 'str' whereas _() returns unicode. My question is: how should this be fixed properly ? A simple solution would be to force all strings passed to the logger to be unicode: log.debug(u%s: %s % ...) and more generally force all string in my code to be unicode by using the 'u' prefix. or is there a proper solution ? Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Re: tkinter mainloop
Rick Johnson rantingrickjohn...@gmail.com a écrit dans le message de news:3385be62-e21c-4efe-802e-8f7351155...@googlegroups.com... You don't need to call mainloop() when building Tkinter widgets on the command-line, but for *real* scripts i believe you'll need to. For instance, if you run the following code you will see a window with a label inside: You are right In fact, I used to open *.py programs with IDLE and then I run programs from IDLE menu. With this way, mainloop( ) is not needed. I tried to double click on a *.py to run a program. Without mainloop( ), the console appears a split seconds, then deseapears, and that's all. With mainloop( ) it works. Second question, is it possible to cancel a mainloop() ? I don't think you meant to say cancel, did you really mean pause? I neeed this feature because I have a main window root = Tk() which opens a Toplevel secondary window top = Toplevel() and I would like root window to be frozen while the user fills the top window. Sounds like you're trying to create a modal dialog, yes? Tkinter has a few methods for handling such cases. One is called wait_window and another is called quit, with wait_window being preferred over quit for most tasks. There are also methods for setting the input focus and grab. A good example for you to look at is the tkSimpleDialog.Dialog class. OK tkinter.simpledialog.askstring is exactly what I need Thanks -- https://mail.python.org/mailman/listinfo/python-list
pack circles into a partial annulus
I need to pack circles into a partial annulus ie part of a larger circle bounded by two radii and angles of say 18 90. The region is described in polar coords as {(r,theta) | r0=r=r1 theta0=theta=theta1}. The circles to be packed have three different radii, but all will fit singly into the region. The idea is that they should be as far apart as possible so as to minimize overlap and avoid crossing the region boundary. Circle packing is hard so I'm thinking of using some kind of spring/repulsion model to do this. Has anyone any ideas about how to do this? -- Robin Becker -- https://mail.python.org/mailman/listinfo/python-list
Re: Trouble getting full response content from PATCH request
On 19Nov2014 17:17, John Gordon gor...@panix.com wrote: In mailman.15988.1416366536.18130.python-l...@python.org Cameron Simpson c...@zip.com.au writes: The API uses the HTTP PATCH operation to set user passwords, and in case of unacceptable passwords, the response is supposed to be an HTML document containing a diagnostic message in the body tag. When I submit my test data via a functional testing tool (SoapUI), it behaves as expected. However, when I submit test data from Python code, the response content consists only of the diagnostic message, with no enclosing html or body tags. [...] You need a SOAPAction: HTTP header with SOAP requests. It may be that simple. The API does provide some SOAP calls, but the specific call I'm using is REST. Is there a corresponding header I should use? At this point I have no idea; I took things to be SOAP because your SoapUI tool worked. My next suggestion would be to insert a proxy between yourself and the API, specificly so that you can run your working SoapUI test through it. Then you can get a snapshot of headers and requests that work. We've used Paros in the past, but a search for debugging http proxy on Google shows several choices. Cheers, Cameron Simpson c...@zip.com.au The ten thousand things How long do any persist? Netscape, too, has gone. - Haiku Error Messages http://www.salonmagazine.com/21st/chal/1998/02/10chal2.html -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014 at 8:40 PM, Francis Moreau francis.m...@gmail.com wrote: My question is: how should this be fixed properly ? A simple solution would be to force all strings passed to the logger to be unicode: log.debug(u%s: %s % ...) and more generally force all string in my code to be unicode by using the 'u' prefix. Yep. And then you may want to consider from __future__ import unicode_literals, which will make string literals represent Unicode strings rather than byte strings. Basically the same as you're saying, only without the explicit u prefixes. This will also make your Py2 code behave more like the way your Py3 code does (as bare string literals are always Unicode strings in Py3). ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On 20/11/2014 04:58, Steven D'Aprano wrote: And the award for the most gratuitous comments before an import goes to one of my (former) workmates, who wrote this piece of code: # Used for base64-decoding. import base64 # Used for ungzipping. import gzip I wonder if anybody has ever written this? # Used for importing this. import this -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Francis Moreau wrote: Hello, My application is using gettext module to do the translation stuff. Translated messages are unicode on both python 2 and 3 (with python2.7 I had to explicitely asked for unicode). A problem arises when formatting those messages before logging them. For example: log.debug(%s: %s % (header, _(will return an unicode string))) This is only problematic if header is a non-ascii bytestring. Indeed on python2.7, %s: %s is 'str' whereas _() returns unicode. My question is: how should this be fixed properly ? A simple solution would be to force all strings passed to the logger to be unicode: log.debug(u%s: %s % ...) and more generally force all string in my code to be unicode by using the 'u' prefix. or is there a proper solution ? You don't need to change an all-ascii bytestring to unicode. Lo and behold: %s %s % (uüblich, uähnlich) u'\xfcblich \xe4hnlich' u%s %s % (uüblich, uähnlich) u'\xfcblich \xe4hnlich' Only non-ascii bytestrings mean trouble, either noisy u%s nötig %s % (uüblich, ähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) %s nötig %s % (uüblich, uähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) or silently until you have to decipher the logfile contents. It's best to stay away from them, and the from __future__ unicode_literals that Chris mentionend is a convenient way to achieve that. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014 at 11:35 PM, Peter Otten __pete...@web.de wrote: You don't need to change an all-ascii bytestring to unicode. Lo and behold: %s %s % (uüblich, uähnlich) u'\xfcblich \xe4hnlich' u%s %s % (uüblich, uähnlich) u'\xfcblich \xe4hnlich' Only non-ascii bytestrings mean trouble, either noisy It's better to not depend on that, though. Be clear and explicit about the difference between bytes and text, and don't try to pretend they're the same thing, even for ASCII. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: pack circles into a partial annulus
In article mailman.16011.1416478357.18130.python-l...@python.org, Robin Becker ro...@reportlab.com wrote: I need to pack circles into a partial annulus ie part of a larger circle bounded by two radii [...] Circle packing is hard so I'm thinking of using some kind of spring/repulsion model to do this. Has anyone any ideas about how to do this? This is not a Python question. This is an algorithm question, and would be better asked on some sort of math forum. Googling for things like circle packing algorithm brought me to http://www.packomania.com/, which looks like the perfect place to start your investigations. Once you have a specific algorithm in mind, and are having problems coding it up, come back here for help on the Python aspects. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Distutils] Call for information - What assumptions can I make about Unix users' access to Windows?
On Sat, Nov 15, 2014 at 10:45 +, Paul Moore wrote: On 7 November 2014 15:46, Paul Moore p.f.mo...@gmail.com wrote: To that end, I'd like to get an idea of what sort of access to Windows a typical Unix developer would have. Thanks to all who contributed to this thread. Based on the feedback, I think it's going to be useful to provide two options. First of all, an EC2 AMI that can be used by people without access to a local Windows system. While other cloud providers are a possibility, EC2 provides a free tier (for the first year) and is well-known, so it's probably the easiest to get started with (at least it was for me!) Also, I will provide a script that can be used to automatically build the environment on a newly-installed machine. The idea is that you can use this on a Windows VM (something that a number of people have said they have access to). The script may be usable on an existing machine, but it's hard to make it robust, as there are too many failure modes to consider (software already installed, configuration and/or permission differences, etc). So while such use may be possible, I probably won't consider it as supported. Thanks Paul for going through this! Looking forward to the link/code. holger Thanks again, Paul ___ Distutils-SIG maillist - distutils-...@python.org https://mail.python.org/mailman/listinfo/distutils-sig -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote: %s nötig %s % (uüblich, uähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) This is surprising to me - why is it trying to decode the format string, rather than encode the arguments? -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Hi, On 11/20/2014 11:47 AM, Chris Angelico wrote: On Thu, Nov 20, 2014 at 8:40 PM, Francis Moreau francis.m...@gmail.com wrote: My question is: how should this be fixed properly ? A simple solution would be to force all strings passed to the logger to be unicode: log.debug(u%s: %s % ...) and more generally force all string in my code to be unicode by using the 'u' prefix. Yep. And then you may want to consider from __future__ import unicode_literals, which will make string literals represent Unicode strings rather than byte strings. Basically the same as you're saying, only without the explicit u prefixes. Thanks for the from __future__ import unicode_literals trick, it makes that switch much less intrusive. However it seems that I will suddenly be trapped by all modules which are not prepared to handle unicode. For example: from __future__ import unicode_literals import locale locale.setlocale(locale.LC_ALL, 'fr_FR') Traceback (most recent call last): File stdin, line 1, in module File /usr/lib64/python2.7/locale.py, line 546, in setlocale locale = normalize(_build_localename(locale)) File /usr/lib64/python2.7/locale.py, line 453, in _build_localename language, encoding = localetuple ValueError: too many values to unpack Is the locale module an exception and in that case I'll fix it by doing: locale.setlocale(locale.LC_ALL, b'fr_FR') or is a (big) part of the modules in python 2.7 still not ready for unicode and in that case I have to decide which prefix (u or b) I should manually add ? Thanks. -- https://mail.python.org/mailman/listinfo/python-list
Tag objects in Beautiful Soup
Re:'Accessing the Tag object from Beautiful Soup' (page 22-25 - Getting Started with Beautiful Soup) So far the code to python27 runs as given in the book, re: - html_atag = htmlbodypTest html a tag example/p ... a href=http://www.packtpub.com'Home/a ... a href=http;//www.packtpub.com/books'.Books/a ... /body ... /html soup = BeautifulSoup(html_atag,'lxml') atag = soup.a print(atag) a href=http://www.packtpub.com'gt;Homelt;/agt; lt;a href= http= /a type(atag) class 'bs4.element.Tag' tagname = atag.name print tagname a atag.name = 'p' print (soup) htmlbodypTest html a tag example/p p href=http://www.packtpub.com'gt;Homelt;/agt; lt;a href= http= /p/body /html then under the next Sub heading : 'Attributes of a Tag object' text reads : atag = soup_atag.a print (atag['href']) #output http://www.packtpub.com however when I put this code to the console I get error returns at the first line re:- atag = soup_atag.a Traceback (most recent call last): File stdin, line 1, in module NameError: name 'soup_atag' is not defined Can anyone tell me where I am going wrong or where the text is wrong ? So far the given code has run okay, I have put to the console everything the text tells you to. Thank you for reading. Simon Evans -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 12:59 AM, random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote: %s nötig %s % (uüblich, uähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) This is surprising to me - why is it trying to decode the format string, rather than encode the arguments? Why should it encode to bytes? Makes much better sense to work in Unicode. But mainly, it has to do one of them, and be predictable. If you add a float and an int, you have to predictably get back one of those two types, and since neither is a perfect superset of the other, one just has to be picked. (And that's float, because it's more likely to be the better option.) In this case, picking Unicode to meet on is easily the better option, because you'll often have pure-ASCII string literals as format strings, and Unicode data being interpolated into it. So using an ASCII codec is far more likely to succeed if you decode the format string than if you encode the data. Personally, I'd much rather be very clear about what's text and what's bytes, and not have any automatic encoding at all. That's why I use Python 3. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Tag objects in Beautiful Soup
Simon Evans wrote: Re:'Accessing the Tag object from Beautiful Soup' (page 22-25 - Getting Started with Beautiful Soup) So far the code to python27 runs as given in the book, re: - html_atag = htmlbodypTest html a tag example/p ... a href=http://www.packtpub.com'Home/a ... a href=http;//www.packtpub.com/books'.Books/a ... /body ... /html soup = BeautifulSoup(html_atag,'lxml') atag = soup.a print(atag) a href=http://www.packtpub.com'gt;Homelt;/agt; lt;a href= http= /a type(atag) class 'bs4.element.Tag' tagname = atag.name print tagname a atag.name = 'p' print (soup) htmlbodypTest html a tag example/p p href=http://www.packtpub.com'gt;Homelt;/agt; lt;a href= http= /p/body /html then under the next Sub heading : 'Attributes of a Tag object' text reads : There is no assignment soup_atag = whatever but there is one to atag. The whole session should when you omit the offending line atag = soup_atag.a or insert soup_atag = soup before it. print (atag['href']) #output http://www.packtpub.com however when I put this code to the console I get error returns at the first line re:- atag = soup_atag.a Traceback (most recent call last): File stdin, line 1, in module NameError: name 'soup_atag' is not defined Can anyone tell me where I am going wrong or where the text is wrong ? So far the given code has run okay, I have put to the console everything the text tells you to. Thank you for reading. Simon Evans -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 1:14 AM, Francis Moreau francis.m...@gmail.com wrote: Hi, Thanks for the from __future__ import unicode_literals trick, it makes that switch much less intrusive. However it seems that I will suddenly be trapped by all modules which are not prepared to handle unicode. For example: from __future__ import unicode_literals import locale locale.setlocale(locale.LC_ALL, 'fr_FR') Traceback (most recent call last): File stdin, line 1, in module File /usr/lib64/python2.7/locale.py, line 546, in setlocale locale = normalize(_build_localename(locale)) File /usr/lib64/python2.7/locale.py, line 453, in _build_localename language, encoding = localetuple ValueError: too many values to unpack Is the locale module an exception and in that case I'll fix it by doing: locale.setlocale(locale.LC_ALL, b'fr_FR') or is a (big) part of the modules in python 2.7 still not ready for unicode and in that case I have to decide which prefix (u or b) I should manually add ? Sadly, there are quite a lot of parts of Python 2 that simply don't handle Unicode strings. But you can probably keep all of those down to just a handful of explicit bwhatever strings; most places should accept unicode as well as str. What you're seeing here is a prime example of one of this author's points (caution, long post): http://unspecified.wordpress.com/2012/04/19/the-importance-of-language-level-abstract-unicode-strings/ The lesson of Python 3 is: give programmers a Unicode string type, *make it the default*, and encoding issues will /mostly/ go away. There's a whole ecosystem to Python 2 - some in the standard library, heaps more in the rest of the world - and a lot of it was written on the assumption that a byte is a character is an octet. When you pass Unicode strings to functions written to expect byte strings, sometimes you win, and sometimes you lose... even with the standard library itself. But the Python 3 ecosystem has been written on the assumption that strings are Unicode. It's only a narrow set of programs (boundary code, where you're moving text across networks and stuff like that) where the Python 2 model is easier to work with; and the recent Py3 releases have been progressively working to relieve that pain. The absolute worst case is a function which exists in Python 2 and 3, and requires a byte string in Py2 and a text string in Py3. Sadly, that may be exactly what locale.setlocale() is. For that, I would suggest explicitly passing stuff through str(): locale.setlocale(locale.LC_ALL, str('fr_FR')) In Python 3, 'fr_FR' is already a str, so passing it through str() will have no significant effect. (Though it would be worth commenting that, to make it clear to a subsequent reader that this is Py2 compat code.) In Python 2 with unicode_literals active, 'fr_FR' is a unicode, so passing it through str() will encode it to ASCII, producing a byte string that setlocale should be happy with. By the way, the reason for the strange error message is clearer in Python 3, which chains in another exception: locale.setlocale(locale.LC_ALL, b'fr_FR') Traceback (most recent call last): File /usr/local/lib/python3.5/locale.py, line 498, in _build_localename language, encoding = localetuple ValueError: too many values to unpack (expected 2) During handling of the above exception, another exception occurred: Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python3.5/locale.py, line 594, in setlocale locale = normalize(_build_localename(locale)) File /usr/local/lib/python3.5/locale.py, line 507, in _build_localename raise TypeError('Locale must be None, a string, or an iterable of two strings -- language code, encoding.') TypeError: Locale must be None, a string, or an iterable of two strings -- language code, encoding. So when it gets the wrong type of string, it attempts to unpack it as an iterable; it yields five values (the five bytes or characters, depending on which way it's the wrong type of string), but it's expecting two. Fortunately, str() will deal with this. But make sure you don't have the b prefix, or str() in Py3 will give you quite a different result! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On 11/19/2014 07:53 PM, Juan Christian wrote: Thanks, it's working using QTimer. The thing is that whenever the program is going to do something, in my case, draw a new QGroupBox with some components inside and put it in the Form (I'm using VBoxLayout in the main form) the program freezes, and I'm using very simple components just for testing.This shouldn't be normal, right? Am I doing something wrong? Make sure your callbacks always return very quickly. Never do any long task in a GUI event callback. Even your timer event callbacks should return quickly. If you need to do something that takes longer, like load a web page from a url, you need to either do it asynchronously with Qt's API, or spawn a thread to do the heavy lifting. Qt provides a whole bunch of apis for doing this (that overlap python's standard library. For example, instead of urllib2, there's QNetwork (http://pyqt.sourceforge.net/Docs/PyQt4/qtnetwork.html) that provides an asynchronous means of doing sockets, retrieving web content, etc. They aren't very pythonic probably, but they do all emit signals upon completion, so yo don't have to sit in a callback waiting for the download to complete. If you do want to spawn a thread to handle your longer-running task (normal urllib2), you'll have to come up with a way of notifying the main thread that the download is complete; you shouldn't call any GUI calls from the thread, typically. Here's an example of how to have a thread notify the main loop of completion: http://stackoverflow.com/questions/16879971/example-of-the-right-way-to-use-qthread-in-pyqt A quick google can reveal all this information, but it's harder if you don't know what to look for. So I hope this helps. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote: %s nötig %s % (uüblich, uähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) This is surprising to me - why is it trying to decode the format string, rather than encode the arguments? Probably to make it easier to mix byte and unicode strings. In hindsight it may not have been a good idea, but it had the potential to save some memory. I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On 11/19/2014 07:53 PM, Juan Christian wrote: Thanks, it's working using QTimer. The thing is that whenever the program is going to do something, in my case, draw a new QGroupBox with some components inside and put it in the Form (I'm using VBoxLayout in the main form) the program freezes, and I'm using very simple components just for testing.This shouldn't be normal, right? Am I doing something wrong? I clicked send too soon. The stackoverflow link is really referring to another link, which is much more complete and hopefully helpful to you: http://joplaete.wordpress.com/2010/07/21/threading-with-pyqt4/ -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten __pete...@web.de wrote: I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... Hang on a minute, what does it even mean to decode a Unicode string? That's where the problem is. Fortunately that's one that Py3 solved - str simply doesn't have a decode() method. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On Friday, July 31, 2009 2:10:45 PM UTC-6, kj wrote: I'm pretty new to Python, and I like a lot overall, but I find the documentation for Python rather poor, overall. I'm sure that Python experts don't have this problem: they have internalized some good ways to access the documentation, are productive with it, and therefore have lost the ability to see why the Python documentations is deficient for beginners. This explains why a suboptimal situation can persist like this: those who are most able fix it are also the least able to perceive it. I've heard similar complaints from other experienced programmers who are trying out Python for the first time: poor documentation. Here is an *entirely typical* example: on some Unix, try % pydoc urllib The displayed documentation mention the optional parameter data in practically every function listed (a few dozen of them). This parameter is not documented *anywhere* on that page. All that we are told is that its default value is always None. I'm sure that I can find a full description of this parameter if I fire up Google, and search online. In fact, more likely than not, I'll find far more documentation than I want. But my point is that a programmer should not need to do this. The full documentation should be readily accessible directly through a few keystrokes. I would love to know how experienced Python programmers quickly zero in on the Python documentation they need. TIA! kynn I write this to address the criticism which targets a user's lack of responsibility for the real/implied/insinuated failings of the docs. As a relatively inexperienced student of programming, I am not in any position to contribute/edit the documents. THAT DOES NOT, however, DENY THE CATEGORICAL STUPIDITY OF THE DOCUMENTATION: . Not only are the semantics of the editors in question, but so are the syntactical and grammatical conventions, too. Semantics, even in the hands of the honest, is a fuzzy beast; the elements of exposition and structure are not. Perhaps the inquisitive mind is correctly labeled stupid, or irresponsible, if it cannot decipher some fine piece of programming crypsis. And perhaps not. It can just as perhaps be that there is an equal, even greater irresponsibility, on the part of those who have taken up the task of clarifying the obscure to the confused. There is no greater arrogance, and it seems to me particularly prevalent among the educators in the techni cal fields, than pretending any hermeneutic, an effective hermeneutic. Sadly, most of these creatures cannot tell a verb from a noun, and scarcely know where modifiers are best, most effectively, posted to qualify their objects, let alone use those same nouns and verbs and modifiers to explain the intricacies of a subject. Tell one of these cognoscenti that language is about COMMUNICATION, and they begin pointing abstract fingers at their critics, and labeling. Perhaps the reason programs are so inelegant, and so user-UNfriendly, and so bug-infested, is a natural consequence, when a field is dominated by creatures who know much more than they comprehend, and much less than they need to? If, I think, you cannot explain a thing to me, you do not understand it. After all, I'm a lot smarter than you, and I have thankfully learned make out a fool however obscurely he covers himself. -- https://mail.python.org/mailman/listinfo/python-list
Re: pack circles into a partial annulus
I need to pack circles into a partial annulus ie part of a larger circle bounded by two radii and angles of say 18 90. You might take a look at Descartes Circle Theorem http://en.wikipedia.org/wiki/Descartes'_theorem Blub from google search In geometry, Descartes' theorem states that for every four kissing, or mutually tangent, circles, the radii of the circles satisfy a certain quadratic equation. By solving this equation, one can construct a fourth circle tangent to three given, mutually tangent circles. There is a screen saver in Debian Linux named Apollonian that uses this algorihm packing smaller circles into a larger circle The C source code for this screen saver is available under Debian -- Stanley C. Kitching Human Being Phoenix, Arizona -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Chris Angelico wrote: On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten __pete...@web.de wrote: I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... Hang on a minute, what does it even mean to decode a Unicode string? Let's not get philosophical ;) That's where the problem is. Fortunately that's one that Py3 solved - str simply doesn't have a decode() method. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 3:32 AM, Peter Otten __pete...@web.de wrote: Chris Angelico wrote: On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten __pete...@web.de wrote: I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... Hang on a minute, what does it even mean to decode a Unicode string? Let's not get philosophical ;) No, I'm quite serious. You encode Unicode text into bytes; you decode bytes into text. You can also encode a floating-point value into bytes, and decode bytes into a float. Or you could encode a large and complex structure into bytes, using something like pickle or json, and then decode those bytes later on. The pattern is always the same: the abstract object with meaning to a human is encoded into a concrete form that a computer can handle, and the concrete is decoded into the abstract. If you're not good at sight-reading sheet music, you'll have the same feeling of staring at the dots, decoding them one by one into this abstract thing called music, and then being able to work with it. When you try to decode a Unicode string, what happens is that Python 2 says Oh, you're trying to do a byte-string operation on a Unicode string... I'll quickly encode that to bytes for you, then do what you asked. That's why you can get an *en*coding error when you asked to *de*code - because both operations have to happen. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On 11/20/2014 09:32 AM, Peter Otten wrote: Chris Angelico wrote: On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten __pete...@web.de wrote: I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... Hang on a minute, what does it even mean to decode a Unicode string? Let's not get philosophical ;) It's not philosophical. It's an important distinction that folks need to be clear on when understanding unicode and the errors that python can throw. Unicode can only be encoded to bytes. Bytes can only be decoded to unicode. Without understanding that, the exception errors about decoding won't be properly understood, nor will one know how to fix them. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On Thu, Nov 20, 2014 at 10:54 AM, jstnms...@gmail.com wrote: On Friday, July 31, 2009 2:10:45 PM UTC-6, kj wrote: I'm pretty new to Python, and I like a lot overall, but I find the documentation for Python rather poor, overall. I'm sure that Python experts don't have this problem: they have internalized some good ways to access the documentation, are productive with it, and therefore have lost the ability to see why the Python documentations is deficient for beginners. This explains why a suboptimal situation can persist like this: those who are most able fix it are also the least able to perceive it. I've heard similar complaints from other experienced programmers who are trying out Python for the first time: poor documentation. Here is an *entirely typical* example: on some Unix, try % pydoc urllib The displayed documentation mention the optional parameter data in practically every function listed (a few dozen of them). This parameter is not documented *anywhere* on that page. All that we are told is that its default value is always None. I'm sure that I can find a full description of this parameter if I fire up Google, and search online. In fact, more likely than not, I'll find far more documentation than I want. But my point is that a programmer should not need to do this. The full documentation should be readily accessible directly through a few keystrokes. I would love to know how experienced Python programmers quickly zero in on the Python documentation they need. TIA! kynn I write this to address the criticism which targets a user's lack of responsibility for the real/implied/insinuated failings of the docs. As a relatively inexperienced student of programming, I am not in any position to contribute/edit the documents. THAT DOES NOT, however, DENY THE CATEGORICAL STUPIDITY OF THE DOCUMENTATION: . Not only are the semantics of the editors in question, but so are the syntactical and grammatical conventions, too. Semantics, even in the hands of the honest, is a fuzzy beast; the elements of exposition and structure are not. Perhaps the inquisitive mind is correctly labeled stupid, or irresponsible, if it cannot decipher some fine piece of programming crypsis. And perhaps not. It can just as perhaps be that there is an equal, even greater irresponsibility, on the part of those who have taken up the task of clarifying the obscure to the confused. There is no greater arrogance, and it seems to me particularly prevalent among the educators in the tech ni cal fields, than pretending any hermeneutic, an effective hermeneutic. Sadly, most of these creatures cannot tell a verb from a noun, and scarcely know where modifiers are best, most effectively, posted to qualify their objects, let alone use those same nouns and verbs and modifiers to explain the intricacies of a subject. Tell one of these cognoscenti that language is about COMMUNICATION, and they begin pointing abstract fingers at their critics, and labeling. Perhaps the reason programs are so inelegant, and so user-UNfriendly, and so bug-infested, is a natural consequence, when a field is dominated by creatures who know much more than they comprehend, and much less than they need to? If, I think, you cannot explain a thing to me, you do not understand it. After all, I'm a lot smarter than you, and I have thankfully learned make out a fool however obscurely he covers himself. -- https://mail.python.org/mailman/listinfo/python-list I learned a new word: hermeneutic Or just WOW!. Programming is hard, and people have just started to do it. Fifty years isn't that long. It has only been 20 years or so that the web has been around. That makes it easier to find information from a variety or sources -- the official docs, tutorials, articles. If you feel the docs are awful, write a tutorial based on your knowledge level and experience. Improve the situation. I'm trying to wrap my mind around DOCUMENTION being STUPID. -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On 11/20/2014 08:54 AM, jstnms...@gmail.com wrote: Perhaps the reason programs are so inelegant, and so user-UNfriendly, and so bug-infested, is a natural consequence, when a field is dominated by creatures who know much more than they comprehend, and much less than they need to? If, I think, you cannot explain a thing to me, you do not understand it. After all, I'm a lot smarter than you, and I have thankfully learned make out a fool however obscurely he covers himself. I'm not really sure what your point is, who are you are talking to, or the purpose in replying to your own post from 5 years ago! You seem to be addressing you but I don't know who that is. Kudos for apparently sticking with Python despite your struggles with its documentation. Personally I find the online docs to be *very* good, comparable to the best of documentation for programming languages anywhere. For example, Python's official docs have either improved since your last look in 2009, or maybe you didn't know to look there: https://docs.python.org/2/library/urllib2.html https://docs.python.org/2/howto/urllib2.html The data parameter that confused you so much in 2009 is explained very clearly. But if it's not clear enough, try it out and see what it does. Python is a very discoverable language. Just fire up the interpreter and try out code, and interrogate the returned objects (dir, help, etc). Between the python docs and loads of helpful folk on this list and on the web in general, I can do a google search on just about any python-related coding question and find loads (heaps for Chris!) of helpful information including complete examples, which I find very helpful. I'm sure google was around in 2009 when you last posted. Surely you could have googled for python urllib example and found one. For all your talk of communication and many words, you're saying very little, I'm not at all sure what you are talking and to whom your audience is. Since you're apparently not explaining this does that mean you don't understand it? Methinks you are misrepresenting the adage about being able to explain something is to understand it. If an engineer explains dynamic force analysis to you but you don't understand, does that mean he really doesn't understand it? Of course not. He just lacks the ability to explain it in terms of reference you will understand, or maybe you lack prerequisite knowledge. Study engineering for a while and you'll understand him well enough. If you're just trolling, hopefully the list will forgive me. -- https://mail.python.org/mailman/listinfo/python-list
Re: How modules work in Python
On 11/19/2014 02:50 PM, Chris Angelico wrote: On Thu, Nov 20, 2014 at 6:00 AM, sohcahto...@gmail.com wrote: I only started reading this list about a month ago, and from what I've seen, being pedantic is pretty much par for the course. Usually in a good way. :) And often for good reason. -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with HTML5 documents
On Wed, 19 Nov 2014 13:43:17 -0800, Novocastrian_Nomad wrote: On Wednesday, November 19, 2014 2:08:27 PM UTC-7, Denis McMahon wrote: So what I'm looking for is a method to create an html5 document using dom manipulation, ie: doc = new htmldocument(doctype=HTML) html = new html5element(html) doc.appendChild(html) head = new html5element(body) html.appendChild(head) body = new html5element(body) html.appendChild(body) title = new html5element(title) txt = new textnode(This Is The Title) title.appendChild(txt) head.appendChild(title) para = new html5element(p) txt = new textnode(This is some text.) para.appendChild(txt) body.appendChild(para) print(doc.serialise()) generates: !doctype HTMLhtmlheadtitleThis Is The Title/title/ headbodypThis is some text./p/body/html I'm finding various mechanisms to generate the structure from an existing piece of html (eg html5lib, beautifulsoup etc) but I can't seem to find any mechanism to generate, manipulate and produce html5 documents using this dom manipulation approach. Where should I be looking? Use a search engine (Google, DuckDuckGo etc) and search for 'python write html' Surprise surprise, already tried that, can't find anything that holds the document in the sort of tree structure that I want to manipulate it in. Everything there seems to assume I'll be creating a document serially, eg that I won't get to some point in the document and decide that I want to add an element earlier. bs4 and html5lib will parse a document into a tree structure, but they're not so hot on manipulating the tree structure, eg adding and moving nodes. Actually it looks like bs4 is going to be my best bet, although limited it does have most of what I'm looking for. I just need to start by giving it html/html to parse. -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On Thu, Nov 20, 2014 at 9:54 AM, jstnms...@gmail.com wrote: Here is an *entirely typical* example: on some Unix, try % pydoc urllib I don't know who kj is, and jstnms123 seems to be basically off his rocker, so I won't try cc'ing either of them. (They also seem to misunderstand the nature of contributing to open source software, but I'll ignore that.) Hopefully I'm not duplicating someone else's response. I just stumbled on this thread. A couple things to note. One, pydoc just assembles the documentation strings for the item you asked for. Python has both inline documentation (meant to be brief, quick reference material) and long form documentation (the library and reference documentation, as well as the tutorial.) Pydoc just extracts what is available at the interpreter prompt if you execute import urllib help(urllib) That is meant to answer quick questions like, what arguments does urllib.urlopen accept?, not, what's the overall intent of the urllib module?. Despite its admitted brevity, note that if you ask pydoc for a module's documentation, that at the very top of its output, it also identifies the location of the source code on your system and refers you to the long form online documentation: Help on module urllib: NAME urllib - Open an arbitrary URL. FILE /opt/TWWfsw/python27/lib/python2.7/urllib.py MODULE DOCS http://docs.python.org/library/urllib DESCRIPTION ... I in no way mean to suggest that the documentation can't be improved. I'm simply pointing out that the documentation is almost certainly better than kj and jstnms123 give the authors credit for. I added that particular feature to the pydoc module over ten years ago, so I know it is highly unlikely your version of pydoc is missing this feature. Skip -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with HTML5 documents
On Thursday, November 20, 2014 12:04:09 PM UTC-5, Denis McMahon wrote: On Wed, 19 Nov 2014 13:43:17 -0800, Novocastrian_Nomad wrote: On Wednesday, November 19, 2014 2:08:27 PM UTC-7, Denis McMahon wrote: So what I'm looking for is a method to create an html5 document using dom manipulation, ie: doc = new htmldocument(doctype=HTML) html = new html5element(html) doc.appendChild(html) head = new html5element(body) html.appendChild(head) body = new html5element(body) html.appendChild(body) title = new html5element(title) txt = new textnode(This Is The Title) title.appendChild(txt) head.appendChild(title) para = new html5element(p) txt = new textnode(This is some text.) para.appendChild(txt) body.appendChild(para) print(doc.serialise()) generates: !doctype HTMLhtmlheadtitleThis Is The Title/title/ headbodypThis is some text./p/body/html I'm finding various mechanisms to generate the structure from an existing piece of html (eg html5lib, beautifulsoup etc) but I can't seem to find any mechanism to generate, manipulate and produce html5 documents using this dom manipulation approach. Where should I be looking? Use a search engine (Google, DuckDuckGo etc) and search for 'python write html' Surprise surprise, already tried that, can't find anything that holds the document in the sort of tree structure that I want to manipulate it in. Everything there seems to assume I'll be creating a document serially, eg that I won't get to some point in the document and decide that I want to add an element earlier. bs4 and html5lib will parse a document into a tree structure, but they're not so hot on manipulating the tree structure, eg adding and moving nodes. Actually it looks like bs4 is going to be my best bet, although limited it does have most of what I'm looking for. I just need to start by giving it html/html to parse. -- Denis McMahon I believe lxml should work for this. Here's a snippet that I have used to create an HTML document: from lxml import etree page = etree.Element('html') doc = etree.ElementTree(page) head = etree.SubElement(page, 'head') body = etree.SubElement(page, 'body') table = etree.SubElement(body, 'table') etc etc with open('mynewfile.html', 'wb') as f: doc.write(f, pretty_print=True, method='html') (you can leave out the method= option to get xhtml). hope that helps, --Tim -- https://mail.python.org/mailman/listinfo/python-list
Help with an 8th grade science project
Hello, I am the adult advisor (aka father) to an 8th grader who is doing a science project that will compare / benchmark CPU performance between an AMD 64 Phenom II running Ubuntu 14.04 and a Raspberry Pi 700MHz ARM. Basic procedure: - Run a Python script on both computers that that stresses the CPU and measure -- Time to complete the calculation -- Max CPU during the calculation -- We have chosen to do factorials and compare performance by running calculations by order of magnitude. Our hypothesis is that we will begin to see a wider performance gap between the two computers as the factorials increase in order of magnitude. Status: - We have a working program. Pseudo code follows: import linux_metrics from linux_metrics import cpu_stat import time print 'Welcome to the stress test' number = raw_input(Enter the number to compute the factorial:) ## function to calculate CPU usage percentage def CPU_Percent(): cpu_pcts = cpu_stat.cpu_percents(.25) print 'cpu utilization: %.2f%%' % (100 - cpu_pcts['idle']) write cpu utilization to a csv file with g.write ## function to compute factorial of a given number def factorial(n): num = 1 while n = 1: num = num * n CPU_Percent() This is the function call irt Q 1 below n = n - 1 return num # Main program Record start time by using time.time() Call function to compute the factorial. Record finish time by using time.time() write time to compute to a file f.write(totalEndTime - totalStartTime) print (Execution time = , totalEndTime - totalStartTime) Questions: 1. In the factorial() function we call the CPU_Percent() function and write the CPU utilization value to a file. - Is this a correct value or will the CPU utilization below lower because the factorial() function made its calculation and is now just checking the CPU utilization? - If we are not getting the true max CPU utilization, can someone offer a design change to accomplish this? 2. What unit does time.time() use? An example for calculating the factorial of 10 is our program gives: Execution time = ', 1.5703258514404297 I presume this is telling us it took 1.57 seconds to complete the calculation? Thanks in advance for any help / suggestions. Best regards, Dave -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Chris Angelico wrote: On Fri, Nov 21, 2014 at 3:32 AM, Peter Otten __pete...@web.de wrote: Chris Angelico wrote: On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten __pete...@web.de wrote: I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... Hang on a minute, what does it even mean to decode a Unicode string? Let's not get philosophical ;) No, I'm quite serious. I'm sorry I'm limited to text, otherwise I would have formatted the ;) as 30pt blinking magenta... You encode Unicode text into bytes; you decode bytes into text. You can also encode a floating-point value into bytes, and decode bytes into a float. Or you could encode a large and complex structure into bytes, using something like pickle or json, and then decode those bytes later on. The pattern is always the same: the abstract object with meaning to a human is encoded into a concrete form that a computer can handle, and the concrete is decoded into the abstract. If you're not good at sight-reading sheet music, you'll have the same feeling of staring at the dots, decoding them one by one into this abstract thing called music, and then being able to work with it. When you try to decode a Unicode string, what happens is that Python 2 says Oh, you're trying to do a byte-string operation on a Unicode string... I'll quickly encode that to bytes for you, then do what you asked. That's why you can get an *en*coding error when you asked to *de*code - because both operations have to happen. In an alternative universe unicode.decode() could have been implemented as a no-op. As you put it it looks like you have to find the true nature of the problem and then cast it into code -- a kind of essentialism. I would rather emphasise the process; the evolving interface changes your view on the underlying problem -- a hermeneutic cycle if you will. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014, at 09:59, Chris Angelico wrote: On Fri, Nov 21, 2014 at 12:59 AM, random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote: %s nötig %s % (uüblich, uähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) This is surprising to me - why is it trying to decode the format string, rather than encode the arguments? Why should it encode to bytes? Because a bytes format string suggests a bytes result. Why does unicode always win, rather than the type of the format string always winning? Makes much better sense to work in Unicode. But mainly, it has to do one of them, and be predictable. Yeah, but string % is not a symmetrical operator. People's mental model of it is likely to be that it acts like format (which does use the type of the format string) or C sprintf/wsprintf (both of which use the same type for the format string and result). And literally every other type is converted to the type of the format string when used with %s - having unicode be special adds cognitive load, and it means you can't safely blindly use %s with an unknown object. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
So, I need to study QThreads, do you know any book or video-course that talks about this matter? I've seen the tutorials that you pointed but I need a wider approach regarding QThreads to really understand it and apply it to my needs. The docs aren't that clear for me. On Thu Nov 20 2014 at 1:43:21 PM Michael Torrie torr...@gmail.com wrote: On 11/19/2014 07:53 PM, Juan Christian wrote: Thanks, it's working using QTimer. The thing is that whenever the program is going to do something, in my case, draw a new QGroupBox with some components inside and put it in the Form (I'm using VBoxLayout in the main form) the program freezes, and I'm using very simple components just for testing.This shouldn't be normal, right? Am I doing something wrong? I clicked send too soon. The stackoverflow link is really referring to another link, which is much more complete and hopefully helpful to you: http://joplaete.wordpress.com/2010/07/21/threading-with-pyqt4/ -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Challenge: optimizing isqrt
On 01.11.14 03:29, Steven D'Aprano wrote: There is an algorithm for calculating the integer square root of any positive integer using only integer operations: Here is my optimized implementation inspired by Christian's ideas. import math, sys C1 = sys.float_info.radix ** sys.float_info.mant_dig C2 = int(sys.float_info.max) C3 = C2.bit_length() - 2 def isqrt(n): if n 0: raise ValueError if n == 0: return 0 if n = C1: return int(math.sqrt(n)) if n = C2: x = int(math.sqrt(n)) else: b = (n.bit_length() - C3) // 2 x = int(math.sqrt(n (2 * b))) b y = (x + n // x) // 2 if y == x: return x while True: x = y y = (x + n // x) // 2 if y = x: return x -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014 at 10:42 AM, random...@fastmail.us wrote: and it means you can't safely blindly use %s with an unknown object. You can't safely do this anyway. Whether it's %s with a str and a unicode, or %s with a unicode and a str, *something* is going to have to be implicitly encoded or decoded, and if ascii doesn't happen to be the correct encoding then the result will be either an error or a silent failure. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014 at 11:06 AM, Ian Kelly ian.g.ke...@gmail.com wrote: On Thu, Nov 20, 2014 at 10:42 AM, random...@fastmail.us wrote: and it means you can't safely blindly use %s with an unknown object. You can't safely do this anyway. Whether it's %s with a str and a unicode, or %s with a unicode and a str, *something* is going to have to be implicitly encoded or decoded, and if ascii doesn't happen to be the correct encoding then the result will be either an error or a silent failure. Also note that if you use %r instead of %s, you'll get the result you want (although the unicode string will be quoted rather than encoded). -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 09:59, Chris Angelico wrote: On Fri, Nov 21, 2014 at 12:59 AM, random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 07:35, Peter Otten wrote: %s nötig %s % (uüblich, uähnlich) Traceback (most recent call last): File stdin, line 1, in module UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128) This is surprising to me - why is it trying to decode the format string, rather than encode the arguments? Why should it encode to bytes? Because a bytes format string suggests a bytes result. Why does unicode always win, rather than the type of the format string always winning? My guess is that when unicode was introduced the decision to propagate str to unicode in some cases was made because the developers expected that more old code that was unaware of unicode would continue to work. The old methods __mod__(), replace(), and join() that conceptually deal with strings propate while those that deal with characters -- center(), r/ljust(), translate() -- dont. The newer format() method doesn't propagate which is probably due to a change in attitude rather than an oversight. -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On Wednesday, November 19, 2014 8:59:01 PM UTC-8, Steven D'Aprano wrote: And the award for the most gratuitous comments before an import goes to one of my (former) workmates, who wrote this piece of code: # Used for base64-decoding. import base64 # Used for ungzipping. import gzip -- Steven I blame CS professors that demand that every line of code be commented. # increment x x += 1 -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Michael Torrie torr...@gmail.com: Unicode can only be encoded to bytes. Bytes can only be decoded to unicode. I don't really like it how Unicode is equated with text, or even character strings. There's barely any difference between the truth value of these statements: Python strings are ASCII. Python strings are Latin-1. Python strings are Unicode. Each of those statements is true as long as you stay within the respective character sets, and cease to be true when your text contains characters outside the character sets. Now, it is true that Python currently limits itself to the 1,114,112 Unicode code points. And it likely won't adopt more characters unless Unicode does it first. However, text is something more lofty and abstract than a sequence of Unicode code points. We shouldn't call strings Unicode any more than we call numbers IEEE or times ISO. Marko -- https://mail.python.org/mailman/listinfo/python-list
Python IDE.
Can someone suggest a good python IDE. -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with HTML5 documents
Tim schrieb am 20.11.2014 um 18:31: On Thursday, November 20, 2014 12:04:09 PM UTC-5, Denis McMahon wrote: On Wednesday, November 19, 2014 2:08:27 PM UTC-7, Denis McMahon wrote: So what I'm looking for is a method to create an html5 document using dom manipulation, ie: doc = new htmldocument(doctype=HTML) html = new html5element(html) doc.appendChild(html) head = new html5element(body) html.appendChild(head) body = new html5element(body) html.appendChild(body) title = new html5element(title) txt = new textnode(This Is The Title) title.appendChild(txt) head.appendChild(title) para = new html5element(p) txt = new textnode(This is some text.) para.appendChild(txt) body.appendChild(para) print(doc.serialise()) generates: !doctype HTMLhtmlheadtitleThis Is The Title/title/ headbodypThis is some text./p/body/html I'm finding various mechanisms to generate the structure from an existing piece of html (eg html5lib, beautifulsoup etc) but I can't seem to find any mechanism to generate, manipulate and produce html5 documents using this dom manipulation approach. Where should I be looking? Everything there seems to assume I'll be creating a document serially, eg that I won't get to some point in the document and decide that I want to add an element earlier. bs4 and html5lib will parse a document into a tree structure, but they're not so hot on manipulating the tree structure, eg adding and moving nodes. Actually it looks like bs4 is going to be my best bet, although limited it does have most of what I'm looking for. I just need to start by giving it html/html to parse. I believe lxml should work for this. Here's a snippet that I have used to create an HTML document: from lxml import etree page = etree.Element('html') doc = etree.ElementTree(page) head = etree.SubElement(page, 'head') body = etree.SubElement(page, 'body') table = etree.SubElement(body, 'table') etc etc with open('mynewfile.html', 'wb') as f: doc.write(f, pretty_print=True, method='html') (you can leave out the method= option to get xhtml). There's also the E-factory for creating (sub-)trees and a nicely objectish way: http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory and the just released lxml 3.4.1 has an htmlfile context manager that allows you to generate HTML incrementally: http://lxml.de/api.html#incremental-xml-generation Obviously, you can combine both, so you can create a subtree in memory and write it into an incrementally built HTML stream. Pretty versatile. Stefan -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On 11/20/2014 10:57 AM, Juan Christian wrote: So, I need to study QThreads, do you know any book or video-course that talks about this matter? I've seen the tutorials that you pointed but I need a wider approach regarding QThreads to really understand it and apply it to my needs. The docs aren't that clear for me. Yes you should definitely study up on QThreads. What is unclear about the docs? Which docs did you read? Did you read the links I sent you, particularly the wordpress blog post where he had a complete example (although I understand that it's not quite the correct way to do it)? What things have you tried searching for? Google reveals another discussion on stackoverflow which seems to give you a pretty complete, and correct, example: http://stackoverflow.com/questions/16241297/how-to-signal-from-a-running-qthread-back-to-the-pyqt-gui-that-started-it . Note that the first post there is not working, but the fix is listed in the second post. Put them together and you'll have a working example. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On Thu, Nov 20, 2014 at 2:01 PM, dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. PyCharm, but it's not free. -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
Chris Angelico schrieb am 20.11.2014 um 06:06: On Thu, Nov 20, 2014 at 3:58 PM, Steven D'Aprano wrote: And the award for the most gratuitous comments before an import goes to one of my (former) workmates, who wrote this piece of code: # Used for base64-decoding. import base64 # Used for ungzipping. import gzip Well hey. Good to know he's using the tools for their intended purposes! Not necessarily. The comments only suggest that the imports were added (or at least commented on) with the intended purpose in mind. Whether that purpose is still what the modules are used for or whether they are even still in use at all, is unclear from the above. Stefan -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On Thursday, November 20, 2014 2:09:24 PM UTC-5, larry@gmail.com wrote: On Thu, Nov 20, 2014 at 2:01 PM, dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. PyCharm, but it's not free. If you can tell me a free one, that will be great. I was looking at the following document, which states different IDE's. http://www.linuxcandy.com/2012/07/which-python-ide-is-best-choose-your-own.html -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On 20-11-2014 20:19, dvenkatj2ee...@gmail.com wrote: On Thursday, November 20, 2014 2:09:24 PM UTC-5, larry@gmail.com wrote: On Thu, Nov 20, 2014 at 2:01 PM, dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. PyCharm, but it's not free. If you can tell me a free one, that will be great. I was looking at the following document, which states different IDE's. http://www.linuxcandy.com/2012/07/which-python-ide-is-best-choose-your-own.html PyCharm *is* free, if you fall in one of several categories. See http://www.jetbrains.com/pycharm/buy/license-matrix.jsp Even when you have to buy it, it is cheap (IMO) for what it offers. Irmen -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On 11/20/2014 12:01 PM, dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. I'm sure Google can reveal many options and opinions on the matter. Personally I don't find IDEs that useful with Python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On Thu, 20 Nov 2014 11:19:23 -0800, dvenkatj2eedev wrote: On Thursday, November 20, 2014 2:09:24 PM UTC-5, larry@gmail.com wrote: On Thu, Nov 20, 2014 at 2:01 PM, dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. PyCharm, but it's not free. If you can tell me a free one, that will be great. I was looking at the following document, which states different IDE's. http://www.linuxcandy.com/2012/07/which-python-ide-is-best-choose-your- own.html lotts of good options there. try one see how you feel if it dosn't suit try another btw it would help if you specified your os although may are available for most platforms -- The man who raises a fist has run out of ideas. -- H.G. Wells, Time After Time -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
Yes, I read everything and saw that stackoverlfow on Google too. I'm reading this doc: http://pyqt.sourceforge.net/Docs/PyQt4/classes.html I just asked for a book because normally there are books for anything =p On Thu Nov 20 2014 at 5:08:09 PM Michael Torrie torr...@gmail.com wrote: On 11/20/2014 10:57 AM, Juan Christian wrote: So, I need to study QThreads, do you know any book or video-course that talks about this matter? I've seen the tutorials that you pointed but I need a wider approach regarding QThreads to really understand it and apply it to my needs. The docs aren't that clear for me. Yes you should definitely study up on QThreads. What is unclear about the docs? Which docs did you read? Did you read the links I sent you, particularly the wordpress blog post where he had a complete example (although I understand that it's not quite the correct way to do it)? What things have you tried searching for? Google reveals another discussion on stackoverflow which seems to give you a pretty complete, and correct, example: http://stackoverflow.com/questions/16241297/how-to- signal-from-a-running-qthread-back-to-the-pyqt-gui-that-started-it . Note that the first post there is not working, but the fix is listed in the second post. Put them together and you'll have a working example. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
Another problem is that this doc doesn't use Python. On Thu Nov 20 2014 at 5:36:37 PM Juan Christian juan0christ...@gmail.com wrote: Yes, I read everything and saw that stackoverlfow on Google too. I'm reading this doc: http://pyqt.sourceforge.net/Docs/PyQt4/classes.html I just asked for a book because normally there are books for anything =p On Thu Nov 20 2014 at 5:08:09 PM Michael Torrie torr...@gmail.com wrote: On 11/20/2014 10:57 AM, Juan Christian wrote: So, I need to study QThreads, do you know any book or video-course that talks about this matter? I've seen the tutorials that you pointed but I need a wider approach regarding QThreads to really understand it and apply it to my needs. The docs aren't that clear for me. Yes you should definitely study up on QThreads. What is unclear about the docs? Which docs did you read? Did you read the links I sent you, particularly the wordpress blog post where he had a complete example (although I understand that it's not quite the correct way to do it)? What things have you tried searching for? Google reveals another discussion on stackoverflow which seems to give you a pretty complete, and correct, example: http://stackoverflow.com/questions/16241297/how-to-signal- from-a-running-qthread-back-to-the-pyqt-gui-that-started-it . Note that the first post there is not working, but the fix is listed in the second post. Put them together and you'll have a working example. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with HTML5 documents
On Thu, Nov 20, 2014 at 12:02 PM, Stefan Behnel stefan...@behnel.de wrote: There's also the E-factory for creating (sub-)trees and a nicely objectish way: http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory That looks ugly with all those caps and also hard to extend. Notably it seems to be missing any functions to build HTML5 elements, unless those have been added in lxml 3.4. Working with lxml.html.Element directly seems pretty versatile, though. -- https://mail.python.org/mailman/listinfo/python-list
RE: Python IDE.
Community edition is free but with limited capability, although you will be hard pressed to find a limiting factor especially for general programming. All of the bells and whistles can be found in the sold product. Also, the student/teacher edition is available, and in fact a new version came out today. It is somewhere between pro and community I think. Clayton -Original Message- From: Python-list [mailto:python-list- bounces+crk=godblessthe...@python.org] On Behalf Of Larry Martell Sent: Thursday, November 20, 2014 11:09 AM To: python-list@python.org Subject: Re: Python IDE. On Thu, Nov 20, 2014 at 2:01 PM, dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. PyCharm, but it's not free. -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with HTML5 documents
Ian Kelly schrieb am 20.11.2014 um 20:44: On Thu, Nov 20, 2014 at 12:02 PM, Stefan Behnel wrote: There's also the E-factory for creating (sub-)trees and a nicely objectish way: http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory That looks ugly with all those caps and also hard to extend. Notably it seems to be missing any functions to build HTML5 elements, unless those have been added in lxml 3.4. It's actually trivial to extend, and it's designed for it. The factory simply uses __getattr__(), so you can ask it for any tag name. The predefined names in the builder.py module are mainly there to easily detect typos on user side. https://github.com/lxml/lxml/blob/master/src/lxml/html/builder.py If you don't like capital names for constants, just copy the module and change the tag names to lower case, or use the blank E-factory if you feel like it. Stefan -- https://mail.python.org/mailman/listinfo/python-list
Re:Help with an 8th grade science project
dave em daveandem2...@gmail.com Wrote in message: Hello, I am the adult advisor (aka father) to an 8th grader who is doing a science project that will compare / benchmark CPU performance between an AMD 64 Phenom II running Ubuntu 14.04 and a Raspberry Pi 700MHz ARM. Basic procedure: - Run a Python script on both computers that that stresses the CPU and measure -- Time to complete the calculation -- Max CPU during the calculation -- We have chosen to do factorials and compare performance by running calculations by order of magnitude. Our hypothesis is that we will begin to see a wider performance gap between the two computers as the factorials increase in order of magnitude. Status: - We have a working program. Pseudo code follows: import linux_metrics from linux_metrics import cpu_stat import time print 'Welcome to the stress test' number = raw_input(Enter the number to compute the factorial:) ## function to calculate CPU usage percentage def CPU_Percent(): cpu_pcts = cpu_stat.cpu_percents(.25) print 'cpu utilization: %.2f%%' % (100 - cpu_pcts['idle']) write cpu utilization to a csv file with g.write ## function to compute factorial of a given number def factorial(n): num = 1 while n = 1: num = num * n CPU_Percent() This is the function call irt Q 1 below n = n - 1 return num # Main program Record start time by using time.time() Call function to compute the factorial. Record finish time by using time.time() write time to compute to a file f.write(totalEndTime - totalStartTime) print (Execution time = , totalEndTime - totalStartTime) Questions: 1. In the factorial() function we call the CPU_Percent() function and write the CPU utilization value to a file. - Is this a correct value or will the CPU utilization below lower because the factorial() function made its calculation and is now just checking the CPU utilization? I'm not familiar with that package; I just took a quick look at pypi. So I'd have to guess. But since your timing is so huge, I'd guess that you're measuring utilization during a time period that your factorial calculation is paused. In other words you're measuring cpu utilization for the other processes in your system. Probably someone else will correct me, but I'd guess you need to measure utilization with a separate process. - If we are not getting the true max CPU utilization, can someone offer a design change to accomplish this? 2. What unit does time.time() use? An example for calculating the factorial of 10 is our program gives: Execution time = ', 1.5703258514404297 I presume this is telling us it took 1.57 seconds to complete the calculation? It does indeed give results in seconds, but that value is ridiculous. Calculating factorial of 10 takes about 70 microseconds on this laptop. And doing it for 10,000 (which gives a very large result) takes about a tenth of a second. Including printing it, which takes longer than calculating it. Benchmarking can be extremely tricky, and I assume you're not permitted to use the timeit module. But at the very least: Measure an empty loop and compare it to the real loop. If they both measure similar, then you're mostly measuring loop overhead. Watch out for doing i/o during the timed part of the test; you may be mostly measuring console time or file time, and not your algorithm. Do your i/o after the ending call to time.time. If you get times in the microsecond or millisecond range, put the whole mess in a loop so you can do a sanity check with your wrist watch. Check each systems to make sure time.time works well. Read the docs, but do your own tests. Some systems only give you integer seconds. If you're stuck with overhead that'll affect your results, do some measurements to see how to minimize it. I'd guess that range (or xrange, since you're apparently using Python 2.x) will be faster than while with increment. If you're comparing two entirely different processors, make sure you're using exactly the same version of Python. 2.75 on one system probably should not be compared with 2.62, or even with 2.74 Don't forget the effects of other processes, and of disk caching. You can orobably minimize them by a fresh boot, and by flushing. Watch out for memory usage. You can calculate the factorial of one hundred thousand in a few seconds. But it's some 450 thousand digits long, and takes quite a bit of memory. The math module has a factorial function in it. You could use it to double check your results and your timings. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
**Back to the list So, as I said the PyQt doc is using C o.0 Yes, I read the tutorials, I'll google for some books and things related. On Tue Nov 18 2014 at 10:48:44 AM Vincent Vande Vyvre vincent.vande.vy...@telenet.be wrote: Le 18/11/2014 13:18, Juan Christian a écrit : I have this simple code that load any Qt Designer .UI file: from PySide.QtCore import QFile from PySide.QtGui import QApplication from PySide.QtUiTools import QUiLoader def loadui(file_name): loader = QUiLoader() uifile = QFile(file_name) uifile.open(QFile.ReadOnly) ui = loader.load(uifile) uifile.close() return ui if __name__ == __main__: import sys app = QApplication(sys.argv) MainWindow = loadui(main.ui) MainWindow.show() app.exec_() Let's say I have a QTextEdit called txtbox. How can I access this txtbox inside my Python code? How about MainWindow.txtbox ? -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Help with an 8th grade science project
On Thu, Nov 20, 2014 at 1:13 PM, Dave Angel da...@davea.name wrote: dave em daveandem2...@gmail.com Wrote in message: 1. In the factorial() function we call the CPU_Percent() function and write the CPU utilization value to a file. - Is this a correct value or will the CPU utilization below lower because the factorial() function made its calculation and is now just checking the CPU utilization? I'm not familiar with that package; I just took a quick look at pypi. So I'd have to guess. But since your timing is so huge, I'd guess that you're measuring utilization during a time period that your factorial calculation is paused. In other words you're measuring cpu utilization for the other processes in your system. Probably someone else will correct me, but I'd guess you need to measure utilization with a separate process. I'm not familiar with it either, but I would guess that it's probably just pulling data from /proc/stat. The data is not going to be any different if pulled from one process versus another. However, the time that is spent waiting for this data could skew the results if done a lot, so I suggest doing it only once at the end of the factorial function rather than on every iteration of the factorial loop. If you want multiple measurements while the function is running, then either check it only every X iterations, or run a separate process and check it every 100 milliseconds or so. The latter is probably preferable since the time between iterations will depend on the system and will also get progressively slower for large factorials. -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On 20/11/2014 18:06, Ian Kelly wrote: On Thu, Nov 20, 2014 at 10:42 AM, random...@fastmail.us wrote: and it means you can't safely blindly use %s with an unknown object. You can't safely do this anyway. Whether it's %s with a str and a unicode, or %s with a unicode and a str, *something* is going to have to be implicitly encoded or decoded, and if ascii doesn't happen to be the correct encoding then the result will be either an error or a silent failure. All I know about this encoding/decoding malarky is that I'd prefer an error to a silent failure any day of the week. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On 20/11/2014 17:57, Juan Christian wrote: So, I need to study QThreads, do you know any book or video-course that talks about this matter? I've seen the tutorials that you pointed but I need a wider approach regarding QThreads to really understand it and apply it to my needs. The docs aren't that clear for me. You also need to study the difference between top posting, interspersed posting and bottom posting. The second and third are very much the prefered styles here. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Help with an 8th grade science project
On Thursday, November 20, 2014 1:48:06 PM UTC-7, Ian wrote: On Thu, Nov 20, 2014 at 1:13 PM, Dave Angel da...@davea.name wrote: 1. In the factorial() function we call the CPU_Percent() function and write the CPU utilization value to a file. - Is this a correct value or will the CPU utilization below lower because the factorial() function made its calculation and is now just checking the CPU utilization? I'm not familiar with that package; I just took a quick look at pypi. So I'd have to guess. But since your timing is so huge, I'd guess that you're measuring utilization during a time period that your factorial calculation is paused. In other words you're measuring cpu utilization for the other processes in your system. Probably someone else will correct me, but I'd guess you need to measure utilization with a separate process. I'm not familiar with it either, but I would guess that it's probably just pulling data from /proc/stat. The data is not going to be any different if pulled from one process versus another. However, the time that is spent waiting for this data could skew the results if done a lot, so I suggest doing it only once at the end of the factorial function rather than on every iteration of the factorial loop. If you want multiple measurements while the function is running, then either check it only every X iterations, or run a separate process and check it every 100 milliseconds or so. The latter is probably preferable since the time between iterations will depend on the system and will also get progressively slower for large factorials. All, thanks for all of the advice. I took the function call to measure CPU usage out of the loop and now get very fast responses. For example execution time for 1 is 0.46 seconds and for 10 is 0.0082 seconds. I took a quick look at subprocesses to run the cpu function simultaneously with the factorial function or maybe we can figure out a way to use something like top and filter out CPU while we run the factorial program. Anyway, thanks for all of the help and the sanity check on the times I was getting. Best regards, Dave -- https://mail.python.org/mailman/listinfo/python-list
Re: Working with HTML5 documents
On Thu, Nov 20, 2014 at 1:10 PM, Stefan Behnel stefan...@behnel.de wrote: Ian Kelly schrieb am 20.11.2014 um 20:44: On Thu, Nov 20, 2014 at 12:02 PM, Stefan Behnel wrote: There's also the E-factory for creating (sub-)trees and a nicely objectish way: http://lxml.de/lxmlhtml.html#creating-html-with-the-e-factory That looks ugly with all those caps and also hard to extend. Notably it seems to be missing any functions to build HTML5 elements, unless those have been added in lxml 3.4. It's actually trivial to extend, and it's designed for it. The factory simply uses __getattr__(), so you can ask it for any tag name. The predefined names in the builder.py module are mainly there to easily detect typos on user side. This is not the case from what I saw in my testing based on the documentation. Python 2.7.6 (default, Mar 22 2014, 22:59:56) [GCC 4.8.2] on linux2 Type help, copyright, credits or license for more information. from lxml.html import builder as E html = E.HTML(E.HEAD(), E.BODY()) html = E.HTML(E.HEAD(), E.BODY(E.ARTICLE())) Traceback (most recent call last): File stdin, line 1, in module AttributeError: 'module' object has no attribute 'ARTICLE' https://github.com/lxml/lxml/blob/master/src/lxml/html/builder.py If you don't like capital names for constants, just copy the module and change the tag names to lower case, or use the blank E-factory if you feel like it. Based on the source file that you linked, I can see that this would work but is undocumented: from lxml.builder import ElementMaker import lxml.html E = ElementMaker(makeelement=lxml.html.html_parser.makeelement) html = E.html(E.head(), E.body(E.article())) lxml.html.tostring(html) 'htmlhead/headbodyarticle/article/body/html' -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On Thu Nov 20 2014 at 7:07:10 PM Mark Lawrence breamore...@yahoo.co.uk wrote: You also need to study the difference between top posting, interspersed posting and bottom posting. The second and third are very much the prefered styles here. Yes I know, but I'm using the new Google Inbox, and I limited to what I can do when replying, to do the right way I have to do many steps now... -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On 11/20/2014 07:53 AM, Chris Angelico wrote: On Fri, Nov 21, 2014 at 2:40 AM, Peter Otten __pete...@web.de wrote: I think that you may get a Unicode/Encode/Error when you try to /decode/ a unicode string is more confusing... Hang on a minute, what does it even mean to decode a Unicode string? That's where the problem is. Fortunately that's one that Py3 solved - str simply doesn't have a decode() method. If your unicode string happens to contain a base64 encoded .png, then you could decode that into bytes. ;) -- ~Ethan~ signature.asc Description: OpenPGP digital signature -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
sohcahto...@gmail.com wrote: # increment x x += 1 But it shouldn't say 'increment x', it should say 'add one to the line count' or some such. Although changing the variable name to 'lineCount' would do almost as well. -- Chris Green · -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On Thursday, November 20, 2014 1:33:16 PM UTC-8, c...@isbd.net wrote: s...@gmail.com wrote: # increment x x += 1 But it shouldn't say 'increment x', it should say 'add one to the line count' or some such. Although changing the variable name to 'lineCount' would do almost as well. -- Chris Green · This is the kind of pedantic crap I was referring to in another thread. Of course I wouldn't call a variable 'x' unless it was representing an x coordinate in 2D or 3D space. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Distutils] Call for information - What assumptions can I make about Unix users' access to Windows?
On 20 November 2014 13:31, holger krekel hol...@merlinux.eu wrote: Thanks Paul for going through this! Looking forward to the link/code. Cheers - it's not forgotten, but real life's being a nuisance, so it's on the back burner for a short while. I'll try to get something done in a few weeks. Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On Thu, Nov 20, 2014 at 11:29 AM, Irmen de Jong irmen.nos...@xs4all.nl wrote: PyCharm *is* free, if you fall in one of several categories. See http://www.jetbrains.com/pycharm/buy/license-matrix.jsp Even when you have to buy it, it is cheap (IMO) for what it offers. PyCharm Editions Comparison [1] is a better comparison between the differences of the always free Community Edition and the Pro Edition of PyCharm. [1] https://www. jetbrains.com/pycharm/features/editions_comparison_matrix.html -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Ethan Furman et...@stoneleaf.us: If your unicode string happens to contain a base64 encoded .png, then you could decode that into bytes. ;) You could embed your PNG file in XML in binary form as CDATA. Then, your characters would represent 8- or 16-bit integers. You just need to replace all accidental occurrences of ]] with ![CDATA[ Marko -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On Thu, 20 Nov 2014 21:19:28 +, Juan Christian wrote: On Thu Nov 20 2014 at 7:07:10 PM Mark Lawrence breamore...@yahoo.co.uk wrote: You also need to study the difference between top posting, interspersed posting and bottom posting. The second and third are very much the prefered styles here. Yes I know, but I'm using the new Google Inbox, and I limited to what I can do when replying, to do the right way I have to do many steps now... Then either do the necessary work (you have just proven you can)or find a better way of communicating with this news group(NNTP or the mailing list), otherwise you may find a number of good people simply ignore your posts. While you are at it try to restrict your replies to text only, i see a lot of html garbage at the end of your posts which is also off putting. -- There is nothing so easy but that it becomes difficult when you do it reluctantly. -- Publius Terentius Afer (Terence) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On Thu Nov 20 2014 at 8:20:29 PM alister alister.nospam.w...@ntlworld.com wrote: Then either do the necessary work (you have just proven you can)or find a better way of communicating with this news group(NNTP or the mailing list), otherwise you may find a number of good people simply ignore your posts. While you are at it try to restrict your replies to text only, i see a lot of html garbage at the end of your posts which is also off putting. Which HTML garbage you talking about? -- https://mail.python.org/mailman/listinfo/python-list
Re: Tag objects in Beautiful Soup
On Thu, 20 Nov 2014 06:31:08 -0800, Simon Evans wrote: Can anyone tell me where I am going wrong or where the text is wrong ? So far the given code has run okay, I have put to the console everything the text tells you to. Thank you for reading. Simon Evans Having looked at the ebook, there seems to be an error in the book. Unfortunately I'm not 100% sure what the error is. However, it may be that: atag = soup_atag.a is meant to be: atag = soup.a There are also errors in the html itself in the ebook, the href of each of the urls is quoted as href=' (mixing single and double quotes) and one of the urls has a semi-colon where a colon is expected, these seem to throw the parser. These errors also appear in your html snippet: html_atag = htmlbodypTest html a tag example/p a href=http://www.packtpub.com'Home/a ^...^ a href=http;//www.packtpub.com/books'.Books/a ^^^ /body /html In addition to these errors in the source html, you seem to have replaced a '' with a '.' on the second anchor tag in the html. a href=http;//www.packtpub.com/books'.Books/a ...^ -- Denis McMahon, denismfmcma...@gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014, at 16:29, Ethan Furman wrote: If your unicode string happens to contain a base64 encoded .png, then you could decode that into bytes. ;) Bytes of the PNG, or of the raw pixels? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On 2014-11-20, jstnms...@gmail.com jstnms...@gmail.com wrote: I write this to address the criticism which targets a user's lack of responsibility for the real/implied/insinuated failings of the docs. As a relatively inexperienced student of programming, I am not in any position to contribute/edit the documents. Wrong. As an inexperienced user, you are _exactly_ the right person to contribute/edit the documents. A documents _always_ make sense to the author and to somebody who already knows the information. They are often not capable of seeing what's wrong. It's those who are _not_ familiar with the subject matter who can often make the most valuable contributions. THAT DOES NOT, however, DENY THE CATEGORICAL STUPIDITY OF THE DOCUMENTATION: . Not only are the semantics of the editors in question, but so are the syntactical and grammatical conventions, too. Then send in suggestions, corrections and improvements. Or pony up and actually take over maintenance of one of the documents you think is so bad. The authors of the documentation aren't _intentionally_ writing things that other people don't understand. If you don't understand the documentation or think it needs to be extended/expanded, then help _do_ it. Just telling somebody the document you wrote SUCKS! is not even a _tiny_ bit helpful. -- Grant Edwards grant.b.edwardsYow! Everybody gets free at BORSCHT! gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On 2014-11-20, dvenkatj2ee...@gmail.com dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. Sure: emacs, bash, grep, et alia. -- Grant Edwards grant.b.edwardsYow! Hello? Enema Bondage? at I'm calling because I want gmail.comto be happy, I guess ... -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. Yes. Use a UNIX or Linux system: http://blog.sanctum.geek.nz/series/unix-as-ide/ -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
sohcahto...@gmail.com wrote: On Thursday, November 20, 2014 1:33:16 PM UTC-8, c...@isbd.net wrote: s...@gmail.com wrote: # increment x x += 1 But it shouldn't say 'increment x', it should say 'add one to the line count' or some such. Although changing the variable name to 'lineCount' would do almost as well. This is the kind of pedantic crap I was referring to in another thread. Of course I wouldn't call a variable 'x' unless it was representing an x coordinate in 2D or 3D space. I think you may have missed the point of Chris' post. In context, the use of x as a variable might be meaningful, but x can also be an archetypal bad variable name. Chris' point is that choosing a meaningful name can be self-documenting and so reduces the need for comments. (By the way, whatever tool you are using to post comments is badly breaking attributions. It is polite to give the person's full name when quoting them, when they provide one, if not give their full email address. Truncating their email address to a single letter before the @ has no useful purpose and breaks attribution.) -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
On 20/11/2014 23:10, Grant Edwards wrote: On 2014-11-20, jstnms...@gmail.com jstnms...@gmail.com wrote: I write this to address the criticism which targets a user's lack of responsibility for the real/implied/insinuated failings of the docs. As a relatively inexperienced student of programming, I am not in any position to contribute/edit the documents. Wrong. As an inexperienced user, you are _exactly_ the right person to contribute/edit the documents. A documents _always_ make sense to the author and to somebody who already knows the information. They are often not capable of seeing what's wrong. It's those who are _not_ familiar with the subject matter who can often make the most valuable contributions. THAT DOES NOT, however, DENY THE CATEGORICAL STUPIDITY OF THE DOCUMENTATION: . Not only are the semantics of the editors in question, but so are the syntactical and grammatical conventions, too. Then send in suggestions, corrections and improvements. Or pony up and actually take over maintenance of one of the documents you think is so bad. The authors of the documentation aren't _intentionally_ writing things that other people don't understand. If you don't understand the documentation or think it needs to be extended/expanded, then help _do_ it. Just telling somebody the document you wrote SUCKS! is not even a _tiny_ bit helpful. Having seen some of the garbage that turns up on the bug tracker under the guise of improvements I suggest that many people who criticize the docs don't take up a career as a technical author. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On 20/11/2014 21:32, c...@isbd.net wrote: sohcahto...@gmail.com wrote: # increment x x += 1 But it shouldn't say 'increment x', it should say 'add one to the line count' or some such. Although changing the variable name to 'lineCount' would do almost as well. Would you please clarify whether you are being serious or funny, thank you? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Python docs disappointing
jstnms...@gmail.com wrote: I write this to address the criticism which targets a user's lack of responsibility for the real/implied/insinuated failings of the docs. As a relatively inexperienced student of programming, I am not in any position to contribute/edit the documents. THAT DOES NOT, however, DENY THE CATEGORICAL STUPIDITY OF THE DOCUMENTATION: . Not only are the semantics of the editors in question, but so are the syntactical and grammatical conventions, too. Semantics, even in the hands of the honest, is a fuzzy beast; the elements of exposition and structure are not. Perhaps the inquisitive mind is correctly labeled stupid, or irresponsible, if it cannot decipher some fine piece of programming crypsis. And perhaps not. It can just as perhaps be that there is an equal, even greater irresponsibility, on the part of those who have taken up the task of clarifying the obscure to the confused. There is no greater arrogance, and it seems to me particularly prevalent among the educators in the technical fields, than pretending any hermeneutic, an effective hermeneutic. Sadly, most of these creatures cannot tell a verb from a noun, and scarcely know where modifiers are best, most effectively, posted to qualify their objects, let alone use those same nouns and verbs and modifiers to explain the intricacies of a subject. Tell one of these cognoscenti that language is about COMMUNICATION, and they begin pointing abstract fingers at their critics, and labeling. Perhaps the reason programs are so inelegant, and so user-UNfriendly, and so bug-infested, is a natural consequence, when a field is dominated by creatures who know much more than they comprehend, and much less than they need to? If, I think, you cannot explain a thing to me, you do not understand it. After all, I'm a lot smarter than you, and I have thankfully learned make out a fool however obscurely he covers himself. I take my hat off to you, sir or madam, that is a brilliant satire of pretentious self-important impenetrable prose complaining about the lack of readability of another text. Although I found that the occasional grammatical errors (such as the missing how to from the last sentence), which I assume are deliberate, were a bit heavy handed and more distracting than ironic. Nevertheless, a masterful job. You made me laugh. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 4:42 AM, random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 09:59, Chris Angelico wrote: Why should it encode to bytes? Because a bytes format string suggests a bytes result. Why does unicode always win, rather than the type of the format string always winning? For the same reason that float always wins: 1.0 + 2 3.0 1 + 2.0 3.0 Makes much better sense to work in Unicode. But mainly, it has to do one of them, and be predictable. Yeah, but string % is not a symmetrical operator. People's mental model of it is likely to be that it acts like format (which does use the type of the format string) or C sprintf/wsprintf (both of which use the same type for the format string and result). And literally every other type is converted to the type of the format string when used with %s - having unicode be special adds cognitive load, and it means you can't safely blindly use %s with an unknown object. True, but Python 2 deliberately lets you conflate the two, so you get a bit of convenience at the expensive of complexity when things go wrong. Python 3, on the other hand, is much more careful about the difference: asdf %s qwer % bzxcv asdf b'zxcv' qwer basdf %s qwer % zxcv Traceback (most recent call last): File stdin, line 1, in module TypeError: unsupported operand type(s) for %: 'bytes' and 'str' So your complaint *has* been resolved... but only in Python 3, because the change would break stuff. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 5:56 AM, Marko Rauhamaa ma...@pacujo.net wrote: Michael Torrie torr...@gmail.com: Unicode can only be encoded to bytes. Bytes can only be decoded to unicode. I don't really like it how Unicode is equated with text, or even character strings. There's barely any difference between the truth value of these statements: Python strings are ASCII. Python strings are Latin-1. Python strings are Unicode. Each of those statements is true as long as you stay within the respective character sets, and cease to be true when your text contains characters outside the character sets. The difference is that ASCII and Latin-1 cut out a large number of active world languages, UCS-2 (the intermediate option you didn't mention) cuts out a small proportion (by usage) of significant characters, and Unicode cuts out only those characters which fall under issues like Han unification. (Plus any that haven't yet been allocated. But since Python doesn't actually validate code points to ensure that they've been given meanings, you can use today's Python to work with tomorrow's Unicode.) Do you have actual text that you're unable to represent in Unicode? If so, you are going to have major problems using it with *any* computer system. There are Japanese encodings that can represent additional characters, but they also *cannot* represent a lot of the other characters we use, so there'll be fundamental incompatibilities. Now, it is true that Python currently limits itself to the 1,114,112 Unicode code points. And it likely won't adopt more characters unless Unicode does it first. However, text is something more lofty and abstract than a sequence of Unicode code points. We shouldn't call strings Unicode any more than we call numbers IEEE or times ISO. We don't call numbers IEEE, but if we're working with Python floats, we *do* require all numbers to be representable as IEEE floating-point. Don't like that? Pick decimal.Decimal instead, or fractions.Fraction, and pick a different set of limitations... but ultimately, you *will* have restrictions - and much tighter restrictions than Unicode places on text. Do you genuinely have text that you can't represent in Unicode, or are you just arguing against Unicode to try to justify Python strings are something else as a basis for your code? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On Fri, Nov 21, 2014 at 9:41 AM, Juan Christian juan0christ...@gmail.com wrote: On Thu Nov 20 2014 at 8:20:29 PM alister alister.nospam.w...@ntlworld.com wrote: Then either do the necessary work (you have just proven you can)or find a better way of communicating with this news group(NNTP or the mailing list), otherwise you may find a number of good people simply ignore your posts. While you are at it try to restrict your replies to text only, i see a lot of html garbage at the end of your posts which is also off putting. Which HTML garbage you talking about? An extra - and completely superfluous - text/html section in your email. See if you can switch your mailer to use plain text mode. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On Thursday, November 20, 2014 3:16:33 PM UTC-8, Steven D'Aprano wrote: sohcahto...@gmail.com wrote: On Thursday, November 20, 2014 1:33:16 PM UTC-8, c...@isbd.net wrote: s...@gmail.com wrote: # increment x x += 1 But it shouldn't say 'increment x', it should say 'add one to the line count' or some such. Although changing the variable name to 'lineCount' would do almost as well. This is the kind of pedantic crap I was referring to in another thread. Of course I wouldn't call a variable 'x' unless it was representing an x coordinate in 2D or 3D space. I think you may have missed the point of Chris' post. In context, the use of x as a variable might be meaningful, but x can also be an archetypal bad variable name. Chris' point is that choosing a meaningful name can be self-documenting and so reduces the need for comments. My point was that I was making fun of CS professors that demand a comment on every line of code, regardless of how clear the line of code is. The fact that I happened to use 'x' as a variable name was inconsequential, and I felt that Chris's criticism of using a single-letter variable name was pedantic because it missed the point entirely and picked on something else that wasn't an issue. I was trying to illustrate the point that some professors would demand you write code like this... # increment the line count lineCount += 1 # Check if line count is over 10 if lineCount 10 # Tell the user there are too many lines print 'There are too many lines! ...which is obviously bad commenting style. But I guess my original minimal example was too minimal. (By the way, whatever tool you are using to post comments is badly breaking attributions. It is polite to give the person's full name when quoting them, when they provide one, if not give their full email address. Truncating their email address to a single letter before the @ has no useful purpose and breaks attribution.) -- Steven I use Google Groups which seems to be pretty unpopular on this list. Does it break thread organization? Or is it really just a politeness thing? -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On Fri, Nov 21, 2014 at 10:59 AM, sohcahto...@gmail.com wrote: (By the way, whatever tool you are using to post comments is badly breaking attributions. It is polite to give the person's full name when quoting them, when they provide one, if not give their full email address. Truncating their email address to a single letter before the @ has no useful purpose and breaks attribution.) I use Google Groups which seems to be pretty unpopular on this list. Does it break thread organization? Or is it really just a politeness thing? It's about giving people proper credit for what they said. Compare the two slabs of text that I quote above. One of them is clearly attributed to a full email address (not a name, though it would have been included if your post headers had provided one); the other, because of the way I trimmed the quote, is completely unattributed. You can't tell, from the above text, that the By the way parenthesis was written by Steven D'Aprano. This is unfair on Steven, and unclear for the next reader. (Caveat: Responsibility for quoting is primarily on the *first* person to make the quote - the first level of chevrons. It's somewhat more acceptable to omit re-attribution, as in my example above. But when you're directly quoting people, you really need to include info about who said what.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Python's import statement and the history of external dependencies
On 16/11/2014 3:01 PM, Rick Johnson wrote: Python's attempt to solve the external dependencies problem has yet to produce the results that many people, including myself, would like. I'd say this was an argumentum ad populum, only you didn't cite anything that shows the many you claim you speak for. Actually, Python is not alone in this deficiency, no, Python is just *ANOTHER* language in a *STRING* of languages over the years who has *YET AGAIN* implemented the same old crusty design patterns, packaged them in a shiny metallic wrapping paper with a big red bow on top, and hoped that no one would notice the stench... Are you sure that's not just you? 1. Name clashes! 2. Smaller name pool! Just off the top of my head, we have several solutions for this: 1) Rebinding imports import foo as foo2 2) Namespace packages import mypackage.foo 3) Filepath imports (deprecated in 3.4 but under discussion for reprecation or replacement) import importlib.machinery loader = importlib.machinery.SourceFileLoader(module.name, /path /to/file.py) foo = loader.load_module() foo.MyClass() 4) Virtual environments In before but WHY so MANY different WAYS OMG PYTHON you M.F.P.O.S.: because they offer flexibility. 3. Machinery is too implicit! See: importlib 4. Circular imports are inevitable! They're also clear indication of bad design. That's not something Python should explicitly set out to support. 5. Much too difficult to use and/or explain! Well sure, if your reaction to things you don't understand is to rant against them instead of asking questions, then I can see how that would be true. Also: citation needed. 6. Too many gotchas! Is this the sequel to Too Many Cooks? Awesome. In closing, there is only one thing you need to know about Python's import statement: it is deceptively easy to underestimate it's ability to *EFF UP* your expectations! There's your problem right there: a language conforms to its specification, not your random expectation. I'm eager to see how you resolve your concerns in RickPython3000. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python IDE.
On Fri, Nov 21, 2014 at 10:13 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: dvenkatj2ee...@gmail.com wrote: Can someone suggest a good python IDE. Yes. Use a UNIX or Linux system: http://blog.sanctum.geek.nz/series/unix-as-ide/ My IDE is Xfce, with a bunch of plugins called SciTE, Google Chrome, xfce4-terminal, Gypsum, and VLC. It's the best IDE in the world... how many pay-for Python IDEs have a built-in feature for playing Let It Go in Polish (with subtitles and translation) while you work? Because that's what's playing right now... ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On Thursday, November 20, 2014 4:17:33 PM UTC-8, Chris Angelico wrote: On Fri, Nov 21, 2014 at 10:59 AM, sohcahto...@gmail.com wrote: (By the way, whatever tool you are using to post comments is badly breaking attributions. It is polite to give the person's full name when quoting them, when they provide one, if not give their full email address. Truncating their email address to a single letter before the @ has no useful purpose and breaks attribution.) I use Google Groups which seems to be pretty unpopular on this list. Does it break thread organization? Or is it really just a politeness thing? It's about giving people proper credit for what they said. Compare the two slabs of text that I quote above. One of them is clearly attributed to a full email address (not a name, though it would have been included if your post headers had provided one); the other, because of the way I trimmed the quote, is completely unattributed. You can't tell, from the above text, that the By the way parenthesis was written by Steven D'Aprano. This is unfair on Steven, and unclear for the next reader. (Caveat: Responsibility for quoting is primarily on the *first* person to make the quote - the first level of chevrons. It's somewhat more acceptable to omit re-attribution, as in my example above. But when you're directly quoting people, you really need to include info about who said what.) ChrisA Fair enough. -- https://mail.python.org/mailman/listinfo/python-list
Re: PyWart: Python's import statement and the history of external dependencies
On Fri, Nov 21, 2014 at 11:14 AM, alex23 wuwe...@gmail.com wrote: 1. Name clashes! 2. Smaller name pool! Just off the top of my head, we have several solutions for this: 1) Rebinding imports import foo as foo2 To be fair to Rick, this doesn't actually solve anything. If you have two modules called foo, you can't import one of them this way. But part of the problem is actually before you even get as far as importing: it's the nature of open source, forking, and the internet. There's a module called remix, which one Peter Sobot forked and tweaked for his own use, and then distributed a slightly changed version of. (I believe the original intention was for the patches to be incorporated into trunk, but that hasn't happened as yet.) If you want to use his app, you need to use his tweaked remix module; if you want to use someone else's, you might need to use the original from upstream. What do you do about that? They're both called remix. How do you import one or the other? How do you install one or the other? There is fundamentally no solution to this. As soon as there are two incompatible (even just slightly incompatible) versions of a project in the wild, people need to cope with it. It's the same with avconv vs ffmpeg, it's the same with wodim vs cdrecord, it's the same with all of them - until one of them undergoes a name change, everyone's stuck. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Most gratuitous comments
On Fri, Nov 21, 2014 at 11:19 AM, sohcahto...@gmail.com wrote: On Thursday, November 20, 2014 4:17:33 PM UTC-8, Chris Angelico wrote: It's about giving people proper credit for what they said. Fair enough. Thank you. That's a nice, tidy attribution line, and it's clear who said what. Including both name and email address is common, but either one is normally unambiguous. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
Marko Rauhamaa wrote: Michael Torrie torr...@gmail.com: Unicode can only be encoded to bytes. Bytes can only be decoded to unicode. I don't really like it how Unicode is equated with text, or even character strings. That surely depends on the context. To be technically correct, Unicode is a character set together with a set of rules for dealing with them (e.g. rules for uppercasing characters, sorting rules, etc.). When referring to the standard, Unicode is a noun; when referring to text, it is actually an adjective being used as a noun. That is, Unicode text has become abbreviated as just Unicode in much the same way as human beings has become abbreviated as just humans. In that sense, text is Unicode just means in the context in which we are talking, when I say 'text' I mean 'Unicode text' as opposed to (for example) 'ASCII text' or 'KOI-8 text'. It certainly doesn't mean that *all* text in other contexts are Unicode, since that is obviously untrue. (E.g. there are millions of existing files across the world containing text which use legacy encodings that are not compatible with Unicode.) There's barely any difference between the truth value of these statements: Python strings are ASCII. Python strings are Latin-1. Python strings are Unicode. Each of those statements is true as long as you stay within the respective character sets, and cease to be true when your text contains characters outside the character sets. When we say Python strings are FOO, we are making a statement about arbitrary Python strings, not a particular set of concrete examples of strings. If Python strings are FOO, that means that for all possible Python strings s, s is FOO is a true statement. We cannot say that Python strings are uppercase, because we can easily find counter-examples such as 'xyz'. Likewise we cannot say Python strings are ASCII, or Latin-1, because we can easily find counter-examples such as 'Ř' On the other hand, Python strings *are* Unicode, because by design Python strings are limited to Unicode. Every Python string is a Unicode string. Now, it is true that Python currently limits itself to the 1,114,112 Unicode code points. And it likely won't adopt more characters unless Unicode does it first. However, text is something more lofty and abstract than a sequence of Unicode code points. You are certainly correct that in it's full generality, text is much more than just a string of code points. Unicode strings is a primitive data type. A powerful and sophisticated text processing application may even find Python strings too primitive, possibly needing something like ropes of graphemes rather than strings of code points. We Western and Northern European speakers -- and I don't know whether Finns are counted as Northern Europeans or Eastern Europeans -- are lucky in that our natural languages are well-covered by Unicode. All our graphemes are also code points, even the funny ones with accents. As an English speaker. I have to remind myself that not every grapheme is a single code point, but Devanagari or Navajo writers will never make that mistake. We shouldn't call strings Unicode any more than we call numbers IEEE or times ISO. We certainly shouldn't call numbers IEEE, but we might very well call them IEEE-754. Actually, since IEEE-754 covers multiple formats, we have to be more specific: Python floats are IEEE-754 double-precision binary floats. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 11:32 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: (E.g. there are millions of existing files across the world containing text which use legacy encodings that are not compatible with Unicode.) Not compatible with Unicode? There aren't many character sets out there that include characters not in Unicode - that was the whole point. Of course, there are plenty of files in unspecified eight-bit encodings, so you may have a problem with reliable decoding - but if you know what the encoding is, you ought to be able to represent each character in Unicode. Not compatible with any of the UTFs, that's different. Plenty of that in the world. You are certainly correct that in it's full generality, text is much more than just a string of code points. Unicode strings is a primitive data type. A powerful and sophisticated text processing application may even find Python strings too primitive, possibly needing something like ropes of graphemes rather than strings of code points. That's probably more an efficiency point, though. It should be possible to do a perfect two-way translation between your grapheme rope and a Python string; otherwise, you'll have great difficulty saving your file to the disk (which will normally involve representing the text in Unicode, then encoding that to bytes). To be sure, a Python string is a poor representational form for a text editor. But that's largely because it's immutable, so every little edit would involve massive copying. Depending on what you're doing, it might be worth using a chunked UTF-8 byte stream (allowing for insertion at any chunk boundary), or an array of lines, or something grapheme-based... but all of those questions are performance, not correctness, issues. We Western and Northern European speakers -- and I don't know whether Finns are counted as Northern Europeans or Eastern Europeans -- are lucky in that our natural languages are well-covered by Unicode. All our graphemes are also code points, even the funny ones with accents. As an English speaker. I have to remind myself that not every grapheme is a single code point, but Devanagari or Navajo writers will never make that mistake. I've been working with different languages a bit, lately. Broadly speaking, you have: 1) Languages which use the Roman alphabet, plus a handful of other characters (eg Finnish, German). These can be represented largely in ASCII, and used to be handled fairly easily with a single codepage - an eight-bit ASCII-compatible encoding. 2) Languages which use a different alphabet (eg Cyrillic - Russian, Bulgarian). You could possibly cram them into an eight-bit encoding without tipping ASCII out, but I'm not sure. In Unicode, these languages are all easily supported by the BMP, as they don't use a huge number of characters each. 3) Languages which use a non-alphabetic system (eg Korean). I think they're all still covered by the BMP, but there's no way you can fit them into eight-bit encodings - one single language will use more than 256 symbols. 4) Ancient, esoteric, or symbolic writing systems. Not fundamentally different from the above categories except that they're less used, and the BMP has finite space. These will definitely need the SMP. But all of them are covered by Unicode. (Sadly, they are NOT all covered by all fonts, so I've been finding that certain pieces of text come out as strings of little boxes. But I can at least manipulate the text, even if I can't read it back.) I can, for example, zip lines of text like this: English: Let it go, let it go! I am one with the wind and sky Let it go, let it go! You'll never see me cry! Icelandic: Þetta er nóg, þetta er nóg Uppi í himni eins og vindablær Þetta er nóg, komið nóg Og tár mín enginn sér fær Russian: Отпусти и забудь, Этот мир из твоих грёз. Отпусти и забудь, И не будет больше слёз. Output: Let it go, let it go! Þetta er nóg, þetta er nóg Отпусти и забудь, I am one with the wind and sky Uppi í himni eins og vindablær Этот мир из твоих грёз. Let it go, let it go! Þetta er nóg, komið nóg Отпусти и забудь, You'll never see me cry! Og tár mín enginn sér fær И не будет больше слёз. In fact, it's trivially easy to write something like this, because all this text is Unicode. ALL of these languages (and plenty more) are well-covered by Unicode. There's still the ongoing debate of Han unification, plus the progressive work of adding characters for ancient scripts and such, but AFAIK, all writing systems currently in use are covered. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Thu, Nov 20, 2014, at 20:10, Chris Angelico wrote: 2) Languages which use a different alphabet (eg Cyrillic - Russian, Bulgarian). You could possibly cram them into an eight-bit encoding without tipping ASCII out, but I'm not sure. In Unicode, these languages are all easily supported by the BMP, as they don't use a huge number of characters each. There are numerous eight-bit encodings that support latin and one other alphabet. Remember, ASCII is a seven-bit encoding, and an eight-bit encoding is basically two seven-bit encodings. The most difficult (of those still possible at all) language to encode in eight bits is actually Vietnamese, which uses the Latin alphabet, due to the sheer number of accented letters used. Windows' encoding of it (along with some other lesser used encodings, all for Vietnamese) is the only 8-bit encoding to use combining accents, in a way unfortunately incompatible with unicode normalization if naively translated, whereas VISCII sacrifices a handful of C0 control characters in addition to fully packing the high half with letters. -- Random832 -- https://mail.python.org/mailman/listinfo/python-list
Re: python 2.7 and unicode (one more time)
On Fri, Nov 21, 2014 at 12:31 PM, random...@fastmail.us wrote: On Thu, Nov 20, 2014, at 20:10, Chris Angelico wrote: 2) Languages which use a different alphabet (eg Cyrillic - Russian, Bulgarian). You could possibly cram them into an eight-bit encoding without tipping ASCII out, but I'm not sure. In Unicode, these languages are all easily supported by the BMP, as they don't use a huge number of characters each. There are numerous eight-bit encodings that support latin and one other alphabet. Remember, ASCII is a seven-bit encoding, and an eight-bit encoding is basically two seven-bit encodings. I'm aware of this; Greek, for instance, fits quite happily into ISO-8859-7, which is eight-bit. The most difficult (of those still possible at all) language to encode in eight bits is actually Vietnamese, which uses the Latin alphabet, due to the sheer number of accented letters used. Windows' encoding of it (along with some other lesser used encodings, all for Vietnamese) is the only 8-bit encoding to use combining accents, in a way unfortunately incompatible with unicode normalization if naively translated, whereas VISCII sacrifices a handful of C0 control characters in addition to fully packing the high half with letters. This is what I was suspicious of. The very notion of combining accents already breaks the notion that a byte is a character is a glyph, which most eight-bit encodings try to pretend. In any case, the BMP still easily copes with them all. (Hmm. I wonder how you'd typeset the old Self-Pronouncing Alphabet for English? It's basically English text with a few markings added to letters - not standard diacriticals that already exist in Unicode, but dots. Probably possible, one way or another... but I haven't seen SPA text since the 90s, and that was in stuff published back in the 80s or so.) ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On 11/20/2014 01:25 PM, Juan Christian wrote: **Back to the list So, as I said the PyQt doc is using C o.0 Yes, I read the tutorials, I'll google for some books and things related. Okay so I took a long look at the example code that was on stackoverflow and figured it out. It's not quite as complete as I thought, and it's only partially functioning. I rewrote it to function a little better. Hopefully it will give you an example. Working with QThread and then moving the worker object to that thread is apparently the recommended way of doing it, but it makes signal handling a two-stage affair. Basically the worker thread has to notify Qthread that it's finished using a finished signal which has to be connected to the QThread's quit() method. That in turn emits its own finished signal which the GUI can trap. It seems a bit convoluted to me. anyway I've attached the working example. import time, sys from PyQt4.QtCore import * from PyQt4.QtGui import * class SimulRunner(QObject): 'Object managing the simulation' stepIncreased = pyqtSignal(int, name = 'stepIncreased') finished = pyqtSignal(name = 'finished') def __init__(self): super(SimulRunner, self).__init__() self._step = 0 self._isRunning = True self._maxSteps = 20 def longRunning(self): self._step = 0 self._isRunning = True while self._step self._maxSteps and self._isRunning == True: self._step += 1 self.stepIncreased.emit(self._step) time.sleep(1) # note since the delay is one second, the thread won't die and the signal # won't be emitted for an entire second. self.finished.emit() def stop(self): print ('stopping.') self._isRunning = False class SimulationUi(QDialog): 'PyQt interface' def thread_finished (self): print ('The thread is finished. You could now do something to update the GUI') def on_stop_button (self): # for some reason we can't have the signal call this directly # but it works from here. Don't know why. self.simulRunner.stop() def __init__(self): super(SimulationUi, self).__init__() self.goButton = QPushButton('Go') self.stopButton = QPushButton('Stop') self.currentStep = QSpinBox() self.layout = QHBoxLayout() self.layout.addWidget(self.goButton) self.layout.addWidget(self.stopButton) self.layout.addWidget(self.currentStep) self.setLayout(self.layout) self.simulRunner = SimulRunner() self.simulThread = QThread() self.simulRunner.moveToThread(self.simulThread) self.simulRunner.stepIncreased.connect(self.currentStep.setValue) self.stopButton.clicked.connect(self.simulRunner.stop) self.goButton.clicked.connect(self.simulThread.start) # As soon as the QThread object starts, instruct it to run our # worker thread's longRunning() method. Can be arbitrarily named self.simulThread.started.connect(self.simulRunner.longRunning) # Here's the tricky part. You must connect a signal from your # thread worker instance that tells the QThread object to # terminate. self.simulRunner.finished.connect(self.simulThread.quit) # now we want to get a signal from the thread so our GUI could # do some update. self.simulThread.finished.connect(self.thread_finished) self.stopButton.clicked.connect(self.on_stop_button) self.goButton.clicked.connect(self.simulThread.start) #self.connect(self.goButton, SIGNAL('clicked()'), self.simulThread.start) self.simulRunner.stepIncreased.connect(self.currentStep.setValue) #self.connect(self.simulRunner,SIGNAL('stepIncreased'), self.currentStep.setValue) if __name__ == '__main__': app = QApplication(sys.argv) simul = SimulationUi() simul.show() sys.exit(app.exec_()) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to access Qt components loaded from file?
On 11/20/2014 08:06 PM, Michael Torrie wrote: anyway I've attached the working example. Just a little caveat. This code is not my original code. I would not do certain things that I just noticed, like these lines: from PyQt4.QtCore import * I would never do that normally, and recommend that you don't either. I might do: import PyQt4.QtCore as QtCore for the sake of brevity while preserving the namespace. Also, while PyQt, being a binding to a C++ library uses camelCase, I would not use it for my own variables and classes. I prefer pep8_compliant_variable_names. Also I note you are using PySide. I believe this example should run with minimal modification to the import statements on PySide -- https://mail.python.org/mailman/listinfo/python-list