Difference between revisions of "Python:Files"

From wiki
Jump to navigation Jump to search
(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...")
(No difference)

Revision as of 11:35, 4 January 2018


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>