Why give a local variable an initial value immediately before assigning to it?

While looking at the source code of the asyncore module I came across this method. I'll include it here without context, as it seems to be quite self contained:

def initiate_send(self):
    num_sent = 0
    num_sent = dispatcher.send(self, self.out_buffer[:512])
    self.out_buffer = self.out_buffer[num_sent:]

My question: Why is num_sent first set to 0, but then immediately set again to another value?

If i'd found this anywhere but in the python source code, I'd say that this line of code is superfluous. Is there any point to it, or is it dead code?


That's dead code; it's a local variable, so it is not ever going to influence anything else.

If it had been a instance variable, then dispatcher.send could have read the value while executing, but it's completely superfluous here.

The asyncore module is relatively ancient, the line has been there since it was first committed to the python codebase in 1999.

Need Your Help

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.