Basically, I need to write an entire class to a new .py file. The only problem is that two important variables inside the class rely on user input. When I write the class to the file I need to have the actual number/string where the user input is instead. Here is an example of what I currently have:
class CreateClient:
def writer(self):
file = open('client_test.py', 'w+')
file.write(Client)
print("File created")
class ClientConfig:
def hostvar(self):
inhost = str(input('Enter the listener hostname: '))
return inhost
def portvar(self):
inport = int(input('Enter the port: '))
return inport
class Client:
def examp(self):
host = ClientConfig.hostvar(ClientConfig)
port = ClientCOnfig.portvar(ClientConfig)
As you can see I need Client to be writed to a new file, except it will write
host = ClientConfig.hostvar(ClientConfig)
port = ClientCOnfig.portvar(ClientConfig)
instead of what I need (i.e host='127.0.0.1', port = 9999). Is there any way I can do this, possibly use the operation 'replace'? If I attempt to access the host or port variable by doing Client.examp.host it won't work, so I don't see how I could use replace.
Clientthat needs to go somewhere else? Also, why are you passingClientConfigas a parameter to those functions?