chapter 7/sampleCode1.py
def flush_buffer_if_needed(self):
        "Check the buffer capacity and write to a new file if needed"
        length = len(self.buffered_data)
        if length > 0 and length % 10 == 0:
            with open(os.path.join( output_dir, "tweets{}.csv".format(self.counter)), "w") as fs:
                self.counter += 1
                csv_writer = csv.DictWriter( fs, fieldnames = fieldnames)
                for data in self.buffered_data:
                    csv_writer.writerow(data)
            self.buffered_data = []
Check the buffer capacity and write to a new file if needed
Check the buffer capacity and write to a new file if needed
Check the buffer capacity and write to a new file if needed
def flush_buffer_if_needed(self):
        length = len(self.buffered_data)
        if length > 0 and length % 10 == 0:
            with open(os.path.join( output_dir, "tweets{}.csv".format(self.counter)), "w") as fs:
                self.counter += 1
                csv_writer = csv.DictWriter( fs, fieldnames = fieldnames)
                for data in self.buffered_data:
                    csv_writer.writerow(data)
            self.buffered_data = []
def flush_buffer_if_needed ( self ) : length = len ( self . buffered_data ) if length > 0 and length % 10 == 0 : with open ( os . path . join ( output_dir , "tweets{}.csv" . format ( self . counter ) ) , "w" ) as fs : self . counter += 1 csv_writer = csv . DictWriter ( fs , fieldnames = fieldnames ) for data in self . buffered_data : csv_writer . writerow ( data ) self . buffered_data = [ ]
Check the buffer capacity and write to a new file if needed
Check the buffer capacity and write to a new file if needed
"Check the buffer capacity and write to a new file if needed"
self