[Tutor] subprocess adds %0A to end of string

David david at abbottdavid.com
Mon Dec 22 03:18:46 CET 2008


Martin Walsh wrote:

> 
> Welcome!
> 

thanks

> You should probably try to avoid reassigning sys.stdout. This is usually
> a bad idea, and can cause odd behavior that is difficult to
> troubleshoot, especially for a beginner. A reasonable approach is to
> assign the open file object to a name of your own choosing...
> 
> .>>> podcast_file = open('podcast.txt', 'a')
> 
> ... and then, use the write method of the file object ...
> 
> .>>> podcast_file.write('%s: %s' % (entry.updated, entry.link))
> 
> More info here:
> http://www.python.org/doc/2.5.3/tut/node9.html#SECTION009200000000000000000
> 
> 
>>         print '%s: %s' % (entry.updated, entry.link)
>>         sys.stdout.close()
>>     for entry in data.entries:
>>         sys.stdout = open("podcast_links.txt", "a")
>>         print '%s' % (entry.link)
>>         sys.stdout.close()
>> getFeed()
This "podcast_file.write('%s: %s' % (entry.updated, entry.link))"
writes it in one very long string

The Latest Link
http://linuxcrazy.com/podcasts/LC-44-arne.ogghttp://linuxcrazy.com/podcas=>>

and sys.stdout prints to the file one line at a time

How do I split the long string, not even sure if that is the correct term?

for i in somefile: ?

re.somefile(do_something) ?



-- 
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu



More information about the Tutor mailing list