'Python load, create and save changes in one object

I have an object that is responsible for the project files. That is, it binds everything together (backups, project files, etc.). It basically has three tasks that are interesting to us at the moment (the others have no impact on the issue):

  • Create a project and save its files to the given location
  • Load a project from a specific location
  • Save changes to the project (I separated because such a method does not require with so many arguments, it performs far fewer operations, except it does not change the values ​​that are required to be given as arguments first method)

In theory, everything is fine, except that:

  1. The specified argument list and cannot be accepted in the constructor perform creating or loading a project because it is not known what the programmer is going to do - create a new one or load it existing project (and therefore many values ​​that are created when creating required as arguments taken from project files).
  2. If the constructor takes no arguments (it seemed to get the best solution) it could be done afterwards object.load or object.create, but if someone would use object.save_changes before loading or creating project files project, you could get an error because many needed variables would not be created. An exception could then be made, but no I am sure if it would not be in conflict with the standards we apply in Python. There should probably be the case that one method throws you exception and refuses to cooperate if we do not call another one first.
  3. I was thinking about reloading in the constructor so that I created an instance object could (depending on the given arguments) be at the same time creating a project or loading it. However, I have the impression - perhaps not true - that Python avoids use reloads, especially in the constructor. I also don't know if such a thing would be suitably intuitive to a programmer. I have a impression that it would be better to do instance = object () and then object.load (method arguments) or object.create (method arguments). However, I do not know how to make it all agree with art.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source