On Fri, 21 Jan 2005 16:13:19 -0800, André wrote:
> Short version of what I am looking for:
>
> Given a class "public_class" which is instantiated a few times e.g.
>
> a = public_class()
> b = public_class()
> c = public_class()
>
> I would like to find out the name of the instances so that I co
Ryan Paul wrote:
> On Mon, 24 Jan 2005 13:19:45 +, Ryan Paul wrote:
>
> >
> > A working solution:
> >
> > class A:
> > pass
> >
> > a = A()
> > b = A()
> > c = A()
> >
> > [x for x,y in locals().items() if
> > hasattr(y,"__class__") and y.__class__ == A]
> >
>
> Just wanted to clarify, bec
Op 2005-01-24, Nick Coghlan schreef <[EMAIL PROTECTED]>:
> Steven Bethard wrote:
>> That is, you can just keep track of all the names of a Robot in the
>> Robot object. In the simple case, where there's only one name, you can
>> display it as such. In the more complicated case, where there's so
On Mon, 24 Jan 2005 13:19:45 +, Ryan Paul wrote:
>
> A working solution:
>
> class A:
> pass
>
> a = A()
> b = A()
> c = A()
>
> [x for x,y in locals().items() if
> hasattr(y,"__class__") and y.__class__ == A]
>
Just wanted to clarify, because I know that the intellectually deficient
Nick Coghlan wrote:
> Incidentally, this discussion made me realise the real reason why using a
> lambda to create a named
> function is evil:
>
> Py> def f(): pass
> ...
> Py> f.func_name
> 'f'
> Py> f = lambda: None
> Py> f.func_name
> ''
>
> I think I've heard that explanation before, but it
Steven Bethard wrote:
That is, you can just keep track of all the names of a Robot in the
Robot object. In the simple case, where there's only one name, you can
display it as such. In the more complicated case, where there's some
aliasing, you can display the multiple aliases. This means you
I have a similar problem. Here's what I do:
.def new_robot_named(name,indict=globals()):
. execstr = name + " = robot('" + name + "')"
. exec(execstr,indict)
.class robot(object):
. def __init__(self,name):
. self.name = name
. def sayhi(self):
. print "Hi! I'm %s!" % self.nam
Nick Coghlan wrote:
It also directly addresses the question of aliasing. Think about how
Steven's modified dictionary would react to this code:
pete = CreateRobot(2, 3)
dad = pete
dad.move()
pete.move()
If you'd like to handle these cases, but you don't want to have to
explain aliasing right off
Michael Tobis wrote:
> I have a similar problem. Here's what I do:
>
> .def new_robot_named(name,indict=globals()):
> . execstr = name + " = robot('" + name + "')"
> . exec(execstr,indict)
>
> .class robot(object):
> . def __init__(self,name):
> . self.name = name
>
> . def sayhi(se
Michael Tobis wrote:
I have a similar problem. Here's what I do:
.def new_robot_named(name,indict=globals()):
. execstr = name + " = robot('" + name + "')"
. exec(execstr,indict)
.class robot(object):
. def __init__(self,name):
. self.name = name
. def sayhi(self):
. print "Hi! I
Scott David Daniels wrote:
> André Roberge wrote:
> > Craig Ringer wrote:
> >
> >> On Fri, 2005-01-21 at 16:13 -0800, André wrote:
> >>
> >>> Short version of what I am looking for:
> >>>
> >>> Given a class "public_class" which is instantiated a few times
e.g.
> >>>
> >>> a = public_class()
> >>>
Nick Coghlan wrote:
> André wrote:
> > So, students will be able to write:
> > pete = CreateRobot(2, 3)
> > pete.move()
> >
> > learning about objects and methods.
> >
> > As for things like
> > for robot in robots:
> > do stuff
> >
> > that will be for my use only: drawing robots on the screen,
u
André wrote:
So, students will be able to write:
pete = CreateRobot(2, 3)
pete.move()
learning about objects and methods.
As for things like
for robot in robots:
do stuff
that will be for my use only: drawing robots on the screen, updating
the 'world' when robots pick stuff up, etc. My intention i
André wrote:
I have tried this exact example (using Python 2.3 if it makes any
difference) and what I got was:
robot None moved
robot None moved
I checked what I wrote, used cut & paste on your code, removing the
leading "junk", tried it again ... to no avail. :-(
Worked exactly as written for me,
Steven Bethard wrote:
> If you have access to the user module's text, something like this
might
> be a nicer solution:
>
> py> class Robot(object):
> ... def __init__(self):
> ... self.name = None
> ... def move(self):
> ... print "robot %r moved" % self.name
> ...
> py> cl
Andrà Roberge wrote:
Craig Ringer wrote:
On Fri, 2005-01-21 at 16:13 -0800, Andrà wrote:
Short version of what I am looking for:
Given a class "public_class" which is instantiated a few times e.g.
a = public_class()
b = public_class()
c = public_class()
I would like to find out the name of the inst
Jeremy Bowers wrote:
> On Fri, 21 Jan 2005 21:01:00 -0400, André Roberge wrote:
> > etc. Since I want the user to learn Python's syntax, I don't want
to
> > require him/her to write
> > alex = CreateRobot(name = 'alex')
> > to then be able to do
> > alex.move()
>
> This is just my opinion, but I'v
André Roberge <[EMAIL PROTECTED]> wrote:
> alex = CreateRobot()
> anna = CreateRobot()
>
> alex.move()
> anna.move()
H -- while I've long since been identified as a 'bot, I can assure
you that my wife Anna isn't!
Alex
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 21 Jan 2005 21:01:00 -0400, Andrà Roberge wrote:
> etc. Since I want the user to learn Python's syntax, I don't want to
> require him/her to write
> alex = CreateRobot(name = 'alex')
> to then be able to do
> alex.move()
This is just my opinion, but I've been involved with teaching new
pro
Andrà Roberge wrote:
Behind the scene, I have something like:
robot_dict = { 'robot' = CreateRobot( ..., name = 'robot') }
and have mapped move() to correspond to
robot_dict['robot'].move()
(which does lots of stuff behind the scene.)
I have tested robot_dict[] with more than one robot (each with
i
Steven Bethard wrote:
> André Roberge wrote:
> > Behind the scene, I have something like:
> > robot_dict = { 'robot' = CreateRobot( ..., name = 'robot') }
> > and have mapped move() to correspond to
> > robot_dict['robot'].move()
> > (which does lots of stuff behind the scene.)
> >
> > I have test
André wrote:
Steven Bethard wrote:
André wrote:
Using the method suggested by Steven Bethard, I *almost* got it
working
the way I would like.
[snip]
It looks like you want PrivateClass.dict updated every time that
globals() is updated.
yes, that is what I would like to do.
You can just use global
Andrà Roberge wrote:
Behind the scene, I have something like:
robot_dict = { 'robot' = CreateRobot( ..., name = 'robot') }
and have mapped move() to correspond to
robot_dict['robot'].move()
(which does lots of stuff behind the scene.)
I have tested robot_dict[] with more than one robot (each with
i
Steven Bethard wrote:
> André wrote:
> > Using the method suggested by Steven Bethard, I *almost* got it
working
> > the way I would like.
[snip]
>
> It looks like you want PrivateClass.dict updated every time that
> globals() is updated.
yes, that is what I would like to do.
>You can just use g
André wrote:
Using the method suggested by Steven Bethard, I *almost* got it working
the way I would like.
Here's my program:
===
.class PrivateClass(object):
.dict = {}
.def not_so_simple_method(self):
.for name in PrivateClass.dict.keys():
.if PrivateClass.dict[name] =
Using the method suggested by Steven Bethard, I *almost* got it working
the way I would like.
Here's my program:
===
.class PrivateClass(object):
.dict = {}
.def not_so_simple_method(self):
.for name in PrivateClass.dict.keys():
.if PrivateClass.dict[name] == self:
.
Craig Ringer wrote:
On Fri, 2005-01-21 at 16:13 -0800, Andrà wrote:
Short version of what I am looking for:
Given a class "public_class" which is instantiated a few times e.g.
a = public_class()
b = public_class()
c = public_class()
I would like to find out the name of the instances so that I could
André wrote:
Given the statement
a = public_class()
I would like to generate
my_dict['a'] = private_class()
so that one could write
a.apparently_simple_method()
and that, behind the scene, I could translate that as
my_dict['a'].not_so_simple_method()
as well as do things like
for name in my_dict:
On Fri, 2005-01-21 at 16:13 -0800, Andrà wrote:
> Short version of what I am looking for:
>
> Given a class "public_class" which is instantiated a few times e.g.
>
> a = public_class()
> b = public_class()
> c = public_class()
>
> I would like to find out the name of the instances so that I coul
Short version of what I am looking for:
Given a class "public_class" which is instantiated a few times e.g.
a = public_class()
b = public_class()
c = public_class()
I would like to find out the name of the instances so that I could
create a list of them e.g.
['a', 'b', 'c']
I've read the Python
30 matches
Mail list logo