Почему бы не сохранить вещи в словаре, например, так?
import pandas as pd
object1 = pd.read_csv(file1.csv)
object2 = pd.read_cdv(file2.csv)
# This is the dictionary, a key-value mapping
# We can lookup the key 'object1' (or whatever table name, in your case)
# and return the "table"/DataFrame associated to which that key maps
table_lookup = {'object1': object1, 'object2': object2}
def printTable(tableName):
table = table_lookup[tableName]
rows, columns = table.shape
for row in range(rows):
# do something like print the row
# but the following code throws an error
# "AttributeError: 'str' object has no attribute 'shape'
# How do get the User to select the object?
while True:
tableName = input("\nEnter a table name: \n")
if tableName:
printTable(tableName)
else:
break
input
вернет объект str
, а не фактическое пространство имен, ссылающееся на переменную.Таким образом, tableName
будет 'object1'
, а не object1
.Вы видите разницу?