Here are two snippets of code:

Code 1:

```
# -*- coding: utf-8 -*-
class Foo:
    with open('myfile.json') as f:
        bar = json.loads(f)
    del f

    def __init__(self):
        print('Constructor')

# end of file

```

Code 2:

```
# -*- coding: utf-8 -*-
class Foo:
    def __init__(self):
        print('Constructor')

with open('myfile.json') as f:
    Foo.bar = json.loads(f)
del f

# end of file

```

Is there any difference between these two codes? If not, which one is to be preferred?