problem using pickle

Veek M vek.m1234 at gmail.com
Thu Oct 27 11:52:09 EDT 2016


Ben Finney wrote:

> "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
> 
Oh awesome - thanks - that's a neat module. Yeah, basically keywords are 
part of the language but not punctuation - kind of like how you had to 
do: print 'foo' in 2.x - part of the grammar of the language. Dunno why 
i muffed that.. 'object's a class anyhow so it couldn't be a keyword 
(inherited with its methods etc) - thanks for catching that and sorry 
for the delay.. saw that today.



More information about the Python-list mailing list