Here is new code to get the word and a working extraction scenario.
The extraction, although colorful, does it's job.
As time goes on, you will need to be colorful when naming things.
Of course 'fred', 'harry' is a little silly.
You'll notice that the extraction methods are similar to the search function.
Code:
import os
import os.path
import re
fileIN = open('c:/temp/test.txt','r')
line1 = fileIN.readline()
line = line1.upper() # change all text to upper case
#==============================================================
# The search function to Parse a file line is directly below
#==============================================================
def Find(pat, line):
match = re.search (pat, line)
if match: return match.group()
else: return ""
#==============================================================
# The search 'actual', is directly below
#==============================================================
def gSearch():
gsearch = Find( r' *G *\.*\d\d*\.*\d* *', line)
if gsearch != "":
gstring = (gsearch)
gstrip = (gstring).strip()
list (gstrip)
gword = list (gstrip)
if gword [1] .isdigit:
gletter = ' G'
glistnum = gword [1: ]
gstringnum = "".join (glistnum)
gnum = (gstringnum).strip()
g = float (gnum)
gout = gletter + gnum
return gout,g
else:
gletter = ''
glistnum = ''
gstringnum = ''
gnum = ''
g = ''
gout = gletter + gnum
return gout,g
fred = gSearch() # fred will get back, gout and g, again within a 'tuple'()
if fred != ('',''):
print "This is what we get back from the search"
print fred, " We can't do much with a tuple"
tom = list (fred) # tom = fred which is now a list containing gout and g
print tom, """
So now we've made a list from what we found in the tuple.
We can do things with items in a list.
"""
dick = tom [1: ] # dick is now equal to g only
print dick[0], """
this is the G words' number in our list and unlike a string, it's a real number.
Meaning we can go ahead and process this using math if we want.
If it was from an axis word like X, Y or Z, we might want to do something
with it, like, add 1 to the number.
"""
harry = dick[0]
thenumber = harry + 1
print thenumber, " Within reason of course, we can do as we please, with it."
else:
print "No G word found"
fileIN.close()