#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    3
    Rep Power
    0

    Unhappy Very Newbie - Python classes across modules


    Can anyone tell me how to get say module 'a' to recognize the classe(s) in module 'b'? I can instantiate a class in module 'b' but I can not figure out how to have module 'a' recognize it.
    Having to use 'global' would be a pain and I don't even know if it would work.
    In addition, I can not figure out how or even if it is possible to instantiate a class from module 'b' inside of module 'a'.
    I am trying to convert a program that has a ton of separate files to Python and putting everything in one file is just not practical.
    I'm sure it must be a simple thing but, so far, it's too much for me apparently.
    I know this is a silly question but try not to abuse me too much.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2005
    Location
    >>> import pygtk
    Posts
    4
    Rep Power
    0
    in module b:
    from a import YourKlass #get YourKlass from module a
    yk = YourKlass() #instantiate that class
    do_stuff(yk)

    -OR-

    import a #get module 'a'
    yk = a.YourKlass() #instantiate YourKlass in module a
    do_stuff(yk)

    global wouldn't work anyway.

    Originally Posted by catlover
    Can anyone tell me how to get say module 'a' to recognize the classe(s) in module 'b'? I can instantiate a class in module 'b' but I can not figure out how to have module 'a' recognize it.
    Having to use 'global' would be a pain and I don't even know if it would work.
    In addition, I can not figure out how or even if it is possible to instantiate a class from module 'b' inside of module 'a'.
    I am trying to convert a program that has a ton of separate files to Python and putting everything in one file is just not practical.
    I'm sure it must be a simple thing but, so far, it's too much for me apparently.
    I know this is a silly question but try not to abuse me too much.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2004
    Location
    There where the rabbits jump
    Posts
    556
    Rep Power
    11
    the way I understood the question is how to recognize a class remotly and as far as I know you can't do that...
    Those people who think they know everything are a great annoyance to those of us who do.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2005
    Posts
    3
    Rep Power
    0
    Thank you very much for taking the time to help.

IMN logo majestic logo threadwatch logo seochat tools logo