Python Programming help please

Hi there,

I got this txt file with following contents:

My Glossary

The above text is saved in test.txt file.

I need to write a python script that would load the above file as list of strings. I then need display only the text from to in python.

If anybody can help me please with the code. I've tried searching a lot on net but haven't found anything.

Thank You


  • [code]
    import re

    name_block = re.compile('(?P.*)')

    def get_name_block():
    #open the file for reading
    file_name = "test.txt"
    f = open(file_name, 'r')

    #look through it one line at a time
    name_block = ""
    search_result = None
    for l in f:
    search_result = name_block.match(l)
    if search_result:
    name_block = search_result.groups[0]
    return name_block

    That will have a problem if ... spans over multiple lines, because "for l in f" pulls one line at a time. In that case, no one line would ever match the regex. Hope that works for you!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion