File not closed

ast none at gmail.com
Wed Mar 20 04:18:04 EDT 2019


Hello

In the following snippet, a file is opened but
without any variable referring to it.
So the file can't be closed.

[line.split(":")[0]
  for line in open('/etc/passwd')
  if line.strip() and not line.startswith("#")]

What do you think about this practice ?






More information about the Python-list mailing list