Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 12th, 2004, 09:42 PM
jmank88 jmank88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 jmank88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 12th, 2004, 10:54 PM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
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.

Reply With Quote
  #3  
Old October 13th, 2004, 02:59 AM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,254 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 8 h 9 m
Reputation Power: 265
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

Reply With Quote
  #4  
Old October 13th, 2004, 08:04 AM
rebbit rebbit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Posts: 84 rebbit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 7 m
Reputation Power: 5
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?

Reply With Quote
  #5  
Old October 13th, 2004, 01:30 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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:
>>> import sys
>>> sys.path.append('c:/path/to/my/dir')
>>>


to add the modules location directly into Python search path. As rebbit suggested.

Mark.
__________________
programming language development: www.netytan.com Hula


Last edited by netytan : October 13th, 2004 at 01:32 PM.

Reply With Quote
  #6  
Old October 13th, 2004, 04:27 PM
eriksays eriksays is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 167 eriksays User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 21 m 21 sec
Reputation Power: 5
Send a message via AIM to eriksays
Quote:
Originally Posted by netytan
Most of us wouldn't use IDLE to write full programs....
Mark.


what would you use? i just started using wxPython (PyAlaCrust)

Reply With Quote
  #7  
Old October 13th, 2004, 04:37 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 11 m 13 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #8  
Old October 13th, 2004, 05:56 PM
jmank88 jmank88 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 5 jmank88 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up sweet

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > newb question about modules


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT