In article ,
Tim Chase wrote:
>Luis M. González wrote:
>>
>> If you want a list of items, you use tuples or lists. Examples:
>>
>> ('a', 'm', 'p') ---> this is a tuple, and it's made with
>> parenthesis ()
>
>Actually, a tuple is made with commas...the parens are just there
>to clarify the
The problem i see with using globals() is that it can overwrite a previously
defined function or key within the global namespace, making the code
potentially dangerous and wild with exploits.
my $0.02
-Alex Goretoy
--
http://mail.python.org/mailman/listinfo/python-list
Luis M. González wrote:
I still don't understand why is it a bad idea in the case of
globals().
This is the only way I know to define variables programatically in the
top-level namespace, without having to do it manually one by one.
The point is that creating variables whose names are computed
On Wed, 24 Feb 2010 02:58:38 -0800, Luis M. González wrote:
> I wonder why updating locals(), not from within a function, works (at
> least in my interactive session).
Because if you're in the global scope, locals() returns globals(), which
is a real namespace and modifying it works.
Inside a f
On Wed, 24 Feb 2010 13:41:08 -, Luis M. González
wrote:
This is the only way I know to define variables programatically in the
top-level namespace, without having to do it manually one by one.
We see requests for this a lot, and the response that's frequently missed
amongst all the te
Luis M. González a écrit :
On Feb 24, 8:48 am, Bruno Desthuilliers wrote:
Luis M. Gonz lez a crit :
And what about the trick of updating globals? Is it legal?
It's legal, but it's (usually) a very bad idea - at the top-level, it
harms readability, and from within a function it's doubly ba
On Feb 24, 8:48 am, Bruno Desthuilliers wrote:
> Luis M. Gonz lez a crit :
> (snip)
>
> > Alright, this is what the docs say about locals:
> > "Note
> > The built-in functions globals() and locals() return the current
> > global and local dictionary, respectively, which may be useful to pass
> > a
Luis M. González a écrit :
(snip)
Alright, this is what the docs say about locals:
"Note
The built-in functions globals() and locals() return the current
global and local dictionary, respectively, which may be useful to pass
around for use as the second and third argument to exec().
Note
The def
Luis M. González a écrit :
On Feb 23, 10:41 pm, Steven D'Aprano
wrote:
On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
By the way, if you want the variables inside myDict to be free
variables, you have to add them to the local namespace. The local
namespace is also a dictionary "lo
Luis M. González a écrit :
On Feb 23, 5:53 pm, vsoler wrote:
Hi,
I have two dicts
n={'a', 'm', 'p'}
v={1,3,7}
and I'd like to have
a=1
m=3
p=7
that is, creating some variables.
How can I do this?
You are probably coming from another language and you're not used to
python's data structur
On Feb 24, 7:44 am, Luis M. González wrote:
> On Feb 24, 4:08 am, Steven D'Aprano
>
>
>
>
>
> wrote:
> > On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. González wrote:
> > > On Feb 24, 1:15 am, Steven D'Aprano
> > > wrote:
> > >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> > >> >
On Feb 24, 4:08 am, Steven D'Aprano
wrote:
> On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. González wrote:
> > On Feb 24, 1:15 am, Steven D'Aprano
> > wrote:
> >> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> >> > On Feb 23, 10:41 pm, Steven D'Aprano
> >> > wrote:
> >> >> On Tue, 2
On Tue, 23 Feb 2010 20:44:10 -0800, Luis M. González wrote:
> On Feb 24, 1:15 am, Steven D'Aprano
> wrote:
>> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
>> > On Feb 23, 10:41 pm, Steven D'Aprano
>> > wrote:
>> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
>> >>
On Feb 24, 1:15 am, Steven D'Aprano
wrote:
> On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> > On Feb 23, 10:41 pm, Steven D'Aprano
> > wrote:
> >> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
> >> > By the way, if you want the variables inside myDict to be free
> >>
On Tue, 23 Feb 2010 19:47:22 -0800, Luis M. González wrote:
> On Feb 23, 10:41 pm, Steven D'Aprano
> wrote:
>> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
>> > By the way, if you want the variables inside myDict to be free
>> > variables, you have to add them to the local namespac
On Feb 23, 10:41 pm, Steven D'Aprano
wrote:
> On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
> > By the way, if you want the variables inside myDict to be free
> > variables, you have to add them to the local namespace. The local
> > namespace is also a dictionary "locals()". So you c
On Tue, 23 Feb 2010 15:41:16 -0800, Luis M. González wrote:
> By the way, if you want the variables inside myDict to be free
> variables, you have to add them to the local namespace. The local
> namespace is also a dictionary "locals()". So you can update locals as
> follows:
>
> locals().upd
On Feb 23, 7:56 pm, Luis M. González wrote:
> On Feb 23, 5:53 pm, vsoler wrote:
>
>
>
>
>
> > Hi,
>
> > I have two dicts
>
> > n={'a', 'm', 'p'}
> > v={1,3,7}
>
> > and I'd like to have
>
> > a=1
> > m=3
> > p=7
>
> > that is, creating some variables.
>
> > How can I do this?
>
> You are probably
Luis M. González wrote:
If you want a list of items, you use tuples or lists. Examples:
('a', 'm', 'p') ---> this is a tuple, and it's made with
parenthesis ()
Actually, a tuple is made with commas...the parens are just there
to clarify the order of operations and make it easier to read :
On Feb 23, 5:53 pm, vsoler wrote:
> Hi,
>
> I have two dicts
>
> n={'a', 'm', 'p'}
> v={1,3,7}
>
> and I'd like to have
>
> a=1
> m=3
> p=7
>
> that is, creating some variables.
>
> How can I do this?
You are probably coming from another language and you're not used to
python's data structures.
I
vsoler wrote:
Hi,
I have two dicts
n={'a', 'm', 'p'}
v={1,3,7}
Those aren't dicts, they're sets.
and I'd like to have
a=1
m=3
p=7
that is, creating some variables.
How can I do this?
The real question is not how, but why?
Anyway, assuming you want them to be global variables:
glo
On Feb 23, 12:53 pm, vsoler wrote:
> Hi,
>
> I have two dicts
>
> n={'a', 'm', 'p'}
> v={1,3,7}
>
> and I'd like to have
>
> a=1
> m=3
> p=7
>
> that is, creating some variables.
>
> How can I do this?
I think you meant to use the square brackets [ ] instead of the curly
ones { } to define the li
vsoler writes:
> Hi,
>
> I have two dicts
>
> n={'a', 'm', 'p'}
> v={1,3,7}
These are sets, not dicts.
> and I'd like to have
>
> a=1
> m=3
> p=7
As sets are unordered, you may as well have
a = 3
m = 7
p = 1
or any other permutation. You need some sequences instead. E.g.
n = [
Hi,
I have two dicts
n={'a', 'm', 'p'}
v={1,3,7}
and I'd like to have
a=1
m=3
p=7
that is, creating some variables.
How can I do this?
--
http://mail.python.org/mailman/listinfo/python-list
24 matches
Mail list logo