Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > I/O Operations .....

Reply
Thread Tools

I/O Operations .....

 
 
saif.shakeel@gmail.com
Guest
Posts: n/a
 
      04-30-2007
Hi,
I am parsing an XML file and sending the output to two files.The
code asks the user to enter the input file,something like:

file_input = raw_input("Enter The ODX File Path:")
input_xml = open(file_input,'r')

Now suppose the user enters the path as :
C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.odx.xml

I have 2 output files to which i have to redirect the output.The
output file name should be same as input file in the same path ( the
extension has to change to a format "ini" which is basically text file
opened using notepad).Eg..
output files should be :
C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.ini, and,
C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.xls

Can someone help me in this.
cheers

 
Reply With Quote
 
 
 
 
Daniel Nogradi
Guest
Posts: n/a
 
      04-30-2007
> I am parsing an XML file and sending the output to two files.The
> code asks the user to enter the input file,something like:
>
> file_input = raw_input("Enter The ODX File Path:")
> input_xml = open(file_input,'r')
>
> Now suppose the user enters the path as :
> C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.odx.xml
>
> I have 2 output files to which i have to redirect the output.The
> output file name should be same as input file in the same path ( the
> extension has to change to a format "ini" which is basically text file
> opened using notepad).Eg..
> output files should be :
> C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.ini, and,
> C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.xls


If you only would like to know how to write files, this might help:

content1 = ..............
content2 = ...............

f = open( 'file1', 'w' )
f.write( content1 )
f.close( )

f = open( 'file2', 'w' )
f.write( content2 )
f.close( )


HTH,
Daniel
 
Reply With Quote
 
 
 
 
saif.shakeel@gmail.com
Guest
Posts: n/a
 
      04-30-2007
On Apr 30, 2:13 pm, "Daniel Nogradi" <(E-Mail Removed)> wrote:
> > I am parsing an XML file and sending the output to two files.The
> > code asks the user to enter the input file,something like:

>
> > file_input = raw_input("Enter The ODX File Path:")
> > input_xml = open(file_input,'r')

>
> > Now suppose the user enters the path as :
> > C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.odx.xml

>
> > I have 2 output files to which i have to redirect the output.The
> > output file name should be same as input file in the same path ( the
> > extension has to change to a format "ini" which is basically text file
> > opened using notepad).Eg..
> > output files should be :
> > C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.ini, and,
> > C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.xls

>
> If you only would like to know how to write files, this might help:
>
> content1 = ..............
> content2 = ...............
>
> f = open( 'file1', 'w' )
> f.write( content1 )
> f.close( )
>
> f = open( 'file2', 'w' )
> f.write( content2 )
> f.close( )
>
> HTH,
> Daniel- Hide quoted text -
>
> - Show quoted text -


Hi,
File writing can be done in that way,but my query is
something different.I have to rename the output file by default with
input file name(only changing the extension.
Thanks

 
Reply With Quote
 
Marc 'BlackJack' Rintsch
Guest
Posts: n/a
 
      04-30-2007
In <(E-Mail Removed) .com>, saif.shakeel
wrote:

> File writing can be done in that way,but my query is
> something different.I have to rename the output file by default with
> input file name(only changing the extension.


Take a look at the functions in `os.path`.

Ciao,
Marc 'BlackJack' Rintsch
 
Reply With Quote
 
Daniel Nogradi
Guest
Posts: n/a
 
      04-30-2007
> > > I am parsing an XML file and sending the output to two files.The
> > > code asks the user to enter the input file,something like:

> >
> > > file_input = raw_input("Enter The ODX File Path:")
> > > input_xml = open(file_input,'r')

> >
> > > Now suppose the user enters the path as :
> > > C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.odx.xml

> >
> > > I have 2 output files to which i have to redirect the output.The
> > > output file name should be same as input file in the same path ( the
> > > extension has to change to a format "ini" which is basically text file
> > > opened using notepad).Eg..
> > > output files should be :
> > > C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.ini, and,
> > > C:\Projects\ODX Import\Sample Files\Global _A_UHP_Low_0.7.xls

> >
> > If you only would like to know how to write files, this might help:
> >
> > content1 = ..............
> > content2 = ...............
> >
> > f = open( 'file1', 'w' )
> > f.write( content1 )
> > f.close( )
> >
> > f = open( 'file2', 'w' )
> > f.write( content2 )
> > f.close( )
> >
> > HTH,
> > Daniel- Hide quoted text -
> >
> > - Show quoted text -

>
> Hi,
> File writing can be done in that way,but my query is
> something different.I have to rename the output file by default with
> input file name(only changing the extension.



Maybe something like this will help (on Linux, Windows is similar):

>>> from os import path
>>> f = '/tmp/hello.xls'
>>> path.splitext( f )

('/tmp/hello', '.xls')
>>> path.dirname( f )

'/tmp'
>>> path.basename( f )

'hello.xls'


Daniel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stand-alone JMS, other JDBC operations, and transactions ( ActiveMQ + JOTM + JDBC operations ) Jesus M. Salvo Jr. Java 2 02-11-2006 06:33 PM
Pipelining Fixed_pkg operations (VHDL 200x-FT) Divyang M VHDL 3 02-04-2005 03:06 AM
Binary File Operations Jeremy Robbins Perl 0 07-14-2004 09:45 PM
Mathematical Operations in VHDL MtnSurf8 VHDL 1 04-25-2004 06:07 AM
array operations Liang Perl 2 01-05-2004 04:42 AM



Advertisments