Re: RE Module Performance

2013-07-15 Thread Steven D'Aprano
ess jargon, the other three are relevant enough to fool people into thinking that maybe it is a human being. It had me fooled for a long time. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Homework help requested (not what you think!)

2013-07-16 Thread Steven D'Aprano
ith text-based games. Here are two suggestions: - guess the number - twenty questions ("is it bigger than a breadbox?") You might also like to investigate Inform-7. http://inform7.com/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
; My irony meter didn't merely explode, it actually vaporized. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Find and Replace Simplification

2013-07-19 Thread Steven D'Aprano
ing using regexes unless the text you are searching for actually contains a regular expression of some kind. If it's merely a literal character or substring, standard string methods will probably be faster. Oh, and a tip for you: - don't escape quotes unless you don't need to, use the other quote. s = '\'' # No, don't do this! s = "'" # Better! and vice versa. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Messages to Python-List aren't posting

2013-07-19 Thread Steven D'Aprano
t we ran into this problem, and since then we've just routinely whitelisted email from Optus and Bigpond, curse their black souls for making spam prevention just that little bit harder. So I suppose it's possible that they've stopped being bad actors and started following the standards correctly. No really, stop laughing, it is technically possible. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
but even that can't always take into account localised rules, e.g. in German, you should not convert SS to ß for placenames or person names, so for example Herr Meißner and Herr Meissner are two different people. This is one of the motivating reasons for introducing the uppercase ß. http:/

Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
lowercase. It's not a perfect solution, but it works reasonably well if you don't care about full localization. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Share Code Tips

2013-07-19 Thread Steven D'Aprano
r family of languages. For an introduction to the problem: http://www.w3.org/International/wiki/Case_folding http://www.unicode.org/faq/casemap_charprop.html > Also, "ß" is not really the same as "ss". Sometimes it is. Sometimes it isn't. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [ANN] pyparsing 2.0.1 released - compatible with Python 2.6 and later

2013-07-20 Thread Steven D'Aprano
On Sat, 20 Jul 2013 14:30:14 -0700, Paul McGuire wrote: > Thanks for your continued support and interest in pyparsing! And thank you for pyparsing! Paul, I thought I would mention that over the last week or so on the Python-Dev mailing list, there has been some discussion about adding a parser

Re: How can I make this piece of code even faster?

2013-07-20 Thread Steven D'Aprano
temp = fsum(o*w for (o, w) in zip(self.outputs, self.o_weight)) self.output = [1/(1+exp(-temp))]*self.output_num I have neither tested that this works the same as your code (or even works at all!) nor that it is faster, but I would expect that it will be faster. Good luck! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I make this piece of code even faster?

2013-07-21 Thread Steven D'Aprano
s, best of 3: 0.319 usec per loop [steve@ando ~]$ python3.3 -m timeit -s "x = 2.357e7" -s "from math import sqrt" "sqrt(x)" 1000 loops, best of 3: 0.172 usec per loop How exactly are you timing the code? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: How to tick checkboxes with the same name?

2013-07-22 Thread Steven D'Aprano
to solve your problem with "Grab" (whatever that is), feel free to come back. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Strange behaviour with os.linesep

2013-07-23 Thread Steven D'Aprano
iting. http://docs.python.org/3/library/functions.html#open http://docs.python.org/2/library/functions.html#open Some further discussion here: http://stackoverflow.com/questions/12193047/is-universal-newlines-mode- supposed-to-be-default-behaviour-for-open-in-python -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: non sequitur: [OT] SPF - was Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Steven D'Aprano
; enforced on the newsgroups } Are you implying that failure to avoid disparaging others in newsgroups is harmful? That disparages me. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3: dict & dict.keys()

2013-07-23 Thread Steven D'Aprano
. Such differences as exist are trivial: - if you need an actual callable function or method, say to pass to some other function, you can do this: for method in (d.items, d.keys, d.values): process(method) instead of this: # untested for method in (d.items, d.keys, lambda d=d: iter(d)): process(method) - d.keys() is a view, not the dict itself. That's a pretty fundamental difference: compare dir(d.keys()) with dir(d). Basically, views are set-like, not list-like. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Steven D'Aprano
il it stops working. I have code that manually walks over each dict and extracts keys that are in both, or one but not the other. Once I drop support for Python 2.6, I throw that code away and just use views. But until then, I'm stuck doing it the horrible way. Judging by a naive grep of my

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Steven D'Aprano
That second point was the deciding factor when direct iteration over dicts was added. has_key() was deprecated in favour of "key in dict", and that pretty much forced iteration to go over keys by default. The reasoning is, "x in y" ought to be equivalent to: for tmp in y:

Re: RE Module Performance

2013-07-24 Thread Steven D'Aprano
strings are O(n) for indexing a > position within the string. Not so for UTF-32. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3: dict & dict.keys()

2013-07-24 Thread Steven D'Aprano
s the same in both > 2 and 3. Fair point. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: RE Module Performance

2013-07-25 Thread Steven D'Aprano
re relatively small (say, a paragraph rather than multiple pages of text) then even that initial conversion will be invisible. A fast touch typist hits a key about every 0.1 of a second; if it takes a millisecond to convert the chunk, you wouldn't even notice the delay. You can copy and up-

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Steven D'Aprano
er have been invented. Making an actual list copy of the keys (values, items) is useful, but it's not useful enough to dedicate a method (three methods) for it. Just call list() on the view (or, in the case of keys, directly on the dict). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: RE Module Performance

2013-07-25 Thread Steven D'Aprano
. It is *possible* to have non-buggy string routines using UTF-16, but the implementation is a lot more complex than most language developers can be bothered with. I'm not aware of any language that uses UTF-16 internally that doesn't give wrong results for surrogate pairs. -- Ste

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Steven D'Aprano
On Thu, 25 Jul 2013 16:02:42 +1000, Chris Angelico wrote: > On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano > wrote: >> Dicts aren't sets, and don't support set methods: >> >> py> d1 - d2 >> Traceback (most recent call last): >> File &q

Re: RE Module Performance

2013-07-25 Thread Steven D'Aprano
On Thu, 25 Jul 2013 17:58:10 +1000, Chris Angelico wrote: > On Thu, Jul 25, 2013 at 5:15 PM, Steven D'Aprano > wrote: >> On Thu, 25 Jul 2013 04:15:42 +1000, Chris Angelico wrote: >> >>> If nobody had ever thought of doing a multi-format string >>> repres

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Steven D'Aprano
On Thu, 25 Jul 2013 18:15:22 +1000, Chris Angelico wrote: > On Thu, Jul 25, 2013 at 5:27 PM, Steven D'Aprano > wrote: >> On Thu, 25 Jul 2013 16:02:42 +1000, Chris Angelico wrote: >> >>> On Thu, Jul 25, 2013 at 3:48 PM, Steven D'Aprano >>> wrote:

Re: Python 3: dict & dict.keys()

2013-07-25 Thread Steven D'Aprano
On Thu, 25 Jul 2013 20:34:23 +1000, Chris Angelico wrote: > On Thu, Jul 25, 2013 at 7:44 PM, Steven D'Aprano > wrote: >> On Thu, 25 Jul 2013 18:15:22 +1000, Chris Angelico wrote: >>> That's true, but we already have that issue with sets. What's the >>>

Re: RE Module Performance

2013-07-25 Thread Steven D'Aprano
aw 8- bit bytes and characters not unified with > Unicode. > " Do you know what those characters not unified with Unicode are? Is there a list somewhere? I've read all of the pages from here to no avail: http://www.gnu.org/software/emacs/manual/html_node/elisp/Non_002dASCII-Characters.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: RE Module Performance

2013-07-25 Thread Steven D'Aprano
On Fri, 26 Jul 2013 01:36:07 +1000, Chris Angelico wrote: > On Fri, Jul 26, 2013 at 1:26 AM, Steven D'Aprano > wrote: >> On Thu, 25 Jul 2013 14:36:25 +0100, Jeremy Sanders wrote: >>> "To conserve memory, Emacs does not hold fixed-length 22-bit numbers >>>

Re: RE Module Performance

2013-07-25 Thread Steven D'Aprano
On Thu, 25 Jul 2013 15:45:38 -0500, Ian Kelly wrote: > On Thu, Jul 25, 2013 at 12:18 PM, Steven D'Aprano > wrote: >> On Fri, 26 Jul 2013 01:36:07 +1000, Chris Angelico wrote: >> >>> On Fri, Jul 26, 2013 at 1:26 AM, Steven D'Aprano >>> wrote: &

Re: Critic my module

2013-07-26 Thread Steven D'Aprano
mmands by wrapping them in Python. There are plenty of big, complex shell commands that take a plethora of options and could do with some useful Python wrappers, like wget. But you haven't done them. Nor have you added extra security, or even extra convenience. You've done nothing that couldn't be done using the shell "alias" command, except in Python where the syntax is less convenient (e.g. "ls" in the shell, versus "ls()" in Python). [1] I think every newbie programmer goes through a stage of pointlessly writing one-liner wrappers to every second function they see. I know I did. The difference is, before the Internet, nobody did it publicly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: dump a multi dimensional dictionary

2013-07-26 Thread Steven D'Aprano
esting it, debugging it, going through revision after revision to try to bring it to the same level of maturity as pickle, which would you prefer? :-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: RE Module Performance

2013-07-26 Thread Steven D'Aprano
On Thu, 25 Jul 2013 21:20:45 -0600, Ian Kelly wrote: > On Thu, Jul 25, 2013 at 8:48 PM, Steven D'Aprano > wrote: >> UTF-8 uses a flexible representation on a character-by-character basis. >> When parsing UTF-8, one needs to look at EVERY character to decide how >> ma

Re: RE Module Performance

2013-07-26 Thread Steven D'Aprano
On Fri, 26 Jul 2013 22:12:36 -0600, Ian Kelly wrote: > On Fri, Jul 26, 2013 at 9:37 PM, Steven D'Aprano > wrote: >> See the similarity now? Both flexibly change the width used by code- >> points, UTF-8 based on the code-point itself regardless of the rest of >> th

Re: RE Module Performance

2013-07-26 Thread Steven D'Aprano
in use, but they're unlikely to support Unicode. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Cross-Platform Python3 Equivalent to notify-send

2013-07-27 Thread Steven D'Aprano
capabilities: Windows XP, 2000, Vista, 7, 8 ... Mac OS-X FreeBSD, OpenBSD, Linux, running KDE (3 or 4?), Gnome (2 or 3?), Trinity, RatPoison, XFCE, something else... or no window manager at all -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: collections.Counter surprisingly slow

2013-07-28 Thread Steven D'Aprano
data (lines). Calling the get method has higher overhead than dict[key], that will also contribute. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: FSR and unicode compliance - was Re: RE Module Performance

2013-07-28 Thread Steven D'Aprano
d__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] There's 45 ASCII-only strings right there, in only one built-in type, out of dozens. There are dozens, hundreds of ASCII-only strings in Python: builtin functions and classes, attributes, exceptions, internal attributes, variable names, and so on. You already know this, and yet you persist in repeating nonsense. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: dynamic type returning NameError:

2013-07-28 Thread Steven D'Aprano
lled. That means putting it all those calls inside a function object, for later use, instead of executing them directly *right now*: def method1(self): return super(WhatEver, self).request("method1") WhatEver = type("WhatEver", (BaseClass,), {"method1": method1}) You could alternatively use lambda: WhatEver = type("WhatEver", (BaseClass,), {"method1": lambda self: super(WhatEver, self).request("method1") } ) Note that the class name inside super() *must* match the global name the class is assigned to, "WhatEver". The internal class __name__ -- the first argument to type() -- doesn't have to match, but it should, to avoid confusion. The above should fix the NameError you are getting, and it might even work, but I think delegation is a better solution to this problem. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Unexpected results comparing float to Fraction

2013-07-29 Thread Steven D'Aprano
ey do the opposite: they convert the float to a Fraction: py> Fraction(1/3) Fraction(6004799503160661, 18014398509481984) Am I the only one who is surprised by this? Is there a general rule for which way numeric coercions should go when doing such comparisons? -- Steven -- http://mai

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Steven D'Aprano
e float value 1/3 is more likely to be >>> Fraction(1, 3) than Fraction(6004799503160661, 18014398509481984). >> >> At what point should it become Fraction(1, 3)? >> > When the error drops below a certain threshold. Good plan! I pick a threshold of 42.7. Anyone got a better

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Steven D'Aprano
e to me to cast to Fraction when > > comparing. > > Otherwise, == becomes non-transitive This is Python, and we can make __eq__ methods that do anything, including be non-transitive, non-reflexive, and nonsensical if we like :-) But I take your point, and that makes sense. -- Ste

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Steven D'Aprano
nk it would be useful for Fraction.from_float() to accept an optional second argument, the maximum denominator: Fraction.from_float(x, den=None) => nearest fraction to float 1/3, with denominator no greater than den -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Unexpected results comparing float to Fraction

2013-07-29 Thread Steven D'Aprano
calculating with. Oh, for what it's worth, I don't pretend to know how to choose an epsilon either. I can sometimes recognise a bad epsilon, but not a good one. Floats are *hard*. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP8 79 char max

2013-07-29 Thread Steven D'Aprano
ipt performance? No, it is irrelevant to performance, except performance of the reader. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP8 79 char max

2013-07-29 Thread Steven D'Aprano
e base, possibly excepting unit tests with long lists of data. I simply don't write deeply nested classes and functions unless I absolutely need to. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Has anyone gotten Pyglet to work

2013-07-29 Thread Steven D'Aprano
27; object has no attribute 'media' Since your module has no attribute 'media', that error is correct. The lesson here is, never name your own files the same as library files. Unfortunately, that's easier said than done. I think everyone has made the same mistake at le

Re: PEP8 79 char max

2013-07-29 Thread Steven D'Aprano
g you. But no, there's no meaningful performance difference based on line length. Interpreting the source code is not meaningfully affected by line length, and by the time the code is compiled and then run, line length is irrelevant. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Has anyone gotten Pyglet to work

2013-07-29 Thread Steven D'Aprano
install AVbin and hopefully your distro will already support the latest, or at least working, version. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: timing issue: shutil.rmtree and os.makedirs

2013-07-30 Thread Steven D'Aprano
hours, and a minimum of 1.7 minutes (assuming the directory doesn't get deleted instantaneously). time.sleep() takes an argument in seconds. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: RE Module Performance

2013-07-30 Thread Steven D'Aprano
ither character above is larger than 4 bytes. You forgot to deduct the size of the object header. Python is a high-level object-oriented language, if you care about minimizing every possible byte, you should use a low-level language like C. Then you can give every character 21 bits, and be hap

Re: Checking compatibility of a script across Python versions automatically

2012-06-19 Thread Steven D'Aprano
7;d prefer > not to. You could try running it and see if it breaks. That usually works for me :) For anything except throw-away scripts, I prefer to write scripts with a "self-test" option so that I (or any other user) can run the test and see if it works without actually using it f

Re: Py3.3 unicode literal and input()

2012-06-19 Thread Steven D'Aprano
On Mon, 18 Jun 2012 07:00:01 -0700, jmfauth wrote: > On 18 juin, 12:11, Steven D'Aprano [email protected]> wrote: >> On Mon, 18 Jun 2012 02:30:50 -0700, jmfauth wrote: >> > On 18 juin, 10:28, Benjamin Kaplan wrote: >> >> The u prefix is only t

Re: Py3.3 unicode literal and input()

2012-06-20 Thread Steven D'Aprano
) > :u'\u00e9l\xe9phant' > 'éléphant' I cannot reproduce that behaviour. When I try it, I get the expected result: >>> input(': ') : u'\u00e9l\xe9phant' "u'\\u00e9l\\xe9phant'" I expect that the mysterious smidzero.py is monkey-patching the input builtin to do something silly. If that is the case, you are making a rod for your own back. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Jython and PYTHONSTARTUP

2012-06-20 Thread Steven D'Aprano
nster. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is python a interpreted or compiled language?

2012-06-20 Thread Steven D'Aprano
nough JIT can be faster than a static compiler, which leads to cases where Python can be faster than C: http://morepypy.blogspot.com.au/2011/02/pypy-faster-than-c-on-carefully-crafted.html http://morepypy.blogspot.com.au/2011/08/pypy-is-faster-than-c-again-string.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Generator vs functools.partial?

2012-06-21 Thread Steven D'Aprano
ere implemented in Python bytecode, but still, two calls can't be faster than one. [...] > Old news? Thoughts, criticisms, theories? Premature optimization is the root of all evil. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: cPickle - sharing pickled objects between scripts and imports

2012-06-23 Thread Steven D'Aprano
t case, monkey-patching __main__ may very well break that script. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: exception problem

2012-06-25 Thread Steven D'Aprano
d it's just an attractive nuisance to beginners. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: exception problem

2012-06-25 Thread Steven D'Aprano
y: main() # run my application except Exception as err: display_error_dialog(err) # or log to a file, or something... -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: exception problem

2012-06-25 Thread Steven D'Aprano
heir only editor. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Py3.3 unicode literal and input()

2012-06-25 Thread Steven D'Aprano
ou want to treat it as a Python string literal format using escape characters, you have to parse it as Python string literal format. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: tiffany 0.6 released

2012-06-25 Thread Steven D'Aprano
f work. Thank you for sharing it with the community, even if only a few people find it useful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-25 Thread Steven D'Aprano
uot;list zip a b c"? Making print a statement in the first place was a mistake, but fortunately it was a simple enough mistake to rectify once the need for backward compatibility was relaxed. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-26 Thread Steven D'Aprano
_" (or "prnt", "pr", etc.) around it. Compare that to print as a statement, which only has one argument in favour: backwards compatibility. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Slow output

2012-06-27 Thread Steven D'Aprano
Repeated string concatenation can be *painfully* slow, especially under Windows. (For some reason, the details of Windows memory management sometimes prevents the string concat optimization from working.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Question:Programming a game grid ...

2012-06-27 Thread Steven D'Aprano
ons.html#vars Python 3: http://docs.python.org/py3k/library/functions.html#vars > and it does not appear to be valid Python syntax. It's perfectly fine syntax, no different from: my_dict['spam'] = 'a yummy ham-like substance' or similar. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: exception problem

2012-06-27 Thread Steven D'Aprano
On Wed, 27 Jun 2012 17:13:00 -0700, Charles Hixson wrote: > On 06/25/2012 12:48 AM, Steven D'Aprano wrote: >> On Sun, 24 Jun 2012 16:16:25 -0700, Charles Hixson wrote: >> >> >>> But what I wanted was to catch any exception. >>> >> Be c

Re: Why has python3 been created as a seperate language where there is still python2.7 ?

2012-06-27 Thread Steven D'Aprano
o CPython too. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Question:Programming a game grid ...

2012-06-27 Thread Steven D'Aprano
on 3: http://docs.python.org/py3k/library/functions.html#vars -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: retry many times decorator

2012-06-28 Thread Steven D'Aprano
ude and pointless to repeatedly retry the same failed request if it cannot possibly succeed. I also find that exponential backoff for the delay is best. E.g. wait 1 second after the first failed attempt, 2 seconds after the second, 4 seconds after the third, 8 seconds after the fourth, etc. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-06-29 Thread Steven D'Aprano
ted. > > I couldn't find any actual code at that site, the git repository is > currently empty. Given that all code contains bugs, that's the best sort of repository! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: format() not behaving as expected

2012-06-29 Thread Steven D'Aprano
ibrary/string.html#formatspec although sadly all the examples are about using brace substitutions, not format specs. (Personally, I find the documentation about format to be less than helpful.) You can also read the PEP that introduced the new formatting, but keep in mind that there have been some changes since the PEP was written, so it may not quite match the current status quo. http://www.python.org/dev/peps/pep-3101/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-06-29 Thread Steven D'Aprano
ropriate and composition should be used. I would re-write the Car class as follows: class Engine(object): pass class Car(Vehicle): def __init__(self): self.engine = Engine() So now we can talk about Herbie's engine: herbie.engine # Herbie, being a car, has an engine, he

Re: code review

2012-06-30 Thread Steven D'Aprano
feature, but the arguments don't stand up. By all means say that you don't like chained comparisons, that is your right, but your attempts to rationalise that dislike simply do not work. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-06-30 Thread Steven D'Aprano
a language where (unsigned)-1 == -1 apparently is true. http://nitoprograms.blogspot.com.au/2011/05/signed-and-unsigned- comparisons-in-c-c.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-06-30 Thread Steven D'Aprano
On Sun, 01 Jul 2012 12:20:52 +1000, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 12:06 PM, Steven D'Aprano > wrote: >> You can't just arbitrarily stick parentheses around parts of >> expressions and expect the result to remain unchanged. Order of >> evaluati

Re: code review

2012-06-30 Thread Steven D'Aprano
On Sun, 01 Jul 2012 14:23:36 +1000, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 2:17 PM, Steven D'Aprano > wrote: >> Nonsense. Of course parens change the evaluation of the expression. >> That's what parens are for! > > The whole point of my example was th

Re: code review

2012-06-30 Thread Steven D'Aprano
On Sun, 01 Jul 2012 13:48:04 +1000, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 1:23 PM, Steven D'Aprano > wrote: >> All the worse for those languages, since they violate the semantics of >> mathematical notation. > > Not so. It simply means that booleans

Re: code review

2012-07-01 Thread Steven D'Aprano
ity.html Chained comparisons in the Python sense may be rare in computer languages, but it is the standard in mathematics and hardly needs to be explained to anyone over the age of twelve. That is a terrible indictment on the state of programming language design. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-07-01 Thread Steven D'Aprano
On Sun, 01 Jul 2012 09:35:40 +0200, Thomas Jollans wrote: > On 07/01/2012 04:06 AM, Steven D'Aprano wrote: >> On Sun, 01 Jul 2012 00:05:26 +0200, Thomas Jollans wrote: >> >>> As soon as you read it as a ternary operator, >> >> Well that's you

Re: code review

2012-07-01 Thread Steven D'Aprano
On Sun, 01 Jul 2012 05:55:24 -0400, Terry Reedy wrote: > On 7/1/2012 2:54 AM, Steven D'Aprano wrote: > >> So no, Python has always included chained comparisons, and yes, it is >> shameful that a language would force you to unlearn standard notation >> in favour

Re: code review

2012-07-01 Thread Steven D'Aprano
On Sun, 01 Jul 2012 16:33:15 +1000, Chris Angelico wrote: > On Sun, Jul 1, 2012 at 4:27 PM, Steven D'Aprano > wrote: >> Yes, you can find specially crafted examples where adding parentheses >> in certain places, but not others, doesn't change the overall >> eva

Re: code review

2012-07-02 Thread Steven D'Aprano
On Sun, 01 Jul 2012 21:50:29 -0400, Devin Jeanpierre wrote: > On Sun, Jul 1, 2012 at 9:28 PM, Steven D'Aprano > wrote: >> Technically, < in Python is left-associative: a < b < c first evaluates >> a, not b or c. But it is left-associative under the rules of comp

Re: code review

2012-07-02 Thread Steven D'Aprano
thing to do with algebra. It is about picking semantics for chained comparisons which is sensible and useful and matches what people expect from regular language. If you write 2+2 = 2*2 = 4, nearly everyone will agree that, yes, that is true. Interpreting it as 1 == 4 is neither sensible nor useful and it is certainly not what people expect. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-07-02 Thread Steven D'Aprano
the world would be better off if mathematicians threw out the existing precedence rules and replaced them with a strict left-to-right precedence. (Personally, I doubt it.) But until they do, consistency with mathematics is far more important than the foolish consistency of left-to-right precedence. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: code review

2012-07-02 Thread Steven D'Aprano
On Tue, 03 Jul 2012 12:25:59 +1000, John O'Hagan wrote: > On Tue, 3 Jul 2012 11:22:55 +1000 > Chris Angelico wrote: > >> On Tue, Jul 3, 2012 at 10:57 AM, Steven D'Aprano >> wrote: >> >> > Perhaps the world would be better off if mathematicians th

Dictless classes

2012-07-02 Thread Steven D'Aprano
oc__': None}) I wonder whether there is some metaclass magic one can do to create a class without a __dict__? I don't have a use-case for this. But I have some code which assumes that every class will have a __dict__, and I wonder whether that is a safe assumption. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: adding a simulation mode

2012-07-04 Thread Steven D'Aprano
7;t have an answer. I suppose you could monkey-patch a bunch of stuff: if ONLY_PRETEND: open = my_mock_open copytree = my_mock_copytree # etc. main() # run your application but that would also be painful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: import class from string

2012-07-04 Thread Steven D'Aprano
tattr(module, class_name)() # note the extra () brackets I say: class_ = getattr(module, class_name) Either that or you have a bug in your module and it can't be imported. Or you have misspelled the module name, or the class. Or forgotten to import importlib. Or are shadowing it with your

Re: locals().update(...)

2012-07-04 Thread Steven D'Aprano
There are tricks to getting read-only namespaces, but you can legitimately expect to write to globals(). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Discussion on some Code Issues

2012-07-04 Thread Steven D'Aprano
th, > and using slice. Works perfect. I don't understand this. What sort of combinations do you think you need to support? What are "I" values, and why are they important? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 2 + 2 = 5

2012-07-04 Thread Steven D'Aprano
nce Python 2.4 if I remember correctly. Somebody who cares more than me can possibly check the "What's New" documents :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating an instance when the argument is already an instance.

2012-07-05 Thread Steven D'Aprano
ructor, rather than __init__, which runs after the instance is already created, and to use an isinstance test to detect when you already have an instance. Good luck! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: simpler increment of time values?

2012-07-05 Thread Steven D'Aprano
arth's rotational period relative to the distant stars) is slightly more than 86164.098 seconds; the sidereal day is slightly more than 86164.090 seconds. Both are approximately 3 minutes 56 seconds shorter than the mean solar day. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: 2 + 2 = 5

2012-07-05 Thread Steven D'Aprano
On Thu, 05 Jul 2012 15:57:53 +0200, Hans Mulder wrote: > On 5/07/12 07:32:48, Steven D'Aprano wrote: >> On Wed, 04 Jul 2012 23:38:17 -0400, Terry Reedy wrote: >> >>> If I run the script in 3.3 Idle, I get the same output you got. If I >>> then enter '5

Re: Confusing datetime.datetime

2012-07-05 Thread Steven D'Aprano
tc) t2 = datetime(t1.year, t1.month, t1.day, tzinfo=utc) assert t1.tzinfo == t2.tzinfo No assertion error at all. This makes me think that the "retardation" as you put it is not in Python's datetime module at all, but in pytz. What does TZ == TZ give? If it returns False, I recom

Re: 2 + 2 = 5

2012-07-05 Thread Steven D'Aprano
ot;Hoory for new math, new-hoo-hoo math" :-) +1 QOTW -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: simpler increment of time values?

2012-07-05 Thread Steven D'Aprano
chance of being accepted if you include a patch, or at least tests. http://bugs.python.org/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Issues with `codecs.register` and `codecs.CodecInfo` objects

2012-07-06 Thread Steven D'Aprano
the 3.3 beta is no longer accepting new functionality, only bug fixes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: What’s the differences between these two pieces of code ?

2012-07-07 Thread Steven D'Aprano
rs printed (of course! the for loops are identical), except at the end, after the for-loop has finished, you also call print(), which gives you this output: py> for i in range(1, 7): ... print(2 * i, end=' ') ... 2 4 6 8 10 12 py> print() py> Notice the blank line printed? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

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