简体   繁体   中英

TypeError: open() got an unexpected keyword argument 'buffering'

I am writing a chatbot program with python and when I run my code I get the following error.

Traceback (most recent call last):
  File "C:/Users/stephen/AppData/Local/Programs/Python/Python35/chatbot.py", line 97, in <module>
    with bz2.open("C:/RC_{}".format(timeframe.split('-')[0],timeframe), buffering=1000) as f:
TypeError: open() got an unexpected keyword argument 'buffering'

Could not find any information online regarding error. All I saw was maybe that it was a bug and I should report it to python. Currently running python3.5.3. This is the part of the code that gets the error.

with bz2.open("C:/RC_{}".format(timeframe.split('-')[0],timeframe), buffering=1000) as f:
    for row in f:
        row_counter += 1
        parent_id = row['parent_id']
        body = format_data(row['body'])
        created_utc = row['created_utc']
        score = row['score']
        comment_id = row['name']
        subreddit = row['subreddit']
        parent_data = find_parent(parent_id)

The error is very explicit:

TypeError: open() got an unexpected keyword argument 'buffering'

A simple check of the documentation for bz2.open would then show you that this function does not take a buffering argument.

So simply remove it.

The bz2.open function doesn't take a buffering argument. Even bz2.BZ2File , which takes buffering , explicitly notes:

The buffering argument is ignored. Its use is deprecated.

Buffering arguments are a bit nonsensical for compressors; they have to buffer to some extent, since if you request X amount of data, they may need need to decompress a block of unknown final size to get it, so they're either decompressing the whole block and buffering the uncompressed data beyond the X request, or stopping decompression when they reach X, buffering the compressed data (and they might still have to buffer some uncompressed data since decompressing a single byte from a stream can produce many bytes of output).

Point is, there is no reasonable way to disable or limit buffering; the needs of the compressor mean you don't have that level of control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM