I have a function that will open a file, look for a line in the file, and attempt to replace the voltage in the line for every iteration of my voltage loop I created below the function and I print it for testing purposes.
I am getting this error:
File "test.py", line 23, in
update_code(voltage)
File "test.py", line 11, in update_code
data[i-1]='VINPUT input 0 ' + in +'\n'
TypeError: cannot concatenate 'str' and 'float' objects
# function required to change the input voltage in the pbit.sp file:
def update_code (vin):
ff=open("pbit.sp", "r+")
i=0
data= ff.readlines()
for line in data:
i+=1
if 'VINPUT' in line:
data[i-1]='VINPUT input 0 ' + vin +'\n'
ff.seek(0)
ff.truncate()
ff.writelines(data)
ff.close()
prob=[]
voltages = [0.3, 0.32, 0.34, 0.36, 0.38, 0.4, 0.42, 0.44, 0.46, 0.48, 0.5]
for voltage in voltages:
update_code(voltage)
print(voltage)
I am very new to Python, I would love support from the community!