Home > Mobile >  How can I make python download file to current directory of main.py?
How can I make python download file to current directory of main.py?

Time:08-22

I have a project on Gitlab that should download files to its current directory (regardless of user OS being Mac/Windows) when the user downloads the repo and uses it on locals. Also, I will read the same file again further in the program.

Can anyone suggest to me what directory name should I pass in the python variable to achieve this?

Thank you

CodePudding user response:

If you want to download to the same folder as your python file, you can do

from pathlib import Path

dir_to_download_to = Path(__file__).parent

If you want to download to the same folder as the user is in, then

import os

dir_to_download_to = os.getcwd()
  • Related