473,396 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to give a single Tab Space between two or columns in Output In python

Expand|Select|Wrap|Line Numbers
  1. import psycopg2
  2. import os.path
  3.  
  4. conn = psycopg2.connect("dbname=overlapanalysis user=postgres")
  5. cur = conn.cursor()
  6. cur.execute("select * from  annotation(5,-10000,-10000) ")
  7.  
  8. result=cur.fetchall()
  9. for columns in result:
  10.  
  11.     print (str(columns[1])+"\t"+str(columns[2])+"\t"+str(columns[3])+"\t"+str(columns[4])+"\t"+str(columns[5]));
  12. conn.commit()
  13. cur.close()
  14. conn.close()


In this the picture is also upload of Out put the white spaces is to much i want only 1 Tab Space in every column.
Attached Images
File Type: jpg Untitled.jpg (53.2 KB, 590 views)
Jan 19 '12 #1
1 3759
dwblas
626 Expert 512MB
I would test the length of each column with code along the lines of this untested (since we don't have the DB) snippet
Expand|Select|Wrap|Line Numbers
  1. result=cur.fetchall()
  2. for columns in result:
  3.     stop = 6
  4.     if len(columns) < 6:
  5.         stop = len(columns)
  6.     for num in range(1, stop):
  7.         print(num, len(columns[num]))
  8.     this_line = [str(columns[num]).strip() for num in range(1, stop)]
  9.     print "\t".join(this_line) 
Also, the commit statement does nothing as you have not changed the DB.
Jan 19 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: David H | last post by:
Hello. Simple question for you probably. I can't understand why the output for something like <%="x"%> <%="x"%> is "xx" (no quotation marks)
2
by: Colin Hale | last post by:
This is driving me bananas. Can't find any info on this anywhere.... SQL 2000 seems to replace double space with a single space when I set a varchar field to " " (2spaces), it only stores " "...
2
by: José Joye | last post by:
Hello, I was wondering if there is a method that exists to replace multi-spaces within a string with single-space. eg: "12 3 4 56" --> "12 3 4 56" I think this could be done by...
1
by: Dgates | last post by:
This request might belong in a "SQL"-related newsgroup, but it's such a pain using Agent to subscribe to a new group (and download its 50,000 messages!) just to ask one question. So, since it...
0
by: Andy | last post by:
Hi All. I'm working for a company that has set out a guideline for retrieving data from a database. Nobody can explain to me the reason for the following. When retrieving a set of records...
4
by: CC | last post by:
Hi there, I wanna compile a 6000x1000 array with python. The array starts from 'empty', each time I get a 6000 length list, I wanna add it to the exist array as a column vector. Is there any...
0
by: Alan Silver | last post by:
Hello, I am using a RequiredFieldValidator in a form, but have discovered that it will allow someone to enter a single space. What I want is that someone has to enter something real, ie a name,...
2
by: Fareast Adam | last post by:
Here is my code: if(isset($_REQUEST)) { //capture name from textfield $name = $_POST; //make pattern for name function checkName($uname) {
3
by: skyy | last post by:
Hi.. i have a string that i would want split on a single blank space only. eg. $string = File: abc.txt using split with white space i can get the name of the file : abc.txt However i run...
5
by: polturgiest | last post by:
hie all i got a form <form name="TEST" method=POST action="test.php"> <input type="text" name="MyInput"> <input type="submit" name="ACTION" value="SAVE">
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.