another problem with modules

Tim Hanson tjhanson at yahoo.com
Thu Feb 17 12:11:49 EST 2011


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.
intersect('spam','spmmer')

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?



More information about the Python-list mailing list