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


Groups > comp.lang.python > #86185

Re: calling subprocess

Date 2015-02-22 22:07 -0500
From Dave Angel <davea@davea.name>
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> <54EA929F.70509@davea.name>
Newsgroups comp.lang.python
Message-ID <mailman.19047.1424660848.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 02/22/2015 09:38 PM, Dave Angel wrote:
> 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.
>
Two other things I should have pointed out here.  The debugger uses 
repr() to display things, when you have an unassigned expression.

And you can solve a lot of problems by just using a forward slash for a 
directory separator.  The forward slash is just as correct in most 
circumstances within a program.  It's mainly on the command line that 
forward slash takes on a different meaning.

>
>
> 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 | 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