Drop usage of obsolete function "file"

Also use context manager