Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

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 January 21st, 2013, 03:32 PM
ShadowCore ShadowCore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Sweden
Posts: 3 ShadowCore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 42 sec
Reputation Power: 0
Import module problem

Hi!

I'm trying to import a module that contains some information. The file is called config and the code to include it is:

Code:
import config
config.path("/home/raven/ShadowBot-0.0.1/")


The file IS in that path, but when I start the program it gives me a "No such module" error.

Reply With Quote
  #2  
Old January 21st, 2013, 03:46 PM
eliskan eliskan is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 43 eliskan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 59 m 28 sec
Reputation Power: 1
Quote:
Originally Posted by ShadowCore
Hi!

I'm trying to import a module that contains some information. The file is called config and the code to include it is:

Code:
import config
config.path("/home/raven/ShadowBot-0.0.1/")


The file IS in that path, but when I start the program it gives me a "No such module" error.




I am not sure but I think you are trying to import sys module, then add a path to the sys.path section.

When I print my sys.path, it returns:

Code:
['C:\\Python26\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages']



These are all the folders it will look for a module. According to Python's Documentation:

Quote:
When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path.




Sooo I am assuming what you want to do is:

import sys
dir="C://Windows/ect"+"/home/raven/ShadowBot-0.0.1/"
sys.path.append(dir)
import config



I am not sure but I think you will need the full directory for this to work. Also not sure if this WILL work. The reason you're having problems importing a module that's undefined is because the path of that module isn't in sys.path.

Reply With Quote
  #3  
Old January 21st, 2013, 04:36 PM
ShadowCore ShadowCore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Location: Sweden
Posts: 3 ShadowCore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 42 sec
Reputation Power: 0
I actually got it working the same minute that you replied to me. I first had to rename the file from config to config.py and then just add "from config import *" and it worked! But thank you for the fast reply

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Import module problem

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap