How to make new variables using exec() in imported method (python)

import pandas as pd

def get_data(names):
    print('Loading data...')

    for name in names:
        exec(f'{name} = pd.read_csv(\'{name}.csv\')', globals())

    print('Data successfully loaded.)

from get_data import *

names = ['apple', 'banana', 'tomato']


I want to do this.

But it is not working T.T

What should I do

Please help me...

Read more here:

Content Attribution

This content was originally published by junglekim at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: