python - How to refactor a large method when its components don't make sense on their own? -


I'm looking for a very large method to reactor on a diego models.Manager . For clarity (also my discretion), I would like to break it into my component parts.

This method takes an object, uses that object's information to load that webpage, and gives it a new or existing object from the database based on the content of that page.


We think that I'm trying to get vehicle the web page. In addition to other things, this may include:

  • Loading the page in question
  • Finding the vehicle's name from the page
  • If any
  •   class vehicle manager (models. Manager): def getForSale (self, sales): # lots and many codes  

    I would like to break it in smaller methods, each of which will be one of the bullet points .


    The ideological problem that I am facing is that I am not sure where small methods are kept, they are not related to vehicle manager / because:

    • There are no things I do do a set of code vehicle objects (e.g., Vehicle.objects.findNameOnPage
    • Many of them do not even use the example variable

    I can think of some ways to refactor it: / P>

    • Just create new ways, prefixel with underscore, eg:

        def _findNameOnPage (self, page): # the self is not used < / Code> 

      The problem with this approach is that the methods are more useful than actual methods.

    • Make steady ways:

        @staticmethod def _findNameOnPage (page):  

      Associates with methods (good), but to make such namespace false (false).

    • Place the methods in the form of a module area

      This does not disrupt the namespace (good), but also makes it less clear that the methods clas Are related to S (poor)


    Is there an acceptable form / way to get it in Python?


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -