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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:41:17+00:00 2026-05-21T12:41:17+00:00

class Test(forms.Form): def set_choices(self, choices): self.choices = choices def get_choices(self): return self.choices options =

  • 0
class Test(forms.Form):

    def set_choices(self, choices):
        self.choices = choices

    def get_choices(self):
        return self.choices

    options  = forms.ChoiceField(choices=get_choices())

f = Test()
f.set_choices(...)

Why isn’t this possible?
How else can I achieve the goal of passing data into class Test?
Thanks in advance.

  • 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-21T12:41:17+00:00Added an answer on May 21, 2026 at 12:41 pm

    This is a basic Python issue. You need to think about the order these commands are executed in, and their scope.

    First, you define a form class called Test. That class has three attributes: a set_choices method, a get_choices method, and an options field. These definitions are evaluated when the class itself is defined. The definition of options calls get_choices(). However, there is no get_choices method in scope at that point, because the class is not yet defined.

    Even if you somehow managed to sort out the scope issue, this would still not do what you want, because the definition of choices for options is done at define time. Even if you later call set_choices, options still has the value of get_choices that was returned when the field was defined.

    So, what do you actually want to do? It seems like you want to set dynamic choices on the options field. So, you should override the __init__ method and define them there.

    class Test(forms.Form):
        options = forms.ChoiceField(choices=())
    
        def __init__(self, *args, **kwargs):
            choices = kwargs.pop('choices', None)
            super(Test, self).__init__(*args, **kwargs)
            if choices is not None:
                self.fields['options'].choices = choices
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

# I have this class: class Test(webapp.RequestHandler): myList = [] def get(self): s =
class Test { bool isVal() const { return isVal; } private: bool isVal; };
E,g class Test { public: void setVal(const std::string& str) { this.isVal = str; //This
I have a class which looks something like this: public class Test { private
Say I've got a class like this: class Test { int x; SomeClass s;
I am testing this controller: class SessionsController < ApplicationController def new end def create
class test { public: test &operator=(const test & other){} // 1 const test &
public class Test { public static void main(String[] args) { } } class Outer
Consider following class class test { public: test(int x){ cout<< test \n; } };
I have the following example class: Test.h: @interface Test : UIButton { NSString *value;

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.