2015-05-03 17 views

risposta

9

penso che tu stai solo suppone di utilizzare lo standard try-it-and-see-se-da-opere tecnica:

# New-style buffer API, for Python 2.7 and 3.x. 
# PyObject_CheckBuffer uses the new-style API. 
# 2.6 also has the new-style API, but no memoryview, 
# so you can't use it or check compatibility from Python code. 
try: 
    memoryview(thing) 
except TypeError: 
    # Doesn't support it! 

# Old-style API. Doesn't exist in 3.x. 
# Not quite equivalent to PyObject_CheckBuffer. 
try: 
    buffer(thing) 
except TypeError: 
    # Doesn't support it! 
+0

NameError: nome 'tampone' non è definito –

+0

@HristoVenev È necessario stai usando Python 3, nel qual caso dovresti usare la parola chiave 'memoryview' invece di' buffer'. La versione sicura raccomandata è di controllare sys.version_info nella parte superiore vicino alle istruzioni di importazione. Se è maggiore di (3,), quindi definisci 'buffer = memoryview', quindi puoi usare' buffer' in Python 2 o 3. – ely

Problemi correlati