Я пытаюсь присвоить переменной значение строки и даты, используя exec ().
Я изначально получал
SyntaxError: unqualified exec is not allowed in function 'getinfo' it contains a nested function with free variables when I tried to execute it like exec('person_{} = entries[index].who.encode("UTF8")' ).format(number_of_credits)
Я перепробовал все, он работает без каких-либо ошибок, когда я использую globals (), locals (), но не выдает вывод.
def getinfo(client, ticket):
if ticket.number ==3:
stuck = list(response.ticket.approval.approvers)
for i in stuck:
if "status: CURRENT_PENDING" in str(i):
stuck_on= str(i).splitlines()
stuck_on= stuck_on[1]
stuck_on= stuck_on.replace('assignees: ', "")
stuck_on= stuck_on.replace('"', "")
entries= response.ticket.core.worklog.entries
number_of_approvals = 0
index =-1
for e in entries:
index+=1
if 'Credit' in e.comment:
number_of_credits +=1
credits= 'person_{}'.format(number_of_credits)
credit_date = 'person_date_{}'.format(number_of_credits)
_locals = locals()
exec('credits = entries[index].who.encode("UTF8")', globals(), _locals)
exec('credit_date = time.strftime("%Y-%m-%d", time.localtime(int(str(entries[index].when)[:-3])))', globals(), _locals)
как можно больше людей и дат я хотел бы присвоить им значения. I.e person_1 = records [index] .who.encode ("UTF8"), который оценивается как "Bob" и person_date_1 = "2009-01-08"