Reputation: 41
How to tell python for example, I made a program, which opens a specific .scv
In example csv=open('c:\Users\Luka\Desktop\prvi.csv','r')
But when I make an .exe file, that is required to run on all PCs. How can I swap that "Luka" so it works for any PC that has a prvi.csv file on desktop.
Upvotes: 0
Views: 366
Reputation: 2309
import os
to get username, use os.environ['username']
to construct the path to the file, in case file is on desktop on every machine, use
csv=open(os.environ['homedrive'] + os.environ['homepath'] + '\\Desktop\\prvi.csv','r')
Upvotes: 1
Reputation: 729
check out
http://docs.python.org/library/getpass.html
Should be
>>> import getpass
>>> getpass.getuser()
Store the username in a variable and substitute in your path name.
Upvotes: 0