[Tutor] PYTHONPATH (Mac OS X)

Stayvoid stayvoid at gmail.com
Sun Dec 25 23:55:06 CET 2011


Hey there!

I'm reading Lutz's Learning Python.

Here is some code from the book.

There is a module called lcclient_lutz.py:

from lengthcounter_lutz import countLines, countChars
print countLines('lengthcounter_lutz.py'), countChars('lengthcounter_lutz.py')

And there is another one called lengthcounter_lutz.py:

def countLines(name):
    file = open(name)
    return len(file.readlines())

def countChars(name):
    return len(open(name).read())

def test(name):
    return "Lines:", countLines(name), "Chars:", countChars(name)

if __name__ == '__main__':
    print test('lengthcounter_lutz.py')

I've got an error while trying to load lcclient_lutz module:
python /Users/Username/Python_modules/lcclient_lutz.py
Traceback (most recent call last):
  File "/Users/Username/Python_modules/lcclient_lutz.py", line 2, in <module>
    print countLines('lengthcounter_lutz.py'),
countChars('lengthcounter_lutz.py')
  File "/Users/Username/Python_modules/lengthcounter_lutz.py", line 2,
in countLines
    file = open(name)
IOError: [Errno 2] No such file or directory: 'lengthcounter_lutz.py'

How to fix it? Is it connected with the PYTHONPATH variable?

P.S. There might be an error in the lengthcounter_lutz module, because
it makes mistakes while counting.


Kind regards.


More information about the Tutor mailing list