Re: Exec inside a class method to call other class methods?



On Dec 25, 6:35 pm, "David Stanek" <dsta...@xxxxxxxxxxx> wrote:
You won't need the dictionary at all if each type has a parse method.

How do you know what type to use if you don't have a if...elif...,
dictionary, getattr, or some other sort of dispatching? Look at his
requirements: there is a variable called "data_type" that controls how
to parse the data. Whether he uses the variable to figure out what
method to call, or to figure out what type of object to create to call
the parse method of, some sort of dispatching is necessary. This is
inevitable when type information is supplied through the input.

To be honest I am a little concerned over the more-or-less knee-jerk
suggestions to refactor this into a highly object-oriented approach.
For the task at hand the OP's approach is fine (aside from the use of
exec).


Carl Banks
.



Relevant Pages

  • Text parsing and substitution
    ... parse the line, ... load a hashmap with the key, ... I was thinking this sort of logic but a little apprehensive how elastic ...
    (comp.lang.perl.misc)
  • Re: Typed named groups in regular expression
    ... If you do a ot of that sort of thing in many programs ... then the name of a type conversion function to all ... pyparsing might just be this sort of framework, ... parse actions to elements within a grammar. ...
    (comp.lang.python)
  • Re: Read webpage with VB app
    ... > Is there a simple way to read (and parse) a webpage with a VB.net ... Right now I can sort of read a page but it's a framed page ... "Programming is an art form that fights back" Empower ASP.NET with IntraWeb ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Question about MSComm
    ... If you have no way to parse the data without a timeout, ... of some sort is what you have to do. ... parse it as it arrives and I don't have to wait for it to halt (a tricky ... all of the code you've already written for parsing, ...
    (microsoft.public.vb.controls)
  • Re: VFS: C99 sparse format for struct vfsops
    ... You should look at kobj, it's precisely this sort of dynamic ... dispatching that it was designed to support. ...
    (freebsd-current)