Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def printStructure(struct, stream = stdout):
- for e in struct.element:
- print >> stream, struct
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys
- def printStructure(struct, stream=sys.stdout):
- if stream != sys.stdout:
- sys.stdout = stream
- print struct
- else:
- print struct
- if __name__ == "__main__":
- printStructure("Print to file: 0", open('out.log', 'w'))
- printStructure("Print to console: 1")
- printStructure("Print to file: 1", open('out.log', 'aw'))
- printStructure("Print to file: 2", open('out.log', 'aw'))
- printStructure("Print to console: 2")
- stream = open("myfile.txt", "w")
- print("Some text", out=stream) # prints "Some text" to myfile.txt
- print("Some text") # prints "Some text" to stdout
- from __future__ import print_function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement