I know you can populate lists using a one line "x for x in y" style loop, is it possible to do it using with?
I tried pulling all lines from a text file into a list and it didn't seem to work, at least not the way I tried it.
I tried:
lines = [ x with open("text.txt").readlines() as x]
and
lines = [ x.readlines() with open("text.txt") as x]
which would seem to use the same format but gives me an invalid syntax error. I appreciate I could do it with a for but I'd like to save myself the job of using a close()
Is this possible or am I grasping at straws? This is Python 2 by the way.