Re: Is Python a commercial proposition ?

2012-07-30 Thread Steven D'Aprano
e cores -- why the hell does your microwave oven need two cores?) It seems to me that those who claim that the GIL is a serious barrier to Python's use in the enterprise are mostly cargo-cult programmers, parroting what they've heard from other cargo-cultists. It really is astonishing

Re: [ANN] pyknon: Simple Python library to generate music in a hacker friendly way.

2012-07-30 Thread Steven D'Aprano
plicitly trust that each upgrade is an actual *upgrade*, not a downgrade with a higher version number like KDE 3 -> KDE 4, or a sidegrade, like Firefox. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is Python a commercial proposition ?

2012-07-30 Thread Steven D'Aprano
On Mon, 30 Jul 2012 21:45:51 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> And at that level, you aren't going to write your app in Python anyway, >> and not because of the GIL. (These microcontrollers are unlikely to >> have multiple cores -- why the hel

Re: CRC-checksum failed in gzip

2012-08-01 Thread Steven D'Aprano
e network diagnostics, to eliminate corruption introduced in the network layer. But I expect that you won't find anything there, and the problem is a simple thread bug. Simple, but really, really hard to find. Good luck. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling Values

2012-08-03 Thread Steven D'Aprano
d pay attention to modern practices for writing good quality code. If you would rather stick to worst-practices from the 1960s, don't expect any encouragement. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Eclipse and the Python plugin

2012-08-03 Thread Steven D'Aprano
and Context. Mind you, both of those are seriously large, Decimal has 117 methods and Context around 70-80 (I stopped counting). So as I said, that's about the upper limit for what I consider reasonable in a single module. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: attribute is accessed from Nonetype

2012-08-03 Thread Steven D'Aprano
ype *is* a standard type. It's just not bound to a publicly accessible name in the built-ins. But you can easily get access to the class using either: type(None) None.__class__ or in Python 2.6 at least, import types types.NoneType (although it has been removed from Python 3.2 for some re

Re: Deciding inheritance at instantiation?

2012-08-03 Thread Steven D'Aprano
ut using type(), there's an easier way. def factory(name, parent_class): class MyClass(parent_class): def method(self): print "Called method" return 42 MyClass.__name__ = name return MyClass Much easier than the equivalent using type. def method(self): print "Called method" return 42 type(name, (parent_class,), {'method': method}) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: attribute is accessed from Nonetype

2012-08-03 Thread Steven D'Aprano
eginner for getting the case wrong, you have done exactly the same thing. A form of Muphry's Law (the Iron Law of Nitpicking) perhaps? http://en.wikipedia.org/wiki/Muphry%27s_law -- Steven -- http://mail.python.org/mailman/listinfo/python-list

On-topic: alternate Python implementations

2012-08-03 Thread Steven D'Aprano
rsion of Python with capabilities. http://plash.beasts.org/wiki/CapPython http://en.wikipedia.org/wiki/Object-capability_model Berp - a compiler which works by translating Python to Haskell and compiling that. https://github.com/bjpop/berp/wiki Give them some love! -- Steven -- http://mai

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
urn sin(x*x) If that's Python code, then I'm Ethel the Aardvark. Cython is very Python-like, but there is no doubt in my mind that it is a superset of Python and therefore a different language. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 16:34:17 +1000, Chris Angelico wrote: > On Sat, Aug 4, 2012 at 4:15 PM, Steven D'Aprano > wrote: >> CLPython, an implementation of Python written in Common Lisp. >> >> Berp - a compiler which works by translating Python to Haskell and >

Re: when an iterable object is exhausted or not

2012-08-04 Thread Steven D'Aprano
e in Python 3? In Python 3, filter returns a lazy iterator, a "filter object". It generates items on demand. In Python 2, filter is eager, not lazy, and generates items all up-front. If the input is a string, it generates a string; if the input is a tuple, it generates a tuple; otherwise it generates a list. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
ig speedups for most code at the cost of trivial slowdowns when you do something unusual. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: when an iterable object is exhausted or not

2012-08-04 Thread Steven D'Aprano
filter take different arguments, do different things, and return different objects. Why is it hard to remember that range is restartable and filter is not? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: On-topic: alternate Python implementations

2012-08-04 Thread Steven D'Aprano
On Sat, 04 Aug 2012 18:38:33 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Runtime optimizations that target the common case, but fall back to >> unoptimized code in the rare cases that the optimization doesn't apply, >> offer the opportunity of big speedu

Re: conditional running of code portion

2012-08-04 Thread Steven D'Aprano
BOSE_FLAG: for item in loop: print(DEBUG_INFORMATION) do_actual_work(item) else: for item in loop: do_actual_work(item) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Intermediate Python user needed help

2012-08-05 Thread Steven D'Aprano
that appears to be perfectly fine, the reason is a missing bracket of some sort on a previous line. (For Americans, I mean parentheses, brackets or braces; for Britons and Australians, round square or curly brackets; for everyone else, whatever you call them.) -- Steven -- http://mail.py

Re: Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Steven D'Aprano
for Object-Oriented Analysis and Design (OOAD). An OOAD > textbook /should/ be language neutral and, these days, likely using the > constructs/notation of UML [which derived from a merger of two or three > separate proposals for OOAD tools] Good lord. I'd rather read C++ than UML. A

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Steven D'Aprano
tract and jargon-ridden that they have become a badge of membership into an elite. Shorn of their excessive abstractness, they're not very special. People were writing helper functions to assemble complex data long before the Builder pattern was named, and a Facade is just an interface layer. > Learn Python by all means, the interactive mode is particularly fun,just > try and get a good idea of what OO is all about before you start. As far as I am concerned, any language without an interactive interpreter is incomplete. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Steven D'Aprano
rying to solve. I almost invariably use one type of box and one type of arrowhead. Sometimes if I'm bored I draw doodles on the diagram. If only I could remember to be consistent about what doodle I draw where, I too could be an UML guru. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Intermediate Python user needed help

2012-08-05 Thread Steven D'Aprano
word, but this does not stop you from defining a word called ::: or "foo:bar" (with or without the quotes!). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-05 Thread Steven D'Aprano
e. > I suspect), but can't say that I've ever used a "factory function"... If you've ever used an ordinary function decorator, you almost certainly have. If you've every created a closure, you definitely have. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread Steven D'Aprano
On Mon, 06 Aug 2012 17:17:33 +0100, Mark Lawrence wrote: > Please see my comment at the bottom hint hint :) Please trim unnecessary quoted text. We don't need to see the entire thread of comment/reply/reply-to-reply duplicated in *every* email. -- Steven -- http://mail.python.org

Re: Intermediate Python user needed help

2012-08-06 Thread Steven D'Aprano
e.com/meme/359ofp/ http://www.quickmeme.com/meme/3q8648/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: looking for a neat solution to a nested loop problem

2012-08-06 Thread Steven D'Aprano
.chain(xrange(N, 250), xrange(N)) # in Python 3 for j in jvalues: for i in ivalues: ... -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] String to binary conversion

2012-08-06 Thread Steven D'Aprano
strings: py> text = 'aπ©Z!' py> data = text.encode('iso-8859-7') py> data.decode('latin1') 'að©Z!' py> data.decode('iso-8859-14') 'aŵ©Z!' Both the encode and decode methods take an optional argument, errors, which specify t

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread Steven D'Aprano
On Mon, 06 Aug 2012 09:55:24 +0100, lipska the kat wrote: > On 06/08/12 01:22, Steven D'Aprano wrote: >> On Sun, 05 Aug 2012 20:46:23 +0100, lipska the kat wrote: >> >>> >>> Object Oriented programming is a mindset, a way of looking at that >>> part

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-06 Thread Steven D'Aprano
uot;Simplify the interface, oh and also change the API of these three methods to match this other library, and add a couple of helper methods, and while you're at it, this method has a bug that upstream refuses to patch, do something about that." So is that a facade or an adaptor, or s

Re: OT probably but still relevant (was Re: Looking for a good introduction to object oriented programming with Python)

2012-08-07 Thread Steven D'Aprano
lly not that Java methods take an extra "Two lines per source file". It is that Java forces a single mental model on you, all the time, whether it makes for better, more readable code or not. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: I thought I understood how import worked...

2012-08-07 Thread Steven D'Aprano
th.__dict__) py> math.__dict__ == namespace True py> math.__dict__ is namespace False It are modules which should be special, and Python tries really hard to ensure that they are singletons. (Multitons?) But not superhumanly hard. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie] Looking for a good introduction to object oriented programming with Python

2012-08-07 Thread Steven D'Aprano
On Tue, 07 Aug 2012 10:19:31 +0100, lipska the kat wrote: > On 07/08/12 06:19, Steven D'Aprano wrote: [...] >> But what *really* gets me is not the existence of poor terminology. I >> couldn't care less what terminology Java programmers use among >> themselves. &

Re: Unexpected behavior using contextmanager on a class method

2012-08-07 Thread Steven D'Aprano
used as the default, each and every time. In your case, you can fix this problem and get the effect of "late binding" like this: class SymList: def __init__(self, L=None): if L is None: L = [] self.L = L Now each time the method body runs, you get a different empty

Re: I thought I understood how import worked...

2012-08-07 Thread Steven D'Aprano
On Tue, 07 Aug 2012 08:25:43 -0700, Roy Smith wrote: > On Tuesday, August 7, 2012 9:52:59 AM UTC-4, Steven D'Aprano wrote: > >> In general, you should avoid non-idempotent code. You should doubly >> avoid it during imports, and triply avoid it on days ending wi

Re: Looking for a good introduction to object oriented programming with Python

2012-08-07 Thread Steven D'Aprano
://c2.com/cgi/wiki?CategoryPattern And the ever-finer distinctions between variations on patterns. Without looking them up, what are the difference between Default Visitor, Extrinsic Visitor, Acyclic Visitor, Hierarchical Visitor, Null Object And Visitor, and regular old Visitor patterns? -- and no, I did not make any of them up. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for a good introduction to object oriented programming with Python

2012-08-07 Thread Steven D'Aprano
we now have a communication mismatch. The finer the distinction between Foo and Bar Visitor, the more likely that people will misunderstand or fail to see the distinction, and the less useful the terminology gets. There is a point of diminishing returns in terminology, where finer distinctions lead to less clarity rather than more, and in my opinion that point was already passed when Go4 wrote their book, and it's just got worse since. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Looking for a good introduction to object oriented programming with Python

2012-08-08 Thread Steven D'Aprano
hey say: I'll believe that corporations are people when Texas executes one.) You can, of course, ban the name "Person" from your classes and databases. But that's a mere cosmetic quirk -- you're still modelling people as objects and/or database records, whether you use the word or not. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a clever way to pass arguments

2012-08-08 Thread Steven D'Aprano
Python 3, use list(range(8)) instead. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: save dictionary to a file without brackets.

2012-08-10 Thread Steven D'Aprano
pam, spam, and >>> spam. >> >> Now now gentlemen we're getting slightly off topic here and wouldn't >> want to upset the people who insist on staying on topic. Or would we? >> :) > > We apologise for the off-topicness in the thread. Those responsible >

Re: [Newbie] How to wait for asyncronous input

2012-08-11 Thread Steven D'Aprano
when the flag is set. It doesn't need to be a global flag. You can make the flag an attribute of the thread, and then have the thread check self.flag. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: save dictionary to a file without brackets.

2012-08-11 Thread Steven D'Aprano
ction cannot fail to have collisions. The problem is that in general you have an essentially unlimited number of objects being mapped to a large but still finite number of hash values. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Xlib: watching key presses without trapping them

2012-08-11 Thread Steven D'Aprano
r forum. If there is none, try emailing the author. If you do get an answer elsewhere, please consider passing it on here so others can learn about it too. Have you looked at how GUIs like wxPython and Tkinter handle key events? That might help. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: in-place exponentiation incongruities

2012-08-11 Thread Steven D'Aprano
hat the ipow operation ""is the equivalent > of the Python statement o1 **= o2 when o3 is Py_None, or an in-place > variant of pow(o1, o2, o3) otherwise."" Where is that from? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: in-place exponentiation incongruities

2012-08-12 Thread Steven D'Aprano
ncy with something other than **= would be inconsistency. > and provide a feature that at the > moment is not present. (well if the designers of python care really much > about consistency they'd probably add an "ipow" built-in function, so > that you don't have to import it from "operator"). Not everything needs to be a built-in function. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic with Boolean values

2012-08-12 Thread Steven D'Aprano
e to do something like that, I'd say > >for x in range(1 + (len(L) & 1)): [snip] I'd simplify it even more: for x in (0,) if len(L)%2 else (0, 1): ... which is even more explicit and simpler to read even though it is longer. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: save dictionary to a file without brackets.

2012-08-13 Thread Steven D'Aprano
ce but I think I got away with it." http://www.youtube.com/watch?v=7xnNhzgcWTk -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Official reason for omitting inspect.currentcallable() ?

2012-08-13 Thread Steven D'Aprano
*stably*[1] return the currently executing callable object? I doubt it. Should there be? "currentcallable" is not a standard function in any language I'm familiar with, although I may be missing something obvious. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to uncompress a VOB file? (Win XP)

2012-08-13 Thread Steven D'Aprano
On Mon, 13 Aug 2012 03:18:49 -0700, Xantipius wrote: > subj The same way as you compressed it, only in reverse. When you ask a sensible question, I'm sure that somebody will give you a sensible answer. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Threading KeyError in Python 3.3 beta 2?

2012-08-13 Thread Steven D'Aprano
t; if len(set(s)) == 9: > print(n, s) Um, I don't think so. >>> for pre in ('12', '13', '14', '15', '21' ): ... n = int(pre + '543') ... s = str(n * n) ... if len(set(s)) == 9: ... print(n, s) ... 12

Re: save dictionary to a file without brackets.

2012-08-13 Thread Steven D'Aprano
t;> >> >> > Yes m'lud. Do I lick your boots or polish them? Children children, if you won't play nice don't play at all. You're scaring away the people who are here to learn about Python. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to uncompress a VOB file? (Win XP)

2012-08-13 Thread Steven D'Aprano
is crosses the line to total dickishness. Chill out before you get yourself kill-filed into irrelevance. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to call perl script from html using python

2012-08-13 Thread Steven D'Aprano
have already tried? Show us your code. - Show us some *simple* sample data. The more you help us, the more we can help you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: pylagiarism -- Need help now! Please provide code...

2012-08-14 Thread Steven D'Aprano
y back. Can someone please contribute a functioning module showing me > how to do it? [snip] Ha ha, very amusing :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to call perl script from html using python

2012-08-14 Thread Steven D'Aprano
ode lives, you can't. Once you have the Perl code, you can then run it using the subprocess module, and collect its results. Once you have the results, you can store it in a database. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to uncompress a VOB file? (Win XP)

2012-08-14 Thread Steven D'Aprano
On Tue, 14 Aug 2012 12:38:24 +0100, Mark Lawrence wrote: > On 14/08/2012 04:00, Steven D'Aprano wrote: [...] > For the record I was asked to use my full name rather than my user name > on Python mailing lists. But see also my earlier reply to you on the > "save dictio

Re: Sharing code between different projects?

2012-08-14 Thread Steven D'Aprano
are in-house, then a utilities module makes more sense. If you're writing libraries for independent release, not so much. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP))

2012-08-14 Thread Steven D'Aprano
f > anyone wants a truly unique handle for me, "Rosuav" is more effective > than my real name. Mom? Is that you? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behavior

2012-08-14 Thread Steven D'Aprano
th_x.append(word) else: words_without_x.append(word) words[:] = words_without_x # slice assignment return words_with_x The only downside of this is that if the list of words is so enormous that you can fit it in memory *once* but not *twice*, this may fail. But the same applies to the list comprehension solution. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Posting under ones full name (was: How to uncompress a VOB file? (Win XP))

2012-08-14 Thread Steven D'Aprano
On Wed, 15 Aug 2012 11:44:29 +1000, Chris Angelico wrote: > On Wed, Aug 15, 2012 at 9:55 AM, Steven D'Aprano > wrote: >> On Wed, 15 Aug 2012 07:46:31 +1000, Chris Angelico wrote: >> >>> I have my surname in my From address, but I tend to sign my posts >>

Re: [OT] Posting under ones full name

2012-08-15 Thread Steven D'Aprano
this sort of quoting, meta-quoting, etc. in detail. A good read if you want your brain stretched to the point it starts leaking out of your ears. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: email with a non-ascii charset in Python3 ?

2012-08-15 Thread Steven D'Aprano
atter to Emacs or some other editors, but Python simply matches on this regex: coding[=:]\s*([-\w.]+) http://docs.python.org/py3k/reference/lexical_analysis.html#encoding-declarations -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically determine base classes on instantiation

2012-08-15 Thread Steven D'Aprano
s still good, with unfortunately one complication: If you inherit from builtins, you cannot use automatic delegation on the magic "double-underscore" (dunder) methods like __eq__, __len__, etc. See this thread here for one possible solution: http://www.velocityreviews.com/forums/t732798-automatic-delegation-in-python-3-a.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: dbf.py API question concerning Index.index_search()

2012-08-15 Thread Steven D'Aprano
ning a (number, bool) tuple -- safer, yet more > boring... ;) Boring is good, but it is also a PITA to use, and that's not good. I never remember whether the signature is (offset, flag) or (flag, offset), and if you get it wrong, your code will probably fail silently: py> flag, offset = (23

Re: type(None)()

2012-08-16 Thread Steven D'Aprano
On Thu, 16 Aug 2012 14:47:47 +0200, Hans Mulder wrote: > On 8/08/12 04:14:01, Steven D'Aprano wrote: >> NoneType raises an error if you try to create a second instance. bool >> just returns one of the two singletons (doubletons?) again. >> >> py> type(None)()

Re: Strange behavior

2012-08-16 Thread Steven D'Aprano
On Thu, 16 Aug 2012 13:18:59 +0200, Virgil Stokes wrote: > On 15-Aug-2012 02:19, Steven D'Aprano wrote: >> On Tue, 14 Aug 2012 21:40:10 +0200, Virgil Stokes wrote: >> >>> You might find the following useful: >>> >>> def testFunc(startingList): >&

Re: Dynamically determine base classes on instantiation

2012-08-16 Thread Steven D'Aprano
not subclasses, they are both the same type, namely Foo. "Share a common base class" is a much weaker statement: class Foo: pass class Bar(Foo): pass a = Foo() b = Bar() Now we can see that a and b are NOT the same type, but they share a common base class, Foo. -- Steven -- ht

Re: Dynamically determine base classes on instantiation

2012-08-16 Thread Steven D'Aprano
(cls, arg) > > class FooList(Foo, list): > pass > > class FooDict(Foo, dict): > pass Did you actually try your code? py> x = Foo([]) Traceback (most recent call last): File "", line 1, in File "", line 7, in __new__ TypeError: object.__new__(Fo

Re: Dynamically determine base classes on instantiation

2012-08-16 Thread Steven D'Aprano
wanted `a' and `b' to share the > same function (the `merge' function), I thought that the easiest way to > achieve this is by letting them share the same name-space. Or you could you use composition, or a mixin, or straits, or prototypes. Well, prototypes are hard in Python -- I'm not sure how you would go about doing that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Dynamically determine base classes on instantiation

2012-08-16 Thread Steven D'Aprano
erged dict for key, value in d2.items(): if key in d1 and d1[key] is None: d3[key] = value # merge Now pass d3 to your recursive_type function. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: set and dict iteration

2012-08-16 Thread Steven D'Aprano
t mutation-during-iteration, they are more than welcome to come up with a patch. Don't forget unit and regression tests, and also a set of timing results which show that the slow-down isn't excessive. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: remote read eval print loop

2012-08-16 Thread Steven D'Aprano
some protocols for running Python code remotely over a network. Please do not re-invent the wheel without good reason. See pyro, twisted, rpyc, rpclib, jpc, and probably many others. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Top-posting &c. (was Re: [ANNC] pybotwar-0.8)

2012-08-17 Thread Steven D'Aprano
r heroes to die of hunger and cold homeless in the street, and cultures that top-post. What's your point? > Of course, "Do in Rome as romans do" is universally sound advice, (with > Rome suitably parameterized), so its best to follow the netiquette of > the forum you are u

Re: Dynamically determine base classes on instantiation

2012-08-17 Thread Steven D'Aprano
On Fri, 17 Aug 2012 04:50:43 -0700, Richard Thomas wrote: > On Thursday, 16 August 2012 19:49:43 UTC+2, Steven D'Aprano wrote: >> On Thu, 16 Aug 2012 10:03:51 -0700, Richard Thomas wrote: >> >> > class Foo(object): >> > def __new__(cls, arg)

Re: How do I display unicode value stored in a string variable using ord()

2012-08-17 Thread Steven D'Aprano
ython compilers will have the same support for unicode, rather than most being BMP-only. Each individual string's internal storage will use only as many bytes-per- character as needed to store the largest character in the string. This will save a lot of memory for those using mostly

Re: How do I display unicode value stored in a string variable using ord()

2012-08-17 Thread Steven D'Aprano
e efficient than Python 3.2 > for any string which had a max code point of 65535 or less (in Windows), > or 4billion or less (in real systems). So unless French has code points > over 64k, I can't figure that anything is lost. I think that on narrow builds, it won't make terribly much difference. The big savings are for wide builds. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
using two code points. This is fragile and doesn't work very well, because string-handling methods can break the surrogate pairs apart, leaving you with invalid unicode string. Not good.) The difference between 44 bytes and 22 bytes for one little string is not very important, but when you double the memory required for every single string it becomes huge. Remember that every class, function and method has a name, which is a string; every attribute and variable has a name, all strings; functions and classes have doc strings, all strings. Strings are used everywhere in Python, and doubling the memory needed by Python means that it will perform worse. With PEP 393, each Python string will be stored in the most efficient format possible: - if it only contains ASCII characters, it will be stored using 1 byte per character; - if it only contains characters in the BMP, it will be stored using UCS-2 (2 bytes per character); - if it contains non-BMP characters, the string will be stored using UCS-4 (4 bytes per character). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Regex Question

2012-08-18 Thread Steven D'Aprano
en None is returned instead. if mo is not None: print(mo.group(0)) => prints @victory So far so good. But we can do better. In this case, we don't really care about the tags , we only care about the "victory" part. Here's how to use grouping to extract substrings

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
On Sat, 18 Aug 2012 08:07:05 -0700, wxjmfauth wrote: > Le samedi 18 août 2012 14:27:23 UTC+2, Steven D'Aprano a écrit : >> [...] >> The problem with UCS-4 is that every character requires four bytes. >> [...] > > I'm aware of this (and all the blah blah bl

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
This is a long post. If you don't feel like reading an essay, skip to the very bottom and read my last few paragraphs, starting with "To recap". On Sat, 18 Aug 2012 11:26:21 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> (There is an extension to UCS-2,

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
e "utf-8 == ascii" and > the rest of the world doesn't count. UTF-8 is not ASCII. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
7;s first 256 code points. That's not the same thing though: there is no Unicode standard mapping to a single byte format. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
rom sys import getsizeof as size; print(size ('abcœ…'*1000))" 10038 As I said, there is a *tiny* overhead difference. But identifiers will generally be smaller: steve@runes:~$ python3.2 -c "from sys import getsizeof as size; print(size (size.__name__))" 48 steve@runes:~$ python3.3 -c "from sys import getsizeof as size; print(size (size.__name__))" 34 You can check the object overhead by looking at the size of the empty string. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-18 Thread Steven D'Aprano
his myth that PEP 393 uses Latin-1 internally, it does not. Read the PEP, it explicitly states that 1-byte formats are only used for ASCII strings. > Adding "€", it will still be stored as 2 bytes/codepoint. That is correct. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
hey make basic string operations O(N) instead of O(1). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Top-posting &c. (was Re: [ANNC] pybotwar-0.8)

2012-08-19 Thread Steven D'Aprano
nd "knows how to read". I'm not sure which is worse -- that perhaps I *am* some sort of mega- genius and keep overestimating the difficulty of scroll-down-and-read for normal people, or that others have such short attention spans that anything that they can't see immediately in front of them might as well not exist. Either thought is rather depressing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
don't save any memory. Because the objects are so much bigger and more complex, your CPU cache goes to the dogs and your code still runs slow. Which leaves us right back where we started, PEP 393. > Obviously one can concoct hypothetical examples that would suffer. If you think &q

Re: New internal string format in 3.3, was Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
On Sun, 19 Aug 2012 09:43:13 +0200, Peter Otten wrote: > Steven D'Aprano wrote: >> I don't know where people are getting this myth that PEP 393 uses >> Latin-1 internally, it does not. Read the PEP, it explicitly states >> that 1-byte formats are only us

Re: Branch and Bound Algorithm / Module for Python?

2012-08-19 Thread Steven D'Aprano
tell us please. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
On Sun, 19 Aug 2012 01:11:56 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> result = text[end:] > > if end not near the end of the original string, then this is O(N) even > with fixed-width representation, because of the char copying. Technically, yes. But it

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
On Sun, 19 Aug 2012 01:04:25 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> This standard data structure is called UCS-2 ... There's an extension >> to UCS-2 called UTF-16 > > My own understanding is UCS-2 simply shouldn't be used any more. Pretty m

Re: New internal string format in 3.3

2012-08-19 Thread Steven D'Aprano
here. Your objection appears to be based on some sort of philosophical objection to Latin-1 than on any genuine problem. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Abuse of Big Oh notation [was Re: How do I display unicode value stored in a string variable using ord()]

2012-08-19 Thread Steven D'Aprano
ing about string indexing and slicing. There is no value of k, say, k = 2, for which you can say "People will sometimes ask for string[2] but never ask for string[3]". That is absurd. Since k can vary from 0 to N-1, we can say that the average string index lookup is k = (N-1)//2 w

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
On Sun, 19 Aug 2012 11:50:12 -0600, Ian Kelly wrote: > On Sun, Aug 19, 2012 at 12:33 AM, Steven D'Aprano > wrote: [...] >> The PEP explicitly states that it only uses a 1-byte format for ASCII >> strings, not Latin-1: > > I think you misunderstand the PEP then

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
On Sun, 19 Aug 2012 18:03:34 +0100, Blind Anagram wrote: > "Steven D'Aprano" wrote in message > news:502f8a2a$0$29978$c3e8da3$54964...@news.astraweb.com... > > > If you can consistently replicate a 100% to 1000% slowdown in string > > handling, p

Re: Why doesn't Python remember the initial directory?

2012-08-19 Thread Steven D'Aprano
telling the programmer "don't change working directories, or if you do, you need to change back again before doing X, Y or Z". Personally, I think that trying to fix all the things that break if you chdir is not worthwhile, but having Python record the directory you started with in (say) sys.startingdirectory might be a worthwhile feature request. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
r ability to outstrip storage continues, compression and memory-efficient storage schemes will remain in demand. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I display unicode value stored in a string variable using ord()

2012-08-19 Thread Steven D'Aprano
On Mon, 20 Aug 2012 00:44:22 -0400, Roy Smith wrote: > In article <5031bb2f$0$29972$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> > So it may be with utf-8 someday. >> >> Only if you believe that people's ability to generate d

Re: Why doesn't Python remember the initial directory?

2012-08-20 Thread Steven D'Aprano
admins who want to write quick scripts in Python than a function intended to be used in libraries or major applications. An interesting question is, what do other languages do in this case? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Class.__class__ magic trick help

2012-08-20 Thread Steven D'Aprano
dict but it is not derived from dict and I want > isinstance(x,dict)==True to use it in place of dict in some other code). Be aware that some parts of Python will insist on real dicts, not just subclasses or fake dicts. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

python-list@python.org

2012-08-20 Thread Steven D'Aprano
context > (e.g. conversation history) and get all the information I need from > what the sender is writing. In my experience, if you ask a question in corporate environments by email, you're lucky to get an answer within a day. Slow indeed. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    2   3   4   5   6   7   8   9   10   11   >