#๐Ÿ”’ Python relative path in Onedrive/Sharepoint

28 messages ยท Page 1 of 1 (latest)

chilly owl
#

Is there a reason that relative paths don't seem to work in Sharepoint?
The whole project is inside the same folder parent, but it doesn't seem to find images and paths.

visual minnowBOT
#

@chilly owl

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.

grand harness
#

it's probably a problem in your code

chilly owl
#

It works when the folder is on my desktop

grand harness
#

so you found a solution

chilly owl
#

No i did not. It does not work when on Onedrive. Thats my problem

grand harness
#

I see. I know it's not what you're asking for, but may I suggest not putting your code on onedrive?
if you want to share your code with other people there are better ways.

chilly owl
#

It's the company storage and backup, so "better" ways doesn't really help me

#

I'm just wondering if anyone has had similar issues. I'm assuming Microsoft maybe does some funky syncing tricks that i dont know of

blissful hollow
#

Not really

#

Are you sure the you copied that path too when you copied your code?

chilly owl
#

The paths are relative to the project files. No directory paths

grand harness
#

try using __file__ for the working directory

blissful hollow
chilly owl
#

It does, because the program works when its located on my desktop, or anywhere else on my C drive

chilly owl
grand harness
#

no. give me a second

wind vessel
#

I'm pretty sure relative paths are relative to the cwd, not the location the script is in

chilly owl
#

Is there a macro that tells it relative to this file?

grand harness
#

it should be relative to the place of the script

wind vessel
grand harness
#
import os
from pathlib import Path

directory = Path(__file__).absolute().parent
print(os.listdir(directory))
chilly owl
#

I will try ๐Ÿ‘

wind vessel
#

or

from pathlib import Path

directory = Path(__file__).parent
print(list(directory.iterdir()))
visual minnowBOT
#
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.