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 8421593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:11:27+00:00 2026-06-10T03:11:27+00:00

So I have a list that gets generated e.g. missingfromauthoratative and with that list

  • 0

So I have a list that gets generated e.g. missingfromauthoratative and with that list I want to do two things.
1. Print the results on the screen and;
2. Write the results to a csv file.

With what I have it will do one or the other or sometimes a combination. The code below is what I have.

#Find what is missing or new
    missingFromAuthoritative = dBase.execute('SELECT url, mapindex, mapname, layerid, layername FROM authoritative EXCEPT SELECT url, mapindex, mapname, layerid, layername FROM current;')
    newToAuthoritative = dBase.execute('SELECT url, mapindex, mapname, layerid, layername FROM current EXCEPT SELECT url, mapindex, mapname, layerid, layername FROM authoritative;')


    #Print missing services (-) and new services (+)
    for missing in missingFromAuthoritative:
            print '-', missing[0], '\n  Map:  ', missing[2], '\n  Layer:', missing[4], '\n'
            self.inconsistency += 1
            outcsv = csv.writer(open('missing.csv', "wb"))
            header = ("Map Service","Map Index","Data Frame","Layer ID","Layer Name")
            outcsv.writerow(header)
            outcsv.writerows(missingFromAuthoritative)

It also sometimes writes one row to the screen and the other three to the csv.
This is what I want on the screen
– MapServer
Map: Layers
Layer: Proposed Power Generation Sites
– MapServer
Map: Layers
Layer: Existing Infrastructure
– MapServer
Map: Layers
Layer: Existing Utility Sites
– MapServer
Map: Layers
Layer: Existing Transmission Lines
4 inconsistencies found in 81.28 seconds.

and this is what I want in the csv
Map Service Map Index Data Frame Layer ID Layer Name
MapServer 0 Layers 0 Proposed Power Generation Sites
MapServer 0 Layers 1 Existing Infrastructure
MapServer 0 Layers 2 Existing Utility Sites
MapServer 0 Layers 3 Existing Transmission Lines

I have no idea why putting them after the for iterator doesn’t work. The only way to get wither to work is to comment the other out.

Thanks

  • 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-10T03:11:29+00:00Added an answer on June 10, 2026 at 3:11 am

    You have several problems. You are reopening the file on every loop iteration, and thus truncating it every time. You are also writing the header and the entire missingFromAuthoritative list on every iteration, masking the first bug. Also, every time you iterate through the list, you are consuming a row from the query, so by the time you get to the end, there is nothing left to write.

    You should open the file once before the loop, write the header before the loop, write one row to the csv on each iteration, and close the file afterwards. You can do this with a with block:

    with open('missing.csv', "wb") as outFile:
        outCsv = csv.writer(outFile)
        outCsv.write(header)
        for missing in missingFromAuthoritative:
            # do your other stuff with inconsistencies, etc., here
            print missing
            outCsv.writerow(missing)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a select box that gets generated dynamically. I want to allow users
I have created a list form that gets attached to a main form in
I have a VBA Word Macro that gets words from .txt list and color
I have a Java program that is supplied a directory name, gets a list
I have a list that has two items: projects and groups. Projects can go
I have a list that I want to loop through (for trimtemp in trim)
I have one list that I want to take a slice of, reverse that
I have a table that gets a dynamic source list for each row, with
I have an Android activity that gets a list of files from a directory
I have a list that contains 10**7 lists in the format: big_list = [[1,

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.