Python:Files
Revision as of 10: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...")
- 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>