Re: Python 2.6 OR 3.2

2011-06-10 Thread Steven D'Aprano
onsibility for fixing the system when it breaks :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
en than not. So I'd be -1 on automatically inheriting them. >> >> However, I'd be +1 easily on a little help from the language to >> explicitly request to inherit the docstring. > > An empty docstring "" could be interpreted as 'ditto' ;-) It

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
information. If Python does inherit > docstrings, it can lead to incorrect information. This is no different from inheriting any other attribute. If your class inherits "attribute", you might get an invalid value unless you take steps to ensure it is a valid value. This failure mode doesn't cause us to prohibit inheritance of attributes. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
#x27; assert all(cls.__doc__ is None for cls in (A, B, D)) assert all(cls.__doc__ == 'A docstring.' for cls in (C, E, F)) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
On Fri, 10 Jun 2011 16:47:03 +, Steven D'Aprano wrote: > On Thu, 09 Jun 2011 00:22:54 -0600, Eric Snow wrote: > >> Sometimes when using class inheritance, I want the overriding methods >> of the subclass to get the docstring of the matching method in the base >>

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
On Fri, 10 Jun 2011 11:01:41 -0600, Eric Snow wrote: > On Fri, Jun 10, 2011 at 10:47 AM, Steven D'Aprano > wrote: >> Here's some Python 3 code that uses a factory function as a metaclass >> to inherit docstrings. Give the class a docstring of an empty string, >>

Re: how to inherit docstrings?

2011-06-10 Thread Steven D'Aprano
On Fri, 10 Jun 2011 14:46:06 -0700, Carl Banks wrote: > On Friday, June 10, 2011 2:51:20 AM UTC-7, Steven D'Aprano wrote: >> On Thu, 09 Jun 2011 20:36:53 -0700, Carl Banks wrote: >> > Put it this way: if Python doesn't automatically inherit docstrings, >> >

Recursion error in metaclass

2011-06-10 Thread Steven D'Aprano
ck (most recent call last): File "", line 1, in File "", line 9, in __new__ File "", line 5, in get_mro File "", line 9, in __new__ File "", line 5, in get_mro File "", line 9, in __new__ File "", line 4, in get_mro RuntimeError: maximum recursion depth exceeded while calling a Python object I am utterly perplexed. What's going on here? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursion error in metaclass

2011-06-11 Thread Steven D'Aprano
On Sat, 11 Jun 2011 01:33:25 -0400, Terry Reedy wrote: > On 6/10/2011 11:34 PM, Steven D'Aprano wrote: >> I have a metaclass in Python 3.1: >> >> class MC1(type): >> @staticmethod >> def get_mro(bases): >> print('get_mro called&

Re: __dict__ is neato torpedo!

2011-06-11 Thread Steven D'Aprano
more subtle risk: not all objects have a __dict__. But if you obey the rule about never updating from arbitrary objects you don't know, then you won't be surprised by an object with no __dict__. Other than that, using update is a good trick to have in your toolbox. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: __dict__ is neato torpedo!

2011-06-12 Thread Steven D'Aprano
On Sat, 11 Jun 2011 21:28:40 -0500, Andrew Berg wrote: > On 2011.06.11 09:13 PM, Steven D'Aprano wrote: >> A second, more subtle risk: not all objects have a __dict__. But if you >> obey the rule about never updating from arbitrary objects you don't >> know, th

Re: Handling emails

2011-06-12 Thread Steven D'Aprano
rstand your problem. In general, if you have some bytes, you can decode it into a string by hand: >>> header = b'To: [email protected]\n' >>> s = header.decode('ascii') >>> s 'To: [email protected]\n' If this is not what you mean, perhaps you should give an example of what header looks like, what you hope to get, and a concrete example of how it differs in Python 3. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Keyboard Layout: Dvorak vs Colemak: is it Worthwhile to Improve the Dvorak Layout?

2011-06-13 Thread Steven D'Aprano
pessimation: if it takes you three months to get back up to speed on a new keyboard layout, you potentially may never make back that lost time in your entire programming career. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Function declarations ?

2011-06-13 Thread Steven D'Aprano
hy Python use definitions instead of declarations. > > It's not either/or. Any language has to provide a way to define > functions whether or not it provides a way to declare them. Exactly. Pascal has both; Python only has definitions. > Anyway, it seems the Python way to dec

Re: dummy, underscore and unused local variables

2011-06-13 Thread Steven D'Aprano
mailing list yesterday. http://code.activestate.com/lists/python-tutor/83236/ Yes, I realise that Tim probably won't see this either. I'm just making a point. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: What is the most efficient way to compare similar contents in two lists?

2011-06-13 Thread Steven D'Aprano
On Tue, 14 Jun 2011 01:39:50 +1000, Chris Angelico wrote: > Python: "Batteries Included". > > (Although Python 3 is "Most of the batteries you're used to, included".) Oh gods, you're not going to bring up sort(cmp=...) again are you???? /me

Re: dummy, underscore and unused local variables

2011-06-13 Thread Steven D'Aprano
) >>  |  bool(x) -> bool >>  .. >>  I'd welcome comments on this as well. > > _ is special to IDLE. Not just IDLE. Also the vanilla Python command line interpreter. In fact, you can even find the code that controls it: help(sys.displayhook) http://docs.python.or

Re: [Python-ideas] 'Injecting' objects as function-local constants

2011-06-13 Thread Steven D'Aprano
example given, that's unlikely to be the bottleneck. But if you want to optimize name lookup, it has to be a local. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries and incrementing keys

2011-06-14 Thread Steven D'Aprano
r ints, the "if key in dict" version will usually be faster. Unless there are lots of missing keys, in which case the version using dict.get may be faster. Either way, the difference is unlikely to be significant except for the tightest of tight loops. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Dictionaries and incrementing keys

2011-06-14 Thread Steven D'Aprano
esent, it is faster to use try...except. Only if the key is frequently missing does it become faster to test first. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path and Path

2011-06-16 Thread Steven D'Aprano
th components in a form independent of the path separator, and only care about the separator when converting to and from strings. [...] > So, I suppose I shall have to let go of my dreams of > > --> Path('/some/path/and/file') == '\\some\\path\\and\\file' To s

Re: os.path and Path

2011-06-16 Thread Steven D'Aprano
these two paths could represent the same location: 'a/b/c:d/e' # on Linux or OS X 'a:b:c/d:e' # on classic Mac pre OS X and be impossible on Windows. So what's the canonical path it should be converted to? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Composing regex from a list

2011-06-16 Thread Steven D'Aprano
*for* cicle? How about this? def compile_alternatives(*args): alternatives = map(lambda s: '(' + s + ')', args) alternatives = '|'.join(alternatives) return re.compile(alternatives) >>> x = compile_alternatives('spam', 'ham', 'cheese') >>> x.search('fried egg and spam').group() 'spam' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: os.path and Path

2011-06-16 Thread Steven D'Aprano
On Thu, 16 Jun 2011 09:16:22 -0700, Ethan Furman wrote: > Steven D'Aprano wrote: >> If Path is intended to be platform independent, then these two paths >> could represent the same location: >> >> 'a/b/c:d/e' # on Linux or OS X >> 'a:b:c/d:e

Re: break in a module

2011-06-16 Thread Steven D'Aprano
g: # === module extras.py === def ham(): pass def cheese(): pass def salad(): pass # === module other.py === def spam(): pass if not some_condition: from extras import * -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: break in a module

2011-06-16 Thread Steven D'Aprano
xisting uses of the word, e.g. sys.exit(). Overloading "break" strikes me as disagreeable, but not as disagreeable as overloading "return" or "in" :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Fun and games with lambda

2011-06-17 Thread Steven D'Aprano
ve/v/5H3d1yQN5N15HEgOWHMx Encouraging-hatred-of-lambdas-for-fun-and-profit-ly y'rs, -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Best way to insert sorted in a list

2011-06-17 Thread Steven D'Aprano
99420166 >>> t_bisect.timeit(number=100) 0.3741610050201416 (For those unfamiliar with timeit, small numbers are faster.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: break in a module

2011-06-17 Thread Steven D'Aprano
On Sat, 18 Jun 2011 12:36:42 +1000, Cameron Simpson wrote: > On 17Jun2011 06:00, Steven D'Aprano > wrote: | If we were to have a > "exit this module early, but without exiting Python | altogether" > statement, I'd consider "exit" to be the most descript

Re: break in a module

2011-06-17 Thread Steven D'Aprano
On Sat, 18 Jun 2011 14:31:51 +1000, Chris Angelico wrote: > On Sat, Jun 18, 2011 at 1:50 PM, Steven D'Aprano > wrote: >> I don't think the use-case for this is convincing enough to need it, >> but it's an interesting concept. I once played around with a >&

Re: integer to binary 0-padded

2011-06-18 Thread Steven D'Aprano
(255, 1 + 2 + 16)) > 255 >>>> eval('{:+#0{}b}'.format(-255, 1 + 2 + 16)) > -255 Is this a question? Or did you just decide to share some code? Please leave enough context so that readers can understand what you are talking about. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Strategy to Verify Python Program is POST'ing to a web server.

2011-06-19 Thread Steven D'Aprano
d the website? > Either that, or just accept that it cannot be done. Compare the amount > of effort game developers put into trying to implement tamper-proofing > in software with how little success they've had. Exactly. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Lisp : car and cdr

2011-06-19 Thread Steven D'Aprano
) Three element list: (42, (43, (44, None))) and so forth. So while you could harmlessly use a slice L[1:], there is no point, since L[1:] will have at most a single element. >> def length(L): >> if not L: return 0 >> return 1 + length(cdr(L)) > > How is this differ

Re: What is this syntax ?

2011-06-19 Thread Steven D'Aprano
d, careful, look. As such, I would want to think long and hard before inflicting it on others by using it myself. For those unfamiliar with the idea of code smells: http://www.joelonsoftware.com/articles/Wrong.html -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Is the mailing list to usenet gateway borked?

2011-06-20 Thread Steven D'Aprano
The last couple of messages on this list show up fine on the mailman archives, but are empty posts on comp.lang.python. Is there a problem with the mail -> usenet gateway? Who controls that? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Is the mailing list to usenet gateway borked?

2011-06-20 Thread Steven D'Aprano
On Mon, 20 Jun 2011 16:49:33 +, Peter Pearson wrote: > On 20 Jun 2011 01:41:44 GMT, Steven D'Aprano wrote: >> The last couple of messages on this list show >> up fine on the mailman archives, but are empty posts on >> comp.lang.python. Is there a problem with

Re: Python scoping

2011-06-20 Thread Steven D'Aprano
If your functions are so large that you worry about name clashes between code in different parts of the one function, the solution is to break this one huge function into many small functions. That's what functions are for: to encapsulate a limited amount of reusable functionality into a

Re: Is there any advantage or disadvantage to using sets over list comps to ensure a list of unique entries?

2011-06-20 Thread Steven D'Aprano
#x27;2', '7', '5', '9'] source = ['6', '2', '1', '0'] # add unique items of source to target, keeping the order tmp = sorted(target) for item in source: flag = binary search for item in tmp if not flag: insert item in tmp keeping the list sorted append item to the end of target del tmp The bisect module will be useful here. For small lists, it really doesn't matter what you do. This probably only matters beyond a few tens of thousands of items. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: those darn exceptions

2011-06-21 Thread Steven D'Aprano
e exceptions that could occur in any > function, by using __exceptions__ (if provided) or recursively finding > exceptions for all functions called, and doing a set-union. In general, you can't do this at compile-time, only at runtime. There's no point inspecting len.__exceptions__ at compile-time if len is a different function at runtime. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: writable iterators?

2011-06-22 Thread Steven D'Aprano
o change (they don't store their values anywhere, but calculate them one by one on demand and then immediately forget that value); * immutable sequences, like tuples, are immutable and cannot be changed because that's what immutable means; * mutable sequences like lists can be

Re: writable iterators?

2011-06-22 Thread Steven D'Aprano
On Thu, 23 Jun 2011 09:10 am Neal Becker wrote: > Steven D'Aprano wrote: > >> On Wed, 22 Jun 2011 15:28:23 -0400, Neal Becker wrote: >> >>> AFAICT, the python iterator concept only supports readable iterators, >>> not write. Is this true? >>

Re: writable iterators?

2011-06-22 Thread Steven D'Aprano
On Thu, 23 Jun 2011 09:30 am Thomas 'PointedEars' Lahn wrote: > Mel wrote: > >> Steven D'Aprano wrote: >>> I *guess* that what you mean by "writable iterators" is that rebinding e >>> should change seq in place, i.e. you would expect that s

Re: those darn exceptions

2011-06-23 Thread Steven D'Aprano
that particular one. Let everything else propagate. Good advice. +1 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: performance critical Python features

2011-06-23 Thread Steven D'Aprano
lots of tiny scripts really fast: each invocation of the interpreter requires a whole lot of imports, which are slow the first time. (Still, Python's overhead at startup time is nowhere near as expensive as that of Java... but Java is faster once started up.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Project-wide variable...

2011-06-23 Thread Steven D'Aprano
me__ to '__main__' instead. So this is a (slightly hacky) way of distinguishing code that runs when the module is imported from code that runs on execution. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: unzip problem

2011-06-24 Thread Steven D'Aprano
g takes place, but you've messed up the line numbers (probably by editing the file after importing it). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Significant figures calculation

2011-06-24 Thread Steven D'Aprano
#x27;12') Decimal('49') >>> >>> D('25.624') / D('25') Decimal('1.0') The only thing you have to watch out for is this: >>> D('1.2') == D('1.23') # no rounding False >>> D('1.2') == +D('1.23') # force rounding True -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: NEED HELP-process words in a text file

2011-06-24 Thread Steven D'Aprano
RRUPTED UPPERCASE WORDS AS SHOUTING LOUDLY -- regardless of the poor design of programming languages in the 60s and 70s. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Significant figures calculation

2011-06-27 Thread Steven D'Aprano
about when 1200 is actually 4 significant digits? Or 3? Then you shouldn't write it as 1200.0. By definition, zeros on the right are significant. If you don't want zeroes on the right to count, you have to not show them. Five sig figures: 1200.0 Four sig figures: 1200 Three sig figur

Re: Significant figures calculation

2011-06-28 Thread Steven D'Aprano
On Tue, 28 Jun 2011 01:16 pm Chris Angelico wrote: > On Tue, Jun 28, 2011 at 12:56 PM, Steven D'Aprano > wrote: >> Zero sig figure: 0 >> > > Is 0.0 one sig fig or two? (Just vaguely curious. Also curious as to > whether a zero sig figures value is ever use

Re: how to call a function for evry 10 secs

2011-06-29 Thread Steven D'Aprano
hisan wrote: > Hi All, > I need to call a function for evry 10 secs > how can i achieve this in python import time while True: time.sleep(10) function() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Safely modify a file in place -- am I doing it right?

2011-06-30 Thread Steven D'Aprano
ents were helpful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Enhanced dir() function

2011-06-30 Thread Steven D'Aprano
: >>> dir(str) ['__add__', '__class__', ... snip 60+ other names ... 'upper', 'zfill'] you can easily filter the results to show only names that interest you, by passing a glob: >>> dir(str, '*split*') ['rsplit', '

Re: Enhanced dir() function

2011-07-01 Thread Steven D'Aprano
Tim Chase wrote: > On 06/30/2011 11:29 PM, Steven D'Aprano wrote: >> The dir() function is designed for interactive use, inspecting objects >> for the names of attributes and methods. >> >> Here is an enhanced version that allows you to pass a glob to filter the

Re: How to save a email message?

2011-07-02 Thread Steven D'Aprano
nter is at the end of the file, so when you read from it, it immediately gets EOF (i.e. empty). >>> from io import BytesIO as B >>> x = B() >>> x.write(bytes("hello", 'ascii')) 5 >>> x.read() b'' But if you seek back to the beginning: >>> x.seek(0) 0 >>> x.read() b'hello' >>>> from mailbox import mbox as Mbx *raises eyebrow* Do you need to rename mbox? You don't even save a keypress: shift-m b x and m b o x both take 4 keypresses. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why won't this decorator work?

2011-07-02 Thread Steven D'Aprano
e decorator syntax is completely different. It is doing this: # replace the function roll_die with the output of move, which is a string roll_die = move(roll_die) # now try to call "roll_die", actually a string roll_die() which is more like: move(roll_die)() See the difference? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Inexplicable behavior in simple example of a set in a class

2011-07-02 Thread Steven D'Aprano
.myNum 9 >>> z.__dict__ # No instance attributes yet. {} >>> z.clearNum() >>> z.__dict__ # Now there is one. {'myNum': 0} >>> z.__class__.myNum # the class attribute still exists 9 The simplest way to fix this is to move the declaration of self.mySet into the __init__ method. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Steven D'Aprano
rantingrick wrote: > Hello fellow programmers, scripters, hackers, and debutantes. Your ideas are intriguing to me and I wish to subscribe to your newsletter. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-02 Thread Steven D'Aprano
my sympathy. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Testing if a global is defined in a module

2011-07-04 Thread Steven D'Aprano
module, which may or may not happen to point to the same object as the other module as well. >'usingCgi' is the only data variable defined in It seems to me that your approach here is unnecessarily complex and fragile. I don't know what problem you are trying to solve, but trying to solve it by intraspecting differences that aren't differences is surely the wrong way to do it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-04 Thread Steven D'Aprano
nk unicorns. And even if we did, we wouldn't want YOUR idea of the perfect language. Rick, stop trying to "help" the community with these over-reaching grand schemes that nobody but you wants, that always involve you telling everyone else that they have to build the system you think you want. Go do something useful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem!!

2011-07-04 Thread Steven D'Aprano
amir chaouki wrote: > the problem is when i use the seek function on windows it gives me > false results What do you mean "false results"? What does this even mean? Please show us: * what you do * what result you expect * what result you actually get -- Steven -- http:/

Re: Testing if a global is defined in a module

2011-07-04 Thread Steven D'Aprano
way to do it. > See my last post... Yes, but what are you actually *trying to do*? "Detecting data members" is not an end in itself. Why do you think you need to detect data members? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-05 Thread Steven D'Aprano
l the last window is closed, and no window is privileged over the others. Even in Windows, the sort of MDI interface Rick seems to be describing is less common now than it used to be -- possibly even rare. http://en.wikipedia.org/wiki/Multiple_document_interface -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: embedding: how do I redirect print output?

2011-07-05 Thread Steven D'Aprano
ut >>> print "Hello world" dlrow olleH >>> print "Goodbye cruel world!!!" !!!dlrow leurc eybdooG >>> sys.stdout = sys.__stdout__ >>> fake_out.log.getvalue() 'HELLO WORLD\nGOODBYE CRUEL WORLD!!!\n' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Implicit initialization is EXCELLENT

2011-07-05 Thread Steven D'Aprano
forcing the user to do so. When they need to learn about root windows, they will in their own good time. Now, I have an ulterior motive in raising this issue... I can't find the original article I read! My google-fu has failed me (again...). I don't suppose anyone can recognise it and

Re: Testing if a global is defined in a module

2011-07-05 Thread Steven D'Aprano
, code and the comments describing them get out of sync. Quote: "At Resolver we've found it useful to short-circuit any doubt and just refer to comments in code as 'lies'. " --Michael Foord paraphrases Christian Muirhead on python-dev, 2009-03-22 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-06 Thread Steven D'Aprano
Corey. My statement has nothing to do with > sort. sort is just the vehicle. My statement is that the cmp argument > to sort IS a user defined control structure (the code block to be > exact). The cmp argument to sort is not a control structure because it is not a structure and it does not control the program flow. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EXCELLENT

2011-07-06 Thread Steven D'Aprano
rns me not to add a link, although perhaps it's > time for recalibration (after all, summer season started) :-) No! I was serious. I've spent *ages* trying to find the link to the article... if you know it, please share. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-06 Thread Steven D'Aprano
sal migondis wrote: > How could a belief be wrong? I believe you are a small glass of beer. Are you *actually* a small glass of beer in reality? If so, my belief is right. If you are a human being, then my belief is wrong. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-06 Thread Steven D'Aprano
, which is different again to the sort of knife is needed by some guy working in a warehouse unpacking boxes. Different jobs need different tools. There is no perfect language because different tasks need different tools, and any compromise tool that tries to do everything will be weaker than a specialist tool. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-06 Thread Steven D'Aprano
or! No, it does not run in the background: it is a foreground app. An extreme case, but telling. There is no absolute need for any windows at all, let alone for one privileged window to rule all the others. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: The end to all language wars and the great unity API to come!

2011-07-06 Thread Steven D'Aprano
rantingrick wrote: > On Jul 6, 6:44 am, Steven D'Aprano [email protected]> wrote: > >> A control structure is a structure which controls the program flow. >> Control structures include: >> >> * jumps (goto, gosub, comefrom, exceptions, brea

Re: Implicit initialization is EVIL!

2011-07-06 Thread Steven D'Aprano
27;d better replace it, then. (he takes a quick peek behind the counter) Owner: Sorry squire, I've had a look 'round the back of the shop, and uh, we're right out of windows. Customer: I see. I see, I get the picture. Owner: I got a DOS batch file. (pause) Customer: (sweet as sugar) Pray, does it talk? Owner: Yes. Customer: Right, I'll have that one then. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-06 Thread Steven D'Aprano
Andrew Berg wrote: > On 2011.07.06 11:11 AM, Steven D'Aprano wrote: >> The Dead Window Sketch >> == > As much as I hate it when people feed trolls, that was pretty funny. Thanks. Re the troll-feeding, every few months I get a strange seizure in my b

Re: interactive plots

2011-07-06 Thread Steven Howe
On 07/06/2011 09:59 AM, Ian Kelly wrote: On Wed, Jul 6, 2011 at 9:04 AM, Mihai Badoiu wrote: How do I do interactive plots in python? Say I have to plot f(x) and g(x) and I want in the plot to be able to click on f and make it disappear. Any python library that does this? Matplotlib can be i

Re: multiple calls to show doesnot work for matplotlib

2011-07-06 Thread Steven D'Aprano
eforge.net/faq/howto_faq.html#use-show Does that answer your question? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Does hashlib support a file mode?

2011-07-06 Thread Steven D'Aprano
Phlip wrote: > Note the fix also avoids comparing to None, which, as usual, is also > icky and less typesafe! "Typesafe"? Are you trying to make a joke? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EXCELLENT

2011-07-06 Thread Steven D'Aprano
s than initialisation. The blog post I'm looking for is not about finalizers, but about API design: don't make the caller give an explicit second activation call if you don't need to. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: TypeError: unbound method DefaultTracer() must be called with MyClass instance as first argument (got str instance instead)

2011-07-07 Thread Steven D'Aprano
object): def __init__(self): self.func = function but now you can't call C.func because it doesn't exist, you have to initialise an instance first. > Alternately, how can I achieve what I want, i.e. a class-wide default > used by all instances created off it, but > itself be changeable, so that once changed, the changed default would > be used by subsequent newer instances of that class. class C(object): default = staticmethod(function) def __init__(self): self.func = type(self).default ought to do it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-07 Thread Steven D'Aprano
ously viewing page 303. An alternate UI for to split the one window into two panes, and scroll them independently. So a single file may have one or two panes, in one or more windows. So, you can have multiple documents in multiple windows, and there is no 1:1 relationship between them. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Does hashlib support a file mode?

2011-07-07 Thread Steven D'Aprano
d for is to ever care about the type of the arguments -- that's just a waste of time, since a fast identity (memory location) test is sufficient. This is why I initially thought that Phlip was joking when he suggested that "m is None" could be type-unsafe. It doesn't matter what type m has, "m is " will always be perfectly safe. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Does hashlib support a file mode?

2011-07-08 Thread Steven D'Aprano
() with open(path, 'rb') as f: while True: s = f.read(blocksize) if not s: break hash.update(s) return hash.hexdigest() -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Implicit initialization is EVIL!

2011-07-08 Thread Steven D'Aprano
rantingrick wrote: > On Jul 7, 8:25 pm, Steven D'Aprano [email protected]> wrote: >> rantingrick wrote: >> > On Jul 7, 12:34 am, Gregory Ewing wrote: >> >> The important thing is that it's okay for an app to stay >> >> ali

Re: Does hashlib support a file mode?

2011-07-08 Thread Steven D'Aprano
Phlip wrote: > On Jul 8, 12:42 am, Steven D'Aprano [email protected]> wrote: >> Phlip wrote: >> >> I worded that poorly. None is (AFAIK) the only instance of NoneType, >> >> but I should've clarified the difference.> The is o

Re: String concatenation vs. string formatting

2011-07-08 Thread Steven D'Aprano
ng things just for the sake of being different, or because they're cool, although of course that's a subjective judgement. (Some people think that functional programming idioms such as map and filter fall into that category, wrongly in my opinion.) In any case, it's clear that Python support

Re: String concatenation vs. string formatting

2011-07-08 Thread Steven D'Aprano
ther. This is not a hypothetical risk. People have been burned by this in real life: http://www.gossamer-threads.com/lists/python/dev/771948 If you're interested in learning about the optimization: http://utcc.utoronto.ca/~cks/space/blog/python/ExaminingStringConcatOpt -- Steven --

Re: What makes functions special?

2011-07-09 Thread Steven D'Aprano
as compiled code objects, closures, etc. You would have to fake them somehow. Provided you could fake them sufficiently well, then the lack of a byte-code compiler is just a quality of implementation issue. If that's *not* your question, them I'm stumped. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: String concatenation vs. string formatting

2011-07-10 Thread Steven D'Aprano
ne of them are pretty. fields = (demux_filter, field_filter, fpsin_filter, i2pfilter, dn_filter, fpsout_filter, trim_filter, info_filter) avs.write("%s"*len(fields) % fields) works for me. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: String concatenation vs. string formatting

2011-07-10 Thread Steven D'Aprano
fo_filter] > avs.write(''.join(fields)) I can't believe I didn't think of that. I must be getting sick. (The sore throat, stuffy nose and puffy eyes may also be a sign.) Yes, ''.join() is far to be preferred over my solution using "%s". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Function docstring as a local variable

2011-07-10 Thread Steven D'Aprano
"""This is my documentation string. Imagine this has actual useful information. """ def f2(): dc = """This is my documentation string. Imagine this has actual useful information. """ Now, at the interactive interpreter, call: help(f1) help(f2) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Wgy isn't there a good RAD Gui tool fo python

2011-07-12 Thread Steven D'Aprano
projects that have been taken over by developers from the Windows world (I'm looking at you, Firefox). YMMV. > And as soon as developers start developing for Unix customers (say > Komodo, for instance), they start following the "Windows model" - as you > call it. Surely that's because Komodo started off as a Windows application before being ported to Unix? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Set run vars with each call

2011-07-12 Thread Steven D'Aprano
e used by the caller. # (Guarantee void on planet Earth.) then replace None by MISSING in the code above. Is this the sort of scenario you are talking about? If not, I'm completely lost. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: "Python Wizard," with apologies to The Who

2011-07-12 Thread Steven D'Aprano
guy", but that's acceptable. (Most parodies get the syllable count wrong -- if a lyric goes dum-de-dum-de-dum, the parody ends up like dum-dum-de-dum-de-dum or dum-de-dum-de.) Have a +1 from me and the missus. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

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

2011-07-13 Thread Steven D'Aprano
n makes it >> abundantly clear to the human reader that a block follows, > > The block that follows makes it abundantly clear to the human reader > that a block follows. But it's too late by then. You have to mentally backtrack. blah blah blah blah indented block blah blah bl

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

2011-07-13 Thread Steven D'Aprano
thing as simple as "don't use global state, instead pass arguments to functions as needed" is a Good Trick learned from functional programming. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

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

2011-07-14 Thread Steven D'Aprano
Inside wrote: > As telling in the subject,because "list" and "tuple" aren't functions,they > are types.Is that right? Yes they are types. But they can still be used as functions. Does it matter? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

None versus MISSING sentinel -- request for design feedback

2011-07-14 Thread Steven D'Aprano
n mean(axis, dtype, out) TypeError: unsupported operand type(s) for +: 'int' and 'NoneType' I would appreciate any comments, advice or suggestions. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

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

2011-07-15 Thread Steven D'Aprano
Cameron Simpson wrote: > On 15Jul2011 15:28, Steven D'Aprano > wrote: > | In favour of None: it's already there, no extra code required. People > | may expect it to work. > > Broadly, I like this one for the reasons you cite. > > | Against None: it's to

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

2011-07-15 Thread Steven D'Aprano
Rob Williscroft wrote: > Steven D'Aprano wrote in news:4e1fd009$0$29986$c3e8da3 > [email protected] in gmane.comp.python.general: > >> I'm designing an API for some lightweight calculator-like statistics >> functions, such as mean, standard deviati

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