Sharing package data across files

scottpakin1 at gmail.com scottpakin1 at gmail.com
Tue Jun 28 19:51:24 EDT 2016


On Tuesday, June 28, 2016 at 4:37:45 PM UTC-6, Michael Selik wrote:
> Why do you want to?

I have a standalone script that grew and grew until reaching an unmaintainable size.  I was hoping to refactor it into a relatively small top-level script plus a package containing a bunch of relatively small files.

> Isn't easier to have the ``funcs`` module import the ``vars`` module?

Easier, yes.  Correct, no:

    from vars import foo

    def bar():
        global foo
        foo += 1
        return foo

which surprisingly (to me, anyway) changes a _copy_ of foo, not the foo I'd think of as belonging to the example package:

    >>> from example import foo, bar
    >>> foo
    123
    >>> bar()
    124
    >>> foo
    123

> Even easier, paste all the code into a single file.

That kind of defeats my goal of splitting a single file into more maintainable chunks.

Thanks,
-- Scott



More information about the Python-list mailing list