[Tutor] PYTHONPATH (Mac OS X)

Stayvoid stayvoid at gmail.com
Mon Dec 26 13:23:26 CET 2011


>Simply that python is saying it cannot find the file.
>So it is probably in a different folder to the one in which the program is running. You need to provide a valid path to the file,

Those files are in the same folder:
/Users/Username/Python_modules/

I don't want to write a full path here:
if __name__ == '__main__':
   print test('lengthcounter_lutz.py')

How to add this directory to the search path?

>So what is it doing exactly that seems wrong?
>What input? What output? What did you expect?

I have a slightly different copy of this file:

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

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

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

if __name__ == '__main__':
    import lengthcounter
    print test(lengthcounter)

I've tried to run it in the interactive shell:

import lengthcounter as lc
lc.test(lengthcounter)

And here is the output:

('Lines:', 5, 'Chars:', 885)

But that code has 13 lines and 317 characters according to the Emacs' counter.
Where is an error?

Cheers.


More information about the Tutor mailing list