Drop usage of obsolete function "file"

Also use context manager
Merge pull request #339 from nanonyme/patch-1

Drop usage of obsolete function "file"