Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attribute': 0.05; 'case.': 0.05; 'class,': 0.07; 'attribute.': 0.09; 'instance.': 0.09; 'subject:Getting': 0.09; 'subject:module': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.10; 'stored': 0.10; 'all?': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'string': 0.17; 'wrote:': 0.17; 'have:': 0.17; 'instance': 0.17; 'string,': 0.17; 'developer': 0.19; 'module': 0.19; 'trying': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'class.': 0.23; 'this:': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'class': 0.29; "i'm": 0.29; 'figure': 0.30; 'asking': 0.32; 'could': 0.32; 'print': 0.32; 'anyone': 0.33; 'equal': 0.33; 'path': 0.35; 'really': 0.36; 'but': 0.36; 'method': 0.36; 'does': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'there,': 0.38; 'advice': 0.39; 'received:192': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'offer': 0.65; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72 Date: Tue, 13 Nov 2012 04:36:30 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: Some Developer Subject: Re: Getting module path string from a class instance References: <50A1EAE7.1090700@googlemail.com> In-Reply-To: <50A1EAE7.1090700@googlemail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:5VWtTzdVqSBxnLKhexi3sUsNcmoUkoioNSqQdrv+Gm0 3CNSlLcvsNpBsUPufIzO4m91lXqi225+NWTremj2NE+kX34vGx 6ioedg9LGJG8bYq9BZra5lC/UJ0bIFzoc/YsAEFne5idq2cqVq c2rz7RX2JiAD4f5eH3eNaTDCU9lkvrQSpcbOHW8j6q09Zt5T+1 qsgZIlVoiZUPNgm4SWd6DcopLNBuruYAdkRzLv74Y8BNG+jQcp AxrwABmATuHOZE1Y+mT0UWz4kgB9C8HZ6DrpexTNl+gAyTkOrd 2rHaieRsai8LOwAIzzdNaJ7gTO37kpH2U4jz5pkjpFBz0VdvA= = Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: d@davea.name 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352799412 news.xs4all.nl 6903 [2001:888:2000:d::a6]:52951 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33231 On 11/13/2012 01:38 AM, Some Developer wrote: > I'm trying to find a way to get a string of the module path of a class. > > So for instance say I have class Foo and it is in a module called > my.module. I want to be able to get a string that is equal to this: > "my.module.Foo". I'm aware of the __repr__ method but it does not do > what I want it to do in this case. > > Can anyone offer any advice at all? So you have: import my.module theclass = my.module.Foo print tellme(theClass) and you want to know how to write tellme? Why not just change it to take a string, and pass it "my.module.Foo" ? If you have stored the class away somewhere, and want to figure it out from there, you could look at the __module__ attribute. that'll tell you the module name, but not the class name. If you're really asking how to get that string from an INSTANCE of the class, then try the __class__ attribute of that instance. -- DaveA