how to get full-text search of pysqlite3 work in python2.5.2

2008-10-30 Thread hawk
Hi,
my environment is debian, python 2.5.2.
when i call con.enable_load_extension(True), the following message
prompt out.
debian:~# python2.5
Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> con = sqlite3.connect(":memory:")
>>> con.enable_load_extension(True)
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'sqlite3.Connection' object has no attribute
'enable_load_extension'

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


Unicode Problem

2008-10-30 Thread Seid Mohammed
I am new to python.
I want to print Amharic character using the Python IDLE.
here goes somple code
==
>>> abebe = 'አበበ በሶ በላ'
>>> abebe
'\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0 \xe1\x89\xa0\xe1\x88\xb6
\xe1\x89\xa0\xe1\x88\x8b'
>>> print abebe
አበበ በሶ በላ
>>> abeba = ['አበበ','በሶ','በላ']
>>> abeba
['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
'\xe1\x89\xa0\xe1\x88\x8b']
>>> print abeba
['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
'\xe1\x89\xa0\xe1\x88\x8b']
>>> len(abebe)
23

so my question is
1)why >>> abebe prints  '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0
\xe1\x89\xa0\xe1\x88\xb6 \xe1\x89\xa0\xe1\x88\x8b' instead of አበበ በሶ
በላ
2) why >>> print abeba don't print the expected አበበ በሶ በላ string
thanks a lot.
Seid M.
--
http://mail.python.org/mailman/listinfo/python-list


urlencode() doseq and Python 3.0

2008-10-30 Thread Thomas Guettler
Hi,

I think the default of urlencode doseq being false is just
there to preserve the old behavior.


http://svn.python.org/view/python/branches/py3k/Lib/urllib/parse.py?rev=66199&sortby=date&view=markup

{{{
   ...
   if not doseq:
# preserve old behavior
}}}

I guess no one want really wants this:

>>> urllib.urlencode({'key': ['value1', 'value2']})
'key=%5B%27value1%27%2C+%27value2%27%5D'

I think this is what most people want:
>>> urllib.urlencode({'key': ['value1', 'value2']}, doseq=True)
'key=value1&key=value2'


Should I open a bug against 3.0?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unicode Problem

2008-10-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Oct 2008 10:28:39 +0300, Seid Mohammed wrote:

> I am new to python.
> I want to print Amharic character using the Python IDLE. here goes
> somple code
> ==
 abebe = 'አበበ በሶ በላ'
 abebe
> '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0 \xe1\x89\xa0\xe1\x88\xb6
> \xe1\x89\xa0\xe1\x88\x8b'
 print abebe
> አበበ በሶ በላ
 abeba = ['አበበ','በሶ','በላ'] abeba
> ['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
> '\xe1\x89\xa0\xe1\x88\x8b']
 print abeba
> ['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
> '\xe1\x89\xa0\xe1\x88\x8b']
 len(abebe)
> 23
> 
> so my question is
> 1)why >>> abebe prints  '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0
> \xe1\x89\xa0\xe1\x88\xb6 \xe1\x89\xa0\xe1\x88\x8b' instead of አበበ በሶ በላ
> 2) why >>> print abeba don't print the expected አበበ በሶ በላ string thanks
> a lot.

Because lists represent their content in the `repr()` form.  So you, the 
programmer, can see what's really in there.

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


Re: Fastest way to convert sql result into a dict or list ?

2008-10-30 Thread Peter Otten
Dennis Lee Bieber wrote:

> On Wed, 29 Oct 2008 04:35:31 -0700 (PDT), "[EMAIL PROTECTED]"
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
> 
>> Hello,
>> 
>> I'm trying to find the fastest way to convert an sql result into a
>> dict or list.
>> What i mean, for example:
>> my sql result:
>> contact_id, field_id, field_name, value
>> sql_result=[[1, 1, 'address', 'something street'],
>>  [1, 2, 'telnumber', '11'],
>>  [1, 3, 'email', '[EMAIL PROTECTED]'],
>>  [2, 1, 'address','something stree'],
>>  [2, 3, 'email','[EMAIL PROTECTED]']]
> 
> Off-hand, field_ID and field_name are equivalent and only one would
> be needed (either you know that "2" is a telnumber, or you just take the
> name directly).
> 
>> I hope there is an easyest way to do something like this ??
>> any idea ?
> 
> Let the database do it?
> 
> select
> c.contact_id as contact,
> c.value as address,
> t.value as telephone,
> e.value as email
> from thetable as c
> inner join thetable as t
> on c.contact_id = t.contact_id and c.field_id = 1 and t.field_id = 2
> inner join thetable as e
> on c.contact_id = e.contact_id and c.field_id = 1 and e.field_id= 3
> 
> If the join complains about the "= constant" clauses, try
> 
> select
> c.contact_id as contact,
> c.value as address,
> t.value as telephone,
> e.value as email
> from thetable as c
> inner join thetable as t
> on c.contact_id = t.contact_id
> inner join thetable as e
> on c.contact_id = e.contact_id
> where c.field_id = 1 and t.field_id = 2 and e.field_id = 3
> 
> (technically, the latter first finds all combinations
> 
> c.address, t.address, e.address
> c.address, t.address, e.telephone
> etc.
> 
> and then removes the results where c is not the address, t is not the
> phone, and e is not the email; doing them on the joins should mean a
> smaller intermediate result is generated)

You will lose contact information if you use an inner join and there are
contacts that lack fields (like contact #2 without a telephone number). Use
an outer join like in my (generated) sql to fix that and "distinct" to
suppress duplicate contact_id-s. The following should work with SQLite3:

select distinct 
c.contact_id, a.value as address, 
t.value as telnumber, 
e.value as email
from contacts as c
left outer join contacts as a 
on c.contact_id = a.contact_id and a.field_id=1
left outer join contacts as t 
on c.contact_id = t.contact_id and t.field_id=2
left outer join contacts as e 
on c.contact_id = e.contact_id and e.field_id=3

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


Re: Need some help speeding up this loop

2008-10-30 Thread Marc 'BlackJack' Rintsch
On Wed, 29 Oct 2008 19:24:32 -0700, erikcw wrote:

> I'm trying to write a loop that will build a list of "template strings".
> 
> My current implementation is *really slow*.  It took 15 minutes to
> finish. (final len(list) was about 16k entries.)

What is `list` here?  Do you mean ``len(templates)``?

> templates = []
> for c in combinations:
> if len(states):
> for state in states:
> if type(geo) is City:
> cities = state.city_set.all()
> else:
> cities = geo
> for city in cities:
> if type(city) is City:
> city = city.city
> templates.append(c.template.replace('{{ city }}',
> city))
> templates.append(c.template) #just in case there are no
> cities
> templates = [k.replace('{{ state }}',
> state.state).replace('{{ state_abbr }}', state.abbreviation) for k in
> templates]

It seems you are iterating over *all* accumulated templates so far, over 
and over again, even those which don't have those place holders anymore.  
Looks like the source of quadratic runtime for me.

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


Re: Unicode Problem

2008-10-30 Thread Ulrich Eckhardt
Seid Mohammed wrote:
> I am new to python.

Welcome! :)

 abebe = 'አበበ በሶ በላ'
 abebe
> '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0 \xe1\x89\xa0\xe1\x88\xb6
> \xe1\x89\xa0\xe1\x88\x8b'
 print abebe
> አበበ በሶ በላ
 abeba = ['አበበ','በሶ','በላ']
 abeba
> ['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
> '\xe1\x89\xa0\xe1\x88\x8b']
 print abeba
> ['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
> '\xe1\x89\xa0\xe1\x88\x8b']
 len(abebe)
> 23
> 
> so my question is
> 1)why >>> abebe prints  '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0
> \xe1\x89\xa0\xe1\x88\xb6 \xe1\x89\xa0\xe1\x88\x8b' instead of አበበ በሶ
> በላ
> 2) why >>> print abeba don't print the expected አበበ በሶ በላ string

When you just type an identifier X on the commandline, Python outputs the
result of calling repr(X). This typically gives you something that you
could enter in any Python program. Note that e.g. the string 'አበበ በሶ በላ' is
not suitable in any Python program, it requires an encoding where those
characters are supported like e.g. UTF-8.

Now, if you type "print X" on the commandline, it will output the thing as a
string instead, giving you the original contents. If, like for a list, no
string representation exists, it will fall back to using repr() instead.


Disclaimer: I'm not a pro yet myself, but I think this covers the background
a bit. Maybe someone will correct me if I'm horribly wrong.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: Unicode Problem

2008-10-30 Thread Bard Aase
On Thu, Oct 30, 2008 at 8:28 AM, Seid Mohammed <[EMAIL PROTECTED]> wrote:
> I am new to python.
> I want to print Amharic character using the Python IDLE.
> here goes somple code
> ==
 abebe = 'አበበ በሶ በላ'
 abebe
> '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0 \xe1\x89\xa0\xe1\x88\xb6
> \xe1\x89\xa0\xe1\x88\x8b'
 print abebe
> አበበ በሶ በላ
 abeba = ['አበበ','በሶ','በላ']
 abeba
> ['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
> '\xe1\x89\xa0\xe1\x88\x8b']
 print abeba
> ['\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0', '\xe1\x89\xa0\xe1\x88\xb6',
> '\xe1\x89\xa0\xe1\x88\x8b']
 len(abebe)
> 23
> 
> so my question is
> 1)why >>> abebe prints  '\xe1\x8a\xa0\xe1\x89\xa0\xe1\x89\xa0
> \xe1\x89\xa0\xe1\x88\xb6 \xe1\x89\xa0\xe1\x88\x8b' instead of አበበ በሶ
> በላ
> 2) why >>> print abeba don't print the expected አበበ በሶ በላ string


when you print strings from the interpreter using >>> abeba it will
escape any non-ascii characters.
if you, instead print it using >>> print abeba it will print the
proper characters, as long as your terminal supports it.


-- 
mvh base (Bård Aase)
MSN: [EMAIL PROTECTED]
http://blog.elzapp.com
:wq
--
http://mail.python.org/mailman/listinfo/python-list


Ascii codec can't encode

2008-10-30 Thread luca72
hello i have this problem:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 8: ordinal not in range(128)
Generally i solve the problem inserting :
# -*- coding: ISO-8859-1 -*-
at the top of the file but now he don't work can you help me

thanks

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


Re: Ascii codec can't encode

2008-10-30 Thread Ulrich Eckhardt
luca72 wrote:
> hello i have this problem:
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
> position 8: ordinal not in range(128)

This is the result of transcoding a Unicode string to ASCII, where the
Unicode string contains a character that is not representable in ASCII.
This happens to me when I try to print such a character because my console
is set to ASCII.

> Generally i solve the problem inserting :
> # -*- coding: ISO-8859-1 -*-
> at the top of the file but now he don't work can you help me

This only tells Python that your sourcecode uses Latin 1 as encoding. It
doesn't affect other files or any input or output streams.

What code exactly triggers the error?

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: How to open a shell prompt from an existing shell prompt

2008-10-30 Thread gaurav kashyap
Do we have subprocess module in python 2.3
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ascii codec can't encode

2008-10-30 Thread luca72
On 30 Ott, 10:27, luca72 <[EMAIL PROTECTED]> wrote:
> Hy the code is this:
>
> Pok\xe9mon
>
> Luca

Sorry is the é
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to open a shell prompt from an existing shell prompt

2008-10-30 Thread gaurav kashyap
reply please
--
http://mail.python.org/mailman/listinfo/python-list


open a shell prompt froma python program

2008-10-30 Thread gaurav kashyap
Dear all,

Can u tell me a python program that when executed in a shell
prompt,opens another shell prompt.

Simply i want to open a shell prompt from a python program.

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


Re: Ascii codec can't encode

2008-10-30 Thread Ulrich Eckhardt
luca72 wrote:
> Hy the code is this:
> 
> Pok\xe9mon

That's not what I meant, I meant a piece of Python source code. This piece
has to be large enough to demonstrate the problem but with everything else
removed. The point is that guessing what is wrong in your program is just
futile; In order to help, people need information.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: open a shell prompt froma python program

2008-10-30 Thread Lars Stavholm
gaurav kashyap wrote:
> Dear all,
> 
> Can u tell me a python program that when executed in a shell
> prompt,opens another shell prompt.
> 
> Simply i want to open a shell prompt from a python program.

I think you're looking for:

import os
os.system("/bin/sh")

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


Re: Regarding shared memory

2008-10-30 Thread James Mills
On Thu, Oct 30, 2008 at 2:13 PM, gaurav kashyap <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I have a server program that listens to a particular port and a number
> of client programs that connect to the server.
>
> Now i want to put some data in form of python list in main memory on
> server.Hence whenver a client program is run it connects to the server
> and access the data in main memory.Here the server calls a module that
> processes the data as per the client request and the returns some
> information to the client.
>
> I can create client and server programs using socket programming,but i
> am not able to put the data in shared memory and then access it.
>
> NOTE:I want to put the data in main memory only once(on the server
> using server program) i.e. whenever client connects to the server it
> should only access the data and not create a replica of data already
> loaded in memory.How can this be achieved

This is trivially done with an event-driven framework
such as Twisted or Circuits. I'm the author of circuits (1.0
release coming soon), so here is a circuits based example:

Server code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sw=3 sts=3 ts=3

"""(Example) Echo Server

A simple Echo Server example that sends back to connected clients
the input the server receieves.

This example demonstrates:
   * Basic Component creation.
   * Basic Event handling.
   * Basic TCP Server

This example makes use of:
   * Component
   * Event
   * Manager
   * lib.sockets.TCPServer
"""

from circuits.lib.sockets import TCPServer
from circuits.core import listener, Event, Component, Manager

###
### Components
###

class EchoServer(TCPServer):

   def __init__(self, *args, **kwargs):
  super(EchoServer, self).__init__(*args, **kwargs)

  self.data = [1, 2, 3, 4]

   @listener("read")
   def onREAD(self, sock, data):
  self.write(sock, data)
  self.write(sock, "Data: %s" % self.data)

###
### Main
###

def main():
   manager = Manager()
   server = EchoServer(8000)
   manager += server

   while True:
  try:
 manager.flush()
 server.poll()
  except KeyboardInterrupt:
 break

###
### Entry Point
###

if __name__ == "__main__":
   main()


Client code: (I'm just using a basic telnet example here)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sw=3 sts=3 ts=3

"""(Example) Telnet Client

A basic telnet-like clone that connects to remote hosts
via tcp and allows the user to send data to the remote
server.

This example demonstrates:
   * Basic Component creation.
   * Basic Event handling.
   * Basiv Networking
   * Basic Request/Response Networking

This example makes use of:
   * Component
   * Event
   * Manager
   * lib.sockets.TCPClient
"""

import optparse

from circuits.lib.io import Stdin
from circuits.lib.sockets import TCPClient
from circuits import __version__ as systemVersion
from circuits.core import listener, Event, Component, Manager

USAGE = "%prog [options] host [port]"
VERSION = "%prog v" + systemVersion

###
### Functions
###

def parse_options():
   """parse_options() -> opts, args

   Parse any command-line options given returning both
   the parsed options and arguments.
   """

   parser = optparse.OptionParser(usage=USAGE, version=VERSION)

   parser.add_option("-s", "--ssl",
 action="store_true", default=False, dest="ssl",
 help="Enable Secure Socket Layer (SSL)")

   opts, args = parser.parse_args()

   if len(args) < 1:
  parser.print_help()
  raise SystemExit, 1

   return opts, args

###
### Components
###

class Telnet(TCPClient):

   @listener("connect")
   def onCONNECT(self, host, port):
  print "Connected to %s" % host

   @listener("read")
   def onREAD(self, data):
  print data.strip()

   @listener("stdin:read")
   def onINPUT(self, data):
  self.write(data)

###
### Main
###

def main():
   opts, args = parse_options()

   host = args[0]
   if len(args) > 1:
  port = int(args[1])
   else:
  port = 23

   manager = Manager()

   telnet = Telnet()
   stdin = Stdin()

   manager += stdin
   manager += telnet

   print "Trying %s..." % host
   telnet.open(host, port, ssl=opts.ssl)

   while telnet.connected:
  try:
 manager.flush()
 stdin.poll()
 telnet.poll()
  except KeyboardInterrupt:
 break

   telnet.close()

###
### Entry Point
###

if __name__ == "__main__":
   main()


Client output:

$ ./telnet.py localhost 8000
Trying localhost...
Connected to localhost
test
test
Data: [1, 2, 3, 4]


Circuits can be downloaded from:
http://trac.softcircuit.com.au/circuits/

cheers
James

-- 
--
-- "Problems are solved by method"
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is ctypes appropriate in my case?

2008-10-30 Thread dudeja . rajat
On Wed, Oct 29, 2008 at 6:51 PM, Terry Reedy <[EMAIL PROTECTED]> wrote:

> [EMAIL PROTECTED] wrote:
>
>> Hi,
>>
>> I've a dll and its header file that controls an hardware. I want to write
>> a wrapper for this dll in Python.
>> What is the best way that I can write a wrapper?
>>
>
> What do you want to do with the wrapper?


I'm intending to use STAF - software testing automation framework where I
want to test this dll. Test cases for STAF are written in xml and python. So
for this I want to write a wrapper class for this dll in python that has Dll
API's as the member function of the wrapper class.

This class will be in a python module. This module can be then be imported
in the test cases thereby exposing the dll APIs for testing.

Please suggest if there are better solutions around.


>
>
>  I know ctypes modules and have used it before. As far as I know ctypes is
>> only used to call the dll functions in a python module.
>>
>
> I am not sure what you mean here.  Python code can directly import and call
> functions in dlls that represent Python extension modules and that are
> placed in the Pythonxx/dlls directory in your Windows Python installation.
>  Ctypes is mostly used to call functions in a dll that is *not* a python
> extension module, that was not written for Python.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Well I did not know this. What is a Python extension module?



-- 
Regrads,
Rajat
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ascii codec can't encode

2008-10-30 Thread luca72
Hello Again

the code is this
# -*- coding: ISO-8859-1 -*-
from BeautifulSoup import BeautifulSoup
import urllib
sito = urllib.urlopen('http://text.net/')
esamino = BeautifulSoup(sito)
luca = esamino.findAll('tr', align='center')
lunghezza = len(luca)
messaggio_per_scar = open('me', 'wb')
file_ricerca = open('ri', 'wb')
for dati in range(lunghezza):
gino = luca[dati]
test = gino.findAll(text=True)
print test
valori_a = gino.find("a")["onclick"].split("'")
print valori_a
nome_boot = valori_a[1]
print nome_boot
frase_scar = '/msg '+nome_boot+' xdcc send '+test[0]+'\n\r'
messaggio_per_scar.write(frase_scar)
nome = test[2]
if nome ==' ':
nome = test[4]
frase_ric = nome+' '+test[1]+' '+test[0]+'\n\r'
file_ricerca.write(frase_ric)  #here i have the error
messaggio_per_scar.close()
file_ricerca.close()

Regards

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


Re: Need some help speeding up this loop

2008-10-30 Thread Arnaud Delobelle
On Oct 30, 2:24 am, erikcw <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm trying to write a loop that will build a list of "template
> strings".
>
> My current implementation is *really slow*.  It took 15 minutes to
> finish. (final len(list) was about 16k entries.)
>
> #combinations = 12 small template strings ie "{{ city }},
> {{ state }}..."
> #states = either a django model or a list of 50 states
> #cities = either a django model of 400 cities or a smaller list of
> cities.
>
> templates = []
> for c in combinations:
>     if len(states):
>         for state in states:
>             if type(geo) is City:
>                 cities = state.city_set.all()
>             else:
>                 cities = geo
>             for city in cities:
>                 if type(city) is City:
>                     city = city.city
>                 templates.append(c.template.replace('{{ city }}',
> city))
>             templates.append(c.template) #just in case there are no
> cities
>             templates = [k.replace('{{ state }}',
> state.state).replace('{{ state_abbr }}', state.abbreviation) for k in
> templates]

The line above does a lot of unnecessary work as you iterate over lots
of templates which have already been completely substituted.

>     elif len(geo):
>         for city in geo:
>             templates.append(c.template.replace('{{ city }}', city))
>     else:
>         #no cities or states so add roots
>         templates.append(c.template)
>
> The final output needs to be a list of the templates combined with all
> the states and cities (some templates will only have the city, some
> only the state).
>
> Any ideas how I can optimize this?
>
> Thanks!

I would suggest this (untested):

def template_replace(template, values):
for var, val in values.iteritems():
template = template.replace('{{ %s }}' % var, val)
return template

templates = []
for c in combinations:
if len(states):
for state in states:
values = { 'state': state.state,
   'state_abbr': state.abbreviation }
#just in case there are no cities :
templates.append(template_replace(c.template, values)
if type(geo) is City:
cities = state.city_set.all()
else:
cities = geo
for city in cities:
if type(city) is City:
values['city'] = city.city
# Do all the replacing in one go:
templates.append(template_replace(c.template,
values))
elif len(geo):
for city in geo:
templates.append(template_replace(c.template,
{'city':city}))
else:
#no cities or states so add roots
templates.append(c.template)

HTH

Even better would be to iterate over states, then cities, then only
templates.

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


Re: open a shell prompt froma python program

2008-10-30 Thread gaurav kashyap
On Oct 30, 2:59 pm, Lars Stavholm <[EMAIL PROTECTED]> wrote:
> gaurav kashyap wrote:
> > Dear all,
>
> > Can u tell me a python program that when executed in a shell
> > prompt,opens another shell prompt.
>
> > Simply i want to open a shell prompt from a python program.
>
> I think you're looking for:
>
> import os
> os.system("/bin/sh")



Dear,

Its not opening a new window,
I want to do that only from already opened shell prompt window
--
http://mail.python.org/mailman/listinfo/python-list


Re: Unit Testing: a couple of questions

2008-10-30 Thread Emanuele D'Arrigo
Thank you all for the very instructive replies! Much appreciated!

By the sound of it I just have to relax a little and acquire a little
bit more experience on the matter as I go along. =)

Thank you again!

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


Re: download image from flickr.com

2008-10-30 Thread Justin Ezequiel
##compile_obj = re.compile(r'dyn.Img\(".*?",".*?",".*?","(.*?)"')
compile_obj = re.compile(r'\http://mail.python.org/mailman/listinfo/python-list


Re: open a shell prompt froma python program

2008-10-30 Thread Diez B. Roggisch
gaurav kashyap wrote:

> On Oct 30, 2:59 pm, Lars Stavholm <[EMAIL PROTECTED]> wrote:
>> gaurav kashyap wrote:
>> > Dear all,
>>
>> > Can u tell me a python program that when executed in a shell
>> > prompt,opens another shell prompt.
>>
>> > Simply i want to open a shell prompt from a python program.
>>
>> I think you're looking for:
>>
>> import os
>> os.system("/bin/sh")
> 
> 
> 
> Dear,
> 
> Its not opening a new window,
> I want to do that only from already opened shell prompt window

Then you need to open a terminal, like xterm or konsole. Use
os.system("/usr/bin/konsole") 

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


Re: How to open a shell prompt from an existing shell prompt

2008-10-30 Thread Tino Wildenhain

gaurav kashyap wrote:

reply please


try to invest some time in your question, it might be a
cultural thing and from my observations common in questions
from the indian area...

So "give me that." "I require..." might syntactically be
correct, but the sound to other people on mailinglists
is not so nice.

Better try to describe what your problem is - and not
only the immediate one but an overall picture of what
you want to achive and then put your question. That
was people can better understand what you want to do
and help you. Ah and btw, sentence with questions
are better ended with question marks -> ?
This makes it easier to parse.

Back to your problem: its not clear what you mean by
"open a shell prompt (window)"

You can execute a script via subprocess module
and get all the input and output in separate
file handles you could use to interact with the
script. Open a new window would mean a new terminal
and is very os specific. Usually you don't have
control over such a spawned terminal window.

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python-list Digest, Vol 61, Issue 443

2008-10-30 Thread Seid Mohammed
ok
but still i am not clear with my problem.
if i test this one
==
 kk ='how old are you'
>>> len(kk)
15
==
but in my case
==
>>> abebe = 'አበበ በሶ በላ'
>>> len(abebe)
 23
==
why the lenght is 23 while I am expecting to be 9 only. becuase I have
9 characters(including space) just typed.
there must be a kind of trick over it.
thanks all
Seid M

On 10/30/08, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
> Send Python-list mailing list submissions to
>   [email protected]
>
> To subscribe or unsubscribe via the World Wide Web, visit
>   http://mail.python.org/mailman/listinfo/python-list
> or, via email, send a message with subject or body 'help' to
>   [EMAIL PROTECTED]
>
> You can reach the person managing the list at
>   [EMAIL PROTECTED]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Python-list digest..."
>


-- 
"RABI ZIDNI ILMA"
--
http://mail.python.org/mailman/listinfo/python-list


Re: open a shell prompt froma python program

2008-10-30 Thread gaurav kashyap
HI,
I am getting the following error:

konsole: cannot connect to X server

do i need to install the related files.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ascii codec can't encode

2008-10-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Oct 2008 03:01:07 -0700, luca72 wrote:

> the code is this
> # -*- coding: ISO-8859-1 -*-
> from BeautifulSoup import BeautifulSoup import urllib
> sito = urllib.urlopen('http://text.net/') esamino = BeautifulSoup(sito)
> luca = esamino.findAll('tr', align='center') lunghezza = len(luca)
> messaggio_per_scar = open('me', 'wb') file_ricerca = open('ri', 'wb')
> for dati in range(lunghezza):
> gino = luca[dati]
> test = gino.findAll(text=True)
> print test
> valori_a = gino.find("a")["onclick"].split("'") print valori_a
> nome_boot = valori_a[1]
> print nome_boot
> frase_scar = '/msg '+nome_boot+' xdcc send '+test[0]+'\n\r'
> messaggio_per_scar.write(frase_scar)
> nome = test[2]
> if nome ==' ':
> nome = test[4]
> frase_ric = nome+' '+test[1]+' '+test[0]+'\n\r'
> file_ricerca.write(frase_ric)  #here i have the error
> messaggio_per_scar.close()
> file_ricerca.close()

And which of those line raised the exception?  Full traceback please.

I guess it is one of the ``print``\s because `BeatifulSoup` returns 
`unicode` objects which may lead to that exception when printed and the 
output encoding can not be determined.

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


Re: How to open a shell prompt from an existing shell prompt

2008-10-30 Thread gaurav kashyap
Dear Tino,
I am using python 2.3.5. on POSIX system,I have the simple query as:

I log into the shell as root.Can i issue some command that will open
another terminal?(i.e I get a duplicate copy of the shell prompt
already opened)



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


The way that will help you to be a professional game developer.

2008-10-30 Thread smartx
Hi, I would like to share my knowledge as a game programmer, really
game programming is hard, I don't want to disappoint you, the
important point to become a game programmer is to love game
programming, this way you will reach your target, also you need to be
patient, don't stop on the half of the road, like you are building a
great building and when you leave it like you destroy what you built,
sure because what you learn needs a practice to keep it fresh in your
mind otherwise you will forget what you learn, I start learning c++ as
a programming language then win32Api, this prepare the road for game
programming, I chose direct x, also while I'm learning I make a pause
why do you know why? because I saw that I must have a base before
I dive into direct x, this base is the mathematics.
I learned the important math for game, then I continued direct x, then
I saw that I need people to help me providing scene meshes, characters
to animate, well it's not so easy to get them, also the internet has a
free models, you can take a benefit of this, but I didn't let this to
be a nightmare for me, I learned modeling, texturing (photoshop),
rigging and character animation with maya, also I learned to combine
the great benefit from using zbrush to add details to the characters
and also for texturing, also I used 3ds max, but my main 3d package is
maya.

And finally building 3d game engine that you can modify, use into your
own game.


Great luck !
smart,
http://gptutors.com
--
http://mail.python.org/mailman/listinfo/python-list


about recursive load

2008-10-30 Thread Michel Perez
Hi, am very newbie in Python, but as part of a project i need to load
configuration -a settings.py file in the package dir- of my apps
recursively, something like this:

settings.load_config("project.test.app")
settings.load_config("project.test.*")
settings.load_config("project.test")
settings.load_config("*")

this allows me to load them as:

settings.project.CONFIG_PARAMETER_1  # project configuration
settings.project.test.CONFIG_PARAMETER_1 # sub project

and so on.
This it's what i've done, 

class Settings:
  def __getattr__( self,  attr):
return self.__dict__['flags'][attr]
  
  def __setattr__(self,  attr,  value):
self.__dict__['flags'][attr]=value
  
  def __init__(self, package = None,  parent = None):
self.__package = package
self.__parent = None
self.__dict__['flags']={}

  def get_parent ( self):
return self.__parent

  def create_config_structure( self, pkg, parent = None ):
# ... assuming no error and all that
if pkg.count(".") > 0:
  if parent is None:
if not self.__dict__['flags'].has_key(pkg[:pkg.find(".")]):
  father=self.__dict__['flags'][pkg]=Settings( \
pkg[:pkg.find(".")],self)
else:
  father = parent
  else:
if not parent.__dict__['flags'].has_key(pkg[:pkg.find(".")]):
  father=parent.__dict__['flags'][pkg[:pkg.find(".")]]= \
Settings(pkg[:pkg.find(".")],  parent)
else:
 father = parent
  self.create_config_structure( pkg [pkg.find(".")+1:],father)
else:
  if not parent.__dict__['flags'].has_key:
parent.__dict__['flags'][pkg]=Settings(pkg,parent)
  return parent.__dict__['flags'][pkg]

  def load_config ( self, pkg= None ):
config_module_object = self.create_config_structure( pkg )

# the loading configuration part
try:
  if pkg is not None:
mod = __import__( pkg + ".settings", {},{},[''])
  else:
mod = __import__( "settings", {},{},[''])
except:
  raise ImportError("Settings not found") 

data={}
for setting in dir(mod):
  if setting == setting.upper():
data[setting]=getattr(mod, setting)  

for key in data:
  if pkg is not None:
setattr( config_module_object.__dict__['flags'], key, data[key])
  else:
setattr(self.__dict__['flags'], key, data[key])

Any idea it's welcome


---
Red Telematica de Salud - Cuba
  CNICM - Infomed
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-30 Thread Fuzzyman
On Oct 30, 1:13 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Oct 29, 2008, at 4:52 PM, Fuzzyman wrote:
>
> > You're pretty straightforwardly wrong. In Python the 'value' of a
> > variable is not the reference itself.
>
> That's the misconception that is leading some folks around here into
> tangled nots of twisty mislogic, ultimately causing them to make up
> new terms for what every other modern language is perfectly happy
> calling Call-By-Value.
>
> I've thought a lot about why this misconception is so widespread here,
> and I think it must be one of the following:
>
> 1. There was one community leader with this idea, who has been
> successful at promoting it widely, much to the detriment of all; or,
>
> 2. Because everything in Python is an object, you're not forced to
> think clearly (and more generally) about references as values as you
> are in languages (such as Java, VB.NET, etc.) which have both simple
> types and object types.
>


But those languages clearly make the distinction between values and
references that you refuse to make! Go figure...

Michael

> Either way, it's wrong (or at least, a needlessly complicated way of
> looking at things).
>
> > .NET does draw a distinction between 'value types' and reference types
> > - where using reference types are called by reference (the reference
> > is passed) and value types are called by value (the value itself is
> > copied).
>
> Quite right.  Now, note that "ByRef" and "ByVal" apply to both.
> Generalize to Python.  There you go.
>
> Best,
> - Joe
>
> P.S. I really am trying to quit responding to this thread.  Sometimes
> the urge is too strong.  But I'll keep trying!

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


Restricted Execution of untrusted code

2008-10-30 Thread Emanuele D'Arrigo
I noticed that this issue has been discussed in this newsgroup
periodically over the years and I seem to understand that -
comprehensive- safe/restricted execution of untrusted code in python
is currently quite hard to achieve.

What if the safety requirements are a little relaxed though? All I'd
want to prevent is for the code opening/damaging files, formatting
drives or similarly catastrophic exploits. I'm not particularly
concerned if the application freeze or crashes. Nor if the
application's objects are inspected and exploited. All I want is to
make sure that if somebody uses my application plus a third party
plugin for it, the worst that can happen is that they can't use my
application with that plugin.

Is that feasible?

Thanks for your help!

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


Re: Python-list Digest, Vol 61, Issue 443

2008-10-30 Thread Marc 'BlackJack' Rintsch
On Thu, 30 Oct 2008 13:50:47 +0300, Seid Mohammed wrote:

> ok
> but still i am not clear with my problem. if i test this one
> ==
>  kk ='how old are you'
 len(kk)
> 15
> ==
> but in my case
> ==
 abebe = 'አበበ በሶ በላ'
 len(abebe)
>  23
> ==
> why the lenght is 23 while I am expecting to be 9 only. becuase I have 9
> characters(including space) just typed. there must be a kind of trick
> over it.

You have typed 9 characters but they are not encoded as 9 bytes.  I guess 
your environment uses UTF-8 as encoding, because mine does too and:

In [124]: abebe = 'አበበ በሶ በላ'

In [125]: len(abebe)
Out[125]: 23

In [126]: s = 'አ'

In [127]: len(s)
Out[127]: 3

In [128]: s
Out[128]: '\xe1\x8a\xa0'

So that one character is encoded in three bytes.  If you really want to 
operate on characters instead of bytes, use `unicode` objects:

In [129]: u = abebe.decode('utf-8')

In [130]: len(u)
Out[130]: 9

In [131]: print u[0]
አ

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


Re: Ascii codec can't encode

2008-10-30 Thread luca72
Hy the code is this:

Pok\xe9mon

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


py2exe

2008-10-30 Thread Gandalf
I'm new to py2exe.

i'm using python 2.5 on XP
and py2exe 0.6.6


does someone know what may be wrong with this script:

from distutils.core import setup

import py2exe

setup(console=['babylon.py'],

options = {

"py2exe": {

"packages": ["pyHook", "encodings", "pywinauto",

"pywinauto.controls", "pywinauto.tests", "urllib2", "pyTTS"],

"excludes" : ["sendkeys"],

}

}

)


if you need more information please tell me...

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


Re: how to get full-text search of pysqlite3 work in python2.5.2

2008-10-30 Thread Guilherme Polo
On 10/30/08, hawk <[EMAIL PROTECTED]> wrote:
> Hi,
>  my environment is debian, python 2.5.2.
>  when i call con.enable_load_extension(True), the following message
>  prompt out.
>  debian:~# python2.5
>  Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
>  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> import sqlite3
>  >>> con = sqlite3.connect(":memory:")
>  >>> con.enable_load_extension(True)
>  Traceback (most recent call last):
>   File "", line 1, in 
>  AttributeError: 'sqlite3.Connection' object has no attribute
>  'enable_load_extension'
>

enable_load_extension was added in pysqlite 2.5, but python 2.5.2
includes an older version of pysqlite.

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


-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-30 Thread Fuzzyman
On Oct 30, 1:13 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Oct 29, 2008, at 4:52 PM, Fuzzyman wrote:
>
> > You're pretty straightforwardly wrong. In Python the 'value' of a
> > variable is not the reference itself.
>
> That's the misconception that is leading some folks around here into
> tangled nots of twisty mislogic, ultimately causing them to make up
> new terms for what every other modern language is perfectly happy
> calling Call-By-Value.
>
> I've thought a lot about why this misconception is so widespread here,
> and I think it must be one of the following:
>
> 1. There was one community leader with this idea, who has been
> successful at promoting it widely, much to the detriment of all; or,
>
> 2. Because everything in Python is an object, you're not forced to
> think clearly (and more generally) about references as values as you
> are in languages (such as Java, VB.NET, etc.) which have both simple
> types and object types.
>


To make it clearer for you, call by value means that the value is
copied in - and therefore changes to the value won't be visible to the
caller.

In .NET this is true of mutable value types - changes made are made to
a copy and not visible to the caller. In Python we *only* have
reference types, so changes to *any* mutable object are visible to the
caller.

In .NET you can call by reference with a value type - and the runtime
does boxing for you so that you can see the changes. You have to
explicitly ask for call by reference though.

Michael

> Either way, it's wrong (or at least, a needlessly complicated way of
> looking at things).
>
> > .NET does draw a distinction between 'value types' and reference types
> > - where using reference types are called by reference (the reference
> > is passed) and value types are called by value (the value itself is
> > copied).
>
> Quite right.  Now, note that "ByRef" and "ByVal" apply to both.
> Generalize to Python.  There you go.
>
> Best,
> - Joe
>
> P.S. I really am trying to quit responding to this thread.  Sometimes
> the urge is too strong.  But I'll keep trying!

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


Re: py2exe

2008-10-30 Thread Gandalf
OK this question is not clear enough.

I'm trying to convert my python script to executable file.
it seems than the simple setup(console=['file.py']) won't work in my
case because i use unsupported  modules (like pywinauto and extra).

this are the modules I import:

import wx
import wx.html as html
import pythoncom, pyHook
from pywinauto import win32defines
from pywinauto.controls.HwndWrapper import win32functions
from pywinauto.controls.HwndWrapper import HwndWrapper
from pywinauto.controls.HwndWrapper import win32structures
from pywinauto.controls.HwndWrapper import time
from pywinauto.controls.HwndWrapper import Timings
from pywinauto.controls.HwndWrapper import ctypes
from pywinauto import win32defines
from pywinauto import win32functions
from pywinauto.controls.HwndWrapper import SendKeys
import sys
import urllib2
import re

import pywinauto.clipboard
import sqlite3 as lite

import time
import pyTTS

can someone please show me the right way to right write my setup.py
script?

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Andy O'Meara


> Okay, here's the bottom line:
> * This is not about the GIL.  This is about *completely* isolated
> interpreters; most of the time when we want to remove the GIL we want
> a single interpreter with lots of shared data.
> * Your use case, although not common, is not extraordinarily rare
> either.  It'd be nice to support.
> * If CPython had supported it all along we would continue to maintain
> it.
> * However, since it's not supported today, it's not worth the time
> invested, API incompatibility, and general breakage it would imply.
> * Although it's far more work than just solving your problem, if I
> were to remove the GIL I'd go all the way and allow shared objects.
>

Great recap (although saying "it's not about the GIL" may cause some
people lose track of the root issues here, but your following comment
GIL removal shows that we're on the same page).

> So there's really only two options here:
> * get a short-term bodge that works, like hacking the 3rd party
> library to use your shared-memory allocator.  Should be far less work
> than hacking all of CPython.

The problem there is that we're not talking about a single 3rd party
API/allocator--there's many, including the OS which has its own
internal allocators.  My video encoding example is meant to illustrate
a point, but the real-world use case is where there's allocators all
over the place from all kinds of APIs, and when you want your C module
to reenter the interpreter often to execute python helper code.

> * invest yourself in solving the *entire* problem (GIL removal with
> shared python objects).

Well, as I mentioned, I do represent a company willing an able to
expend real resources here.  However, as you pointed out, there's some
serious work at hand here (sadly--it didn't have to be this way) and
there seems to be some really polarized people here that don't seem as
interested as I am to make python more attractive for app developers
shopping for an interpreter to embed.

>From our point of view, there's two other options which unfortunately
seem to be the only out the more we seem to uncover with this
discussion:

3) Start a new python implementation, let's call it "CPythonES",
specifically targeting performance apps and uses an explicit object/
context concept to permit the free threading under discussion here.
The idea would be to just implement the core language, feature set,
and a handful of modules.  I refer you to that list I made earlier of
"essential" modules.

4) Drop python, switch to Lua.

The interesting thing about (3) is that it'd be in the same spirit as
how OpenGL ES came to be (except in place of the need for free
threading was the fact the standard OpenGL API was too overgrown and
painful for the embedded scale).

We're currently our own in-house version of (3), but we unfortunately
have other priorities at the moment that would otherwise slow this
down.  Given the direction of many-core machines these days, option
(3) or (4), for us, isn't a question of *if*, it's a question of
*when*.  So that's basically where we're at right now.

As to my earlier point about representing a company ready to spend
real resources, please email me off-list if anyone here would have an
interest in an open "CPythonES" project (and get full compensation).
I can say for sure that we'd be able to lead with API framework design
work--that's my personal strength and we have a lot of real world
experience there.

Andy


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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Jesse Noller
On Wed, Oct 29, 2008 at 8:05 PM, Glenn Linderman <[EMAIL PROTECTED]> wrote:
> On approximately 10/29/2008 3:45 PM, came the following characters from the
> keyboard of Patrick Stinson:
>>
>> If you are dealing with "lots" of data like in video or sound editing,
>> you would just keep the data in shared memory and send the reference
>> over IPC to the worker process. Otherwise, if you marshal and send you
>> are looking at a temporary doubling of the memory footprint of your
>> app because the data will be copied, and marshaling overhead.
>
> Right.  Sounds, and is, easy, if the data is all directly allocated by the
> application.  But when pieces are allocated by 3rd party libraries, that use
> the C-runtime allocator directly, then it becomes more difficult to keep
> everything in shared memory.
>
> One _could_ replace the C-runtime allocator, I suppose, but that could have
> some adverse effects on other code, that doesn't need its data to be in
> shared memory.  So it is somewhat between a rock and a hard place.
>
> By avoiding shared memory, such problems are sidestepped... until you run
> smack into the GIL.

If you do not have shared memory: You don't need threads, ergo: You
don't get penalized by the GIL. Threads are only useful when you need
to have that requirement of large in-memory data structures shared and
modified by a pool of workers.

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


Re: Ascii codec can't encode

2008-10-30 Thread luca72
the arror are:

>>> Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1006, in __unhandled_exception
self.mainThread.user_exception(None, (exctype,excval,exctb), 1)
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugBase.py", line 538, in user_exception
self._dbgClient.eventLoop()
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 921, in eventLoop
self.readReady(self.readstream.fileno())
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
AsyncIO.py", line 67, in readReady
self.handleLine(s)
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 311, in handleLine
self.__dumpVariables(int(frmnr), int(scope), filter)
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1128, in __dumpVariables
vlist = self.__formatVariablesList(keylist, dict, scope, filter)
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1594, in __formatVariablesList
valtypestr = unicode(type(value))[1:-1]
TypeError: unbound method __unicode__() must be called with
NavigableString instance as first argument (got nothing instead)

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClient.py", line 38, in 
debugClient.main()
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 1900, in main
self.__interact()
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 897, in __interact
self.eventLoop()
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 921, in eventLoop
self.readReady(self.readstream.fileno())
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
AsyncIO.py", line 67, in readReady
self.handleLine(s)
  File "/usr/lib/python2.5/site-packages/eric4/DebugClients/Python/
DebugClientBase.py", line 445, in handleLine
execfile(sys.argv[0], self.debugMod.__dict__)
  File "/home/luca11/Desktop/prova.py", line 36, in 
file_ricerca.write(frase_ric)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
position 8: ordinal not in range(128)

I have solve in this way:

file_ricerca = codecs.open('ri', 'wb', 'ISO-8859-15', 'repalce')

That is not exact what i want because instead of the 'é' i get '?' but
the loop contine.
Thanks

Luca


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


Re: Graphical object browser

2008-10-30 Thread Propad
On Oct 30, 2:10 am, Jason <[EMAIL PROTECTED]> wrote:
> Hooray! I discovered PyCrust. I made this script (for Linux - under
> Win, you could just have all but the first line as a python file and
> run it directly):
>
> #!/usr/bin/python
> import wx
> import wx.py.PyCrust
>
> if __name__ == '__main__' :
>     app = wx.App()
>     pc = wx.py.PyCrust.App(app)
>     pc.MainLoop()
>
> Run it from the working dir and tinker from there.

Hello,
is it still possible to run PyCrust with Python 2.2? I see no
installer for it anywhere...
Cheers,
Propad
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to open a shell prompt from an existing shell prompt

2008-10-30 Thread Tino Wildenhain

gaurav kashyap wrote:

Dear Tino,
I am using python 2.3.5. on POSIX system,I have the simple query as:

I log into the shell as root.Can i issue some command that will open
another terminal?(i.e I get a duplicate copy of the shell prompt
already opened)


I'd say so but what would that have to do with python?

What is the goal you really want to achive? What will you
do with the "shell prompt" once you have it?

Regards
Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: open a shell prompt froma python program

2008-10-30 Thread [EMAIL PROTECTED]
On Oct 30, 11:53 am, gaurav kashyap <[EMAIL PROTECTED]> wrote:
> HI,
> I am getting the following error:
>
> konsole: cannot connect to X server
>
> do i need to install the related files.

Do you have an x-server running? I assume so, because you have a
terminal window opened.

If you became root using su, you need to allow connections to x-
server, which is started by the regular user. you can do this for
local access using
$ xhost local:

Best wishes! Bernhard
--
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter: How to get Label wraplength functionality in Text Box

2008-10-30 Thread Mudcat
I'm not sure why my tkinter would not be compiled against 8.5 since I
have the latest version. I assumed that Python 2.6 would have it
without requiring me to do an extra compile.

However I was able to get it working using the code you gave me.
Thanks for that. The only problem is that it seems to simply be
counting newlines (or number of \n). When I use the following:

numlines = widget.count("1.0", "end", "displaylines", "lines")
print "Number of lines is ", numlines

I get this:

Number of lines is  (153, 1)

So that's not actually the number of lines displayed in the box, just
the number of newline chars it finds. I couldn't find anything in the
tk documentation that would give me any other options to count lines
differently, or number of lines displayed after wrapping.


On Oct 29, 9:10 am, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:

>
> You would need to wrap it and add it as a method to the Text class inTkinter. 
> Fortunately it is easily done:
>
> importTkinter
>
> def text_count(self, index1, index2, *options):
>     args = ["-%s" % opt for opt in options]
>     args.extend([index1, index2])
>     return self.tk.call(self._w, "count", *args)
>
> Tkinter.Text.count = text_count
>
> Then to try it:
>
> root =Tkinter.Tk()
> text =Tkinter.Text()
> text.pack()
>
> text.insert("1.0", "a\nb\c\nd")
> print text.count("1.0", "end", "displaylines", "lines")
>
> root.mainloop()
>
> Note that I inverted the order of the arguments here, indices and then
> the options or no options. If it doesn't work saying "count" is not an
> acceptable command then yourtkinteris not compiled against tcl/tk
> 8.5 or later.
>
>
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: Graphical object browser

2008-10-30 Thread Mike Driscoll
On Oct 30, 8:33 am, Propad <[EMAIL PROTECTED]> wrote:
> On Oct 30, 2:10 am, Jason <[EMAIL PROTECTED]> wrote:
>
> > Hooray! I discovered PyCrust. I made this script (for Linux - under
> > Win, you could just have all but the first line as a python file and
> > run it directly):
>
> > #!/usr/bin/python
> > import wx
> > import wx.py.PyCrust
>
> > if __name__ == '__main__' :
> >     app = wx.App()
> >     pc = wx.py.PyCrust.App(app)
> >     pc.MainLoop()
>
> > Run it from the working dir and tinker from there.
>
> Hello,
> is it still possible to run PyCrust with Python 2.2? I see no
> installer for it anywhere...
> Cheers,
> Propad

PyCrust is part of wxPython now (I think). But I'm not sure how long
it's been a part of that package. You can try downloading one of the
really old wxPython versions and see if it's included:

http://sourceforge.net/project/showfiles.php?group_id=10718&package_id=10559

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


Re: Finding the instance reference of an object

2008-10-30 Thread Dale Roberts
On Oct 29, 9:13 pm, Joe Strout <[EMAIL PROTECTED]> wrote:
> On Oct 29, 2008, at 4:52 PM, Fuzzyman wrote:
>
> > You're pretty straightforwardly wrong. In Python the 'value' of a
> > variable is not the reference itself.
>
> That's the misconception that is leading some folks around here into  
> tangled nots of twisty mislogic, ultimately causing them to make up  
> new terms for what every other modern language is perfectly happy  
> calling Call-By-Value.

Doesn't this logic also apply to Call By Reference? Isn't that term
redundant too? (see my 3 C++ examples above). If not, why not? Are you
saying that C++ is capable of using the Call By Reference idiom, but C
is not, because C does not have a reference designation for formal
function parameters?

"Call By Object Reference" is an idiom, just like Call By Reference.
It is not a physical description of what is going on internally at the
register/stack level (which is always just shuffling values around -
or flipping bits, as Steven points out), it is a higher level concept
that helps people understand the *intention* (not necessarily the
implementation) of the mechanism.

You cannot look a C++ programmer straight in the eye and say that
"Python uses Call By Value, Period", without also informing them that
"Python variables can ONLY EVER hold object references - that is the
only "value" they can ever hold". Then the C++ programmer will go "Oh,
yea, that makes sense".

Instead of having to say all of that, we just give it a new name.
Instead of "Call By Value, Where Every Single Value Is Only Ever A
Reference To An Object Which Contains The Actual Value That
Programmers Usually Refer To", we just say "Call By Object Reference".

> ...
> 2. Because everything in Python is an object, you're not forced to  
> think clearly (and more generally) about references as values

I think we've shown that we are all in fact thinking clearly about it,
and we all (you included, of course!) understand what is going on.
It's just a matter of what words we choose to describe it.

Using your definition of value, though, I believe that if you want to
throw out Call By Object Reference, you also have to throw out Call By
Reference. See my 3 C++ examples above. And just for fun I did look at
the assembler output, and, indeed, the output for examples 1 and 3 is
absolutely identical. They are the same thing, as far as the CPU is
concerned.

Would you give them different names?

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


Re: how to get full-text search of pysqlite3 work in python2.5.2

2008-10-30 Thread hawk
On Oct 30, 8:21 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> On 10/30/08, hawk <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
> >  my environment is debian, python 2.5.2.
> >  when i call con.enable_load_extension(True), the following message
> >  prompt out.
> >  debian:~# python2.5
> >  Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
> >  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> >  Type "help", "copyright", "credits" or "license" for more information.
> >  >>> import sqlite3
> >  >>> con = sqlite3.connect(":memory:")
> >  >>> con.enable_load_extension(True)
> >  Traceback (most recent call last):
> >   File "", line 1, in 
> >  AttributeError: 'sqlite3.Connection' object has no attribute
> >  'enable_load_extension'
>
> enable_load_extension was added in pysqlite 2.5, but python 2.5.2
> includes an older version of pysqlite.
>
> >  Thanks
> >  Hawk
>
> > --
> >  http://mail.python.org/mailman/listinfo/python-list
>
> --
> -- Guilherme H. Polo Goncalves

i have solved this problem by install from latest source package. but,
another issue raised, when i called con.execute("select
load_extension('./fts3.so')") and con.execute("CREATE VIRTUAL TABLE
posts using FTS3(title, body);"). the error message is,

>>> from pysqlite2 import dbapi2 as sqlite3
>>> con = sqlite3.connect(":memory:")
>>> con.enable_load_extension(True)
>>> con.execute("select load_extension('./fts3.so')")
Traceback (most recent call last):
  File "", line 1, in 
pysqlite2.dbapi2.OperationalError: extension loading is disabled

i checked whole file system for fts.so. but there is no fts3.so
anymore. then i downloaded the full source code of latest sqlite, and
compiled it. but also, no fts2.so exists under build folder. finally,
i downloaded sqlite-amalgamation-3_6_4.zip and compiled it with
CFLAGS="-DSQLITE_ENABLE_FTS3=1" option. the whole command line is
"CFLAGS="-DSQLITE_ENABLE_FTS3=1" ./configure". unfortunately, the
fts3.so cannot be found too.
how can i get the fts2.so!!!
--
http://mail.python.org/mailman/listinfo/python-list


how can i get the fts2.so?

2008-10-30 Thread hawk
Hello, everybody,
i already have python2.5.2 on my debian box. i checked whole file
system for fts.so. but there is no fts3.so anymore. then i downloaded
the full source code of latest sqlite, and compiled it. but also, no
fts2.so exists under build folder. finally, i downloaded sqlite-
amalgamation-3_6_4.zip and compiled it with CFLAGS="-
DSQLITE_ENABLE_FTS3=1" option. the whole command line is "CFLAGS="-
DSQLITE_ENABLE_FTS3=1" ./configure". unfortunately, the fts3.so cannot
be found too.
how can i get the fts2.so!!!
Thanks in advance
Xiang
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is ctypes appropriate in my case?

2008-10-30 Thread Terry Reedy

[EMAIL PROTECTED] wrote:



On Wed, Oct 29, 2008 at 6:51 PM, Terry Reedy <[EMAIL PROTECTED] 
> wrote:


[EMAIL PROTECTED]  wrote:

Hi,

I've a dll and its header file that controls an hardware. I want
to write a wrapper for this dll in Python.
What is the best way that I can write a wrapper?


What do you want to do with the wrapper?


I'm intending to use STAF - software testing automation framework where 
I want to test this dll. Test cases for STAF are written in xml and 
python. So for this I want to write a wrapper class for this dll in 
python that has Dll API's as the member function of the wrapper class.


This class will be in a python module. This module can be then be 
imported in the test cases thereby exposing the dll APIs for testing.


Please suggest if there are better solutions around.
 




I know ctypes modules and have used it before. As far as I know
ctypes is only used to call the dll functions in a python module.


I am not sure what you mean here.  Python code can directly import
and call functions in dlls that represent Python extension modules
and that are placed in the Pythonxx/dlls directory in your Windows
Python installation.  Ctypes is mostly used to call functions in a
dll that is *not* a python extension module, that was not written
for Python.

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

Well I did not know this. What is a Python extension module?


For CPython, an importable module written in C.  There is a doc 
Extending and Embedding the Python Interpreter.  But I expect you can 
write the class in Python with ctypes.


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


Re: how can i get the fts2.so?

2008-10-30 Thread hawk
sorry, all fts2 is fts3.

On Oct 30, 10:06 pm, hawk <[EMAIL PROTECTED]> wrote:
> Hello, everybody,
> i already have python2.5.2 on my debian box. i checked whole file
> system for fts.so. but there is no fts3.so anymore. then i downloaded
> the full source code of latest sqlite, and compiled it. but also, no
> fts2.so exists under build folder. finally, i downloaded sqlite-
> amalgamation-3_6_4.zip and compiled it with CFLAGS="-
> DSQLITE_ENABLE_FTS3=1" option. the whole command line is "CFLAGS="-
> DSQLITE_ENABLE_FTS3=1" ./configure". unfortunately, the fts3.so cannot
> be found too.
> how can i get the fts2.so!!!
> Thanks in advance
> Xiang

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


Re: how to get full-text search of pysqlite3 work in python2.5.2

2008-10-30 Thread hawk
sorry, all fts2 is fts3.
On Oct 30, 10:04 pm, hawk <[EMAIL PROTECTED]> wrote:
> On Oct 30, 8:21 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
>
>
> > On 10/30/08, hawk <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
> > >  my environment is debian, python 2.5.2.
> > >  when i call con.enable_load_extension(True), the following message
> > >  prompt out.
> > >  debian:~# python2.5
> > >  Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
> > >  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> > >  Type "help", "copyright", "credits" or "license" for more information.
> > >  >>> import sqlite3
> > >  >>> con = sqlite3.connect(":memory:")
> > >  >>> con.enable_load_extension(True)
> > >  Traceback (most recent call last):
> > >   File "", line 1, in 
> > >  AttributeError: 'sqlite3.Connection' object has no attribute
> > >  'enable_load_extension'
>
> > enable_load_extension was added in pysqlite 2.5, but python 2.5.2
> > includes an older version of pysqlite.
>
> > >  Thanks
> > >  Hawk
>
> > > --
> > >  http://mail.python.org/mailman/listinfo/python-list
>
> > --
> > -- Guilherme H. Polo Goncalves
>
> i have solved this problem by install from latest source package. but,
> another issue raised, when i called con.execute("select
> load_extension('./fts3.so')") and con.execute("CREATE VIRTUAL TABLE
> posts using FTS3(title, body);"). the error message is,
>
> >>> from pysqlite2 import dbapi2 as sqlite3
> >>> con = sqlite3.connect(":memory:")
> >>> con.enable_load_extension(True)
> >>> con.execute("select load_extension('./fts3.so')")
>
> Traceback (most recent call last):
>   File "", line 1, in 
> pysqlite2.dbapi2.OperationalError: extension loading is disabled
>
> i checked whole file system for fts.so. but there is no fts3.so
> anymore. then i downloaded the full source code of latest sqlite, and
> compiled it. but also, no fts2.so exists under build folder. finally,
> i downloaded sqlite-amalgamation-3_6_4.zip and compiled it with
> CFLAGS="-DSQLITE_ENABLE_FTS3=1" option. the whole command line is
> "CFLAGS="-DSQLITE_ENABLE_FTS3=1" ./configure". unfortunately, the
> fts3.so cannot be found too.
> how can i get the fts2.so!!!

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


Simple ElementTree Help

2008-10-30 Thread Heston James - Cold Beans
Hello Guys,

 

I have a small element tree task here whereby I need to crack open an XML
file, modify the text for one element and then resave it back again. I'm
currently trying to do this like follows:

 

# Parse the XML file.

application_settings = etree.parse('/configuration/application.xml')

 

# Modify the single_send_mode element.

application_settings.find("single_send_mode").text =
new_configuration["single_send_mode"]

 

# Save the XML file.

application_settings.write("/configuration/application_new.xml")

 

This runs without error however it doesn't save the text into the
'single_send_mode' element and I end up with a configuration file which
contains  in it.

 

Can anyone offer any suggestions on how to get this to work properly?

 

Thanks guys, I appreciate it.

 

Heston

 

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


Re: Tkinter: How to get Label wraplength functionality in Text Box

2008-10-30 Thread Guilherme Polo
On 10/30/08, Mudcat <[EMAIL PROTECTED]> wrote:
> I'm not sure why my tkinter would not be compiled against 8.5 since I
>  have the latest version. I assumed that Python 2.6 would have it
>  without requiring me to do an extra compile.

It is not really python's fault if tkinter is compiled against tcl/tk
8.5 or not. The windows installer for python 2.6 happens to include
tcl/tk 8.5 and tkinter compiled against them, but ubuntu for example
doesn't distribute tkinter compiled against tcl/tk 8.5 at the moment.

>
>  However I was able to get it working using the code you gave me.
>  Thanks for that. The only problem is that it seems to simply be
>  counting newlines (or number of \n). When I use the following:
>
> numlines = widget.count("1.0", "end", "displaylines", "lines")
> print "Number of lines is ", numlines
>
>  I get this:
>
>  Number of lines is  (153, 1)

The first is the number of displaylines, the second is the number of lines.

>
>  So that's not actually the number of lines displayed in the box, just
>  the number of newline chars it finds.

Not really. displaylines returns the number of lines displayed in the
text widget, and lines returns the number of newlines found.
Note that it is important to call "count" only after the text widget
is being displayed, otherwise displaylines won't work correctly (not
with tk 8.5.3 at least).

> I couldn't find anything in the
>  tk documentation that would give me any other options to count lines
>  differently, or number of lines displayed after wrapping.

Try this and check what you get:


import Tkinter

root = Tkinter.Tk()
text = Tkinter.Text()
text.pack()

def test(event):
print "displaylines:", text.count("1.0", "end", "displaylines")
print "lines:", text.count("1.0", "end", "lines")

text.insert("1.0", "a" * 81)
text.insert("2.0", "b\n")
text.bind('', test)

root.mainloop()


You should have 3 lines displayed but only 2 "real" lines.


-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Single string vs list of strings

2008-10-30 Thread Scott Sharkey

Hi All,

I have a need to determine whether a passed variable is a single string, 
or a list of strings.  What is the most pythonic way to do this?


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


Re: py2exe

2008-10-30 Thread Mike Driscoll
On Oct 30, 7:19 am, Gandalf <[EMAIL PROTECTED]> wrote:
> I'm new to py2exe.
>
> i'm using python 2.5 on XP
> and py2exe 0.6.6
>
> does someone know what may be wrong with this script:
>
> from distutils.core import setup
>
> import py2exe
>
> setup(console=['babylon.py'],
>
> options = {
>
> "py2exe": {
>
> "packages": ["pyHook", "encodings", "pywinauto",
>
> "pywinauto.controls", "pywinauto.tests", "urllib2", "pyTTS"],
>
> "excludes" : ["sendkeys"],
>
> }
> }
>
> )
>
> if you need more information please tell me...
>
> thank you

You need to post the error or at least what the issue is as well. And
why are you importing wx and then creating a console (i.e. command-
line interface) program?

I prefer to use GUI2Exe for creating executables: 
http://code.google.com/p/gui2exe/

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


"xxx.has_key(a)" vs "a in xxx"

2008-10-30 Thread Łukasz Ligowski
Hi, 

There is small inconsistency (or I don't understand it right) between python 
2.5 docs and python 2.6 docs.

2.5 docs say that:
 "a.has_key(k) Equivalent to k in a, use that form in new code"

2.6 docs say that:
 "dict.has_key(key) is equivalent to key in d, but deprecated."

which is true?

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


Re: Is ctypes appropriate in my case?

2008-10-30 Thread dudeja . rajat
> For CPython, an importable module written in C.  There is a doc Extending
> and Embedding the Python Interpreter.  But I expect you can write the class
> in Python with ctypes.

Thanks Terry. I'll be using ctypes now and have started writing the class.
But the problem is that there are some 150 APIs exposed by the dll. Is there
any tool that can autogenerate some of the member functions for the class
since new APIs might as well get added in future.

Could SWIG be of use here?

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


Is psyco available for python 2.6?

2008-10-30 Thread sert
I used the windows installer for the latest version of psyco, 
which is labeled as compatible with 2.5, but it gives the 
following error:

ImportError: DLL load failed: The specified module could not be 
found. (check that the compiled extension 'C:\Python26\lib\site-
packages\psyco\_psyco.pyd' is for the correct Python version; 
this is Python 2.6)
--
http://mail.python.org/mailman/listinfo/python-list


Re: "xxx.has_key(a)" vs "a in xxx"

2008-10-30 Thread Terry Reedy

Łukasz Ligowski wrote:
Hi, 

There is small inconsistency (or I don't understand it right) between python 
2.5 docs and python 2.6 docs.


2.5 docs say that:
 "a.has_key(k) Equivalent to k in a, use that form in new code"

2.6 docs say that:
 "dict.has_key(key) is equivalent to key in d, but deprecated."

which is true?


Both. Dict.has_key is gone in 3.0.

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


Re: "xxx.has_key(a)" vs "a in xxx"

2008-10-30 Thread Kurt Smith
On Thu, Oct 30, 2008 at 9:37 AM, Łukasz Ligowski <[EMAIL PROTECTED]>wrote:

> Hi,
>
> There is small inconsistency (or I don't understand it right) between
> python
> 2.5 docs and python 2.6 docs.
>
> 2.5 docs say that:
>  "a.has_key(k) Equivalent to k in a, use that form in new code"


Meaning: don't use 'a.has_key(k)'.


>
>
> 2.6 docs say that:
>  "dict.has_key(key) is equivalent to key in d, but deprecated."


Meaning, 'd.has_key(key)' is deprecated -- use 'key in d'.


>
>
> which is true?


Both.

[269]$ python2.6 -3
Python 2.6 (r26:66714, Oct  2 2008, 12:46:52)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> D = {'foo':'bar'}
>>> 'foo' in D
True
>>> D.has_key('foo')
__main__:1: DeprecationWarning: dict.has_key() not supported in 3.x; use the
in operator
True
>>>



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


Re: how to get full-text search of pysqlite3 work in python2.5.2

2008-10-30 Thread Guilherme Polo
On 10/30/08, hawk <[EMAIL PROTECTED]> wrote:
> On Oct 30, 8:21 pm, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
>
> > On 10/30/08, hawk <[EMAIL PROTECTED]> wrote:
>  >
>  >
>  >
>  > > Hi,
>  > >  my environment is debian, python 2.5.2.
>  > >  when i call con.enable_load_extension(True), the following message
>  > >  prompt out.
>  > >  debian:~# python2.5
>  > >  Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
>  > >  [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
>  > >  Type "help", "copyright", "credits" or "license" for more information.
>  > >  >>> import sqlite3
>  > >  >>> con = sqlite3.connect(":memory:")
>  > >  >>> con.enable_load_extension(True)
>  > >  Traceback (most recent call last):
>  > >   File "", line 1, in 
>  > >  AttributeError: 'sqlite3.Connection' object has no attribute
>  > >  'enable_load_extension'
>  >
>
> > enable_load_extension was added in pysqlite 2.5, but python 2.5.2
>  > includes an older version of pysqlite.
>  >
>
> > >  Thanks
>  > >  Hawk
>  >
>  > > --
>  > >  http://mail.python.org/mailman/listinfo/python-list
>  >
>
> > --
>  > -- Guilherme H. Polo Goncalves
>
>  i have solved this problem by install from latest source package. but,
>  another issue raised, when i called con.execute("select
>  load_extension('./fts3.so')") and con.execute("CREATE VIRTUAL TABLE
>  posts using FTS3(title, body);"). the error message is,
>
>  >>> from pysqlite2 import dbapi2 as sqlite3
>
> >>> con = sqlite3.connect(":memory:")
>  >>> con.enable_load_extension(True)
>
> >>> con.execute("select load_extension('./fts3.so')")
>
> Traceback (most recent call last):
>   File "", line 1, in 
>
> pysqlite2.dbapi2.OperationalError: extension loading is disabled
>
>  i checked whole file system for fts.so. but there is no fts3.so
>  anymore. then i downloaded the full source code of latest sqlite, and
>  compiled it. but also, no fts2.so exists under build folder. finally,
>  i downloaded sqlite-amalgamation-3_6_4.zip and compiled it with
>  CFLAGS="-DSQLITE_ENABLE_FTS3=1" option. the whole command line is
>  "CFLAGS="-DSQLITE_ENABLE_FTS3=1" ./configure". unfortunately, the
>  fts3.so cannot be found too.

If you already compiled sqlite with SQLITE_ENABLE_FTS3 then you don't
need to load a fts3 extension, sqlite is already compiled with it.

Just skip the enable_load_extension and start at con.execute("CREATE
VIRTUAL TABLE posts using FTS3(title, body);").

>  how can i get the fts2.so!!!
>
> --
>  http://mail.python.org/mailman/listinfo/python-list
>


-- 
-- Guilherme H. Polo Goncalves
--
http://mail.python.org/mailman/listinfo/python-list


Re: Single string vs list of strings

2008-10-30 Thread Grant Edwards
On 2008-10-30, Scott Sharkey <[EMAIL PROTECTED]> wrote:

> I have a need to determine whether a passed variable is a single string, 
> or a list of strings.  What is the most pythonic way to do this?

>>> type('asdf') is list
False
>>> type(['asdf','qwer']) is list
True

The question you might want to asked is whether the parameter
is a single string or a sequence of strings.  That way your
code will also work with an iterator that returns strings.

>>> type('asdf') is str   
True

Checking to see if something is a sequence of strings is a bit
trickier, since a string is actually a sequence of strings.
You first have to verify that it's not a string, and then check
for the API that you're going to use (iteration or indexing).

-- 
Grant Edwards   grante Yow! I represent a
  at   sardine!!
   visi.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-30 Thread Joe Strout

On Oct 30, 2008, at 7:56 AM, Dale Roberts wrote:


That's the misconception that is leading some folks around here into
tangled nots of twisty mislogic, ultimately causing them to make up
new terms for what every other modern language is perfectly happy
calling Call-By-Value.


Doesn't this logic also apply to Call By Reference? Isn't that term
redundant too? (see my 3 C++ examples above). If not, why not?


It's not.  Wikipedia explains the difference pretty well.

Are you saying that C++ is capable of using the Call By Reference  
idiom,
but C is not, because C does not have a reference designation for  
formal

function parameters?


It's been a LONG time since I did anything in C, but yes, I believe  
that reference parameters were an addition that came with C++.



"Call By Object Reference" is an idiom, just like Call By Reference.
It is not a physical description of what is going on internally at the
register/stack level (which is always just shuffling values around -
or flipping bits, as Steven points out), it is a higher level concept
that helps people understand the *intention* (not necessarily the
implementation) of the mechanism.


Right.  And you can easily tell the difference, by whether an  
assignment to the formal parameter causes any change to the actual  
parameter that was passed in.  If it does, that's call-by-reference.   
If it doesn't, it's call-by-value.  In Python, it doesn't.  In VB.NET  
(and relatives), it doesn't if the parameter is declared (explicitly  
or implicitly) "ByVal", and does if it's declared "ByRef".  (Whether  
the parameter is a reference type or a simple value type makes no  
difference.)


Python's behavior is exactly and always equivalent to the "ByVal"  
behavior of languages that have both behaviors.  It also matches the  
definition of call-by-value.  I quite agree that it's not helpful to  
delve into the physical flipping of transistor states.  We're talking  
about the behavior, and the behavior, very clearly, is call-by-value.   
To call it something else only clouds the issue and results in  
confusion.  (Perhaps explaining why there appears to be far more  
confusion about call semantics in the Python community than in the  
community of other languages where the default semantics are exactly  
the same.)


Best,
- Joe


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


Re: Single string vs list of strings

2008-10-30 Thread Joe Strout

On Oct 30, 2008, at 8:55 AM, Grant Edwards wrote:


The question you might want to asked is whether the parameter
is a single string or a sequence of strings.  That way your
code will also work with an iterator that returns strings.


type('asdf') is str

True


I agree with the general approach, but this test will fail for Unicode  
strings, and so is probably bad mojo moving forward.  Instead I suggest:


   isinstance(x, basestring)

which will work whether x='asdf' or x=u'asdf'.

Best,
- Joe

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


Re: "xxx.has_key(a)" vs "a in xxx"

2008-10-30 Thread D'Arcy J.M. Cain
On Thu, 30 Oct 2008 09:50:57 -0500
"Kurt Smith" <[EMAIL PROTECTED]> wrote:
> > 2.5 docs say that:
> >  "a.has_key(k) Equivalent to k in a, use that form in new code"
> 
> Meaning: don't use 'a.has_key(k)'.
> 
> > 2.6 docs say that:
> >  "dict.has_key(key) is equivalent to key in d, but deprecated."
> 
> Meaning, 'd.has_key(key)' is deprecated -- use 'key in d'.

Wow!  That is so badly written.  Both those statements could easily be
read the opposite by someone reading the docs.  Granted the latter is
better and it is correct but it could be clearer the the user.  It
should be something like;

  """dict.has_key(key) is deprecated.  Use "key in dict" instead."""

IOW your explanation of the sentence is better than the sentence.  :-)

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Ascii codec can't encode

2008-10-30 Thread Ulrich Eckhardt
luca72 wrote:
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in
> position 8: ordinal not in range(128)
> 
> I have solve in this way:
> 
> file_ricerca = codecs.open('ri', 'wb', 'ISO-8859-15', 'repalce')

That should be 'replace' instead of 'repalce', I assume you just mistyped it
here. In any case, you could use 'UTF-8', which is a good default encoding
and which further allows the full range of Unicode characters.

> That is not exact what i want because instead of the 'é' i get '?' but
> the loop contine.

Hmmm, weird, I'd say that ISO-8859-15 should support the accented 'é'.
However, this could also be caused by how you look at the file. If the
editor you use to open it uses a different encoding, it will display
garbage.

Uli

-- 
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

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


Re: open a shell prompt froma python program

2008-10-30 Thread Derek Martin
On Thu, Oct 30, 2008 at 03:53:52AM -0700, gaurav kashyap wrote:
> HI,
> I am getting the following error:
> 
> konsole: cannot connect to X server
> 
> do i need to install the related files.

Maybe, but given that error message, probably not.

You would do yourself a great favor by providing a lot more detail
about what you are trying to do...  On a Unix/Linux system, unlike
Windows, there is no one single "shell prompt window" -- there are
lots of them.  They all need the X Window System (a suite of software
which provides a GUI interface to Unix systems -- it's not "built in"
like it is in Windows).  X works as a client-server model, and you
need to make sure X authentication is handled properly.  Depending on
what you are doing, this can be either very easy, or very complicated.

-- 
Derek D. Martin
http://www.pizzashack.org/
GPG Key ID: 0x81CFE75D



pgpnBx41jvOnI.pgp
Description: PGP signature
--
http://mail.python.org/mailman/listinfo/python-list


Re: "xxx.has_key(a)" vs "a in xxx"

2008-10-30 Thread Łukasz Ligowski
Hi,

On Thursday 30 of October 2008 16:11:07 you wrote:
> On Thu, 30 Oct 2008 09:50:57 -0500
>
> Wow!  That is so badly written.  Both those statements could easily be
> read the opposite by someone reading the docs.  Granted the latter is
> better and it is correct but it could be clearer the the user.  It
> should be something like;
>
>   """dict.has_key(key) is deprecated.  Use "key in dict" instead."""
>
> IOW your explanation of the sentence is better than the sentence.  :-)

I second this ;)

Thanks both of you for explanation.

L

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


Re: Is psyco available for python 2.6?

2008-10-30 Thread bearophileHUGS
sert:
> I used the windows installer for the latest version of psyco,
> which is labeled as compatible with 2.5, but it gives the
> following error:
> ImportError: DLL load failed: The specified module could not be
> found. (check that the compiled extension 'C:\Python26\lib\site-
> packages\psyco\_psyco.pyd' is for the correct Python version;
> this is Python 2.6)

I think you have tried to install something compiled for Python 2.5 on
Python 2.6, therefore it doesn't work.
At the moment Psyco isn't available for Python 2.6, you will probably
have to wait some months (or use Python 2.5+Psyco in the meantime).

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


Fwd: how to get full-text search of pysqlite3 work in python2.5.2

2008-10-30 Thread hawk gao
actually, the latest situation is

debian:~/pysqlite-2.5.0/doc# python
>>> from pysqlite2 import dbapi2 as sqlite3
>>> con = sqlite3.connect(":memory:")
>>> con.execute("CREATE VIRTUAL TABLE posts using FTS3(title, body);")
Traceback (most recent call last):
  File "", line 1, in 
pysqlite2.dbapi2.OperationalError: no such module: FTS3


-- Forwarded message --
From: hawk gao <[EMAIL PROTECTED]>
Date: 2008/10/30
Subject: Re: how to get full-text search of pysqlite3 work in python2.5.2
To: Guilherme Polo <[EMAIL PROTECTED]>


I build and install a 3.6.4 by following this guide
http://www.sqlite.org/cvstrac/wiki?p=CompilingFts
eventually, i can run "CREATE VIRTUAL TABLE posts using FTS3(title, body);"
under sqlite3 command line.

debian:~/pysqlite-2.5.0# sqlite3
SQLite version 3.6.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> CREATE VIRTUAL TABLE posts using FTS3(title, body);
sqlite>

then i rebuild and reinstall pysqlite2.5.0.  but, even "from pysqlite2
import dbapi2 as sqlite3" cannot be accepted.

debian:~/pysqlite-2.5.0# python
Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pysqlite2 import dbapi2 as sqlite3
Traceback (most recent call last):
  File "", line 1, in 
  File "pysqlite2/dbapi2.py", line 27, in 
from pysqlite2._sqlite import *
ImportError: No module named _sqlite


2008/10/30 Guilherme Polo <[EMAIL PROTECTED]>

> On 10/30/08, hawk gao <[EMAIL PROTECTED]> wrote:
>
> > Thanks for your advice. but the problem still here.
> >
> > debian:~/sqlite-3.6.4-build# python
> > Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
> > [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> > Type "help", "copyright", "credits" or "license" for more information.
> >  >>> from pysqlite2 import dbapi2 as sqlite3
> > >>> con = sqlite3.connect(":memory:")
> > >>> con.execute("CREATE VIRTUAL TABLE posts using FTS3(title, body);")
> > Traceback (most recent call last):
> >File "", line 1, in 
> > pysqlite2.dbapi2.OperationalError: no such module: FTS3
> >
>
> Yes... you have to compile pysqlite against the sqlite library that
> has the builtin support fot fts3. pysqlite is probably being compiled
> against the sqlite found in /usr/lib, while the sqlite with fts3
> support is at /usr/local/lib.
>
> --
> -- Guilherme H. Polo Goncalves
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Andy O'Meara
On Oct 28, 6:11 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> > Because then we're back into the GIL not permitting threads efficient
> > core use on CPU bound scripts running on other threads (when they
> > otherwise could).
>
> Why do you think so? For C code that is carefully written, the GIL
> allows *very well* to write CPU bound scripts running on other threads.
> (please do get back to Jesse's original remark in case you have lost
> the thread :-)
>

I don't follow you there.  If you're referring to multiprocessing, our
concerns are:

- Maturity (am I willing to tell my partners and employees that I'm
betting our future on a brand-new module that imposes significant
restrictions as to how our app operates?)
- Liability (am I ready to invest our resources into lots of new
python module-specific code to find out that a platform that we want
to target isn't supported or has problems?).  Like it not, we're a
company and we have to show sensitivity about new or fringe packages
that make our codebase less agile -- C/C++ continues to win the day in
that department.
- Shared memory -- for the reasons listed in my other posts, IPC or a
shared/mapped memory region doesn't work for our situation (and I
venture to say, for many real world situations otherwise you'd see end-
user/common apps use forking more often than threading).


>
> > It's turns out that this isn't an exotic case
> > at all: there's a *ton* of utility gained by making calls back into
> > the interpreter. The best example is that since code more easily
> > maintained in python than in C, a lot of the module "utility" code is
> > likely to be in python.
>
> You should really reconsider writing performance-critical code in
> Python.

I don't follow you there...  Performance-critical code in Python??
Suppose you're doing pixel-level filters on images or video, or
Patrick needs to apply a DSP to some audio...  Our app's performance
would *tank*, in a MAJOR way (that, and/or background tasks would take
100x+ longer to do their work).

> Regardless of the issue under discussion, a lot of performance
> can be gained by using "flattened" data structures, less pointer,
> less reference counting, less objects, and so on - in the inner loops
> of the computation. You didn't reveal what *specific* computation you
> perform, so it's difficult to give specific advise.

I tried to list some abbreviated examples in other posts, but here's
some elaboration:

- Pixel-level effects and filters, where some filters may use C procs
while others may call back into the interpreter to execute logic --
while some do both, multiple times.
- Image and video analysis/recognition where there's TONS of intricate
data structures and logic.  Those data structures and logic are
easiest to develop and maintain in python, but you'll often want to
call back to C procs which will, in turn, want to access Python (as
well as C-level) data structures.

The common pattern here is where there's a serious mix of C and python
code and data structures, BUT it can all be done with a free-thread
mentality since the finish point is unambiguous and distinct -- where
all the "results" are handed back to the "main" app in a black and
white handoff.  It's *really* important for an app to freely make
calls into its interpreter (or the interpreter's data structures)
without having to perform lock/unlocking because that affords an app a
*lot* of options and design paths.  It's just not practical to be
locking and locking the GIL when you want to operate on python data
structures or call back into python.

You seem to have placed the burden of proof on my shoulders for an app
to deserve the ability to free-thread when using 3rd party packages,
so how about we just agree it's not an unreasonable desire for a
package (such as python) to support it and move on with the
discussion.

>
> Again, if you do heavy-lifting in Python, you should consider to rewrite
> the performance-critical parts in C. You may find that the need for
> multiple CPUs goes even away.

Well, the entire premise we're operating under here is that we're
dealing with "embarrassingly easy" parallelization scenarios, so when
you suggest that the need for multiple CPUs may go away, I'm worried
that you're not keeping the big picture in mind.

>
> > I appreciate your arguments these a PyC concept is a lot of work with
> > some careful design work, but let's not kill the discussion just
> > because of that.
>
> Any discussion in this newsgroup is futile, except when it either
> a) leads to a solution that is already possible, and the OP didn't
> envision, or
> b) is followed up by code contributions from one of the participants.
>
> If neither is likely to result, killing the discussion is the most
> productive thing we can do.
>

Well, most others here seem to have a lot different definition of what
qualifies as a "futile" discussion, so how about you allow the rest of
us continue to discuss these issues and possible solutions.  An

Re: HTML File Parsing

2008-10-30 Thread Felipe De Bene
On Oct 28, 6:18 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Felipe De Bene wrote:
> > I'm having problems parsing anHTMLfile with the following syntax :
>
> > 
> > User ID
> > Name > BGCOLOR='#c0c0c0'>Date
> > and so on
>
> > whenever I feed the parser with such file I get the error :
>
> > HTMLParser.HTMLParseError: bad end tag: "", at
> > line 515, column 45
>
> YourHTMLpage is notHTML, i.e. it is broken. Python's HTMLParser is not made
> for parsing brokenHTML. However, you can use the parse of lxml.htmlto fix up
> yourHTMLfor you.
>
> http://codespeak.net/lxml/
>
> Stefan

Actually i fetch from an application that i thought it should act like
this and as I told you, the program is ready to be shipped so
rewriting an entire class that has public methods would be a real
pain. I really had to find a way to work this out by using the
python's parser instead of external libraries. But thanks anyway for
the clue, I might start working on a similar project next and this
library may be a good and a less painful path. Thanks :D
Felipe.

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


Re: open a shell prompt froma python program

2008-10-30 Thread Grant Edwards
On 2008-10-30, Derek Martin <[EMAIL PROTECTED]> wrote:
> On Thu, Oct 30, 2008 at 03:53:52AM -0700, gaurav kashyap wrote:
>> HI,
>> I am getting the following error:
>> 
>> konsole: cannot connect to X server
>> 
>> do i need to install the related files.
>
> Maybe, but given that error message, probably not.
>
> You would do yourself a great favor by providing a lot more detail
> about what you are trying to do...  On a Unix/Linux system, unlike
> Windows, there is no one single "shell prompt window" -- there are
> lots of them.

There are both lots of "shell prompt windows" (which, I assume
means terminal emulators), and lots of shells and other
programs you can run in such a window.

> They all need the X Window System (a suite of software which
> provides a GUI interface to Unix systems -- it's not "built
> in" like it is in Windows).  X works as a client-server model,
> and you need to make sure X authentication is handled
> properly.  Depending on what you are doing, this can be either
> very easy, or very complicated.

-- 
Grant Edwards   grante Yow! This PORCUPINE knows
  at   his ZIPCODE ... And he has
   visi.com"VISA"!!
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is psyco available for python 2.6?

2008-10-30 Thread Gerhard Häring

[EMAIL PROTECTED] wrote:

sert:

I used the windows installer for the latest version of psyco,
which is labeled as compatible with 2.5, but it gives the
following error:
ImportError: DLL load failed: The specified module could not be
found. (check that the compiled extension 'C:\Python26\lib\site-
packages\psyco\_psyco.pyd' is for the correct Python version;
this is Python 2.6)


I think you have tried to install something compiled for Python 2.5 on
Python 2.6, therefore it doesn't work.
At the moment Psyco isn't available for Python 2.6, you will probably
have to wait some months (or use Python 2.5+Psyco in the meantime).


psyco seems to just work on Linux with Python 2.6. So it is probably 
"only" a matter of compiling it on Windows for Python 2.6.


-- Gerhard

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


Re: Tkinter: How to get Label wraplength functionality in Text Box

2008-10-30 Thread Mudcat
Awesome...there it goes. I guess my main problem was trying to
evaluate the box before it had been displayed (or all the frame
propagations were finished). The key was getting the  binding in
there once I got the count functionality to work. After all
that...such a simple function:


def textBoxResize(self, event):
widget = event.widget
dispLines = widget.count("1.0", "end", "displaylines")
widget.config(height=dispLines)


Thanks for the help!


On Oct 30, 9:19 am, "Guilherme Polo" <[EMAIL PROTECTED]> wrote:
> On 10/30/08, Mudcat <[EMAIL PROTECTED]> wrote:
>
> > I'm not sure why my tkinter would not be compiled against 8.5 since I
> >  have the latest version. I assumed that Python 2.6 would have it
> >  without requiring me to do an extra compile.
>
> It is not really python's fault if tkinter is compiled against tcl/tk
> 8.5 or not. The windows installer for python 2.6 happens to include
> tcl/tk 8.5 and tkinter compiled against them, but ubuntu for example
> doesn't distribute tkinter compiled against tcl/tk 8.5 at the moment.
>
>
>
> >  However I was able to get it working using the code you gave me.
> >  Thanks for that. The only problem is that it seems to simply be
> >  counting newlines (or number of \n). When I use the following:
>
> >         numlines = widget.count("1.0", "end", "displaylines", "lines")
> >         print "Number of lines is ", numlines
>
> >  I get this:
>
> >  Number of lines is  (153, 1)
>
> The first is the number of displaylines, the second is the number of lines.
>
>
>
> >  So that's not actually the number of lines displayed in the box, just
> >  the number of newline chars it finds.
>
> Not really. displaylines returns the number of lines displayed in the
> text widget, and lines returns the number of newlines found.
> Note that it is important to call "count" only after the text widget
> is being displayed, otherwise displaylines won't work correctly (not
> with tk 8.5.3 at least).
>
> > I couldn't find anything in the
> >  tk documentation that would give me any other options to count lines
> >  differently, or number of lines displayed after wrapping.
>
> Try this and check what you get:
>
> import Tkinter
>
> root = Tkinter.Tk()
> text = Tkinter.Text()
> text.pack()
>
> def test(event):
>     print "displaylines:", text.count("1.0", "end", "displaylines")
>     print "lines:", text.count("1.0", "end", "lines")
>
> text.insert("1.0", "a" * 81)
> text.insert("2.0", "b\n")
> text.bind('', test)
>
> root.mainloop()
>
> You should have 3 lines displayed but only 2 "real" lines.
>
> --
> -- Guilherme H. Polo Goncalves

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Jesse Noller
On Thu, Oct 30, 2008 at 12:05 PM, Andy O'Meara <[EMAIL PROTECTED]> wrote:
> On Oct 28, 6:11 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
>> > Because then we're back into the GIL not permitting threads efficient
>> > core use on CPU bound scripts running on other threads (when they
>> > otherwise could).
>>
>> Why do you think so? For C code that is carefully written, the GIL
>> allows *very well* to write CPU bound scripts running on other threads.
>> (please do get back to Jesse's original remark in case you have lost
>> the thread :-)
>>
>
> I don't follow you there.  If you're referring to multiprocessing, our
> concerns are:
>
> - Maturity (am I willing to tell my partners and employees that I'm
> betting our future on a brand-new module that imposes significant
> restrictions as to how our app operates?)
> - Liability (am I ready to invest our resources into lots of new
> python module-specific code to find out that a platform that we want
> to target isn't supported or has problems?).  Like it not, we're a
> company and we have to show sensitivity about new or fringe packages
> that make our codebase less agile -- C/C++ continues to win the day in
> that department.
> - Shared memory -- for the reasons listed in my other posts, IPC or a
> shared/mapped memory region doesn't work for our situation (and I
> venture to say, for many real world situations otherwise you'd see end-
> user/common apps use forking more often than threading).
>

FWIW (and again, I am not saying MP is good for your problem domain) -
multiprocessing works on windows, OS/X, Linux and Solaris quite well.
The only platforms it has problems on right now *BSD and AIX. It has
plenty of tests (I want more more more) and has a decent amount of
usage is my mail box and bug list are any indication.

Multiprocessing is not *new* - it's a branch of the pyprocessing package.

Multiprocessing is written in C, so as for the "less agile" - I don't
see how it's any less agile then what you've talked about. If you
wanted true platform insensitivity, then Java is a better bet :) As
for your final point:

> - Shared memory -- for the reasons listed in my other posts, IPC or a
> shared/mapped memory region doesn't work for our situation (and I
> venture to say, for many real world situations otherwise you'd see end-
> user/common apps use forking more often than threading).
>

I philosophically disagree with you here. PThreads and Shared memory
as it is today, is largely based on Java's influence on the world. I
would argue that the reason most people use threads as opposed to
processes is simply based on "ease of use and entry" (which is ironic,
given how many problems it causes). Not because they *need* the shared
memory aspects of it, or because they could not decompose the problem
into Actors/message passing, but because threads:

A> are there (e.g. in Java, Python, etc)
B> allow you to "share anything" (which allows you to take horrible shortcuts)
C> is what everyone "knows" at this point.

Even luminaries such as Brian Goetz and many, many others have pointed
out that threading, as it exists today is fundamentally difficult to
get right. Ergo the "renaissance" (read: echo chamber) towards
Erlang-style concurrency.

For many "real world" applications - threading is just "simple". This
is why Multiprocessing exists at all - to attempt to make forking/IPC
as "simple" as the API to threading. It's not foolproof, but the goal
was to open the door to multiple cores with a familiar API:

Quoting PEP 371:

"The pyprocessing package offers a method to side-step the GIL
allowing applications within CPython to take advantage of
multi-core architectures without asking users to completely change
their programming paradigm (i.e.: dropping threaded programming
for another "concurrent" approach - Twisted, Actors, etc).

The Processing package offers CPython a "known API" which mirrors
albeit in a PEP 8 compliant manner, that of the threading API,
with known semantics and easy scalability."

I would argue that most of the people taking part in this discussion
are working on "real world" applications - sure, multiprocessing as it
exists today, right now - may not support your use case, but it was
evaluated to fit *many* use cases.

Most of the people here are working in Pure python, or they're using a
few extension modules here and there (in C). Again, when you say
threads and processes, most people here are going to think "import
threading", "fork()" or "import multiprocessing"

Please correct me if I am wrong in understanding what you want: You
are making threads in another language (not via the threading API),
embed python in those threads, but you want to be able to share
objects/state between those threads, and independent interpreters. You
want to be able to pass state from one interpreter to another via
shared memory (e.g. pointers/contexts/etc).

Example:

ParentAppFoo makes 10 threads (in C)
Each thread gets an itty bi

Re: beutifulsoup

2008-10-30 Thread luca72
hello
Another stupit question instead of use
sito = urllib.urlopen('http://www.prova.com/')
esamino = BeautifulSoup(sito)

i do
 sito = urllib.urlopen('http://onlygame.helloweb.eu/')
 file_sito = open('sito.html', 'wb')
 for line in sito :
 file_sito.write(line)
 file_sito.close()

how can i pass the file sito.html to beautifulsoup?

Regards

Luca

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


Re: Is ctypes appropriate in my case?

2008-10-30 Thread Terry Reedy

[EMAIL PROTECTED] wrote:


For CPython, an importable module written in C.  There is a doc
Extending and Embedding the Python Interpreter.  But I expect you
can write the class in Python with ctypes.




Thanks Terry. I'll be using ctypes now and have started writing the class.
But the problem is that there are some 150 APIs exposed by the dll.


Ugh ;-)

Is 
there any tool that can autogenerate some of the member functions for 
the class since new APIs might as well get added in future.


Could SWIG be of use here?


I have the impression that SWIG has multiple backends for different 
languages.  There is one for automating much of the work of producing an 
extension module.  I presume there could be one, if not already, that 
produced Python/cytpe code instead of C code.  That would be a nice 
thing to have.


You can find threads about real experiences with SWIG in the clp 
archives at google groups.


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


Re: beutifulsoup

2008-10-30 Thread Kay Schluehr
On 30 Okt., 18:28, luca72 <[EMAIL PROTECTED]> wrote:
> hello
> Another stupit question instead of use
> sito = urllib.urlopen('http://www.prova.com/')
> esamino = BeautifulSoup(sito)
>
> i do
>  sito = urllib.urlopen('http://onlygame.helloweb.eu/')
>  file_sito = open('sito.html', 'wb')
>  for line in sito :
>      file_sito.write(line)
>  file_sito.close()
>
> how can i pass the file sito.html to beautifulsoup?
>
> Regards
>
> Luca

download = urllib.urlopen("http://www.fiber-space.de/downloads/
downloads.html")
BeautifulSoup(download.read())

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread VanL
Jesse Noller wrote:

> Even luminaries such as Brian Goetz and many, many others have pointed
> out that threading, as it exists today is fundamentally difficult to
> get right. Ergo the "renaissance" (read: echo chamber) towards
> Erlang-style concurrency.

I think this is slightly missing what Andy is saying. Andy is trying
something that would look much more like Erlang-style concurrency than
classic threads - "green processes" to use someone else's term.

AFAIK, Erlang "processes" aren't really processes at the OS level.
Instead, they are named processes because they only communicate through
message passing. When multiple "processes" are running in the same
os-level-multi-threaded interpreter, the interpreter cheats to make the
message passing fast.

I think Andy is thinking along the same lines. With a Python
subinterpreter per thread, he is suggesting intra-process message
passing as a way to get concurrency.

Its actually not too far from what he is doing already, but he is
fighting OS-level shared library semantics to do it. Instead, if Python
supported a per-subinterpreter GIL and per-subinterpreter state, then
you could theoretically get to a good place:

- You only initialize subinterpreters if you need them, so
single-process Python doesn't pay a large (any?) penalty
- Intra-process message passing can be fast, but still has the
no-shared-state benefits of the Erlang concurrency model
- There are fewer changes to the Python core, because the GIL doesn't go
away

No, this isn't whole-hog free threading (or safe threading), there are
restrictions that go along with this model - but there would be benefits.

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


Re: "xxx.has_key(a)" vs "a in xxx"

2008-10-30 Thread Terry Reedy

D'Arcy J.M. Cain wrote:

On Thu, 30 Oct 2008 09:50:57 -0500
"Kurt Smith" <[EMAIL PROTECTED]> wrote:

2.5 docs say that:
 "a.has_key(k) Equivalent to k in a, use that form in new code"

Meaning: don't use 'a.has_key(k)'.


2.6 docs say that:
 "dict.has_key(key) is equivalent to key in d, but deprecated."

Meaning, 'd.has_key(key)' is deprecated -- use 'key in d'.


Wow!  That is so badly written.  Both those statements could easily be
read the opposite by someone reading the docs.  Granted the latter is
better and it is correct but it could be clearer the the user.  It
should be something like;

  """dict.has_key(key) is deprecated.  Use "key in dict" instead."""

IOW your explanation of the sentence is better than the sentence.  :-)


http://bugs.python.org/issue4243

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Andy O'Meara
On Oct 30, 1:00 pm, "Jesse Noller" <[EMAIL PROTECTED]> wrote:

>
> Multiprocessing is written in C, so as for the "less agile" - I don't
> see how it's any less agile then what you've talked about.

Sorry for not being more specific there, but by "less agile" I meant
that an app's codebase is less agile if python is an absolute
requirement.  If I was told tomorrow that for some reason we had to
drop python and go with something else, it's my job to have chosen a
codebase path/roadmap such that my response back isn't just "well,
we're screwed then."  Consider modern PC games.  They have huge code
bases that use DirectX and OpenGL and having a roadmap of flexibility
is paramount so packages they choose to use are used in a contained
and hedged fashion.  It's a survival tactic for a company not to
entrench themselves in a package or technology if they don't have to
(and that's what I keep trying to raise in the thread--that the python
dev community should embrace development that makes python a leading
candidate for lightweight use).  Companies want to build a flexible,
powerful codebases that are married to as few components as
possible.

>
> > - Shared memory -- for the reasons listed in my other posts, IPC or a
> > shared/mapped memory region doesn't work for our situation (and I
> > venture to say, for many real world situations otherwise you'd see end-
> > user/common apps use forking more often than threading).
>
> I would argue that the reason most people use threads as opposed to
> processes is simply based on "ease of use and entry" (which is ironic,
> given how many problems it causes).

No, we're in agreement here -- I was just trying to offer a more
detailed explanation of "ease of use".  It's "easy" because memory is
shared and no IPC, serialization, or special allocator code is
required.  And as we both agree, it's far from "easy" once those
threads to interact with each other.  But again, my goal here is to
stay on the "embarrassingly easy" parallelization scenarios.


>
> I would argue that most of the people taking part in this discussion
> are working on "real world" applications - sure, multiprocessing as it
> exists today, right now - may not support your use case, but it was
> evaluated to fit *many* use cases.

And as I've mentioned, it's a totally great endeavor to be super proud
of.  That suite of functionality alone opens some *huge* doors for
python and I hope folks that use it appreciate how much time and
thought that undoubtably had to go into it.  You get total props, for
sure, and you're work is a huge and unique credit to the community.

>
> Please correct me if I am wrong in understanding what you want: You
> are making threads in another language (not via the threading API),
> embed python in those threads, but you want to be able to share
> objects/state between those threads, and independent interpreters. You
> want to be able to pass state from one interpreter to another via
> shared memory (e.g. pointers/contexts/etc).
>
> Example:
>
> ParentAppFoo makes 10 threads (in C)
> Each thread gets an itty bitty python interpreter
> ParentAppFoo gets a object(video) to render
> Rather then marshal that object, you pass a pointer to the object to
> the children
> You want to pass that pointer to an existing, or newly created itty
> bitty python interpreter for mangling
> Itty bitty python interpreter passes the object back to a C module via
> a pointer/context
>
> If the above is wrong, I think possible outlining it in the above form
> may help people conceptualize it - I really don't think you're talking
> about python-level processes or threads.
>

Yeah, you have it right-on there, with added fact that the C and
python execution (and data access) are highly intertwined (so getting
and releasing the GIL would have to be happening all over).  For
example, consider and the dynamics, logic, algorithms, and data
structures associated with image and video effects and image and video
image recognition/analysis.


Andy


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


In search for a simple build tool

2008-10-30 Thread Orestis Markou

Hello,

as many of you probably know anyway, there's been a lot of talk about  
Python build tools and solutions these days. The thing is, now with so  
many tools to choose from, I can't choose! Hopefully people with more  
experience can help me.


My requirements are:

 * Simple filesystem operations (copy this file here, etc)
 * Easy to use
 * setuptools integration and extension (so that setup.py still works)
 * not needed for distribution (so that end-users won't even know  
it's there)


The closest I could found is Paver; It seems that it's much bigger  
than I need, but it's and it has a bootstrapping library I can  
distribute transparently. Any other options?


Thanks,
Orestis Markou
--
[EMAIL PROTECTED]
http://orestis.gr/




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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Jesse Noller
On Thu, Oct 30, 2008 at 1:54 PM, Andy O'Meara <[EMAIL PROTECTED]> wrote:
> On Oct 30, 1:00 pm, "Jesse Noller" <[EMAIL PROTECTED]> wrote:
>
>>
>> Multiprocessing is written in C, so as for the "less agile" - I don't
>> see how it's any less agile then what you've talked about.
>
> Sorry for not being more specific there, but by "less agile" I meant
> that an app's codebase is less agile if python is an absolute
> requirement.  If I was told tomorrow that for some reason we had to
> drop python and go with something else, it's my job to have chosen a
> codebase path/roadmap such that my response back isn't just "well,
> we're screwed then."  Consider modern PC games.  They have huge code
> bases that use DirectX and OpenGL and having a roadmap of flexibility
> is paramount so packages they choose to use are used in a contained
> and hedged fashion.  It's a survival tactic for a company not to
> entrench themselves in a package or technology if they don't have to
> (and that's what I keep trying to raise in the thread--that the python
> dev community should embrace development that makes python a leading
> candidate for lightweight use).  Companies want to build a flexible,
> powerful codebases that are married to as few components as
> possible.
>
>>
>> > - Shared memory -- for the reasons listed in my other posts, IPC or a
>> > shared/mapped memory region doesn't work for our situation (and I
>> > venture to say, for many real world situations otherwise you'd see end-
>> > user/common apps use forking more often than threading).
>>
>> I would argue that the reason most people use threads as opposed to
>> processes is simply based on "ease of use and entry" (which is ironic,
>> given how many problems it causes).
>
> No, we're in agreement here -- I was just trying to offer a more
> detailed explanation of "ease of use".  It's "easy" because memory is
> shared and no IPC, serialization, or special allocator code is
> required.  And as we both agree, it's far from "easy" once those
> threads to interact with each other.  But again, my goal here is to
> stay on the "embarrassingly easy" parallelization scenarios.
>

That's why when I'm using threads, I stick to Queues. :)

>
>>
>> I would argue that most of the people taking part in this discussion
>> are working on "real world" applications - sure, multiprocessing as it
>> exists today, right now - may not support your use case, but it was
>> evaluated to fit *many* use cases.
>
> And as I've mentioned, it's a totally great endeavor to be super proud
> of.  That suite of functionality alone opens some *huge* doors for
> python and I hope folks that use it appreciate how much time and
> thought that undoubtably had to go into it.  You get total props, for
> sure, and you're work is a huge and unique credit to the community.
>

Thanks - I'm just a cheerleader and pusher-into-core, R Oudkerk is the
implementor. He and everyone else who has helped deserve more credit
than me by far.

My main interest, and the reason I brought it up (again) is that I'm
interested in making it better :)

>>
>> Please correct me if I am wrong in understanding what you want: You
>> are making threads in another language (not via the threading API),
>> embed python in those threads, but you want to be able to share
>> objects/state between those threads, and independent interpreters. You
>> want to be able to pass state from one interpreter to another via
>> shared memory (e.g. pointers/contexts/etc).
>>
>> Example:
>>
>> ParentAppFoo makes 10 threads (in C)
>> Each thread gets an itty bitty python interpreter
>> ParentAppFoo gets a object(video) to render
>> Rather then marshal that object, you pass a pointer to the object to
>> the children
>> You want to pass that pointer to an existing, or newly created itty
>> bitty python interpreter for mangling
>> Itty bitty python interpreter passes the object back to a C module via
>> a pointer/context
>>
>> If the above is wrong, I think possible outlining it in the above form
>> may help people conceptualize it - I really don't think you're talking
>> about python-level processes or threads.
>>
>
> Yeah, you have it right-on there, with added fact that the C and
> python execution (and data access) are highly intertwined (so getting
> and releasing the GIL would have to be happening all over).  For
> example, consider and the dynamics, logic, algorithms, and data
> structures associated with image and video effects and image and video
> image recognition/analysis.

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Paul Boddie
On 30 Okt, 14:12, "Andy O'Meara" <[EMAIL PROTECTED]> wrote:
>
> 3) Start a new python implementation, let's call it "CPythonES"

[...]

> 4) Drop python, switch to Lua.

Have you looked at tinypy? I'm not sure about the concurrency aspects
of the implementation, but the developers are not completely
unfamiliar with game development, and there is a certain amount of
influence from Lua:

http://www.tinypy.org/

It might also be a more appropriate starting point than CPython for
experimentation.

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


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Terry Reedy

Andy O'Meara wrote:

On Oct 28, 6:11 pm, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:



You should really reconsider writing performance-critical code in
Python.


I don't follow you there...  Performance-critical code in Python??


Martin meant what he said better later
>> Again, if you do heavy-lifting in Python, you should consider to
>> rewrite the performance-critical parts in C.


I tried to list some abbreviated examples in other posts, but here's
some elaboration:

...

The common pattern here is where there's a serious mix of C and python
code and data structures,


I get the feeling that what you are doing is more variegated that what 
most others are doing with Python.  And the reason is that what you are 
doing is apparently not possible with *stock* CPython.  Again, it is a 
chicken-and-egg type problem.


You might find this of interest from the PyDev list just hours ago.
"""
Hi to all Python developers

For a student project in a course on virtual machines, we are
evaluating the possibility to
experiment with removing the GIL from CPython

We have read the arguments against doing this at
http://www.python.org/doc/faq/library/#can-t-we-get-rid-of-the-global-interpreter-lock.

But we think it might be possible to do this with a different approach
than what has been tried till now.

The main reason for the necessity of the GIL is reference counting.

We believe that most of the slowdown in the free threading
implementation of Greg Stein was due to the need of atomic
refcounting, as this mail seems to confirm:
http://mail.python.org/pipermail/python-ideas/2007-April/000414.html

So we want to change CPython into having a "real" garbage collector -
removing all reference counting, and then the need for locks (or
atomic inc/dec ops) should be
highly alleviated.

Preferably the GC should be a high-performance one for instance a
generational one.

We believe that it can run quite a lot faster than ref-counting.

Shared datastructures would get their lock obviously.
Immutable objects (especially shared global objects, like True, False, Null)
would not.

Most of the interpreter structure would be per-thread, at that point.

We do not know how Greg Stein did his locking in the free threads
patch, but as a part of the course we learned there exists much faster
ways of locking than using OS-locks (faster for the uncontented case)
that are used in e.g. the HOT-SPOT java-compiler. This might make
"free threading" in python more attractive than some pessimists think.
(http://blogs.sun.com/dave/entry/biased_locking_in_hotspot)
In particular, we are talking about making the uncontended case go fast,
not about the independent part of stack-allocating the mutex
structure, which can only be done and is only needed in Java.

These ideas are similar to the ones used by Linux fast mutexes
(futexes), the implementation of mutexes in NPTL.

We have read this mail thread - so it seems that our idea surfaced,
but Greg didn't completely love it (he wanted to optimize refcounting
instead):
http://mail.python.org/pipermail/python-ideas/2007-April/000436.html

He was not totally negative however. His main objections are about:
- cache locality (He is in our opinion partially right, as seen in some
other paper time ago - any GC, copying GC in particular, doubles the
amount of used memory, so it's less cache-friendly). But still GCs are
overall competitive or faster than explicit management, and surely
much faster of refcounting.

We know it is the plan for PyPy to work in this way, and also that
Jython and Ironpython works like that (using the host vm's GC), so it
seems to be somehow agreeable with the python semantics (perhaps not
really with __del__ but they are not really nice anyway).

Was this ever tried for CPython?

Any other comments, encouragements or warnings on the project-idea?

Best regards: Paolo, Sigurd <[EMAIL PROTECTED]>
"""

Guido's response
"
It's not that I have any love for the GIL, it just is the best
compromise I could find. I expect that you won't be able to do better,
but I wish you luck anyway.
"

And a bit more explanation from Van Lindberg
"
Just an FYI, these two particular students already introduced themselves
on the PyPy list. Paolo is a masters student with experience in the
Linux kernel; Sigurd is a PhD candidate.

Their professor is Lars Bak, the lead architect of the Google V8
Javascript engine. They spent some time working on V8 in the last couple
months.
"

I agree that you should continue the discussion.  Just let Martin ignore 
it for awhile until you need further input from him.


Terry Jan Reedy

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


Code not work - DESPERATE HELP :(

2008-10-30 Thread fx5900

Hi,

   i am trying to convert an .osm (openstreetmap) file into gml format  and
finally to shapefile given this wiki info 
http://wiki.openstreetmap.org/index.php/GML. I'm using windows and when i
entered the following commands osm2gml.py < map_01_data.osm >
map_01_data.gml  on my dos prompt i get a number of errors, some of which
are bellow:

Traceback :
File "C:\osm2gml.py, line 86, in 
xml.sax.parse 
IOError : [Errono 9] bad discriptor

i did manage to convert it to gml format but was clearly unsuccesful because
of the error and it was 1kb. 
Another point i would like to add is that ran the file using PythonWin
(ActiveState) with map_01_data.osm as the argument and after hitting ok,
then cancel i got
 
Traceback (most recent call last):
  File
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\osm2gml.py", line 86, in 
xml.sax.parse( sys.stdin, osmParser )
  File "C:\Python25\lib\xml\sax\__init__.py", line 33, in parse
parser.parse(source)
  File "C:\Python25\lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
  File "C:\Python25\lib\xml\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
  File "C:\Python25\lib\xml\sax\expatreader.py", line 211, in feed
self._err_handler.fatalError(exc)
  File "C:\Python25\lib\xml\sax\handler.py", line 38, in fatalError
raise exception
SAXParseException: :1:0: syntax error

Please would somebody mind telling how i can covert my osm file into the
.gml format using the python file on the dos command or using pythonwin.

Cheers
-- 
View this message in context: 
http://www.nabble.com/Code-not-work---DESPERATE-HELP-%3A%28-tp20253039p20253039.html
Sent from the Python - python-list mailing list archive at Nabble.com.

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


Re: Python suitable for Midi ?

2008-10-30 Thread Chuckk Hubbard
On Wed, Oct 29, 2008 at 10:32 PM, J Kenneth King <[EMAIL PROTECTED]> wrote:

>
> One also has access to nice-levels on unix systems.

True enough, but it's not so much a problem for me, as I'm pretty okay
at tuning my own system, but I believe most of the people who'd be
interested in my app (if any) are not *nix users.  At any rate, it's
one option for those who are, and thanks for reminding me.

-Chuckk

-- 
http://www.badmuthahubbard.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-30 Thread Dale Roberts
On Oct 30, 11:03 am, Joe Strout <[EMAIL PROTECTED]> wrote:
> ...
>> Are you saying that C++ is capable of using the Call By Reference idiom,
>> but C is not, because C does not have a reference designation for formal
>> function parameters?
>
> It's been a LONG time since I did anything in C, but yes, I believe  
> that reference parameters were an addition that came with C++.

Okay, I completely understand you, and I think we will just have to
agree to disagree about the best term to use for Python's parameter
passing mechanism, and this will likely be my concluding post on this
topic (although I have enjoyed it very much and have solidified my own
understanding).

I even found a few web sites that very strongly support your viewpoint
(as it relates to Java):

  http://www.ibm.com/developerworks/library/j-praxis/pr1.html
  http://javadude.com/articles/passbyvalue.htm
  http://www.yoda.arachsys.com/java/passing.html

The difference is that I would say that C supports the Pass By
Reference idiom using this syntax:

  myfunc(int *val){}   /*CALL:*/ myfunc(&i);

which actually passes an address expression (not a variable) by value,
but "looks and feels" like a reference to the "i" variable, which
contains the real value that we care about - and allows modification
of that value.

C++ adds a syntactic change for this very commonly used C idiom, but
does not add any new capability - the results are absolutely
indistinguishable.

Python, likewise, in relation to the values we care about (the values
contained only in objects, never in variables) behaves like Call by
Object Reference.

If I tell someone that Python uses only Call By Value (and that is all
I tell them), they may come away with the impression that variables
contain the values they care about, and/or that the contents of
objects are copied, neither of which is the case, even for so-called
"simple", immutable objects (indeed, at the start of this thread, you
said you believed that, like Java, simple values were contained within
Python variables).

But Python, unlike Java or most other commonly used languages, can
ONLY EVER pass an object reference, and never an actual value I care
about, and I think that idiom deserves a different name which
distinguishes it from the commonly accepted notion of Pass By Value.

Thanks for a thoughtful discussion,
dale
--
http://mail.python.org/mailman/listinfo/python-list


PyCon 2009 (US) - Call for tutorials Extended to 11/3

2008-10-30 Thread Greg Lindstrom
We have had requests to extend the deadline for submitting Tutorial
Proposals for PyCon 2009 (US) through the weekend and are willing to do so.
We will accept tutorial proposals through Monday, November 3.

--greg

==

The period for submitting tutorial proposals for Pycon 2009 (US) is open and
will continue through Monday, November 3rd. This year features two
"pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday
March 26 in Chicago. This allows for more classes than ever.

Tutorials are 3-hours long on a specific topic of your choice. Last year we
featured classes on Learning Python, Web Development, Scientific Computing,
and many more. Class size varied from 10 to over 60 students. The extended
time spent in class allows teachers to cover a lot of material while
allowing for interaction with students.

The full Call for Tutorial Proposals, including submission details, an
example proposal as well as a template, is available at <
http://us.pycon.org/2009/tutorials/proposals/>.

Tutorial selections will be announced in early December to give you time to
prepare your class and PyCon will compensate instructors US$1,500 per
tutorial.

If you have any questions, please contact [EMAIL PROTECTED]

Greg Lindstrom
Tutorial Coordinator, PyCon 2009 (US)
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Martin v. Löwis
>> Why do you think so? For C code that is carefully written, the GIL
>> allows *very well* to write CPU bound scripts running on other threads.
>> (please do get back to Jesse's original remark in case you have lost
>> the thread :-)
>>
> 
> I don't follow you there.  If you're referring to multiprocessing

No, I'm not. I refer to regular, plain, multi-threading.

>>> It's turns out that this isn't an exotic case
>>> at all: there's a *ton* of utility gained by making calls back into
>>> the interpreter. The best example is that since code more easily
>>> maintained in python than in C, a lot of the module "utility" code is
>>> likely to be in python.
>> You should really reconsider writing performance-critical code in
>> Python.
> 
> I don't follow you there...  Performance-critical code in Python??

I probably expressed myself incorrectly (being not a native speaker
of English): If you were writing performance-critical in Python,
you should reconsider (i.e. you should rewrite it in C).

It's not clear whether this calling back into Python is in the
performance-critical path. If it is, then reconsider.

> I tried to list some abbreviated examples in other posts, but here's
> some elaboration:
> 
> - Pixel-level effects and filters, where some filters may use C procs
> while others may call back into the interpreter to execute logic --
> while some do both, multiple times.

Ok. For a plain C proc, release the GIL before the proc, and reacquire
it afterwards. For a proc that calls into the interpreter:
a) if it is performance-critical, reconsider writing it in C, or
   reformulate so that it stops being performance critical (e.g.
   through caching)
b) else, reacquire the GIL before calling back into Python, then
   release the GIL before continuing the proc

> - Image and video analysis/recognition where there's TONS of intricate
> data structures and logic.  Those data structures and logic are
> easiest to develop and maintain in python, but you'll often want to
> call back to C procs which will, in turn, want to access Python (as
> well as C-level) data structures.

Not sure what the processing is, or what processing you need to do.
The data structures themselves are surely not performance critical
(not being algorithms). If you really run Python algorithms on these
structures, then my approach won't help you (except for the general
recommendation to find some expensive sub-algorithm and rewrite that
in C, so that it both becomes faster and can release the GIL).

> It's just not practical to be
> locking and locking the GIL when you want to operate on python data
> structures or call back into python.

This I don't understand. I find that fairly easy to do.

> You seem to have placed the burden of proof on my shoulders for an app
> to deserve the ability to free-thread when using 3rd party packages,
> so how about we just agree it's not an unreasonable desire for a
> package (such as python) to support it and move on with the
> discussion.

Not at all - I don't want a proof. I just want agreement on Jesse
Noller's claim

# A c-level module, on the other hand, can sidestep/release
# the GIL at will, and go on it's merry way and process away.

>> If neither is likely to result, killing the discussion is the most
>> productive thing we can do.
>>
> 
> Well, most others here seem to have a lot different definition of what
> qualifies as a "futile" discussion, so how about you allow the rest of
> us continue to discuss these issues and possible solutions.  And, for
> the record, I've said multiple times I'm ready to contribute
> monetarily, professionally, and personally, so if that doesn't qualify
> as the precursor to "code contributions from one of the participants"
> then I don't know WHAT does.

Ok, I apologize for having misunderstood you here.

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


Re: [PyCon-Organizers] PyCon 2009 (US) - Call for tutorials Extended to 11/3

2008-10-30 Thread Douglas Napoleone
We should get an announcement out on the blog:
http://pycon.blogspot.com/

and note that the deadline is approaching for both talks and tutorials.

For some reason blogger does not like my google account, so I cant
seem to do it :-(

-Doug

On Thu, Oct 30, 2008 at 3:28 PM, Greg Lindstrom <[EMAIL PROTECTED]> wrote:
> We have had requests to extend the deadline for submitting Tutorial
> Proposals for PyCon 2009 (US) through the weekend and are willing to do so.
> We will accept tutorial proposals through Monday, November 3.
>
> --greg
>
> ==
>
> The period for submitting tutorial proposals for Pycon 2009 (US) is open and
> will continue through Monday, November 3rd. This year features two
> "pre-conference" days devoted to tutorials on Wednesday March 25 & Thursday
> March 26 in Chicago. This allows for more classes than ever.
>
> Tutorials are 3-hours long on a specific topic of your choice. Last year we
> featured classes on Learning Python, Web Development, Scientific Computing,
> and many more. Class size varied from 10 to over 60 students. The extended
> time spent in class allows teachers to cover a lot of material while
> allowing for interaction with students.
>
> The full Call for Tutorial Proposals, including submission details, an
> example proposal as well as a template, is available at
> .
>
> Tutorial selections will be announced in early December to give you time to
> prepare your class and PyCon will compensate instructors US$1,500 per
> tutorial.
>
> If you have any questions, please contact [EMAIL PROTECTED]
>
> Greg Lindstrom
>
> Tutorial Coordinator, PyCon 2009 (US)
>
> ___
> PyCon-organizers mailing list
> [EMAIL PROTECTED]
> http://mail.python.org/mailman/listinfo/pycon-organizers
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Re: 2.6, 3.0, and truly independent intepreters

2008-10-30 Thread Patrick Stinson
On Wed, Oct 29, 2008 at 4:05 PM, Glenn Linderman <[EMAIL PROTECTED]> wrote:
> On approximately 10/29/2008 3:45 PM, came the following characters from the
> keyboard of Patrick Stinson:
>>
>> If you are dealing with "lots" of data like in video or sound editing,
>> you would just keep the data in shared memory and send the reference
>> over IPC to the worker process. Otherwise, if you marshal and send you
>> are looking at a temporary doubling of the memory footprint of your
>> app because the data will be copied, and marshaling overhead.
>
> Right.  Sounds, and is, easy, if the data is all directly allocated by the
> application.  But when pieces are allocated by 3rd party libraries, that use
> the C-runtime allocator directly, then it becomes more difficult to keep
> everything in shared memory.

good point.

>
> One _could_ replace the C-runtime allocator, I suppose, but that could have
> some adverse effects on other code, that doesn't need its data to be in
> shared memory.  So it is somewhat between a rock and a hard place.

ewww scary. mousetraps for sale?

>
> By avoiding shared memory, such problems are sidestepped... until you run
> smack into the GIL.
>
> --
> Glenn -- http://nevcal.com/
> ===
> A protocol is complete when there is nothing left to remove.
> -- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking
>
>
--
http://mail.python.org/mailman/listinfo/python-list


Printing with interspersed element

2008-10-30 Thread Paulo J. Matos
Hi all,

I guess this is a recurring issue for someone who doesn't really know
the python lib inside out. There must be a simple way to do this.
I have a list of objects [x1, x2, x3, ..., xn] and I have defined a
print method for them print_obj(). Now I want to print them
intersepersed by an element.
If I print [x1, x2, x3] interspersed by the element 10:
x1.print_obj() 10 x2.print_obj() 10 x3.print_obj()

Now, the question is, what's the best way to do this?

I guess I could do this recursively.
def print(el, lst):
if len(lst) == 0:
return
elif len(lst) == 1:
lst[0].print_obj()
else:
lst[0].print_obj()
print el,
print(el, lst[1:])

Now, some considerations. This seems cumbersome (it may have errors
has I have not tested and was written directly to the mail, but the
idea is clear). From what I know lst[1:] creates a copy of lst without
the first element which is really not good memory-wise.
So, what would be the python way to do it?

Cheers,

-- 
Paulo Jorge Matos - pocmatos at gmail.com
Webpage: http://www.personal.soton.ac.uk/pocm
--
http://mail.python.org/mailman/listinfo/python-list


Re: Printing with interspersed element

2008-10-30 Thread Grant Edwards
On 2008-10-30, Paulo J. Matos <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I guess this is a recurring issue for someone who doesn't really know
> the python lib inside out. There must be a simple way to do this.
> I have a list of objects [x1, x2, x3, ..., xn] and I have defined a
> print method for them print_obj(). Now I want to print them
> intersepersed by an element.
> If I print [x1, x2, x3] interspersed by the element 10:
> x1.print_obj() 10 x2.print_obj() 10 x3.print_obj()

>>> ','.join([str(i) for i in [1,2,3,4]])
'1,2,3,4'

>>> ','.join([i.__repr__() for i in [1,2,3,4]])
'1,2,3,4'

>>> ','.join([str(i) for i in [1]])
'1'

-- 
Grant Edwards   grante Yow! What I want to find
  at   out is -- do parrots know
   visi.commuch about Astro-Turf?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regarding shared memory

2008-10-30 Thread Aaron Brady
On Oct 29, 11:13 pm, gaurav kashyap <[EMAIL PROTECTED]> wrote:
> Dear all,
>
> I have a server program that listens to a particular port and a number
> of client programs that connect to the server.
>
> Now i want to put some data in form of python list in main memory on
> server.Hence whenver a client program is run it connects to the server
> and access the data in main memory.Here the server calls a module that
> processes the data as per the client request and the returns some
> information to the client.
>
> I can create client and server programs using socket programming,but i
> am not able to put the data in shared memory and then access it.
>
> NOTE:I want to put the data in main memory only once(on the server
> using server program) i.e. whenever client connects to the server it
> should only access the data and not create a replica of data already
> loaded in memory.How can this be achieved
>
> thanks.

Shared memory is available in the 'mmap' module.  However, you can't
share a Python list object between processes.  The closest you can do
is share a ctypes.Array or struct.Struct.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding the instance reference of an object

2008-10-30 Thread Dale Roberts
On Oct 30, 3:06 pm, Dale Roberts <[EMAIL PROTECTED]> wrote:
> ... that idiom deserves a different name which
> distinguishes it from the commonly accepted notion of Pass By Value.

Bah, what I meant to end with was:

Just as the Pass By Reference idiom deserves a unique name to
distinguish it from Pass By Value (even though it is often Pass By
(address) Value internally), so Pass By Object Reference deserves a
unique name (even though it too is Pass By (reference) Value
internally).

Again, thanks for the discussion,
dale
--
http://mail.python.org/mailman/listinfo/python-list


Re: Printing with interspersed element

2008-10-30 Thread Arnaud Delobelle
On Oct 30, 8:07 pm, "Paulo J. Matos" <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I guess this is a recurring issue for someone who doesn't really know
> the python lib inside out. There must be a simple way to do this.
> I have a list of objects [x1, x2, x3, ..., xn] and I have defined a
> print method for them print_obj(). Now I want to print them
> intersepersed by an element.
> If I print [x1, x2, x3] interspersed by the element 10:
> x1.print_obj() 10 x2.print_obj() 10 x3.print_obj()
>
> Now, the question is, what's the best way to do this?

Defining a print_obj() method is probably a bad idea.  What if you
want to print to a file for example?  Instead you can define a
__str__() method for your objects and then use the join() method of
strings like this:

print ' 10 '.join(str(x) for x in lst)

HTH

--
Arnaud

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


  1   2   >