Re: How can a function find the function that called it?

2010-12-24 Thread Mark Wooding
kj writes: > But OrderedDict's functionality *requires* that its __init__ be > run, and this __init__, in turn, does part of its initialization > by calling the update method. > > Therefore, the update method of the new subclass needs to be able > to identify the calling function in order to make

Re: Regular expression for "key = value" pairs

2010-12-22 Thread Mark Wooding
André writes: > How about the following: > > >>> s = 'a=b,c=d' > >>> t = [] > >>> for u in s.split(','): > ... t.extend(u.split('=')) s = 'a = b = c, d = e' => ['a ', ' b ', ' c', ' d ', ' e'] Ugh. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression for "key = value" pairs

2010-12-22 Thread Mark Wooding
Ciccio writes: > suppose I have: > > s='a=b, c=d' > > and I want to extract sub-strings a,b,c and d from s (and in general > from any longer list of such comma separated pairs). [...] > In [12]: re.findall(r'(.+)=(.+)', s) > Out[12]: [('a=b, c', 'd')] I think there are two logically separate job

Re: If/then style question

2010-12-17 Thread Mark Wooding
Steve Holden writes: > I think the choice of keyword is probably not Guido's crowning > language achievement, I remember the behaviour by considering a typical application: for thing in things: if shinyp(thing): break else: raise DullError, 'nothi

Re: PyArg_ParseTuple question

2010-12-14 Thread Mark Wooding
Mark Crispin writes: > In a C module, I want to pick up the arguments for a Python call like: > module.call("string1",["string2a", "string2b", "string2c"], "string3") > and stash these into: > char *arg1; > char *arg2[]; > char *arg3; > All arguments are required, and we can

Re: Comparisons of incompatible types

2010-12-10 Thread Mark Wooding
Steven D'Aprano writes: > On Thu, 09 Dec 2010 12:21:45 +0000, Mark Wooding wrote: > > > John Nagle writes: > > >> "sort" has failed because it assumes that a < b and b < c implies a < > >> c. But that's not a valid assumption here

Re: Comparisons of incompatible types

2010-12-09 Thread Mark Wooding
John Nagle writes: > >>> NaN = float("nan") > >>> arr = [1.0, 4.0, 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0, 1.0, 4.0, > 3.0, 2.0, 5.0, NaN, 6.0, 3.0, NaN, 0.0] > >>> sorted(arr) > [0.0, 0.0, 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 3.0, 3.0, 4.0, 5.0, nan, 5.0, 6.0, > nan, 4.0, nan, 6.0, nan] > > The sorted

Re: Comparison with False - something I don't understand

2010-12-08 Thread Mark Wooding
"OKB (not okblacke)" writes: > This is an interesting setup, but I'm not sure I see why you need > it. If you know that, in a particular context, you want toy(x, 0) to > result in 42 instead of ZeroDivisionError, ... and that's the point. You don't know whether you'll need it at the c

Re: Comparisons of incompatible types

2010-12-07 Thread Mark Wooding
Carl Banks writes: > I think that feeling the need to sort non-homogenous lists is > indictative of bad design. Here's a reason you might want to. You're given an object, and you want to compute a hash of it. (Maybe you want to see whether someone else's object is the same as yours, but don't

Re: Comparisons of incompatible types

2010-12-07 Thread Mark Wooding
John Nagle writes: [Stepanov] > makes the point that, for generic programs to work right, the basic > operations must have certain well-defined semantics. Then the same > algorithms will work right across a wide variety of objects. > > This is consistent with Python's "duck typing", but inconsis

Re: Exception handling in Python 3.x

2010-12-07 Thread Mark Wooding
John Nagle writes: >PEP 255, like too much Python literature, doesn't distinguish > clearly between the language definition and implementation detail. It > says "The mechanics of StopIteration are low-level details, much like > the mechanics of IndexError in Python 2.1". Applications should

Re: Comparison with False - something I don't understand

2010-12-06 Thread Mark Wooding
Carl Banks writes: > On Dec 6, 12:58 pm, m...@distorted.org.uk (Mark Wooding) wrote: > >         def toy(x, y): > >           r = restart('use-value') > >           with r: > >             if y == 0: > >               error(ZeroDivisionError()) > >

Re: Exception handling in Python 3.x

2010-12-06 Thread Mark Wooding
John Nagle writes: > Right. You're not entitled to assume that StopIteration is how a > generator exits. That's a CPyton thing; generators were a retrofit, > and that's how they were hacked in. Other implementations may do > generators differently. This is simply wrong. The StopIteration exc

Re: Comparisons of incompatible types

2010-12-06 Thread Mark Wooding
Terry Reedy writes: > And indeed, code like this that has not been updated does break in > 3.x. to some people's annoyance. We really really cannot please > everyone ;-). The problem is that there are too many useful properties that one might expect from comparison operators. For example, it's

Re: Resumable exceptions bad:

2010-12-06 Thread Mark Wooding
John Nagle writes: > Resumable exceptions were a popular idea in the early days of > programming. LISP, PL/I, and early COBOL had constructs which could > be considered resumable exceptions. They didn't work out well, > because the exception handler gets control in an ambiguous situation, > per

Re: Comparison with False - something I don't understand

2010-12-06 Thread Mark Wooding
Paul Rubin writes: > You know, I've heard the story from language designers several times > over, that they tried putting resumable exceptions into their languages > and it turned out to be a big mess, so they went to termination > exceptions that fixed the issue. That seems very surprising to m

Re: Assigning to __class__ attribute

2010-12-03 Thread Mark Wooding
kj writes: > >>> class Spam(object): pass > > Now I define an instance of Spam and an instance of Spam's superclass: > >>> x = Spam() > >>> y = Spam.__mro__[1]() # (btw, is there a less uncouth way to do this???) There's the `__bases__' attribute, which is simply a tuple of the class's direct su

Re: Comparison with False - something I don't understand

2010-12-03 Thread Mark Wooding
Steven D'Aprano writes: > On Thu, 02 Dec 2010 16:35:08 +0000, Mark Wooding wrote: > > There are better ways to handle errors than Python's exception system. > > I'm curious -- what ways would they be? The most obvious improvement is resumable exceptions.

Re: Comparison with False - something I don't understand

2010-12-02 Thread Mark Wooding
Harishankar writes: > There are some reasons why I hate exceptions but that is a different > topic. However, in short I can say that personally: > > 1. I hate try blocks which add complexity to the code when none is > needed. Try blocks make code much more unreadable in my view and I use it >

Re: Catching user switching and getting current active user from root on linux

2010-12-01 Thread Mark Wooding
Grant Edwards writes: > On 2010-11-30, mpnordland wrote: > > and catch user switching eg user1 locks screen, leaves computer, > > user2 comes, and logs on. basically, when there is any type of user > > switch my script needs to know. > > What do you do when there are multiple users logged in? I

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-28 Thread Mark Wooding
Steve Holden writes: > It isn't. Even inheritance itself isn't as useful as it at first > appears, and composition turns out in practice to be much more useful. > That goes double for multiple inheritance. Composition /with a convenient notation for delegation/ works fairly well. Indeed, this c

Re: inverse of a matrix with Fraction entries

2010-11-27 Thread Mark Wooding
casevh writes: > I coded a quick matrix inversion function and measured running times > using GMPY2 rational and floating point types. For the floating point > tests, I used a precision of 1000 bits. With floating point values, > the running time grew as n^3. With rational values, the running tim

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-27 Thread Mark Wooding
John Nagle writes: > On 11/26/2010 4:21 PM, Mark Wooding wrote: > > John Nagle writes: > >> @This catches the case where two classed both inherit from, say > >> "threading.thread", each expecting to have a private thread. > > > > Why on earth wou

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-26 Thread Mark Wooding
John Nagle writes: > I'd argue that a better implementation would require that when there's > a name clash, you have to specify the class containing the name. In > other words, if A is a subclass of B, then B.foo() overrides > A.foo(). But if C is a subclass of A and B, and there's an A.foo() an

Re: Needed: Real-world examples for Python's Cooperative Multiple Inheritance

2010-11-25 Thread Mark Wooding
John Nagle writes: >Multiple inheritance in Python is basically what fell out of > CPython's internals, not a design. It's one of those areas where > order of execution matters, and that wasn't well worked out. I'm not sure about the history, but this doesn't sound right to me. > Allowing

Re: inverse of a matrix with Fraction entries

2010-11-25 Thread Mark Wooding
Daniel Fetchinson writes: > > I wouldn't do it that way. Let M be your matrix. Work out the LCM l of > > the denominators, and multiply the matrix by that to make it an integer > > matrix N = l M. Then work out the determinant d of that integer matrix. > > Next, the big step: use Gaussian elim

Re: inverse of a matrix with Fraction entries

2010-11-24 Thread Mark Wooding
Daniel Fetchinson writes: > So after all I might just code the inversion via Gauss elimination > myself in a way that can deal with fractions, shouldn't be that hard. I wouldn't do it that way. Let M be your matrix. Work out the LCM l of the denominators, and multiply the matrix by that to mak

Re: Program, Application, and Software

2010-11-18 Thread Mark Wooding
Steven D'Aprano writes: > On Thu, 18 Nov 2010 14:21:47 +, Martin Gregorie wrote: > > > I use 'script' to refer to programs written in languages that don't have > > a separate compile phase which must be run before the program can be > > executed. IOW Python and Perl programs are scripts aloin

Re: Some syntactic sugar proposals

2010-11-18 Thread Mark Wooding
Steven D'Aprano writes: > >> Not everything needs to be a one liner. If you need this, do it the > >> old- fashioned way: > >> > >> t = foo() > >> if not pred(t): t = default_value > > > > I already explained how to write it as a one-liner: > > > > t = (lambda y: y if pred(y) else defau

Re: Is Unladen Swallow dead?

2010-11-18 Thread Mark Wooding
John Nagle writes: > Python is defined by what a naive interpreter with late binding > and dynamic name lookups, like CPython, can easily implement. Simply > emulating the semantics of CPython with generated code doesn't help > all that much. Indeed. > Because you can "monkey patch"

Re: Some syntactic sugar proposals

2010-11-18 Thread Mark Wooding
Steven D'Aprano writes: > On Wed, 17 Nov 2010 16:31:40 +0000, Mark Wooding wrote: > > > But I don't think that's the big problem with this proposal. The real > > problem is that it completely changes the evaluation rule for the > > conditional expression.

Re: Program, Application, and Software

2010-11-17 Thread Mark Wooding
Alexander Kapps writes: > Application: Usually a large(er), complex program I'd say that an `application' is specifically a program intended for direct human use. Other things are servers, daemons and utilities. But I might just be weird. -- [mdw] -- http://mail.python.org/mailman/listinfo/p

Re: simple(?) Python C module question

2010-11-17 Thread Mark Wooding
Mark Crispin writes: > I have a Python module written in C that interfaces with an external C > library. Basically, the project is to make it possible to use that > library from Python scripts. If you know who I am, you can guess > which library. :) You have your very own Wikipedia page, so o

Re: Some syntactic sugar proposals

2010-11-17 Thread Mark Wooding
Christopher writes: > i don't like magic names. what about: > > t = foo() as v if pred(v) else default_value This is an improvement on `it'; anaphorics are useful in their place, but they don't seem to fit well with Python. But I don't think that's the big problem with this proposal. The real

Re: how to use socket to get packet which destination ip is not local?

2010-11-17 Thread Mark Wooding
Hans writes: > I tried socket bind to 0.0.0.0, but it only binds to any local ip, not > any ip which may not be local. therefore the socket cannot get that > dhcp offer packet even I can use wireshark to see that packet did come > to this pc. You must use a raw socket for this. Raw sockets are

Re: Some syntactic sugar proposals

2010-11-15 Thread Mark Wooding
Dmitry Groshev writes: > First of all: how many times do you write something like > t = foo() > t = t if pred(t) else default_value > ? Of course we can write it as > t = foo() if pred(foo()) else default_value > but here we have 2 foo() calls instead of one. Why can't we write just >

Re: strange behavor....

2010-11-15 Thread Mark Wooding
Arnaud Delobelle writes: > >>> exec "a=2" in d > assigning 2 to 'a' > >>> d['a'] > 2 > > >>> exec "global a; a = 3" in d > >>> d['a'] > 3 Oooh, now isn't that an interesting wrinkle? I've been careful (without drawing attention) to restrict my arguments to variables inside functions, largely be

Re: strange behavor....

2010-11-15 Thread Mark Wooding
Steven D'Aprano writes: > > def foo(): > > l = [] > > for i in xrange(10): > > (lambda j: l.append((lambda: i, lambda: j)))(i) > > print [(f(), g()) for f, g in l] > > Here's a slightly less condensed version that demonstrates the same > behaviou

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Steven D'Aprano writes: > On Sat, 13 Nov 2010 21:42:03 +0000, Mark Wooding wrote: > > > Dave Angel writes: > > > >> No, an (=) assignment is always an assignment. > > > > No. In `foo[0] = bar' it's a method call in disguise. > &g

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Dennis Lee Bieber writes: > def swapFunc(a, b): > return b, a That's not what a `swap' function should do. > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > "=" means just one thing, a r

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Steven D'Aprano writes: > On Sat, 13 Nov 2010 20:01:42 +0000, Mark Wooding wrote: > > Some object types are primitive, provided by the runtime system; > > there are no `internal' variables to be assigned in these cases. > > You seem to be making up your own term

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Arnaud Delobelle writes: > m...@distorted.org.uk (Mark Wooding) writes: > > > Assignment /never/ binds. There is syntactic confusion here too, > > since Python interprets a simple assignment in a function body -- in > > the absence of a declaration such as `globa

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Dave Angel writes: > No, an (=) assignment is always an assignment. No. In `foo[0] = bar' it's a method call in disguise. > It changes the item on the left hand side to refer to a new object. Not necessarily. It could do anything at all depending on the type of the recipient object. -- [m

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Terry Reedy writes: > On 11/13/2010 11:29 AM, Mark Wooding wrote: > > > Alas, Python is actually slightly confusing here, since the same > > notation `=' sometimes means assignment and sometimes means mutation. > > I disagree somewhat. An object is mutated by an inte

Re: strange behavor....

2010-11-13 Thread Mark Wooding
Tracubik writes: > >>> def change_integer(int_value): > ... int_value = 10 > ... > ... def change_list(list): > ... list[0] = 10 [...] > why the integer value doesn't change while the list value do? Because in the first case you changed a variable local to the function, and that v

Re: How to test if a module exists?

2010-11-11 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message , MRAB wrote: > > > ... the next one at 3 Nov 2010 22:40 "Re: Allowing comments after the line > > continuation backslash" and _all_ the subsequent ones arrived with an > > _unobfuscated_ email address. > > You mean from this one on >

Re: How to test if a module exists?

2010-11-11 Thread Mark Wooding
r0g writes: > Really? I get a metric butt-ton of spam every day to this address. I'm sure I get sent a lot of spam (though I don't know for sure -- see below). But I don't think much of it comes from Usenet harvesters any more. > Right now it simply filtered by address straight into my recycle

Re: How to test if a module exists?

2010-11-10 Thread Mark Wooding
Lawrence D'Oliveiro writes: > I see that you published my unobfuscated e-mail address on USENET for all to > see. I obfuscated it for a reason, to keep the spammers away. I'm assuming > this was a momentary lapse of judgement, for which I expect an apology. > Otherwise, it becomes grounds for an

Re: Allowing comments after the line continuation backslash

2010-11-10 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message <878w12kt5x.fsf@metalzone.distorted.org.uk>, Mark Wooding > wrote: > > 2. The MainWindow class only has the `Window' attribute described in > > its definition. Apparently there are other attributes as well (t

Re: subclassing str

2010-11-10 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message <87lj52kwln.fsf@metalzone.distorted.org.uk>, Mark Wooding > wrote: > > > One option is to implement a subclass which implements the additional > > protocol. > > This is why I think object orientation ruins

Re: Am I The Only One Who Keeps Reading ?Numpy? as ?Numpty??

2010-11-10 Thread Mark Wooding
Lou Pecora writes: > Bigger question: How do you pronouce it? Rhymes with `grumpy'. -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if a module exists?

2010-11-10 Thread Mark Wooding
r0g writes: > You use your main address on USENET rather than a junk one!? Obfuscated or > not that's either brave or foolhardy! I use my real email address. I also have an aggressive spam filter. But I don't think that much of my comes from Usenet harvesters any more, to be honest. -- [mdw] -

Re: Allowing comments after the line continuation backslash

2010-11-09 Thread Mark Wooding
Tim Chase writes: > On 11/09/10 18:05, Robert Kern wrote: > > For me, putting the brackets on their own lines (and using a > > trailing comma) has little to do with increasing readability. It's > > for making editing easier. > > It also makes diff's much easier to read (my big impetus for doing t

Re: Allowing comments after the line continuation backslash

2010-11-09 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message <87fwvdb69k.fsf@metalzone.distorted.org.uk>, Mark Wooding > wrote: > > for descr, attr, colours in [ > > ('normal', 'image','Normal'), > > ('highlighted

Re: populating a doubly-subscripted array

2010-11-09 Thread Mark Wooding
Gregory Ewing writes: > A reasonably elegant way to fix this is to use list comprehensions > for all except the innermost list: > >ff = [[0.0]*5 for i in xrange(5)] Yes, this is a good approach. I should have suggested something like this as a solution myself, rather than merely explaining

Re: subclassing str

2010-11-09 Thread Mark Wooding
rantingrick writes: > One thing i love about Python is the fact that it can please almost > all the "religious paradigm zealots" with it's multiple choice > approach to programming. However some of the features that OOP > fundamentalists hold dear in their heart are not always achievable in > a c

Re: Silly newbie question - Caret character (^)

2010-11-09 Thread Mark Wooding
Philip Semanchuk writes: > What's funny is that I went looking for a printed copy of the C > standard a few years back and the advice I got was that the cheapest > route was to find a used copy of Schildt's "Annotated ANSI C Standard" > and ignore the annotations. So it serves at least one useful

Re: functions, list, default parameters

2010-11-09 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message , Robert Kern > wrote: > > So examining LHS "selectors" is not sufficient for determining > > immutability. > > Yes it is. All your attempts at counterexamples showed is that it is not > necessary, not that it is not sufficient. You've got them the wron

Re: Compare source code

2010-11-09 Thread Mark Wooding
Arnaud Delobelle writes: > python-mode has python-beginning-of-block (C-c C-u) and > python-end-of-block. Yes. It was one of my explicit gripes that editing Python requires one to learn entirely new and unfamiliar keystrokes for doing fairly familiar editing tasks. -- [mdw] -- http://mail.pyt

Re: Pythonic/idiomatic?

2010-11-09 Thread Mark Wooding
Seebs writes: > ' '.join([x for x in target_cflags.split() if re.match('^-[DIiU]', x)]) > > This appears to do the same thing, but is it an idiomatic use of list > comprehensions, or should I be breaking it out into more bits? It looks OK to me. You say (elsewhere in the thread) that you'

Re: populating a doubly-subscripted array

2010-11-08 Thread Mark Wooding
g...@accutrol.com writes: > What am I missing? I am using Python 3.1.2. > > ff = [[0.0]*5]*5 > ff#(lists 5x5 array of 0.0) > for i in range(5): > for j in range(3): > ff[i][j] = i*10+j > print (i,j,ff[i][j]) # correctly prints ff array values > > ff

Re: Popen Question

2010-11-08 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message , Chris Torek wrote: > > > ['/bin/sh', '-c', 'echo', '$MYVAR'] > > > > (with arguments expressed as a Python list). /bin/sh takes the > > string after '-c' as a command, and the remaining argument(s) if > > any are assigned to positional parameters (

Re: Allowing comments after the line continuation backslash

2010-11-07 Thread Mark Wooding
Lawrence D'Oliveiro writes: > Not surprising, since the above list has become completely divorced from its > original purpose. Anybody remember what that was? It was supposed to be used > in a loop, as follows: > > for \ > Description, Attr, ColorList \ > in \ > ( >

Re: Silly newbie question - Carrot character (^)

2010-11-07 Thread Mark Wooding
Nobody writes: > You're taking "how" too literally, so let me rephrase that: > > A reference manual tells you what you need to know in order to use > the language. A specification tells you what you need to know in > order to implement it. I still don't see those as being different. A lan

Re: Compare source code

2010-11-07 Thread Mark Wooding
Lawrence D'Oliveiro writes: > I would never do that. “Conserving vertical space” seems a stupid reason for > doing it. Vertical space is a limiting factor on how much code one can see at a time. I use old-fashioned CRT monitors with 4x3 aspect ratios and dizzyingly high resolution; I usually w

Re: Silly newbie question - Carrot character (^)

2010-11-06 Thread Mark Wooding
Steven D'Aprano writes: > If you want to argue that the Python reference manual is aimed at the > wrong level of sophistication, specifically that the BNF syntax stuff > should be ripped out into another document, then I might agree with > you. But to argue that it's entirely the wrong "kind" of

Re: How to test if a module exists?

2010-11-06 Thread Mark Wooding
Chris Rebert writes: > Since when does Python have translated error messages? It doesn't yet. How much are you willing to bet that it never will? ;-) -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list

Re: How to test if a module exists?

2010-11-06 Thread Mark Wooding
Chris Rebert writes: > if err.message != "No module named extension_magic_module": Ugh! Surely this can break if you use Python with different locale settings! -- [mdw] -- http://mail.python.org/mailman/listinfo/python-list

Re: functions, list, default parameters

2010-11-06 Thread Mark Wooding
Dennis Lee Bieber writes: > On Sat, 06 Nov 2010 12:37:42 +, m...@distorted.org.uk (Mark Wooding) > declaimed the following in gmane.comp.python.general: > > > > > Two reasons. Firstly, this comes from my Lisp background: making a > > list is the obvious way

Re: functions, list, default parameters

2010-11-06 Thread Mark Wooding
Steven D'Aprano writes: > On Fri, 05 Nov 2010 12:17:00 +0000, Mark Wooding wrote: > > Right; so a half-decent compiler can notice this and optimize > > appropriately. Result: negligible difference. > > Perhaps the biggest cost is that now your language has incon

Re: Compare source code

2010-11-06 Thread Mark Wooding
Rustom Mody writes: > As for tools' brokeness regarding spaces/tabs/indentation heres a > thread on the emacs list wherein emacs dev Stefan Monnier admits to > the fact that emacs' handling in this regard is not perfect. > > http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/1bd0c

Re: functions, list, default parameters

2010-11-05 Thread Mark Wooding
Steven D'Aprano writes: > defaults initialise on function definition (DID) > defaults initialise on function call (DIC) > > I claim that when designing a general purpose language, DID (Python's > existing behaviour) is better than DIC: > > #1 Most default values are things like True, False, None

Re: Man pages and info pages

2010-11-04 Thread Mark Wooding
Tim Harig writes: > Right, and in info with the default key bindings, backspace takes me > to the command help. I would have expected it to either scroll up the > page or take me to the previously visited node. Sounds like your terminal is misconfigured. Backspace should produce ^?, not ^H. (

Re: functions, list, default parameters

2010-11-04 Thread Mark Wooding
Lawrence D'Oliveiro writes: > Mediocre programmers with a hankering towards cleverness latch onto it > as an ingenious way of maintaing persistent context in-between calls > to a function, completely overlooking the fact that Python offers much > more straightforward, comprehensible, flexible, an

Re: functions, list, default parameters

2010-11-04 Thread Mark Wooding
Lawrence D'Oliveiro writes: > In message <20101021235138.609fe...@geekmail.invalid>, Andreas > Waldenburger wrote: > > While not very commonly needed, why should a shared default argument be > > forbidden? > > Because it’s safer to disallow it than to allow it. Scissors with rounded ends are saf

Re: Compare source code

2010-11-04 Thread Mark Wooding
Tim Harig writes: > I use simple comments that are not effected by white space. I don't > waste my time trying to make comments look artistic. They are there > to convey information; not to look pretty. I really detest having to > edit other peoples comment formatting where you have to re-alig

Re: Ways of accessing this mailing list?

2010-11-04 Thread Mark Wooding
John Bond writes: > Hope this isn't too O/T - I was just wondering how people read/send to > this mailing list, eg. normal email client, gmane, some other software > or online service? > > My normal inbox is getting unmanageable, and I think I need to find a > new way of following this and other

Re: Man pages and info pages

2010-11-04 Thread Mark Wooding
Tim Harig writes: > When the GNU folk decided to clone *nix they decided that they knew > better and simply decided to create their own interfaces. This isn't the case. Actually Info has a long history prior to GNU: it was the way that the documentation was presented at the MIT AI lab. In fact

Re: Compare source code

2010-11-04 Thread Mark Wooding
Tim Harig writes: > So, your telling me that mixing tabs and spaces is considered a good > practice in Haskell? It doesn't seem to be a matter which is discussed much. I think Haskell programmers are used to worrying their brains with far more complicated things like wobbly[1] types. > I would

Re: Allow multiline conditions and the like

2010-11-04 Thread Mark Wooding
Chris Rebert writes: > Or, if possible, refactor the conditional into a function (call) so > it's no longer multiline in the first place. No! This /increases/ cognitive load for readers, because they have to deal with the indirection through the name. If you actually use the function multiple

Re: Compare source code

2010-11-04 Thread Mark Wooding
Tim Harig writes: > Python is the only language that I know that *needs* to specify tabs > versus spaces since it is the only language I know of which uses > whitespace formating as part of its syntax and structure. You need to get out more. Miranda, Gofer, Haskell, F#, make(1), and many others

Re: Compare source code

2010-11-04 Thread Mark Wooding
Seebs writes: > Python's the only language I use where an obvious flaw, which is > repeatedly observed by everyone I know who uses the language, is > militantly and stridently defended by dismissing, insulting, and > attacking the character and motives of anyone who suggests that it > might be a

Re: [OFF] sed equivalent of something easy in python

2010-10-30 Thread Mark Wooding
Jussi Piitulainen writes: > Daniel Fetchinson writes: > > > The pattern is that the first line is deleted, then 2 lines are > > kept, 3 lines are deleted, 2 lines are kept, 3 lines are deleted, > > etc, etc. > > So, is there some simple expression in Python for this? (item for i, item in enumera

Re: "Strong typing vs. strong testing" [OT]

2010-10-23 Thread Mark Wooding
Steven D'Aprano writes: > Well, what is the definition of pi? Is it: > > the ratio of the circumference of a circle to twice its radius; > the ratio of the area of a circle to the square of its radius; > 4*arctan(1); > the complex logarithm of -1 divided by the negative of the complex square > r

Re: python list handling and Lisp list handling

2009-04-25 Thread Mark Wooding
Mark Tarver writes: > But are Python lists also indistinguishable from conventional > Lisplists for list processing. > > For example, can I modify a Python list non-destructively? No. > Are they equivalent to Lisp lists. Can CAR and CDR in Lisp be thought > of as > > def car (x): > return

Re: Lisp mentality vs. Python mentality

2009-04-25 Thread Mark Wooding
Carl Banks writes: > Graham, for his part, doesn't seem to appreciate that what he does is > beyond hope for average people, and that sometimes reality requires > average people to write programs. I think he understands that perfectly well. But I think he believes that the sorts of tools which

Re: Definition of Pythonic?

2009-04-11 Thread Mark Wooding
John Yeung writes: > A couple of others have already mentioned the Zen of Python, available > at the Python command prompt. I would agree with that, but also add > the caveat that none of the principles expressed there are hard-and- > fast rules. Indeed, I'd suggest that the very lack of hard-a

Re: siple for in expression

2009-03-03 Thread Mark Wooding
"Matko" writes: > Can someone help me to understand the following code: > > uv_face_mapping = [[0,0,0,0] for f in faces] It constructs a fresh list, with the same number of elements as are in the iterable object referred to by `faces', and where each element is a distinct list of four zero-value

Re: why cannot assign to function call

2009-02-28 Thread Mark Wooding
Ethan Furman writes: > Mark Wooding wrote: >> Here's what I think is the defining property of pass-by-value [...]: >> >> The callee's parameters are /new variables/, initialized /as if by >> assignment/ from the values of caller's argument expressio

Re: Using while loop and if statement to tell if a binary has an odd or even number of 1's.

2009-02-06 Thread Mark Wooding
Duncan Booth writes: > Mark Dickinson wrote: [snip] >> while n: >> count += 1 >> n &= n-1 >> return count >> >> is_even = count_set_bits(the_int) % 2 == 0 >> >> ...but anyone submitting this as a homework >> solution had better be prepared to explain why >> it works. >>

Re: structs

2009-02-04 Thread Mark Wooding
Keith Thompson writes: > "Gary Herron" writes: >> Python *is* object-oriented > > I disagree. Care to provide proof of that statement? AWOOGA! The article I'm following up to (together with at least one other) is a forgery, and the Followup-To header is set to comp.lang.c as part of an effort

Re: Where & how to deallocate resources in Python C extension

2009-02-04 Thread Mark Wooding
fredbasset1...@gmail.com writes: > I've written a C extension, see code below, to provide a Python > interface to a hardware watchdog timer. As part of the initialization > it makes some calls to mmap, I am wondering should I be making > balanced calls to munmap in some kind of de-init function?

Re: is python Object oriented??

2009-02-04 Thread Mark Wooding
Steven D'Aprano writes: > Now, that's a toy example. Languages like Ada make correctness proofs, > well, perhaps not easy, but merely difficult compared to impossible for > languages like Python. Say `generally impractical' rather than `impossible' and I'll agree with you. But I'm not actuall

Re: is python Object oriented??

2009-02-04 Thread Mark Wooding
"Russ P." writes: > Imagine you own a company, and you decide to lease an office building. > Would you expect the office doors to have locks on them? Oh, you > would? Why? You mean you don't "trust" your co-workers? What are locks > but enforced access restriction? Huh? The lock on the door isn

Re: Date Comparison

2009-02-03 Thread Mark Wooding
mohana2...@gmail.com writes: > I need to compare two dates and find the number of days between those > two dates.This can be done with datetime module in python as below, > but this is not supported in Jython. > > example > from datetime import date > a=datetime.date(2009,2,1) > b=datetime.date(2

Re: is python Object oriented??

2009-02-02 Thread Mark Wooding
"Russ P." writes: > I am not sure why people keep "mentioning" that "Python is not Java." > As a slogan, it is rather misleading. Python is not C++, Ada, or Scala > either. All of those languages have enforced access restriction. Why > only mention Java? Because Java is a well-known member of a

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Wooding
John Machin writes: > 3 can be represented in 2 bits and at the same time -3 can be > represented in 2 bits?? But 2 bits can support only 2 ** 2 == 4 > different possibilities, and -3 .. 3 is 7 different integers. Yeah, I made some arbitrary choices about what to do with non-positive inputs. If

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Wooding
Jon Clements writes: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. def nbits(x): ## Special cases. if x == 0: return 0

Re: How to get atexit hooks to run in the presence of execv?

2009-01-29 Thread Mark Wooding
ro...@panix.com (R. Bernstein) writes: > Recently, I added remote debugging via TCP sockets. (Well, also FIFO's > as well but closing sockets before restarting is what's of concern.) > > I noticed that execv in Python 2.5.2 doesn't arrange exit hooks to get > called. Should it? I'd consider that

Re: Does Python really follow its philosophy of "Readability counts"?

2009-01-27 Thread Mark Wooding
"Russ P." writes: > If Python had a "private" keyword (or equivalent), for example, the > user would only need to delete it wherever necessary to gain the > desired access. And you obviously weren't listening when we said that having to make source code changes to upstream modules was a serious

  1   2   3   >