Skip to content

wave.open does not work with pathlib.Path files #140952

Description

@mbyrnepr2

Bug report

Bug description:

Scenario 1 - Opening the file for reading

# Opening the file for readingimportwavefrompathlibimportPathAUDIO_FILE=Path("sound.wav")
withwave.open(AUDIO_FILE, "rb") aswave_read:
pass

Output:

AttributeError: 'PosixPath'objecthasnoattribute'read'

Scenario 2 - Opening the file for writing

# Opening a file for writingimportwavefrompathlibimportPathAUDIO_FILE=Path("sound.wav")
withwave.open(AUDIO_FILE, "wb") aswave_write:
wave_write.setnchannels(1)
wave_write.setsampwidth(2)
wave_write.setframerate(44100)

Output:

AttributeError: 'PosixPath'objecthasnoattribute'write'. Didyoumean: 'drive'?

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions