Calculate field question

460
3
Jump to solution
05-03-2012 01:44 PM
MichaelMiller2
Occasional Contributor III
Any idea why the following code will not work? If I take out the " " and one +, it will run, but not the result I need.

#dateTimeExp = "!AccDate! + " " + !AccTime!" dateTimeExp = "str(!AccDate! + " " + !AccTime!)" arcpy.CalculateField_management(outCrash, "AccDT", dateTimeExp, "PYTHON")



It returns the following error:
ExecuteError: ERROR 000539: Error running expression: str("4/1/2005" +  + "7:35:00 AM") <type 'exceptions.TypeError'>: bad operand type for unary +: 'str'
Failed to execute (CalculateField).
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor
Doh, Mathew beat me, but this also works.
exp = 'str(!AccDate!) + " " + str(!AccTime!)'

View solution in original post

0 Kudos
3 Replies
MathewCoyle
Frequent Contributor
Try this.
dateTimeExp = "str(!AccDate!) + ' ' + str(!AccTime!)"
0 Kudos
DarrenWiens2
MVP Honored Contributor
Doh, Mathew beat me, but this also works.
exp = 'str(!AccDate!) + " " + str(!AccTime!)'
0 Kudos
MichaelMiller2
Occasional Contributor III
Thank you gentlemen!

I'm just getting up to speed with Python and this list is great for nudging me over the hurdles.

Michael Miller
0 Kudos