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

  • Home
  • SEARCH
  • 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 6319489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:48:51+00:00 2026-05-24T15:48:51+00:00

Background: I have a class modeling a chip with registers, the chip has a

  • 0

Background: I have a class modeling a chip with registers, the chip has a bunch of registers, one of them is a high temperature limit for the built-in temperature sensor.

I have the following:

class foo():
  def __init__(self):
    # does not set self._hiTemp!
    ...
  def setHiTemp(self, t):
    self._hiTemp = t
  def getHiTemp(self):
    return self._hiTemp
  def checkHiTemp(self):
    return self._temp > self._hiTemp

The reason that I don’t declare self._hiTemp in the __init__ is because the user may not care about the temp-sensing capabilities of the chip. The user can be using the chip in different ways, and there is no meaning in giving this variable a meaningless value. However, if the user tries to use self._hiTemp without first setting it, the error of using undeclared variables is much easier to debug/backtrace than some obscure error like comparing numbers and None (or in some case even no errors at all).

This is all going fine until I start pylint, and of course I get W0201: Attribute defined outside init just about everywhere. I’m just wondering if this style of coding is frowned upon, and if so, what the “Pythonic way” is.

Thanks

  • 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-05-24T15:48:51+00:00Added an answer on May 24, 2026 at 3:48 pm

    The way I’d do it is set it to None or some other sentinel value that doesn’t occur ‘in nature’. Then for operations that require it to be set, use an assert to fail fast in case the caller is trying to use your object inappropriately.

    def __init__(self):
        self._hiTemp = None
    
    def checkHiTemp(self):
        assert self._hiTemp is not None, 'Why you no set _hiTemp before checking it?'
        return self._temp > self._hiTemp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So i have one class which starts a new class in a new background
Background: I have a MainTest class that has many buttons, each of which instantiate
Say I have a class named testThing: .testThing { background-color:#000000; float:left; height:50px; width:50px; }
lets say i have a background worker in a class that perform db query
I have created a button CSS class that uses background images with different positions
Background: I have enclosed (parent) class E with nested class N with several instances
I have a css class like: .foo { background-color: red; } then I have
First some background: I already have a Result class that I've implemented to carry
Background I have an abstract class, something like class IConverter{ public: virtual void DoConvertion()
Background I have a container class which uses vector<std::string> internally. I have provided a

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.