Sunday 15 April 2012

Python string print formatting -


I am very new to programming & amp; Python. Still working on my first program I had received some help from this forum a week ago, but now I am stuck in the second part of the program so that I will be the only need of any kind to help me again : -)

In this example I have 2 files keyfile.dat in which the entire ASCII charactor set, one character per line. They are real characters, not code

test.txt works like an index file. Each line has a number that indicates a line number within keyfile.dat , which in turn has an ascii character, the code below gives alphabet, comma, letters of question mark Prints. Although this does not print spaces, carriages returns etc. I think because I do not use the command in the str.strip statement if I do not use that command, instead of printing each character on the same line, Carriage does not read returns, it prints each letter on a separate row. Actually this part of the program should print any character, which is indicated, what it is, and print it exactly as it is being typed.

--- Edit - - Code Removed

Any thoughts? & Amp; Thanks in advance for any replies. Clinton.

sample content of keyfile.dat

  8 e ¿½ �f   

content test.txt: 14 203 163 38 52 163 38 188 231 11 38 231 242 208 74 163 38 163 231

Ouput using my code above:

  T, its best! Or is it? As   

you can see the locations printed between words and later! There should be a carriage return.

Personally I think this is due to my print statement I need to use it. Otherwise each field is printed on the new line read from keyfile.dat. Except my knowledge, vacancy, career returns, etc. are removed. So if I read a cart return & amp; Then try to print it, it is stripped because my print uses the starement. Strip.

Use to deal with the file with the statement, because it Automatically closes the file for you:

  Open ('keyfile.dat') as F, Open ('test.txt') as in the form of I: Index = [ii] #apply int () for line {int (line)) here in the index index keyfile = f.readlines (): line = keyfile [ind] if len (line) & gt; 1: print line [: - 1], Elf lane (line) == 1: print line,    

No comments:

Post a Comment