View Dataset from script console

Is there an easy way to view a dataset from the script console while developing?

The easiest way I know of would be to iterate through it and print it .

Check the following page for an example.

That’s what i ended up doing, thank you.

Sorry, I’m on vacation, but family is napping, so I get to play. Yes, this is how I relax. Don’t judge.

def printDataSet(datasetIn):
	# Get Row and Column counts
	nrows = datasetIn.getRowCount()
	ncols = datasetIn.getColumnCount()
	
	# Get max length of row labels
	rowLen = len(max(['row']+[unicode(i) for i in range(nrows)], key=len))
	# Get column names
	colNames = datasetIn.getColumnNames()
	# initialize lists to process columns
	headerList = []
	colData = []
	maxLen = []
	# Process columns
	for i, col in zip(range(ncols), colNames):
		# Get column as list, converting all elemenst to unicode strings
		colIn = ([unicode(element) for element in list(datasetIn.getColumnAsList(i))])
		# Get max lentgh of the column, including the column name
		maxLen = len(max([col]+colIn, key=len))
		# Append data as left justified strings.
		# ljust() will automatically pad to the max string length
		colData.append([element.ljust(maxLen) for element in colIn])
		# Append column name, also using the max string length
		headerList.append(col.ljust(maxLen))
		
	# Concatenate the header string and print it.
	headerString= 'row'.ljust(rowLen) + ' | ' + ' | '.join(headerList)
	print headerString
	# Print a bunch of dashes the same length as the header string
	print'-' * len(headerString)
	
	# Print the rows
	for row in enumerate(zip(*colData)):
		print unicode(row[0]).ljust(rowLen) + ' | ' + ' | '.join(row[1])

Sample output:

row | fgPartNum | Motor    | Harness    | Latch      | DCM        | PSAT       | Antenna | Speaker    | Chassis    | PO     | Description         
--------------------------------------------------------------------------------------------------------------------------------------------------
0   | 4CJ9902   | N/A      | 68343451AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
1   | 4CJ9904   | N/A      | 68343389AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
2   | 4CJ9906   | N/A      | 68483665AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
3   | 4CJ9908   | N/A      | 68505567AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
4   | 4CJ9910   | N/A      | 68457400AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
5   | 4CJ9914   | N/A      | 68483666AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
6   | 4CJ9916   | N/A      | 68483667AA | 68366541AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
7   | 4CJ9918   | N/A      | 68448401AA | 68366541AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
8   | 4CJ9920   | N/A      | 68506501AA | 68367059AA | 68203031AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
9   | 4CJ9922   | N/A      | 68343451AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
10  | 4CJ9924   | N/A      | 68343389AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
11  | 4CJ9926   | N/A      | 68483665AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
12  | 4CJ9930   | N/A      | 68457400AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
13  | 4CJ9932   | N/A      | 68505567AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
14  | 4CJ9934   | N/A      | 68483666AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
15  | 4CJ9936   | N/A      | 68483667AA | 68366541AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
16  | 4CJ9938   | N/A      | 68448401AA | 68366541AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
17  | 4CJ9940   | N/A      | 68506501AA | 68367059AA | 68203033AA | 68370843AA | N/A     | N/A        | 68426067AA | 123456 | LH FRONT            
18  | 4CJ9952   | CM094380 | 68343453AA | 68366543AA | N/A        | N/A        | N/A     | 68426487AA | 68426071AA | 123456 | LH REAR AUTO DOWN   
19  | 4CJ9954   | CM094380 | 68447658AA | 68366543AA | N/A        | N/A        | N/A     | 68426487AA | 68426071AA | 123456 | LH REAR AUTO DOWN   
20  | 4CJ9956   | CM094380 | 68483657AA | 68366543AA | N/A        | N/A        | N/A     | 68347029AA | 68426071AA | 123456 | LH REAR AUTO DOWN   
21  | 4CJ9958   | CM094360 | 68447659AA | 68366543AA | N/A        | N/A        | N/A     | 68347029AA | 68426071AA | 123456 | LH REAR AUTO UP/DOWN
22  | 4CJ9960   | CM094360 | 68447660AA | 68366543AA | N/A        | N/A        | N/A     | 68459976AA | 68426071AA | 123456 | LH REAR AUTO UP/DOWN
23  | 4CJ9962   | CM094380 | 68343449AA | 68366543AA | N/A        | N/A        | N/A     | N/A        | 68426071AA | 123456 | LH REAR AUTO DOWN   
13 Likes

I get NameError: global name 'tagIn' is not defined, first line under your for i, col in zip(range(ncols), colNames):

Change tagIn to datasetIn

1 Like

Yep. Script updated.