I wrote a code which fills numbers into the file and when the file exceeds the size given, it stops adding data. But whenever i run the code there is an indefinite run in the data and the size of file just goes off the chart! Please help!!

def create_file_numbers(filename, size):    ## size given as 1024
    count = 0
    f = open(filename,'wb')
    stat = os.stat(filename)
    while str(stat.st_size) < str(size): ## facing prob here
        count += 1

You're reading the file status once outside of the while loop, so it never changes. You should re-read it every time around the loop.