Masthead

Using The Source Assistent

The last thing you'll need to know about parsing strings is that the "find()" function can take additional parameters including a starting point within the string. This way, when you want to find the next occurrence of the string you can use:

EndOfNextDegree=TheCoordinate.find("\xf8",EndOfDegree+1)

This is also a good time to introduction you to the "Source Assistant in the Wing IDE. Enter the code below but stop after entering the word "find".

TheCoordinate="40\xf8 21' 32\" E, 105\xf8 30' 40\"" 
EndOfDegree=TheCoordinate.find

You should see a tab labeled "Source Assistant" at the right of the Wing IDE. You may need to adjust the size of the panel to see the contents of this tab. You should see something like the documentation below:

Symbol: x.find
 Likely type: builtin method str.find
 def str.find(self, sub, start=None, end=None)
 http://docs.python.org/library/stdtypes.html#str.find
 S.find(sub [,start [,end]]) -> int
 
Return the lowest index in S where substring sub is found, such that sub is contained within s[start:end].  
Optional arguments start and end are interpreted as in slice notation.

Return -1 on failure.

This is a full and exact definition for the function find(). Take a look at the last line of the first section of the definition. This shows you the parameters that can be passed into the find() function. The parameters inside brackets ("[...]") are optional. For find(), you can have to specify a "sub" or substring to search for. Then, you can add a "start" as an index into the string to start searching. Finally, you can add an "end" index to stop the function from searching too far into the string. The "-> int" indicates that the function returns an integer value.

If you keep reading, you'll see some text that describes what the function does and finally that it returns "-1" on failure (i.e. if it does not find the specified string).

This is an incredibly valuable tool to learn exactly what you can do with functions. You can even click on the "http" link provided to jump to the Python.org documentation for the "find()" function.

Additional Resources

Python Documentation: String functions

 

© Copyright 2018 HSU - All rights reserved.