On 06/13/2013 10:37 AM, Matt D wrote:
On 06/13/2013 08:22 AM, Dave Angel wrote:
On 06/13/2013 12:18 AM, Matt D wrote:
<SNIP>
Hey,
line 202: self.logfile.write('%s,'%(str(f))) d
does put the comma in properly but,
line 203: self.logfile.write('\n')
was putting the newline after each value like you said.
I moved this back outside of the if statement to see (i am still a
little unsure about the indention and i have to test) if it will create
a new row only when all the k,v values have been looped through.
Then put it AFTER the loop, not after the if. It should line up with
the for statement. And if you mix spaces with tabs, heaven help you.
Different people have different preferences, but I despise tabs in
source code. Notice that you've done it at least four places:
#output the value with trailing comma
#if the field 'duid' == 'hdu', then clear all the fields
return 0
main()
If your editor let you do that, you aren't using the right settings on
the editor (or the right editor). This didn't affect anything, since
indentation doesn't matter on comments, and the other two lines are
isolated indentations.
the ordering: yes this is quite a hole in my understanding of what is
going on here. the pickle is created in a collection of pretty
complicated C++ code that doesn't explicitly show how the pickle is
ordered or whats in it even in the pickle.cc and pickle.h files. the
pickle files take in some sort of stream, pickle the data, and send it
to a message queue that the trafficpanel waits on. i need to log this
pickle or at at least dump it to terminal because i am pretty sure the
'source' and 'dest' fields (which currently are not available) are in
the pickle, albeit in a different data unit. I have read
"http://www.python.org/doc//current/library/pickle.html" two times
already and still cant find a way to print the pickle in human readable
form. my understanding of pickling stinks. The ordering at this point
is not so important (not nearly as important as getting the 'source'
'dest' fields) because the point of the .csv file is just to import it
into librecalc and work time series analysis on the data manually. at
some later point in the development maybe this this task can be
automated but for now just an unordered file will suffice.
If you want a consistent ordering, then add the line I described to your
own source code, at module scope. Since you have no access to (control
over) the C++ code, you'll just have to make up your own list, as you've
already effectively done with your GUI. For every field that is NOT in
the dict, you should be outputting a simple comma.
So your if test is wrong, since it will eat zeros as well as missing
values. And you need an else clause:
for k,v in FIELD_LIST_NAMES:
# get the value of the current TextCtrl field
f = field_values.get(k, None)
if not f is None:
#output the value with trailing comma
self.logfile.write('%s,'%(str(f)))
else:
self.logfile.write(",")
self.logfile.write("\n")
And don't forget to add in the header line to your csv file, naming the
fields that are to be used in every line.
--
--
DaveA
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor