Importing packages and classes help required by newbie

Discussion in 'Python' started by Rogue 9, Jul 4, 2003.

  1. Rogue 9

    Rogue 9 Guest

    Hi All,
    I have a small problem in a program I'm developing and could do with some
    guidance as to how I resolve it.
    The hierachy of my program is as follows:

    1)The toplevel package is called oop_lb 2)Beneath oop_lb are 3 packages -
    analysis,process and tests

    oop_lb
    |
    |
    -------------------------------------------------------
    | | |
    analysis process tests


    I am using the very excellent unittest module to help me to create a
    program that is as bug free as I can make it and the tests are as you cn
    guess in the tests package mentioned above. I have developed several
    modules which reside in the process package and succesfully created tests
    in the tests package which ensure the code does what I intended.When I
    moved on to the analysis package however,things went a bit wonky as the
    modules in this package called classes which resided in the process
    package and when using the import statements to make them available I
    found that either I could get the oop_lb module to run with one set of
    import statements but the tests I wrote would not recognise the modules
    from process in the import statements and produced the following type of
    error:

    Traceback (most recent call last):
    File "CalculateMedianTest.py", line 14, in ?
    import oop_lb.analysis.CalculateMedian
    File "/home/lol/disk/python/lotto/oop_lb/analysis/CalculateMedian.py",
    line 14, in ?
    from process import GetDraw
    ImportError: No module named process

    This occurs with the following import statement in the CalculateMedian.py
    module

    from process import GetDraw

    If I change this to
    import oop_lb.process.GetDraw

    then the test program will work but the oop_lb.py file fails with the
    following error

    Traceback (most recent call last):
    File "oop_lb.py", line 21, in ?
    from analysis import CalculateMedian # import class definition from
    file
    File "/home/lol/disk/python/lotto/oop_lb/analysis/CalculateMedian.py",
    line 13, in ?
    import oop_lb.process.GetDraw
    File "/home/lol/disk/python/lotto/oop_lb/oop_lb.py", line 21, in ?
    from analysis import CalculateMedian # import class definition from
    file
    ImportError: cannot import name CalculateMedian

    So.....my problem is that I can't seem to find the proper way to import
    the modules to satisfy both the testing modules in the oop_lb.tests
    package and also allow oop_lb.py to run without import errors. I apologise
    for the length of the post and any ambiguities I may not have managed to
    clear up whilst proff reading this before posting.

    Thanks,Lol
    --
    Remove NOSPAM from my email address to use it,please.
    Rogue 9, Jul 4, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ravi sankar
    Replies:
    2
    Views:
    378
    abdul bari
    Aug 27, 2003
  2. Paul  Smith
    Replies:
    0
    Views:
    717
    Paul Smith
    Nov 18, 2003
  3. IShai
    Replies:
    1
    Views:
    1,469
    Anton Spaans
    Nov 25, 2003
  4. David Lyon
    Replies:
    19
    Views:
    555
    David Lyon
    Apr 24, 2009
  5. Ian
    Replies:
    3
    Views:
    156
Loading...

Share This Page