简体   繁体   English

pyinstaller中的sys.stdin.readlines()

[英]sys.stdin.readlines() in pyinstaller

Here, I want to creat a simple exe program that removes duplicated people using pyinstaller. 在这里,我想创建一个简单的exe程序,该程序使用pyinstaller删除重复的人。

Since I want to get multiline of inputs, I used: 由于我想获得多行输入,因此我使用了:

text = sys.stdin.readlines()

but even though it works well on Jupyter notebook or spyder, after when I create and open its exe file, it does not show anything but just black window. 但是,即使它在Jupyter笔记本电脑或spyder上运行良好,当我创建并打开其exe文件后,它也只显示黑色窗口而没有显示任何内容。 if I remove that line, I know that it works, but only single line input will be allowed. 如果删除该行,我知道它可以工作,但是仅允许单行输入。

Also, I've try to switch these two, so input first then sys.stdin.readlines(): 另外,我尝试切换这两个,所以先输入,然后输入sys.stdin.readlines():

text = sys.stdin.readlines()
text = input('Type or Paste your text, and press Ctrl + Z.\n\n')

However, even though it allows multiline input, it only processes duplication function on the very first line of the input. 但是,即使它允许多行输入,它也只在输入的第一行处理复制功能。

Here is my full code. 这是我的完整代码。 Please help me out. 请帮帮我。 Thanks 谢谢

# -*- coding: utf-8 -*-

import re
import sys


def duplication():


    text = sys.stdin.readlines()
    text = input('Type or Paste your text, and press Ctrl + Z.\n\n')
    text = re.split(", |-|  |,", text)


    text = list(filter(None, text)) # fastest

    names = set()
    remove = set()

    for n in text:

        if not n.startswith(("*", "-")):
            n = n.lstrip()
            if n in names:
                remove.add(n)
            elif n not in names:
                names.add(n)

    print(f'\n\nDuplicated person: {(sorted(remove))}\n\nTotal of {len(remove)}is/are removed, Total of {len(names)}is shown.')
    print (sorted(names))




def next_move():
    nxt = input("\n\nWhat do you want to do next?\n   1. Enter another text\n   2. exit\n\n")
    if nxt == '1':
        duplication()
        next_move()
    elif nxt == '2':
        exit()
    else:
        print('Please choose between 1 and 2.')
        next_move()


def overall():
    duplication()
    next_move()


overall()

Your input handling is a little out, and you also don't appear to realise that the readlines() method returns a list of all the lines until the end of file. 您的输入处理有点麻烦,并且您似乎也没有意识到readlines()方法会返回所有行的列表,直到文件结尾。 Therefore the input call won't see any input - which might make it hang. 因此, input呼叫将看不到任何输入-这可能使其挂起。

Since you don't discuss the data format I'm assuming that 由于您不讨论数据格式,所以我假设

  • Lines beginning with '#' and '-' should be ignored, as should empty lines '#''-'开头的行应被忽略,空行也应被忽略
  • Each other line contains a single name, possibly surrounded by whitespace 每隔一行包含一个名称,可能用空格包围

Your duplication function should look more like this (untested): 您的duplication功能应该看起来像这样(未经测试):

def duplication():


    print('Type or Paste your text, and press Ctrl + Z.\n\n')
    text = sys.stdin.readlines()    

    names = set()
    remove = set()

    for n in text:

        n = n.strip()
        if n and n.startswith(("*", "-")):
            continue  # straight to next line
        if n in names:
            remove.add(n)
        elif n not in names:  # else: would be just as good!
            names.add(n)

    print(f'\n\nDuplicated person: {(sorted(remove))}\n\nTotal of {len(remove)}is/are removed, Total of {len(names)}is shown.')
    print (sorted(names))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何完成sys.stdin.readlines()输入? - How to finish sys.stdin.readlines() input? sys.stdin.readlines()背后的内容 - What's behind sys.stdin.readlines() sys.stdin.readlines()挂起Python脚本 - sys.stdin.readlines() hangs Python script 在python中支持sys.stdin.readlines()以及命令行参数吗? - Supporting sys.stdin.readlines() as well as command line arguments in python? 在 Python 3 中使用 Ctrl-D 和 sys.stdin.readlines() 后,如何避免 input() 出现 EOFError? - How can I avoid an EOFError for input() after using Ctrl-D with sys.stdin.readlines() in Python 3? Python 3.x:sys.stdin.readlines()上的''.join()输入在最终字符不是换行/换行符时不返回最终字符串 - Python 3.x: ' '.join() on sys.stdin.readlines() Input Does Not Return Final String When Final Character Is Not a Line/Carriage Break 来自sys.stdin的readlines()之后的input()? - input() after readlines() from sys.stdin? python-sys.stdin.readlines() ,停止在命令行中读取行 - python-sys.stdin.readlines() ,Stop reading lines in command line 使用 Pyinstaller 创建的 .exe 文件显示错误 input(): lost sys.stdin - .exe file created with Pyinstaller is showin error input(): lost sys.stdin 在sys.stdin上循环 - Loop on sys.stdin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM