Skip to content

Commit

Permalink
empty strings are falsey in python!
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Jan 22, 2019
1 parent 95374d0 commit b26ab52
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/python/pants/util/dirutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def safe_file_write(filename, payload=None, mode=None):
:param string payload: The string to write to the file. Defaults to the empty string.
:param string mode: A mode argument for the python `open` builtin. Defaults to 'w' (text).
"""
if payload is None:
payload = ''
with safe_open(filename, mode=mode or 'w') as f:
f.write(payload or '')
f.write(payload)


def maybe_read_file(filename, binary_mode=None):
Expand Down

0 comments on commit b26ab52

Please sign in to comment.