Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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_Flask Restful_Yield Keyword_Yield From - Fatal编程技术网

Python `在烧瓶中的产率

Python `在烧瓶中的产率,python,flask-restful,yield-keyword,yield-from,Python,Flask Restful,Yield Keyword,Yield From,首先,我用烧瓶 第二,我产生类似下面代码的值 def upload_file(): if request.method == 'POST': f = request.files['file'] def generate(): yield '<pre>' yield "Processing...\n" file = CheckFile(f.filename, f.read()

首先,我用烧瓶

第二,我
产生类似下面代码的值

def upload_file():
    if request.method == 'POST':
        f = request.files['file']
        def generate():
            yield '<pre>'
            yield "Processing...\n"
            file = CheckFile(f.filename, f.read())
            file.parse()
            for note in file.validate():
                if note.oddity_type == Note.ERROR:
                    yield '<span style="color: red;">%s</span>' % str(note)
                if note.type == Note.WARNING:
                    yield '<span style="color: orange;">%s</span>' % str(note)
                if note.type == Note.INFO:
                    yield '<span style="color: blue;">%s</span>' % str(note)
                if note.type == Note.FATAL:
                    yield '<span style="color: red;">%s</span>' % str(note)
            yield '</pre>'
        return Response(stream_with_context(generate()))
    if request.method == 'GET':
        return app.send_static_file('index.html')
def upload_file():
如果request.method==“POST”:
f=请求.files['file']
def generate():
屈服“
产生“处理…\n”
file=CheckFile(f.filename,f.read())
parse()文件
对于文件.validate()中的注释:
如果note.oddity_type==note.ERROR:
产量“%s”%str(注意)
如果note.type==note.WARNING:
产量“%s”%str(注意)
如果note.type==note.INFO:
产量“%s”%str(注意)
如果note.type==note.FATAL:
产量“%s”%str(注意)
屈服“
返回响应(流_与_上下文(generate()))
如果request.method==“GET”:
返回app.send\u静态文件('index.html')
因此,在
检查文件
中的
\uuuu init\uuuuuuuuuuuuuuuuuuuuuuu完成后,我
返回
值并
yield`到响应中


我想做的是能够
\uuu init\uuu
file.parse()

中产生
值,我读了三遍,但没有弄清楚您想做什么。好的,我已经澄清了一点。美元更好吗?将
parse
作为生成器,并使用
yield from
关键字。我不认为对构造函数也这样做是个好主意。这不是它的目的,我也不知道这是否可行。是的,这实际上也是我的想法,但是,我不确定如何实现它(“解析是一个生成器”)。基本上,解析就是读取一个JSON文件并读取该JSON的某些键。您只需要在
parse
中有一个或多个
yield
语句,然后
yield from file.parse()
。我没有测试它,所以如果它有效,请给我一个通知。