I am a complete novice and have written the following code and it work as required, with the exeption of the text being in a tidy format when printed.
The origDict.txt has been exported in a fixed file format, and I am trying to acheive a fixed file layout for the 2nd colomn so it looks neat and readable.
I feel my problem could be something to do with unusual 'escape characters' in the origDict.txt. Is there some way I can display the 'escape characters' so as to enable some further investigation?
I have tried various layout techniques to no avail. Some help would be very much appreciated.
Copy of my code
lines_per_page = 73 current_page = 0 line_pointer_a = 1 line_pointer_b = line_pointer_a + lines_per_page write_file = open ("newDict.txt", "w") read_file = open ("origDict.txt", "r") lines_in_file = read_file.readlines () read_file.close() lengh_file = len (lines_in_file) while line_pointer_a != (lines_per_page * (current_page + 1 ) + 1): lineA = lines_in_file [line_pointer_a].strip() #Read line & delete CR lineB = lines_in_file[line_pointer_b] # Read line newString = '%-56s %-56s' % ( lineA , lineB) write_file.write (newString) # write string to newDict print newString line_pointer_a += 1 line_pointer_b += 1 if line_pointer_b >= lengh_file: write_file.close() print 'Job Done' break if line_pointer_a == (lines_per_page * (current_page + 1 ) + 1): current_page += 2 line_pointer_a = (lines_per_page * (current_page ) + 1) line_pointer_b = line_pointer_a + lines_per_page
A sample of part of the generated newDict.txt file, it is an English to Greek Dictionary. The printed result is not very well represented below, due to limitations of the site display (I think!)
about, approximately περίπου cinema σινεμά (το)
after μετά cinema σινεμά/κινηματογράφος
afternoon απόγευμα (το) city πόλη (η)
again πάλι clock, watch ρολόι (το)
airplane αεροπλάνο (το) closed κλειστός, -ή, -ό
all όλος, -η, -ο clothes ρούχα (τα)
alone, only μόνος, -η, -ο cloud σύννεφο (το)
always πάντα/πάντοτε coffee καφές (ο)
American αμερικανικός, -ή, -ό coffehouse καφενείο (το)
and και cognac κονιάκ (το)
and, too, also και cognac κονιάκ (το)