VB to python

406
1
06-28-2011 12:51 AM
TomasTencer
New Contributor II
Hi could anyone please, help me to rewrite the code from VB to python?
Expresion:
strCobj


Dim strCobj as string
If Mid ( [PointId],2,1 ) = 1 Then
strCobj = "O"& Mid ( [PointId],3,3 )

elseif Mid ( [PointId],2,1 ) = 9 Then
strCobj = ""

elseif Mid ( [PointId],2,1 ) = 0 Then
strCobj = "F"& Mid ( [PointId],3,3 )

end if


So far Im failed.
I m using arcgis10 and the old one VB code doesnt work:(

ty for any help
0 Kudos
1 Reply
BruceNielsen
Regular Contributor
This should be equivalent:
if PointId[1:2] == 1:
  strCobj = "O" + PointId[2:5]
elif PointId[1:2] == 9:
  strCobj = ""
elif PointId[1:2] == 0:
  strCobj = "F" + PointId[2:5]

Python thinks in terms of offsets from the first position, so the first character has an offset of 0. Check out the section on 'slicing' in the tutorial that comes with Python help.
0 Kudos