从输出中删除"无"

mar*_*rin 2 python python-3.x

我正在尝试删除所有不属于法语的短语.我尝试使用langdetect库(不幸的是没有pandas)

CSV文件

message
Je suis fatiguée
The book is on the table
Il fait chaud aujourd'hui!
They are sicks
La vie est belle
Run Code Online (Sandbox Code Playgroud)

脚本:

import csv
from langdetect import detect

with open('ddd.csv', 'r') as file:
    fichier = csv.reader(file)

    for line in fichier:
        if line[0] != '':
            message = line[0]

            def detecteur_FR(message):
                #We need to turn the column into a list of lists.
                message_list = [comments for comments in message.split('\n')]
                for text in message_list:
                    if detect(text) == 'fr':
                        message_FR = text
                        return message_FR

            print(detecteur_FR(message))
Run Code Online (Sandbox Code Playgroud)

我的输出:

None
Je suis fatiguée
None
Il fait chaud aujourd hui!
None
La vie est belle
Run Code Online (Sandbox Code Playgroud)

我想要:

Je suis fatiguée
Il fait chaud aujourd hui!
La vie est belle
Run Code Online (Sandbox Code Playgroud)

我怎么能删除'无'?

iBu*_*Bug 5

您只需在打印前添加一个检查:

result = detecteur_FR(message)
if result is not None:
    print(result)
Run Code Online (Sandbox Code Playgroud)