As I assume the text you want to process has some source you might want to
look at http://docs.python.org/library/pickle.html ...
2012/1/24 T H
> I’m new to python, sorry if my question is a bit naive, I was
> wondering if it is possible to parse some text (ie. from a text file
> or say html) an
On Jan 24, 6:22 pm, T H wrote:
> I’m new to python, sorry if my question is a bit naive, I was
> wondering if it is possible to parse some text (ie. from a text file
> or say html) and then dynamically create a class?
>
> for example lets say the contents of the text file is:
>
> functionName
On Wed, Jan 25, 2012 at 4:22 AM, T H wrote:
> I’m new to python, sorry if my question is a bit naive, I was
> wondering if it is possible to parse some text (ie. from a text file
> or say html) and then dynamically create a class?
Presuming that your class name comes from somewhere (eg the name o
I’m new to python, sorry if my question is a bit naive, I was
wondering if it is possible to parse some text (ie. from a text file
or say html) and then dynamically create a class?
for example lets say the contents of the text file is:
functionName: bark arg1: numberBarks
functionName:
On Sun, 20 Dec 2009 11:11:54 -0500, Steve Holden wrote:
> Dave Angel wrote:
> [...]
>> We were talking about 2.x And I explicitly mentioned 3.x because if
>> one develops code that depends on old-style classes, they'll be in
>> trouble with 3.x, which has no way to specify old-style classes. In
Dave Angel wrote:
[...]
> We were talking about 2.x And I explicitly mentioned 3.x because if
> one develops code that depends on old-style classes, they'll be in
> trouble with 3.x, which has no way to specify old-style classes. In
> 3.x, all classes are new-style. And although it'll no longer
Steve Holden wrote:
Dave Angel wrote:
seafoid wrote:
Hey Guys,
I have started to read over classes as a brief respite from my parsing
problem.
When a class is defined, how does the class access the data upon which
the
class should act?
Example:
class Seq:
Dave Angel wrote:
> seafoid wrote:
>> Hey Guys,
>>
>> I have started to read over classes as a brief respite from my parsing
>> problem.
>>
>> When a class is defined, how does the class access the data upon which
>> the
>> class should act?
>>
>> Example:
>>
>> class Seq:
Hello Dave
>
> There are more complex things that can go on, like creating "bound"
> function objects, but I think this should get you pretty far.
>
> Could explain the complex things for me?
Regards,
Janus
--
http://mail.python.org/mailman/listinfo/python-list
Alf P. Steinbach wrote:
* Dave
Angel -> seafoid:
One other point: you should always derive a class from some other
class, or 'object' by default. So you should being the class
definition by:
class Seq(object):
Why? It mainly has to do with super(). But in any case if you omit
the 'o
* Dave Angel -> seafoid:
One other point: you should always derive a class from some other
class, or 'object' by default. So you should being the class definition
by:
class Seq(object):
Why? It mainly has to do with super(). But in any case if you omit the
'object' it's an "old style"
seafoid wrote:
Hey Guys,
I have started to read over classes as a brief respite from my parsing
problem.
When a class is defined, how does the class access the data upon which the
class should act?
Example:
class Seq:
def _
Steve, that has indeed clarified matters!
Thanks!
--
View this message in context:
http://old.nabble.com/Creating-Classes-tp26848375p26849864.html
Sent from the Python - python-list mailing list archive at Nabble.com.
--
http://mail.python.org/mailman/listinfo/python-list
seafoid wrote:
> Hey Guys,
>
> I have started to read over classes as a brief respite from my parsing
> problem.
>
> When a class is defined, how does the class access the data upon which the
> class should act?
>
> Example:
>
> class Seq:
.
--
View this message in context:
http://old.nabble.com/Creating-Classes-tp26848375p26848375.html
Sent from the Python - python-list mailing list archive at Nabble.com.
--
http://mail.python.org/mailman/listinfo/python-list
On May 12, 4:45 am, samwyse wrote:
> Unfortunately, 'boilerplate()' uses the handlers that I provide when
> MetaBlog is instantiated.
In that case, the handler functions should be attributes of the
instance, not of the class. Do something like this:
class MetaBlog(object):
def __init__(self
On May 11, 9:01 pm, Carl Banks wrote:
> On May 11, 11:16 am, samwyse wrote:
>
> > Should I use a class decorator, or a metaclass?
>
> Here's the thing: unless you have advance knowledge of the methods
> defined by self.blog, you can't get the attr_list at class definition
> time, which means neit
On May 11, 11:16 am, samwyse wrote:
> I'm writing a class that derives it's functionality from mix-ins.
> Here's the code:
>
> def boilerplate(what): # This used to be a decorator, but all of
> the
> ##what = f.__name__ # function bodies turned out to be
> 'pass'.
> 'Validat
On May 11, 1:16 pm, samwyse wrote:
> I'm writing a class that derives it's functionality from mix-ins.
While waiting, I gave a try at using class decorators. Here's what I
came up with:
def add_methods(*m_list, **kwds):
def wrapper(klass):
for m_name in m_list:
def templ
I'm writing a class that derives it's functionality from mix-ins.
Here's the code:
def boilerplate(what): # This used to be a decorator, but all of
the
##what = f.__name__ # function bodies turned out to be
'pass'.
'Validate the user, then call the appropriate plug-in.'
En Sat, 29 Nov 2008 04:51:59 -0200, Carl Banks <[EMAIL PROTECTED]>
escribió:
On Nov 28, 11:51 pm, Carl Banks
Absolute versus relative imports don't have anything to do with the
issue here. PEP 328 concerns itself with imports relative to the
executing module in package space. It has nothing
On Nov 28, 11:51 pm, Carl Banks
> Absolute versus relative imports don't have anything to do with the
> issue here. PEP 328 concerns itself with imports relative to the
> executing module in package space. It has nothing to do with imports
> relative to the current directory in filename space.
On Nov 28, 2:59 pm, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Carl Banks <[EMAIL PROTECTED]> writes:
> > On Nov 28, 3:15 am, Ben Finney <[EMAIL PROTECTED]>
> > wrote:
> > > This is resolved in the Python 2.x series by implementing PEP 328
> > > http://www.python.org/dev/peps/pep-0328/>, such that the
Carl Banks <[EMAIL PROTECTED]> writes:
> On Nov 28, 3:15 am, Ben Finney <[EMAIL PROTECTED]>
> wrote:
> > This is resolved in the Python 2.x series by implementing PEP 328
> > http://www.python.org/dev/peps/pep-0328/>, such that the
> > search path for ‘import’ does *not* contain the current direct
On Nov 28, 3:24 am, Viktor Kerkez <[EMAIL PROTECTED]> wrote:
> On Nov 28, 9:35 am, Carl Banks <[EMAIL PROTECTED]> wrote:
>
> > However, I'm not so sure the effect of os.chdir() on the import path
> > is a good idea.
>
> I'm not actually using os.chidir(), I just used it here to create a
> clearer e
On Nov 28, 3:15 am, Ben Finney <[EMAIL PROTECTED]>
wrote:
> Carl Banks <[EMAIL PROTECTED]> writes:
> > I like to think that "import abc" always does the same thing
> > regardless of any seemingly unrelated state changes of my program,
> > especially since, as the OP pointed out, import is used as a
On Nov 28, 9:35 am, Carl Banks <[EMAIL PROTECTED]> wrote:
> However, I'm not so sure the effect of os.chdir() on the import path
> is a good idea.
I'm not actually using os.chidir(), I just used it here to create a
clearer example.
Here is the simplest representation of the problem:
http://www.n
Carl Banks <[EMAIL PROTECTED]> writes:
> I like to think that "import abc" always does the same thing
> regardless of any seemingly unrelated state changes of my program,
> especially since, as the OP pointed out, import is used as a means
> to ensure singleness. Thus, if I were designing the lang
On Nov 27, 11:42 am, Viktor Kerkez <[EMAIL PROTECTED]> wrote:
> Here is the situation:
>
> $ ls
> test
> $ cd test
> $ ls
> __init__.py data.py
> $ cat __init__.py
>
> $ cat data.py
> DATA = {}
>
> $ cd ..
> $ python>>> import os
> >>> from test.data import DATA
> >>> DATA['something'] = 33
> >>> o
On Nov 28, 12:32 am, "Chris Rebert" <[EMAIL PROTECTED]> wrote:
> The Python position on singletons is generally to just use a module
> instead (preferred), or apply the Borg
> pattern:http://code.activestate.com/recipes/66531/
The same problem appears if I use the module (as I pointed in the
firs
On Thu, Nov 27, 2008 at 2:36 PM, Viktor Kerkez <[EMAIL PROTECTED]> wrote:
> A better way to do this was http://pastebin.com/m1130d1fe :)
> --
> http://mail.python.org/mailman/listinfo/python-list
>
The Python position on singletons is generally to just use a module
instead (preferred), or apply th
A better way to do this was http://pastebin.com/m1130d1fe :)
--
http://mail.python.org/mailman/listinfo/python-list
But this means that there is no way to create a safe Singleton in
python, because the classes are also created twice.
This is the problem that I encountered. I created a complex
implementation of a Singleton pattern using metaclasses because I
needed the __init__ method to be called just once and
Viktor Kerkez <[EMAIL PROTECTED]> writes:
> Here is the situation:
>
> $ ls
> test
> $ cd test
> $ ls
> __init__.py data.py
> $ cat __init__.py
>
> $ cat data.py
> DATA = {}
>
> $ cd ..
> $ python
import os
from test.data import DATA
DATA['something'] = 33
os.chdir('test')
On Nov 27, 6:42 pm, Viktor Kerkez <[EMAIL PROTECTED]> wrote:
> Is this a bug?
It is not a bug: the dictionaries are different because they are
loaded from different modules.
>>> import os
>>> import test.data
>>> test.data
>>> os.chdir('test')
>>> import data
>>> data
>>> test.data is data
Fals
Viktor Kerkez wrote:
> Here is the situation:
>
> $ ls
> test
> $ cd test
> $ ls
> __init__.py data.py
> $ cat __init__.py
>
> $ cat data.py
> DATA = {}
>
> $ cd ..
> $ python
import os
from test.data import DATA
DATA['something'] = 33
os.chdir('test')
from data import
Here is the situation:
$ ls
test
$ cd test
$ ls
__init__.py data.py
$ cat __init__.py
$ cat data.py
DATA = {}
$ cd ..
$ python
>>> import os
>>> from test.data import DATA
>>> DATA['something'] = 33
>>> os.chdir('test')
>>> from data import DATA as NEW_DATA
>>> DATA
{'something': 33}
>>> NEW_DAT
37 matches
Mail list logo