print s obj.close() obj2.open("MyFile.txt", "r") s1 = obj2.read(20) print s1 obj2.close() print obj.name #MyFile.txt print obj.mode #w or r (if obj2) print obj.closed #False # r - read # rb - read binary # r+ - read and write, pointer at beginning # w - write # wb - write binary # w+ - read and write, if file already exists it will overwrite or else create a new file # wb+ - same as above but for binary file # a - append # ab - append binary import os os.remane("existingfile.txt", "newfile.txt") os.remove("oldfile.txt") #Deletes file os.mkdir("new") #Makes new directory os.chdir("new") #Makes changes to current directory print os.getcwd #Gives the current working directory os.rmdir( "new" ) #Removes a directory before removing the directory, the directory should be empty
import os # zet er mp3 achter als het geen extensie heeft for f in os.listdir(): if "." not in f: os.rename(f, f + ".mp3") # haal de spatie weg als die voor de '.mp3' zit for f in os.listdir(): if f[-5:] == " .mp3": os.remane(f, f[:-5] + f[-4:])
def rename(dir, pathAndFilename, pattern, titlePatteren): os.remane(pathAndFilename, os.path.join(dir, titlePatteren)) # methdoe to do the rename