Skip to main content
Solved

Python problem after upgreading to FME Desktop 2019

  • May 29, 2019
  • 6 replies
  • 90 views

Hi all,

 

I have problem with small script removing accents from letters, it worked fine in FME Desktop 2018 and after upgrading it to 2019 gives me errors like:

"

Python Exception <NameError>: name 'unicode' is not defined

Error encountered while calling function `strip_accents'

API_POI_Name-strip (PythonFactory): PythonFactory failed to process feature

A fatal error has occurred. Check the logfile above for details

Bridge failed to output feature on tag `PYOUTPUT'

"

Why is so?

 


import fme

import fmeobjects

import sys

import reload(sys)

sys.setdefaultencoding("utf-8")

import re

import unicodedata

 

def strip_accents(feature):

 

n1 = feature.getAttribute('Name_1')

n2 = feature.getAttribute('Name_2')

 

nkfd_form = unicodedata.normalize('NFKD', unicode(n1))

t1 = u"".join([c for c in nkfd_form if not unicodedata.combining(c)])

nkfd_form = unicodedata.normalize('NFKD', unicode(n2))

t2 = u"".join([c for c in nkfd_form if not unicodedata.combining(c)])

 

feature.setAttribute('Name_1', t1)

feature.setAttribute('Name_2', t2)

Best answer by david_r

Python 2 and Python 3 are not fully compatible, if you have a script developed for Python 2 you will, in most cases, have to modify it to run under Python 3.

This is particularly the case for anything dealing with unicode, as this was fundamentally changed in Python 3.

There is a tool that can help in migrating code from Python 2 to 3:

https://docs.python.org/2/library/2to3.html

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

david_r
Celebrity
  • May 29, 2019

Is your workspace maybe configured for Python 3?


  • Author
  • May 29, 2019

Is your workspace maybe configured for Python 3?

Yes, it should be so. Scripting-> Python Compatibility is set on 'Python 3.5+'


david_r
Celebrity
  • May 29, 2019

Yes, it should be so. Scripting-> Python Compatibility is set on 'Python 3.5+'

Did you use Python 3 when running the workspace under FME 2018 as well?


  • Author
  • May 29, 2019

Did you use Python 3 when running the workspace under FME 2018 as well?

Good question. I think it was 2.7. But I've tried to change Python interpreter on 2.7 and 3, as it is in the options but errors stayed the same. How should I proceed to make it work?


david_r
Celebrity
  • Best Answer
  • May 29, 2019

Python 2 and Python 3 are not fully compatible, if you have a script developed for Python 2 you will, in most cases, have to modify it to run under Python 3.

This is particularly the case for anything dealing with unicode, as this was fundamentally changed in Python 3.

There is a tool that can help in migrating code from Python 2 to 3:

https://docs.python.org/2/library/2to3.html


  • Author
  • May 29, 2019

Python 2 and Python 3 are not fully compatible, if you have a script developed for Python 2 you will, in most cases, have to modify it to run under Python 3.

This is particularly the case for anything dealing with unicode, as this was fundamentally changed in Python 3.

There is a tool that can help in migrating code from Python 2 to 3:

https://docs.python.org/2/library/2to3.html

Thank you very much for the link! Small changes done and everything works perfect!