Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Why would you need to do that? What is the source of the dict? Also, literal_eval is safe, it won't execute arbitrary code like eval will.
This is extremely useful when storing things in text files. You can store literals as defined by converting a data object to a string. -
@millido @Demolishun I have a dict that has numpy.unit8 objects (I didn't write any of that, and I don't want to touch it) in it, and I need to store it as JSON due to DBus. But JSON doesn't like uint8, so I realized as I was sorting this out in the console, that a simple print the dict, c/p the dict, Bob's your uncle. So I just needed to figure out how to do that in python itself.
Also @Demolishun good to know, now I don't feel as bad. -
@millido cause it's a tuple that's returned, I wrote this at midnight, it works like a charm.
-
@-pthread @Wisecrack
Except the numbers in the tuple are uint8
@highlight
dict = {
1: {
1: (255, 255, 255)
}
}
Related Rants
I hate this line with my soul.
The fact that I need to convert a dict to a string and then invoke the python parser to read it, feels so wrong!
rant
stupid python
python