Skip to content
Advertisement

Generator function for file reading returning object type as regular function

I am trying to create a generator function to return the content of a .csv file row by row and while the generator function does seem to be iterable with me being able to loop over it with a for loop, when I print the object type of the generator function, instead of returning class ‘generator’, it returns class ‘function’. The generator function also has a memory size consistent with it being a generator function.

The function code:

JavaScript

This returns the output:

<function file_row_generator at 0x00F3BC40>

<class ‘function’>

68

0.05980682373046875

Advertisement

Answer

file_row_generator is a function that returns a generator. Try print(file_row_generator()).

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement