I am writing a Python module whose purpose is to export a single data structure. I believe this means my module should export a single symbol (e.g. `foo`), with all its other symbols being underscore-prefixed. 

Generating the data structure takes a fair amount of code - how should I structure the module to ensure that no symbols within this code are exported without a prefix? Two possible approaches are:

1. Put the generation code at the top-level, being careful to use underscores throughout, e.g.:

```
_bar = ...
for _i in ...:
    _bar.append(...)

foo = [_bar, ...]

```
2. Put the generation code within a function which returns the data structure. This requires only the function name to use an underscore. For example:

```
def _generate_foo():
    bar = ...
    for i in ...:
        bar.append(...)
    return [bar, ...]

foo = _generate_foo()

```

Is either of these approaches considered better? Or, is there another way to structure this module which would be preferred?