【发布时间】:2020-11-05 05:06:27
【问题描述】:
'''
#import simpleaudio as sa
#from playsound import playsound
import winsound
from chart import chart
from BreakerZones import BreakerZones
import time
import sys
import colorama
import yaml # to print the nested_lookup results(n) on separate lines
from nested_lookup import nested_lookup, get_all_keys # importing 2 items from nested_lookup
from colorama import Fore, Back, Style
import os
colorama.init(autoreset=True) # If you don't want to print Style.RESET_ALL all the time,
# reset automatically after each print statement with True
print(colorama.ansi.clear_screen())
print('\n'*4) # prints a newline 4 times
print(Fore.MAGENTA + ' Arriving-' + Fore.GREEN + ' *** BREAKERVILLE USA ***')
def main():
print('\n' * 2)
print(Fore.BLUE + ' Breaker Numbers and Zones')
k = get_all_keys(BreakerZones)
# raw amount of keys even repeats , has quotes
new_l = [] # eliminate extra repeating nested keys
for e in k: # has quotes
if e not in new_l and sorted(e) not in new_l: #
new_l.append(e) #
print()
new_l.sort() # make alphabetical
newer_l = ('%s' % ', '.join(map(str, new_l)).strip("' ,")) # remove ['%s'] brackets so they don't show up when run
print(' ', yaml.dump(newer_l, default_flow_style=False)) # strip("' ,") or will see leading "' ," in output
print(Fore.BLUE + ' ENTER A BREAKER # OR ZONE', Fore.GREEN + ': ', end='')
i = input().strip().lower() # these lines is workaround for the colorama
print() # user input() issue of 'code' appearing in screen output
if i in k:
n = (nested_lookup(i, BreakerZones, wild=False, with_keys=False)) # wild=True means key not case sensitive,
print(yaml.dump(n, default_flow_style=False)) # 'with_keys' returns values + keys also
# for key, value in n.items(): eliminated by using yaml
# print(key, '--', value) eliminated by using yaml
else:
print(Fore.YELLOW + ' Typo,' + Fore.GREEN + ' try again')
main()
print()
print(Fore.GREEN + ' Continue? Y or N: C for breaker chart : ', end='') # see comments ENTER A BREAKER
ans = input().strip().lower() # strip() removes any spaces before or after user input
if ans == 'c':
chart()
print()
print(Fore.GREEN + ' Continue? Y or N : ', end='')
ans = input().strip().lower() # strip() removes any spaces before or after user input
if ans == 'y': # shorter version 'continue Y or N' after printing breaker chart
main()
else:
print()
print(Fore.MAGENTA + ' Departing -' + Fore.GREEN + ' *** BREAKERVILLE ***')
filename = os.path.join(getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__))),
'train_whistle.wav')
#filename = 'C:/Users/oseda/PycharmProjects/FirstProject/train_whistle.wav'
winsound.PlaySound(filename, winsound.SND_FILENAME)
time.sleep(2) # delay to exit program
sys.exit()
elif ans != 'y':
print()
print(Fore.MAGENTA + ' Good Day -' + Fore.GREEN + ' *** BREAKERVILLE ***')
filename = os.path.join(getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__))),
'train_whistle.wav')
#filename = 'C:/Users/oseda/PycharmProjects/FirstProject/train_whistle.wav'
winsound.PlaySound(filename, winsound.SND_FILENAME)
time.sleep(2) # delay to exit program
sys.exit()
else:
main()
main()
'''
【问题讨论】:
-
pyinstaller.readthedocs.io/en/stable/… 这个链接有一个很好的“测试代码”来检查我正在使用的应用程序是“捆绑”还是“源代码”。对于我列出的问题,这似乎是一个很好的测试。当我在我的脚本中运行它时,我得到:模块'sys'没有属性'frozen'。
-
好的,我刚刚发现我必须使用 Pyinstaller 运行该测试。对我来说太棒了。我确实看到了“在 Pyinstaller 包中运行”的结果
标签: windows pyinstaller