How can you assign a name to a sheet, for example, or a variable?

I enter the name of the variable that I need. I will use this name for the sheet name.

name of your list=raw_input("Enter name of your list:") 

I would like for a new sheet, which is a copy of the created sheet a, to give a name via the keyboard, by typing it in raw_input. And the sheet a itself is obtained by me through operations in an infinite while True

 "сюда я хочу вставить то что ввожу в raw_input"=a[:] 
  • one
    Nothing is clear, reformulate and give a ready-made example of what you want, or something - andreymal
  • @andreymal perhaps the author has in mind: namespace[raw_input("enter name"]=a where namespace=globals() (with locals () is not required to work) is not a recommended option in both cases. You need to edit the question and add more context: what specifically and most importantly, why do you want to do it. It looks like an XY task - jfs

3 answers 3

I need to set the name of the sheet through raw_input ... Every time through the while - I get a new sheet and I would like to save the result by entering the name of the sheet as a variable to refer to it.

To give each list its name, you can use the dictionary in Python:

 import sys lists = {} # name -> list while not enough(lists): name = raw_input("Enter list name") if valid(name): lists[name] = get_new_list() else: print >>sys.stderr, "invalid name %r. Try again." % name 

Type options: exec "{name} = get_new_list()".format(**vars()) should be avoided.

  • Your code did not work.)) Enough - this is some kind of function. In any case, the name will be valid if it is not duplicated with another. - Alex Skys
  • @AlexSkys my answer: use a dictionary, and the code is just an example of how the dictionary can be used: literally, it naturally does not work (you mean you substitute your code for enough() , valid() , get_new_list() functions). - jfs
  • Your idea with a dictionary seems more convincing to me. Thanks, I will try - Alex Skys
 name = raw_input("Enter the name: ") a = list() name = a 
     a = input("Enter name of your list:") globals()[a] = list(a) print('< %s >' % test) 

    out:

     Enter name of your list:test < ['t', 'e', 's', 't'] > 
    • I need a comment to the code - iluxa1810
    • I need to give the sheet a name through raw_input. So it turns out that the name name has become global in the post above. Every time through while - I get a new sheet and I would like to save the result by entering the name of the sheet as a variable to refer to it. - Alex Skys
    • the code does exactly what you are writing about, saves a sheet with the name entered in input. or you didn’t pay attention to the test variable in which the list is located - vadim vaduxa