Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'forgive': 0.05; 'output': 0.05; 'great.': 0.07; 'init': 0.07; 'none,': 0.07; 'referring': 0.07; 'created,': 0.09; 'executed': 0.09; 'ide': 0.09; 'method,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'referenced': 0.09; 'works.': 0.09; 'python': 0.11; '"run': 0.16; 'assignment.': 0.16; 'class:': 0.16; 'constructor.': 0.16; 'program?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:class': 0.16; 'subject:where': 0.16; 'throwaway': 0.16; 'top-level': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'all,': 0.19; 'bit': 0.19; 'module': 0.19; 'pointed': 0.19; 'unlike': 0.19; 'thanks.': 0.20; 'help.': 0.21; 'seems': 0.21; 'code,': 0.22; 'input': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User- Agent:1': 0.23; 'library,': 0.24; 'typical': 0.24; 'fairly': 0.24; '(or': 0.24; 'question': 0.24; 'sort': 0.25; "i've": 0.25; 'source': 0.25; 'class.': 0.26; 'nearly': 0.26; 'header:X -Complaints-To:1': 0.27; 'idea': 0.28; 'point': 0.28; 'function': 0.29; 'generally': 0.29; "doesn't": 0.30; 'statement': 0.30; "i'm": 0.30; 'included': 0.31; 'code': 0.31; 'towards': 0.31; 'about.': 0.31; 'trace': 0.31; 'anyone': 0.31; 'file': 0.32; 'class': 0.32; 'this.': 0.32; 'figure': 0.32; 'run': 0.32; 'maybe': 0.34; 'classes': 0.35; 'but': 0.35; 'there': 0.35; 'located': 0.36; 'really': 0.36; 'method': 0.36; 'charset:us- ascii': 0.36; 'thanks': 0.36; 'possible': 0.36; 'similar': 0.36; 'should': 0.36; 'throughout': 0.37; 'wrong': 0.37; 'being': 0.38; 'expected': 0.38; 'sometimes': 0.38; 'to:addr:python-list': 0.38; 'files': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'even': 0.60; 'new': 0.61; 'first': 0.61; 'great': 0.65; 'worth': 0.66; 'sound': 0.68; 'evening': 0.84; 'laid': 0.84; 'colleague': 0.91; 'spoke': 0.91; 'responses': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: Find out where a class is used throughout a program. Date: Thu, 5 Sep 2013 09:08:23 +0000 (UTC) References: <9d290db6-b9cb-41af-8107-e7f27d2da6d0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 174.32.174.36 User-Agent: XPN/1.2.6 (Street Spirit ; Linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378372134 news.xs4all.nl 15948 [2001:888:2000:d::a6]:47893 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53684 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