Update data.py

write_attr_subdicts can handle x as a dict too
added checks to avoid writing keys starting with '_'