I was instructed to define a class which takes 3 variables: (which looks something like this)
class random(object):
def __init__(self,a,b,c):
self.a=a
self.b=b
self.c=c
self.result= #calculations with a,b and c.
def __str__(self):
#functions so that self.result prints correctly
However, I also have to write another function in the above class:
def read(#takes whatever parameter I need)
#functions which I dont know how to write
This function should allow me to read from another file (lets call it file.txt"), and replace the self.a, self.b and self.c with information from that file, if you know what I mean? like for example:
itemA=random(1,2,3)
and file.txt contains three lines:
6
7
8
running the following:
itemA.read()
is suppose to replace the 1,2,3 in the parameter as 6,7,8, so that
itemA=random(6,7,8)
How can I achieve that? I already wrote the part that reads and reproduce random(6,7,8),with:
fileHandle=open('file.txt', 'r')
fileHandle.readlines()
#some codes that turn string into integer/floats
fileHandle.close()
random(#put integers in)
however I am not able to update itemA from random(1,2,3) to random(6,7,8) without writing manually:
itemA=itemA.read() #in python shell
btw itemA is just an example name, it can be named anything so I cant actually use itemA in my calculations...