Skip to main content
Solved

Python function enumerate


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()))

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

10 replies

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

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

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
takashi wrote:
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
slerendu wrote:
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
david_r wrote:
Fixed the typo, should work now

 

 

myFile: []

 

You all were right...

 

 


takashi
Influencer
  • August 24, 2016
slerendu wrote:
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.

 

 


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