Unusual i/o problems

S

saif.shakeel

Hi,
I am parsing an xml file ,before that i have replaced a string in
the original xml file with another and made a new xml file which will
now be parsed.I am also opening some more files for output.The
following code shows some i/o commands.
file_input = raw_input("Enter The ODX File Path:")
input_xml = open(file_input,'r')

(shortname,ext)=os.path.splitext(file_input)
f_open_out=shortname+".ini"
log=shortname+".xls"
test_file=shortname+"testxml.xml"

saveout = sys.stdout

xmlcont=input_xml.read()
input_xml.close()

xmlcont=xmlcont.replace('localId','dataPackageId')

output_file = open(test_file,"w")
output_file.write(xmlcont)
output_file.close()

f_open=open(f_open_out, 'w')
logfile=open(log,"w")
sys.stdout = f_open

After this i have to parse the new xml file which is in
output_file .hence

input_xml_sec = open(output_file,'r')
xmldoc = minidom.parse(input_xml_sec)

But i am getting an error on this line
(input_xml_sec = open(output_file,'r')).I have tried to figure out but
not able to debug.Can someone throw some light or anything they feel
could be going wrong somewhere.
Thanks
 
D

Diez B. Roggisch

Hi,
I am parsing an xml file ,before that i have replaced a string in
the original xml file with another and made a new xml file which will
now be parsed.I am also opening some more files for output.The
following code shows some i/o commands.
file_input = raw_input("Enter The ODX File Path:")
input_xml = open(file_input,'r')

(shortname,ext)=os.path.splitext(file_input)
f_open_out=shortname+".ini"
log=shortname+".xls"
test_file=shortname+"testxml.xml"

saveout = sys.stdout

xmlcont=input_xml.read()
input_xml.close()

xmlcont=xmlcont.replace('localId','dataPackageId')

output_file = open(test_file,"w")
output_file.write(xmlcont)
output_file.close()

f_open=open(f_open_out, 'w')
logfile=open(log,"w")
sys.stdout = f_open

After this i have to parse the new xml file which is in
output_file .hence

input_xml_sec = open(output_file,'r')
xmldoc = minidom.parse(input_xml_sec)

But i am getting an error on this line
(input_xml_sec = open(output_file,'r')).I have tried to figure out but
not able to debug.Can someone throw some light or anything they feel
could be going wrong somewhere.

How about telling us what the error is?

Suggested read:

http://www.catb.org/~esr/faqs/smart-questions.html

Diez
Diez
 
P

Peter Otten

output_file = open(test_file,"w") ...
input_xml_sec = open(output_file,'r')

Can you spot the problem now? To prevent it, use a naming convention that
allows you to distinguish between file /names/ and file /objects/.
But i am getting an error on this line
(input_xml_sec = open(output_file,'r')).I have tried to figure out but
not able to debug.Can someone throw some light or anything they feel
could be going wrong somewhere.

In the future, to make it as easy as possible to help you, please post the
actual traceback which contains valuable hints about the error you
encountered even if you cannot make sense of it.

Peter
 
S

saif.shakeel

Can you spot the problem now? To prevent it, use a naming convention that
allows you to distinguish between file /names/ and file /objects/.


In the future, to make it as easy as possible to help you, please post the
actual traceback which contains valuable hints about the error you
encountered even if you cannot make sense of it.

Peter

Hi,
I am running the exe from command prompt,but i am not able to see
the error as it goes off very quickly.How do i capture the error
(traceback).I tried putting an input prompt after the expected line of
error but wont work.Is there a command to capture the error.
Thanks
 
P

Peter Otten

P

Peter Otten

ok i traced the error for above code.It says something like this:
Traceback (most recent call last):
File "C:\Projects\ODX Import\code_ini\odxparse_mod.py", line 294, in
<module>
input_xml_sec = open(output_file,'r')
TypeError: coercing to Unicode: need string or buffer, file found
Can someone help me in this.
Thanks

I already pointed you to the error in my first post in this thread.
output_file is a file, but open() expects a file name.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

i/o prob revisited 3
Problems in string replacement 0
I/O Error 1
Element tree errors 1
replacing string in xml file--revisited 7
I/O Operations ..... 4
replacing string in xml file 6
Ascii Menu I/O redirection 1

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top