# parsepoint.py # Walker M. White (wmw2), Lillian Lee (ljl2) # September 6, 2013 """Functions for parsing Point objects This module contains a single function: parse_point. It is kept separate from Lab 3 in order to cut down on the amount of time that it takes to complete Lab 3. The function parse_point may include intentional errors.""" from tuple3d import Point def parse_point(s): """Returns: a point object whose representation is the string s Given a string such as "(1,2.2,3)", this function returns a point object equivalent to it. It uses find() and string slicing to break the string up into individual parts. It then converts the three coordinates in the string to floats, and puts them inside a point object. Precondition: s is a string representing a Point object""" # Find the first comma first = s.find(",") # x coordinate is between paren and first comma xstring = s[1:first] # Get the slice after the first comma after_comma = s[first:] # Use new slice to find the second comma second = after_comma.find(",") # Use second comma to get x and y coordinates # REMEMBER: Working with aftercomma, not s!! ystring = after_comma[0:second] zstring = after_comma[second+1:len(after_comma)-1] # Create a new point object p = Point() # Convert coordinates to points and put them in object p.x = float(xstring) p.y = float(ystring) p.z = float(zstring) # All done return p