473,320 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to do regular BASH work in Python?

What is the best way to do the regular bash commands in native python?

- create directory
- create file
- make a symlink
- copy a file to another directory
- move a file
- set permissions

I need to write a program that creates real application/FTP accounts
and make regular backups to external disk and I think its best to do
it all consistently with my application in Python.
This way I can easily link it to the customer database and front-end
web application. I'd want to avoid BASH/SHELL if that's possible.
Oct 9 '08 #1
6 1851
Hey,
I found it. Python rocks:
http://www.python.org/doc/2.5.2/lib/os-file-dir.html

If you have any further links that provide some lively code examples
and recipes, please pass them on.

Thank you

Frank Malina
http://vizualbod.com
Oct 9 '08 #2
jdd
On Oct 9, 10:13*am, Frantisek Malina <fmal...@gmail.comwrote:
Hey,
I found it. Python rocks:http://www.python.org/doc/2.5.2/lib/os-file-dir.html

If you have any further links that provide some lively code examples
and recipes, please pass them on.

Thank you

Frank Malinahttp://vizualbod.com
http://examples.oreilly.com/python3/ has some good examples, although
they may be a little tough to read through if you don't have a copy of
"programming python", the book they're from.
Oct 9 '08 #3
On Oct 9, 3:22*pm, jdd <jeremiah.do...@gmail.comwrote:
On Oct 9, 10:13*am, Frantisek Malina <fmal...@gmail.comwrote:
Hey,
I found it. Python rocks:http://www.python.org/doc/2.5.2/lib/os-file-dir.html
If you have any further links that provide some lively code examples
and recipes, please pass them on.
Thank you
Frank Malinahttp://vizualbod.com

http://examples.oreilly.com/python3/has some good examples, although
they may be a little tough to read through if you don't have a copy of
"programming python", the book they're from.
Coming form PHP, I find Python is pleasure to read no matter what.
Oct 9 '08 #4
You might also be interested in the 'shutil' module:
http://docs.python.org/library/shuti...#module-shutil

Cheers,
Chris
--
Follow the path of the Iguana...
http://rebertia.com

On Thu, Oct 9, 2008 at 7:13 AM, Frantisek Malina <fm*****@gmail.comwrote:
Hey,
I found it. Python rocks:
http://www.python.org/doc/2.5.2/lib/os-file-dir.html

If you have any further links that provide some lively code examples
and recipes, please pass them on.

Thank you

Frank Malina
http://vizualbod.com
--
http://mail.python.org/mailman/listinfo/python-list
Oct 9 '08 #5
Frantisek Malina wrote:
What is the best way to do the regular bash commands in native python?

- create directory
- create file
- make a symlink
- copy a file to another directory
- move a file
- set permissions

I need to write a program that creates real application/FTP accounts
and make regular backups to external disk and I think its best to do
it all consistently with my application in Python.
This way I can easily link it to the customer database and front-end
web application. I'd want to avoid BASH/SHELL if that's possible.
As others have said, the os and shutils modules should fulfill most of
your needs.

But unfortunately Python is definitely not a shell-scripting language
and some things that are easy in bash are really, really hard in python,
such as interacting with and stringing together processes, redirecting
outputs, etc. Whereas in bash it's easy to create pipes between
processes and redirect inputs with '|', '>', '2>', etc, in Python you'd
have to use the subprocess module to spawn a real shell to do much of
that.

In many circumstances, though, the purpose of the piping and redirection
in Bash is to do text processing, which is very easy to do with python
and generators. See http://www.dabeaz.com/generators/ for the real
power that python can bear on the problems traditionally solved with
bash. I find that in most cases in python, a simple wrapper around
subprocess to run a command and get its stdout, stderr and return error
code works pretty well.

Oct 10 '08 #6
In message <ma**************************************@python.o rg>, Michael
Torrie wrote:
But unfortunately Python is definitely not a shell-scripting language
and some things that are easy in bash are really, really hard in
python ...

Why not combine the two
<http://groups.google.co.nz/group/nz.comp/msg/3a572e757bbdd816>.
Oct 11 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Woudenberg | last post by:
I just installed a Python 2.3.4 Windows binary on a friend's WinXP machine (because the latest Cygwin-provided Python 2.3 build leaves out the winsound module for some reason). When I try and...
4
by: Tom Purl | last post by:
I just wrote a Python script that is going to be called from bash script. If the Python script fails, I want the bash script to also stop running. Unfortunately, I can't seem to get that to work. ...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
2
by: mike.ceravolo | last post by:
What is the best way to use regular expressions to extract information from the internet if one wants to search multiple pages? Let's say I want to search all of www.cnn.com and get a list of all...
11
by: Magnus Jonneryd | last post by:
Hi, I'm planning on writing a program that interactively is fed input via a shell (bash). I also want to be able to write a shell script that executes various commands related to my program. In...
16
by: John Salerno | last post by:
Hi all. I just installed Ubuntu and I'm learning how to use the bash shell. Aside from the normal commands you can use, I was wondering if it's possible to use Python from the terminal instead of...
6
by: Ishpeck | last post by:
I'm using Python to automate testing software for my company. I wanted the computers in my testing lab to automatically fetch the latest version of the python scripts from a CVS repository and...
1
by: Fredrik Lundh | last post by:
John Lawrence wrote: doesn't exactly work for Python scripts, though: $ cat env.py #!/usr/bin/env python import os os.environ = "hello"
1
by: James Mills | last post by:
On Wed, Oct 22, 2008 at 10:32 AM, gita ziabari <gitaziabari@gmail.comwrote: The only possibility is to use the subprocess module and this is a more general problem, one involving the invocation...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.