0

I'm beginner - only a few months at this stuff. So... maybe something dumb. This is a GUI program with multiple modules, and the GUI works on both platforms. pathLib seems to be transforming the path as I would expect, backslashes from forward and prefixing the Windows root, C: etc, Both cases use Python v.3.9. I'm also using PyCharm on both. OS is Catalina (Mac) and Win10. The data files are cvs from Excel, UTF - 8. The data is in a folder in same directory as my source modules. Any ideas?

myfile = 'dbm.csv'

csvFileObj = Path.cwd() / 'data' / myfile

with csvFileObj as datafile:
    dbx = list(csv.reader(open(datafile)))
khelwood
  • 55,782
  • 14
  • 81
  • 108
  • try with `os.path.dirname(os.path.abspath(__file__))` instead of `Path.cwd()` – Fravadona Apr 15 '21 at 19:58
  • You said that _"The data is in a folder in same directory as my source modules."_ `Path.cwd()` doesn't give you that, see [Diference between os.getcwd() and os.path.dirname(\_\_file\_\_)](https://stackoverflow.com/questions/65453576/diference-between-os-getcwd-and-os-path-dirname-file) – Fravadona Apr 15 '21 at 21:31
  • Thanks for getting me straight about Path. cwd(). The reference Link you gave was very infromative. So anyway, I redid my code per your idea (I think): Now I have: source_path = (os.path.dirname(os.path.realpath(__file__))) data_path = os.path.join(source_path, "data") full_path = os.path.join(data_path, myfile) dbx = list(csv.reader(open(full_path))) – user15347951 Apr 17 '21 at 20:45
  • @– Fravadona Continuing the above... as before, this code works fine on my Mac, no-go on my PC. I'm wondering if it it perhaps is not a path prbrlblem, but rather something tricky about Windowns handling of the file type suffix, or ... something eles. Sorry about my ugly code. I'm also new ro mini-markdown - tying to figure that out too. – user15347951 Apr 17 '21 at 21:15
  • OK, this is in fact working now (and apparently was when I wrote the above, So thanks for your guidance on that. It turns out that I have a different problem at the same point in my code: my cosole has an erroe message about an unrecognized unicode character in position 18. I don't know how to locate position 18 either, but I'll have to submit that a a separate qusretion. Again thanks for your excellent advise on the right way to get the path. – user15347951 Apr 18 '21 at 17:00

0 Answers0