Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Type error: not enough arguments for format string

418 views
Skip to first unread message

sync...@gmail.com

unread,
Sep 19, 2018, 12:12:19 PM9/19/18
to
I'm just trying to follow along with the logging tutorial documentation and I am getting this error:

import logging


logging.basicConfig(format= '%(asctime)s % (message)s', datefmt='%m%d%Y %I:%M:%S %p')
logging.warning('is when this event was logged')

Error:

C:\Users\Malcy\PycharmProjects\Udemy\venv\Scripts\python.exe C:/Users/Malcy/PycharmProjects/logging/logger.py
Traceback (most recent call last):
File "C:\Users\Malcy\AppData\Local\Continuum\anaconda2\Lib\logging\__init__.py", line 861, in emit
msg = self.format(record)
File "C:\Users\Malcy\AppData\Local\Continuum\anaconda2\Lib\logging\__init__.py", line 734, in format
return fmt.format(record)
File "C:\Users\Malcy\AppData\Local\Continuum\anaconda2\Lib\logging\__init__.py", line 469, in format
s = self._fmt % record.__dict__
TypeError: not enough arguments for format string
Logged from file logger.py, line 6

David Raymond

unread,
Sep 19, 2018, 12:21:39 PM9/19/18
to
My first bet at the culprit is the space between the % and (message)s, they should be together like you have them for asctime.
--
https://mail.python.org/mailman/listinfo/python-list

Cameron Simpson

unread,
Sep 19, 2018, 6:44:28 PM9/19/18
to
On 19Sep2018 09:12, sync...@gmail.com <sync...@gmail.com> wrote:
>I'm just trying to follow along with the logging tutorial documentation and I am getting this error:
>
>import logging
>
>logging.basicConfig(format= '%(asctime)s % (message)s', datefmt='%m%d%Y %I:%M:%S %p')

Probably this: --------------------------^^

The space after the "%" in "% (message)s" is preventing correct recognision of
the format.

Cheers,
Cameron Simpson <c...@cskk.id.au>

Anssi Saari

unread,
Sep 20, 2018, 4:25:41 AM9/20/18
to
Cameron Simpson <c...@cskk.id.au> writes:

> On 19Sep2018 09:12, sync...@gmail.com <sync...@gmail.com> wrote:
>>I'm just trying to follow along with the logging tutorial documentation and I am getting this error:
>>
>>import logging
>>
>>logging.basicConfig(format= '%(asctime)s % (message)s', datefmt='%m%d%Y %I:%M:%S %p')
>
> Probably this: --------------------------^^
>
> The space after the "%" in "% (message)s" is preventing correct
> recognision of the format.

Yes. It makes sense to copy-paste examples instead of typing them in. I
guess the original is from
https://docs.python.org/2/howto/logging.html#changing-the-format-of-displayed-messages
and it doesn't have the extra space which is a problem here.

0 new messages