Remona Remona - 6 months ago 11
Python Question

What is the AttributeError in this code? Pathon 3.4

# Do the fun!
def fire(self):

self.printHeader()
print ("Hitting webserver in mode '{0}' with {1} workers running {2} connections each. Hit CTRL+C to cancel.").format(self.method, self.nr_workers, self.nr_sockets)

if DEBUG:
print ("Starting {0} concurrent workers").format(self.nr_workers)


AttributEerror: 'NoneType' object has no attribute 'format'

enter image description here

enter image description here

AKS AKS
Answer

You are formatting after print statement is closed

print (x).format(something)
#       ^ Move this parentheses to end

What you need is this:

print ("Starting {0} concurrent workers".format(self.nr_workers))
#                                                               ^ here 

In Python 2 however, it wouldn't have mattered:

>>> print ("Starting {0} concurrent workers").format(5)
Starting 5 concurrent workers
Comments