Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

func_noerror_new_style_class_py_30.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """check builtin data descriptors such as mode and name attributes
  2. on a file are correctly handled
  3. bug notified by Pierre Rouleau on 2005-04-24
  4. """
  5. from __future__ import print_function
  6. __revision__ = None
  7. class File(file): # pylint: disable=file-builtin
  8. """ Testing new-style class inheritance from file"""
  9. #
  10. def __init__(self, name, mode="r", buffering=-1, verbose=False):
  11. """Constructor"""
  12. self.was_modified = False
  13. self.verbose = verbose
  14. super(File, self).__init__(name, mode, buffering)
  15. if self.verbose:
  16. print("File %s is opened. The mode is: %s" % (self.name,
  17. self.mode))
  18. #
  19. def write(self, a_string):
  20. """ Write a string to the file."""
  21. super(File, self).write(a_string)
  22. self.was_modified = True
  23. #
  24. def writelines(self, sequence):
  25. """ Write a sequence of strings to the file. """
  26. super(File, self).writelines(sequence)
  27. self.was_modified = True
  28. #
  29. def close(self):
  30. """Close the file."""
  31. if self.verbose:
  32. print("Closing file %s" % self.name)
  33. super(File, self).close()
  34. self.was_modified = False