[Tutor] Need help printing a pickled data
Prasad, Ramit
ramit.prasad at jpmorgan.com
Tue Jun 25 23:11:27 CEST 2013
Matt D write:
> [Ramit Prasad wrote:]
> >
> > The real question is why do you want this pickle in a file? I am not sure
> > it will be easy to pull out and reuse anyway. Given your experience level,
> > I think this is a lot of work for something that you are unlikely to be able
> > to easily use. I think it would be more useful to `log.write(repr(attrs))`.
> >
> > Once you have the bytes of pickled data, just write that to file.
> >
> > with open('mypicklelog.txt','ab') as log:
> > # All pickles will run together because there is no spacing.
> > log.write(self.data.to_string())
> >
> >
> > Again, I think you would be better off with the repr()
> > with open('mypicklelog.txt','ab') as log:
> > log.write(repr(pickle.loads(self.data.to_string())))
> >
> >
>
> OK thanks. what i did is went back to the old logger where everything
> was working. and then i put
>
> self.update(attrs)
> with open('mypicklelog.txt','ab') as log:
> log.write(repr(attrs))
>
> to try to lay eyes on the pickle. What i really need is a way to test
> this GUI without waiting so long. I was thinking if i could get a hold
> of one of the c++ maps i could make a small program that would enable me
> to send it to the python gui at will; to test the gui.
That is not as simple as it sounds.
How would you send it to the UI? Would you be using the same process?
Are you hard coding the pickle location? Why not just hard code the dictionary
instead and pass that? If you are using a separate process how do you
plan to get the information to the UI? Files? Why not just hard code
(or use a non-pickle format for file) and generate the dictionary needed?
Are you going to use sockets for IPC/network communication? That is
probably even more difficult.
>
> I am not sure if there is a way around this testing difficulty because
> two of the TextCtrl fields are empty. This is because currently the c++
> is only sending in the container the contents of the Header Data Unit
> (HDU). In digital radio the transmission consists of frames, the HDU is
> one of them, as the name suggest it is the first. But the Logical Data
> Unit 1 (LDU1) contains the source and destination id data that
> ultimately i need to get in the UI. So I am going to have to get into
> the c++ map stuff and get familiar with how this pickle process works
> anyway. This is pass/fail thing, it doesn't matter if my code is 'ugly'
> or whatever and I have time so it shouldn't be impossible.
You are better off polling a directory for a text file with a
specified format and reading that file. Construct the dictionary from
that file and call update with it. Delete the file when done.
An even easier solution is to call update() with a hard coded
dictionary in TrafficPane.__init__. Or create a temporary button with
a function that generates random data for the UI and passes it to
update.
I really think focusing on pickle is really a red herring and not
related to any bit you are interested in.
~Ramit P
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
More information about the Tutor
mailing list