Yethrosh Yethrosh - 1 year ago 149
Python Question

Auto Increment in wikitable using python

I have mediawiki user statistics in wikitable format, which have been generated by sql query.
Now I would like to replace all

exist in first column and in every row to auto increment numbers i.e 1,2,3,4 starting from first row using python script.

Any idea how to accomplish this task?

Data in wikitable format:

matter = """{| class="wikitable"

with open("wikit.txt", 'w') as f:

with open('wikit.txt', 'r') as f:
m =


Answer Source

Haven't tested but it should work for you

   with open('wikit.txt', 'r') as f:
        lines = f.readlines()
    newlines =[]
    for line in lines:
        if "#" in line:

   newlines_str='\n'.join(line for line in newlines)

    with open("wikit.txt", 'w') as f:
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download