In my python Script I have:
user = nuke.getInput("Frames Turned On")
userLst = [user]
print userLst
Result:
['12,33,223']
I was wondering How I would remove the '
in the list, or somehow convert it into int?
In my python Script I have:
user = nuke.getInput("Frames Turned On")
userLst = [user]
print userLst
Result:
['12,33,223']
I was wondering How I would remove the '
in the list, or somehow convert it into int?
Use split()
to split at the commas, use int()
to convert to integer:
user_lst = map(int, user.split(","))
There's no '
to remove in the list. When you print a list, since it has no direct string representation, Python shows you its repr
—a string that shows its structure. You have a list with one item, the string 12,33,223
; that's what [user]
does.
You probably want to split the string by commas, like so:
user_list = user_input.split(',')
If you want those to be int
s, you can use a list comprehension:
user_list = [int(number) for number in user_input.split(',')]
[int(s) for s in user.split(",")]
I have no idea why you've defined the separate userLst
variable, which is a one-element list.
>>> ast.literal_eval('12,33,223')
(12, 33, 223)
>>> result = ['12,33,223']
>>> int(result[0].replace(",", ""))
1233233
>>> [int(i) for i in result[0].split(',')]
[12, 33, 233]
You could use the join method and convert that to an integer:
int(''.join(userLst))
1233223