Hi,
I have written a script which parses a UTF-8 text file and prints the required result. The code is below:

import os
import sys
import string
import csv
import codecs
usage = "usage: Specify the directories for files and the RDOCK cut-off value"
tm_append=[]
if len(sys.argv) < 1:
    print usage
    sys.exit()
else:
    f=codecs.open(sys.argv[1],  encoding='utf-8')
    for line in f:
        if line[0:3] =="The":
            print line[56:]
        elif line[0:4] == "Stru":
            print line[24:]
        elif line[0:4] == "RMSD":
            print line
        elif line[0:4] =="TM-s":
            print line
        elif line [0:4] == "MaxSu":
            print line
        elif line[0:4] =="GDT-":
            print line
        elif line[0:4] =="Supe":
            print line
            print "-------------------------------------------------------------------------------------"

The output given is:

ab_c/with_d/complex.394

/ab_c/with_d/complex.1094

Length=  917

Length=  917 (by which all scores are normalized)

RMSD of  the common residues=   38.213

TM-score    = 0.3821  (d0=10.18, TM10= 0.3501)

GDT-TS-score= 0.3501 %(d<1)=0.3501 %(d<2)=0.3501 %(d<4)=0.3501 %(d<8)=0.3501

GDT-HA-score= 0.3501 %(d<0.5)=0.3501 %(d<1)=0.3501 %(d<2)=0.3501 %(d<4)=0.3501

Superposition in the TM-score: Length(d<5.0)=321  RMSD=  0.00

Though the output is correct, I want them to be printed on the same line instead of multiple lines? Can anyone help me?
Cheers,
Chavanak

First when you iterate over the lines, there is a newline character at the end of each line. This newline can be removed with line = line.rstrip("\r\n") . You should write this as the first statement in the for loop. Then I suggest that you invoke an output function instead of printing lines. It means that you replace all the print line[4:] by output(line[4:]) . This allows you to change the effect of your code just by defining the output function. For example you can write

import sys
def output(data):
    sys.stdout.write(data)

Later, you can change this function definition to print to a file, or add newlines, etc.

commented: Helped me a lot and answered my question +1

Thanks for the help, the problem is solved now :)

hi ,i m unable to make a grid like 0000
0000
0000 .... plz can anybody help me. how to print output
in a same line.
for row in range(3):
for col in range(4):
print (0)
print ()

I assume that you are using Python 3 from the function style prints. You can give end keyword parameter the letter you want inserted after print, if you want print right after previous one for example end="".

Like this:

for row in range(3):
    for col in range(4):
        print '0',
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.