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

  • Home
  • SEARCH
  • 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 6817979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:07:15+00:00 2026-05-26T21:07:15+00:00

I’m looking for a way, in python 3.2, to create a large number of

  • 0

I’m looking for a way, in python 3.2, to create a large number of variables and assign them values. Something like

X = 10
Y = 10
A = 0
B = 0
while X >= 0:
    while Y >= 0:
        cell[C]X[A] = A
        cell[C]Y[B] = B
        B = B + 1
        Y = Y - 1
        C = C + 1
    A = A + 1
    X = X - 1

Which would optimally create 200 variables of cell1X1, cell1Y1, cell2X1, cell2Y2, etc etc etc.

Is this possible? How would it be done?

Please keep in mind that I’m still very new to python, so please make things as simple as possible.

Also, while I understand that there are other ways to do this, and they they are probably better, I still want to know how to do things this way.

I understand dictionaries might be better in every possible way, but that’s not what I’m asking for.

Thanks for the help.

Edit: When I say new to python, I meant to say new to programming in general. Like very new. Like, just recently learned how to write functions.

  • 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-26T21:07:15+00:00Added an answer on May 26, 2026 at 9:07 pm

    It’s dark and hacky, but you could try:

     for i in range(100):
         locals()['A%i'%i] = i
    

    But please don’t do this. It’s usually terrible practice.

    As @delnan points out, it probably won’t work on some python versions and implementations. locals() is the local namespace, which is part of Python’s implementation. You don’t really want to play with it.

    Another more important reason why you don’t want to do this – it’s a security and reliability nightmare. You can’t see what all the variable names will be, so it’s possible you will accidentally overwrite one of your other variables. You are getting all these “variables” from the same place, so it’s logical to put them all together in a dictionary.

    I’ll explain why it works, at least in some cases: the local namespace is often implemented as a dictionary, and locals() will sometimes return the local namespace dictionary, not a copy.

    Did that make no sense at all?

    Python variables are like items in a dictionary. There’s one namespace for the module, one for the function, one “global” namespace, and so on. locals() gets you the most local namespace, and globals() gets you the global namespace.

    If the local namespace is actually implemented as a dictionary, you may be able edit it by editing locals() (reaching into the guts of the python interpreter). HOWEVER, sometimes the local namespace is not implemented as a dictionary (for performance reasons) – this happens inside functions. In that case, locals() will give you a copy of the namespace, and you will not be able to edit it (or at least, it won’t change the local namespace).

    Still confused? Don’t do it.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have some data like this: 1 2 3 4 5 9 2 6

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.