reading and writing files note that '**/pywould indicate the current directory and any sub directory for examplethe following code will return all files where the file name ends with txtfor given pathprint('- for file in path glob('txt')print('file:'fileprint('- an example of the output generated by this code isfilemy-new-file txt filemyfile txt filetextfile txt filetextfile txt paths that reference file can also be used to read and write data to that file for example the open(method can be used to open file that by default allows file to be readopen(mode=' 'this can be used to open the file referenced by the path object this is used below to read the contents of file line at time (note that with as statement is used here to ensure that the file represented by the path is closed) path('mytext txt'with open(as fprint( readline()howeverthere are also some high-level methods available that allow you to easily write data to file or read data from file these include the path methods write_text and read_text methodswrite_text(dataopens the file pointed to in text mode and writes the data to it and then closes the file read_text(opens the file in read modereads the text and closes the fileit then returns the contents of the file as string