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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:01:05+00:00 2026-05-16T18:01:05+00:00

I have functions like this: def activate_field_1(): print 1 def activate_field_2(): print 2 def

  • 0

I have functions like this:

def activate_field_1():
   print 1

def activate_field_2():
   print 2

def activate_field_3():
   print 3

How do I define activate_field_[x] for x=1:10, without typing out each one of them? I’d much rather pass a parameter, of course, but for my purposes this is not possible.

  • 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-16T18:01:06+00:00Added an answer on May 16, 2026 at 6:01 pm

    Do you want to define these individually in your source file, statically? Then your best option would be to write a script to generate them.

    If on the other hand you want these functions at runtime you can use a higher order function. For e.g.

    >>> def make_func(value_to_print):
    ...     def _function():
    ...         print value_to_print
    ...     return _function
    ...
    >>> f1 = make_func(1)
    >>> f1()
    1
    >>> f2 = make_func(2)
    >>> f2()
    2
    

    You can generate a list of these and store, again at runtime.

    >>> my_functions = [make_func(i) for i in range(1, 11)]
    >>> for each in my_functions:
    ...     each()
    ...
    1
    2
    3
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have functions that look like this that is littered through out the code
In my script I have four functions that work like this: def function_four(): #
I have a function like this: def eventcateg_detail(request): ca = EventTypeCategory.objects.values() for i in
Suppose I have a function like this (I use akka 2.0.2): def foo(message: String):
I have a couple functions like this: object obj.getChild(childIndex) int obj.numChildren() So I am
Suppose I have two functions which look like this: public static void myFunction1(int a,
I have 2 functions/methods in the same controller in CodeIgniter like this: public function
I have a set of functions that I declare in a header like this:
I originally made a custom function for timing functions that looks like this: def
What I want to do is something like this: template.py def dummy_func(): print(VAR) #

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.