Re: Python 3D CAD -- need collaborators, or just brave souls :)

2009-02-12 Thread greg

rantingrick wrote:


It has long been my dream to create an open source 3D CAD program and

I have a real good idea of the UI design


Have you seen Sketchup?

   http://sketchup.google.com/

It has an amazingly intuitive user interface, much better
than any other 3D modeller I've seen. Anyone thinking of
designing a 3D app would do well to study it closely, IMO.

Something with a Sketchup-like UI but designed for serious
CAD work would be an incredibly good thing to have.

In any case, your project sounds interesting, and I'll
be happy to discuss ideas if you want.

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


Re: Breaking Python list into set-length list of lists

2009-02-12 Thread John Machin
On Feb 12, 6:46 pm, Gerard Flanagan  wrote:
> Jason wrote:
> > Hey everyone--
>
> > I'm pretty new to Python, & I need to do something that's incredibly
> > simple, but combing my Python Cookbook & googling hasn't helped me out
> > too much yet, and my brain is very, very tired & flaccid @ the
> > moment
>
> > I have a list of objects, simply called "list".  I need to break it
> > into an array (list of lists) wherein each sublist is the length of
> > the variable "items_per_page".  So array[0] would go from array[0][0]
> > to array[0][items_per_page], then bump up to array[1][0] - array[1]
> > [items_per_page], until all the items in the original list were
> > accounted for.
>
> If you need to pad the last item:
>
> def chunk( seq, size, pad=None ):
>      '''
>      Slice a list into consecutive disjoint 'chunks' of
>      length equal to size. The last chunk is padded if necessary.
>
>      >>> list(chunk(range(1,10),3))
>      [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>      >>> list(chunk(range(1,9),3))
>      [[1, 2, 3], [4, 5, 6], [7, 8, None]]
>      >>> list(chunk(range(1,8),3))
>      [[1, 2, 3], [4, 5, 6], [7, None, None]]
>      >>> list(chunk(range(1,10),1))
>      [[1], [2], [3], [4], [5], [6], [7], [8], [9]]
>      >>> list(chunk(range(1,10),9))
>      [[1, 2, 3, 4, 5, 6, 7, 8, 9]]
>      >>> for X in chunk([],3): print X
>      >>>
>      '''
>      n = len(seq)
>      mod = n % size
>      for i in xrange(0, n-mod, size):
>          yield seq[i:i+size]
>      if mod:
>          padding = [pad] * (size-mod)
>          yield seq[-mod:] + padding
>
> If you search the list archive, there is surely an example which will do
> the same for an arbitrary iterable (in general, you can't assume that
> `len(seq)` will work for an iterable that is not a list, set or tuple).
> But if you are just starting with Python, don't worry about this.

Aren't you making it out to be more mysterious than it needs to be?

Let's show the guy just a teensy bit of Python 102:

| >>> import string; data = string.ascii_lowercase
| >>> page_size = 6
| >>> pages = []
| >>> index = 0
| >>> for item in data:
| ...if not index:
| ...   pages.append([])
| ...   shelve_it = pages[-1].append
| ...index = (index + 1) % page_size
| ...shelve_it(item)
| ...
| >>> pages
| [['a', 'b', 'c', 'd', 'e', 'f'], ['g', 'h', 'i', 'j', 'k', 'l'],
['m', 'n', 'o', 'p', 'q', 'r'], ['s', 't', 'u', 'v', 'w', 'x'], ['y',
'z']]
| >>>
--
http://mail.python.org/mailman/listinfo/python-list


Why does way_1() obtain the correct list but way_2() gets an empty list?

2009-02-12 Thread WP
Hello group! This is probably a silly newbie mistake but consider the 
following program:


import libsbml

def getSBMLModel(biomodel_path):
reader = libsbml.SBMLReader()

sbml_doc = reader.readSBML(biomodel_path)
sbml_model = None

if sbml_doc.getNumErrors() > 0:
print 'I couldn\'t read the file %s!' % biomodel_path
return None
else:
sbml_model = sbml_doc.getModel()

return sbml_doc.getModel() # None if file couldn't be opened


def way_1(biomodel_path):
reader = libsbml.SBMLReader()
sbml_doc = reader.readSBML(biomodel_path)
sbml_model = sbml_doc.getModel()

if sbml_model == None:
return

l = sbml_model.getListOfSpecies()
print 'In way_1(): Got list %s with the length %i' % (l, len(l))


def way_2(biomodel_path):
sbml_model = getSBMLModel(biomodel_path)

if sbml_model == None:
return

l = sbml_model.getListOfSpecies()
print 'In way_2(): Got list %s with the length %i' % (l, len(l))


file = '../BIOMD03.xml'
# Changing the order of these two calls doesn't help, only way_1() works.
way_1(file)
way_2(file)

When run, the output is:
In way_1(): Got list type 'ListOfSpecies *' at 0x291c8bc> > with the length 3
In way_2(): Got list type 'ListOfSpecies *' at 0x27fb57c> > with the length 0


I don't get it way the species list obtained in way_2() is empty? For 
the input file I'm using I should be getting 3 species for the test file 
I'm using.
I'm sorry that this program uses a third-party library which is probably 
unknown to many, but since I make a lot of newbie mistakes I thought 
that it's very likely that this is a issue in how I use python, not a 
library issue. To compensate somewhat I tried to show my entire test 
program and its output and make that test program as clear as possible.


So if anyone knows why I get this behavior I would like to hear it and I 
will have learned something today too! :)


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


Re: Embed a web browser into a page

2009-02-12 Thread Diez B. Roggisch
Carbon Man wrote:

> Hi,
> I need to embed a web browser into a python page. I am coming from the MS
> world where I created an app that all of it's interfaces were actually web
> pages rendered in an Internet Explorer activex control. There was a object
> hook that allowed you to call into the host environment from javascript.
> Basically the host environment would receive the documentComplete event
> and call a method in the document's Javascript passing in an object
> reference. That reference would then be available for calls to be made
> from Javascript back into the host environment.
> I am just starting to explore the Pythonic programming jungle and I was
> wondering if there is a way to do something similar that would work
> cross-platform?
> I guess there is much more complexity in it when you start to go across
> o/s platform boundaries. The common web interface would then be Gecko or
> WebKit? So can someone suggest what would be required to build a
> cross-platform Python app that was capable of browsing HTML files,
> receiving events from the browser, and that allows the embedded page to
> call host Python modules from Javascript via an object reference? Or I am
> asking too much :)

The only thing that might work is Qt + webkit that is used as it's browser.
Everything else is not cross platform.

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


Re: ANN: Python 2.6 Quick Reference available

2009-02-12 Thread Krzysztof Retel
On Feb 12, 12:54 am, [email protected] wrote:
> Richard,
>
> An excellent tool. Great job!!!
>
> Thank you for sharing this with the Python community.
>
> Regards,
> Malcolm

Many thanks Richard and Josh.
I've just started my adventure with Python, and this document will
help me a lot.

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


Re: Thank you, Tkinter. (easy to use)

2009-02-12 Thread Eric Brunel

On Thu, 12 Feb 2009 06:06:06 +0100,  wrote:
[snip]

My only (minor) complaint is that Tk
doesn't draw text antialiased in the various widgets (menus, labels,
buttons, etc.).


From version 8.5 of tcl/tk, it's supposed to do it. See this page:
http://www.tcl.tk/software/tcltk/8.5.tml
under 'Highlights of Tk 8.5', item 'Font rendering'. It seems to talk only  
about X11 and Mac OS X; don't know if it works on Windows...

--
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"

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


Re: best way to serve wsgi with multiple processes

2009-02-12 Thread Robin Becker

Graham Dumpleton wrote:
.

requests.

If the work is indeed long running, the backend process would normally
just acknowledge the request and not wait. The web page would return
and it would be up to user to then somehow occassionally poll web
server, manually or by AJAX, to see how progres is going. That is,
further XML-RPC requests from main server to backend daemon process
asking about progress.

...
this is exactly what we do with the long runners. The wsgi (django in our case) 
process can work out how long the process is likely to take and either responds 
directly or offloads the job to an xmrpc server and responds with a page 
containing a token allowing access to the queue server which refreshes 
periodically to determine job status etc etc. When the job finishes the refresh 
request returns the job result and finishes looping. In our case we don't need 
to worry about people abandoning the job since the results are cached and may be 
of use to others (typical case produce brochure containing details of all 
resources in a country or large city). To avoid overload the xmlrpc server is 
only allowed to run 3 active threads from its queue.

--
Robin Becker

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


Match items in large list

2009-02-12 Thread Fisherking
Hi,

I hope you can help me with this optimizing problem!
I have a large list of dictionaries (about 250 000 of them). Two or
more of these dictionaries contains the same data (not more than five
or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d':
4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...].
(the dictionaries are really containg phone numbers, duration time and
call time.)

Which are the best way of searching through the list and extract the
items that are the same. In the first run I want to find every item
that are the same as {'a':1,'b':'2','c':3}, the second {'d':
4,'e':'5','f':6} etc. The list are not read-only and I can pop them
out of the list when I have found them!

(How can I found items that are almost the same? e.g. {'a':
1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} )

In the second part of this program I need to take each of these items
(similar items are treated as one) and find these in a database that
contains 2.5M posts!

The python version I am bound to is Python 2.3

thanks for your help!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Another optimization request :-)

2009-02-12 Thread andrew cooke
jeffg wrote:
> To be honest, this is not my code and I'm new to python.  It's part of
> the open source project NetworkX, but I'm using this one call
> extensively.  I'm also not that familiar with the math behind the
> physics.  I'll read the documents and see if I can figure it
> out.  :-)  Thank you for the links and suggestions.  I really need to
> get this code performing at peak levels.

the maths is quite simple really, if you know any physics.  it imagines
that a spring connects each point, and then works out what the total
effect of all the springs is.  that gives the net "push" on each point. 
it then goes through and moves each point a small amount in the direction
of the push (there's a "max" that makes no sense physically but probably
gives better numeric stability).

once they have moved, their positions have changed, so everything needs to
be calculated again, hence the iteration.

terry's suggestion was that, rather than working particle by particle, if
you can generalise the code to use matrices then you can use numpy.  that
would mean more of the calculation is done using C rather than Python, and
so would be a big speed-up.

that means that you need to rewrite the program so that you don't have the
for-loops in Python (for u.. and for v...).  instead you need to call
numpy to do array calculations.

that is going to give you much more speedup than what i recommended
(modifying the integration step at the end).

to be honest, although this is not hard if you are used to this kind of
thing, if the above isn't obvious it is quite a job.  you would probably
be better looking for a different library.  unfortunately i don't know of
one (i looked for exactly this a month or two ago and concluded i would
have to write my own; i didn't have time so i used a simpler layout).  i'm
really busy, or i would do this for you, because it's interesting and
useful.  but the code you have looks "amateur" - it wasn't written by
someone who does numerical work for a living.  that doesn't mean it's not
correct or that the original author was stupid, but it does mean that to
make it efficient means looking at the problem in a different way.

there are certainly (very good) java libraries that do this.  could you
use jpython and call out to one of those?  if so, that's probably your
best approach.

andrew


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


Re: Match items in large list

2009-02-12 Thread Paul Rubin
Fisherking  writes:
> Which are the best way of searching through the list and extract the
> items that are the same.

Sort the list, then scan through looking for duplicates, which will be
adjacent to each other.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Match items in large list

2009-02-12 Thread Martin
Hi,

2009/2/12 Paul Rubin :
> Fisherking  writes:
>> Which are the best way of searching through the list and extract the
>> items that are the same.

hmmm how about using sqlites in memory database and let SQL take care
of finding that for you?

hth
Martin


-- 
http://soup.alt.delete.co.at
http://www.xing.com/profile/Martin_Marcher
http://www.linkedin.com/in/martinmarcher

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does way_1() obtain the correct list but way_2() gets an empty list?

2009-02-12 Thread Bruno Desthuilliers

WP a écrit :
Hello group! This is probably a silly newbie mistake but consider the 
following program:


import libsbml

def getSBMLModel(biomodel_path):
reader = libsbml.SBMLReader()

sbml_doc = reader.readSBML(biomodel_path)
sbml_model = None

if sbml_doc.getNumErrors() > 0:
print 'I couldn\'t read the file %s!' % biomodel_path


This should go to stderr. stdout is for normal program outputs.


return None


Also, Python has exception handling, which is usually a better solution 
than returning None or whatever.



else:


since you returned in the other branch, this else is useless


sbml_model = sbml_doc.getModel()

return sbml_doc.getModel() # None if file couldn't be opened


You're calling  sbml_doc.getModel() a first time, binding the returned 
value to name sbml_model, then you're calling it a second time to return it.


A first fix:

import sys

def getSBMLModel(biomodel_path):
reader = libsbml.SBMLReader()
sbml_doc = reader.readSBML(biomodel_path)
if sbml_doc.getNumErrors() > 0:
 # XXX : there's perhaps a better error message
 #   to get from sbml_doc ?
 print >> sys.stderr,  "I couldn't read the file %s!"\
% biomodel_path
 return None

return sbml_doc.getModel()




def way_1(biomodel_path):
reader = libsbml.SBMLReader()
sbml_doc = reader.readSBML(biomodel_path)
sbml_model = sbml_doc.getModel()

if sbml_model == None:


Better to use the identity test here - None is garanteed to be a singleton:

  if sbml_model is None:


return

l = sbml_model.getListOfSpecies()
print 'In way_1(): Got list %s with the length %i' % (l, len(l))


def way_2(biomodel_path):
sbml_model = getSBMLModel(biomodel_path)

if sbml_model == None:
return

l = sbml_model.getListOfSpecies()
print 'In way_2(): Got list %s with the length %i' % (l, len(l))


file = '../BIOMD03.xml'


This shadows the builtin 'file' symbol. Better to use another name.


# Changing the order of these two calls doesn't help, only way_1() works.
way_1(file)
way_2(file)

When run, the output is:
In way_1(): Got list type 'ListOfSpecies *' at 0x291c8bc> > with the length 3
In way_2(): Got list type 'ListOfSpecies *' at 0x27fb57c> > with the length 0


I don't get it way the species list obtained in way_2() is empty?


The only explanation I can imagine here would be that a second call to 
sbml_doc.getModel() doesn't return the same thing as the first... 
(remember, there are two calls in your getSBMLModel() function).


My 2 cents...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Functional schmunctional...

2009-02-12 Thread Steve Holden
Hendrik van Rooyen wrote:
> "Steve Holden"  wrote:
> 
>> Jeez, doesn't anyone read the fine manual any more? I hope this was just
>> an academic exercise.
>>
> socket.inet_ntoa(struct.pack("!l", 10))
>> '59.154.202.0'
>> Holden's rule: when it looks simple enough to be worth including in the
>> standard library it may well already *be* in the standard library.
> 
> Aaah! But how do you find it, if you don't already know
> where it lives and what it's called ?
> 
Well, my usual answer would be "Ask on c.l.py", but it appears that's no
longer reliable. Jeez, doesn't anyone ... (rinse and repeat).

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

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


Re: Match items in large list

2009-02-12 Thread Peter Otten
Fisherking wrote:

> I hope you can help me with this optimizing problem!
> I have a large list of dictionaries (about 250 000 of them). Two or
> more of these dictionaries contains the same data (not more than five
> or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d':
> 4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...].
> (the dictionaries are really containg phone numbers, duration time and
> call time.)

I'd assume the dictionaries to look like

{"phone": "0123...", "duration": 5.67, "calltime": "10:42"}

What do the different keys ("a", "b", "c") versus ("d", "e", "f") mean?
 
> Which are the best way of searching through the list and extract the
> items that are the same. In the first run I want to find every item
> that are the same as {'a':1,'b':'2','c':3}, the second {'d':
> 4,'e':'5','f':6} etc. The list are not read-only and I can pop them
> out of the list when I have found them!

items = [dict(a=1, b=2), dict(a=1, b=2), dict(a=3, c=2), dict(a=3, c=2.2),
dict(a=3, c=2.6)]

# 2.5
seen = set()
for row in items:
rowkey = frozenset(row.iteritems())
if rowkey in seen:
print "dupe", row
else:
seen.add(rowkey)

# 2.3 (and older); not tested
seen = {}
for row in items:
rowkey = row.items()
rowkey.sort()
rowkey = tuple(rowkey)
if rowkey in seen:
print "dupe", row
else:
seen[rowkey] = 1

> (How can I found items that are almost the same? e.g. {'a':
> 1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} )

If you are content with detecting similarities on a single "axis":

def window(items):
items = iter(items)
prev = items.next()
for cur in items:
yield cur, prev
prev = cur

def todict(k, v, rest):
d = dict(rest)
d[k] = v
return d

axis = "c"
d = {}
eps = 0.5
for row in items:
row = dict(row)
try:
value = row.pop(axis)
except KeyError:
pass
else:
key = frozenset(row.iteritems())
d.setdefault(key, []).append(value)

for key, values in d.iteritems():
if len(values) > 1:
for cur, prev in window(sorted(values)):
if abs(cur-prev) < eps:
print "similar rows", todict(axis, cur, key), todict(axis,
prev, key)
 
Otherwise you have to define a distance function and use a clustering
algorithm. Segaran's "Programming Collective Intelligence" has some
examples in Python, though the code can hardly be called idiomatic.

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


Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread W. eWatson
It appears if one moves between IDLE and pythonWin (pyWin) that two separate 
loops (threads?) can occur, and that IDLE can produce incorrect results. 
Since I have preferred IDLE over pyWin, that leaves me currently in a 
quandry. How do I renew these processes, so that I can proceed with IDLE?


I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach 
some understanding of what was going on. Killing these tasks didn't help 
restore order to IDLE. It seems my only choice now is to reboot? Comments?

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Library similar to UserAgent (perl)

2009-02-12 Thread Diez B. Roggisch
mattia wrote:

> Hi everybody, I'm looking for an easy way to put data in a form, then
> click the button and follow the redirect. Also I need to use cookies. I
> read that using perl this can be done using the UserAgent lib, that also
> provide th browser functionality to let the site believe that you are
> getting the pages from a normali browser like ff. Any suggestion? I think
> that the main concen is to easilly put the data in the numerous textlabel
> provided and then magically simulate the 'click me' button.

Python mechanize.

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


xacml api info request

2009-02-12 Thread Oguz Yarimtepe
I am looking for how can i use XACML with Python. Anybody who had used xacml
with python or and idea?

Thanx.

-- 
Oğuz Yarımtepe
www.loopbacking.info
--
http://mail.python.org/mailman/listinfo/python-list


Re: cannot install

2009-02-12 Thread Benjamin Kaplan
On Thu, Feb 12, 2009 at 3:41 AM, Vladimír Župka  wrote:

> Here is config.log:
>
> This file contains any messages produced by compilers while
> running configure, to aid debugging if configure makes a mistake.
>
> It was created by python configure 3.0, which was
> generated by GNU Autoconf 2.61.  Invocation command line was
>
>   $ ./configure --enable-framework
>
> ## - ##
> ## Platform. ##
> ## - ##
>
> hostname = Macintosh.local
> uname -m = i386
> uname -r = 9.6.0
> uname -s = Darwin
> uname -v = Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008;
> root:xnu-1228.9.59~1/RELEASE_I386
>
> /usr/bin/uname -p = i386
> /bin/uname -X = unknown
>
> /bin/arch  = unknown
> /usr/bin/arch -k   = unknown
> /usr/convex/getsysinfo = unknown
> /usr/bin/hostinfo  = Mach kernel version:
>  Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008;
> root:xnu-1228.9.59~1/RELEASE_I386
> Kernel configured for up to 2 processors.
> 2 processors are physically available.
> 2 processors are logically available.
> Processor type: i486 (Intel 80486)
> Processors active: 0 1
> Primary memory available: 4.00 gigabytes
> Default processor set: 101 tasks, 414 threads, 2 processors
> Load average: 1.02, Mach factor: 0.99
> /bin/machine   = unknown
> /usr/bin/oslevel   = unknown
> /bin/universe  = unknown
>
> PATH: /opt/local/bin
> PATH: /opt/local/sbin
> PATH: /Developer/usr/bin
> PATH: /usr/bin
> PATH: /bin
> PATH: /usr/sbin
> PATH: /sbin
> PATH: /Users/admin
> PATH: /usr/local/bin
> PATH: /usr/X11/bin
>
>
> ## --- ##
> ## Core tests. ##
> ## --- ##
>
> configure:1900: checking for --with-universal-archs
> configure:1912: result: 32-bit
> configure:2033: checking MACHDEP
> configure:2197: result: darwin
> configure:2208: checking machine type as reported by uname -m
> configure:2211: result: i386
> configure:2224: checking for --without-gcc
> configure:2250: result: no
> configure:2311: checking for gcc
> configure:2327: found /Developer/usr/bin/gcc
> configure:2338: result: gcc
> configure:2576: checking for C compiler version
> configure:2583: gcc --version >&5
> i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
> Copyright (C) 2005 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> configure:2586: $? = 0
> configure:2593: gcc -v >&5
> Using built-in specs.
> Target: i686-apple-darwin9
> Configured with: /var/tmp/gcc/gcc-5490~1/src/configure --disable-checking
> -enable-werror --prefix=/usr --mandir=/share/man
> --enable-languages=c,objc,c++,obj-c++
> --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/
> --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib
> --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic
> --host=i686-apple-darwin9 --target=i686-apple-darwin9
> Thread model: posix
> gcc version 4.0.1 (Apple Inc. build 5490)
> configure:2596: $? = 0
> configure:2603: gcc -V >&5
> gcc-4.0: argument to `-V' is missing
> configure:2606: $? = 1
> configure:2629: checking for C compiler default output file name
> configure:2656: gccconftest.c  >&5
> ld: library not found for -lcrt1.10.5.o
> collect2: ld returned 1 exit status
> configure:2659: $? = 1
> configure:2697: result:
> configure: failed program was:
> | /* confdefs.h.  */
> | #define _GNU_SOURCE 1
> | #define _NETBSD_SOURCE 1
> | #define __BSD_VISIBLE 1
> | #define _BSD_TYPES 1
> | #define _DARWIN_C_SOURCE 1
> | /* end confdefs.h.  */
> |
> | int
> | main ()
> | {
> |
> |   ;
> |   return 0;
> | }
> configure:2704: error: C compiler cannot create executables
> See `config.log' for more details.
>
> ##  ##
> ## Cache variables. ##
> ##  ##
>
> ac_cv_env_CC_set=
> ac_cv_env_CC_value=
> ac_cv_env_CFLAGS_set=
> ac_cv_env_CFLAGS_value=
> ac_cv_env_CPPFLAGS_set=
> ac_cv_env_CPPFLAGS_value=
> ac_cv_env_CPP_set=
> ac_cv_env_CPP_value=
> ac_cv_env_LDFLAGS_set=
> ac_cv_env_LDFLAGS_value=
> ac_cv_env_LIBS_set=
> ac_cv_env_LIBS_value=
> ac_cv_env_build_alias_set=
> ac_cv_env_build_alias_value=
> ac_cv_env_host_alias_set=
> ac_cv_env_host_alias_value=
> ac_cv_env_target_alias_set=
> ac_cv_env_target_alias_value=
> ac_cv_prog_ac_ct_CC=gcc
>
> ## - ##
> ## Output variables. ##
> ## - ##
>
> AR=''
> ARCH_RUN_32BIT=''
> BASECFLAGS=''
> BLDLIBRARY=''
> BLDSHARED=''
> BUILDEXEEXT=''
> CC='gcc'
> CCSHARED=''
> CFLAGS=''
> CFLAGSFORSHARED=''
> CONFIGURE_MACOSX_DEPLOYMENT_TARGET=''
> CONFIG_ARGS=' '\''--enable-framework'\'''
> CPP=''
> CPPFLAGS=''
> CXX=''
> DEFS=''
> DLINCLDIR=''
> DLLLIBRARY=''
> DYNLOADFILE=''
> ECHO_C='ECHO_N=''
> ECHO_T=''
> EGREP=''
> EXEEXT=''
> EXPORT_MACOSX_DEPLOYMENT_TARGET='#'
> FRAMEWORKALTINSTALLFIRST='frameworkinstallstructure bininstall maninstall'
> FRAMEWORKALTINSTALLLAST='frameworkinstallmaclib frameworkinstallapps
> frameworkaltinstal

[ANN] TracShell 0.1 released

2009-02-12 Thread J Kenneth King

I tend to work a lot with Trac for project management and have always
found the browser interface to be a productivity killer. I always
wanted a simple command-line interface to Trac, but having never found
one I found a little free time and got off my laurels to make one.

TracShell 0.1 is an early release, but it works. So far you can only
query and view tickets, but planned updates include the obvious
ability to create and edit tickets. Future plans will allow browsing
of comments, change histories, attachments, and so forth.

Please consider it really beta. The code needs a little tidying up
around the edges. If you find any bugs, please report them and I'll
fix them ASAP. Ideas, suggestions, and contributions are welcome.

http://code.google.com/p/tracshell/

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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread Diez B. Roggisch
W. eWatson wrote:

> It appears if one moves between IDLE and pythonWin (pyWin) that two
> separate loops (threads?) can occur, and that IDLE can produce incorrect
> results. Since I have preferred IDLE over pyWin, that leaves me currently
> in a quandry. How do I renew these processes, so that I can proceed with
> IDLE?
 
> I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach
> some understanding of what was going on. Killing these tasks didn't help
> restore order to IDLE. It seems my only choice now is to reboot? Comments?

Gosh no, rebooting shouldn't be needed. Just quit all idle & pywin
processes, including of course the main programs. Which *should* be
anything that is needed anyway. 

And you still seem to not understand what is really happening.

Working between pywin and idle is perfectly fine, they are separate
programs. You can start as many instances of a program as you want and
happily work with them. Even several instances of idle and pywin, unless
these come with some logic to prevent multiple starts  - some windows app
do that.

What does *NOT* work is writing a Tkinter-based app in idle, and to run it
*FROM INSIDE* idle. Instead, open your explorer and double-click on the
pyhton-file your app is in. That's all that there is to it.

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


An executable operational semantics for Python

2009-02-12 Thread gideon
Hi everybody,

I've recently finished my Master's thesis on the semantics of Python.
In my thesis I define the semantics of Python by rewriting an abstract
machine. The sources that are used to produce my thesis can also be
compiled into a working interpreter. Hence I call it an 'executable'
semantics.

Anyone interested should have a look at the short intro I put on my
web page:
http://gideon.smdng.nl/2009/01/an-executable-operational-semantics-for-python/

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


Re: TracShell 0.1 released

2009-02-12 Thread Krzysztof Retel
On 12 Feb, 14:06, J Kenneth King  wrote:
> I tend to work a lot with Trac for project management and have always
> found the browser interface to be a productivity killer. I always
> wanted a simple command-line interface to Trac, but having never found
> one I found a little free time and got off my laurels to make one.
>
> TracShell 0.1 is an early release, but it works. So far you can only
> query and view tickets, but planned updates include the obvious
> ability to create and edit tickets. Future plans will allow browsing
> of comments, change histories, attachments, and so forth.
>
> Please consider it really beta. The code needs a little tidying up
> around the edges. If you find any bugs, please report them and I'll
> fix them ASAP. Ideas, suggestions, and contributions are welcome.
>
> http://code.google.com/p/tracshell/
>
> Cheers.

Nice work.

Maybe it would be worth building at some point vim or emacs interface.

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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread W. eWatson

Diez B. Roggisch wrote:

W. eWatson wrote:


It appears if one moves between IDLE and pythonWin (pyWin) that two
separate loops (threads?) can occur, and that IDLE can produce incorrect
results. Since I have preferred IDLE over pyWin, that leaves me currently
in a quandry. How do I renew these processes, so that I can proceed with
IDLE?
 

I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach
some understanding of what was going on. Killing these tasks didn't help
restore order to IDLE. It seems my only choice now is to reboot? Comments?


Gosh no, rebooting shouldn't be needed. Just quit all idle & pywin
processes, including of course the main programs. Which *should* be
anything that is needed anyway. 
Done that. Been there. It doesn't work. If I take another py tkinter program 
and run it in IDLE, it *will work*. The current program goes boom.


And you still seem to not understand what is really happening.
Whether I understand it exactly or not is not the issue. The issue is how do 
I execute IDLE *now* to get the correct results it once allowed? The fact of 
the matter is that I was happily working in IDLE for days and hours. I 
encountered a problem in IDLE that seemed suspicious, so I then fired up 
pyWin to see if it gave the same results. It worked fine. Then my problems 
with IDLE got worse.


Working between pywin and idle is perfectly fine, they are separate
programs. You can start as many instances of a program as you want and
happily work with them. Even several instances of idle and pywin, unless
these come with some logic to prevent multiple starts  - some windows app
do that.

How could this be true; otherwise,  I wouldn't be complaining?


What does *NOT* work is writing a Tkinter-based app in idle, and to run it
*FROM INSIDE* idle. Instead, open your explorer and double-click on the
pyhton-file your app is in. That's all that there is to it.

Personally, I like running entirely in IDLE.

If there is no other way than you suggested in "NOT work", then I may just 
uninstall pyWin.


Diez



--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


cx_Oracle-5.0 Problem

2009-02-12 Thread Brandon Taylor
Hello everyone,

I'm Brandon Taylor, senior web developer with the University of Texas
at Austin. We're using Python 2.6.1 and having a lot of difficulty
getting the cx_Oracle-5.0 library to install on one of our MacBooks
running OS X 10.5.6.

We can get cx_Oracle to compile, but after running setup.py install
and trying to import the library, we are getting an error:

Traceback (most recent call last):
  File "", line 1, in 
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/
lib/python2.6/site-packages/cx_Oracle.so, 2): Symbol not found:
___divdi3
  Referenced from: /Users/mas80/Library/Oracle/instantclient_10_2/
libclntsh.dylib.10.1
  Expected in: flat namespace


Can anyone shed some light on how we can solve this issue? It's a show
stopper for us of we can not connect to Oracle from Python.

Kind regards,
Brandon Taylor
--
http://mail.python.org/mailman/listinfo/python-list


Re: how can this iterator be optimized?

2009-02-12 Thread josh logan
On Feb 11, 8:22 pm, Basilisk96  wrote:
> Hello all,
>
> I have the following function that uses an intermediate iterator
> "rawPairs":
>
> def MakePairs(path):
>     import os
>     import operator
>     join = os.path.join
>     rawPairs = (
>         (join(path, s), func(s))
>         for s in os.listdir(path)
>         if func(s) is not None and func(s).endswith("some criterion")
>     )
>     #Use the second item in the pair as the sort criterion
>     result = sorted(rawPairs, key=operator.itemgetter(1))
>     return result
>
> where "func" is a single-argument function that returns either a
> string or None, but is an expensive call.
> I am pretty sure that the sorted() construct cannot be improved much
> further, but...
> ...does anyone have ideas on improving the "rawPairs" iterator so that
> it calls "func(s)" only once per iteration?  Perhaps a lambda
> construct, but I am not sure how to go about it...?
>
> Cheers,
> Basilisk96

Hi,
Try something like this:

import os
from os.path import join
from itertools import ifilter #assuming 2.5 and earlier, for 3.0 just
use the filter builtin
from operator import itemgetter

def isvalid(pair):
return (s[1] is not None) and s[1].endswith('some criteria')

def makepairs(path):
pair_iter = ((join(path,s), func(s)) for s in os.listdir(path))
pair_iter = ifilter(isvalid, pair_iter)
result = sorted(pair_iter, key=itemgetter(1))

return result


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


Re: TracShell 0.1 released

2009-02-12 Thread J Kenneth King
Krzysztof Retel  writes:

> On 12 Feb, 14:06, J Kenneth King  wrote:
>> I tend to work a lot with Trac for project management and have always
>> found the browser interface to be a productivity killer. I always
>> wanted a simple command-line interface to Trac, but having never found
>> one I found a little free time and got off my laurels to make one.
>>
>> TracShell 0.1 is an early release, but it works. So far you can only
>> query and view tickets, but planned updates include the obvious
>> ability to create and edit tickets. Future plans will allow browsing
>> of comments, change histories, attachments, and so forth.
>>
>> Please consider it really beta. The code needs a little tidying up
>> around the edges. If you find any bugs, please report them and I'll
>> fix them ASAP. Ideas, suggestions, and contributions are welcome.
>>
>> http://code.google.com/p/tracshell/
>>
>> Cheers.
>
> Nice work.
>
> Maybe it would be worth building at some point vim or emacs interface.
>
> Krzysztof

Thanks. :)

I considered a native editor interface, but since both vi and emacs
can run a shell within a buffer, I decided to go with a more flexible
solution.

However, if someone wanted to, the actual code fetching and displaying
the data isn't tied directly to the shell interface. It could be
possible to dispatch calls from a native editor front-end if it
doesn't mind spawning a python interpreter (or keeping one running)
for each request.

Anyway, thanks for checking it out. Hope you find it useful. I do. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Could you recommend job schedulling solution?

2009-02-12 Thread redbaron
>
> I think parallel python will take of that for you
> (http://www.parallelpython.com/)

I've found that RPyC (http://rpyc.wikidot.com/) is quite usefull for
my task.  It allows me to build RPC service which accepts ordinary
python function from client and return result in synchronous or
asynchronous way. Of course it is able to serve multiple clients and
it's forking server help me to solve GIL problems on intense
calculations inside Python code.

Some limitations are present, like the fact that you couldn't send on
execution any code which use C extensions which are not present on RPC
server, but I didn't expect this could work at all, so in general RPyC
makes me happy.
--
http://mail.python.org/mailman/listinfo/python-list


some history of computing and celebrities [was lisp machine keyboards]

2009-02-12 Thread Xah Lee
On Feb 12, 7:28 am, Xah Lee  wrote:
> lisp machine keyboards.
>
> • Knite keyboard. I think this is one of the 
> earlist.http://world.std.com/~jdostale/kbd/Knight.html
>
> • Symbolics earlier style keyboard (PN 364000), by Peter 
> Painehttp://www.asl.dsl.pipex.com/symbolics/photos/IO/kbd-older.html
>
> Symbolics later model Symbolics keyboard PN 365407 Rev C
> at Joey Devilla's blog, several hi quality 
> photoshttp://www.globalnerdy.com/2009/02/05/hacklabtos-lisp-machine-keyboard/
>
> also at Rainer site, with info on how to use it on mac os 
> xhttp://lispm.dyndns.org/news?ID=NEWS-2008-07-27-1
>
> one of the most funny comment from Joey's blog is:
> “Man, my pinkies are getting tired just looking at that thing.”
>
> of course, the most baroque, showy, with a fancy name is the
> Space-cadet keyboard
>  http://xahlee.org/emacs/emacs_kb_shortcuts_pain.html
>
> Space-cadet! LOL.
>
> btw, how did that name came to be?
>
>   Xah
> ∑http://xahlee.org/
>
> ☄


while nosing about lisp machines, i checked out the Wikipedia article
on Symbolics again:
 http://en.wikipedia.org/wiki/Symbolics

it's content has improved significantly since last year or so i
checked.

My firts daily use of computer or owning one is ~1991, and didn't
really become pro after 1995. So, lisp machines are before my time.
Though, i have already had some interest in lisp history and have
strong interest in the the history of how the motherfucking unix
tookover its/lisp/vms/whatnot war. Reading such history is usually not
easy, because you are bombarded with many OSes or technologies that
you are not familiar and really difficult to understand its situation
without having lived in the tech of that era...

anyhow, check out some of the interesting tidbits in the article:

«Symbolics staffers Dan Weinreb, David Moon, Neal Feinberg, Kent
Pitman, Scott McKay, Sonya Keene and others made significant
contributions to the emerging Common Lisp language standard from the
mid-1980s through the release of the ANSI Common Lisp standard in
1994»

There, Dan Weinred, Kent Pitman, 2 guy who still write here sometimes,
are mentioned. (Kent i knew as a online acquaintance since ~2000 here.
Dan i knew only last year.)

Also note how Richard Stallman, who the open sourcing or FSF fuckheads
take to be a god unquestioned, who was at the time simply doing
questionable deeds. (note that in general, history doesn't have a
right and wrong. How came out as winner, is the hero.)

Given the Symbolic vs MIT/RMS situation, one can question what is the
interpersonal relation or formal relation between these people with
RMS. (in general, often many historical issue or truth cannot be
discussed when the persons are still alive, for many real life
complexities.)

Also of interest is tat Scott McKay, the Sun Micro guy, is there
too...

O, a wee bit of rambling.

«Advances in garbage collection techniques by Henry Baker, David Moon
and others, particularly the first commercial use of generational
scavenging, allowed Symbolics computers to run large Lisp programs for
months at a time.»

interesting to me is seeing the name Henry Baker. He has wrote a few
articles i've came cross in the past and enjoyed.

• “Buffer Overflow” Security Problems, (2001), by Henry G Baker
  http://catless.ncl.ac.uk/Risks/21.84.html#subj10.1

• Communications of the ACM 34, 4 (April 1991), 18. Henry G Baker,
1990. (On the harm of speed)
 http://home.pipeline.com/~hbaker1/letters/CACM-DubiousAchievement.html

• “Iterators: Signs of Weakness in Object-Oriented Languages” (1992)
By Henry G Baker.
http://home.pipeline.com/~hbaker1/Iterator.html

I'm posting this to python group too, for the last article above about
iterators. I whole heartedly agree to all Henry's opinions... often
today's hotshot programing morons have no understanding fuck. Python 3
is going full with iterators and enumerators fuck.

i'd link to few articles i wrote pertinent to some of the above
issues... but think rather not, since i've already done that often.

  Xah
∑ http://xahlee.org/

☄

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


Re: cx_Oracle-5.0 Problem

2009-02-12 Thread redbaron
> ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/
> lib/python2.6/site-packages/cx_Oracle.so, 2): Symbol not found:
> ___divdi3

You didn't link cx_Oracle.so all libs which it use. run "ldd -r
cx_Oracle.so" and you'll have an idea about all missing symbols. The
names of missed symbols could give you an idea what else should
cx_Oracle.so should be linked with

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


Read Only attributes, auto properties and getters and setters

2009-02-12 Thread TechieInsights
Ok, so I noticed some of the modules (such as many of the datetime
attributes) are read-only, which means the __setattr__ and __set__
methods are intercepted... pretty easy.  I am looking for a way to
automate this.  The real goal is not to have read only attributes, but
to have getters and setters that are automatically called when a
property is called.  The getting is pretty easily achieved by setting
the metaclass which also creates the properties.  What I have so far
will protect the get_ and set_ methods as well as the properties that
call the get methods.  The reasoning for this is that I don't want
someone accidentally overwriting the property when the class uses a
private class variable.  What I have so far:



class ReadOnlyMeta(type):
def __new__(cls, name, bases, methoddict):
pname = '_%s__protected_items' %(name)
protected = [pname]
methoddict[pname] = protected
for key, value in methoddict.items():
if key.startswith("get_"):
methoddict[key[4:]] = property(value)
protected.append(key[4:])
protected.append(key)
elif key.startswith("set_"):
protected.append(key)
return type.__new__(cls, name, bases, methoddict)

class ReadOnly(object):
__metaclass__ = ReadOnlyMeta

def __check_private(self, name, msg = None):
if name in self.__protected_items:
if msg is None:
msg = "'%s' of '%s' is Read only." %(name,
self.__class__.__name__)
raise AttributeError(msg)

def __setattr__(self, name, value):
self.__check_private(name, "attribute '%s' of '%s' objects is 
not
writable" %(name, self.__class__.__name__))
self.__dict__[name] = value

def __delattr__(self, name):
self.__check_private(name, "attribute '%s' of '%s' objects 
cannot be
removed" %(name, self.__class__.__name__))
self.__dict__.pop(name)

def __set__(self, instance, value):
self.__check_private(instance, "You cannot remap the method 
'%s'" %
(instance))
self.__dict__[instance] = value



I then implement this by creating a subclass of the read only class:

class MyClass(ReadOnly):
def __init__(self, x):
self.set_x(x)

def get_x(self):
return self.__x

def set_x(self, x):
print 'Hello the setter was called!'
self.__x = x


What I want is to be able to auto-call the set_ methods whenever
someone tries to call a method that has a setter.  This could be done
by each class... tedious!  I want automation!  To do this I have tried
adding a list of setters to the metaclass and then in the __set__ and
__setattr__ methods I check to see if 'set_%s' %(variable) exists in
the list... if it does I call the method.  This would work, however
there are two lists of setters (in the example above), the ReadOnly
list and a MyClass list.  When you print out a dir(self) IN the
ReadOnly class from an implementation (MyClass) it will show the
MyClass attributes, however they cannot be called from the parent
class... so my real question... how can you (or can you ever) call a
child method from a parent class without explicitly passing the
callable?

I hope this hasn't been too confusing... or made your head hurt like
mine does...  If you want more code examples of what I have tried and
the out put... I'd be happy to give them.

Greg




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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread Diez B. Roggisch
> Done that. Been there. It doesn't work. If I take another py tkinter
> program and run it in IDLE, it *will work*. The current program goes boom.

That's pure luck then. IDLE is written in Tkinter, and *running* Tkinter
apps inside of it is bound to fail sooner or later. Failure might be as
drastic as termination of IDLE, or just some glitches.

This has hit numerous people before, as you've been told several times now.
What makes you think it doesn't affect you?

>> 
>> And you still seem to not understand what is really happening.
> Whether I understand it exactly or not is not the issue. The issue is how
> do I execute IDLE *now* to get the correct results it once allowed? The
> fact of the matter is that I was happily working in IDLE for days and
> hours. I encountered a problem in IDLE that seemed suspicious, so I then
> fired up pyWin to see if it gave the same results. It worked fine. Then my
> problems with IDLE got worse.
>> 
>> Working between pywin and idle is perfectly fine, they are separate
>> programs. You can start as many instances of a program as you want and
>> happily work with them. Even several instances of idle and pywin, unless
>> these come with some logic to prevent multiple starts  - some windows app
>> do that.
> How could this be true; otherwise,  I wouldn't be complaining?

Coincidence? When Mom tells me the car broke down after she passed by the
bakery, I don't assume one has to do with the other either.

>> What does *NOT* work is writing a Tkinter-based app in idle, and to run
>> it *FROM INSIDE* idle. Instead, open your explorer and double-click on
>> the pyhton-file your app is in. That's all that there is to it.
> Personally, I like running entirely in IDLE.

This is not a question of your liking, it's a question of technical
feasibility.

if you have been working happily for hours and days as you tell us, I can
only hope & assume that you made actual progress. Which might have brought
your own program to a point where it wasn't tolerable working from within
idle anymore. That you in the meanttime chose to work with Pywin is
irrelevant to that.
 
> If there is no other way than you suggested in "NOT work", then I may just
> uninstall pyWin.

Do so if you like - cargo cult programming isn't uncommon these days.

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


Re: Read Only attributes, auto properties and getters and setters

2009-02-12 Thread TechieInsights
Oh... one other thing that would be really cool is to do this with AOP/
descriptors!  I just haven't been able to get that to work either.
Basics...

@readonly
class MyClass(object):
def __init__(self, x):
self.set_x(x)

def get_x(self):
return self.__x

def set_x(self, x):
print 'Hello the setter was called!'
self.__x = x

and it's done!  I don't think this will work because (maybe I'm wrong)
but I don't think you can set the metaclass in the descriptor???  If
this is the case, it is more work to do the AOP and set a metaclass...
better to just inherit.  If it can be done... that would be awesome!

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


Embarrasing questio

2009-02-12 Thread Catherine Heathcote
But I just cant find it. How do I do an or, as in c/c++'s ||? Just 
trying to do something simple, the python equivilent of:


if(i % 3 == 0 || i % 5 == 0)

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


Re: Embarrasing questio

2009-02-12 Thread TechieInsights
On Feb 12, 9:03 am, Catherine Heathcote
 wrote:
> But I just cant find it. How do I do an or, as in c/c++'s ||? Just
> trying to do something simple, the python equivilent of:
>
> if(i % 3 == 0 || i % 5 == 0)
>
> Thanks.

if i % 3  == 0 or i % 5 == 0

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


Re: Embarrasing questio

2009-02-12 Thread TechieInsights
On Feb 12, 9:03 am, Catherine Heathcote
 wrote:
> But I just cant find it. How do I do an or, as in c/c++'s ||? Just
> trying to do something simple, the python equivilent of:
>
> if(i % 3 == 0 || i % 5 == 0)
>
> Thanks.

in 2.5 and above you can do
if any(i%3 == 0, i%5 == 0)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Breaking Python list into set-length list of lists

2009-02-12 Thread MRAB

Mensanator wrote:

On Feb 11, 10:58�pm, Jason  wrote:

Hey everyone--

I'm pretty new to Python, & I need to do something that's incredibly
simple, but combing my Python Cookbook & googling hasn't helped me out
too much yet, and my brain is very, very tired & flaccid @ the
moment

I have a list of objects, simply called "list". �I need to break it
into an array (list of lists) wherein each sublist is the length of
the variable "items_per_page". �So array[0] would go from array[0][0]
to array[0][items_per_page], then bump up to array[1][0] - array[1]
[items_per_page], until all the items in the original list were
accounted for.

What would be the simplest way to do this in Python? �And yes, I
realize I should probably be taking Programming 101.



items_per_page = 20
x = range(113)
layout = divmod(113,20)
if layout[1]>0:

pages = layout[0]+1
else:
pages = layout[0]

array = [ x[i*items_per_page:i*items_per_page+items_per_page]  for i in 
xrange(pages)]
array

[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19], [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
53, 54, 55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
70, 71, 72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86,
87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112]]

>
Using list comprehension:

>>> my_list = range(113)
>>> items_per_page = 20
>>>
>>> array = [my_list[start : start + items_per_page] for start in 
range(0, len(my_list), items_per_page)]

>>>
>>> array
[[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], 
[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 
38, 39], [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 
55, 56, 57, 58, 59], [60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 
72, 73, 74, 75, 76, 77, 78, 79], [80, 81, 82, 83, 84, 85, 86, 87, 88, 
89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99], [100, 101, 102, 103, 104, 
105, 106, 107, 108, 109, 110, 111, 112]]

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


Re: Embarrasing questio

2009-02-12 Thread Aahz
In article ,
Catherine Heathcote   wrote:
>
>But I just cant find it. How do I do an or, as in c/c++'s ||? Just 
>trying to do something simple, the python equivilent of:
>
>if(i % 3 == 0 || i % 5 == 0)

if i % 3 == 0 or i % 5 == 0:

You may find it worthwhile to quickly step through everything in the
standard Python tutorial, it covers lots of stuff like this.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embarrasing questio

2009-02-12 Thread Catherine Heathcote

TechieInsights wrote:

On Feb 12, 9:03 am, Catherine Heathcote
 wrote:

But I just cant find it. How do I do an or, as in c/c++'s ||? Just
trying to do something simple, the python equivilent of:

if(i % 3 == 0 || i % 5 == 0)

Thanks.


if i % 3  == 0 or i % 5 == 0



Yea, new it would be embarrasing, thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: An executable operational semantics for Python

2009-02-12 Thread bearophileHUGS
gideon:
> I've recently finished my Master's thesis on the semantics of Python.
> In my thesis I define the semantics of Python by rewriting an abstract
> machine. The sources that are used to produce my thesis can also be
> compiled into a working interpreter. Hence I call it an 'executable'
> semantics.

Can it be used for some useful purpose?

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


Re: Another optimization request :-)

2009-02-12 Thread bearophileHUGS
On Feb 12, 2:48 am, jeffg  wrote:
> If anyone wants to take this on... I would really really like to have
> the spring_layout modified to support multi-threading if at all
> possible.

You can start creating a compiled Python extension using ShedSkin, it
may be enough.

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


Re: Embarrasing questio

2009-02-12 Thread Michele Simionato
On Feb 12, 5:07 pm, TechieInsights  wrote:
> On Feb 12, 9:03 am, Catherine Heathcote
>
>  wrote:
> > But I just cant find it. How do I do an or, as in c/c++'s ||? Just
> > trying to do something simple, the python equivilent of:
>
> > if(i % 3 == 0 || i % 5 == 0)
>
> > Thanks.
>
> in 2.5 and above you can do
> if any(i%3 == 0, i%5 == 0)

You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but
the idiomatic solution is to use or).
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embarrasing questio

2009-02-12 Thread km
Hi,

you could do it this way also :

if i in [3,5]:
do something...

KM
~
On Fri, Feb 13, 2009 at 1:19 AM, Michele Simionato <
[email protected]> wrote:

> On Feb 12, 5:07 pm, TechieInsights  wrote:
> > On Feb 12, 9:03 am, Catherine Heathcote
> >
> >  wrote:
> > > But I just cant find it. How do I do an or, as in c/c++'s ||? Just
> > > trying to do something simple, the python equivilent of:
> >
> > > if(i % 3 == 0 || i % 5 == 0)
> >
> > > Thanks.
> >
> > in 2.5 and above you can do
> > if any(i%3 == 0, i%5 == 0)
>
> You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but
> the idiomatic solution is to use or).
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embarrasing questio

2009-02-12 Thread Catherine Heathcote

Aahz wrote:

In article ,
Catherine Heathcote   wrote:
But I just cant find it. How do I do an or, as in c/c++'s ||? Just 
trying to do something simple, the python equivilent of:


if(i % 3 == 0 || i % 5 == 0)


if i % 3 == 0 or i % 5 == 0:

You may find it worthwhile to quickly step through everything in the
standard Python tutorial, it covers lots of stuff like this.


I did, though perhapse a little to quickly! lol
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embarrasing questio

2009-02-12 Thread Tim Rowe
2009/2/12 km :
> Hi,
>
> you could do it this way also :
>
> if i in [3,5]:
> do something...

True, you could do it, but it would be wrong. The original is true for
i = 6, 9, 10, 12 and so on, but yours doesn't seem to be...

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


Re: Read Only attributes, auto properties and getters and setters

2009-02-12 Thread josh logan
On Feb 12, 10:58 am, TechieInsights  wrote:
> Oh... one other thing that would be really cool is to do this with AOP/
> descriptors!  I just haven't been able to get that to work either.
> Basics...
>
> @readonly
> class MyClass(object):
>         def __init__(self, x):
>                 self.set_x(x)
>
>         def get_x(self):
>                 return self.__x
>
>         def set_x(self, x):
>                 print 'Hello the setter was called!'
>                 self.__x = x
>
> and it's done!  I don't think this will work because (maybe I'm wrong)
> but I don't think you can set the metaclass in the descriptor???  If
> this is the case, it is more work to do the AOP and set a metaclass...
> better to just inherit.  If it can be done... that would be awesome!
>
> Greg

Are your needs not already satisfied by the Python built-in property?

http://docs.python.org/dev/3.0/library/functions.html#property
--
http://mail.python.org/mailman/listinfo/python-list


Re: Embarrasing questio

2009-02-12 Thread TechieInsights
On Feb 12, 9:19 am, Michele Simionato 
wrote:
> On Feb 12, 5:07 pm, TechieInsights  wrote:
>
> > On Feb 12, 9:03 am, Catherine Heathcote
>
> >  wrote:
> > > But I just cant find it. How do I do an or, as in c/c++'s ||? Just
> > > trying to do something simple, the python equivilent of:
>
> > > if(i % 3 == 0 || i % 5 == 0)
>
> > > Thanks.
>
> > in 2.5 and above you can do
> > if any(i%3 == 0, i%5 == 0)
>
> You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but
> the idiomatic solution is to use or).

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


Re: Read Only attributes, auto properties and getters and setters

2009-02-12 Thread TechieInsights
On Feb 12, 9:27 am, josh logan  wrote:
> On Feb 12, 10:58 am, TechieInsights  wrote:
>
>
>
> > Oh... one other thing that would be really cool is to do this with AOP/
> > descriptors!  I just haven't been able to get that to work either.
> > Basics...
>
> > @readonly
> > class MyClass(object):
> >         def __init__(self, x):
> >                 self.set_x(x)
>
> >         def get_x(self):
> >                 return self.__x
>
> >         def set_x(self, x):
> >                 print 'Hello the setter was called!'
> >                 self.__x = x
>
> > and it's done!  I don't think this will work because (maybe I'm wrong)
> > but I don't think you can set the metaclass in the descriptor???  If
> > this is the case, it is more work to do the AOP and set a metaclass...
> > better to just inherit.  If it can be done... that would be awesome!
>
> > Greg
>
> Are your needs not already satisfied by the Python built-in property?
>
> http://docs.python.org/dev/3.0/library/functions.html#property

yea... just read the docs... I love reinventing the wheel (sarcasm)...

Thanks for this... I just realized that you can set the fset and fdel
to None... so everything can be done from the metaclass!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Match items in large list

2009-02-12 Thread MRAB

Fisherking wrote:

Hi,

I hope you can help me with this optimizing problem!
I have a large list of dictionaries (about 250 000 of them). Two or
more of these dictionaries contains the same data (not more than five
or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d':
4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...].
(the dictionaries are really containg phone numbers, duration time and
call time.)

Which are the best way of searching through the list and extract the
items that are the same. In the first run I want to find every item
that are the same as {'a':1,'b':'2','c':3}, the second {'d':
4,'e':'5','f':6} etc. The list are not read-only and I can pop them
out of the list when I have found them!

(How can I found items that are almost the same? e.g. {'a':
1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} )

In the second part of this program I need to take each of these items
(similar items are treated as one) and find these in a database that
contains 2.5M posts!

The python version I am bound to is Python 2.3


The best way of looking for duplicates is to make a dict or set of the
items. Unfortunately a dict isn't hashable, so it can't be a key.
Therefore I suggest you convert the dicts into tuples, which are
hashable:

counts = {}
for d in my_list:
d_as_list = d.items()
# Standardise the order so that identical dicts become identical 
tuples.

d_as_list.sort()
key = tuple(d_as_list)
if key in counts:
counts[key] += 1
else:
counts[key] = 1
--
http://mail.python.org/mailman/listinfo/python-list


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread Mike Driscoll
On Feb 12, 8:57 am, "W. eWatson"  wrote:
> Diez B. Roggisch wrote:
> > W. eWatson wrote:
>
> >> It appears if one moves between IDLE and pythonWin (pyWin) that two
> >> separate loops (threads?) can occur, and that IDLE can produce incorrect
> >> results. Since I have preferred IDLE over pyWin, that leaves me currently
> >> in a quandry. How do I renew these processes, so that I can proceed with
> >> IDLE?
>
> >> I noticed that I had about 10-15 copies of pythonw.exe as I tried to reach
> >> some understanding of what was going on. Killing these tasks didn't help
> >> restore order to IDLE. It seems my only choice now is to reboot? Comments?
>
> > Gosh no, rebooting shouldn't be needed. Just quit all idle & pywin
> > processes, including of course the main programs. Which *should* be
> > anything that is needed anyway.
>
> Done that. Been there. It doesn't work. If I take another py tkinter program
> and run it in IDLE, it *will work*. The current program goes boom.
>
> > And you still seem to not understand what is really happening.
>
> Whether I understand it exactly or not is not the issue. The issue is how do
> I execute IDLE *now* to get the correct results it once allowed? The fact of
> the matter is that I was happily working in IDLE for days and hours. I
> encountered a problem in IDLE that seemed suspicious, so I then fired up
> pyWin to see if it gave the same results. It worked fine. Then my problems
> with IDLE got worse.
>
> > Working between pywin and idle is perfectly fine, they are separate
> > programs. You can start as many instances of a program as you want and
> > happily work with them. Even several instances of idle and pywin, unless
> > these come with some logic to prevent multiple starts  - some windows app
> > do that.
>
> How could this be true; otherwise,  I wouldn't be complaining?
>
> > What does *NOT* work is writing a Tkinter-based app in idle, and to run it
> > *FROM INSIDE* idle. Instead, open your explorer and double-click on the
> > pyhton-file your app is in. That's all that there is to it.
>
> Personally, I like running entirely in IDLE.
>
> If there is no other way than you suggested in "NOT work", then I may just
> uninstall pyWin.
>
>
>
> > Diez
>
> --
>                                 W. eWatson
>
>               (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
>                Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet
>
>                      Web Page: 

I like IDLE too. However, I've experienced seemingly random crashes
when programming wxPython programs in it. As already stated, the
mainloops clash from time to time. So now I use Wingware or just edit
the files in IDLE and run the program by double-click or via command
line.

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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread W. eWatson

I simply ask, "How do I get around the problem?"

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread W. eWatson
As with Diez, I simply ask, "How do I get around the problem?" Are you two 
telling me that it is impossible?


OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and have 
 good familiarity with Tkinter? If so, I'll send you the code and you can 
try it yourself. My guess is that it will work, and if not, and you are 
sufficiently skilled with Tkinter and debugging, you may find the problem in 
the code. The steps to create the problem are very easy.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: openOffic, windows, and Python 2.5

2009-02-12 Thread John Fabiani
Terry Reedy wrote:

> John Fabiani wrote:
>> Hi,
>> OpenOffice 3 on windows uses python 2.3.x (I have no idea why).
> 
> I presume because no one has volunteered to do the update for the Py-UNO
> bridge.  In any case, why do you consider that to be a problem.  It is
> common for apps to include the Python they are known to work with.
> 
> tjr

Thanks for the response.  The reason is the others apps are written in
python 2.5.x.  All the testing was done on Linux using 2.5 and now we need
it to work on the windows side too.  
--
http://mail.python.org/mailman/listinfo/python-list


Spam

2009-02-12 Thread Kottiyath
Hi,
   There seems to be lot of spam coming in this newsgroup.
   Is it possible to have some mechanism similar to say - slashdot -
wherein mails can be moderated by any of the usual users?
   This is required only for people who is posting for the first time
(or people who has been rated spam before). Second post onwards, no
moderation required.
Just wondering.

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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread W. eWatson

W. eWatson wrote:
As with Diez, I simply ask, "How do I get around the problem?" Are you 
two telling me that it is impossible?


OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and 
have  good familiarity with Tkinter? If so, I'll send you the code and 
you can try it yourself. My guess is that it will work, and if not, and 
you are sufficiently skilled with Tkinter and debugging, you may find 
the problem in the code. The steps to create the problem are very easy.


Well, this may be a bit trickier than I thought. I'd have to give you the 
same PIL, tkinter, numpy libraries the program users. However, I"m willing 
to send the files for them to you. Here's the start of the code


=
from Tkinter import *
from numpy import *
import Image
import ImageChops
import ImageTk
import ImageDraw # wtw
import time
import binascii
import tkMessageBox
import tkSimpleDialog
from pylab import plot, xlabel, ylabel, title, show, xticks, bar

from tkFileDialog import asksaveasfilename, asksaveasfile
from tkFileDialog import askopenfilename

import MakeQTE
===
You'd also need clut.txt, wagon.gif, and MakQTE. All small files.

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7" N, 121° 2' 32" W, 2700 feet

Web Page: 

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


Re: Spam

2009-02-12 Thread Stephen Hansen
>   There seems to be lot of spam coming in this newsgroup.
>   Is it possible to have some mechanism similar to say - slashdot -
> wherein mails can be moderated by any of the usual users?
>   This is required only for people who is posting for the first time
> (or people who has been rated spam before). Second post onwards, no
> moderation required.
>Just wondering.

C.P.L is an unmoderated newsgroup: so there's no content controls on
posts. I don't think that's possible to change. But I haven't gotten
directly near a newsgroup-as-a-newsgroup in eons, so I may be wrong.

If you subscribe to C.P.L as a mailing list instead of a newsgroup, I
believe most of the spam gets filtered out at the mailing list<->news
group gateway by the Python.org spam filters... At least no spam in my
Gmail spam folder appears to be flagged from this group(at a very
brief glance) so they appear to be doing quite well.

http://mail.python.org/mailman/listinfo/python-list is the list
subscription page.

(C.P.L and python-list are essentially the same thing: things posted
to the list get forwarded to the newsgroup, and vice-versa)

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


Re: Spam

2009-02-12 Thread Stephen Hansen
> C.P.L

C.L.P even.

Ahem.

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


Re: Embarrasing questio

2009-02-12 Thread MRAB

Michele Simionato wrote:

On Feb 12, 5:07 pm, TechieInsights  wrote:

On Feb 12, 9:03 am, Catherine Heathcote

 wrote:

But I just cant find it. How do I do an or, as in c/c++'s ||? Just
trying to do something simple, the python equivilent of:
if(i % 3 == 0 || i % 5 == 0)
Thanks.

in 2.5 and above you can do
if any(i%3 == 0, i%5 == 0)


You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but
the idiomatic solution is to use or).


any() is really only useful with a generator, otherwise you're always
evaluating both conditions, unlike the solution with 'or'.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Spam

2009-02-12 Thread Tim Chase

If you subscribe to C.P.L as a mailing list instead of a
newsgroup, I believe most of the spam gets filtered out at the
mailing list<->news group gateway by the Python.org spam
filters... At least no spam in my Gmail spam folder appears to
be flagged from this group(at a very brief glance) so they
appear to be doing quite well.


Allow  me to take this opportunity to thank the folks that *are* 
doing/managing this spam-filtering of the mailing list side of 
things -- the drastic drop in spam (from 6+ months back) is much 
appreciated!


Though I guess this thread does beg the question:  is there a way 
to read the filtered mailing list with a newsreader (via NNTP) 
instead of getting it delivered via email or subjecting oneself 
to the spamminess of c.l.p?  I like some of the "kill-thread" 
types of options I've got on the NNTP side of readers that aren't 
as readily available to me on the email side of things 
(Thunderbird allows for thread-kills in News, but not in email).


-tkc




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


Re: Avoiding argument checking in recursive calls

2009-02-12 Thread Terry Reedy

Steven D'Aprano wrote:

On Wed, 11 Feb 2009 04:31:10 -0500, Terry Reedy wrote:


Steven D'Aprano  writes:

def fact(n):
if n < 0: raise ValueError
if n = 0: return 1
return fact(n-1)*n

At the risk of premature optimization, I wonder if there is an idiom
for avoiding the unnecessary test for n <= 0 in the subsequent
recursive calls?

Reverse the test order

def fact(n):
 if n > 0: return fact(n-1)*n
 if n == 0: return 1
 raise ValueError

You must test recursive versus terminal case every call in any case.
Nearly always, the first test passes and second is not done. You only
test n==0 once, either to terminate or raise exception. This works for
any integral value and catches non-integral values. (There is some delay
for that, but only bad calls are penalized.)


Nice try, but in fact no.


I meant non-integral numbers.  Others inputs are outside the usual spec 
for fact().  You asked about "an idiom for avoiding the unnecessary test 
for n <= 0 in the subsequent recursive calls?" and I gave you that.  You 
should have thanked me.



fact(None)  # works okay

Traceback (most recent call last):
  File "", line 1, in 
  File "", line 4, in fact
ValueError

fact({})

Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in fact
TypeError: unsupported operand type(s) for -: 'dict' and 'int'

You're relying on arbitrary ordering of types in Python 2.x,


No I'm not.  I don't even know what you mean by that claim.


and of course in Python 3 that fails altogether.


In 3.0, which is what I use, the comparison 'n>0' raises an exception 
for non-numbers, as it should.  To me, that is success.  What else would 
you want?


Terry Jan Reedy

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


Re: zlib interface semi-broken

2009-02-12 Thread Travis
So I've submitted a patch to bugs.python.org to add a new member
called is_finished to the zlib decompression object.

Issue 5210, file 13056, msg 81780
-- 
Crypto ergo sum.  http://www.subspacefield.org/~travis/
Do unto other faiths as you would have them do unto yours.
If you are a spammer, please email [email protected] to get blacklisted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Read Only attributes, auto properties and getters and setters

2009-02-12 Thread TechieInsights
Ok... for some closure I have written a class to automate the
process.  It takes getters and setters and deleters and then sets the
property automatically.  Sweet!


class AutoProperty(type):
def __new__(cls, name, bases, methoddict):
processed = []
getter = 'get_'
setter = 'set_'
deleter = 'del_'

starters = {getter:PropertyAttr(getter, PropertyAttr.FGET),
setter:PropertyAttr(setter, 
PropertyAttr.FSET),
deleter:PropertyAttr(deleter, 
PropertyAttr.FDEL)
}
for key, value in methoddict.items():
var = None
for start in starters.keys():
if key.startswith(start):
var = key[len(start):]
break
if var is None or var in processed:
continue
property_values = []

for start in starters.keys():
if '%s%s' %(start, var) in methoddict.keys():

property_values.append(starters[start].tostring(var))
else:

property_values.append(starters[start].tostring(None))
property_map = 'methoddict["%s"] = property(%s)' %(var, 
','.join
(property_values))
exec(property_map)
return type.__new__(cls, name, bases, methoddict)

class PropertyAttr(object):
FGET = 'fget'
FSET = 'fset'
FDEL = 'fdel'
def __init__(self, start, type = FGET):
self.start = start
self.type = type

def tostring(self, var):
if self.type == self.FSET:
vars = ['v']
else:
vars = []
fullvar = ['self'] + vars
if var is None:
return '%s=None' %(self.type)
return '%s=lambda %s: self.%s%s(%s)' %(self.type, 
','.join(fullvar),
self.start, var, ','.join(vars))

class ReadOnly(object):
__metaclass__ = AutoProperty


class MyClass(ReadOnly):
def __init__(self, x, y):
self.__x = x
self.__y = y

def get_x(self):
return self.__x

def set_x(self, x):
self.__x = x

def get_y(self):
return self.__y

mc = MyClass(10, 100)
print mc.x, mc.y
mc.x = 10
print mc.x
try:
mc.y = 100
except AttributeError:
print 'Yea it worked!'

try:
del mc.y
except AttributeError:
print "It's read only!"

And the output:
10 100
10
Yea it worked!
It's read only!


Now to work on descriptors doing it for you.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Spam

2009-02-12 Thread TechieInsights
On Feb 12, 10:23 am, Tim Chase  wrote:
> > If you subscribe to C.P.L as a mailing list instead of a
> > newsgroup, I believe most of the spam gets filtered out at the
> > mailing list<->news group gateway by the Python.org spam
> > filters... At least no spam in my Gmail spam folder appears to
> > be flagged from this group(at a very brief glance) so they
> > appear to be doing quite well.
>
> Allow  me to take this opportunity to thank the folks that *are*
> doing/managing this spam-filtering of the mailing list side of
> things -- the drastic drop in spam (from 6+ months back) is much
> appreciated!
>
> Though I guess this thread does beg the question:  is there a way
> to read the filtered mailing list with a newsreader (via NNTP)
> instead of getting it delivered via email or subjecting oneself
> to the spamminess of c.l.p?  I like some of the "kill-thread"
> types of options I've got on the NNTP side of readers that aren't
> as readily available to me on the email side of things
> (Thunderbird allows for thread-kills in News, but not in email).
>
> -tkc

Enhancement request for google: hide messages by a certain author

it would be individually set, but can get rid of a lot of junk at
once.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Match items in large list

2009-02-12 Thread Terry Reedy

Fisherking wrote:

Hi,

I hope you can help me with this optimizing problem!
I have a large list of dictionaries (about 250 000 of them). Two or
more of these dictionaries contains the same data (not more than five
or six of them per item) e.g. [{'a':1,'b':'2','c':3} , {'d':
4,'e':'5','f':6},{'a':1,'b':'2','c':3} , {'d':4,'e':'5','f':6},...].
(the dictionaries are really containg phone numbers, duration time and
call time.)

Which are the best way of searching through the list and extract the
items that are the same. In the first run I want to find every item
that are the same as {'a':1,'b':'2','c':3}, the second {'d':
4,'e':'5','f':6} etc. The list are not read-only and I can pop them
out of the list when I have found them!


Popping items out of the middle of a list is a slow O(n) operation.
MRAB's set of tuples is what I would have suggested.



(How can I found items that are almost the same? e.g. {'a':
1,'b':'2','c':3.1} and {'a':1,'b':'2','c':3.2} )

In the second part of this program I need to take each of these items
(similar items are treated as one) and find these in a database that
contains 2.5M posts!

The python version I am bound to is Python 2.3


For that, dict of tuples (with fake value == None) might be faster than 
the add-on set module.


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


how to distribute python extensions independently of python

2009-02-12 Thread Travis
So,

Recently I made a fix to the zlib module that I need for use at work.

I would like other employees to be able to use it without recompiling python.

I assume I can just rename it and distribute it as a python extension.

I was wondering how I can provide a way for other employees to build it.

I saw a "Universal Unix Makefile for Python extensions" that looks promising.

Is this the accepted way to compile python extensions still?
-- 
Crypto ergo sum.  http://www.subspacefield.org/~travis/
Do unto other faiths as you would have them do unto yours.
If you are a spammer, please email [email protected] to get blacklisted.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread Diez B. Roggisch
W. eWatson wrote:

> As with Diez, I simply ask, "How do I get around the problem?" Are you two
> telling me that it is impossible?

YES. That's what we and all the others who answered to you in the other
thread are telling you, repeatedly. It is impossible. Really. No kidding.
For sure. Jawoll, ganz sicher sogar.

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


Re: Spam

2009-02-12 Thread andrew cooke

A quick search on "imap nntp" turned up this list that might be useful -
http://deflexion.com/messaging/ although I wonder when it was written
because I remember using Aaron's RSS to email aggregator when RSS was
new(!).

It mentions gmane, though, which certainly still exists (I assume it
carries this list too).  And this page suggests you can read gmane via
nntp - http://reticule.gmane.org/

Aha!  yes!  It;s in the FAQ :o)

  Can I read news via secure NNTP (nntps)?
  Yes. Point your news reader towards nntps://snews.gmane.org/.

http://www.gmane.org/faq.php

I should be working; I will try that this evening.  What was the name of
the client that threaded messages with a cute ascii tree?!

Cheers,
Andrew


Tim Chase wrote:
> Though I guess this thread does beg the question:  is there a way
> to read the filtered mailing list with a newsreader (via NNTP)


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


Re: Embarrasing questio

2009-02-12 Thread Michele Simionato
On Feb 12, 6:22 pm, MRAB  wrote:
> Michele Simionato wrote:
> > On Feb 12, 5:07 pm, TechieInsights  wrote:
> >> On Feb 12, 9:03 am, Catherine Heathcote
>
> >>  wrote:
> >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just
> >>> trying to do something simple, the python equivilent of:
> >>> if(i % 3 == 0 || i % 5 == 0)
> >>> Thanks.
> >> in 2.5 and above you can do
> >> if any(i%3 == 0, i%5 == 0)
>
> > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but
> > the idiomatic solution is to use or).
>
> any() is really only useful with a generator, otherwise you're always
> evaluating both conditions, unlike the solution with 'or'.

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


Re: how to distribute python extensions independently of python

2009-02-12 Thread andrew cooke

You might want to read
https://www.dfwpython.org/repo/Presentations/2008-10-04-PyArkansas-PythonEggsIntro/eggs-introduction.pdf

It covers a lot of ground; I used it to work out how to distribute a pure
Python package, but I am sure it mentions compiled packages too.  In my
case I ended up using setuptools (easy_install) and distutils.

(Not sure if you asking just about compiling, or more general packaging,
but IIRC it covers both).

Andrew


Travis wrote:
> So,
>
> Recently I made a fix to the zlib module that I need for use at work.
>
> I would like other employees to be able to use it without recompiling
> python.
>
> I assume I can just rename it and distribute it as a python extension.
>
> I was wondering how I can provide a way for other employees to build it.
>
> I saw a "Universal Unix Makefile for Python extensions" that looks
> promising.
>
> Is this the accepted way to compile python extensions still?
> --
> Crypto ergo sum.  http://www.subspacefield.org/~travis/
> Do unto other faiths as you would have them do unto yours.
> If you are a spammer, please email [email protected] to get
> blacklisted.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


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


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread Scott David Daniels

W. eWatson wrote:
As with Diez, I simply ask, "How do I get around the problem?" Are you 
two telling me that it is impossible?


OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and 
have  good familiarity with Tkinter? If so, I'll send you the code and 
you can try it yourself. My guess is that it will work, and if not, and 
you are sufficiently skilled with Tkinter and debugging, you may find 
the problem in the code. The steps to create the problem are very easy.


They are telling you the truth, and you are replying, "I don't
want to understand, I just want it to work."  They have shown great
forbearance.  The only time I have debugged any Tkinter code in IDLE,
I have start with "python -m idlelib.idle -n" and accepted the fact
that I will see crashes.  The one advantage of my technique is that
I can hand-execute single Tkinter operations and see the results
immediately since I am running piggyback on IDLE's main loop.

Once more, though I'm sure you don't want to hear it:
Normally IDLE starts as a program running that talks to the user
(idle.py). It starts a separate process that talks to the user interface
over a TCP/IP port and does the things inside the shell (for
example the expression evaluation).  When you use the command
"Shell / Restart Shell," the process that interacts with your program
is wiped out and new process is started (I think, perhaps they simply
flush almost everything and restart).  The reason only one IDLE session
can live at a time is that a TCP/IP communication port has only two
ends.  If you don't kill _all_ of the pythonw processes, something will
go wrong in the initial setting up the parent/child processes.

Similarly, a GUI is not a library, but a framework.  The GUI itself
is the main program (run after you do some setup) that calls parts of
your program as subroutines.  You have a problem when you use a GUI to
debug another GUI (there can be only _one_ main program).  It does no
good to stomp your foot and proclaim that you want it to work.
Sometimes your code doesn't interfere too badly with IDLE's GUI, so it
looks as if you have gotten away with it.  For example, in-process IDLE
(the "-n" flag) fiddles with the Tkinter environment in an attempt to
reduce the conflict between IDLE's and your program's use of the GUI.

The only solutions I've seen for debugging GUIs involve separated
processes (even more so than IDLE), running on separate machines.
With those, you don't share a keyboard, mouse, or display between
the debugger and the program under test.  Such solutions are available
for a price.  ActiveState, for example, sells one.

The issue in each case is sharing things that the programs have
every right to expect that they "own."  To wit, Display refresh points,
the main program, the keyboard, tcp/ip ports, the mouse.

--Scott David Daniels
[email protected]
--
http://mail.python.org/mailman/listinfo/python-list


something wrong with isinstance

2009-02-12 Thread maksym . kaban
Hi there.
now i'm a complete newbie for python, and maybe my problem is stupid
but i cannot solve it myself

i have an object of class GeoMap which contains lists with objects of
GeoMapCell (i will not explain what they should do, hope its not
important). Then i want to serialize these objects to json notation.
So i imported json module and as shown in docs for it extended
JSONEncoder class.  Look at the code below

##main module
from worldmap import GeoMap, GeoMapCell

import testdata
import json

class GeoMapEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, GeoMap):
return None
return json.JSONEncoder.default(self, obj)

def main():
print(json.dumps(2 + 5j, cls=ComplexEncoder))

geomap = testdata.createTestMap()
print(json.dumps(geomap, cls=GeoMapEncoder))
pass

if __name__ == '__main__':
main()

===

##worldmap module
class GeoMap:
cells = []
activerow = 0
activecol = 0

def addCell(self, acell):
if len(self.cells) == 0:
  self.cells.append([])
  self.activerow = 0
acell.col = self.activerow
acell.row = self.activecol
self.cells[self.activerow].append(acell)
self.activecol += 1

def addRow(self):
self.cells.append([])
self.activerow += 1;
self.activecol = 0;

class GeoMapCell:
neighbours = (None, None, None, None, None, None, )
col = 0
row = 0

The problem is in here.

class GeoMapEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, GeoMap):  ## <===   isinstance doesnot
work as i expected
return None
return json.JSONEncoder.default(self, obj)

 Though obj is object of GeoMap class, isinstance returns False. Where
was i mistaken. If i shouldn't use isinstance, then what function
would check class of object?

Oh, maybe its important. I'm working on WinXP SP3, Python 3.0, IDE -
PyScript
--
http://mail.python.org/mailman/listinfo/python-list


Re: Untangling pythonWin and IDLE Processes on XP Pro

2009-02-12 Thread Terry Reedy

W. eWatson wrote:
As with Diez, I simply ask, "How do I get around the problem?" Are you 
two telling me that it is impossible?


Try this analogy.  One television, two stubborn kids that want to watch 
different programs.  One has the remote, the other the buttons on the 
TV.  What happens?  How do you make both happy.  Solve that and get rich 
;-).


Even better analogy.  One inbox.  Two people on opposite sides each want 
'first dibs' on each item that drops.  How do you make them both happy, 
especially if they are equally stubborn clones?



OK, here's my offer to both of you. Do you have IDLE for Python 2.5 and 
have  good familiarity with Tkinter? If so, I'll send you the code and 
you can try it yourself. My guess is that it will work, and if not, and 
you are sufficiently skilled with Tkinter and debugging, you may find 
the problem in the code. The steps to create the problem are very easy.


That is a request, not an offer.

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


Re: Embarrasing questio

2009-02-12 Thread Hrvoje Niksic
Michele Simionato  writes:

> On Feb 12, 6:22 pm, MRAB  wrote:
>> Michele Simionato wrote:
>> > On Feb 12, 5:07 pm, TechieInsights  wrote:
>> >> On Feb 12, 9:03 am, Catherine Heathcote
>>
>> >>  wrote:
>> >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just
>> >>> trying to do something simple, the python equivilent of:
>> >>> if(i % 3 == 0 || i % 5 == 0)
>> >>> Thanks.
>> >> in 2.5 and above you can do
>> >> if any(i%3 == 0, i%5 == 0)
>>
>> > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but
>> > the idiomatic solution is to use or).
>>
>> any() is really only useful with a generator, otherwise you're always
>> evaluating both conditions, unlike the solution with 'or'.
>
> Indeed.

any(f() for f in (lambda: i % 3 == 0, lambda: i % 5 == 0))

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


Re: Spam

2009-02-12 Thread Grant Edwards
On 2009-02-12, andrew cooke  wrote:

>   Can I read news via secure NNTP (nntps)?
>   Yes. Point your news reader towards nntps://snews.gmane.org/.
>
> http://www.gmane.org/faq.php
>
> I should be working; I will try that this evening.  What was the name of
> the client that threaded messages with a cute ascii tree?!

slrn?

-- 
Grant Edwards   grante Yow! How's the wife?
  at   Is she at home enjoying
   visi.comcapitalism?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Spam

2009-02-12 Thread andrew cooke
Grant Edwards wrote:
>> I should be working; I will try that this evening.  What was the name of
>> the client that threaded messages with a cute ascii tree?!
>
> slrn?

i think i was remembering trn, which is now apparently dead.  will try
slrn...  thanks, andrew


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


Help: makefile in Windows

2009-02-12 Thread Muddy Coder
Hi Folks,

I am learning Extending Python, by testing the demo script of
Programming Python. In the book, a makefile for Linux is there, but I
am using Windows currently. I wish somebody would help me to get a
makefile for Windows, my makefile.linux is as below:

PYDIR= c:\Python25
PY = $(PYDIR)

hello.so: hello.c
gcc hello.c -g -I$(PY)/include -I$(PY) -fpic -share -o
hello.so
clean:
   rm hello.so core



Thanks a lot!


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


Re: Read Only attributes, auto properties and getters and setters

2009-02-12 Thread josh logan
On Feb 12, 12:27 pm, TechieInsights  wrote:
> Ok... for some closure I have written a class to automate the
> process.  It takes getters and setters and deleters and then sets the
> property automatically.  Sweet!
>
> class AutoProperty(type):
>         def __new__(cls, name, bases, methoddict):
>                 processed = []
>                 getter = 'get_'
>                 setter = 'set_'
>                 deleter = 'del_'
>
>                 starters = {getter:PropertyAttr(getter, PropertyAttr.FGET),
>                                         setter:PropertyAttr(setter, 
> PropertyAttr.FSET),
>                                         deleter:PropertyAttr(deleter, 
> PropertyAttr.FDEL)
>                                         }
>                 for key, value in methoddict.items():
>                         var = None
>                         for start in starters.keys():
>                                 if key.startswith(start):
>                                         var = key[len(start):]
>                                         break
>                         if var is None or var in processed:
>                                 continue
>                         property_values = []
>
>                         for start in starters.keys():
>                                 if '%s%s' %(start, var) in methoddict.keys():
>                                         
> property_values.append(starters[start].tostring(var))
>                                 else:
>                                         
> property_values.append(starters[start].tostring(None))
>                         property_map = 'methoddict["%s"] = property(%s)' 
> %(var, ','.join
> (property_values))
>                         exec(property_map)
>                 return type.__new__(cls, name, bases, methoddict)
>
> class PropertyAttr(object):
>         FGET = 'fget'
>         FSET = 'fset'
>         FDEL = 'fdel'
>         def __init__(self, start, type = FGET):
>                 self.start = start
>                 self.type = type
>
>         def tostring(self, var):
>                 if self.type == self.FSET:
>                         vars = ['v']
>                 else:
>                         vars = []
>                 fullvar = ['self'] + vars
>                 if var is None:
>                         return '%s=None' %(self.type)
>                 return '%s=lambda %s: self.%s%s(%s)' %(self.type, 
> ','.join(fullvar),
> self.start, var, ','.join(vars))
>
> class ReadOnly(object):
>         __metaclass__ = AutoProperty
>
> class MyClass(ReadOnly):
>         def __init__(self, x, y):
>                 self.__x = x
>                 self.__y = y
>
>         def get_x(self):
>                 return self.__x
>
>         def set_x(self, x):
>                 self.__x = x
>
>         def get_y(self):
>                 return self.__y
>
> mc = MyClass(10, 100)
> print mc.x, mc.y
> mc.x = 10
> print mc.x
> try:
>         mc.y = 100
> except AttributeError:
>         print 'Yea it worked!'
>
> try:
>         del mc.y
> except AttributeError:
>         print "It's read only!"
>
> And the output:
> 10 100
> 10
> Yea it worked!
> It's read only!
>
> Now to work on descriptors doing it for you.

I think I'll stick with the built-in, Thanks :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: something wrong with isinstance

2009-02-12 Thread Paul McGuire
On Feb 12, 11:53 am, [email protected] wrote:
> Hi there.
> now i'm a complete newbie for python, and maybe my problem is stupid
> but i cannot solve it myself
>
> i have an object of class GeoMap which contains lists with objects of
> GeoMapCell (i will not explain what they should do, hope its not
> important). Then i want to serialize these objects to json notation.
> So i imported json module and as shown in docs for it extended
> JSONEncoder class.  Look at the code below
>
> ##main module
> from worldmap import GeoMap, GeoMapCell
>
> import testdata
> import json
>
> class GeoMapEncoder(json.JSONEncoder):
>     def default(self, obj):
>         if isinstance(obj, GeoMap):
>             return None
>         return json.JSONEncoder.default(self, obj)
>
> def main():
>     print(json.dumps(2 + 5j, cls=ComplexEncoder))
>
>     geomap = testdata.createTestMap()
>     print(json.dumps(geomap, cls=GeoMapEncoder))
>     pass
>
> if __name__ == '__main__':
>     main()
>
> ===
>
> ##worldmap module
> class GeoMap:
>     cells = []
>     activerow = 0
>     activecol = 0
>
>     def addCell(self, acell):
>         if len(self.cells) == 0:
>           self.cells.append([])
>           self.activerow = 0
>         acell.col = self.activerow
>         acell.row = self.activecol
>         self.cells[self.activerow].append(acell)
>         self.activecol += 1
>
>     def addRow(self):
>         self.cells.append([])
>         self.activerow += 1;
>         self.activecol = 0;
>
> class GeoMapCell:
>     neighbours = (None, None, None, None, None, None, )
>     col = 0
>     row = 0
>
> The problem is in here.
>
> class GeoMapEncoder(json.JSONEncoder):
>     def default(self, obj):
>         if isinstance(obj, GeoMap):  ## <===   isinstance doesnot
> work as i expected
>             return None
>         return json.JSONEncoder.default(self, obj)
>
>  Though obj is object of GeoMap class, isinstance returns False. Where
> was i mistaken. If i shouldn't use isinstance, then what function
> would check class of object?
>
> Oh, maybe its important. I'm working on WinXP SP3, Python 3.0, IDE -
> PyScript

Here's a crazy idea out of left field.  Just before calling
isinstance, why not try:

print(type(obj))
print(str(obj))

This may illuminate the unexpected behavior, you'll find out just what
obj has in it.

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


Re: Spam

2009-02-12 Thread Aahz
In article ,
andrew cooke  wrote:
>Grant Edwards wrote:
>>> I should be working; I will try that this evening.  What was the name of
>>> the client that threaded messages with a cute ascii tree?!
>>
>> slrn?
>
>i think i was remembering trn, which is now apparently dead.  will try
>slrn...  thanks, andrew

trn 3.6 works fine for me ... just as it has for almost twenty years.
-- 
Aahz ([email protected])   <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.
--
http://mail.python.org/mailman/listinfo/python-list


Get an image from a webcam in macOS

2009-02-12 Thread Jonathan Chacón
Hello,
 
I can get an Image from a webcam in windows but I don't know how can I
get an image from the webcam in a macbook in leopard.
 
How can I do this?
 
thanks and regards
Jonathan Chacón
--
http://mail.python.org/mailman/listinfo/python-list


how many databases exists?

2009-02-12 Thread Rosell Pupo Polanco
hello, i am working in pythoncard and i need to know how many databases exist 
in my server POstgresql, exists some funcion in python that can help me??

greettings..Rosell



.::[ La vida es rica en saberes, pero la vida es breve y no se vive, si no se 
sabe. ]::.
--
http://mail.python.org/mailman/listinfo/python-list


Capture images in macOS X

2009-02-12 Thread Jonathan Chacón
Hello,

I need to capture images from the macbook webcam in leopard.
Does anybody know how can I do this?

Thanks and regards
Jonathan Chacón

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


Library similar to UserAgent (perl)

2009-02-12 Thread mattia
Hi everybody, I'm looking for an easy way to put data in a form, then 
click the button and follow the redirect. Also I need to use cookies. I 
read that using perl this can be done using the UserAgent lib, that also 
provide th browser functionality to let the site believe that you are 
getting the pages from a normali browser like ff. Any suggestion? I think 
that the main concen is to easilly put the data in the numerous textlabel 
provided and then magically simulate the 'click me' button.
--
http://mail.python.org/mailman/listinfo/python-list


__import__ Confusion

2009-02-12 Thread scott . bronson . nelson
Can someone explain to me what's going on here?

>>> __import__('some.package.module', {}, {}, [])

>>> __import__('some.package.module', {}, {}, [''])


(Note that '' is two single quotes)

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


Re: something wrong with isinstance

2009-02-12 Thread maksym . kaban
> Here's a crazy idea out of left field.  Just before calling
> isinstance, why not try:
>
> print(type(obj))
> print(str(obj))
>
> This may illuminate the unexpected behavior, you'll find out just what
> obj has in it.
>
> -- Paul

Well the output of
> print(type(obj))
> print(str(obj))

was




Just looks well, isn't it? i have no idea what's wrong
--
http://mail.python.org/mailman/listinfo/python-list


Re: openOffic, windows, and Python 2.5

2009-02-12 Thread Terry Reedy

John Fabiani wrote:

Terry Reedy wrote:


John Fabiani wrote:

Hi,
OpenOffice 3 on windows uses python 2.3.x (I have no idea why).

I presume because no one has volunteered to do the update for the Py-UNO
bridge.  In any case, why do you consider that to be a problem.  It is
common for apps to include the Python they are known to work with.

tjr


Thanks for the response.  The reason is the others apps are written in
python 2.5.x.  All the testing was done on Linux using 2.5 and now we need
it to work on the windows side too.  


Have you tried it?  What breaks?  Win OOo's use of 2.3 should only 
affect Python code that you run within the OO process itself, with its 
copy of Python.  Avoiding things introduced in 2.4/2.5 is probably 
easier than recompiling OOo on Windows.


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


Re: something wrong with isinstance

2009-02-12 Thread redbaron
Don't really sure, but try to define your class as new-style one.
Like
class GeoMap(object):
   ...

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


is there a project running (GUI Builder for Python ) ?

2009-02-12 Thread azrael
To be honest, in compare to Visual Studio, Gui Builders for wx widgets
are really bad. Also completly for python there is not one good
GuiBuilder. The only one I have seen that would come near VS was
BoaConstructor, But the number of Bugs is just horrific. Too bad that
no one is developing it further.

Do you know if there is any project curently running for GUI builders,
maybe for WX, That I could maybe join.
--
http://mail.python.org/mailman/listinfo/python-list


Re: __import__ Confusion

2009-02-12 Thread Benjamin Peterson
  gmail.com> writes:

> 
> Can someone explain to me what's going on here?
> 
> >>> __import__('some.package.module', {}, {}, [])
> 
> >>> __import__('some.package.module', {}, {}, [''])
> 

As documented [1], unless fromlist is not empty, the first module is returned.
Use the solution at the end of the docs to get around this.


[1] http://docs.python.org/library/functions.html#__import__

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


Re: cx_Oracle-5.0 Problem

2009-02-12 Thread Brandon Taylor
On Feb 12, 9:31 am, redbaron  wrote:
> > ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.6/
> > lib/python2.6/site-packages/cx_Oracle.so, 2): Symbol not found:
> > ___divdi3
>
> You didn't link cx_Oracle.so all libs which it use. run "ldd -r
> cx_Oracle.so" and you'll have an idea about all missing symbols. The
> names of missed symbols could give you an idea what else should
> cx_Oracle.so should be linked with

We are getting a "command not found" error for the ldd command in OS X
10.5.6

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


Re: is there a project running (GUI Builder for Python ) ?

2009-02-12 Thread J Kenneth King
azrael  writes:

> To be honest, in compare to Visual Studio, Gui Builders for wx
> widgets are really bad.

That's because Visual Studio is a Microsoft product to build
interfaces for Microsoft products.

wx on the other hand is cross platform and ergo, much more
complicated.

> Do you know if there is any project curently running for GUI
> builders, maybe for WX, That I could maybe join.

You could help wx. Make your own gui builder if you think you could do
better. There's also GTK and Qt... and probably many others.
--
http://mail.python.org/mailman/listinfo/python-list


need help from some one who uses python-ooolib

2009-02-12 Thread Krishnakant
hello all,
Has any one used python-ooolib to create open office spreadsheets?
I want to know the method of merging cells using the library's calc
class.
happy hacking.
Krishnakant.


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


Re: Spam

2009-02-12 Thread Terry Reedy

andrew cooke wrote:

A quick search on "imap nntp" turned up this list that might be useful -
http://deflexion.com/messaging/ although I wonder when it was written
because I remember using Aaron's RSS to email aggregator when RSS was
new(!).

It mentions gmane, though, which certainly still exists (I assume it
carries this list too).


Yes.  For everything possible, I read and post via gmane.  Gmane mirrors 
technical mailing lists.  As near as I can tell, posts via gmane go to 
the mailing list first, for whatever filtering the list does. 
Conversely then, gmane only posts the filtered output from the mailing list.


>  And this page suggests you can read gmane via

nntp - http://reticule.gmane.org/


news.gmane.org works fine.


Aha!  yes!  It;s in the FAQ :o)

  Can I read news via secure NNTP (nntps)?
  Yes. Point your news reader towards nntps://snews.gmane.org/.

http://www.gmane.org/faq.php


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


Re: is there a project running (GUI Builder for Python ) ?

2009-02-12 Thread Stef Mientki

azrael wrote:

To be honest, in compare to Visual Studio, Gui Builders for wx widgets
are really bad. Also completly for python there is not one good
GuiBuilder. The only one I have seen that would come near VS was
BoaConstructor, But the number of Bugs is just horrific. Too bad that
no one is developing it further.

Do you know if there is any project curently running for GUI builders,
maybe for WX, That I could maybe join.
--
http://mail.python.org/mailman/listinfo/python-list
  
Well I come from Delphi, and compared to Delphi, even Visual Studio 
vanishes ;-)

I also tried to start with wxGlad, Boa, XRC 
... but they were full of bugs, or even couldn't be started.
The best seems to be PyQt, but the license is (still) terrible (and 
maybe only their stories are much better than the real result ;-).

I didn't try XRC, because I found it much too difficult,
but instead I wrote a small program,
making a much easier version of the XRC-idea.
And after a few months,
I don't even notice the difference between Delphi (which I'm still using)
and wxPython.

I think this story happened to other people to,
so instead of putting a lot of effort in designing and maintaining a GUI 
builders,

it might be better to choose another solution.

btw, the idea I used, can be seen here]
http://mientki.ruhosting.nl/data_www/pylab_works/pw_gui_support.html
and the code can be found here
http://code.google.com/p/pylab-works/downloads/list

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


Re: Spam

2009-02-12 Thread Terry Reedy

Terry Reedy wrote:

andrew cooke wrote:

A quick search on "imap nntp" turned up this list that might be useful -
http://deflexion.com/messaging/ although I wonder when it was written
because I remember using Aaron's RSS to email aggregator when RSS was
new(!).

It mentions gmane, though, which certainly still exists (I assume it
carries this list too).


Yes.  For everything possible, I read and post via gmane.  Gmane mirrors 
technical mailing lists.  As near as I can tell, posts via gmane go to 
the mailing list first, for whatever filtering the list does. Conversely 
then, gmane only posts the filtered output from the mailing list.


 >  And this page suggests you can read gmane via

nntp - http://reticule.gmane.org/


news.gmane.org works fine.


Aha!  yes!  It;s in the FAQ :o)

  Can I read news via secure NNTP (nntps)?
  Yes. Point your news reader towards nntps://snews.gmane.org/.

http://www.gmane.org/faq.php


I just switched my Thunderbird gmane account to snews... and [x] use ssl 
and it seems to work ok.  It did, however, reset everything to unread.


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


Can't load smtplib

2009-02-12 Thread S-boy
I can't seem to import smtplib in either a script or the command line
interpreter.

When I try to import smtp, there seems to be some kind of collision
with urllib2. I get a weird error about Web server authorization, even
though I'm not calling urllib2.

Any ideas on what might be causing this?

Here's the mess

Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin

>>> import smtplib

Traceback (most recent call last):
  File "", line 1, in 
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/smtplib.py", line 46, in 
import email.Utils
  File "email.py", line 4, in 
response = urlopen("https://webmail.canwest.com";)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 387, in open
response = meth(req, response)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 498, in http_response
'http', request, response, code, msg, hdrs)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 425, in error
return self._call_chain(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 506, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires
authorization to fulfill the request. Access to the Web server is
denied. Contact the server administrator.  )
--
http://mail.python.org/mailman/listinfo/python-list


Re: Can't load smtplib

2009-02-12 Thread Jean-Paul Calderone

On Thu, 12 Feb 2009 11:40:57 -0800 (PST), S-boy  wrote:

I can't seem to import smtplib in either a script or the command line
interpreter.

When I try to import smtp, there seems to be some kind of collision
with urllib2. I get a weird error about Web server authorization, even
though I'm not calling urllib2.

Any ideas on what might be causing this?

Here's the mess

Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin


import smtplib


Traceback (most recent call last):
 File "", line 1, in 
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/smtplib.py", line 46, in 
   import email.Utils
 File "email.py", line 4, in 


Ooops.  Here's your problem.  Notice how that's not 
/Library/Frameworks/Python.framework/Versions/2.5/lib/

python2.5/email/?  You have an "email" module that's obscuring the stdlib

email package.


   response = urlopen("https://webmail.canwest.com";)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 124, in urlopen
   return _opener.open(url, data)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 387, in open
   response = meth(req, response)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 498, in http_response
   'http', request, response, code, msg, hdrs)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 425, in error
   return self._call_chain(*args)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 360, in _call_chain
   result = func(*args)
 File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/urllib2.py", line 506, in http_error_default
   raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized ( The server requires
authorization to fulfill the request. Access to the Web server is
denied. Contact the server administrator.  )


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


Re: something wrong with isinstance

2009-02-12 Thread maksym . kaban
On 12 фев, 21:49, redbaron  wrote:
> Don't really sure, but try to define your class as new-style one.
> Like
> class GeoMap(object):
>    ...

Sorry, it didn't work
--
http://mail.python.org/mailman/listinfo/python-list


Re: something wrong with isinstance

2009-02-12 Thread Paul McGuire
On Feb 12, 12:26 pm, [email protected] wrote:
>
> Well the output of
>
> > print(type(obj))
> > print(str(obj))
>
> was
>
> 
> 
>
> Just looks well, isn't it? i have no idea what's wrong

So then how do you know isinstance is evaluating to False?  And why do
you return None if it evals to True?  Can you drop a print command
inside the if block just before returning None, and another print just
before returning the default default?

I also would recommend using a debugger like winpdb when in a spot
like this - despite the name, it is not Windows-only, and you can step
through this code and evaluate variables and expressions inline.

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


Re: something wrong with isinstance

2009-02-12 Thread Diez B. Roggisch

[email protected] schrieb:

Hi there.
now i'm a complete newbie for python, and maybe my problem is stupid
but i cannot solve it myself

i have an object of class GeoMap which contains lists with objects of
GeoMapCell (i will not explain what they should do, hope its not
important). Then i want to serialize these objects to json notation.
So i imported json module and as shown in docs for it extended
JSONEncoder class.  Look at the code below

##main module
from worldmap import GeoMap, GeoMapCell

import testdata
import json

class GeoMapEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, GeoMap):
return None
return json.JSONEncoder.default(self, obj)

def main():
print(json.dumps(2 + 5j, cls=ComplexEncoder))

geomap = testdata.createTestMap()
print(json.dumps(geomap, cls=GeoMapEncoder))
pass

if __name__ == '__main__':
main()

===

##worldmap module
class GeoMap:
cells = []
activerow = 0
activecol = 0

def addCell(self, acell):
if len(self.cells) == 0:
  self.cells.append([])
  self.activerow = 0
acell.col = self.activerow
acell.row = self.activecol
self.cells[self.activerow].append(acell)
self.activecol += 1

def addRow(self):
self.cells.append([])
self.activerow += 1;
self.activecol = 0;

class GeoMapCell:
neighbours = (None, None, None, None, None, None, )
col = 0
row = 0

The problem is in here.

class GeoMapEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, GeoMap):  ## <===   isinstance doesnot
work as i expected
return None
return json.JSONEncoder.default(self, obj)

 Though obj is object of GeoMap class, isinstance returns False. Where
was i mistaken. If i shouldn't use isinstance, then what function
would check class of object?

Oh, maybe its important. I'm working on WinXP SP3, Python 3.0, IDE -
PyScript



I think you have a common problem here that occurs when using a script 
with more that non-trivial contents as main-script.



What happens is this: you have a

__main__.GeoMap, which is the one tested against in isinstance.

*And* you have a .GeoMap (replace  with the 
actual name) that is imported & used from the other module.



A simple testscript illustrates the issue:


### test.py 

class Foo(object):
pass


if __name__ == "__main__":
   import test
   print Foo == test.Foo


Run it from inside the directory you saved it in.

To work around this issue, simply create a bootstrap-main-module that 
has not much in it.


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


Re: Capture images in macOS X

2009-02-12 Thread Diez B. Roggisch

Jonathan Chacón schrieb:

Hello,

I need to capture images from the macbook webcam in leopard.
Does anybody know how can I do this?


Use the pyobjc bridge & some ObjectiveC-framework such as 
CocoaSequenceGrabber.


http://www.skyfell.org/cocoasequencegrabber.html

There are similar ones out there.

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


  1   2   >