Output of selected multiple rows from power table

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.

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?

Post your whole code.

Here's my whole code

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.

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'

No worries lol

print ",".join(projectLst)

print "'" + "', '".join(projectLst) + "'"

'Project 1', 'Project 2'

1 Like

Yey bless you! Thank you again! :hugs:

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