Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:42:33+00:00 2026-06-17T20:42:33+00:00

This is a style conventions question. PEP8 convention for a class definition would be

  • 0

This is a style conventions question.

PEP8 convention for a class definition would be something like

class MyClass(object):
    def __init__(self, attri):
        self.attri = attri

So say I want to write a module-scoped function which takes some data, processes it, and then creates an instance of MyClass.

PEP8 says that my function definitions should have lowercase_underscore style names, like

def get_my_class(arg1, arg2, arg3):
    pass

But my inclination would be to make it clear that I’m talking about MyClass instances like so

def get_MyClass(arg1, arg2, arg3):
    pass

For this case, it looks trivially obvious that my_class and MyClass are related, but there are some cases where it’s not so obvious. For example, I’m pulling data from a spreadsheet and have a SpreadsheetColumn class that takes the form of a heading attribute and a data list attribute. Yet, if you didn’t know I was talking about an instance of the SpreadsheetColumn class, you might think that I’m talking about a raw column of cells as they might appear in an Excel sheet.

I’m wondering if it’s reasonable to violate PEP8 to use get_MyClass. Being new to Python, I don’t want to create a habit for a bad naming convention.

I’ve searched PEP8 and Stack Overflow and didn’t see anything that addressed the issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:42:34+00:00Added an answer on June 17, 2026 at 8:42 pm

    Depending on the usage of the function, it might be more appropriate to turn it into a classmethod or staticmethod. Then it’s association with the class is clear, but you don’t violate any naming conventions.

    e.g.:

    class MyClass(object):
         def __init__(self,arg):
             self.arg = arg
    
         @classmethod
         def from_sum(cls,*args):
             return cls(sum(args))
    
    inst = MyClass.from_sum(1,2,3,4)
    print inst.arg  #10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my team I've been told to write resource class like this style: class
This CSS style applies to links inside a table which the class property is
For many programming languages there are style guides available, e.g. PEP8 for Python, this
When I write a class in Java, it (almost) always looks like this: public
This question is about variable naming style in objective c and cocoa. I just
(Pardon the question title; hard to summarize this question.) On Facebook, you like things.
I've created an old-style .ASMX web service and would like to know how the
in Java code convention is simple and obvious, in this style: public: int GetMyAge(){
This is a style question: Because Apple reserves the _ privatization for its keywords,
I have this style: <Style x:Key=SelectableListBoxItemStyle TargetType={x:Type ListBoxItem}> <Setter Property=Template> <Setter.Value> <ControlTemplate TargetType={x:Type ListBoxItem}>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.