In article <4c495b50$0$28634$c3e8...@news.astraweb.com>,
Steven D'Aprano wrote:
>On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote:
>
>> On 7/22/10 7:47 PM, wheres pythonmonks wrote:
>[...]
>>> The truth is that I don't intend to use these approaches in anything
>>> serious. However, I've
On Fri, 23 Jul 2010 09:22:16 -0700, Stephen Hansen wrote:
> On 7/23/10 2:05 AM, Steven D'Aprano wrote:
>> On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote:
>>
>>> On 7/22/10 7:47 PM, wheres pythonmonks wrote:
>> [...]
The truth is that I don't intend to use these approaches in anythi
On 7/23/2010 4:10 AM, Steven D'Aprano wrote:
Using exec or friends to avoid the overhead of function calls is like
pushing your car to work to avoid the overhead of having to get in and
out of the car.
And, of course, exec *is* a function call (explicitly in 3.x, but
somewhere also in the inn
On 07/23/2010 07:13 PM, Thomas Jollans wrote:
> On 07/23/2010 12:34 AM, wheres pythonmonks wrote:
>> 2. Is there a better way to loopup by id? I'm not very familiar with
>> sys.exc_info, but creating the id->name hash each time seems like
>> overkill.
>
> I just had the most horrendous idea. Rea
On 07/23/2010 12:34 AM, wheres pythonmonks wrote:
> 2. Is there a better way to loopup by id? I'm not very familiar with
> sys.exc_info, but creating the id->name hash each time seems like
> overkill.
I just had the most horrendous idea. Really, looking up objects by ID,
or even swapping two obj
On 7/23/10 2:05 AM, Steven D'Aprano wrote:
> On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote:
>
>> On 7/22/10 7:47 PM, wheres pythonmonks wrote:
> [...]
>>> The truth is that I don't intend to use these approaches in anything
>>> serious. However, I've been known to do some metaprogrammi
wheres pythonmonks wrote:
Funny... just spent some time with timeit:
I wonder why I am passing in strings if the callback overhead is so light...
More funny: it looks like inline (not passed in) lambdas can cause
python to be more efficient!
import random
d = (['A','B'][random.randint(0,1)
Duncan Booth wrote:
Consider languages where you can easily write a swap function (or any other
function that updates its arguments). e.g. consider C or C#.
For C your function must take pointers to the variables, so when you call
swap you have to make this explicit by taking the address of
wheres pythonmonks wrote:
> Funny... just spent some time with timeit:
>
> I wonder why I am passing in strings if the callback overhead is so
> light...
>
> More funny: it looks like inline (not passed in) lambdas can cause
> python to be more efficient!
import random
d = [ (['A','B'
Steven D'Aprano wrote:
> On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote:
>
>> Thanks for pointing out that swap (and my swap2) don't work everywhere
>> -- is there a way to get it to work inside functions?
Consider languages where you can easily write a swap function (or any other
Funny... just spent some time with timeit:
I wonder why I am passing in strings if the callback overhead is so light...
More funny: it looks like inline (not passed in) lambdas can cause
python to be more efficient!
>>> import random
>>> d = [ (['A','B'][random.randint(0,1)],x,random.gauss(0,1))
On Thu, 22 Jul 2010 21:23:05 -0700, Stephen Hansen wrote:
> On 7/22/10 7:47 PM, wheres pythonmonks wrote:
[...]
>> The truth is that I don't intend to use these approaches in anything
>> serious. However, I've been known to do some metaprogramming from time
>> to time.
>
> Depending on how you d
On Thu, 22 Jul 2010 22:47:11 -0400, wheres pythonmonks wrote:
> Thanks for pointing out that swap (and my swap2) don't work everywhere
> -- is there a way to get it to work inside functions?
Not in CPython. In IronPython or Jython, maybe, I don't know enough about
them. But even if you got it to
On Jul 22, 7:47 pm, wheres pythonmonks
wrote:
> Thanks for pointing out that swap (and my swap2) don't work everywhere
> -- is there a way to get it to work inside functions?
Impossible without hacking the interpreter.
> "No offense, but you seem like you're still tying to be a hacker. If
> th
On 7/22/10 7:47 PM, wheres pythonmonks wrote:
> Thanks for pointing out that swap (and my swap2) don't work everywhere
> -- is there a way to get it to work inside functions?
>
> "No offense, but you seem like you're still tying to be a hacker. If
> that's what you want, fine, but generally speak
On Thu, 22 Jul 2010 18:34:11 -0400, wheres pythonmonks wrote:
> Okay -- so I promised that I would try the namespace mangling approach,
> and here's what I have come up with:
>
> Approach #1: Pass in the variables to be swapped as strings. (boring)
Boring and slow and stupid. It makes an inter
Thanks for pointing out that swap (and my swap2) don't work everywhere
-- is there a way to get it to work inside functions?
"No offense, but you seem like you're still tying to be a hacker. If
that's what you want, fine, but generally speaking (and particularly
for Python), you are going to have
On Jul 22, 3:34 pm, wheres pythonmonks
wrote:
> Okay -- so I promised that I would try the namespace mangling
> approach, and here's what I have come up with:
>
> Approach #1: Pass in the variables to be swapped as strings. (boring)
>
> >>> import sys
> >>> def swap(n1,n2):
>
> ... try:
> ...
On 7/22/10 3:34 PM, wheres pythonmonks wrote:
> Now, I want to make the above codes more "Pythonic" -- is there a way to:
>
> 1. Get the function's arguments from the perspective of the caller?
>
> def f(x):
> print "caller's view of x = %s" % callersview(x)
>
> Then, f(1+2+3) would yield:
>
Okay -- so I promised that I would try the namespace mangling
approach, and here's what I have come up with:
Approach #1: Pass in the variables to be swapped as strings. (boring)
>>> import sys
>>> def swap(n1,n2):
... try:
... raise RuntimeException()
... except:
... e,b,t = sys.exc_info
On Jul 14, 1:24 pm, Grant Edwards wrote:
> As of a few minutes ago, this thread had 48 postings on my news
> server.
>
> To paraphrase somebody famous:
>
> There are no such things as easy questions. There are, however,
> easy answers. And they're wrong.
Ha! This is the very re
On 2010-07-11, wheres pythonmonks wrote:
> I have some easy issues (Python 2.6)
As of a few minutes ago, this thread had 48 postings on my news
server.
To paraphrase somebody famous:
There are no such things as easy questions. There are, however,
easy answers. And they're wrong.
--
On 7/14/2010 12:06 PM, Ethan Furman wrote:
... Have you tried this?
--> def foo():
... print locals()
... blah = 'interesting'
... print locals()
...
--> foo()
{}
{'blah': 'interesting'}
As can be clearly seen, blah does not exist before the assignment -- the
*name* blah has not been *bound* t
On Wed, 14 Jul 2010 09:06:34 -0700, Ethan Furman wrote:
> Alf P. Steinbach /Usenet wrote:
[...]
>> Clearly when the exception is raised, referring to the variable, the
>> variable exists.
>
> You are the only one spouting nonsense. Have you tried this?
>
> --> def foo():
> ... print locals()
Alf P. Steinbach /Usenet wrote:
* MRAB, on 12.07.2010 00:37:
Alf P. Steinbach /Usenet wrote:
Of course there are variables, that's why the docs call them variables.
In Java a variable is declared and exists even before the first
assignment to it. In Python a 'variable' isn't declared and won
On Jul 12, 2010, at 15:55 , Alf P. Steinbach /Usenet wrote:
> * Rami Chowdhury, on 13.07.2010 00:14:
>> Perhaps I'm misunderstanding, but ...
>>
>> On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote:
>>>
>>> Existence of a variable means, among other things, that
>>>
>>> * You can use
* Steven D'Aprano, on 13.07.2010 01:34:
On Mon, 12 Jul 2010 20:28:49 +0200, Alf P. Steinbach /Usenet wrote:
As I see it it doesn't matter whether the implementation is CPython call
frame slots or that mechanism called something else or a different
mechanism called the same or a different mechan
* Steven D'Aprano, on 13.07.2010 01:50:
On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote:
Existence of a variable means, among other things, that
* You can use the value, with guaranteed effect (either unassigned
exception
or you get a proper value): in particul
On Mon, 12 Jul 2010 22:57:10 +0200, Alf P. Steinbach /Usenet wrote:
> Existence of a variable means, among other things, that
>
>* You can use the value, with guaranteed effect (either unassigned
>exception
> or you get a proper value): in particular, you won't be accessing a
>
On Mon, 12 Jul 2010 20:28:49 +0200, Alf P. Steinbach /Usenet wrote:
> As I see it it doesn't matter whether the implementation is CPython call
> frame slots or that mechanism called something else or a different
> mechanism called the same or a different mechanism called something
> different; wha
* Rami Chowdhury, on 13.07.2010 00:14:
Perhaps I'm misunderstanding, but ...
On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote:
Existence of a variable means, among other things, that
* You can use the value, with guaranteed effect (either unassigned exception
or you get a prop
Perhaps I'm misunderstanding, but ...
On Jul 12, 2010, at 13:57 , Alf P. Steinbach /Usenet wrote:
>
> Existence of a variable means, among other things, that
>
> * You can use the value, with guaranteed effect (either unassigned exception
>or you get a proper value)
Surely by that definiti
* Rhodri James, on 12.07.2010 22:19:
On Mon, 12 Jul 2010 13:56:38 +0100, bart.c wrote:
"Steven D'Aprano" wrote in
message news:4c3aedd5$0$28647$c3e8...@news.astraweb.com...
On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote:
That's interesting. So in Python, you can't tell what local variabl
On 7/12/2010 4:48 AM, bart.c wrote:
>>> def foo():
print("Before:", locals())
x = 0
print("After:", locals())
>>> foo()
Before: {}
After: {'x': 0}
That's interesting. So in Python, you can't tell what local variables a
function has just by looking at it's code:
You are being fooled by the
On Sun, 11 Jul 2010 18:17:49 +, Duncan Booth wrote:
> wheres pythonmonks wrote:
>
>> I'm an old Perl-hacker, and am trying to Dive in Python. I have some
>> easy issues (Python 2.6)
>> which probably can be answered in two seconds:
without going into details on how to do these things in py
On Mon, 12 Jul 2010 13:56:38 +0100, bart.c wrote:
"Steven D'Aprano" wrote in
message news:4c3aedd5$0$28647$c3e8...@news.astraweb.com...
On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote:
That's interesting. So in Python, you can't tell what local variables a
function has just by looking at
* Steven D'Aprano, on 12.07.2010 04:39:
On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote:
* MRAB, on 12.07.2010 00:37:
[...]
In Java a variable is declared and exists even before the first
assignment to it. In Python a 'variable' isn't declared and won't exist
until the firs
* sturlamolden, on 12.07.2010 16:59:
On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" wrote:
We're talking about defining a 'swap' routine that works on variables.
I did not miss the point. One cannot make a swap function that rebinds
its arguments in the calling stack frame. But a swap function
On 12 Jul, 07:51, "Alf P. Steinbach /Usenet" wrote:
> We're talking about defining a 'swap' routine that works on variables.
I did not miss the point. One cannot make a swap function that rebinds
its arguments in the calling stack frame. But a swap function can swap
values, given that the type i
On 2010-07-11, Thomas Jollans wrote:
> On 07/11/2010 08:45 PM, wheres pythonmonks wrote:
>> On #3: Sorry this is confusing, but I was browsing some struct array
>> code from numpy, in which one of the columns contained strings, but
>> the type information, supplied in numpy.array's dtype argument
"Steven D'Aprano" wrote in message
news:4c3aedd5$0$28647$c3e8...@news.astraweb.com...
On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote:
That's interesting. So in Python, you can't tell what local variables a
function has just by looking at it's code:
def foo(day):
if day=="Tuesday":
x=0
On Mon, 12 Jul 2010 09:48:04 +0100, bart.c wrote:
> That's interesting. So in Python, you can't tell what local variables a
> function has just by looking at it's code:
In the presence of "exec", you can't really tell *anything*.
>>> def f(s):
... exec s
... print locals()
...
>>> f("x =
"Alf P. Steinbach /Usenet" wrote:
> * sturlamolden, on 12.07.2010 06:52:
>> On 11 Jul, 21:37, "Alf P. Steinbach /Usenet"> +use...@gmail.com> wrote:
>>
>>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo.
>>> Python works like Java in this respect, that's all; neither Java nor
>>> P
"MRAB" wrote in message
news:mailman.591.1278900548.1673.python-l...@python.org...
Alf P. Steinbach /Usenet wrote:
def foo():
print( blah )
blah = "this is both an assignment and a declaration causing it to
exist"
foo()
Clearly when the exception is raised, referring to the
On 7/11/2010 1:48 PM, wheres pythonmonks wrote:
2. How can I write a function, "def swap(x,y):..." so that "x = 3; y
= 7; swap(x,y);" given x=7,y=3??
(I want to use Perl's Ref "\" operator, or C's&).
(And if I cannot do this [other than creating an Int class], is this
behavior limited to string
On Sun, 11 Jul 2010 21:52:17 -0700, sturlamolden wrote:
> On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" +use...@gmail.com> wrote:
>
>> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python
>> works like Java in this respect, that's all; neither Java nor Python
>> support 'swap'.
>
* sturlamolden, on 12.07.2010 06:52:
On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" wrote:
Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works like
Java in this respect, that's all; neither Java nor Python support 'swap'.
x,y = y,x
We're talking about defining a 'swa
On 7/11/10 7:25 PM, Alf P. Steinbach /Usenet wrote:
> The alleged facts etc. you're referring are just that, alleged, by you.
Two people come together and have a debate. Both present arguments. Both
present cases. In the end, they are still in disagreement.
You declare us, "religious", and theref
On 11 Jul, 21:37, "Alf P. Steinbach /Usenet" wrote:
> Oh, I wouldn't give that advice. It's meaningless mumbo-jumbo. Python works
> like
> Java in this respect, that's all; neither Java nor Python support 'swap'.
x,y = y,x
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, Jul 11, 2010 at 10:39 PM, Steven D'Aprano
wrote:
> On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote:
>
>> * MRAB, on 12.07.2010 00:37:
> [...]
>>> In Java a variable is declared and exists even before the first
>>> assignment to it. In Python a 'variable' isn't declared a
* MRAB, on 12.07.2010 04:09:
Alf P. Steinbach /Usenet wrote:
* MRAB, on 12.07.2010 00:37:
Alf P. Steinbach /Usenet wrote:
* Stephen Hansen, on 11.07.2010 21:00:
On 7/11/10 11:45 AM, wheres pythonmonks wrote:
Follow-up:
Is there a way to define compile-time constants in python and have
the
by
On Mon, 12 Jul 2010 03:12:10 +0200, Alf P. Steinbach /Usenet wrote:
> * MRAB, on 12.07.2010 00:37:
[...]
>> In Java a variable is declared and exists even before the first
>> assignment to it. In Python a 'variable' isn't declared and won't exist
>> until the first 'assignment' to it.
>
> That is
* Stephen Hansen, on 12.07.2010 04:02:
On 7/11/10 6:12 PM, Alf P. Steinbach /Usenet wrote:
However, as stated up-thread, I do not expect facts, logic or general
reasoning to have any effect whatsoever on such hard-core religious
beliefs.
Grow up, and/or get a grip, and/or get over yourself.
E
Alf P. Steinbach /Usenet wrote:
* MRAB, on 12.07.2010 00:37:
Alf P. Steinbach /Usenet wrote:
* Stephen Hansen, on 11.07.2010 21:00:
On 7/11/10 11:45 AM, wheres pythonmonks wrote:
Follow-up:
Is there a way to define compile-time constants in python and have the
bytecode compiler optimize away
On 7/11/10 6:12 PM, Alf P. Steinbach /Usenet wrote:
> However, as stated up-thread, I do not expect facts, logic or general
> reasoning to have any effect whatsoever on such hard-core religious
> beliefs.
Grow up, and/or get a grip, and/or get over yourself.
Everyone who disagreed with you, disa
* MRAB, on 12.07.2010 00:37:
Alf P. Steinbach /Usenet wrote:
* Stephen Hansen, on 11.07.2010 21:00:
On 7/11/10 11:45 AM, wheres pythonmonks wrote:
Follow-up:
Is there a way to define compile-time constants in python and have the
bytecode compiler optimize away expressions like:
if is_my_extra
Alf P. Steinbach /Usenet wrote:
* Stephen Hansen, on 11.07.2010 21:00:
On 7/11/10 11:45 AM, wheres pythonmonks wrote:
Follow-up:
Is there a way to define compile-time constants in python and have the
bytecode compiler optimize away expressions like:
if is_my_extra_debugging_on: print ...
when
Chris Rebert wrote:
> On Sun, Jul 11, 2010 at 2:08 PM, News123 wrote:
>> Carl Banks wrote:
>>> On Jul 11, 10:48 am, wheres pythonmonks
>>> wrote:
I'm an old Perl-hacker, and am trying to Dive in Python.
>>> Welcome to the light.
>>>
>>>
I have some
easy issues (Python 2.6)
wh
On Sun, Jul 11, 2010 at 2:08 PM, News123 wrote:
> Carl Banks wrote:
>> On Jul 11, 10:48 am, wheres pythonmonks
>> wrote:
>>> I'm an old Perl-hacker, and am trying to Dive in Python.
>>
>> Welcome to the light.
>>
>>
>>> I have some
>>> easy issues (Python 2.6)
>>> which probably can be answered
Carl Banks wrote:
> On Jul 11, 10:48 am, wheres pythonmonks
> wrote:
>> I'm an old Perl-hacker, and am trying to Dive in Python.
>
> Welcome to the light.
>
>
>> I have some
>> easy issues (Python 2.6)
>> which probably can be answered in two seconds:
>>
>> 1. Why is it that I cannot use prin
On Jul 11, 11:45 am, wheres pythonmonks
wrote:
> On #4: So there are some hacks, but not something as easy as "import
> unimportable" or an @noexport decorator. The underscore works, so
> does "del".
Careful. If you have a module that looks like this:
def foo():
bar()
def bar():
pri
On Jul 11, 10:48 am, wheres pythonmonks
wrote:
> I'm an old Perl-hacker, and am trying to Dive in Python.
Welcome to the light.
> I have some
> easy issues (Python 2.6)
> which probably can be answered in two seconds:
>
> 1. Why is it that I cannot use print in booleans?? e.g.:
>
> >>> True a
* Stephen Hansen, on 11.07.2010 21:00:
On 7/11/10 11:45 AM, wheres pythonmonks wrote:
Follow-up:
Is there a way to define compile-time constants in python and have the
bytecode compiler optimize away expressions like:
if is_my_extra_debugging_on: print ...
when "is_my_extra_debugging" is set t
On 07/11/2010 08:45 PM, wheres pythonmonks wrote:
> Thanks for your answers -- it is much appreciated.
>
> On #1: I had very often used chained logic with both logging and
> functional purposes in Perl, and wanted to duplicate this in Python.
> "It reads like english" Using the print_ print wrap
On 7/11/10 11:45 AM, wheres pythonmonks wrote:
> Follow-up:
> Is there a way to define compile-time constants in python and have the
> bytecode compiler optimize away expressions like:
>
> if is_my_extra_debugging_on: print ...
>
> when "is_my_extra_debugging" is set to false? I'd like to pay no
Thanks for your answers -- it is much appreciated.
On #1: I had very often used chained logic with both logging and
functional purposes in Perl, and wanted to duplicate this in Python.
"It reads like english" Using the print_ print wrapper works for me.
Follow-up:
Is there a way to define compi
On 7/11/10 10:48 AM, wheres pythonmonks wrote:
> I'm an old Perl-hacker, and am trying to Dive in Python. I have some
> easy issues (Python 2.6)
> which probably can be answered in two seconds:
>
> 1. Why is it that I cannot use print in booleans?? e.g.:
True and print "It is true!"
Becau
wheres pythonmonks wrote:
> I'm an old Perl-hacker, and am trying to Dive in Python. I have some
> easy issues (Python 2.6)
> which probably can be answered in two seconds:
>
> 1. Why is it that I cannot use print in booleans?? e.g.:
True and print "It is true!"
>
> I found a nice work-
On 07/11/2010 11:48 AM, wheres pythonmonks wrote:
> I'm an old Perl-hacker, and am trying to Dive in Python. I have some
> easy issues (Python 2.6)
> which probably can be answered in two seconds:
>
> 1. Why is it that I cannot use print in booleans?? e.g.:
True and print "It is true!"
Th
On 07/11/2010 07:48 PM, wheres pythonmonks wrote:
> I'm an old Perl-hacker, and am trying to Dive in Python. I have some
> easy issues (Python 2.6)
> which probably can be answered in two seconds:
>
> 1. Why is it that I cannot use print in booleans?? e.g.:
True and print "It is true!"
pr
I'm an old Perl-hacker, and am trying to Dive in Python. I have some
easy issues (Python 2.6)
which probably can be answered in two seconds:
1. Why is it that I cannot use print in booleans?? e.g.:
>>> True and print "It is true!"
I found a nice work-around using eval(compile(.,"","exec"))
71 matches
Mail list logo