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


Groups > comp.lang.python > #24608

Re: 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!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.024
X-Spam-Evidence '*H*': 0.95; '*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; 'import': 0.21; 'cc:2**0': 0.23; 'somebody': 0.23; 'allows': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'am,': 0.27; 'question': 0.27; 'convention': 0.27; 'in.': 0.27; 'environment': 0.29; 'subject:like': 0.29; 'implement': 0.32; 'instead,': 0.33; 'knowledge': 0.33; 'likely': 0.33; '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; 'subject:: ': 0.38; 'skip:o 20': 0.38; 'some': 0.38; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'is.': 0.62; 'needs,': 0.62; 'more': 0.63; 'header:Reply-To:1': 0.68; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'inform': 0.78; 'received:74.208.4.194': 0.84; 'approach.': 0.91
Date Thu, 28 Jun 2012 08:12:02 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1
MIME-Version 1.0
To 梦幻草 <wustcsvstudio@vip.qq.com>
Subject Re: how can I implement "cd" like shell in Python?
References <tencent_4E10DB29574DE33906193DDE@qq.com>
In-Reply-To <tencent_4E10DB29574DE33906193DDE@qq.com>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Provags-ID V02:K0:sBkViOxYzL//zo7Kah7PIyNQa7TApmEpzagd0oz/LLC cXOy7h6zaeYFv//+eQkQ/XjXOGQHeNmzIPGCZdNFORTDJKaCX0 Kq3euF0rVLWFtz+jCCk7/lCRP1Dd6BG26v0Db2Sn9e37NHTURO kkMZw+QcMrQiFw3wutI66haP7/JO/3P2psK9lwDAAo9DW9DRPe O6NUAMFOG/jumrRUSwrHmeU/fmImlmbJlgs0GdXvwKT1wxwLP5 TiTlrhK/zBuRHdMhsOCQiEsd3Ank8/lIcI4Hpvno726xrW1Iua RLk7px2ntc/W6uVIhsAELk70TfPDfR54ISsYpexQx7DGGgU7Q= =
Cc python-list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
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.1599.1340885548.4697.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1340885548 news.xs4all.nl 6928 [2001:888:2000:d::a6]:51714
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:24608

Show key headers only | View raw


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 | Next | Find similar | Unroll thread


Thread

Re: how can I implement "cd" like shell in Python? Dave Angel <d@davea.name> - 2012-06-28 08:12 -0400

csiph-web