Solved

Python problem after upgreading to FME Desktop 2019


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)

icon

Best answer by david_r 29 May 2019, 11:36

View original

6 replies

Userlevel 4

Is your workspace maybe configured for Python 3?

Is your workspace maybe configured for Python 3?

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

Userlevel 4

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?

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?

Userlevel 4

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

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!

Reply