This question is similar to others asked on here, but after reading the answers I'm not grasping it and would appreciate further guidance. 

While sketching new code I find myself adding a lot of statements like:

```
print('var=')
pprint(var)

```

It became tedious always writing that, so I thought I could make it into a function. Since I want to print the variable name on the preceding line, I tried:

```
def dbp(var):
    eval('print(\'{0}=\')'.format(var))
    eval('pprint({0})'.format(var))

```

so then I do do things like:

```
foo = 'bar'
dbp('foo')

```

which prints

```
foo=
'bar'

```

This is all great, but when I go to use it in a function things get messed up. For example, doing

```
def f():
    a = ['123']
    dbp('a')
f()

```

raises a NameError (NameError: name 'a' is not defined).

My expectation was that dbp() would have read access to anything in f()'s scope, but clearly it doesn't. Can someone explain why? 

Also, better ways of printing a variable's name followed by its formatted contents are also appreciated.