I'm using a power table and the users want to select multiple rows (I have this enabled on the property as well)
I want to output the rows they selected as I'm also going to be using this as a filter in one of my bindings.
So far my code is:
if len(dRow) >= 2:
for index in dRow:
project = table.data.getValueAt(index, "Project")
print project
When I print this the output is similar to
Project1
Project2
It outputs it like that separately.
I'm trying to output it in a one line where it would show as
Project1, Project2,
I tried doing
print project + ","
But that resulted it
Project1,
Project2,
Its close but I want it to be in a one line. What would be the correct concat syntax for this?
Thank you for the help.
wking
December 17, 2020, 8:03pm
2
projectLst = []
if len(dRow) >= 2:
for index in dRow:
projectLst.apend(table.data.getValueAt(index, "Project"))
print projectLst
The output of this was
[u'Project1']
[u'Project1', u'Project2']
Thank you, it's close but how come it also printed the "Project1" on the top?
wking
December 17, 2020, 8:16pm
6
yehet73190:
table = event.source.parent.getComponent(‘Power Table’)
dRow = table.getSelectedRows()
projectLst =
if len(dRow) == 1:
for index in dRow:
Project = table.data.getValueAt(index, "Project")
event.source.parent.getComponent('Power Table').project = Project
print Project, "1"
elif len(dRow) >= 2:
for index in dRow:
projectLst.append(table.data.getValueAt(index, "Project"))
print projectLst #<-----------
Dedent print. You're printing inside a loop and you don't want to be.
1 Like
ahhh its always the smallest things lol. Thank you
How do I get rid of the "u" and square brackets next to it?
[u’Project1’, u’Project2’]
I tried adding "str" at the end
str(projectLst)
but it didn't work.
wking
December 17, 2020, 8:34pm
8
the u doesn’t mean anything. Its just saying its a Unicode object.
print ' '.join(projectLst)
1 Like
You’re awesome, thank you!
1 Like
Hi again, sorry im just a little lost, when using .join how can I modify this so that each of the string that was split into has an apostrophe, so that it would look like this:
'Project1', 'Project2'
wking
December 17, 2020, 9:18pm
11
No worries lol
print ",".join(projectLst)
wking
December 17, 2020, 9:20pm
12
print "'" + "', '".join(projectLst) + "'"
'Project 1', 'Project 2'
1 Like
Yey bless you! Thank you again!
wking
December 17, 2020, 9:26pm
14
You probably dont want the space in there. use this instead.
print "'" + "','".join(projectLst) + "'"
1 Like
A variation on the same idea:
print ",".join("'%s'" % project for project in projectLst)
2 Likes