Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions soundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ def read(file, frames=-1, start=0, stop=None, dtype='float64', always_2d=True,


def write(data, file, samplerate, subtype=None, endian=None, format=None,
closefd=True, exclusive_creation=True):
closefd=True):
"""Write data to a sound file.

.. note:: If `file` exists, it will be truncated and overwritten!

Parameters
----------
data : array_like
Expand All @@ -356,9 +358,6 @@ def write(data, file, samplerate, subtype=None, endian=None, format=None,

Other Parameters
----------------
exclusive_creation : bool
If ``True`` (the default), the file is opened with ``mode='x'``.
Otherwise, it is opened with ``mode='w'``.
format, endian, closefd
See :class:`SoundFile`.

Expand All @@ -377,8 +376,7 @@ def write(data, file, samplerate, subtype=None, endian=None, format=None,
channels = 1
else:
channels = data.shape[1]
mode = 'x' if exclusive_creation else 'w'
with SoundFile(file, mode, samplerate, channels,
with SoundFile(file, 'w', samplerate, channels,
subtype, endian, format, closefd) as f:
f.write(data)

Expand Down
1 change: 0 additions & 1 deletion tests/test_argspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_read_defaults():

def test_write_defaults():
write_defaults = defaults(write_function)
del write_defaults['exclusive_creation']
init_defaults = defaults(init)

# Same default values as SoundFile.__init__()
Expand Down
6 changes: 0 additions & 6 deletions tests/test_pysoundfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,6 @@ def test_write_with_unknown_extension(filename):
assert "file extension" in str(excinfo.value)


def test_write_with_exclusive_creation():
with pytest.raises(OSError) as excinfo:
sf.write(data_mono, filename_mono, 44100)
assert "File exists" in str(excinfo.value)


# -----------------------------------------------------------------------------
# Test blocks() function
# -----------------------------------------------------------------------------
Expand Down