Getting rid of "self."

2005-01-07 Thread BJörn Lindqvist
I think it would be cool if you could refer to instance variables without prefixing with "self." I know noone else thinks like me so Python will never be changed, but maybe you can already do it with Python today? .import sys . .def magic(): .s = "" .for var in sys._getframe(1).f_locals["s

getting rid of pass

2006-05-12 Thread David Murmann
Hi all! i just had this crazy idea: instead of while cond(): pass write while cond(). or try: import xyz except ImportError: pass compared to try: import xyz except ImportError. i don't know whether this is syntactically unambiguous or replaces all uses of pass, but i find

Re: Getting rid of "self."

2005-01-07 Thread Bruno Desthuilliers
BJörn Lindqvist a écrit : I think it would be cool if you could refer to instance variables without prefixing with "self." I know noone else thinks like me so Python will never be changed, but maybe you can already do it with Python today? (snip code) It works! exec(magic()) does the needed hi = se

Re: Getting rid of "self."

2005-01-07 Thread Nick Coghlan
BJörn Lindqvist wrote: So I'm asking here if someone knows a better way, maybe using decorators or metaclasses or other black magic? Wait for Python 3k when this will work: class c: def __init__(self): with self: .x = 1 .y = 2 .hi = "Hi there!" Cheers, Nick. -- Nick Coghlan

Re: Getting rid of "self."

2005-01-07 Thread Luis M. Gonzalez
You can do it easier now without any black magic: class c: def __init__(s): s.x = 1 s.y = 2 s.hi = "Hi there!" The word "self" is not mandatory. You can type anything you want instead of self, as long as you supply a keyword in its place (it can be "self", "s" or whatever you want). -- http://m

Re: Getting rid of "self."

2005-01-07 Thread Simon Brunning
On 7 Jan 2005 08:10:14 -0800, Luis M. Gonzalez <[EMAIL PROTECTED]> wrote: > The word "self" is not mandatory. You can type anything you want > instead of self, as long as you supply a keyword in its place (it can > be "self", "s" or whatever you want). You *can*, yes, but please don't, not if ther

Re: Getting rid of "self."

2005-01-07 Thread Roy Smith
Simon Brunning <[EMAIL PROTECTED]> wrote: >On 7 Jan 2005 08:10:14 -0800, Luis M. Gonzalez <[EMAIL PROTECTED]> wrote: >> The word "self" is not mandatory. You can type anything you want >> instead of self, as long as you supply a keyword in its place (it can >> be "self", "s" or whatever you want).

Re: Getting rid of "self."

2005-01-07 Thread John Roth
"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] I think it would be cool if you could refer to instance variables without prefixing with "self." I know noone else thinks like me so Python will never be changed, but maybe you can already do it with Python today? ...

Re: Getting rid of "self."

2005-01-07 Thread Michael Hobbs
Nick Coghlan <[EMAIL PROTECTED]> wrote: > > Wait for Python 3k when this will work: > > class c: > def __init__(self): > with self: > .x = 1 > .y = 2 > .hi = "Hi there!" Python is looking more like JavaScript every day... -- http://mail.python.org/mailman/listinfo/pytho

Re: Getting rid of "self."

2005-01-07 Thread BJörn Lindqvist
Thank you for your replies. But they don't deal with my original question. :) I have read the thousands of posts all saying "self is good" and they are right. But this time I want to be different m-kay? I figure that there might be some way to solve my problem by doing this: .def instancevar2local

Re: Getting rid of "self."

2005-01-07 Thread John Roth
"Roy Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Simon Brunning <[EMAIL PROTECTED]> wrote: On 7 Jan 2005 08:10:14 -0800, Luis M. Gonzalez <[EMAIL PROTECTED]> wrote: The word "self" is not mandatory. You can type anything you want instead of self, as long as you supply a key

Re: Getting rid of "self."

2005-01-07 Thread Roy Smith
In article <[EMAIL PROTECTED]>, John Roth <[EMAIL PROTECTED]> wrote: > >"Roy Smith" <[EMAIL PROTECTED]> wrote in message >news:[EMAIL PROTECTED] >> Simon Brunning <[EMAIL PROTECTED]> wrote: >>>On 7 Jan 2005 08:10:14 -0800, Luis M. Gonzalez <[EMAIL PROTECTED]> wrote: The word "self" is not ma

Re: Getting rid of "self."

2005-01-07 Thread Sean Ross
"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Thank you for your replies. But they don't deal with my original question. :) I have read the thousands of posts all saying "self is good" and they are right. But this time I want to be different m-kay? I figure that ther

Re: Getting rid of "self."

2005-01-07 Thread Jeremy Bowers
On Fri, 07 Jan 2005 14:39:09 +0100, BJÃrn Lindqvist wrote: > It works! exec(magic()) does the needed hi = self.hi. No it doesn't. Try "hi = 'newValue'" and see what happens. So the next step is to write an "unmagic" function. So now how do you add instance variables? There is no way to avoid "se

Re: Getting rid of "self."

2005-01-07 Thread Roy Smith
Jeremy Bowers <[EMAIL PROTECTED]> wrote: > were I programming in C++ routinely now I'd prefix "this" and > dispense with that ugly "m_" garbage. (One of the things I ***hate*** > about C++ culture is its acceptance of hideously ugly variable names, > but now I'm two parentheticals deep so I prob

Re: Getting rid of "self."

2005-01-07 Thread Nick Coghlan
Roy Smith wrote: It's actually kind of neat, but boy does it play headgames with me when I switch back and forth between that and Python. Switching back and forth betwen C++ and Python plays headgames *anyway* }:> Cheers, Nick. Hardware control with Python is nice. . . -- Nick Coghlan | [EMAIL

Re: Getting rid of "self."

2005-01-08 Thread Terry Reedy
"BJörn Lindqvist" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I think it would be cool if you could refer to instance variables >without prefixing with "self." Others have expressed such a wish -- this comes up perhaps once a year. The bottom line is that as long as Python has

Re: Getting rid of "self."

2005-01-09 Thread Tim Roberts
BJörn Lindqvist <[EMAIL PROTECTED]> wrote: >I think it would be cool if you could refer to instance variables >without prefixing with "self." I know noone else thinks like me so >Python will never be changed, but maybe you can already do it with >Python today? > >.import sys >. >.def magic(): >.

Re: Getting rid of "self."

2005-01-09 Thread Alex Martelli
BJörn Lindqvist <[EMAIL PROTECTED]> wrote: > I think it would be cool if you could refer to instance variables > without prefixing with "self." I know noone else thinks like me so Some do -- Kent Beck's excellent book on TDD-by-example has a specific grouse against that in the chapter where he de

Re: Getting rid of "self."

2005-01-09 Thread John Roth
"Alex Martelli" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] BJörn Lindqvist <[EMAIL PROTECTED]> wrote: I think it would be cool if you could refer to instance variables without prefixing with "self." I know noone else thinks like me so Some do -- Kent Beck's excellent book on TDD-b

Re: Getting rid of "self."

2005-01-09 Thread BJörn Lindqvist
Thank you for your replies. It is very nice to see that a thread you started is generating so much discussion, but please, I have read the previous debates so I know all about what people think about self. Spare the "you shouldn't do that" and "self is here to stay" replies to the threads in which

Re: Getting rid of "self."

2005-01-09 Thread Jeremy Bowers
var is local to the function or an instance member. For me, I prefer the explicit "self" and getting rid of "self" now leaves you with the need to declare member variables *somehow*, which I don't consider progress. But no matter what other magic Alex works, you're only g

Re: Getting rid of "self."

2005-01-10 Thread Alex Martelli
BJörn Lindqvist <[EMAIL PROTECTED]> wrote: ... > > http://starship.python.net/crew/mwh/hacks/selfless.py > > That's excellent! There is one small problem with the code though: It shows the fundamentals of how to rewrite the bytecode, yes. > .class Hi(Selfless): > .__attrs__ = ["x"] > .

Re: getting rid of pass

2006-05-12 Thread Terry Reedy
unction/statement. Many languages have the equivalent. Being explicit is Python's style. Getting rid of it would gratuitously break code for no reason other than your esthetic preference. > i don't know whether this is syntactically unambiguous or replaces all > uses of pass, bu

Re: getting rid of pass

2006-05-12 Thread John Machin
On 13/05/2006 11:40 AM, David Murmann wrote: > Hi all! > > i just had this crazy idea: You said it. > late-in-the-night idea. You said it again. > > what do you people think? I agree with you. -- http://mail.python.org/mailman/listinfo/python-list

Re: getting rid of pass

2006-05-13 Thread Bruno Desthuilliers
David Murmann a écrit : > Hi all! > > i just had this crazy idea: > > instead of > > while cond(): >pass > > write > > while cond(). Yuck > or > > try: >import xyz > except ImportError: >pass > > compared to > > try: >import xyz > except ImportError. Yuck again > i don't

getting rid of EOL character ?

2007-04-27 Thread stef
hello, In the previous language I used, when reading a line by readline, the EOL character was removed. Now I'm reading a text-file with CR+LF at the end of each line, Datafile = open(filename,'r') line = Datafile.readline() now this gives an extra empty line print line and what I

Re: getting rid of EOL character ?

2007-04-27 Thread Michael Hoffman
stef wrote: > hello, > > In the previous language I used, > when reading a line by readline, the EOL character was removed. > > Now I'm reading a text-file with CR+LF at the end of each line, >Datafile = open(filename,'r')line = Datafile.readline() > > now this gives an extra empty line

Re: getting rid of EOL character ?

2007-04-27 Thread stef
> > line = line.rstrip("\r\n") should take care of it. If you leave out > the parameter, it will strip out all whitespace at the end of the > line, which is what I do in most cases. thanks for the solution Michael, cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list

Re: getting rid of EOL character ?

2007-04-27 Thread Jim
If you have a recent Python, see the documentation for open on the library page for built-in functions. http://docs.python.org/lib/built-in-funcs.html Jim -- http://mail.python.org/mailman/listinfo/python-list

Re: getting rid of EOL character ?

2007-04-27 Thread Steven Howe
stef wrote: hello, In the previous language I used, when reading a line by readline, the EOL character was removed. Now I'm reading a text-file with CR+LF at the end of each line, Datafile = open(filename,'r') line = Datafile.readline() now this gives an extra empty line print li

Re: getting rid of EOL character ?

2007-04-27 Thread John Machin
On 27/04/2007 11:19 PM, Michael Hoffman wrote: > stef wrote: >> hello, >> >> In the previous language I used, >> when reading a line by readline, the EOL character was removed. Very interesting; how did you distinguish between EOF and an empty line? Did you need to call an isEOF() method before e

Re: getting rid of EOL character ?

2007-04-28 Thread Stef Mientki
hi John, >>> In the previous language I used, >>> when reading a line by readline, the EOL character was removed. > > Very interesting; how did you distinguish between EOF and an empty line? > Did you need to call an isEOF() method before each read? Yes indeed, and I admit it needs some more cod

Re: getting rid of EOL character ?

2007-04-28 Thread Michael Hoffman
John Machin wrote: > On 27/04/2007 11:19 PM, Michael Hoffman wrote: >> stef wrote: >>> hello, >>> >>> In the previous language I used, >>> when reading a line by readline, the EOL character was removed. > > Very interesting; how did you distinguish between EOF and an empty line? > Did you need to

Re: getting rid of EOL character ?

2007-04-28 Thread John Machin
On Apr 28, 7:25 pm, Michael Hoffman <[EMAIL PROTECTED]> wrote: > John Machin wrote: > > On 27/04/2007 11:19 PM, Michael Hoffman wrote: > >> stef wrote: > >>> hello, > > >>> In the previous language I used, > >>> when reading a line by readline, the EOL character was removed. > > > Very interesting;

getting rid of leading zeros in float expotential

2007-06-03 Thread tom
Hi! I'm wondering whether there's an easy way to remove unnecessary leading zeros from my floating point number. realS = float(-1.25e-5) imgS = float(-7.6e4) print complex(realS, imgS) >> (-1.25e-005-76000j) I would like it to look like (-1.25e-5-76000j) -- http://mail.python.org/mailman/lis

Re: getting rid of leading zeros in float expotential

2007-06-03 Thread [EMAIL PROTECTED]
On 3, 11:47, [EMAIL PROTECTED] wrote: > Hi! I'm wondering whether there's an easy way to remove unnecessary > leading zeros from my floating point number. > > realS = float(-1.25e-5) > imgS = float(-7.6e4) > > print complex(realS, imgS) > > >> (-1.25e-005-76000j) > > I would like it to look li

Re: [Python-Dev] Getting rid of unbound methods: patch available

2005-01-18 Thread Nick Coghlan
Guido van Rossum wrote: What do people think? (My main motivation for this, as stated before, is that it adds complexity without much benefit.) Something important that came up in my response to Marc-Andre: What about C method implementations which are relying on this typecheck and assuming that '

PEP proposal : Getting rid of the extension version/compiler dependency

2006-09-29 Thread Steve Menard
It's been observed a couple times recently ... distributing and compiling extensions is a pain, especially on windows, when the main supported compilers are not freely availble .. nor even commercially availble anymore. What we need is a way to break out of this dependency. A way for python ext

Getting rid of "close failed: [Errno 0] No Error" on Win32

2005-08-24 Thread Yoav
I am using os.popen3 to call a console process and get its output and stderr. However on Win32 (and not OS X) I also get the Errno message. It's printed to the screen, which I wish to keep clean. How can disable this notification? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting rid of "close failed: [Errno 0] No Error" on Win32

2005-08-25 Thread Yoav
Ok , I tried: try: os.popen3(...) except: as someone suggested here. And on FreeBSD I don't get the error message, and it works great. However, on Win32 I do get the annoying message. Any idea why? And How I can make it go away? thanks. Yoav wrote: > I am using os.popen3 to call a co