On 25/10/14 23:46, Clayton Kirkwood wrote:
__author__ = 'SYSTEM'

You are still setting __author__ which is a bit suspect.
Leave double underscores to python.

import string

You are still importing string twice, and you don't use it anywhere
that I can see.

#Pricing                Dividends

raw_table = ('''

I assume this will eventually come from a file?
You are not really going to store it with your code?
If you are then using a string is pointless and causing
you lots of extra work.

a: Ask    y: Dividend Yield
b: Bid     d: Dividend per Share
b2: Ask (Realtime)           r1: Dividend Pay Date
b3: Bid (Realtime)            q: Ex-Dividend Date
...
s7: Short Ratio
''')

You don't need parens as well as triple quotes.
The quotes alone are sufficient.

import re, string

second string import... And you don't seem to be using re either?

col_position, code, description = 0, [], []
key_name = raw_table.replace('\t','\n')

I assume this is because you don't control the file format? Since otherwise you would just use newlines in the file, right?


for each_line in  key_name.splitlines():
     if ':' in each_line:
         c, d = each_line.split(':')
         code.append(c)
         description.append(d.strip())
         print( col_position, code[col_position], description[col_position])
         col_position += 1

You could use enumerate in the for loop and that would set the col_position value for you:

for col_position,each_line in enumerate(key_name.splitlines()):


output_line_len = 120
current_output_pos = index = 0
description_output_string = code_output_string = ''
for description_position, code_position in zip(description, code):

Why not just put the codes and descriptions in tuples when you read them in the loop above? Why use zip? In other words where you do

>          c, d = each_line.split(':')
>          code.append(c)
>          description.append(d.strip())

Why not just join the pair there:

>          c, d = each_line.split(':')
           values.append((c,d))

or even just

>          values.append(each_line.split(':'))

It seems as if you are splitting the values into two lists only
to zip those lists together again in the next loop?

     description_position_len = len(description_position)
     current_output_pos += description_position_len

     if current_output_pos >= output_line_len:
         print(description_output_string)
         print(code_output_string)
         code_output_string=description_output_string=''
         current_output_pos=-1   #start new line

     description_output_string += '{:^}|'.format(description_position)

     code_output_string+='{0:^{1}}|'.format(code_position,
description_position_len)

     current_output_pos+=1  #takes care of '|' at end of string

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to