文件系统模拟程序python_如何使用sh实现Python虚拟文件系统

我已经建立了一个模拟操作系统的Python脚本。它有一个命令提示符和一个虚拟文件系统。我使用shelve模块来模拟文件系统,它是多维的,以便支持目录的层次结构。但是,我在执行“cd”命令时遇到问题。我不知道如何进出目录,即使我有一个小的目录集创建时,你第一次启动程序。这是我的代码:import shelve

fs = shelve.open('filesystem.fs')

directory = 'root'

raw_dir = None

est_dir = None

def install(fs):

fs['System'] = {}

fs['Users'] = {}

username = raw_input('What do you want your username to be? ')

fs['Users'][username] = {}

try:

test = fs['runbefore']

del test

except:

fs['runbefore'] = None

install(fs)

def ls(args):

print 'Contents of directory', directory + ':'

if raw_dir:

for i in fs[raw_dir[0]][raw_dir[1]][raw_dir[2]][raw_dir[3]]:

print i

else:

for i in fs:

print i

def cd(args):

if len(args.split()) > 1:

if args.split()[1] == '..':

if raw_dir[3]:

raw_dir[3] = 0

elif raw_dir[2]:

raw_dir[2] = 0

elif raw_dir[1]:

raw_dir[1] = 0

else:

print "cd : cannot go above root"

COMMANDS = {'ls' : ls}

while True:

raw = raw_input('> ')

cmd = raw.split()[0]

if cmd in COMMANDS:

COMMANDS[cmd](raw)

#Use break instead of exit, so you will get to this point.

raw_input('Press the Enter key to shutdown...')

我没有得到一个错误,我只是不知道如何去做,也不知道除了“python shelve file system”之外要搜索什么,这没有任何有用的东西。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值