You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# %% [python]importosprint(os.path.dirname(os.path.realpath('__file__')))
f=open("demofile.txt", "a")
f.write("File content 🍕!")
f.close()
#open and read the file after the appending:f=open("demofile.txt", "r")
print(f.read()) # Should print out "File content 🍕!"os.mkdir("cat")
f=open("./cat/demofile2.txt", "a")
f.write("Also a file")
f.close()
f=open("cat/demofile2.txt", "r")
print(f.read()) # Should print out "Also a file"# %% [python]f=open("cat/demofile4.txt", "r") # Should cause an errorprint(f.read())
# %% [python]importos# Should print all files and directoriesforcurrentpath, folders, filesinos.walk('/mnt'):
forfolderinfolders:
print(os.path.join(currentpath, folder))
forfileinfiles:
print(os.path.join(currentpath, file))
# %% [python]importglob# Should print all files and directories in /mnt/sharedforfilenameinglob.iglob('**/**', recursive=True):
print(filename)
# %% [python]importosprint(os.listdir(path='.')) # Should show ['demofile.txt', 'cat'] os.rename('demofile.txt', 'catapprovedfile.txt')
print(os.listdir(path='.')) # Should show ['cat', 'catapprovedfile.txt'] os.rename('catapprovedfile.txt', './cat/myfile.txt')
print(os.listdir(path='cat')) # Should show ['demofile2.txt', 'myfile.txt']
The text was updated successfully, but these errors were encountered:
Ideally we'd also have some test cases for the filesystem code.
For reference, here is mine
The text was updated successfully, but these errors were encountered: