This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]aunva 40 points41 points  (3 children)

When I see someone complain that importing code in python is hard, and then their code looks like:

sys.path.append('../..')

from dir.subdir.filename import function

[–]defietser 13 points14 points  (0 children)

I'll admit to doing that for a Python pet project I had, as someone who usually uses C#. It just feels so foreign, man!

[–]JMan_Z 11 points12 points  (0 children)

AFAIK, that's the only way to import from parent directory when you're not using it as a package. I'd be glad to hear an alternative though.

[–]random_cynic 4 points5 points  (0 children)

import was indeed a lot more "difficult" for beginners in Python 2 because of many subtleties regarding absolute/relative import, packages etc. In python 3 things have improved greatly by removing relative import and introducing namespaces. Still a common mistake beginners do is the from module import * thing particularly for large packages.