Skip to main content
Solved

Python function enumerate

  • August 23, 2016
  • 10 replies
  • 25 views

Forum|alt.badge.img

I have a PythonCaller with a script using the unumerate function.

In my Python IDE, it works fine. In my FME project on my laptop either.

 

But, when I copy it in a FME project on another computer (VM actually), the enumerate line seems to be passed without an error message.
 	finalFieldListOutput = []
        with open('formDataOutput.txt') as myFile:
            logger.logMessageString("2dans le with IIIIIIIIIIIIIIII")
            for number, line in enumerate(myFile, 1):
                logger.logMessageString("2dans le for OOOOOOOOOOOOOOOOO")
                if 'FieldName:' in line:
                    logger.logMessageString("2dans le if FFFFFFFFFFFFFFFF")

In the FME logger, there is just "2dans le with IIIIIIIIIIIIIIII".

 

In all the situation, I'm using Python 2.7. So I cannot see where is the problem.

Best answer by david_r

I'm guessing that "myFile" is empty on your VM, in which case enumerate() does nothing.

Maybe try logging the contents of "myFile" on line 3 and check:

logger.logMessageString("myFile: " + repr(myFile.readlines()))

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.

10 replies

takashi
Celebrity
  • August 23, 2016
It seems that there is no problem in the script. Did you check whether the source text file actually contains some lines?

 


david_r
Celebrity
  • Best Answer
  • August 23, 2016

I'm guessing that "myFile" is empty on your VM, in which case enumerate() does nothing.

Maybe try logging the contents of "myFile" on line 3 and check:

logger.logMessageString("myFile: " + repr(myFile.readlines()))


Forum|alt.badge.img
  • Author
  • August 23, 2016

I'm guessing that "myFile" is empty on your VM, in which case enumerate() does nothing.

Maybe try logging the contents of "myFile" on line 3 and check:

logger.logMessageString("myFile: " + repr(myFile.readlines()))

error message : 

 

TypeError: cannot concatenate 'str' and 'list' objects

 

and if remove the string, I have : 

 

TypeError: must be string, not list

 

 


Forum|alt.badge.img
  • August 23, 2016

Probably specify input file by full path?


Forum|alt.badge.img
  • Author
  • August 23, 2016

I'm guessing that "myFile" is empty on your VM, in which case enumerate() does nothing.

Maybe try logging the contents of "myFile" on line 3 and check:

logger.logMessageString("myFile: " + repr(myFile.readlines()))

I saw the FME API documentation but, I can't figure out what is the right one.

 

 


Forum|alt.badge.img
  • Author
  • August 23, 2016
It seems that there is no problem in the script. Did you check whether the source text file actually contains some lines?

 

Actually, I can't figure it out how to check by the logger.

 

 


david_r
Celebrity
  • August 23, 2016
error message :

 

TypeError: cannot concatenate 'str' and 'list' objects

 

and if remove the string, I have :

 

TypeError: must be string, not list

 

 

Fixed the typo, should work now

 

 


Forum|alt.badge.img
  • Author
  • August 23, 2016
Fixed the typo, should work now

 

 

myFile: []

 

You all were right...

 

 


takashi
Celebrity
  • August 24, 2016
Actually, I can't figure it out how to check by the logger.

 

 

Follow David's suggestion.

 


Forum|alt.badge.img
  • Author
  • August 24, 2016
Finally it was, indeed, a problem of empty file. The real cause was far among this lines. My FME project is linked to another software of my company. This sogtware was unable to let run a system command. But problem solved. Thanks guys.