On 03/24/2011 07:39 PM, Seldon wrote:
Hi, I have a question about generating variable assignments dynamically.
I have a list of 2-tuples like this
(
(var1, value1),
(var2, value2),
.. ,
)
where var1, var2, ecc. are strings and value1, value2 are generic objects.
Now, I would like to use data
On Fri, 25 Mar 2011 13:29:20 +0100, Seldon wrote:
> On 03/25/2011 12:05 AM, Steven D'Aprano wrote:
>> On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote:
>>
>>> Hi, I have a question about generating variable assignments
>>> dynamically.
>> [...]
>>> Now, I would like to use data contained in this l
On Fri, 25 Mar 2011 02:47:04 -0700, scattered wrote:
> I specified that the cipher text consists of characters in the range A
> to Z (note the case).
So you did. My apologies.
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 25, 5:29 am, Seldon wrote:
> I thought to refactor the code in a more declarative way, like
>
> assignment_list = (
> ('var1', value1),
> ('var2', value2),
> .. ,
> )
>
> for (variable, value) in assignment_list:
> locals()[variable] = func(arg=value, *args)
Someday we'll get throu
Jean-Michel Pichavant wrote:
Seldon wrote:
On 03/25/2011 12:05 AM, Steven D'Aprano wrote:
On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote:
Hi, I have a question about generating variable assignments
dynamically.
[...]
Now, I would like to use data contained in this list to dynamically
gene
On 03/25/2011 06:29 AM, Seldon wrote:
> Because I'm in this situation. My current code is of the form:
>
> var1 = func(arg=value1, *args)
> ..
> varn = func(arg=valuen, *args)
>
> where var1,..varn are variable names I know in advance and
> value1,..valuen are objects known in advance, too; fun
Seldon wrote:
On 03/25/2011 12:05 AM, Steven D'Aprano wrote:
On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote:
Hi, I have a question about generating variable assignments
dynamically.
[...]
Now, I would like to use data contained in this list to dynamically
generate assignments of the form "
On 03/25/2011 12:05 AM, Steven D'Aprano wrote:
On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote:
Hi, I have a question about generating variable assignments dynamically.
[...]
Now, I would like to use data contained in this list to dynamically
generate assignments of the form "var1 = value1",
On Mar 25, 1:44 am, Steven D'Aprano wrote:
>
> In my earlier post, I described the dynamic creation of variables as:
>
> "... something you should *nearly* always avoid doing." [Emphasis added.]
>
> Congratulations, you've found one of the few exceptions. Of course an
> interactive shell must allo
On Mar 24, 11:08 pm, Tim Leslie wrote:
> On 25 March 2011 13:51, scattered wrote:
>
> > Here is another possibility: you are using Python *interactively* in
> > solving cryptograms (as a matter of fact - I was doing exactly this
> > yesterday in trying to solve some Playfair ciphers). You have a
On Thu, 24 Mar 2011 17:26:34 -0500, Chris Rebert wrote:
> On Thu, Mar 24, 2011 at 1:39 PM, Seldon wrote:
>> Hi, I have a question about generating variable assignments
>> dynamically.
>
> This can frequently be a code smell.
Is there any time when it's not a code smell? A code smell is somethin
On Thu, 24 Mar 2011 19:51:08 -0700, scattered wrote:
> On Mar 24, 7:18 pm, Steven D'Aprano +comp.lang.pyt...@pearwood.info> wrote:
>> On Thu, 24 Mar 2011 14:39:34 -0700, scattered wrote:
>> > Could try:
>>
>> my_list = [("x", 7), ("y", 8)]
>> for pair in my_list: exec(pair[0] + " = " +
On 25 March 2011 13:51, scattered wrote:
> Here is another possibility: you are using Python *interactively* in
> solving cryptograms (as a matter of fact - I was doing exactly this
> yesterday in trying to solve some Playfair ciphers). You have a
> ciphertext that is a stream of letters in the ra
On Mar 24, 10:51 pm, scattered wrote:
[snip]
> I can easily imagine other
> situations in which a user might want to create a large number of
> bindings for interactive use. Maybe as a teacher (I'm a math teacher)
> you have written a student-class which contains things like methods to
> comput
On Thu, Mar 24, 2011 at 4:05 PM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:
> On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote:
>
> > Hi, I have a question about generating variable assignments dynamically.
> [...]
> > Now, I would like to use data contained in this list to dyn
On Mar 24, 7:18 pm, Steven D'Aprano wrote:
> On Thu, 24 Mar 2011 14:39:34 -0700, scattered wrote:
> > Could try:
>
> my_list = [("x", 7), ("y", 8)]
> for pair in my_list: exec(pair[0] + " = " + str(pair[1]))
> x,y
> (7,8)
>
> Please don't ever do such a thing. The world has eno
On Thu, 24 Mar 2011 14:39:34 -0700, scattered wrote:
> Could try:
>
my_list = [("x", 7), ("y", 8)]
for pair in my_list: exec(pair[0] + " = " + str(pair[1]))
x,y
(7,8)
Please don't ever do such a thing. The world has enough buggy software
vulnerable to code injection attacks
On Thu, 24 Mar 2011 19:39:21 +0100, Seldon wrote:
> Hi, I have a question about generating variable assignments dynamically.
[...]
> Now, I would like to use data contained in this list to dynamically
> generate assignments of the form "var1 = value1", ecc where var1 is an
> identifier equal (as a
On Thu, Mar 24, 2011 at 1:39 PM, Seldon wrote:
> Hi, I have a question about generating variable assignments dynamically.
This can frequently be a code smell.
> I have a list of 2-tuples like this
>
> (
> (var1, value1),
> (var2, value2),
> .. ,
> )
>
> where var1, var2, ecc. are strings and val
On Mar 24, 2:39 pm, Seldon wrote:
> Hi, I have a question about generating variable assignments dynamically.
>
> I have a list of 2-tuples like this
>
> (
> (var1, value1),
> (var2, value2),
> .. ,
> )
>
> where var1, var2, ecc. are strings and value1, value2 are generic objects.
>
> Now, I would
Seldon wrote:
Hi, I have a question about generating variable assignments dynamically.
I have a list of 2-tuples like this
(
(var1, value1),
(var2, value2),
.. ,
)
where var1, var2, ecc. are strings and value1, value2 are generic
objects.
Now, I would like to use data contained in this list
Hi, I have a question about generating variable assignments dynamically.
I have a list of 2-tuples like this
(
(var1, value1),
(var2, value2),
.. ,
)
where var1, var2, ecc. are strings and value1, value2 are generic objects.
Now, I would like to use data contained in this list to dynamically
22 matches
Mail list logo