| 70 | }}} |
| 71 | |
| 72 | === Load local data |
| 73 | |
| 74 | The same approach may be used for accessing your own data (e.g. in `csv` or `json` format) stored within your application directory. You need to include the file within the app package description `....pml` file as: |
| 75 | {{{#!xml |
| 76 | <Resources> |
| 77 | <File name="data.csv" src="data" /> |
| 78 | </Resources> |
| 79 | }}} |
| 80 | and load it in a Python box with correct path |
| 81 | {{{#!python |
| 82 | import csv |
| 83 | |
| 84 | class MyClass(GeneratedClass): |
| 85 | def __init__(self): |
| 86 | GeneratedClass.__init__(self) |
| 87 | self.folderName = os.path.join(self.behaviorAbsolutePath(), "..") |
| 88 | self.data = [] |
| 89 | with open(os.path.join(self.folderName, 'data.csv'), 'rb') as f: |
| 90 | reader = csv.reader(f) |
| 91 | for row in reader: |
| 92 | self.data.append(row) |
| 93 | self.logger.info("data: %d rows loaded" % len(self.data)) |