Files
jlengrand.github.io/_posts/2012-06-17-my-very-first-python-script-docfinder.markdown
Julien Lengrand-Lambert e11060535f Replacing all links with HTTPS
2018-03-17 11:04:40 +01:00

2.5 KiB

layout, status, published, title, author, author_login, author_email, author_url, wordpress_id, wordpress_url, date, categories, tags, comments
layout status published title author author_login author_email author_url wordpress_id wordpress_url date categories tags comments
post publish true My very first Python script : DocFinder Julien Lengrand-Lambert jlengrand julien@lengrand.fr https://www.lengrand.fr 652 https://www.lengrand.fr/?p=652 2012-06-17 11:32:37.000000000 +02:00
misc
programming
Python
bash
programmer
first code
code
docfinder
opensource

As you may already have noticed, I am quite found of Python as a programming language.

I fell in love with Python some years ago, but you should know more about this soon :).

As many of Python users, I started with Dive into Python .

Some days ago, I found myself into the very first Python script I ever written (but still use some times :)). I found it funny (even more when you think that It can be reduced to a one-liner), and thought I would share it.

It aims at listing all documents from a given extension in a folder. To use it, simply run

{% highlight bash %}

$ docfinder folder extension

{% endhighlight %}

So here is the code :

{% highlight python %} #!/usr/bin/python #* coding: ISO-8859-15 * import os import sys

def scan_rep(repertoir, extension): """scanne le rep courant pour trouver des tex""" for racine, reps, fichiers in os.walk(repertoir, topdown=True): for fichier in fichiers: if fichier.endswith('.%s' % extension): nom_complet=os.path.join(racine, fichier) print '%s '%(nom_complet) if name=='main': scan_rep(sys.argv[1],sys.argv[2]) {% endhighlight %}

Pretty lame, isn't it ? :)

When you find yourself a bad programmer, it is always good to look at the past and see that you actually made some progress :).

You might want to check my current pet project, it is also all Python :)

Julien

P.S : If you are searching for a list of python resources, WhoIsHostingMe kindly requested me to offer their link as well.