LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Help with Python debug (https://www.linuxquestions.org/questions/programming-9/help-with-python-debug-198109/)

rootyard 06-26-2004 06:54 PM

Help with Python debug
 
CODE STARTS BELOW-----------------------------------------------------------------
import sys

HostAddress =range(10000)
HostName =range(10000)
HostThreshold =range(10000)
HostAlarmLevel =range(10000)
HostDataSend =range(10000)

index = 0

while True:
HostAddress[index] = raw_input("Enter IP Address: ")
HostName[index] = raw_input("Enter host name: ")
HostThreshold[index] = raw_input("Enter threshold: ")
HostAlarmLevel[index] = raw_input("Enter alarm level (1-5 5 being most critical): ")
HostDataSend[index] = raw_input("Store data for this host? (yes or no): ")
index += 1
Option1 = raw_input("Quit? (y/n): ")

if Option1 == 'y':
break

counter = index
index = 0

CCConfigFile = open("connectcheck.cfg", "w")

while index <= counter:
CCConfigFile.write(str(HostAddress[index] + "\n"))
CCConfigFile.write(str(HostName[index] + "\n"))
CCConfigFile.write(str(HostThreshold[index] + "\n"))
CCConfigFile.write(str(HostAlarmLevel[index] + "\n"))
CCConfigFile.write(str(HostDataSend[index] + "\n"))

index += 1

CCConfigFile.close()

CODE ENDS-----------------------------------------------------------------------------

When I run this script everything works fine. The file is written as intended, yet I still keep getting this error message:

Traceback (most recent call last):
File "connectcheck-setup.py", line 29, in ?
CCConfigFile.write(str(HostAddress[index] + "\n"))
TypeError: unsupported operand type(s) for +: 'int' and 'str'

Any reason why I get this warning?

ranger_nemo 06-26-2004 09:16 PM

Try """ CCConfigFile.write(str(HostAddress[index]) + "\n") """

Convert the HostAddress[index] with str() before adding the line-break.


All times are GMT -5. The time now is 04:46 AM.