Re: Can one query full name (or version) of selected packages at pypi?

2006-04-23 Thread Martin v. Löwis
Caleb Hattingh wrote:
> So: I would like to query the package index with a short name (perhaps
> wildcarded), and retrieve either the full name (from which to strip the
> ver.) or version number, and compare it with what I have on disk.  At
> this stage, just reporting the differences is fine.
> 
> I could do these steps myself with normal http access and
> screen-scraping, but is there already such a system/script somewhere?

You can query the Cheeseshop through XML-RPC, see

http://www.inkdroid.org/journal/2005/08/11/pypi-over-xmlrpc/

>  Alternatively, how do you all keep versions of python addons
> up-to-date?  Manually?

I use Debian; this automatically gives me updates of all of
my packages.

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


Re: How can I call a python method from the XML-RPC client in Java?

2006-04-23 Thread Martin v. Löwis
[EMAIL PROTECTED] wrote:
> Hi all, I have created a XML-RPC model (with server and client)
> written in Java. I want to call the methods in another XML-RPC model
> written in Python. I know that in Java, I can use like 
> "xmlrpc_client.excute("handler_name.method", param)" to call the 
> methods in my xml-rpc server written in java. But how can I call the
> methods in Python? I cannot creat a handler in my Python XML-RPC
> server.
>
> Is there anyone able to help me? I would be very appreciate!

It's not clear to me what you are trying to do: Do you want to
know how to write certain Java code (as the subject line
suggests), or how to write certain Python code (as "I cannot
create a handle in my Python XML-RPC server" suggests").

I'm going by the subject: As a first step, please try calling
the demo server in SimpleXMLRPCServer in Java. To do this,
start the demo servre, point your Java client to
http://localhost:8000/RPC2, and invoke
xmlrpc_client("add", new args[]{1, 2}) (or some such, I'm not sure
how parameter passing in your library works).

You are right that there typically is no "handler" in Python,
so you just omit the handler_name part of the method string.

Regards,
Martin

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


Re: Recommended IDE for creating GUI?

2006-04-23 Thread bwaha

"Marty Christion" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> What are some good free or inexpensive (<$50) IDE's for learning how to
> program and create GUI's for Python?  I'm pretty good with the simple
> programming aspect of the language, but I'm a little mystified by the
world
> of GUI's, and the options available in python.
>
>

I've been using python on and off for about 12 months and WxPython for about
5 months. I've found the following combination works well together:

SPE - Stani's Python Editor http://stani.be/python/spe/blog/
WXGlade  - bundled with SPE
WinPDB - debugger bundled with in SPE that works with GUIs
WxPython - python bindings to WxWidgets library (fantastic demos that get
you up and running quickly) http://www.wxpython.org/
Ipython - interactive python shell http://ipython.scipy.org/

hth
bwaha



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


Re: Custom data type in a matrix.

2006-04-23 Thread Diez B. Roggisch
Gaz schrieb:
> Hi guys. I've been lookig for this in the numpy pdf manual, in this
> group and on google, but i could not get an answer...
> 
> Is there a way to create a custom data type (eg: Name: string(30), Age:
> int(2), married: boolean, etc) and then use that custom data in a
> matrix? Actually, this is a two question question :P
> 
> Im doing a simple hex based game and i need a way to store every hex
> property (color, owner,x, y, etc) in a matrix's "cell", representing
> each cell a hex.

You don't want numpy - you want ordinary lists in lists. Consider this:

class Hex(object):
 def __init__(self, x, y):
 self.x, self.y = x, y
 self.terrain_type = "unknown"


map = [[Hex(x, y) for y in xrange(height)] for x in xrange(width)]


There is no advantage of using numpy whatsoever - your fields aren't 
subject to mathematical operations or other transformations/selections.

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


Inexplicable behaviour of

2006-04-23 Thread Fabiano Sidler
Have a look to the following lines of code:
--- snip ---
class Foo: pass
def bar(): pass
Foo.bar = bar
--- snap ---

Why does 'bar.__get__(Foo) is Foo.bar' evaluate to False here? Did I
misunderstand the descriptor protocol?

Thank you for answering,
F. Sidler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inexplicable behaviour of

2006-04-23 Thread Leif K-Brooks
Fabiano Sidler wrote:
> Have a look to the following lines of code:
> --- snip ---
> class Foo: pass
> def bar(): pass
> Foo.bar = bar
> --- snap ---
> 
> Why does 'bar.__get__(Foo) is Foo.bar' evaluate to False here? Did I
> misunderstand the descriptor protocol?

bar.__get__(None, Bar) is what you meant (the first argument is the 
object, not the type), but even then the result will be False, because 
the __get__ method on functions returns a different object each time 
it's called:


  >>> class Foo(object):
  ... def bar(self):
  ... pass
  ...
  >>> Foo.bar is Foo.bar
  False
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Finding Module Dependancies

2006-04-23 Thread robert
Larry Bates wrote:
> 
> Remember that Python is so dynamic that you can build dependencies
> during program execution and import them on-the-fly.  So a dependency
> checker would always be incomplete.  You always need to write unit
> tests.

The Pychecker will usually see also missing on-the-fly imports and most 
of that like.
You'd need to do tricky exec stuff to trick him - and even then he can 
warn for smelling style of code.
You'd have to add upon warnings a #$pycheck_no to all such smelling 
lines in order to confirm, that you really know what you are doing.

To my experience you'd usually not get the written tests dense enough 
(at reasonable costs) to look into all branches of execution flow.

All 5 things are needed for efficiency :
(frequency of application decreasing the list down)

* auto-postmortem debugging (dev) ( auto-postmortem report (dist))
* running written tests
* code checks
* walking major execution branches by manual tests
* beta cycling

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


Re: python's thread problem on Linux platform

2006-04-23 Thread robert
[EMAIL PROTECTED] wrote:

> I found that  multi-threaded program(io-centralize )  runs very slowly
> on linux while the same program   runs very quickly  on windows.If I
> change the thread number to one ,the program runs quickly  on linux, in
> fact the speed is quicker than the multi-threaded version .
> It turns out   that python's multi-thread support on linux has some
> problems.Any comments?
> 

You are probably looping or have other quirks', over-lock-ing ...

Python's thread/threading/Queue stuff is unfortunately Java-ish/ 
OS-mindset and not functional. Thus encourages screwing "ego threads".

Maybe you get things organized frictionless with those 2? :

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491281
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491280

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


Re: Recommended IDE for creating GUI?

2006-04-23 Thread SPE - Stani's Python Editor
SPE also integrates with XRCed which is very stable. Google for more
info.

Stani

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


Re: Define type of 'module' object that is imported

2006-04-23 Thread robert
Zachary Pincus wrote:
> 
> No, just one particular module that needs to do some slow things.
> I'd like for a user to just be able to type
> "import foo"
> and have the foo module's type be some special type. None of the  
> options below really allow this to happen with one step. It would be  
> more like "import lazyFoo; import foo".
> 
> What I'm doing now is in 'foo.py' performing surgery a la:
> sys.modules[__name__] = MyModuleClass(...)
> but that's ugly, and can break the reload mechanism, and causes some  
> other troubles.

modules must go to sys.modules. reloading would have to be prevented by 
simple test. yet if your module is ready no-one would reload.

yet executing the module for reload in that trick namespace will also do 
  to a certain degree.

you could also try to replace / update the original modules's __dict__

you still didn't mention the original motivation for that 
lazy-moduletype replacement.
If its your module anyway, you could (auto-)rework your functions/class 
  to do delayed initializations at the end of the module.

something like:

for func in :
  globals()[func_name]=hook_lazy_init(func)


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


debugging in emacs

2006-04-23 Thread Gary Wessle
Hi python users

I am using emacs and python-mode.el under dabian testing.
is there a way to debug python code where I can step over each line
and watch the value of all the variables and be able to change
any during debugging. say you have a loop structure and want to see
what the values of your variables are during debugging when your code
is running as you step line by line.

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


Re: list example

2006-04-23 Thread Paolo Pantaleo
2006/4/22, Edward Elliott <[EMAIL PROTECTED]>:
> No substantive problems.  The str() calls are unnecessary, print calls
> list.__str__ already.  You can replace the loop with list comprehensions or
> slices.  Same result, a bit more succinct.  See these pages for more:
>
> http://docs.python.org/lib/typesseq.html
> http://docs.python.org/tut/node7.html  (section 5.1.4)
>
>

Thnx, I didn't catch the use of colon in print...

Thanks to the other posting, but actually I want to write some code
that one can modify to his own needings

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


Re: Looking for resources for making the jump from Java to Python easier and more productive

2006-04-23 Thread ToddLMorgan
I've actually managed to find some other links by backtracking through
some of the links that you provided.

The most comprehensive so far is this one
http://www.razorvine.net/python/PythonForJavaProgrammers and a summary
version (on the same site)
http://www.razorvine.net/python/PythonComparedToJava

The site owner (Irmen de Jong) appears to be be compiling a decent
migration path from Java to Python on a Moin-Moin Wiki so perhaps he'll
be harvesting more useful information from here and other places in the
near future as the pages only appears a few days ago.

There was also a follow up to
http://naeblis.cx/rtomayko/2004/12/15/the-static-method-thing  with
http://naeblis.cx/rtomayko/2005/01/20/getters-setters-fuxors

Hopefully this will prove helpful to some other folks :- )

I'm still working my way up to the practice sites (python and math
challenge) ... I want to do a bit more reading first :- )

ciao & thanks
 Todd

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


[ANN] crcmod-1.3 CRC Generator

2006-04-23 Thread Raymond L. Buvel
Crcmod is a Python package for creating functions computing the Cyclic
Redundancy Check (CRC). Any generating polynomial producing 8, 16, 32,
or 64 bit CRCs is allowed. Generated functions can be used in Python or
C/C++ source code can be generated.

Home page: http://crcmod.sourceforge.net/

Changes in 1.3

* Make compatible with Python 2.5 on 64-bit platforms.
* Improve the install procedure.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: debugging in emacs

2006-04-23 Thread Gary Wessle
Gary Wessle <[EMAIL PROTECTED]> writes:

> Hi python users
> 
> I am using emacs and python-mode.el under dabian testing.
> is there a way to debug python code where I can step over each line
> and watch the value of all the variables and be able to change
> any during debugging. say you have a loop structure and want to see
> what the values of your variables are during debugging when your code
> is running as you step line by line.
> 
> thanks

what is the most used the older python-mode.el or the newer python.el?

I am using eamcs 21.4.1 under dabian testing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python from Matlab

2006-04-23 Thread Alexander Schmolck
"Daniel Nogradi" <[EMAIL PROTECTED]> writes:

> > I am desperately looking for a way to call Python from Matlab. I have become
> > used to Python's rich syntax and large number of libraries, and feel
> > ridiculously clumsy being stuck with Matlab's rather restricted facilities
> > for doing other things than standard mathematical work.
> >
> > Does anyone know of good techniques (or readily available software) for
> > achieving a cross-language support between Python and Matlab?
> >
> > Carl
> 
> Perhaps you will find this useful:
> 
> http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html

I'd recommend looking at



instead (but then I'm the author). It's based on pymat but contains several
critical bugfixes and a high-level interface from python to matlab (e.g. you
can just do mlab.plot([1,2,3]) or x = mlab.sin(3)). I'll need to update a
couple of things, but on the whole it appears quite stable -- people have
succefully used it under windows, linux and os x.

'as

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


Re: Can you create an instance of a subclass with an existing instance of the base class?

2006-04-23 Thread Sandra-24
Lawrence D'Oliveiro wrote:
> In article <[EMAIL PROTECTED]>,
>  "Sandra-24" <[EMAIL PROTECTED]> wrote:
>
> >Now that is a clever little trick. I never would have guessed you can
> >assign to __class__, Python always surprises me in it's sheer
> >flexibility.
>
> That's because you're still thinking in OO terms.

It's not quite as simple as all that. I agree that people, escpecially
people with a Java (ew) background overuse OO, when there's often
simpler ways of doing things.

However in this case I'm simply getting an object (an mp_request object
from mod_python) passed into my function, and before I pass it on to
the functions that make up and individual web page it is modified by
adding members and methods to add functionality. It's not that I'm
thinking in OO, but that the object is a convienient place to put
things, especially functions that take an mp_request object as their
first argument.

Sadly I'm unable to create it as a python object first, because it's
created by the time my code comes into play. So I have to resort to
using the new module to add methods.

It works, but it has to be redone for every request, I thought moving
the extra functionality to another object would simplify the task. A
better way might be to contain the mp_request within another object and
use __getattr__ to lazily copy the inner object. I'd probably have to
first copy those few fields that are not read-only or use __setattr__
as well.

Thanks,
-Sandra

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


test assignmet problem

2006-04-23 Thread Paolo Pantaleo
So I tried this

if(not (attr=global_re.match(line)) ):
break

it says  invalid syntax [on the =]
so it is not possible to do test and assignment in C style?
how can I write this otherwise?

Thnx
PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Gerard Flanagan
Nick Craig-Wood wrote:
> Gerard Flanagan <[EMAIL PROTECTED]> wrote:
> >  def distribution(N=2):
> >  p = [0] + sorted( random.random() for _ in range(N-1) ) + [1]
> >  for j in range(N):
> >  yield p[j+1] - p[j]
> >
> >  spread = list(distribution(10))
> >
> >  print spread
> >  print sum(spread)
>
> This is simpler, easier to prove correct and most likely quicker.
>
> def distribution(N=2):
> L = [ random.uniform(0,1) for _ in xrange(N) ]
> sumL = sum(L)
> return [ l/sumL for l in L ]
>

simpler:- ok

easier to prove correct:- in what sense?

quicker:- slightly slower in fact (using xrange in both functions).
This must be due to 'uniform' - using random() rather than uniform(0,1)
then yes, it's quicker. Roughly tested, I get yours (and Alex
Martelli's) to be about twice as fast. (2<=N<1000, probably greater
difference as N increases).

All the best.

Gerard

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


Re: test assignmet problem

2006-04-23 Thread Duncan Booth
Paolo Pantaleo wrote:

> So I tried this
> 
> if(not (attr=global_re.match(line)) ):
> break
> 
> it says  invalid syntax [on the =]
> so it is not possible to do test and assignment in C style?
> how can I write this otherwise?
> 
With fewer parentheses for a start, but all you have to do here is to do 
the assignment and the test on separate lines:

attr = global_re.match(line)
if not attr:
break

In other cases you may have to work a bit harder to restructure your code.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: test assignmet problem

2006-04-23 Thread Paul McGuire

"Paolo Pantaleo" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
So I tried this

if(not (attr=global_re.match(line)) ):
break

it says  invalid syntax [on the =]
  ... because this syntax is not valid ...

so it is not possible to do test and assignment in C style?
  ... no it's not, see
http://www.python.org/doc/faq/general/#why-can-t-i-use-an-assignment-in-an-expression

how can I write this otherwise?
  ... is this so bad?...

attr=global_re.match(line)
if not attr:
break

  ... or, since you don't seem to be doing much with attr, you could just do

if not global_re.match(line):
break

  ... and get rid of all those distracting ()'s!


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


bug in modulus?

2006-04-23 Thread [EMAIL PROTECTED]
I think there might be something wrong with the implementation of
modulus.

Negative float values close to 0.0 break the identity "0 <= abs(a % b)
< abs(b)".

print 0.0 % 2.0 # => 0.0
print -1e-010 % 2.0 # =>1.99

which is correct, but:

print -1e-050 % 2.0 # => 2.0
print -1e-050 % 2.0 < 2.0 # => False

This means I can't use modulus to "wrap around" before it reaches a
certain value. I'm using Python 2.4.2 on WindowsXP.

Thanks
Janto

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


Parsing XML/XSLT

2006-04-23 Thread veracon
Hello,

I'm looking to use XML and XSLT for templates in a system I'm writing,
however I'm not really sure which parser is the "best". Basically,
which library has the most features, and which is the most supported?

A guide I saw mentioned importing xml.xslt, however it appears the xml
module/package contains pretty much nothing - xml.xslt outputs an
exception, No module named xslt.

Help?

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


How I learned Tkinter

2006-04-23 Thread peter
I've been trying to teach myself Tkinter programming over the last few
months
(in a strictly amateur way), and have made a number of requests for
help in this
newsgroup and elsewhere.

I've now (sort of) got there - in that I have used Tkinter for some
programs for
personal use - and I've written up my experiences at

http://www.aqzj33.dsl.pipex.com/how_i_learned_tkinter/contents.htm


In general I found that while Frederik Lundh's tutorial is
comprehensive and
well written, there is little else around to help the newcomer working
without
the benefit of more experienced colleagues, and that in places the
documentation
is too sparse to be of much help.

Any thoughts? Is my experience typical?

Peter

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


MS VC++ Toolkit 2003, where?

2006-04-23 Thread Alex Martelli
So, I thought I'd tool up to let me build and test Python extensions on
Windows (as well as Mac and Linux) -- I'm trying out Parallels
Workstation beta on my new Macbook Pro (and so far it seems to work very
well), I bought and installed a Win2000 Pro on it (since according to
the grapevine it works better than XP in various kinds of virtual
machines, and almost all SW supports w2k anyway -- I also found out that
one exception is the Google Pack, which does require XP), did all the
upgrades (why MS forces you to do 8+ rounds of download-install, from an
off-the-CD win2k SP2 to a fully upgraded win2k SP4, rather than offering
a single-round option, I just don't undersand!), got Python 2.4.3 --
phew, so far so good.

So, I go to  and start
following the instructions, beginning with the download of Visual C++
Toolkit 2003... oops!  I can't find that download any more at
 -- instead, what's at
that URL is a page explaining that
"""
The Visual C++ Toolkit 2003 has been replaced by Visual C++ 2005 Express
Edition.
"""

Hmmm -- I can't build extensions for the standard build of Python 2.4.3
with VC++ 2005, can I?  Express or other, they just use separate and
incompatible C-runtime libraries, I believe.

So -- does anybody know if the 2003-level Toolkit is STILL available for
download somewhere, or can suggest other (legal;-) ways in which I can
build and test Python extensions (with an optimizing compiler --
NON-optimizing ones are right out;-) w/o shelling out beeg moolah to MS?
So far my total investment is about $100 ($40 for Parallels Workstation,
which I preordered after briefly checking out the free-for-1-month beta,
since it worked so well; $60 for the cheapest legal CD+license of w2k I
could find around) -- and I'm not complaining, since the current setup
will still let me TEST many diverse things on Windows; to gain the
further ability of *compiling* Python extensions, I'm not averse to
spending a little more if needed, but certainly not as much as another
$100 (I do prefer free to cheap, but for example the $40 Parallels
product is well worth the money, to me, compared to the free 'Q',
because the latter, while fun to hack around with, was absorbing
countless hours of my time in many attempts to get everything working,
while Parallels essentially "just worked" and saved me LOTS of time).


Thanks in advance for any suggestions!  Just to show that I'm an
oldstyle Usenet dynosaur: suggestions in private mail are also welcome
(but my real mailbox these days is at gmail, not as yahoo as the 'From'
header above says), and I will undertake to summarize and post any
suggestions thus received (unless the suggestions' authors request me to
not repost).


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


how to write special value to a config file with ConfigParser

2006-04-23 Thread Lialie


Hello,all
I found it easy to read configures from a config file.
But how can I set a special value to an item or write it into the 
original file?

I have tried this:

import ConfigParser
config = ConfigParser.ConfigParser()
config.read('a.conf')
config.get('Main', 'Something') # That is OK.
config.set('Main', 'Something', '2') # without any fault
#fp = open('a.conf') # can not be done, raise Error
#fp = open('a.conf', 'a') # Something set to 2, but it copies the all items
#config.write(fp)


# How can I do it?

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

Re: MS VC++ Toolkit 2003, where?

2006-04-23 Thread David Rushby
Alex Martelli wrote:
> So -- does anybody know if the 2003-level Toolkit is STILL available for
> download somewhere...

http://www.microsoft.com/downloads/details.aspx?FamilyId=272BE09D-40BB-49FD-9CB0-4BFA122FA91B&displaylang=en

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


Re: MS VC++ Toolkit 2003, where?

2006-04-23 Thread Alex Martelli
David Rushby <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > So -- does anybody know if the 2003-level Toolkit is STILL available for
> > download somewhere...
> 
>
>http://www.microsoft.com/downloads/details.aspx?FamilyId=272BE09D-40BB-
>49FD-9CB0-4BFA122FA91B&displaylang=en
>

Great, thanks, just what I was looking for!!!


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


Re: how to write special value to a config file with ConfigParser

2006-04-23 Thread Lialie

Lialie write:
OK.I find out myself.
Excuse me.
Just open ini file in write mode.
--- Begin Message ---


Lialie write:
OK.I find out myself.
Excuse me.
Just open ini file in write mode.



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

Re: check whether a value is scalar

2006-04-23 Thread Fredrik Lundh
"Eli" <[EMAIL PROTECTED]> wrote:

> The issue is I want to keep a set of values to share among several
> applications in different languages, and only scalar values can be
> shared. Since objects are not the same in all languages, it's possible
> to share only simple values.

I can assure you that people who've implemented various kinds of
RPC protocols and cross-language bindings would be rather surprised
to hear that you've discovered that it's impossible to do what they've
done.

I'm not entirely convinced that you know what you're talking about,
really.  Maybe you should spend a little more time studying prior art ?





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


Re: how to write special value to a config file with ConfigParser

2006-04-23 Thread pavel . starek
Hi,

I have tried this:


import ConfigParser
fp = file("test.conf","w+")
cp = ConfigParser.ConfigParser()
cp.add_section("Section1")
cp.set("Section1","Value1",12345)
cp.write(fp)


and works fine for me.

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


Re: bug in modulus?

2006-04-23 Thread Tim Peters
[EMAIL PROTECTED]
> I think there might be something wrong with the implementation of
> modulus.
>
> Negative float values close to 0.0 break the identity "0 <= abs(a % b) < 
> abs(b)".

While that's a mathematical identity, floating point has finite
precision.  Many mathematical identities can fail when using floats. 
For example,

(x+y)+z = x+(y+z)

doesn't always hold when using floats either.

> print 0.0 % 2.0 # => 0.0
> print -1e-010 % 2.0 # =>1.99
>
> which is correct, but:
>
> print -1e-050 % 2.0 # => 2.0
> print -1e-050 % 2.0 < 2.0 # => False

See footnote 5.2 in the Language (not Library) reference manual,
section 5.6 "Binary arithmetic operations":

While abs(x%y) < abs(y) is true mathematically, for floats it may
not be true
numerically due to roundoff.  For example, and assuming a platform on which
a Python float is an IEEE 754 double-precision number, in order that
 -1e-100 % 1e100 have the same sign as 1e100, the computed result is
-1e-100 + 1e100, which is numerically exactly equal to 1e100.
Function fmod()
in the math module returns a result whose sign matches the sign of the first
argument instead, and so returns -1e-100 in this case. Which
approach is more
appropriate depends on the application.

> This means I can't use modulus to "wrap around" before it reaches a
> certain value.

It's simply not possible to deliver a float result in all cases that
satisfies all desirable identities.  % and math.fmod make different
tradeoffs, but neither is suitable for all applications, and it's
possble that the neither is suitable for a particular application --
pick your poison, or brew your own.

> I'm using Python 2.4.2 on WindowsXP.

Because it's inherent to using finite-precision approximations to real
numbers, this is a cross-platorm and cross-language phenomenon.  If
you can't tolerate approximations, rework your logic to use integers
instead.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Parsing XML/XSLT

2006-04-23 Thread Paul Boddie
veracon wrote:
>
> I'm looking to use XML and XSLT for templates in a system I'm writing,
> however I'm not really sure which parser is the "best". Basically,
> which library has the most features, and which is the most supported?

I use (my own) libxml2dom [1] and XSLTools [2] to respectively parse
XML documents and perform XSL transformations on those documents, both
solutions employing the widely deployed libxml2 [3] and libxslt [4]
libraries. Alternatively, lxml [5] provides parsing and transformation
APIs based on the same underlying technologies.

> A guide I saw mentioned importing xml.xslt, however it appears the xml
> module/package contains pretty much nothing - xml.xslt outputs an
> exception, No module named xslt.

You could inquire on the XML-SIG mailing list [6] about the status of
XSLT in PyXML or in 4Suite, one or both of which being the origin of
the xml.xslt package.

Paul

[1] http://www.python.org/pypi/libxml2dom
[2] http://www.python.org/pypi/XSLTools
[3] http://www.xmlsoft.org/
[4] http://xmlsoft.org/XSLT/
[5] http://codespeak.net/lxml/
[6] http://mail.python.org/mailman/listinfo/xml-sig/

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


Re: Custom data type in a matrix.

2006-04-23 Thread Gaz
And how im supposed to assign data to a specific hex?

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


Re: Custom data type in a matrix.

2006-04-23 Thread Diez B. Roggisch
Gaz schrieb:
> And how im supposed to assign data to a specific hex?

How would you have done it using numarray? Accessing a specific field is 
done using slicing:

fields[x][y].property = value

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


Re: Custom data type in a matrix.

2006-04-23 Thread Diez B. Roggisch
Diez B. Roggisch schrieb:
> Gaz schrieb:
>> And how im supposed to assign data to a specific hex?
> 
> How would you have done it using numarray? Accessing a specific field is 
> done using slicing:

The term slicing is of course wrong here - it's called array index access.

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


Re: Problem calling math.cos()

2006-04-23 Thread Thomas Bellman
Alex Martelli <[EMAIL PROTECTED]> wrote:

> C has no stand on complex numbers.

If by that you mean that C does not have complex numbers, then
you are wrong.  C99 defines the three types float _Complex,
double _Complex, and long double _Complex, and also the header
.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"God is real, but Jesus is an integer."  !  bellman @ lysator.liu.se
 !  Make Love -- Nicht Wahr!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: bug in modulus?

2006-04-23 Thread [EMAIL PROTECTED]
Hmmm. I understand. I'd suggest that someone just drop a link from the
Library reference manual as the divmod entry over there seems to
contradict it.

"""
divmod(a, b)

Take two (non complex) numbers as arguments and return a pair of
numbers consisting of their quotient and remainder when using long
division. With mixed operand types, the rules for binary arithmetic
operators apply. For plain and long integers, the result is the same as
(a / b, a % b). For floating point numbers the result is (q, a % b),
where q is usually math.floor(a / b) but may be 1 less than that. In
any case q * b + a % b is very close to a, if a % b is non-zero it has
the same sign as b, and 0 <= abs(a % b) < abs(b).
"""

But maybe I'm reading it wrong. In any case what I wanted was simply a
way to extract the angle from a complex number where the angle is
between 0 and 2*pi. I think I'll just take the modulus twice.

def angle(complex):
"""Returns angle where 2*pi > angle >=0

>>> angle(1+1j) - atan(1) < 1e-3
True
>>> angle(-1+1j) - (atan(-1) + 3*pi) % (2*pi) < 1e-3
True
>>> angle(0+1j) == pi/2
True
>>> angle(0-1j) == 1.5*pi
True
>>> angle(1+0j) == 0
True
>>> angle(0+0j) == 0
True
>>> angle(1-1e-100*1j) == 0
True
"""
if complex.real == 0:
if complex.imag == 0:
return 0
if complex.imag < 0:
return 1.5*pi
return pi/2
theta = (atan2(complex.imag, complex.real) % (2*pi)) % (2*pi)
assert 2*pi > theta >=0, (theta, complex)
return theta

Thanks for your help!

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


Re: PYTHONPATH

2006-04-23 Thread Brian van den Broek
bruno at modulix said unto the world upon 20/04/06 08:38 AM:



>>Can anyone help me to make my path persistant?
> 
> 
> Just like any other environnement variable on your system. With most
> distros, it will be something like adding the line:
> 
> export PYTHONPATH="/a/possible/path;/another/one;/and/a/third"
> 
> either in /etc/profile (will be system-wide default) or ~/.bash_profile
> (will be user-specific).
> 
> but this may vary according to your distro and your shell.


Hi all,

reraising a slightly stale thread as I've got the same issue.

I'm a fairly recently convert to ubuntu from Windows and I'm still at 
the stage where I am most comfortable with things right there for the 
clicking, but I'm learning ;-)

The suggestions above appear not to work for me:

[EMAIL PROTECTED]:~/PythonFiles$ pwd
/home/brian/PythonFiles
[EMAIL PROTECTED]:~/PythonFiles$ cd ~
[EMAIL PROTECTED]:~$ cat /etc/profile | grep 'export PYTHONPATH'
export PYTHONPATH="~/PythonFiles"
[EMAIL PROTECTED]:~$ cat .bash_profile | grep 'export PYTHONPATH'
export PYTHONPATH="~/PythonFiles"
[EMAIL PROTECTED]:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from sys import path
 >>> for p in path:
...   if "PythonFiles" in p or "Numeric" in p:
... print p
...
/usr/lib/python2.4/site-packages/Numeric
 >>>

(I don't think it should matter, but I also tried the export line with 
"/home/brian" in place of "~" in both files. I also tried with a ';' 
trailing the single entry in my attempted PYTHONPATHs.)

I don't know where to look for more information; I'm assuming that 
ubuntu isn't doing it the standard way bruno referred to above. Could 
some ubuntu user cast light, please?

Thanks and best,

Brian vdB

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


Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread fumanchu
I'm surprised noone has pursued a course of subtraction rather than
division. Say you want 10 numbers:

>>> s = 1.0
>>> n = []
>>> for x in xrange(9):
... value = random.random() * s
... n.append(value)
... s -= value
...
>>> n.append(s)
>>> n
[0.727922901516, 0.082128708606867745, 0.0080516733577621798,
0.12122060245902817, 0.0034460458833209676, 0.0021046234724371184,
0.054109424914363845, 0.00035750970249204185, 0.00051175075536832372,
0.00015854855820800087]
>>> sum(n)
1.0


Either:
 1) Just because they're *ordered* doesn't mean they're not *random*,
or
 2) You all now know why I'm not a mathematician. ;)

It seems to me that the only constraint on the randomness of my results
is the OP's constraint: that they sum to 1. I'd be fascinated to learn
if and why that wouldn't work.


Robert Brewer
System Architect
Amor Ministries
[EMAIL PROTECTED]

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


Re: Problem calling math.cos()

2006-04-23 Thread Alex Martelli
Thomas Bellman <[EMAIL PROTECTED]> wrote:

> Alex Martelli <[EMAIL PROTECTED]> wrote:
> 
> > C has no stand on complex numbers.
> 
> If by that you mean that C does not have complex numbers, then
> you are wrong.  C99 defines the three types float _Complex,
> double _Complex, and long double _Complex, and also the header
> .

Yeah, I was thinking of the previous (C89) standard, the one which IS
(still) required to build Python.


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


Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Alex Martelli
fumanchu <[EMAIL PROTECTED]> wrote:

> I'm surprised noone has pursued a course of subtraction rather than
> division. Say you want 10 numbers:
> 
> >>> s = 1.0
> >>> n = []
> >>> for x in xrange(9):
> ...   value = random.random() * s
> ...   n.append(value)
> ...   s -= value
> ...
> >>> n.append(s)
> >>> n
> [0.727922901516, 0.082128708606867745, 0.0080516733577621798,
> 0.12122060245902817, 0.0034460458833209676, 0.0021046234724371184,
> 0.054109424914363845, 0.00035750970249204185, 0.00051175075536832372,
> 0.00015854855820800087]
> >>> sum(n)
> 1.0
> 
> 
> Either:
>  1) Just because they're *ordered* doesn't mean they're not *random*,
> or
>  2) You all now know why I'm not a mathematician. ;)
> 
> It seems to me that the only constraint on the randomness of my results
> is the OP's constraint: that they sum to 1. I'd be fascinated to learn
> if and why that wouldn't work.

n[0] is uniformly distributed between 0 and 1; n[1] is not -- not sure
how to characterize its distribution, but it's vastly skewed to favor
smaller values -- and further n[x] values for x>1 are progressively more
and more skewed similarly.

Such total disuniformity, where the very distribution of each value is
skewed by the preceding one, may still be "random" for some sufficiently
vague meaning of "random", but my intuition suggests it's unlikely to
prove satisfactory for the OP's purposes.


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


getattr from local scope

2006-04-23 Thread rob . haswell
Hey there

My question is pretty simple - I want to use something like getattr to
grab a symbol from the local scope from a string.

Basically my application has a scheduler which stores names of
functions
defined in the "schedule" module in a database, to be run on certain
days.
Every night I call schedule.RunSchedule, which grabs all the rows on
the
database that have to be run now, and I want to call the function
defined
the same module according to that string.

I know I can use eval, but I've always been told that if you're using
eval, you're doing it wrong. Also not using eval limits the scope
damage
that can be caused by any errors in my application which could cause
the
database to be poisoned.

Cheers for any help :-)

-Rob

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


Re: PYTHONPATH

2006-04-23 Thread Edward Elliott
Brian van den Broek wrote:
> The suggestions above appear not to work for me:
> 
> [EMAIL PROTECTED]:~$ cat /etc/profile | grep 'export PYTHONPATH'
> export PYTHONPATH="~/PythonFiles"
> [EMAIL PROTECTED]:~$ cat .bash_profile | grep 'export PYTHONPATH'
> export PYTHONPATH="~/PythonFiles"

Those files are only read when you start the shell.  I'm guessing you made 
those changes from the currently running shell.  To fix it you have 3 choices:
1. Close the shell and start a new one
2. Type 'bash -l' at the prompt to invoke a new login shell
3. Type '. .bash_profile' to read the changes into your current shell

> (I don't think it should matter, but I also tried the export line with 
> "/home/brian" in place of "~" in both files.

Nope doesn't matter, as long as 'echo $HOME' is /home/brian.

> I don't know where to look for more information; I'm assuming that 
> ubuntu isn't doing it the standard way bruno referred to above. Could 
> some ubuntu user cast light, please?

This information bruno gave is correct.  It's not an ubuntu issue, it's the 
way unix shells are designed to work.  It's generally udnerstood that 
changing environment variables in a profile requires forcing the shell to 
reprocess them in one of the ways above.  You can also type 'export 
"VAR=value"' to set a variable in the current bash shell (but it's value 
will be lost when the shell exits).

You might want to google for "bash shell tutorial" and familiarize yourself 
with how bash shells work.  It can be somewhat confusing at first, but it's 
a very powerful way to interact with your system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Python from Matlab

2006-04-23 Thread Sébastien Boisgérault

> Also, can you elaborate on what (if anything) it is about Matlab that
> you feel you can't replicate in Python? Are you aware of matplotlib and
> numpy?

The features provided by some matlab 'toolboxes' (libraries in
matlab-speak)
are lacking, and are beyond what numpy + scipy may provide. Some
projects
done in Matlab could easily be translated to Python, but probably not
the control
engineering kind for example -- the algorithms provided by the control
toolbox,
the identification toolbox, etc. are standard tools in the field, and
were
implemented by domain experts.

Don't get me wrong. There are A LOT of scientific projects that can be
done
with Python, and I'd rather cut my hand than do some Matlab programming
when I can avoid it.

I also believe that the work involved in the proper installation of
numpy +
scipy + matplotlib is far beyond the average Matlab user ability (check
the
amount of "installation problem" on the numpy mailing-list ...). But
for sure,
the work done in these libs is just great and their community is
extremely
reactive and helpful.

Last thought: the "All Python behavior in the presence of infinities,
NaNs, and
signed zeroes is a platform-dependent accident" meme still worries me
from
time to time ... But, hey, that's probably just me :)

Cheers,

S.B.

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


Re: getattr from local scope

2006-04-23 Thread Edward Elliott
[EMAIL PROTECTED] wrote:
> Basically my application has a scheduler which stores names of functions
> defined in the "schedule" module in a database, to be run on certain
> days.  Every night I call schedule.RunSchedule, which grabs all the rows on
> the database that have to be run now, and I want to call the function
> defined the same module according to that string.

I know that sys.modules[__name__] gives the module object for the current 
module.  You could do:

m = sys.modules[__name__]  # M now current module object
func = m.__dict__ [fs] # func has function named by string fs
func()

If func isn't in the current module, replace __name__ with 'Foo'.  Add 
try/catch as appropriate in case fs doesn't exist in module M.

If your database stores the function arguments in the same string as the 
function name, you'll have to parse them out separately.

I make no claims to this solution being optimal, as it pretty much 
stretches my knowledge of Python modules and reflection.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-23 Thread Bengt Richter
On Tue, 11 Apr 2006 16:30:10 +0200, bruno at modulix <[EMAIL PROTECTED]> wrote:

>looping wrote:
>> bruno at modulix wrote:
>> 
>>>looping wrote:
>>>
Peter Hansen wrote:


>Georg Brandl wrote:
>
>
>>class C():
>>
>>is meant to be synonymous with
is meant by whom, and according to what rationale?

>>
>>class C:
>>
>>and therefore cannot create a new-style class.
>
>I think "looping" understands that, but is basically asking why anyone
>is bothering with a change that involves a part of the language that is
>effectively deprecated.  In other words, class(): never used to be
>valid, so why make it valid now?
Because it it consistent with passing an empty bases-tuple to type,
which is where a non-empty bases-tuple goes. (See more on metaclass logic 
below).

>
>-Peter


Exact.
But I think that if we make "class C():" a synonym of "class
C(object):", it will save lot of keystrokes ;-)
>>>
+1

>>>Since the class statement without superclass actually creates an
>>>old-style class,  I'd expect the "class MyClass():" variant to behave
>>>the same. Sacrifying readability and expliciteness just to save half a
>>>dozen keystrokes is not pythonic IMHO.
>>>
>> 
>> 
>> I don't think readability suffer 
>
>It does. The statement "class X():" imply there's no superclass, so it
>definitiveley should behave the same as "class X:".
>
I'm not sure what you mean by "no superclass," comparing 

 >>> class X: pass
 ...
 >>> x = X()
 >>> type(x).mro()
 [, ]

with

 >>> class Y(object): pass
 ...
 >>> y = Y()
 >>> type(y).mro()
 [, ]


The way I look at it, in new-style-capable Python,

class X: pass

is really effectively sugar for

class X: __metaclass__ = types.ClassType

and
class X(bases): pass

is sugar for

class X(bases): __metaclass__ = type

so
class X(): pass

ought to be sugar for

class X(): __metaclass__ = type

I.e., "old-style classes" really inherit methods from a metaclass that overrides
the methods of object, so that new-style descriptor logic can be tweaked to 
provide the
old behaviors for classes not having type as metaclass.

>> and expliciteness could sometimes be
>> sacrified to simplify the life of developer: ex "abcd"[0:3]  ->
>> "abcd"[:3].
>
>Here there's no ambiguity.
>
>> And for newbies, the somewhat magic behavior of the "object" superclass
>> is not so clear even that it is very explicit.
>
>There's no magic involved here. And I really doubt that having
>inconsistant behaviour for "class X():" wrt/ "class X:" will help here.
>
Again, IMO any bases-tuple including empty should be sugar for __metaclass__ = 
type, i.e.,

class X(): pass

should be consistent with the empty parens in

X = type("X",(),{}),

not with the backwards-compatibility cleverness (really) of effectively
switching default metaclass to

X = types.ClassType("X",(),{})

using an empty and valid base class tuple as a flag for the switcheroo. Note 
that the code
erroneously creates an empty tuple for class X:pass, as if it were class 
X():pass.

(IMO the proper way to indicate the you don't have a tuple is to use None or 
some other sentinel,
not abuse a perfectly legal tuple value).

 >>> dis.dis(compile('class X:pass','','exec'))
   1   0 LOAD_CONST   0 ('X')   <<--+-- ought to be 
LOAD_CONST 0 (None)
   3 BUILD_TUPLE  0 <<--'
   6 LOAD_CONST   1 ()
   9 MAKE_FUNCTION0
  12 CALL_FUNCTION0
  15 BUILD_CLASS
  16 STORE_NAME   0 (X)
  19 LOAD_CONST   2 (None)
  22 RETURN_VALUE

vs code for class x(something):pass

 >>> dis.dis(compile('class X(object):pass','','exec'))
   1   0 LOAD_CONST   0 ('X')
   3 LOAD_NAME0 (object)
   6 BUILD_TUPLE  1
   9 LOAD_CONST   1 ()
  12 MAKE_FUNCTION0
  15 CALL_FUNCTION0
  18 BUILD_CLASS
  19 STORE_NAME   1 (X)
  22 LOAD_CONST   2 (None)
  25 RETURN_VALUE

IMO generating an empty tuple for class X():pass is a natural variation of the 
immediately above.
What is un-natural is using an empty tuple as a logical flag for old-style 
classes (implementing
the latter by selecting types.ClassType as the metaclass instead of type)
for what would othewise work perfectly normally with the default metaclass of 
type.

Code generation would need to provide something other than an empty tuple
on the stack for class X:pass (IWT None would work?) as the logic flag for 
old-style classes,
and build_class in ceval.c would have to be changed to recognize
the new flag value (None?) for calling types.ClassType,
and pass tuples (including empty) through to type.

>> When I write script I

Re: getattr from local scope

2006-04-23 Thread Alex Martelli
Edward Elliott <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] wrote:
> > Basically my application has a scheduler which stores names of functions
> > defined in the "schedule" module in a database, to be run on certain
> > days.  Every night I call schedule.RunSchedule, which grabs all the rows on
> > the database that have to be run now, and I want to call the function
> > defined the same module according to that string.
> 
> I know that sys.modules[__name__] gives the module object for the current
> module.  You could do:
> 
> m = sys.modules[__name__]  # M now current module object
> func = m.__dict__ [fs] # func has function named by string fs
> func()

sys.modules[__name__].__dict__ may be more handily accessed by the
built-in function globals().


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


Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Robert Kern
Alex Martelli wrote:
> fumanchu <[EMAIL PROTECTED]> wrote:
> 
>>I'm surprised noone has pursued a course of subtraction rather than
>>division. Say you want 10 numbers:
>>
>s = 1.0
>n = []
>for x in xrange(9):
>>
>>...   value = random.random() * s
>>...   n.append(value)
>>...   s -= value
>>...
>>
>n.append(s)
>n
>>
>>[0.727922901516, 0.082128708606867745, 0.0080516733577621798,
>>0.12122060245902817, 0.0034460458833209676, 0.0021046234724371184,
>>0.054109424914363845, 0.00035750970249204185, 0.00051175075536832372,
>>0.00015854855820800087]
>>
>sum(n)
>>
>>1.0
>>
>>Either:
>> 1) Just because they're *ordered* doesn't mean they're not *random*,
>>or
>> 2) You all now know why I'm not a mathematician. ;)
>>
>>It seems to me that the only constraint on the randomness of my results
>>is the OP's constraint: that they sum to 1. I'd be fascinated to learn
>>if and why that wouldn't work.
> 
> n[0] is uniformly distributed between 0 and 1; n[1] is not -- not sure
> how to characterize its distribution, but it's vastly skewed to favor
> smaller values -- and further n[x] values for x>1 are progressively more
> and more skewed similarly.
> 
> Such total disuniformity, where the very distribution of each value is
> skewed by the preceding one, may still be "random" for some sufficiently
> vague meaning of "random", but my intuition suggests it's unlikely to
> prove satisfactory for the OP's purposes.

[digression]

All of this discussion about whether the distribution of values is uniform or
not doesn't mean much until one has defined "uniformity," or equivalently,
"distance" in the space we're talking about. In this case, we're talking about
the unit n-simplex space (SS^n) which has elements S=(s_1, s_2, ... s_n) where
sum(S) = 1 and s_i >= 0. I favor the Aitchison distance:

import numpy as np

def aitchison_distance(x, y):
""" Compute the Aitchison distance between two vectors in simplex space.
"""
lx = np.log(x)
ly = np.log(y)
lgx = np.mean(lx, axis=-1)
lgy = np.mean(ly, axis=-1)
diff = (lx - lgx) - (ly - lgy)
return np.sqrt(np.sum(diff*diff))

Note that zeros yield inifinities, so the borders of the unit simplex are
infinitely farther away from other points in the interior. Consequently,
generating "uniform" random samples from this space is as impractical as it is
to draw "uniform" random samples from the entire infinite real number line. It's
also not very interesting. However, one can transform SS^n into RR^(n-1) and
back again, so drawing numbers from a multivariate normal of whatever mean and
covariance you like will give you "nice" simplicial data and quite possibly even
realistic data, too, depending on your model. I like using the isometric
log-ratio transform ("ilr" transform) for this.

Good Google search terms: "compositional data", Aitchison

But of course, for the OP's purpose of creating synthetic Markov chain
transition tables, generating some random vectors uniformly on [0, 1)^n and
normalizing them to sum to 1 works a treat. Don't bother with anything else.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Edward Elliott
Alex Martelli wrote:
> Such total disuniformity, where the very distribution of each value is
> skewed by the preceding one, may still be "random" for some sufficiently
> vague meaning of "random", but my intuition suggests it's unlikely to
> prove satisfactory for the OP's purposes.

It does seem very odd.  If you could restrict the range, you could get an 
unskewed distribution.  Set range = (0, 2*sum/cnt) and you can generate cnt 
numbers whose sum will tend towards sum (because the average value will be 
sum/cnt):

target_sum = 1
cnt = 100
max = 2.0 * target_sum / cnt  # 0.02
nums = [random.uniform(0,max) for x in range(0,cnt)]
real_sum = sum(nums)   # 0.975... in one sample run

If the sum has to be exact, you can set the last value to reach it:

nums[-1] = target_sum - sum(nums[:-1])
print sum(nums)   # 1.0

which skews the sample ever so slightly.  And check for negatives in case 
the sum exceeded the target.

If the exact count doesn't matter, just generate random nums until you're 
within some delta of the target sum.

Basically, there usually better options to the problem as originally posed. 
  Actually, now that I reread it the OP never said the range had be [0,1). 
  So maybe we read too much into the original phrasing.  If you need 
anything resembling a uniform distribution, scaling the results afterward 
is not the way to go.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getattr from local scope

2006-04-23 Thread Edward Elliott
Alex Martelli wrote:
> sys.modules[__name__].__dict__ may be more handily accessed by the
> built-in function globals().

Well there you go.  Glad it's not that awkward.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHONPATH

2006-04-23 Thread Brian van den Broek
Edward Elliott said unto the world upon 23/04/06 04:28 PM:
> Brian van den Broek wrote:
> 
>>The suggestions above appear not to work for me:
>>
>>[EMAIL PROTECTED]:~$ cat /etc/profile | grep 'export PYTHONPATH'
>>export PYTHONPATH="~/PythonFiles"
>>[EMAIL PROTECTED]:~$ cat .bash_profile | grep 'export PYTHONPATH'
>>export PYTHONPATH="~/PythonFiles"
> 
> 
> Those files are only read when you start the shell.  I'm guessing you made 
> those changes from the currently running shell.  To fix it you have 3 choices:
> 1. Close the shell and start a new one
> 2. Type 'bash -l' at the prompt to invoke a new login shell
> 3. Type '. .bash_profile' to read the changes into your current shell

Edward,

thanks for the reply. I'm going to not worry about exposing my
ignorance in what follows :-)

I ought to have specified that I did indeed think to invoke a new
shell after I made the changes. However, trying (2) and (3) as you
specified shed some light.

Early on, (probably miss-)following something I read on the net, I'd put
a block into my .bash_profile that read:

if 1; then
 somestuff

Trying (3) gave
[EMAIL PROTECTED]:~$ . .bash_profile
bash: 1: command not found

Commenting out the bad block in .bash_profile, if I open a shell and 
things are somewhat better.

Only somewhat, as if I open a brand new shell:

[EMAIL PROTECTED]:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from sys import path
 >>> path[0:3]
['', '/usr/lib/python24.zip', '/usr/lib/python2.4']
 >>>
[EMAIL PROTECTED]:~$ . .bash_profile
[EMAIL PROTECTED]:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01)
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> from sys import path
 >>> path[0:3]
['', '/home/brian/PythonFiles', '/usr/lib/python24.zip']
 >>>


So, it seems that I currently have to invoke '. .bash_profile'
manually with each new shell opened for this to have effect. (Trained 
by Bill, I even rebooted to be sure that the invocation of
'. .bash_profile' is needed.)
But, still it is closer :-)

I still haven't managed to coerce lines in /etc/profile exporting 
PYTHONPATH to have an effect.





>>I don't know where to look for more information; I'm assuming that 
>>ubuntu isn't doing it the standard way bruno referred to above. Could 
>>some ubuntu user cast light, please?
> 
> 
> This information bruno gave is correct.  

I didn't mean to suggest bruno was wrong, but instead that perhaps
ubuntu was a distro falling under his phrase:

> but this may vary according to your distro and your shell

such that the instructions he gave would not work without
modification. Apologies if I gave a different impression.




> You might want to google for "bash shell tutorial" and familiarize yourself 
> with how bash shells work.  It can be somewhat confusing at first, but it's 
> a very powerful way to interact with your system.

Thanks for the suggestions. With luck, I'll get the remaining issue
sorted. Thanks for the help,

Brian vdB

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


Passing data attributes as method parameters

2006-04-23 Thread Panos Laganakos
Hello,

I'd like to know how its possible to pass a data attribute as a method
parameter.

Something in the form of:

class MyClass:
def __init__(self):
self.a = 10
self.b = '20'

def my_method(self, param1=self.a, param2=self.b):
pass

Seems to produce a NameError of 'self' not being defined.

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


Re: Passing data attributes as method parameters

2006-04-23 Thread Ben Cartwright
Panos Laganakos wrote:
> I'd like to know how its possible to pass a data attribute as a method
> parameter.
>
> Something in the form of:
>
> class MyClass:
> def __init__(self):
> self.a = 10
> self.b = '20'
>
> def my_method(self, param1=self.a, param2=self.b):
> pass
>
> Seems to produce a NameError of 'self' not being defined.

Default arguments are statically bound, so you'll need to do something
like this:

class MyClass:
def __init__(self):
self.a = 10
self.b = '20'

def my_method(self, param1=None, param2=None):
if param1 is None:
param1 = self.a
if param2 is None:
param2 = self.b

--Ben

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


Re: Why new Python 2.5 feature "class C()" return old-style class ?

2006-04-23 Thread Paul Boddie
Christophe wrote:
> Aahz a écrit :
> > I'm certainly not alone in believing that new-style classes are
> > better avoided for newbies.
>
> Well, old-style classes are perfect to confuse the newbie. After all,
> there's nothing like adding a "property" in a class and wondering why
> it does not work as expected.

Well, for years everyone joked about Java's "public static void main"
business - confusing boilerplate for newbies, they said - but apart
from various deep runtime-dependent arguments, I can't see how "class
something(object)" is any less forgivable, especially in a teaching
environment where you've just explained that "object" and "instance"
are mostly interchangeable terms for something made from a class.

And to make the "guard of shame" (the opposite of a guard of honour)
complete in this sorry tale, it should be pointed out that they don't
make you write "class Something extends Object" all over the place in
Java, or at least not when I last wrote any Java code. Something to
think about for Python 3000 in the context of reaching a wider
audience, I suppose.

> What would be a language without horrible pitfalls ? Newbies would have
> it easy and they have no right for an easy language !

;-) Or were you being serious? :-O

Paul

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


Re: Passing data attributes as method parameters

2006-04-23 Thread Panos Laganakos
Thanks Ben.

What does it mean that they're statically bound?

It seems weird that I'm not able to access variables in the class
namespace even though these attributes come into existance after class
instantiation.

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


Re: Passing data attributes as method parameters

2006-04-23 Thread Jay Parlar

On Apr 23, 2006, at 4:59 PM, Panos Laganakos wrote:

> Thanks Ben.
>
> What does it mean that they're statically bound?
>
> It seems weird that I'm not able to access variables in the class
> namespace even though these attributes come into existance after class
> instantiation.
>

The parameters are "put together" and bound to the method when the 
class is defined, *not* after class instantiation.

As an example:

 >>> class MyClass:
...  def my_method(self, param1 = []):
...   print param1
...   param1.append(5)
...
 >>> x = MyClass()
 >>> x.my_method()
[]
 >>> x.my_method()
[5]
 >>> y = MyClass()
 >>> y.my_method()
[5, 5]
 >>> y.my_method()
[5, 5, 5]
 >>>


Usually, people use immutable datatypes as default parameter values, so 
it doesn't cause a problem.

And an even more illustrative example:

 >>> class M:
...  x = 2
...  def my_method(self, param = M.x):
...   pass
...
Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 3, in M
NameError: name 'M' is not defined


The class is still being built when the method is created, so even the 
name "M" doesn't exist yet.




Ben's solution is probably the best way to do what you're looking for.

Jay P.

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


Re: PYTHONPATH

2006-04-23 Thread Edward Elliott
Brian van den Broek wrote:
> if 1; then
> somestuff
>
> Trying (3) gave
> [EMAIL PROTECTED]:~$ . .bash_profile
> bash: 1: command not found

The error indicates the shell tried to execute a program named '1' and 
couldn't find one.  Arthimetic expressions generally have to be wrapped in 
(()) in bash:

if ((1)); then
  stuff

Conditional expressions use [[ ]] (the spaces inside the brackets matter). 
   So ((0)) is false while [[ 0 ]] is true.  Yes the difference is screwy 
and it sucks.  Since ((1)) is always true, you could leave out the if line 
altogether, but I'm guessing that 'stuff' is multiple lines that want to 
toggle on and off.


> Only somewhat, as if I open a brand new shell:
> 
> [EMAIL PROTECTED]:~$ python
>  >>> from sys import path
>  >>> path[0:3]
> ['', '/usr/lib/python24.zip', '/usr/lib/python2.4']

You realize this only prints the first 3 elements of path, right?

> So, it seems that I currently have to invoke '. .bash_profile'
> manually with each new shell opened for this to have effect. 

Your shell must not be opening as a login shell.  From the bash man page:

"When  bash is invoked as an interactive login shell, or as a
non-interactive shell with the --login option, it first reads and executes
commands  from  the file /etc/profile, if that file exists.  After reading
that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in
that order, and reads and executes commands from the first one that exists
and is readable...

"When an interactive shell that is not a login shell  is  started,  bash
reads  and  executes  commands  from /etc/bash.bashrc and ~/.bashrc, if
these files exist."

I don't like differences between my interactive and login shell, so I 
usually just link .bashrc to .bash_profile.  You can do that with this 
command (from your home dir):

ln .bash_profile .bashrc

(assuming .bashrc doesn't exist, if so remove it first).  This makes 
.bashrc the same file as .bash_profile, either name accesses the same contents.

Another option is to invoke one from the other with the . command.  I.e. 
put the line '. .bashrc' somewhere in .bash_profile and then move all the 
common commands (like PYTHONPATH=) to .bashrc.

You shouldn't mess with /etc/profile for personal settings.  That's what 
.profile/.bashrc are for.  /etc is for system-wide settings that apply to 
all users on the system (including system processes, which you probably 
don't want to affect).


> (Trained by Bill, I even rebooted to be sure that the invocation of
> '. .bash_profile' is needed.)

Rebooting is something you almost never need to do in linux unless you're 
installing new hardware or a new kernel.  It won't affect the operation of 
bash in any way.  That said, rebooting won't hurt either if you don't know 
how to manually restart an affected process or daemon.


> I still haven't managed to coerce lines in /etc/profile exporting 
> PYTHONPATH to have an effect.

As I said, must not be a login shell (see above).


> I didn't mean to suggest bruno was wrong, but instead that perhaps
> ubuntu was a distro falling ... such that the instructions he gave 
> would not work without modification. Apologies if I gave a different
> impression.

Yes I got that.  When you do need ubuntu-specific help, you can try the 
forums on

http://ubuntuforums.org/

I don't think you'll need that for any Python-related questions though 
(other than installing python packages with apt-get).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: bug in modulus?

2006-04-23 Thread Dan Bishop
[EMAIL PROTECTED] wrote:
> Hmmm. I understand. I'd suggest that someone just drop a link from the
> Library reference manual as the divmod entry over there seems to
> contradict it.
>
> """
> divmod(a, b)
>
> Take two (non complex) numbers as arguments and return a pair of
> numbers consisting of their quotient and remainder when using long
> division. With mixed operand types, the rules for binary arithmetic
> operators apply. For plain and long integers, the result is the same as
> (a / b, a % b). For floating point numbers the result is (q, a % b),
> where q is usually math.floor(a / b) but may be 1 less than that. In
> any case q * b + a % b is very close to a, if a % b is non-zero it has
> the same sign as b, and 0 <= abs(a % b) < abs(b).
> """
>
> But maybe I'm reading it wrong. In any case what I wanted was simply a
> way to extract the angle from a complex number where the angle is
> between 0 and 2*pi. I think I'll just take the modulus twice.

If you absolutely insist on having the angle be less than 2*pi, you
could always do something like:

theta = min(theta, pi*2 - 2**(-50))

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


MySQLdb

2006-04-23 Thread placid
Hi all,

Does anyone have binary for MySQLdb (python 2.4.3, MySQL 5.0a) ?

Regards

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


Re: MySQLdb

2006-04-23 Thread skip

placid> Does anyone have binary for MySQLdb (python 2.4.3, MySQL 5.0a) ?

Platform?  Last I checked a few weeks ago, MySQLdb didn't yet work with
MySQL 5.0.

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


Re: Recommended IDE for creating GUI?

2006-04-23 Thread Luis M. González
Check PythonCard: 
http://pythoncard.sourceforge.net

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


Using distutils in Windows XP / "Python in a Nutshell"

2006-04-23 Thread Blair LeGent
Following the directions in "Python in a Nutshell" (an excellent book), 
I entered the C code for "helloworld.c", saved it as a file, and entered 
this script and saved it as setup.py:

from distutils.core import setup, Extension
setup(name='helloworld', ext_modules= [ 
Extension('helloworld',sources=['helloworld.c'])])

Then, following directions, I type "python setup.py install" from a C:\> 
prompt.  I get these messages:

running install
running build
running build_ext
error: The .NET Framework SDK needs to be installed before building 
extensions for Python.

...but the .NET Framework IS installed; the latest version, in fact, SDK 
v2.0, part of the Visual Studio 2005 beta I've got.  From poking around 
the Internet it looks like I'm supposed to (a) monkey with my registry, 
(b) install an OLD version of the SDK, (c) screw around with distutils 
source code, or (d) switch to Linux.  Nowhere do I find a clear solution 
to my problem, though.  Can anyone help?  Should we submit an errata to 
O'Reilly?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using distutils in Windows XP / "Python in a Nutshell"

2006-04-23 Thread Edward Elliott
Blair LeGent wrote:
> error: The .NET Framework SDK needs to be installed before building 
> extensions for Python.
> 
> ...but the .NET Framework IS installed

Just a guess, but is the C compiler in your PATH when you run python?  I'm 
assuming python on xp still uses environment variables and not some 
windows-specific method for locating binaries.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MySQLdb

2006-04-23 Thread placid

[EMAIL PROTECTED] wrote:

> placid> Does anyone have binary for MySQLdb (python 2.4.3, MySQL 5.0a) ?
>
> Platform?  Last I checked a few weeks ago, MySQLdb didn't yet work with
> MySQL 5.0.
> 
> Skip

Sorry about that , im using Windows XP...

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


Re: MS VC++ Toolkit 2003, where?

2006-04-23 Thread AIM
The site comes back with a message saying ...

"The download you requested is unavailable. If you continue to see this
message when trying to access this download, go to the "Search for a
Download" area on the Download Center home page."

Does anyone have any other ideas of where to look?

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


Re: Using distutils in Windows XP / "Python in a Nutshell"

2006-04-23 Thread Alex Martelli
Blair LeGent <[EMAIL PROTECTED]> wrote:

> Following the directions in "Python in a Nutshell" (an excellent book),

Thanks!

> I entered the C code for "helloworld.c", saved it as a file, and entered
> this script and saved it as setup.py:
> 
> from distutils.core import setup, Extension
> setup(name='helloworld', ext_modules= [ 
> Extension('helloworld',sources=['helloworld.c'])])
> 
> Then, following directions, I type "python setup.py install" from a C:\>
> prompt.  I get these messages:
> 
> running install
> running build
> running build_ext
> error: The .NET Framework SDK needs to be installed before building 
> extensions for Python.
> 
> ...but the .NET Framework IS installed; the latest version, in fact, SDK
> v2.0, part of the Visual Studio 2005 beta I've got.  From poking around
> the Internet it looks like I'm supposed to (a) monkey with my registry,
> (b) install an OLD version of the SDK, (c) screw around with distutils
> source code, or (d) switch to Linux.  Nowhere do I find a clear solution
> to my problem, though.  Can anyone help?  Should we submit an errata to
> O'Reilly?

No need: the second edition (forthcoming!) does explain that the
compiler you need to build Python extensions (for 2.4 and 2.4) is VS
2003.  I don't belabor on the hows and whys of VS2005 not being
supported -- I'm not into Windows (over the last few years) to grok them
fully.   explains one
way to avoid shelling out $$$ to MS while still being able to build
Python extensions -- and just today I asked on this very group about
where to find VS 20003 Toolkit (it's not at its original location
indicated at the above URL, any more!) and was promptly answere with a
URL that worked just fine.


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


Re: MS VC++ Toolkit 2003, where?

2006-04-23 Thread Alex Martelli
AIM <[EMAIL PROTECTED]> wrote:

> The site comes back with a message saying ...
> 
> "The download you requested is unavailable. If you continue to see this
> message when trying to access this download, go to the "Search for a
> Download" area on the Download Center home page."
> 
> Does anyone have any other ideas of where to look?

As suggested to me by David Rushby 10 hours ago,

http://www.microsoft.com/downloads/details.aspx?FamilyId=272BE09D-40BB-4
9FD-9CB0-4BFA122FA91B&displaylang=en

does work.

But, there's another problem -- helloworld.c compiles fine, but linking
doesn't find MSVCRT.LIB -- apparently, the 2.0 .NET Framework SDK does
NOT include this file for x86 (there _are_ a couple of versions under
a64 and some other parallel directory, but I doubt they're good to use
with an x86!-).  As the already-quoted crucial URL
 mentions:

"""
# .NET Framework SDK Version 1.1

  Provides the core msvcrt.lib for msvcr71.dll against which to link
your extensions.  This is critically important, as without it you are
going to wind up linking against the wrong run-time and will see crashes
whenever a core object such as a file is shared across run-time
barriers.

  The 2.0 beta also works according to reports, and may be required
to build Numpy 23.6 (whereas 23.1 seems to work without it).
"""

Whether the 2.0 beta also worked, the current definitive 2.0 seems NOT
to work.

Can anybody suggest where to get a Framework SDK 1.1., or any other
legal way to get "the core msvcrt.lib for msvcr71.dll against which to
link your extensions.  This is critically important"...???


And, as an aside...:

It's sure an interesting reflection, that impecunious or thrifty
developers (ones not willing to shell out mucho $$$ to MS for a pro VS
2003) must go through such gyrations as these in order to be able to
build Python extensions on Windows.  I'm sure my Windows-loving
colleagues in the PSF (who got several free copies of VS 2003 from
Microsoft, I believe -- at the time, I had zero Windows installations
and zero interest in Windows, so I didn't sign up for one) have fully
considered this recurring drama, and come to the decision of sticking
with VS 2003 (avoiding any free-as-in-beer compilers such as VS 2005 or
mingw) with thorough and wise deliberation.

The optimizer in the C compiler used to build Python in Windows *IS*
impressive: just today, I ran (and posted to it.comp.macintosh) pybench
on Python 2.4.3 on iBook G4 12", Macbook Pro 2.0 GHz, and Parallels
Workstation VM with Win2000 on the same Macbook -- while the Macbook is
4 times as fast as the iBook, the Windows version, despite the slight
overhead of running under Parallels' virtualization, is an impressive
12%+ _faster_ than the "native" MacOSX Python 2.4.3 (I'm not quite sure
about how good Parallels' virtualization IS, but even if it's as
impressive as a mere 3% overhead, this still means that the Windows
version of Python on identical HW must be at least 15% faster than the
MacOSX version, compiled with gcc).

I can see the stance that such a speedup warrants using Microsoft's
costly VS 2003 and imposing endless gyrations on developers trying to
get it on the cheap -- being one of the latter developers, I'm inclined
nevertheless to grumble, right now, of course;-)...


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


Re: mod_python web-dav management system

2006-04-23 Thread Kyler Laird
[EMAIL PROTECTED] writes:

>What about if there existed a mod_dav_python for Apache. Would
>that be of interest.

To me it would only be of interest if it's combined with Apache's
suid capabilities.

> The idea is that the module could bridge the
>C API hooks and structures of mod_dav module to Python code.
>This means the benefit from all the hard work that has been put
>into the Apache mod_dav module and only need to implement
>stuff that handles the individual operations if you want to implement
>some sort of custom DAV server.

I can already get what I need using Apache DAV support with a custom
(FUSE) filesystem.  I'd just rather have a nice simple Python solution.

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


MySql -Python question

2006-04-23 Thread ataanis
Hey all, I'm running a query within some python code, and I'm having
difficulties doing something that seems to be really simple . I'm
running a query in the following form:
query01 = 'select max(DirectorID) +1 from Director;'
cursor.execute(query01)
table = cursor.fetchall()
the resulting table , is a 1 row , 1 column table,showing 1 number and
I just need that number inside that table,and save it for a different
query,  but I can't get it , can anybody tell me the best way to do
this? thanks

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


Remember me... The Virtual Interaction configuration?

2006-04-23 Thread threeseas
for those who don't like me, here's your last chance to shoot me down

See wikipedia entries for
Timothy Rue
and
Abstraction Physics.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can you create an instance of a subclass with an existing instance of the base class?

2006-04-23 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>,
 "Sandra-24" <[EMAIL PROTECTED]> wrote:

>However in this case I'm simply getting an object (an mp_request object
>from mod_python) passed into my function, and before I pass it on to
>the functions that make up and individual web page it is modified by
>adding members and methods to add functionality.

All you want is a dictionary, then. That's basically what Python objects 
are.
-- 
http://mail.python.org/mailman/listinfo/python-list


i18n hell

2006-04-23 Thread fyleow
I just spent hours trying to figure out why even after I set my SQL
table attributes to UTF-8 only garbage kept adding into the database.
Apparently you need to execute "SET NAMES 'utf8'" before inserting into
the tables.

Does anyone have experience working with other languages using Django
or Turbogears?  I just need to be able to retrieve and enter text to
the database from my page without it being mangled.  I know these
frameworks employ ORM so you don't need to write SQL and that worries
me because I tried this on Rails and it wouldn't work.

Thanks.

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


Re: MS VC++ Toolkit 2003, where?

2006-04-23 Thread Edward Elliott
Alex Martelli wrote:
> the Windows version, despite the slight
> overhead of running under Parallels' virtualization, is an impressive
> 12%+ _faster_ than the "native" MacOSX Python 2.4.3 (I'm not quite sure
> about how good Parallels' virtualization IS, but even if it's as
> impressive as a mere 3% overhead, this still means that the Windows
> version of Python on identical HW must be at least 15% faster than the
> MacOSX version, compiled with gcc).

Can you post the complete benchmark results from both systems on the 
Macbook?  My understanding is that virtualization overhead is not a 
constant factor like 3%.  Unprivileged instructions run unmodified; only 
privileged instructions like hardware accesses get trapped, adding 
overhead.  Any percentage figure advertised by the manufacturer is most 
likely an average over some data set with both types of instructions.

The types of tests mentioned on the pybench site -- function calls, 
lookups, exceptions, etc -- shouldn't incur any overhead from 
virtualization.  It would be helpful to see exactly which tests were faster 
and by how much instead of an overall average result.

The differences may be due to factors other than compiler optimizations. 
I've heard for instance the OS X virtual memory manager is not particularly 
speedy for large data sets.  That could give the windows pybench a win on 
certain tests regardless of which compiler has better optimizations.

Then you've got issues of whether the compilers are really competing on 
equal footing.  Were similar options enabled for each build, does each 
build represent the best possible optimizations or only the ones the 
builder knew about, etc.  I think Apple switched to the Intel compiler for 
x86 macs, was python built with that or with gcc?

In short, your results are interesting but I'm not sure what to make of 
them yet.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: MS VC++ Toolkit 2003, where?

2006-04-23 Thread Robert Kern
Edward Elliott wrote:
> I think Apple switched to the Intel compiler for 
> x86 macs, was python built with that or with gcc?

I'm pretty sure MacTel OS X still uses gcc 4 (although I think there is a beta
version of the Intel compiler available). All of the Python builds floating
around for it certainly use gcc.

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: How I learned Tkinter

2006-04-23 Thread Ian Parker
In message <[EMAIL PROTECTED]>, 
peter <[EMAIL PROTECTED]> writes
>I've been trying to teach myself Tkinter programming over the last few
>months
>(in a strictly amateur way), and have made a number of requests for
>help in this
>newsgroup and elsewhere.
>
>I've now (sort of) got there - in that I have used Tkinter for some
>programs for
>personal use - and I've written up my experiences at
>
>http://www.aqzj33.dsl.pipex.com/how_i_learned_tkinter/contents.htm
>
>
>In general I found that while Frederik Lundh's tutorial is
>comprehensive and
>well written, there is little else around to help the newcomer working
>without
>the benefit of more experienced colleagues, and that in places the
>documentation
>is too sparse to be of much help.
>
>Any thoughts? Is my experience typical?
>
>Peter
>

Recently I decided to use tkinter because it was included with Python 
and like you I suffered through a few weeks of puzzling out tkinter.  I 
wish I'd read your notes before I started!

Regards

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


Re: Generate a sequence of random numbers that sum up to 1?

2006-04-23 Thread Terry Reedy

"fumanchu" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> I'm surprised noone has pursued a course of subtraction rather than
> division.

I believe someone did mention the subtraction method in one of the initial 
responses.  But the problem is this.  If you independently sample n numbers 
from a given distribution and then rescale, then the scaled numbers still 
all have the same distribution (and are uniform in that sense).  In the 
subtraction method, each comes from a differnt distribution, as others 
explained, with the nth being radically different from the first.

Terry Jan Reedy



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


MinGW and Python

2006-04-23 Thread Srijit Kumar Bhadra
Is there any specific reason for not using MinGW to build the official
distribution of Python for Win32?
A quick Google search did not reveal the answer to my question. If a
link is available, please post it.

Best Regards,
Srijit

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


cmd module "busy waiter" ?

2006-04-23 Thread placid
Hi all,

Just wondering if the cmd module in python uses "busy waiting" for
"polling" user command input as this is inefficient.

Cheers

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