October 12th, 2004, 08:42 PM
newb question about modules
alright, im using pythonwin, and im going through the tutorials on python.org, and im in modules, but i cant seem to import the module into the interactive window
it tells me to create a fibo.py file with whatever in it and save it "in the current directory" then do "import fibo" in the interactive window. where do i need to save the file? i tried saving in different places on C:\Python24\ , and directoryies within it, but everything i try gives this
Traceback (innermost last):
File "<interactive input>", line 1, in ?
ImportError: No module named fibo
October 12th, 2004, 09:54 PM
(without the '>'s ofcourse) and save your module in the directory that the os.getcwd() function returns.
>>> import os
also do this:
and you will get a list of all directories that are in your path, ie all the directories that are searched for modules when you try importing something. saving it in one of those directories will work.
>>> import sys
October 13th, 2004, 01:59 AM
Or you can do
to change the current directory to wherever your file is.
Dave - The Developers' Coach
October 13th, 2004, 07:04 AM
I just had a play with Pythonwin and it starts you (or atleast me, anyway) in C:\Python23\lib\site-packages, but still if I make a quick script and try and import it by just saving the file in the site-packages dir it works fine, so obviously you've got your path set up a bit differently.
just about the chdir() solution, isn't it rather ad hoc, seeing as you'd need to place it in every script rather than just saving the scripts on python's path?
October 13th, 2004, 12:30 PM
Most of us wouldn't use IDLE to write full programs, (though I'm sure some do,) rather IDLE is usually used to test bits of code and ideas and to see the results quickly and easily.
So in this context using os.chdir() to move the the same directory would be perfectly acceptable. But, just to provide another working example. You could always use:
to add the modules location directly into Python search path. As rebbit suggested.
Last edited by netytan; October 13th, 2004 at 12:32 PM.
October 13th, 2004, 03:27 PM
what would you use? i just started using wxPython (PyAlaCrust)
Originally Posted by netytan
October 13th, 2004, 03:37 PM
On windows I've been using Code Genie for a long time. Just because it's a nice little editor, and after writing my own Python syntax highlighting and configuring it to run Python from the editor with a one click it just feels good.
Since Switching to the Mac I've been useing Xcode, their isn't a massive amount of Python support but it is a very well designed, free IDE, which more than makes up for any short comings.
In either case, if I want access to the Python shell test something I either fire up the command line and use the Python shell directly. Or just use good old IDLE or PyCrust.
October 13th, 2004, 04:56 PM
thanks guys, turns out that pythonwin was trying to import from
not the regular python directory, so it works now!
thanks abunch, and its good to see that there is a lot of activity here so i can return next time im stuck