PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, August 26, 2022

[FIXED] How can I make python download file to current directory of main.py?

 August 26, 2022     csv, pandas, python, python-3.x     No comments   

Issue

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


Solution

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()


Answered By - user3808430
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing