Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
I take it then that you believe that ints like 1 should be mutable like lists? Because that is what the suggested behaviour implies. Ah, what a grand thing that would be! We could say: 0 += 1 1 += 2 7 -= 1 and then have 0 + 1 == 7. Think of the obfuscated code we could write! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
lass >>> variable or the object variable but not both. So either it could raise >>> an attribute error or add two to the class variable. >> >> It does exactly what you say. It adds 2 to the a *instance variable* of >> the object instance in 'b'. > > There is no instance variable at that point. How can it add 2, to > something that doesn't exist at the moment. By the standard rules of inheritance. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
don't care that much on how it gets fixed. It isn't broken, there is nothing to fix. The code does precisely what the inheritance model promises to do. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
ints '\n\r' # Scenario 3 # Python code with standard inheritance: class Paragraph: ls = '\n' # line separator linux_para = Paragraph() windows_para = Paragraph() windows_para.ls = '\n\r' linux_para.ls => prints '\n' -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
s not a name: b.a is an attribute reference. You wouldn't call b["a"] a name, and you shouldn't call b.a a name either. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
8 Look at that: the object which is referred to depends on how many times you've already been through the loop. How nuts is that? I guess that brings us back to making ints mutable. I can't wait until I can write 1 - 0 = 99 and still be correct! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
Why would you want b.a = to correspond to b.__class__.a = ? I'm not saying that it couldn't, if that was the model for inheritance you decided to use. I'm asking why would you want it? What is your usage case that demonstrates that your preferred inheritance model is useful? -- St

Re: OT - Re: Microsoft Hatred FAQ

2005-11-03 Thread Steven D'Aprano
On Thu, 03 Nov 2005 13:29:26 +0100, Jerzy Karczmarczuk wrote: > Now, tell me: is the polluting of a newsgroup with off-topic postings, > a crime, Not in any nation that values personal freedom over petty laws controlling people's behaviour for no good purpose. -- Steven

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
ts (e.g. lists) are shared among > instances of a class and the class itself > - simple values are not shared No. it is all about the inheritance, and mutable/immutable objects. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: when and how do you use Self?

2005-11-03 Thread Steven D'Aprano
s? You don't recommend doing this? def MyClass: def __init__(self, x): self.x = x ??? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: reading internet data to generate random numbers.

2005-11-03 Thread Steven D'Aprano
l poster did ask how to read every nth byte of "the Internet stream", so I assumed he had something like that in mind. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: __slots__ and class attributes

2005-11-03 Thread Steven Bethard
Ewald R. de Wit wrote: > I'm running into a something unexpected for a new-style class > that has both a class attribute and __slots__ defined. If the > name of the class attribute also exists in __slots__, Python > throws an AttributeError. Is this by design (if so, why)? > > class A( object ):

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
On Thu, 03 Nov 2005 10:01:04 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Then you don't approve of inheritance? That's fine, it is your choice, but >> as far as I know, all OO languages include inheritance. > > Some OO langu

Re: when and how do you use Self?

2005-11-03 Thread Steven D'Aprano
On Thu, 03 Nov 2005 20:19:03 +0100, bruno at modulix wrote: > Steven D'Aprano wrote: >> On Thu, 03 Nov 2005 10:14:23 +0100, bruno at modulix wrote: >> >> >>>Tieche Bruce A MSgt USMTM/AFD wrote: >>> >>>>I am new to python, >>>&g

Re: reading internet data to generate random numbers.

2005-11-03 Thread Steven D'Aprano
On Thu, 03 Nov 2005 16:40:43 -0500, Peter Hansen wrote: > Steven D'Aprano wrote: >> On Thu, 03 Nov 2005 15:51:30 +, Grant Edwards wrote: >>> >>>I've never heard of anybody using the data as source of >>>entropy. >> >> Me neither,

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
one): self.size = size def print(self): if self.size is None: papersize = self.__class__.default_size else: papersize = self.size do_something(papersize) The standard inheritance model used by Python and all OO languages I kno

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
rd behaviour. Is your behaviour more useful? Does it make code easier to write? Does it result in more compact code? What usage cases? Or is it just a subjective judgement on your part that it would be neater? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 09:03:56 +, Antoon Pardon wrote: > Op 2005-11-03, Steven D'Aprano schreef <[EMAIL PROTECTED]>: >> On Thu, 03 Nov 2005 13:01:40 +, Antoon Pardon wrote: >> >>>> Seems perfectly sane to me. >>>> >>>> What

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 10:48:54 +, Antoon Pardon wrote: > Please explain why this is illegal. > > x = 1 > def f(): > x += 1 Because names in function namespaces don't have inheritance. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
w many times you already went through the loop", I'm supposed to magically read your mind and know that you don't actually object to what you say you object to, but to something completely different? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
efers to two different namespaces at the same time. > That is IMO madness. You may argue that the madness is of little > importance, you can argue that because of the current implementation > little can be done about it. But I don't see how one can defend > it as sane behaviour. Because inheritance is useful, sensible, rational behaviour for OO programming. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
ame.advance() py> print steve_game.level 3 py> print antoon_game.level What will it print? Hint: your scheme means that class attributes mask instance attributes. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 04:42:54 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> There are good usage cases for the current inheritance behaviour. > > Can you name one? Any code that relies on it seems extremely dangerous to me. Dangerous? In

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 18:20:56 -0500, Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> equal? Some things are a matter of objective fact: should CPython use a >> byte-code compiler and virtual machine, or a 1970s style interpreter that >> int

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 16:06:45 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> A basic usage case: >> >> class Paper: >> size = A4 >> def __init__(self, contents): >> # it makes no sense to have class conte

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Sat, 05 Nov 2005 00:25:34 +, Bengt Richter wrote: > On Fri, 04 Nov 2005 02:59:35 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >>On Thu, 03 Nov 2005 14:13:13 +, Antoon Pardon wrote: >> >>> Fine, we have the code: >>> >>>

Re: Getting Python Accepted in my Organisation

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 20:55:48 -0500, Chris F.A. Johnson wrote: So that people reading your reply know what you are commenting about. (Now, imagine that you're reading from a newsgroup where Chris' post has disappeared off the server, or perhaps never showed up at all.) -- Steven.

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 13:52:22 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Follow the logical implications of this proposed behaviour. >> >> class Game: >> current_level = 1 >> # by default, games start at level one

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
esult in more >> compact code? What usage cases? > > What my behaviour? I don't need to specify alternative behaviour in > order to judge specific behaviour. If you are serious about wanting the behaviour changed, and not just whining, then somebody has to come up with an alternative behaviour that is better. If not you, then who? Most of the folks who have commented on this thread seem to like the existing behaviour. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-04 Thread Steven D'Aprano
On Fri, 04 Nov 2005 20:41:31 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> It also allows you to do something like this: >> >> class ExpertGame(Game): >> current_level = 100 > >> and then use ExpertGame any

Re: Getting Python Accepted in my Organisation

2005-11-05 Thread Steven D'Aprano
On Sat, 05 Nov 2005 04:12:38 -0500, Chris F.A. Johnson wrote: > On 2005-11-05, Steven D'Aprano wrote: >> On Fri, 04 Nov 2005 20:55:48 -0500, Chris F.A. Johnson wrote: >> >> >> >> So that people reading your reply know what you are commenting about. >>

Re: Using Which Version of Linux

2005-11-05 Thread Steven D'Aprano
lly horrible German industrial industrial punk themed desktops, you could do a lot worse than play around with the Knoppix LiveCD. That would be the quickest way to get started: no installation necessary. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using Which Version of Linux

2005-11-05 Thread Steven D'Aprano
980... > It also has nice, beginner-friendly FAQs to help you > get started. Just so you understand what Jeffrey is talking about, by "beginner-friendly" he means the FAQs walk you through the process of compiling your own kernel. (Okay, okay, so that's a *tiny* bi

Re: Class Variable Access and Assignment

2005-11-05 Thread Steven D'Aprano
e are jumping through to modify the language so that b.a += 2 assigns b.a in the same scope as it was accessed, I'm still rather perplexed as to why you would want that behaviour. It seems to me like spending many hours building a wonderfully polished, ornate, exquisite device for build

Re: Class Variable Access and Assignment

2005-11-05 Thread Steven D'Aprano
On Fri, 04 Nov 2005 22:19:39 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> > Next you get some performance gain by using gmpy to handle the long int >> > arithmetic, >> >> Then whatever happens next will be my own stup

Re: Class Variable Access and Assignment

2005-11-05 Thread Steven D'Aprano
On Sat, 05 Nov 2005 16:27:00 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> But do you want x += y to work for immutable objects as well? Then >> __iadd__ cannot be a statement, because x can't be modified in place. > > It never

Re: Class Variable Access and Assignment

2005-11-05 Thread Steven D'Aprano
ot;) L.sort() # throws the sorted list away print L # prints the unsorted list The only way the Liskov substitution principle works is if everything works the same way, which means that all subclasses, all *possible* subclasses, must have no more functionality than the subclass that does the absolute

Re: Multiples of a number

2005-11-05 Thread Steven D'Aprano
x in range(2000): > if x % 100 == 0: > do_something() Another way is, if you aren't doing anything *except* counting for the other 99 values of x, just skip them completely: fox x in range(20): do_something(x*100) Ivan, what are you trying to do? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-06 Thread Steven D'Aprano
erent from the dual referencing that happens in Scenario 4. Okay, perhaps wart is not quite the right word... but it is certainly unexpected if you haven't come across it before, or thought *deeply* about what is going on. A gotcha perhaps. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Instead of obsessing over the library *reference*, why not use other documentation?

2005-11-06 Thread Steven D'Aprano
t; the same search today, you'll still find examples, but 5 of the top 10 > hits are references to Xah's problems with the library reference. A > few more rounds, and people will have to start adding -xah to their > Python searches to get quality results.) People are link

Re: Python doc problem example: gzip module (reprise)

2005-11-06 Thread Steven D'Aprano
On Sun, 06 Nov 2005 04:28:35 -0800, jmdeschamps wrote: > This actually brings us back to the jest of F. previous post, I didn't think it was very funny... Unless you meant the *gist* of Fredrik's post. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Alert: Help me store constants pythonically

2005-11-06 Thread Steven D'Aprano
ield.value locals().update({sectionname: obj}) If you are likely to be changing the constants (either names, field names, or values) an hour or three developing this code will save you a lot of heart-ache later. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using python for writing models: How to run models in restricted python mode?

2005-11-07 Thread Steven D'Aprano
ncerned about malicious users, or just incompetent users? I suspect your best bet might be to write a mini-language using Python, and get your users to use that. You will take a small performance hit, but security will be very much improved. What do others think? -- Steven. -- http://

Re: Newbie Alert: Help me store constants pythonically

2005-11-07 Thread Steven D'Aprano
;transversePlanes = [ > Plane(type=3, z=4), > Plane(type=5, z=6), > Plane(type=3, z=8) > ] > ) That's a little trickier, but not much. You effectively are just creating a struct where some attributes are themselves structs. > which I'm not sure the

Re: PYTHON LOOSING FOR JAVA???????

2005-11-07 Thread Steven D'Aprano
ers to create new innovative solutions, when they can just use Google to search teh Interweb for source code which Google has stolen from the rightful owners??? *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
y = 1 is the same as the two liner x = 1 y = x Both create two names, x and y, and sets them both to the same int 1. Because ints are immutable, if you rebind one name, the other one will NOT change: py> x += 1 py> print x, y 2, 1 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
> obj = lst[-3] py> obj 4 py> obj = obj + 1 # rebinds the name obj, doesn't change the underlying object the name points to py> print lst ['Now is the time', 4, 'all good men', {'foo': 42}] You will quickly learn what are mutable and what are immutable. Ints, floats, longs, strs and tuples are immutable. Lists and dicts are mutable. Custom classes could be either, in principle, but are generally mutable. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-08 Thread Steven D'Aprano
the objects in place, you are rebinding the name to another object: py> spam = "a tasty meat-like food" py> alias = spam # both names point to the same str object py> spam = "spam spam spam spam" # rebinds name to new str object py> print spam, alias 'spam spam spam spam' 'a tasty meat-like food' -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: __new__

2005-11-08 Thread Steven Bethard
James Stroud wrote: > Hello All, > > I'm running 2.3.4 > > I was reading the documentation for classes & types >http://www.python.org/2.2.3/descrintro.html > And stumbled on this paragraph: > > """ > __new__ must return an object. There's nothing that requires that it return a > new obj

Re: append to non-existing list

2005-11-09 Thread Steven D'Aprano
print "Now calling RList append" something.append("hello world") # call append on a non-existent object What should Python do? Should "something" be a RList, QList, PList or ordinary list? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Hi, from my login i want to login as a other user ,

2005-11-09 Thread Steven D'Aprano
i want to do these steps > using python , how can i do it?? Type ctrl-d to exit Python, then at the command prompt, type su , then type your root password. Then, as root, type python at the command prompt. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to modify code while debugging it without having to stop and then restart debugger

2005-11-09 Thread Steven D'Aprano
ou are coding in too, or only English? [snip] >> there are several applications that can do this. >> in fact, the free version of the visual studio 2005, which is free, have >> this ability. Just out of curiosity, how much is the free version of Visual Studio 2005? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to modify code while debugging it without having to stop and then restart debugger

2005-11-10 Thread Steven D'Aprano
several applications that can do this. >>>>in fact, the free version of the visual studio 2005, which is free, have >>>>this ability. >> >> >> Just out of curiosity, how much is the free version of Visual Studio 2005? >> >> > I'm not positive, b

Re: Python obfuscation

2005-11-10 Thread Steven D'Aprano
el > inclied to "rip off the code", or in this case, rip out the code. Which leads to the important counter-question. Since there is a Python obfuscator, is there a Python un-obfuscator? I am aware that not all obfuscations can be reversed, but some can. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-10 Thread Steven D'Aprano
27;t want the memory containing the plaintext to be swapped to your swap partition, where raw disk tools can recover it. But as a general rule, you're right. If you, the developer, don't have to think of your users as the enemy, you'd be amazed the amount of make-work you don't have to do. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newb ??

2005-11-10 Thread Steven D'Aprano
ans = raw_input("Is it %d? y/n " % guess) if ans in ('y', 'yes'): break ans = raw_input("Too high? y/n ") if ans in ("y", "yes"): hi = guess-1 else: lo = guess+1 This should run, and it will *almost* do what you want. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-10 Thread Steven D'Aprano
On Thu, 10 Nov 2005 06:47:41 +, Donn Cave wrote: > Quoth Steven D'Aprano <[EMAIL PROTECTED]>: > ... > | So when working with ints, strs or other immutable objects, you aren't > | modifying the objects in place, you are rebinding the name to another > | object: &

Re: append to non-existing list

2005-11-10 Thread Steven D'Aprano
On Wed, 09 Nov 2005 20:45:52 +0100, bruno at modulix wrote: >> If the array does not exist yet, it's created. > > Which is what I don't like. It should crash. Perhaps not *crash* as such. Raise an exception perhaps. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Addressing the last element of a list

2005-11-10 Thread Steven D'Aprano
Some objects can change their value, and some objects can't. But the best way to get an intuitive feel for how Python operates is to start up an interactive session and just experiment! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-10 Thread Steven D'Aprano
itself has costs, costs of time, space, complexity, bugs, lost opportunities, customer dissatisfaction, and even legality. Sony has just found that out: having been caught installing root-kits on peoples computers, they are now being sued. -- Steven. -- http://mail.python.org/mailman/list

Re: different binding behavior

2005-11-10 Thread Steven D'Aprano
f course x += 1 can't change the int in place, it has to rebind x to a new int. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newb ??

2005-11-10 Thread Steven D'Aprano
log2(100) > 5 your five guesses won't always be enough (though seven > should be). Dude, that's what my code does, although I admit I took zero care to get the awkward boundary conditions right, nor did I put code in to stop the game after five attempts. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Internal Variables

2005-11-11 Thread Steven D'Aprano
f you tell us what sort of information you are after, we can suggest where you should be looking, rather than just assume it is hidden in "internal variables". BTW, since Python is open source software, you can download and read through the entire code base if you wish. -- Steven. --

Re: odd behavior

2005-11-11 Thread Steven D'Aprano
everse lexicographic order, which is the result you get. I'm not running Python 2.4 so I can't test this, but to get the result you want I guess you want this: py> x.sort(key=len, reverse=True) py> x ['aardvark', 'abalone', 'aerate', 'acme', 'add'] or: py> x.sort(key=len) py> x.reverse() -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: list of lambda

2005-11-11 Thread Steven D'Aprano
ically, a method) which will return x converted to upper case when called. So the list comprehension you want is: # note all the brackets py> L = [(lambda x: x.upper)(x) for x in ['a', 'b', 'c']] py> L [, , ] py> L[0](); L[1](); L[2]() 'A' &#

Re: Python obfuscation

2005-11-11 Thread Steven D'Aprano
laws are good for either innovation or the economy, and given the absolute artificiality of treating ideas as if they were scarce goods, I don't understand why the artificial monopoly rights of copyright holders are allowed to trump the natural rights of copyright users. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-11 Thread Steven D'Aprano
is to force a system of artificial government-granted monopolies, together with all the proven economic inefficiencies of such monopolies, on the developing world. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-11 Thread Steven D'Aprano
, keep in mind firstly that the source code is obfuscated, and secondly that I am not an idiot, I will recognise my own code if you try to pass it off as yours." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-12 Thread Steven D'Aprano
, well, if you think you can a commercial advantage by annoying your customers, knock yourselves out. [1] By "everyone" I mean "lots of people who should know better". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

[OT] Copyright [was Re: Python obfuscation]

2005-11-12 Thread Steven D'Aprano
product away for free? Promotions, network effects, "the first sample is free", driving your competitors out of business, try before you buy, software which is paid for by advertising... there are many reasons why companies might not just turn a blind eye to piracy but welcome it. The mistake is to only think of piracy as lost revenue. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for adding symbols within Python

2005-11-12 Thread Steven D'Aprano
whatever namespace you define them in. Personally, I think rather than adding a new language feature (...slim to none...) there is more hope of getting something like this added to the standard library: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486 -- Steven. -- http://mail.p

Re: tutorial example

2005-11-12 Thread Steven D'Aprano
t() returns a value: it returns None: who_cares = L.sort() # who_cares is now None; L is now sorted Languages such as Pascal have procedures, which don't return a value, and functions, which do. Python does not have procedures. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for adding symbols within Python

2005-11-13 Thread Steven D'Aprano
you suggesting that the Python language designers should somehow predict every possible symbol that anyone in the world might ever need, and build them into the language as predefined things? If that is not what you mean, can you explain please, because I'm confused. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for adding symbols within Python

2005-11-13 Thread Steven D'Aprano
On Sun, 13 Nov 2005 12:33:48 +0100, Pierre Barbier de Reuille wrote: > Steven D'Aprano a écrit : >> On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote: >> >> >>>The problem, IMHO, is that way you need to declare "symbols" >>

Re: Proposal for adding symbols within Python

2005-11-13 Thread Steven D'Aprano
On Mon, 14 Nov 2005 00:48:46 +1100, Ben Finney wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> On Sun, 13 Nov 2005 10:11:04 +0100, Pierre Barbier de Reuille wrote: >> > The problem, IMHO, is that way you need to declare "symbols" >> > b

Re: Copyright [was Re: Python Obfuscation]

2005-11-13 Thread Steven D'Aprano
n owned the copyright. See http://www.cdbaby.net/articles/courtney_love.html for details of how the major record labels, through their enforcement arm the RIAA, stole rights from the creative artists that they claim to represent. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Abstract Base Classes

2005-11-13 Thread Steven D'Aprano
so here's the implementation I > decided upon. [snip] Seems good to me. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying small chunks from long string

2005-11-14 Thread Steven D'Aprano
f simple tests, then ran it again. Same result. Unless I've made some stupid mistake, I think this is the way to go. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying small chunks from long string

2005-11-14 Thread Steven D'Aprano
Replying to myself... the first sign of madness *wink* Steven D'Aprano wrote: > size = 1024*1024*20 # 20 MB > original = "A" * size > copy = [None] * size > for i in range(size): > copy[i] = original[i].lower() > copy = ''.join(copy) Do you not

Re: Proposal for adding symbols within Python

2005-11-14 Thread Steven D'Aprano
quot;Create a new polygon with n sides.""" self.state = n def grow_side(self): self.state += 1 def lose_side(self): self.state -= 1 Compare that with something like this: class MutablePolygon: """Define a polygon object that

Re: Proposal for adding symbols within Python

2005-11-14 Thread Steven D'Aprano
cos} # easy to modify table["sin"] = my_better_sine_function result = table["sin"](0) If I have missed a usage case, perhaps you should give at specific example. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: modifying small chunks from long string

2005-11-14 Thread Steven D'Aprano
gh, in fairness, if you could cut the time to 0.04s for 20MB then it would be worth the extra work to use the array module. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: best way to discover this process's current memory usage, cross-platform?

2005-11-14 Thread Steven D'Aprano
izeof(obj) (obviously there is no built-in function sizeof... wait, let me check... nope, not a built-in) I've read the docs for gc and pdb and nothing stands out to me as doing anything like this. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposal for adding symbols within Python

2005-11-15 Thread Steven D'Aprano
2 CM_TO_METRES = 100 # ... myObject.value = RIGHT_THING #... 100 lines of code elided... if myObject.value = RIGHT_THING: do_right_thing() else: do_wrong_thing() It isn't always appropriate or necessary to define "constants" (and I sometimes wish that Python would enforce assign-once names), but they can help avoid some silly mistakes. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: string help

2005-11-15 Thread Steven D'Aprano
le compares prefixes with "O" and then "Q", the second looks to see if prefixes is a substring of "OQ". In this case, they will both have the same effect. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Default method arguments

2005-11-15 Thread Steven D'Aprano
, you refer to a plain _marker, but in the method code block, you need to qualify it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: is parameter an iterable?

2005-11-15 Thread Steven D'Aprano
code in a try...except block and catch the exception raised when a non-iterator is passed as an argument. Which exception is that? I leave that as an exercise for the reader. (Hint: Just Do It and read the traceback Python prints.) Actually, I think "Just Do It" might make a good motto for Python. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: is parameter an iterable?

2005-11-15 Thread Steven D'Aprano
On Tue, 15 Nov 2005 11:26:23 -0800, py wrote: > Dan Sommers wrote: >> Just do it. If one of foo's callers passes in a non-iterable, foo will >> raise an exception, and you'll catch it during testing > > That's exactly what I don't want. I don't want an exception, instead I > want to check to se

Re: Python obfuscation

2005-11-15 Thread Steven D'Aprano
software. Very few professional (i.e. they get paid to program) developers actually own the copyright on the programs they write, and of those that do own the copyright, even fewer make money directly from that copyright. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: is parameter an iterable?

2005-11-15 Thread Steven D'Aprano
; print i + 1 > except TypeError: > print "can't add string and integer" try: for item in obj: do_stuff(item) except TypeError, msg: if msg == "iteration over non-sequence": handle_non_iterator() else: # re-raise the exception raise -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: is parameter an iterable?

2005-11-15 Thread Steven D'Aprano
_getitem__(), classes that implement next(), and probably more things that I have forgotten. Your code doesn't check for any of those. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: is parameter an iterable?

2005-11-16 Thread Steven D'Aprano
On Tue, 15 Nov 2005 21:54:07 -0500, Dan Sommers wrote: > On Wed, 16 Nov 2005 13:12:38 +1100, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> try: >> for item in obj: >> do_stuff(item) >> except TypeError, msg: &g

Re: Default method arguments

2005-11-16 Thread Steven D'Aprano
bject that has a magic meaning (e.g. as a sentinel), don't tempt your users to try to use it as if it were an ordinary object. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Default method arguments

2005-11-16 Thread Steven D'Aprano
On Wed, 16 Nov 2005 09:48:47 +, Duncan Booth wrote: > Steven D'Aprano wrote: >> I would like to see _marker put inside the class' scope. That prevents >> somebody from the outside scope easily passing _marker as an argument >> to instance.f. It also neatly

Re: is parameter an iterable?

2005-11-16 Thread Steven D'Aprano
On Tue, 15 Nov 2005 21:59:44 -0500, Roy Smith wrote: > In article <[EMAIL PROTECTED]>, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> try: >> for item in obj: >> do_stuff(item) >> except TypeError, m

Re: derived / base class name conflicts

2005-11-16 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > so the following would not result in any conflicts > > class A: >def __init__(self): > self.__i= 0 > > class B(A): >def __init__(self): > A.__init__(self) > self.__i= 1 > Be careful here. The above won't result in any conflicts, but related

Re: initialising a list of lists

2005-11-16 Thread Steven D'Aprano
ery simple idioms being made even shorter in Python. So perhaps there should be a list method that takes an integer argument and appends that many empty lists: d = [] d.append_empties(5) Or even a function that does this: def nested(numcopies, base=None, *args): if base is None: base = [] for i in range(numcopies): base.append(args[:]) return base -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-16 Thread Steven D'Aprano
On Wed, 16 Nov 2005 13:51:35 +, Ed Jensen wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> I'm not sure if that is meant to be a rhetorical >> question or not, but something of the order of 95% of >> all software written is never distributed to oth

Re: is parameter an iterable?

2005-11-16 Thread Steven D'Aprano
ver non-sequence" to something else, the code should continue to work correctly. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python obfuscation

2005-11-16 Thread Steven D'Aprano
children are lost generations with respect to ethics, manners, > and respect for authority, perhaps we can train our grandchildren to > behave more proprely. There is too much respect for so-called "authority", not too little. Respect for authority is just another way of saying "Don't think for yourself, do as you're told." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

<    36   37   38   39   40   41   42   43   44   45   >