Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Alan Gauld
On 22/02/12 13:14, David Craig wrote: Hi, I have created a list of containing strings that represent distances between many different points and would like to display the results in a table. Others have mentioned using format strings. If it is only for display you could switch to html. Then de

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Jerry Hill
On Wed, Feb 22, 2012 at 10:24 AM, David Craig wrote: > you had me worried for a minute, but > a = [[]] * 3 > a[0]=[1,2,3] > a > [[1, 2, 3], [], []] > That's not the same thing. In your example you create three copies of the same empty list inside your outer list. You then throw away the first

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread David Craig
Thanks everyone, was able to get what I wanted from '/t' but I'm sure the other formatting options will be useful in future. @Peter a = [[]] * 3 >>> a [[], [], []] >>> a[0].append(42) >>> a [[42], [42], [42]] you had me worried for a minute, but a = [[]] * 3 a[0]=[1,2,3] a [[1, 2, 3], [

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Peter Otten
David Craig wrote: > distance = [[]]*len(stations) That doesn't do what you think it does: >>> a = [[]] * 3 >>> a [[], [], []] >>> a[0].append(42) >>> a [[42], [42], [42]] See? You get a list that contains the same list len(stations) times. Use [[] for _ in stations] instead. __

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Steven D'Aprano
David Craig wrote: I have been trying to write them to a text file but it is difficult to organise them into rows and columns with appropriate spacing to make it readable. I would like something like, Stations Station1 Station2 Station1 0.033.57654 Station2 33

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Mark Lawrence
On 22/02/2012 13:40, Evert Rol wrote: Hi, This is always a tricky thing to go about. Nicely human-readable doesn't imply nicely machine readable. Sometimes a single space or a single tab between values/columns is more practical for a(nother) program to read, but not for humans. So I will work

Re: [Tutor] Create a table by writing to a text file.

2012-02-22 Thread Evert Rol
> Hi, > I have created a list of containing strings that represent distances between > many different points and would like to display the results in a table. > I have been trying to write them to a text file but it is difficult to > organise them into rows and columns with appropriate spacing to