Guest User

Untitled

a guest
Feb 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. class Node:
  2.  
  3. def __init__(self, id):
  4. self.id = id
  5. self.neighbours = []
  6. self.distance = 0
  7.  
  8.  
  9. def __str__(self):
  10. return str(self.id)
  11.  
  12. uno = Node(1)
  13. due = Node(2)
  14. tri = Node(3)
  15. qua = Node(4)
  16.  
  17. print uno
  18.  
  19. 1
  20.  
  21. uno.neighbours.append([[due, 4], [tri, 5]])
  22.  
  23. print uno.neighbours
  24.  
  25. [[[<__main__.Node instance at 0x00000000023A6C48>, 4], [<__main__.Node instance at 0x00000000023A6D08>, 5]]]
  26.  
  27. [[2, 4], [3, 5]]
  28.  
  29. __repr__ = __str__
  30.  
  31. class Pet(object):
  32.  
  33. def __init__(self, name, species):
  34. self.name = name
  35. self.species = species
  36.  
  37. def getName(self):
  38. return self.name
  39.  
  40. def getSpecies(self):
  41. return self.species
  42.  
  43. def Norm(self):
  44. return "%s is a %s" % (self.name, self.species)
  45.  
  46. if __name__=='__main__':
  47. a = Pet("jax", "human")
  48. print a
  49.  
  50. <__main__.Pet object at 0x029E2F90>
  51.  
  52. class Pet(object):
  53.  
  54. def __init__(self, name, species):
  55. self.name = name
  56. self.species = species
  57.  
  58. def getName(self):
  59. return self.name
  60.  
  61. def getSpecies(self):
  62. return self.species
  63.  
  64. def __str__(self):
  65. return "%s is a %s" % (self.name, self.species)
  66.  
  67. if __name__=='__main__':
  68. a = Pet("jax", "human")
  69. print a
  70.  
  71. jax is a human
  72.  
  73. class Node:
  74.  
  75. def __init__(self, id, neighbours=[], distance=0):
  76. self.id = id
  77. self.neighbours = neighbours
  78. self.distance = distance
  79.  
  80.  
  81. def __str__(self):
  82. return str(self.id)
  83.  
  84.  
  85. def __repr__(self):
  86. return "Node(id={0.id}, neighbours={0.neighbours!r}, distance={0.distance})".format(self)
  87. # in an elaborate implementation, members that have the default
  88. # value could be left out, but this would hide some information
  89.  
  90.  
  91. uno = Node(1)
  92. due = Node(2)
  93. tri = Node(3)
  94. qua = Node(4)
  95.  
  96. print uno
  97. print str(uno)
  98. print repr(uno)
  99.  
  100. uno.neighbours.append([[due, 4], [tri, 5]])
  101.  
  102. print uno
  103. print uno.neighbours
  104. print repr(uno)
  105.  
  106. print self._grid.__str__()
  107.  
  108. def __str__(self):
  109. """
  110. Return a string representation of the grid for debugging.
  111. """
  112. grid_str = ""
  113. for row in range(self._rows):
  114. grid_str += str( self._grid[row] )
  115. grid_str += 'n'
  116. return grid_str
Add Comment
Please, Sign In to add comment