Python:Files

From wiki
Revision as of 11:35, 4 January 2018 by Hdridder (talk | contribs) (Created page with "Category:Python ;glob.glob(filespec) :Return a list of files matching 'filespec'. Code example: <syntaxhighlight lang=python> import glob files = glob.glob(filespec) </sy...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


glob.glob(filespec)
Return a list of files matching 'filespec'.

Code example:

import glob
files = glob.glob(filespec)
open (filename,"r")
open filname for read and return the filehandle. Use w for write.

Code example:

import os
if os.path.isfile(filename):
    f1 =  open (filename,"r")
with open (filename,"r") as file
Open filename for read and close at the end of the loop

Code example:

with open (filename,"r") as file:
    for line in file:
        <codeblock>