ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
when i import packagename into python and try to use function2:
function2 calls on function1, but I am receiving an error that global name funcion1 is not defined. When i issue a dir(), both function1 and function2 are listed. Similarly, function1 calls on string.split, and it complains that global name 'string' is not defined. Whatever am I to do?
Thank you very much.
Last edited by jhwilliams; 08-06-2007 at 01:30 PM.
String functions are instance methods: you call them on the string you want to split, for example -- "hello world".split(...) -- and then the result gets returned.
If you want to call module1.function1 from module2, you need to import module1 inside module2.
If you want to call module1.function1 from module2, you need to import module1 inside module2.
Yea - I ended up doing this to resolve the problem. I guess what was confusing to me is that I thought that the __init__ script would handle all of the dependencies. I guess I don't really understand what the __init__ script is meant for, afterall.
I guess I don't really understand what the __init__ script is meant for, afterall.
Just off the top of my head (not near my Python reference), I've only used it before for using Java-like package management in Python 2.5 -- like the following:
Code:
from lexicon.pos import *
Where below the current directory there is a "lexicon" directory, and beneath that a "pos" directory, and inside that the modules I'm loading. For this to work, you need to have the __init__.py files in the "lexicon" and "pos" directories. My files were empty, but I know you can put code into there. I'm just not quite clear on when it gets loaded or what it's scope is... which I guess is what your question was. But I do know that it doesn't do what you originally intended, unfortunately.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.