User Profile

Collapse

Profile Sidebar

Collapse
dann
dann
Last Activity: May 5 '11, 11:38 AM
Joined: Dec 4 '10
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Thanks everybody with your help my code is doing what it should do.
    I am catching all the code between a start and an end point and storing it in a list.
    Code:
    import re
    
    parsing =False
    aList = []
    mylist = []
    bBlock = []
    
    fileObj = open('inputfile', 'r')
    for line in fileObj:
        if line.find(".ent") != -1:
            print "Now parsing **************************************"
    ...
    See more | Go to post

    Leave a comment:


  • bvdet,

    Thanks again and to the others who replied.
    That's what I need it to do, but after it finds the start word it strips all the lines and I want to keep the file structure as it was. I tried to remove ".strip()" from "sLine = fileObj.next(). strip()", but that didn't work. With my previous code i used readlines().

    Another question, after that the alist has stored the values between the start...
    See more | Go to post

    Leave a comment:


  • Thank you bvdet for the quick reply.
    I tried to follow your approach, but i got stuck the second loop (while loop). I get an error when i do try to leave both loops. I am not sure where to use the breaks to leave of the loops. Thanks again for your help
    Code:
    import re
    
    fileObj = open(inputFile, 'r')
    #lines = f.readlines()
    aList = []
    for line in fileObj:
        sLine = line.strip()
        #print
    ...
    See more | Go to post

    Leave a comment:


  • Search for 2 words in a file and print out all the lines between these 2 words

    I need to read in a file and split it into lines. Then search for a start and an end word and print out all the words in between including the start and end words.

    For example: (file)
    a
    b
    foo
    c
    d
    bar
    e

    output:
    foo
    c
    d
    bar

    I tried to search on the web but without any luck.
    I'm just a beginner, any help is appreciated thanks....
    See more | Go to post
No activity results to display
Show More
Working...