Python - open text file, but specify name when executing command

Posted by Dunnolol on Stack Overflow See other posts from Stack Overflow or by Dunnolol
Published on 2011-02-16T07:12:29Z Indexed on 2011/02/16 7:25 UTC
Read the original article Hit count: 157

Filed under:
|
|
|
|

I have a directory of text files that all end in the extension .txt My goal is to print the contents of the text file. I wish to be able use the wildcard *.txt to be able to specific the text file name I wish to open (I'm thinking along the lines of something like "F:\text*.txt" ?), split the lines of the text file, then print the output.

Here is an example of what I want to do, but I want to be able to change "somefile" when executing my command.

f = open('F:\text\somefile.txt', 'r')
    for line in f:
    print line,

© Stack Overflow or respective owner

Related posts about python

Related posts about scripting