Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you want to <em>run this script on all the sub directories starting from the one that the script is inside</em>, then try doing it this way instead:</p> <pre><code>import os for path, directories, files in os.walk(os.path.dirname(os.path.realpath(__file__))): print path, directories, files txt_files = [arbitrary_file for arbitrary_file in files if arbitrary_file[-4:].lower() == ".txt"] #run your python here txt_files = [txt_file for arbitrary_file in files if arbitrary_file[] </code></pre> <p>If your original code was this:</p> <pre><code>import sys text_files_to_process = #Do Something with sys.argv - or whatever you're using to parse your arguments. with open("res.txt", "w") as f: #do something with all the text files, and write the output to res.txt. for text_file in text_files_to_process: with open(text_file) as tf: for line in tf: #whatever your text processing is tf.write("something") </code></pre> <p>then you just alter it to something like this:</p> <pre><code>import os for path, directories, files in os.walk(os.path.dirname(os.path.realpath(__file__))): print path, directories, files txt_files = [arbitrary_file for arbitrary_file in files if arbitrary_file[-4:].lower() == ".txt"] txt_files = [txt_file for arbitrary_file in files if arbitrary_file[] with open("res.txt", "w") as f: #do something with all the text files, and write the output to res.txt. for text_file in txt_files: with open(text_file) as tf: for line in tf: #whatever your text processing is tf.write("something") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload