os.system and quoted strings

svata svatoboj at gmail.com
Tue Feb 27 10:18:46 EST 2007


On Feb 27, 2:36 pm, "Sriram" <sriram.sundarara... at gmail.com> wrote:
> Hello svata,
> It is always better to compose your string before you send it as a
> command.
>
> try printing your command string out like this :
> print 'gvim dir+fileName+".txt". You'll see what the problem is.
>
> One possible solution is to compose your command string in the
> following manner:
> cmd = "gvim %s%s.txt" %(dir, fileName)
> and simply call os.system with cmd.
> os.system(cmd)
>
> Here is a little more detail on string format specifiershttp://docs.python.org/lib/typesseq-strings.html
>
> HTH
> Sriram
>
> On Feb 27, 7:24 am, "svata" <svato... at gmail.com> wrote:
>
> > Hello,
>
> > as I'm new to python I've stumbled accros os.system and its not very
> > well documented usage.
>
> > I use Win XP Pro and Python 2.5.
>
> > Here is the code snippet:
>
> > --------------------------------------------------------------------------------------------------
>
> > import time
> > import os
>
> > dir = "C:\\Documents and Settings\\somepath\\"
> > fileName = time.strftime("%d%m%Y")
> > os.system('gvim dir+fileName+".txt"')
>
> > ---------------------------------------------------------------------------------------------------
>
> > The problem is that concatenated variable dir+fileName doesn't get
> > expanded as expected.
>
> > Is there anything I omitted?
>
> > svata

Thank you for prompt reply. I should be more concise with strings, I
think :)

svata




More information about the Python-list mailing list