Forwarding full message to the Python list:
Hello, I am trying to create a script. I have most of it wrote, but it
isn't working like it should. Could you please take a look and let me
know whats wrong with it? What happens is that there is an array that is
created and I verified the information goes in there by sending what was
in the pullerList[i] to an output file. The output file looks like this:
PATCH_NUMBER: 2_3_1
BUG_NUMBER: 8711
FEATURE_AFFECTED: Source Build.xml
OVERVIEW: new features added to the build.xml"
PATH:IPMDFCommons/Source
FILE:build.xml
Below is the script, which I want to go through the pullerList list and
look at the first line and see if it equals N/A, 2_3_1, or 2_3. as you
can see if it equals n/a it exits, if it equal 2_3_1, then it opens that
specific text file and writes what I have there, etc. But my code isn't
creating the text file or doing what it is suppose to. Any ideas?
patchnumber = ""
for line in pullerList:
line = line.strip()
if line.startswith('PATCH_NUMBER:'):
patchnumber = line[17:] == 'N/A'
elif line.startswith('PATCH_NUMBER:'):
patchnumber = line[17:] == '2_3_1'
elif line.startswith('PATCH_NUMBER:'):
patchnumber = line[17:] == '2_3'
if patchnumber == 'N/A':
sys.exit(0)
elif patchnumber == '2_3_1':
ftemp = open("C:/CVSAutoMailerPY/Patch_2_3_1.txt","a")
ftemp.write(sys.argv[1] + "/" + sys.argv[2])
ftemp.write("hi")
sys.exit(0)
elif patchnumber == '2_3':
ftemp = open("C:/CVSAutoMailerPY/Patch_2_3.txt","a")
ftemp.write(sys.argv[1] + "/" + sys.argv[2])
ftemp.write("hi")
sys.exit(0)
The pullerList loop is wrong. You can verify it if you print
patchNumber at the end of the loop. It appears you were playing
guessing games with it... :)
Suggestion: Write the body of your script inside a function, so you
can test it *outside* the cvsnt environment. After you are rather
convinced it works as intended, try it in the real situation.
Try this:
for line in pullerList:
line = line.strip()
if line.startswith('PATCH_NUMBER:'):
patchnumber = line[13:].strip()
Notice the 13 (17 was wrong). Better, to avoid having to count
characters -very prune to error-, try this version:
for line in pullerList:
line = line.strip()
if ':' in line:
key, value = line.split(':',1)
if key=='PATCH_NUMBER'
patchnumber = value.strip()
if key=='ANOTHER'
whatever = value.strip().lower()
Here we split the line on the ":" character; key is the text on the
left, value the remaining text on the right.
If you are using Python 2.5, the partition() string method would be
useful here.
Gabriel Genellina
Softlab SRL
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
--
http://mail.python.org/mailman/listinfo/python-list