edClass(*superclasses):
> pass
> item = MixedClass(**itemArgs)
> return item
>
> instance = foo(MyClass, {'a':1}, [Aclass, Bclass, Cclass])
>
> --
> Steven
I find type() is the better way to go because it allows you to name
the resulting class as we
class came from or, if I make the class a base
for a class in another module, the module where the sub-class is.
I am not familiar with the scope, pros or cons of globals() so I would
love to hear comments on this subject.
Cheers,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 21, 5:02 pm, Rafe <[EMAIL PROTECTED]> wrote:
> On Nov 21, 4:50 pm, Rafe <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > I'm getting this error:
> > # File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py",
> > lin
here you need a module attribute, not a module.
The next example is bad (again, IMO):
>>> from package.subpackage.module import ClassA
>>> ClassA()
It removes the name space and makes it harder to guess where it is
from. There is very little chance of overriding "module.ClassA", but
it would be easy to override just "ClassA":
Even worse!:
>>> from package.subpackage.module import ClassA as Foo
>>> Foo()
Talk about hiding the truth!
Hope this helps. importing isn't nearly as hard as it seems when first
using it. Just put your package in the python path and start importing
away. It should be quite logical if kept simple.
If you have to add things to the python path using sys.path, only add
the top level of the package.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
In the name of self-education can anyone share some pointers, links,
modules, etc that I might use to begin learning how to do some
"metaprogramming". That is, using code to write code (right?)
Cheers,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
oked back since
(until now). I think you would just be adding a new self.a which
blocks access to your class.a, but I'm still shaky on this knowledge.
Instance attribute defaults would be inside __init__() and before
unpacking the *args.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
).
>
> Regards,
>
> John
I'm not sure if you are asking a technical question or a design
question. If it helps, I try to think of an object as a thing which
has a job to do. If the 'thing' needs information every time to define
what it is, or give it a starting state, then that is an argument of
__init__() . If I want the object to change or handle something which
is a logical task of 'thing', then I give it what it needs via
properties or methods (I find I almost never use "public" instance
attributes, but then again I am usually writing SDKs which is all
about interface).
Not sure if that helps...
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 25, 5:41 pm, Aaron Brady <[EMAIL PROTECTED]> wrote:
> On Nov 25, 4:08 am, Rafe <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > In the name of self-education can anyone share some pointers, links,
> > modules, etc that I might use to begin learning how to
ays in the same module as the code that calls it (watch out for
inheritance across more than one module though. This can put the
globals() call in a different module.)
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
h my own custom tools.
In a real situation the generated code file can build some pretty
complex 3D object hierarchies. It moves beyond simple storage of data
and becomes a real script that can be hacked as necessary.
It is nice to have everything as python scripts because we always have
a blend of GUI users and developers to get a job done.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 27, 12:11 pm, Rafe <[EMAIL PROTECTED]> wrote:
> On Nov 27, 11:41 am, "Hendrik van Rooyen" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > "Steven D'Aprano" wrote:
>
> > > Well, I don't know about "any problem". A
areas which are totally missing, but gets very time consuming to
maintain small changes.
What would be really great, is something which ties in to subversion
to display an easy to see and find alert in the docs when the source
has been updated. It would then require some manual action to hide the
alert (hopefully someone would read the doc again before killing the
alert).
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
choice and the
'*' import can really make things muddy if it isn't actually necessary
(rare). Why not just import the module and use what you need? It is
way easier to read/debug and maintains the name-space.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
ng a sub-package or converting
a module to a sub-package to break things down further. As someone who
recently started learning python, I would recommend that you just make
a quick sketch of what you think might work and then just begin
coding. Adjust to logic along the way.
At some p
file or
> directory
>
> Am I saving the file in the wrong spot?(I saved it in documents)
> Should I use a different editor? Is there a better python book
> available online?
if you go to the directory where you put the file and run the python
command, it should work (or sup
ce became humanly
recognizable. I also realize benchmarks should be taken with a grain
of salt since my setup may differ greatly from others'.
I guess, in the end, I'd use getattr() because it feels more pythonic,
and more basic. I got pretty deep in to learning python before I had
to learn what the globals() dict could do for me.
Cheers,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
's __getattr__ and __setattr__, but I
I am concerned about the overhead of every delegated attribute call
running a search and compare (.lower() based compare?).
Any ideas or precedence?
Cheers,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
__setattr__, but I was hoping for some nifty
workaround, maybe in the form of a decorator or something? Again...
any ideas?
Cheers,
- Rafe
On Oct 13, 4:15 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Rafe wrote:
> > Hi,
>
> > I'm working w
aise AttributeError("%s has no attribute '%s'." % (className,
name))
@property
def name(self):
"""
This doesn't do anything here, but in my real code it does.
The
problem is, if the user types 'Name' this
raise Exception(err)
# Don't allow addition of new 'public' attributes
# with AttributeError
className = self.__class__.__name__
msg = "%s has no attribute '%s'." % (className, name)
raise AttributeError(msg)
@property
_name, set_name)
# Usage...
class A(object):
name = "a name"
test = "a test"
a = A()
b = DelegationWrapper(a)
print b.name
print b.test
b.name = "new name"
print b.name
So is iterating through dir() to force both the members of dir(), and
the requested at
al-world
examples (which would be related to 3D animation production) I
wouldn't mind doing so at all. I was just trying really hard to keep
the question generic (and failed it seems).
Thanks again for sticking with the discussion!
- Rafe
On Oct 15, 4:03 am, Matimus <[EMAIL PROTECTED]&
hen
called, python enters __getattr__. If I correct the bug, the attribute
calls work as expected and do not call __getattr__.
I can't seem to make a simple repro. Can anyone offer any clues as to
what might cause this so I can try to prove it?
Cheers,
- Rafe
--
http://mail.python.org/mailman/
gt; I can't seem to make a simple repro. Can anyone offer any clues as to
> > what might cause this so I can try to prove it?
>
> You must subclass from "object" to get a new style class. properties
> don't work correctly on old style classes.
>
> Christian
All classes are a sub-class of object. Any other ideas?
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 24, 9:58 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> Rafe wrote:
> > On Oct 24, 2:21 am, Christian Heimes <[EMAIL PROTECTED]> wrote:
> >> Rafewrote:
> >> > Hi,
>
> >> > I've encountered a problem which is making debugging
On Oct 24, 9:58 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> Rafe wrote:
> > On Oct 24, 2:21 am, Christian Heimes <[EMAIL PROTECTED]> wrote:
> >> Rafewrote:
> >> > Hi,
>
> >> > I've encountered a problem which is making debugging
On Oct 24, 1:47 am, Rafe <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've encountered a problem which is making debugging less obvious than
> it should be. The @property decorator doesn't always raise exceptions.
> It seems like it is bound to the class but ignored when ca
ut 8 hours before sending the third time (and I posted to
GoogleGroups support as well). Even then I didn't see my original
post. I'm surprised it took so long to update. Next time I'll just
make sure the post was made successfully and wait...as long as it
takes.
Cheers,
- Rafe
O
exception which is not an
AttrbiuteError. Which brings me to my next question...
In case it isn't obvious, I'm fairly new to Python (and this level of
programming in general). I've been wondering about the optimal use of
custom exceptions. Up until now, I've been sticking to the built-in
exceptions, which seem to work in 90% of situations. Are you aware of
any resources which talk about this aspect of programming (more about
theory than code)?
Thanks again,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
tribute of an object), just use getattr().
Execute a 'method' (which is just a callable object right?) of an
instance of MyObject named "myCommand":
>>> class MyObject(object):
...def my_command(self):
...print "hello"
...
>>> myObject = MyObject()
>>> attr = getattr(myObject, "my_command")
>>> attr()
hello
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Oct 31, 5:21 pm, Ulrich Eckhardt <[EMAIL PROTECTED]> wrote:
> Rafe wrote:
> > I tried to post some follow-ups to some issues I posted in the hopes
> > of helping others, but I only get "reply to author" and "forward", but
> > no "reply"
I tried to post some follow-ups to some issues I posted in the hopes
of helping others, but I only get "reply to author" and "forward", but
no "reply" option (using GoogleGroups). Is there some kind of time
limit to reply?
Thanks,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
ittle more tricky because doing something like:
this_module = sys.modules[self.__class__.__module__]
will return a different module if the class is inherited in a
different module (since the base class is __class__ now). However,
putting a function at the module level (in the super-class module)
shoul
ents on the bugs or optimization pointers for my code. I
am still quite new to Python. My primary question though is: will
linecache.clearcache() cause me any problems?
Thanks,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 12, 2:22 pm, Rafe <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I think I have discovered two bugs with the inspect module and I would
> like to know if anyone can spot any traps in my workaround.
>
> I needed a function which takes a function or method and returns the
&
the code which creates the 'things' be
encapsulated in the 'thing's class or in a chain of functions? Is
there some design pattern in Python which would allow me to create a
new 'things' in different ways or access existing 'things' with the
same class, without dirtying the instance name-space (since the 'user'
will use an instance for access, but the 'system' would use it for
creation)? Or something else?
Let me know if I can clarify anything. This seems like a basic design
question when dealing with things created and accessed by an object
model, but the devil is in the details.
Thanks for reading,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 15, 1:29 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 12 Nov 2008 05:22:55 -0200,Rafe<[EMAIL PROTECTED]> escribió:
>
> > I think I have discovered two bugs with the inspect module and I would
> > like to know if anyone can spot any tr
ld come up a lot. Are there any design paradigms I
can apply here?
Cheers
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Nov 20, 2:06 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote:
> Rafe <[EMAIL PROTECTED]> writes:
> > Hi,
>
> > I am in a situation where I feel I am being forced to abandon a clean
> > module structure in favor of a large single module. If anyone can save
&
On Nov 21, 1:39 am, Steve Holden <[EMAIL PROTECTED]> wrote:
> Rafe wrote:
> > Hi,
>
> > I am in a situation where I feel I am being forced to abandon a clean
> > module structure in favor of a large single module. If anyone can save
> > my sanity here I would b
you add every module in your packages directly to the
sys.path. Doesn't this destroy the package name-spaces? For example, I
have a module called 'types' in my package if I add that to the python
path, 'import types' still returns the built-in 'types' modu
On Nov 21, 6:41 am, Stef Mientki <[EMAIL PROTECTED]> wrote:
> Christian Heimes wrote:
>
> thanks Christian,
>
> cheers,
> Stef
OT: Just to pass along some great advice I got recently. Read PEP008.
It contains guidelines for formatting your code.
- Rafe
--
http://mail.pyt
t; % word
>>> recursive_func(words)
>>> else:
>>> print "Done"
>>>
>>> words = ["one", "two", "three"]
>>> recursive_func(words)
Popped: three
Popped: two
Popped: one
Done
>>> words
['one', 'two', 'three']
Though I haven't been doing this long enough to know if that last
example has any drawbacks.
If we knew more about what you are trying to do, perhaps an
alternative would be even better.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
s to what might cause this? An error that is not an error
and only happens once?
I would show examples, but it is application-specific and wouldn't
help. I have been using this application for about 10 years, so i know
my usage is correct (especially since it works most times)
Che
On Nov 21, 4:17 pm, [EMAIL PROTECTED] wrote:
> I often use Python to write small programs, in the range of 50-500
> lines of code. For example to process some bioinformatics data,
> perform some data munging, to apply a randomized optimization
> algorithm to solve a certain messy problem, and many
On Nov 21, 4:50 pm, Rafe <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm getting this error:
> # File "C:\Python25\Lib\site-packages\win32com\client\dynamic.py",
> line 491, in __getattr__
> # raise pythoncom.com_error, details
> # COM Error: Unspecified
Forgive me if I mangle any terminology here, but please correct me if
I do...
I have an object which acts exactly like a string as long as I stay in
Python land. However, I am using the object in Softimage|XSI a 3D
application on Windows. It was created while (briefly) owned by
Microsoft, so knowl
The previous message was posted prematurely. Please ignore it. (I hit
enter witht he wrong focus I guess...no confirmation or edit
available? This was my first post.)
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
Forgive me if I mangle any terminology here, but please correct me if
I do...
I have an object which acts exactly like a string as long as I stay in
Python land. However, I am using the object in Softimage|XSI, a 3D
application on Windows. I'm getting variant erros when trying to use
my instances
ss which inherits
the Person class and has an attribute 'name' with the new value.
Basically using python as a text-based storage format instead of
something like XML. Thoughts on this would be great for me if it
doesn't hijack the thread ;) I know there a quite a few who have done
this already.
Cheers,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 15, 10:27 pm, Wolfgang Grafen <[EMAIL PROTECTED]>
wrote:
> Rafe schrieb:
>
> > Forgive me if I mangle any terminology here, but please correct me if
> > I do...
>
> > I have an object which acts exactly like a string as long as I stay in
> > Python
def _Get_state(self):
# Do some work before getting the state.
print "Getting the state using the child's method"
return self._state
print Child().state
Please share your thoughts,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 16, 1:25 am, Wolfgang Grafen <[EMAIL PROTECTED]>
wrote:
> Rafeschrieb:
>
> > On Aug 15, 10:27 pm, Wolfgang Grafen <[EMAIL PROTECTED]>
> > wrote:
> >>Rafeschrieb:
>
> >>> Now if I try to pass this as I would a string, roughly like so...
> >> s = StrLike("test")
> >> Application.AnObje
ou're making things much more complicated than they need to be.
Thanks Bruno, and everyone ! These are exactly the type of hard
answers I was hoping for. I'm mostly converted but my brain still
needs a Pythonic push from time to time. Looks like have some some
clean up to perform...with confidence.
I'm interested to see the implementation of getter, etc overrides in
2.6/3.0. I have two classes that could be simplified with this. For
example, I have a class which does a lot of work and has about 5 key
properties. I want to inherit it, and just trigger an event (update
something only stored in the child) after 4 of these attributes are
finished being set. I was thinking about using a callback which is
empty in the parent or __setattr__() (but I hat using this unless I
have to, it is still troublesome to me).
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
try:
somethingBad()
except TypeError, err:
pass
except Exception, err:
raise TypeError(err)
I suppose you could write a decorator to do this if you want it at the
function level, but that seems a bit to broad. Shouldn't exceptions be
on a case-by-case basis to add protection and return information
exactly where it is needed?
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
hance you might have missed the word "raise", e.g.
except Exception, err:
Exception(err)
vs.
except Exception, err:
raise Exception(err)
This is from the list of stupid things I have done myself,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
perties to a class just before returning the
instance using __new__():
class AClass(object):
def __new__(cls):
setattr(cls,"active", property(fget = ...,
fset = ...,
fdel = ...,
doc = ...))
obj = super(BaseGroup, cls).__new__(cls)
return obj
You can put this in a for loop and add a property per option, etc.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
namically add properties to a class just before returning
the
instance using __new__():
class AClass(object):
def __new__(cls):
setattr(cls,"propName", property(fget = ...,
fset = ...,
fdel = ...,
doc = ...) )
obj = super(AClass, cls).__new__(cls)
return obj
You can put this in a for loop and add a property per option, etc. You
can also do this with your own descriptor if you make a custom one.
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
s are determined by the database contents.
> """
>
> Care to elaborate ? I may be wrong, but I suspect you're trying to roll
> your own python/database mapper. If so, there are quite a couple Python
> ORMs around. Else, please tell us more.
I posted this to another thread, but...
You can dynamically add properties (or anything else) to a CLASS just
before returning the
instance using __new__():
class AClass(object):
def __new__(cls):
setattr(cls,"propName", property(fget = ...,
fset = ...,
fdel = ...,
doc = ...) )
obj = super(AClass, cls).__new__(cls)
return obj
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Aug 20, 12:47 am, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
> Rafe wrote:
> > Again, this is probably too simple to help, but the only way to ignore
> > certain types of exceptions, as far as I know, is to catch them and
> > pass.
> > e.g. this
it cost me two days of work before I realized it was
reload() causing this error and not super() or some other unknown-to-
me inheritance/package structure problem. I rebuilt my code module by
module until I noticed, quite by accident, that the thing worked once
and then never again! oh well, these are the joys of learning the
hard way.
I know this was a long one. If you made it this far, thanks for
reading,
- Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Sep 9, 11:03 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Mon, 08 Sep 2008 05:37:24 -0300,Rafe<[EMAIL PROTECTED]> escribió:
> ...
> This dependency between modules, applied to all modules in your project,
> defines a "dependency graph&qu
On Sep 10, 2:28 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
> En Wed, 10 Sep 2008 00:56:43 -0300,Rafe<[EMAIL PROTECTED]> escribió:
>
>
>
> > On Sep 9, 11:03 pm, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
> >&
> Finally, Python 3 introduced type annotations, which are currently a
> feature looking for a reason.
By type annotations, do you mean function annotations (see PEP 3107,
http://www.python.org/dev/peps/pep-3107/)? Or is this some other
feature that I'm unaware of?
Ra
; is easily
> read as "source code management" or "software configuration management" on
> a programming related list. There's also a Scheme implementation with that
> name.
>
> Stefan
That's how I read it -- I was interested because I thought the thread
tick with Tkinter because I was
proficient with it.
Rafe
--
http://mail.python.org/mailman/listinfo/python-list
and it doesn't seem as closely tied syntactically.
Of course, that's all opinion. But what's done is done; it's doubtful
that the decorator syntax will ever change significantly.
Rafe
--
http://mail.python.org/mailman/listinfo/python-list
me know if you're interested.
>
> Austin
In addition to trying here, try #python on Freenode. You're probably
more likely to find users there. You may also want to consider
expanding the geographic area if you don't have much luck (perhaps for
the region of Norway that Stavanger
te as soon as the fixes are available? I want to
know if I should be on the lookout for a better version of 3.2.
Rafe
--
http://mail.python.org/mailman/listinfo/python-list
On Feb 20, 8:15 am, Gerald Britton wrote:
> I see that Python 3.2 includes a new module -- html -- with a single
> function -- escape. I would like to know how this function differs
> from xml.sax.saxutils.escape and, if there is no difference (or only a
> minor one), what the need is for this ne
ox by a statement like,
>
> manu_item.connect('activate', lambda a: dialogs.open_dilaog())
>
> If this function open_dialog() returns a list of dialog inputs values,
> how can I access those values in the main module ?
Moreover, I don't see why you need a lambda in thi
On Feb 21, 7:59 pm, Steven D'Aprano wrote:
> On Mon, 21 Feb 2011 16:43:49 -0800, Rafe Kettler wrote:
> > On Feb 21, 1:59 pm, pradeepbpin wrote:
> >> I have a main program module that invokes an input dialog box via a
> >> menu item. Now, the code for drawing an
is very mature, it's a
matter of design. Python is a high-level, garbage-collected,
interpreted language, and that's not the ideal type of language for
embedded systems.
Rafe
--
http://mail.python.org/mailman/listinfo/python-list
73 matches
Mail list logo