mirror of https://github.com/cool-RR/PySnooper.git
Test for open attribute on output, to support Paths
This commit is contained in:
parent
2732922e1d
commit
5a82a65bde
|
@ -30,11 +30,18 @@ def get_write_and_truncate_functions(output):
|
||||||
elif callable(output):
|
elif callable(output):
|
||||||
write = output
|
write = output
|
||||||
truncate = None
|
truncate = None
|
||||||
else:
|
elif isinstance(output, utils.WritableStream):
|
||||||
assert isinstance(output, utils.WritableStream)
|
|
||||||
def write(s):
|
def write(s):
|
||||||
output.write(s)
|
output.write(s)
|
||||||
truncate = None
|
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)
|
return (write, truncate)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue