10000 Get Fields Example Code (#51) · vegi1979/document-api-python@c8eb27e · GitHub
[go: up one dir, main page]

Skip to content

Commit c8eb27e

Browse files
author
Russell Hay
authored
Get Fields Example Code (tableau#51)
* Get Fields Example Code * Adding field count and numbering * updating comment to be accurate * Adding GetFields to travis run * Updating to use enumerate to keep track of count
1 parent d9f90f3 commit c8eb27e

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ script:
1818
# Examples
1919
- (cd "Examples/Replicate Workbook" && python replicateWorkbook.py)
2020
- (cd "Examples/List TDS Info" && python listTDSInfo.py)
21+
- (cd "Examples/GetFields" && python show_fields.py)
2122

Examples/GetFields/World.tds

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../List TDS Info/World.tds

Examples/GetFields/show_fields.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
############################################################
2+
# Step 1) Use Datasource object from the Document API
3+
############################################################
4+
from tableaudocumentapi import Datasource
5+
6+
############################################################
7+
# Step 2) Open the .tds we want to inspect
8+
############################################################
9+
sourceTDS = Datasource.from_file('World.tds')
10+
11+
############################################################
12+
# Step 3) Print out all of the fields and what type they are
13+
############################################################
14+
print('----------------------------------------------------------')
15+
print('--- {} total fields in this datasource'.format(len(sourceTDS.fields)))
16+
print('----------------------------------------------------------')
17+
for count, field in enumerate(sourceTDS.fields.values()):
18+
print('{:>4}: {} is a {}'.format(count+1, field.name, field.datatype))
19+
blank_line = False
20+
if field.calculation:
21+
print(' the formula is {}'.format(field.calculation))
22+
blank_line = True
23+
if field.aggregation:
24+
print(' the default aggregation is {}'.format(field.aggregation))
25+
blank_line = True
26+
27+
if blank_line:
28+
print('')
29+
print('----------------------------------------------------------')

0 commit comments

Comments
 (0)
0