|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 help please -jordan |
|
#2
|
|||
|
|||
|
try typing:
Code:
>>> import os >>> os.getcwd() (without the '>'s ofcourse) and save your module in the directory that the os.getcwd() function returns. also do this: Code:
>>> import sys >>> sys.path 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. |
|
#3
|
|||
|
|||
|
Or you can do
os.chdir('c:/path/to/my/dir') to change the current directory to wherever your file is. Dave - The Developers' Coach |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
||||
|
||||
|
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: Quote:
to add the modules location directly into Python search path. As rebbit suggested. Mark. Last edited by netytan : October 13th, 2004 at 01:32 PM. |
|
#6
|
|||
|
|||
|
Quote:
what would you use? i just started using wxPython (PyAlaCrust) |
|
#7
|
||||
|
||||
|
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. Mark. |
|
#8
|
|||
|
|||
|
thanks guys, turns out that pythonwin was trying to import from
C:\program files\python\pythonwin\ 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 -jordan |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > newb question about modules |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|