Solved

Python function enumerate


Badge

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.
icon

Best answer by david_r 23 August 2016, 12:25

View original

10 replies

Userlevel 2
Badge +17
It seems that there is no problem in the script. Did you check whether the source text file actually contains some lines?

 

Userlevel 4

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

Badge

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

 

 

Badge

Probably specify input file by full path?

Badge

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.

 

 

Badge
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.

 

 

Userlevel 4
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

 

 

Badge
Fixed the typo, should work now

 

 

myFile: []

 

You all were right...

 

 

Userlevel 2
Badge +17
Actually, I can't figure it out how to check by the logger.

 

 

Follow David's suggestion.

 

Badge
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.

 

 

Reply