I need help with coding in python!
class CommandLine:
def __init__(self):
s...
![subject](/tpl/images/cats/informatica.png)
Computers and Technology, 15.12.2020 06:50 nati5720
I need help with coding in python!
class CommandLine:
def __init__(self):
self. root = Directory('', None)
self. current_path = self. root
def run(self):
command = input('>>> ')
while command. strip().lower() != 'exit':
split_command = command. split()
if len(split_command):
if split_command[0] == 'ls':
self. current_path. display()
if len(split_command) >= 2:
if split_command[0] == 'cd':
self. change_directory(split_command[1])< br />
elif split_command[0] == 'makedir':
self. current_path. create_directory(split_command[1])< br />
elif split_command[0] == 'fcreate':
self. current_path. create_file(split_command[1])
elif split_command[0] == 'fwrite':
self. current_path. file_write(split_command[1])
elif split_command[0] == 'fread':
self. current_path. file_read(split_command[1])
elif split_command[0] == 'fclose':
self. current_path. close_file(split_command[1])
elif split_command[0] == 'fopen':
self. current_path. open_file(split_command[1])
command = input('>>> ')
def change_directory(self, dir_name):
pass
class Directory:
def __init__(self, name, parent):
pass
def display(self):
pass
def create_file(self, file_name):
pass
def create_directory(self, dir_name):
pass
def file_write(self, file_name):
pass
def file_read(self, file_name):
pass
def close_file(self, file_name):
pass
def open_file(self, file_name):
pass
class File:
pass
if __name__ == '__main__':
cmd_line = CommandLine()
cmd_line. run()
You must keep track of your current directory, and then you must be able to execute the commands listed below.
(The commands are explicitly different from linux so that you don't accidentally execute them in the shell, except for ls and cd which are harmless.)
Command
ls
Lists contents of the directory
cd [dirname]
Change directory up or down one level.
makedir [dirname]
Make a directory
fcreate [filename]
Creates a file, sets it closed.
fwrite [filename]
Write to a file, only if it's open.
fread [filename]
Read a file, even if it's closed.
fclose [filename]
Close a file. Prevents write.
fopen [filename]
Open a file. Reset the contents
![ansver](/tpl/images/cats/User.png)
Answers: 3
![](/tpl/images/ask_question.png)
![](/tpl/images/ask_question_mob.png)
Other questions on the subject: Computers and Technology
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 22.06.2019 13:30, morganwendel126
Use the keyword strategy to remember the meaning of the following word. the meaning for the word has been provided. write your keyword and describe the picture you would create in your mind. centurion: a commander in the army of ancient rome. keyword: picture:
Answers: 2
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 07:30, barkonatree
What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
Answers: 1
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 23.06.2019 13:30, alannaamarriee
Jace needs to answer a question on square roots to win a quiz. how can he use a spreadsheet to find the square root of 786? a. use the functions round and count b. create a table and chart c. use the function sqrt d. use the function now
Answers: 3
![image](/tpl/images/cats/informatica.png)
Computers and Technology, 24.06.2019 02:40, homework1911
Has anyone seen my grandma shes been gone for 4 years already
Answers: 1
You know the right answer?
Questions in other subjects:
![Konu](/tpl/images/cats/fizika.png)
![Konu](/tpl/images/cats/ekonomika.png)
![Konu](/tpl/images/cats/mat.png)
Mathematics, 12.07.2019 21:00
![Konu](/tpl/images/cats/istoriya.png)
![Konu](/tpl/images/cats/istoriya.png)
History, 12.07.2019 21:00
![Konu](/tpl/images/cats/istoriya.png)
![Konu](/tpl/images/cats/mat.png)
Mathematics, 12.07.2019 21:00
![Konu](/tpl/images/cats/istoriya.png)
History, 12.07.2019 21:00
![Konu](/tpl/images/cats/istoriya.png)
History, 12.07.2019 21:00