Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/notes_on_improving_write_api.txt@5349
Revision 3427,
1.5 KB
checked in by astephen, 12 years ago
(diff) |
Added some notes on how we changed write api - but not up to date.
|
Line | |
---|
1 | Proposed change to NAppy so write is separated out from openNAFile() ==================================================================== |
---|
2 | |
---|
3 | Currently when you do: |
---|
4 | |
---|
5 | >>> x = openNAFile("myfile.na", "w", na_dict) |
---|
6 | |
---|
7 | the NASA Ames file is opened and na_dict is written to it all in that one action. |
---|
8 | |
---|
9 | We propose that it would make more sense to split the process into stages as follows: |
---|
10 | |
---|
11 | >>> x = openNAFile("myfile.na", "w") |
---|
12 | >>> x.write(na_dict) |
---|
13 | >>> x.close() |
---|
14 | |
---|
15 | NOTE: need to include the following safety measures: |
---|
16 | |
---|
17 | 1. No writing is done: |
---|
18 | |
---|
19 | >>> x = openNAFile("myfile.na", "w") |
---|
20 | >>> x.close() |
---|
21 | |
---|
22 | Means that myfile.na is a zero-sized file - which is probably OK. |
---|
23 | |
---|
24 | 2. User tries to write to closed file: |
---|
25 | |
---|
26 | >>> x = openNAFile("myfile.na", "w") |
---|
27 | >>> x.write(na_dict) |
---|
28 | >>> x.close() |
---|
29 | |
---|
30 | >>> x.write(na_dict_2) |
---|
31 | WARNING! NASA Ames file instance is closed and cannot be written to. |
---|
32 | |
---|
33 | 3. User tries to write multiple na_dict objects to the file: |
---|
34 | |
---|
35 | >>> x = openNAFile("myfile.na", "w") |
---|
36 | >>> x.write(na_dict_1) |
---|
37 | >>> x.write(na_dict_2) |
---|
38 | WARNING! Cannot write multiple NASA Ames dictionaries to a single file. Please open a new NASA Ames file instance to write new data to. |
---|
39 | |
---|
40 | Also, I propose that we always do an x.file.flush() to make sure the data was written so even if user doesn't do x.close() before the process ends the data will always have been written. |
---|
41 | |
---|
42 | 4. If opened as read only then disable write: |
---|
43 | |
---|
44 | >>> x = openNAFile("myfile.na") |
---|
45 | >>> x.write(na_dict) |
---|
46 | WARNING: You cannot write to a read-only file! If you want to write to a file you must open with 'mode="w"'. |
---|
Note: See
TracBrowser
for help on using the repository browser.