Re: altering an object as you iterate over it?

2006-05-20 Thread netvaibhav
bruno at modulix wrote: > fin = open(path, 'r') > fout = open(temp, 'w') > for line in fin: > if line.strip(): > fout.write(line) > fin.close() > fout.close() > > then delete path and rename temp, and you're done. And yes, this is > actually the canonical way to do this !-) What if there's a

Re: Scanning a file

2005-10-29 Thread netvaibhav
Steve Holden wrote: > Indeed, but reading one byte at a time is about the slowest way to > process a file, in Python or any other language, because it fails to > amortize the overhead cost of function calls over many characters. > > Buffering wasn't invented because early programmers had nothing b

Re: Scanning a file

2005-10-29 Thread netvaibhav
I think implementing a finite state automaton would be a good (best?) solution. I have drawn a FSM for you (try viewing the following in fixed width font). Just increment the count when you reach state 5. <---| || 0 0

Default argument to __init__

2005-10-10 Thread netvaibhav
Hi All: Here's a piece of Python code and it's output. The output that Python shows is not as per my expectation. Hope someone can explain to me this behaviour: [code] class MyClass: def __init__(self, myarr=[]): self.myarr = myarr myobj1 = MyClass() myobj2 = MyClass() m