Format file size for printing

Discussion in 'Python' started by abcd, Feb 19, 2006.

  1. abcd

    abcd Guest

    is there a built-in way of printing the size of a file nicely?

    So if the file size is 103803 bytes it prints out like: 103.8K
    or
    0.1MB

    something liek that?
     
    abcd, Feb 19, 2006
    #1
    1. Advertising

  2. abcd

    John Zenger Guest

    I know of no built-in way, but you could probably code this in a few
    lines using print "%.1f" and so on.

    (Some of us, by the way, are in the camp that believes a kilobyte is
    1024 bytes, not 1000, so 103803 bytes for us is about 101.4 kilobytes).

    abcd wrote:
    > is there a built-in way of printing the size of a file nicely?
    >
    > So if the file size is 103803 bytes it prints out like: 103.8K
    > or
    > 0.1MB
    >
    > something liek that?
    >
     
    John Zenger, Feb 20, 2006
    #2
    1. Advertising

  3. abcd

    Fuzzyman Guest

    Fuzzyman, Feb 20, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tiewknvc9
    Replies:
    6
    Views:
    693
    Chris Uppal
    Oct 1, 2006
  2. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,733
    Michael Jung
    May 25, 2008
  3. Keith Thompson

    Re: File Size - Big File Size

    Keith Thompson, Oct 1, 2009, in forum: C Programming
    Replies:
    6
    Views:
    307
    Phil Carmody
    Oct 3, 2009
  4. Randy Kramer
    Replies:
    2
    Views:
    429
    Randy Kramer
    Jan 12, 2007
  5. Wesley
    Replies:
    1
    Views:
    197
    Wesley
    Apr 15, 2014
Loading...

Share This Page