Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python代码运行但不运行';不执行_Python_Execution - Fatal编程技术网

Python代码运行但不运行';不执行

Python代码运行但不运行';不执行,python,execution,Python,Execution,所以我的代码基本上是运行的,但执行不正常。我不确定我做错了什么。这是密码。当我在shell中键入某个内容时,它会忽略它。我该怎么修?我以前从未真正使用过if“\uuuuuuuu name\uuuuu==”\u main:函数,这就是为什么 import os.path import os import shutil def search_files(direct): directory=os.path.join(direct) directory1=os.path.exists

所以我的代码基本上是运行的,但执行不正常。我不确定我做错了什么。这是密码。当我在shell中键入某个内容时,它会忽略它。我该怎么修?我以前从未真正使用过
if“\uuuuuuuu name\uuuuu==”\u main:
函数,这就是为什么

import os.path
import os
import shutil

def search_files(direct):
    directory=os.path.join(direct)
    directory1=os.path.exists(directory)
    if directory1:
        return directory
    else:
        print ('ERROR')
        direct = input()

def search_characteristics(direct):
    interesting = input()
    space = interesting.count(' ')
    list1 = []
    list2 = []
    list3 = []
    directory = os.path.join(direct)
    files = nested_dir(directory)
    directory1=os.path.exists(directory)
    keyword = interesting[space + 1:len(interesting) + 1]

    if interesting[0] == 'N':
        for item in files:
            if item[item.rfind('\\')+1:item.rfind('.')] == interesting[space+1:len(interesting)+1]:
                list3.append(tem)
                return list3

    elif interesting[0] == 'E' :
        for item in files:
            if item[item.rfind('.')+1:len(item)+ 1] == ((interesting[space:len(interesting)+1]).strip('')).strip('.'):
                list2.append(item)
                return list2

    elif interesting[0] == 'S' :
        for item in files:
            if int(keyword) <os.path.getsize(item):
                list1.append(item)
                return list1
            else:
                print('ERROR')

def directory_files(nested_directory) -> list:
    file_list = []
    for element in os.listdirectory(nested_directory):
        path = os.path.join(nested_directory,element)

        if os.path.isdir(path):
            file_list.extend(nested_directory(path))
        else:
            file_list.append(path)

    return file_list

def path(interesting_files):
    for files in interesting_files:
        print(files)

def read_file(interesting_files):
    for files in interesting_files:
        infile=file
        open_file=open(infile)

    for line in open_file.readlines():
        print(line)
        open_file.close()

def duplicate(interesting_files):
    for files in interesting_files:
        shutil.copy(files,files+'.dup')

def modify(interesting_files):
    for files in interesting_files:
        os.utime(files,(1330712280, 1330712292))

if __name__ == '_main_':
    while True:
        file_input = input("Enter file name")
        if file_input.lower() == 'p':
            path(operation)
        elif file_input.lower() == 'f':
            read_file(operation)
        elif file_input.lower() == 'd':
            duplicate(operation)
        elif file_input.lower() == 't':
            modify(operation)
        else:
            print('ERROR')

    direct = input()
    search_files(direct)
    operation = search_characteristics(direct)
    print(operation)
    operations(operation)
导入操作系统路径
导入操作系统
进口舒蒂尔
def搜索_文件(直接):
directory=os.path.join(直接)
directory1=os.path.exists(目录)
如果目录1:
返回目录
其他:
打印('错误')
直接=输入()
def搜索_特性(直接):
有趣=输入()
空格=有趣的。计数(“”)
列表1=[]
列表2=[]
列表3=[]
directory=os.path.join(直接)
文件=嵌套目录(目录)
directory1=os.path.exists(目录)
关键字=有趣[空格+1:len(有趣)+1]
如果感兴趣[0]=“N”:
对于文件中的项目:
如果item[item.rfind('\\')+1:item.rfind('.')]==interest[space+1:len(interest)+1]:
列表3.追加(tem)
返回列表3
elif有趣的[0]=“E”:
对于文件中的项目:
如果项[item.rfind('.')+1:len(item)+1]=((有趣的[space:len(有趣的)+1]).strip('.'):
列表2.追加(项目)
返回列表2
elif有趣的[0]=='S':
对于文件中的项目:
如果int(关键字)列表:
文件列表=[]
对于os.listdirectory(嵌套目录)中的元素:
path=os.path.join(嵌套的目录,元素)
如果os.path.isdir(路径):
扩展(嵌套目录(路径))
其他:
文件\u list.append(路径)
返回文件列表
def路径(有趣的_文件):
对于感兴趣的\u文件中的文件:
打印(文件)
def read_文件(有趣的_文件):
对于感兴趣的\u文件中的文件:
infle=文件
打开文件=打开(填充)
对于open_file.readlines()中的行:
打印(行)
打开_文件。关闭()
def重复(有趣的_文件):
对于感兴趣的\u文件中的文件:
shutil.copy(文件,文件+'.dup')
def修改(感兴趣的文件):
对于感兴趣的\u文件中的文件:
utime(文件,(1330712280、1330712292))
如果uuuu name uuuuu=='\u main':
尽管如此:
文件输入=输入(“输入文件名”)
如果文件\u input.lower()
路径(操作)
elif file_input.lower()==“f”:
读取文件(操作)
elif file_input.lower()==“d”:
复制(操作)
elif file_input.lower()=='t':
修改(操作)
其他:
打印('错误')
直接=输入()
搜索_文件(直接)
操作=搜索特性(直接)
打印(操作)
操作(操作)

如果您要求使用
main
\uuuu name\uuuu
,我的脚本执行方法如下:

#!/usr/bin/python
def main():
   #your code

if __name__ == "__main__":
    main()

我通常不使用
main
中的所有函数,然后使用
main
作为控制器。如果您试图通过终端运行它,但它没有保存为
.py
,则需要确保
shebang
位于顶部,或者在输入脚本名称之前键入
python
。也就是说,如果调用了
te脚本st_script
您可以使用shebang,然后执行
/test_script
python test_script
。如果您有
.py
扩展名,那么请尝试
python test_script.py
。希望这有点帮助。同时确保
chmod
脚本上的特权。我通常执行
chmod 775 test_script.py在我执行它之前。

你有一个while True循环作为第一个运行的东西,它永远不会退出这个循环。你的代码将按原样运行,因此我想象你被困在
file\u input=input()
行,它正在等待输入。如果你
file\u input=input(“输入文件名”)
这可能会有所帮助。此外,在调用函数之前,您应该先定义函数,
如果uuuu name uu==“uuuuu main”
通常会在脚本末尾。您也没有更改为
如果uuuuu name uuu==“uuu main”__“
如上所述,查看您的vsmine@accelerate,
\u main\u
不是
\u main\u
,但是,即使修复了它,您的ocde@accelerate,是的,这就是我想告诉你的,循环需要在你试图访问的任何函数或变量之后,顺序很重要。如果代码中有10个或更多的错误,我建议您仔细检查并重新排列代码,一个好的代码编辑器会为您突出显示这些错误。
main()
方法不是necessary@cricket_007:我认为问题的关键在于
\uuuu main\uuu
字符串不正确。这不是很清楚,所以不是一个很好的答案,但我不认为他试图暗示使用
main()
是必要的。感谢您的反馈,我在回答中提供了更多细节。