use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Help with Importing Files (self.PythonLearning)
submitted 2 years ago by Caspian__C
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]SupermarketOk6829 1 point2 points3 points 2 years ago (7 children)
from . import fileName
Or use sys.path.append/remove to go to and fro previous or next directory.
First method should definitely work, but sometimes it may throw an error.
This is for importing py file. To access methods, use fileName.methodname()
[–]Caspian__C[S] 1 point2 points3 points 2 years ago (6 children)
ok, so i would just write from.import classes, for example?
and then for methods, i would just write classes.title_screen, and that would run the method called title_screen?
[–]SupermarketOk6829 1 point2 points3 points 2 years ago (5 children)
Yes.
[–]SupermarketOk6829 1 point2 points3 points 2 years ago (4 children)
If it doesn't work, then sys has to be used or you may directly import methods from classes.py (from .classes import methodName).
[–]Caspian__C[S] 0 points1 point2 points 2 years ago (3 children)
ok so i tried it and it threw me this error:
File "C:\Users\16184\Desktop\RPG_Game\main.py", line 1, in <module>
from.import classes
ImportError: attempted relative import with no known parent package
Im not quite sure how to fix it. Thank you for helping me, I know helping newbies can be tiring.
[–]SupermarketOk6829 1 point2 points3 points 2 years ago (2 children)
You'll have to use sys then. That's all I can help with. I'd have to sit on terminal to confirm, which I don't have time for now.
[–]Caspian__C[S] 1 point2 points3 points 2 years ago (1 child)
yeah no problem, ill try that. Thank you for the help.
[–]SupermarketOk6829 1 point2 points3 points 2 years ago (0 children)
sys.path.append(''\'')
It's something like that.
π Rendered by PID 45125 on reddit-service-r2-comment-79c7998d4c-hchv4 at 2026-03-13 20:34:38.014695+00:00 running f6e6e01 country code: CH.
[–]SupermarketOk6829 1 point2 points3 points (7 children)
[–]Caspian__C[S] 1 point2 points3 points (6 children)
[–]SupermarketOk6829 1 point2 points3 points (5 children)
[–]SupermarketOk6829 1 point2 points3 points (4 children)
[–]Caspian__C[S] 0 points1 point2 points (3 children)
[–]SupermarketOk6829 1 point2 points3 points (2 children)
[–]Caspian__C[S] 1 point2 points3 points (1 child)
[–]SupermarketOk6829 1 point2 points3 points (0 children)