Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm new to programing and I'm writing my first python program using quickly. I have added new window and on this new window I want to call function from main window? I google for it and all I found is that I nned to import it but it didnt know how.

Here is what I put new window:

from magic_ebay.MagicEbayWindow import MagicEbayWindow

and I get error:

ImportError: cannot import name MagicEbayWindow

MagicEbayWindow.py is the name of main window in my program and I want to call function from MagicEbayWindow.py but on other window. ( dont know if it make any sense :) )

Thanks for any help!

share|improve this question
    
Needs some context. You could parse parent structures to walk up from a child, pass in a pointer to the class instance (once it's abstracted it's actually a pointer to an instance), or make it a global. Do you have this in a ppa/github or something? –  hbdgaf Jul 19 '12 at 20:48
    
no do don't have it on github. –  Majster-pl Jul 19 '12 at 20:53
    
then you want to be looking at adding to sys.path, but there's not much more i can say without context –  hbdgaf Jul 19 '12 at 21:18
    
thanks for your help, I will try to drop it to github tonight... thanks –  Majster-pl Jul 19 '12 at 21:42
add comment

1 Answer 1

up vote 0 down vote accepted

When you run:

from magic_ebay.MagicEbayWindow import MagicEbayWindow

You are essentially saying "Please import the MagicEbayWindow symbol from the MagicEbayWindow module in the magic_ebay package". The error message indicates that your MagicEbayWindow.py module doesn't have such a symbol.

There are a few ways you could fix this:

  1. Just import the module:

    from magic_ebay import MagicEbayWindow
    

    You can then access functions within the module as e.g. MagicEbayWindow.foo()

  2. Import individual functions from the module:

    from magic_ebay.MagicEbayWindow import foo
    

    With this style, you can call the functions without the module name prefix.

share|improve this answer
    
Ok I got it finally :) instead: –  Majster-pl Jul 20 '12 at 20:54
    
Ok I got it finally :) instead: from magic_ebay import MagicEbayWindow i did: import MagicEbayWindow and it work! now when i want to call function from MagicEbayWindow i need to do : mee = MagicEbayWindow.MagicEbayWindow() mee.foo(self) I might doing it all way around but it work for me for now! THANK YOU! –  Majster-pl Jul 20 '12 at 21:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.