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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:40:00+00:00 2026-05-22T18:40:00+00:00

—-Complete Rephrasing—- I was working on a new class where each instance was essentially

  • 0

—-Complete Rephrasing—-

I was working on a new class where each instance was essentially sequential and linked. I had thought, in a very shell scripty way, that I could define a function to compile a list of all of these instances if I named them systematically. Then I could do what I wanted in the first place, which was navigate through the sequence in some way.

But I see that this is a awful approach. As I understand it now, I should do one of the following instead:

  • Include embedded references in the class and thereby create a recursive data structure.
  • Create a list of all of the instances, which is perhaps updated in the class init or when a new instance is made.
  • Forget defining a new class in the first place and use a list of other objects.

I hope I’ve got that straight. Thanks again for the advice.

—–Original but edited generalized question—–

Hello,

I’m relatively new to Python and I find myself always wanted to generate a list of existing objects of some kind. Say I had three variables named x# where # is a number from 1 to 3. The sort of code I feel tempted to write would be something like:

n=1
List_Of_X=[]
while n < 4:
  List_Of_X.append("x%s" % (n))
  n += 1

But then of course I end up with a list of strings rather than variables. So, is there any way to ‘express’ the variables corresponding to the strings? Or better yet, create a list of variables in the first place?

Edit: The crux was not specifying a list manually – I wanted somehow to automate that. It seems from the answers below that I can use my admittedly crummy method above to generate a list of strings, then use the eval() function to express them. Or, use a somewhat complex method of generating a list of objects in the first place.

I get the feeling that either solutions are probably not the best practices but I appreciate all the help! 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-22T18:40:01+00:00Added an answer on May 22, 2026 at 6:40 pm

    I think you first need to understand that there are no variables in Python. There are only references to objects. So it is a mistake to even think about “creating variables”. They don’t exist.

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

Sidebar

Related Questions

I recently ran against a very interesting site that expresses a very interesting idea
I'm including a local class that requests a file from a remote server. This
I'm trying to write a web application using the new offline capabilities of HTML5.
By fixed vector I mean a static list of values, like 1 through 24.
I'm using some of Firefox's specially-defined values for cursor, in particular -moz-zoom-in -moz-zoom-out -moz-grab
My app uses a WebRequest at certain points to get pages from itself. This
This is a follow-up to the question: Should the folders in a solution match
I've got a typical impedance mismatch where the data is stored in a normalized
I've an ASCII file that contains an EM Dash (— or &mdash; in HTML).
I basically have the classic many to many model. A user, an award, and

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.