Re: Testing if a global is defined in a module

2011-07-07 Thread Grant Edwards
On 2011-07-06, Waldek M. wm@localhost.localdomain wrote: Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): Because unless you are extremely disciplined, code and the comments describing them get out of sync. [...] True, but that gets far worse with external docs. Do you have

Re: Testing if a global is defined in a module

2011-07-07 Thread Chris Rebert
On Thu, Jul 7, 2011 at 7:18 AM, Grant Edwards invalid@invalid.invalid wrote: On 2011-07-06, Waldek M. wm@localhost.localdomain wrote: Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisa?(a): Because unless you are extremely disciplined, code and the comments describing them get out

Re: Testing if a global is defined in a module

2011-07-06 Thread Waldek M.
Dnia Wed, 06 Jul 2011 03:36:24 +1000, Steven D'Aprano napisał(a): Because unless you are extremely disciplined, code and the comments describing them get out of sync. [...] True, but that gets far worse with external docs. Do you have in mind any better replacement? Br. Waldek --

Re: Testing if a global is defined in a module

2011-07-05 Thread Grant Edwards
On 2011-07-05, Chris Angelico ros...@gmail.com wrote: On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson t...@johnsons-web.com wrote: Steven, I'm building a documentation system. I have my own MVC framework and the goal is to have a documentation module for each project. Is there a reason for not

Re: Testing if a global is defined in a module

2011-07-05 Thread Tim Johnson
* Ian Kelly ian.g.ke...@gmail.com [110704 20:37]: It sounds like what you really want is to detect the names *exported* by the module, then. i Yes! Why not do it the same way Python does it? If the module defines an __all__ attribute, then it is taken to be a sequence of strings which

Re: Testing if a global is defined in a module

2011-07-05 Thread Grant Edwards
On 2011-07-05, Tim Johnson t...@johnsons-web.com wrote: * Ian Kelly ian.g.ke...@gmail.com [110704 20:37]: It sounds like what you really want is to detect the names *exported* by the module, then. i Yes! Why not do it the same way Python does it? If the module defines an __all__

Re: Testing if a global is defined in a module

2011-07-05 Thread Waldek M.
Dnia Tue, 5 Jul 2011 14:11:56 + (UTC), Grant Edwards napisał(a): Because those specially-formatted comments are wrong. ... because? Not in sarcasm mode; just curious why you don't like them. Br. Waldek -- http://mail.python.org/mailman/listinfo/python-list

Re: Testing if a global is defined in a module

2011-07-05 Thread Steven D'Aprano
Waldek M. wrote: Dnia Tue, 5 Jul 2011 14:11:56 + (UTC), Grant Edwards napisał(a): Because those specially-formatted comments are wrong. ... because? Not in sarcasm mode; just curious why you don't like them. Because unless you are extremely disciplined, code and the comments describing

Re: Testing if a global is defined in a module

2011-07-05 Thread Grant Edwards
On 2011-07-05, Waldek M. wm@localhost.localdomain wrote: Dnia Tue, 5 Jul 2011 14:11:56 + (UTC), Grant Edwards napisa?(a): Because those specially-formatted comments are wrong. ... because? In my experience, they're wrong because somebody changes the code and not the comments. Not in

Re: Testing if a global is defined in a module

2011-07-05 Thread Chris Angelico
On Wed, Jul 6, 2011 at 3:36 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Because unless you are extremely disciplined, code and the comments describing them get out of sync. Quote: At Resolver we've found it useful to short-circuit any doubt and just refer to comments in

Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
Using Python 2.6 on ubuntu 10.04. inspect module : I want to 'inspect' a module and get a list of all functions, classes and global variables in that module. ## A module has been imported, and we call `getmembers' members = inspect.getmembers(mod) ## While iterating thru `members', we test to

Re: Testing if a global is defined in a module

2011-07-04 Thread rantingrick
On Jul 4, 1:11 pm, Tim Johnson t...@johnsons-web.com wrote: Using Python 2.6 on ubuntu 10.04. inspect module : I want to 'inspect' a module and get a list of all functions, classes and global variables in that module. ## A module has been imported, and we call `getmembers' members =

Re: Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
* rantingrick rantingr...@gmail.com [110704 12:00]: On Jul 4, 1:11 pm, Tim Johnson t...@johnsons-web.com wrote: Well if you follow the python style guide (and most accepted styles for global notation) then it's a trial exercise. You don't even have to import anything!!! :) GLOBAL_STR =

Re: Testing if a global is defined in a module

2011-07-04 Thread Chris Rebert
On Mon, Jul 4, 2011 at 11:11 AM, Tim Johnson t...@johnsons-web.com wrote: Using Python 2.6 on ubuntu 10.04. inspect module : I want to 'inspect' a module and get a list of all functions, classes and global variables in that module. You meant first defined in that module. snip Example, for a

Re: Testing if a global is defined in a module

2011-07-04 Thread rantingrick
On Jul 4, 3:30 pm, Tim Johnson t...@johnsons-web.com wrote:   Thanks for the reply: *but*   dir(targetmodule) will also show globals from other modules imported   by the target module. So I would need a way to distinguish between   those imported and those defined in targetmodule Okay, then

Re: Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
* Chris Rebert c...@rebertia.com [110704 13:16]: What else can I do here? Look at the names in the module's import statements using the `ast` module, and exclude those from the set of names defined in the module. Won't work for `from foo import *`, but that's bad practice and should be

Re: Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
* rantingrick rantingr...@gmail.com [110704 13:47]: On Jul 4, 3:30 pm, Tim Johnson t...@johnsons-web.com wrote:   Thanks for the reply: *but*   dir(targetmodule) will also show globals from other modules imported   by the target module. So I would need a way to distinguish between  

Re: Testing if a global is defined in a module

2011-07-04 Thread Steven D'Aprano
Tim Johnson wrote: dir(targetmodule) will also show globals from other modules imported by the target module. So I would need a way to distinguish between those imported and those defined in targetmodule Why would you want to do that? Importing *is* a definition in targetmodule.

Re: Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
* Steven D'Aprano steve+comp.lang.pyt...@pearwood.info [110704 15:18]: You are mistaken. TestAddresses is *not* a member of an imported module. It is a member of the current module, which may or may not happen to point to the same object as the other module as well. You are correct. I

Re: Testing if a global is defined in a module

2011-07-04 Thread Steven D'Aprano
Tim Johnson wrote: It seems to me that your approach here is unnecessarily complex and fragile. I don't know what problem you are trying to solve, but trying to solve it by intraspecting differences that aren't differences is surely the wrong way to do it. See my last post... Yes, but

Re: Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
* Steven D'Aprano steve+comp.lang.pyt...@pearwood.info [110704 15:48]: Tim Johnson wrote: It seems to me that your approach here is unnecessarily complex and fragile. I don't know what problem you are trying to solve, but trying to solve it by intraspecting differences that aren't

Re: Testing if a global is defined in a module

2011-07-04 Thread Chris Angelico
On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson t...@johnsons-web.com wrote:  Steven, I'm building a documentation system. I have my own MVC framework  and the goal is to have a documentation module for each project. Is there a reason for not using Doxygen / Autodoc / etc, or at least something

Re: Testing if a global is defined in a module

2011-07-04 Thread Tim Johnson
* Chris Angelico ros...@gmail.com [110704 16:19]: On Tue, Jul 5, 2011 at 10:01 AM, Tim Johnson t...@johnsons-web.com wrote:  Steven, I'm building a documentation system. I have my own MVC framework  and the goal is to have a documentation module for each project. Is there a reason for

Re: Testing if a global is defined in a module

2011-07-04 Thread Ian Kelly
On Mon, Jul 4, 2011 at 6:01 PM, Tim Johnson t...@johnsons-web.com wrote: Yes, but what are you actually *trying to do*? Detecting data members is not an end in itself. Why do you think you need to detect data members?  Steven, I'm building a documentation system. I have my own MVC framework