Is this possible ....

S

Stef Mientki

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()


thanks,
Stef Mientki
 
P

Paul Hankin

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]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,787
Messages
2,569,629
Members
45,332
Latest member
LeesaButts

Latest Threads

Top