Question: This code:

```
for root, dirs, files in os.walk('.'):
    print(root)

```

Gives me this error:

```
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc3' in position 27: surrogates not allowed

```

How do I walk through a file tree without getting toxic strings like this?

Answer: 
I ended up passing in a byte string to `os.walk()` which will apparently return byte strings instead of incorrect unicode strings

```
for root, dirs, files in os.walk(b'.'):
    print(root)

```
Filter with `sed` or `grep`:

```
set | sed -n '/^[a-zA-Z0-9_]*=/p'
# ... or ...
set | grep '^[a-zA-Z0-9_]*='
# ... or ...
set | egrep '^[_[:alnum:]]+='

```

This is sensitive to how crazy your variable names are. The last version should handle most crazy things.