我是Python的新手,但我必须在学校实现Python语言的命令行解释器,但我有点迷失在如何做到这一点.
我已经阅读了一些教程并创建了一个名为functions.py的简单文件,其中包含一些简单的函数,如下所示:
def delete(loc):
if os.path.exists(loc) == True:
os.remove(loc)
print "Removed"
else:
print "File not exists"
Run Code Online (Sandbox Code Playgroud)
现在..这里是东西..为了使用这个我必须在python命令解释器中导入它,就像...
import functions
functions.delete("file to delete")
Run Code Online (Sandbox Code Playgroud)
我怎样才能创建一个Shell/CLI,而不必编写所有这些,我可以这样写:
delete file_name
Run Code Online (Sandbox Code Playgroud)
谢谢!
仅当用户没有URI时,如何将用户发送到新位置?我正在尝试以下,但它不起作用...它总是把我发送到/ newlocation
rewrite ^/$ http://www.domain.com/newlocation permanent;
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
Run Code Online (Sandbox Code Playgroud)
基本上,我需要的是:
如果用户在浏览器www.domain.org上写入,则会发送到www.domain.com/newlocation如果用户在浏览器www.domain.org/something上写入,则会发送到www.domain.com/something
谢谢!