Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #86179

Re: calling subprocess

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'string': 0.09; 'converted': 0.09; 'escape': 0.09; 'newline': 0.09; 'strings.': 0.09; 'variable,': 0.09; 'changes': 0.15; '\\n,': 0.16; 'explicitly,': 0.16; 'hint': 0.16; 'jumping': 0.16; 'literals': 0.16; 'repr()': 0.16; 'str()': 0.16; 'tabs': 0.16; 'variables,': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'trying': 0.19; 'print': 0.22; 'header:User-Agent:1': 0.23; 'directory.': 0.24; "shouldn't": 0.24; 'string,': 0.24; '(or': 0.24; 'environment': 0.24; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'converting': 0.30; 'relative': 0.30; 'returned': 0.30; "i'm": 0.30; 'getting': 0.31; 'about.': 0.31; 'quotes': 0.31; 'probably': 0.32; 'sense': 0.34; 'problem': 0.35; 'something': 0.35; '(2)': 0.35; 'one,': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'really': 0.36; 'much.': 0.36; 'doing': 0.36; "didn't": 0.36; 'should': 0.36; 'positive': 0.37; 'wrong': 0.37; 'list': 0.37; 'solving': 0.38; 'handle': 0.38; 'to:addr:python- list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'matter': 0.61; "you're": 0.61; 'back': 0.62; "you'll": 0.62; 'email addr:gmail.com': 0.63; 'show': 0.63; 'charset:windows-1252': 0.65; 'effectively': 0.66; 'between': 0.67; 'received:74.208': 0.68; 'useful.': 0.68; 'nice,': 0.84; 'relate': 0.84; 'try,': 0.84
Date Sun, 22 Feb 2015 21:38:23 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: calling subprocess
References <edfc56d5-8696-49d0-8b71-69044bbab1f5@googlegroups.com> <mailman.19035.1424643724.18130.python-list@python.org> <4e828264-5445-42fc-a647-c56f80fc86ab@googlegroups.com>
In-Reply-To <4e828264-5445-42fc-a647-c56f80fc86ab@googlegroups.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:mVondldxb7maCE4Qy8vVx2lpO6YhQrCb+ltT32zmbrW vf5a2Rl9dO+ptFhkSzpT7sDrPLqVAvSUn54FtjH0NpkAVgTuFB kRbp0oHh1iJF2KrSPgqTlsH3wm8el1mxNRVfFWFsIEuLCxbIEN TuUrLpeLC3rNyUjNgOoIJgeLoMKegq7QzLuzFN2LuYiTyzDd4a VfkjJWbIr2Lilqy287FcRYZIwPI+pDOVNJ176s83MpwhODA9io vIWr4A6vcTJVsm/xvt3g0VSgbn/lfKHz4Wfk1PpwdrCUqOEPyj W4Mu3LIhq8JIOtqv67ThnV67A1Gg84ZUJM00QfC4lnndmGwhA= =
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.19042.1424659124.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1424659124 news.xs4all.nl 2874 [2001:888:2000:d::a6]:34080
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:86179

Show key headers only | View raw


On 02/22/2015 08:13 PM, jkuplinsky@gmail.com wrote:
>
> OK (1) sorry about for/from

That's not what you should be sorry about.  You should be sorry you 
didn't use cut&paste.

> (2) print() sounds nice, but fact is , no matter what I try, i always get C:\\apps instead of c:\apps. So in this sense print() doesn't help much. Obviously i'm doing something wrong -- which is what you perhaps call shotgun debugging; but that's why i'm asking.
>

You probably are getting confused about the difference between str() and 
repr().  If you print the repr() of a string, it'll add quotes around 
it, and escape the unprintable codes.  So it'll double the backslash. 
It also turns a newline into  \n, and tabs into \t, and so on.  Very useful.

That's also what happens when you print a list that contains strings. 
The individual elements of the list are converted using repr().  Watch 
for the quotes to get a strong hint about what you're seeing.

If you don't get a positive handle on how string literals relate to 
string variables, and on str() and repr(), and print(), you'll be 
jumping around the problem instead of solving it.



Back to your original problem, which had you trying to use 
subprocess.call to change the current directory.  Current directory is 
effectively (or actually) depending on the OS involved) an environment 
variable, and changes made in a child process are not magically returned 
to the parent.

But even though there is an os.chdir() in Python, you really shouldn't 
use it.  Long experience of many people show that you're better off 
manipulating the directories you need explicitly, converting any 
directory that's relative to something other than the current one, to an 
absolute.

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

calling subprocess jkuplinsky@gmail.com - 2015-02-22 14:06 -0800
  Re: calling subprocess Tim Golden <mail@timgolden.me.uk> - 2015-02-22 22:14 +0000
  Re: calling subprocess Chris Angelico <rosuav@gmail.com> - 2015-02-23 09:21 +1100
    Re: calling subprocess jkuplinsky@gmail.com - 2015-02-22 17:13 -0800
      Re: calling subprocess Chris Angelico <rosuav@gmail.com> - 2015-02-23 12:31 +1100
      Re: calling subprocess Dave Angel <davea@davea.name> - 2015-02-22 21:38 -0500
      Re: calling subprocess Dave Angel <davea@davea.name> - 2015-02-22 22:07 -0500

csiph-web