From: svata on 27 Feb 2007 10:18 On Feb 27, 2:36 pm, "Sriram" <sriram.sundarara...(a)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...(a)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
From: Dan Bishop on 27 Feb 2007 20:53 On Feb 27, 9:16 am, Steven D'Aprano <s...(a)REMOVE.THIS.cybersource.com.au> wrote: > On Tue, 27 Feb 2007 06:24:41 -0800, svata wrote: .... > > import time > > import os > > > dir = "C:\\Documents and Settings\\somepath\\" > > I believe that Windows will accept forward slashes as directory > separators, so you can write that as: > > dir = "C:/Documents and Settings/somepath/" Windows system calls treat / and \ interchangeably, but the command prompt insists on backslashes.
From: Duncan Booth on 28 Feb 2007 05:28 "Dan Bishop" <danb_83(a)yahoo.com> wrote: > Windows system calls treat / and \ interchangeably, but the command > prompt insists on backslashes. No. Commands built-in to the command prompt and certain other programs (mostly but not exclusively from Microsoft) insist on backslashes. Most programs, especially those originating from the unixverse, will accept backslashes and forward slashes interchangeably from the command prompt. Even a lot of Microsoft's own programs are happy to accept backslashed command line arguments. If in doubt just call os.path.normpath() on a path string before using it. Also it is usually worth putting command line arguments inside " marks to avoid problems with spaces or other special characters in path names.
From: Sion Arrowsmith on 28 Feb 2007 09:28 Dennis Lee Bieber <wlfraed(a)ix.netcom.com> wrote: >>>> import os.path >>>> os.path.join("c:", >... "Documents and Settings", >... "somepath") >'c:Documents and Settings\\somepath' >>>> > >Hmmm, a quick test with > >dir "e:userdata" > >worked, so the top level \ may not be needed... "drive:" is the 'cwd' on the drive, so "drive:directory" is relative to that. Try "cd e:userdata" and repeat "dir e:userdata" and see what happens. os.path.join() has to behave as above, otherwise you wouldn't be able to use it to construct a relative path like that. (And since I don't think anyone's mentioned it in this thread yet, subprocess.call() instead of os.system().) -- \S -- siona(a)chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the other" \X/ | -- Arthur C. Clarke her nu become� se bera eadward ofdun hl�ddre heafdes b�ce bump bump bump
First
|
Prev
|
Pages: 1 2 Prev: threading and multicores, pros and cons Next: GIS Shape file upload to FTP server |