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


Groups > comp.lang.python > #24609

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

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <wustcsvstudio@vip.qq.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.042
X-Spam-Evidence '*H*': 0.92; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.05; 'python': 0.09; 'os.path': 0.09; 'unexpected': 0.09; 'cc:addr:python-list': 0.10; 'ends,': 0.16; 'wrote:': 0.17; 'shell': 0.18; 'python?': 0.20; 'skip:" 40': 0.20; 'import': 0.21; 'cc:2**0': 0.23; '&gt;': 0.23; 'somebody': 0.23; 'linux': 0.24; 'command': 0.24; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'am,': 0.27; 'question': 0.27; 'convention': 0.27; 'in.': 0.27; 'environment': 0.29; 'subject:like': 0.29; 'implement': 0.32; 'skip:- 10': 0.32; 'instead,': 0.33; 'knowledge': 0.33; 'likely': 0.33; 'skip:- 20': 0.34; 'changed': 0.34; 'program,': 0.34; 'path': 0.35; 'subject:?': 0.35; 'continue': 0.35; 'but': 0.36; 'subject:" ': 0.36; 'should': 0.36; 'why': 0.37; 'skip:o 20': 0.38; 'some': 0.38; 'called': 0.39; 'skip:" 10': 0.40; 'your': 0.60; 'is.': 0.62; 'needs,': 0.62; 'more': 0.63; '8bit%:57': 0.71; 'inform': 0.78; '8bit%:24': 0.84; 'message-id:@qq.com': 0.84; 'received:qq.com': 0.84; 'x-mailer:qqmail 2.x': 0.84; 'approach.': 0.91; '8bit%:67': 0.93; 'received:183': 0.93
X-QQ-SSF 0000000000000050000000000000000
X-HAS-ATTACH no
X-QQ-BUSINESS-ORIGIN 2
X-Originating-IP 61.135.5.95
X-QQ-STYLE
X-QQ-mid webmail569t1340886520t6748933
From "Alex chen" <wustcsvstudio@vip.qq.com>
To "d" <d@davea.name>
Subject 回复: how can I implement "cd" like shell in Python?
Mime-Version 1.0
Content-Type multipart/alternative; boundary="----=_NextPart_4FEC4DF8_087D9E20_205603A9"
Content-Transfer-Encoding 8Bit
Date Thu, 28 Jun 2012 20:28:40 +0800
X-Priority 3
X-QQ-MIME TCMime 1.0 by Tencent
X-Mailer QQMail 2.x
X-QQ-Mailer QQMail 2.x
X-QQ-ReplyHash 1636628337
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1600.1340886607.4697.python-list@python.org> (permalink)
Lines 73
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1340886607 news.xs4all.nl 6961 [2001:888:2000:d::a6]:56706
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24609

Show key headers only | View raw


[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

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


Thread

回复: 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

csiph-web