Creating a directory structure and modifying files automatically in Python

MRAB python at mrabarnett.plus.com
Mon Apr 30 12:08:57 EDT 2012


On 30/04/2012 16:19, deltaquattro at gmail.com wrote:
> Hi,
>
> I would like to automate the following task under Linux. I need to create a set of directories such as
>
> 075
> 095
> 100
> 125
>
> The directory names may be read from a text file foobar, which also contains a number corresponding to each dir, like this:
>
> 075 1.818
> 095 2.181
> 100 2.579
> 125 3.019
>
>
> In each directory I must copy a text file input.in. This file contains  two lines which need to be edited:
>
> .
> .
> .
> foo = 1.5 !edit me..
> .
> .
> .
> bar = 1.5 !..and me, too
> .
> .
>
> The number after the "=" must be set to the value given in foobar for the corresponding directory
> I thought to write a bash/awk shell script for this. However, if and when the script works, I'll probably start to add more features in order to automate even more tasks. It seems to me that Python or perl would be better suited to write a larger, mantainable script. Unfortunately, I know neither of them. Could you show me how to write the script in Python? Thanks,
>
If you don't know Python, could I suggest that you start by reading a 
tutorial such as "Dive Into Python", which is at 
http://www.diveintopython.net/



More information about the Python-list mailing list