Is this possible ....

Paul Hankin paul.hankin at gmail.com
Wed Jul 23 11:11:17 CEST 2008


On Jul 23, 9:58 am, Stef Mientki <stef.mien... at gmail.com> wrote:
> hello,
>
> I'm looking for a way to remove duplicate code.
> The problem is this:
> In all my modules I've version information,
> containing version information, date, author, testconditions etc,
> something like this:
>
> Version_Text = [
> [ 0.2, '10-02-2008', 'Stef Mientki',
> 'Test Conditions:', (1,2),
> _(0, """
>    - scaling and offset is set for each individual signal
>    - Time history window for 1 signal with min/max display
>    - set attributes for all signals at once
> """) ],
>
> [ 0.1, '04-11-2007', 'Stef Mientki',
> 'Test Conditions:', (1,),
> """
>     - orginal release
> """ ]
> ]
>
> Now I've made modules that can generate docs, a library manager, etc,
> and that even in different languages.
>
> But for the simple case I would like to have a simple function, which
> just displays the version number.
> So in each module, there is a function:
>
> def version () :
>   return ( version_text [0] [0] )
>
> But is there a way to avoid the placing of this function "version" in
> each module,
> and still use a simple call like:
>   <module>.version()

You could use version(<module>) instead of module.version(), and just
declare 'version' in one place. Presumably you already have a module
for getting the metadata out of one of your modules; perhaps it could
go in there?

def version(module):
    return getattr(module, 'Version_Text')[0][0]

--
Paul Hankin



More information about the Python-list mailing list