473,804 Members | 3,725 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

__name__ becoming read-write?



Did I hallucinate something about __name__ becoming read-write?

Not in alpha2.

Can't find the reference to this I thought I read - that it was
concluded to be necessary in connection with PEP318.

Better get my facts straight first....

But if true that would seem to solve the main objection to:

the_horrible_na me_I _need_to_call=t ransform(__f)

And would mean that a byproduct of the PEP318 implementation would go
50% toward obviating the need for a PEP318 implementation. At least
by one measure.

But the whole thing might be a hallucination.

Art
Jul 18 '05 #1
19 1812
Arthur wrote:
Did I hallucinate something about __name__ becoming read-write?


_Becoming_ read-write? When was it read-only?

Python 1.5.2 (#1, Jul 14 2004, 20:34:28) [GCC 3.2.3] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
class foo: pass .... foo.__name__ = 'bar'
foo.__module__ = 'baz'
foo

<class baz.bar at c5ee0>

--
Hallvard
Jul 18 '05 #2
Arthur <aj******@opton line.com> writes:
Did I hallucinate something about __name__ becoming read-write?
For functions? No, you didn't hallucinate that.
Not in alpha2.
Indeed. The changes were only checked in a couple of weeks ago.
They'll be in alpha3.
Can't find the reference to this I thought I read - that it was
concluded to be necessary in connection with PEP318.
It's something that's been nagging at me for ages, but it was a PEP
318-related comment that finally prodded me into writing the patch.
Better get my facts straight first....


Glad to be of service <wink>!

Cheers,
mwh

--
I've reinvented the idea of variables and types as in a
programming language, something I do on every project.
-- Greg Ward, September 1998
Jul 18 '05 #3
On 23 Aug 2004 16:50:22 +0200, Hallvard B Furuseth
<h.**********@u sit.uio.no> wrote:
Arthur wrote:
Did I hallucinate something about __name__ becoming read-write?


_Becoming_ read-write? When was it read-only?

Python 1.5.2 (#1, Jul 14 2004, 20:34:28) [GCC 3.2.3] on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
class foo: pass... foo.__name__ = 'bar'
foo.__module__ = 'baz'
foo<class baz.bar at c5ee0>


Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)]
on win32
def foo(): pass
foo.__name__='b ar'


Traceback (most recent call last):
File "<pyshell#3 >", line 1, in -toplevel-
foo.__name__='b ar'
TypeError: readonly attribute

I hope I'm not being stupid.

And what's with running 1.5.2 ;)

Art
Jul 18 '05 #4
Hallvard B Furuseth <h.**********@u sit.uio.no> writes:
Arthur wrote:
Did I hallucinate something about __name__ becoming read-write?


_Becoming_ read-write? When was it read-only?


When it was a function :-) Or a new style class in 2.2.

Cheers,
mwh

--
I never disputed the Perl hacking skill of the Slashdot creators.
My objections are to the editors' taste, the site's ugly visual
design, and the Slashdot community's raging stupidity.
-- http://www.cs.washington.edu/homes/k...shdot.html#faq
Jul 18 '05 #5
On Mon, 23 Aug 2004 14:49:41 GMT, Michael Hudson <mw*@python.net >
wrote:
Arthur <aj******@opton line.com> writes:
Did I hallucinate something about __name__ becoming read-write?


For functions? No, you didn't hallucinate that.
Not in alpha2.


Indeed. The changes were only checked in a couple of weeks ago.
They'll be in alpha3.


Thanks for confirming I am not hullicinating. This time, anyway.

My argument - obviously, I think - is that this as a stand-alone
change does enough to ease the pain of the current syntax, and is in
proportion to the problem.

The fact that some of think we are way, way out of proportion with the
direction now headed, having been previously established.

Art
Jul 18 '05 #6
On Mon, 23 Aug 2004 14:07:42 GMT, Arthur <aj******@opton line.com> wrote:


Did I hallucinate something about __name__ becoming read-write? Better get my facts straight first....

But if true that would seem to solve the main objection to: the_horrible_na me_I _need_to_call=t ransform(__f) And would mean that a byproduct of the PEP318 implementation would go
50% toward obviating the need for a PEP318 implementation. At least
by one measure.


No, it is now read-write, thanks to mwh. I think, though, that you're
misunderstandin g the difference between setting a local variable in
the function, called '__name__', and setting the actual __name__ of
the function object.
def foo(): pass .... foo.__name__ = 'bar'
foo.__name__ 'bar' def foo(): .... __name__ = 'bar'
.... foo.__name__ 'foo' foo.func_code.c o_names

('__name__',)
Jul 18 '05 #7
On Tue, 24 Aug 2004 01:40:29 +1000, Anthony Baxter
<an***********@ gmail.com> wrote:
On Mon, 23 Aug 2004 14:07:42 GMT, Arthur <aj******@opton line.com> wrote:


Did I hallucinate something about __name__ becoming read-write?

Better get my facts straight first....

But if true that would seem to solve the main objection to:

the_horrible_na me_I _need_to_call=t ransform(__f)

And would mean that a byproduct of the PEP318 implementation would go
50% toward obviating the need for a PEP318 implementation. At least
by one measure.


No, it is now read-write, thanks to mwh. I think, though, that you're
misunderstandi ng the difference between setting a local variable in
the function, called '__name__', and setting the actual __name__ of
the function object.


You are right. I did know this to be *possibly* true, but had no
implementation to test.

Though __doc__ (and I am sure other stuff) exhjibits the same
behavior, so there is no real excuse to be surprised.

This sabotages my approach, but only to the extent that we would still
need until after __f's def to know the name we are imposing on it.

Of course I am curious as to why, and what would be involved, and
wrong,. with merging the local variable and the actual name for these
special syntax items. It would seem to have merit on its own terms.

For example I had noticed to use string substition on a function doc I
needed to assign to __doc__ outside the function.

Unless I was hallucinating.

Though I would understand if you are not in tutorial mood, or mode.

Art

def foo(): pass... foo.__name__ = 'bar'
foo.__name__'bar' def foo():... __name__ = 'bar'
... foo.__name__'foo' foo.func_code.c o_names

('__name__', )


Jul 18 '05 #8
On Mon, 23 Aug 2004 15:58:26 GMT, Arthur <aj******@opton line.com> wrote:
Of course I am curious as to why, and what would be involved, and
wrong,. with merging the local variable and the actual name for these
special syntax items. It would seem to have merit on its own terms.

For example I had noticed to use string substition on a function doc I
needed to assign to __doc__ outside the function.


How would you envisage this working? Look at the following code:

def foo(arg):
__doc__ = "bingle!"
if arg < 0:
__doc__ = "bangle!"
if arg > 0:
__doc__ = "bongle!"

Now, _before_ this code is run, what's foo.__doc__ supposed to be set
to? Remember, at this point, the code has not been run. The local
__doc__ has no value at this point.

Special casing __doc__ (or __name__) so that assignments to a local
like that inside a function assign magically to the function object is
bad magic. It leads to confusion and poor coding. In general, inside a
function, you don't have access to the function object itself[1]

Anthony

[1] I except using sys._getframe() , or raising an exception and
traversing up through the traceback object, as they're hacks.
Jul 18 '05 #9
On Tue, 24 Aug 2004 02:28:09 +1000, Anthony Baxter
<an***********@ gmail.com> wrote:
On Mon, 23 Aug 2004 15:58:26 GMT, Arthur <aj******@opton line.com> wrote:
Of course I am curious as to why, and what would be involved, and
wrong,. with merging the local variable and the actual name for these
special syntax items. It would seem to have merit on its own terms.

For example I had noticed to use string substition on a function doc I
needed to assign to __doc__ outside the function.


How would you envisage this working? Look at the following code:

def foo(arg):
__doc__ = "bingle!"
if arg < 0:
__doc__ = "bangle!"
if arg > 0:
__doc__ = "bongle!"

Now, _before_ this code is run, what's foo.__doc__ supposed to be set
to? Remember, at this point, the code has not been run. The local
__doc__ has no value at this point.

Special casing __doc__ (or __name__) so that assignments to a local
like that inside a function assign magically to the function object is
bad magic. It leads to confusion and poor coding. In general, inside a
function, you don't have access to the function object itself[1]

I see the point.

But.. there is always a but.

I'm thinking now a special sytnax item in the __form__ at the top of
function that would:

1) put one on notice that the function is to be transformed (as in
"see below").

2) allow a name to be assigned to it, which will become the
transform's __name__.

Something in the general direction, I think, of where Paul Morrow's
instincts were going.

I like it.

And have no idea whether it is feasible.

Art
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
11460
by: Eli Stevens \(WG.c\) | last post by:
I have a question about proper Python style when it comes to having a main function in a module. I'm fairly new to Python - a few months of very-part-time tinkering (lots'o'Java at work, shrug); my apologies if this has been hashed out before. Random Googling didn't enlighten me, so instead I'll ask here. :) Take the following strmod.py (it's silly, I know): ---- import sys import getopt
5
2756
by: Ed Leafe | last post by:
I'm working on creating a generic runtime engine for the Dabo framework. Right now I'm focusing on Windows, since many of our potential users are running on that platform. I've got py2exe and Inno Setup running, so all that is well and good. My question concerns the ability to generically run scripts as if they were being run on an installed copy of Python. Many scripts have the following structure: if __name__ == "__main__":
6
2256
by: gong | last post by:
hi i recently looked at alexandrescu's book on c++, and i found it pretty much unintelligible. i have a few points which i wonder about. 1. as a developer, it is important, from a bottom line standpoint, to make code as transparent as possible. through its lifecycle, code inevitably becomes larger and more complex to cope with unexpected demands. if the starting point looks like alexandrescu's code, it will require very specialized...
7
1401
by: Jim Michaels | last post by:
This is a simple coding tip I learned to prevent comparisons from becoming assignments (and this becoming a hair-pulling session during debugging): in comparisons, try to put your constants on the left hand side of the operator and variables on the right hand side. example if (3==$x) { //do something }
3
2534
by: aspmonger | last post by:
Hello, I really believe that IE 6 has a new (intentional?) bug that severely limits the capability of dhtml and cross domain scripting. Yesterday, I read an interesting article about the subject and it only supported my claim. The article explained why Microsoft will not be letting the IE DHTML Implementation get any more powerful than it already is. Microsoft has realized that an experienced DHTML developer can create a web application that...
4
3180
by: alf | last post by:
Hi, is there a more elegant way to get o.__class__.__name__. For instance I would imagine name(o). -- alf
3
2302
by: johnny | last post by:
What is the purpose of if __name__ == "__main__": If you have a module, does it get called automatically?
4
3515
by: gtb | last post by:
Hi, I often see the following 'if' construct in python code. What does this idiom accomplish? What happens if this is not main? How did I get here if it is not main? Thanks, gtb
16
5907
by: Singulus | last post by:
Hello all, I've searched for similar threads, I've found some bit of useful info here and there, but nevertheless I want to post my questions...So, how can I (we, in fact the forum can benefit from the discussion, this is the point here) become C++ gurus? I have 5 years of working experience with C/C++, I know that this can be very ambiguous thing, but anyway...I've come to the point where I want to structure and organize my further...
8
2321
by: gtb | last post by:
The lines if __name__ == 'main': someClass().fn() appear at the end of many examples I see. Is this to cause a .class file to be generated? The last line of the sample below has a string parameter. When I
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10575
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10330
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10319
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.