There are a number of ways I could figure out whether I am dealing
with connection or filter log.
I could pass it in when creating the Parser, but that doesn't seem
very pythonic.
I could figure out the type of log file a particular instance of the
Parser is working with by looking at the format of the file. This
wouldn't be hard but it seems unnecessary.
It would be jiffy if I could find what kind of object instantiated
that particular parser. So if a FilterLog object instantiated it, the
parser would know to parse a Filter log.
Can the Parser object know who its Daddy is?
Thanks
If you have two different things to do, perhaps you should consider providing
two different APIs to do them.
>
>There are a number of ways I could figure out whether I am dealing
>with connection or filter log.
>
>I could pass it in when creating the Parser, but that doesn't seem
>very pythonic.
Guessing isn't very Pythonic.
>
>I could figure out the type of log file a particular instance of the
>Parser is working with by looking at the format of the file. This
>wouldn't be hard but it seems unnecessary.
>
>It would be jiffy if I could find what kind of object instantiated
>that particular parser. So if a FilterLog object instantiated it, the
>parser would know to parse a Filter log.
Make a FilterLogParser and a ConnectionLogParser, or make a Parser which
takes a parameter that tells it if it is parsing filter logs or
connection logs.
>
>Can the Parser object know who its Daddy is?
>
Inspecting the call stack or the execution context to decide what to do is
a really awful idea. It's complicated to implement, complicated to maintain,
complicated to read, and there's no reason to do it. Just do the simple
thing - add a parameter or make two separate APIs.
Jean-Paul
What makes you believe that?
> I could figure out the type of log file a particular instance of the
> Parser is working with by looking at the format of the file. This
> wouldn't be hard but it seems unnecessary.
>
> It would be jiffy if I could find what kind of object instantiated
> that particular parser. So if a FilterLog object instantiated it, the
> parser would know to parse a Filter log.
>
> Can the Parser object know who its Daddy is?
Yes, by Daddy telling him so. That's how nature does it, and how you
should do it. Or do you think that because DNA-tests are available to us
we should just put all kids into a big pool and make them find out who
their parents are themselves, once they grew up?
Diez
+1 QOTW
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/
Why is this newsgroup different from all other newsgroups?
>> Can the Parser object know who its Daddy is?
>
> Yes, by Daddy telling him so. That's how nature does it, and how you
> should do it. Or do you think that because DNA-tests are available to us
> we should just put all kids into a big pool and make them find out who
> their parents are themselves, once they grew up?
Oh, were you raised in a hippie commune in the Sixties too?
*wink*
--
Steven
Close. Australia.