I am working with a Macbook programming python. What I want to know is how I can access certain files using Python’s file functions. A google search failed me.
For example, Windows would be something like this:
f = open(r'C:\text\somefile.txt')
How would I access something from a folder saved on the Desktop of a Mac?
The desktop is just a subdirectory of the user’s home directory. Because the latter is not fixed, use something like
os.path.expanduserto keep the code generic. For example, to read a file calledsomefile.txtthat resides on the desktop, useIf you want this to be portable across operating systems, you have to find out where the desktop directory is located on each system separately.