J
jojoba
yes.
</F>
Thank you for the clear answer.
By the way, what exactly led you to this conclusion?
jojoba
yes.
</F>
Exactly the point that's being made. It's so easy just do it yourself:
banana={"name":"banana"}
Hey what is the name of my dictionary?
banana["name"]
But why build it into Python and force everyone else to do it, when
most of the time nobody cares what the name is, or they already know?
It's like forcing everybody everywhere always and forever to wear
"Hello My Name Is" tags.
i don't want to do anything sophisticated with this, i am really only
looking for a TITLE for my dictionary when i throw it in a tree editor
that i have built. And i do realize that its not possible now. I am just
pressing a point here.
Well, how are you passing the dictionary itself? You must have aI'm not sure how to dynamically pass the name of the dictionary without
hard coding it.
Steven said:how difficult would it be to assign a string name(s)
to an object upon creation (and upon referencing)?
Exactly the point that's being made. It's so easy just do it yourself:
banana={"name":"banana"}
Hey what is the name of my dictionary?
banana["name"]
But why build it into Python and force everyone else to do it, when
most of the time nobody cares what the name is, or they already know?
It's like forcing everybody everywhere always and forever to wear
"Hello My Name Is" tags.
On reflection, I'm wondering if we've been too harsh on Jojoba and not
thought this through, simply because "that's the way it's always been".
Functions have a __name__ attribute. So do classes and modules. Why are
these three objects "special" that they know the name they were created
with, when other objects don't? Python doesn't attempt to track what name
they are known at *now*, just the name they were born with.
jojoba said:By the way, what exactly led you to this conclusion?
Steven said:But an upside is that it would enable more useful error messages, at least
sometimes. Here's some trivial pseudo-code:
def foo(a):
assert len(a) > 10, "%s is too short" % a.__name__
y = "hello"
foo(y)
would display "AssertionError: y is too short".
why not "a is too short" ?
or for that matter, "x is to short" ?
Steven said:These are all valid responses too. But consider that when you get an
exception that says "a is too short", you often have to mentally change
gears and think about where a came from and what it is called in the
enclosing scope. After all, if the value of a is invalid, and the value of
a is set in the enclosing scope, it makes sense to refer to "the object
known locally as a" by the name it was known as when it was set.
But an upside is that it would enable more useful error messages, at least
sometimes. Here's some trivial pseudo-code:
def foo(a):
assert len(a) > 10, "%s is too short" % a.__name__
y = "hello"
foo(y)
would display "AssertionError: y is too short".
That's what tracebacks are for. You don't have to mentally change gears; you
just look.
jojoba said:given any dictionary, get a name for it.
Steven said:Here's a traceback. One of the arguments to spam() is too small. Can you
tell which one just by looking at the traceback?
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 6, in spam
File "<stdin>", line 5, in eggs
File "<stdin>", line 4, in beans
ValueError: x is too small
Of course you can't. x could be any one of a, b, c or d, and the traceback
doesn't give you enough information to tell which.
Fredrik said:the fact that despite all attempts to explain how things work, you're
still haven't realized that if you want the names of things, you should
pass *namespaces* to your object viewer, not individual objects.
And what im saying is that isnt it silly that we need pass an entire
namespace, when a much simpler notion would be to have each object know
its own name(s) (even if that name doesnt exist).
Now, here's where everyone tells me this isnt possible, and how my
statement implies that i have no idea whatsoever of how python
works....
And what im saying is that isnt it silly that we need pass an entire
namespace, when a much simpler notion would be to have each object know
its own name(s) (even if that name doesnt exist).
jojoba said:please note: in my above comment, i was completely disregarding any
notions of added costs that would be incurred to have such a feature,
and that in fact, such costs might actually nullify any other benefits
from having such a feature. Purely a what-if idea from a nascent python
programmer.
jojoba said:And what im saying is that isnt it silly that we need pass an entire
namespace, when a much simpler notion would be to have each object know
its own name(s) (even if that name doesnt exist).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.