0

In C# you have the ability to split code across several files, that way in the case of code containing generated code, you can quickly find the custom code and functionality.

I was just wondering if Python had an equivalent solution.

Or some code hack that would enable it.

edit So i looked at the other supposed answer and saw something very inelegant.

To answer the questions of the juniors, the purpose of partial classes is to allow code generated by a tool to exist in the same class as custom code the programmer uses to extend it. In VS, you can even use intellisense for autocomplete, and the major reason for this is lack of interference as the one gentleman said, but also really, because some class files get very very large. it's actually a pretty nice feature since the code files don't have to have the same basename I believe if you don't want it just looks for the partial class decorator.

Anyway I saw something ugly in the page stackoverflow suggested, I'd like a more elegant way.

6
  • What do you mean by "generated code"? Commented Feb 11 at 15:21
  • 2
    @JRiggles In C#/.Net you can have code that is generated by tools. That's what OP is talking about. Some of it, like for example GUI Forms will consist of a Tool-Controlled / generated part and a developer-customized part for which you can split the class into two different files, so changes do not interfere that are done by the GUI Designer tool and the changes made by the dev in a code editor. Commented Feb 11 at 15:22
  • classes are just objects, you can modify them at will whenever you want. Commented Feb 11 at 15:34
  • I suspect you mean inheritance or extending a class? Then yes. But we would need some examples to give a real answer Commented Feb 11 at 15:38
  • 1
    The natural Python equivalent to that is using multiple inheritance. That is not exactly the same thing, but it will be the way that flows along the way Python works. It would be possible to have methods declared in separate files, and just attach then into the class body - using either the = operator or a plain import statement - but that would loose the support to calling super() - as that depends on the method being written inside the class body. It is possible to work around it, but multiple inheritance is the way to go. Commented Feb 11 at 16:44

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.