# View Dataset from script console

**URL:** <https://forum.inductiveautomation.com/t/view-dataset-from-script-console/36704>\
**Category:** Ignition\
**Created:** [July 15, 2020, 12:31am UTC](https://forum.inductiveautomation.com/t/view-dataset-from-script-console/36704 "2020-07-15T00:31:01Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 15, 2020, 11:37pm UTC](https://forum.inductiveautomation.com/t/view-dataset-from-script-console/36704/4 "2020-07-15T23:37:51Z")

</div>

Sorry, I'm on vacation, but family is napping, so I get to play. Yes, this is how I relax. Don't judge.  
~~EDIT: Added option for printing from Perspective.~~ Sorry, not quite ready for prime time. 🙄

```python
def printDataSet(datasetIn):
	from itertools import izip
	import ast
	if 'PropertyTreeScriptWrapper$ArrayWrapper' in str(type(datasetIn)):
		headers = datasetIn[0].keys()
		data = []
		for row in datasetIn:
			data.append([item.value for item in row.values()])
		
		datasetIn = system.dataset.toDataSet(headers, data)
		
	# 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 izip(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(izip(*colData)):
		print unicode(row[0]).ljust(rowLen) + ' | ' + ' | '.join(row[1])

```

Sample output:

```plaintext
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   

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/view-dataset-from-script-console/36704)._
