I'm currently working on a simple script where i want to take the input from the console. This input is a python code snippet. While writing the input in the file, overall alignment is improper.
For an eg:
model_def = str(input("Paste the defination of the classifier used :"))
f = open("classifier.py","w+")
f.write(model_def)
f.close()
Input was provided something like that:
class classifier(nn.Module):
def __init__(self):
super().__init__()
self.fc1 = nn.Linear(2208, 500)
self.fc2 = nn.Linear(500, 256)
self.fc3 = nn.Linear(256, 3)
self.dropout = nn.Dropout(0.5)
self.logsoftmax = nn.LogSoftmax(dim=1)
self.acivation = relu
def forward(self,x):
x = x.view(x.size(0), -1)
x = self.dropout(self.acivation(self.fc1(x)))
x = self.dropout(self.acivation(self.fc2(x)))
x = self.logsoftmax(self.fc3(x))
return x
Saving it results in an improper alignment.
class classifier(nn.Module): def __init__(self): super().__init__() self.fc1 = nn.Linear(2208, 500) self.fc2 = nn.Linear(500, 256) self.fc3 = nn.Linear(256, 3) self.dropout = nn.Dropout(0.5) self.logsoftmax = nn.LogSoftmax(dim=1) self.acivation = relu def forward(self,x): x = x.view(x.size(0), -1) x = self.dropout(self.acivation(self.fc1(x))) x = self.dropout(self.acivation(self.fc2(x))) x = self.logsoftmax(self.fc3(x)) return x