order of words in python
I have a code like:
class <name>
{
public:
...
private:
...
};
I want to ensure that the public section is declared before the private section and not after that.One way of doing this in Python is by comparing the line numbers where these words occur.However,am not sure if this would work when I have several such sections(such declarations) in my code.Any 开发者_如何学Cother suggestions?
This problem is, in general, much harder than you think. Not all classes are laid out like that.
- Some won't have
private
sections and rely on the default visibility. - Some might not have public sections.
- Some might have multiple
private
and/orpublic
sections. - How will you know when the class declaration has finished? You don't want to move code around from another class!
- Some classes might use macros which will throw you.
And so on. To do this properly and reliably you need a proper C++ parser which is notoriously hard to get right. Don't try to implement one of those yourself using simple text search.
精彩评论