Python 2.7 fnmatch NOT editing text

99
January 27, 2021, at 11:50 PM

I have a file with 600k+ records of string labels I am trying to edit with an update cursor using both the string modules and fnmatch to find patterns to edit. The section using fnmatch is successfully printing the matched records but not changing / parsing out the matched pattern.

There is no error and there is no change to the record. What am I missing with my syntax?

(Also - side issue, the last print row 4 statement only prints the first record of the file.)

The result samples are unchanged from original text 1000STR92SE 8000STR37NW 7000STR35SW 8000STR44 1000STR88SE 1000STR74SE

But results need to be 92SE 37NW 35SW 44 88SE 74SE

def newlabel():
#Global Conversions - works on editing the string
    with arcpy.da.UpdateCursor(mvum_fc, newfields) as uc:
        for row in uc:
            if row[1] == None or row[1].startswith('0'):
                row[4] = '{}'.format(row[4].lstrip(ascii_letters).replace('_', "-").lstrip('0').replace(' ', '-'))
            if row[1] == None or row[1].startswith('-'):
                row[4] = '{}'.format(row[4].lstrip('-').lstrip('0'))
#Regional Conversions - lstrip and replace tried - not changing text.
            elif row[1].startswith('0118'):
                pattern = ('?000STR*')
                match = fnmatch.fnmatch(row[4], pattern)
                if match == True:
                    row[4] = '{}'.format(row[4].lstrip('?000STR'))
                    print(row[4])
            uc.updateRow(row)
            print(row[4])
Answer 1

Remove the ? in the string you want to strip. It is a wildcard used in pattern matching.

row[4] = '{}'.format(row[4].lstrip('000STR'))
Answer 2

I have resolved this by avoiding the .lstrip:

row[4] = '{}'.format(row[4].lstrip('000STR'))

and simply replacing it with:

row[4] = '{}'.format(row[4][7:])

READ ALSO
How to build a known apk for play store in flutter?

How to build a known apk for play store in flutter?

i made app and build it as an apk file in flutter and i tried to install it in my android phone but while installing it, play store said: the app is unkhown do you wanna install, and then i installed the app and app was working well, the question is how i can solve it, Do i have to buy a play store account?...

101
Unable to start Hive metastore related to java exception

Unable to start Hive metastore related to java exception

I installed Apache hive 3, Apache Hadoop 3, Trino and Mysql (mysql Ver 1414 Distrib 5

127
Select content from “div class” which contains certain words

Select content from “div class” which contains certain words

I have the following ajax-response which is generated by a server sided script:

109
I'm not able to pass the state value to the method or function in React [closed]

I'm not able to pass the state value to the method or function in React [closed]

Want to improve this question? Add details and clarify the problem by editing this post

136