How to write many and similar python scripts at once?
I need to have 100 of those similar python scripts that have MyData class from MyData_1 to MyData_100.
import torch
import numpy as np
from torch_geometric.data import InMemoryDataset, Data
from torch_geometric.utils import to_undirected

class MyData_1(InMemoryDataset):
    def __init__(self, root, transform=None):
        super(MyData_1, self).__init__(root, transform)
        self.data, self.slices = torch.load(self.processed_paths[0])

    @property
    def raw_file_names(self):
        return &quot;mydata_1.npz&quot;

    @property
    def processed_file_names(self):
        return &quot;data_1.pt&quot;

    def process(self):
        raw_data = np.load(self.raw_paths[0])
        cluster_data = torch.load('./raw/total_clusters.pt')
        x = torch.from_numpy(raw_data['x'])
        y = torch.from_numpy(raw_data['y'])
        
        pos = torch.stack([x,y], dim=-1)
        cp = torch.from_numpy(raw_data['cp'])

        data_list = []
        for i in range(cp.size(0)):
            data = Data(x=cp[i].view(-1,1),pos=pos.view(-1,2),  cluster=cluster_data[0])
            data_list.append(data)

        torch.save(self.collate(data_list), self.processed_paths[0])

I'm trying to do this because each MyData class calls different mydata_1,2,...100.npz to generate dataset.
Is there any way to make this fast?
Thanks in advance!

I didn't fully understand the reason why you need to create 100 different classes.
Is it because you need to return mydata_1.npz to mydata_100.npz? If then, You can create a single class like this:
class Myclass:
  def __init__(self, index):
    self.index = index

  def raw_file_names(self):
    return &quot;mydata_{}.npz&quot;.format(self.index)

Then, at another script like main.py, you can create/assign it like:
for i in range(100):
  exec('dataset_{} = MyData_{}({})'.format(i, i, i))

I believe you can build your own code that fits your problem with above examples.
