Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #24603 > unrolled thread
| Started by | Sergi Pasoev <s.pasoev@gmail.com> |
|---|---|
| First post | 2012-06-28 15:09 +0400 |
| Last post | 2012-06-28 19:13 +0200 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
how can I implement "cd" like shell in Python? Sergi Pasoev <s.pasoev@gmail.com> - 2012-06-28 15:09 +0400
Re: how can I implement "cd" like shell in Python? Hans Mulder <hansmu@xs4all.nl> - 2012-06-28 13:33 +0200
Re: how can I implement "cd" like shell in Python? Christian Heimes <lists@cheimes.de> - 2012-06-28 13:35 +0200
Re: how can I implement "cd" like shell in Python? Laurent Pointal <laurent.pointal@free.fr> - 2012-06-28 19:13 +0200
| From | Sergi Pasoev <s.pasoev@gmail.com> |
|---|---|
| Date | 2012-06-28 15:09 +0400 |
| Subject | how can I implement "cd" like shell in Python? |
| Message-ID | <87pq8jsnfp.fsf@gmail.com> |
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.
[toc] | [next] | [standalone]
| From | Hans Mulder <hansmu@xs4all.nl> |
|---|---|
| Date | 2012-06-28 13:33 +0200 |
| Message-ID | <4fec40f6$0$6961$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #24603 |
On 28/06/12 13:09:14, Sergi Pasoev wrote: > 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. 'cd' is a shell built-in, because otherwise it would have no effect. You can write a Python script that invokes os.chdir(), but that won't have any effect on the shell that starts the script. What are you trying to achieve? -- HansM
[toc] | [prev] | [next] | [standalone]
| From | Christian Heimes <lists@cheimes.de> |
|---|---|
| Date | 2012-06-28 13:35 +0200 |
| Message-ID | <mailman.1597.1340883352.4697.python-list@python.org> |
| In reply to | #24603 |
Am 28.06.2012 13:09, schrieb Sergi Pasoev: > 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: Please note that you can't change the working directory of another process. Your snipplet won't alter the current working directory of the shell. "cd" is a builtin shell command, not a binary. Christian
[toc] | [prev] | [next] | [standalone]
| From | Laurent Pointal <laurent.pointal@free.fr> |
|---|---|
| Date | 2012-06-28 19:13 +0200 |
| Message-ID | <4fec90b1$0$6573$426a34cc@news.free.fr> |
| In reply to | #24603 |
Sergi Pasoev wrote: > 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. To have a shell / python script interaction for cwd management, you can take a look at autojump https://github.com/joelthelion/autojump/wiki Its a Python script + different shells glue. A+ Laurent. -- Laurent POINTAL - laurent.pointal@laposte.net
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web