Python : Typeerror : Non-empty format string passed to object.__format__

后端 未结 1 1342
灰色年华
灰色年华 2020-12-19 21:45

I know this question has been asked here but the solution does not work for me. I am using python 3.4.

I have the following formatting in my script :

相关标签:
1条回答
  • 2020-12-19 22:11

    One of your parameters is a type that doesn't have their own __format__() method, so object.__format__() is used instead.

    object.__format__() doesn't support any formatting options, including field widths and alignment, which is why you get the error.

    Conversion to string first should help, but you do need to put your conversion after the field name; instead of {!s4:11s} use {4!s:11s}, etc:

    print ( "\t {0:20} {1:<11} {2:<25} {3:11} {4!s:11s} {5!s:>32s}".format(
        files.name.split('/')[-1], sizeof_fmt(files.size),                                                                           
        str(formatted_timestamp), files.owner,
        files.version_id, files.etag))
    
    0 讨论(0)
提交回复
热议问题