#๐Ÿ”’ Paths

50 messages ยท Page 1 of 1 (latest)

muted walrus
serene shuttleBOT
#

@muted walrus

Python help channel opened

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.

sick haven
muted walrus
sick haven
#

but you can still use the lib importlib

muted walrus
sick haven
muted walrus
#

from project import config*

sick haven
muted walrus
#

Rina Disnake its just name of project, i renamed it too now

sick haven
#

that might be why

gentle flicker
#

In Leave.py add the following to the top of the file. This will tell the python interpreter where to look for the file. In the append function use the actual path of the parent directory

import sys
sys.path.append('C:\Users\zay...\Rina')
import config
muted walrus
muted walrus
amber zealot
#

I would recommend using pathlib

#
if __name__ == '__main__':
    import sys
    import pathlib
    sys.path.append(pathlib.Path().absolute().parent.as_posix())
#

this will relatively locate the path of Rina(project root) when that file is directly runned

gentle flicker
#

Also look into using python modules with init.py that might that right way to do it. I'm pretty new to python myself.

amber zealot
muted walrus
amber zealot
#

?

#

you mean the last line

muted walrus
#

sys.path.append(pathlib.Path().absolute().parent.as_posix())

#

this

amber zealot
#

it mean
append a path that is the parent of the current working directory to sys.path in string format

sys.path is a list of path that python will look through to import module

muted walrus
#

okey i will try it

gentle flicker
#

I tried that and I think you will still need to add the name of your project to the end. Like this.

sys.path.append(pathlib.Path().absolute().parent.as_posix()+"/Rina")
gentle flicker
#

what about this?

import sys
import pathlib
path = pathlib.Path().absolute().parent.as_posix()+"/Rina"
sys.path.append(path)
gentle flicker
#

your config import should work now

muted walrus
gentle flicker
#

no just
import config

amber zealot
#

Instead you should just print the content

#

For debug purposes

muted walrus
#

and deleted.user0 thank you too! ๐Ÿค—

gentle flicker
amber zealot
#

Btw you can close the post with

#

!close

muted walrus
#

!close

serene shuttleBOT
#
Python help channel closed

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.