On 17/02/2011 17:11, Tim Hanson wrote:
Okay, I solved my problem with Python finding modules:

I put the following into a file in my home directory, on the good advice of
Andrea Crotti:

import sys
sys.path.append('/home/foo/mypath'

I named the file "~/pypath.py", so now, in idle:

import pypath

No errors.

I'm still getting a little frustrated loading modules.  I typed the following
little test function into idle:

def intersect(seq1,seq2):
   res=[]
   for x in seq1:
     if x in seq2:
       res.append(x)
   return res

intersect('spam','spmmer')


No big deal.  Runs fine.  Exited and re-entered idle,

import pypath
import intersect #the name of a file that contains the above short function.

This imports the module 'intersect'. The name 'intersect' refers to the
module itself.

intersect('spam','spmmer')

This tries to call the module. Perhaps you meant:

    intersect.intersect('spam','spmmer')

If you have a module "foo", which contains a function "bar", then "foo"
refers to the module and "foo.bar" refers to the function.

Traceback (most recent call last):
   File "<pyshell#2>", line 1, in<module>
     intersect('spam','spmmer')
TypeError: 'module' object is not callable


Huh?  Why doesn't this run when imported?  More importantly, how do I
interpret this error message so that I can find the problem myself next time?
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to