Programmer's Corner Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programmer's Corner - Forums


Getting file.readlines() to work with carrage returns?

 
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Python
Author Message
Cerulean
Gokenin


Joined: 22 Oct 2004
Posts: 742
Location: London, England

PostPosted: Thu Oct 21, 2004 5:52 pm    Post subject: Getting file.readlines() to work with carrage returns? Reply with quote

I'm trying to iterate over the lines in a file, but its not working as the page seems to not use newline characters but carriage returns instead. Is there anyway to make readlines() seperate into a list of strings seperated by carriage returns?

Back to top
Algorithms
Dragon


Joined: 21 Oct 2004
Posts: 343
Location: Florida

PostPosted: Thu Oct 21, 2004 7:33 pm    Post subject: Re: Getting file.readlines() to work with carrage returns? Reply with quote

You reading old mac files? hehe
Code:

file(..).read().split("\r\n")
# OR
file(..).read().split("\r")

Give that a whirl


Last edited by Algorithms on Fri Oct 22, 2004 9:13 pm; edited 1 time in total
Back to top
Cerulean
Gokenin


Joined: 22 Oct 2004
Posts: 742
Location: London, England

PostPosted: Fri Oct 22, 2004 5:44 am    Post subject: Reply with quote

First one, just what I needed. Thanks.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Programmer's Corner Forum Index -> Python All times are GMT - 5 Hours
Page 1 of 1

 


Powered by phpBB © 2001, 2002 phpBB Group