I found a quick fix but i still have the same damn fucking error ive asked multiple python devs and theyre all confused please help
#๐ Local import error so confused bruh
13 messages ยท Page 1 of 1 (latest)
@jovial rain
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
"Explain what you expect to happen and what actually happens."
i want to import a custom error handler but for some reason the "attribute" isnt found which its there it just for some reason cant be found and idk why
yeah, no clue either. If anything maybe try moving manager into src?
personally I always stick to using absolute imports, and always use this structure for my projects:
- https://packaging.python.org/en/latest/tutorials/packaging-projects/
- alternative / builds on top of the above: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/
note: It requires pyproject.toml, and while the tutorials are a bit focused on publishing, this structure is great even when you do not want to publish it
Use pip install -e . inside of a virtual environment to install it after formatting as a package
typically you'll want to avoid from src import xyz or import src.xyz though, format your project in a way such that your imports have a more meaningful name
Thanks
import handler as _handler
handler = _handler```
why not just ```py
import handler```
You're running manager.py, yes? When you run a script, its directory is put in Python's search path. That is what causes your handler.py file to be the module src.handler - src is found in the directory of manager.py. The you import the name handler from src, so you've imported your src.handler module, and it has the name handler in your script. I'm assuming there's a Handler class in handler.py. Then its name is handler.Handler, not handler.handler.Handler. The local name handler_is_ yoursrc.handlermodule and thereforeHandleris obtained from that, so its name ishandler.Handler`.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.