0

I am wanting to set up a system of CSV formatters in conjunction with a PySimpleGUI program. I want the output file to go to the users Downloads folder, but currently I know how to only use the Path method for my own Downloads folder. If I packaged this up, it would not be dynamic.

path = Path(r"C:\\Users\\xxx.xxxxx\\downloads\\Finished_File.csv")

I am unsure of other ways to go about auto-filling the user info without inputting it manually

My only other thinking is perhaps have this change dynamically with PySimpleGui using a list of potential names, and then having the user set who they are?

Pongotan
  • 15
  • 4
  • 1
    Side note: you probably shouldn't be using a raw string literal (prefixed with `r`) and double backslashes together. – ChrisGPT was on strike Dec 21 '22 at 20:56
  • THANK YOU! I'm building this to stream lie work-flows in my healthcare job. It gives me an excuse to learn to program while I work -- I'm quite a beginner, so I appreciate your input! – Pongotan Dec 21 '22 at 20:59

1 Answers1

-1

Find it manually before saving uisng pathlib

from pathlib import Path
users_download_path = str(Path.home() / "Downloads")
res =str( users_download_path) + '\' + str('Finished_File.csv')
path = Path(res)
  • This isn't seeming to work. Could a permission on my work computer be blocking it? No errors occur, it jus is not exporting when I push df.to_csv(path, header=True, index=False) – Pongotan Dec 21 '22 at 21:38
  • @BHhargav it seems to print C:\Users\kye.hache\DownloadsFinished_File.csv How do i get the extra \ in there? it isnt wanting to work, it sees the back \ as an operator to the string. – Pongotan Dec 21 '22 at 22:08
  • Why are you creating strings from a path, then back to a path? It's probably better to just stay in the `pathlib` world, e.g. `Path.home() / "Downloads" / "Finished_file.csv"`. No `str()` needed. – ChrisGPT was on strike Dec 21 '22 at 22:30
  • this is the changes I made prior to this comment -- you both did it a little cleaner than me, though :) Thank you both. – Pongotan Dec 21 '22 at 22:32
  • `'\'` doesn't do what you think it does. Are you looking for `'\\'`? – ChrisGPT was on strike Dec 22 '22 at 17:13
  • On Windows and some Linux distros the name of the download directory is localized so will not be "Downloads". In addition on Windows the user is free to rename or move the Downloads directory/path. – hippietrail Apr 10 '23 at 05:41