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
        f.write(str(count)+"\r\n")
        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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.