self.__dict__ = data
self.__dict__.update(data)
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/5a32b912-3d74-4980-b3bd-768bdc147b80%40googlegroups.com.--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
data = {'chars_folder': r'G:\TestProject\Source\Characters','renders_folder': r'G:\TestProject\Output\images','textures_folder': r'G:\TestProject\Resources\Images\Textures'}from the functionality of saving data.Then you can update both separately.Maybe you can have and optional argument, and that data as default in a cascade fashion,somthing like# have default data in a separate file for example projectDefaults.pydata = {'chars_folder': r'G:\TestProject\Source\Characters','renders_folder': r'G:\TestProject\Output\images','textures_folder': r'G:\TestProject\Resources\Images\Textures'}# then in the other fileimport projectDefaultsdef store_data_to_file(data=None):if data is None:data = projectDefaults.dataHope its usefull...Eduardo
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGQH2FFWUjEvA4vpjzCXS73A3UwcAFwf3ouumwY5%3DPCdcjW0xw%40mail.gmail.com.
Hi David,
About injecting the contents of an external file into a class, I’d have to go with “its a bad idea”. The main and possibly only reason being the lack of feedback between the contents of the file and existing methods/properties of the class. I’m thinking you may one day extend your class with additional members which may either override previous ones from the file, or get overwritten sometime in the future by the next file.
I know object-oriented approaches rock and all, but have you considered not using a class for this?
import myio
myio.folder('chars')
myio.folder('renders')
mydata.get would then be reading from your external file directly (as opposed to being read upon instantiation) and either return a value or throw an error depending on what you’re looking for and it’d better follow the http://en.wikipedia.org/wiki/Open/closed_principle in that you could transparently append additional methods of reading data other than JSON and from disk, such as a database, as the only requirement would be a string key, as opposed to variables of a class which are both limited in which characters they may contain but also more lengthy to try/except
On another note, it seems you’re coding towards absolute paths, is this temporary? At the very least it could be helpful to store the root of paths within something more dynamic such as an environment variable so that you can work across OSs:
data = {'chars_folder': r'$ROOT\TestProject\Source\Characters',
'renders_folder': r'$ROOT\TestProject\Output\images',
'textures_folder': r'$ROOT\TestProject\Resources\Images\Textures'}
Additionally, it may also be helpful to store the information relative the directories you are referencing:
# $ROOT/TestProject/paths.json
{
'Characters': 'Source/Characters',
'Images': 'Output/images',
'Textures': 'Resources/Images/Textures'
}
That way they’d stay portable across both platforms and projects, in case you’d prefer re-using the template/schema for others.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CACt6GrmR_t59LvF5ia4G8SpVng-A0eip8rc6M%2B6zy5busj1yKQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmODphh1nuS7Y4HMi4gJpFhLbROM_2QQHtXCkSq4fDUiv7Q%40mail.gmail.com.