Create directories and modify files with Python

deltaquattro at gmail.com deltaquattro at gmail.com
Tue May 1 06:51:57 EDT 2012


Il giorno martedì 1 maggio 2012 01:57:12 UTC+2, Irmen de Jong ha scritto:
> > Hi, 0 I would like to automate some simple tasks I'm doing by hand. Given a text file
> >  foobar.fo:
> 
> [...]
> 
> > At first, I tried to write a bash script to do this. However, when and if the script
> > will work, I'll probably want to add more features to automate some other tasks. So I
> > thought about using some other language, to have a more flexible and mantainable
> > code. I've been told that both Python and perl are well suited for such tasks, but
> > unfortunately I know neither of them. Can you show me how to write the script in
> > Python? Thanks,
> 
> Err.. if you don't know Python, why do you think a Python script will be more flexible
> and maintainable for you?
> 

Eheh :) good question. The point is that, when in the past I chose to use only languages that I know, I always ended up with one of these two solutions:

1) write a "simple" shell script, which three years from now will make me curse in Sumeric because I can't make heads or tails of it. Been there, done that.

2) with time, the shell script may become larger and require some mathematics. For example, the second column of foobar.fo consists of mass flows, which today I get from another code, but that I could compute in the script. At this point, I go for a Fortran/C code, which takes me longer to write.

Now I'd like to try another road. The problem is that each time I stumble upon a good chance to learn Python, I never have enough time to learn the language from zero, and I end up with one of two solutions above. If you can provide me with a working solution or at least some code to start with, I should be able to solve my immediate problem, and then have time to learn some more (that's how I learned shell scripting). The (possibly wrong) underlying assumption is that the problem is simple enough for one of you Python experts to solve easily, without wasting too much of his/her time. Anyway, I'm willing to pay a reasonable fee for help, provided you have Paypal.

> But if you really want to go this way (and hey, why not) then first you'll have to learn
> some basic Python. A good resource for this might be: http://learnpythonthehardway.org/

Ehm...name's not exactly inspiring for a newbie who's short on time :)

> 
> Focus on file input and output, string manipulation, and look in the os module for stuff
> to help scanning directories (such as os.walk).
> 
> Irmen

Thanks for the directions. By the way, can you see my post in Google Groups? I'm not able to, and I don't know why. 

Sergio



More information about the Python-list mailing list