On 06/13/2013 11:23 AM, Dave Angel wrote: > 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)2013-06-12 16:28:59,Unknown (0x658), DES-OFB, HDU, 0xa4d5010ca0bbdb0900, 0xfff, Standard MFID (pre-2001), 00x1, > 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. > as of now the order in the .csv file is like this:
2013-06-12 16:28:59,Unknown (0x658), 00x80, $80 Clear, 0xa4d5010ca0bbdb0900, 0xfff, Standard MFID (pre-2001), 00x1, and keeps repeating this order as long as HUDs are coming in. i am unsure why the date/time is on the same line as NAC? Oh and i have not tested yet with the '\n' newline command out of the if statement. If i have to i can modify the C++ code but was hoping not to have to do that at this stage. the C++ is used for what is computationally intense and the Python is used mainly for the UI. Any idea of a way to write the pickle to file to see what it contains? because it is not explicit in the C++ files, at least not as far as I can tell as of yet. Thanks! _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor