Defer In Python you can sort of achive the same thing by keeping the contentbetween the and the block short. Gopackage main "os") func main() { defer f.Close() // you can now read from this // `f` thing and it'll be closed later