Re: 1-liner to iterate over infinite sequence of integers?

2005-10-13 Thread Steven D'Aprano
Not everything needs to be a one-liner or a mysterious blackbox. You could even modify your function to take start and step arguments: def integers(start=1, step=1): x = start while True: yield x x += step for odd in integers(step=2): print odd for even in integers(0, 2):

Re: deleting a parameter's name as it is passed to a function

2005-10-14 Thread Steven D'Aprano
r. > The idea is to garbage collect the object as soon as possible, and this > may be sooner than when dosomestuff returns. What difference does that make? Why do you care when object a is garbage collected? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: output

2005-10-14 Thread Steven D'Aprano
t) Why are you calling self as if it were a function? Does now.now have a __call__ method? > if __name__ == "__main__": > n = today() > print "The year is", n.year I would guess that when you create an instance of class today, somewhere in that mess of calling the superclass, you have a print statement that prints the current time and date. That piece of code is being called twice. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem splitting a string

2005-10-15 Thread Steven D'Aprano
.extend(item.split('_') You can *almost* do that as a one-liner: L2 = [item.split('_') for item in mystr.split()] except that gives a list like this: [['this', 'NP'], ['is', 'VL'], ['funny', 'JJ']] which needs flattening. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-15 Thread Steven D'Aprano
al computer with the Apple. IBM's prediction at a time when everybody thought that computers would cost billions of dollars and be as large as a house. Trying to credit Microsoft for the invention of the PC is foolish to the extreme. Microsoft didn't even exist when the Apple II was bringing computers to ordinary people. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem splitting a string

2005-10-15 Thread Steven D'Aprano
On Sat, 15 Oct 2005 10:51:41 +0200, Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >... >> You can *almost* do that as a one-liner: > > No 'almost' about it... > >> L2 = [item.split('_') for item in mystr.split()]

Re: Comparing lists

2005-10-15 Thread Steven D'Aprano
looks O(log N) to me, and quite fast too: about 8 seconds to compare and separate two lists of one million items each. The craziest thing is, the amount of time it took to write and test two different algorithms was probably 1% of the time it would take to hunt up theoretical discussions of what the big O behaviour of the algorithms would be. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing lists

2005-10-15 Thread Steven D'Aprano
r. No I did not, because I didn't have a function to do it. You've got my source code. Knock yourself out to use it to test any function you like. > Supposing the OP had actually sorted > lists to begin with, then a single, simultaneous walk of the lists would > be about as fast as it can get. Very, very likely *faster* than > conversion to sets would be... Please let us know how you go with that. It should be really interesting to see how well your prediction copes with the real world. (Hint: another of those awkward little implementation details... how much work is being done in C code, and how much in pure Python? Just something for you to think about. And remember, an O(N) algorithm in Python will be faster than an O(N**2) algorithm in C... or is that slower?) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-15 Thread Steven D'Aprano
for less than the same hardware plus Windows. Talk is cheap -- I'm not aware of anyone who has actually seen these Linux PCs. I'd love to know either way. (Oh, and since I am in Australia, and we haven't yet been invaded by Walmart, I can't go and look for myself.) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-15 Thread Steven D'Aprano
petitor. [1] Or any other part of the rat. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-16 Thread Steven D'Aprano
why are consumers forced to make the choice of either paying for Windows with their laptop, or no laptop at all? You will notice that only 30% of servers run Windows (lots of competition in the server market) and over 90% of desktops (no competition in the desktop market). Coincidence? I think not.

Re: Microsoft Hatred FAQ

2005-10-16 Thread Steven D'Aprano
On Sun, 16 Oct 2005 05:26:51 +, John Bokma wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >> On Sun, 16 Oct 2005 00:47:09 +, John Bokma wrote: >> >>> Ok, let me spell it out for you: If all your applications are web >>> b

Re: Microsoft Hatred FAQ

2005-10-16 Thread Steven D'Aprano
other software suppliers. Is it possible for you to get your arguments even more wrong? What's next? Microsoft invented the transistor? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-16 Thread Steven D'Aprano
practices in *many* civil suits, and settled out of court many more, plus TWO American DoJ investigations by two different judges, plus Japan, the EU, and a number of individual European nations. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: "Microsoft has never made a computer in its existence."

2005-10-16 Thread Steven D'Aprano
On Sun, 16 Oct 2005 12:54:48 +0200, Fredrik Lundh wrote: > Steven D'Aprano wrote: > >> Microsoft has never made a computer in its existence. Not one. > > http://www.microsoft.com/xbox/ Does Microsoft actually make the Xbox or just sub-contract it out? Either way, y

Re: Comparing lists - somewhat OT, but still ...

2005-10-16 Thread Steven D'Aprano
)... Or, to put it another way: your student discovered something by running an experimental test of his code that he would never have learnt in a million years of analysis of his algorithm: the VAX compiler was very cleverly optimized. The fact that your student didn't understand the problem well enough to craft a good test of it is neither here nor there. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: subtle side effect of generator/generator expression

2005-10-16 Thread Steven D'Aprano
a single module, this behaviour >> can cause subtle bugs ? > > sure, in the same way as > > >>> f = open(filename) > >>> f.read() > 'hello world\n' > >>> f.read() # oops! > '' > > causes subtle bugs (that is, almost never) Are you saying that the bugs it causes aren't subtle? *wink* -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-16 Thread Steven D'Aprano
Right. Well, I think that's just demonstrated the quality of John's reasoning ability. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing lists

2005-10-16 Thread Steven D'Aprano
. So yet again, your triumph of theory is actually a victory for experiment. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing lists - somewhat OT, but still ...

2005-10-16 Thread Steven D'Aprano
I was searching text strings of less than a megabyte, for five or six targets. The Big O analysis I did was completely, 100% correct, and completely, 100% useless. Not just useless in that it didn't help me, but it actually hindered me, leading me to waste a day's work needlessly looking for a

Re: Comparing lists - somewhat OT, but still ...

2005-10-16 Thread Steven D'Aprano
se or average case, and are still perfectly useful. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-17 Thread Steven D'Aprano
all to just ignore the court's rulings as Microsoft has done, and continues to do. Twenty years ago, Microsoft were the knights in shining armour going to save Apple Macintosh from the Big Blue evil empire. But that was then, this is now, and unlike IBM, Microsoft hasn't yet learnt about ka

Re: [newbie]Is there a module for print object in a readable format?

2005-10-17 Thread Steven D'Aprano
""" for item in L: if type(item) == list: multiline_print(item, indent + "") else: print indent + "|_" + str(item) Hope this helps. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: [newbie]Is there a module for print object in a readable format?

2005-10-17 Thread Steven D'Aprano
hel. They do different work. Is there > James> another module which do this kind of job? > > from pprint import pprint > pprint(object) I don't think that even comes *close* to what James wants. py> import pprint py> pprint.pprint([1,2,3,4,[0,1,2], 5]) [1, 2, 3, 4, [0, 1, 2], 5] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-17 Thread Steven D'Aprano
y. Microsoft is a collection of human beings. They don't get to excuse anti-social behaviour on the basis that they're only trying to make money. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Hygenic Macros

2005-10-18 Thread Steven D'Aprano
tried coming up with better names for your arguments than A and B? Many people find that using self-documenting variable names helps make code easier to understand. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: override a property

2005-10-18 Thread Steven Bethard
Robin Becker wrote: > ## my silly example > class ObserverProperty(property): > def __init__(self,name,observers=None,validator=None): > self._name = name > self._observers = observers or [] > self._validator = validator or (lambda x: x) > self._pName = '_' + nam

Re: Microsoft Hatred FAQ

2005-10-18 Thread Steven D'Aprano
is, or at least should be, although sadly when we allow the psychopaths to make the rules, they tend to make rules that allow themselves to prosper at our expense. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Hygenic Macros

2005-10-18 Thread Steven D'Aprano
On Tue, 18 Oct 2005 13:42:21 -0700, Robert Kern wrote: > Steven D'Aprano wrote: >> On Mon, 17 Oct 2005 22:23:43 -0700, David Pokorny wrote: >> >>>Hi, >>> >>>Just wondering if anyone has considered macros for Python. I have one >>>good use

Re: [newbie]Is there a module for print object in a readable format?

2005-10-19 Thread Steven D'Aprano
On Wed, 19 Oct 2005 09:39:48 +0800, James Gan wrote: > Hi, Steven > > :) width parameter do the magic : > > >>> pprint.pprint([1,2,3,4,[0,1,2,[3,4]],5], width=1,indent=4) > [ 1, > 2, > 3, > 4, > [ 0, > 1, >

Re: Python variables are bound to types when used?

2005-10-19 Thread Steven D'Aprano
ariable" as a synonym for "name" when talking about Python code. Do people think I am wrong to do so? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: sqlstring -- a library to build a SELECT statement

2005-10-19 Thread Steven Bethard
[EMAIL PROTECTED] wrote: > Jason Stitt wrote: > >>Using // for 'in' looks really weird, too. It's too bad you can't >>overload Python's 'in' operator. (Can you? It seems to be hard-coded >>to iterate through an iterable and look for the value, rather than >>calling a private method like some other

Re: Microsoft Hatred FAQ

2005-10-20 Thread Steven D'Aprano
or the board of directors of a company. The board of directors are also employees of the company. That's why the company can fire them. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: classmethods, class variables and subclassing

2005-10-21 Thread Steven Bethard
Andrew Jaffe wrote: > Hi, > > I have a class with various class-level variables which are used to > store global state information for all instances of a class. These are > set by a classmethod as in the following (in reality the setcvar method > is more complicated than this!): > > class sup(

Re: best way to replace first word in string?

2005-10-21 Thread Steven D'Aprano
ord): """Replace the first word of source with newword.""" return newword + " " + "".join(source.split(None, 1)[1:]) import time def test(): t = time.time() for i in range(1): s = replace_word("aa to become", "/aa/&

Re: Microsoft Hatred FAQ

2005-10-21 Thread Steven D'Aprano
n encouraged when done by small businesses in a competitive market can easily become harmful and bad for the economy when done by a monopolist or duopolist in an uncompetitive market. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-22 Thread Steven D'Aprano
On Fri, 21 Oct 2005 21:47:27 -0700, David Schwartz wrote: > > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> That's basic economics. Something which can be allowed or ignored or even >> encouraged when do

Re: A question about searching with multiple strings

2005-10-22 Thread Steven D'Aprano
t was just a list I could say > "sublist = []", what do I use for self defined classes? See my next post (to follow). > I Am also > usure how to go about creating a function that will accept any number > of parameters. def func1(*args): for arg in args: print arg def func2(mandatory, *args): print "Mandatory", mandatory for arg in args: print arg Does that help? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: A question about searching with multiple strings

2005-10-22 Thread Steven D'Aprano
earch = SearchOneAnd for source in source_list: if search(source, height, length, function, kwargs): found.append(source) return found Now pass all_items to SearchAll as the first argument, and it will search through them all and return a list of all the items which match

Re: best way to replace first word in string?

2005-10-22 Thread Steven D'Aprano
- t2 ... assert s1 == s2 ... print t1, t2 ... py> x = 10 py> tester(x) 3.24212408066 0.01252317428 py> tester(x) 2.58376598358 0.01238489151 py> tester(x) 2.76262307167 0.01474809646 The string formatting is two orders of magnitude faster than the concatenation. The speed difference becomes even more obvious when you increase the number of strings being concatenated: py> tester(x*10) 2888.56399703 0.13130998611 Almost fifty minutes, versus less than a quarter of a second. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: best way to replace first word in string?

2005-10-22 Thread Steven D'Aprano
On Sat, 22 Oct 2005 21:05:43 +1000, Steven D'Aprano wrote: > The thing is, a > *single* string concatenation is almost certainly more efficient than a > single string concatenation. Dagnabit, I meant a single string concatenation is more efficient than a single string rep

Re: Python vs Ruby

2005-10-22 Thread Steven D'Aprano
apabilities already built-in that the C programmer has to create from scratch. For many tasks, Python provides even more capabilities, in a language that demands less syntax scaffolding to make things happen. Every line of code you don't have to write not only is a bug that just can't happen, but it also saves time and labour. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Binding a variable?

2005-10-22 Thread Steven D'Aprano
e > namespace, and returns that value. Or something even conceptually simpler than having to muck about with looking up different namespaces: class Data: def __init__(self, obj): self.value = obj def __str__(self): return self.value temp = Data(5) L = [temp] print L

Re: best way to replace first word in string?

2005-10-22 Thread Steven D'Aprano
sonal preference. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-22 Thread Steven D'Aprano
goes for companies as >> well. > > I am not saying Microsoft did not know the law. I am saying that no > rational person could have expected the law to be applied to Microsoft > that way it was. No rational person could have expected that Microsoft would be expected to obey the law? You have a bizarre concept of "rational". > The law *must* put a person on notice of precisely what > conduct it prohibits. However, in this case, the law's applicability was > conditioned on an abritrary and irrational choice of what the relevant > market was. Rght. Because as we all know, micro-controllers for VCRs and desktop PCs are the same market. If you want to run common business applications like word processing, book-keeping, web-browsing, etc, you have a free choice between running those applications on a desktop PC or a VCR. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-22 Thread Steven D'Aprano
ommie pinko fascist Jew Nazi". Mike Meyer has got just as much right to live in America as David Schwartz. Nice to see how quickly Americans' supposed love of freedom disappears once they are exposed to views that contradict their own. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: best way to replace first word in string?

2005-10-22 Thread Steven D'Aprano
order of 500 HOURS. In other words, yes the char conversion adds some time to the process, but for large numbers of iterations, it gets swamped by the time taken repeatedly copying chars over and over again. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: downloading web images

2005-10-23 Thread Steven D'Aprano
ust > wandering if there is a better way of doing this. What do you mean that the file does not appear to be an image? If it works fine and you can open the image, then what is the problem? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: best way to replace first word in string?

2005-10-23 Thread Steven D'Aprano
tements of the form s = s + "abc" and s += "abc" are now performed more efficiently in certain circumstances. This optimization won't be present in other Python implementations such as Jython, so you shouldn't rely on it; using the join() method of strings is still recomm

Re: Microsoft Hatred FAQ

2005-10-23 Thread Steven D'Aprano
On Sun, 23 Oct 2005 11:43:44 -0700, David Schwartz wrote: > You are dishonest, lying sack of shit. And David posts his true colours to the mast at last. When rational argument and logical thoughts fails, fall back on personal insults. -- Steven. -- http://mail.python.org/mail

Re: Microsoft Hatred FAQ

2005-10-23 Thread Steven D'Aprano
ut you state in the very next sentence that they are. > And if you go by application, Windows, Linux, and FreeBSD > are all interchangeable -- there is nothing significant you can do on > one that you can't do on the other. Try telling that to a business that needs to do computerised bo

Re: Tricky Areas in Python

2005-10-24 Thread Steven D'Aprano
r doesn't actually take an argument to set the property too. Is that it, or have a missed a cunningly hidden deeper problem? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Steven D'Aprano
n different orders. Sorting those two lists should give the same order, correct? py> L1.sort() py> L2.sort() py> L1 [Set([1]), Set([2]), Set([3])] py> L2 [Set([2]), Set([3]), Set([1])] Should, but doesn't. Oops. That's a bug. Personally, I argue that sorting is something th

Re: Tricky Areas in Python

2005-10-24 Thread Steven Bethard
Alex Martelli wrote: > >>>class Base(object) >>>def getFoo(self): ... >>>def setFoo(self): ... >>>foo = property(getFoo, setFoo) >>> >>>class Derived(Base): >>>def getFoo(self): >> [snip] > the solution, in Python 2.4 and earlier, is to use > one extra

Re: [OT] Re: output from external commands

2005-10-24 Thread Steven Bethard
darren kirby wrote: > quoth the Fredrik Lundh: > >>(using either on the output from glob.glob is just plain silly, of course) > [snip] > > It is things like this that make me wary of posting to this list, either to > help another, or with my own q's. All I usually want is help with a specific

Re: namespace dictionaries ok?

2005-10-25 Thread Steven D'Aprano
in turn pass them on to other functions, you probably shouldn't be using deeply nested function calls and should be looking for another program structure. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: more than 100 capturing groups in a regex

2005-10-25 Thread Steven D'Aprano
o you really think that the regular expression needed to do that would be maintainable? I'm also curious, what sort of usage case would need ten thousand capturing groups? I'd love to see the performance, especially if all ten thousand of them do backtracking. -- Steven. -- http://m

Re: overiding assignment in module

2005-10-25 Thread Steven D'Aprano
n do something like that. Choose a different language. There is no assignment method in Python. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: more than 100 capturing groups in a regex

2005-10-25 Thread Steven D'Aprano
hose cases, the limit isn't really arbitrary. In cases of genuinely arbitrary limits, I agree they are pointless and annoying (as opposed to having a point but still being annoying). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: more than 100 capturing groups in a regex

2005-10-25 Thread Steven D'Aprano
On Tue, 25 Oct 2005 06:30:35 -0700, Iain King wrote: > > Steven D'Aprano wrote: >> On Tue, 25 Oct 2005 05:17:52 -0700, Iain King wrote: >> >> > >> > Fredrik Lundh wrote: >> >> Joerg Schuster wrote: >> >> >> >> > I

Re: Would there be support for a more general cmp/__cmp__

2005-10-25 Thread Steven D'Aprano
huge difference whether "nuclear bomb in New York" is true or not. In fact, I'm quite surprised that Antoon should object to "in" as "this doesn't define a mathematical ordering, the subset relationship does" when "subset" is just "in&quo

Re: Microsoft Hatred FAQ

2005-10-25 Thread Steven D'Aprano
are vendors competing on price and features. Only those blinded by ideology fail to see the connection. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-25 Thread Steven D'Aprano
But that's the whole point: they *can't* do whatever they want, and certain behaviours *are* crimes. Just because Microsoft executives wear business suits instead of torn jeans or dirty sweatshirts doesn't make them beyond the law. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-25 Thread Steven D'Aprano
al behaviour began long before OS/2 was even planned. It began in the mid 1970s, with MS DOS. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-25 Thread Steven D'Aprano
e, they aren't illegal, and even if they are illegal, they shouldn't be." The first two points are factually wrong, and the third is an opinion based on the concept, as far as I can see, that Microsoft should be allowed to do anything they like, even if those actions harm others.

Re: Newbie question: string replace

2005-10-25 Thread Steven D'Aprano
file as a string, try something like this: py> s = open('filename', 'r').read() py> print s service A = { params { dir = "c:\test", username = "test", password = "test" } } py> target = 'username = ' py> p1 = s.find(target) + len(target) py> p2 = s.find(',\n', p1) py> s = s[:p1] '"J. Random User"' + s[p2:] That's not good enough for professional code, but it will get you started. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-25 Thread Steven D'Aprano
On Tue, 25 Oct 2005 16:54:13 +, John Wingate wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >> That would be a good guess, except that Microsoft's predatory and illegal >> behaviour began long before OS/2 was even planned. It began in the mid >> 197

Re: Documentation for iteration in mappings

2005-10-25 Thread Steven D'Aprano
dig out an old "What's New" for version 2.2 to find it, hidden away in a section on iterators: http://aspn.activestate.com/ASPN/docs/ActivePython/2.2/whatsnew/2.2/index.html#SECTION00040 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Microsoft Hatred FAQ

2005-10-25 Thread Steven D'Aprano
On Tue, 25 Oct 2005 11:51:02 -0700, David Schwartz wrote: > > "Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > >> The first two points are factually wrong, and the third is an opinion >> based on the concept,

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-25 Thread Steven D'Aprano
stupid mistakes like that, by encouraging people to hit send after they've said the first thing they thought of, without actually reading through the email to see if there are other issues that need to be dealt with. [1] There are no sloths in Borneo. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Steven Bethard
Antoon Pardon wrote: > Christopher Subich schreef : > >> Antoon Pardon wrote: >>> >>>from decimal import Decimal >>> >>>Zero = Decimal(0) >>> >>>cmp( ( ) , Zero) >>> -1 >>> >>>cmp(Zero, 1) >>> -1 >>> >>>cmp(1, ( ) ) >>> -1 >> >> I'd argue that the wart here is that cmp doesn't throw an exception,

Re: Python vs Ruby

2005-10-27 Thread Steven D'Aprano
On Wed, 26 Oct 2005 22:35:33 -0500, Andy Leszczynski wrote: > Steven D'Aprano wrote: > >> >> Every line = more labour for the developer = more cost and time. >> Every line = more places for bugs to exist = more cost and time. >> > > The place I work a

Re: loop help

2005-10-27 Thread Steven D'Aprano
is? Please explain your problem first. In particular, show us the code that you use that "it (what?) starts accumulating". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: time conversion

2005-10-27 Thread Steven D'Aprano
hours = int(t) t = (t - hours)*60 minutes = int(t) seconds = (t - minutes)*60 return (hours, minutes, seconds) def Seconds_HMS(h): """Convert time t in seconds to hours minutes seconds.""" hours, t = divmod(t, 60*60) minutes, seconds = divmod(t, 60) return (hours, minutes, seconds) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to replace all None values with the string "Null" in a dictionary

2005-10-28 Thread Steven D'Aprano
'item3': 42, 'item4': 'Null', 'item5': 15} as needed. And I really, really hope this is of no hope whatsoever! ;-) -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-28 Thread Steven D'Aprano
o unnecessary local variables, and is not unnecessarily terse. Unfortunately, it doesn't solve the original poster's problem, because his file is too big to read into memory all at once -- or so he tells us. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-28 Thread Steven D'Aprano
pecially valuable if your files really are huge. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question: string replace

2005-10-28 Thread Steven D'Aprano
On Fri, 28 Oct 2005 12:27:36 -0700, [EMAIL PROTECTED] wrote: > hm...Is there a way to get rid of the newline in "print"? Yes, by using another language *wink* Or, instead of using print, use sys.stdout.write(). -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: How do I sort these?

2005-10-28 Thread Steven D'Aprano
seq2)) is not quite a null-op, because some type information is lost, e.g. lists and strings are converted into tuples. """ return zip(*L) As you can see, the documentation for unzip is longer than the code itself :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-29 Thread Steven D'Aprano
handle(f) finally: try: f.close() except: print "The file could not be closed; see your sys admin." except: print "The file could not be opened." -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-30 Thread Steven D'Aprano
On Sat, 29 Oct 2005 16:41:42 -0700, Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >... >> I should also point out that for really serious work, the idiom: >> >> f = file("parrot") >> handle(f) >> f.close() >&g

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Steven D'Aprano
ist of valid keywords into another dictionary to > make it easy to specify default values for all the parameters as well. Here's a thought... instead of passing a class instance which you access with obj.name, why not pass a dict which you access with dict[name]? I don't understand

Re: Automatic binding of **kwargs to variables

2005-10-30 Thread Steven D'Aprano
hat when you change your web form to use "number" instead of "num", you only have to change your code in one place. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-10-30 Thread Steven D'Aprano
On Sun, 30 Oct 2005 08:35:12 -0700, Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >... >> > Don't ever catch and ``handle'' exceptions in such ways. In particular, >> > each time you're thinking of writing a bare &#x

Re: Scanning a file

2005-10-30 Thread Steven D'Aprano
Alex Martelli wrote: > Steven D'Aprano <[EMAIL PROTECTED]> wrote: >... > >>>No. But if you get a totally unexpected exception, >> >>I'm more concerned about getting an expected exception -- or more >>accurately, *missing* an expected exce

Re: Scanning a file

2005-10-31 Thread Steven D'Aprano
David Rasmussen wrote: > Steven D'Aprano wrote: > >> On Fri, 28 Oct 2005 06:22:11 -0700, [EMAIL PROTECTED] wrote: >> >>> Which is quite fast. The only problems is that the file might be huge. >> >> >> What *you* call huge and what *Python* calls

Re: data hiding/namespace pollution

2005-10-31 Thread Steven D'Aprano
thout the need for declaring variables and/or attributes. No doubt there will be some who disagree. Let me postscript my comments with YMMV, and remind folks that even if declarations are the best thing since the transistor, Python currently doesn't have them and all the arguing in the world won't change that. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: mixin helper class for unknown attribute access?

2005-10-31 Thread Steven D'Aprano
ine 1, in ? AttributeError: Example instance has no attribute 'aeg' Your __getattr__ code is completely unnecessary. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: mixin helper class for unknown attribute access?

2005-10-31 Thread Steven D'Aprano
else: raise AttributeError("No such attribute.") Of the two approaches, I would say the second is marginally less of a bad idea. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: mixin helper class for unknown attribute access?

2005-10-31 Thread Steven D'Aprano
l-style code) it won't work. __slots__ only work with new-style classes, not classic classes. Before using __slots__, read this: http://www.python.org/doc/current/ref/slots.html Then read this recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: data hiding/namespace pollution

2005-10-31 Thread Steven Bethard
Alex Hunsley wrote: > The two main versions I've encountered for data pseudo-hiding > (encapsulation) in python are: > > method 1: > > _X - (single underscore) - just cosmetic, a convention to let someone > know that this data should be private. > > > method 2: > > __X - (double unders

Re: Python's website does a great disservice to the language

2005-11-01 Thread Steven D'Aprano
onfused and gone here: http://www.pythonline.com/ And then you might like to point us at a language site or two that your boss considers "professional". -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Scanning a file

2005-11-02 Thread Steven D'Aprano
ounting bytes -- at least if you want reliable, accurate counts and not just "number of frames, plus some file-specific random number". And heaven help you if you want to support MPEGs that are slightly broken... (It has to be said, depending on your ultimate needs, "close enough" may very well be, um, close enough.) Good luck! -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Attributes of builtin/extension objects

2005-11-02 Thread Steven Bethard
George Sakkis wrote: > - Where do the attributes of a datetime.date instance live if it has > neither a __dict__ nor __slots__ ? > - How does dir() determine them ? py> from datetime import date py> d = date(2003,1,23) py> dir(date) == dir(d) True py> for attr_name in ['day', 'month', 'year']: ...

Re: Most efficient way of storing 1024*1024 bits

2005-11-02 Thread Steven D'Aprano
me search speeds. Or forget about manipulating bits, and just store your data as bools in a list. Explain your problem a little better, and you may get some better advice. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting a function name from string

2005-11-02 Thread Steven D'Aprano
than not, any time you think you want to evaluate strings, you don't need to. For instance, instead of passing around the name of the function as a string: s = "someFunction" eval(s)() you can pass around the function as an object: s = someFunction # note the lack of brackets s() -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: reading internet data to generate random numbers.

2005-11-02 Thread Steven D'Aprano
ible for that. > Randomness is a deep subject. This is certainly true. I love the Dilbert cartoon where Dilbert is on a tour of Accounting. He comes across a troll sitting at a desk chanting "Nine, nine, nine, nine, ...". His guide says, "This is our random number generato

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
are two possible fixes, either by prohibiting instance variables > with the same name as class variables, which would allow any reference > to an instance of the class assign/read the value of the variable. Or > to only allow class variables to be accessed via the class name itself. The

Re: OT - Re: Microsoft Hatred FAQ

2005-11-03 Thread Steven D'Aprano
even be markets where Microsoft has *not* been able -- or cared to -- capture a monopoly. Accounting software comes to mind. But just because Microsoft did not, or was unable to, illegally squelch competition in one market does not excuse them for doing so in another. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list

Re: Class Variable Access and Assignment

2005-11-03 Thread Steven D'Aprano
A.a. On the other hand, if this happened: py> class A: ... a = [] ... py> b = A() py> b.a.append(None) py> print b.a, A.a [None], [] *then* you should be surprised. (Note that this is not what happens: you get [None], [None] as expected. The difference is that append modifies the

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