can python do this?
Ken Seehof
kens at sightreader.com
Tue Jun 13 08:03:59 EDT 2000
Thomas Weholt wrote:
> On Tue, 13 Jun 2000 16:39:23 +1000, "Jason" <it at onestopent.com.au>
> wrote:
>
> >> import string
> >> file = open ("file")
> >> lines = file.readlines()
> >> for line in lines:
> >> pair = string.split(line,":")
> >> print pair[0] +": "+ `string.split(string.strip(pair[1]),",")`
> >> file.close()
>
> The line :
>
> file = open("file")
>
> change "file" to the complete path of your text-file, like if your
> file resides in c:\temp\music.txt, change it to :
>
> file = open("c:\\temp\\music.txt")
>
> And YES, the double backslashes are needed, or the \t in \temp is
> interpreted as TAB. Just change that and run the script from PythonWin
> or IDLE. They both come with Python, or eh ... at least IDLE does.
>
> Thomas
Or put an r before the string to neutralize the backslashes:
file = open(r"c:\temp\music.txt")
BTW, you can use forward slashes instead of backslashes if you want.
file = open("c:/temp/music.txt")
This is a portability feature. I'm pretty sure the converse, backslashes
in unix, works too.
--
Ken Seehof
kens at sightreader.com
starship.python.net/crew/seehof
Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kens.vcf
Type: text/x-vcard
Size: 343 bytes
Desc: Card for Ken Seehof
URL: <http://mail.python.org/pipermail/python-list/attachments/20000613/a4ff3b49/attachment.vcf>
More information about the Python-list
mailing list