Importing a class from a sub-directory
Phil <[email protected]> Sat, 10 Feb 2024 11:58:11 +1000
| Newsgroups | gmane.comp.python.tutor |
|---|---|
| Message-ID | <[email protected]> |
Thank you for reading this and this is a problem that I've struggled with for quite some time. The simple fix was to copy myclass into whatever project directory that I was working on at the time, but of course, this means that I have to maintain multiple copies of the same class. Say I have myclass.py saved in ~/Python and I want to import myclass into myproject.py that is saved in ~/Python/Tkinter/myproject. How do I do that? I have tried countless possibilities including: from ..myclass import Myclass I've created a file named "__init__.py and saved myclass.py into that file I've tried from "~/Python/myclass" import Myclass but that's a syntax error I've scoured the Internet looking for a solution and read several tutorials and even consulted my AI friends and I'm still at a lose to solve this seemingly simple problem. Using the tree command I have confirmed that I have the following directory structure: ~/Python |__ myclass.py |__ Tkinter |_ myproject.py -- Regards, Phil _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor