On Tue, 6 Dec 2016 05:39 am, vmaha...@centerpointmedia.com wrote:

> Can someone help me print a generator object?

The same way as you print any other object:

print(obj)  # Python 3

print obj  # Python 2


But what you're actually asking for is a way to print the values produced by
the generator object. You do that the same way as you would print the
values produced by any sequence or iterable. You can print one value per
line:

for value in obj:
    print(value)


Or you can convert to a list, and then print the list:

print(list(obj))


Or you can format it yourself, any way you like, by writing some code:


display_string = '::'.join(str(value).upper() for value in obj)
print('[[' + display_string + ']]')




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to