Python Forum
Create, assign and print variables in loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create, assign and print variables in loop
#8
Why does it confuse you?

It would be possible to do what you wanted, but you'd have to make more use of exec (or eval, I guess). What are the problems with that? There are at least two:

1. Those functions allow any arbitrary Python expression to be entered in a string. So, if data came in from a user, that could present a security risk (in the same way that SQL injection does).

2. You'd end up having a lot of code written in the strings you pass to those functions. That's quickly going to become unreadable as you'll lose the benefits of syntax highlighting in your editor/IDE, not to mention that you'll have lots of concatenation which you won't if you're just writing Python code in the file.
Reply


Messages In This Thread
RE: Create, assign and print variables in loop - by ndc85430 - May-28-2020, 03:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Create X Number of Variables and Assign Data RockBlok 8 1,168 Nov-14-2023, 08:46 AM
Last Post: perfringo
  How to create a variable only for use inside the scope of a while loop? Radical 10 2,185 Nov-07-2023, 09:49 AM
Last Post: buran
Question How create programmatically variables ? SpongeB0B 6 1,532 Aug-19-2023, 05:10 AM
Last Post: SpongeB0B
  How to print variables in function? samuelbachorik 3 999 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,594 Jul-27-2022, 08:50 PM
Last Post: rob101
  Create array of values from 2 variables paulo79 1 1,177 Apr-19-2022, 08:28 PM
Last Post: deanhystad
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,604 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  How to create 2 dimensional variables in Python? plumberpy 5 2,007 Mar-31-2022, 03:15 AM
Last Post: plumberpy
  how to use 3 variables python loop evilcode1 2 1,751 Nov-12-2021, 11:43 AM
Last Post: jamesaarr
  How can I assign "multiple variables" to a single "value"? Psycpus 2 1,942 Oct-04-2021, 03:29 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020