Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53684

Re: Find out where a class is used throughout a program.

From Dave Angel <davea@davea.name>
Subject Re: Find out where a class is used throughout a program.
Date 2013-09-05 09:08 +0000
References <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.83.1378372134.5461.python-list@python.org> (permalink)

Show all headers | View raw


On 4/9/2013 12:32, Azureaus wrote:

> Hi All,
> I'm fairly new to Python so please forgive me If I sound confused or include anything a bit irrelevant. I've had some great responses from this group already though so thanks.
>
> I have a source file that is laid out roughly like
>
> class:
> class methods
> methods 
> init statement

Perhaps you mean the __init__() method ?  This method is invoked when an
object of this class is created, and generally has the job of
initializing the instance data.  There may also (or instead) be a
__new__() method, which is the constructor.

> class:
> method
>
> It doesn't seem to have a run method unlike other similar source files I have so it seems to be that this is being referenced from other files and is almost a 'utility file'.

A method is a function located inside a class.  i think by "run method"
you are referring to top-level code.  That is code that is executed when
the script/module is first loaded.  You are right that if there is no
top-level code, then the file must be intended as a module (or library,
as it is sometimes called).  However nearly every module will have some
top-level code, even if it's only an import statement or a class
instance assignment.

>
> To try and make this question as general as possible - is there a way of finding out / visualising where a particular class is called/used throughout a program? I need to find out the way in which these classes are being used and their typical input (and where the output from these are going) so I can have a play around and really figure out how it works. Without a run method to call, or an idea of expected input/output it's difficult. Also without some sort of trace it's difficult.

As others have pointed out, an IDE can help greatly with this.  But your
first line of attack should be the documentation included with the
file(s).  If there's none, then perhaps it's throwaway code, and not
worth worrying about.

>
> I spoke to colleague and was told to look into dir() method in a Python shell which I will do this evening but if anyone has any suggestions that would be great. Even better if you think this is what I'm after a quick example/use case would be even better. Or maybe I'm looking at this the wrong way and you can point me towards some docs?
> Thanks for your help.

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Find out where a class is used throughout a program. Azureaus <lo0446@my.bristol.ac.uk> - 2013-09-04 09:32 -0700
  Re: Find out where a class is used throughout a program. dieter <dieter@handshake.de> - 2013-09-04 22:08 +0200
    Re: Find out where a class is used throughout a program. Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2013-09-04 22:40 +0200
  Re: Find out where a class is used throughout a program. Terry Reedy <tjreedy@udel.edu> - 2013-09-04 17:36 -0400
  Re: Find out where a class is used throughout a program. alex23 <wuwei23@gmail.com> - 2013-09-05 10:11 +1000
  Re: Find out where a class is used throughout a program. Roy Smith <roy@panix.com> - 2013-09-04 21:48 -0400
  Re: Find out where a class is used throughout a program. Steven D'Aprano <steve@pearwood.info> - 2013-09-05 02:16 +0000
  Re: Find out where a class is used throughout a program. Dave Angel <davea@davea.name> - 2013-09-05 09:08 +0000
  Re: Find out where a class is used throughout a program. Azureaus <lo0446@my.bristol.ac.uk> - 2013-09-05 05:42 -0700
    Re: Find out where a class is used throughout a program. Chris Angelico <rosuav@gmail.com> - 2013-09-05 22:53 +1000

csiph-web