MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / save_and_import

Method save_and_import

opcua/common/structures.py:204–220  ·  view source on GitHub ↗

save the new structures to a python file which be used later import the result and return resulting classes in a dict if append_to is a dict, the classes are added to the dict

(self, path, append_to=None)

Source from the content-addressed store, hash-verified

202 return _generate_python_class(self.model, env=env)
203
204 def save_and_import(self, path, append_to=None):
205 """
206 save the new structures to a python file which be used later
207 import the result and return resulting classes in a dict
208 if append_to is a dict, the classes are added to the dict
209 """
210 self.save_to_file(path)
211 name = os.path.basename(path)
212 name = os.path.splitext(name)[0]
213 mymodule = importlib.import_module(name)
214 if append_to is None:
215 result = {}
216 else:
217 result = append_to
218 for struct in self.model:
219 result[struct.name] = getattr(mymodule, struct.name)
220 return result
221
222 def _make_header(self, _file):
223 _file.write("""

Callers 1

Calls 1

save_to_fileMethod · 0.95

Tested by 1