【问题标题】:unprintable string to number in python不可打印的字符串在python中编号
【发布时间】:2011-05-29 01:30:57
【问题描述】:

文档http://docs.python.org/library/wave.html

Wave_read.readframes(n)

读取并返回最多 n 帧音频,作为字节串。

我想以十六进制或数字形式查看这些字符串,以了解当没有声音或加号、减号时的值

我试过了

import wave

target = wave.open('t2.wav')

length = target.getnframes()

section = target.readframes(2205)

print section[0:2]

这个代码打印字符串看起来像+,当我运行代码时,

print int(section[0:2])

加薪

Traceback (most recent call last):

  File "D:/py/pitch2.py", line 5, in <module>

    print int(section[0:2])

ValueError: invalid literal for int() with base 10: '\x10'

如何解决?

【问题讨论】:

    标签: python string printing hex


    【解决方案1】:
    print [ord(i) for i in section[0:2]]
    

    print [hex(ord(i)) for i in section[0:2]]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      • 2023-01-09
      • 2010-09-10
      • 1970-01-01
      • 2017-12-16
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多