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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:47:32+00:00 2026-05-22T01:47:32+00:00

perhaps I’m asking the wrong question. I have code like this: class ExpressionGrammar(Grammar): def

  • 0

perhaps I’m asking the wrong question. I have code like this:

class ExpressionGrammar(Grammar):
  def __init__(self, nonterminals, terminals, macros, rules, precedence, nonterminal_name = '_expr'):
    self.nonterminals = nonterminals
    self.terminals = terminals
    self.rules = rules
    self.macros = macros
    self.precedence = precedence
    self.nonterminal = nonterminal

and I find it redundant to always have to to self.x = x. I know python tries to avoid repetition, so what would be the correct way to do something like this?

  • 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-22T01:47:33+00:00Added an answer on May 22, 2026 at 1:47 am

    You can avoid doing that with something like:

    class C(object):
        def __init__(self, x, y, z, etc):
            self.__dict__.update(locals())
    

    then all these arguments become members (including the self argument). So you may remove it with: self.__dict__.pop('self')

    I don’t know how pythonic this approach is, but it works.

    PS:
    If you’re wondering what __dict__ is, it’s a dict that holds every member of an instance in the form {'member1': value, 'member2': value}

    locals() is a function that returns a dict with local variables.

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

Sidebar

Related Questions

Perhaps I am not asking or searching for this correctly: I want to have
Perhaps this is a naive question. In my understanding, ASP.NET MVC cannot work with
Perhaps my question is similar in nature to this one: Do you use design
Perhaps this isn't the best forum for this question. If so, would one of
Perhaps i'm wandering down the wrong path - I'm looking for a tool like
Perhaps this is a stupid question, but I'm trying to use BGL's dijkstra_shortest_paths ,
Perhaps a stupid question: I have a List of type <Data> which I want
Perhaps this is a simple newbie C# question, but so be it---it will be
Perhaps I'm going about this all wrong (and please tell me if I am),
Perhaps I have been looking at this for too long as I cannot find

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.