Re: mutable numeric type

2007-01-01 Thread Steven D'Aprano
came up with a mutable numeric > type, which implements all the numerical operators (instances are of > course not hashable). This allows me to change the edge weights after > creating the graph. This is another alternative, although I still don't understand why you can&

Re: When argparse will be in the python standard installation

2007-01-03 Thread Steven Bethard
Martin v. Löwis wrote: > [EMAIL PROTECTED] schrieb: >> I feel argparse has some useful things that optparse doesn't have. But >> I can't find it argparse in python library reference. I'm wondering >> when it will be available in the python standard installation. > > On its own, never. Somebody has

Re: code optimization (calc PI) / Full Code of PI calc in Python and C.

2007-01-03 Thread Steven D'Aprano
ge(100): pass", "pass") >>> t.timeit(100) # time the loop one hundred times 29.367985010147095 Now compare it to the speed where you only create the list once. >>> t = timeit.Timer("for i in L: pass", "L = range(100)") >>> t.timeit(100) 16.155359983444214 -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: question on creating class

2007-01-04 Thread Steven D'Aprano
%s..." % self.__class__.__name__ def method(self): print "This is a method." k = Klass k.__name__ = classname return k >>> K = create_class("TestClass") >>> obj = K() Creating object of TestClass... -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: When argparse will be in the python standard installation

2007-01-04 Thread Steven Bethard
Martin v. Löwis wrote: > Steven Bethard schrieb: >> If someone has an idea how to include argparse features into optparse, >> I'm certainly all for it. But I tried and failed to do this myself, so I >> don't know how to go about it. > > It's not necessary

Re: When argparse will be in the python standard installation

2007-01-04 Thread Steven Bethard
Steven Bethard schrieb: > If someone has an idea how to include argparse features into optparse, > I'm certainly all for it. But I tried and failed to do this myself, so > I don't know how to go about it. Martin v. Löwis wrote: > It's not necessary that the imple

[ANN] argparse 0.4 - Command-line parsing library

2007-01-04 Thread Steven Bethard
Announcing argparse 0.4 --- argparse home: http://argparse.python-hosting.com/ argparse single module download: http://argparse.python-hosting.com/file/trunk/argparse.py?format=raw argparse bundled downloads at PyPI: http://www.python.org/pypi/argparse/ New in this

Re: When argparse will be in the python standard installation

2007-01-05 Thread Steven Bethard
[Thanks for looking through all these Martin!] Martin v. Löwis wrote: > Steven Bethard schrieb: >> * alias ArgumentParser to OptionParser >> * alias add_argument to add_option >> * alias Values to Namespace >> * alias OptionError and OptionValueError to ArgumentError &

Re: (newbie) Is there a way to prevent "name redundancy" in OOP ?

2007-01-05 Thread Steven Bethard
Stef Mientki wrote: > Not sure I wrote the subject line correct, > but the examples might explain if not clear [snip] > class pin2: > def __init__ (self, naam): > self.Name = naam > > aap2 = pin2('aap2') # seems completely redundant to me. > print aap2.Name You can use class statements

Re: program deployment

2007-01-06 Thread Steven D'Aprano
to > stop 99% of programmers from > reading your code. Yes, in theory they could decompile it, but in > practice, programmers are lazy. 99% of programmers won't read the code if you ship the source. > Look, I am so lazy that usually I don't read the source code, even if >

Re: program deployment

2007-01-06 Thread Steven D'Aprano
On Fri, 05 Jan 2007 07:19:37 -0800, king kikapu wrote: > > >> > Are they embarassed by their code? > > hehehe...no, just worried about stealing their ideas... I don't understand... how can they steal an idea? If somebody copies your idea, you've still got

Re: Encoding / decoding strings

2007-01-06 Thread Steven D'Aprano
ed1" are both used and he has to be "fred2". md5 checksums can now be broken, in both directions: it is relatively easy to generate collisions, and there are reverse md5 lookup tables. I imagine your use of md5 would be especially easy to attack, since the attacker knows that the string is an email address. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: attribute decorators

2007-01-06 Thread Steven D'Aprano
; depending on whether you want private attributes to be by convention or by name-mangling. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why less emphasis on private data?

2007-01-07 Thread Steven D'Aprano
es" and hypotheticals in this thread, there were two practical cases that revolved around private variables. In one, we see that they aren't a panacea: data hiding doesn't help when the data isn't hidden. In the other, we see that one developer's private attribute is just what another developer needs to solve a problem. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find the longst element list of lists

2007-01-07 Thread Steven Bethard
Scott David Daniels wrote: > Dan Sommers wrote: >> ... >> longest_list, longest_length = list_of_lists[ 0 ], len( >> longest_list ) >> for a_list in list_of_lists[ 1 : ]: >> a_length = len( a_list ) >> if a_length > longest_length: >> longest_list, longest_lengt

Re: Why less emphasis on private data?

2007-01-07 Thread Steven D'Aprano
On Sun, 07 Jan 2007 19:30:05 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> > If you want to write bug-free code, pessimism is the name of the game. >> >> I wonder whether Paul uses snow chains all year round, even in the blazing &g

Re: regex question

2007-01-08 Thread Steven D'Aprano
r *outside* the quotation marks is a raw-string. The r is not part of the string, but part of the delimiter. A string with a leading r *inside* the quotation marks is just a string with a leading r. It has no special meaning. -- Steven D'Aprano -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find the longst element list of lists

2007-01-08 Thread Steven D'Aprano
FASTER; For 100 items, sorting is 2.3 times faster; For 1000 items, sorting is 1.6 times faster; For 10,000 items, sorting is 1.2 times faster; For 20,000 items, sorting is 1.1 times faster. The precise results depend on the version of Python you're running, the amount of memory you have, other processes running, and the details of what's in the list you are trying to sort. But as my test shows, sort has some overhead that makes it a trivial amount slower for sufficiently small lists, but for everything else you're highly unlikely to beat it. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why less emphasis on private data?

2007-01-08 Thread Steven D'Aprano
On Sun, 07 Jan 2007 23:49:21 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> Just how often do you inherit from two identically-named classes >> both of which use identically-named private attributes? > > I have no idea how often i

Re: Why less emphasis on private data?

2007-01-08 Thread Steven D'Aprano
tal and utter nonsense and displays the most appalling misunderstanding of probability, not to mention a shocking lack of common sense. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to find the longst element list of lists

2007-01-08 Thread Steven D'Aprano
:]). That's going to be very time consuming for big lists. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why less emphasis on private data?

2007-01-09 Thread Steven D'Aprano
On Tue, 09 Jan 2007 10:27:56 +0200, Hendrik van Rooyen wrote: > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote: > > >> On Mon, 08 Jan 2007 13:11:14 +0200, Hendrik van Rooyen wrote: >> >> > When you hear a programmer use the word "probabil

Re: Question about using "with"

2007-01-09 Thread Steven Bethard
Steven W. Orr wrote: >> From the tutorial, they said that the following construct will > automatically close a previously open file descriptor: > > --- > #! /usr/bin/python > import sys > > for nn in range ( 1, len(sys.argv ) ): > print "

Re: Some thougts on cartesian products

2006-01-22 Thread Steven D'Aprano
On Sun, 22 Jan 2006 19:12:49 +0100, Christoph Zwerschke wrote: > Steven D'Aprano wrote: >> On Sun, 22 Jan 2006 18:29:45 +0100, Christoph Zwerschke wrote: >>> For doing such things I would use a vector subtype of list. >> >> Not everything needs to be a separ

Re: OT: excellent book on information theory

2006-01-23 Thread Steven D'Aprano
7;t it more likely that having passed the test of time, something that old is going to be better than some untested, untried new invention? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Arithmetic sequences in Python

2006-01-23 Thread Steven D'Aprano
ittedly I still confused between the various flavours of functions (function, bound method, unbound method, class method, static method...) *wink* but the difference between types and functions is fairly clear. Just don't ask about the difference between type and class... *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Some thougts on cartesian products

2006-01-23 Thread Steven D'Aprano
ficant? Order? Google "cartesian product" and hit "I'm feeling lucky". Or go here: http://mathworld.wolfram.com/CartesianProduct.html Still think there is no such thing? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Some thougts on cartesian products

2006-01-23 Thread Steven D'Aprano
it's widely useful. > By itself, it's usually not what one wants. Google on "Cartesian product python" and you will find thousands of hits. This is something that keeps coming up over and over again. Personally, I think cartesian products, together with permutations and combinations

Re: Some thougts on cartesian products

2006-01-23 Thread Steven D'Aprano
On Mon, 23 Jan 2006 18:17:08 +, Bryan Olson wrote: > Steven D'Aprano wrote: >> Bryan Olson wrote: >> >> > [Christoph Zwerschke had written:] >>>>What I expect as the result is the "cartesian product" of the strings. >>> >>>

Re: list comprehention

2006-01-23 Thread Steven D'Aprano
gt; This is the type of solution I was hoping to see: one-liners, with no use > of local variables. Because you like unreadable, incomprehensible, unmaintainable code? *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using non-ascii symbols

2006-01-24 Thread Steven D'Aprano
e ways of entering non-ASCII characters, and better support for displaying non-ASCII characters in the console, I can't see this suggestion going anywhere. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Creating a more random int?

2006-01-24 Thread Steven Macintyre
om.randint(3, 8) 6 >>> random.randint(3, 8) 3 >>> random.randint(3, 8) 8 >>> random.randint(3, 8) 8 >>> random.randint(3, 8) 5 >>> random.randint(3, 8) 3 >>> random.randint(3, 8) 4 Regards, Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: append to the end of a dictionary

2006-01-24 Thread Steven D'Aprano
a colour foods["red"].append("strawberry") for colour, foodlist in foods.iteritems(): for food in foodlist: print colour, food If you need to use the keys in a particular order, extract the keys and sort them first: colours = foods.keys() colours.sort() for colour in colours: for food in foods[colour]: print colour, food -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: append to the end of a dictionary

2006-01-24 Thread Steven D'Aprano
It returns None. What you are doing there is sorting the keys, throwing the sorted list away, and trying to iterate over None. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using non-ascii symbols

2006-01-24 Thread Steven D'Aprano
mes which can be easily misread are always a bad idea.) Consider how easy it is to shoot yourself in the foot with plain ASCII: l1 = 0 l2 = 4 ... pages of code ... assert 11 + l2 = 4 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Creating a more random int?

2006-01-24 Thread Steven D'Aprano
On Tue, 24 Jan 2006 18:47:01 +0200, Steven Macintyre wrote: > Hi all, > > I need to retrieve an integer from within a range ... this works ... below > is my out puts ... it just does not seem so random ... You are choosing from six values. You should expect each value _about_ 17%

Re: Creating a more random int?

2006-01-24 Thread Steven D'Aprano
should look like. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-24 Thread Steven D'Aprano
hon automatically removes them and reclaims the memory they used. You rarely need to worry about that. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using non-ascii symbols

2006-01-24 Thread Steven D'Aprano
On Tue, 24 Jan 2006 15:58:35 -0600, Dave Hansen wrote: > On Wed, 25 Jan 2006 08:26:16 +1100 in comp.lang.python, Steven > D'Aprano <[EMAIL PROTECTED]> wrote: > >>On Tue, 24 Jan 2006 10:38:56 -0600, Dave Hansen wrote: >> >>> The latter, IMHO. Especiall

Re: Real-world use cases for map's None fill-in feature?

2006-01-24 Thread Steven D'Aprano
ween a non-terminating bug and a correct calculation that would have finished if you had just waited a little longer. (How much is a little longer?) Hence, in general, a terminating wrong answer is easier to test for than a non-terminating bug. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-24 Thread Steven D'Aprano
urn memory to the operating system while it is still running. But the memory allocated to your data structures will be reclaimed by Python when they are not in use. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-24 Thread Steven D'Aprano
think we would be able to debug some code that you haven't shown us? I mean, some of the folks on comp.lang.python are really good, but even they aren't that good *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
extensions: s = fix_extension(s, old, new) return s newname = fix_all_extensions(newname, [ (".mpeg", ".mpg"), (".ram", ".rm"), (".jpeg", ".jpg"), (".qt", ".mov") ] > while string.count(newname, "__") > 0: > newname = string.replace(newname,"__","_") > while string.count(newname, "..") > 0: > newname = string.replace(newname,"..",".") We've already refactored those calls: newname = replace_all(newname, "__", "_") newname = replace_all(newname, "..", ".") That will do for starters. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
Giovanni Bajo wrote: > Steven D'Aprano wrote: > > >>But the real killer is this one line: >> >>row=row+chr(num/64) >> >>Bad, bad BAD idea. Every time you add two strings together, Python >>has to copy BOTH strings. As row gets huge, this t

Re: What's wrong?

2006-01-25 Thread Steven D'Aprano
rror you are getting? No, no, I love to guess... should the function be spelt PyCallable_Chock with an o instead of an a? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
; newname = re.sub("([_.])\\1+", "\\1", newname) _Slightly_? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
Replying to myself... the first step towards perdition... Steven D'Aprano wrote: > We really don't know what the optimization recognises, how it works, or > how fast a difference it makes. Of course, by "we" I mean "those of us who haven't seen and unders

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
the last three hours I've suddenly started coming down with a cold -- in the middle of our summer. So this is not the time for me to try to learn anything new. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using non-ascii symbols

2006-01-25 Thread Steven D'Aprano
gt; C2 is not defined, and NaNs, where NaN != NaN is always true but NaN <> NaN is undefined. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pulling numbers from ASCII filename not working

2006-01-25 Thread Steven D'Aprano
o string The traceback tells you exactly what is wrong, and where it is going wrong: you are trying to add a string to an int. What you probably want is either gp.AddMessage("LatInt is " + LatString) or gp.AddMessage("LatInt is %d" % LatInt). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
paging, screen savers, disk I/O? Are the files you are loading from disk badly fragmented? If your code is not optimized for memory, and hence pages a lot, you should be including that time in your measurements. But you probably don't want to count elapsed time when the screen saver kicks in. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pulling numbers from ASCII filename not working

2006-01-25 Thread Steven D'Aprano
ur problem would have been solved after one post. In other words, you sent us all on a wild goose chase. But the main thing is, the traceback was telling you exactly what was wrong. Listen to it, it knows. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
c cases. O(n*n/8) is still quadratic..." I presume Fredrik meant to say "nothing else". Or have I misunderstood something? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Possible memory leak?

2006-01-25 Thread Steven D'Aprano
On Wed, 25 Jan 2006 20:08:56 +0100, Giovanni Bajo wrote: > Steven D'Aprano wrote: > >> No, that's not correct. You are making a false >> assumption. > > Did you ever try to measure the code yourself? I'm still running Python 2.3, it would give misleading

Re: How to handle two-level option processing with optparse

2006-01-26 Thread Steven Bethard
R. Bernstein wrote: > Magnus Lycka informs: >> [in response to my comment]: >>> I see how I missed this. Neither disable_.. or enable_.. have document >>> strings. And neither seem to described in the optparser section (6.21) >>> of the Python Library (http://docs.python.org/lib/module-optparse.htm

Re: Question about isinstance()

2006-01-26 Thread Steven D'Aprano
ff, isn't it? On the one hand, you risk false negatives, by refusing to compare against things you didn't think of. On the other hand, you risk false positives, by comparing against more generic objects. I guess that trade-off is one each programmer must decide for herself, in full u

Re: Python String Substitution

2006-01-26 Thread Steven D'Aprano
way: print "something %(x)s something" % somedict "something %(x)s something" is a string, so all the substrings of it are also strings, including "x". That's pretty obvious. But the same holds if you change the x to something else: print "something %(123.456)s something" % somedict "123.456" is still a string. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: any way to customize the is operator?

2006-01-27 Thread Steven D'Aprano
hy did you want to customize "is"? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: writing large files quickly

2006-01-27 Thread Steven D'Aprano
s.system("dd if=/dev/zero of=largefile.bin bs=64K count=16384") That should make a 4GB file as fast as possible. If you have lots and lots of memory, you could try upping the block size (bs=...). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I dynamically create functions without lambda?

2006-01-27 Thread Steven Bethard
Russell wrote: > I want my code to be Python 3000 compliant, and hear > that lambda is being eliminated. The problem is that I > want to partially bind an existing function with a value > "foo" that isn't known until run-time: > >someobject.newfunc = lambda x: f(foo, x) > > The reason a neste

Re: Python String Substitution

2006-01-27 Thread Steven D'Aprano
t; % some_dictionary unless the string "123" is a key in the dictionary. Having a key 123 will not work, and the same for any other object. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I dynamically create functions without lambda?

2006-01-27 Thread Steven D'Aprano
n as: def __init__(self, fn, *args, **kw): self.fn, self.args, self.kw = fn, args, kw - It seems a shame to me that having created a partial _function_ using that technique, type(partial(...)) returns . It would be nicer if the type made it more obvious that the instance was callabl

Re: Efficient Find and Replace

2006-01-27 Thread Steven D'Aprano
Y. Here every time the search starts from the beginning of the > list. Hence the inefficiency. Yes, but the inefficient search code is done in C, which is so fast that it really doesn't matter unless your list is HUGE. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: indentation messing up my tuple?

2006-01-27 Thread Steven D'Aprano
e purpose of data? > f = open("test.txt", 'a') > f.write ( ''.join( tuple ) ) You are re-opening the file every single time around the loop. You should either do this: f = open("test.txt", "w") for row in bs(...): # processing f.write(one line only) f.close() or do this: data = [] for row in bs(...): # processing # accumulate everything you want in data f.writelines(data) f.close() -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient Find and Replace

2006-01-27 Thread Steven D'Aprano
nation, so I wrote this function to add two ints using bit manipulation. How do I make it go faster?" would it be better to optimize the bit manipulation code, or to just tell me that + also does integer addition? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I tell if I'm running in the PyWin interpreter?

2006-01-27 Thread Steven D'Aprano
expect to. When do you expect to get an EOFError? The only way I get an EOFError is if I explicitly hit Ctrl-D while raw_input is running. When do you expect to get it? Have you tried Ctrl-Z under Windows? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: VB to Python migration

2006-01-27 Thread Steven D'Aprano
B code in Python, which is sure to be slow, inefficient, bulky and buggy. You may also like to think about using a web front end. If your GUI app only uses simple controls like text fields and push buttons, a web front end might simplify things a lot. Good luck. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Returning a value from code string

2006-01-27 Thread Steven D'Aprano
hoops for very little benefit. What am I missing? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs C for a mail server

2006-01-27 Thread Steven D'Aprano
Google is your friend. The first four mail servers listed are, in order: sendmail postfix Microsoft Exchange qmail Of the four, source code is available free of charge for three of them. Can you guess which is the odd man out? :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I dynamically create functions without lambda?

2006-01-28 Thread Steven D'Aprano
gance of his one liners; what happens next? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Decoupling the version of the file from the name of the module.

2006-01-28 Thread Steven D'Aprano
ctical problem it is for Python, but if you have a rapidly changing module, with changes to the API, this is certainly a theoretical problem, if not a practical one. If it is not a problem in practice, why not? What do people do to avoid this? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Decoupling the version of the file from the name of the module.

2006-01-29 Thread Steven D'Aprano
impractical answer. Blaming the user is no real solution either. In old-time Windows land, installation programs would blindly nuke newer DLLs with older DLLs all the time. Under Linux, one convention is for shared libraries to include the version number in the file name, so that newer libraries were

Re: Returning a value from code string

2006-01-29 Thread Steven D'Aprano
and it pissed me off when I wrote to the newsgroup > asking "how do I do x,y,z?" and somebody writes back saying "you really > shouldn't want to do x,y,z..." when they really haven't a clue. But the million dollar question is, after you had explained what you wanted to accomplish (rather than how you thought it should be accomplished), did people agree that x,y,z was the right way to go about it? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Language Semantics: @ symbol??

2006-01-30 Thread Steven D'Aprano
igns, surely the first bazillion and a half hits would be email address? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Python vs C for a mail server

2006-01-30 Thread Steven D'Aprano
Volker Grabsch wrote: > Any programming language allows you to do strange/stupid stuff. But none > of them encourages it. One word: Intercal. :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Question about idioms for clearing a list

2006-01-31 Thread Steven Watanabe
ed? I think the first two are changing the list in-place, but why is that better? Isn't the end result the same? Thanks in advance. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Why checksum? [was Re: Fuzzy Lookups]

2006-01-31 Thread Steven D'Aprano
ou have the checksum, you don't need to read the file again)? Are there any other reasons? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Why checksum? [was Re: Fuzzy Lookups]

2006-02-01 Thread Steven D'Aprano
On Tue, 31 Jan 2006 13:38:50 -0800, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: >> This isn't a criticism, it is a genuine question. Why do people compare >> local files with MD5 instead of doing a byte-to-byte compare? Is it purely >&g

Re: OO conventions

2006-02-02 Thread Steven D'Aprano
raise KlassError("Can't foo an uninitialized Klass object.") else: # do something then you are just doing pointless make-work to fit a convention that doesn't make sense for your class. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread Steven D'Aprano
nvalid syntax See how much information is given by the traceback? If I just posted "SyntaxError: invalid syntax" to the newsgroup with no further information, what do you think the chances are anyone would guess the cause of the problem? So, how about trying again with the complete tra

Re: Another try at Python's selfishness

2006-02-03 Thread Steven D'Aprano
.foo(a) normal method foo So instances can have methods that they don't inherit from their class! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Steven D'Aprano
ass. But if bar does need to be a method, perhaps you want something like this: # for Python 2.2 and up class Foo: def bar(a,b): return a+b bar = staticmethod(bar) # for Python 2.4 and up class Foo: @staticmethod def bar(a,b): return a+b Foo().bar(1,2) works exactly the same as before, but your definition of bar doesn't need that extraneous "self" parameter. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Steven D'Aprano
o me that you are concerned about that extraneous "self" parameter >> for methods that don't need it: > > No, I wasn't talking about functions that don't use the "self" > parameter. I rarely ever have such functions. I just tried to make the > examp

Re: OO conventions

2006-02-03 Thread Steven D'Aprano
le the file. Don't let the user shoot themselves in the foot if they aren't technically sophisticated enough to realise they are shooting themselves in the foot. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Steven D'Aprano
two new identifiers ("x" and "self"), too? Sure, but now the call foo.bar has special meaning inside a def statement than elsewhere. Elsewhere, foo.bar is an attribute access, looking up attribute bar in foo's namespace. Using your syntax, in a def statement foo.bar is a pa

Re: Another try at Python's selfishness

2006-02-03 Thread Steven D'Aprano
hem, there is an apparent conflict So, most of the time, foo.bar looks up attribute "bar" in foo; but in a method definition, foo.bar assigns attribute "foo" in bar. That's special behaviour too, and it seems to me probably harder to live with and even more confusing than the behaviour you aim to remove. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Steven D'Aprano
On Fri, 03 Feb 2006 07:40:38 -0800, Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >... >> > Why shouldn't >> > def self.x(): >> > declare two new identifiers ("x" and "self"), too? >> >>

Re: newbie - script works in PythonWin - fails from Python

2006-02-03 Thread Steven D'Aprano
r anyone to help you. Is it a secret what DLL you are trying to call? What is "lib"? Googling on 0xeedfade suggests that it is an internal Delphi error, possibly an out-of-memory error. Are you calling a Delphi DLL? What does that exception mean? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Recursive function going infinite and I can't see why.

2006-02-04 Thread Steven D'Aprano
1 has a subtree with node 2 that has a subtree with node 3 that has a subtree with node 1 again, most recursive algorithms will never halt, just keep cycling through the tree forever. Could that be your problem? There is no way for us to tell from the information we've got. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: A problem with some OO code.

2006-02-04 Thread Steven D'Aprano
rited by the class B). > > Why I can't do the same thing in test.py and in PyObject.py? Here is your exception again: > line 582, in __makeLinkSafe > i = self.__ls_demanded_links.index( s_object ) > AttributeError: 'Obj' object has no attribute > '_Object__ls_demanded_links' This is not making sense to me. If self is an instance of Obj, the name-mangling rules will convert self.__ls_demanded_links to self._Obj__ls_demanded_links. The only thing I can guess is that somehow, somewhere, you have tried to manually set the class of an object. Something like this perhaps? >>> class Obj: ... __bar = "nothing" ... >>> class Object(Obj): ... __foo = "something" ... def foo(self): ... print self.__foo ... def bar(self): ... print self.__bar ... >>> x = Object() >>> x.__class__.__name__ = "Obj" >>> x.foo() something >>> x.bar() Traceback (most recent call last): File "", line 1, in ? File "", line 6, in bar AttributeError: Obj instance has no attribute '_Object__bar' That's the only way I can think of to get such an unusual error. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: numeric expression from string?

2006-02-04 Thread Steven D'Aprano
d way of doing this? Look into PyParsing: http://cheeseshop.python.org/pypi/pyparsing/1.3.3 If you read back over the Newsgroup archives, just in the last week or so, there was a link to a PyParsing tutorial. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Generators vs. Functions?

2006-02-05 Thread Steven D'Aprano
generators often far outweigh the tiny setup cost each time you call one. In addition, for any complex function with significant execution time, the call/resume time may be an insignificant fraction of the total execution time. There is little or no point in avoiding generators due to a misplaced and foolish attempt to optimise your code. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Python support a peek like method for its file objects?

2006-02-05 Thread Steven D'Aprano
del c fp.seek(-1, 1) # but be careful in text mode! break # now read the byte "for real" b = fp.read(1) if not b: # we've reached the end of the file break fp.close() I'm not sure exactly why you'd want to do this,

Re: Does Python support a peek like method for its file objects?

2006-02-05 Thread Steven D'Aprano
On Sun, 05 Feb 2006 19:25:21 +1100, Steven D'Aprano wrote: > On Sun, 05 Feb 2006 05:45:24 +, Avi Kak wrote: > >> Hello: >> >> Does Python support a peek like method for its file objects? >> >> I'd like to be able to look at the next byte

Re: Generators vs. Functions?

2006-02-05 Thread Steven D'Aprano
On Sun, 05 Feb 2006 09:49:21 +0100, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> So on the basis of my tests, there is a small, but significant speed >> advantage to _calling_ a function versus _resuming_ a generator. > > now add state handling to your mi

Back-end for python.org

2006-02-05 Thread Steven Bethard
Fredrik Lundh wrote: >> >> If you build it, they will come. >> > > http://pydotorg.dyndns.org:8000 Very cool. I'd love to see something like this on the actual website... Is the hope that in the real python.org version edits will show up immediately, as they do in your version? Or that the

Re: Generators vs. Functions?

2006-02-05 Thread Steven D'Aprano
On Sun, 05 Feb 2006 16:14:54 +, Neil Schemenauer wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> Have you actually measured this, or are you just making a wild >> guess? > > I haven't timed it until now but my guess it not so wild. I&#

Re: Python V2.4.2 source code

2006-02-06 Thread Steven D'Aprano
s why it wouldn't compile... *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about idioms for clearing a list

2006-02-06 Thread Steven D'Aprano
the name L, but the list instance still exists Perhaps it is arguable that there is no need for a clear method because L[:] = [] is so easy to do. Personally, while I agree that it is easy, it is hardly intuitive or obvious, and I too would prefer an explicit clear method for mutable sequences. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Question about idioms for clearing a list

2006-02-06 Thread Steven D'Aprano
On Mon, 06 Feb 2006 09:39:32 -0500, Dan Sommers wrote: > On Tue, 07 Feb 2006 01:01:43 +1100, > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> On Mon, 06 Feb 2006 13:35:10 +, Steve Holden wrote: >>>> I'm wondering why there is no 'clear'

<    95   96   97   98   99   100   101   102   103   104   >