Python Global State

2009-02-03 Thread er
Simple question, I think: Is there a way to make a completely global
variable across a slew of modules?  If not, what is the canonical way to
keep a global state?  The purpose of this is to try to prevent circular
module imports, which just sort of seems nasty.  Thank you!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Global State

2009-02-03 Thread er
That was my hack for one other app, but I did it because I'd only been
studying Python for a month or two.  Glad to see others did it once as well,
but that we all wised up.  =P

It might be nice if Python could provide a global dictionary, perhaps _G{},
where you can throw things.  This is actually the solution provided by the
Lua scripting language.  Thanks for the global_ module solution, I was just
making sure that was the canonical way.

On Tue, Feb 3, 2009 at 1:27 PM,  wrote:

> Quoth MRAB :
> > er wrote:
> > > Simple question, I think: Is there a way to make a completely global
> > > variable across a slew of modules?  If not, what is the canonical
> > > way to keep a global state?  The purpose of this is to try to prevent
> > > circular module imports, which just sort of seems nasty.  Thank you!
> > >
> > Simple answer: no.
>
> I'm wondering a little about posting this, but...well, the answer actually
> isn't "no".  It's just that it's not something you should _ever_ do.
> The trick is to assign the value to the __builtins__ module...
>
> --RDM
>
> PS: I know this because Zope used to do it.  Fortunately they wised
> up and refactored that code to be more sane.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Lists implemented as integer-hashed Dictionaries?

2009-02-06 Thread er
Somebody much more intelligent than I said today that someone told him that
Python lists are just dictionaries with lists hashed by integers.  Since he
said that someone else told him this, I piped up and said that I thought
that wasn't true.  I looked at the source code for lists in python, and I
did not expressly remember seeing dictionaries.  Unfortunately I am not
somewhere where I can easily look at the code right now (I'm logged into
Windows!), and I might not realize exactly what I'm looking at anyways, but
I'd like to extend an apology to the guy soon if I was wrong.  So, can
anyone tell me if lists are really just dictionaries?  Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lists implemented as integer-hashed Dictionaries?

2009-02-06 Thread er
Correction, the first sentence should read, "lists are just dictionaries
keyed with integers."

On Fri, Feb 6, 2009 at 10:18 PM, er  wrote:

> Somebody much more intelligent than I said today that someone told him that
> Python lists are just dictionaries with lists hashed by integers.  Since he
> said that someone else told him this, I piped up and said that I thought
> that wasn't true.  I looked at the source code for lists in python, and I
> did not expressly remember seeing dictionaries.  Unfortunately I am not
> somewhere where I can easily look at the code right now (I'm logged into
> Windows!), and I might not realize exactly what I'm looking at anyways, but
> I'd like to extend an apology to the guy soon if I was wrong.  So, can
> anyone tell me if lists are really just dictionaries?  Thanks!
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Lists implemented as integer-hashed Dictionaries?

2009-02-06 Thread er
Thanks Chris.  Lua tables are one of my favorite linguistic traits, which
was actually part of the discussion that brought up this nugget.
Nevertheless, any details you care to provide about the details.  I'm going
to dive into the source code in more depth tomorrow, just so I can get a
better understanding anyway, but I'd love to hear some details, or see any
links, if you have them.

On Fri, Feb 6, 2009 at 10:25 PM, Chris Rebert  wrote:

> On Fri, Feb 6, 2009 at 7:18 PM, er  wrote:
> > Somebody much more intelligent than I said today that someone told him
> that
> > Python lists are just dictionaries with lists hashed by integers.  Since
> he
> > said that someone else told him this, I piped up and said that I thought
> > that wasn't true.  I looked at the source code for lists in python, and I
> > did not expressly remember seeing dictionaries.  Unfortunately I am not
> > somewhere where I can easily look at the code right now (I'm logged into
> > Windows!), and I might not realize exactly what I'm looking at anyways,
> but
> > I'd like to extend an apology to the guy soon if I was wrong.  So, can
> > anyone tell me if lists are really just dictionaries?  Thanks!
>
> They most certainly are not. This is Python, not Lua or PHP (where for
> reasons I cannot fathom, they've seen fit to conflate dictionaries and
> lists; although it does make slightly more sense in Lua's case)
>
> Cheers,
> Chris
>
> --
> Follow the path of the Iguana...
> http://rebertia.com
>
--
http://mail.python.org/mailman/listinfo/python-list