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

  • Home
  • SEARCH
  • 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 8641291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:29:14+00:00 2026-06-12T11:29:14+00:00

I am a beginner with python and I am trying to print the results

  • 0

I am a beginner with python and I am trying to print the results of a query to a pipe delimited file. How can I modify this script to do so?

import cx_Oracle
import csv

connection = cx_Oracle.connect("blah blah blah connection stuff")
cursor = connection.cursor()
cursor.execute("select column1, column2 from schema.table")
result=cursor.fetchall()
c = csv.writer(open("C:\mystuff\output.csv","wb"))
c.writerow(result)      

Right now it prints out like this
“(10001965, ‘0828442C00548’)”,”(10001985, ‘0696230C35242’)”,”(10001986, ‘C41251’)”

I want it to print pipe delimited and a new line at the end of the row. Thanks for any help!
10001965|0828442C00548\n
10001985|0696230C35242\n
10001986|C41251\n

  • 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-12T11:29:16+00:00Added an answer on June 12, 2026 at 11:29 am

    To get the pipes symbol as the delimiter, you can pass in a “delimiter” parameter when creating the writer:

    c = csv.writer(open(“C:\mystuff\output.csv”,”wb”), delimiter=”|”)

    you can also add a lineterminator param:

    c = csv.writer(open(“C:\mystuff\output.csv”,”wb”), delimiter=”|”, lineterminator=”\n”)

    though it is supposed to default to “\r\n”

    I think you may also have a problem with the call to “writerow”. The db result is a list of tuples, to correctly write this to the csv files, you should use “writerows” (NOTE THE plural form of the function). This should correctly handle the list and put the pairs of db values on separate line, correctly delimited with pipes. Currently, your code is writing one “row”, that’s why there are no newlines separating the data values.

    New code:

    c = csv.writer(open(“C:\mystuff\output.csv”,”wb”), delimiter=”|”)

    c.writerows(result)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get simple code working, unfortunately I'm a python beginner. My script
I am beginner in python and facing this problem. So how i can break
I am a beginner at python (one week). Here I am trying print the
I'm a beginner to Python trying to decode this javascript sequence. I'm not only
I am quite a beginner to Python and trying to get my head around
I am a beginner of Python. I am trying now figuring out why the
Python beginner here. I have a text file that is sorted into columns: fields
I am a beginner with Python and trying few programs. I have something like
This is my first question. My python script opens and reads from a present
I'm a beginner in python and I'm trying to use a octal number in

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.