Save a file depending on the user Python -


i try write script in python saves file in each user directory. example user 1, 2 , 3.

c:\users\user1\documents\arcgis\file1.gdb  c:\users\user2\documents\arcgis\file1.gdb  c:\users\user3\documents\arcgis\file1.gdb 

how can this?

as 1 commenter pointed out, simplest solution use userprofile environment variable write file path. like:

import os userprofile = os.environ['userprofile'] path = os.path.join(userprofile, 'documents', 'arcgis', 'file1.gdb') 

or more (with better platform-independence, work on mac osx/linux, too; credit abhijit's answer below):

import os path = os.path.join(os.path.expanduser('~'), 'documents', 'arcgis', 'file1.gdb') 

both of above may have portability issues across windows versions, since microsoft has been known change name of "documents" folder , forth "my documents".

if want windows-portable way "documents" folder, see code here: https://stackoverflow.com/questions/3858851#3859336


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -