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


Groups > comp.lang.python > #24607

转发:Re:how can I implement "cd" like shell in Python?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.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.023
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'example:': 0.03; 'subject:Python': 0.05; 'sys': 0.05; 'extent': 0.07; 'python': 0.09; 'to:name:python-list': 0.15; '"python': 0.16; 'shell': 0.18; 'code.': 0.20; 'skip:p 30': 0.20; 'python?': 0.20; 'skip:" 30': 0.20; 'import': 0.21; 'this:': 0.23; 'command': 0.24; 'script': 0.24; 'skip:" 20': 0.26; 'executing': 0.27; 'subject:like': 0.29; 'date:': 0.29; 'url:mailman': 0.29; 'implement': 0.32; 'url:python': 0.32; 'file': 0.32; 'skip:- 10': 0.32; 'could': 0.32; 'url:listinfo': 0.32; 'directory,': 0.33; 'to:addr:python- list': 0.33; 'skip:- 20': 0.34; 'thanks': 0.34; 'path': 0.35; 'subject:?': 0.35; 'add': 0.36; 'subject:': 0.36; 'url:org': 0.36; 'subject:" ': 0.36; 'method': 0.36; 'from:': 0.38; 'mean': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'url:mail': 0.40; 'easy': 0.60; '8bit%:57': 0.71; 'subject::': 0.83; 'message-id:@qq.com': 0.84; 'received:64.71': 0.84; 'received:64.71.138': 0.84; 'received:qq.com': 0.84; 'x-mailer:qqmail 2.x': 0.84
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 webmail569t1340883570t9834718
From "梦幻草" <wustcsvstudio@vip.qq.com>
To "python-list" <python-list@python.org>
Subject 转发:Re:how can I implement "cd" like shell in Python?
Mime-Version 1.0
Content-Type multipart/alternative; boundary="----=_NextPart_4FEC4272_086F2AA0_444C85D9"
Content-Transfer-Encoding 8Bit
Date Thu, 28 Jun 2012 19:39:30 +0800
X-Priority 3
X-QQ-MIME TCMime 1.0 by Tencent
X-Mailer QQMail 2.x
X-QQ-Mailer QQMail 2.x
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.1598.1340883579.4697.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1340883579 news.xs4all.nl 6880 [2001:888:2000:d::a6]:45457
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24607

Show key headers only | View raw


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

thanks !But this method can not change the directory of the main process.For example:
the current directory is "/home/work/local/scripts",this directory have a python script file "cd.py"
after executing the script cd.py by "python cd.py ..",the current work directory has no changes,the path is still "/home/work/local/scripts"
 




------------------ Original ------------------
From: "Sergi Pasoev"; 
Date: 2012年6月28日(星期四) 晚上7:09
To: "python-list"; 
Subject: how can I implement "cd" like shell in Python?



Do you mean to implement the cd command ? To what extent do you want to
implement it ? if what you want is just to have a script to change the
current working directory, it is as easy as this:


import sys
import os
os.chdir(sys.argv[1])

plus you could add some error-handling code.
-- 
http://mail.python.org/mailman/listinfo/python-list

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


Thread

转发:Re:how can I implement "cd" like shell in Python? "梦幻草" <wustcsvstudio@vip.qq.com> - 2012-06-28 19:39 +0800

csiph-web