Hi I nedd to create a script in Python for use in ArcMap 10. This script must be able to calculate a field from the shp currently selected in ArcMap. Any ideas?, I'm new to Python so any code example will be most welcome. Thank you, I'm confident you will be able to help me
After running a tool in ArcMap you can go to the results window (Geoprocessing > Results) and right click on the finished tool. This will give the option to copy the Python code that you can then paste into your Python shell of choice. This is a great way to begin learning. After working with Python for a couple years now I still find myself doing this just to find out how the GP tool wants the parameters.
Unless I'm missing something from your question, you're just asking how to calculate [field2] from [field1] in the same shapefile, correct? If so, you just need to use the "Calculate Field" tool to do this. And if you just want to run this tool on a selected feature(s), all ArcGIS tools will only work on the selection set if one exists.
ArcGIS Help has python code examples that show exactly how to do it in Python.
Look in the "Code Sample" section about halfway down help. Their [generalized] example is:
If that is all you are after, it's pretty simple.