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

The Archive Base Latest Questions

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

#!/usr/bin/env python import csv import pyodbc out_file = file.csv conn = pyodbc.connect(DRIVER={driver};SERVER=servername;UID=user;PWD=pass;DATABASE=data) cursor =

  • 0
#!/usr/bin/env python
import csv
import pyodbc

out_file = "file.csv"

conn = pyodbc.connect("DRIVER={driver};SERVER=servername;UID=user;PWD=pass;DATABASE=data")

cursor = conn.execute("SELECT TOP 10 * FROM table")

with open(out_file, 'w') as f:
  print cursor
  csv.writer(f, quoting=csv.QUOTE_MINIMAL).writerows(cursor)

That is my code as of now, and that works as expected. My question is, how would I add a few null-valued columns to the row before inserting it into the CSV? I need to do this because I’ll be combining it with another query that is going to have a few extra data columns and I’d like the data to line up with null-filled columns.

  • 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-10T22:27:17+00:00Added an answer on June 10, 2026 at 10:27 pm

    How about:

    writer = csv.writer(f, quoting=csv.QUOTE_MINIMAL)
    for row in cursor:
        writer.writerow(list(row) + ['', '', '', ''])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a simple python script in file 'bin/test': #!/usr/bin/env python import argparse PROGRAM_NAME
#! /usr/bin/env python import os import stat import sys class chkup: def set(file): filepermission
I run python CGIHTTPServer with (server.py) #!/usr/bin/env python import CGIHTTPServer def main(): server_address =
#!/usr/bin/env python import os, sys, subprocess, time while True: print subprocess.call(xsel, shell=True); time.sleep(1); Takes
the code here below: #!/usr/bin/env python import wx class MyForm(wx.Frame): def __init__(self): wx.Frame.__init__(self, None,
I have the following code: #!/usr/bin/env python import sys from PyQt4 import QtGui, QtCore
I'm running a simple python script sending data to a mongodb #!/usr/bin/env python import
The Problem This code #!/usr/bin/env python import pynotify import time import datetime c='5/1/12 1:15
The following code: #!/usr/bin/env python import mechanize class MechanizeSubclass(mechanize.Browser): def __init__(self, factory=None, history=None, request_class=None,
The following python script works fine: #!/usr/bin/env python import httplib, urllib params = urllib.urlencode({'url':'xxx/xxx/0AAAUw7n6qPQ922.jpg',

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.