By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,095 Members | 1,586 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,095 IT Pros & Developers. It's quick & easy.

Unusual i/o problems

P: n/a
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

May 16 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
sa**********@gmail.com wrote:
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
May 16 '07 #2

P: n/a
sa**********@gmail.com wrote:
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
May 16 '07 #3

P: n/a
On May 16, 7:55 pm, Peter Otten <__pete...@web.dewrote:
saif.shak...@gmail.com wrote:
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
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

May 18 '07 #4

P: n/a
sa**********@gmail.com wrote:
I am running the exe from command prompt,but i am not able to see
the error as it goes off very quickly.
http://effbot.org/pyfaq/how-do-i-run...er-windows.htm
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.
You can redirect stderr to a file:

http://www.microsoft.com/resources/d...direction.mspx

Peter

May 18 '07 #5

P: n/a
On May 18, 1:01 pm, Peter Otten <__pete...@web.dewrote:
saif.shak...@gmail.com wrote:
I am running the exe from command prompt,but i am not able to see
the error as it goes off very quickly.

http://effbot.org/pyfaq/how-do-i-run...er-windows.htm
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.

You can redirect stderr to a file:

http://www.microsoft.com/resources/d...s/xp/all/prodd...

Peter
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

May 18 '07 #6

P: n/a
sa**********@gmail.com wrote:
On May 18, 1:01 pm, Peter Otten <__pete...@web.dewrote:
>saif.shak...@gmail.com wrote:
I am running the exe from command prompt,but i am not able to see
the error as it goes off very quickly.

http://effbot.org/pyfaq/how-do-i-run...er-windows.htm
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.

You can redirect stderr to a file:

http://www.microsoft.com/resources/d...s/xp/all/prodd...

Peter

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
May 18 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.