Showing posts with label General Programming. Show all posts
Showing posts with label General Programming. Show all posts
Tuesday, 31 March 2015

Test answers for Python 2015 oDesk


Test answers for Python Test 2015

oDesk • General Programming


1. Which of the following will disable output buffering in Python?
Answers:
• Using the -u command line switch
• class Unbuffered: def __init__(self, stream): self.stream = stream def write(self, data): self.stream.write(data) self.stream.flush() def __getattr__(self, attr): return getattr(self.stream, attr) import sys sys.stdout=Unbuffered(sys.stdout)
• Setting the PYTHONUNBUFFERED environment variable
• sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

2. Which of the following members of the object class compare two parameters?
Answers:
• object.__eq__(self, other)
• object.__ne__(self, other)
• object.__compare__(self, other)
• object.__equals__(self, other)
• object.__co__(self, other)
• None of these