How to convert generator object into list?

Viewed 91384

My code

def yieldlines(thefile, whatlines):
  return (x for i, x in enumerate(thefile) if i in whatlines)

file1=open('/home/milenko/EDIs/site1/newst2.txt','r')
whatlines1 = [line.strip() for line in open('m1.dat', 'r')]

x1=yieldlines(file1, whatlines1)

print x1

I got

<generator object <genexpr> at 0x7fa3cd3d59b0>

Where should I put the list,or I need to rewrite the code?

I want my program to pen the file and read the content so for specific lines that are written in m1.dat.I have found that solution Reading specific lines only (Python)

2 Answers
Related