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
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
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
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
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
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
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).
"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?
...
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
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
"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
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
"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
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
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
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
"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
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():
>.
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
"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
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
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
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"]
> .
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
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
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
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
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
>
> 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
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
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
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
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
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
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;
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
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
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 '
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
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
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
41 matches
Mail list logo