Project-wide variable...

Noah Hall enalicho at gmail.com
Thu Jun 23 10:55:35 EDT 2011


On Thu, Jun 23, 2011 at 3:09 PM, Gnarlodious <gnarlodious at gmail.com> wrote:
> On Jun 23, 7:59 am, Noah Hall wrote:
>> >>>from a import x
>
> I'm doing that:
> import Module.Data as Data

Well, that's not quite the same. You're using Module.Data as Data - I
guess you've done this because you've realised that import Module
means you still have to write Module.Data every time. But the correct
way to is state exactly which function or object you want - for
example, from Module import Data. Simple, right? I mean, you almost
had it, but it seems like you've gotten a little confused with various
theories.


>
> However I end up doing it in every submodule, so it seems a little
> redundant. I wish I could load the variable in the parent program and
> have it be available in all submodules. Am I missing something?

Well, generally, if you've got a variable that you need in all your
sub-modules, the chances are that your code infrastructure needs a bit
of reordering (at least, that's what I find in my case). Without
seeing your code, though, I would find it hard to make a judgement on
what you need. Perhaps reading up on the documentation will help -
http://docs.python.org/tutorial/modules.html#packages

Noah.



More information about the Python-list mailing list