Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8495585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:36:49+00:00 2026-06-10T23:36:49+00:00

I have a file in which i provide steps and then based on the

  • 0

I have a file in which i provide steps and then based on the steps the content to follow.
Here is the textfile that i read in:

[Steps]
step1 = WebAddress
step2 = Tab
step3 = SecurityType
step4 = Criteria
step5 = Date
step6 = Click1
step7 = Results
step8 = Download
[data]
WebAddress___________________________ Destination___________ Tab_____________ SecurityType___________________________________________________ Criteria___ Date_______ Click1_ Results_ Download    
https://mbsdisclosure.fanniemae.com/  q:\\%s\\raw\\fnmapool  Advanced Search  Interim MBS: Single-Family                                      Issue Date  09/01/2012  Search  100      CSV XML
https://mbsdisclosure.fanniemae.com/  q:\\%s\\raw\\fnmapool  Advanced Search  Preliminary Mega: Fannie Mae/Ginnie Mae backed Adjustable Rate  Issue Date  09/01/2012  Search  100      CSV XML
https://mbsdisclosure.fanniemae.com/  q:\\%s\\raw\\fnmapool  Advanced Search  Preliminary Mega: Fannie Mae/Ginnie Mae backed Fixed Rate       Issue Date  09/01/2012  Search  100      CSV XML

I already have a working model in reading the file, and then assignning the correct content to the correct header (e.g. the url to the header WebAdress). However, what i want to do is follow the looping based on the steps.
Code to process the data:

from itertools import groupby
count =0
file_name = "FNMA.tbl"
with open(file_name) as f:
      pre_data,post_data =[s.strip() for s in (f.read()).split("[data]")]
post_data_lines = post_data.splitlines()
headers = post_data_lines[0].split()
headers2 = [s.replace("_"," ").strip() for s in headers]
for line in post_data_lines[1:]:
    tmpline  = []
    pos = 0
    for itm in headers:
        tmpline.append(line[pos:pos+len(itm)])
        pos += len(itm)+1
    myDict= dict(zip(headers2,tmpline))
    count += 1
    for key, group in groupby(myDict.iteritems(), lambda x: x[0]):
        for thing in group:
            print "step: %s header: %s" % (thing[1], key)
    print "Finished processing row %s" % count
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:36:50+00:00Added an answer on June 10, 2026 at 11:36 pm

    First, create a dictionary mapping the name of a step to a number, like this:

    steps = dict((step.split()[2], pos) 
            for (pos, step) in enumerate(pre_data.splitlines()[1:]))
    

    (Granted, this is a pretty ugly line of Python, but it seems to work)

    Now, you can sort the items in your dict by those steps:

    sorted_items = sorted(myDict.items(), 
            key=lambda item: steps[item[0]] if item[0] in steps else 999)
    

    And iterate over those items:

    for key, thing in sorted_items:
        print "step: %s header: %s" % (thing, key)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this file which I need to read the first bytes to check
Suppose I have file which goes like this : a void measure() { a
I have a file which contains lines of data in the following format: a11
I have a file which I'm trying to extract information from, the file has
I have a file which has multiple columns, whitespace separated. e.g: data1 data2 data3
I have .zip file which contain csv data. I am reading .zip file using
i have a file which contains a lot of update query and some other
I have a file which is combination of PHP and HTML. How can i
I have a file which may be in ASCII or UTF-8 format. I can
I have a file which i'm parsing out myself. Every time i spot a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.