Re: allow line break at operators

2011-08-10 Thread Steven D'Aprano
at least prevents that, > since most unary operators bind to the operand on the right; Not so: >>> x = (42 + - ... 100) >>> >>> x -58 -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-10 Thread Steven D'Aprano
e1, value2, value3)) Agreed. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-10 Thread Steven D'Aprano
Ian Kelly wrote: > On Wed, Aug 10, 2011 at 8:37 AM, Steven D'Aprano > wrote: >>> Without the parentheses, this is legal but (probably) useless; it >>> applies the unary + operator to the return value of those functions. >>> Putting the + at the end of th

Re: Docstrings and class Attributes

2011-08-10 Thread Steven D'Aprano
eresting, there is at least one species of bat where the males are known to routinely lactate and feed baby bats. http://en.wikipedia.org/wiki/Male_lactation So just because a feature is an accident of history, doesn't mean that a use can't be found for it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-10 Thread Steven D'Aprano
cutable pseudo-code will converge on a similar look, because executable pseudo-code tends to be based on natural language (usually English) and mathematics syntax. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Bizarre behavior of the 'find' method of strings

2011-08-10 Thread Steven D'Aprano
er is not included. The reason for that is that experience with other languages shows that it leads to fewer "off-by-one" errors. See also: http://mail.python.org/pipermail/tutor/2010-December/080592.html http://en.wikipedia.org/wiki/Off-by-one_error -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-10 Thread Steven D'Aprano
Python scripts and programs, and require extra, unnecessary line-noise on every single line of Python code, just so that you can occasionally avoid a writing a pair of parentheses? This will never happen. Forget it. Python is more likely to get static types than compulsory semi-colons. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-11 Thread Steven D'Aprano
rom emails, would you fix the bug, or would you insist that braces were a failed experiment and that C should stop using { } and start using BEGIN END like Pascal? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-11 Thread Steven D'Aprano
Steven D'Aprano wrote: > indentation as flow control Gah! Of course, I meant indentation for blocks... after making the earlier point that indentation is *not* used for flow control, this was a particularly egregious error. How embarrassment. -- Steven -- http://mail.python.org

Re: allow line break at operators

2011-08-11 Thread Steven D'Aprano
ers considered to be a benefit?) Hell yes! -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Processing a large string

2011-08-11 Thread Steven D'Aprano
, it will be better to do this: # untested def split(source): start = 0 i = source.find("3") while i >= 0: yield source[start:i] start = i+1 i = source.find("3", start) That should give you the pieces of the string one at a time, as efficiently as possible. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python-ideas] allow line break at operators

2011-08-11 Thread Steven D'Aprano
great. A final : is not needed for arbitrary expressions. flag = (a and b or c) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-12 Thread Steven D'Aprano
Ben Finney wrote: > Likewise, “end of line as end of statement” has caused me and many > others problems. I don't understand this. Can you give an example? Do you mean, "Sometimes I want more code in a single statement than will comfortably fit in a single line"?

Re: generate and send mail with python: tutorial

2011-08-12 Thread Steven D'Aprano
aspineux wrote: > Hi I have written a tutorial about how to generate and send emails > with python. [...] Thank you, that is an extremely detailed tutorial. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-12 Thread Steven D'Aprano
Responding to Rick's standard obnoxious posts is like wrestling with a pig -- you get tired and filthy, you never accomplish anything useful, and after a while, you realise that the pig is enjoying it. Save yourself a lot of aggravation and kill-file him now. -- Steven -- http://mail.

Re: allow line break at operators

2011-08-12 Thread Steven D'Aprano
the programmer. But the human brain is a funny thing: you can train it to expect to do more work than is necessary, and it will complain when you make its job easier. [1] For some definition of intuition. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-14 Thread Steven D'Aprano
y're right, I don't think it's a *big* problem. Either way, given the restriction that blocks are statements, not expressions, the lack of an overt block markers is not a problem for code (with the proviso that a rogue editor doesn't go making arbitrary changes to your source code). -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-14 Thread Steven D'Aprano
ve never mis-indented a block of code, surely I must have. But if I did, it was so trivial to fix, and done so rarely, I've forgotten all about it. Consequently I don't want to pay the cost of that insurance, as little as it is, because I don't get the benefit of it -- for me, it's just redundant information that I have to type and read that provides no real benefit. And that's why I love Python, because it doesn't make my pay for insurance I don't need. [1] For some definition of "careless". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-14 Thread Steven D'Aprano
Chris Angelico wrote: > On Sun, Aug 14, 2011 at 3:26 PM, Steven D'Aprano > wrote: >> Yes, print as a statement was a mistake. But assignment as a statement, >> not so much. Assignment as an expression in languages that have it tends >> to be associated with frequen

Re: same code to login,one is ok,another is not

2011-08-14 Thread Steven D'Aprano
.replace(/^\.\//gi,"<a rel="nofollow" href="http://passport.baidu.com/"">http://passport.baidu.com/"</a>;); > location.href=url; > > > > > > -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Ten rules to becoming a Python community member.

2011-08-14 Thread Steven D'Aprano
Chris Angelico wrote: > I think you need to start a blog, Rick. > > You'd be easier to ignore. And yet, here you are, engaging him in conversation and feeding him the attention he craves :( -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-14 Thread Steven D'Aprano
Seebs wrote: > On 2011-08-14, Steven D'Aprano > wrote: >> The way I see it, if something operates by side-effect, then it has no >> business being treated as an expression. Which I later withdrew. > Interesting! I tend to really like the ability to chain methods, &g

Re: allow line break at operators

2011-08-15 Thread Steven D'Aprano
about fluent interfaces if they were written more like Unix shell script pipelines instead of using attribute access notation: foo.array_of_things | sort | map block | join ", " -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: allow line break at operators

2011-08-15 Thread Steven D'Aprano
lets out of the attic: they are nonassociative." (And don't even ask about the sedenions...) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-15 Thread Steven D'Aprano
a style issue, nothing else. There's nothing worse about: def spam(list): pass compared to class thingy: pass def spam(thingy): pass Why should built-ins be treated as more sacred than your own objects? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Ten rules to becoming a Python community member.

2011-08-15 Thread Steven D'Aprano
off with a warning.) "Used to" is unexceptional English: http://www.englishpage.com/verbpage/usedto.html http://www.bbc.co.uk/worldservice/learningenglish/youmeus/quiznet/newquiz114.shtml http://www.englishclub.com/grammar/verbs-m_used-to-do.htm http://www.learnenglish.de/grammar/usedtotex

Re: testing if a list contains a sublist

2011-08-15 Thread Steven D'Aprano
st[p+i] != x: start = p+1 break else: # for loop exits without break return True -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-15 Thread Steven D'Aprano
On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: > > On Aug 15, 2011, at 9:32 PM, Steven D'Aprano wrote: > >> On Tue, 16 Aug 2011 08:15 am Chris Angelico wrote: >> >>> If you want a future directive that deals with it, I'd do it th

Re: testing if a list contains a sublist

2011-08-16 Thread Steven D'Aprano
On Tue, 16 Aug 2011 12:12 pm Steven D'Aprano wrote: > On Tue, 16 Aug 2011 09:26 am Johannes wrote: > >> hi list, >> what is the best way to check if a given list (lets call it l1) is >> totally contained in a second list (l2)? > > This is not the most efficien

Re: testing if a list contains a sublist

2011-08-16 Thread Steven D'Aprano
's a standard term, like substring: "12" is a substring of "01234". "21" and "13" are not. [1, 2] is a sublist of [0, 1, 2, 3, 4]. [2, 1] and [1, 3] are not. Since lists are ordered, so are sublists. If the OP does want a solution that ignores order, then he needs to describe his problem better. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Steven D'Aprano
Seebs wrote: > On 2011-08-16, Steven D'Aprano > wrote: >> On Tue, 16 Aug 2011 01:23 pm Philip Semanchuk wrote: >>>> Why should built-ins be treated as more sacred than your own objects? > >>> Because built-ins are described in the official documentation

Re: Ten rules to becoming a Python community member.

2011-08-16 Thread Steven D'Aprano
flogged for an hour by my boss. I get all tingly in my man-bits, if you know what I mean." The first case is more subtle. The implication of "I used to wear..." is that you did back in the past, but no longer do, while "I wore..." has no such implication. It merely says that in the past you did this, whether you still do or don't is irrelevant. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-16 Thread Steven D'Aprano
rbage collector. I have no objection to lint tools. But separation of concerns should apply: the Python compiler should just compile what I tell it to, the linter should warn me if I'm running with scissors. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-17 Thread Steven D'Aprano
ey go > walking back up the scope chain checking. And that's a pretty big cost > to attach to stuff that is, by design, basic and universally available. Sure. But they can't have that certainty regardless of whether you shadow something, because how do they know whether you've shadowed it or not? In theory, anything could be anything at any time, and you have no protection. In practice, I worry more about being eaten by genetically-engineered flying piranhas than about rogue monkey-patching code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Wait for a keypress before continuing?

2011-08-17 Thread Steven D'Aprano
ng people who are trying to solve your problems. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Wait for a keypress before continuing?

2011-08-17 Thread Steven D'Aprano
cated. os.system will not be going away any time in the foreseeable future. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Wait for a keypress before continuing?

2011-08-17 Thread Steven D'Aprano
avyweight for a simple CLI script. I note also that even the Python interactive interpreter under Linux has an extremely limited detect-single-keypress capability: Ctrl-C generates a KeyboardInterrupt without needing to hit Enter, and Ctrl-D exits the interpreter. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why no warnings when re-assigning builtin names?

2011-08-17 Thread Steven D'Aprano
Seebs wrote: > On 2011-08-17, Steven D'Aprano > wrote: >> Fortunately, while we are proud of having that ability, actually *using* >> it is considered a mortal sin. We're not Ruby developers -- if you >> actually monkey-patch something, especially built-

Re: How to convert a list of strings into a list of variables

2011-08-18 Thread Steven D'Aprano
out of a billion to cause grief.) Code injection attacks are the first and second most common form of security vulnerability, ahead of even buffer overflows. Please don't add to the list. http://cwe.mitre.org/top25/?2011 (Oh, and if you think that protecting against code injection attacks whil

Re: List spam

2011-08-18 Thread Steven D'Aprano
h them. Now, an ISP might not have the bandwidth to supply all the needs of their customers, that's a separate issue. But complaining that the problem is specifically because they use bittorrent, as if it would disappear if they changed to HTTP, is bogus. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: List spam

2011-08-18 Thread Steven D'Aprano
ny. It is ironic that some people say that the solution to the spam problem is to move to Google Groups, because most of the spam comes *from* Google Groups. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: try... except with unknown error types

2011-08-19 Thread Steven D'Aprano
base class Exception: Except that is nearly always poor advice, because it catches too much: it hides bugs in code, as well as things which should be caught. You should always catch the absolute minimum you need to catch. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Replacement for the shelve module?

2011-08-19 Thread Steven D'Aprano
t make sense, etc.). I would like to see this replicated. If it is true, that's a bug in shelve, but I expect you're probably doing something wrong. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Stop quoting spam [was Re: Hot Girls ...]

2011-08-19 Thread Steven D'Aprano
hat when the posting is archived on a couple of dozen websites, this will boost the spammer's Google rankings. Thanks heaps! Your "joke" was so worth it. Not. [spam deleted] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: try... except with unknown error types

2011-08-19 Thread Steven D'Aprano
John Gordon wrote: > In <[email protected]> Steven D'Aprano > writes: > >> > You can catch all exceptions by catching the base class Exception: > >> Except that is nearly always poor advice, because it catches too much

Re: Replacement for the shelve module?

2011-08-19 Thread Steven D'Aprano
Robert Kern wrote: > On 8/19/11 3:36 PM, Steven D'Aprano wrote: > >> By the way, you know that you should never, ever use floats for currency, >> right? > > That's just incorrect. You shouldn't use (binary) floats for many > *accounting* purposes, b

Re: testing if a list contains a sublist

2011-08-19 Thread Steven D'Aprano
ctivestate.com/recipes/577850-search-sequences-for-sub-sequence/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Compare tuples of different lenght

2011-08-20 Thread Steven D'Aprano
# Flag t2 to be removed. flags[j] = False saved_tuples = [] for t,flag in zip(list_of_tuples, flags): if flag: saved_tuples.append(t) This gives: >>> saved_tuples [(12, 13), (2, 3, 4), (5, 6), (7, 8, 9)] which matches what you wanted: > [(12,13),(2,3,4),(5,6),(7,8,9),] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: try... except with unknown error types

2011-08-20 Thread Steven D'Aprano
Paul Rubin wrote: > Steven D'Aprano writes: >>> You can catch all exceptions by catching the base class Exception: >> >> Except that is nearly always poor advice, because it catches too much: it >> hides bugs in code, as well as things which should be cau

Re: extended slicing and negative stop value problem

2011-08-20 Thread Steven D'Aprano
d of the second slice), or to write a helper function to adjust the indexes and get whatever behaviour you like. Hint: >>> a[10:-11:-1] [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: try... except with unknown error types

2011-08-21 Thread Steven D'Aprano
Paul Rubin wrote: > Steven D'Aprano writes: >>> But there's no way to know what that minimum is. Python libraries throw >>> all sorts of exceptions that their documentation doesn't mention. >> >> Yes, you're absolutely correct. But it's

Re: try... except with unknown error types

2011-08-21 Thread Steven D'Aprano
t;>> issubclass(socket.error, EnvironmentError) False (Fortunately that specific example is fixed in Python 3.) Besides, there's a world of difference between "should be" and "are". -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Steven D'Aprano
loop [steve@sylar python]$ python3.2 -m timeit -s 'n=0' 'n += 1' 100 loops, best of 3: 0.49 usec per loop I simply do not believe that we can justify making *any* claim about the relative speeds of n=n+1 and n+=1 other than "they are about the same". Any result you get, faster or slower, will depend more on chance than on any real or significant difference in the code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Steven D'Aprano
the following code and try to predict what it would do: a = 42 b = a b.inc() print(a) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: try... except with unknown error types

2011-08-21 Thread Steven D'Aprano
On Mon, 22 Aug 2011 10:41 am Chris Angelico wrote: > On Mon, Aug 22, 2011 at 1:30 AM, Steven D'Aprano > wrote: >> /s/would/should/ >> >> I don't see why you expect this, when *existing* network-related failures >> aren't > > Ehh, granted.

Re: relative speed of incremention syntaxes (or "i=i+1" VS "i+=1")

2011-08-21 Thread Steven D'Aprano
affected and everything just will work fine. But you can't /know/ that at all, unless you know that the object isn't "underhanded" (however you define that!). And given some arbitrary object, how can you know that? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding modified methods from another class without subclassing

2011-08-21 Thread Steven D'Aprano
hood it may not be a good idea. I can almost hear the screams of > "No, don't do that!" The general technique is called delegation and is perfectly legitimate. http://c2.com/cgi/wiki?WhatIsDelegation http://en.wikipedia.org/wiki/Delegation_(programming) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Steven D'Aprano
nistic order? Have you considered sorting the addresses yourself? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: questions (& answers) about object, type, builtin types, class, metaclass and __getattribute__

2011-08-22 Thread Steven D'Aprano
, *args, **kwargs) if isinstance(instance, self): instance.__init__(*args, **kwargs) return instance def __new__(cls, *args): # magic to actually create a new type object Note that this may not be how ``type`` actually does it. See the source code, and I hope you have better luck reading it than I did! http://hg.python.org/cpython/file/c8e73a89150e/Objects/typeobject.c -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Order of addresses returned by socket.gethostbyname_ex()

2011-08-22 Thread Steven D'Aprano
connection. If I tell you that my server has the following 6 connections: Wifi1, LAN4, LAN1, LAN2, Wifi2, LAN5 which one is "best"? Once you have an algorithm for deciding which connection is "best" for everybody, then you can check whether gethostbyname_ex uses that a

Re: Adding modified methods from another class without subclassing

2011-08-22 Thread Steven D'Aprano
appen. Which is what the call to super will accomplish, but if the behaviour ever changes (including the error message given), you won't have to change your class. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding modified methods from another class without subclassing

2011-08-23 Thread Steven D'Aprano
On Mon, 22 Aug 2011 11:08 pm John O'Hagan wrote: > On Mon, 22 Aug 2011 15:27:36 +1000 > Steven D'Aprano wrote: [...] >> # Untested >> class MySeq(object): >> methods_to_delegate = ('__getitem__', '__len__', ...) >> pitches = ...

Re: try... except with unknown error types

2011-08-23 Thread Steven D'Aprano
events/hotos03/tech/full_papers/candea/candea.pdf -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-23 Thread Steven D'Aprano
= prefix.lower() # Chunk #1 menu = self._cleaned_menu # Chunk #2 for i,s in enumerate(menu, 1): # Chunk #3 if s.lower().startswith(prefix): return i return None # Chunk #4 So that's three one-line chunks and one three-line chunk. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Methods on file-like objects can only used once on one object?

2011-08-23 Thread Steven D'Aprano
f = open('my_file.txt') lines = f.readlines() print lines print lines print lines print lines f.close() There's no need to read the lines again unless you expect that the file has changed. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: why i cannot invoke python script using command line?

2011-08-23 Thread Steven D'Aprano
and cd into f:\project\src\ before executing python a.py OR (2) learn how to use packages, and put a and b into a package; OR (3) Inside script a.py, add this to the start of the file: import os import sys import __main__ location = os.path.split(__main__.__file__)[0] location = os.path.joi

Re: Hiding token information from users

2011-08-23 Thread Steven D'Aprano
ould your users do with the plain token that they shouldn't? I don't see why, if it's not worth encrypting properly, why it's worth obfuscating it at all. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: truncating strings

2011-08-23 Thread Steven D'Aprano
ty in a function. It's not hard, and is elegant. Not everything needs to be a built-in. # Untested. def truncate(s, maxwidth=50): if len(s) <= maxwidth: return s s = s[:maxwidth - 3] return s + '...' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-23 Thread Steven D'Aprano
Terry Reedy wrote: > On 8/23/2011 11:22 AM, Steven D'Aprano wrote: > >> Even 7±2 is probably excessive: I find that I'm most comfortable with >> functions that perform 4±1 chunks of work. An example from one of my >> classes: >> >> def find(se

Re: Learning Python

2011-08-23 Thread Steven D'Aprano
On Wed, 24 Aug 2011 12:46 pm User wrote: > Hello all, > Does anyone have any good resources for learning Python? http://duckduckgo.com/?q=python+tutorial -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Weird interaction with nested functions inside a decorator-producing function and closuring of outer data...

2011-08-24 Thread Steven D'Aprano
r's problem, and you've solved one problem... teach a coder how to solve his own problems, and you've solved them all" *wink* I can't begin to count how many times I've started writing up a post to ask a question, and in the process of reducing the example code to the sm

[OT-ish] Design principles: no bool arguments

2011-08-25 Thread Steven D'Aprano
off(arg): _spam(arg, False) def _spam(arg, flag): do stuff if flag: a else: b more stuff [1] This is the Internet. There's *always* a certain amount of disagreement. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-26 Thread Steven D'Aprano
on is likely to be only a couple of hundred KB in size: >>> text = '\n'.join('print x+i' for i in range(1, 10001)) >>> code = compile(text, '', 'exec') >>> sys.getsizeof(code.co_code) # size in bytes 90028 So that&#x

Catch and name an exception in Python 2.5 +

2011-08-26 Thread Steven D'Aprano
2.7 accept either form. Is there any way to catch an exception and bind it to a name which will work across all Python versions from 2.5 onwards? I'm pretty sure there isn't, but I thought I'd ask just in case. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-26 Thread Steven D'Aprano
Chris Angelico wrote: > On Sat, Aug 27, 2011 at 4:16 AM, Steven D'Aprano > wrote: >> I can think of at least five reasons apart from re-use why it might be >> appropriate to pull out code into its own function or method even if it >> is used in one place only: &g

Re: Catch and name an exception in Python 2.5 +

2011-08-26 Thread Steven D'Aprano
Thomas Jollans wrote: > On 26/08/11 21:56, Steven D'Aprano wrote: >> Is there any way to catch an exception and bind it to a name which will >> work across all Python versions from 2.5 onwards? >> >> I'm pretty sure there isn't, but I thought I'd

Re: how to format long if conditions

2011-08-27 Thread Steven D'Aprano
ot;"" return (isinstance(left, PyCompare) and isinstance(right, PyCompare) and left.complist[-1] is right.complist[0]) # PEP 8 version left as an exercise. # later... if is_next(left, right): py_and = PyCompare(left.complist + right.complist[1:]

Re: how to format long if conditions

2011-08-27 Thread Steven D'Aprano
Hans Mulder wrote: [...] > It may look ugly, but it's very clear where the condition part ends > and the 'then' part begins. Immediately after the colon, surely? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: UnicodeEncodeError -- 'character maps to '

2011-08-27 Thread Steven D'Aprano
al not in range(128) The right way is to specify an encoding that includes all the characters you need. Unless you have some reason to choose another encoding, the best thing to do is to just use UTF-8. >>> s.encode('utf-8') 'BIEBER FEVER \xe2\x99\xa5' -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Record seperator

2011-08-27 Thread Steven D'Aprano
tra characters is the price you pay for making your language readable. At the cost of a few extra key presses, you get something that you will be able to understand in 10 years time. AWK is a specialist text processing language. Python is a general scripting and programming language. They have different values: AWK values short, concise code, Python is willing to pay a little more in source code. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is there any principle when writing python function

2011-08-27 Thread Steven D'Aprano
r of degree, or a matter of opinion, or both. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Custom dict to prevent keys from being overridden

2011-08-27 Thread Steven D'Aprano
StrictDict(dict): def __init__(self, items): for key, value in items: self[key] = value def __setitem__(self, key, value): if key in self: raise KeyError('key %r already exists' % key) super(StrictDict, self).__setitem__(key, value) should more or less do it. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python] Why I need the parameter when the call doesn't use it?

2011-08-28 Thread Steven D'Aprano
h as this one: http://code.activestate.com/recipes/577030-dualmethod-descriptor/ But as Ben hints at, this is getting into fairly advanced territory. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

A tale of yak shaving

2011-08-29 Thread Steven D'Aprano
ption when either making a copy of a list or iterating over that copy? Was the list corrupted? Was it not actually a list but some list-like object that was somehow returning non-integers for its min and max indexes? [end quote] -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: killing a script

2011-08-29 Thread Steven D'Aprano
possible to just have some magic switch at the top of your script to make it work. You actually have to do the work yourself. (But of course you can do the work inside a function, and re-use it elsewhere.) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

PC locks up with list operations

2011-08-31 Thread Steven D'Aprano
incidents were with Python 2.5. Do newer versions of Python respond to this sort of situation more gracefully? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: PC locks up with list operations

2011-08-31 Thread Steven D'Aprano
Chris Withers wrote: > On 31/08/2011 13:33, Steven D'Aprano wrote: >> I am using Linux desktops; both incidents were with Python 2.5. Do newer >> versions of Python respond to this sort of situation more gracefully? > > Ironically, Windows does better here and dumps yo

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Steven D'Aprano
ments) can be used for class and static methods * bound and unbound methods semantics plus as a bonus, plenty of ongoing arguments about whether or not having to explicitly list "self" as a parameter is a good thing or not, thus keeping people busy arguing on mailing lists instead of coding -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Steven D'Aprano
ages are free to choose differently. Cobra, for example, is explicitly derived from Python in many ways, but it drops the "self" (as well as other changes). http://cobra-language.com/docs/python/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: fun with nested loops

2011-08-31 Thread Steven D'Aprano
want to redo, the right solution is to put the loop inside a function, and then "redo the loop" becomes "call the function again". I suppose that, just possibly, your application really would benefit from named labels to jump to. But if so, you've stumbled across something

Re: fun with nested loops

2011-08-31 Thread Steven D'Aprano
go and which I'd never > heard of until Google showed it to me just now: > http://entrian.com/goto/ You're a wicked, wicked man. :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Steven D'Aprano
ble by the fact that methods are just wrappers around functions with an explicitly declared "self". That dynamism is rarely used, but not *that* rarely, and is very useful when used. Implicit self would likely negate all that. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: idiomatic analogue of Perl's: while (<>) { ... }

2011-08-31 Thread Steven D'Aprano
eractive prompt. For what it's worth, the default buffersize for fileinput.input is 0, so if that doesn't do what you want, I don't think fileinput is the right solution. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: fun with nested loops

2011-09-01 Thread Steven D'Aprano
an't check whether it has labelled loops. http://cobra-language.com/ [1] Not really magic, and probably more like 4±2. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't threading.join() return a value?

2011-09-02 Thread Steven D'Aprano
he code launching the thread would have to block, waiting until the thread is completed, so it will have a result to return. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Why doesn't threading.join() return a value?

2011-09-02 Thread Steven D'Aprano
Seebs wrote: > On 2011-09-02, Steven D'Aprano > wrote: [...] >> Because then the code launching the thread would have to block, waiting >> until the thread is completed, so it will have a result to return. > > Isn't "waiting until the thread is completed

Re: Functions vs OOP

2011-09-03 Thread Steven D'Aprano
hod of that object? Yes. http://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html [...] > Am I missing something, or am I taking things too literally? No, it is the OO purists who are missing something. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions vs OOP

2011-09-04 Thread Steven D'Aprano
rogramming languages enforce those conventions as design features, rather than just leaving it up to the coder to apply them as a convention. Impure functional languages, such as Python, don't enforce all (or even any) of those conditions, although they may provide certain functional features. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Functions vs OOP

2011-09-04 Thread Steven D'Aprano
ional programming" If you would like to suggest improvements, please do so. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Hello, and request for help with 'dynamic grids'

2011-09-05 Thread Steven D'Aprano
On Mon, 5 Sep 2011 03:18 pm Simon Cropper wrote: > I am looking for the ability to create dynamic grids in a window but > can't for the life of me find how to do this. What GUI toolkit are you using? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

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