Memoization and encapsulation

2005-12-30 Thread Steven D'Aprano
and again it works, but I can't help feeling it is an abuse of the class mechanism to do this. What do folks think? Is there a better way? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: why writing list to file puts each item from list on seperate line?

2005-12-30 Thread Steven D'Aprano
pple, .49. star market Then what you want to do is change data to a list of strings rather than a list of tuples. Before appending to data, you join the tuple ("apple", "0.49", "market") like so: data.append(", ".join(L) + "\n") # note newline at the end of each line Then, after you have appended ALL the lines, you open your file once for writing, and write data in one go: f.writelines(data) Hope this helps. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Memoization and encapsulation

2005-12-31 Thread Steven D'Aprano
On Fri, 30 Dec 2005 21:08:29 -0800, Raymond Hettinger wrote: > Steven D'Aprano wrote: >> I was playing around with simple memoization and came up with something >> like this: [snip] > Try something like this: > > def func(x, _cache={}): > if x in

Re: Memoization and encapsulation

2005-12-31 Thread Steven D'Aprano
't have to declare it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Global Variables in OOP and Python

2005-12-31 Thread Steven D'Aprano
On Sat, 31 Dec 2005 21:21:29 +, Dennis Lee Bieber wrote: > On Sat, 31 Dec 2005 11:37:38 +1100, Steven D'Aprano > <[EMAIL PROTECTED]> declaimed the following in > comp.lang.python: > >> >> Do you mean something like this? >> >> # Module care_

Re: python coding contest

2005-12-31 Thread Steven D'Aprano
56**2 + 66*256 + 64 100 >>> A.tostring() '\x0fB@' The reverse transformation is just as easy: >>> A = array.array('b', "\x0fB@") # initialise from a byte string >>> n = 0L >>> for b in A: ... n = n << 8 | b ... >>> n 100L And of course these can be turned into functions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Array construction from object members

2005-12-31 Thread Steven D'Aprano
attribute "height" to myClass, and want to work out the mean height, you would need a second function to do it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python article in Free Software Magazine

2005-12-31 Thread Steven D'Aprano
tations. You, as the author, aren't responsible for the wrong-headed frames that many readers will bring to the article, but you should be aware of them and work around them if you can. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Hypergeometric distribution

2006-01-01 Thread Steven D'Aprano
51057434082 >>> timefact(30) # ten times bigger 4255.2370519638062 Keep in mind, if you are calculating the hypergeometric probabilities using raw factorials, you are doing way too much work. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python article in Free Software Magazine

2006-01-01 Thread Steven D'Aprano
On Sun, 01 Jan 2006 06:09:14 -0500, Dan Sommers wrote: > On Sun, 01 Jan 2006 18:06:10 +1100, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> I don't want to nit-pick all my way through the article, which is very >> decent and is worth reading, but I wil

Re: Python article in Free Software Magazine

2006-01-01 Thread Steven D'Aprano
thon is not suited for a particular job, then we would not be doing anyone any favours to push Python for that job. I'm worried about people who pre-judging (as in prejudice) Python negatively on the basis of buzzwords they barely understand. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line replace

2006-01-01 Thread Steven D'Aprano
taneous write access to a file. What problem are you trying to solve by having simultaneous writes to the same file? Perhaps there is another way. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Compressing folders in Windows using Python.

2006-01-01 Thread Steven D'Aprano
s... your disk is full... am I close? *wink* > What command is there to zip files in Windows? Or is there any other problem ? What happens if you call up a Windows command prompt and type zip at the prompt? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: python coding contest

2006-01-01 Thread Steven D'Aprano
a pig?" The moral of the story is, before spending time working on some scheme to save CPU time, you better be absolutely sure that firstly, you are going to save CPU time, secondly, that it is enough CPU time to be worth saving, and thirdly, that you aren't wasting more of your own time to do it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Global Variables in OOP and Python

2006-01-01 Thread Steven D'Aprano
) or using static > variables. Mutable OO-singletons are not less harmfull than good old > globals. Now that you mention it, how obvious it is. That is good thinking, thanks. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Hypergeometric distribution

2006-01-01 Thread Steven D'Aprano
On Sun, 01 Jan 2006 14:24:39 -0800, Raven wrote: > Thanks Steven for your very interesting post. > > This was a critical instance from my problem: > >>>>from scipy import comb >>>> comb(14354,174) > inf Curious. It wouldn't surprise me if scipy

Re: Spiritual Programming (OT, but Python-inspired)

2006-01-02 Thread Steven D'Aprano
reasoning about the afterlife. Life is a process, not a thing -- when a clock runs down and stops ticking, there is no essence of ticking that keeps going, the gears just stop. When I stop walking, there is no spirit of walk that survives me coming to a halt. I just stop walking. --

Re: indentation preservation/restoration

2006-01-02 Thread Steven D'Aprano
ndentation and numeric literals, but also string literals, keywords, operators, and anything else. Using compression and error-correcting codes should mean that your Python scripts will then be safe from absolutely anything short of deleting the entire file -- and for that, you have backups. -- St

Re: Python or Java or maybe PHP?

2006-01-02 Thread Steven D'Aprano
improvement of error-full code. Writing error-free code *the first time* is hard. One wonders how many edit-compile-test cycles it takes to get these millions of lines of error-free code. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: One-step multiples list generation?

2006-01-03 Thread Steven D'Aprano
ule and list comprehensions: >>> foo = [] >>> import copy >>> multi_foo = [copy.copy(foo) for _ in range(10)] >>> multi_foo [[], [], [], [], [], [], [], [], [], []] >>> multi_foo[5].append(None) >>> multi_foo [[], [], [], [], [], [None], [

OT: Degrees as barriers to entry [was Re: - E04 - Leadership! Google, Guido van Rossum, PSF]

2006-01-03 Thread Steven D'Aprano
the higher fees they can charge for them. In my inexpert opinion, the cause of shortages of experts is more the fault of the universities than of the professional bodies. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling GPL code from a Python application

2006-01-03 Thread Steven D'Aprano
are intimate enough, exchanging complex internal data structures, that too could be a basis to consider the two parts as combined into a larger program. [end quote] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Re: Calling GPL code from a Python application

2006-01-03 Thread Steven D'Aprano
On Wed, 04 Jan 2006 14:57:58 +1100, Tim Churches wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> In particular: >> >> http://www.gnu.org/licenses/gpl-faq.html >> >> [quote] >> >> Q: If a library is released under the GPL (not the

Re: Calling GPL code from a Python application

2006-01-03 Thread Steven D'Aprano
ly see the good parts of our Copyright Act being over-ridden in de facto (if not de jure). And for those who don't speak Latin, I mean that having the legal right to make legal backup copies doesn't help you one bit if the Digital Restrictions Management software prevents those backup copies from working when you need them. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling GPL code from a Python application

2006-01-04 Thread Steven D'Aprano
the definition of "derivative work" > above. I don't have to stretch my imagination even the tiniest bit to see why program Foo (consisting of code X linked to code Y) is obviously derived from program Bar consisting of code X on its own. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: inline function call

2006-01-04 Thread Steven D'Aprano
# inline version: # original version: foo = myObject.something.foo for i in xrange(10): foo() # one name space lookup every loop -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
ve code, i is a name bound one at a time to the ints [1,2,3]. When you re-assign i to 4, that doesn't change the object 2 into the object 4, because ints are immutable. Only the name i is rebound to a new object 4. That doesn't change objects like lst which include 2 inside them. See this

Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
can not get to them. It has names and objects. Keep thinking about "call by reference" and you just confuse yourself and others. Think about names and objects and it is simple and straight-forward. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Apology Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
Steven D'Aprano wrote: > On Wed, 04 Jan 2006 10:54:17 -0800, KraftDiner wrote: >>I though the contents of lst would be modified.. (After reading that >>'everything' is a refrence.) > > See, this confusion is precisely why I get the urge to slap people who >

Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
ifferent and doesn't come with any mental frame, so instead of thinking they understand Python's behaviour, they think "Call by what now? How does that work?" instead of making incorrect assumptions. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
Peter Hansen wrote: > Steven D'Aprano wrote: > >> Python does not have references or pointers, except internally where >> Python coders can not get to them. It has names and objects. Keep >> thinking >> about "call by reference" and you just confuse

Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > >>On Wed, 04 Jan 2006 10:54:17 -0800, KraftDiner wrote: >> >>>I was under the assumption that everything in python was a refrence... >>>so if I code this: >>>lst = [1,2,3]

Re: Is 'everything' a refrence or isn't it?

2006-01-04 Thread Steven D'Aprano
Mike Meyer wrote: > Peter Hansen <[EMAIL PROTECTED]> writes: > > >>Steven D'Aprano wrote: >> >>>Python does not have references or pointers, except internally where >>>Python coders can not get to them. It has names and objects. Keep thinking

Re: Try Python update

2006-01-05 Thread Steven Bethard
Mike Meyer wrote: > The url is http://www.mired.org/home/mwm/try_python/. Reports of > problems would appreciated. You're probably already aware of this, but the online help utility doesn't work. It exits before you can type anything into it:

Re: Is 'everything' a refrence or isn't it?

2006-01-05 Thread Steven D'Aprano
On Thu, 05 Jan 2006 05:21:24 +, Bryan Olson wrote: > Steven D'Aprano wrote: >> Mike Meyer wrote: > [...] >>> Correct. What's stored in a list is a reference. >> >> Nonsense. What is stored in the list is an object. > > According to the

Re: Is 'everything' a refrence or isn't it?

2006-01-05 Thread Steven D'Aprano
difference between CBR and CBV > when you're passing immutable objects. Consider this: def do_nothing(x): pass huge_tuple = (None,) * 1**4 do_nothing(huge_tuple) If Python made a copy of huge_tuple before passing it to the function, you would notice. -- Steven. -- http:

Re: Apology Re: Is 'everything' a refrence or isn't it?

2006-01-05 Thread Steven D'Aprano
nclusions about what it means, like they do with "reference", they will stop and think and if need be look for further information about Python's object model. At the very least, they won't say "Everything in Python is a reference, so this should work, but it doesn't". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools.izip brokeness

2006-01-06 Thread Steven D'Aprano
with an API of function(*iterators [, fill]): Perform function on one or more iterators, with an optional fill object. Of course, this has to be defined in code as: def function(*iterators, **kwargs): if kwargs.keys() != ["fill"]: raise ValueError ... It might

Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Steven D'Aprano
ions. The emphasis is on the *object*, not the passing mechanism. In C, everything is mutable, and whether you can change an item depends on whether you are working with a reference to that item or a copy of the item. That's a language issue, not a data issue -- in some language

Re: Is 'everything' a refrence or isn't it?

2006-01-06 Thread Steven D'Aprano
On Fri, 06 Jan 2006 02:19:29 -0800, bonono wrote: > > Steven D'Aprano wrote: >> I'll tell you what I say: Python passes objects to functions or >> assignments. >> > Which in C sense, is a reference(or pointer) to some opaque "table" > maintain by

Re: Translate this to python?

2006-01-06 Thread Steven D'Aprano
at the start of their code. Will Guido end up re-introducing str.find to Python 4.0 because people define this in all their code (complete with deliberately included bug)? def find(s, target, start=None, end=None): try: return s.index(target, start, end) except: return -1 On the other hand, there are genuine improvements: apply(f, L) is *much* better written as f(*L). I don't think anyone will miss apply. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Spelling mistakes!

2006-01-06 Thread Steven D'Aprano
"patch" became a "minor version upgrade". > Duh. Next time I use a dictionary before freezing an API! Can you please explain what you mean by that? Use a dictionary how? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Spelling mistakes!

2006-01-06 Thread Steven D'Aprano
On Fri, 06 Jan 2006 17:29:32 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> > Duh. Next time I use a dictionary before freezing an API! >> Can you please explain what you mean by that? Use a dictionary how? > > Use a dictionary by

Re: Is 'everything' a refrence or isn't it?

2006-01-07 Thread Steven D'Aprano
On Sat, 07 Jan 2006 01:29:46 -0500, Mike Meyer wrote: > Call by object is the worst choice among the three, because "object" > has such a vague meaning, so you never know what implications someone > will come away with. So very unlike "call by reference", r

Re: Is 'everything' a refrence or isn't it?

2006-01-07 Thread Steven D'Aprano
. > > I'm sorry if you got confused, but please don't project it on > the rest of the discipline. Perhaps you should check out the beginning of the thread before making any additional comments. It wasn't me who was confused and asked "Hey what's going on? I was

Re: Returning Values from Bash Scripts

2006-01-07 Thread Steven D'Aprano
;>> output = os.popen('ls -l').read() Perhaps the simplest way if subprocess is not available to you is the commands module. Other possibilities are os.fork, os.execv and the popen2 module. There may be other solutions as well. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to test for a dependency

2006-01-09 Thread Steven Bethard
Darren Dale wrote: > I would like to test that latex is installed on a windows, mac or linux > machine. What is the best way to do this? This should work: > > if os.system('latex -v'): > print 'please install latex' > > but I dont actually want the latex version information to print to screen

Re: Why keep identity-based equality comparison?

2006-01-10 Thread Steven Bethard
Mike Meyer wrote: > [EMAIL PROTECTED] writes: > >> My question is, what reasons are left for leaving the current default >> equality operator for Py3K, not counting backwards-compatibility? >> (assume that you have idset and iddict, so explicitness' cost is only >> two characters, in Guido's examp

Re: Why keep identity-based equality comparison?

2006-01-11 Thread Steven Bethard
Mike Meyer wrote: > Steven Bethard writes: > >> Not to advocate one way or the other, but how often do you use >> heterogeneous containers? > > Pretty much everything I do has heterogenous containers of some sort > or another. Sorry, I should have been a lit

Re: Help with super()

2006-01-13 Thread Steven Bethard
David Hirschfield wrote: > Here's an example that's giving me trouble, I know it won't work, but it > illustrates what I want to do: > > class A(object): >_v = [1,2,3] > def _getv(self): >if self.__class__ == A: >return self._v >return super(self.__class__,sel

Re: decode unicode string using 'unicode_escape' codecs

2006-01-13 Thread Steven Bethard
aurora wrote: > I have some unicode string with some characters encode using python > notation like '\n' for LF. I need to convert that to the actual LF > character. There is a 'unicode_escape' codec that seems to suit my purpose. > encoded = u'A\\nA' decoded = encoded.decode('unicod

Re: Why can't I "from module import *" except at module level?

2006-01-13 Thread Steven D'Aprano
. Should security be defined somewhere? > So > without this functionality, how do I target modules to import in other > directories after program execution has begun? I'd consider putting your import logic into a module of its own, at the module-level and not inside a function. Then just call "from importer import *" in the top level of your code and I think that should meet your needs. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Steven D'Aprano
lass or part of the instance value is, in my opinion, not a useful question. The answer depends on which way you want to look at it. > 5. The (only?) way to get an object's value is to > evaluate something (a name or a "reference"(*) > that refers to the object. I can't think of any other way to get at an object except by accessing that object, or even what it would mean if there was such a way. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to improve this simple block of code

2006-01-13 Thread Steven D'Aprano
oat(x)) > I do it like this because if > x = "132.15" ...i dont want to modify it. But if > x = "132.60" ...I want it to become "132.6" Then you want: x = float("123.60") # full precision floating point value r = round(x, 1) # rounded to one decimal place -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-13 Thread Steven D'Aprano
On Sat, 14 Jan 2006 04:22:53 +, Donn Cave wrote: > Quoth Steven D'Aprano <[EMAIL PROTECTED]>: > | On Thu, 12 Jan 2006 16:11:53 -0800, rurpy wrote: > |> It would help if you or someone would answer these > |> five questions (with something more than "yes

Re: Marshal Obj is String or Binary?

2006-01-13 Thread Steven D'Aprano
On Fri, 13 Jan 2006 22:20:27 -0800, Mike wrote: > Thanks everyone. It seems broken storing complex structures as escaped > strings, but I think I'll take my changes. Have you read the marshal reference? http://docs.python.org/lib/module-marshal.html marshal doesn't store data as escaped strin

Re: Marshal Obj is String or Binary?

2006-01-14 Thread Steven D'Aprano
;.join(['\0' for i in range(256)]) >>> len(s) 256 >>> len(repr(s)) 1026 # one particular mix of both printable and unprintable data >>> s = ''.join([chr(i) for i in range(256)]) >>> len(s) 256 >>> len(repr(s)) 737 # a different mix of both printable and unprintable data >>> s = '+'.join([chr(i) for i in range(128)]) >>> len(s) 255 >>> len(repr(s)) 352 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
On Sat, 14 Jan 2006 14:14:01 +, Antoon Pardon wrote: > On 2006-01-14, Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> On Thu, 12 Jan 2006 16:11:53 -0800, rurpy wrote: >> >>> It would help if you or someone would answer these >>> five ques

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
On Sat, 14 Jan 2006 17:33:07 -0500, Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> On Sat, 14 Jan 2006 04:22:53 +, Donn Cave wrote: >>> |> 2. What is the value of object()? >>> [ I assume you mean, the object returned by object().

Re: Marshal Obj is String or Binary?

2006-01-14 Thread Steven D'Aprano
the database. Your database can't automatically suck data structures out of Python's working memory! So why re-invent the wheel? marshal is not recommended, but if you can live with the limitations of marshal then it might do the job. But trying to optimise code that hasn't

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
ce of bugs: >>> distance_in_feet = 5 >>> weight_in_milligrams = 5 >>> distance_in_feet == weight_in_milligrams True Since when is a distance comparable to a weight, let alone equal? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
On Sat, 14 Jan 2006 18:49:43 -0500, Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> object instances are like electrons (note for pedants: in classical >> physics, not QED): they are all exactly the same, distinguishable only by >> their posit

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
ange their value, some are not. That's no different from having a byte in memory, and flipping bits. It is the same *byte*, even though the value it has changes. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
On Sat, 14 Jan 2006 23:21:14 -0500, Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Likewise instances of object() have a rich, object-oriented structure -- >> dir(object()) returns a list with twelve items -- but every instance is >> identi

Re: Is 'everything' a refrence or isn't it?

2006-01-14 Thread Steven D'Aprano
On Sat, 14 Jan 2006 23:26:40 -0500, Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> On Sat, 14 Jan 2006 18:26:41 -0500, Mike Meyer wrote: >>> If two objects ARE the same value, then they should be the same >>> object. >> You a

Re: More than you ever wanted to know about objects [was: Is everything a refrence or isn't it]

2006-01-14 Thread Steven D'Aprano
On Sun, 15 Jan 2006 06:08:43 +, Steve Holden wrote: > I just wish Mike Meyer and Steven D'Aprano were close enough that you > could bang their heads together. In the same playground, perhaps? :-) Well, after such a deeply-reasoned, well-explained refutation of my position, what c

Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Steven D'Aprano
On Sun, 15 Jan 2006 03:11:27 -0500, Mike Meyer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> On Sat, 14 Jan 2006 23:26:40 -0500, Mike Meyer wrote: >>>> I have no problem with that. Some objects are mutable and can change >>>> their value

Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Steven D'Aprano
x27;s value is None" or something else? None is a singleton, so it is meaningless to ask about two instances of NoneType. How about this? >>> class Empty: ... pass ... >>> id(Empty()) -151107636 >>> type(Empty()) Do two instances of Empty have the same value, or is the question meaningless? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-15 Thread Steven D'Aprano
that it is fuzzy and depends on context. Often we want to exclude type (so that 1 and 1.0 have the same value), we almost always want to exclude identity (so that [1,2] and [1]+[2] have the same value), but there are enough exceptions to make things interesting. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Preventing class methods from being defined

2006-01-16 Thread Steven D'Aprano
itly report that something is disabled than to just have it magically appear and disappear). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-16 Thread Steven D'Aprano
step=1): yield start while 1: start += step yield start The equivalent generator for a geometric sequence is left as an exercise for the reader. If your proposal included support for ranges of characters, I'd be more interested. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is 'everything' a refrence or isn't it?

2006-01-16 Thread Steven D'Aprano
ttr; raise > AttributeError > ... > >>> A()==B() > A().__eq__ > B().__eq__ > B().__eq__ > A().__eq__ > A().__coerce__ > B().__coerce__ > A().__cmp__ > B().__cmp__ > False Why are A().__eq__ and B().__eq__ both being called twice? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-16 Thread Steven D'Aprano
to undermine that. *shakes head in amazement* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Preventing class methods from being defined

2006-01-16 Thread Steven D'Aprano
On Mon, 16 Jan 2006 06:39:48 -0500, Dan Sommers wrote: > By the principle of least surprise, if dir(some_sobject) contains foo, > then some_object.foo should *not* raise a NameError. Good thinking. Yes, it should raise a different exception. -- Steven. -- http://mail.python.org/m

Re: Arithmetic sequences in Python

2006-01-16 Thread Steven D'Aprano
On Mon, 16 Jan 2006 02:58:39 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> For finite sequences, your proposal adds nothing new to existing >> solutions like range and xrange. > > Oh come on, [5,4,..0] is much easier to read than ra

Re: Shrinky-dink Python (also, non-Unicode Python build is broken)

2006-01-16 Thread Steven Bethard
Larry Hastings wrote: > Of course, it's not the most important thing in the world--after all, > I'm the first person to even *notice*, right? But it seems a shame > that > one can break the build so easily. If it pleases the stewards of > Python, I would be happy to submit patches that fix the no

Re: Is 'everything' a refrence or isn't it?

2006-01-16 Thread Steven D'Aprano
On Mon, 16 Jan 2006 21:18:35 +, Bengt Richter wrote: > On Mon, 16 Jan 2006 21:58:26 +1100, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >>On Mon, 16 Jan 2006 10:34:40 +, Bengt Richter wrote: >> >>> >>> class A: >>> ...

Re: Decimal ROUND_HALF_EVEN Default

2006-01-16 Thread Steven D'Aprano
Is Your Friend: http://www.diycalculator.com/popup-m-round.shtml -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: On Numbers

2006-01-16 Thread Steven D'Aprano
e integer 1 or the real number 1, are unlikely to write 1**0.5, prefering the squareroot symbol. For the rest of us, including applied mathematicians, 1**0.5 implies floating point, which implies the correct answer is 1.0. So I don't really know what point you are making. What solution(s) for 1**0.5 were you expecting? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-17 Thread Steven Bethard
Antoon Pardon wrote: > Why don't we give slices more functionality and use them. > These are a number of ideas I had. (These are python3k ideas) > > 1) Make slices iterables. (No more need for (x)range) > > 2) Use a bottom and stop variable as default for the start and >stop attribute. top wo

Re: magical expanding hash

2006-01-17 Thread Steven Bethard
Paul Rubin wrote: > Hmm, > >x[a][b][c][d] = e# x is a "magic" dict > > becomes > >x.setdefault(a,{}).setdefault(b,{}).setdefault(c,{})[d] = e > > if I understand correctly. Ugh. Agreed. I really hope that Python 3.0 applies Raymond Hettinger's suggestion "Improved default value

Re: Arithmetic sequences in Python

2006-01-17 Thread Steven Bethard
Gregory Petrosyan wrote: > Hey guys, this proposal has already been rejected (it is the PEP 204). No, this is a subtly different proposal. Antoon is proposing *slice* literals, not *range* literals. Note that "confusion between ranges and slice syntax" was one of the reasons for rejection of `

Re: magical expanding hash

2006-01-17 Thread Steven Bethard
Steve Holden wrote: > Steven Bethard wrote: >> Agreed. I really hope that Python 3.0 applies Raymond Hettinger's >> suggestion "Improved default value logic for Dictionaries" from >> http://wiki.python.org/moin/Python3%2e0Suggestions >> >> Th

Re: magical expanding hash

2006-01-18 Thread Steven D'Aprano
On Tue, 17 Jan 2006 18:00:00 -0700, Steven Bethard wrote: > Steve Holden wrote: >> Steven Bethard wrote: >>> Agreed. I really hope that Python 3.0 applies Raymond Hettinger's >>> suggestion "Improved default value logic for Dictionaries" from &g

Re: check to see if value can be an integer instead of string

2006-01-18 Thread Steven D'Aprano
or: raise else: do_this() Or even simpler: int(var) do_this() -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: On Numbers

2006-01-18 Thread Steven D'Aprano
ess you explicitly uses complex numbers. That's the best behaviour for the majority of people: most people don't even know what complex numbers are, let alone want to deal with them in their code. Python, after all, is not Mathematica. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Being unjust

2006-01-18 Thread Steven D'Aprano
preferred status, it sounds like a good move to me. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-18 Thread Steven Bethard
Alex Martelli wrote: > Tom Anderson <[EMAIL PROTECTED]> wrote: >> Sounds good. More generally, i'd be more than happy to get rid of list >> comprehensions, letting people use list(genexp) instead. That would >> obviously be a Py3k thing, though. > > I fully agree, but the BDFL has already (tentat

use cases for a defaultdict

2006-01-18 Thread Steven Bethard
Steven Bethard wrote: > Agreed. I really hope that Python 3.0 applies Raymond Hettinger's > suggestion "Improved default value logic for Dictionaries" from > http://wiki.python.org/moin/Python3%2e0Suggestions > > This would allow you to make the setdef

list(...) and list comprehensions (WAS: Arithmetic sequences in Python)

2006-01-18 Thread Steven Bethard
ut the BDFL has already (tentatively, I hope) > Pronounced that the [...] form will stay in Py3K as syntax sugar for > list(...). I find that to be a truly hateful prospect, but that's the > prospect:-(. Steven Bethard wrote: > I'm not sure I find it truly hateful, but definitely u

Re: check to see if value can be an integer instead of string

2006-01-18 Thread Steven D'Aprano
e: try: print error_table[value_from_hardware] except KeyError: raise CustomHardwareError("Unknown value!") -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Can a simple a==b 'hang' in and endless loop?

2006-01-18 Thread Steven D'Aprano
que ID of an object, which as an implementation detail may be the actual memory address, but that's just an implementation detail. In any case, given a memory address, you can't do anything with that knowledge. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: [OT] Nit: please don't user "it's" unless you can substitute "it is" without changing your inteded meaning.

2006-01-18 Thread Steven D'Aprano
o will ;-) For all three of the people on the Internet who haven't seen this: http://www.angryflower.com/bobsqu.gif And in colour: http://www.angryflower.com/aposter.html -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: a more precise re for email addys

2006-01-18 Thread Steven D'Aprano
ress that distinguishes the two sets. Doesn't the relevent RFC state that the only way to determine a valid email address is to send to it and see if the mail server likes it? I believe it explicitly warns against validating email addresses, since you will invariably end up refusing to accep

Re: OT: excellent book on information theory

2006-01-18 Thread Steven D'Aprano
nce, it could > have referred to a metered lot, or to a parking garage > with time tickets, or even some kind of valet parking. But a car park can be any one of those things, or something else such as an unmetered lot. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-18 Thread Steven D'Aprano
Steven Bethard wrote: > I'm not sure I find it truly hateful, but definitely unnecessary. > TOOWTDI and all... TOOWTDI Considered Harmful. There is confusion between "There's Only One Way To Do It" and "There's One Obvious Way To Do It". The first i

Re: [OT] Nit: please don't user "it's" unless you can substitute "it is" without changing your inteded meaning.

2006-01-18 Thread Steven D'Aprano
Grant Edwards wrote: > On 2006-01-19, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > > >>>Typos happen to all of us, but in case you hadn't realized what "it's" >>>is a contraction for ("it is"), now you do, and you can save

Re: [OT] Nit: please don't user "it's" unless you can substitute "it is" without changing your inteded meaning.

2006-01-18 Thread Steven D'Aprano
Steven D'Aprano wrote: >> But wait, if you follow the rules on the poster, you'd use an >> apostrophe for the possive of "it", right? > > > But not if you actually followed the link I intended to send but forgot to: > > http://www.angryflower.co

Re: OT: excellent book on information theory

2006-01-18 Thread Steven D'Aprano
be made of wood or steel or uphostered springs, be on legs or coasters, fixed or movable? If it mattered, a good author will tell you, and if it doesn't matter, it doesn't matter. I cheer your willingness to look unfamiliar words in the dictionary, no sarcasm implied, but the dictionary rarely gives you either context or connotations (see the difference between describing somebody as wearing "sensible shoes" and "practical shoes"). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: why is my hash being weird??

2006-01-19 Thread Steven D'Aprano
keys. You don't need to write the code from C, just do it all in Python: hash = {} def summa(i): global hash for j in range(i): hash[j] = j import sys summa(sys.argv[1]) Now run the script: python test.py 10 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

<    90   91   92   93   94   95   96   97   98   99   >