Hi, i am trying to use row.setValue to set the field value of my username column to my username. Is there another way i can automate this with python as my code below is not working:
row.setValue("INTERNAL_ROW_CREATED_BY", userName())
If you look at the thread on stack overflow:
portability - Is there a portable way to get the current username in Python? - Stack Overflow
... there are some examples provided to get the current user name which worked on my system (Windows 8.1, Python 2.7):
import os print os.environ["USERNAME"] print os.path.split(os.path.expanduser('~'))[-1] import getpass print getpass.getuser()
They all printed my current user name.
Kind regards,
Xander
thanks xander. i used getpass and it worked
it's okay Dan. Thanks for trying to help.
Sorry, can't find userName() as a reference property anywhere except when associated with server stuff
Hi. Here is the code:
# Import all necessary modules
import os, sys, arcpy
from arcpy import env
outpath = "C:/Users/ssantos/Desktop/Overarching/Vector/TEMP.gdb/"
# Get the information you need to populate temporary table
a = arcpy.GetParameterAsText(0).upper()
b = arcpy.GetParameterAsText(1).upper()
c = arcpy.GetParameterAsText(2)
d = arcpy.GetParameterAsText(3).upper()
e = arcpy.GetParameterAsText(4)
f = arcpy.GetParameterAsText(5).upper()
g = arcpy.GetParameterAsText(6).upper()
h = arcpy.GetParameter(7)
i = arcpy.GetParameter(8)
j = arcpy.GetParameter(9)
k = arcpy.GetParameter(10)
l = arcpy.GetParameter(11)
m = arcpy.GetParameter(12)
n = arcpy.GetParameterAsText(13)
o = arcpy.GetParameterAsText(14)
# Create insert cursor for temporary tablerows = arcpy.InsertCursor(outpath + "temptbl","")
#Inserts a row into the tabletry: for x in xrange(1,2): row = rows.newRow() row.setValue("GDA_FORM_NUMBER", a) row.setValue("JOB_COORDINATOR", b) row.setValue("JC_PHONE_NUMBER", c) row.setValue("SUPERVISOR", d) row.setValue("SR_PHONE_NUMBER", e) row.setValue("CONTRACTOR", f) row.setValue("PLANT_AREA", g) row.setValue("ESTIMATED_START", h) row.setValue("ESTIMATED_END", i) row.setValue("GDA_DUE_DATE", j) row.setValue("CENTER_X_COORD", k) row.setValue("CENTER_Y_COORD", l) row.setValue("WORKAREA", m) row.setValue("CLOSED", n) row.setValue("DESCRIPTION", o) row.setValue("EXTERNAL_SOURCE", "GDA PERMIT TABLE") row.setValue("EXTERNAL_SOURCE_DOCUMENT", "GDA FORM") row.setValue("INTERNAL_ROW_CREATED_DATE", time.strftime("%x %X", time.localtime())) row.setValue("INTERNAL_ROW_CREATED_BY", userName()) row.setValue("INTERNAL_ACTIVE_IND","Y") rows.insertRow(row)except: print arcpy.GetMessages(1)
# Delete cursor and row objects to remove locks on the datadel rowdel rows
Can you post all the code, one line out of an updatecursor isn't going to provide much information
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.