Who is your daddy: Can I find what object instantiates anotherobject?

H

hubritic

I want to build a parser object that handles two different log file
formats. I have an object that handles Connection logs and an object
for Filter logs. Each will instantiate a Parser object, passing in
the path to individual log files.

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
 
D

Diez B. Roggisch

hubritic said:
I want to build a parser object that handles two different log file
formats. I have an object that handles Connection logs and an object
for Filter logs. Each will instantiate a Parser object, passing in
the path to individual log files.

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.

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
 
A

Aahz

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?

+1 QOTW
 
S

Steven D'Aprano

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*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,293
Messages
2,571,502
Members
48,189
Latest member
StaciLgf76

Latest Threads

Top