And I'd not use a `try` for checking whether there is a `name` on `fileobj`, you can use `hasattr`:
```python
if hasattr(fileobj, 'name'):
    …
```