Skip to main content
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)

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

View original
Did this help you find an answer to your question?

6 replies

david_r
Evangelist
  • May 29, 2019

Is your workspace maybe configured for Python 3?


  • Author
  • May 29, 2019
david_r wrote:

Is your workspace maybe configured for Python 3?

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


david_r
Evangelist
  • May 29, 2019
kabinczyk wrote:

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
david_r wrote:

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
Evangelist
  • 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
david_r wrote:

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings