Hey,

Let me explain what my program is supposed to do...

I am using a macro program in conjunction with a python script I am writing. 
The macro inputs data into a database we use at my job, blah blah blah.

The script asks how many numbers (devices) you need to enter. Next, it asks you 
to input the device numbers. When you input them, it creates a list with all of 
the devices. I then tell it to go into the script of the Macro (firstdev.ahk) 
that will run on the back-end, and replace the word "device" with the first 
device in the list. It then should execute the Macro, change the device number 
back to the word "Device" for future use, and then delete the first number from 
the list. It will repeat as long as there are numbers in the list.

The error I receive is "TypeError: Can't convert 'int' object to str 
implicitly" when it tries to put the device into the macro script. It worked 
fine when I just had it input one device into the script without the use of 
lists, but for whatever reason, using a list does not play nice with replacing 
the words "Device" with the number from the list. Here is my script. I will 
give you up until the part that the error occurs, as everything afterwords is 
pointless.

I am fairly new to python, so if anything looks screwed up or like I am an 
idiot, it is because I am.

import fileinput, sys, os
devlist = []
maxdev = int(input("How many devices to add: "))
curdev = int("0")
while curdev < maxdev:
    try:
        Number = int(input("Enter Device number: "))
        devlist.append(Number)
        curdev = curdev + 1
    except ValueError:
        print("Please enter a valid number")
ready = 0
while ready != "Y" and ready != "y" and ready != "yes" and ready != "YES" and 
ready != "ready" and ready != "Ready":
    try:
        ready = input("Confirm when you are ready ")
    except ValueError:
        print("shit broke. ")
##This next step will seek out the word Device within firstdev.ahk, and replace 
with devlist[0]
for line in fileinput.input(["firstdev.ahk"], inplace=True):
    line = line.replace("device", devlist[0])
    sys.stdout.write(line)
##next step runs firstdev.ahk
os.system('firstdev.ahk')
##next step is replacing devlist[0] with "device" 
for line in fileinput.input(["firstdev.ahk"], inplace=True):
    line = line.replace(devlist[0], "device")
    sys.stdout.write(line)
del devlist[0] #deleting the first item from the list. next steps will repeat.


Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to