Is this possible ....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stef Mientki

    Is this possible ....

    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>.versio n()


    thanks,
    Stef Mientki
  • Paul Hankin

    #2
    Re: Is this possible ....

    On Jul 23, 9:58 am, Stef Mientki <stef.mien...@g mail.comwrote:
    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>.versio n()
    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

    Comment

    • Stef Mientki

      #3
      Re: Is this possible ....

      thanks Paul,

      your solution works very well.

      cheers,
      Stef


      Paul Hankin wrote:
      On Jul 23, 9:58 am, Stef Mientki <stef.mien...@g mail.comwrote:
      >
      ....
      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
      >

      Comment

      Working...