forked from tableau/document-api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshow_fields.py
More file actions
39 lines (35 loc) · 2.15 KB
/
show_fields.py
File metadata and controls
39 lines (35 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
############################################################
# Step 1) Use Datasource object from the Document API
############################################################
from tableaudocumentapi import Datasource
############################################################
# Step 2) Open the .tds we want to inspect
############################################################
datasources = [Datasource.from_file('world.tds'), Datasource.from_file('nested.tds')]
for sourceTDS in datasources:
############################################################
# Step 3) Print out all of the fields and what type they are
############################################################
print('----------------------------------------------------------')
print('-- Info for our .tds:')
print('-- name:\t{0}'.format(sourceTDS.name))
print('-- version:\t{0}'.format(sourceTDS.version))
print('----------------------------------------------------------')
print('--- {} total fields in this datasource'.format(len(sourceTDS.fields)))
print('----------------------------------------------------------')
for count, field in enumerate(sourceTDS.fields.values()):
blank_line = False
if field.calculation:
print('{:>4}: field named `{}` is a `{}`'.format(count+1, field.name, field.datatype))
print(' field id, caption, calculation: `{}`, `{}`, `{}`'.format(field.id, field.caption,
field.calculation))
blank_line = True
if field.default_aggregation:
print('{:>4}: `{}` is a `{}`, default aggregation is `{}`'.format(count+1, field.name, field.datatype,
field.default_aggregation))
if field.description:
print('{:>4}: `{}` is a `{}`, description is `{}`'.format(count+1, field.name, field.datatype,
field.description))
if blank_line:
print('')
print('----------------------------------------------------------')