Change field names with Python

19240
20
Jump to solution
04-23-2015 09:37 PM
PV
by
New Contributor III

Hi

I have an attribute table with many fields where I have to change the field name. Most of the field names start with All_txt_ .

As I found out in the Data Management Forum, there is no way to automatically change all these field names in ArcGIS with a tool. Can someone tell me on how to do so with python? (I am not familiar with Python)

I already saw this page: Mapping input fields to output fields—Help | ArcGIS for Desktop
However, it does not really help me further as I don't know Python so well..

Best, P.

*Question is post-crossed on GIS Stack Exchange Forum

20 Replies
SepheFox
Frequent Contributor

Well, I have no problem with him trying several places to get an answer. Hopefully he will be kind enough to come back and let us know if he gets the answer he need though. Thanks for trying, Dan. Now I can see where I went wrong with my script, so it's good for me too!

PV
by
New Contributor III

Thank you Sephe FoxSol WuenschXander Bakker

Xander's code worked perfectly on ArcGIS 10.2, however I need the code for 10.1 where I got the answer on Stackexchange (I agree with Sephe, looking for the answer at different forums should be allowed)

Here the link to the code which worked for me:

python - Change field names automatically - Geographic Information Systems Stack Exchange

I got an error for Sephe's Code without the alter field management,but I am sure anyone familiar with Python could find the error very quickly.

SepheFox
Frequent Contributor

Yes, I spotted at least one myself... it should be, for field in fieldList That's what I get for trying to think so late at night. I'm glad you solved your problem. That, after all, is the point.

XanderBakker
Esri Esteemed Contributor

Hi P V ,

Could you mention the version of ArcGIS for Desktop the next time you post a question. The link in your original post to the Help links to the Help of 10.3. Hence a code that works for that version.

PV
by
New Contributor III

Hey Xander Bakker

Yes sorry my mistake, I didn't know it was different for 10.1 until I tried Sephe's code.

NeilAyres
MVP Alum

And giving yourself the answer after so many people contributed is bad form...

PV
by
New Contributor III

Hi Neil

well technically the as correct marked answer is not my answer but the one from the link I posted. Also it is the answer which worked best on my question... But yes of course it is not very polite to do so, so I can change it to another answer.

0 Kudos
Sol_Wuensch
Occasional Contributor II

IMO - It's perfectly fine to cross post your question on other forums.  However, I also think it is helpful, for those trying to help with the OP, that the OP post a link to the same question on the other forum (full disclosure is appreciated by those who try to help).  Imagine taking the time to help someone and then later finding out that they had already asked their question somewhere else and were not included in that same discussion somewhere else, or if the OP gets their answer elsewhere while other people keep looking for a solution and trying to help the OP.

In regard to "marking your own question as answered" I'm split on this topic.  I think the Correct answer is more coveted by those trying to help the OP.  From helping others myself, I know it can be disappointing when the OP marks their own question as the answer, especially since the correct answer is a nice form of recognition and gives the user points in the 'gamification' system.  From the perspective of someone looking for a correct answer it gets a little bit more complex - most likely future viewers of the thread don't care about points, they want to find the best possible answer to their own problem in a timely manner.  For a long thread with many responses, the user looking for a solution to their own problem will probably have to read most of the comments to fully understand and possibly find a solution to their problem.  Although, for future viewer the 'correct answer' may not be the one they are actually looking for.  Sometimes the user may find the answer somewhere else within the thread (possibly because their problem is similar but different and someone else's comment was the solution to their specific problem).  This is where the 'Helpful' tag on the comments proves it's value.  Anyone can mark a post as helpful and it awards the same number of points in the gamification system as a correct answer does.  It may be somewhere else in the thread...  It's important to realize that giving yourself the 'correct answer' does not award you any points in the gamification, but it might decrease the likelihood that the same user(s) will be willing to help you in the future.  I have felt this way before, although generally each situation is a bit different and open to interpretation.

P V​ Maybe you can add a comment in response to the post that helped you find the solution and explain it in the thread for future users who stumble across this thread looking for a solution?  Just a few thoughts on the subject...

PV
by
New Contributor III

I actually agree 100% with you, Sol Wuensch​. Anyways, I guess I learned the lessons on how to ask a question and tag an answer on an Esri Forum now, and I appreciate all the help I got.

And I will add a comment very soon!

DanPatterson_Retired
MVP Emeritus

And now for a different perspective...

I am active on both sites...

Nothing is more irritating than to provide an answer to a post on this site than to go to the other site and find that the OP got there answer there and didn't come back here to say...sorry for the delay...got my answer there.

What I do appreciate, is a statement like

... I have cross-posted this on GIS Stack exchange as well...

What I will do, is see what avenues have been proposed there, so I don't waste my time trying to find an answer and post the same one here.  That is why I will post a cross-thread statement if the OP has NOT taken that courtesy since, I don't want someone to waste their time pursuing a parallel investigation and finding it has been answered elsewhere.  I will, however, investigate a question, if the other site isn't following the same train of thought I would have.

So in short here are some suggestions...

  • pick a site and post your question...if you don't get an answer in a reasonable period of time, post on the other site.
  • if you choose to post on both site because of some sense of urgency, take the effort to indicate that you have done so...I know others on both sites that won't bother to research an answer if this is not done
  • if you cross-post, then indicate on both sites that you have received an answer and provide the solution you accepted.

Well that is my 2 cents worth