转换为字符并逐个字母打印

时间:2019-08-28 16:53:52

标签: python

您好,我正在开发一个在数组中具有十六进制的程序:

data = ['000000'] #random dummy hex

我正在尝试解码十六进制并打印字母中的字母,就像有人在打字一样:

def typer(type):
s = bytearray.fromhex(type).decode()
for y in type:
 sleep(0.1)
 sys.stdout.write(y)
 sys.stdout.flush()

发生的是它将从数字中打印出十六进制数字,而不是将其转换为字符串并从字母中打印出字符串字母。但是当我放:

def typer(type):
s = bytearray.fromhex(type).decode()
for y in type:
 sleep(0.1)
 sys.stdout.write(s)
 sys.stdout.flush()

它反而向字符串发送垃圾邮件,但我希望它像某个人在键入字母一样执行字母操作,并且直到它在字符串末尾时才停止。我已经尝试了从上述方法执行的所有方法,直到将其解码为十六进制并将其打印在文件中,然后将其输出并尝试将其执行,这些方法都不起作用。

但总代码为:

data = ['0000'] #dummy hex
def typer(type):
  s = bytearray.fromhex(type).decode()
  for y in type:
   sleep(0.1)
   sys.stdout.write(y)
   sys.stdout.flush() 

typer(data[0])

0 个答案:

没有答案