Looking to gain understanding in Python'stokenize module. I am interested in calling the tokenize.tokenize method on a given python source file (like the one below) and get its tokenized output with the 5-tuple as mentioned in the docs.
# Python source file
import os
class Test():
"""
This class holds latitude, longitude, depth and magnitude data.
"""
def __init__(self, latitude, longitude, depth, magnitude):
self.latitude = latitude
self.longitude = longitude
self.depth = depth
self.magnitude = magnitude
def __str__(self):
# -1 is for detection of missing data
depth = self.depth
if depth == -1:
depth = 'unknown'
magnitude = self.magnitude
if magnitude == -1:
depth = 'unknown'
return "M{0}, {1} km, lat {2}\N{DEGREE SIGN} lon {3}\N{DEGREE SIGN}".format(magnitude, depth, self.latitude, self.longitude)
Unfortunately, the example in the docs is not clear enough given my inexperience in Python to make it work. Also, I could not find any related useful example code online.
Any simple workable code examples will be greatly appreciated.
Also, if you know of useful online material with examples/explanations of the tokenize module and its methods that would be great.