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


Groups > comp.lang.python > #24609 > unrolled thread

回复: how can I implement "cd" like shell in Python?

Started by"Alex chen" <wustcsvstudio@vip.qq.com>
First post2012-06-28 20:28 +0800
Last post2012-06-28 15:54 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  回复: how can I implement "cd" like shell in Python? "Alex chen" <wustcsvstudio@vip.qq.com> - 2012-06-28 20:28 +0800
    Re: 回复: how can I implement "cd" like shell in Python? Alister <alister.ware@ntlworld.com> - 2012-06-28 15:54 +0000

#24609 — 回复: how can I implement "cd" like shell in Python?

From"Alex chen" <wustcsvstudio@vip.qq.com>
Date2012-06-28 20:28 +0800
Subject回复: how can I implement "cd" like shell in Python?
Message-ID<mailman.1600.1340886607.4697.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

I just want to write a python program,it can be called in the linux terminal like the command "cd" to change the directory of the shell terminal 




------------------ 原始邮件 ------------------
发件人: "Dave Angel"<d@davea.name>;
发送时间: 2012年6月28日(星期四) 晚上8:12
收件人: "Alex Chen"<wustcsvstudio@vip.qq.com>; 
抄送: "python-list"<python-list@python.org>; 
主题: Re: how can I implement "cd" like shell in Python?



On 06/28/2012 05:30 AM, 梦幻草 wrote:
> how can I implement "cd" like shell in Python?
>

import os
os.chdir("newdirectory")


But the more important question is why you want to.  Inside a Python
program, many people find that changing directory causes unexpected
difficulties, and they simply keep track of a full path instead, using
various os.path functions to manage it.

And once the python program ends, the shell should have no knowledge of
what you changed it to.

Now, a particular shell program might have some convention that allows a
program to inform it what directory to continue in.  But that's a
question about that shell, not about Python.  And you never said what
your environment is.


So give some more specifics to your needs, and somebody is likely to
know an approach.



-- 

DaveA

[toc] | [next] | [standalone]


#24619

FromAlister <alister.ware@ntlworld.com>
Date2012-06-28 15:54 +0000
Message-ID<w6%Gr.460892$PV.115941@fx09.am4>
In reply to#24609
On Thu, 28 Jun 2012 20:28:40 +0800, Alex chen wrote:

> I just want to write a python program,it can be called in the linux
> terminal like the command "cd" to change the directory of the shell
> terminal
> 
> 
> 
That would not only be needlesly re-inventing the wheel but making it 
square in the process.

what is wrong with just calling cd if you are in the terminal.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web