5 Replies - 216 Views - Last Post: 02 September 2013 - 03:38 PM Rate Topic: -----

#1 rippinrob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 29-August 13

importing modules

Posted 02 September 2013 - 12:57 PM

I'm using windows 7, python 2.7.5 running the python Shell using IDLE

Im learning about importing modules, following a tutorial, but a hit a wall. Whenever I open my IDLE, I try to import a file func.py into my shell by using
 import func
. The func.py file is in my C:\Python27\Scripts folder but it gets an error "no module named func". well, i open func.py using IDLE and hit f5(run) and then I can import it, or call the function in my func.py without importing it in the shell.

I'm not sure what i did differently before, but sometimes I have to use
 func.functionInFunc(args) 
for it to work in my shell, after i have imported it(or sometimes after I ran the script) and other times all I have to do it call the function like
 functionInFunc(args) 
and that works to.

I know I'm probably doing something wrong or different, just wondering what I have to do to be able to import, do I have to open my module every time and run it? And when do I have to put the modules name in front of the function when I want to call it, and when I don't have to. the tutorial does it both ways but doesn't explain why.

Is This A Good Question/Topic? 0
  • +

Replies To: importing modules

#2 DblAAssassin  Icon User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 247
  • Joined: 11-May 13

Re: importing modules

Posted 02 September 2013 - 02:25 PM

I'm pretty sure for 2.7, you must have your Modules in C:\Python27, although, in Python 3.3, you must have it in the C:\Python33\Lib. The reason I mention that is I'm not sure when the Lib folder was implemented. So this is what I would do.
  • Make sure the func.py file is in either the main directory or the Lib folder.
  • Try telling the shell, that you want to import func.py (see code below)
  • Post, that it still doesn't work, if that statement is true :)


So for the second, one there, this is what it should look like.
import func.py


Instead of
import func



I've had this issue in the past, and this solved it! So hopefully that will fix it. ;)
Was This Post Helpful? 0
  • +
  • -

#3 rippinrob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 29-August 13

Re: importing modules

Posted 02 September 2013 - 02:48 PM

Is there no way to organize my scripts? I know im gonna be collecting a lot of them, and having 100 scripts in my C:\Python27 might be a bit cluttered
Was This Post Helpful? 0
  • +
  • -

#4 DblAAssassin  Icon User is offline

  • D.I.C Head

Reputation: 32
  • View blog
  • Posts: 247
  • Joined: 11-May 13

Re: importing modules

Posted 02 September 2013 - 02:59 PM

That's the way it works mate, if you update to 3.3, you can use the Lib folder all you want!
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3371
  • View blog
  • Posts: 11,420
  • Joined: 12-December 12

Re: importing modules

Posted 02 September 2013 - 03:05 PM

Python's search path can be modified.
Was This Post Helpful? 1
  • +
  • -

#6 rippinrob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 29-August 13

Re: importing modules

Posted 02 September 2013 - 03:38 PM

awesome! just spent some learning about the search path and finally figured out how to edit it. just took 1 line to append to the site.py file.

thanks man!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1