I'm having issues writing to a text file. The first file gets created but there are no text that is written. Here is my code:
def write2file(self):
generate_file = ['SHIFT_TRAFFIC_OFF','REMOVE_ADD_BUNDLE','SHIFT_TRAFFIC_ON']
for method in generate_file:
f = open("/home/superloop/10gto100g/test/%s_%s" % (self.hostname,method), "w")
output = getattr(self,method)
# self.SHIFT_TRAFFIC_OFF()
f.write(output())
f.close()
def SHIFT_TRAFFIC_OFF(self):
print "router ospf 1"
print " area 0"
print " interface Bundle-Ether%s" % self.bundle
print " cost 100"
print "!"
print "router ospfv3 1"
print " area 0"
print " interface Bundle-Ether%s" % self.bundle
print " cost 100"
And here is the output when I execute the application:
router ospf 1
area 0
interface Bundle-Ether4
cost 100
!
router ospfv3 1
area 0
interface Bundle-Ether4
cost 100
Traceback (most recent call last):
File "main.py", line 42, in <module>
main()
File "main.py", line 20, in main
parse_engine(database)
File "/home/superloop/10gto100g/parser.py", line 15, in parse_engine
device = BaseDevice(list[0],list[1],list[2],list[3],list[4])
File "/home/superloop/10gto100g/objects/basedevice.py", line 12, in __init__
self.write2file()
File "/home/superloop/10gto100g/objects/basedevice.py", line 20, in write2file
f.write(output())
TypeError: expected a character buffer object
What is going on here?