Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Jul 15, 2011 at 3:28 PM, Steven D'Aprano > wrote: >> My question is, should I accept None as the missing value, or a dedicated >> singleton? >> >> In favour of None: it's already there, no extra code required. People may

Re: None versus MISSING sentinel -- request for design feedback

2011-07-15 Thread Steven D'Aprano
Chris Angelico wrote: > On Fri, Jul 15, 2011 at 8:46 PM, Steven D'Aprano > wrote: >> In general, you have missing values in statistics because somebody >> wouldn't answer a question, and the Ethics Committee frowns on >> researchers torturing their subjects

Re: Type checking versus polymorphism (was: list(), tuple() should not place at "Built-in functions" in documentation)

2011-07-15 Thread Steven D'Aprano
r code with assertions turned off if you use assert for testing?) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible File iteration bug

2011-07-15 Thread Steven D'Aprano
com/tailing-in-python/ Modifying it to be non-blocking should be pretty straightforward -- just add a `yield ""` after the `if not line`. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: list(), tuple() should not place at "Built-in functions" in documentation

2011-07-15 Thread Steven D'Aprano
to take the square root of it. Assertions should be rare, and never used for testing arguments (except, maybe, for purely internal functions that only get called by your own functions, never by the caller). If the caller ever sees an AssertionError generated by your code, that is a bug in your cod

Re: An interesting beginner question: why we need colon at all in the python language?

2011-07-15 Thread Steven D'Aprano
nt token or expression. Including a newline inside an expression is an error, unless you explicitly silence it by using a backslash or using brackets. It's a bit too far to say that "any if statement is an explicit way to silent newline errors". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: HOWTO: Parsing email using Python part2

2011-07-15 Thread Steven D'Aprano
tremely detailed and useful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Type checking versus polymorphism (was: list(), tuple() should not place at "Built-in functions" in documentation)

2011-07-15 Thread Steven D'Aprano
Chris Rebert wrote: > On Fri, Jul 15, 2011 at 7:47 PM, Steven D'Aprano > wrote: > >> Assertions are for testing internal program logic, not for validation. >> >> (I don't even like using assert for testing. How do you test your code >> with assertio

Re: Aw: Functional style programming in python: what will you talk about if you have an hour on this topic?

2011-07-15 Thread Steven D'Aprano
concentrate on concrete examples. As far as Python goes, the use of list comps/generator expressions, iterators and decorators are the main functional idioms, not so much map, filter and especially reduce, which only avoided being removed from Python 3 by the narrowest margin. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Is there a way to customise math.sqrt(x) for some x?

2011-07-16 Thread Steven D'Aprano
I have a custom object that customises the usual maths functions and operators, such as addition, multiplication, math.ceil etc. Is there a way to also customise math.sqrt? I don't think there is, but I may have missed something. -- Steven -- http://mail.python.org/mailman/listinfo/p

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-16 Thread Steven D'Aprano
way to go: > > from distutils.core import setup > > setup( > name = 'Elucidation', > version = '0.0.1-WIP', [snip] Hilariously, in my newsreader, the first example (allegedly unaligned) was lined up as straight as an arrow, while the allegedly aligned s

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-16 Thread Steven D'Aprano
tion he craves, or that he honestly believes this crap. I suspect the later. I get the impression that he genuinely has so little self-awareness that he doesn't notice that for all his talk about FREEDOM, he's constantly trying to deny it to others by forcing them to do what he wants them to do. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal to extend PEP 257 (New Documentation String Spec)

2011-07-16 Thread Steven D'Aprano
nd forum software, even those aimed at programmers, often do an astonishingly crap job at not messing with your text. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Steven D'Aprano
but were too terrified to say so publicly would drop CPython in a flash and follow him. Thread starts here: read and weep. http://www.gossamer-threads.com/lists/python/python/835227?do=post_view_threaded#835227 How's that fork going Rick? Written a single line of code yet? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Steven D'Aprano
80 columns is hogwash. I agree! Which is why I set my line width to 78 columns. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-17 Thread Steven D'Aprano
Steven D'Aprano wrote: > Roy Smith wrote: > >> We don't have that problem any more. It truly boggles my mind that >> we're still churning out people with 80 column minds. I'm willing to >> entertain arguments about readability of long lines, but th

Re: Crazy what-if idea for function/method calling syntax

2011-07-17 Thread Steven D'Aprano
r 23 to 42 of theStr put suffix after theStr delete first char of theStr although this only applied to built-in functions, not user-functions. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Tabs -vs- Spaces: Tabs should have won.

2011-07-18 Thread Steven D'Aprano
Tim Chase wrote: > On 07/17/2011 08:01 PM, Steven D'Aprano wrote: >> Roy Smith wrote: >>> We don't have that problem any more. It truly boggles my >>> mind that we're still churning out people with 80 column >>> minds. I'm willing to ente

Re: Partial Function Application -- Advantages over normal function?

2011-07-18 Thread Steven D'Aprano
t() 0.7412619590759277 >>> t2.timeit() 0.3557558059692383 So in this example, the partial function is about twice as fast as the one written in Python. This does not necessarily apply for all functions, but it sometimes is useful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-18 Thread Steven D'Aprano
SCII, rather than understand you meant it as a sign of the utmost respect for the richness and diversity of human beings and their languages, cultures, maths and sciences. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-18 Thread Steven D'Aprano
rusi wrote: > Every time I try to understand unicode and remain stuck I come to the > conclusion that I must be an imbecile. http://www.joelonsoftware.com/articles/Unicode.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-18 Thread Steven D'Aprano
o treat it as UTF-8 will give an error, just as trying to view a mp3 file as if it were a jpeg will give an error. Why you imagine this is a problem for Unicode is beyond me. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path.isdir do not work for Foder named '2011-07-03'

2011-07-18 Thread Steven D'Aprano
ry backslash with an extra backslash: >>> print "logs\\2011-07-03" logs\2011-07-03 (2) Use forward slashes, as Windows will happily accept them instead of backslashes. (3) Use another operating system. *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path.isdir do not work for Foder named '2011-07-03'

2011-07-19 Thread Steven D'Aprano
Thomas Jollans wrote: > On 19/07/11 06:42, Steven D'Aprano wrote: >> (1) Escape every backslash with an extra backslash: >> >>>>> print "logs\\2011-07-03" >> logs\2011-07-03 > > There is a more elegant solution: use raw strings: r'c

Re: Pythonic way with more than one max possible

2011-07-19 Thread Steven D'Aprano
uggestions? # Untested. def get_winner(adict): values = sorted(adict.values(), reverse=True) if values[0] == values[1]: return adict['b'] else: return values[0] Assumes that adict has at least two items. May be slow if it has millions of items. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: I am fed up with Python GUI toolkits...

2011-07-19 Thread Steven D'Aprano
gt; 5. No particular GUI thread synchronization is needed -- Python has a > GIL. Except for Jython, IronPython and PyPy. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: I am fed up with Python GUI toolkits...

2011-07-20 Thread Steven D'Aprano
On Wed, 20 Jul 2011 05:20 pm Stefan Behnel wrote: > Steven D'Aprano, 20.07.2011 06:28: >>> Python has a GIL. >> >> Except for Jython, IronPython and PyPy. > > PyPy has a GIL, too. Isn't it optional though? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: (Maybe off topic) Can someone explain what a finite state machine is?

2011-07-20 Thread Steven D'Aprano
n() turning on turning off turning on turning off Traceback (most recent call last): File "", line 1, in File "", line 9, in run KeyboardInterrupt More complex finite state machines can have many different states, and much more complicated behaviour. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: a little parsing challenge ☺

2011-07-20 Thread Steven D'Aprano
On Wed, 20 Jul 2011 05:54 pm jmfauth wrote: > DRY? acronym for ? I'd like to tell you, but I already told somebody else... *grins* http://en.wikipedia.org/wiki/Don't_repeat_yourself http://c2.com/cgi/wiki?DontRepeatYourself -- Steven -- http://mail.python.org/mailman/li

Re: I am fed up with Python GUI toolkits...

2011-07-20 Thread Steven D'Aprano
On Wed, 20 Jul 2011 05:51 pm Andrew Berg wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: RIPEMD160 > > On 2011.07.20 02:28 AM, Steven D'Aprano wrote: >> Isn't it optional though? > No. > http://doc.pypy.org/en/latest/faq.html#does-pypy-have-a-gil-why Ah,

Re: Changing subject sucks. Re: I am fed up with Python GUI toolkits...

2011-07-20 Thread Steven D'Aprano
sn't. Rambling off on a new topic under the wrong subject is > rude. Ha ha, rantingrick lecturing others on rudeness! How cute! Or hypocritical. Sometimes I get those two confused. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert '165.0' to int

2011-07-23 Thread Steven D'Aprano
amming is deciding *precisely* what behaviour you want. Once you've done that, the rest is easy. Apart from debugging and writing documentation and making it fast enough, which is the other 90%. *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert '165.0' to int

2011-07-24 Thread Steven D'Aprano
ating more heat in the CPU and making other developers laugh at you :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert '165.0' to int

2011-07-24 Thread Steven D'Aprano
raise ValueError('Invalid literal for int') > return int(num) > return int(s) Consider what happens if you pass s = "42.-0". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Refactor/Rewrite Perl code in Python

2011-07-24 Thread Steven D'Aprano
ident that Python A does everything that Perl A does. Possibly *better* than the Perl module, since if you don't have a test suite for it, it probably has many hidden bugs. Continue in this way with the rest of the modules. At the end, you will have a full test suite against the entire collection of modules. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert '165.0' to int

2011-07-25 Thread Steven D'Aprano
n Python 3. Generator expressions become more efficient; itertools.imap disappears; the built-in map becomes a lazy generator rather than returning a list.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PEP 8 and extraneous whitespace

2011-07-26 Thread Steven D'Aprano
haven't seen your code, so I could be way off base here, but I expect you're using deeply hierarchical data structures, and violating the Law of Demeter: paper = paper_boy.give_newspaper() # Pay the paper boy. paper_boy.collect_payment(customer.backpocket.wallet(2.0, tip=300.00)) Don&

Re: @PyNoobs: The Fundamental Five Built-in Functions, and Beyond!

2011-07-26 Thread Steven D'Aprano
tive Get Out Of Kill-File card. Don't make me regret it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Strings show as brackets with a 'u'.

2011-07-26 Thread Steven D'Aprano
hould be, not what your terminal is actually using. Your console app (xterm, konsole, Gnome terminal, whatever...) probably has a way to query what encoding it is using, but I'll be buggered if I can find out what that is. In konsole I can look at the Settings > Encodings menu, but it claim

Maximize already running tkinter program on invocation

2011-07-27 Thread Steven Kauffmann
e web, but nothing about showing the already running application when 1 instance of the program already exists. Is there a way to realize this in python? I'm now doing the development on a linux machine, but the final program should work on Windows. Cheers, Steven -- http://mail.python.o

Re: PyWart: PEP8: A cauldron of inconsistencies.

2011-07-27 Thread Steven D'Aprano
er words, BE CONSISTENT! Oh, and you were doing so good there for all of one day. Back to the kill-file with you. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: NoneType and new instances

2011-07-28 Thread Steven D'Aprano
here. As for True and False, bool has to be able to return them, because the whole purpose of exposing bool is so people can call it: if bool(some_value) was an error, that would defeat the purpose of having bool! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: NoneType and new instances

2011-07-28 Thread Steven D'Aprano
ce if it didn't explode when list_of_objects contains None. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: NoneType and new instances

2011-07-28 Thread Steven D'Aprano
empty': str, 'null': lambda: None } does the job. No need for a top-level named function. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: os.path needs immediate attention!

2011-07-29 Thread Steven D'Aprano
;m currently writing a library where nearly all the functions violate the No Constant Argument rule. (The API isn't yet stable, so I may still change my mind.) Make of that what you will. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension to do os.path.split_all ?

2011-07-29 Thread Steven D'Aprano
would be a major bug. Did you actually try it? >>> '/home//h1122/bin///ghi/'.split('/') ['', 'home', '', 'h1122', 'bin', '', '', 'ghi', ''] Exactly as expected, and correct. Now obviously if you intend treating this as a list of path components, you have to filter out the empty strings, but otherwise works fine. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWart: os.path needs immediate attention!

2011-07-29 Thread Steven D'Aprano
ect. Been there, done that, floundered on the inability of people to work out the details. http://www.python.org/dev/peps/pep-0355/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: What is xrange?

2011-07-29 Thread Steven D'Aprano
i = y[0] i = y[1] i = y[2] ... until IndexError is raised. You break after calling y[0], but the next loop starts at y[0] again, and so you never progress beyond the first item in the xrange object. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: What is xrange?

2011-07-30 Thread Steven D'Aprano
Brian Blais wrote: > On Jul 29, 2011, at 9:22 PM, Steven D'Aprano wrote: > >> Billy Mays wrote: >> >>> Is xrange not a generator? I know it doesn't return a tuple or list, so >>> what exactly is it? >> >> xrange pre-dates generators

Re: eval, exec and execfile dilemma

2011-07-30 Thread Steven D'Aprano
sures? def factory(x): def inner(param): return param + x return inner plusone = factory(1) plustwo = factory(2) I'm betting that this will be much faster than exec, and much more readable. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to learn about metaclasses

2011-07-30 Thread Steven D'Aprano
[email protected] wrote: > On 25 juil, 17:36, "Steven W. Orr" wrote: >> I have been doing a lot of reading. I'm starting to get it. I think it's >> really cool as well as dangerous, > > Dangerous ??? Why so ? Is there anything "dangero

Re: NoneType and new instances

2011-07-30 Thread Steven D'Aprano
that there's only one instance of each. I'm sure that I remember a short period during which Python had bools, but didn't guarantee that there would only be one instance of True and one of False, but I'm damned if I can find any evidence of this. Am I confabulating? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Spam

2011-08-01 Thread Steven D'Aprano
ded all the spammer's URLs, as that will help improve their Google page ranks. I'm sure the spammer will thank you for your assistance. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Question

2011-08-01 Thread Steven D'Aprano
File "test.py", line 1 def func: ^ SyntaxError: invalid syntax Note that the error shows the line that is bad, and puts an up-arrow ^ directly under where it goes bad. Please COPY and PASTE the FULL error. Do not re-type it from memory, summarise it, put it in your own words, o

Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-01 Thread Steven D'Aprano
o write: cache = [-1]*900 Even better is to use a dict instead of a list. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-01 Thread Steven D'Aprano
Billy Mays wrote: > I have fixed the problem for you: > > > def fibo(n): > phi = (1+5**.5)/2; iphi = 1-phi; > return (phi**n - iphi**n) / (5**.5) Does your definition of "fixed" mean "gives wrong results for n >= 4 "? >>> fibo(4) ==

Re: test systems

2011-08-01 Thread Steven D'Aprano
o be so far out on the bleeding edge that even Slackware users consider them nuts. :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: where the function has problem? n = 900 is OK , but n = 1000 is ERROR

2011-08-02 Thread Steven D'Aprano
wered, "Who cares, we're making great time!" (True story.) > I find this tradeoff acceptable. Given that Fibonacci numbers are mostly of interest to number theorists, who care about the *actual* Fibonacci numbers and not almost-but-not-quite Fibonacci numbers, I&

Re: range() vs xrange() Python2|3 issues for performance

2011-08-02 Thread Steven D'Aprano
. However, at some point I would expect adding hand-crafted optimizations to CPython will cease to be worthwhile. Guido is already talking about CPython becoming the reference implementation, and PyPy the production implementation because it's faster. PyPy's optimizing compiler is already abou

Re: Spam

2011-08-02 Thread Steven D'Aprano
7;t all have a "more options" link. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

with statement and context managers

2011-08-02 Thread Steven D'Aprano
;NoneType' object has no attribute 'recv' Am I right to expect that the above idiom cannot work? If not, what sort of context managers do work as shown? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Syntactic sugar for assignment statements: one value to multiple targets?

2011-08-03 Thread Steven D'Aprano
nt targets. While slightly ugly, it doesn't seem ugly enough to justify the extra complexity of special syntax for such a special case. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Early binding as an option

2011-08-03 Thread Steven D'Aprano
next time I call test() I'll get len=None. [...] > So... Would this potentially produce wrong results? Would it be of any > use, or would its benefit be only valued in times when the whole > function needs to be redone in C? You really would need to demonstrate that the bottleneck in useful code (as opposed to toy examples) was the name lookups. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Early binding as an option

2011-08-03 Thread Steven D'Aprano
r: (1) use a different name: length = len (2) use a fully-qualified name: import builtins; len = builtins.len (3) do the assignment as a default parameter, which has slightly different binding rules: def func(x, len=len) (4) manual lookup: len = builtins.__dict__['len'] # untested I don't recommend that last one, unless you're deliberately trying to write obfuscated code :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: range() vs xrange() Python2|3 issues for performance

2011-08-03 Thread Steven D'Aprano
t code simply calls isperfect(n) for each n. The number of iterations in each call to isperfect is approximately sqrt(n), so the total in any exhaustive test is approximately sum(x**0.5 for x in range(upperlimit)), which gets rather large. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: range() vs xrange() Python2|3 issues for performance

2011-08-04 Thread Steven D'Aprano
Chris Angelico wrote: > On Thu, Aug 4, 2011 at 4:01 AM, Steven D'Aprano > wrote: >> a, b = divmod(n, i) >> if b == 0: >> total += a+i >> > > Wouldn't this fail on squares? It happens to give correct results as > far as I've checked; no squ

Re: PIL question. having exactly same font on multiple platforms

2011-08-04 Thread Steven D'Aprano
/www.joelonsoftware.com/items/2007/06/12.html http://www.codinghorror.com/blog/2007/06/whats-wrong-with-apples-font-rendering.html http://jujusoft.com/?page_id=25 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWhich

2011-08-04 Thread Steven D'Aprano
on. I would recommend not catching ImportError at all, and just let the standard Python error handling print the traceback. Especially for a tool aimed at programmers (who else would be interested in PyWhich?), hiding useful diagnostic errors and replacing them with a generic, and potentially wrong, message, is very bad. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: with statement and context managers

2011-08-04 Thread Steven D'Aprano
Thomas Rachel wrote: > Am 03.08.2011 04:15 schrieb Steven D'Aprano: [...] > > but to me that looks badly wrong. Surely the spam context manager > > object will exit after the first iteration, and always raise an > > exception on the second? But I don't quite u

Re: PyWhich

2011-08-05 Thread Steven D'Aprano
Tim Chase wrote: > On 08/04/2011 07:34 PM, Steven D'Aprano wrote: >> Billy Mays wrote: >>> #!/usr/bin/python >> >> I believe the recommended, platform independent hash-bang line is >> >> #!/usr/bin/which python > > I think you mean > >

Re: Observations on the three pillars of Python execution

2011-08-05 Thread Steven D'Aprano
tain code. Even methods are just wrappers around functions. Even built-in functions like len don't contain code! (Or at least, their code isn't accessible from Python.) Which makes sense, if you think about it: their code is part of the Python virtual machine, not the object. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive functions (was Re: Observations on the three pillars of Python execution)

2011-08-05 Thread Steven D'Aprano
ing recursive: An easier way to demonstrate the process: >>> def f(x): ... print x ... if x > 0: f(x-1) ... >>> f(3) 3 2 1 0 >>> g = f >>> del f >>> g(3) 3 Traceback (most recent call last): File "", line 1, in File "", line 3, in f NameError: global name 'f' is not defined -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PyWhich

2011-08-05 Thread Steven D'Aprano
g special with it. Well you better also catch SyntaxError, because a later version of your script might need to do something special with it too :) Also RuntimeError, ValueError, TypeError... *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Observations on the three pillars of Python execution

2011-08-05 Thread Steven D'Aprano
Eric Snow wrote: > On Fri, Aug 5, 2011 at 8:36 AM, Steven D'Aprano > wrote: >> Eric Snow wrote: >> >>> In Python, three types of objects have special syntax and mechanics >>> for their instantiation, during which a code object is generated: >>>

Re: Replace all references to one object with references to other

2011-08-05 Thread Steven D'Aprano
you the tools to shoot yourself in the foot, although it won't necessarily be easy, or pretty, or fast. So, tell us what your real problem is, the end towards which you think "replace all..." is the solution, and we'll see if we can help. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Observations on the three pillars of Python execution

2011-08-05 Thread Steven D'Aprano
Mel wrote: > Steven D'Aprano wrote: > >> There may be some other obscure built-in type that includes code objects, >> but I can't imagine what it would be. I feel confident in saying that >> functions, and functions alone, contain code. Even methods are just

Re: Observations on the three pillars of Python execution

2011-08-05 Thread Steven D'Aprano
Eric Snow wrote: > On Fri, Aug 5, 2011 at 11:29 AM, Steven D'Aprano > wrote: [...] >> Do you believe that this process of generating a code object and throwing >> it away is a part of the Python language specification, which any >> compiler must do in order to ca

Re: Question about encoding, I need a clue ...

2011-08-05 Thread Steven D'Aprano
s is the default for Mac OS's terminal app, but I have no idea about the many different Linux terminals). Then: >>> bytes = 'ao\xc3\xbbt' # From calendar.month_name[8] >>> s = bytes.decode('utf-8') # Like unicode(bytes, 'utf-8') >>&g

Re: Complex sort on big files

2011-08-05 Thread Steven D'Aprano
such big files, because it *takes* a lot more work. For something as small as one million numbers, chances are the Unix sort falls back on a heapsort or a quicksort, which will be pretty fast, but it ain't no timsort. So yes, Python's timsort is awesome, but so is Unix's sort, just in different ways. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: install editra

2011-08-06 Thread Steven D'Aprano
8/ sudo python setup.py install and if that doesn't work, try asking on an Editra mailing list. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to separate a list into two lists?

2011-08-06 Thread Steven D'Aprano
t in any version of Python between 1.5 and 3.3 that I have. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to separate a list into two lists?

2011-08-06 Thread Steven D'Aprano
s to a list, > below works because there are exactly 2 items on the rhs. > Does Python have a catchall, or an ignore the rest? Yes. In Python 3, you can do this: >>> a, b, *t, c = (1, 2, 3, 4, 5, 6, 7, 8, 9) >>> t [3, 4, 5, 6, 7, 8] (but not in Python 2) -- Steven -- http

Re: how to separate a list into two lists?

2011-08-06 Thread Steven D'Aprano
t really doesn't matter what you do, they will all be more or less as efficient. Write whatever you feel looks best. But if L is huge, then the difference between a four-liner that iterates over the list once, and one-liner that iterates over it four times, may be considerable. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to separate a list into two lists?

2011-08-06 Thread Steven D'Aprano
t was he wanted to avoid *writing out an explicit loop*. That is, he wants a one-liner, so he doesn't have to think about the details of iterating over the list. When we write: a = sum(a_sequence) aren't we doing the same thing really? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to dynamically generate __name__ for an object?

2011-08-06 Thread Steven D'Aprano
"name"? Double-leading-and-trailing-underscore attributes are reserved for Python, and have special semantics. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Restricted attribute writing

2011-08-07 Thread Steven D'Aprano
#x27;) that's a prime candidate for turning into an assertion: assert condition, 'condition unexpectedly false' do_something() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Restricted attribute writing

2011-08-07 Thread Steven D'Aprano
d "b", or by index, 0 and 1: instance = ThingWithTwoIntegers(23, 42) instance[0] => 23 instance.b => 42 Obviously this isn't a full blown list, but if you don't need all the list-like behaviour (sorting, inserting, deleting items, etc.) why support it? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: import hooks (PEP 302) broken in Python >=2.5?

2011-08-07 Thread Steven D'Aprano
sion(s) of Python are you using? Depending on whether you are asking out of curiosity, or because you have code that uses import hooks and you're about to migrate from Python 2.3 to 3.1, the answers may be different. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Wait for a keypress before continuing?

2011-08-07 Thread Steven D'Aprano
l be interfering with the keyboard buffer, for its own purposes. E.g. in IDLE 2.6.2, if I call getch it *immediately* returns without blocking: >>> msvcrt.getch() '\xff' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: WxPython and TK

2011-08-07 Thread Steven D'Aprano
f I would have gotten a dollar for every time I talked to someone in a > company about why they dont use python for their products and I was served > the answer "Well it kind of sucks in GUI development", I would be a > millionaire. What, these millions of companies don't ha

Re: Docstrings and class Attributes

2011-08-08 Thread Steven D'Aprano
teger, so t.fred.__doc__ returns the docstring from the integer, not for the property. >>> t.__class__.fred.__doc__ 'attribute' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Docstrings and class Attributes

2011-08-08 Thread Steven D'Aprano
But the hard part is ensuring that Test.fred doesn't get replaced: >>> Test.fred = 11 >>> Test.fred.__doc__ 'int(x[, base]) -> integer\n\nConvert a string or number ...' Not impossible to solve, but an awful lot of trouble for very little benefit. Just put

Re: Docstrings and class Attributes

2011-08-08 Thread Steven D'Aprano
Ethan Furman wrote: > So if property docstrings are so hard to get to, what's the point in > having them? Hard to get, not impossible. But I have no idea really -- they don't seem very useful to me. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Object Diffs

2011-08-08 Thread Steven D'Aprano
ources may help: http://wiki.python.org/moin/DistributedProgramming http://wiki.python.org/moin/ParallelProcessing -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Docstrings and class Attributes

2011-08-08 Thread Steven D'Aprano
ngs on the individual getter/setter/deleter functions. But property() itself explicitly takes a docstring parameter. It is that docstring that seems of limited value, except that Eric Snow has pointed out that help(instance) will display property help strings. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: __all__

2011-08-09 Thread Steven D'Aprano
with this is that there are roughly a dozen items I > would like to make available via the `import *` mechanism in my dbf > module, and another dozen that, while part of the public API, don't need > to be available via an `import *`. You have to choose both, or neither, but you can't have just one. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: just for fun: make a class (not its instances) iterable

2011-08-09 Thread Steven D'Aprano
!" ... >>> >>> for obj in MyClass: ... print obj ... 42 23 -99 Surprise! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: input file format

2011-08-09 Thread Steven D'Aprano
;) for line in f: if some_condition(line): continue # skip the line process(line) f.close() some_condition can be anything you like. You just have to write the code to make it so. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-10 Thread Steven D'Aprano
y to do it > this way. But it does force people to read it, because some people will use it, and so others will have to suffer for their poor judgement. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: String concatenation - which is the fastest way ?

2011-08-10 Thread Steven D'Aprano
se join, which is consistently fast. You should limit string addition to small numbers of substrings: result = head + body + tail # This is okay. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

<    13   14   15   16   17   18   19   20   21   22   >