Redian新闻
>
[合集] Re: 大龄女性生育困难还真不是耸人听闻
avatar
[合集] Re: 大龄女性生育困难还真不是耸人听闻# Piebridge - 鹊桥
f*t
1
(Coding) Write a basic file system and implement the commands ls, pwd, mkdir
, create, rm, cd, cat, mv. This was done on my own computer, in the
interview room, with a 1.5 hour time limit.
1.5小时,大牛提示下咋写?谢谢
avatar
c*o
2
☆─────────────────────────────────────☆
piaobotuzi (漂泊的兔子) 于 (Wed Aug 11 23:02:52 2010, 美东) 提到:
IED,我还没有那么大,你就接受我吧,我真的不是恐龙,真的,相貌真的是中等偏上

☆─────────────────────────────────────☆
IED (TNT) 于 (Wed Aug 11 23:10:45 2010, 美东) 提到:
你老跟着我干嘛?我和你不熟。 再说我早就不available了
女人长得怎样挺重要, 但更重要得是为人和性格。
☆─────────────────────────────────────☆
piaobotuzi (漂泊的兔子) 于 (Wed Aug 11 23:16:14 2010, 美东) 提到:
好吧,我这次是彻底的死心了。
☆─────────────────────────────────────☆
YCTIme (笨笨) 于 (Wed Aug 11 23:17:58 2010, 美东) 提到:
avatar
w*a
3
file system一般都是用tree,每个node就是一个folder,是不是这样啊?

mkdir

【在 f**********t 的大作中提到】
: (Coding) Write a basic file system and implement the commands ls, pwd, mkdir
: , create, rm, cd, cat, mv. This was done on my own computer, in the
: interview room, with a 1.5 hour time limit.
: 1.5小时,大牛提示下咋写?谢谢

avatar
j*3
4
mark
avatar
f*t
5
自己先写点抛砖引玉好了,还没写完
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
from collections import defaultdict
from os.path import join, getsize
# Write a basic file system and implement the commands ls, pwd, mkdir ,
# create, rm, cd, cat, mv.
class TreeNode:
def __init__(self, name, isDir):
self.name = name
self.children = defaultdict()
self.isDir = isDir
class FileSystem(object):
def __init__(self):
self.root = TreeNode("", True)
self.cur = self.root
def mkdir_(self, cur, nodes):
for node in nodes:
if node not in cur.children:
cur.children[node] = TreeNode(node, True)
cur = cur.children[node]
def mkdir(self, *args):
for arg in args:
nodes = arg.strip().split('/')
if nodes[0] == "": # absolute path
self.mkdir_(self.root, nodes[1:])
else:
self.mkdir_(self.cur, nodes)
# print (arg, ' ')
def dispatch(self, *args):
if len(args) < 1:
return
cmd = args[0].lower()
handler = getattr(self, cmd)
handler(*args[1:])
def ls_(self, cur, nodes):
for node in nodes:
if node not in cur.children:
return
cur = cur.children[node]
for v in self.cur.children.values():
print(v.name)
# print(v.name for v in self.cur.children.values())
def ls(self, *args):
if len(args) == 0:
ls_(self, self.cur, [])
else:
for arg in args:
nodes = arg.strip().split('/')
if nodes[0] == "":
self.ls_(self.root, nodes[1:])
else:
self.ls_(self.cur, nodes)
def walkDir(dir):
for root, dirs, files in os.walk(dir):
print(root, "consumes", end=" ")
print(sum(getsize(join(root, name)) for name in files), end=" ")
print("bytes in", len(files), "non-directory files")
if 'CVS' in dirs:
dirs.remove('CVS') # don't visit CVS directories
def main():
fs = FileSystem()
while 1:
cmd = input(">> ")
# print(cmd)
fs.dispatch(*cmd.strip().split())
if __name__ == '__main__':
main()

【在 w**a 的大作中提到】
: file system一般都是用tree,每个node就是一个folder,是不是这样啊?
:
: mkdir

avatar
w*o
6
直接FUSE.
具體可以自己查一下FUSE API, 填空就好了.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。