Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

Commonmark migration
Source Link

The following code works fine in python 2.7:

def GetMaxNoise(data, max_noise):
 for byte in data:
 noise = ComputeNoise(struct.unpack('=B',byte)[0])
 if max_noise < noise:
 max_noise = noise
 return max_noise

where data is a string holding binary data (taken from a network packet).

I'm trying to port it to Python 3 and I get this:

File "Desktop/Test.py", line 2374, in GetMaxNoise

noise = ComputeNoise(struct.unpack('=B',byte)[0])

TypeError: 'int' does not support the buffer interface

How can I convert "data" to the appropriate type needed by unpack()?

The following code works fine in python 2.7:

def GetMaxNoise(data, max_noise):
 for byte in data:
 noise = ComputeNoise(struct.unpack('=B',byte)[0])
 if max_noise < noise:
 max_noise = noise
 return max_noise

where data is a string holding binary data (taken from a network packet).

I'm trying to port it to Python 3 and I get this:

File "Desktop/Test.py", line 2374, in GetMaxNoise

noise = ComputeNoise(struct.unpack('=B',byte)[0])

TypeError: 'int' does not support the buffer interface

How can I convert "data" to the appropriate type needed by unpack()?

The following code works fine in python 2.7:

def GetMaxNoise(data, max_noise):
 for byte in data:
 noise = ComputeNoise(struct.unpack('=B',byte)[0])
 if max_noise < noise:
 max_noise = noise
 return max_noise

where data is a string holding binary data (taken from a network packet).

I'm trying to port it to Python 3 and I get this:

File "Desktop/Test.py", line 2374, in GetMaxNoise

noise = ComputeNoise(struct.unpack('=B',byte)[0])

TypeError: 'int' does not support the buffer interface

How can I convert "data" to the appropriate type needed by unpack()?

Source Link
tgthsh
  • 61
  • 1
  • 3

Porting struct.unpack from python 2.7 to 3

The following code works fine in python 2.7:

def GetMaxNoise(data, max_noise):
 for byte in data:
 noise = ComputeNoise(struct.unpack('=B',byte)[0])
 if max_noise < noise:
 max_noise = noise
 return max_noise

where data is a string holding binary data (taken from a network packet).

I'm trying to port it to Python 3 and I get this:

File "Desktop/Test.py", line 2374, in GetMaxNoise

noise = ComputeNoise(struct.unpack('=B',byte)[0])

TypeError: 'int' does not support the buffer interface

How can I convert "data" to the appropriate type needed by unpack()?

lang-py

AltStyle によって変換されたページ (->オリジナル) /