fork(1) download
  1. class line_type:
  2. def __init__(self, content, tabs):
  3. self.content = content
  4. self.tabs = tabs
  5.  
  6. def print_content(self):
  7. print('\t' * self.tabs, self.content, sep='')
  8.  
  9.  
  10. class lines_type(list):
  11. def __init__(self, lines):
  12. list.__init__(self, lines[:])
  13.  
  14. def print_all_lines(self):
  15. for u in self.lines:
  16. u.print_content()
  17.  
  18. def remove(self, idx):
  19. self.lines.remove(self.lines[idx])
  20.  
  21.  
  22. line = line_type('ideone is the best online compiler', 2)
  23. line.print_content()
  24. print('-------------')
  25.  
  26. lines = []
  27. lines.append(line)
  28. lines.insert(1, line_type('fun', 3))
  29. lines.insert(1, line_type('fun2', 3))
  30. lines.insert(1, line_type('fun3', 3))
  31.  
  32. _lines = lines_type(lines)
  33. print(_lines)
  34. _lines.insert(0, line_type('bad', 1))
  35. _lines.print_all_lines()
  36. print('-------------')
  37. _lines.print_all_lines()
Runtime error #stdin #stdout #stderr 0.02s 27656KB
stdin
Standard input is empty
stdout
		ideone is the best online compiler
-------------
[<__main__.line_type object at 0x2af2f7e48160>, <__main__.line_type object at 0x2af2f7e48208>, <__main__.line_type object at 0x2af2f7e481d0>, <__main__.line_type object at 0x2af2f7e48198>]
stderr
Traceback (most recent call last):
  File "./prog.py", line 35, in <module>
  File "./prog.py", line 15, in print_all_lines
TypeError: 'NoneType' object is not iterable