Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110932 > unrolled thread

Re: problem using pickle

Started by"Veek. M" <vek.m1234@gmail.com>
First post2016-07-02 09:16 +0530
Last post2016-10-27 21:22 +0530
Articles 5 — 4 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: problem using pickle "Veek. M" <vek.m1234@gmail.com> - 2016-07-02 09:16 +0530
    Re: problem using pickle Rustom Mody <rustompmody@gmail.com> - 2016-07-01 21:05 -0700
      Re: problem using pickle Veek M <vek.m1234@gmail.com> - 2016-10-27 21:23 +0530
    Re: problem using pickle Ben Finney <ben+python@benfinney.id.au> - 2016-07-02 14:29 +1000
      Re: problem using pickle Veek M <vek.m1234@gmail.com> - 2016-10-27 21:22 +0530

#110932 — Re: problem using pickle

From"Veek. M" <vek.m1234@gmail.com>
Date2016-07-02 09:16 +0530
SubjectRe: problem using pickle
Message-ID<nl7df9$lhe$2@dont-email.me>
Nicky Mac wrote:

> Dear Python team,
> I have studied the excellent documentation, and attempted to make use
> of pickle thus:
> 
> filename = 'my_saved_adventure'
> import  pickle
> class object:
>     def __init__(self,i,.........t) :
>         self.id       = i
>          .....
> 
> class world:
>     def __init__(self):
>         self.object
> 
> class object:
>     def __init__(self,i,
> 
> .....then   Object instances of object are created ........
> 
>         myworld = world;
>         myworld.Object = Object
>         fileobj = open(filename,'wb')
>         pickle.dump(myworld,fileobj); fileobj.close()
>         result = "saved your game to " + filename
> 
>         fileobj = open(filename,'rb')
>         myworld = pickle.load(fileobj); fileobj.close()
>         Object = myworld.Object
>         result = "restored your game from " + filename
> 
> 
> The proecedures execute without error
> but a file of only 21b is created containing " ?c__main__world q .
> altho there are several k of object instance data.
> 

class Foo(object):
  pass

object is a keyword and you're using it as an identifier

[toc] | [next] | [standalone]


#110933

FromRustom Mody <rustompmody@gmail.com>
Date2016-07-01 21:05 -0700
Message-ID<7e4ba6e5-eb3f-4c07-8c3a-6c3c24991ca0@googlegroups.com>
In reply to#110932
On Saturday, July 2, 2016 at 9:17:01 AM UTC+5:30, Veek. M wrote:
> object is a keyword and you're using it as an identifier

keyword and builtin are different
In this case though the advice remains the same
In general maybe not...
Just sayin'

[toc] | [prev] | [next] | [standalone]


#115880

FromVeek M <vek.m1234@gmail.com>
Date2016-10-27 21:23 +0530
Message-ID<nut7se$3ed$2@dont-email.me>
In reply to#110933
Rustom Mody wrote:

> On Saturday, July 2, 2016 at 9:17:01 AM UTC+5:30, Veek. M wrote:
>> object is a keyword and you're using it as an identifier
> 
> keyword and builtin are different
> In this case though the advice remains the same
> In general maybe not...
> Just sayin'
np - feel free to correct me

[toc] | [prev] | [next] | [standalone]


#110936

FromBen Finney <ben+python@benfinney.id.au>
Date2016-07-02 14:29 +1000
Message-ID<mailman.9.1467433773.2295.python-list@python.org>
In reply to#110932
"Veek. M" <vek.m1234@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

[toc] | [prev] | [next] | [standalone]


#115879

FromVeek M <vek.m1234@gmail.com>
Date2016-10-27 21:22 +0530
Message-ID<nut7qj$3ed$1@dont-email.me>
In reply to#110936
Ben Finney wrote:

> "Veek. M" <vek.m1234@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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web