FAQ
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 do i capture the error as it vanishes very
qucikly when i run through command prompt,(the idle envir gives
indentation errors for no reason(which runs perfectly from cmd
prompt),hence i dont run using conventional F5.

Search Discussions

  • Half Italian at May 18, 2007 at 8:50 am

    On May 18, 12:06 am, saif.shak... at 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 do i capture the error as it vanishes very
    qucikly when i run through command prompt,(the idle envir gives
    indentation errors for no reason(which runs perfectly from cmd
    prompt),hence i dont run using conventional F5.
    http://docs.python.org/tut/

    Read carefully.
  • Saif Shakeel at May 18, 2007 at 8:58 am

    On May 18, 1:50 pm, half.ital... at gmail.com wrote:
    On May 18, 12:06 am, saif.shak... at 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 do i capture the error as it vanishes very
    qucikly when i run through command prompt,(the idle envir gives
    indentation errors for no reason(which runs perfectly from cmd
    prompt),hence i dont run using conventional F5.
    http://docs.python.org/tut/

    Read carefully.- Hide quoted text -

    - Show quoted text -
    ok i am able to trace the error ...It says:
    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
    Any solutions.
    Thanks
  • Tim Roberts at May 22, 2007 at 6:40 am

    saif.shakeel at gmail.com wrote:
    ok i am able to trace the error ...It says:
    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
    Any solutions.
    I don't see how the error could possibly make it any clearer. "open"
    expects a file name. "output_file" is not a file NAME. It is a file
    OBJECT. If you want to reopen that file, then pass the file NAME here.
    --
    Tim Roberts, timr at probo.com
    Providenza & Boekelheide, Inc.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 18, '07 at 7:06a
activeMay 22, '07 at 6:40a
posts4
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase