Take the 2-minute tour ×

The following code provides my needed functionality; but, takes a bit more than 10 seconds for a table that includes 200 variables with 64000 rows. Is there a more efficient way to create a variable namespace that matches the column names?

strExec = "a = table[:]"  
for colobj in table.description._f_walk(type="Col"):  
    colName = colobj._v_pathname  
    strExec = strExec + '\n' + colName + " = a['" + colName + "']"  

The code will be executed within an analysis environment and represents a large proportion of the wait time for the end user; so, I would like confirmation that this is the best way to achieve the establishment of a namespace dynamically based upon the PyTable column names.

share|improve this question
Have you timed how long a=table[:] takes? Copying the table may be the most time consuming part. –  unutbu Sep 22 '10 at 3:25
What is the reason for wanting barename variables like colName instead of referencing the columns with a['colName']? I think the latter leads to more organized code than the former. –  unutbu Sep 22 '10 at 3:29
After timing this, copying the table is the time consumer - thank you! –  tnt Sep 22 '10 at 7:01
I think I understand your point of being more explicit with a['colName'] instead. My user will be scripting with the variable set intensively and I wanted to provide a namespace with just the barename to ease the burden from him. Good feedback on both of your points. –  tnt Sep 22 '10 at 7:06
add comment

1 Answer

up vote 1 down vote accepted

As suggested by unutbu, the table copy a=table[:] is the time consumer. The code suggested does otherwise provide access to the tablename variables without a prefix. It's acknowledged that using this method of simplifying the variable namespace is questionable as it may not lend itself to self-evident code.

share|improve this answer
add comment

Your Answer


