[Tutor] Reading a csv of coordinates, trying to write a csv of bearings.

Joel Goldstick joel.goldstick at gmail.com
Mon Jul 9 13:53:07 CEST 2012


On Mon, Jul 9, 2012 at 3:14 AM, Hugo Arts <hugo.yoshi at gmail.com> wrote:
> On Mon, Jul 9, 2012 at 3:10 AM, Gregory Lund <gnj091405 at gmail.com> wrote:
>>
>> I'm Not looking for an absolute solution, but perhaps some insight
>> into some snippets of code, or
>>         suggestions of where I should seek out answers to this issue.
>> Or where I've gone wrong below.

1. Look at the csv module.  It makes dealing with csv very convenient.
2. The fact that every other line in your input file is blank will
require you to through out those lines.  One way to do this is with
slicing:
    >>> a = [0,1,2,3,4,5,6]
    >>> b = a[::2]
    >>> b
    [0, 2, 4, 6]
    >>>
3. I would read the input into a list of lists (each line item is in a
list, each line is in the containing list
4. get rid of the blanks
5. make a function to take the input lists and do your math,
producting a list of lists to be output
6. use the csv writer to write to a file
7. You have way to many comments in your code.  At the top of your
file, and immediately underneath each function definition use
docstrings (triple quoted multi-line strings).  These are great in
that they provide automatic documentation for your functions using
pydocs, or when you are in the python shell you can do
help(function_name) and find out what it does



-- 
Joel Goldstick


More information about the Tutor mailing list