473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

maintain lines and space after sort

29
how do I keep my file as is after a sort - it is jumbled with \t tabs and \n newlines

ran this script

af = open('c:\Documents and Settings\Administrator\Desktop\pm2.txt', 'r')
keyfld = [item for item in af]
keyfld.sort()
print keyfld

on this file

00000047f36d014afe88 12/14/2008 10:48:53 PM Deleted session ID 00000047f36d014afe88 due to server request|
00000047f36d014afe88 12/14/2008 10:48:53 PM Terminated session 00000047f36d014afe88|
00000047f36d014c5086 12/14/2008 10:48:54 PM Created session ID 00000047f36d014c5086 due to server request|
00000047f36d014c5086 12/14/2008 10:54:25 PM Deleted session ID 00000047f36d014c5086 due to server request|
00000047f36d01bf1b99 12/15/2008 12:00:00 AM Created session ID 00000047f36d01bf1b99 due to server request|
00000047f36d01c0baa5 12/15/2008 12:00:00 AM Deleted session ID 00000047f36d01c0baa5 due to server request|
00000047f36d01c0baa5 12/15/2008 12:00:00 AM Terminated session 00000047f36d01c0baa5|
00000047f36d01c0baa5 12/15/2008 12:00:00 AM Created session ID 00000047f36d01c0baa5 due to server request|
00000047f36d0292fbf7 12/15/2008 12:00:00 AM Terminated session 00000047f36d0292fbf7|
00000047f36d0292fbf7 12/15/2008 12:00:00 AM Created session ID 00000047f36d0292fbf7 due to server request|
00000047f36d029908b3 12/15/2008 12:00:00 AM Terminated session 00000047f36d029908b3|
00000047ff9402b66b26 12/15/2008 12:00:00 AM Deleted session ID 00000047ff9402b66b26 due to server request|
00000047ff9402b66b26 12/15/2008 12:00:00 AM Terminated session 00000047ff9402b66b26|
00000047ff9402b66b26 12/15/2008 12:00:00 AM Created session ID 00000047ff9402b66b26 due to server request|

I got this output - tabs and newline characters

['00000047f36d014afe88\t12/14/2008\t10:47:28 PM\tCreated session ID 00000047
f36d014afe88 due to server request|', '00000047f36d014afe88\t12/14/200
8\t10:48:53 PM\tDeleted session ID 00000047f36d014afe88 due to server
request|\n', '00000047f36d014afe88\t12/14/2008\t10:48:53 PM\tTerminated sess
ion 00000047f36d014afe88|\n', '00000047f36d014c5086\t12/14/2008\t10:48:54 PM\tCr
eated session ID 00000047f36d014c5086 due to server request|\n', '
00000047f36d014c5086\t12/14/2008\t10:54:25 PM\tDeleted session ID 00000047f36d01
4c5086 due to server request|\n', '00000047f36d01bf1b99\t12/15/2008\t1
2:00:00 AM\tCreated session ID 00000047f36d01bf1b99 due to server
Nov 28 '09 #1
1 1054
kudos
127 Expert 100+
@dragrid
replace 'print keyfld' with
Expand|Select|Wrap|Line Numbers
  1. for k in keyfld:
  2.  print k
  3.  
-kudos
Nov 28 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jay Chan | last post by:
I am trying to use a command line program to run a stored procedure that generates output in a comma-delimitted format. Somehow, ISQL or OSQL always wrap the lines at 256 characters. I believe this...
6
by: Daniel Jung | last post by:
Hi This is not a "CSS I want you to do for me since my boss needs it yesterday"... I am wondering about a few things, and I am still working on this, but wanted to share it with you at this...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
5
by: N | last post by:
Hi, I got an error during load on a couple of the tables. And it seems to be complaining that I'm running out of tempspace (possibly during index rebuild). Below is the load command and error....
3
by: Bob Dankert | last post by:
Is there any way to maintain the sort order of a sort on a 2D array? For example: I have the array: 1,a 2,a 3,f 4,a 5,s 6,a 7,z 8,b and sort it by the second column, and I...
1
by: darin_dimitrov | last post by:
I have an application which consists of 2 web forms. On the first page I have a datagrid with paging and sorting turned on. I also have a textbox which allows me to filter the data in the grid and...
82
by: Edward Elliott | last post by:
This is just anecdotal, but I still find it interesting. Take it for what it's worth. I'm interested in hearing others' perspectives, just please don't turn this into a pissing contest. I'm in...
23
by: r.e.s. | last post by:
I have a million-line text file with 100 characters per line, and simply need to determine how many of the lines are distinct. On my PC, this little program just goes to never-never land: def...
0
by: rockdale | last post by:
Hi, All: I dynamic add an arrow up/down image in OnItemDataBound event for my datagrid, it works fine. But I have another textbox which trigger postback and doing something, after this event get...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.