Re: EAFP gone wrong

2010-02-10 Thread Arnaud Delobelle
Malte Helmert  writes:

> Arnaud Delobelle wrote:
>
>> This means that EAFP made me hide a typo which would have been obviously
>> detected had I LBYLed, i.e. instead of
>> 
>> try:
>> return val.latex()
>> except AttributeError:
>> ...
>> 
>> do
>> 
>> if hasattr(val, 'latex'):
>> return val.latex()
>> else:
>> ...
>> 
>> 
>> So was it wrong to say it's EAFP in this case?
>
> I would say that it's not really the EAFP concept that is problematic
> here, but rather that the try block encompasses more code than it
> should. Generally try blocks should be as narrow as possible, i.e., they
> should contain only the part where you really want to catch a potential
> failure.
>
> "return val.latex()" does two separate things that might fail: the
> lookup of val.latex, and the actual method call. If I understood you
> correctly, you only want to catch the AttributeError in the "val.latex"
> lookup here, and hence I'd say the "correct" application of EAFP here
> would be something like:
>
> try:
> foo = val.latex
> except AttributeError:
> ...
> else:
> return foo()
>
> Whether that's any better than LBYL in this particular case is of course
> debatable -- one nice thing compared to your LBYL version is that it
> doesn't look up val.latex twice upon success. But you could also get
> that via the LBYLish:
>
> latex_method = getattr(val, "latex")
> if latex_method:
> return latex_method()
> 

Ben, Malte,

Thanks for your informative replies.  I can now see where my blind spot
was and that I never really used EAFP properly before.  I think I will
go with one of the two solutions above (probably the second) as I feel
it's a bit heavy handed to create a closure and perhaps call it every
time the latex() function is called.

Matthew,

You are right.  Believe me I am fully aware of this.  To my shame I have
many thousands lines of Python without any tests in this project and I
don't even know where to start...

Thanks again,

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Alf P. Steinbach

* Stephen Hansen:


On Tue, Feb 9, 2010 at 1:08 PM, Alf P. Steinbach > wrote:
[abundant snips which do not accurately represent who said what where 
due to my own laziness]


Not sure, but perhaps it's possible to mail directly
to gmane?

Is there *any* problem you don't have a fatuous answer for?

I thought the answer could help.

You thought you cold do a bit of ad hominem attack.

That's the difference between us.

Well, the way I see it, you assumed you knew better than
Stephen, and
insisted on proposing a solution to a problem that he clearly
stated he
had no interest in.


You're going into motivations, that it seems to me that you're
projecting, saying that any helpful suggestion mean that one thinks
one knows better and implies a desire to demonstrate imagined
superiority.

You're trying to portray a helping hand as a negative personal
characteristic of the helper.

"the only reason that guy tries to help you is because he wishes to
show how superior he (thinks he) is".

That's your style in a fair number of postings, and now here:

 * ad hominem attack,


I am, frankly, tired of this.

Please stop this overly obsessive sensitivity towards what you think are 
"ad hominem" attacks. Just drop it. Its worthless. It degrades you. Your 
arguments are frequently nothing more then, "I define the world this way 
and you do not disagree so I declare your argument invalid".


I'm happy that even though that may (with some low probability) be your actual 
opinion, it's incorrect.



You've 
dismissed at least one of my arguments with a simple hand-waving of, 
"That's invalid, cuz."


That is not a quote of me. It is a lie.


The thing is, there was no basis for 'cuz' beyond 
"In my own head this is what I think, this is how I'm defining words"


That's also a lie, and it's not a quote of me.

And just to be clear, as anyone can see by looking up-thread, generally, 
contrary to your claims, I give references for whatever that I suspect might be 
genuinely misunderstood.


And so I've done in (nearly) every article in the original thread, especially 
for the terms, and still people have posted articles apparently mis-interpreting 
those terms in very non-sensible ways  --  one gets tired of that, yes.



The response of others to such arguments has been, "Do you /really/ need 
to be so absolutely right in everything?!" which is said in frustration, 
irritation and with deep sighing. 


It's true that that kind of insinuative arguments have been used in this group, 
yes.

It goes to alleged motives and alleged history instead of the technical, that 
is, it is a purely personal attack.


So, ironically, you're here citing one kind of hominem attack  --  not exactly 
clever when you're arguing that such does not occur.



And then begins the loud declarations of ad hominem attacks. 


Its not productive. It doesn't help your case or arguments.

Its tired.

It doesn't make your case. It doesn't make anyone but you look bad. 
Every time you go on about, "YOU ARE AD HOMINEM'N ME!", you just make 
yourself look worse.


Yeah. People can be snarky in a community. Maybe... MAYBE... Steve 
Holden is periodically a little snarky at you. It is not without reason. 
And your declarations of his ad hominem attacks against you comes off as 
nothing but base /whining/.


Just drop it. 


Its boring.

Also...

I'm not quite sure, given that, what the point of the advice was.


There are many people who read just the Usenet group, e.g. via
Google groups.

When you say you don't understand the point of the advice, you're
saying that

 * those people don't matter, and that

 * it doesn't matter whether they can read Stephen Hansen's articles.

That's

 * slighting Stephen Hansen, and

 * showing off an extreme ego-centric view of the world,


Please do NOT presume to take up my defense on ANY level.

I can handle myself, thank you. 


I do offer unsolicited help now and then, as I gave you and for which Steve 
Holden decided that a bit of personal attack would be suitable.


But my help was just as much in order to help others (who can't read your 
non-propagated articles) as in order to help you personally. That's the spirit 
of Usenet in many other groups. One just helps out, and often the reaction is a 
"thank you" instead of an ad hominem attack (as with Steve Holden) or, as in 
your case, faked quotes and general lies, which is border-line ad hominem.


Anyway, please stop post faked quotes and general lies, as you do above.


Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Stephen Hansen
On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach  wrote:

> You've dismissed at least one of my arguments with a simple hand-waving of,
>> "That's invalid, cuz."
>>
>
> That is not a quote of me. It is a lie.
>
>
>
>  The thing is, there was no basis for 'cuz' beyond "In my own head this is
>> what I think, this is how I'm defining words"
>>
>
> That's also a lie, and it's not a quote of me.
>


On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach  wrote:
>
> Anyway, please stop post faked quotes and general lies, as you do above.


Wow. If that's your argument, I question your sanity.

None of the "quotes" were faked. None of the "quotes" were lies.

If a message were intended as an actual quotation of another's words, I'd
include actual citation. That a message is included in quotation-characters
does not make it an actual citation.

They are, quite obviously IMHO, paraphrased references to how I evaluate
your arguments.

The word "cuz" alone seems to make that very, very, very, very, very, very
obvious.

Get over yourself.

Seriously.

Quote marks don't make a quotation. If and when I choose to quote you, I
will quote you. You will see a line saying, as you see above, "On ,
Alf  wrote:"

>
>> I can handle myself, thank you.
>>
>
> I do offer unsolicited help now and then, as I gave you and for which Steve
> Holden decided that a bit of personal attack would be suitable.
>
> But my help was just as much in order to help others (who can't read your
> non-propagated articles) as in order to help you personally. That's the
> spirit of Usenet in many other groups. One just helps out, and often the
> reaction is a "thank you" instead of an ad hominem attack (as with Steve
> Holden) or, as in your case, faked quotes and general lies, which is
> border-line ad hominem.
>

I reject the assistance of you-- or anyone else-- to make my voice heard.

You do not speak for me.

You will not speak for me.

I speak for myself, thank you. Do not presume to subjugate my voice by
defending it for your purposes.

Anyway, please stop post faked quotes and general lies, as you do above.


I didn't. You're nuts if you think I did.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ternary plus

2010-02-10 Thread Mark Dickinson
On Feb 9, 6:47 pm, Martin Drautzburg  wrote:
> BTW I am not really trying to add three objects, I wanted a third object
> which controls the way the addition is done. Sort of like "/" and "//"
> which are two different ways of doing division.

That seems like a reasonable use case for a third parameter to
__add__, though as others have pointed out the only way to pass the
third argument is to call __add__ explicitly.  Here's an extract from
the decimal module:

class Decimal(object):

...

def __add__(self, other, context=None):
other = _convert_other(other)
if other is NotImplemented:
return other

if context is None:
context = getcontext()



...

And here's how it's used in the decimal.Context module:

class Context(object):

...

def add(self, a, b):
"""Return the sum of the two operands.

>>> ExtendedContext.add(Decimal('12'), Decimal('7.00'))
Decimal('19.00')
>>> ExtendedContext.add(Decimal('1E+2'), Decimal('1.01E+4'))
Decimal('1.02E+4')
"""
return a.__add__(b, context=self)

--
Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Stephen Hansen
>
> On Wed, Feb 10, 2010 at 12:13 AM, Alf P. Steinbach  wrote:
>
>> I do offer unsolicited help now and then, as I gave you and for which
>>> Steve Holden decided that a bit of personal attack would be suitable.
>>
>>
Really, I do have to say.

It's one thing to say, "Aren't you being rude?" (please note, this is not an
actual quotation of any actual person, and I feel it is required I make this
disclaimer since you have shown you are unable to differentiate a statement
paraphrased in quotation marks from an actual quotation and citation of
another's words)

It's another thing entirely to decide on your own to be my champion and
choose to speak for me in my defense.

The former is someone offering unsolicited help; the latter I find more then
a little insulting.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "if {negative}" vs. "if {positive}" style

2010-02-10 Thread Martin P. Hellwig

On 02/10/10 03:36, Tim Chase wrote:

Larry Hudson wrote:

But a minor rearrangement is simpler, and IMHO clearer:

if 'mystring' not in s:
print 'not found'
else:
print 'foundit'
print 'processing'


I've always vacillated on whether that would better be written as Larry
does, or as

if 'mystring' in s
print 'foundit'
print 'processing'
else:
print 'not found'





Any thoughts on how others make the choice?

I cases like this when aesthetics are not that much of a deal breaker, I 
usually put the condition which I think will be the true the majority of 
the time first.
This is not for performance reasons (never tested whether this has any 
effect) but more documentation like purpose to go from a most expected 
case to the least expected one. YMMV


--
mph
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ternary plus

2010-02-10 Thread Mark Dickinson
On Feb 10, 8:31 am, Mark Dickinson  wrote:
> And here's how it's used in the decimal.Context module:

Aargh!  decimal.Context *class*, not module.

And it occurs to me that it would have been cleaner to have
Decimal.__add__ call Context.add rather than the other way around.
Then Decimal.__add__ could have stayed a two-argument function, as
 intended.  Oh well.

--
Mark
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use strings to call functions

2010-02-10 Thread Klaus Neuner
On Feb 9, 11:01 am, Stefan Behnel  wrote:
> KlausNeuner, 09.02.2010 10:04:
>
> > my program is supposed to parse files that I have created myself and that
> > are on my laptop. It is not supposed to interact with anybody else
> > than me.
>
> Famous last words.
>
> Stefan

All right, I admit that eval() is evil and should never be used. Under
no circumstances. (Which is, of course, the reason, why Python has
eval().) The same applies to knives. You shouldn't use them. You
shouldn't even use them in your own kitchen. A man might enter your
kitchen, take your knife away and use it against you.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programing family

2010-02-10 Thread Bruno Desthuilliers

Steven D'Aprano a écrit :

On Tue, 09 Feb 2010 17:49:21 +0100, Bruno Desthuilliers wrote:


Not that much C++ in Python, IMHO. If that's for the OO part, then the
closer to Python's object model I can think of is javascript.


I thought that Javascript didn't even have inheritance until recently? 


If you mean "class inheritance", it's obviously not something you'd 
expect to find in a prototype based language. But inheritance works with 
prototypes too.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Peter Otten
[email protected] wrote:

> Does Python provide a way to format a string according to a
> 'picture' format?
> 
> For example, if I have a string '123456789' and want it formatted
> like '(123)-45-(678)[9]', is there a module or function that will
> allow me to do this or do I need to code this type of
> transformation myself?

A basic implementation without regular expressions:

>>> def picture(s, pic, placeholder="@"):
... parts = pic.split(placeholder)
... result = [None]*(len(parts)+len(s))
... result[::2] = parts
... result[1::2] = s
... return "".join(result)
...
>>>
>>> picture("123456789", "(@@@)-@@-(@@@)[...@]")
'(123)-45-(678)[9]'

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mac install

2010-02-10 Thread Ned Deily
In article 
,
 Thomas Nelson  wrote:

> I downloaded the 3.1.1 dmg from http://www.python.org/download/releases/3.1.1/
> but when I run it I get the error "The folowing install step failed:
> run postflight script for python documentation."  The bugs list has
> this bug at http://bugs.python.org/issue6934 but it's described as
> fixed.  Is it only fixed for the source version?  Where should I go to
> install?

Unfortunately, there hasn't been a release of Python 3.1 since 3.1.1.  
On the other hand, the problem isn't critical: it only prevents the 
installation from creating the .pyc compiled byte-code files for the 
python files in the standard library.  Python 3.1.1 should run just 
fine, albeit sometimes a bit slower, without them.

-- 
 Ned Deily,
 [email protected]

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Jean-Michel Pichavant

Quin wrote:
Thanks guys, I'm thinking it's a problem with IronPython.  I'm 
switching to PyScripter and will test tomorrow.



I'm willing to bet money that it is not. If ironPython had a broken if 
statement, don't you think we would have known, already ?


There's a rule when test writing/testing code:
"if you think the compiler is wrong, then you are wrong twice."

JM
--
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Quin
Well, PyScripter works find with that code.  Furthermore, the 
un-intellisense in IronPython was problematic, inserting the wrong things, 
which I had to erase.


Also, there were some code constructs IronPython let pass that PyScripter 
didn't, namely, print(), PyScripter requires the ()


Something simple, like:
n = -1
if n <> -1:
print('fell through')

falls through to the print.

So, I don't know what the problem is with IronPython, perhaps it isn't 
compatible with Python v3, but on my machine, at least, it doesn't perform.


"Steve Holden"  wrote in message 
news:[email protected]...

Quin wrote:

Thanks guys, I'm thinking it's a problem with IronPython.  I'm switching
to PyScripter and will test tomorrow.


I'd be very surprised to find that something as basic as this was wrong
with IronPython. Complex commercial software has been built on it, so
there's little question that the platform is sound.

Are you *sure* you copied and pasted the session you listed?

regards
Steve


"Larry Hudson"  wrote in message
news:[email protected]...

Quin wrote:

s = f.readline()
if 'mystring' in s: print 'foundit'
if 'mystring' not in s: print 'not found'
if 'mystring' in s:
   print 'processing'

this generates output:
not found
processing

so, it doesn't find the substring, but goes into processing code 
anyway.


This is using IronPython


As others have already said, this _does_ work properly.

But a minor rearrangement is simpler, and IMHO clearer:

if 'mystring' not in s:
print 'not found'
else:
print 'foundit'
print 'processing'

 -=- Larry -=-





--
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/



--
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Quin

Well, now you know!

"Jean-Michel Pichavant"  wrote in message 
news:[email protected]...

Quin wrote:
Thanks guys, I'm thinking it's a problem with IronPython.  I'm switching 
to PyScripter and will test tomorrow.



I'm willing to bet money that it is not. If ironPython had a broken if 
statement, don't you think we would have known, already ?


There's a rule when test writing/testing code:
"if you think the compiler is wrong, then you are wrong twice."

JM 


--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Olof Bjarnason
2010/2/10 Peter Otten <[email protected]>:
> [email protected] wrote:
>
>> Does Python provide a way to format a string according to a
>> 'picture' format?
>>
>> For example, if I have a string '123456789' and want it formatted
>> like '(123)-45-(678)[9]', is there a module or function that will
>> allow me to do this or do I need to code this type of
>> transformation myself?
>
> A basic implementation without regular expressions:
>
 def picture(s, pic, placeholder="@"):
> ...     parts = pic.split(placeholder)
> ...     result = [None]*(len(parts)+len(s))
> ...     result[::2] = parts
> ...     result[1::2] = s
> ...     return "".join(result)
> ...

 picture("123456789", "(@@@)-@@-(@@@)[...@]")
> '(123)-45-(678)[9]'
>
> Peter
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Inspired by your answer here's another version:

>>> def picture(s, pic):
...   if len(s)==0: return pic
...   if pic[0]=='#': return s[0]+picture(s[1:], pic[1:])
...   return pic[0]+picture(s, pic[1:])
...
>>> picture("123456789", "(###)-##-(###)[#]")
'(123)-45-(678)[9]'
>>>

-- 
http://olofb.wordpress.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Jean-Michel Pichavant

Quin wrote:

Well, now you know!

"Jean-Michel Pichavant"  wrote in message 
news:[email protected]...

Quin wrote:
Thanks guys, I'm thinking it's a problem with IronPython.  I'm 
switching to PyScripter and will test tomorrow.



I'm willing to bet money that it is not. If ironPython had a broken 
if statement, don't you think we would have known, already ?


There's a rule when test writing/testing code:
"if you think the compiler is wrong, then you are wrong twice."

JM 




All I know is that you are using a python implementation that does not 
support python 3. No wonder why your py3 code fails.


Please do not top post.

JM


   IronPython

   * Stable Version is 2.0.3 (targeting Python 2.5)
   * Developers Version is 2.6 Beta 3 (targeting Python 2.6)

--
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: obfuscate

2010-02-10 Thread Daniel Fetchinson
>> All algorithms in obfuscate are obsolete, insecure and only
>> interesting for people *that* want to get well educated in the history
>> of encryption.
>
> Not true. Another use case is suggested by the chosen name for the
> library: to obfuscate text against casual human reading, while not
> making it at all difficult to decrypt by people who are motivated to do
> so.
>
> The classic example is rot-13 encryption of text in internet messages;
> it would be a failure of imagination to suggest there are not other,
> similar use cases.

I fully agree. Judging by the posts on c.l.p the need for simple
obfuscation regularly comes up. I also posted something not so long
ago and got all sorts of useful advice, a package here, a module
there, etc. It also turned out that everybody mostly writes his/her
own obfuscation routine. That is why I suggested that perhaps if the
code base stabilizes an inclusion into the stdlib could be discussed.
I'm not sure it really needs to go there but if it turns out that as
many people need this kind of stuff as I imagine it, well, then we
have enough use cases for sure.

>> Grab pycrypto, m2crypto or one of the other packages if you need a
>> minimum amount of security.
>
> Agreed. However, for cases that *don't* need security from determined
> attackers, I don't think those obviate the usefulness of this library.

Exactly.

Cheers,
Daniel




-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "if {negative}" vs. "if {positive}" style (was: New to Python)

2010-02-10 Thread Simon Brunning
On 10 February 2010 03:36, Tim Chase  wrote:
> Any thoughts on how others make the choice?

There are two criteria that I use here. I'll often tend towards the
positive test; it's just that little bit easier to comprehend, I
think. On the other hand, if one case is overwhelmingly more common,
I'll usually put that first even if it does mean using a negative
test.

I'm not buying the short-case-first argument. If the code in a case
block is long enough for that to matter, it really belongs in a
function of its own anyway.

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: obfuscate

2010-02-10 Thread Simon Brunning
On 10 February 2010 01:24, Ben Finney  wrote:
> The classic example is rot-13 encryption of text in internet messages;
> it would be a failure of imagination to suggest there are not other,
> similar use cases.

That's built-in:

>>> "Hello World!".encode('rot-13')
'Uryyb Jbeyq!'

-- 
Cheers,
Simon B.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: obfuscate

2010-02-10 Thread Tim Golden

On 10/02/2010 11:23, Simon Brunning wrote:

"Hello World!".encode('rot-13')


Not any more!


Python 3.1.1 (r311:74483, Aug 17 2009,
win32
Type "help", "copyright", "credits" or

"Hello World!".encode('rot-13')

Traceback (most recent call last):
  File "", line 1, in 
LookupError: unknown encoding: rot-13







TJG
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Alf P. Steinbach

* Olof Bjarnason:

2010/2/10 Peter Otten <[email protected]>:

[email protected] wrote:


Does Python provide a way to format a string according to a
'picture' format?

For example, if I have a string '123456789' and want it formatted
like '(123)-45-(678)[9]', is there a module or function that will
allow me to do this or do I need to code this type of
transformation myself?

A basic implementation without regular expressions:


def picture(s, pic, placeholder="@"):

... parts = pic.split(placeholder)
... result = [None]*(len(parts)+len(s))
... result[::2] = parts
... result[1::2] = s
... return "".join(result)
...

picture("123456789", "(@@@)-@@-(@@@)[...@]")

'(123)-45-(678)[9]'

Peter
--
http://mail.python.org/mailman/listinfo/python-list



Inspired by your answer here's another version:


def picture(s, pic):

...   if len(s)==0: return pic
...   if pic[0]=='#': return s[0]+picture(s[1:], pic[1:])
...   return pic[0]+picture(s, pic[1:])
...

picture("123456789", "(###)-##-(###)[#]")

'(123)-45-(678)[9]'


I learned a bit by Peter Otten's example; I would have gotten to that notation 
sooner or later, but that example made it 'sooner' :-).


I think your version is cute.

I'd probably write it in a non-recursive way, though, like

def picture( s, pic, placeholder = "@" ):
result = ""
char_iter = iter( s )
for c in pic:
result += c if c != placeholder else next( char_iter )
return result

Of course this is mostly personal preference, but there is also a functional 
difference.


With your version an IndexError will be raised if there are too /many/ 
characters in s, while too few characters in s will yield "#" in the result.


With my version a StopIteration will be raised if there are to /few/ characters 
in s, while too many characters will just have the extraneous chars ignored.



Cheers,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: use strings to call functions

2010-02-10 Thread Bruno Desthuilliers

Klaus Neuner a écrit :


All right, I admit that eval() is evil and should never be used.


Can you tell the difference between your above statement and the following:

"""
eval() is potentially dangerous and can make code harder to debug. 99% 
of the proposed use case for eval() are covered by simpler, less 
dangerous and easier to understand solutions, so the GoodPractice(tm) is 
to favor these solutions and only use eval() - with appropriate care - 
for the remaining 1% _real_ use case.

"""

If you can't tell the difference, then you're about as (im)mature as my 
13 year old son and it might eventually be time to grow up.



The same applies to knives. You shouldn't use them. You
shouldn't even use them in your own kitchen. A man might enter your
kitchen, take your knife away and use it against you.


Knives - specially the kind I use in my kitchen - are indeed potentially 
dangerous, and I indeed had to educate my son so he wouldn't do anything 
stupid with them - like pointing a knife at someone, running across the 
house with a knife in his hand, or using them instead of a more 
appropriate tool.


The probability that someone will enter your kitchen and use one of your 
knives against you, while not null, are low enough to be ignored IMHO. I 
whish I could say the same about script kiddies or more educated (and 
dangerous) bad guys trying to attack our servers.


But you obviously never had to neither fix a compromised server nor 
raise a kid - else you'd now better. Hopefully you didn't raise my kid - 
now I just pray none of your code will ever run on our servers.

--
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Martin P. Hellwig

On 02/10/10 10:53, Jean-Michel Pichavant wrote:

Quin wrote:

Well, now you know!





All I know is that you are using a python implementation that does not
support python 3. No wonder why your py3 code fails.



You knew you known, you know :-)

--
mph
--
http://mail.python.org/mailman/listinfo/python-list


Generic spreadsheet interface

2010-02-10 Thread Phil Hibbs
I've currently got an Excel spreadsheet with loads of VBA, and I've
been thinking of porting it to OpenOffice.org. "This is a Python
list!" I hear you cry, but bear with me - rather than just re-writing
all the VBA code in OOo script, I thought, "why not make it generic -
so it can work with Excel or OOo?" - then I thought of Python. Python
can interface with both, but the specifics of how to interface with
each are very different. What would be nice is a generic wrapper class
that can work with either. Has anyone come across anything like that?

Phil Hibbs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dreaming of new generation IDE

2010-02-10 Thread Fuzzyman
On Feb 3, 7:38 pm, Phlip  wrote:
> On Feb 3, 10:57 am, Adam Tauno Williams 
> wrote:
>
> > > Current editors suck because they can't see into the code and browse
> > > it - unless it's so statically typed it's painful.
>
> > ?  I edit Python in MonoDevelop  2.2;  and I can browse my file,
> > classes, etc...  So I don't know what you mean by "can't see into the
> > code".  It works pretty well.
>
> > Of course it can't tell that I've set x = {an integer}, as that only
> > happens at runtime.
>
> > > That's why I wrote this:
> > >http://www.oreillynet.com/onlamp/blog/2008/05/dynamic_languages_vs_ed...
>
> You just said that your code browsing "works pretty well, except when
> it doesn't".
>
> Hence my blog entry. If your editor analyzed your code at runtime,
> instead of just static analysis, then it could see that x = an
> integer, or an object, no matter how dynamic your language.
>

The Wingware Wing IDE has an integrated debugger. The IDE does type
inferencing through static analysis to provide autocomplete and code
navigation features. If you run the code under the debugger it will
also use 'actual' type information to augment the static analysis.

Michael Foord

--
http://www.voidspace.org.uk/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Olof Bjarnason
2010/2/10 Alf P. Steinbach :
> * Olof Bjarnason:
>>
>> 2010/2/10 Peter Otten <[email protected]>:
>>>
>>> [email protected] wrote:
>>>
 Does Python provide a way to format a string according to a
 'picture' format?

 For example, if I have a string '123456789' and want it formatted
 like '(123)-45-(678)[9]', is there a module or function that will
 allow me to do this or do I need to code this type of
 transformation myself?
>>>
>>> A basic implementation without regular expressions:
>>>
>> def picture(s, pic, placeholder="@"):
>>>
>>> ...     parts = pic.split(placeholder)
>>> ...     result = [None]*(len(parts)+len(s))
>>> ...     result[::2] = parts
>>> ...     result[1::2] = s
>>> ...     return "".join(result)
>>> ...
>>
>> picture("123456789", "(@@@)-@@-(@@@)[...@]")
>>>
>>> '(123)-45-(678)[9]'
>>>
>>> Peter
>>> --
>>> http://mail.python.org/mailman/listinfo/python-list
>>>
>>
>> Inspired by your answer here's another version:
>>
> def picture(s, pic):
>>
>> ...   if len(s)==0: return pic
>> ...   if pic[0]=='#': return s[0]+picture(s[1:], pic[1:])
>> ...   return pic[0]+picture(s, pic[1:])
>> ...
>
> picture("123456789", "(###)-##-(###)[#]")
>>
>> '(123)-45-(678)[9]'
>
> I learned a bit by Peter Otten's example; I would have gotten to that
> notation sooner or later, but that example made it 'sooner' :-).
>
> I think your version is cute.

Thanks!

Here's another version (maybe a little more readable?):

def first(s): return s[0]

def rest(s): return s[1:]

def picture(s, pic):
  if not s: return pic
  if first(pic)=='#': return first(s)+picture(rest(s), rest(pic))
  return first(pic)+picture(s, rest(pic))


>
> I'd probably write it in a non-recursive way, though, like
>
>    def picture( s, pic, placeholder = "@" ):
>        result = ""
>        char_iter = iter( s )
>        for c in pic:
>            result += c if c != placeholder else next( char_iter )
>        return result
>
> Of course this is mostly personal preference, but there is also a functional
> difference.
>
> With your version an IndexError will be raised if there are too /many/
> characters in s, while too few characters in s will yield "#" in the result.
>
> With my version a StopIteration will be raised if there are to /few/
> characters in s, while too many characters will just have the extraneous
> chars ignored.
>
>
> Cheers,
>
> - Alf
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://olofb.wordpress.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Your beloved python features

2010-02-10 Thread Ricardo Aráoz
Bruce C. Baker wrote:
> "Terry Reedy"  wrote in message 
> news:[email protected]...
>   
>> Iterators, and in particular, generators.
>> A killer feature.
>>
>> Terry Jan Reedy
>>
>> 
>
> Neither unique to Python.
>
> And then're the other killer "features" superfluous ":"s and rigid 
> formatting! 
>   

H Let's see. nope, I could not find the "unique" word
neither in the subject or in the cited text.
I've had a strange feeling last weeks.
Two possible explanations come to mind :
a) The list is under a concerted troll attack.
b) Idiocy is contagious.

I wonder which...

P.S. : will the indentation of the choices be noticed? Shouldn't I put
them within braces?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Easter Eggs

2010-02-10 Thread rantingrick
On Feb 9, 5:40 pm, "Alf P. Steinbach"  wrote:
> I know 3 Python Easter Eggs,
>
>    from __future__ import braces
>    import this
>    help( "antigravity" )
>
> Are there more?
>
> Cheers,
>
> - Alf

Oh this is just great ALF! Now what secrets will the Py-Illuminati
have to giggle about whist watching Monty Python's flying circus and
enjoying those delightfully delicious little crumpets? I very
disappointed in you sir!  :'-(

PS WTF




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tangling with mathplotlib(MPL) on XP and Win7 -- show() stopper

2010-02-10 Thread W. eWatson
Solved. I need to get into the interactive mode. Never heard of it until 
this morning.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Personal criticisms and logical fallacies

2010-02-10 Thread Ben Finney
"D'Arcy J.M. Cain"  writes:

> On Wed, 10 Feb 2010 01:38:50 +0100
> "Alf P. Steinbach"  wrote:
> > However, although in this particular case the Ad Hominems
> > constituted logical fallacies, not all Ad Hominems are logical
> > fallacies.
>
> Yes they are.  Using the reputation of someone to prove or disprove
> their claims is a logical fallacy.

The trouble is, the bulk of statements Alf is calling “ad hominem
attack” are, if one actually reads them, a criticism of his person. Not
intended as a connecting claim in an argument, but a claim *distinct
from* the argument Alf is engaged in.

So they're *not intended* to prove or disprove the specific claims that
immediately precede them. They're intended, at least partly, to provoke
self-reflection on the part of the person criticised and, ideally, an
improvement in behaviour.

Failure to recognise a criticism as such, and instead repeatedly
flinging the term “ad hominem” around as though it has any bearing, is
an example of behaviour that could easily be improved, if only the
person engaging in it would stop.

-- 
 \  “You've got to think about big things while you're doing small |
  `\  things, so that all the small things go in the right |
_o__)   direction.” —Alvin Toffler |
Ben Finney
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure elapsed time under Windows?

2010-02-10 Thread Grant Edwards
On 2010-02-09, Grant Edwards  wrote:
> On 2010-02-09, Jean-Michel Pichavant  wrote:

>> Did you try with the datetime module ?
>
> No.  What mechanism does it use to get the current date/time?
>
>> import datetime
>> t0 = datetime.datetime.now()
>> t1 = t0 - datetime.datetime.now()
>> t1.microseconds
>> Out[4]: 644114
>
> That looks very broken to me.  I need to measure stuff in the
> 1-20ms range, and the smallest value you can measure using the
> method above appears to be 640ms.  Thats almost 2/3 of a second.

Duh.  It just occurred to me that was done interactively.  I'll
give the datetime module a try once I reboot my test machine
back into Windows.

-- 
Grant Edwards   grante Yow! Is this sexual
  at   intercourse yet??  Is it,
   visi.comhuh, is it??
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programing family

2010-02-10 Thread Paul Rubin
Bruno Desthuilliers  writes:
> Now you forgot the whole Lisp / ML heritage - most FP stuff -, and of
> course Simula and Smalltalk.

http://i.imgur.com/1gF1j.jpg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programing family

2010-02-10 Thread Gnarlodious
On Feb 9, 9:56 am, Paul Rubin wrote:

> http://i.imgur.com/1gF1j.jpg

Very funny, except where is Python and Forth?

-- Gnarlie
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use strings to call functions

2010-02-10 Thread Klaus Neuner
On Feb 10, 12:55 pm, Bruno Desthuilliers  wrote:
> KlausNeunera écrit :
>
>
>
> > All right, I admit that eval() is evil and should never be used.
>
> Can you tell the difference between your above statement and the following:

As already pointed out in my second post (though perhaps not
explicitly enough), I like the getattr-stuff better than eval(). That
is why I will not use eval(). I don't have a reason to use eval(). All
I wanted to say is this: If there are no circumstances at all under
which eval() can reasonably be used, then it should not be part of
Python. As it is part of Python (and as Python is a carefully designed
language), there will most probably some situations in which one might
want to use it.


-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: visvis v1.1

2010-02-10 Thread Almar Klein
Hi all,

I am pleased to announce version 1.1 of visvis, a Python
visualization library for of 1D to 4D data.

Website: http://code.google.com/p/visvis/
Discussion group: http://groups.google.com/group/visvis/
Documentation: http://code.google.com/p/visvis/wiki/Visvis_basics

=== Description ===

Visvis is a pure Python visualization library that uses OpenGl to
display 1D to 4D data; it can be used from simple plotting tasks to
rendering 3D volumetric data that moves in time.

Visvis can be used in Python scripts, interactive Python sessions (as
with IPython) and can be embedded in applications.

Visvis employs an object oriented structure; each object being
visualized (e.g. a line or a texture) has various properties that can
be modified to change its behavior or appearance. A Matlab-like
interface in the form of a set of functions allows easy creation of
these objects (e.g. plot(), imshow(), volshow()).

=== Changes ===
A complete list can be found at
http://code.google.com/p/visvis/wiki/releaseNotes.

- Colormaps are now supported for texture objects. A colorbar and
colormapEditor wibject are also available.
- The performance of rendering 3D volumes has significantly improved. A new
shader (raycast) is also available).
- Fonts are rendered more smoothly and faster.
- Data for textures is automatically padded to a factor two if necessary,
and down-sampled if too large to fit in OpenGl memory.
- Visvis now works for any OpenGl version from OpenGl 1.1 (some features
might not be supported for lower versions though).

Regards,
  Almar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure elapsed time under Windows?

2010-02-10 Thread Paul McGuire
On Feb 10, 2:24 am, Dennis Lee Bieber  wrote:
> On Tue, 9 Feb 2010 21:45:38 + (UTC), Grant Edwards
>  declaimed the following in
> gmane.comp.python.general:
>
> > Doesn't work.  datetime.datetime.now has granularity of
> > 15-16ms.
>
> > Intervals much less that that often come back with a delta of
> > 0.  A delay of 20ms produces a delta of either 15-16ms or
> > 31-32ms
>
>         WinXP uses an ~15ms time quantum for task switching. Which defines
> the step rate of the wall clock output...
>
> http://www.eggheadcafe.com/software/aspnet/35546579/the-quantum-was-n...http://www.eggheadcafe.com/software/aspnet/32823760/how-do-you-set-ti...
>
> http://www.lochan.org/2005/keith-cl/useful/win32time.html
> --
>         Wulfraed         Dennis Lee Bieber               KD6MOG
>         [email protected]     HTTP://wlfraed.home.netcom.com/

Gabriel Genellina reports that time.clock() uses Windows'
QueryPerformanceCounter() API, which has much higher resolution than
the task switcher's 15ms.  QueryPerformanceCounter's resolution is
hardware-dependent; using the Win API, and a little test program, I
get this value on my machine:
Frequency is 3579545 ticks/sec
Resolution is 0.279365114840015 microsecond/tick

-- Paul
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "if {negative}" vs. "if {positive}" style (was: New to Python)

2010-02-10 Thread Roy Smith
In article ,
 Tim Chase  wrote:

> Larry Hudson wrote:
> > But a minor rearrangement is simpler, and IMHO clearer:
> > 
> > if 'mystring' not in s:
> >  print 'not found'
> > else:
> >  print 'foundit'
> >  print 'processing'
> 
> I've always vacillated on whether that would better be written as 
> Larry does, or as
> 
>if 'mystring' in s
>  print 'foundit'
>  print 'processing'
>else:
>  print 'not found'
> 
> removing the "not" from the condition.  I admit I choose one over 
> the other based on some gut-feeling aesthetic that I can't really 
> nail down.  I think one of my major influencing factors revolves 
> around the negative "not" portion having one or two lines and the 
>   positive portion having a large block of code.  If the 
> code-blocks are more equal in size, I tend to use "if 
> {positive}", but if the negative "not" section is only 1-2 lines, 
> I tend to do as Larry writes and make it harder to miss by using 
> "if {negative}".  Otherwise the "if {positive}...else" can end up 
> sufficiently distant from the "if" that it's easy to miss.
> 
> Any thoughts on how others make the choice?
> 
> -tkc

In general, I try to avoid negation, because it makes things harder to 
understand.  When you write:

if not foo:
   blah
else:
   blah-blah

the else clause is executed if "not foo is not true".  That quickly gets 
confusing.

As for the code blocks being so large that the else becomes distant from 
the condition, that smells like the two codeblocks want to be refactored 
into distinct functions:

if foo:
   do_one_thing()
else:
   do_something_else()

It's not always practical, but my first reaction would be to try that and 
see if it works.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dreaming of new generation IDE

2010-02-10 Thread catonano
Vladimir,

On Feb 3, 12:10 pm, Vladimir Ignatov  wrote:
> Hello,
>
> I am sitting here for quite some time, but usually keep silent ;-) I


> Finally I develop a feeling that strong instrumentation / tools can
> bring us the best of two worlds. That I am dreaming on is an absolute
> new type/class of IDE suitable for Python and potentially for other
> dynamic-type languages. Instead of current text-oriented IDEs, it
> should be a database-centric and resemble current CAD systems instead
> of being just "fancy text editor". Source text should be an output
> product of that CAD and not a "source material" itself.

I don't know CAD systems, but I want to share my comments about this.

I self learned to program with Squeak Smalltalk at 17. Later, I worked
with VisualAge for Java, that was a Smalltalk IDE applied to Java.

Now, I can tell you that in Smalltalk IDEs the code is not written in
files. It's stored in a thing called "image".

You have these frames, in the first frame you have the classes, in the
second frame you have the child classes and in the third frame you
have the methods of the child class you selected.

A bigger frame showed the code of the single method you had selected.

You modified the method, hit ctrl-s and it was COMPILED and saved in
the image.

You had a frame in which you could interactively call your objects,
some of them represented things that were "showable" on the monitor
and you could see these things pop up as you instantiated them.

Then, you had some specialized browsers in which you could search, for
example, all the places a method was called in (a thing I have
difficulties with, in python, today)

VisualAge had its own management version system such that EVERY TIME I
saved a method, it became a VERSION and there was a specialized
browser for browsing the versions (the image tended to grow, that's
it) while the regular browser defaulted on the last version and there
was a tool for freezing a version as a milestone.


Today, I tried to understand the twisted.web.client code and I found 3
methods I couldn't find by who were called.

I asked on the mailing list and they suggested me where they were
called and that the tool for such thing is "grep".

So, you grep, you get a list of files, you open each one of them and
keep scrolling and switching from one file to another... endlessly.
Maybe I'm getting old, but I tend to get lost in the process.

I can't believe the code editing situation today is in a such sorry
state.

Is this what you meant ?

If it's this, then it's not experimental at all, it's been done
already and been put apart.

Crap won :-(

You write:

> Instead of current text-oriented IDEs, it
> should be a database-centric

well, it seems you agree with Alan Kay, (the Smalltalk inventor) when
he wrote that programming is NOT glorified text editing.

He called it "direct manipulation" every method was a live thing you
could send messages to and the source code that implemented it was
just an attribute of the method.

So you could have had a World Of Warcraft like interface, to
manipulate your methods.

You know what I'm doing now ? I'm drawing the map of
twisted.web.client on a paper with a pencil :-(

Bye
Catonano
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use strings to call functions

2010-02-10 Thread Bruno Desthuilliers

Klaus Neuner a écrit :

On Feb 10, 12:55 pm, Bruno Desthuilliers  wrote:

KlausNeunera écrit :




All right, I admit that eval() is evil and should never be used.

Can you tell the difference between your above statement and the following:


As already pointed out in my second post (though perhaps not
explicitly enough),


Or perhaps is it me that failed to re-read a bit more of the thread 
before answering - I obviously missed the irony (and made an a... of 
myself), sorry :-/



All
I wanted to say is this: If there are no circumstances at all under
which eval() can reasonably be used, then it should not be part of
Python. As it is part of Python (and as Python is a carefully designed
language), there will most probably some situations in which one might
want to use it.


Indeed.


--
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Duncan Booth
"Alf P. Steinbach"  wrote:

>> In CPython objects once created remain in the same memory location
>> (and their id is their address). Compare that to IronPython where the
>> objects themselves can move around in memory so they have no fixed
>> address. Try comparing the IronPython implementation to C pointers
>> and you'll cause a lot of confusion. e.g. someone might think the
>> id() value is in some way related to an address.
> 
> Did you /read/ what you quoted?
> 
> 
>> Ruby implements integers without using any pointers at all: there's
>> nothing in the Python specification which prevents a Python
>> implementation doing the same for small integers, in fact I believe
>> it has been tried but wasn't found to improve performance.
> 
> All theree of your points about Python are wrong; I don't know about
> the Ruby point. 

Would you care to expand upon your claim that my three points about Python 
are wrong? Are you saying that CPyhton objects move around, or that 
IronPython objects are fixed to a single memory location or that their id 
is related to their address? Clue here:

IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 42
>>> id(x)
43
>>> y = 43
>>> id(y)
44
>>> z = "whatever"
>>> id(z)
45

-- 
Duncan Booth http://kupuguy.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Quin
You know, Jack, that was the point of my original post: to determine why 
things weren't working.  Do you still want to bet money that it is?  I can 
screenshot you TD.



"Jean-Michel Pichavant"  wrote in message 
news:[email protected]...

Quin wrote:

Well, now you know!

"Jean-Michel Pichavant"  wrote in message 
news:[email protected]...

Quin wrote:
Thanks guys, I'm thinking it's a problem with IronPython.  I'm 
switching to PyScripter and will test tomorrow.



I'm willing to bet money that it is not. If ironPython had a broken if 
statement, don't you think we would have known, already ?


There's a rule when test writing/testing code:
"if you think the compiler is wrong, then you are wrong twice."

JM




All I know is that you are using a python implementation that does not 
support python 3. No wonder why your py3 code fails.


Please do not top post.

JM


   IronPython

   * Stable Version is 2.0.3 (targeting Python 2.5)
   * Developers Version is 2.6 Beta 3 (targeting Python 2.6)



--
http://mail.python.org/mailman/listinfo/python-list


Function attributes

2010-02-10 Thread Muhammad Alkarouri
Hi everyone,

What is the simplest way to access the attributes of a function from
inside it, other than using its explicit name?
In a function like f below:

def f(*args):
f.args = args
print args

is there any other way?
I am guessing the next question will be: should I really care? It just
feels like there should be a way, but I am not able to verbalise a
valid one at the moment, sorry.

Regards,

Muhammad Alkarouri
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 09:13:22 +0100, Alf P. Steinbach wrote:

>> You've
>> dismissed at least one of my arguments with a simple hand-waving of,
>> "That's invalid, cuz."
> 
> That is not a quote of me. It is a lie.

Alf, although your English in this forum has been excellent so far, I 
understand you are Norwegian, so it is possible that you aren't a native 
English speaker and possibly unaware that quotation marks are sometimes 
ambiguous in English.

While it is true that quoted text is officially meant to indicate a 
direct quote, it is also commonly used in informal text to indicate a 
paraphrase. (There are other uses as well, but they don't concern us now.)

Unfortunately, this means that in informal discussions like this it is 
sometimes difficult to distinguish a direct quote from a paraphrase, 
except by context. In context, as a native speaker, I can assure you that 
Stephen Hansen's use of quotation marks is a paraphrase and not meant to 
be read as a direct quote.

As a paraphrase, it's not a *lie* -- it should be read as Stephen's 
*opinion* of your actions, not a direct quote. Stephen might, or might 
not, be *mistaken*, but it's unlikely he's actively lying. Arguing 
pedantically that you didn't write those exact words won't win you any 
friends or supporters.

You can choose to defend yourself against a gross misrepresentation of 
what you actually said; or you can accept that it captures the spirit 
(but not the letter) of your words; or you can choose a middle position, 
and accept that even if it is not a 100% accurate representation of your 
statements, perhaps it is 90% accurate, or 10%, or 50%. The exact amount 
doesn't really matter, and will be subjective, and frankly I don't care. 
But whatever degree you choose to accept, it is obvious that a number of 
people are not just being annoyed by your behaviour, but they are annoyed 
enough to publicly chastise you for it. That includes Steve Holden, who 
is usually far more even-tempered than (e.g.) me.

Without necessarily suggesting that you are 100% to blame for the 
antagonism, its unlikely that so many disparate individuals are all 100% 
mistaken. As you say, the public record is there for anyone who wishes to 
read the history.

Believe me Alf, the fact that people are taking the time to try to argue 
with you instead of just kill-filing you is a compliment.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-10 Thread waku
On Feb 9, 10:41 pm, Jonathan Gardner 
wrote:
> On Feb 9, 1:51 am, waku  wrote:
>
> > 'stupid', 'wrong', 'deficient', 'terrible', ...  you're using strong
> > words instead of concrete arguments, it might intimidate your
> > opponents, but is hardly helpful in a fair discussion.
>
> In today's day and age, I don't know how a text editor which cannot do
> simple indentation can be considered anything but "stupid", "wrong",
> "deficient", and "terrible". There is simply no excuse for this kind
> of behavior on the part of the text editor.

i thought we were not discussing text editors, why should you insist
so much on diverting attention from the issue of a programmer being
*forced* to keep perfect indentation to the issue of an editor doing
autoindent or the like.

>
> I mean, how long has vi had the auto indent feature? How many decades
> has emacs supported the same? This isn't new technology, or difficult
> technology to implement. It's not even non-standard anymore. Heck, far
> more advanced features, such as syntax highlighting, are standard in
> all text editors.

wow!  and then, back to the issue of enforced indentation in python?


> Your problem is you're using something like Windows Notepad to edit
> your code.

thin ice!  you haven't got the faintest idea of what i use to edit my
code, do you.


Windows Notepad is a terrible tool for writing anything,
> let alone writing code. Why in the world would any programming
> language adapt itself to the mental deficiencies of Windows Notepad? I
> mean, if you were an artist, would you use MS Paint to do anything
> serious? If you did, would you complain that the art world has a
> problem because they don't accept your paintings?
>
> I strongly suggest you download one of the *hundreds* of free text
> editors available for the Windows platform that give you the
> indentation features you so sorely lack. I suggest ViM, though it has
> a steep learning curve.

listen to what people say before responding, and stop showing off.
again, you haven't used a single reasonable argument here.

vQ

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:

> Hi everyone,
> 
> What is the simplest way to access the attributes of a function from
> inside it, other than using its explicit name? In a function like f
> below:
> 
> def f(*args):
> f.args = args
> print args
> 
> is there any other way?

Not built-in.


> I am guessing the next question will be: should I really care? It just
> feels like there should be a way, but I am not able to verbalise a valid
> one at the moment, sorry.

I completely agree with you. It is a wart that functions are only able to 
refer to themselves by name, because if the name changes, things break. 
Consider:

old_f = f  # save the old version of the function

def f(x):
return old_f(x+1)  # make a new function and call it f

This won't work correctly, because old_f still tries to refer to itself 
under the name "f", and things break very quickly.





-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Peter Otten
Quin wrote:

> You know, Jack, that was the point of my original post: to determine why
> things weren't working.  Do you still want to bet money that it is?  I can
> screenshot you TD.

You haven't posted the complete script, and you haven't given a thorough 
description how you invoke that script.

To help us find an explanation for your problem and a possible fix please 
make the script as small as you can while preserving its very strange 
behaviour, open a DOS window and invoke the Ironpython interpreter manually 
on the command line. 

Finally copy and paste the output and the complete script and post it here 
again.

Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Krister Svanlund
On Wed, Feb 10, 2010 at 2:59 PM, Muhammad Alkarouri
 wrote:
> Hi everyone,
>
> What is the simplest way to access the attributes of a function from
> inside it, other than using its explicit name?
> In a function like f below:
>
> def f(*args):
>    f.args = args
>    print args
>
> is there any other way?
> I am guessing the next question will be: should I really care? It just
> feels like there should be a way, but I am not able to verbalise a
> valid one at the moment, sorry.
>
> Regards,
>
> Muhammad Alkarouri
> --
> http://mail.python.org/mailman/listinfo/python-list
>

This sounds like something you shouldn't be doing. You should probably
use a class instead.

(Sending again to get it on the list >_<)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: use strings to call functions

2010-02-10 Thread Klaus Neuner
> Or perhaps is it me that failed to re-read a bit more of the thread
> before answering - I obviously missed the irony (and made an a... of
> myself), sorry :-/

There is nothing to be sorry about. I am grateful to all participants
of this thread. I know a lot more about Python than before.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-10 Thread Steve Holden
waku wrote:
> On Feb 9, 10:41 pm, Jonathan Gardner 
> wrote:
>> On Feb 9, 1:51 am, waku  wrote:
>>
>>> 'stupid', 'wrong', 'deficient', 'terrible', ...  you're using strong
>>> words instead of concrete arguments, it might intimidate your
>>> opponents, but is hardly helpful in a fair discussion.
>> In today's day and age, I don't know how a text editor which cannot do
>> simple indentation can be considered anything but "stupid", "wrong",
>> "deficient", and "terrible". There is simply no excuse for this kind
>> of behavior on the part of the text editor.
> 
> i thought we were not discussing text editors, why should you insist
> so much on diverting attention from the issue of a programmer being
> *forced* to keep perfect indentation to the issue of an editor doing
> autoindent or the like.
> 
It's as sensible to complain about people being "*forced* to keep
perfect indentation" as it is to complain about people being *forced* to
use braces to delimit code blocks.

This is called "syntax", and it's a part of the language, so get over it
- this aspect of Python has been present in the language since its
inception, and it isn't going to change.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Jean-Michel Pichavant

Quin wrote:
You know, Jack, that was the point of my original post: to determine 
why things weren't working.  Do you still want to bet money that it 
is?  I can screenshot you TD.



Another flaming war starting...

IronPython implements python 2.5 and you're still complaining about your 
py3 code not working.
Try your code in a ruby shell, and tell the ruby community that their 
intepreter cannot even handle an if statement. Feel free to put my mail 
address in cc.


So to be clear, IronPython can properly handle if statements. I'll bet 
all your money on that.


Jack
--
http://mail.python.org/mailman/listinfo/python-list


looking for some libraries

2010-02-10 Thread Vision
hi all,
I am doing some stuffs with some software, which has similar layout
like this:
Editbox1
Editbox2
Editbox3
   _OK_
___
|output|
|output|
|output|
|output|
|output|
--
What I need to do is to fill the edit boxes, then press the OK button,
then I will get some output text below.
This is tedious since I have lots of entries to deal with.
So I am trying to write some scripts to handle this. And I wonder if
there is any library available for me to simplify the process?
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread John Posner

On 2/10/2010 9:36 AM, Steven D'Aprano wrote:

On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:


Hi everyone,

What is the simplest way to access the attributes of a function from
inside it, other than using its explicit name? In a function like f
below:

def f(*args):
 f.args = args
 print args

is there any other way?


Not built-in.



I am guessing the next question will be: should I really care? It just
feels like there should be a way, but I am not able to verbalise a valid
one at the moment, sorry.


I completely agree with you. It is a wart that functions are only able to
refer to themselves by name, because if the name changes, things break.
Consider:

old_f = f  # save the old version of the function

def f(x):
 return old_f(x+1)  # make a new function and call it f

This won't work correctly, because old_f still tries to refer to itself
under the name "f", and things break very quickly.


They didn't break immediately for me -- what am I missing?:

#---
def f(): return "old func"
g = f
print "name attr of f:", f.__name__
print "name attr of g:", g.__name__

def f(): return "new func"
print "name attr of f:", f.__name__
print "name attr of g:", g.__name__

print "*** calling function currently named f:"
print f()
print "*** calling function currently named g:"
print g()
#---

program output (Python 2.6.4):

name attr of f: f
name attr of g: f
name attr of f: f
name attr of g: f
*** calling function currently named f:
new func
*** calling function currently named g:
old func

-John
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Bruno Desthuilliers

John Posner a écrit :

On 2/10/2010 9:36 AM, Steven D'Aprano wrote:

On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:


(snip)


def f(*args):
 f.args = args
 print args


(snip)

I completely agree with you. It is a wart that functions are only able to
refer to themselves by name, because if the name changes, things break.
Consider:

old_f = f  # save the old version of the function

def f(x):
 return old_f(x+1)  # make a new function and call it f

This won't work correctly, because old_f still tries to refer to itself
under the name "f", and things break very quickly.


They didn't break immediately for me -- what am I missing?:


The fact that in the OP's snippet, code inside f's body refers to f by 
its name.


--
http://mail.python.org/mailman/listinfo/python-list


Python v. Processing

2010-02-10 Thread Sky Larking
I am a light user of Python in a role as a systems administrator...I
am new to the list, but have grown to really enjoy using Python to
help in my job...Another interest I have ( but haven't fully
explored )  is the idea of using programming as a creative outlet .. I
have heard Processing: http://processing.org/ is a good language for
these sort of endeavors --- I am interested in Processing, but would
rather do similar creative work in  Python (i know that is vague, but
the projects on Processing.org are good examples of what I am
intending to do ). I've tried learning different languages
concurrently, and it is usually too much for me too handle Are
there creative types using Python in the way Processing is being
implemented? Just curious of their similarities and differences, and
what Python's limitations maybe be in this arena ( if any ) .

Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote:

>> This won't work correctly, because old_f still tries to refer to itself
>> under the name "f", and things break very quickly.
> 
> They didn't break immediately for me -- what am I missing?:

The original function f doesn't try to refer to itself in any way. With 
no recursive call or access, it doesn't matter what f is named.

See this example  instead:


>>> def f(x):
... if x < 0:
... print "original"
... return f(-x)
... else:
... return x+1
...
>>> f(2)
3
>>> f(-2)
original
3
>>>
>>> old_f = f
>>> def f(x):
... if x > 0:
... return old_f(-x)
... else:
... return x
...
>>> f(-1)
-1
>>> f(1)
original
original
original
original
original
original
[...]
  File "", line 3, in f
  File "", line 4, in f
  File "", line 3, in f
RuntimeError: maximum recursion depth exceeded





-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Stephen Hansen
On Wed, Feb 10, 2010 at 6:16 AM, Steven D'Aprano <
[email protected]> wrote:

> While it is true that quoted text is officially meant to indicate a
> direct quote, it is also commonly used in informal text to indicate a
> paraphrase. (There are other uses as well, but they don't concern us now.)
>

Hm. I hadn't considered that others may interpret my words in the context of
other cultural punctuation rules; it seemed obvious to me that the phrases
Alf declared a "lie" were an opinion, and indeed as Steven points out, my
interpretation and paraphrasing of the original arguments.

Apologies if you considered it a direct quote and thought I was attempting
to assert you actually said what was in quote marks.

The comments were simply my interpretation (accurate or inaccurate as that
may be, it is my interpretation) of your remarks, and not a quotation of
your remarks to be attributed to you.

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Dreaming of new generation IDE

2010-02-10 Thread Steve Holden
catonano wrote:
[... much wishing for the "good old day" of SmallTalk ...]
> Today, I tried to understand the twisted.web.client code and I found 3
> methods I couldn't find by who were called.
> 
> I asked on the mailing list and they suggested me where they were
> called and that the tool for such thing is "grep".
> 
> So, you grep, you get a list of files, you open each one of them and
> keep scrolling and switching from one file to another... endlessly.
> Maybe I'm getting old, but I tend to get lost in the process.
> 
Maybe you are getting old. Or maybe you didn't realise that the advice
was given you so that it would be useful whether or not you were using
an IDE.

> I can't believe the code editing situation today is in a such sorry
> state.
> 
It isn't. There are many IDEs that will allow you to easily locate the
calls of specific methods.

> Is this what you meant ?
> 
> If it's this, then it's not experimental at all, it's been done
> already and been put apart.
> 
> Crap won :-(
> 
It seems you yearn for the days of the SmallTalk image. Unfortunately
this didn't allow for conveniences like using external data stored in
files whose contents persisted and which could be transferred between
different machines.

I would never call SmallTalk "crap": it was a ground-breaking system
almost 40 yers ago. But the environment suffered from many limitations
of which you appear to be entirely unaware.

> You write:
> 
>> Instead of current text-oriented IDEs, it
>> should be a database-centric
> 
> well, it seems you agree with Alan Kay, (the Smalltalk inventor) when
> he wrote that programming is NOT glorified text editing.
> 
> He called it "direct manipulation" every method was a live thing you
> could send messages to and the source code that implemented it was
> just an attribute of the method.
> 
This aspect of SmallTalk was one of the things that made software
engineering rather difficult. Everything could be changed on the fly.

> So you could have had a World Of Warcraft like interface, to
> manipulate your methods.
> 
> You know what I'm doing now ? I'm drawing the map of
> twisted.web.client on a paper with a pencil :-(
> 
Well why don't you get yourself a sensible tool like Wing IDE or Komodo?
They at least will let you solve the problem you currently face without
having to poke around in the innards of a running virtual machine the
way we used to in SmallTalk.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python v. Processing

2010-02-10 Thread Robert Franke
Hi Sky,


there is a project called pyprocessing
(http://code.google.com/p/pyprocessing/) that aims to create a similar
environment like processing in python. I am not sure though how
advanced this is.

Cheers,

Robert

On Wed, Feb 10, 2010 at 4:29 PM, Sky Larking  wrote:
> I am a light user of Python in a role as a systems administrator...I
> am new to the list, but have grown to really enjoy using Python to
> help in my job...Another interest I have ( but haven't fully
> explored )  is the idea of using programming as a creative outlet .. I
> have heard Processing: http://processing.org/ is a good language for
> these sort of endeavors --- I am interested in Processing, but would
> rather do similar creative work in  Python (i know that is vague, but
> the projects on Processing.org are good examples of what I am
> intending to do ). I've tried learning different languages
> concurrently, and it is usually too much for me too handle Are
> there creative types using Python in the way Processing is being
> implemented? Just curious of their similarities and differences, and
> what Python's limitations maybe be in this arena ( if any ) .
>
> Thanks!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Stephen Hansen
On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano <
[email protected]> wrote:

> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:
> > What is the simplest way to access the attributes of a function from
> > inside it, other than using its explicit name? In a function like f
>
> Not built-in.
>
> > I am guessing the next question will be: should I really care? It just
> > feels like there should be a way, but I am not able to verbalise a valid
> > one at the moment, sorry.
>
> I completely agree with you. It is a wart that functions are only able to
> refer to themselves by name, because if the name changes, things break.
>

I agree its slightly... in-elegant, or sub-optimal, but I'm not sure I want
to call it a *wart*. If one calls it a wart, there might be inspiration to
fix it.

And this sounds like a precursor to making "self" non-explicit, and I
*really* like my explicit self. :)

Then again, I have been slightly bruised by this sub-optimal situation
before.

I tried to do a function using a frame hack to get the information easily,
but failed. My long years of avoiding frame hacks like the plague have left
me deficient. :(

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread MRAB

Olof Bjarnason wrote:

2010/2/10 Peter Otten <[email protected]>:

[email protected] wrote:


Does Python provide a way to format a string according to a
'picture' format?

For example, if I have a string '123456789' and want it formatted
like '(123)-45-(678)[9]', is there a module or function that will
allow me to do this or do I need to code this type of
transformation myself?

A basic implementation without regular expressions:


def picture(s, pic, placeholder="@"):

... parts = pic.split(placeholder)
... result = [None]*(len(parts)+len(s))
... result[::2] = parts
... result[1::2] = s
... return "".join(result)
...

picture("123456789", "(@@@)-@@-(@@@)[...@]")

'(123)-45-(678)[9]'

Peter
--
http://mail.python.org/mailman/listinfo/python-list



Inspired by your answer here's another version:


def picture(s, pic):

...   if len(s)==0: return pic
...   if pic[0]=='#': return s[0]+picture(s[1:], pic[1:])
...   return pic[0]+picture(s, pic[1:])
...

picture("123456789", "(###)-##-(###)[#]")

'(123)-45-(678)[9]'


Here's a version without recursion:

>>> def picture(s, pic):
... pic = pic.replace("%", "%%").replace("#", "%s")
... return pic % tuple(s)
...
>>> picture("123456789", "(###)-##-(###)[#]")
'(123)-45-(678)[9]'

--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Stephen Hansen
On Wed, Feb 10, 2010 at 1:45 AM, Peter Otten <[email protected]> wrote:

> A basic implementation without regular expressions:
>
> >>> def picture(s, pic, placeholder="@"):
> ... parts = pic.split(placeholder)
> ... result = [None]*(len(parts)+len(s))
> ... result[::2] = parts
> ... result[1::2] = s
> ... return "".join(result)
> ...
> >>>
> >>> picture("123456789", "(@@@)-@@-(@@@)[...@]")
> '(123)-45-(678)[9]'
>

Huh. This is the best version of those posted, I think (especially including
mine! My jumping to regex is worthy of shame, sh ame).

It took a little bit to figure out what was really going on here, but its a
single-pass through to do it without recursion or building a bunch of
intermediate strings that are concatenated and dropped away.

Its clever, and I don't mean that in the bad way, because -all- the
solutions are pretty clever in the sneaky-tricky-neat way. But this is
clever-cool.

Just slightly dark-voodoo-incantation-esque. Slightly!

--S
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Personal criticisms and logical fallacies

2010-02-10 Thread Robert Kern

On 2010-02-10 01:06 AM, Steven Howe wrote:

Really, is this a relevant topic on a program mail list?


Yes. Meta-discussions about how we discuss programming productively are also 
on-topic.


--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: How to measure elapsed time under Windows?

2010-02-10 Thread Grant Edwards
On 2010-02-09, Gabriel Genellina  wrote:
> En Tue, 09 Feb 2010 13:10:56 -0300, Grant Edwards  
> escribi?:
>
>> What's the correct way to measure small periods of elapsed
>> time.  I've always used time.clock() in the past:
>>
>> However on multi-processor machines that doesn't work.
>> Sometimes I get negative values for delta.  According to
>> google, this is due to a bug in Windows that causes the value
>> of time.clock() to be different depending on which core in a
>> multi-core CPU you happen to be on.   [insert appropriate
>> MS-bashing here]
>
> I'm not sure you can blame MS of this issue; anyway, this
> patch should fix the problem:
> http://support.microsoft.com/?id=896256

I'm curious why it wouldn't be Microsoft's fault, because

 A) Everything is Microsoft's fault. ;)

 B) If a patch to MS Windows fixes the problem, how is it not a
problem in MS Windows?

>> Is there a way to lock the python process to a single core so
>> that time.clock() works right?
>
> Interactively, from the Task Manager:
> http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskman_assign_process.mspx

Thanks.  That looks a bit easier than disabling the second core
(which is what I ended up doing).

> In code, using SetProcessAffinityMask and related functions:
> http://msdn.microsoft.com/en-us/library/ms686223(VS.85).aspx

With help from google and some old mailing list posting I might
even try that.

-- 
Grant Edwards   grante Yow! It's a lot of fun
  at   being alive ... I wonder if
   visi.commy bed is made?!?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for some libraries

2010-02-10 Thread rantingrick
On Feb 10, 8:59 am, Vision  wrote:
> hi all,
> I am doing some stuffs with some software, which has similar layout
> like this:
> Editbox1
> Editbox2
> Editbox3
>        _OK_
> ___
> |        output        |
> |        output        |
> |        output        |
> |        output        |
> |        output        |
> --
> What I need to do is to fill the edit boxes, then press the OK button,
> then I will get some output text below.
> This is tedious since I have lots of entries to deal with.
> So I am trying to write some scripts to handle this. And I wonder if
> there is any library available for me to simplify the process?
> Thanks!

Well a GUI kit comes to mind. And since you did not mention a
preference (or much really) i would suggest Tkinter in the stdlib as a
starting point. Here is a big hint!

#-- start code --#
import Tkinter as tk

def fooit():
lister.insert(END, entry1.get())

app = tk.Tk()

label1 = tk.Label(app, text='label-1').grid(row=0, column=0)
entry1 = tk.Entry(app).grid(row=0, column=1)
tk.Button(app, text='OK', command=fooit).grid(row=1, column=0,
columnspan=2)
lister = tk.Listbox(app, width=20, height=10)
lister.grid(row=2, column=0, columnspan=2)

app.mainloop()
#-- end code --#

i would wrap the label and entry up into a class myself but milage may
vary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread MRAB

Stephen Hansen wrote:
On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano 
> wrote:


On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:
 > What is the simplest way to access the attributes of a function from
 > inside it, other than using its explicit name? In a function like f

Not built-in.

 > I am guessing the next question will be: should I really care? It
just
 > feels like there should be a way, but I am not able to verbalise
a valid
 > one at the moment, sorry.

I completely agree with you. It is a wart that functions are only
able to
refer to themselves by name, because if the name changes, things break.


I agree its slightly... in-elegant, or sub-optimal, but I'm not sure I 
want to call it a *wart*. If one calls it a wart, there might be 
inspiration to fix it.


And this sounds like a precursor to making "self" non-explicit, and I 
*really* like my explicit self. :)


Then again, I have been slightly bruised by this sub-optimal situation 
before.


I tried to do a function using a frame hack to get the information 
easily, but failed. My long years of avoiding frame hacks like the 
plague have left me deficient. :(



Does this mean that Python needs, say, __function__ (and perhaps also
__module__)?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread python
Original poster here.

Thank you all for your ideas. I certainly learned some great techniques
by studying everyone's solutions!!

I was thinking that there was a built-in function for this common(?) use
case which is why I shied away from writing my own in the first place
... hoping to not-reinvent the wheel, etc.

Here's the solution I came up with myself. Its not as sexy as some of
the posted solutions, but it does have the advantage of not failing when
the number of input chars <> the number of placeholders in the pic
string. I think it handles the edge cases pretty elegantly unless I'm
too close to the details to miss the obvious.

Any feedback on what follows would be appreciated.

# format s using a picture string 
# stops processing when runs out of chars in s or pic string
# example: picture("123456789", "(@@@)-@@-(@@@)[...@]")
def picture( s, pic, placeholder="@" ):
s = list( s )
output = []
for sym in pic:
if sym <> placeholder:
output.append( sym )
elif len( s ):
output.append( s.pop( 0 ) )
else:
break
return ''.join( output )

# test cases
print picture("123456789", "(@@@)-@@-(@@@)[...@]")
print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]")
print picture("1234", "(@@@)-@@-(@@@)[...@]")
print picture("123456789", "(@@@)-@@-(@@@)")
print picture("123456789", "(@@@)-@@-(@@@)[...@][@]")

Regards,
Malcolm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [PyOpenGL-Users] Mouse wheel events?

2010-02-10 Thread Craig Berry
I'm happy to report that FreeGLUT solved my problem.  I obtained the
Windows prepackaged binary distribution, pulled out freeglut.dll,
renamed it to glut32.dll, and replaced the existing glut32.dll in the
PyOpenGL installation directory tree with the new version.  Mousewheel
events are now reported, and everything else seems to be working as
expected.  Thanks for your help!

-- 
Craig Berry - http://www.cine.net/~cberry/
"Lots of things in the universe don’t solve any problems, and
nevertheless exist."  -- Sean Carroll
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: looking for some libraries

2010-02-10 Thread Jean-Michel Pichavant

Vision wrote:

hi all,
I am doing some stuffs with some software, which has similar layout
like this:
Editbox1
Editbox2
Editbox3
   _OK_
___
|output|
|output|
|output|
|output|
|output|
--
What I need to do is to fill the edit boxes, then press the OK button,
then I will get some output text below.
This is tedious since I have lots of entries to deal with.
So I am trying to write some scripts to handle this. And I wonder if
there is any library available for me to simplify the process?
Thanks!
  


Someone posted this link few weeks ago:
http://www.sikuli.org/

It supports only mac & windows though.

You can also have a look at
http://pywinauto.openqa.org/

JM

--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Tim Chase

[email protected] wrote:

Original poster here.

Thank you all for your ideas. I certainly learned some great techniques
by studying everyone's solutions!!


Thanks for the positive feedback -- it's something most folks 
like to hear when they try to assist and such thanks appears too 
rarely on the list.



Here's the solution I came up with myself. Its not as sexy as some of
the posted solutions, but it does have the advantage of not failing when
the number of input chars <> the number of placeholders in the pic
string. 

>

Any feedback on what follows would be appreciated.

[snip]

# test cases
print picture("123456789", "(@@@)-@@-(@@@)[...@]")
print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]")
print picture("1234", "(@@@)-@@-(@@@)[...@]")
print picture("123456789", "(@@@)-@@-(@@@)")
print picture("123456789", "(@@@)-@@-(@@@)[...@][@]")



You don't give the expected output for these test cases, so it's 
hard to tell whether you want to pad-left or pad-right.


Riffing on MRAB's lovely solution, you can do something like

  def picture(
  s, pic,
  placeholder='@',
  padding=' ',
  pad_left=True
  ):
assert placeholder != '%'
s = str(s)
expected = pic.count(placeholder)
if len(s) > expected:
  s = s[:expected]
if len(s) < expected:
  if pad_left:
s = s.rjust(expected, padding)
  else:
s = s.ljust(expected, padding)
return pic.replace(
  '%', '%%').replace(
  placeholder, '%s') % tuple(s)

print picture("123456789", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("1234", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False)
print picture("123456789", "(@@@)-@@-(@@@)[...@][@]", 
pad_left=False)


That way you can specify your placeholder, your padding 
character, and whether you want it to pad to the left or right.


-tkc



--
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread John Posner

On 2/10/2010 10:24 AM, Bruno Desthuilliers wrote:


They didn't break immediately for me -- what am I missing?:


The fact that in the OP's snippet, code inside f's body refers to f by
its name.


Of course! Tx.  -John



--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Arnaud Delobelle
[email protected] writes:

> Original poster here.
>
> Thank you all for your ideas. I certainly learned some great techniques
> by studying everyone's solutions!!
>
> I was thinking that there was a built-in function for this common(?) use
> case which is why I shied away from writing my own in the first place
> ... hoping to not-reinvent the wheel, etc.
>
> Here's the solution I came up with myself. Its not as sexy as some of
> the posted solutions, but it does have the advantage of not failing when
> the number of input chars <> the number of placeholders in the pic
> string. I think it handles the edge cases pretty elegantly unless I'm
> too close to the details to miss the obvious.
>
> Any feedback on what follows would be appreciated.
>
> # format s using a picture string 
> # stops processing when runs out of chars in s or pic string
> # example: picture("123456789", "(@@@)-@@-(@@@)[...@]")
> def picture( s, pic, placeholder="@" ):
> s = list( s )
> output = []
> for sym in pic:
> if sym <> placeholder:
> output.append( sym )
> elif len( s ):
> output.append( s.pop( 0 ) )
> else:
> break
> return ''.join( output )
>
> # test cases
> print picture("123456789", "(@@@)-@@-(@@@)[...@]")
> print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]")
> print picture("1234", "(@@@)-@@-(@@@)[...@]")
> print picture("123456789", "(@@@)-@@-(@@@)")
> print picture("123456789", "(@@@)-@@-(@@@)[...@][@]")
>   
> Regards,
> Malcolm

def picture(s, pic, placeholder='@'):
nextchar=iter(s).next
return ''.join(nextchar() if i == placeholder else i for i in pic)

passes all your test cases I think (I can't be sure because you didn't
post the expected output).  The trick is that when nextchar reaches the
end of the string 's', it raises a StopIteration which is caught by the
generator expression.

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread python
Hi Tim,

Thank you very much for your update to MRAB's creative solution.

> You don't give the expected output for these test cases, so 
> it's hard to tell whether you want to pad-left or pad-right.

To be honest, I wasn't sure myself :)

My original post was the result of doing some simple formatting where my
input strings were 'guaranteed' to be a consistent length. I hadn't
started to think about the specs for a more universal picture function
until I started to study and test the solutions proposed by others. It
bears repeating again - what a clever mix of techniques - I really
learned a lot more than I was expecting!

I appreciate you taking the extra time to analyze the problem and refine
it further.

Cheers,
Malcolm

Riffing on MRAB's lovely solution, you can do something like

   def picture(
   s, pic,
   placeholder='@',
   padding=' ',
   pad_left=True
   ):
 assert placeholder != '%'
 s = str(s)
 expected = pic.count(placeholder)
 if len(s) > expected:
   s = s[:expected]
 if len(s) < expected:
   if pad_left:
 s = s.rjust(expected, padding)
   else:
 s = s.ljust(expected, padding)
 return pic.replace(
   '%', '%%').replace(
   placeholder, '%s') % tuple(s)

print picture("123456789", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("1234", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False)
print picture("123456789", "(@@@)-@@-(@@@)[...@][@]", 
pad_left=False)

That way you can specify your placeholder, your padding 
character, and whether you want it to pad to the left or right.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [PyOpenGL-Users] Mouse wheel events?

2010-02-10 Thread Gary Herron

Craig Berry wrote:

I'm happy to report that FreeGLUT solved my problem.  I obtained the
Windows prepackaged binary distribution, pulled out freeglut.dll,
renamed it to glut32.dll, and replaced the existing glut32.dll in the
PyOpenGL installation directory tree with the new version.  Mousewheel
events are now reported, and everything else seems to be working as
expected.  Thanks for your help!

  


:-)

Gary Herron

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python and Ruby

2010-02-10 Thread Andreas Waldenburger
On Wed, 10 Feb 2010 09:51:11 -0500 Steve Holden 
wrote:

> [snip]
> It's as sensible to complain about people being "*forced* to keep
> perfect indentation" as it is to complain about people being *forced*
> to use braces to delimit code blocks.
> 
> This is called "syntax", and it's a part of the language, so get over
> it - this aspect of Python has been present in the language since its
> inception, and it isn't going to change.
> 
Amen. Now everybody do a quick

from __future__ import braces

and get back to work.

/W

-- 
INVALID? DE!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
Steven D'Aprano  writes:

> On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote:
>
>>> This won't work correctly, because old_f still tries to refer to itself
>>> under the name "f", and things break very quickly.
>> 
>> They didn't break immediately for me -- what am I missing?:
>
> The original function f doesn't try to refer to itself in any way. With 
> no recursive call or access, it doesn't matter what f is named.
>
> See this example  instead:
>
>
 def f(x):
> ... if x < 0:
> ... print "original"
> ... return f(-x)
> ... else:
> ... return x+1
> ...
 f(2)
> 3
 f(-2)
> original
> 3

 old_f = f
 def f(x):
> ... if x > 0:
> ... return old_f(-x)
> ... else:
> ... return x
> ...
 f(-1)
> -1
 f(1)
> original
> original
> original
> original
> original
> original
> [...]
>   File "", line 3, in f
>   File "", line 4, in f
>   File "", line 3, in f
> RuntimeError: maximum recursion depth exceeded

It's not ideal, but you can use a decorator like this to solve this
problem:

def bindfunction(f):
def bound_f(*args, **kwargs):
return f(bound_f, *args, **kwargs)
bound_f.__name__ = f.__name__
return bound_f

>>> @bindfunction
... def factorial(this_function, n):
... if n > 0:
... return n * this_function(n - 1)
... else:
... return 1
... 
>>> factorial(15)
1307674368000L
>>> fac = factorial
>>> fac(15)
1307674368000L
>>> factorial = 'foobar'
>>> fac(15)
1307674368000L

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread python
Arnaud,

Very cool!! Just when I thought the problem couldn't be made simpler ...
WOW!!!

Again, a big thank you to everyone who posted solutions!!!

I'm humbled at how clever and different everyone's techniques have been.

I have to say, I learned much more than I thought I needed to learn :)

Thanks again!

Malcolm

- Original message -
From: "Arnaud Delobelle" 
To: [email protected]
Date: Wed, 10 Feb 2010 18:21:35 +
Subject: Re: Creating formatted output using picture strings

[email protected] writes:

> Original poster here.
>
> Thank you all for your ideas. I certainly learned some great techniques
> by studying everyone's solutions!!
>
> I was thinking that there was a built-in function for this common(?) use
> case which is why I shied away from writing my own in the first place
> ... hoping to not-reinvent the wheel, etc.
>
> Here's the solution I came up with myself. Its not as sexy as some of
> the posted solutions, but it does have the advantage of not failing when
> the number of input chars <> the number of placeholders in the pic
> string. I think it handles the edge cases pretty elegantly unless I'm
> too close to the details to miss the obvious.
>
> Any feedback on what follows would be appreciated.
>
> # format s using a picture string 
> # stops processing when runs out of chars in s or pic string
> # example: picture("123456789", "(@@@)-@@-(@@@)[...@]")
> def picture( s, pic, placeholder="@" ):
> s = list( s )
> output = []
> for sym in pic:
> if sym <> placeholder:
> output.append( sym )
> elif len( s ):
> output.append( s.pop( 0 ) )
> else:
> break
> return ''.join( output )
>
> # test cases
> print picture("123456789", "(@@@)-@@-(@@@)[...@]")
> print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]")
> print picture("1234", "(@@@)-@@-(@@@)[...@]")
> print picture("123456789", "(@@@)-@@-(@@@)")
> print picture("123456789", "(@@@)-@@-(@@@)[...@][@]")
>   
> Regards,
> Malcolm

def picture(s, pic, placeholder='@'):
nextchar=iter(s).next
return ''.join(nextchar() if i == placeholder else i for i in pic)

passes all your test cases I think (I can't be sure because you didn't
post the expected output).  The trick is that when nextchar reaches the
end of the string 's', it raises a StopIteration which is caught by the
generator expression.

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 17:23:36 +, MRAB wrote:

> Stephen Hansen wrote:
>> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano
>> > > wrote:
>> 
>> On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:
>>  > What is the simplest way to access the attributes of a function
>>  > from inside it, other than using its explicit name? In a
>>  > function like f
>> 
>> Not built-in.

[...]

> Does this mean that Python needs, say, __function__ (and perhaps also
> __module__)?

Python already has __module__, except that it is spelled:

import __main__


As for __function__, perhaps, but a solution I would be satisfied with 
would be to make it optional. Most functions are not recursive, and do 
not attach attributes to themselves. For the few that do need to refer to 
themselves, it would be sufficient to call a decorator to get the 
behaviour needed. I thought I had come up with such a thing, once before, 
but I can't find it now :(


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread donn

On 10/02/2010 20:36, [email protected] wrote:

def picture(s, pic, placeholder='@'):
 nextchar=iter(s).next
 return ''.join(nextchar() if i == placeholder else i for i in pic)

Hell's teeth - even I understood that! Amazing solution.

\d

--
Fonty Python and Things! -- http://otherwise.relics.co.za/wiki/Software
--
http://mail.python.org/mailman/listinfo/python-list


Re: Function attributes

2010-02-10 Thread Steven D'Aprano
On Wed, 10 Feb 2010 18:31:23 +, Arnaud Delobelle wrote:

> It's not ideal, but you can use a decorator like this to solve this
> problem:
> 
> def bindfunction(f):
> def bound_f(*args, **kwargs):
> return f(bound_f, *args, **kwargs)
> bound_f.__name__ = f.__name__
> return bound_f

Ah, very nice. Perhaps it's better to use functools.wraps?

import functools

def bindfunction(f):
@functools.wraps(f)
def bound_f(*args, **kwargs):
return f(bound_f, *args, **kwargs)
return bound_f



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread kj


Some people have mathphobia.  I'm developing a wicked case of
Unicodephobia.

I have read a *ton* of stuff on Unicode.  It doesn't even seem all
that hard.  Or so I think.  Then I start writing code, and WHAM:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal 
not in range(128)

(There, see?  My Unicodephobia just went up a notch.)

Here's the thing: I don't even know how to *begin* debugging errors
like this.  This is where I could use some help.

In the past I've gone for method of choice of the clueless:
"programming by trial-and-error", try random crap until something
"works."  And if that "strategy" fails, I come begging for help to
c.l.p.  And thanks for the very effective pointers for getting rid
of the errors.

But afterwards I remain as clueless as ever...  It's the old "give
a man a fish" vs. "teach a man to fish" story.

I need a systematic approach to troubleshooting and debugging these
Unicode errors.  I don't know what.  Some tools maybe.  Some useful
modules or builtin commands.  A diagnostic flowchart?  I don't
think that any more RTFM on Unicode is going to help (I've done it
in spades), but if there's a particularly good write-up on Unicode
debugging, please let me know.

Any suggestions would be much appreciated.

FWIW, I'm using Python 2.6.  The example above happens to come from
a script that extracts data from HTML files, which are all in
English, but they are a daily occurrence when I write code to
process non-English text.  The script uses Beautiful Soup.  I won't
post a lot of code because, as I said, what I'm after is not so
much a way around this specific error as much as the tools and
techniques to troubleshoot it and fix it on my own.  But to ground
the problem a bit I'll say that the exception above happens during
the execution of a statement of the form:

  x = '%s %s' % (y, z)

Also, I found that, with the exact same values y and z as above,
all of the following statements work perfectly fine:

  x = '%s' % y
  x = '%s' % z
  print y
  print z
  print y, z

TIA!

~K
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread Jonathan Gardner
On Feb 10, 11:09 am, kj  wrote:
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: 
> ordinal not in range(128)
>

You'll have to understand some terminology first.

"codec" is a description of how to encode and decode unicode data to a
stream of bytes.

"decode" means you are taking a series of bytes and converting it to
unicode.

"encode" is the opposite---take a unicode string and convert it to a
stream of bytes.

"ascii" is a codec that can only describe 0-127 with bytes 0-127.
"utf-8", "utf-16", etc... are other codecs. There's a lot of them.
Only some of them (ie, utf-8, utf-16) can encode all unicode. Most
(ie, ascii) can only do a subset of unicode.

In this case, you've fed a stream of bytes with 128 as one of the
bytes to the decoder. Since the decoder thinks it's working with
ascii, it doesn't know what to do with 128. There's a number of ways
to fix this:

(1) Feed it unicode instead, so it doesn't try to decode it.

(2) Tell it what encoding you are using, because it's obviously not
ascii.

>
> FWIW, I'm using Python 2.6.  The example above happens to come from
> a script that extracts data from HTML files, which are all in
> English, but they are a daily occurrence when I write code to
> process non-English text.  The script uses Beautiful Soup.  I won't
> post a lot of code because, as I said, what I'm after is not so
> much a way around this specific error as much as the tools and
> techniques to troubleshoot it and fix it on my own.  But to ground
> the problem a bit I'll say that the exception above happens during
> the execution of a statement of the form:
>
>   x = '%s %s' % (y, z)
>
> Also, I found that, with the exact same values y and z as above,
> all of the following statements work perfectly fine:
>
>   x = '%s' % y
>   x = '%s' % z
>   print y
>   print z
>   print y, z
>

What are y and z? Are they unicode or strings? What are their values?

It sounds like someone, probably beautiful soup, is trying to turn
your strings into unicode. A full stacktrace would be useful to see
who did what where.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread MRAB

Tim Chase wrote:

[email protected] wrote:

Original poster here.

Thank you all for your ideas. I certainly learned some great techniques
by studying everyone's solutions!!


Thanks for the positive feedback -- it's something most folks like to 
hear when they try to assist and such thanks appears too rarely on the 
list.



Here's the solution I came up with myself. Its not as sexy as some of
the posted solutions, but it does have the advantage of not failing when
the number of input chars <> the number of placeholders in the pic
string. 

 >

Any feedback on what follows would be appreciated.

[snip]

# test cases
print picture("123456789", "(@@@)-@@-(@@@)[...@]")
print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]")
print picture("1234", "(@@@)-@@-(@@@)[...@]")
print picture("123456789", "(@@@)-@@-(@@@)")
print picture("123456789", "(@@@)-@@-(@@@)[...@][@]")



You don't give the expected output for these test cases, so it's hard to 
tell whether you want to pad-left or pad-right.


Riffing on MRAB's lovely solution, you can do something like

  def picture(
  s, pic,
  placeholder='@',
  padding=' ',
  pad_left=True
  ):
assert placeholder != '%'
s = str(s)
expected = pic.count(placeholder)
if len(s) > expected:
  s = s[:expected]
if len(s) < expected:
  if pad_left:
s = s.rjust(expected, padding)
  else:
s = s.ljust(expected, padding)
return pic.replace(
  '%', '%%').replace(
  placeholder, '%s') % tuple(s)

print picture("123456789", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("123456789ABC", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("1234", "(@@@)-@@-(@@@)[...@]", pad_left=False)
print picture("123456789", "(@@@)-@@-(@@@)", pad_left=False)
print picture("123456789", "(@@@)-@@-(@@@)[...@][@]", pad_left=False)

That way you can specify your placeholder, your padding character, and 
whether you want it to pad to the left or right.



The code changes any existing '%' to '%%' because each placeholder will
be changed to '%s'. However, if the placeholder itself is '%' then the
initial 'fix' isn't necessary. Therefore:

def picture(s, pic, placeholder='@', padding=' ', pad_left=True):
s = str(s)
expected = pic.count(placeholder)
if len(s) > expected:
s = s[:expected]
elif len(s) < expected:
if pad_left:
s = s.rjust(expected, padding)
else:
s = s.ljust(expected, padding)
if placeholder != '%':
pic = pic.replace('%', '%%')
return pic.replace(placeholder, '%s') % tuple(s)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread Duncan Booth
kj  wrote:

> But to ground
> the problem a bit I'll say that the exception above happens during
> the execution of a statement of the form:
> 
>   x = '%s %s' % (y, z)
> 
> Also, I found that, with the exact same values y and z as above,
> all of the following statements work perfectly fine:
> 
>   x = '%s' % y
>   x = '%s' % z
>   print y
>   print z
>   print y, z
> 

One of y or z is unicode, the other is str. The statement that goes wrong 
is combining the unicode string with the other one so the result has to be 
unicode. That means whichever of y or z is str is being decoded to unicode 
is being decoded with the default of 'ascii'.

When you format them separately one assignment to x gives a unicode result, 
the other gives str.

When you print them you are encoding the unicode value to ascii and that 
isn't giving a problem.

1. Print the repr of each value so you can see which is which.
2. Explicitly decode the str to unicode using whatever encoding is correct 
(possibly utf-8) when formatting.
3. Explicitly encode back to str when printing using the encoding of your 
output device.
4. Know what types you are using: never mix str and unicode without being 
explicit.
5. When you post to this newsgroup include the full traceback, not just the 
error message.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Grant Edwards
On 2010-02-10, [email protected]  wrote:

[regardning "picture" output format specifiers]

> I was thinking that there was a built-in function for this
> common(?) use case

I haven't seen that paradigm since my one-and-only exposure to
COBOL in a class I took back in 1979.  Is the "picture" thing
commonly used in other places than COBOL?

-- 
Grant Edwards   grante Yow! Did I say I was
  at   a sardine?  Or a bus???
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Alf P. Steinbach

* Duncan Booth:

"Alf P. Steinbach"  wrote:


In CPython objects once created remain in the same memory location
(and their id is their address). Compare that to IronPython where the
objects themselves can move around in memory so they have no fixed
address. Try comparing the IronPython implementation to C pointers
and you'll cause a lot of confusion. e.g. someone might think the
id() value is in some way related to an address.

Did you /read/ what you quoted?



Ruby implements integers without using any pointers at all: there's
nothing in the Python specification which prevents a Python
implementation doing the same for small integers, in fact I believe
it has been tried but wasn't found to improve performance.

All theree of your points about Python are wrong; I don't know about
the Ruby point. 


Would you care to expand upon your claim that my three points about Python 
are wrong?


Sure. I already did in the article you're replying to, immediately following 
what you quote above. You snipped that which you're asking for, so I requote:




First, the current Python language specification formally prevents the 
optimization you mention, because there's no support for binding to do anything 
but direct binding leaving object identities unchanged.


But in practice that's no big deal though: I can't imagine any code relying on 
identities of completely immutable objects.


Second, even the variant that was tried improved performance.

But it would reportedly have wreaked havoc with imperfect C code.

Third, the optimization doesn't do away with pointers. If it did then it would 
transform the language completely. The user's view is still one where names 
denote pointers.




Since in the quoting above no reference to definition of "pointer" remains: 
"pointer" refers to a copyable reference value as seen from the Python level, in 
the same way as "pointer" is used by e.g. the Java language spec.



Are you saying that CPyhton objects move around, or that 
IronPython objects are fixed to a single memory location or that their id 
is related to their address?


No, I can't see how you can deduce any such connection from I wrote.

Whether objects "move around" depends on what exactly you mean by "move around", 
and given that, it may then depend on the Python implementation.


However, from the Python point of view every object has a fixed unique id, 
available via id().




Clue here:

IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082
Type "help", "copyright", "credits" or "license" for more information.

x = 42
id(x)

43

y = 43
id(y)

44

z = "whatever"
id(z)

45



I'm guessing wildly that you're trying to illustrate id's that don't correspond 
to memory addresses?


If so, then that's correct: a Python (or Java, or whatever language) pointer is 
not necessarily directly a memory address, and furthermore id is not guaranteed 
to reproduce the bits of a pointer value  --  which might not even make sense.


All that id does is to produce a value that uniquely identifies the object 
pointed to, i.e. it corresponds to the pointer value, and although in CPython 
that's simply the bits of a C pointer typed as integer, in IronPython it's not.



Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread MRAB

kj wrote:


Some people have mathphobia.  I'm developing a wicked case of
Unicodephobia.

I have read a *ton* of stuff on Unicode.  It doesn't even seem all
that hard.  Or so I think.  Then I start writing code, and WHAM:

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 0: ordinal 
not in range(128)

(There, see?  My Unicodephobia just went up a notch.)

Here's the thing: I don't even know how to *begin* debugging errors
like this.  This is where I could use some help.

In the past I've gone for method of choice of the clueless:
"programming by trial-and-error", try random crap until something
"works."  And if that "strategy" fails, I come begging for help to
c.l.p.  And thanks for the very effective pointers for getting rid
of the errors.

But afterwards I remain as clueless as ever...  It's the old "give
a man a fish" vs. "teach a man to fish" story.

I need a systematic approach to troubleshooting and debugging these
Unicode errors.  I don't know what.  Some tools maybe.  Some useful
modules or builtin commands.  A diagnostic flowchart?  I don't
think that any more RTFM on Unicode is going to help (I've done it
in spades), but if there's a particularly good write-up on Unicode
debugging, please let me know.

Any suggestions would be much appreciated.

FWIW, I'm using Python 2.6.  The example above happens to come from
a script that extracts data from HTML files, which are all in
English, but they are a daily occurrence when I write code to
process non-English text.  The script uses Beautiful Soup.  I won't
post a lot of code because, as I said, what I'm after is not so
much a way around this specific error as much as the tools and
techniques to troubleshoot it and fix it on my own.  But to ground
the problem a bit I'll say that the exception above happens during
the execution of a statement of the form:

  x = '%s %s' % (y, z)

Also, I found that, with the exact same values y and z as above,
all of the following statements work perfectly fine:

  x = '%s' % y
  x = '%s' % z
  print y
  print z
  print y, z


Decode all text input; encode all text output; do all text processing
in Unicode, which also means making all text literals Unicode (prefixed
with 'u').

Note: I'm talking about when you're working with _text_, as distinct
from when you're working with _binary data_, ie bytes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Alf P. Steinbach

* Steven D'Aprano:

On Wed, 10 Feb 2010 09:13:22 +0100, Alf P. Steinbach wrote:


You've
dismissed at least one of my arguments with a simple hand-waving of,
"That's invalid, cuz."

That is not a quote of me. It is a lie.


Alf, although your English in this forum has been excellent so far, I 
understand you are Norwegian, so it is possible that you aren't a native 
English speaker and possibly unaware that quotation marks are sometimes 
ambiguous in English.


While it is true that quoted text is officially meant to indicate a 
direct quote, it is also commonly used in informal text to indicate a 
paraphrase. (There are other uses as well, but they don't concern us now.)


Unfortunately, this means that in informal discussions like this it is 
sometimes difficult to distinguish a direct quote from a paraphrase, 
except by context. In context, as a native speaker, I can assure you that 
Stephen Hansen's use of quotation marks is a paraphrase and not meant to 
be read as a direct quote.


I'm aware that Stephen Hansen maintains that, but I'm not replying to his 
ramblings about insanity and so on (perhaps he is a child, but I'm not replying 
to that kind of stuff).


Anyway, in the original article he refererred to part of the quoted text, 
quoting that in turn as an example of how allegedly patronising (or whatever) 
I'd been to him.


Re-quoting a part *does not make sense* for paraphrasing.

And anyway, he wrote a piece where quotes seemed to signify quoting, drawing 
conclusions from the quoted text.


It's just plain lying.


Cheers & hth.,

- Alf
--
http://mail.python.org/mailman/listinfo/python-list


SocketServer error: AttributeError: instance has no __call__ method

2010-02-10 Thread Jordan Apgar
Hey guys,
I'm having some issues connecting to my Socket Server,  I get this
traceback on the sever side:

Exception happened during processing of request from ('127.0.0.1',
56404)
Traceback (most recent call last):
  File "/usr/lib/python2.6/SocketServer.py", line 281, in
_handle_request_noblock
self.process_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 307, in
process_request
self.finish_request(request, client_address)
  File "/usr/lib/python2.6/SocketServer.py", line 320, in
finish_request
self.RequestHandlerClass(request, client_address, self)
AttributeError: Negotiator instance has no __call__ method

here's the handler and my server:
#server side negotiator
from message import message
from sharedComs import *
from Crypto.Hash import SHA256
from Crypto.Cipher import AES
from Crypto import Random
from Crypto.PublicKey import RSA
import xmlrpclib as xmlrpc
import os
import SocketServer

class Negotiator(SocketServer.BaseRequestHandler):
CLIENT_KEY = 0
CSCIPHER = 1
SCCIPHER = 2
CSHALVES = 3
SCHALVES = 4
FILENAME = 5

def __init__(self, host, hostid, rsa_key, buf = 512):
self.host = host
self.hostid = hostid
self.serverKey = rsa_key
self.buffer = buf
self.clientKey = None
self.SCcipher = None
self.CScipher = None
self.CSHalves = None
self.SCHalves = None
self.file = None

usr_dict = {}

def setSChalves(self):
usr_dict[str(self.client_address)][SCHALVES] =
(Random.new().read(32),
  Random.new().read(32))

def createCiphers(self):
"""Create the two ciphers we will be using for communication
between negotiators"""
name = str(self.client_address)
usr_dict[name][1] = AES.new(SHA256.new(str("KCS",
   usr_dict[name]
[SCHALVES][0],
 
self.serverKey.publickey(),
   usr_dict[name]
[CSHALVES][0],
   usr_dict[name]
[CLIENT_KEY].publickey())).digest())
usr_dict[name][2] = AES.new(SHA256.new(str("KSC",
   usr_dict[name]
[SCHALVES][1],
 
self.serverKey.publickey(),
   usr_dict[name]
[CSHALVES][1],
   usr_dict[name]
[CLIENT_KEY].publickey())).digest())

def handleConn(self, clmsg):
data = clmsg[1]
if data[0] == self.host and data[1] == self.hostid:
return True
else:
return False

def getClientHalves(self, clmsg):
"""Get the halves from the clien as well as the client key."""
print clmsg
print "clmsg[1]", clmsg[1]
data = stringToTuple(clmsg[1])
print "tuple", data
print "tuple[0]", data[0]
print "tuple[1]", data[1]
data = self.serverKey.decrypt(str(data[0]))
print
print "data:",data
print
data = stringToTuple(data)
usr_dict[str(self.client_address)][CLIENT_KEY] =
RSA.construct((data[0],data[1]))
usr_dict[str(self.client_address)][CSHALVES] = (data[2],
data[3])


def handleFileReq(self, clmsg):
"""Determine if the file requested exists:
TODO: if the client is allowed to acces"""

data = DecodeAES(self.CScipher, clmsg[1])
usr_dict[str(self.client_address)][FILENAME] = data
return os.path.exists(usr_dict[str(self.client_address)][5])

def packageFile(self):
f = open(usr_dict[str(self.client_address)][5],"rb")
data = f.read()
f.close()
crypt = EncodeAES(self.SCcipher, data)
f = open(usr_dict[str(self.client_address)]
[5]+str(self.client_address),
 "wb")
f.write(crypt)
f.close
return (True,self.file+self.client.getAddr())


def handleUserDisc(self, clmsg):
os.remove(usr_dict[str(self.client_address)][FILENAME]
+str(self.client_address))



def handle(self):

#Plan on being asked for server comfirmation
msg = self.request.recv(self.buffer)
name = str(self.client_address)
clmsg = None
if not msg == "":
clmsg = xmlrpc.loads()
if not name in usr_dict:
user_dict[name] = ["","","","","",""]

print "handle Server ver"
clmsg = clmsg[0]
if clmsg[0] == CONN:
if not self.handleConn(clmsg):
print "Not right HostID"
del usr_dict[name]

else:
#We got the right message send a reply with our key
srvmsg = message(SERVER_INFO,
 str(self.serverKey.publickey()))
self.request.send(xmlrpc.dump

Re: Creating formatted output using picture strings

2010-02-10 Thread [email protected]
On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote:

> On 2010-02-10, [email protected]  wrote:
> 
> [regardning "picture" output format specifiers]
> 
>> I was thinking that there was a built-in function for this
>> common(?) use case
> 
> I haven't seen that paradigm since my one-and-only exposure to
> COBOL in a class I took back in 1979.  Is the "picture" thing
> commonly used in other places than COBOL?

Seriously?

I've seen it in dozens places other than COBOL over the years in everything 
from  templating languages to report generators, to built-in support in a 
variety of languages (dBASE II anyone?).

Haven't you ever had to get a e.g. a phone number or social security number 
from user input?

S


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread Anthony Tolle
On Feb 10, 2:09 pm, kj  wrote:
> Some people have mathphobia.  I'm developing a wicked case of
> Unicodephobia.
> [snip]

Some general advice (Looks like I am reiterating what MRAB said -- I
type slower :):

1. If possible, use unicode strings for everything.  That is, don't
use both str and unicode within the same project.

2. If that isn't possible, convert strings to unicode as early as
possible, work with them that way, then convert them back as late as
possible.

3. Know what type of string you are working with!  If a function
returns or accepts a string value, verify whether the expected type is
unicode or str.

4. Consider switching to Python 3.x, since there is only one string
type (unicode).

--
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New to Python

2010-02-10 Thread Terry Reedy

On 2/10/2010 5:21 AM, Quin wrote:

Well, PyScripter works find with that code.  Furthermore, the
un-intellisense in IronPython was problematic, inserting the wrong
things, which I had to erase.

Also, there were some code constructs IronPython let pass that
PyScripter didn't, namely, print(), PyScripter requires the ()

Something simple, like:
n = -1
if n <> -1:
print('fell through')

falls through to the print.

So, I don't know what the problem is with IronPython, perhaps it isn't
compatible with Python v3, but on my machine, at least, it doesn't perform.


'<>' is not legal in Python3, so above is not Python3 code.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Tim Chase

Grant Edwards wrote:

[regardning "picture" output format specifiers]

I was thinking that there was a built-in function for this
common(?) use case


I haven't seen that paradigm since my one-and-only exposure to
COBOL in a class I took back in 1979.  Is the "picture" thing
commonly used in other places than COBOL?


I've spotted in the wild as recently as Visual Basic 6.  I don't 
know if remnants made it into Visual Fred (VB.net).  I think 
they're referred to as "format strings", but they're a mystical 
(and poorly documented) suite of characters that seem to have 
accrued features like my bathtub gets mildew.  Most folks just 
copy and paste the format strings from the web.


-tkc



--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread Grant Edwards
On 2010-02-10, [email protected]  wrote:
> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote:
>
>> On 2010-02-10, [email protected]  wrote:
>> 
>> [regardning "picture" output format specifiers]
>> 
>>> I was thinking that there was a built-in function for this
>>> common(?) use case
>> 
>> I haven't seen that paradigm since my one-and-only exposure to
>> COBOL in a class I took back in 1979.  Is the "picture" thing
>> commonly used in other places than COBOL?
>
> Seriously?

Seriously.

> I've seen it in dozens places other than COBOL over the years
> in everything from templating languages to report generators,
> to built-in support in a variety of languages (dBASE II
> anyone?).
>
> Haven't you ever had to get a e.g. a phone number or social
> security number from user input?

Nope.  I guess it's specific to certain application areas. I've
never done any database type stuff.  I do mostly embedded,
device drivers, networking/protocols, industrial automation,
Unix system admin/automation, and scientific visualization.

-- 
Grant Edwards   grante Yow! I once decorated my
  at   apartment entirely in ten
   visi.comfoot salad forks!!
-- 
http://mail.python.org/mailman/listinfo/python-list


A silly question on file opening

2010-02-10 Thread joy99
Dear Group,

I was using Python with IDLE as GUI for quite some time. My Operating
System was Windows XP with Service Pack2.
Recently I changed the Operating System to Windows XP with Service
Pack3. I had to reinstall Python for which I downloaded
"python-2.6.4.msi"and loaded it in my D drive.

Here, as I am trying to open the file if I am giving a statement like,
  file_open=open("python26/file","r")
It is showing an error,
On checking how the files are stored it is showing that it is storing
in D drive directly but not in Python folder in D drive there is no
Python folder at all.
I tried to change the location to D:\file and as I saw in Python Docs
the file reading option is now "r+" so I changed the statement to
   file_open=open("D:\file","r+")
but it is still giving error.
Did I install it wrongly?
If you can please help it out.
Best Regards,
Subhabrata.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "if {negative}" vs. "if {positive}" style

2010-02-10 Thread Ethan Furman

Tim Chase wrote:

Any thoughts on how others make the choice?

-tkc


If one branch is only a few lines, it comes first.  As often as not, 
that tiny branch is checking for errors, and the "else" branch doesn't 
need to be indented.


def func(arg1):
if arg1 is 'stupid':
raise ValueError("that's a stupid argument!")
do_something
do_something_else
etc, etc


~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: Creating formatted output using picture strings

2010-02-10 Thread [email protected]

On Feb 10, 2010, at 3:40 PM, Grant Edwards wrote:

> On 2010-02-10, [email protected]  wrote:
>> On Feb 10, 2010, at 2:57 PM, Grant Edwards wrote:
>> 
>>> On 2010-02-10, [email protected]  wrote:
>>> 
>>> [regardning "picture" output format specifiers]
>>> 
 I was thinking that there was a built-in function for this
 common(?) use case
>>> 
>>> I haven't seen that paradigm since my one-and-only exposure to
>>> COBOL in a class I took back in 1979.  Is the "picture" thing
>>> commonly used in other places than COBOL?
>> 
>> Seriously?
> 
> Seriously.
> 
>> I've seen it in dozens places other than COBOL over the years
>> in everything from templating languages to report generators,
>> to built-in support in a variety of languages (dBASE II
>> anyone?).
>> 
>> Haven't you ever had to get a e.g. a phone number or social
>> security number from user input?
> 
> Nope.  I guess it's specific to certain application areas. I've
> never done any database type stuff.  I do mostly embedded,
> device drivers, networking/protocols, industrial automation,
> Unix system admin/automation, and scientific visualization.

Yah, I've hardly ever had to get SSN input from users in a device driver ;-).

That's what makes groups like this go 'round; we have all done different types 
of things which gives us all different perspectives.

S

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A silly question on file opening

2010-02-10 Thread Anthony Tolle
On Feb 10, 3:42 pm, joy99  wrote:
> Dear Group,
> [snip]
> I tried to change the location to D:\file and as I saw in Python Docs
> the file reading option is now "r+" so I changed the statement to
>    file_open=open("D:\file","r+")
> but it is still giving error.

Only use "r+" if you need to also write to the file.  "r" is still
good for opening for reading.

Without seeing a traceback, I can only assume the error is caused by
using a backslash in the path without escaping it.  Try either the
following:

file_open=open("D:\\file","r+")

file_open=open(r"D:\file","r+")

For an explanation, see the Python documentation:

http://docs.python.org/reference/lexical_analysis.html#string-literals
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need debugging knowhow for my creeping Unicodephobia

2010-02-10 Thread kj
In <402ac982-0750-4977-adb2-602b19149...@m24g2000prn.googlegroups.com> Jonathan 
Gardner  writes:

>On Feb 10, 11:09=A0am, kj  wrote:
>> FWIW, I'm using Python 2.6. =A0The example above happens to come from
>> a script that extracts data from HTML files, which are all in
>> English, but they are a daily occurrence when I write code to
>> process non-English text. =A0The script uses Beautiful Soup. =A0I won't
>> post a lot of code because, as I said, what I'm after is not so
>> much a way around this specific error as much as the tools and
>> techniques to troubleshoot it and fix it on my own. =A0But to ground
>> the problem a bit I'll say that the exception above happens during
>> the execution of a statement of the form:
>>
>> =A0 x =3D '%s %s' % (y, z)
>>
>> Also, I found that, with the exact same values y and z as above,
>> all of the following statements work perfectly fine:
>>
>> =A0 x =3D '%s' % y
>> =A0 x =3D '%s' % z
>> =A0 print y
>> =A0 print z
>> =A0 print y, z
>>

>What are y and z?

  x = "%s %s" % (table['id'], table.tr.renderContents())

where the variable table represents a BeautifulSoup.Tag instance.

>Are they unicode or strings?

The first item (table['id']) is unicode, and the second is str.

>What are their values?

The only easy way I know to examine the values of these strings is
to print them, which, I know, is very crude.  (IOW, to answer this
question usefully, in the context of this problem, more Unicode
knowhow is needed than I have.)  If I print them, the output for
the first one on my screen is "mainTable", and for the second it is

  Tags
  Id


>It sounds like someone, probably beautiful soup, is trying to turn
>your strings into unicode. A full stacktrace would be useful to see
>who did what where.

Unfortunately, there's not much in the stacktrace: 

Traceback (most recent call last):
  File "./download_tt.py", line 427, in 
x = "%s %s" % (table['id'], table.tr.renderContents())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 41: 
ordinal not in range(128)

(NB: the difference between this error message and the one I
originally posted, namely the position of the unrecognized byte,
is because I simplified the code for the purpose of posting it
here, eliminating one additional processing of the second entry of
the tuple above.)

~K

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Ethan Furman

Steven D'Aprano wrote:


Believe me Alf, the fact that people are taking the time to try to argue 
with you instead of just kill-filing you is a compliment.


It's a compliment I am not paying, although I am grateful to those who 
are attempting to teach him.  At the rate it's going, though, I don't 
see myself buying any book he produces.


Besides the arrogant attitude, he is wrong on so many things about 
Python it is truly stunning.  He seems to have confidence born of 
ignorance... a scary sight to see.


In the spirit of being helpful and not just being a jerk myself:

Alf,

Using smileys after declaring somebody is mistaken/wrong/etc makes you 
look bad.


Not attempting to learn the language makes you look like an arrogant 
idiot (case in point: passing-by-object).


Accusing anyone and everyone that criticizes you of making ad hominem 
(sp?) attacks makes you look like a whiner.


After all is said and done - if you had a truly good grasp of Python, I 
might buy your book even if you still had -- ummm -- a less than winning 
presence on the mailing list; but right now your understanding is not 
worth paying for.


Hoping-this-helps-but-not-really-expecting-it-to-ly yours,
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Re: Modifying Class Object

2010-02-10 Thread Steve Holden
Alf P. Steinbach wrote:
> * Duncan Booth:
>> "Alf P. Steinbach"  wrote:
>>
 In CPython objects once created remain in the same memory location
 (and their id is their address). Compare that to IronPython where the
 objects themselves can move around in memory so they have no fixed
 address. Try comparing the IronPython implementation to C pointers
 and you'll cause a lot of confusion. e.g. someone might think the
 id() value is in some way related to an address.
>>> Did you /read/ what you quoted?
>>>
>>>
 Ruby implements integers without using any pointers at all: there's
 nothing in the Python specification which prevents a Python
 implementation doing the same for small integers, in fact I believe
 it has been tried but wasn't found to improve performance.
>>> All theree of your points about Python are wrong; I don't know about
>>> the Ruby point. 
>>
>> Would you care to expand upon your claim that my three points about
>> Python are wrong?
> 
> Sure. I already did in the article you're replying to, immediately
> following what you quote above. You snipped that which you're asking
> for, so I requote:
> 
> 
> 
> First, the current Python language specification formally prevents the
> optimization you mention, because there's no support for binding to do
> anything but direct binding leaving object identities unchanged.
> 
> But in practice that's no big deal though: I can't imagine any code
> relying on identities of completely immutable objects.
> 
> Second, even the variant that was tried improved performance.
> 
> But it would reportedly have wreaked havoc with imperfect C code.
> 
> Third, the optimization doesn't do away with pointers. If it did then it
> would transform the language completely. The user's view is still one
> where names denote pointers.
> 
> 
> 
> Since in the quoting above no reference to definition of "pointer"
> remains: "pointer" refers to a copyable reference value as seen from the
> Python level, in the same way as "pointer" is used by e.g. the Java
> language spec.
> 
> 
>> Are you saying that CPyhton objects move around, or that IronPython
>> objects are fixed to a single memory location or that their id is
>> related to their address?
> 
> No, I can't see how you can deduce any such connection from I wrote.
> 
> Whether objects "move around" depends on what exactly you mean by "move
> around", and given that, it may then depend on the Python implementation.
> 
> However, from the Python point of view every object has a fixed unique
> id, available via id().
> 
> 
>> Clue here:
>>
>> IronPython 2.6 (2.6.10920.0) on .NET 2.0.50727.3082
>> Type "help", "copyright", "credits" or "license" for more information.
> x = 42
> id(x)
>> 43
> y = 43
> id(y)
>> 44
> z = "whatever"
> id(z)
>> 45
>>
> 
> I'm guessing wildly that you're trying to illustrate id's that don't
> correspond to memory addresses?
> 
> If so, then that's correct: a Python (or Java, or whatever language)
> pointer is not necessarily directly a memory address, and furthermore id
> is not guaranteed to reproduce the bits of a pointer value  --  which
> might not even make sense.
> 
> All that id does is to produce a value that uniquely identifies the
> object pointed to, i.e. it corresponds to the pointer value, and
> although in CPython that's simply the bits of a C pointer typed as
> integer, in IronPython it's not.
> 
You go too far here. What you are referring to in your bizarrely
constructed definition above as a pointer does not allow you to access
the value that is "pointed to". So I fail to see why you feel its its
introduction is necessary.

Whether in CPython, Jython or IronPython the value returned by calling
id(x) (whether x is a literal, a simple name or a more complex
expression) is absolutely no use as an accessor: it does not give you
access to the referenced value.

If you disagree, please write (in any implementation you like: it need
not even be portable, though I can't imagine why ti wouldn't be) a
Python function which takes an id() value as its argument and returns
the value for which the id() value was provided.

So in your world it's unnecessary for pointers to point to anything (or
references to refer to something)? For someone who cheerfully admits to
being wrong from time to time (an admirable characteristic) you are
certainly difficult to convince on this point. One wonders what further
hand-waving will follow.

regards
 Steve
-- 
Steve Holden   +1 571 484 6266   +1 800 494 3119
PyCon is coming! Atlanta, Feb 2010  http://us.pycon.org/
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS:http://holdenweb.eventbrite.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >