[Tutor] Lexer implementation
Hi All, Is there a classical way to implement a lexer in Python without using a parser toolkit? Something like the lexer MJD illustrates in Higher Order Perl, section 8.1.2. It's even better if it can act on a stream instead of a string. Best regards, Jason Doege ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Dynamically changing a class
Hi All, I'd like to change the behavior of a class' member function dynamically such that, once changed, all objects of the type would see the new behavior. For instance: >>> class MyClass (object) : def mfunc(self, data): print 'pre change behavior' >>> aMyClassObj = MyClass() >>> aMyClassObj.mfunc(data) pre change behavior >>> def MyClass.mfunc(self, data): #this does not work :-( print 'post change behavior' >>> aMyClassObj.mfunc(data) post change behavior Does anyone have any guidance on how to accomplish this? I'd also like to be able to add and delete attributes, similarly. Best regards, Jason Doege ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Dynamically changing a class
Thanks for the good and useful information on this. Now for the why... I am building an API and for various reasons I have chosen Python to implement it. I'd like to separate the implementation from the interface as, for instance, C++ does with separate .hpp and .cpp files. Apart from defining a class with a bunch of empty methods and then redefining them, I have not seen a good way to do this in Python. Can you recommend the Pythonic way to do this? Best regards, Jason Doege ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor