一段有意思的代码
本帖最后由 Daniel_Zhang 于 2021-3-5 00:47 编辑今天在做一个提醒事项的 exe 的时候,发现一段很神奇的代码{:10_334:}
import platform
import os
import time
SYSTEM = platform.system()# 判断操作系统
if SYSTEM == 'Windows':# 不同的系统
import winsound
duration = 3000# millisecond
freq = 600# Hz
winsound.Beep(freq, duration)
elif SYSTEM == 'Linux':
for each in range(15):
os.system('spd-say "ding"')
time.sleep(0.5)
else:
try:
for each in range(15):
os.system('say "你的电脑已经被控制"')
time.sleep(0.5)
except:
pass
给你段更神奇的看看(听听):from winsound import Beep
from time import sleep
from sys import argv
from os import system
from os import path as op_pa
my_dict = [{1:261, 2:294, 3:330, 4:349, 5:392, 6:440, 7:494}, \
{1:523, 2:587, 3:659, 4:699, 5:784, 6:880, 7:988}, \
{1:1047, 2:1175, 3:1319, 4:1397, 5:1568}]
class Player:
def __init__(self, line, speed = 0.2, last = 150):
self.line = line
self.speed = speed
self.last = last
def play(self):
state = 3
i = 0
while i < len(self.line):
if self.line == '\\':
state = int(self.line)
i += 2
if self.line == '[':
tmp = int(self.line)
for each in range(tmp):
i += 2
a, b = int(self.line), int(self.line)
if b == 0:
sleep(self.last // tmp / 1000)
continue
Beep(my_dict, self.last // tmp)
i += 2
sleep(self.speed)
continue
if state == 3:
if i + 2 < len(self.line):
if self.line == '-':
tmp = 1
while self.line == '-':
tmp += 1
if not(i + tmp + 1 < len(self.line)):
break
a, b = int(self.line), int(self.line)
Beep( \
my_dict, \
round(self.last * tmp + \
self.speed * (tmp - 1) * 1000))
i += 1 + tmp
sleep(self.speed)
continue
a, b = int(self.line), int(self.line)
i += 2
else:
a, b = state, int(self.line)
i += 1
if b == 0:
sleep(self.last / 1000)
sleep(self.speed)
continue
Beep(my_dict, self.last)
sleep(self.speed)
def main():
'''
try:
path = argv
except IndexError:
system('_for_player_get_path.exe')
with open('tmp.txt', 'rt') as f:
path = f.readline()
system('del tmp.txt')
if path == 'exit':
exit()
with open(path, 'rt') as f:
tmp = '#'
while tmp == '#':
tmp = f.readline()
speed, last = eval(tmp)
tmp = '#'
while tmp == '#':
tmp = f.readline()
callable_char = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', \
'\\', '[', '-'}
line = ''
for each in tmp:
if each in callable_char:
line += each
'''
line = r'\15543[21111251[3050505\0555\1[21314543[211112\05[20006[20605\11[21314\315--\1[2141565[21414[213112\06[20011[207065\1[21311\312--[311111116-\14655431[21211[21213\060565\1[21112322431[20605[2121310\316-\146[21514[21314\315--00\314-\124[21514[21312\313--\101[20511316[21416530[2121431\0665\11[21311\312--00[21111[20511\1316[2141653[21212[2121431\0665\123\311--00\13[21314[2151504[21415[2161605543[211112[21314\315--00\13[21314[2151504[21415[2161605543[211112510'
speed, last = 0.1, 150
path = tmp = callable_char = None
player = Player(line, speed, last)
del path, line, speed, last, tmp, callable_char
print('关闭该窗口即可停止播放')
player.play()
if __name__ == '__main__':
main() 考不好不改名 发表于 2021-3-7 16:43
给你段更神奇的看看(听听):
啥也没发生啊
就print 一行 关闭该窗口即可停止播放{:10_245:} Daniel_Zhang 发表于 2021-3-7 16:52
啥也没发生啊
就print 一行 关闭该窗口即可停止播放
你开声音了吗? 考不好不改名 发表于 2021-3-7 17:00
你开声音了吗?
开了啊,我系统提示都有声音{:10_245:}
看样子你的代码我是无缘了{:10_269:} Daniel_Zhang 发表于 2021-3-7 17:02
开了啊,我系统提示都有声音
看样子你的代码我是无缘了
啊这,,,我这有,,,真是奇怪{:10_269:}
页:
[1]