Python Forum
I need help with loop one function and creating variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help with loop one function and creating variables
#1
my code that is working
*****************************************************
names = ['xx','yy','cc']

for name in names:
    exec("%s_mar = []" % name)
    some code...
    else:
       pass

xx_var = countAll(xx_mar)
yy_var = countAll(yy_mar)
cc_var = countAll(cc_mar)
***********************************************************
I need help with loop one function and creating variables - code below doesn't work

for name in names:
    eval("%s_var)" % name) = countAll('{0}_mar'.format(name))
    else:
       pass
Reply


Messages In This Thread
I need help with loop one function and creating variables - by don - Jan-23-2019, 05:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to print variables in function? samuelbachorik 3 928 Dec-31-2022, 11:12 PM
Last Post: stevendaprano
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,536 Jul-27-2022, 08:50 PM
Last Post: rob101
  User-defined function to reset variables? Mark17 3 1,685 May-25-2022, 07:22 PM
Last Post: Gribouillis
  WHILE Loop - constant variables NOT working with user input boundaries C0D3R 4 1,517 Apr-05-2022, 06:18 AM
Last Post: C0D3R
  how to use 3 variables python loop evilcode1 2 1,697 Nov-12-2021, 11:43 AM
Last Post: jamesaarr
  creating a loop yk303 2 1,880 Feb-08-2021, 08:41 PM
Last Post: nilamo
  Do I have to pass 85 variables to function? Milfredo 10 4,353 Sep-26-2020, 10:13 PM
Last Post: Milfredo
  Exit Function - loop Tetsuo30 2 2,075 Sep-17-2020, 09:58 AM
Last Post: Tetsuo30
  Creating a variables inside FOR loop zazas321 5 4,142 Sep-16-2020, 04:42 PM
Last Post: Naheed
  [split] Creating a variable as a function DPaul 23 6,862 Sep-07-2020, 05:20 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

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