Hi,
I have a simple class that subclasses list:
class CaListOfObj(list):
subclass of list
def __init__(self, *args, **kwargs):
list.__init__(self, *args, **kwargs)
a = CaListOfObj([1,2,3])
I want an instance method to be run EVERY time a is modified. Is this
possible?
Hi,
I have a simple class that subclasses a list:
class CaListOfObj(list):
subclass of list
def __init__(self, *args, **kwargs):
list.__init__(self, *args, **kwargs)
a= CaListOfObj([1,2,3])
Is it possible to have a method in the class that is called EVERY time
a is modified?
test
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I have a simple subclass of a list:
class CaListOfObj(list):
subclass of list
def __init__(self, *args, **kwargs):
list.__init__(self, *args, **kwargs)
a= CaListOfObj([1,2,3])
How do I write a method that does something EVERY time a is modified?
Thanks
--
Hi,
I'm not sure why this doesn't work:
dic_myinstances={}
class MyClass(object):
def __init__(self, id):
global dic_myinstances
if dic_myinstances.has_key(id):
self = dic_myinstances[id]
else:
dic_myinstances[id] = self
ins1 =
Hi,
I solved it myself! I realised that __new__ creates self prior to
init, so this works:
dic_myinstances={}
class MyClass(object):
def __new__(self,id):
global dic_myinstances
if dic_myinstances.has_key(id):
return dic_myinstances[id]
else:
Hi, yet again to myself!
I've realised after further testing and reading that I actually need
to do this:
dic_myinstances={}
class MyClass(object):
def __new__(cls,id):
global dic_myinstances
if dic_myinstances.has_key(id):
return dic_myinstances[id]
else:
how do I detect a change in a list of class instances?
from copy import deepcopy
class CaListOfObj(list):
subclass of list
def __init__(self, *args, **kwargs):
list.__init__(self, *args, **kwargs)
class CaClass(object):
pass
class CaData(object):
pass
Thanks.
All I want to know is whether the newlist, as a list of instances, is
modified. I thought equality was the way to go, but is there a simpler
way? How can I monitor the state of newlist and set a flag if it is
changed in anyway?
--
http://mail.python.org/mailman/listinfo/python-list
Thanks everyone for your replies. The language is Cache Object Script,
a language used in Intersystems Relational Dbase.
I think egbert's answer provides the simplest answer. It allows our
python interface to Cache to be almost identical to Cache Object
Script, with simeply the addition of (),
Hi,
My question probably reflects my misunderstanding of python objects,
but I would still like to know the answer.
The question is, is it possible for an instnace to have a value (say a
string, or integer) that can interact with other datatypes and be
passed as an argument?
The following code
Hi,
There was a mistake above, and then I'll explain what we're doing:
insCacheClass = CacheClass(oref)
insCacheProperty = CacheProperty(insOref,'Chapter')
should have been
insCacheClass = CacheClass(oref)
insCacheProperty = CacheProperty(insCacheClass ,'Chapter')
Now, to answer some
Thanks for your input. Here is my next version, which works very well,
but for one problem I explain below:
class CacheProperty(object):
def __init__(self, insCacheClass, name):
self.Name = name
self._bind_to_parent(insCacheClass)
self.__parent = insCacheClass
Hi Ben,
Could I also do something like the following? What does it mean to
store the parent class as a private variable in the child class?
class CacheProperty(object):
def __init__(self, obj, parent, properties=None):
self.__data = obj
self._parent = parent
Hi,
I am having trouble designing my classes.
I have two classes. The first one wraps around an old-style class
called oref
Class CacheClass(object):
def __init__(self, obj):
self.__data = obj
def __getattr__(self, attr):
return getattr(self.__data, attr)
The second
Hi,
Our class has its attributes set as classes, as in
MyClass.Phone.Value='34562346'
MyClass.Phone.Private=True
Inside the MyClass definition we have a function like this:
def MyFunc(self,clsProperty):
if clsProperty.Private:
print 'Private property'
else:
print
I have a problem I would like some advice on.
We have a Python binding to the Intersystems Cache OO database. It
provides an old style class in Python as an in memory instance of a
Cache class, and this is a intersystems.pythonbind.object type (= ipo).
The ipo class has three basic methods,
Hi,
Is is possible to have two classes, ClassA and ClassB, and
setattr(ClassA, 'xx',ClassB), AND to then have ClassA.xx store an
integer value as well, which is not part of ClassB?
e.g. If ClassB has two properties, name and address:
ClassA.xx=10
ClassA.xx.name = 'John'
ClassA.xx.address =
I have a ClassWrapper that wraps around a third party database object.
Each database object has a set of properties, like columns in a
relational database.
I want my wrapper to generate a property for each database object and
load its value into it.
Thus, in my database (which is an oodbms) say
We've looked at them a little. Cache is a native OO dbase, so there is
no ORM required. Cache does that for you behind the scenes if you need
it to. What I want is to translate Cache classes and properties into
Python classes and properties. We can only use class wrappers, because
cache uses old
properties into the class, but I
don't know how to do this. Any ideas?
George Sakkis wrote:
manstey wrote:
I have a ClassWrapper that wraps around a third party database object.
Each database object has a set of properties, like columns in a
relational database.
I want my wrapper
Hi,
I am using Python with Cache dbase, which provides pythonbind module,
and intersys.pythonbind.object types. But I can't create a class based
on this type:
import intersys.pythonbind
class MyClass(intersys.pythonbind.object):
pass
gives me the error: TypeError: Error when calling the
Hi,
Is there a neat way to write a function that can receive either a
string or a list of strings, and then if it receives a string it
manipulates that, otherwise it manipulates each string in the list?
That is, rather than having to send a list of one member
MyFunction(['var1']), I can send
Hi,
If I have a string, how can I give that string name to a python object,
such as a tuple.
e.g.
a = 'hello'
b=(1234)
and then a function
name(b) = a
which would mean:
hello=(1234)
is this possible?
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
But this doesn't work if I do:
a=object()
x='bob'
locals()[x] = a
How can I do this?
James Stroud wrote:
manstey wrote:
Hi,
If I have a string, how can I give that string name to a python object,
such as a tuple.
e.g.
a = 'hello'
b=(1234)
and then a function
name
Hi,
thanks for the suggestions. this is my problem:
I have a metadata file that another user defines, and I don't know
their structure in advance. They might have 300+ structures. the
metadata defines the name and the tuple-like structure when read by
python.
my program reads in the metadata
Hi,
thanks for the suggestions. this is my problem:
I have a metadata file that another user defines, and I don't know
their structure in advance. They might have 300+ structures. the
metadata defines the name and the tuple-like structure when read by
python.
my program reads in the metadata
Thanks Marc, that was very helpful.
Marc 'BlackJack' Rintsch wrote:
In [EMAIL PROTECTED], manstey wrote:
I often have code like this:
data='asdfbasdf'
find = (('a','f')('s','g'),('x','y'))
for i in find:
if i[0] in data:
data = data.replace(i[0],i[1
Hi,
I have a text file called a.txt:
# comments
[('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]
[('recId', 5), ('parse', {'pos': u'np', 'gen': u'm'})]
[('recId', 7 ), ('parse', {'pos': u'np', 'gen': u'm'})]
I read it using this:
filAnsMorph = codecs.open('a.txt', 'r', 'utf-8') #
Hi,
I often have code like this:
data='asdfbasdf'
find = (('a','f')('s','g'),('x','y'))
for i in find:
if i[0] in data:
data = data.replace(i[0],i[1])
is there a faster way of implementing this? Also, does the if clause
increase the speed?
Thanks,
Matthew
--
But what about substitutions like:
'ab' 'cd', 'ced' 'de', etc
what is the fastest way then?
Roel Schroeven wrote:
manstey schreef:
Hi,
I often have code like this:
data='asdfbasdf'
find = (('a','f')('s','g'),('x','y'))
for i in find:
if i[0] in data:
data
Hi,
If I have a tuple like this:
tupGlob = (('VOWELS','aeiou'),('CONS','bcdfgh'))
is it possible to write code using tupGlob that is equivalent to:
VOWELS = 'aeiou'
CONS = ''bcdfgh'
Thanks,
Matthew
--
http://mail.python.org/mailman/listinfo/python-list
That doesn't work. I just get an error:
x = eval(line.strip('\n'))
File string, line 1
[('recId', 3), ('parse', {'pos': u'np', 'gen': u'm'})]
SyntaxError: unexpected EOF while parsing
any other ideas?
Bruno Desthuilliers wrote:
manstey wrote:
Hi,
I have a text file called
Hi,
I often use:
a='yy'
tup=('x','yy','asd')
if a in tup:
...
but I can't find an equivalent code for:
a='xfsdfyysd asd x'
tup=('x','yy','asd')
if tup in a:
...
I can only do:
if 'x' in a or 'yy' in a or 'asd' in a:
...
but then I can't make the if clause dependent on changing
I know I can do it this way. I wanted to know if there was another way.
Fredrik Lundh wrote:
manstey [EMAIL PROTECTED] wrote:
but I can't find an equivalent code for:
a='xfsdfyysd asd x'
tup=('x','yy','asd')
if tup in a:
...
I can only do:
if 'x' in a or 'yy' in a or 'asd
I can't figure out why my code is not working. I thought I had the list
copied correctly:
Here is my code:
a=[[u'HF', []], [u')F', [u'75']], [u'RE', []], [u'C', []]]
b=a[:]
for index in reversed(range(0,len(a)-1)):
if '75' in b[index][1]:
b[index][1].remove('75')
Thanks very much. Deepcopy works fine, as does reversed(b). I thought I
needed the index number but I didn't.
Duncan Booth wrote:
manstey wrote:
for index in reversed(range(0,len(a)-1)):
if '75' in b[index][1]:
b[index][1].remove('75')
b[index][1].append('99')
What
Thanks very much. How large is *really* large for making pytables
worthwhile. Our python script generates an xml file of about 450Mb. Is
pytables worth using then?
--
http://mail.python.org/mailman/listinfo/python-list
Thanks. I didn't know eval could do that. But why do many posts say
they want a solution that doesn't use eval?
--
http://mail.python.org/mailman/listinfo/python-list
But will this work if I don't know parts in advance. I only know parts
by reading through the file, which has 450,000 lines.
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I am running a script that produces about 450,000 dictionaries. I tried
putting them into a tuple and then pickling the tuple, but the tuple
gets too big. Can I pickle dictionaries one after another into the same
file and then read them out again?
Cheers,
Matthew
--
Hi,
How do I convert a string like:
a={'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS': u'8'}
into a dictionary:
b={'syllable': u'cv-i b.v^ y^-f', 'ketiv-qere': 'n', 'wordWTS': u'8'}
Thanks, Matthew
PS why in Python is it so often easy to convert one way but not the
other?
--
Hi,
I have an xml file of about 140Mb like this:
book
record
...
wordpartWTS1/wordpartWTS
/record
record
...
wordpartWTS2/wordpartWTS
/record
record
...
wordpartWTS1/wordpartWTS
/record
/book
I want to traverse it from bottom to top and add another field to each
Hi,
Is there a clever way to see if two strings of the same length vary by
only one character, and what the character is in both strings.
E.g. str1=yaqtil str2=yaqtel
they differ at str1[4] and the difference is ('i','e')
But if there was str1=yiqtol and str2=yaqtel, I am not interested.
can
Hi Martin,
Thanks very much. Your def comma_separated_utf8(items): approach raises
an exception in codecs.py, so I tried = u, .join(word_info + parse +
gloss), which works perfectly. So I want to understand exactly why this
works. word_info and parse and gloss are all tuples. does str convert
in for loops like the following:
word='abcade'
for letter in word:
print letter
Is it possible to get the position of letter for any iteration through
the loop?
so for examlpe letter=='a', and I want to know if it is the first or
second 'a' in 'abcade'.
can i do this by looking at a
Hi Martin,
HEre is how I write:
input_file = open(input_file_loc, 'r')
output_file = open(output_file_loc, 'w')
for line in input_file:
output_file.write(str(word_info + parse + gloss)) # = three
functions that return tuples
(u'F', u'\u0254') are two of the many unicode tuple elements
I'm a newbie at python, so I don't really understand how your answer
solves my unicode problem.
I have done more reading on unicode and then tried my code in IDLE
rather than WING IDE, and discovered that it works fine in IDLE, so I
think WING has a problem with unicode. For example, in WING this
OK, I apologise for not being clearer.
1. Here is my input data file, line 2:
gn1:1,1.2 R)$I73YT R)[EMAIL PROTECTED]
2. Here is my output data file, line 2:
u'gn', u'1', u'1', u'1', u'2', u'-', u'R)$I73YT', u'R)$IYT',
u'R)$IYT', u'@', u'ncfsa', u'nc', '', '', '', u'f', u's', u'a', '',
'', '',
I am writing a program to translate a list of ascii letters into a
different language that requires unicode encoding. This is what I have
done so far:
1. I have # -*- coding: UTF-8 -*- as my first line.
2. In Wing IDE I have set Default Encoding to UTF-8
3. I have imported codecs and opened and
Hi,
I have a text file with about 450,000 lines. Each line has 4-5 fields,
separated by various delimiters (spaces, @, etc).
I want to load in the text file and then run routines on it to produce
2-3 additional fields.
I am a complete newbie to Python but I have the docs and done some
51 matches
Mail list logo