Writing to a file with python

Hello,
I am playing around with a script and trying to have python write a dictionary to a file for storing purposes. I have it writing out but it only writes about the first 1/3rd of the dictionary and thats all. I can not figure out why this is :(:

EDIT: Nm, I was checking the file too quickly, I just re-ran it and went to grab a drink and when I came back and checked the file it was all written to the file. Sorry.

If you haven’t already I’d recommend reading-up on Python’s pickle module. Powerful, dead-simple way to serialize Python data structures to disk and back again. I use it every day.

[QUOTE=Adam Pletcher;10434]If you haven’t already I’d recommend reading-up on Python’s pickle module. Powerful, dead-simple way to serialize Python data structures to disk and back again. I use it every day.[/QUOTE]

Definitively. I also use it to store data structures in variables inside Maya files for some tools. Good Stuff. :):

[QUOTE=Wolfsong;10440]Definitively. I also use it to store data structures in variables inside Maya files for some tools. Good Stuff. :):[/QUOTE]

So i’ve been experimenting with something along these lines myself recently, what’s your methodology for this? Are you hijacking maya’s save, doing it outside of maya, or something else?

[QUOTE=djTomServo;10442]So i’ve been experimenting with something along these lines myself recently, what’s your methodology for this? Are you hijacking maya’s save, doing it outside of maya, or something else?[/QUOTE]

No hijacking. Right now the tools themselves save the Maya file when they update their data as it’s all stored in a variables on a dedicated scriptNode. The only tool I use it on atm is validation feedback of the scene, which can either be run by the artists anytime while working, launches automatically when they want to export or can be batched over source files externally from command line.

The main reason I added this feature is for the command line batching all source files in a folder structure and get a list back on all files that reported any errors. As the validation data is stored inside each file we can then send that list to the art team and tell them to fix it and they have all the info they need when they open the source file and look in the UI. It’s not a common thing we do but it’s available if we need it.

Thinking back on Adam’s GDC talk, I see the possibility to connecting this to an external database which could give us better external data overview on everything the artists export. It would also remove the need for the tool to save the source file, which could be good. This will probably be the next iteration of my current system and good time to learn to use databases. :slight_smile:

Check out the YAML module for Python too.

if it’s node-related data, I’ll frequently pickle the data to an attr on the node itself

I will definitely give that a look over. Thanks for the recommendation.