November 20 Webinar: Interpolation with NumPy/SciPy

2009-11-15 Thread Amenity Applewhite


Having trouble viewing this email? Click here

Friday, November 20:
Interpolation with NumPy/SciPy
Dear Amenity,

It's time for our mid-month Scientific Computing with Python webinar!  
This month's topic is sure to prove very useful for data analysts:  
Interpolation with NumPy and SciPy.


In many data-processing scenarios, it is necessary to use a discrete  
set of available data-points to infer the value of a function at a new  
data-point. One approach to this problem is interpolation, which  
constructs a new model-function that goes through the original data- 
points. There are many forms of interpolation - polynomial, spline,  
kriging, radial basis function, etc. - and SciPy includes some of  
these interpolation forms. This webinar will review the interpolation  
modules available in SciPy and in the larger Python community and  
provide instruction on their use via example.

Scientific Computing with Python Webinar:
Interpolation with NumPy/SciPy
Friday, November 20
1pm CDT/7pm UTC
Register at GoToMeeting
We look forward to seeing you Friday! As always, feel free to contact  
us with questions, concerns, or suggestions for future webinar topics.


Thanks,

The Enthought Team
QUICK LINKS :::
www.enthought.com
code.enthought.com
Facebook
Enthought Blog
Forward email

This email was sent to amen...@enthought.com by amen...@enthought.com.
Update Profile/Email Address | Instant removal with SafeUnsubscribe™ |  
Privacy Policy.

Enthought, Inc. | 515 Congress Ave. | Suite 2100 | Austin | TX | 78701


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

   Support the Python Software Foundation:
   http://www.python.org/psf/donations/


gevent 0.11.1 released

2009-11-15 Thread Denis Bilenko
gevent is a coroutine-based Python networking library that uses
greenlet to provide
a high-level synchronous API on top of libevent event loop.

Features include:

* convenient API around greenlets
* familiar synchronization primitives (gevent.event, gevent.queue)
* socket module that cooperates
* WSGI server on top of libevent-http
* DNS requests done through libevent-dns
* monkey patching utility to get pure Python modules to cooperate

0.11.1 fixes a few bugs:

* Fixed bug in select.select() function. Passing non-empty list of
write descriptors used to cause this function to fail.
* Changed setup.py to go ahead with the compilation even if the actual
version of libevent cannot be determined (version 1.x.x is assumed in
that case).
* Fixed wsgi‘s start_response to recognize exc_info argument.
* Fixed setup.py to look for libevent.dylib rather than .so on Darwin platforms.

Thanks to Ludvig Ericson for contributing the last two items.

Get it on PyPI: http://pypi.python.org/pypi/gevent
Homepage: http://gevent.org/
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations/


Re: Vote on PyPI comments

2009-11-15 Thread Michele Simionato
On Nov 15, 5:17 am, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Fri, 13 Nov 2009 07:53:05 -0800, Michele Simionato wrote:
  I am skeptical about the utility of both rating and comments. If
  somebody wants to know
  if a package is good, she should ask here.

 Because unlike people writing comments, people here are never
 incompetent, misinformed, dishonest, confused, trolling or just wrong.

 But sometimes sarcastic.

 --
 Steven

All right, but the newsgroup has interactivity and the presence of
true Python experts too.
A blind vote given by an anonymous person does not look more
informative to me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-15 Thread Terry Reedy

greg wrote:

John Nagle wrote:

   Take a good look at Shed Skin.  ...
You give up some flexibility; a variable can have only one primitive type
in its life, or it can be a class object.  That's enough to simplify the
type analysis to the point that most types can be nailed down before the
program is run.


These restrictions mean that it isn't really quite
Python, though.


Python code that only uses a subset of features very much *is* Python 
code. The author of ShedSkin makes no claim that is compiles all Python 
code.


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


Re: Vote on PyPI comments

2009-11-15 Thread Daniel Fetchinson
  I am skeptical about the utility of both rating and comments. If
  somebody wants to know
  if a package is good, she should ask here.

 Because unlike people writing comments, people here are never
 incompetent, misinformed, dishonest, confused, trolling or just wrong.

 But sometimes sarcastic.


 All right, but the newsgroup has interactivity and the presence of
 true Python experts too.
 A blind vote given by an anonymous person does not look more
 informative to me.

You are right about a single vote, but the way these things usually
work is that out of 1000 votes the non-informative ones average out
(wow! awsome package! vs this sucks bad!) and the net vote result
is generally indicative of the actual thing that was voted on
especially when there is no direct financial incentive to cheat.

Cheers,
Daniel


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


Re: #define (from C) in Python

2009-11-15 Thread garabik-news-2005-05
Santiago Romero srom...@gmail.com wrote:
 Hey, I got 100% with ASM ZX Spectrum emulator on a low end 386 :-) (I do
 not remember the CPU freqeuncy anymore, maybe 25MHz).
 
 Yes, in ASM a simple 25 or 33Mhz 386 computer was able to emulate
 the
 Spectrum. At least, under MSDOS, like did Warajevo, Z80, x128 and
 Spectrum
 from Pedro Gimeno.

And my very own, (sadly, rather little known at the time) 'Nuclear ZX'
:-) It did not use a dispatch table - rather, each Z80 instruction was
taken as a high byte of the pointer to a 64KB block of 8086 code, low
byte being zero for unprefixed instructions or a given value for
prefixed ones. This approach saved one lookup (several cycles) and one
indirect jump (another several cycles) per instruction. Another
optimization would be to unroll the return jump from each of the
emulated instructions and replace it directly with inline
read-the-next-instruction-and-jump-there code, but I never got around to
that (would save one 8086 jump per one Z80 instruction :-))

 
 http://perl-spectrum.sourceforge.net/

 It is quite fast IMHO.
 
 It does not run 100% in my 1.8Ghz centrino computer :-(, but almost.
 At least, is a good start to see that is possible, at least no current
 DualCore computers :-)

Python IS slower than perl, especially since you are dealing with
objects. However, I'd suggest go the cPickle route - have a Z80Cpu
module, and its C equivalent, cZ80, and use that one if available. This
way, the emulator will be actually usable everywhere.


-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Vote on PyPI comments

2009-11-15 Thread Jonathan Hartley
On Nov 15, 9:21 am, Daniel Fetchinson fetchin...@googlemail.com
wrote:
   I am skeptical about the utility of both rating and comments. If
   somebody wants to know
   if a package is good, she should ask here.

  Because unlike people writing comments, people here are never
  incompetent, misinformed, dishonest, confused, trolling or just wrong.

  But sometimes sarcastic.

  All right, but the newsgroup has interactivity and the presence of
  true Python experts too.
  A blind vote given by an anonymous person does not look more
  informative to me.

 You are right about a single vote, but the way these things usually
 work is that out of 1000 votes the non-informative ones average out
 (wow! awsome package! vs this sucks bad!) and the net vote result
 is generally indicative of the actual thing that was voted on
 especially when there is no direct financial incentive to cheat.

 Cheers,
 Daniel

 --
 Psss, psss, put it down! -http://www.cafepress.com/putitdown


I haven't used the PyPI rating / comments system at all. Can comments
accrue which complain about bugs or missing features of old versions
of the package? If so, they could be misleading for users coming to
view a package before trying it.

Or do comments and ratings only apply to a particular version of a
package, and get removed from the package's 'front page' every time a
new version is released?

Thanks,
  Jonathan Hartley
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: #define (from C) in Python

2009-11-15 Thread Santiago Romero
 Python IS slower than perl, especially since you are dealing with
 objects. However, I'd suggest go the cPickle route - have a Z80Cpu
 module, and its C equivalent, cZ80, and use that one if available. This
 way, the emulator will be actually usable everywhere.

 Thanks for the advice but ... my (currently working) emulator is
already written in C, I don't see the point of calling it from a
python module. I had 2 options: port the emulator from C+Allegro to C
+SDL or port it to Python+Pygame+SDL...

 And the fun is trying to write it in pure python with pygame, without
external C :-)

 I'll do a quick test, if I see that I can't achieve 100% speed in my
other computer (DualCore2 1.82Ghz, the basic-standard-minimum computer
nowadays), then I'll give up, but at least I want to try it X-D

 Today or tomorrow I'm finishing the pyinliner.py preprocessor X-D.
I'll paste the results here :-)

 Thanks for your answer :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Changing the current directory

2009-11-15 Thread vsoler
Ever since I installed my Python 2.6 interpreter, I've been saving my
*.py files in the C:\Program Files\Python26 directory, which is the
default directory for such files in my system.

However, I have realised that the above is not the best practice.
Therefore I created the C:\Program Files\Python26\test directory and I
want it to be my default directory for saving *.py files, importing
modules, etc.

I'd like to do something like the DOS equivalent of   CD test but I
do not know kow to do it.

I am currently doing something really awful: I open a *.py file in the
est subdirectory, I run it with the F5 key and it works! but I am
doing really something stupid.

I can see that it works because if I do
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More Python versions on an XP machine

2009-11-15 Thread Nobody
On Sat, 14 Nov 2009 14:45:48 +0100, Gabor Urban wrote:

 this a very MS specific question. I do use a rather old Python
 version, because we have a couple of applications written for that.
 Porting them to a newer Python is not allowed by the bosses. Now we
 will start a new project with latest stable Python. Can I have them
 both on my computer, and how should I do that.

You can have multiple versions, but you can only associate one specific
version with the .py suffix.

This matters if you need to be able to execute .py files as if they
were executables, e.g. double-clicking on the script in Explorer or
typing the script's name in the command prompt.

You can run scripts which use other versions of Python by specifying the
interpreter explicitly, e.g.:

C:\Program Files\Python25\python.exe C:\Program Files\MyApp\myscript.py

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


Changing the current directory (full post)

2009-11-15 Thread vsoler
Oops!!! something went wrong with my keyboard. Here you have my full
post:

Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
been saving my
*.py files in the C:\Program Files\Python26 directory, which is the
default directory for such files in my system.

However, I have realised that the above is not the best practice.
Therefore I created the C:\Program Files\Python26\test directory and I
want it to be my default directory for saving *.py files, importing
modules, etc.

I'd like to do something like the DOS equivalent of   CD test but I
do not know kow to do it.

I am currently doing something really awful: I open a *.py file in the
test subdirectory, I run it with the F5 key and it works! but I am
doing really something stupid.

I can see that it works because if I do

import sys
sys.path

... the first directory in the list is the test one.

How should I proceed, if I want to proceed properly?

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


Re: How to know if a file is a text file

2009-11-15 Thread Nobody
On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote:

 I'm looking for a way to be able to load a generic file from the
 system and understand if he is plain text.
 The mimetype module has some nice methods, but for example it's not
 working for file without extension.
 
 Any suggestion?

You could use the file command. It's normally installed by default on
Unix systems, but you can get a Windows version from:

http://gnuwin32.sourceforge.net/packages/file.htm

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


Re: How to know if a file is a text file

2009-11-15 Thread Chris Rebert
On Sun, Nov 15, 2009 at 4:06 AM, Nobody nob...@nowhere.com wrote:
 On Sat, 14 Nov 2009 17:02:29 +0100, Luca Fabbri wrote:

 I'm looking for a way to be able to load a generic file from the
 system and understand if he is plain text.
 The mimetype module has some nice methods, but for example it's not
 working for file without extension.

 Any suggestion?

 You could use the file command. It's normally installed by default on
 Unix systems, but you can get a Windows version from:

FWIW, IIRC the heuristic `file` uses to check whether a file is text
or not is whether it contains any null bytes; if it does, it
classifies it as binary (i.e. not text).

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


basic class question..

2009-11-15 Thread Pyrot
class rawDNA:
import string
trans = string.maketrans(GATC,CTAG)


def __init__(self, template = GATTACA):
self.template = template  //shouldn't this make template
accessible within the scope of rawDNA??


def noncoding(self):
print template.translate(trans)  //
test = rawDNA()

test.noncoding()

Traceback (most recent call last):
  File pyshell#29, line 1, in module
test.noncoding()
  File pyshell#25, line 7, in noncoding
print template.translate(trans)
NameError: global name 'template' is not defined

I'm curious .. what am I doing wrong??

P.S

class rawDNA:
import string
trans = string.maketrans(GATC,CTAG)
def __init__(self, template = GATTACA):
self.template = template
def noncoding(self):
print self.template.translate(trans)

this works as intended.

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


Re: How to know if a file is a text file

2009-11-15 Thread Luca
On Sat, Nov 14, 2009 at 6:51 PM, Philip Semanchuk phi...@semanchuk.com wrote:
 Hi Luca,
 You have to define what you mean by text file. It might seem obvious, but
 it's not.

 Do you mean just ASCII text? Or will you accept Unicode too? Unicode text
 can be more difficult to detect because you have to guess the file's
 encoding (unless it has a BOM; most don't).

 And do you need to verify that every single byte in the file is text? What
 if the file is 1GB, do you still want to examine every single byte?

 If you give us your own (specific!) definition of what text means, or
 perhaps a description of the problem you're trying to solve, then maybe we
 can help you better.


Thanks all.

I was quite sure that this is not a very simple task. Right now search
only inside ASCII encode is not enough for me (my native language is
outside this encode :-)
Checking every single byte can be a good solution...

I can start using the mimetype module and, if the file has no
extension, check byte one by one (commonly) as file command does.
Better: I can check use the file command if available.

Again: thanks all!

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


Re: basic class question..

2009-11-15 Thread Diez B. Roggisch

Pyrot schrieb:

class rawDNA:
import string


Importing here is unusual. Unless you have good reasons to do so, I 
suggest you put the imports on top of the file.



trans = string.maketrans(GATC,CTAG)


def __init__(self, template = GATTACA):
self.template = template  //shouldn't this make template
accessible within the scope of rawDNA??


No.



def noncoding(self):
print template.translate(trans)  //


This needs to be

  print self.template.translate(trans)

Thes scopes insied a class are only the method-locals (to which the 
parameters count of course), and globals.


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


python win32com problem

2009-11-15 Thread elca



hello , these day im very stress of one of some strange thing.

i want to enumurate inside list of url, and every enumurated url i want to
visit

i was uplod incompleted script source in here =

http://elca.pastebin.com/m6f911584

if anyone can help me really appreciate

thanks in advance

Paul

-- 
View this message in context: 
http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: basic class question..

2009-11-15 Thread Tim Chase

Pyrot wrote:

class rawDNA:
import string
trans = string.maketrans(GATC,CTAG)


def __init__(self, template = GATTACA):
self.template = template  //shouldn't this make template
accessible within the scope of rawDNA??


No.  Python's scope resolution consists only of local, global, 
or explicit.  There is no try to find this in the instance or 
class scope-resolution guessing.  Your code makes template 
accessible within the scope of self, not in a global 
unqualified scope.


So this:


def noncoding(self):
print template.translate(trans)  //


tries to reference template first in the local scope (within 
noncoding(), but it doesn't exist there), then in the global 
scope (it also doesn't exist there), and stops.


It should be as you have it here:


class rawDNA:
import string
trans = string.maketrans(GATC,CTAG)
def __init__(self, template = GATTACA):
self.template = template
def noncoding(self):
print self.template.translate(trans)


Here, you start with self which *is* in the local scope, which 
*does* contain template and so it successfully finds it and all 
is [qualifiedly] good.  However, you'll also find that trans 
isn't found because it's neither in the local nor global scope:



   class RawDNA:
  ... import string
  ... trans = string.maketrans(GATC, CTAG)
  ... def __init__(self, template=GATTACA):
  ... self.template = template
  ... def noncoding(self):
  ... print self.template.translate(trans)
  ...
   r = RawDNA()
   r.noncoding()
  Traceback (most recent call last):
File stdin, line 1, in module
File stdin, line 7, in noncoding
  NameError: global name 'trans' is not defined

so you need to fully qualify it as RawDNA.trans for Python to 
find it.  (I also shifted to using the PEP-8 naming convention 
RawDNA instead of rawDNA).


Which you indeed discovered:


this works as intended.


Being explicit is part of Python Zen  (from the python 
command-prompt, type import this to see the whole list)


-tkc




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


Re: basic class question..

2009-11-15 Thread Diez B. Roggisch

Diez B. Roggisch schrieb:

Pyrot schrieb:

class rawDNA:
import string


Importing here is unusual. Unless you have good reasons to do so, I 
suggest you put the imports on top of the file.



trans = string.maketrans(GATC,CTAG)


def __init__(self, template = GATTACA):
self.template = template  //shouldn't this make template
accessible within the scope of rawDNA??


No.



def noncoding(self):
print template.translate(trans)  //


This needs to be

  print self.template.translate(trans)


Ah, sorry, that should have been

  self.template.translate(self.trans)

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


Code for finding the 1000th prime

2009-11-15 Thread mrholtsr
I am absolutely new to python and barely past beginner in programming.
Also I am not a mathematician. Can some one give me pointers for
finding the 1000th. prime for a course I am taking over the internet
on Introduction to Computer Science and Programming. Thanks, Ray
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Code for finding the 1000th prime

2009-11-15 Thread Diez B. Roggisch

mrholtsr schrieb:

I am absolutely new to python and barely past beginner in programming.
Also I am not a mathematician. Can some one give me pointers for
finding the 1000th. prime for a course I am taking over the internet
on Introduction to Computer Science and Programming. Thanks, Ray


Do you really think we are so retarded that we don't remember you posted 
the same question a week ago?


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


Stagnant Frame Data?

2009-11-15 Thread Mike
I'll apologize first for this somewhat lengthy example. It does
however recreate the problem I've run into. This is stripped-down code
from a much more meaningful system.

I have two example classes, AutoChecker and Snapshot that evaluate
variables in their caller's namespace using the frame stack. As
written, the output is not what is expected: the variables evaluate to
stagnant values.

However, if the one indicated line is uncommented, then the result is
as expected.

So my questions are: Is this a bug in Python? Is this an invalid use
of frame data? Why does the single line sys._getframe(1).f_locals
fix the behavior?

Thanks,

Mike


import sys

class Snapshot(object):
def __init__(self, caller_globals, caller_locals):
self.signals = []
self.caller_globals = caller_globals
self.caller_locals = caller_locals

def get_values(self):
samples = {}
for signal in self.signals:
samples[signal] = eval(signal, self.caller_globals,
self.caller_locals)
return samples

def print_values(self):
print 'snapshot data'
for name, value in self.get_values().items():
print '\t', name, '=', value


class AutoChecker(object):
def __init__(self, statement):
self.statement = statement
self.caller_globals = sys._getframe(1).f_globals
self.caller_locals = sys._getframe(1).f_locals
self.snapshot = Snapshot(self.caller_globals,
self.caller_locals)
self.snapshot_history = []

def check(self):
# uncomment following line to get expected behavior
#sys._getframe(1).f_locals
if eval(self.statement, self.caller_globals,
self.caller_locals) == False:
print self.statement, 'failed'
self.snapshot.print_values()
self.snapshot_history.append(self.snapshot.get_values())

def report(self):
if len(self.snapshot_history):
return
print 'snapshot history'
for samples in self.snapshot_history:
for name, value in samples.items():
print '\t', name, '=', value


def f():
x = 0.0
y = 0.0
ac1 = AutoChecker('x  2.0')
ac1.snapshot.signals.append('x')
ac1.snapshot.signals.append('y')

for i in range(5):
x = i / 2.0
y = x / 2
print i, x
ac1.check()
ac1.snapshot.print_values()
ac1.report()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python win32com problem

2009-11-15 Thread Jon Clements
On Nov 15, 1:08 pm, elca high...@gmail.com wrote:
 hello , these day im very stress of one of some strange thing.

 i want to enumurate inside list of url, and every enumurated url i want to
 visit

 i was uplod incompleted script source in here =

 http://elca.pastebin.com/m6f911584

 if anyone can help me really appreciate

 thanks in advance

 Paul

 --
 View this message in 
 context:http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html
 Sent from the Python - python-list mailing list archive at Nabble.com.

How much effort have you put into this? It looks like you've just
whacked together code (that isn't valid -- where'd the magical
'buttons' variable come from), given up and cried for help.

Besides, I would suggest you're taking completely the wrong route.
You'll find it one hell of a challenge to automate a browser as you
want, that's if it supports exposing the DOM anyway. And without being
rude, would definitely be beyond your abilities from your posts to
c.l.p.

Download and install BeautifulSoup from 
http://www.crummy.com/software/BeautifulSoup/
- you seem to have quite a few HTML based needs in your pastebin, so
it'll come in useful for the future.

Here's a snippet to get you started:

from urllib2 import urlopen
from BeautifulSoup import BeautifulSoup as BS

url = urlopen('http://news.naver.com/main/presscenter/category.nhn')
urldata = url.read()
soup = BS(urldata)
atags = soup('a', attrs={'href': lambda L: L and L.startswith('http://
news.khan.co.kr')})
for atag in atags:
print atag['href']

I'll leave it to you where you want to go from there (ie, follow the
links, or automate IE to open said pages etc...)

I strongly suggest reading the urllib2 and BeautifulSoup docs, and
documenting the above code snippet -- you should then understand it,
should be less stressed, and have something to refer to for similar
requirements in the future.

hth,
Jon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Stagnant Frame Data?

2009-11-15 Thread Peter Otten
Mike wrote:

 I'll apologize first for this somewhat lengthy example. It does
 however recreate the problem I've run into. This is stripped-down code
 from a much more meaningful system.
 
 I have two example classes, AutoChecker and Snapshot that evaluate
 variables in their caller's namespace using the frame stack. As
 written, the output is not what is expected: the variables evaluate to
 stagnant values.
 
 However, if the one indicated line is uncommented, then the result is
 as expected.
 
 So my questions are: Is this a bug in Python? Is this an invalid use
 of frame data? Why does the single line sys._getframe(1).f_locals
 fix the behavior?

A simplified demonstration of your problem:

 def f(update):
... a = locals()
... x = 42
... if update: locals()
... print a
...
 f(False)
{'update': False}
 f(True)
{'a': {...}, 'x': 42, 'update': True}

The local namespace is not a dictionary, and the locals()/f_locals 
dictionary contains a snapshot of the local namespace. Accessing the 
f_locals attribute is one way to trigger an update of that snapshot. 

What's puzzling is that the same dictionary is reused.

Peter

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


Re: (unknown)

2009-11-15 Thread Gabriel Genellina
En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross ronn.r...@gmail.com  
escribió:



I'm attempting to convert latitude and longitude coordinates from degrees
minutes and second to decimal form. I would like to go from:
N39 42 36.3 W77 42 51.5
 to:
-77.739855,39.70

Does anyone know of a library or some existing out their to help with  
this

conversion?


Should be:

decimal = degrees + minutes/60.0 + seconds/3600.0
N,E are positive; S,W are negative.

But the above numbers don't match.

--
Gabriel Genellina

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


Re: (unknown)

2009-11-15 Thread Gabriel Genellina
En Fri, 13 Nov 2009 16:05:26 -0300, Ronn Ross ronn.r...@gmail.com  
escribió:



I'm attempting to convert latitude and longitude coordinates from degrees
minutes and second to decimal form. I would like to go from:
N39 42 36.3 W77 42 51.5
 to:
-77.739855,39.70

Does anyone know of a library or some existing out their to help with  
this

conversion?


Should be:

decimal = degrees + minutes/60.0 + seconds/3600.0
N,E are positive; S,W are negative.

But the above numbers don't match.

--
Gabriel Genellina

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


Re: Choosing GUI Module for Python

2009-11-15 Thread Dietmar Schwertberger

sturlamolden schrieb:

On 14 Nov, 19:02, Dietmar Schwertberger n...@schwertberger.de wrote:

I tried 3.01.63.
I can see in the Python window already that the code is not correct.


3.01.63

Did you remember to install the wxAdditions?

No. I think that they should not be required (a minimal version seems
to be included in wxFormBuilder) and I don't get any error message.
Also using wxAdditions for wx Python doesn't seem to be straightforward.


Could you send me an .fbp file demonstrating the error?

Sent by email. Did you receive it?

Regards,

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


Re: Stagnant Frame Data?

2009-11-15 Thread exarkun

On 04:00 pm, __pete...@web.de wrote:

Mike wrote:

I'll apologize first for this somewhat lengthy example. It does
however recreate the problem I've run into. This is stripped-down code
from a much more meaningful system.

I have two example classes, AutoChecker and Snapshot that evaluate
variables in their caller's namespace using the frame stack. As
written, the output is not what is expected: the variables evaluate to
stagnant values.

However, if the one indicated line is uncommented, then the result is
as expected.

So my questions are: Is this a bug in Python? Is this an invalid use
of frame data? Why does the single line sys._getframe(1).f_locals
fix the behavior?


A simplified demonstration of your problem:

def f(update):

... a = locals()
... x = 42
... if update: locals()
... print a
...

f(False)

{'update': False}

f(True)

{'a': {...}, 'x': 42, 'update': True}

The local namespace is not a dictionary, and the locals()/f_locals
dictionary contains a snapshot of the local namespace. Accessing the
f_locals attribute is one way to trigger an update of that snapshot.

What's puzzling is that the same dictionary is reused.


http://bugs.python.org/issue6116 is vaguely related.

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


Redirect stdout to a buffer

2009-11-15 Thread Ecir Hana
Hello,

I'm trying to write a simple Win32 app, which may run some Python
scripts. Since it is a Windows GUI app, I would like to redirect all
output (Python print, C printf, fprinf stderr, ...) to a text area
inside the app. In other words, I'm trying to log all the output from
the app (C, Python) to a window. So far, this works for C printf():

int fds[2];
_pipe(fds, 1024, O_TEXT);
_dup2(fds[1], 1);
...
and then I read from pipe's read-end and append the text to the text
area.

But when I try to run:
Py_Initialize();
PyRun_SimpleString(print 'abc');
Py_Finalize();

I get an error:
IOError: [Errno 9] Bad file descriptor

What am I doing wrong? How to redirect standard IO, both for C and for
Python?
PS: Maybe I'm doind something wrong, but SetStdHandle() does not work
at all
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __import__ returns module without it's attributes?

2009-11-15 Thread Gabriel Genellina

En Fri, 13 Nov 2009 20:27:29 -0300, Zac Burns zac...@gmail.com escribió:


I've overloaded __import__ to modify modules after they are
imported... but running dir(module) on the result only returns
__builtins__, __doc__, __file__,
__name__, __package__, and __path__.

Why is this? More importantly, where can I hook in that would allow me
to see the contents of the module?


Post some code. This works for me:

py import __builtin__
py builtin_import = __builtin__.__import__
py def __import__(*args):
...   module = builtin_import(*args)
...   module.__signature__ = kilroywashere
...   return module
...
py __builtin__.__import__ = __import__
py
py import htmllib
py dir(htmllib)
['AS_IS', 'HTMLParseError', 'HTMLParser', '__all__', '__builtins__',
 '__doc__', '__file__', '__name__', '__package__', '__signature__',
 'sgmllib', 'test']
py htmllib.__signature__
'kilroywashere'

--
Gabriel Genellina

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


IDE for python

2009-11-15 Thread Peng Yu
There had been some discussion on IDE. But I'm not sure what pros and
cons of each choice. Current, I'm using vim and ctags.

Could somebody give some advices on choosing the best IDE for me?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4b3300d10285ae2b/e934bd5b9f2d0f8c?lnk=gstq=IDE#e934bd5b9f2d0f8c
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for python

2009-11-15 Thread Diez B. Roggisch

Peng Yu schrieb:

There had been some discussion on IDE. But I'm not sure what pros and
cons of each choice. Current, I'm using vim and ctags.

Could somebody give some advices on choosing the best IDE for me?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/4b3300d10285ae2b/e934bd5b9f2d0f8c?lnk=gstq=IDE#e934bd5b9f2d0f8c


I suggest you use your google foo that you just showed to search in this 
group for the numerous discussions about emacs, vi, eclipse+pydev, wing 
ide, komodo and notepad.


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


How can pip install a GitHub code drop?

2009-11-15 Thread Phlip
Not Hyp:

Suppose I have a Python library, complete with a respectable setup.py.

How can I point pip at the repo to install the library?

if I use this...

sudo pip -e git+git://github.com/Phlip/Kozmiq.git

...I get an editable drop in a ~/src/ folder.

--
  Phlip
  http://c2.com/cgi/wiki?ZeekLand
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-15 Thread Paul Boddie
On 15 Nov, 09:30, Terry Reedy tjre...@udel.edu wrote:
 greg wrote:


[Shed Skin]

  These restrictions mean that it isn't really quite
  Python, though.

 Python code that only uses a subset of features very much *is* Python
 code. The author of ShedSkin makes no claim that is compiles all Python
 code.

Of course, Shed Skin doesn't support all the usual CPython features,
but the code you would write for Shed Skin's benefit should be Python
code that runs under CPython. It's fair to say that Shed Skin isn't a
complete implementation of what CPython defines as being the full
Python, but you're still writing Python. One can argue that the
restrictions imposed by Shed Skin inhibit the code from being proper
Python, but every software project has restrictions in the form of
styles, patterns and conventions.

This is where the Lesser Python crowd usually step in and say that
they won't look at anything which doesn't support the full Python,
but I think it's informative to evaluate which features of Python give
the most value and which we could do without. The Lesser Python
attitude is to say, No! We want it all! It's all necessary for
everything! That doesn't really help the people implementing proper
implementations or those trying to deliver better-performing
implementations.

In fact, the mentality that claims that it's perfect, or it will be
if we keep adding features could drive Python into a diminishing
niche over time. In contrast, considering variations of Python as some
kind of Greater Python ecosystem could help Python (the language)
adapt to the changing demands on programming languages to which Go
(the Google language, not Go! which existed already) is supposedly a
response.

Paul

P.S. And PyPy is hardly a dud: they're only just getting started
delivering the performance benefits, and it looks rather promising.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python win32com problem

2009-11-15 Thread elca



Jon Clements-2 wrote:
 
 On Nov 15, 1:08 pm, elca high...@gmail.com wrote:
 hello , these day im very stress of one of some strange thing.

 i want to enumurate inside list of url, and every enumurated url i want
 to
 visit

 i was uplod incompleted script source in here =

 http://elca.pastebin.com/m6f911584

 if anyone can help me really appreciate

 thanks in advance

 Paul

 --
 View this message in
 context:http://old.nabble.com/python-win32com-problem-tp26358976p26358976.html
 Sent from the Python - python-list mailing list archive at Nabble.com.
 
 How much effort have you put into this? It looks like you've just
 whacked together code (that isn't valid -- where'd the magical
 'buttons' variable come from), given up and cried for help.
 
 Besides, I would suggest you're taking completely the wrong route.
 You'll find it one hell of a challenge to automate a browser as you
 want, that's if it supports exposing the DOM anyway. And without being
 rude, would definitely be beyond your abilities from your posts to
 c.l.p.
 
 Download and install BeautifulSoup from
 http://www.crummy.com/software/BeautifulSoup/
 - you seem to have quite a few HTML based needs in your pastebin, so
 it'll come in useful for the future.
 
 Here's a snippet to get you started:
 
 from urllib2 import urlopen
 from BeautifulSoup import BeautifulSoup as BS
 
 url = urlopen('http://news.naver.com/main/presscenter/category.nhn')
 urldata = url.read()
 soup = BS(urldata)
 atags = soup('a', attrs={'href': lambda L: L and L.startswith('http://
 news.khan.co.kr')})
 for atag in atags:
   print atag['href']
 
 I'll leave it to you where you want to go from there (ie, follow the
 links, or automate IE to open said pages etc...)
 
 I strongly suggest reading the urllib2 and BeautifulSoup docs, and
 documenting the above code snippet -- you should then understand it,
 should be less stressed, and have something to refer to for similar
 requirements in the future.
 
 hth,
 Jon.
 -- 
 http://mail.python.org/mailman/listinfo/python-list
 
 

Hello, 
thanks for your kind reply.
your script is working very well 
im making scraper now.
and im making with PAMIE but still slow module 
but i have no choice because of javascript support.
before i was try to look for method with mechanize but almost failed.
if mechanize can support javascript maybe my best choice will be mechanize.
ok anyway..there is almost no choice so  i have to go 
automate IE to open said pages etc..
i want to visit every collect link with IE com interface..
for example i was collect 10 url ...i want to visit every 10 url.
would you help me some more?
if so much appreciate thanks
-- 
View this message in context: 
http://old.nabble.com/python-win32com-problem-tp26358976p26361229.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: IDE for python

2009-11-15 Thread Peng Yu
On Nov 15, 11:15 am, Diez B. Roggisch de...@nospam.web.de wrote:
 Peng Yu schrieb:

  There had been some discussion on IDE. But I'm not sure what pros and
  cons of each choice. Current, I'm using vim and ctags.

  Could somebody give some advices on choosing the best IDE for me?

 http://groups.google.com/group/comp.lang.python/browse_thread/thread/...

 I suggest you use your google foo that you just showed to search in this
 group for the numerous discussions about emacs, vi, eclipse+pydev, wing
 ide, komodo and notepad.

I see too many threads. But I don't any of them give me a complete
comparison between different choices. If you are familiar with
different choices, would you please give me some advices?

http://groups.google.com/group/comp.lang.python/search?group=comp.lang.pythonq=IDEqt_g=Search+this+group
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get directory of Python C library

2009-11-15 Thread arve.knud...@gmail.com
Hi

I need to link against Python, is there a way to get the path to the
directory containing Python's C library (e.g., exec-prefix/libs on
Windows)?

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


Re: Documentation bugs in 3.1 - C-API - TypeObjects

2009-11-15 Thread DreiJane
Thanks a second time - the picture has
gotten clearer indeed. But for third-party
readers the complexities of this matter
require the correction, that

Py_Type(Foo_Type) = PyType_Type

must be:
Py_TYPE(Foo_Type) = PyType_Type 

- or am i completely wrong ? Joost
-- 
http://mail.python.org/mailman/listinfo/python-list


overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
I ran the following program, and found its output surprising in one
place:

class OnlyAl:
def __getitem__(self, key): return 'al'

class OnlyBob(dict):
def __getitem__(self, key): return 'bob'

import sys; print sys.version

al = OnlyAl()
bob = OnlyBob()

print al['whatever']
al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!'
print al['whatever']

print bob['whatever']
bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems
impossible'
print bob['whatever']

2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3]
al
NEW AND IMPROVED AL!
bob
bob

In attempting to change the behavior for bob's dictionary lookup, I am
clearly doing something wrong, or maybe even impossible.

Obviously the examples are contrived, but I am interested on a purely
academic level why setting __getitem__  on bob does not seem to change
the behavior of bob['foo'].   Note that OnlyBob subclasses dict;
OnlyAl does not.

On a more practical level, I will explain what I am trying to do.
Basically, I am trying to create some code that allows me to spy on
arbitrary objects in a test environment.  I want to write a spy()
method that takes an arbitrary object and overrides its implementation
of __getitem__ and friends so that I can see how library code is
invoking the object (with print statements or whatever).  Furthermore,
I want spy() to recursively spy on objects that get produced from my
original object.  The particular use case is that I am creating a
context for Django templates, and I want to see which objects are
getting rendered, all the way down the tree.  It would be pretty easy
to just create a subclass of the context method to spy at the top
level, but I want to recursively spy on all its children, and that is
why I need a monkeypatching approach.  The original version had spy
recursively returning proxy/masquerade objects that intercepted
__getitem__ calls, but it becomes brittle when the proxy objects go
off into places like template filters, where I am not prepared to
intercept all calls to the object, and where in some cases it is
impossible to gain control.

Although I am interested in comments on the general problems (spying
on objects, or spying on Django template rendering), I am most
interested in the specific mechanism for changing the __getitem__
method for a subclass on a dictionary.  Thanks in advance!

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


Re: Stagnant Frame Data?

2009-11-15 Thread Terry Reedy

Peter Otten wrote:

Mike wrote:


I'll apologize first for this somewhat lengthy example. It does
however recreate the problem I've run into. This is stripped-down code
from a much more meaningful system.

I have two example classes, AutoChecker and Snapshot that evaluate
variables in their caller's namespace using the frame stack. As
written, the output is not what is expected: the variables evaluate to
stagnant values.

However, if the one indicated line is uncommented, then the result is
as expected.

So my questions are: Is this a bug in Python?


No. The existence and use of sys._getframe -- notice the leading 
underscore -- is a CPython implementation artifact. Use at your own risk.


 Is this an invalid use of frame data?

Up to you to decide.

 Why does the single line sys._getframe(1).f_locals

fix the behavior?


It updates the dictionary.


A simplified demonstration of your problem:


def f(update):

... a = locals()
... x = 42
... if update: locals()
... print a
...

f(False)

{'update': False}

f(True)

{'a': {...}, 'x': 42, 'update': True}

The local namespace is not a dictionary, and the locals()/f_locals 
dictionary contains a snapshot of the local namespace. Accessing the 
f_locals attribute is one way to trigger an update of that snapshot. 


What's puzzling is that the same dictionary is reused.


Efficiency? Consistency? The doc for locals says locals()
Update and return a dictionary representing the current local symbol 
table. In class statements, where (currently) the local namespace *is* 
a dict, no update is needed and locals() simply returns the dict, the 
same one each time.


Terry Jan Reedy


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


Re: Python Go

2009-11-15 Thread Yoav Goldberg
On Sun, Nov 15, 2009 at 4:00 AM, Terry Reedy tjre...@udel.edu wrote:

 Yoav Goldberg wrote:


 On Sun, Nov 15, 2009 at 12:10 AM, Terry Reedy tjre...@udel.edu mailto:
 tjre...@udel.edu wrote:

Paul Rubin wrote:

Mark Chu-Carroll has a new post about Go:


 http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php

In a couple of minutes, I wrote his toy prime filter example in
Python, mostly from the text rather than the code, which I can
barely stand to read. It ran the first time without error.

 Yes, but the cool thing about the Go version is that it does each
 generator in a different thread, so in theory it could run twice as fast on
 a multi-core machine.


 Which is why I added, in my opinion, that It would be much better, for
 instance, to tweak Python, which it has had great success with, to better
 run on multiple cores.

 For instance, add a new keyword 'go' such that
 go def f(): yield 1
 runs the generator in a different thread, possibly on a different core.

 [...]


 I see no reason why we cannot have that with Python. I not even sure we
 cannot have it with CPython, but I am not familiar enough with threads,
 processes, and CPython internals.


 Yes, this could work, and would really cool.
I believe you can go a long way with annotations, and maybe even provide a
full working demo.
So we can definitely have this in python, and it could be a really cool
feature.
Having it in CPython, though, is a different story altogether -- CPython way
of handling threads is problematic, and not going to change soon, see here
about the problem:

http://blog.snaplogic.org/?p=94

and here about it no going away soon:

http://www.python.org/doc/faq/library/#can-t-we-get-rid-of-the-global-interpreter-lock
http://www.artima.com/weblogs/viewpost.jsp?thread=214235


So, yes, we could have this in python, but no I don't see it happening very
soon.. And the compiled Go is really different in design than python -- easy
to parse, easy to compile, static, works fast, etc.  Different language.  Is
it a good thing to have a different language and not base yourself on an
existing one? Not sure.  But that's a different debate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Slicing history?

2009-11-15 Thread Aahz
Anyone remember or know why Python slices function like half-open
intervals?  I find it incredibly convenient myself, but an acquaintance
familiar with other programming languages thinks it's bizarre and I'm
wondering how it happened.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

[on old computer technologies and programmers]  Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As.  --Andrew Dalke
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to know if a file is a text file

2009-11-15 Thread Nobody
On Sun, 15 Nov 2009 04:34:10 -0800, Chris Rebert wrote:

 I'm looking for a way to be able to load a generic file from the
 system and understand if he is plain text.
 The mimetype module has some nice methods, but for example it's not
 working for file without extension.

 Any suggestion?

 You could use the file command. It's normally installed by default on
 Unix systems, but you can get a Windows version from:
 
 FWIW, IIRC the heuristic `file` uses to check whether a file is text
 or not is whether it contains any null bytes; if it does, it
 classifies it as binary (i.e. not text).

file provides more granularity than that, recognising many specific
formats, both text and binary.

First, it uses magic number checks, checking for known signature bytes
(e.g. #! or JFIF) at the beginning of the file. If those checks fail
it checks for common text encodings. If those also fail, it reports data.

Also, UTF-16-encoded text is recognised as text, even though it may
contain a high proportion of NUL bytes.


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


Re: How to know if a file is a text file

2009-11-15 Thread Nobody
On Sun, 15 Nov 2009 13:49:54 +0100, Luca wrote:

 I was quite sure that this is not a very simple task. Right now search
 only inside ASCII encode is not enough for me (my native language is
 outside this encode :-)
 Checking every single byte can be a good solution...
 
 I can start using the mimetype module and, if the file has no
 extension, check byte one by one (commonly) as file command does.
 Better: I can check use the file command if available.

Another possible solution:

Universal Encoding Detector
Character encoding auto-detection in Python 2 and 3

http://chardet.feedparser.org/

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


Re: Slicing history?

2009-11-15 Thread Jon Clements
On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote:
 Anyone remember or know why Python slices function like half-open
 intervals?  I find it incredibly convenient myself, but an acquaintance
 familiar with other programming languages thinks it's bizarre and I'm
 wondering how it happened.
 --
 Aahz (a...@pythoncraft.com)           *        http://www.pythoncraft.com/

 [on old computer technologies and programmers]  Fancy tail fins on a
 brand new '59 Cadillac didn't mean throwing out a whole generation of
 mechanics who started with model As.  --Andrew Dalke

Good ol' zero based indexing. It makes a lot more sense that range(len
(my_list)) returns 'n' values which are valid indicies, otherwise
they'd be a lot of IndexError's being raised.

Besides, when you really want the full range (a corner case), it's a
lot easier to do a +1, than to force people to write -1 for the vast
majority of cases.

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


Re: Python Go

2009-11-15 Thread Steve Howell
On Nov 14, 3:26 am, kj no.em...@please.post wrote:

 One more thing: I found Rob Pike's mutterings on generics (towards
 the end of his rollout video) rather offputting, because he gave
 the impression that some important aspects of the language were
 not even considered before major decisions for it were set in stone.
 It looks like, if they ever get around to supporting generics, it
 will be a late-in-the-day hack.


By set in stone, do you mean implemented?  Or have Rob Pike and
friends literally put a redesign freeze on the language that was just
released this month?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE for python

2009-11-15 Thread Diez B. Roggisch

Peng Yu schrieb:

On Nov 15, 11:15 am, Diez B. Roggisch de...@nospam.web.de wrote:

Peng Yu schrieb:


There had been some discussion on IDE. But I'm not sure what pros and
cons of each choice. Current, I'm using vim and ctags.
Could somebody give some advices on choosing the best IDE for me?
http://groups.google.com/group/comp.lang.python/browse_thread/thread/...

I suggest you use your google foo that you just showed to search in this
group for the numerous discussions about emacs, vi, eclipse+pydev, wing
ide, komodo and notepad.


I see too many threads. But I don't any of them give me a complete
comparison between different choices. If you are familiar with
different choices, would you please give me some advices?

http://groups.google.com/group/comp.lang.python/search?group=comp.lang.pythonq=IDEqt_g=Search+this+group


Again: read the threads. They discuss the various aspects. They arose 
because of the same question asked as yours. If you don't find in them 
what you are looking for, chances are hight that you won't get it.


This is very much a question of personal preferences, not of 
feature-matrices and strict metrics. So go, read, and them make an 
informed choice on what at least to try. Stick with what you prefer.


And given your track record in this group here, I assume regardless of 
*what* beautiful scheme of explaining various IDEs and their respective 
merits, they all fall short of your unique way of doing things.


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


Re: How to get directory of Python C library

2009-11-15 Thread Diez B. Roggisch

arve.knud...@gmail.com schrieb:

Hi

I need to link against Python, is there a way to get the path to the
directory containing Python's C library (e.g., exec-prefix/libs on
Windows)?


Most probably from the registry somehow. In general, try  locate a 
python-executable, and make it execute


 python -c import sys; print sys.prefix

Capture that, and you're done. Depending on the OS, the libs then are 
placed in e.g. prefix/lib.


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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Gary Herron

Steve Howell wrote:

I ran the following program, and found its output surprising in one
place:

class OnlyAl:
def __getitem__(self, key): return 'al'

class OnlyBob(dict):
def __getitem__(self, key): return 'bob'

import sys; print sys.version

al = OnlyAl()
bob = OnlyBob()

print al['whatever']
al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!'
print al['whatever']

print bob['whatever']
bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems
impossible'
print bob['whatever']

2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3]
al
NEW AND IMPROVED AL!
bob
bob
  


It's the difference between old-style and new-style classes.  Type dict 
and therefore OnlyBob are new style.  OnlyAl defaults to old-style.  If 
you derive OnlyAl from type object, you'll get consistent results.


Gary Herron




In attempting to change the behavior for bob's dictionary lookup, I am
clearly doing something wrong, or maybe even impossible.

Obviously the examples are contrived, but I am interested on a purely
academic level why setting __getitem__  on bob does not seem to change
the behavior of bob['foo'].   Note that OnlyBob subclasses dict;
OnlyAl does not.

On a more practical level, I will explain what I am trying to do.
Basically, I am trying to create some code that allows me to spy on
arbitrary objects in a test environment.  I want to write a spy()
method that takes an arbitrary object and overrides its implementation
of __getitem__ and friends so that I can see how library code is
invoking the object (with print statements or whatever).  Furthermore,
I want spy() to recursively spy on objects that get produced from my
original object.  The particular use case is that I am creating a
context for Django templates, and I want to see which objects are
getting rendered, all the way down the tree.  It would be pretty easy
to just create a subclass of the context method to spy at the top
level, but I want to recursively spy on all its children, and that is
why I need a monkeypatching approach.  The original version had spy
recursively returning proxy/masquerade objects that intercepted
__getitem__ calls, but it becomes brittle when the proxy objects go
off into places like template filters, where I am not prepared to
intercept all calls to the object, and where in some cases it is
impossible to gain control.

Although I am interested in comments on the general problems (spying
on objects, or spying on Django template rendering), I am most
interested in the specific mechanism for changing the __getitem__
method for a subclass on a dictionary.  Thanks in advance!

  


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


Re: Slicing history?

2009-11-15 Thread Nobody
On Sun, 15 Nov 2009 10:50:43 -0800, Aahz wrote:

 Anyone remember or know why Python slices function like half-open
 intervals?  I find it incredibly convenient myself, but an acquaintance
 familiar with other programming languages thinks it's bizarre and I'm
 wondering how it happened.

How else would they function? Closed intervals?

Using a closed interval (for just about anything) indicates that the
designer has very limited programming experience. Anyone with a modicum of
programming experience knows that half-open intervals are the norm, and
that using closed intervals will confuse anyone else with a modicum of
programming experience.

That's aside from the objective merits, i.e. the fact that they can be
used to partition an interval into subintervals without having to
adjust the upper bound (which requires knowing how much to adjust the
upper bound by, if that's even possible (for reals, it isn't)).

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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
On Nov 15, 10:25 am, Steve Howell showel...@yahoo.com wrote:
 [see original post...]
 I am most
 interested in the specific mechanism for changing the __getitem__
 method for a subclass on a dictionary.  Thanks in advance!

Sorry for replying to myself, but I just realized that the last
statement in my original post was a little imprecise.

I am more precisely looking for a way to change the behavior of foo
['bar'] (side effects and possibly return value) where foo is an
instance of a class that subclasses dict, and where foo is not
created by me.  The original post gives more context and example code
that does not work as I expect/desire.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
On Nov 15, 11:19 am, Gary Herron gher...@islandtraining.com wrote:
 Steve Howell wrote:
  I ran the following program, and found its output surprising in one
  place:

      class OnlyAl:
          def __getitem__(self, key): return 'al'

      class OnlyBob(dict):
          def __getitem__(self, key): return 'bob'

      import sys; print sys.version

      al = OnlyAl()
      bob = OnlyBob()

      print al['whatever']
      al.__getitem__ = lambda key: 'NEW AND IMPROVED AL!'
      print al['whatever']

      print bob['whatever']
      bob.__getitem__ = lambda key: 'a NEW AND IMPROVED BOB seems
  impossible'
      print bob['whatever']

      2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
      [GCC 4.3.3]
      al
      NEW AND IMPROVED AL!
      bobe
      bob

 It's the difference between old-style and new-style classes.  Type dict
 and therefore OnlyBob are new style.  OnlyAl defaults to old-style.  If
 you derive OnlyAl from type object, you'll get consistent results.


Thanks, Gary.  My problem is that I am actually looking for the
behavior that the old-style OnlyAl provides, not OnlyBob--allowing me
to override the behavior of al['foo'] and bob['foo'].  I (hopefully)
clarified my intent in a follow-up post that was sent before I saw
your reply.  Here it is re-posted for convenience of discussion:

I am more precisely looking for a way to change the behavior of foo
['bar'] (side effects and possibly return value) where foo is an
instance of a class that subclasses dict, and where foo is not
created by me.


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


Re: python simply not scaleable enough for google?

2009-11-15 Thread Edward A. Falk
In article m2d43kemvs@roger-vivier.bibliotech.com,
Robert Brown  bbr...@speakeasy.net wrote:

It's hard to refute your assertion.  You're claiming that some future
hypothetical Python implementation will have excellent performance via a JIT.
On top of that you say that you're willing to change the definition of the
Python language, say by adding type declarations, if an implementation with a
JIT doesn't pan out.  If you change the Python language to address the
semantic problems Willem lists in his post and also add optional type
declarations, then Python becomes closer to Common Lisp, which we know can be
executed efficiently, within the same ballpark as C and Java.

Ya know; without looking at Go, I'd bet that this was some of the thought
process that was behind it.

-- 
-Ed Falk, f...@despams.r.us.com
http://thespamdiaries.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Jon Clements
On Nov 15, 7:23 pm, Steve Howell showel...@yahoo.com wrote:
 On Nov 15, 10:25 am, Steve Howell showel...@yahoo.com wrote:

  [see original post...]
  I am most
  interested in the specific mechanism for changing the __getitem__
  method for a subclass on a dictionary.  Thanks in advance!

 Sorry for replying to myself, but I just realized that the last
 statement in my original post was a little imprecise.

 I am more precisely looking for a way to change the behavior of foo
 ['bar'] (side effects and possibly return value) where foo is an
 instance of a class that subclasses dict, and where foo is not
 created by me.  The original post gives more context and example code
 that does not work as I expect/desire.

[quote from http://docs.python.org/reference/datamodel.html]
For instance, if a class defines a method named __getitem__(), and x
is an instance of this class, then x[i] is roughly equivalent to
x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i)
for new-style classes.
[/quote]

A quick hack could be:

class Al(dict):
  def __getitem__(self, key):
return self.spy(key)
  def spy(self, key):
return 'Al'

 a = Al()
 a[3]
'Al'
 a.spy = lambda key: 'test'
 a[3]
'test'
 b = Al()
 b[3]
'Al'

Seems to be what you're after anyway...

hth,
Jon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python simply not scaleable enough for google?

2009-11-15 Thread Paul Rubin
f...@mauve.rahul.net (Edward A. Falk) writes:
 If you change the Python language to address the semantic problems
 Willem lists in his post and also add optional type declarations,
 then Python becomes closer to Common Lisp, which we know can be
 executed efficiently, within the same ballpark as C and Java.
 
 Ya know; without looking at Go, I'd bet that this was some of the thought
 process that was behind it.

I don't have the slightest impression that Python had any significant
influence on Go.  Go has C-like syntax, static typing with mandatory
declarations, and concurrency inspired by Occam.  It seems to be a
descendant of Oberon and Newsqueak (Pike's earlier language used in
Plan 9).  It also seems to be decades behind the times in some ways.
Its creators are great programmers and system designers, but I wish
they had gotten some PL theorists involved in designing Go.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Documentation bugs in 3.1 - C-API - TypeObjects

2009-11-15 Thread Martin v. Löwis
DreiJane wrote:
 Thanks a second time - the picture has
 gotten clearer indeed. But for third-party
 readers the complexities of this matter
 require the correction, that
 
 Py_Type(Foo_Type) = PyType_Type
 
 must be:
 Py_TYPE(Foo_Type) = PyType_Type 
 
 - or am i completely wrong ? Joost

No, you are right - I forgot that the spelling had been
changed to upper case.

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


Re: Documentation bugs in 3.1 - C-API - TypeObjects

2009-11-15 Thread Martin v. Löwis
 Still there remains the difference to what is told with the
 Noddy_Type in the tutorial.

Please report that to bugs.python.org.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
On Nov 15, 12:01 pm, Jon Clements jon...@googlemail.com wrote:
 On Nov 15, 7:23 pm, Steve Howell showel...@yahoo.com wrote:

  I am more precisely looking for a way to change the behavior of foo
  ['bar'] (side effects and possibly return value) where foo is an
  instance of a class that subclasses dict, and where foo is not
  created by me.  The original post gives more context and example code
  that does not work as I expect/desire.

 [quote fromhttp://docs.python.org/reference/datamodel.html]
 For instance, if a class defines a method named __getitem__(), and x
 is an instance of this class, then x[i] is roughly equivalent to
 x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i)
 for new-style classes.
 [/quote]

 A quick hack could be:

 class Al(dict):
   def __getitem__(self, key):
     return self.spy(key)
   def spy(self, key):
     return 'Al'

  a = Al()
  a[3]
 'Al'
  a.spy = lambda key: 'test'
  a[3]
 'test'
  b = Al()
  b[3]

 'Al'

 Seems to be what you're after anyway...


This is very close to what I want, but the problem is that external
code is defining Al, and I do not seem to be able to get this
statement to have any effect:

a.__getitem__ = lambda key: test

How can I change the behavior of a['foo'] without redefining Al?

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


Re: Slicing history?

2009-11-15 Thread Mark Dickinson
On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote:
 Anyone remember or know why Python slices function like half-open
 intervals?  I find it incredibly convenient myself, but an acquaintance
 familiar with other programming languages thinks it's bizarre and I'm
 wondering how it happened.

Sounds like an excuse to post this Dijkstra link:

http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF

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


Re: How to get directory of Python C library

2009-11-15 Thread arve.knud...@gmail.com
On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:
 arve.knud...@gmail.com schrieb:

  Hi

  I need to link against Python, is there a way to get the path to the
  directory containing Python's C library (e.g., exec-prefix/libs on
  Windows)?

 Most probably from the registry somehow. In general, try  locate a
 python-executable, and make it execute

   python -c import sys; print sys.prefix

 Capture that, and you're done. Depending on the OS, the libs then are
 placed in e.g. prefix/lib.

That doesn't solve anything, the hard part is figuring out the part
after prefix ..

Arve

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


Re: How to get directory of Python C library

2009-11-15 Thread Diez B. Roggisch

arve.knud...@gmail.com schrieb:

On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:

arve.knud...@gmail.com schrieb:


Hi
I need to link against Python, is there a way to get the path to the
directory containing Python's C library (e.g., exec-prefix/libs on
Windows)?

Most probably from the registry somehow. In general, try  locate a
python-executable, and make it execute

  python -c import sys; print sys.prefix

Capture that, and you're done. Depending on the OS, the libs then are
placed in e.g. prefix/lib.


That doesn't solve anything, the hard part is figuring out the part
after prefix ..


AFAIK is that only varying based on the OS. Under unix, it's

 prefix/lib/pythonversion/

You can get the platform via sys.platform.


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


Re: Slicing history?

2009-11-15 Thread Steve Howell
On Nov 15, 12:11 pm, Mark Dickinson dicki...@gmail.com wrote:
 On Nov 15, 6:50 pm, a...@pythoncraft.com (Aahz) wrote:

  Anyone remember or know why Python slices function like half-open
  intervals?  I find it incredibly convenient myself, but an acquaintance
  familiar with other programming languages thinks it's bizarre and I'm
  wondering how it happened.

 Sounds like an excuse to post this Dijkstra link:

 http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF


That is really good stuff!  Like Aahz I have Python's slicing
mechanism (and zero-based indexing) burnt into my brain, but I never
had a good way to explain why it makes sense, other than just an
intuitive notion that it works for me.  It is interesting how the link
actually seems to explain zero-based indexing as a consequence of the
slicing approach, not a cause.  I always understood zero-based
indexing as a relic of memory management, which was fine, but I guess
the reasons go deeper than that.




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


Re: How to get directory of Python C library

2009-11-15 Thread arve.knud...@gmail.com
On 15 Nov, 21:24, Diez B. Roggisch de...@nospam.web.de wrote:
 arve.knud...@gmail.com schrieb:





  On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:
  arve.knud...@gmail.com schrieb:

  Hi
  I need to link against Python, is there a way to get the path to the
  directory containing Python's C library (e.g., exec-prefix/libs on
  Windows)?
  Most probably from the registry somehow. In general, try  locate a
  python-executable, and make it execute

    python -c import sys; print sys.prefix

  Capture that, and you're done. Depending on the OS, the libs then are
  placed in e.g. prefix/lib.

  That doesn't solve anything, the hard part is figuring out the part
  after prefix ..

 AFAIK is that only varying based on the OS. Under unix, it's

   prefix/lib/pythonversion/

 You can get the platform via sys.platform.

Well, my point is that I should like a way to query for this
directory, just as I can query distutils.sysconfig for the include
directory and Python library (i.e., the standard Python library)
directory. It's not trivial to figure out Python's installation scheme
so long as it's not written in stone ..

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


Re: How to get directory of Python C library

2009-11-15 Thread Diez B. Roggisch

arve.knud...@gmail.com schrieb:

On 15 Nov, 21:24, Diez B. Roggisch de...@nospam.web.de wrote:

arve.knud...@gmail.com schrieb:






On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:

arve.knud...@gmail.com schrieb:

Hi
I need to link against Python, is there a way to get the path to the
directory containing Python's C library (e.g., exec-prefix/libs on
Windows)?

Most probably from the registry somehow. In general, try  locate a
python-executable, and make it execute
  python -c import sys; print sys.prefix
Capture that, and you're done. Depending on the OS, the libs then are
placed in e.g. prefix/lib.

That doesn't solve anything, the hard part is figuring out the part
after prefix ..

AFAIK is that only varying based on the OS. Under unix, it's

  prefix/lib/pythonversion/

You can get the platform via sys.platform.


Well, my point is that I should like a way to query for this
directory, just as I can query distutils.sysconfig for the include
directory and Python library (i.e., the standard Python library)
directory. It's not trivial to figure out Python's installation scheme
so long as it's not written in stone ..



Well, than how about you word your question like that? But there is no 
simple function to call. So the answer to the question you asked is: no.


I showed you a way that works for current python, and consists of 
stitching together a number of informations.


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


Re: Slicing history?

2009-11-15 Thread Aahz
In article 667394cb-d505-4906-8c6b-ab2d361b3...@j24g2000yqa.googlegroups.com,
Mark Dickinson  dicki...@gmail.com wrote:
On Nov 15, 6:50=A0pm, a...@pythoncraft.com (Aahz) wrote:

 Anyone remember or know why Python slices function like half-open
 intervals? =A0I find it incredibly convenient myself, but an acquaintance
 familiar with other programming languages thinks it's bizarre and I'm
 wondering how it happened.

Sounds like an excuse to post this Dijkstra link:

http://www.cs.utexas.edu/~EWD/ewd08xx/EWD831.PDF

Many thanks!
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.  --Brian W. Kernighan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing an emulator in python - implementation questions (for performance)

2009-11-15 Thread Baptiste Lepilleur
I think you can use python itself for pre-processing. Here is an
(shortened) example from PyPy RPython paper:

# operators: the docstrings contain the
# symbol associated with each operator
class Op_Add(BinaryExpr):
’+’
class Op_Sub(BinaryExpr):
’-’

# INIT-TIME only: build the table of
# opcodes and add the ’eval’ methods
def gen_eval(ch):
code = 
def eval(self):
return self.l.eval() %s self.r.eval()

d = {}
exec code.strip() % (ch) in d
return d['eval']
OPCODES = {}
def build_opcodes():
for name, value in globals().items():
if name.startswith(’Op_’):
value.eval = gen_eval(value.__doc__)
OPCODES[value.__doc__] = value
build_opcodes()

From the paper:

The eval method is generated via a call to the helper
routine gen_eval, which creates a string of Python code that
performs the desired computation and uses exec to compile
this string into a Python method.

Adding the class object to the OPCODES dictionary is done
by simple assignment, using the class docstring as the key
and the class object itself as the value.


You might also want to have a look at PyGirl, the Nintendo Gameboy emulator
of the PyPy project written in RPython (a subset of Python that allow static
type inference). There is probably some ideas to borrow. The paper on PyGirl
also details some of the pre-processing trick they used. They sometime
call it meta-programming but its all the same, generating code with code :).

See http://codespeak.net/pypy/dist/pypy/doc/extradoc.html for more info and
look-up the rpython and pygirl docs.

2009/11/14 greg g...@cosc.canterbury.ac.nz

 Santiago Romero wrote:

   Can the above be easily done with another already-existing
 application? (example: can m4 do this job)?


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


Re: How to get directory of Python C library

2009-11-15 Thread arve.knud...@gmail.com
On 15 Nov, 22:11, Diez B. Roggisch de...@nospam.web.de wrote:
 arve.knud...@gmail.com schrieb:





  On 15 Nov, 21:24, Diez B. Roggisch de...@nospam.web.de wrote:
  arve.knud...@gmail.com schrieb:

  On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:
  arve.knud...@gmail.com schrieb:
  Hi
  I need to link against Python, is there a way to get the path to the
  directory containing Python's C library (e.g., exec-prefix/libs on
  Windows)?
  Most probably from the registry somehow. In general, try  locate a
  python-executable, and make it execute
    python -c import sys; print sys.prefix
  Capture that, and you're done. Depending on the OS, the libs then are
  placed in e.g. prefix/lib.
  That doesn't solve anything, the hard part is figuring out the part
  after prefix ..
  AFAIK is that only varying based on the OS. Under unix, it's

    prefix/lib/pythonversion/

  You can get the platform via sys.platform.

  Well, my point is that I should like a way to query for this
  directory, just as I can query distutils.sysconfig for the include
  directory and Python library (i.e., the standard Python library)
  directory. It's not trivial to figure out Python's installation scheme
  so long as it's not written in stone ..

 Well, than how about you word your question like that? But there is no
 simple function to call. So the answer to the question you asked is: no.

 I showed you a way that works for current python, and consists of
 stitching together a number of informations.

 Diez

My original question was pretty clear I think. And I don't have the
required information to deduce what the library path may look like on
any given platform, there really should be a standard function for
this.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
On Nov 15, 12:01 pm, Jon Clements jon...@googlemail.com wrote:
 On Nov 15, 7:23 pm, Steve Howell showel...@yahoo.com wrote:

  On Nov 15, 10:25 am, Steve Howell showel...@yahoo.com wrote:

   [see original post...]
   I am most
   interested in the specific mechanism for changing the __getitem__
   method for a subclass on a dictionary.  Thanks in advance!

  Sorry for replying to myself, but I just realized that the last
  statement in my original post was a little imprecise.

  I am more precisely looking for a way to change the behavior of foo
  ['bar'] (side effects and possibly return value) where foo is an
  instance of a class that subclasses dict, and where foo is not
  created by me.  The original post gives more context and example code
  that does not work as I expect/desire.

 [quote fromhttp://docs.python.org/reference/datamodel.html]
 For instance, if a class defines a method named __getitem__(), and x
 is an instance of this class, then x[i] is roughly equivalent to
 x.__getitem__(i) for old-style classes and type(x).__getitem__(x, i)
 for new-style classes.
 [/quote]


Ok, thanks to Jon and Gary pointing me in the right direction, I think
I can provide an elaborate answer my own question now.

Given an already instantiated instance foo of Foo where Foo subclasses
dict, you cannot change the general behavior of calls of the form foo
[bar]. (Obviously you can change the behavior for specific examples of
bar after instantiation by setting foo['apple'] and foo['banana'] as
needed, but that's not what I mean.)

This may be surprising to naive programmers like myself, given that is
possible to change the behavior of foo.bar() after instantiation by
simply saying foo.bar = some_method.  Also, with old-style classes,
you can change the behavior of foo[bar] by setting foo.__getitem__.
Even in new-style classes, you can change the behavior of
foo.__getitem__(bar) by saying foo.__getitem__ = some_method, but it
is a pointless exercise, since foo.__getitem__ will have no bearing on
the processing of foo[bar].  Finally, you can define __getitem__ on
the Foo class itself to change how foo[bar] gets resolved, presumably
even after instantiation of foo itself (but this does not allow for
instance-specific behavior).

Here is the difference:

  foo.value looks for a definition of value on the instance before
looking in the class hierarchy
  foo[bar] can find __getitem__ on foo before looking at Foo and its
superclasses, if Foo is old-style
  foo[bar] will only look for __getitem__ in the class hierarchy if
Foo derives from a new-style class

Does anybody have any links that points to the rationale for ignoring
instance definitions of __getitem__ when new-style classes are
involved?  I assume it has something to do with performance or
protecting us from our own mistakes?

So now I am still in search of a way to hook into calls to foo[bar]
after foo has been instantiated.  It is all test code, so I am not
particularly concerned about safety or future compatibility.  I can do
something really gross like monkeypatch Foo class instead of foo
instance and keep track of the ids to decide when to override
behavior, but there must be a simpler way to do this.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to get directory of Python C library

2009-11-15 Thread Diez B. Roggisch

arve.knud...@gmail.com schrieb:

On 15 Nov, 22:11, Diez B. Roggisch de...@nospam.web.de wrote:

arve.knud...@gmail.com schrieb:






On 15 Nov, 21:24, Diez B. Roggisch de...@nospam.web.de wrote:

arve.knud...@gmail.com schrieb:

On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:

arve.knud...@gmail.com schrieb:

Hi
I need to link against Python, is there a way to get the path to the
directory containing Python's C library (e.g., exec-prefix/libs on
Windows)?

Most probably from the registry somehow. In general, try  locate a
python-executable, and make it execute
  python -c import sys; print sys.prefix
Capture that, and you're done. Depending on the OS, the libs then are
placed in e.g. prefix/lib.

That doesn't solve anything, the hard part is figuring out the part
after prefix ..

AFAIK is that only varying based on the OS. Under unix, it's
  prefix/lib/pythonversion/
You can get the platform via sys.platform.

Well, my point is that I should like a way to query for this
directory, just as I can query distutils.sysconfig for the include
directory and Python library (i.e., the standard Python library)
directory. It's not trivial to figure out Python's installation scheme
so long as it's not written in stone ..

Well, than how about you word your question like that? But there is no
simple function to call. So the answer to the question you asked is: no.

I showed you a way that works for current python, and consists of
stitching together a number of informations.

Diez


My original question was pretty clear I think. And I don't have the
required information to deduce what the library path may look like on
any given platform, there really should be a standard function for
this.


I at least misunderstood it - which might be my fault. However, as there 
is no such function. I suggest you discuss this on the devel-list - 
however, anything before python2.7 is unlikely to grow such a function, 
so you are stuck with the ways I described.


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


Re: How to get directory of Python C library

2009-11-15 Thread arve.knud...@gmail.com
On 15 Nov, 23:59, Diez B. Roggisch de...@nospam.web.de wrote:
 arve.knud...@gmail.com schrieb:





  On 15 Nov, 22:11, Diez B. Roggisch de...@nospam.web.de wrote:
  arve.knud...@gmail.com schrieb:

  On 15 Nov, 21:24, Diez B. Roggisch de...@nospam.web.de wrote:
  arve.knud...@gmail.com schrieb:
  On 15 Nov, 20:05, Diez B. Roggisch de...@nospam.web.de wrote:
  arve.knud...@gmail.com schrieb:
  Hi
  I need to link against Python, is there a way to get the path to the
  directory containing Python's C library (e.g., exec-prefix/libs on
  Windows)?
  Most probably from the registry somehow. In general, try  locate a
  python-executable, and make it execute
    python -c import sys; print sys.prefix
  Capture that, and you're done. Depending on the OS, the libs then are
  placed in e.g. prefix/lib.
  That doesn't solve anything, the hard part is figuring out the part
  after prefix ..
  AFAIK is that only varying based on the OS. Under unix, it's
    prefix/lib/pythonversion/
  You can get the platform via sys.platform.
  Well, my point is that I should like a way to query for this
  directory, just as I can query distutils.sysconfig for the include
  directory and Python library (i.e., the standard Python library)
  directory. It's not trivial to figure out Python's installation scheme
  so long as it's not written in stone ..
  Well, than how about you word your question like that? But there is no
  simple function to call. So the answer to the question you asked is: no.

  I showed you a way that works for current python, and consists of
  stitching together a number of informations.

  Diez

  My original question was pretty clear I think. And I don't have the
  required information to deduce what the library path may look like on
  any given platform, there really should be a standard function for
  this.

 I at least misunderstood it - which might be my fault. However, as there
 is no such function. I suggest you discuss this on the devel-list -
 however, anything before python2.7 is unlikely to grow such a function,
 so you are stuck with the ways I described.

 Diez

OK, thanks. Perhaps I'll try distutils-sig, given that it looks
natural to extend distutils.sysconfig.

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


Re: ANN: PyGUI 2.1

2009-11-15 Thread r
OK this is my third attempt, someone please email me if these messages
are getting through. I mailed this only to c.l.py and not the announce
group this time, that may have been my previous problems??? Here we
go...

Hello Greg,

I have looked over this kit in the past and it looks quite promising
for meeting it stated goals (and mine). One the the best things about
it (for me anyway) is the small size and the fact you have an OpenGL
widget! I think all GUI kits should support OpenGL out of the box!
This is the 21st century as we all know.

Also these stated goals are what every GUI package should aspire to.
(Hope you don't mind me quoting your site??)


Develop a GUI API that is designed specifically for Python, taking
advantage of Python's unique language features and working smoothly
with Python's data types. Provide implementations of the API for the
three major platforms (Unix, Macintosh and Windows) that are small and
lightweight, interposing as little code as possible between the Python
application and the platform's underlying GUI facilities, and not
bloating the Python installations or applications which use them.


I really like this!


Document the API purely in Python terms, so that the programmer does
not need to read the documentation for another GUI library, in terms
of another language, and translate into Python.


This is *so* important for any GUI. wxPython IMO lacks greatly in this
department. I very much wish we had docs for wxPython as we do for
Tkinter. But even Tkinter needs more details! You should never need to
consult the TCL/TK doc's unless you are doing something really
advanced. (or evil!)


Get the library and its documentation included in the core Python
distribution, so that truly cross-platform GUI applications may be
written that will run on any Python installation, anywhere.


This i also agree with! While we currently have Tkinter in Python we
lack the real docs in Python for Tkinter. There are a few very good
sites (effbot, NMT, and others) but users must bounce around from site
to site to find all this. I want visit one place for a reference and
one place only. Tuts can exist on the web. And by reference look at
this site to see what i mean http://infohost.nmt.edu/tcc/help/pubs/tkinter/

I actually like Tkinter (because of ease of use) however!, having an
embedded TCL interpretor and wrapping TK calls with Python just seems
wrong, and Tkinter is notoriously slow (probably due to this fact) as
we all know.

But after looking over your pyGUI it does seem that Tkinter has a
richer widget set. (i could be wrong) What are the comparisons between
Tkinter and PyGUI. I would love to use a kit that is lighter weight
and has better cross platform abilities (and a glWidget to boot!), but
i can't sacrifice the widget set. Can you give us a pros and cons of
pyGUI versus Tkinter? This will help me decide and i think many others
would benefit also.

Here is the main widgets of Tkinter:
-Entry
-Label
-Button
-RadioButton
-CheckButton
-Frame
-LabelFrame
-Text
-Listbox
-Scrollbar
-Scale
-Toplevel
-Canvas (2d)
-Menu
-MenuButton
-OptionMenu
-PanedWindow
-Spinbox

Easy to use dialogs from:
-tkFileDialog
-tkSimpleDialog
-tkMessageBox

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


Re: A terminators' club for clp

2009-11-15 Thread David Bolen
Terry Reedy tjre...@udel.edu writes:

 r wrote:
 On Nov 14, 4:59 am, kj no.em...@please.post wrote:
 But, as I already showed, I'm out of my depth here,
 so I'd better shut up.

 Don't give up so easy! The idea is great, what Paul is saying is that
 most people who read this group use newsreaders and that has nothing
 to do with google groups. These guy's have kill filters for just this
 sort of thing but either way the emails are on their puters so they
 have to deal with them on an individual basis. It would be nice
 however to clean up the Google group version and rid it of the plagues
 of spam infestations.

 Anyone with a newsreader can, like me, read gmane.comp.python.general,
 which mirrors python-list, which now filters out much/most of the spam
 on c.l.p from G.g.

The same is true on some (not sure if it qualifies for many) Usenet
servers.  I use news.individual.net for example (for a modest yearly
fee as of a few years ago) and in my experience it does a great job at
filtering spam.  I'm sure there are other services that do as well.  I
don't have to manage any special filters and don't seem to see any of
the stuff in this group, for example, mentioned in this thread.

I do use gmane for a lot of other lists (including python-dev) that
aren't operated as a Usenet newsgroups and it's an excellent service.

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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Christian Heimes
Steve Howell wrote:
 Does anybody have any links that points to the rationale for ignoring
 instance definitions of __getitem__ when new-style classes are
 involved?  I assume it has something to do with performance or
 protecting us from our own mistakes?

Most magic methods are implemented as descriptors. Descriptors only
looked up on the type to increase the performance of the interpreter and
to simply the C API. The same is true for other descriptors like
properties. The interpreter invokes egg.__getitem__(arg) as
type(egg).__getitem__(egg, arg).

 So now I am still in search of a way to hook into calls to foo[bar]
 after foo has been instantiated.  It is all test code, so I am not
 particularly concerned about safety or future compatibility.  I can do
 something really gross like monkeypatch Foo class instead of foo
 instance and keep track of the ids to decide when to override
 behavior, but there must be a simpler way to do this.

Try this untested code:

class Spam(dict):
def __getitem__(self, key):
getitem = self.__dict__.get(__getitem__, dict.__getitem__)
return getitem(self, key)

Because dict is the most important and speed critical type in Python it
has some special behaviors. If you are going to overwrite __getitem__ of
a dict subclass then you have to overwrite all methods that call
__getitem__, too. These are get, pop, update and setdefault.

Christian

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


Re: How can pip install a GitHub code drop?

2009-11-15 Thread Wolodja Wentland
On Sun, Nov 15, 2009 at 09:16 -0800, Phlip wrote:
 How can I point pip at the repo to install the library?

 sudo pip -e git+git://github.com/Phlip/Kozmiq.git

Make that:

pip -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq

and (preferably) don't install into system paths ;-)

kind regards

Wolodja
-- 
  .''`. Wolodja Wentlandwentl...@cl.uni-heidelberg.de 
 : :'  :
 `. `'` 4096R/CAF14EFC 
   `-   081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic class question..

2009-11-15 Thread Pyrot
On 11월15일, 오후10시15분, Tim Chase python.l...@tim.thechases.com wrote:
 Pyrot wrote:
  class rawDNA:
 import string
 trans = string.maketrans(GATC,CTAG)

 def __init__(self, template = GATTACA):
 self.template = template  //shouldn't this make template
  accessible within the scope of rawDNA??

 No.  Python's scope resolution consists only of local, global,
 or explicit.  There is no try to find this in the instance or
 class scope-resolution guessing.  Your code makes template
 accessible within the scope of self, not in a global
 unqualified scope.

 So this:

 def noncoding(self):
 print template.translate(trans)  //

 tries to reference template first in the local scope (within
 noncoding(), but it doesn't exist there), then in the global
 scope (it also doesn't exist there), and stops.

 It should be as you have it here:

  class rawDNA:
 import string
 trans = string.maketrans(GATC,CTAG)
 def __init__(self, template = GATTACA):
 self.template = template
 def noncoding(self):
 print self.template.translate(trans)

 Here, you start with self which *is* in the local scope, which
 *does* contain template and so it successfully finds it and all
 is [qualifiedly] good.  However, you'll also find that trans
 isn't found because it's neither in the local nor global scope:

 class RawDNA:
... import string
... trans = string.maketrans(GATC, CTAG)
... def __init__(self, template=GATTACA):
... self.template = template
... def noncoding(self):
... print self.template.translate(trans)
...
 r = RawDNA()
 r.noncoding()
Traceback (most recent call last):
  File stdin, line 1, in module
  File stdin, line 7, in noncoding
NameError: global name 'trans' is not defined

 so you need to fully qualify it as RawDNA.trans for Python to
 find it.  (I also shifted to using the PEP-8 naming convention
 RawDNA instead of rawDNA).

 Which you indeed discovered:

  this works as intended.

 Being explicit is part of Python Zen  (from the python
 command-prompt, type import this to see the whole list)

 -tkc

thanks!

one last question, is self.template.translate(trans) the right way
to go(pythonic?)?
I found it to be cumbersome(and a mouthful) and thought I might have
been doing it wrong :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic class question..

2009-11-15 Thread Pyrot
On 11월15일, 오후9시52분, Diez B. Roggisch de...@nospam.web.de wrote:
 Pyrot schrieb:

  class rawDNA:
     import string

 Importing here is unusual. Unless you have good reasons to do so, I
 suggest you put the imports on top of the file.

     trans = string.maketrans(GATC,CTAG)

     def __init__(self, template = GATTACA):
             self.template = template  //shouldn't this make template
  accessible within the scope of rawDNA??

 No.



     def noncoding(self):
             print template.translate(trans)  //

 This needs to be

    print self.template.translate(trans)

 Thes scopes insied a class are only the method-locals (to which the
 parameters count of course), and globals.

 Diez

Thanks for the tip Diez.

(Tthe core reason that I'm bothering with this at all is because I
heard imports are costly(in time, space, processing power). If this
turns out to be a non-issue, than my questions regarding Imports are
all moot :-)

I forgot to write about my second question which was:

what happens when I use the import statement within a class/function
declaration?
I'm thinking either
1) It imports during the class/function declaration
2) It imports the first time a class/function call(x = rawDNA() )
occurs

But if it's 2) then is the import valid outside of the function/class?
what happens when the last function reference is removed?(del x)

obviously this is a lot of questions...

I respect your(or anyone who would like to help me) time, so all I ask
is some kind of document or Best practices guide dealing all about
import.(because sadly, 
http://docs.python.org/reference/simple_stmts.html#the-import-statement
does not ask my questions)

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


Re: How can pip install a GitHub code drop?

2009-11-15 Thread Wolodja Wentland
On Mon, Nov 16, 2009 at 01:11 +0100, Wolodja Wentland wrote:
 On Sun, Nov 15, 2009 at 09:16 -0800, Phlip wrote:
  How can I point pip at the repo to install the library?

  sudo pip -e git+git://github.com/Phlip/Kozmiq.git

 pip -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq

err...

pip install -e git+git://github.com/Phlip/Kozmiq.git#egg=Kozmiq
^^^ ^^^
Hope it works

-- 
  .''`. Wolodja Wentlandwentl...@cl.uni-heidelberg.de 
 : :'  :
 `. `'` 4096R/CAF14EFC 
   `-   081C B7CD FF04 2BA9 94EA  36B2 8B7F 7D30 CAF1 4EFC


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread MRAB

Christian Heimes wrote:

Steve Howell wrote:

Does anybody have any links that points to the rationale for ignoring
instance definitions of __getitem__ when new-style classes are
involved?  I assume it has something to do with performance or
protecting us from our own mistakes?


Most magic methods are implemented as descriptors. Descriptors only
looked up on the type to increase the performance of the interpreter and
to simply the C API. The same is true for other descriptors like
properties. The interpreter invokes egg.__getitem__(arg) as
type(egg).__getitem__(egg, arg).


So now I am still in search of a way to hook into calls to foo[bar]
after foo has been instantiated.  It is all test code, so I am not
particularly concerned about safety or future compatibility.  I can do
something really gross like monkeypatch Foo class instead of foo
instance and keep track of the ids to decide when to override
behavior, but there must be a simpler way to do this.


Try this untested code:

class Spam(dict):
def __getitem__(self, key):
getitem = self.__dict__.get(__getitem__, dict.__getitem__)
return getitem(self, key)

Because dict is the most important and speed critical type in Python it
has some special behaviors. If you are going to overwrite __getitem__ of
a dict subclass then you have to overwrite all methods that call
__getitem__, too. These are get, pop, update and setdefault.


I wonder whether it's possible to define 2 behaviours, an optimised one
for instances of a class and another non-optimised one for instances of
a subclasses. That would make it easier to subclass built-in classes
without losing their speed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
On Nov 15, 4:03 pm, Christian Heimes li...@cheimes.de wrote:
 Steve Howell wrote:
  Does anybody have any links that points to the rationale for ignoring
  instance definitions of __getitem__ when new-style classes are
  involved?  I assume it has something to do with performance or
  protecting us from our own mistakes?

 Most magic methods are implemented as descriptors. Descriptors only
 looked up on the type to increase the performance of the interpreter and
 to simply the C API. The same is true for other descriptors like
 properties. The interpreter invokes egg.__getitem__(arg) as
 type(egg).__getitem__(egg, arg).


Is the justification along performance lines documented anywhere?

  So now I am still in search of a way to hook into calls to foo[bar]
  after foo has been instantiated.  It is all test code, so I am not
  particularly concerned about safety or future compatibility.  I can do
  something really gross like monkeypatch Foo class instead of foo
  instance and keep track of the ids to decide when to override
  behavior, but there must be a simpler way to do this.

 Try this untested code:

 class Spam(dict):
     def __getitem__(self, key):
         getitem = self.__dict__.get(__getitem__, dict.__getitem__)
         return getitem(self, key)
 [...]

Not sure how this helps me, unless I am misunderstanding...

It is the futility of writing lowercase_spam.__getitem__ that is
setting me back.  For my use case I do not want to override
__getitem__ for all Spam objects, nor do I even have the option to
modify the Spam class in some cases.


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


[ANNC] acromania-0.5

2009-11-15 Thread Lee Harr

Acromania is a word game of acronyms.

This program is a computer moderator for networked
games of acromania. It can connect to a channel on
IRC, or start a standalone server which can be
accessed much like a MUD.

http://acromania.googlecode.com/


Acromania uses Twisted and SQLite. Optionally, it can
use NLTK to generate computer opponents.

Acromania is released under GPLv3.


Changes in acromania-0.5:
    - add versioning for database
    - make building and loading bots more resilient
    - sort score report
    - add info command for in-game contact information
    - allow listing top10 acros per player
    - make leaderboard and top10 more resilient when empty
    - improve color usage
    - allow user to change password
    - add admin user account
    - allow admin user to change any user's password


Notes:
    I have only played the game using the standalone
    server on a secure network. If you have experience
    with programming IRC bots securely, please take
    a look and contact me if you see any problems.

    If you decide to connect it to IRC, please let me
    know, because I'd like to play :o)

  
_
Windows Live: Make it easier for your friends to see what you’re up to on 
Facebook.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092009
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Changing the current directory (full post)

2009-11-15 Thread Gabriel Genellina

En Sun, 15 Nov 2009 09:04:06 -0300, vsoler vicente.so...@gmail.com
escribió:


Ever since I installed my Python 2.6 interpreter (I use IDLE), I've
been saving my
*.py files in the C:\Program Files\Python26 directory, which is the
default directory for such files in my system.

However, I have realised that the above is not the best practice.
Therefore I created the C:\Program Files\Python26\test directory and I
want it to be my default directory for saving *.py files, importing
modules, etc.


This is *not* a good place either. Non-privileged users should not have
write permission in the C:\Program Files directory.


I'd like to do something like the DOS equivalent of   CD test but I
do not know kow to do it.

I am currently doing something really awful: I open a *.py file in the
test subdirectory, I run it with the F5 key and it works! but I am
doing really something stupid.


it works! What's the problem then?


How should I proceed, if I want to proceed properly?


Sorry but I don't even see your problem. You can save your .py files  
anywhere you like...


--
Gabriel Genellina

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


Re: overriding __getitem__ for a subclass of dict

2009-11-15 Thread Steve Howell
On Nov 15, 4:58 pm, Steve Howell showel...@yahoo.com wrote:
 On Nov 15, 4:03 pm, Christian Heimes li...@cheimes.de wrote:

  Try this untested code:

  class Spam(dict):
      def __getitem__(self, key):
          getitem = self.__dict__.get(__getitem__, dict.__getitem__)
          return getitem(self, key)
  [...]

 [I originally responded...] Not sure how this helps me, unless I am 
 misunderstanding...


Ok, now I get where you were going with the idea.  The following code
runs as expected.  Even in pure testing mode, I would want to make it
a little more robust, but it illustrates the basic idea that you can
monitor just particular objects by overriding the class method to look
for an attribute on the instance before doing any special processing.

class MyDict(dict):
pass

dict1 = MyDict()
dict1['foo'] = 'bar'

dict2 = MyDict()
dict2['spam'] = 'eggs'

dict3 = MyDict()
dict3['BDFL'] = 'GvR'

def spy(dict):
def mygetitem(self, key):
if hasattr(self, '__SPYING__'):
value = self.__class__.__old_getitem__(self, key)
print 'derefing %s to %s on %s' % (key, value, self)
return value
if not hasattr(dict.__class__, '__HOOKED__'):
setattr(dict.__class__, '__old_getitem__',
dict.__class__.__getitem__)
setattr(dict.__class__, '__getitem__', mygetitem)
setattr(dict.__class__, '__HOOKED__', True)
dict.__SPYING__ = True

dict1['foo'] # not spied yet
spy(dict1) # this changes class and instance
dict1['foo'] # spied
dict2['spam'] # not spied
spy(dict3) # this only changes instance
dict3['BDFL'] # spied
dict2['spam'] # spied

Thanks, Christian!

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


Re: tkFileDialog question

2009-11-15 Thread Gabriel Genellina
En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell  
mmitch...@transparent.com escribió:



answer = tkFileDialog.askdirectory()

if answer is not '':
#do stuff


Although it reads well, this is *wrong*. You want != here, not the `is  
not` operator.


if answer != '': ...

If you want to compare the *values* of two objects, to see if they are  
equal or not, use == or !=.
If you want to compare *identity*, to see if two results refer to the very  
same object or not, use `is` or `is not`


(In your example, it *may* appear to work, because CPython optimizes very  
short strings like 'a' or '', but you should not rely on this optimization)


--
Gabriel Genellina

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


Re: tkFileDialog question

2009-11-15 Thread r
On Nov 15, 8:56 pm, Gabriel Genellina gagsl-...@yahoo.com.ar
wrote:
 En Fri, 13 Nov 2009 11:32:37 -0300, Matt Mitchell  
 mmitch...@transparent.com escribió:

  answer = tkFileDialog.askdirectory()

  if answer is not '':
     #do stuff

 Although it reads well, this is *wrong*. You want != here, not the `is  
 not` operator.

 if answer != '': ...

 If you want to compare the *values* of two objects, to see if they are  
 equal or not, use == or !=.
 If you want to compare *identity*, to see if two results refer to the very  
 same object or not, use `is` or `is not`

Actually Gabe your right and wrong.. the pythonic way to check for
True/False is..

path = tkFileDialog.askwhatever()

if path:
   #do something here

NOT

if path != '':
   #do something here

Both work equally but the first is more Pythonic! UNLESS you are
specifically testing for anything but the empty string that is. In
that case your way *is* correct. But that is not the case with a file
dialog return value. Yes the dialog returns either an empty string OR
a valid path but True False is all that matters here when deciding
whether to act on that path -- or not act on it. NOT whether or not it
is an empty string.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Choosing GUI Module for Python

2009-11-15 Thread sturlamolden
On 15 Nov, 17:05, Dietmar Schwertberger n...@schwertberger.de wrote:

  Could you send me an .fbp file demonstrating the error?

 Sent by email. Did you receive it?

No... could you please resend to stu...@molden.no?





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


Re: Choosing GUI Module for Python

2009-11-15 Thread sturlamolden
On 15 Nov, 17:05, Dietmar Schwertberger n...@schwertberger.de wrote:

 Sent by email. Did you receive it?


Yes I did, thank you :)

(I thought I didn't, but it was just a problem with my e-mail filter.)






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


Re: Choosing GUI Module for Python

2009-11-15 Thread sturlamolden
On 14 Nov, 15:35, Dietmar Schwertberger n...@schwertberger.de wrote:

    self.m_toolBar1 = self.CreateToolBar( wx.TB_HORIZONTAL, wx.ID_ANY )
    self.m_button1 = wx.Button( self.m_toolBar1, wx.ID_ANY, uMyButton,
 wx.DefaultPosition, wx.DefaultSize, 0 )
    m_toolBar1.AddControl( m_button1 )

I can confirm this. There seems to be a bug in the generation of
Python code for wxToolBar.




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


Re: python simply not scaleable enough for google?

2009-11-15 Thread John Nagle

Paul Boddie wrote:

On 15 Nov, 09:30, Terry Reedy tjre...@udel.edu wrote:

greg wrote:



[Shed Skin]


These restrictions mean that it isn't really quite
Python, though.

Python code that only uses a subset of features very much *is* Python
code. The author of ShedSkin makes no claim that is compiles all Python
code.


Of course, Shed Skin doesn't support all the usual CPython features,
but the code you would write for Shed Skin's benefit should be Python
code that runs under CPython. It's fair to say that Shed Skin isn't a
complete implementation of what CPython defines as being the full
Python, but you're still writing Python. One can argue that the
restrictions imposed by Shed Skin inhibit the code from being proper
Python, but every software project has restrictions in the form of
styles, patterns and conventions.

This is where the Lesser Python crowd usually step in and say that
they won't look at anything which doesn't support the full Python,
but I think it's informative to evaluate which features of Python give
the most value and which we could do without. The Lesser Python
attitude is to say, No! We want it all! It's all necessary for
everything! That doesn't really help the people implementing proper
implementations or those trying to deliver better-performing
implementations.

In fact, the mentality that claims that it's perfect, or it will be
if we keep adding features could drive Python into a diminishing
niche over time. In contrast, considering variations of Python as some
kind of Greater Python ecosystem could help Python (the language)
adapt to the changing demands on programming languages to which Go
(the Google language, not Go! which existed already) is supposedly a
response.


Yes.  Niklaus Wirth, who designed Pascal, Modula, and Oberon, had
that happen to his languages.  He's old and bitter now; a friend of
mine knows him.

 The problem is that Greater Python is to some extent the set of
features that are easy to implement if we look up everything at run time.
You can insert a variable into a running function of
another thread.  This feature of very marginal utility is free in a
naive lookup-based interpreter, and horribly expensive in anything that
really compiles.  Obsession with the CPython implementation as the language
definition tends to overemphasize such features.

 The big headache from a compiler perspective is hidden dynamism -
use of dynamic features that isn't obvious from examining the source code.
(Hidden dynamism is a big headache to maintenance programmers, too.)
For example, if you had the rule that you can't use getattr and setattr
on an object from the outside unless the class itself implements or uses getattr
and setattr, then you know at compile time if the machinery for dynamic
attributes needs to be provided for that class.  This allows the slots
optimization, and direct compilation into struct-type code.

 Python is a very clean language held back from widespread use by slow
implementations.  If Python ran faster, Go would be unnecessary.

 And yes, performance matters when you buy servers in bulk.

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


Re: Python Go

2009-11-15 Thread sturlamolden
On 15 Nov, 05:21, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:

 Psyco does JIT compilation to machine-code for CPython, at the cost of
 much extra memory. It's also limited to 32-bit Intel processors. The aim
 of the PyPy project is to (eventually) make JIT machine-code compilation
 available to any Python, on any machine.

Who wants a JIT when it's orders of magnitude slower than interpreted
Python?

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


Re: python simply not scaleable enough for google?

2009-11-15 Thread sturlamolden
On 16 Nov, 05:09, John Nagle na...@animats.com wrote:

       Python is a very clean language held back from widespread use by slow
 implementations.  If Python ran faster, Go would be unnecessary.

That boggles me.

NASA can find money to build a space telescope and put it in orbit.
They don't find money to create a faster Python, which they use for
analyzing the data.

Google is a multi-billion dollar business. They are using Python
extensively. Yes I know about Unladen Swallow, but why can't they put
1 mill dollar into making a fast Python?

And then there is IBM and Cern's Blue Brain project. They can set up
the fastest supercomputer known to man, but finance a faster Python?
No...

I saw this myself. At work I could get money to buy a € 30,000
recording equipment. I could not get money for a MATLAB license.

It seems software and software development is heavily underfinanced.
The big bucks goes into fancy hardware. But fancy hardware is not so
fancy without equally fancy software.
















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


Re: python simply not scaleable enough for google?

2009-11-15 Thread sturlamolden
On 16 Nov, 05:09, John Nagle na...@animats.com wrote:

       Python is a very clean language held back from widespread use by slow
 implementations.

Python is clean, minimalistic, and beautiful.

Python don't have bloat like special syntax for XML or SQL databases
(cf C#) or queues (Go).

Most of all, it is easier to express ideas in Python than any computer
language I know.

Python's major drawback is slow implementations. I always find myself
resorting to Cython (or C, C++, Fortran 95) here and there.

But truth being told, I wrote an awful lot of C mex files when using
MATLAB as well. MATLAB can easily be slower than Python by orders of
magnitude, but it has not preventet it from widespread adoption.
What's keeping it back is an expensive license.















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


Re: IDE for python

2009-11-15 Thread sturlamolden
On 15 Nov, 18:09, Peng Yu pengyu...@gmail.com wrote:
 There had been some discussion on IDE. But I'm not sure what pros and
 cons of each choice. Current, I'm using vim and ctags.

 Could somebody give some advices on choosing the best IDE for me?

There is a plug-in to develop (amd debug) Python using MS Visual
Studio. It works with IronPython and CPython.

There is the PyDev plug-in for Eclipse.

There is Komodo from ActiveState.

There is KDevelop in KDE4.

Which is better? I don't know.

My impression is that Python development does noe need an IDE like
e.g. C++ development do. There is no build process, which takes the
major advantage of the IDE away. I am fine with a editor like IDLE or
Kate.














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


Re: Python Go

2009-11-15 Thread Simon Forman
On Sat, Nov 14, 2009 at 5:10 PM, Terry Reedy tjre...@udel.edu wrote:
 Paul Rubin wrote:

 Mark Chu-Carroll has a new post about Go:


  http://scienceblogs.com/goodmath/2009/11/the_go_i_forgot_concurrency_an.php

 In a couple of minutes, I wrote his toy prime filter example in Python,
 mostly from the text rather than the code, which I can barely stand to read.
 It ran the first time without error.

 def plurals():
  i = 2
  while True:
    yield i
    i += 1

 def primefilter(src, prime):
  for i in src:
    if i % prime:
      yield i

 src = plurals()
 while True:
  i = next(src)
  print(i)
  src = primefilter(src, i)

 As I commented there
 It stopped at 7877 when it hit the default recursion limit of 1000, which
 could easily be increased to get out-of-memory error instead.

 I think Google is making a blunder if it moves to another old-fashioned
 language whose code is bloated with junky boilerplate that doubles the size.
 It would be much better, for instance, to tweak Python, which it has had
 great success with, to better run on multiple cores.

 Terry Jan Reedy

FWIW,

def plurals():
 i = 3
 while True:
   yield i
   i += 2
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: tkFileDialog question

2009-11-15 Thread r
Matt,

There is also a nice thing you need to know about Python if you
already do not know. That is the fact that all empty collections bool
to False. This makes Truth testing easier.

 bool([])
False
 bool('')
False
 bool({})
False
 bool([1])
True
 bool([[]])
True
 bool(' ')
True

any empty collection, string, or 0 always bools to False.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Go

2009-11-15 Thread sturlamolden
On 14 Nov, 23:10, Terry Reedy tjre...@udel.edu wrote:

 It would be much better, for instance, to tweak Python, which it
 has had great success with, to better run on multiple cores.

Python run well on multiple cores, you just have to use processes
instead of threads.




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


Pokemon gamestyle in Python

2009-11-15 Thread Martijn Arts
First; sorry, the title might be somewhat unclear about what I mean.

Then; I know PyGame and I've worked with it, but I want to make a
Pokemon/Legend of Zelda style game with a moving guy on a map.
So what I'm asking is; is there anything better than PyGame for this
gamestyle?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: basic class question..

2009-11-15 Thread r
On Nov 15, 6:26 pm, Pyrot sungs...@gmail.com wrote:

 what happens when I use the import statement within a class/function
 declaration?
 I'm thinking either
 1) It imports during the class/function declaration
 2) It imports the first time a class/function call(x = rawDNA() )
 occurs

 But if it's 2) then is the import valid outside of the function/class?
 what happens when the last function reference is removed?(del x)


Well just fire up you interpretor fella!

 class A():
def __init__(self):
import sys
print sys.version


 a = A()
2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]
 'sys' in dir()
False
 print sys.version

Traceback (most recent call last):
  File pyshell#7, line 1, in module
print sys.version
NameError: name 'sys' is not defined

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


Re: Python 2.6.3 TarFile Module Add odd behavior

2009-11-15 Thread Gabriel Genellina
En Fri, 13 Nov 2009 16:23:31 -0300, Tilson, Greg (IS)  
greg.til...@ngc.com escribió:



In Windows Python 2.6.3 calling TarFile.add requires arcname= to be set
to work with WinZIP or WinRAR [...]If arcname= is not set during  
extraction all filenames are None


Suggest document change or filing a bug report


Post some code showing your problem. I wrote a quick test and worked fine  
for me.


--
Gabriel Genellina

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


[issue4683] urllib2.HTTPDigestAuthHandler fails on third hostname?

2009-11-15 Thread Senthil Kumaran

Senthil Kumaran orsent...@gmail.com added the comment:

Interesting issue. RFC 2617 supports the claim. In RFC 2617, section
3.2.2 The Authorization Request Header, we see that nonce-count is
maintained for each particular nonce value and it can used by the server
to verify the replays.


The nc-value is the hexadecimal count of the number of requests
(including the current request) that the client has sent with the nonce
value in this request.  For  example, in the first request sent in
response to a given nonce value, the client sends nc=0001.  The
purpose of this  directive is to allow the server to detect request
replays by  maintaining its own copy of this count - if the same
nc-value is  seen twice, then the request is a replay. 


resetting the nonce_count for each new nonce is the correct thing to do.
Patch seems okay and I going ahead with that.

We don't have test for HTTPDigestAuth yet, the nonce tests should be a
part of that.

--
resolution:  - accepted

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4683
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7309] crasher in str(Exception())

2009-11-15 Thread Ezio Melotti

Ezio Melotti ezio.melo...@gmail.com added the comment:

 I'm not sure what the functions should do when start and end are
 out of range.

I think the best approach would be to prevent these values to be out of
range in the first place. 
All the args should be checked when the instance is created (to avoid
things like UnicodeTranslateError(None, 2**30, 2**30+1, 'bah')) and
then, if possible, the attributes should be set as read-only.
I don't see any valid reason to change them anyway.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7309
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >