problem using pickle

Ben Finney ben+python at benfinney.id.au
Sat Jul 2 00:29:22 EDT 2016


"Veek. M" <vek.m1234 at gmail.com> writes:

> class Foo(object):
>   pass
>
> object is a keyword and you're using it as an identifier

Python does not have ‘object’ as a keyword. ‘and’ is a keyword.

Here's the difference::

    >>> object
    <class 'object'>
    >>> object = "Lorem ipsum"
    >>> object
    'Lorem ipsum'

    >>> and
      File "<stdin>", line 1
        and
          ^
    SyntaxError: invalid syntax
    >>> and = "Lorem ipsum"
      File "<stdin>", line 1
        and = "Lorem ipsum"
          ^
    SyntaxError: invalid syntax

Here is how you can test whether a word is a Python keyword::

    >>> import keyword
    >>> keyword.iskeyword('object')
    False
    >>> keyword.iskeyword('and')
    True

The set of keywords in Python is quite small.

    >>> len(keyword.kwlist)
    33

-- 
 \       “The best in us does not require the worst in us: Our love of |
  `\     other human beings does not need to be nurtured by delusion.” |
_o__)                             —Sam Harris, at _Beyond Belief 2006_ |
Ben Finney




More information about the Python-list mailing list