[Tutor] Add newline's, wrap, a long string

David david at abbottdavid.com
Wed Apr 29 13:15:36 CEST 2009


Martin Walsh wrote:
>> ... but, you don't need to use subprocess at all. How about (untested),
>> 
>> # grep USE /tmp/comprookie2000/emerge_info.txt |head -n1|cut -d\" -f2
>> infof = open('/tmp/comprookie2000/emerge_info.txt')
>> for line in infof:
>>     if 'USE' in line:
>>         USE = line.split('"')[1]
>>         break
>> else:
>>     USE = ''
>> infof.close()
>> 

Thanks Martin works perfect. So I understand correctly, line.split('"') 
splits the list on " so [1] grabs after USE = " and up till [2] starts.

>
> 
> Just one more comment, string.join is deprecated, yet join is a method
> of str objects. So ...
> 
>       Lines = '\n'.join(L)
> 
> ... or use textwrap.fill which returns a string with the newlines
> already in place ...
> 
>       Lines = textwrap.fill(USE, 80)
> 
> HTH,
> Marty

Again thanks, I like the comments :)
-david

-- 
Powered by Gentoo GNU/Linux
http://linuxcrazy.com


More information about the Tutor mailing list