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

2009-04-29 Thread Alan Gauld
"David" wrote I don't know how else to describe it, that is so cool :) :-) Couple of comments below. import textwrap data = {'CBUILD':None, 'CFLAGS':None, 'MAKEOPTS':None} def get_use(): fname = open('/tmp/comprookie2000/emerge_info.txt') for line in fname: for keyphrase

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

2009-04-29 Thread David
Alan Gauld wrote: "Sander Sweers" wrote What you can do is define all the variables upfront. This way you can get rid of the else. Below is an example how you can do this with only looping once over the fle. And you can put the variables as keys of a dictionary and avoid all the if tests:

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

2009-04-29 Thread Alan Gauld
"Sander Sweers" wrote What you can do is define all the variables upfront. This way you can get rid of the else. Below is an example how you can do this with only looping once over the fle. And you can put the variables as keys of a dictionary and avoid all the if tests: data = {'CBUILD':

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

2009-04-29 Thread Martin Walsh
Sander Sweers wrote: > 2009/4/29 David : >> Here is the whole program so far, what it does is it logs into a druple web >> site and posts. I would like to make it better, as you can see I do the same >> thing over and over. >> >> http://linuxcrazy.pastebin.com/m7689c088 > > What you can do is defi

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

2009-04-29 Thread Martin Walsh
David wrote: > 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: >>>

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

2009-04-29 Thread Sander Sweers
2009/4/29 David : > Here is the whole program so far, what it does is it logs into a druple web > site and posts. I would like to make it better, as you can see I do the same > thing over and over. > > http://linuxcrazy.pastebin.com/m7689c088 What you can do is define all the variables upfront. Th

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

2009-04-29 Thread David
David wrote: Martin Walsh wrote: 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

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

2009-04-29 Thread David
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]

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

2009-04-29 Thread A.T.Hofkamp
David wrote: I am getting information from .txt files and posting them in fields on a web site. I need to break up single strings so they are around 80 characters then a new line because when I enter the info to the form on the website it has fields and it errors out with such a long string.

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

2009-04-28 Thread Martin Walsh
David wrote: > vince spicer wrote: >> first, grabbing output from an external command try: >> >> import commands >> >> USE = commands.getoutput('grep USE /tmp/comprookie2000/emege_info.txt >> |head -n1|cut -d\\"-f2') >> >> then you can wrap strings, >> >> import textwrap >> >> Lines = textwrap.wr

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

2009-04-28 Thread Martin Walsh
David wrote: > I am getting information from .txt files and posting them in fields on a > web site. I need to break up single strings so they are around 80 > characters then a new line because when I enter the info to the form on > the website it has fields and it errors out with such a long string

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

2009-04-28 Thread David
vince spicer wrote: first, grabbing output from an external command try: import commands USE = commands.getoutput('grep USE /tmp/comprookie2000/emege_info.txt |head -n1|cut -d\\"-f2') then you can wrap strings, import textwrap Lines = textwrap.wrap(USE, 80) # return a list so in short:

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

2009-04-28 Thread vince spicer
first, grabbing output from an external command try: import commands USE = commands.getoutput('grep USE /tmp/comprookie2000/emege_info.txt |head -n1|cut -d\\"-f2') then you can wrap strings, import textwrap Lines = textwrap.wrap(USE, 80) # return a list so in short: import commands, textwrap

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

2009-04-28 Thread David
I am getting information from .txt files and posting them in fields on a web site. I need to break up single strings so they are around 80 characters then a new line because when I enter the info to the form on the website it has fields and it errors out with such a long string. here is a samp