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 7771537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:40:36+00:00 2026-06-01T16:40:36+00:00

Is there a synonym for attr_reader in python, like something that doesn’t have to

  • 0

Is there a “synonym” for attr_readerin python, like something that doesn’t have to make me type out?:

class Foo():
    def __init__(self, foo, bar, spam, spammity, spam, spam, quux, foobar, barfoo):
        self.foo = foo
        self.bar = bar
        self.spam = spam
        # And so on...

Just a one line thing that makes self.foo = foo, etc., sort of like how ruby’s attr_reader would make

@foo = foo
  • 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-01T16:40:37+00:00Added an answer on June 1, 2026 at 4:40 pm

    You can do this with kwargs:

    class Foo():
      def __init__(self, **kwargs):
        self.foo = kwargs['foo']
    

    And you pass in named arguments:

    foo = Foo(foo='bar')
    

    Of course, you might want to catch KeyError exception

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Out of curiousity, is there any way to edit an existing synonym? That is,
Is there any api/lib for python that will get me the synonyms of a
I have to index a lot documents that contain reference numbers like aaa.bbb.ddd-fff. The
We have a couple of synonyms that are being used to reference tables in
This is pretty weird. I have my Profiler open and it obviously shows that
If, in Database A, there exists a table named MyTable that actually comes from
How does it come, that the following type checks {-# LANGUAGE RankNTypes #-} module
Is there any good api from where I can fetch synonym of a word(English
Is it valid to do something such as CREATE SYNONYM [dbo].[MyTable] FOR [AnotherDatabase].dbo.[MyTable] and
Hasty research tells me that even EF4 still doesn't support SQL Server synonyms. What

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.