Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i have some code that creates a bunch of variable names with their intended values. the names are formed in strings. is eval() safe to get these all assigned in the local namespace as their names and values are created?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
i took my original problem and re-expressed it as a problem setting local variables (before i asked here). doing this as in a dict had a complication that doing things as locals would solve. i'll need to go back to the original problem and try it again as a dict. a way to set an arbitrary named local would have solved it. but Python seems to resist that (though globals seem OK).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
"storing arbitrary variable names in local space" is X in an XY problem? i came up with what i thought was a solution, but a small part of it had a problem. my posted question was to see if that small part had a solution. apparently not and my interim solution it is a part of can't be viable. back to square [0][0].
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,789
Threads: 76
Joined: Jan 2018
(Aug-31-2024, 02:21 AM)Skaperen Wrote: my posted question was to see if that small part had a solution. apparently not
The main question is why do you want to create automatically a bunch of variable names? This is the unusual part, so tell us really why you need this. That's where you tell us your solution instead of telling us your problem.
buran and
ndc85430 like this post
« We can solve any problem by introducing an extra level of indirection »
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
it's apparently not a solution. a dict seems to be the way to go. i will just have to automatically translate code in a different way (to use an indexed dict instead of a variable name, everywhere such variables would have been). there will be a mix of code sources in this. first thoughts on design are being kicked out.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.