Re: Pickle performing class instantiation ??

2012-02-28 Thread Andrew Berg
On 2/28/2012 9:54 AM, Smiley 4321 wrote: > NameError: name 'self' is not defined self is meaningless outside a class definition. You should refactor your dump, load and print code as methods inside the class definition, create an instance and call the methods on that instance. -- CPython 3.2.2 |

Re: Pickle performing class instantiation ??

2012-02-28 Thread Peter Otten
Smiley 4321 wrote: > Am I doing the right thing for - > > - Have a class > - Instantiate the class with 3 parameters > - pickle the class instance > - generate a bytestream (.pkl) using pickle.dump, simply guessing - > > as - > > --- > #!/usr/bin/python > > import pickle > > class Pickle: >

RE: Pickle performing class instantiation ??

2012-02-28 Thread Prasad, Ramit
>class Pickle: >    def __init__(self, Parameter1, Parameter2, Parameter3): >        self.PM1 = Parameter1 >        self.PM2 = Parameter2 >        self.PM3 = Parameter3 >with open('/tmp/readfile.pkl', 'wb') as f: >    pickle.dump((self.PM1, self.PM2, self.PM3), f)     >with open('/tmp/readfile.pk

Re: Pickle performing class instantiation ??

2012-02-28 Thread Smiley 4321
#x27; is not defined -- On Tue, Feb 28, 2012 at 8:44 PM, Smiley 4321 wrote: > I am looking for pickle performing class instantiation, something as > prototype like - > > - Have a class > - Instantiate the class with 3 parameters > - pickle the class instance > - genera

Pickle performing class instantiation ??

2012-02-28 Thread Smiley 4321
I am looking for pickle performing class instantiation, something as prototype like - - Have a class - Instantiate the class with 3 parameters - pickle the class instance - generate a bytestream (.pkl) using pickle.dump -- http://mail.python.org/mailman/listinfo/python-list

Re: Variable class instantiation

2009-12-11 Thread Steven D'Aprano
On Fri, 11 Dec 2009 11:36:13 +, Sion Arrowsmith wrote: > Steven D'Aprano wrote: >>thisModule = __import__(__name__) >>classToUse = thisModule.__dict__['C1'] > > Any reason to prefer this over: > > classToUse = getattr(thisModule, 'C1') > > ? (I think, for a module, they should do exactly

Re: Variable class instantiation

2009-12-11 Thread Sion Arrowsmith
Steven D'Aprano wrote: >thisModule = __import__(__name__) >classToUse = thisModule.__dict__['C1'] Any reason to prefer this over: classToUse = getattr(thisModule, 'C1') ? (I think, for a module, they should do exactly the same thing. Personally, I prefer keeping explicit references to __specia

Re: Variable class instantiation

2009-12-11 Thread Lie Ryan
On 12/11/2009 8:26 PM, Jan Mach wrote: Hi everybody, I am currently solving the following problem and I am stuck. I am trying to create instance of the class of variable name. I know, that the following works: if (something): classToUse = C1 else: classToUse = C2 o = classToUse() ,bu

Re: Variable class instantiation

2009-12-11 Thread Steven D'Aprano
On Fri, 11 Dec 2009 10:26:49 +0100, Jan Mach wrote: > I need to have the class name in the > string and then instantiate it: > > (this does not work of course) > classToUse = "C1" > o = classToUse() > > It is because I don`t know at the moment what the name of the class will > be, I will load it

Re: Variable class instantiation

2009-12-11 Thread Richard Thomas
On Dec 11, 9:26 am, Jan Mach wrote: > Hi everybody, > I am currently solving the following problem and I am stuck. I am trying > to create instance of the class of variable name. I know, that the > following works: > > if (something): >     classToUse = C1 > else: >     classToUse = C2 > > o = cla

Variable class instantiation

2009-12-11 Thread Jan Mach
Hi everybody, I am currently solving the following problem and I am stuck. I am trying to create instance of the class of variable name. I know, that the following works: if (something): classToUse = C1 else: classToUse = C2 o = classToUse() ,but this is not what I want. I need to have t

Re: Class instantiation fails when passed in a file but work via line by line interpreter

2008-11-18 Thread Jeff Tchang
> Random related question. If you're writing a SAML implementation have > you found an XML Signature implementation that works reliably from > python? I've had a hell of a time finding something that doesn't > segfault and is interoperable with .NET. I guess you could call it a SAML implementation

Re: Class instantiation fails when passed in a file but work via line by line interpreter

2008-11-18 Thread John Krukoff
On Tue, 2008-11-18 at 10:45 -0800, Jeff Tchang wrote: > Odd issue I am having with class instantiation on Python 2.5.2 (Windows). > > I have a custom module with a few classes in it. The module is named SAML.py. > There is a copy of it in C:\Python25\Lib\site-packages\SAML.py. > &

Re: Class instantiation fails when passed in a file but work via line by line interpreter

2008-11-18 Thread Steve Holden
Jeff Tchang wrote: > Odd issue I am having with class instantiation on Python 2.5.2 (Windows). > > I have a custom module with a few classes in it. The module is named SAML.py. > There is a copy of it in C:\Python25\Lib\site-packages\SAML.py. > > Basically when I try to run

Class instantiation fails when passed in a file but work via line by line interpreter

2008-11-18 Thread Jeff Tchang
Odd issue I am having with class instantiation on Python 2.5.2 (Windows). I have a custom module with a few classes in it. The module is named SAML.py. There is a copy of it in C:\Python25\Lib\site-packages\SAML.py. Basically when I try to run a python file that tries to create an instance of

Re: Local variables in classes and class instantiation

2007-12-27 Thread Gabriel Genellina
En Sun, 23 Dec 2007 08:05:18 -0300, Peter Otten <[EMAIL PROTECTED]> escribió: >> Still, when I execute all three methods, I get two instances that are >> equal and the third is different. >> Is there some circomstance that makes two object creations result in the >> same object? >> >> ==

Re: Local variables in classes and class instantiation

2007-12-23 Thread Peter Otten
A.J. Bonnema wrote: > I have a small question about how classes get instantiated within other > classes. I have added the source of a test program to the bottom of this > mail, that contains 3 methods within a testclass that each instantiate > the same class and bind it to a local variable. My

Re: Local variables in classes and class instantiation

2007-12-23 Thread Matt Nordhoff
A.J. Bonnema wrote: > Hi all, > > I just started using Python. I used to do some Java programming, so I am > not completely blank. > > I have a small question about how classes get instantiated within other > classes. I have added the source of a test program to the bottom of this > mail, that

Local variables in classes and class instantiation

2007-12-23 Thread A.J. Bonnema
Hi all, I just started using Python. I used to do some Java programming, so I am not completely blank. I have a small question about how classes get instantiated within other classes. I have added the source of a test program to the bottom of this mail, that contains 3 methods within a testcla

Re: python class instantiation

2006-10-23 Thread Paul McGuire
"Éric Daigneault" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > It is humbling to see how simple yet powerfull python`s view on things > is +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: python class instantiation

2006-10-23 Thread Gabriel Genellina
At Monday 23/10/2006 17:56, Éric Daigneault lists wrote: >When creating a class with data members but no __init__ method. Python >deals differently with data members that are muatable and immutables. See specially items 4 and 5. And

Re: python class instantiation

2006-10-23 Thread Chetan
Éric Daigneault wrote: >Got a question for you all... > >I noticed a behaviour in python class creation that is strange, to say the >least. > >When creating a class with data members but no __init__ method. Python deals >differently with data members that are muatable and immutables. > >Ex: >class

Re: python class instantiation

2006-10-23 Thread Éric Daigneault
Fredrik Lundh wrote: > Éric Daigneault lists wrote: > > >> When creating a class with data members but no __init__ method. Python >> deals differently with data members that are muatable and immutables. >> > > no, it doesn't. it's your code that deals with them in different ways, > not

Re: python class instantiation

2006-10-23 Thread Fredrik Lundh
Éric Daigneault lists wrote: > When creating a class with data members but no __init__ method. Python > deals differently with data members that are muatable and immutables. no, it doesn't. it's your code that deals with them in different ways, not Python. > Ex: > class A(object): > stri

python class instantiation

2006-10-23 Thread Éric Daigneault lists
Got a question for you all... I noticed a behaviour in python class creation that is strange, to say the least. When creating a class with data members but no __init__ method. Python deals differently with data members that are muatable and immutables. Ex: class A(object): stringData = "W

Re: Class instantiation

2006-08-23 Thread Colin J. Williams
Fredrik Lundh wrote: > Colin J. Williams wrote: > >> In the example below, with the disassembly following that, we run into >> trouble with the line: >> self.connect(fileID, mode= 'r') # open sheet in the read mode >> >> the traceback is: >> Traceback (most recent call last): >>File

Re: Class instantiation

2006-08-23 Thread Fredrik Lundh
Colin J. Williams wrote: > In the example below, with the disassembly following that, we run into > trouble with the line: > self.connect(fileID, mode= 'r') # open sheet in the read mode > > the traceback is: > Traceback (most recent call last): >File "C:\Documents and Settings\cjw

Re: Class instantiation

2006-08-23 Thread Paul McNett
Colin J. Williams wrote: > class arSpread(object): >def __init__(self, fileId= None, ar= None): > if fileId: >if ar is not None: > print fileId > self.connect(fileID, mode= 'r') # open sheet in the read mode >else: > self.connect(fileID, mod

Re: Class instantiation

2006-08-23 Thread Gabriel Genellina
At Wednesday 23/8/2006 16:21, Colin J. Williams wrote: In the example below, with the disassembly following that, we run into trouble with the line: NameError: global name 'fileID' is not defined At line 26, location 31, why is LOAD_GLOBAL generated for fileId, when LOAD_FAST has done the job a

Class instantiation

2006-08-23 Thread Colin J. Williams
In the example below, with the disassembly following that, we run into trouble with the line: self.connect(fileID, mode= 'r') # open sheet in the read mode the traceback is: Traceback (most recent call last): File "C:\Documents and Settings\cjw\My Documents\OODev\tArray.py", line 26

Re: dynamic class instantiation

2006-02-03 Thread Volker Grabsch
Kent Johnson wrote: > Ognen Duzlevski wrote: >> I appreciate your comments. Basically, the reason why this code generator >> exists is the fact that I do not want to hard-code the resulting xml in >> any way. The users of the web/db framework of which this solution is part of >> might like the "we

Re: dynamic class instantiation

2006-02-02 Thread Ognen Duzlevski
Kent Johnson <[EMAIL PROTECTED]> wrote: > Ognen Duzlevski wrote: > > Can you suggest a better approach or did you already do that and I just > > missed > > it? :) > With the above definitions, an equivalent class is created by calling > page = classFactory( 'page', { 'name' : None, 'caption': No

Re: dynamic class instantiation

2006-02-02 Thread Kent Johnson
Ognen Duzlevski wrote: > Volker Grabsch <[EMAIL PROTECTED]> wrote: >>I'm sure you could replace 2/3 of your code with something much simpler >>(and shorter!) just by not inventing a new language and using the power >>of Python instead. > > > Hi Volker, > > I appreciate your comments. Basically,

Re: dynamic class instantiation

2006-02-01 Thread Ognen Duzlevski
Volker Grabsch <[EMAIL PROTECTED]> wrote: > Ognen Duzlevski wrote: > > Kent Johnson <[EMAIL PROTECTED]> wrote: > >> Ognen Duzlevski wrote: > >> > Say I got "page" as a string. How do I go about > >> > instantiating a class from this piece of information? To make it > >> > more obvious how do I cr

Re: dynamic class instantiation

2006-01-31 Thread Volker Grabsch
Ognen Duzlevski wrote: > Kent Johnson <[EMAIL PROTECTED]> wrote: >> Ognen Duzlevski wrote: >> > Say I got "page" as a string. How do I go about >> > instantiating a class from this piece of information? To make it >> > more obvious how do I create the page() class based on the "page" >> > string

Re: dynamic class instantiation

2006-01-31 Thread Ognen Duzlevski
Kent Johnson <[EMAIL PROTECTED]> wrote: > Ognen Duzlevski wrote: > > Say I got "page" as a string. How do I go about > > instantiating a class from this piece of information? To make it > > more obvious how do I create the page() class based on the "page" > > string I have? > Use getattr(). H

Re: dynamic class instantiation

2006-01-30 Thread Kent Johnson
Ognen Duzlevski wrote: > I have a parser that will go through the language definition > file and produce the following as a separate .py file: > > class page(object): > def __init__(): > self.name = None > self.caption = None > self.functions = [] >

Re: dynamic class instantiation

2006-01-30 Thread Larry Bates
Ognen Duzlevski wrote: > Larry Bates <[EMAIL PROTECTED]> wrote: >>> Now I want to use something like xml.dom.minidom to "parse" the >>> .xml file into a set of classes defined according to the "language >>> definition" file. The parse() method from the xml.dom.minidom >>> package will return a d

Re: dynamic class instantiation

2006-01-30 Thread Ognen Duzlevski
Larry Bates <[EMAIL PROTECTED]> wrote: > > Now I want to use something like xml.dom.minidom to "parse" the > > .xml file into a set of classes defined according to the "language > > definition" file. The parse() method from the xml.dom.minidom > > package will return a document instance and I ca

Re: dynamic class instantiation

2006-01-30 Thread Larry Bates
Ognen Duzlevski wrote: > Hi, I have a "language definition" file, something along the lines of: > > page :: > name : simple > caption : simple > function : complex > > function :: > name : simple > code : simple > > component :: > name : simple > type :

dynamic class instantiation

2006-01-30 Thread Ognen Duzlevski
Hi, I have a "language definition" file, something along the lines of: page :: name : simple caption : simple function : complex function :: name : simple code : simple component :: name : simple type : simple dataset : complex