mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 10:15:11 +00:00
Test for open attribute on output, to support Paths
This commit is contained in:
parent
2732922e1d
commit
5a82a65bde
1 changed files with 9 additions and 2 deletions
|
|
@ -30,11 +30,18 @@ def get_write_and_truncate_functions(output):
|
|||
elif callable(output):
|
||||
write = output
|
||||
truncate = None
|
||||
else:
|
||||
assert isinstance(output, utils.WritableStream)
|
||||
elif isinstance(output, utils.WritableStream):
|
||||
def write(s):
|
||||
output.write(s)
|
||||
truncate = None
|
||||
elif hasattr(output, 'open'):
|
||||
def write(s):
|
||||
with output.open('a') as output_file:
|
||||
output_file.write(s)
|
||||
|
||||
def truncate():
|
||||
with output.open('w'):
|
||||
pass
|
||||
|
||||
return (write, truncate)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue