Steiner Tree

2007-02-05 Thread [EMAIL PROTECTED]
Hi,
I am looking for links to any implementation of Steiner Tree (
http://en.wikipedia.org/wiki/Steiner_tree ) construction in Python. I
could find GeoSteiner  ( http://www.diku.dk/geosteiner/ ) which is
implemented as a C program. Anybody know python wrapper for this?
Anybody tried this program in a python program?

-
Suresh

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


Assigning pointer to PySwigObject in Boost

2007-02-05 Thread willievdm
Hi all

I'm working with Boost.Python at the moment and have to do the
following:
-Using Boost, assign a char* in C++ to a PySwigObject (SWIG exposed
object) of type uchar*, which is received in C++ as a
boost::python::object class.

The uchar* pointer in the PySwigObject points to a buffer containing
image data. All I wish to do is assign a C++ pointer that is also
pointing to a buffer with image data to the PySwigObject pointer and
send it back to Python. The PySwigObject is part of the CvMat class
used with OpenCV for image-processing in Python. It is already wrapped
in SWIG, so I CANNOT change it. I've already been to the python Wiki
that explains how to extract SWIG exposed pointers in python (http://
wiki.python.org/moin/boost.python/HowTo), but this does NOT tell me
how to do the opposite: assigning C++ pointers to SWIG exposed
pointers with Boost.

Any tips or tricks to get this working?

Thanks

Will

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


Re: Python does not play well with others

2007-02-05 Thread [EMAIL PROTECTED]
John Nagle wrote:
> Graham Dumpleton wrote:
> > On Feb 4, 1:05 pm, Paul Rubin  wrote:
> >
> >>"Paul Boddie" <[EMAIL PROTECTED]> writes:
> >>
> >>>Probably the biggest inhibitor, as far as I can see, has been the
> >>>server technology chosen. Many hosting providers have historically
> >>>offered no better than CGI for Python, whilst PHP runs within Apache
> >>>itself, and it has previously been stated that mod_python has been
> >>>undesirable with regard to isolating processes from each other.
> >>>Consequently, a number of Python people seem to have held out for
> >>>other "high performance" solutions, which various companies now offer.
> >>
> >>Your point that shared hosting with Python isn't so easy because of
> >>insufficient isolation between apps is valid.  Maybe Python 3.0 can do
> >>something about that and it seems like a valid thing to consider while
> >>fleshing out the 3.0 design.
> >
> >
> > To clarify some points about mod_python, since these posts do not
> > properly explain the reality of the situation and I feel people are
> > getting the wrong impression.
> >
> > First off, when using mod_python it is possible to have it create
> > multiple sub interpreters within each Apache child process.
>
>  Realistically, mod_python is a dead end for large servers,
> because Python isn't really multi-threaded.  The Global Python
> Lock means that a multi-core CPU won't help performance.

The GIL doesn't affect seperate processes, and any large server that
cares about stability is going to be running a pre-forking MPM no
matter what language they're supporting.

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


Finding cpu time spent on my program

2007-02-05 Thread [EMAIL PROTECTED]
I am trying to measure the time the processor spends on some
operation, and I want this measure to not depend on the current load
of the machine. But doing the following prints different values each
time a run.

import time
c1 = time.clock()
for x in xrange(0xF): pass

c2 = time.clock()
print "Time spent is %f" % (c2-c1)

Is there a way to measure the number of cpu cycles spent on my program
alone irrespective of the current load etc of the machine.

-
Suresh

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


Re: when will python 2.5 take in mainstream?

2007-02-05 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
> When they have to ...
> 
> One of the big things about Python is that its penetration slows it
> down. There's more legacy code and interdependant systems around now
> that Python is more successful and more mature.
> 
> Here's a thought -- perhaps it would be worth having some good ways to
> interact with Python from Python. Suppose you have some 2.4 code
> someplace, interacting with your mysqldb or whatever, and you don't
> want to rewrite it. So long as you have some kind of object broker,
> you could (plausibly) leave your 2.4 apps running with the old
> interpreter, but wrap them for Python 2.5 and use that in your new
> development.

KISS please.

> Ditto 3.0.
> 
> Rather than having to re-write every interacting component, maybe it
> could be straightforward to all Python2.4 from Python2.5 to execute
> particular library calls. I'm not an expert, I don't know how you'd
> build such a system, but I do know that re-writing stuff is a real
> pain.

Most of Python 2.4 source code is compatible with Python 2.5. Problems
come with native compiled modules, you must have those for you 2.X
Python version - some times just a compilation is enough.

For Python 3.0, AFAIK its a big rewrite and developers know that it will
be uncompatible in large parts with existing code.


> Perhaps APIs for 2.5 and 3.0 could have a special version flag, and if
> not present or not compatible, a 2.4 interpreter could be called
> instead...

Making Python interpreter bigger and more complex.
Some code already has "hacks", trying to import a newer module and
installing a fallback if its not available.

If really your old Python 2.4 software cant run under Python 2.5, then
you can have both Python 2.4 and 2.5 installed and running some code.
Setup Pyro [1] on both, and go throught remote object invocation.
And if you dont need new Python 2.5 stuff in your code evolution, just
stay with 2.4, it works well.


A+

Laurent.

[1] http://pyro.sourceforge.net/


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


Re: Decimating Excel files

2007-02-05 Thread greg
Arnd wrote:

> Good observation, but as we have numbers of type Cardinalia,
> Ordinalia, Distributiva & Multiplicativa in Latin I would prefer
> secundating or secondating. (Bisimating or bicimating would multiply
> the lines by a factor 2)

Interesting. But does this mean that "duplicating" is
actually from the wrong root? And also we have
"bifurcation", which means splitting in two rather
than multiplication by two -- or does that come
down to the same thing?

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


python references

2007-02-05 Thread dustin . getz
>>> from Numeric import zeros
>>> p=zeros(3)
>>> p
array([0,0,0])
>>> p[0]
0
>>> x=p[0]
>>> x=10
>>> p
array([0,0,0]) #actual behavior
#array([10,0,0]) #desired behavior

I want x to be a C++-esque reference to p[0] for convenience in a
vector3 class.  i dont want accessor methods.  i know python can do
this, but it's been a long time since I used it and am unsuccessful in
my googling and docreading.  a little help please?

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


in place-ness of list.append

2007-02-05 Thread Bart Van Loon
Hi all,

I would like to find out of a good way to append an element to a list
without chaing that list in place, like the builtin list.append() does.

currently, I am using the following (for a list of integers, but it
could be anything, really)

#--
def addnumber(alist, num):
""" work around the inplace-ness of .append """ 
mylist = alist[:]
mylist.append(num)
return mylist
#--

and I am wondering if this is good practice or not.

any advice on this matter?

thanks!

-- 
regards,
BBBart

   "Someday I'll write my own philosophy book." -Calvin
-- 
http://mail.python.org/mailman/listinfo/python-list


Inheriting str object

2007-02-05 Thread [EMAIL PROTECTED]
I want to have a str with custom methods, but I have this problem:

class myStr(str):
def hello(self):
return 'hello '+self

s=myStr('world')
print s.hello() # prints 'hello world'
s=s.upper()
print s.hello() # expected to print 'hello WORLD', but s is no longer
myStr, it's a regular str!

What can I do?

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


Re: LDAP/LDIF Parsing

2007-02-05 Thread Michael Ströder
Bruno Desthuilliers wrote:
> 
> If you know which attributes are supposed to be multivalued in your
> specific application, then it's time to write a more serious,
> application-specific wrapper.

ldap.schema can be used to find that out.

Ciao, Michael.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How can I access data from MS Access?

2007-02-05 Thread Andy Dingley
On 3 Feb, 15:43, [EMAIL PROTECTED] wrote:
> How to access data from MS Access?

Can you access Access from Access ?  from Excel / Visual Basic / SQL
Query? First of all check that the DSN is working and connects to the
back end MDB. This might not be Python's problem.

Secondly check whatever errors you're being returned.

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


Re: in place-ness of list.append

2007-02-05 Thread skip

Bart> #--
Bart> def addnumber(alist, num):
Bart> """ work around the inplace-ness of .append """ 
Bart> mylist = alist[:]
Bart> mylist.append(num)
Bart> return mylist
Bart> #--

Bart> and I am wondering if this is good practice or not.

Bart> any advice on this matter?

Such an operation will be O(N**2), and thus expensive if performed
frequently on lists of moderate length.  I've never been tempted to do this.
Can you say a little about why you'd want to do this?  Knowing that, perhaps
someone here can point you in a more Pythonic direction.

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


Re: python references

2007-02-05 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 from Numeric import zeros
 p=zeros(3)
 p
> array([0,0,0])
 p[0]
> 0
 x=p[0]
 x=10
 p
> array([0,0,0]) #actual behavior
> #array([10,0,0]) #desired behavior
> 
> I want x to be a C++-esque reference to p[0] for convenience in a
> vector3 class.  i dont want accessor methods.  i know python can do
> this, but it's been a long time since I used it and am unsuccessful in
> my googling and docreading.  a little help please?

Nope, python can't do this. 

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


Re: in place-ness of list.append

2007-02-05 Thread Kent Johnson
Bart Van Loon wrote:
> Hi all,
> 
> I would like to find out of a good way to append an element to a list
> without chaing that list in place, like the builtin list.append() does.
> 
> currently, I am using the following (for a list of integers, but it
> could be anything, really)
> 
> #--
> def addnumber(alist, num):
> """ work around the inplace-ness of .append """ 
> mylist = alist[:]
> mylist.append(num)
> return mylist
> #--

Use + :

In [1]: a=[1,2]

In [2]: b=a+[3]

In [3]: a
Out[3]: [1, 2]

In [4]: b
Out[4]: [1, 2, 3]

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


Re: in place-ness of list.append

2007-02-05 Thread Robin Becker
Bart Van Loon wrote:
> Hi all,
> 
...
> 
> #--
> def addnumber(alist, num):
> """ work around the inplace-ness of .append """ 
> mylist = alist[:]
> mylist.append(num)
> return mylist
> #--
> 
> and I am wondering if this is good practice or not.
> 
> any advice on this matter?
...

would it not be simpler to just use

. alist+[num].

where you need it? Seems more natural than

def addnumber(alist,num):
return alist+[num]

and then

..addnumber(alist,num)..

-- 
Robin Becker

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


Re: Python design project

2007-02-05 Thread solrick51
I think I need to explain the things better I think, so I do;

First answering the questions above; I think i have to explain the
project more.

With type I mean; typography/fonts/characters.. For my final exam I
created the idea to treath fonts as a living organisms.
There for I want to create with the help of somebody, a little program
were i can import vector based fonts, and when they are imported they
"turn alive"
By turn alive I mean; they move random over the work area, opacity
changing, changing of size/color, merge together ans some more things,
little fonts changing.

Because my python skills are zero, I'm looking for a partner which can
help me. I'm working On mac, but windows is not a problem.

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


Re: in place-ness of list.append

2007-02-05 Thread Bart Van Loon
It was Mon, 05 Feb 2007 11:00:50 GMT, when Kent Johnson wrote:
> Bart Van Loon wrote:
>> Hi all,
>> 
>> I would like to find out of a good way to append an element to a list
>> without chaing that list in place, like the builtin list.append() does.
>> 
>> currently, I am using the following (for a list of integers, but it
>> could be anything, really)
>> 
>> #--
>> def addnumber(alist, num):
>> """ work around the inplace-ness of .append """ 
>> mylist = alist[:]
>> mylist.append(num)
>> return mylist
>> #--
>
> Use + :
>
> In [1]: a=[1,2]
>
> In [2]: b=a+[3]
>
> In [3]: a
> Out[3]: [1, 2]
>
> In [4]: b
> Out[4]: [1, 2, 3]

should have known that...

thanks for you fast response!

-- 
regards,
BBBart

   "Who can fathom the feminine mind?" -Calvin "I like `em anyway" -Hobbes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting str object

2007-02-05 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:

> I want to have a str with custom methods, but I have this problem:
> 
> class myStr(str):
> def hello(self):
> return 'hello '+self
> 
> s=myStr('world')
> print s.hello() # prints 'hello world'
> s=s.upper()
> print s.hello() # expected to print 'hello WORLD', but s is no longer
> myStr, it's a regular str!
> 
> What can I do?

Return a `myStr` instance instead of a regular `str`:

def hello(self):
return myStr('hello ' + self)

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Decimating Excel files

2007-02-05 Thread Arnd
On 5 Feb., 10:53, greg <[EMAIL PROTECTED]> wrote:

> Interesting. But does this mean that "duplicating" is
> actually from the wrong root?

by definition: roots are never wrong ;)
But indeed, you're right, one has to look at the root (eg connected
verb) to understand the Numeralia they used:
The number 2 has Numeralia duo, secundus, bini and bis:

duo + plicare (=to fold): Cardinalia (how much? ->n-fold)

> And also we have  "bifurcation",

yes, or eg "bisection" (from "bis"):  Multiplicativa (how many times?)
To complete the story:
"binary" (from "bini"): Distributiva (how much each time?, to build
groups or distributions)
"second" (from "secundus"): Ordinalia (which? -> the 2nd, the 3rd etc)

Arnd (I hated Latin)


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


Re: in place-ness of list.append

2007-02-05 Thread Bart Van Loon
It was Mon, 5 Feb 2007 05:01:28 -0600, when [EMAIL PROTECTED] wrote:
>
> Bart> #--
> Bart> def addnumber(alist, num):
> Bart> """ work around the inplace-ness of .append """ 
> Bart> mylist = alist[:]
> Bart> mylist.append(num)
> Bart> return mylist
> Bart> #--
>
> Bart> and I am wondering if this is good practice or not.
>
> Bart> any advice on this matter?
>
> Such an operation will be O(N**2), 

why is that?

> and thus expensive if performed frequently on lists of moderate
> length.  I've never been tempted to do this.  Can you say a little
> about why you'd want to do this?  Knowing that, perhaps someone here
> can point you in a more Pythonic direction.

I am building a binary tree where each node is a list. the two children
are the parent list + 1 and the parent list + 2.

I am using it recursively as such:

#---
def makescoretree(scorelist):
""" generates the Tree of possible scores """
if waves(scorelist) >= MAXWAVES:
return []
return Scoretree(scorelist, 
 makescoretree(addnumber(scorelist, 1)),
 makescoretree(addnumber(scorelist, 6)))
#---

but now I found out that I can do this easily like

#---
def makescoretree(scorelist):
""" generates the Tree of possible scores """
if waves(scorelist) >= MAXWAVES:
return []
return Scoretree(scorelist, 
 makescoretree(scorelist + [1]),
 makescoretree(scorelist + [6]))
#---

-- 
regards,
BBBart

   "Who can fathom the feminine mind?" -Calvin "I like `em anyway" -Hobbes
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inheriting str object

2007-02-05 Thread Benjamin Niemann
Marc 'BlackJack' Rintsch wrote:

> In <[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] wrote:
> 
>> I want to have a str with custom methods, but I have this problem:
>> 
>> class myStr(str):
>> def hello(self):
>> return 'hello '+self
>> 
>> s=myStr('world')
>> print s.hello() # prints 'hello world'
>> s=s.upper()
>> print s.hello() # expected to print 'hello WORLD', but s is no longer
>> myStr, it's a regular str!
>> 
>> What can I do?
> 
> Return a `myStr` instance instead of a regular `str`:
> 
> def hello(self):
> return myStr('hello ' + self)

yes, but the 'upper' method is the problem here.
So you'd have to override all string methods, like

class myStr(str):
...

def upper(self):
return myStr(str.upper(self))


And I'm not sure, if it then works in the intended way...
What you are probably looking for, is to extend the 'str' class itself, so
every str instance has your added functionality.
Don't know, if this is possible at all, but usually it's not a good idea to
mess with the bowels of Python unless you have some greater surgical
skills.


HTH

-- 
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://pink.odahoda.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question

2007-02-05 Thread Simon Brunning
On 2/4/07, Magdy Sanad <[EMAIL PROTECTED]> wrote:
> I have certain data in the default file format ( GADGET ) .
>
> I Will be appreciated if you guide me to read these data
>
> under Python ?

You'd probably get more help if you told people what GADGET is. ;-)
Are you talking about this - ?

If so, then a quick Google doesn't reveal anything pre-built. But
then, "gadget" is a pretty appalling product name to Google for - *so*
many hits for that word!

There's a run-down on the file format here, though -
,
so you might be able to write your own using the struct module.

Good luck!

-- 
Cheers,
Simon B
[EMAIL PROTECTED]
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python references

2007-02-05 Thread Rob Wolfe

[EMAIL PROTECTED] wrote:
> >>> from Numeric import zeros
> >>> p=zeros(3)
> >>> p
> array([0,0,0])
> >>> p[0]
> 0
> >>> x=p[0]

`x' is now a reference to immutable integer object
with value 0, not to first element of array `p'

> >>> x=10

now `x' is a reference to immutable integer object
with value 10, array doesn't change

> >>> p
> array([0,0,0]) #actual behavior
> #array([10,0,0]) #desired behavior
>
> I want x to be a C++-esque reference to p[0] for convenience in a
> vector3 class.  i dont want accessor methods.  i know python can do
> this, but it's been a long time since I used it and am unsuccessful in
> my googling and docreading.  a little help please?

You can have such a reference to mutable objects.
Consider this:

>>> p = [[0,0,0], [0,0,0]]
>>> x = p[0]# reference to mutable list object
>>> x[0] = 10
>>> p
[[10, 0, 0], [0, 0, 0]]

--
HTH,
Rob

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


Re: Inheriting str object

2007-02-05 Thread Virgil Dupras
On Feb 5, 5:48 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I want to have a str with custom methods, but I have this problem:
>
> class myStr(str):
> def hello(self):
> return 'hello '+self
>
> s=myStr('world')
> print s.hello() # prints 'hello world'
> s=s.upper()
> print s.hello() # expected to print 'hello WORLD', but s is no longer
> myStr, it's a regular str!
>
> What can I do?

To prevent operations with your myStr class to return a simple str
instance, you will have to override pretty much all str method, as
well as magic methods, such as __add__, __radd__ etc.. Major pain in
perspective. You might want to reconsider you developing strategy.

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


C parsing fun

2007-02-05 Thread karoly.kiripolszky
Helo ppl!

At the job I was given the task to make a script to analyze C++ code
based on concepts my boss had. To do this I needed to represent C++
code structure in Python somehow. I read the docs for Yapps, pyparsing
and other stuff like those, then I came up with a very simple idea. I
realized that bracketed code is almost like a Python list, except I
have to replace curly brackets with squared ones and surround the
remaining stuff with quotes. This process invokes no recursion or node
objects, only pure string manipulations so I believe it's really fast.
Finally I can get the resulting list by calling eval() with the
string.

For example when I need to parse a class definition, I only need to
look for a list item containing the pattern "*class*", and the next
item will be the contents of the class as another list.

You can grab the code at:

http://kiri.csing.hu/stack/python/bloppy-0.1.zip

(test script [test.py] included)

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


Re: C parsing fun

2007-02-05 Thread karoly.kiripolszky
and the great thing is that the algorithm can be used with any
language that structures the code with brackets, like PHP and many
others.

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


comp.lang.python Podcast - URL Change

2007-02-05 Thread [EMAIL PROTECTED]
Unfortunately I have had to change domains. The feeds for the podcast
are updated and available at:
http://www.latedecember.co.uk/sites/pythonpod/

Thanks,
Davy Mitchell

http://www.latedecember.co.uk/sites/personal/davy/

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


Re: subprocess stdin encoding

2007-02-05 Thread Thinker
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

yc wrote:
> I have a encoding problem during using of subprocess. The input is
> a string with UTF-8 encoding.
>
> the code is:
>
> tokenize =
> subprocess.Popen(tok_command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,close_fds=True,shell=True)
>
>
> (tokenized_text,errs) = tokenize.communicate(t)
>
> the error is: File "/usr/local/python/lib/python2.5/subprocess.py",
> line 651, in communicate return self._communicate(input) File
> "/usr/local/python/lib/python2.5/subprocess.py", line 1115, in
> _communicate bytes_written = os.write(self.stdin.fileno(),
> input[:512]) UnicodeEncodeError: 'ascii' codec can't encode
> character u'\xa9' in position 204: ordinal not in range(128)
>
>
> How I change the default encoding from "ascii" to "utf-8"?
>
> Ying Chen
>
find code like

def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
if 0:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]

in site.py . and change if 0: to if 1: to enable string encoding.
Now, you can execute python interpreter with LC_CTYPE='UTF-8'.


- --
Thinker Li - [EMAIL PROTECTED] [EMAIL PROTECTED]
http://heaven.branda.to/~thinker/GinGin_CGI.py
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (FreeBSD)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFxykX1LDUVnWfY8gRAseRAKCjAksq22bD2YoOt5IEOIcwOB2KiQCbBvvw
lEccSfEaeOhzAUbvulnDoDk=
=y4Jj
-END PGP SIGNATURE-

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

Re: C parsing fun

2007-02-05 Thread Szabolcs Nagy
> based on concepts my boss had. To do this I needed to represent C++
> code structure in Python somehow. I read the docs for Yapps, pyparsing
> and other stuff like those, then I came up with a very simple idea. I
> realized that bracketed code is almost like a Python list, except I
> have to replace curly brackets with squared ones and surround the
> remaining stuff with quotes. This process invokes no recursion or node

yes that's a nice solution
sometimes it's not enough though (won't work on code obfuscated with
macros)

anyway if you need something more sophisticated then i'd recommend
gccxml or it's python binding:

http://www.language-binding.net/pygccxml/pygccxml.html

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


Re: C parsing fun

2007-02-05 Thread Károly Kiripolszky
Thx for responding, Szabolcs! I've already tried that, but couldn't
manage to get it to work. The source I tried to parse is a huge MSVC
7.1 solution containing about 38 projects, and I believe the code is
so complex that it has too many different dependencies and GCC just
can't handle them. Btw I'm not deeply familiar with C++ compilers, so
maybe it was because of compiler misconfiguration, but I really don't
know...

Szabolcs Nagy írta:
> > based on concepts my boss had. To do this I needed to represent C++
> > code structure in Python somehow. I read the docs for Yapps, pyparsing
> > and other stuff like those, then I came up with a very simple idea. I
> > realized that bracketed code is almost like a Python list, except I
> > have to replace curly brackets with squared ones and surround the
> > remaining stuff with quotes. This process invokes no recursion or node
>
> yes that's a nice solution
> sometimes it's not enough though (won't work on code obfuscated with
> macros)
>
> anyway if you need something more sophisticated then i'd recommend
> gccxml or it's python binding:
>
> http://www.language-binding.net/pygccxml/pygccxml.html

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

Re: confused about resizing array in Python

2007-02-05 Thread Neil Cerutti
On 2007-02-04, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> How about the traditional programming languages like C, Pascal
>> or C++?
>
> For a start they don't have a built in list type.  C and Pascal
> don't even have one in the standard library.  C++ has STL
> vectors and if you, the programmer, decide to store pointers in
> it instead of structures or objects then you have something
> like Python's list type.

You need to store some form of smart pointer (rather than a bare
pointer) in C++ standard containers in order to avoid heart, head
and stomach aches. A reference counted pointer type will come
fairly close to Python semantics.

-- 
Neil Cerutti
Eddie Robinson is about one word: winning and losing. --Eddie Robinson's agent
Paul Collier
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HELP NEEDED ... Regd. Regular expressions PyQt

2007-02-05 Thread Neil Cerutti
On 2007-02-03, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I am trying to work out a regular expression in a PyQt
> environment for time in hh:mm:ss format. Any suggestions?

After you find your time in hh:mm:ss format, be sure to check out
time.strptime for a quick conversion.

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


Re: in place-ness of list.append

2007-02-05 Thread skip
> "Bart" == Bart Van Loon <[EMAIL PROTECTED]> writes:

>> Such an operation will be O(N**2), 

Bart> why is that?

The a[:] operation makes a copy of a (as will the x = a + [n] idiom).

Bart> I am building a binary tree where each node is a list. the two
Bart> children are the parent list + 1 and the parent list + 2.

You might consider creating each node as

left = [parent, 1]
right = [parent, 2]

You thus wind up with a nested set of two-element nodes, e.g.:

[]
 [[], 1]   [[], 2]
 [[[], 1], 1]   [[[], 1], 2]   [[[], 2], 1]   [[[], 2], 2] 

where the left-hand side of each node is just a reference to the parent
node.  Once the tree is built if you can flatten the resulting node lists to
generate lists which are more efficient for direct element access.

Again, this all depends on how big your trees are, what you do with them
once they are built, if you need to search the tree while building the tree,
etc.

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


Re: Why less emphasis on private data?

2007-02-05 Thread Steve Holden
Paul Boddie wrote:
> Paul Rubin wrote:
>> Right, the problem is if those methods start changing the "private"
>> variable.  I should have been more explicit about that.
>>
>> class A:
>>def __init__(self):
>>   self.__x = 3
>>def foo(self):
>>   return self.__x
>>
>> class B(A): pass
>>
>> class A(B):
>>def bar(self):
>>  self.__x = 5   # clobbers private variable of earlier class named A
> 
> Has this ever been reported as a bug in Python? I could imagine more
> sophisticated "name mangling": something to do with the identity of the
> class might be sufficient, although that would make the tolerated
> "subversive" access to private attributes rather difficult.
> 
> Paul
> 
It would also force the mangling to take place at run-time, which would 
probably affect efficiently pretty adversely (thinks: should really 
check that mangling is a static mechanism before posting this).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

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


Re: C parsing fun

2007-02-05 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>,
karoly.kiripolszky wrote:

> and the great thing is that the algorithm can be used with any
> language that structures the code with brackets, like PHP and many
> others.

But it fails if brackets appear in comments or literal strings.

Ciao,
Marc 'BlackJack' Rintsch

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


Re: Inheriting str object

2007-02-05 Thread BJörn Lindqvist
On 5 Feb 2007 02:48:08 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> I want to have a str with custom methods, but I have this problem:
>
> class myStr(str):
> def hello(self):
> return 'hello '+self
>
> s=myStr('world')
> print s.hello() # prints 'hello world'
> s=s.upper()
> print s.hello() # expected to print 'hello WORLD', but s is no longer
> myStr, it's a regular str!

You could use the proxy pattern:

class GreeterString(object):
def __init__(self, str):
self.proxy = str

def hello(self):
return 'hello ' + self.proxy

def __getattr__(self, attr):
if attr in dir(self.proxy):
proxy_attr = getattr(self.proxy, attr)
if callable(proxy_attr):
def wrapper(*args, **kwargs):
return self.__class__(proxy_attr())
return wrapper

def __str__(self):
return self.proxy.__str__()


gs = GreeterString('world')
print gs.upper().hello()

Magic methods has to be overridden manually, I think.

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in place-ness of list.append

2007-02-05 Thread BJörn Lindqvist
On 2/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Bart> #--
> Bart> def addnumber(alist, num):
> Bart> """ work around the inplace-ness of .append """
> Bart> mylist = alist[:]
> Bart> mylist.append(num)
> Bart> return mylist
> Bart> #--
>
> Such an operation will be O(N**2), and thus expensive if performed
> frequently on lists of moderate length.  I've never been tempted to do this.

How can that be? Making a copy of a list is O(N), isn't it?

-- 
mvh Björn
-- 
http://mail.python.org/mailman/listinfo/python-list


Watch folder for new file and execute extern program

2007-02-05 Thread Michael Bo
Hi.
Can anyone guide me on how to minitor a folder for new files? And when
they appear I need to run and externe program with the file just
created (buy a 3rd program).
- Michael Bo

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


Re: wxPython: TextCtrl delayed update when using TE_RICH(2)

2007-02-05 Thread Chris Mellon
On 2/4/07, jean-michel bain-cornu <[EMAIL PROTECTED]> wrote:
> Hi,
> > def Execute(self, evt):
> > print "Start query"
> > time.sleep(5)
> >
> > The "Start query" message should show in the *messages* box when I
> > press the button. Instead, it shows only after the time.sleep(5)
> > delay.
> >
> > If I don't use the wx.TE_RICH / wx.TE_RICH2 style on *messages*, the
> > text shows before the time.sleep(5)
>
> For this kind of stuff, I'd try to put "self.out.WriteText(string)" in
> some 'Idle' event, which avoid to fall in focus loops or other objects
> events management problems not easy to solve.
>

This doesn't have anything to do with focus loops or otherwise, it's
because the OP isn't familiar with event based programming.

You're performing a long-running task which is preventing the event
loop from processing, so your text isn't updating and your application
is unresponsive. You need to rewrite your task - either do everything
asynchronously, or use a threaded approach. If you use the thread
approach, be sure to not call the updates directly, you can use the
wx.CallAfter mechanism to call gui functions in a threadsafe manner.

There is a lot of information about this on the wxPython wiki and in
the archives of the wxpython-users ML.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: C parsing fun

2007-02-05 Thread Károly Kiripolszky

Marc 'BlackJack' Rintsch írta:
> In <[EMAIL PROTECTED]>,
> karoly.kiripolszky wrote:
>
> > and the great thing is that the algorithm can be used with any
> > language that structures the code with brackets, like PHP and many
> > others.
>
> But it fails if brackets appear in comments or literal strings.
>
> Ciao,
>   Marc 'BlackJack' Rintsch

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

Re: in place-ness of list.append

2007-02-05 Thread skip
> "BJörn" == BJörn Lindqvist <[EMAIL PROTECTED]> writes:

BJörn> On 2/5/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>> 
Bart> #--
Bart> def addnumber(alist, num):
Bart> """ work around the inplace-ness of .append """
Bart> mylist = alist[:]
Bart> mylist.append(num)
Bart> return mylist
Bart> #--
>> 
>> Such an operation will be O(N**2), and thus expensive if performed
>> frequently on lists of moderate length.  I've never been tempted to
>> do this.

BJörn> How can that be? Making a copy of a list is O(N), isn't it?

Yes, not enough sleep under my belt or caffeine in my system (*) when I
wrote those replies.  addnumber is O(N).  If you are building a binary tree
of M elements you're going to wind up with an O(N*M) or O(N**2) cost to
build the tree though.  Actually, I think in the case of building the binary
tree you wind up with an O(N*log N) algorithm since you don't have to
traverse the entire set of nodes you've already built to find where to
insert the next one.

Skip

(*) It really sucks when someone's car alarm goes off at 4AM with no visual
indication when it's about -5F outside and you have to actually go outside
to check and make sure it's not your car (only to find out it's the car
directly behind yours)...

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


Re: C parsing fun

2007-02-05 Thread Károly Kiripolszky
You're right, thank you for the comment! I will look after how to
avoid this.

Marc 'BlackJack' Rintsch írta:
> In <[EMAIL PROTECTED]>,
> karoly.kiripolszky wrote:
>
> > and the great thing is that the algorithm can be used with any
> > language that structures the code with brackets, like PHP and many
> > others.
>
> But it fails if brackets appear in comments or literal strings.
>
> Ciao,
>   Marc 'BlackJack' Rintsch

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

Python 3.0 (Was: when will python 2.5 take in mainstream?)

2007-02-05 Thread Steven Bethard
Laurent Pointal wrote:
> For Python 3.0, AFAIK its a big rewrite and developers know that it will
> be uncompatible in large parts with existing code.

Wrong on both counts. ;-) Python 3.0 is not a rewrite. It's based on the 
same code base as the 2.X line, but with a lot of the old deprecated 
things removed. And, while Python 3.0 is allowing itself to break 
backwards compatibility, at least that the Python level, it should be 
largely compatible with the 2.X line. There will be some breakages, but 
(1) they shouldn't be too extensive and (2) there will be utilities to 
help you update your code. In many cases, it will be possible to write 
code that works in both Python 2.X and 3.0.

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


Re: Watch folder for new file and execute extern program

2007-02-05 Thread Diez B. Roggisch
Michael Bo wrote:

> Hi.
> Can anyone guide me on how to minitor a folder for new files? And when
> they appear I need to run and externe program with the file just
> created (buy a 3rd program).

This is OS-dependend. On Linux, FAM/GAM-server come to mind.

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


Re: subprocess stdin encoding

2007-02-05 Thread Jean-Paul Calderone
On Mon, 05 Feb 2007 20:54:48 +0800, Thinker <[EMAIL PROTECTED]> wrote:
> [snip]
>
>in site.py . and change if 0: to if 1: to enable string encoding.
>Now, you can execute python interpreter with LC_CTYPE='UTF-8'.
>

While this is sort of a correct answer to the question asked, it
isn't really a correct answer overall.  I hope no one actually
goes off and does this.  Doing so will result in completely
unportable code with very difficult to track down bugs.

Instead, use the str and unicode methods "encode" and "decode".

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


Re: subprocess stdin encoding

2007-02-05 Thread Jean-Paul Calderone
On 4 Feb 2007 23:10:29 -0800, yc <[EMAIL PROTECTED]> wrote:
>I have a encoding problem during using of subprocess. The input is a
>string with UTF-8 encoding.
>
>the code is:
>
>tokenize =
>subprocess.Popen(tok_command,stdin=subprocess.PIPE,stdout=subprocess.PIPE,close_fds=True,shell=True)
>
>(tokenized_text,errs) = tokenize.communicate(t)
>
>the error is:
>  File "/usr/local/python/lib/python2.5/subprocess.py", line 651, in
>communicate
>return self._communicate(input)
>  File "/usr/local/python/lib/python2.5/subprocess.py", line 1115, in
>_communicate
>bytes_written = os.write(self.stdin.fileno(), input[:512])
>UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in
>position 204: ordinal not in range(128)
>
>
>How I change the default encoding from "ascii" to "utf-8"?

You don't need to change the default encoding.  You just need to encode
the unicode string you are sending to the child process.  Try:

tokenized_text, errs = tokenize.communicate(t.encode('utf-8'))

Jean-Paul

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


Re: when will python 2.5 take in mainstream?

2007-02-05 Thread Jean-Paul Calderone
On Mon, 05 Feb 2007 10:19:26 +0100, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] a écrit :
>> When they have to ...
>>
>> One of the big things about Python is that its penetration slows it
>> down. There's more legacy code and interdependant systems around now
>> that Python is more successful and more mature.
>>
>> Here's a thought -- perhaps it would be worth having some good ways to
>> interact with Python from Python. Suppose you have some 2.4 code
>> someplace, interacting with your mysqldb or whatever, and you don't
>> want to rewrite it. So long as you have some kind of object broker,
>> you could (plausibly) leave your 2.4 apps running with the old
>> interpreter, but wrap them for Python 2.5 and use that in your new
>> development.
>
>KISS please.
>

Requiring change is simpler than not requiring change?  Okay, perhaps
you could make a case, but it's far from obvious this is always true.

>> Ditto 3.0.
>>
>> Rather than having to re-write every interacting component, maybe it
>> could be straightforward to all Python2.4 from Python2.5 to execute
>> particular library calls. I'm not an expert, I don't know how you'd
>> build such a system, but I do know that re-writing stuff is a real
>> pain.
>
>Most of Python 2.4 source code is compatible with Python 2.5. Problems
>come with native compiled modules, you must have those for you 2.X
>Python version - some times just a compilation is enough.

Do you have any data to actually back this assertion up?  I have plenty
of evidence to the contrary.

>
>For Python 3.0, AFAIK its a big rewrite and developers know that it will
>be uncompatible in large parts with existing code.
>

How does knowing that it will not be compatible have any bearing on the
arguments made by the original poster?  It doesn't change anything, as
far as I can tell.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python 3.0 (Was: when will python 2.5 take in mainstream?)

2007-02-05 Thread Jean-Paul Calderone
On Mon, 05 Feb 2007 07:01:26 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote:
>Laurent Pointal wrote:
>> For Python 3.0, AFAIK its a big rewrite and developers know that it will
>> be uncompatible in large parts with existing code.
>
>Wrong on both counts. ;-) Python 3.0 is not a rewrite. It's based on the
>same code base as the 2.X line, but with a lot of the old deprecated
>things removed. And, while Python 3.0 is allowing itself to break
>backwards compatibility, at least that the Python level, it should be
>largely compatible with the 2.X line. There will be some breakages, but
>(1) they shouldn't be too extensive and (2) there will be utilities to
>help you update your code. In many cases, it will be possible to write
>code that works in both Python 2.X and 3.0.

Hopefully that will be the case.  Misunderstandings aren't too surprising
though.  Until recently, it didn't appear that this would be the case at
all.  Of course, your statement isn't entirely accurate either.  For example,
many things which _aren't_ deprecated are being removed as well.  Some of
them may be deprecated in 2.x releases which haven't happened yet, but that
remains to be seen.  And 3.0 won't be "largely compatible" with any _existing_
2.x release, but hopefully a future 2.x release will add a usable transition
path.

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


Re: C parsing fun

2007-02-05 Thread Claudio Grondi
Károly Kiripolszky wrote:
> You're right, thank you for the comment! I will look after how to
> avoid this.
And after you have resolved this 'small' ;-) detail you will probably 
notice, that some full functional and in wide use being parser have 
still trouble with this ...

Claudio
> 
> Marc 'BlackJack' Rintsch írta:
>> In <[EMAIL PROTECTED]>,
>> karoly.kiripolszky wrote:
>>
>>> and the great thing is that the algorithm can be used with any
>>> language that structures the code with brackets, like PHP and many
>>> others.
>> But it fails if brackets appear in comments or literal strings.
>>
>> Ciao,
>>  Marc 'BlackJack' Rintsch
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling J from Python

2007-02-05 Thread Gosi
It is quite easy to call J from Python

http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e

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


Re: C parsing fun

2007-02-05 Thread Károly Kiripolszky
I've found a brute-force solution. In the preprocessing phase I simply
strip out the comments (things inside comments won't appear in the
result) and replace curly brackets with these symbols: #::OPEN::# and
#::CLOSE::#. After parsing I convert them back. In fact I can disclude
commented lines from the analyzis as I only have to cope with
production code.

Claudio Grondi írta:
> Károly Kiripolszky wrote:
> > You're right, thank you for the comment! I will look after how to
> > avoid this.
> And after you have resolved this 'small' ;-) detail you will probably
> notice, that some full functional and in wide use being parser have
> still trouble with this ...
>
> Claudio
> >
> > Marc 'BlackJack' Rintsch írta:
> >> In <[EMAIL PROTECTED]>,
> >> karoly.kiripolszky wrote:
> >>
> >>> and the great thing is that the algorithm can be used with any
> >>> language that structures the code with brackets, like PHP and many
> >>> others.
> >> But it fails if brackets appear in comments or literal strings.
> >>
> >> Ciao,
> >>Marc 'BlackJack' Rintsch
> >

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


Re: C parsing fun

2007-02-05 Thread Károly Kiripolszky
http://kiri.csing.hu/stack/python/bloppy-0.2.zip

Test data now also contains brackets in literal strings.

Claudio Grondi írta:
> Károly Kiripolszky wrote:
> > You're right, thank you for the comment! I will look after how to
> > avoid this.
> And after you have resolved this 'small' ;-) detail you will probably
> notice, that some full functional and in wide use being parser have
> still trouble with this ...
>
> Claudio
> >
> > Marc 'BlackJack' Rintsch írta:
> >> In <[EMAIL PROTECTED]>,
> >> karoly.kiripolszky wrote:
> >>
> >>> and the great thing is that the algorithm can be used with any
> >>> language that structures the code with brackets, like PHP and many
> >>> others.
> >> But it fails if brackets appear in comments or literal strings.
> >>
> >> Ciao,
> >>Marc 'BlackJack' Rintsch
> >

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


Re: Calling J from Python

2007-02-05 Thread Diez B. Roggisch
Gosi wrote:

> It is quite easy to call J from Python
> 
>
http://groups.google.com/group/J-Programming/browse_thread/thread/5e84b75667f5f64e

What is J, and why should we care?

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


Re: Why less emphasis on private data?

2007-02-05 Thread Bart Ogryczak
On Jan 7, 1:07 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Coming from a C++ / C# background, the lack of emphasis on private data
> seems weird to me. I've often found wrapping private data useful to
> prevent bugs and enforce error checking..
>
> It appears to me (perhaps wrongly) that Python prefers to leave class
> data public.  What is the logic behind that choice?

Often it´s a question of efficiency. Function calls in Python are
bloody slow. There is no "inline" directive, since it´s intepreted,
not compiled. Eg. consider code like that:

class MyWhatever:
  ...
  def getSomeAttr(self):
   return self._someAttr
  def getSomeOtherAttr(self):
return self._someOtherAttr

[x.getSomeAttr() for x in listOfMyWhatevers if x.getSomeOtherAttr() ==
'whatever']

You´d get it running hundreds times faster doing it the "wrong" way:

[x._someAttr for x in listOfMyWhatevers if x._someOtherAttr ==
'whatever']



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


Re: CTypes

2007-02-05 Thread Chris Mellon
On 2/4/07, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 4 Feb 2007 05:16:27 -0800, "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
> > script file 'test.py' and a DLL 'AutoIt3X.DLL' in the same folder, how
> > could I load it? The tutorial did something like dll=windll.kernel32,
> > which I understands loads the kernel but I don't see how I could apply
> > that to load AutoIt3X. Thanks in advanced.
>
> I've not used ctypes, but from all the examples I've seen
>
> What happens if you specify:
>
> dll = ctypes.windll.AutoIt3X
>
> I think ctypes uses a getattr() trap to extract the dll name from
> the invocation, then passes that to the Windows library loading code.
> --

This is indeed what ctypes does. There's also a LoadLibrary static
method of windll.cdll etc that you can use to get it explicitly (like
if you need to load a DLL not on your path).

dll = ctypes.windll.LoadLibrary(r"C:\AutoIT#x.dll")
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 (Was: when will python 2.5 take in mainstream?)

2007-02-05 Thread Laurent Pointal
Steven Bethard a écrit :
> Laurent Pointal wrote:
>> For Python 3.0, AFAIK its a big rewrite and developers know that it will
>> be uncompatible in large parts with existing code.
> 
> Wrong on both counts. ;-) Python 3.0 is not a rewrite. It's based on the
> same code base as the 2.X line, but with a lot of the old deprecated
> things removed. And, while Python 3.0 is allowing itself to break
> backwards compatibility, at least that the Python level, it should be
> largely compatible with the 2.X line. There will be some breakages, but
> (1) they shouldn't be too extensive and (2) there will be utilities to
> help you update your code. In many cases, it will be possible to write
> code that works in both Python 2.X and 3.0.
> 
> STeVe

Hum my brain just mix 3 and 3000. Sorry, just a factor 1000.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Watch folder for new file and execute extern program

2007-02-05 Thread Larry Bates
Michael Bo wrote:
> Hi.
> Can anyone guide me on how to minitor a folder for new files? And when
> they appear I need to run and externe program with the file just
> created (buy a 3rd program).
> - Michael Bo
> 
Here is a link that should help.

http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html

BTW-It helps us out here if you let us know what platform you
are running on (e.g. Windows, Linux, Mac, etc.).

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


Re: Why less emphasis on private data?

2007-02-05 Thread Paul Rubin
Steve Holden <[EMAIL PROTECTED]> writes:
> >> class A(B):
> >>def bar(self):
> >>  self.__x = 5   # clobbers private variable of earlier class named A
> > Has this ever been reported as a bug in Python? I could imagine more
> > sophisticated "name mangling": something to do with the identity of the
> > class might be sufficient, although that would make the tolerated
> > "subversive" access to private attributes rather difficult.
> >
> It would also force the mangling to take place at run-time, which
> would probably affect efficiently pretty adversely (thinks: should
> really check that mangling is a static mechanism before posting this).

I think it could still be done statically.  For example, the mangling
could include a random number created at compile time when the class
definition is compiled, that would also get stored in the class object.

I guess there are other ways to create classes than class statements
and those would have to be addressed too.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython: TextCtrl delayed update when using TE_RICH(2)

2007-02-05 Thread jean-michel bain-cornu
>> For this kind of stuff, I'd try to put "self.out.WriteText(string)" in
>> some 'Idle' event, which avoid to fall in focus loops or other objects
>> events management problems not easy to solve.
>>
> 
> This doesn't have anything to do with focus loops or otherwise, it's
> because the OP isn't familiar with event based programming.
> 
> You're performing a long-running task which is preventing the event
> loop from processing, so your text isn't updating and your application
> is unresponsive. You need to rewrite your task - either do everything
> asynchronously, or use a threaded approach. If you use the thread
> approach, be sure to not call the updates directly, you can use the
> wx.CallAfter mechanism to call gui functions in a threadsafe manner.

So it is an event management problem.
The event loop is not yet finished when the program want to display 
something, potentially initiating a new event loop.

If you don't want to bother with threads, the idle event approach is not 
so bad. Put something to display in a buffer, and display it only one 
time the gui have nothing else to do.
I use it every time I can, and it's very safe and easy to do. 
Furthermore, you can still step into the program with a debugger, which 
can be tricky if the program uses threads (I'd say impossible, but I 
didn't try in fact).

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


Re: in place-ness of list.append

2007-02-05 Thread Alexander Schmolck
[EMAIL PROTECTED] writes:

> > "Bart" == Bart Van Loon <[EMAIL PROTECTED]> writes:
> 
> >> Such an operation will be O(N**2), 
> 
> Bart> why is that?
> 
> The a[:] operation makes a copy of a (as will the x = a + [n] idiom).

I'm pretty confident append itself (and a+[n]) are linear in N=len(a) since
the copying is linear and appending a single item in-place is constant time
(OTOH calling append N times to construct a list or tree of length N from
scratch is quadratic; I assume that is what you meant and also what the OP
seems to want to use it for, so not doing it this way is sound advice).
 
> Bart> I am building a binary tree where each node is a list. the two
> Bart> children are the parent list + 1 and the parent list + 2.
> 
> You might consider creating each node as
> 
> left = [parent, 1]
> right = [parent, 2]

Or, if you don't need to mutate the tree ``left = (parent, 1)``. Tuples ought
to have a little less memory overhead.
 
'as
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: in place-ness of list.append

2007-02-05 Thread Alexander Schmolck
Alexander Schmolck <[EMAIL PROTECTED]> writes:

> [EMAIL PROTECTED] writes:
> 
> > > "Bart" == Bart Van Loon <[EMAIL PROTECTED]> writes:
> > 
> > >> Such an operation will be O(N**2), 
> > 
> > Bart> why is that?
> > 
> > The a[:] operation makes a copy of a (as will the x = a + [n] idiom).
> 
> I'm pretty confident append itself (and a+[n]) are linear in N=len(a) since

Sorry -- I just see that I missed your other post.

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


[no subject]

2007-02-05 Thread Zahid Ahmadzai

HI THERE

I NEED HELP WITH THE FOLLOWING EXERSISE CAN YOU PLEASE HELP IF YOU CAN.

PLEASE SEND ME THE CODE ON E-MAIL

MANY THANKS







For presentation to your tutor during your scheduled tutorial in the week
commencing 12 February.

I decided that it might be a good idea to create a suitable program to test
sorting algorithms using simple integer data. Although our student record
program is realistic in terms of the data it uses, integers have the
advantage that they can be generated automatically (using the
*rand()*function to return a random integer). To use
*rand()* you need to *#include *.

An outline design for a program would be much the same as the initial design
for the student record program:

  - get the data
  - sort the data
  - display the results

In this case the data will be 'generated' using the random number function
(instead of reading data from a file). We need to clarify a little bit how
the user interface would appear. As far as I am concerned, I have decide
that the program will run interactively (keyboard input and display output)
as follows:
How many numbers to sort? 50
Numbers generated ...
41 467 334 500 169 724 478 358 962 464 705 145 281 827 961 491 995 942 827
436 391 604 902 153 292 382 421 716 718 895 447 726 771 538 869 912 667 299
35 894 703 811 322 333 673 664 141 711 253 868

After sorting ...
41 141 145 153 169 253 281 292 299 322 333 334 358 382 391 421 436 447 464
467 478 491 500 538 604 664 667 673 703 705 711 716 718 724 726 771 811 827
827 868 869 894 895 902 912 942 961 962 995

At the moment this only uses the bubble sort (as we have in the notes) and I
have arbitrarily decided to generate random numbers between 0 and 999. The
constant field width is obtained by using the *cout.width(4)* function call.


Using the following data type and prototypes:

typedef int intArray[];

void generate(intArray nums, int size, int low, int high);
//generates size random ints between low and high inclusive

void bubSort(intArray nums, int size);

void displayNums(intArray nums, int size);
//displays numbers nicely laid out
// in this case - of width 4 digits and 15 to a line

void display(int n);
//displays a single integer in a fieldwidth of 4 chars

bool notInOrder(int a, int b);
//returns true if a and b need swapping

and a *main()* function which has the following design:
void main()
{
  const int MAX_SIZE = 5000; // arbitrary
  int numbers[ MAX_SIZE ];
  int howMany;
  cout << "How many numbers to sort? " ;
  cin >> howMany;
  if ( howMany > MAX_SIZE )
 { howMany = MAX_SIZE; }
  generate( numbers, howMany, 0, 999 );
  cout << "Numbers generated..." << endl;
  displayNums( numbers, howMany );
  bubSort( numbers, howMany );
  cout << "After sorting..." << endl;
  displayNums( numbers, howMany );
}

Complete the program so that it behaves much as shown above.

Notes:

The bubble sort code is given in the notes (use the best version) - you need
to change it (very slightly) to work with an array of integers instead of an
array of students.

The function *generate()* is a bit tricky. Think about how to start with a
simple *stub* (i.e. don't worry initially about implementing the whole
functionality - just make some numbers using simple code that can be sorted.


The function *displayNums()* can also initially be implemented in a crude
form (i.e. a *stub*) and improved later.

Think carefully about how you test *generate()*.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: when will python 2.5 take in mainstream?

2007-02-05 Thread Laurent Pointal
Jean-Paul Calderone a écrit :
> On Mon, 05 Feb 2007 10:19:26 +0100, Laurent Pointal
> <[EMAIL PROTECTED]> wrote:
>> [EMAIL PROTECTED] a écrit :
>>> When they have to ...
>>>
>>> One of the big things about Python is that its penetration slows it
>>> down. There's more legacy code and interdependant systems around now
>>> that Python is more successful and more mature.
>>>
>>> Here's a thought -- perhaps it would be worth having some good ways to
>>> interact with Python from Python. Suppose you have some 2.4 code
>>> someplace, interacting with your mysqldb or whatever, and you don't
>>> want to rewrite it. So long as you have some kind of object broker,
>>> you could (plausibly) leave your 2.4 apps running with the old
>>> interpreter, but wrap them for Python 2.5 and use that in your new
>>> development.
>>
>> KISS please.
>>
> 
> Requiring change is simpler than not requiring change?  
> Okay, perhaps
> you could make a case, but it's far from obvious this is always true.
> 

IMHO trying to have a binary compatibility with older compiled modules
by maintaining an ad-hoc layer to switch between 2.4/2.5 engines make
Python code more complex. And more complex code have generally more
bugs. This is the reason for my KISS hope about Python.

Its simple to require changes, not so sure that doing these
modifications keep things simple. Maybe an internal Python hacker can
give us his advice on such a modification (ie. staying compatible with
legacy modules compiled for previous versions).

A+

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

Re: in place-ness of list.append

2007-02-05 Thread skip

as> I'm pretty confident append itself (and a+[n]) are linear in
as> N=len(a) ...

Yes, as I indicated in an earlier reply.  The overall construction of his
data structure would be O(N**2) or O(N*log N).  The latter is for binary
tree construction, but I didn't know what the OP was going to do with his
lists at the time I originally replied.

as> Or, if you don't need to mutate the tree ``left = (parent,
as> 1)``. Tuples ought to have a little less memory overhead.

Since at least 2.4, lists overallocate space for new entries proportional to
the current size of the list, so yes, tuples will be a bit friendlier,
certainly if your tree is very deep.

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


Re: when will python 2.5 take in mainstream?

2007-02-05 Thread Jean-Paul Calderone
On Mon, 05 Feb 2007 17:07:15 +0100, Laurent Pointal <[EMAIL PROTECTED]> wrote:
>Jean-Paul Calderone a écrit :
>> On Mon, 05 Feb 2007 10:19:26 +0100, Laurent Pointal
>> <[EMAIL PROTECTED]> wrote:
>>> [EMAIL PROTECTED] a écrit :
 When they have to ...

 One of the big things about Python is that its penetration slows it
 down. There's more legacy code and interdependant systems around now
 that Python is more successful and more mature.

 Here's a thought -- perhaps it would be worth having some good ways to
 interact with Python from Python. Suppose you have some 2.4 code
 someplace, interacting with your mysqldb or whatever, and you don't
 want to rewrite it. So long as you have some kind of object broker,
 you could (plausibly) leave your 2.4 apps running with the old
 interpreter, but wrap them for Python 2.5 and use that in your new
 development.
>>>
>>> KISS please.
>>>
>>
>> Requiring change is simpler than not requiring change?
>> Okay, perhaps
>> you could make a case, but it's far from obvious this is always true.
>>
>
>IMHO trying to have a binary compatibility with older compiled modules
>by maintaining an ad-hoc layer to switch between 2.4/2.5 engines make
>Python code more complex. And more complex code have generally more
>bugs. This is the reason for my KISS hope about Python.
>
>Its simple to require changes, not so sure that doing these
>modifications keep things simple. Maybe an internal Python hacker can
>give us his advice on such a modification (ie. staying compatible with
>legacy modules compiled for previous versions).
>

It's very easy to maintain compatibility in the C API.  I'm much more
interested in compatibility at the Python layer, which is changed
incompatibly much, much more frequently than is the C layer.

Anyway, you didn't address my point.  Maintaining compatibility in
Python itself might be more complex than not maintaining complexity.
But _not_ maintaining compatibility just pushes the complexity into
every program and library written with Python.  Which one of these
things do you think results in more developer time being spent? (Hint:
it's the 2nd one.)

Don't mistake this for advocacy that Python never break any compatibility.
Whether or not I think that is the case is unrelated to whether or not
it is useful to understand and admit all of the costs associated with
breaking compatibility.

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

Re: when will python 2.5 take in mainstream?

2007-02-05 Thread Paul Rubin
Laurent Pointal <[EMAIL PROTECTED]> writes:
> IMHO trying to have a binary compatibility with older compiled modules
> by maintaining an ad-hoc layer to switch between 2.4/2.5 engines make
> Python code more complex. And more complex code have generally more
> bugs. This is the reason for my KISS hope about Python.

I haven't heard of other languages that seriously try to do that,
though maybe some do.  I do know that in high-availability systems
it's common to expect to be able to upgrade the software without
interrupting the running system.  Erlang has features for that, and
I've worked on C programs that implemented such hot-upgrade in painful
ways.  It's done (at least in the one I worked on) by making fresh
copies in of all the important objects in a new address space,
converting if necessary from the old version's data formats to the new
version's, then switching from the old software and old space to the
new software and new space.  I think Python isn't used much for this
type of application and so nobody has gone to such extremes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling J from Python

2007-02-05 Thread Gosi
On Feb 5, 2:59 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Gosi wrote:
> > It is quite easy to call J from Python
>
> http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...
>
> What is J, and why should we care?
>
> Diez

J is in many ways similar to Python.

J has very many advanced operations.

http://www.jsoftware.com/

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


get objects referencing another one

2007-02-05 Thread Olivier Feys
I'm working on a tree and I have refcounting problems.
Is it possible from an object, to get the list of objects referencing it ?

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


Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread M�ta-MCI
Re!

I can do :

def ff():
this=ff
try:
this.count=this.count+1
except:
this.count=1
a=1
b=2
c=a+b

ff()
fa=ff
ff()
fa()

print ff.count


But that use, inside the function, the litteral name of the function; and I 
want no use litteral name (inside)

@+

Michel Claveau




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


Re: wxPython: TextCtrl delayed update when using TE_RICH(2)

2007-02-05 Thread Chris Mellon
On 2/5/07, jean-michel bain-cornu <[EMAIL PROTECTED]> wrote:
> >> For this kind of stuff, I'd try to put "self.out.WriteText(string)" in
> >> some 'Idle' event, which avoid to fall in focus loops or other objects
> >> events management problems not easy to solve.
> >>
> >
> > This doesn't have anything to do with focus loops or otherwise, it's
> > because the OP isn't familiar with event based programming.
> >
> > You're performing a long-running task which is preventing the event
> > loop from processing, so your text isn't updating and your application
> > is unresponsive. You need to rewrite your task - either do everything
> > asynchronously, or use a threaded approach. If you use the thread
> > approach, be sure to not call the updates directly, you can use the
> > wx.CallAfter mechanism to call gui functions in a threadsafe manner.
>
> So it is an event management problem.
> The event loop is not yet finished when the program want to display
> something, potentially initiating a new event loop.
>

This is almost totally wrong. There is no "new event loop" involved.
The OP is running a long task in the main thread, which is blocking
the event loop. When the event loop is blocked, the application will
not update and cannot be interacted with. It's that simple. The event
loop in a gui application doesn't "finish" until the application
exits.

> If you don't want to bother with threads, the idle event approach is not
> so bad. Put something to display in a buffer, and display it only one
> time the gui have nothing else to do.

The problem is not putting the text into the control - the OP is
mislead by the symptoms. The problem is the task he's perform in
addition to the logging, which is a long running task (and in his
sample code is represented by time.sleep). The logging issue is a red
herring, the real problem is the way he's structured his application,
with work blocking the event loop. Until he changes this, nothing
about the way he writes to his log is going to fix the problem.

> I use it every time I can, and it's very safe and easy to do.
> Furthermore, you can still step into the program with a debugger, which
> can be tricky if the program uses threads (I'd say impossible, but I
> didn't try in fact).
>

Using idle events for continual calculation actually has several
caveats you need to be aware of, and I don't recommend it. A
background thread or a timer is generally a better solution.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread Bjoern Schliessmann
Méta-MCI wrote:

> Example, with meta-data (attributs of function) :

Apart from asking what counting "nb call" of a function means, I
wonder why you didn't use an iterator?

> @-salutations

@-less Regards,


Björn

-- 
BOFH excuse #65:

system needs to be rebooted

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


Re: Calling J from Python

2007-02-05 Thread Bjoern Schliessmann
Gosi wrote:

> J is in many ways similar to Python.

The only one I see at the moment is that they're both some kind of
programming languages.

> J has very many advanced operations.

Sure.

Mh, just looking at some "advanced" J source taken from
wikipedia.org makes me feel sick:

| Here's a J program to calculate the average of a list of numbers:
|avg=: +/ % #
|avg 1 2 3 4
| 2.5

In the meantime, do you now have an answer to why we should care?

Regards,


Björn

-- 
BOFH excuse #314:

You need to upgrade your VESA local bus to a MasterCard local bus.

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


Re:

2007-02-05 Thread Jonathan Curran
On Monday 05 February 2007 10:07, Zahid Ahmadzai wrote:
> HI THERE
>
> I NEED HELP WITH THE FOLLOWING EXERSISE CAN YOU PLEASE HELP IF YOU CAN.
>
> PLEASE SEND ME THE CODE ON E-MAIL
>
> MANY THANKS
>
>

Quick, everyone, send him the solution to his homework problem!

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


Re: Calling J from Python

2007-02-05 Thread skip

Gosi> J is in many ways similar to Python.

Gosi> J has very many advanced operations.

Gosi> http://www.jsoftware.com/

Doesn't look like open source of any variety.  If a person uses Python with
various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
to a closed source product?

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


Re: Calling J from Python

2007-02-05 Thread hg
Bjoern Schliessmann wrote:

> Gosi wrote:
> 
>> J is in many ways similar to Python.
> 
> The only one I see at the moment is that they're both some kind of
> programming languages.
> 
>> J has very many advanced operations.
> 
> Sure.
> 
> Mh, just looking at some "advanced" J source taken from
> wikipedia.org makes me feel sick:
> 
> | Here's a J program to calculate the average of a list of numbers:
> |avg=: +/ % #
> |avg 1 2 3 4
> | 2.5
> 
> In the meantime, do you now have an answer to why we should care?
> 
> Regards,
> 
> 
> Björn
> 
> --
> BOFH excuse #314:
> 
> You need to upgrade your VESA local bus to a MasterCard local bus.


Be nice !

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


Will Python Run On Microsoft Vista?

2007-02-05 Thread slogging_away
I know, I know - flame away but its not clear to me if Python will run
on a system running Microsoft Vista.  Is anyone successfully running
Python on Vista?  If so, is it what version of Python are you
running?  I'm ordering a new system and if Python won't work on Vista
then it will definately influence the OS selection.

Thanks in advance!

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


Re: Will Python Run On Microsoft Vista?

2007-02-05 Thread Jonathan Curran
On Monday 05 February 2007 11:08, slogging_away wrote:
> I know, I know - flame away but its not clear to me if Python will run
> on a system running Microsoft Vista.  Is anyone successfully running
> Python on Vista?  If so, is it what version of Python are you
> running?  I'm ordering a new system and if Python won't work on Vista
> then it will definately influence the OS selection.
>
> Thanks in advance!

I don't see why Python wouldn't work. The 2.5 version clearly has a version 
for Vista albeit its the x64 Edition. If you downloaded the regular version 
(x86) then I assume it would work just fine. D/L an evaluation copy of Vista 
and try it yourself.

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


Re: Will Python Run On Microsoft Vista?

2007-02-05 Thread hg
slogging_away wrote:

> I know, I know - flame away but its not clear to me if Python will run
> on a system running Microsoft Vista.  Is anyone successfully running
> Python on Vista?  If so, is it what version of Python are you
> running?  I'm ordering a new system and if Python won't work on Vista
> then it will definately influence the OS selection.
> 
> Thanks in advance!
OK so it does not ;-) !


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


Re: Calling J from Python

2007-02-05 Thread Diez B. Roggisch
Gosi wrote:

> On Feb 5, 2:59 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
>> Gosi wrote:
>> > It is quite easy to call J from Python
>>
>> http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...
>>
>> What is J, and why should we care?
>>
>> Diez
> 
> J is in many ways similar to Python.
> 
> J has very many advanced operations.

What exactly do you call "similar to python" when the following is a program
written in it? Compared to that, even Perl is a wonder of readability...

m=: >@(0&{)
v=: >@(1&{)
h=: >@(2&{)
qu   =: >@(3&{)
z=: [EMAIL PROTECTED]:
ret  =: |[EMAIL PROTECTED]:
init =: z;z;z;i.
f1m  =: (m,[EMAIL PROTECTED]);v;h;[EMAIL PROTECTED]
f5m  =: (z;(v,{:@m);h;qu,[EMAIL PROTECTED]) @ (f1m^:5)
f1h  =: (z;z;(h,{:@v);(qu,[EMAIL PROTECTED])) @ (f5m^:12)
f12h =: (z;z;z;qu,[EMAIL PROTECTED],{:@h) @ (f1h^:12)
perm =: qu @ f12h @ init
ord  =: *./ @ (#&>"_) @ C.
days =: -: @ ord @ perm


http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem


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


Re: get objects referencing another one

2007-02-05 Thread Diez B. Roggisch
Olivier Feys wrote:

> I'm working on a tree and I have refcounting problems.
> Is it possible from an object, to get the list of objects referencing it ?

The gc-module might help, but it is somewhat overwhelming.

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


Re: Calling J from Python

2007-02-05 Thread George Sakkis
On Feb 5, 12:23 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:

> Gosi wrote:
> > On Feb 5, 2:59 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> >> Gosi wrote:
> >> > It is quite easy to call J from Python
>
> >>http://groups.google.com/group/J-Programming/browse_thread/thread/5e8...
>
> >> What is J, and why should we care?
>
> >> Diez
>
> > J is in many ways similar to Python.
>
> > J has very many advanced operations.
>
> What exactly do you call "similar to python" when the following is a program
> written in it? Compared to that, even Perl is a wonder of readability...
>
> (cryptic gibberish snipped)
>
> http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem
>
> Diez

Please avoid posting code looking like garbled profanities in c.l.py.
This was outright offensive.

George

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


Re: Calling J from Python

2007-02-05 Thread Alexander Schmolck
[EMAIL PROTECTED] writes:

> Gosi> J is in many ways similar to Python.
> 
> Gosi> J has very many advanced operations.
> 
> Gosi> http://www.jsoftware.com/
> 
> Doesn't look like open source of any variety.  If a person uses Python with
> various add-ons (RPy, numpy, matplotlib, etc) why would they want to switch
> to a closed source product?

You wouldn't, if for nothing else because python has far better scientific
libraries. If you've got an interest in programming languages as such J (or
some other APL) is worth a look though; it's also handy for quick mathematical
experimentation (J's array primitives are more expressive than what numpy
offers and python doesn't support rationals, so it's not just concise due to
perl-style crypticness). For example I once wrote this (slow) code to display
part of a mandelbrot fractal:

load'viewmat'
viewmat+/2&>:|((j.~/~(%~i:)99)&+@:*:)^:(i.32)0

It'll likely require you more typing in python, but then you'd need to do such
things quite a lot for seeing an amortization in terms of less time spent with
your PC; I think most people will find they need a seizable learning
investment to get anywhere with J and python already is very expressive for
the kind of things J is good at.

'as

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


Re: Calling J from Python

2007-02-05 Thread Larry Bates
Bjoern Schliessmann wrote:
> Gosi wrote:
> 
>> J is in many ways similar to Python.
> 
> The only one I see at the moment is that they're both some kind of
> programming languages.
> 
>> J has very many advanced operations.
> 
> Sure.
> 
> Mh, just looking at some "advanced" J source taken from
> wikipedia.org makes me feel sick:
> 
> | Here's a J program to calculate the average of a list of numbers:
> |avg=: +/ % #
> |avg 1 2 3 4
> | 2.5
> 
> In the meantime, do you now have an answer to why we should care?
> 
> Regards,
> 
> 
> Björn
> 
And why is that superior to this:

def avg(l):
return float(sum(l))/len(l)

>>>avg([1,2,3,4])
2.5


Which can actually be read and debugged in the future!

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


Re: Python does not play well with others

2007-02-05 Thread John Nagle
[EMAIL PROTECTED] wrote:
> John Nagle wrote:
> 
>>Graham Dumpleton wrote:
>>
>>>On Feb 4, 1:05 pm, Paul Rubin  wrote:
>>>
>>>
"Paul Boddie" <[EMAIL PROTECTED]> writes:

>> Realistically, mod_python is a dead end for large servers,
>>because Python isn't really multi-threaded.  The Global Python
>>Lock means that a multi-core CPU won't help performance.
> 
> 
> The GIL doesn't affect seperate processes, and any large server that
> cares about stability is going to be running a pre-forking MPM no
> matter what language they're supporting.

   Pre-forking doesn't reduce load; it just improves responsiveness.
You still pay for loading all the modules on every request.  For
many AJAX apps, the loading cost tends to dominate the transaction.

   FastCGI, though, reuses the loaded Python (or whatever) image.
The code has to be written to be able to process transactions
in sequence (i.e. don't rely on variables intitialized at load),
but each process lives for more than one transaction cycle.
However, each process has a copy of the whole Python system,
although maybe some code gets shared.

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


Unicode formatting for Strings

2007-02-05 Thread robson . cozendey . rj
Hi,

I´m trying desperately to tell the interpreter to put an 'á' in my
string, so here is the code snippet:

# -*- coding: utf-8 -*-
filename = u"Ataris Aquáticos #2.txt"
f = open(filename, 'w')

Then I save it with Windows Notepad, in the UTF-8 format. So:

1) I put the "magic comment" at the start of the file
2) I write u"" to specify my unicode string
3) I save it in the UTF-8 format

And even so, I get an error!

  File "Ataris Aqußticos #2.py", line 1
SyntaxError: Non-ASCII character '\xff' in file Ataris Aqußticos #2.py
on line 1
, but no encoding declared; see http://www.python.org/peps/
pep-0263.html for det
ails

I don´t know how to tell Python that it should use UTF-8, it keeps
saying "no encoding declared" !

Robson

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


Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread M�ta-MCI
Re!

>>> why you didn't use an iterator?

If the iterator is extern (to the function), it's like decorator, or global 
var.
If it is internal, it's huge, compare to  this.count=this.count+1  (or 
this.count+=1)


@+

Michel Claveau



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


Re: Calling J from Python

2007-02-05 Thread Robin Becker
Dennis Lee Bieber wrote:
> On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
> <[EMAIL PROTECTED]> declaimed the following
> in comp.lang.python:
> 
>> Mh, just looking at some "advanced" J source taken from
>> wikipedia.org makes me feel sick:
>>
>> | Here's a J program to calculate the average of a list of numbers:
>> |avg=: +/ % #
>> |avg 1 2 3 4
>> | 2.5
>>
>   That looks like some variation of APL

my colleague informs me that it is indeed associated with some of the same 
people if not with Mr Iverson.
-- 
Robin Becker

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


Re: Count nb call of a function, without global var or decorator

2007-02-05 Thread Bjoern Schliessmann
Méta-MCI wrote:

> If the iterator is extern (to the function), it's like decorator,
> or global var.

Please excuse me, I don't understand your point. I'm not even sure
if both of us speak of the same iterators.

> If it is internal, it's huge, compare to  this.count=this.count+1 
> (or this.count+=1)

In which way huge? If you want top notch performance you should use
a C extension anyway ...

Regards,


Björn

-- 
BOFH excuse #339:

manager in the cable duct

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


Re: Python compiled on Windows

2007-02-05 Thread Duncan Booth
Franz Steinhaeusler <[EMAIL PROTECTED]> wrote:

> Hello, I'm only curious.
> 
> Why is Python and most extension (also wxPython) not built using an
> open source compiler like gcc or g++ on Windows?
> 
> I'm always wondering, why Microsoft is still supported 
> in that way, using VC++ 7.1, if I'm not wrong.
> 
> Ok, maybe the compiled assembler code could be better, but
> this cannot be the reason, or?
> 
> It would be wonderful (from the principle) if this could be possible.
> From the standpoint of open source.
> 
> What are your opinions?

Practicality beats purity.

To maximise the interoperability of Python with other software on the 
platform it makes sense to use the best supported compiler environment for 
the platform.

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


Re: Calling J from Python

2007-02-05 Thread Alexander Schmolck
Robin Becker <[EMAIL PROTECTED]> writes:

> Dennis Lee Bieber wrote:
> > On Mon, 05 Feb 2007 17:52:27 +0100, Bjoern Schliessmann
> > <[EMAIL PROTECTED]> declaimed the following
> > in comp.lang.python:
> >
> 
> >> Mh, just looking at some "advanced" J source taken from
> >> wikipedia.org makes me feel sick:
> >>
> >> | Here's a J program to calculate the average of a list of numbers:
> >> |avg=: +/ % #
> >> |avg 1 2 3 4
> >> | 2.5
> >>
> > That looks like some variation of APL
> 
> my colleague informs me that it is indeed associated with some of the same
> people if not with Mr Iverson.

The late Ken Iverson designed both J and APL (he has also written an number of
freely downloadable math books using J, see jsoftware.com).

'as

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


Re: Python does not play well with others

2007-02-05 Thread Paul Boddie
On 5 Feb, 18:52, John Nagle <[EMAIL PROTECTED]> wrote:
>
>Pre-forking doesn't reduce load; it just improves responsiveness.
> You still pay for loading all the modules on every request.  For
> many AJAX apps, the loading cost tends to dominate the transaction.

According to the Apache prefork documentation, you can configure how
often the child processes stick around...

http://httpd.apache.org/docs/2.2/mod/mpm_common.html#maxrequestsperchild

...and I suppose mod_python retains its state in a child process as
long as that process is running:

"Once created, a subinterpreter will be reused for subsequent
requests. It is never destroyed and exists until the Apache process
dies."
- http://www.modpython.org/live/current/doc-html/pyapi-interps.html

"Depending on the use of various PythonInter* directives, a single
python interpreter (and list of imported modules, and per-module
global variables, etc) might be shared between multiple mod_python
applications."
- http://www.modpython.org/FAQ/faqw.py?req=show&file=faq03.005.htp

The FAQ entry (3.1) about module reloading would appear to be
pertinent here, too:

http://www.modpython.org/FAQ/faqw.py?req=show&file=faq03.001.htp

Paul

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


Re: Calling J from Python

2007-02-05 Thread Alexander Schmolck
Larry Bates <[EMAIL PROTECTED]> writes:

> And why is that superior to this:
> 
> def avg(l):
> return float(sum(l))/len(l)
> 
> >>>avg([1,2,3,4])
> 2.5

Apart from being less to type and it is superior in that it's generalizes much
better, e.g:

avg&.^.   NB. geomtric mean
avg&.%NB. harmonic mean
avg M NB. column mean of matrix M
avg"1 M   NB. row mean of matrix M

'as

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


Re: Python compiled on Windows

2007-02-05 Thread hg
Duncan Booth wrote:

> Franz Steinhaeusler <[EMAIL PROTECTED]> wrote:
> 
>> Hello, I'm only curious.
>> 
>> Why is Python and most extension (also wxPython) not built using an
>> open source compiler like gcc or g++ on Windows?
>> 
>> I'm always wondering, why Microsoft is still supported
>> in that way, using VC++ 7.1, if I'm not wrong.
>> 
>> Ok, maybe the compiled assembler code could be better, but
>> this cannot be the reason, or?
>> 
>> It would be wonderful (from the principle) if this could be possible.
>> From the standpoint of open source.
>> 
>> What are your opinions?
> 
> Practicality beats purity.
> 
> To maximise the interoperability of Python with other software on the
> platform it makes sense to use the best supported compiler environment for
> the platform.

Still, if one considers the many threads of people trying to get it to work
with the "free" version + other people that had to invest in VS mostly for
that (I did) / it might eventually be fair to reconsider.

+ a dll is a dll 

hg

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


Re: Calling J from Python

2007-02-05 Thread Laurent Pointal
Diez B. Roggisch wrote:

> m=: >@(0&{)
> v=: >@(1&{)
> h=: >@(2&{)
> qu   =: >@(3&{)
> z=: [EMAIL PROTECTED]:
> ret  =: |[EMAIL PROTECTED]:
> init =: z;z;z;i.
> f1m  =: (m,[EMAIL PROTECTED]);v;h;[EMAIL PROTECTED]
> f5m  =: (z;(v,{:@m);h;qu,[EMAIL PROTECTED]) @ (f1m^:5)
> f1h  =: (z;z;(h,{:@v);(qu,[EMAIL PROTECTED])) @ (f5m^:12)
> f12h =: (z;z;z;qu,[EMAIL PROTECTED],{:@h) @ (f1h^:12)
> perm =: qu @ f12h @ init
> ord  =: *./ @ (#&>"_) @ C.
> days =: -: @ ord @ perm
> 
> 
> http://www.jsoftware.com/jwiki/Essays/The_Ball_Clock_Problem
> 
> 
> Diez

Why dont they call it "smiley" ?

Operators:  :-) :) :o) :-$ *<¦:O)XD-_-+_+^_^*_*!_!   
>_<=_=o_oX_X-_o;)$_$<_<>_>o_0   
><_>-<" =] {-_-}


(source: http://en.wikipedia.org/wiki/Smiley )


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

Re: Python does not play well with others

2007-02-05 Thread Paul Rubin
John Nagle <[EMAIL PROTECTED]> writes:
> > The GIL doesn't affect seperate processes, and any large server that
> > cares about stability is going to be running a pre-forking MPM no
> > matter what language they're supporting.
> 
>Pre-forking doesn't reduce load; it just improves responsiveness.
> You still pay for loading all the modules on every request.  For
> many AJAX apps, the loading cost tends to dominate the transaction.

I think the idea is that each pre-forked subprocess has its own
mod_python that services multiple requests serially.  

New to me is the idea that you can have multiple separate Python
interpreters in a SINGLE process (mentioned in another post).  I'd
thought that being limited to one interpreter per process was a
significant and hard-to-fix limitation of the current CPython
implementation that's unlikely to be fixed earlier than 3.0.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling J from Python

2007-02-05 Thread Bjoern Schliessmann
Alexander Schmolck wrote:

> Apart from being less to type 

Cool. Less to type.

> and it is superior in that it's 
> generalizes much better, e.g:
> 
> avg&.^.   NB. geomtric mean
> avg&.%NB. harmonic mean
> avg M NB. column mean of matrix M
> avg"1 M   NB. row mean of matrix M

Is there any regularity in this? If it is, it's not obvious at all.

Regards,


Björn

-- 
BOFH excuse #78:

Yes, yes, its called a design limitation

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


Re: Calling J from Python

2007-02-05 Thread Stef Mientki
> 
> Mh, just looking at some "advanced" J source taken from
> wikipedia.org makes me feel sick:
> 
> | Here's a J program to calculate the average of a list of numbers:
> |avg=: +/ % #
> |avg 1 2 3 4
> | 2.5
> 
And here is the Python way of calculating the average
 >>> mean([1,2,3,4])
2.5

sorry, I don't see any advantage.

cheers,
Stef Mientki
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode formatting for Strings

2007-02-05 Thread kyosohma
On Feb 5, 11:55 am, [EMAIL PROTECTED] wrote:
> Hi,
>
> I´m trying desperately to tell the interpreter to put an 'á' in my
> string, so here is the code snippet:
>
> # -*- coding: utf-8 -*-
> filename = u"Ataris Aquáticos #2.txt"
> f = open(filename, 'w')
>
> Then I save it with Windows Notepad, in the UTF-8 format. So:
>
> 1) I put the "magic comment" at the start of the file
> 2) I write u"" to specify my unicode string
> 3) I save it in the UTF-8 format
>
> And even so, I get an error!
>
>   File "Ataris Aqußticos #2.py", line 1
> SyntaxError: Non-ASCII character '\xff' in file Ataris Aqußticos #2.py
> on line 1
> , but no encoding declared; seehttp://www.python.org/peps/
> pep-0263.html for det
> ails
>
> I don´t know how to tell Python that it should use UTF-8, it keeps
> saying "no encoding declared" !
>
> Robson

I can't tell from your email if you get the message when you try to
open or close the file. So, I recommend that you read the following
article as it explains the whole unicode business quite well:
http://www.pyzine.com/Issue008/Section_Articles/article_Encodings.html

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


Re: Finding cpu time spent on my program

2007-02-05 Thread kyosohma
On Feb 5, 2:37 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> I am trying to measure the time the processor spends on some
> operation, and I want this measure to not depend on the current load
> of the machine. But doing the following prints different values each
> time a run.
>
> import time
> c1 = time.clock()
> for x in xrange(0xF): pass
>
> c2 = time.clock()
> print "Time spent is %f" % (c2-c1)
>
> Is there a way to measure the number of cpu cycles spent on my program
> alone irrespective of the current load etc of the machine.
>
> -
> Suresh

One of the best ways to time small snippets of code is python's timeit
module. See the docs at http://docs.python.org/lib/module-timeit.html

- Mike

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


Re: Finding cpu time spent on my program

2007-02-05 Thread Carl J. Van Arsdall
[EMAIL PROTECTED] wrote:
> On Feb 5, 2:37 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>   
>> I am trying to measure the time the processor spends on some
>> operation, and I want this measure to not depend on the current load
>> of the machine. But doing the following prints different values each
>> time a run.
>>
>> import time
>> c1 = time.clock()
>> for x in xrange(0xF): pass
>>
>> c2 = time.clock()
>> print "Time spent is %f" % (c2-c1)
>>
>> Is there a way to measure the number of cpu cycles spent on my program
>> alone irrespective of the current load etc of the machine.
>> 
There's an performance testing suite that you might also find useful.  
Check out TAU: Tuning and Analysis Utilities toolkit (simple google 
search will take you to the page).  You can get some serious numbers 
using that thing and they have python support as well as some tools for 
automatically profiling an entire application.  Check it out.

-carl

-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


  1   2   >