Re: Am I missing something with Python not having interfaces?
Am Freitag 09 Mai 2008 10:19:45 schrieb Bruno Desthuilliers: very often sees do-nothing catch-all try/catch blocks in Java - which is way worse than just letting the exception propagate. I find all this totally pointless, because there's just no way for a compiler to check if your code is logically correct. But it's enough if the called method exists and returns the correct type. At least it prevents a crash. Then providing an appropriate default in the base class is enough too. Only working *if* there is a base-class, and not only convention for should-have-methods. That's the point. Interfaces garantee that a duck is a duck, an not only a chicken that quack. Who cares if it's a chicken as long as it quacks when you ask her to ? Now *This* is the whole point of chicken^Mduck typing, isn't it ?-) Ducks can also swim and fly. And if you need a really duck, If you're code expects something that quacks, swims and flies, anything that quacks, swims and flies is ok. You just don't care if it's a duck or a flying whale with a quacking device tied to it. Not the point. Of course, in the practical world that all doesn't matter. But in the theoretical world of the big coding farms, called business, that's one cornerstone of success, in the tinking of managers and so. Sorry, I live in a very practical world - and we're by no mean running out of business here... Like i said. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I missing something with Python not having interfaces?
Am Mittwoch 07 Mai 2008 22:39:30 schrieb Luis Zarrabeitia: There you have it, interfaces are not enough to ensure that the implementors actually implement the methods. They are useful for warning at compile time if there is a missing method, but nothing more. It's not the fault of the enviroment, if the coder is to stupid to use it the right way. I believe you could achieve a very similar warning in python using some kind of Interface metaclass (too lazy right now to hack a proof of concept, but it looks doable). Of course. And unlike Javas interfaces, it ensure a more dynamic coding-style, without great tools which check all the time for correct behaviour. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I missing something with Python not having interfaces?
Am Donnerstag 08 Mai 2008 00:12:26 schrieb [EMAIL PROTECTED]: very often sees do-nothing catch-all try/catch blocks in Java - which is way worse than just letting the exception propagate. I find all this totally pointless, because there's just no way for a compiler to check if your code is logically correct. But it's enough if the called method exists and returns the correct type. At least it prevents a crash. Interfaces work at compile-time, while method-stubs raise at their first call, so in worst case, never. And then ? If it's never called, why bother implementing it ? You never can't say when it's called at least, that's the point. That's the point. Interfaces garantee that a duck is a duck, an not only a chicken that quack. Who cares if it's a chicken as long as it quacks when you ask her to ? Now *This* is the whole point of chicken^Mduck typing, isn't it ?-) Ducks can also swim and fly. And if you need a really duck, but have onyl a chicken while the coder was to bored to make one... Of course, in the practical world that all doesn't matter. But in the theoretical world of the big coding farms, called business, that's one cornerstone of success, in the tinking of managers and so. -- http://mail.python.org/mailman/listinfo/python-list
Re: Am I missing something with Python not having interfaces?
Am Dienstag 06 Mai 2008 16:07:01 schrieb Mike Driscoll: If so, then it looks like an Interface is a generic class with method stubs. You can do that with Python just as easily by creating empty methods with just the pass keyword. Well, no. It's a litte different. Interfaces force to implement methods. Simple inheritance with method-stubs can't garantee that a specific method is reimplementat in a sub-class. Interfaces work at compile-time, while method-stubs raise at their first call, so in worst case, never (when the developer is available). Since it's just a construct to implement polymorphism, I don't think you'll lose anything. However, Python does not require you to re- implement every method of the class it is inheriting from. That's the point. Interfaces garantee that a duck is a duck, an not only a chicken that quack. You can just override those that you want and leave the others alone. Not always desirable. But often enough ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: getting the line just before or after a pattern searched
[EMAIL PROTECTED] wrote: i have a file something like this abcdefgh ijklmnopq 12345678 rstuvwxyz . . . 12345678 . whenever i search the file and reach 12345678, how do i get the line just above and below ( or more than 1 line above/below) the pattern 12345678 and save to variables? thanks source = file(bla).read().split('\n') for i, line in enumerate(source): if line == '12345678': print '\n'.join( source[i-1:i+1] ) Something like this, for example. Of course, you must also secure that i-1 isn't smaller than zero. mfg Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: How to check...
Lad wrote: How can I check that a string does NOT contain NON English characters? try: foobar.encode('ascii') except: bla or use string.ascii_letters and enhance it. mfg Daniel -- http://mail.python.org/mailman/listinfo/python-list