1

I have some Java's serialized objects (arrays of doubles) in MySql database fields that I generated previously. Now I needed to read them from Python and I have just realized that it is probably not possible to do directly.

Then I tried to convert them to strings in java (simply comma delimited), and manually parse them from Python. But, it turned out that parsing from Python works painfully slow this way. Is there any better way for serializing arrays that is compatible between Java and Python?


Edit: Sorry, my parsing code was the problem, of course. I replaced it with this:

stringList = string.split(', ')
svdVector = [float(x) for x in stringList]

..and now it is almost instant for my case of 1000x1000 doubles. Although it still feels wrong to store doubles as strings instead of binary, but since it's easy to code and runs fast enough, it is fine.

1
  • 1
    Parsing comma-delimited strings in Python is quite fast, actually. You might get some mileage from posting your code and asking for help in speeding it up. My guess is that you're doing something wrong. Commented Mar 8, 2012 at 0:31

2 Answers 2

2

Python comes with modules for CSV files, XML, and JSON, so one of those would likely do the trick quite well.

Sign up to request clarification or add additional context in comments.

Comments

0

If you really want to try binary serialization, check out the built-in struct and array modules for help with interpreting the data in Python.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.