Re: Determin network interface

2006-10-03 Thread jakobsg
Thanks a bunch! That is just what I was looking for !

Best regards Jakob

Bryan Olson skrev:
> [EMAIL PROTECTED] wrote:
> > Hi. How can I determin the hwaddr or ipaddress of the networkinterface
> > that is used in an outgoing connection?
>
> Is sock_object.getsockname() enough?
>
>  http://docs.python.org/lib/socket-objects.html
> 
> 
> -- 
> --Bryan

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


Re: saving an exception

2006-10-03 Thread Gabriel G
At Tuesday 3/10/2006 02:15, Bryan wrote:

>i would like to save an exception and reraise it at a later time.
>def foo():
>Â  Â  try:
>Â  Â  Â  Â  1/0
>Â  Â  except Exception, e:
>Â  Â  Â  Â  exception = e
>
>if exception: raise exception
>
>with the above code, i'm able to successfully raise the exception, but the
>line number of the exception is at the place of the explicit raise instead
>of the where the exception originally occurred. Â is there anyway to fix
>this?

The raise statement has 3 arguments, the third 
being the traceback (not used so much, except in cases like yours).
You can get the values using sys.exc_info()
(Don't store the traceback more than needed 
because it holds a reference to all previous stack frames...)


Gabriel Genellina
Softlab SRL 





__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas

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


Re: CGI -> mod_python

2006-10-03 Thread grahamd

[EMAIL PROTECTED] wrote:
> Hi,
>
> it is a kind of nooby question. Is there a way to transfer a CGI python
> script to mod_python without rewriting the code?

Did you look in the mod_python documentation?

  http://www.modpython.org/live/current/doc-html/hand-cgi.html

It certainly isn't the preferred way of using mod_python. You really
should consider porting it properly to either mod_python or as
someone else suggested, WSGI.

Graham

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


Re: switch user

2006-10-03 Thread Nick Vatamaniuc
Check out the os module, especially the
os.getgid(),
os.getuid(),
os.setgid(),
os.getuid(),
methods. There are more , take at a look at Python documentation.

You can start a script as root then change your priveleges with
os.setgid() os.setuid() methods. Note: those methods operate with
integer user and group IDs, not with user and group names.

Hope that helps,
-Nick Vatamaniuc


[EMAIL PROTECTED] wrote:
> hi
>
> due to certain constraints, i will running a python script as root
> inside this script, also due to some constraints, i need to switch user
> to user1 to run the 
> rest of the script...is there a way ?thanks

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


Re: postgresql database

2006-10-03 Thread Paolo

Michele Simionato ha scritto:

> Paolo wrote:
> > Ciao a tutti, sto cercando di implementare un applicazione che si
> > interfaccia con postgresql(8.1), utilizzando Psycopg2, in ambiente
> > windows (python versione 2.5). Ho installato Psycopg2 e provando
> > solamente fare: import psycopg mi ritorna il seguente errore:
> >
> > import psycopg
> > ImportError: No module named psycopg
> >
> > come mai? va settata qualche path oltre a quella di postgresql ?
> >
> > grazie dell'aiuto
>
> Well, if you are using Psycopg2, do
>
> import psycopg2

sure, I have mistaken to write the import, the problem was in the
version of the driver. Thank you for tour fast answer.

>
> (and please use the italian mailing list for questions in Italian).

sorry, but I thought to write in the italian mailing list.

> 
>  Michele Simionato

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


Re: VIdeo Converence Software: Tk and thread synchronization

2006-10-03 Thread Eric Brunel
On Mon, 02 Oct 2006 14:42:15 +0200, Paolo Pantaleo  
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am going on writing my video conference software. I wrote the video
> grab, code/decode, and netwoark (multicast) transport.
>
> I have one thread doing this:
>
> [thread 1]
> while True:
>   for some times:
> my_socket.recv() #blocking here
> store data
>   compute image #here we have a complete new image to display
>
> Now, I was thinking to display the image in a  Tk window. But I think
> i will need a separate thread to run the mainloop() [thread 2], right?

I don't know if tk likes to be run in anything else than the main thread;  
never tested it. If you can use the main thread for tk, you'll probably  
have far less problems.

>  How can I signale to the Tk thread that a new image is ready to be
> shown? I was thinkin on using an event generated for the first
> (network) thread. But I don't know how to do it exactly. Any
> suggestion, please?

Quite simple: in the tk thread, do:

widget.bind('<>', command)

Then in the secondary thread, do:

widget.event_generate('<>', when='tail')

'<>' can be anything, as long as you surround it with << & >>  
(these are custom events in tk). Don't forget to put the when='tail' in  
the event_generate call, or your binding may get called immediatly in the  
current thread.

> What if I access to Tk object form thread 1, is Tk thread safe?

General answer: no, it isn't. The only thing that seems to work everytime  
on tk widgets from secondary threads is generating events as above. If you  
try to do anything else, you may experience deadlocks or even crashes.

HTH
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in  
'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: VIdeo Converence Software: Tk and thread synchronization

2006-10-03 Thread Paul Rubin
"Eric Brunel" <[EMAIL PROTECTED]> writes:
> General answer: no, it isn't. The only thing that seems to work
> everytime  on tk widgets from secondary threads is generating events
> as above. 

I wouldn't bet on even that always being safe.

> If you try to do anything else, you may experience deadlocks or even
> crashes.

The way I do it is use a .after event in the main tkinter loop
to check a queue every 20 msec or so.  Other threads send commands
through the queue.  I usually pass commands as tuples (func, *args, **kw)
so that the .after handler simply calls the func on the args.
-- 
http://mail.python.org/mailman/listinfo/python-list


How Build VTK for Python 2.5 under Windows?

2006-10-03 Thread Sébastien Ramage
Hello,
I'm running on Windows and I want to test VTK but I don't understand
how build it

Somebody can help me to build VTK for Python 2.5 under Windows? (or
Python 2.43 if python 2.5 is a problem)

I have no C compiler but I can install one if it's free.

Thank you

Seb

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


I need Cryptogrphy in Python please .

2006-10-03 Thread NicolasG
Looking around for a Cryptography tool kit, the best recommendations I
found about was for pyCrypto. I try to install it unsuccessfully in my
windowsXP SP2 with python 2.4.3 and I get the following message :
C:\Python24\pycrypto-2.0.1>python setup.py build
running build
running build_py
running build_ext
error: The .NET Framework SDK needs to be installed before building
extensions f
or Python.

I have installed .NET framework latest release.
Unfortunately the pyCrypto project looks abandoned , I couldn't find an
active mailing list and the last release are a couple of year old.

Can some one guide me how to fix the problem above or point me to
another Cyrptography library that I can use easily ?

Thanks.

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


Re: Need help with an array problem.

2006-10-03 Thread Thomas Bellman
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:

>   Of course, there is also the confusion between "type cast" and "type
> conversion" -- at least, for me...

> cast  taking the bit-pattern of a value in one "type" and
> interpreting the same bit-pattern as if it were a different "type"

> conversiontaking the value of a bit-pattern in one "type" and
> converting it to the bit pattern of the equivalent value in another
> "type"

>From where have you learned those definitions?  If it's from C,
then you have read the wrong books.  A cast in C is a type
conversion, with the same semantics as you write under "conversion"
above.  The C standard (ISO/IEC 9899:1999) says:

6.5.4 Cast operators
[...]
Semantics
Preceding an expression by a parenthesized type name converts the
value of the expression to the named type.  This construction is
called a cast.  A cast that specifies no conversion has no effect
on the type or value of an expression.

("A cast that specifies no conversion" refers to when you cast
from one type to the same type, e.g. '(int)x' if x is of the type
'int'.)

You may also try this program:

#include 
#include 

int main(void)
{
/* Assumption: sizeof(float)==sizeof(int).  This is the most
 * common case on modern computers. */
float f = -17.0;
int i = -23;
float fjunk;
int ijunk;

printf("Cast: %d %10.6f\n", (int)f, (float)i);
memcpy(&fjunk, &i, sizeof i);
memcpy(&ijunk, &f, sizeof f);
printf("Bitcopy: %d %10.6f\n", ijunk, fjunk);
return 0;
}

If a cast had been what you believed, both printf() statements
above would give the same output.  Unless your C compiler uses
some really strange floating point representation, they will
print rather different things.  The first one must print

Cast: -17 -23.00

showing very clearly that a cast is a type conversion.  The
second printf() will print some seemingly random numbers, showing
that those bit-patterns will be interpreted very differently when
interpreted as another type.

What you might have been confused by, is dereferencing a casted
pointer.  Add the following statement:

printf("Pointer cast: %d %10.6f\n", *(int*)&f, *(float*)&i);

to the program.  It should output the same numbers as the
"Bitcopy" printf().  But what is cast here is the *address* of
the variables, not the actual contents of them.  It is the
*dereferencing* of those casted pointers that interpret the bit
patterns in the variables as if they were another type, not the
casting itself.


-- 
Thomas Bellman,   Lysator Computer Club,   Linköping University,  Sweden
"I don't think [that word] means what you!  bellman @ lysator.liu.se
 think it means."   -- The Princess Bride!  Make Love -- Nicht Wahr!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: I need Cryptogrphy in Python please .

2006-10-03 Thread Paul Rubin
"NicolasG" <[EMAIL PROTECTED]> writes:
> Can some one guide me how to fix the problem above or point me to
> another Cyrptography library that I can use easily ?

There are several.  What do you want to do with it?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: I need Cryptogrphy in Python please .

2006-10-03 Thread MonkeeSage
NicolasG wrote:
> I have installed .NET framework latest release.

The SDK is different from the framework. ;)

> Can some one guide me how to fix the problem above or point me to
> another Cyrptography library that I can use easily ?

Prebuilt binaries:
http://www.voidspace.org.uk/python/modules.shtml#pycrypto

Ps. The project still looks active to me, and has an active mailing
list:
http://www.amk.ca/python/code/crypto.html

Regards,
Jordan

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


Re: Sockets in python

2006-10-03 Thread Christophe
OneMustFall a écrit :
> 
>> What's your set-up and which cord are you pulling?
>>
> 
> Well i now i think the clue is in the OS, i have sniffed and it seems
> that Twisted have no magic.
> It is seems that i simply tested things in a wrong way -
> when i pulled cord from ethernet card windows determined that network
> lost and started to closing all sockets opened to that network (and so
> EINVAL or other OS error raised when twisted tryed to read wrom that
> socket),
> while the server did had a network - and it was right thing that server
> was thinking that socket is alive.

Stupid Windows behaviour btw! I hate that, it makes testing code 
stability for temporary network lags much much harder to do.

And don't get me started on when we reboot the switch which causes all 
open sockets on my computer to fail, even though the reboot only takes a 
few seconds and though the internet connection doesn't change.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python to use a non open source bug tracker?

2006-10-03 Thread Giovanni Bajo
Hello,

I just read this mail by Brett Cannon:
http://mail.python.org/pipermail/python-dev/2006-October/069139.html
where the "PSF infrastracture committee", after weeks of evaluation, recommends
using a non open source tracker (called JIRA - never heard before of course)
for Python itself.

Does this smell "Bitkeeper fiasco" to anyone else than me?
-- 
Giovanni Bajo


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


Re: app with standalone gui and web interface

2006-10-03 Thread [EMAIL PROTECTED]
Hi Daniel.

> What would the simplest way to make an application that has both a web
> interface and runs from behind a web server but also can be used as a
> standalone app with a gui? More precisely is it possible to avoid
> creating an html/xml/whatever based web interface for the web version
> and separately creating a gui (wxpython for example) for the
> standalone version and instead create a graphical frontend at once
> that can be used for both?

I was experimenting with something roughly similar a couple of years
ago. You might find it interesting. What I did may or may not work in
your case. It depends on what you want to be able to do in the
application.

I built an application that consisted of some server side Java/JSPs
that gave out XML. I used two stylesheets to transform the data into
either HTML (for the web version) or another XML-format called wxWML
(for the wxPython version). Desktop users accessed the application via
a custom "webbrowser" that translates the wxWML to wxPython code which
is executed to generate the GUI. This way, anyone with the wxBrowser
installed could access the application as if it was a desktop app.

But you should know that this was an experiment. We ended up not using
it because it felt weird and because there was not much extra gain to
be had from the desktop part. You should also know that the wxBrowser
is a HUGE security hole which is a good reason not to use it.

You can still download the code I wrote and a "tutorial" PDF from
http://www.pulp.se/wx/ but I haven't touched it since last summer so
I'm not sure it works with the latest version of wxPython. Also, I just
noted that the example URL that I point to on that page doesn't work
because I've moved my hosting since then, but that can be fixed.

Good luck
Johan Lindberg
[EMAIL PROTECTED]

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


Overriding builtin getattr method

2006-10-03 Thread Raja Raman Sundararajan
Hello guys,
I have data stored in the database which has special characters
like <, > etc.
Case 1: Whenever I wanted to present the output to a browser
  I need to escape these special characters into the browser
equivalent like <  > etc.( for example by using the cgi module)
Case 2: Whenever I wanted to present the output to some client other
than a browser, I wanted to present the data as it is stored in the
database.

For doing this I thought of overriding the __builtin__.__getattr__
method.
I am wondering if there is any other way of achieving this. I have
loads of files that get the attribute values of objects stored in the
database and I do not want to manually change the way of DB access in
those files. I rather prefer a centralized way to achieve this.

Good inputs are always appreciated.
:-)
Raja

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


Re: Overriding builtin getattr method

2006-10-03 Thread Raja Raman Sundararajan
Correction: I meant __builtin__.getattr method and not the other one I
mentioned.
:-)
Thanks
Raja

Raja Raman Sundararajan skrev:

> Hello guys,
> I have data stored in the database which has special characters
> like <, > etc.
> Case 1: Whenever I wanted to present the output to a browser
>   I need to escape these special characters into the browser
> equivalent like <  > etc.( for example by using the cgi module)
> Case 2: Whenever I wanted to present the output to some client other
> than a browser, I wanted to present the data as it is stored in the
> database.
>
> For doing this I thought of overriding the __builtin__.__getattr__
> method.
> I am wondering if there is any other way of achieving this. I have
> loads of files that get the attribute values of objects stored in the
> database and I do not want to manually change the way of DB access in
> those files. I rather prefer a centralized way to achieve this.
> 
> Good inputs are always appreciated.
> :-)
> Raja

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Robert Kern
Giovanni Bajo wrote:
> Hello,
> 
> I just read this mail by Brett Cannon:
> http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> where the "PSF infrastracture committee", after weeks of evaluation, 
> recommends
> using a non open source tracker (called JIRA - never heard before of course)
> for Python itself.
> 
> Does this smell "Bitkeeper fiasco" to anyone else than me?

No.

-- 
Robert Kern

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

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


Re: Simple but fast 2D lib for drawing pixels

2006-10-03 Thread Peter Ilgenschütz
Thanks Dave for this tip, this is excellent, exactly what I have been
looking for!
I'm using it already :-)

Kind Regards,
Peter

[EMAIL PROTECTED] wrote:
>
> On Oct 1, 2006, at 6:28 PM, Peter Mexbacher wrote:
>
>> Hello,
>>
>> we want to teach absolute programming newbies
>> a first language, so they can start programming
>> simple scientific models.
>>
>> We thought Python would make a good choice for
>> a first language; but where pretty stumped when
>> we found out that there is no simple way to draw
>> pixels to a screen. (This is needed for fractals,
>> agent-based models etc -> like Conways Game of Life)
>>
>> Our requirements:
>>
>> -) easy to learn (newbs!)
>> -) not too slow (after all, the models should simulate something)
>> -) python :-)
>>
>> Any ideas?
>>
>> Best Regards,
>> Peter
>
>
> You might check out John Zelle's Python book - he uses a simple
> graphics library on top of Tk (which Python comes with). You can find
> information on his book and the graphics.py file he uses at:
>
> http://mcsp.wartburg.edu/zelle/python/
>
> It certainly meets your easy to learn and Python requirements - and of
> course speed is subjective so it may or may not be fast enough for you.
>
> Dave
>
>
>
>
>

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Fredrik Lundh
Giovanni Bajo wrote:

> I just read this mail by Brett Cannon:
> http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> where the "PSF infrastracture committee", after weeks of evaluation, 
> recommends
> using a non open source tracker (called JIRA - never heard before of course)
> for Python itself.
> 
> Does this smell "Bitkeeper fiasco" to anyone else than me?

not necessarily (and good support for data export is high on the 
requirements list), but for those of us who's been following the 
committee's work, there has indeed been a disturbing amount of
"free as in - oh shiny!" from the very beginning.

however, note that the committee do realize that using a Python-
powered tool for Python is a good thing in itself; they are asking
for volunteers that can keep a roundup instance running, and fix
any issues that arises.  python.org has plenty of hardware, but not 
enough manpower to do everything that could be done.  see brett's
post for details.



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


Re: I need Cryptogrphy in Python please .

2006-10-03 Thread NicolasG
I have made a site using Karrigell as a web server and I want to
provide cryptography services to the visitors. They should wirte their
text on the site and be able choose different encryption algorithms to
apply on the text .

MonkeeSage wrote:
> NicolasG wrote:
> > I have installed .NET framework latest release.
>
> The SDK is different from the framework. ;)

How can I fix this ?

>
> > Can some one guide me how to fix the problem above or point me to
> > another Cyrptography library that I can use easily ?
>
> Prebuilt binaries:
> http://www.voidspace.org.uk/python/modules.shtml#pycrypto

I need the modules source to use it with my web server.

> Ps. The project still looks active to me, and has an active mailing
> list:
> http://www.amk.ca/python/code/crypto.html

The last messages in the mailing list was on august (only one message)
and the author does  said that he does not reply to the this list , he
point if anyone have an issue to use the bug trucker at sourceforge
which looks not helpful ...

cheers.. 

> Jordan

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


Re: I need Cryptogrphy in Python please .

2006-10-03 Thread Paul Rubin
"NicolasG" <[EMAIL PROTECTED]> writes:
> I have made a site using Karrigell as a web server and I want to
> provide cryptography services to the visitors. They should wirte their
> text on the site and be able choose different encryption algorithms to
> apply on the text .

Um, why?  Just as an exercise?  If that's the case, you might enjoy
implementing the algorithms in Python.  They'd be slow but that might
not matter.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Paul Rubin
"Giovanni Bajo" <[EMAIL PROTECTED]> writes:
> I just read this mail by Brett Cannon:
> http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> where the "PSF infrastracture committee", after weeks of evaluation,
> recommends using a non open source tracker (called JIRA - never
> heard before of course) for Python itself.
> 
> Does this smell "Bitkeeper fiasco" to anyone else than me?

Sounds crazy, what's wrong with bugzilla?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Overriding builtin getattr method

2006-10-03 Thread Gabriel Genellina

At Tuesday 3/10/2006 05:24, Raja Raman Sundararajan wrote:


Hello guys,
I have data stored in the database which has special characters
like <, > etc.
Case 1: Whenever I wanted to present the output to a browser
  I need to escape these special characters into the browser
equivalent like <  > etc.( for example by using the cgi module)
Case 2: Whenever I wanted to present the output to some client other
than a browser, I wanted to present the data as it is stored in the
database.

For doing this I thought of overriding the __builtin__.__getattr__
method.


Not very reasonable on the source object itself. Escaping <&> is a 
*presentation* requirement and should be managed at that level. For 
example, in a PageTemplate, using tal:content or tal:attribute does 
the right escaping.



I am wondering if there is any other way of achieving this. I have
loads of files that get the attribute values of objects stored in the
database and I do not want to manually change the way of DB access in
those files. I rather prefer a centralized way to achieve this.


If your data contains a '<', that's OK, it's the real contents and 
should remain that way.

If you have to build an HTML page, escape those characters at *that* stage.
If you have to write a CSV file, perhaps a '<' is irrelevant but a 
',' is problematic.

For some Windows text controls you have to escape '&' characters.
None of these operations should make you to change your data, or the 
way you access your data. You invoke them at the presentation stage, 
depending on the final target.




Gabriel Genellina
Softlab SRL 







__ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 

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

Re: Python to use a non open source bug tracker?

2006-10-03 Thread Fredrik Lundh
Robert Kern wrote:

>> Does this smell "Bitkeeper fiasco" to anyone else than me?
> 
> No.

that's just not true.  lots of people have voiced concerns over using 
closed-sourced stuff originally designed for enterprise-level Java users 
for an application domain where Python has several widely used agile 
alternatives to chose from.

if they hadn't done so, there probably wouldn't have been an evaluation 
period in the first place.



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


Re: Overriding builtin getattr method

2006-10-03 Thread Diez B. Roggisch
>> I have data stored in the database which has special characters
>> like <, > etc.
>> Case 1: Whenever I wanted to present the output to a browser
>>   I need to escape these special characters into the browser
>> equivalent like <  > etc.( for example by using the cgi module)
>> Case 2: Whenever I wanted to present the output to some client other
>> than a browser, I wanted to present the data as it is stored in the
>> database.
>>
>> For doing this I thought of overriding the __builtin__.__getattr__
>> method.
>> I am wondering if there is any other way of achieving this. I have
>> loads of files that get the attribute values of objects stored in the
>> database and I do not want to manually change the way of DB access in
>> those files. I rather prefer a centralized way to achieve this.

The centralized approach to this is certainly not achieved by 
overloading getattr alone - because even if it was possible to do so 
(which it isn't), the implementation needed a way to know when to use 
escaping or not. Which would be signaled by some means, e.g. a 
thread-local variable or even a global (shudder).

This signal gets set in the code that decides that it wants the data 
escaped - or not. And thus the code looks like this:

needs_escaping()
work_with_objects()
no_escaping_anymore()

But that is fragile, think of work_with_objects() throwing an exception 
and the no_escaping_anymore() isn't called again.

So the better approach is to gather the data as it is, and when you 
transform it to something that requires escaping, do it there.

That means: the way to do it is to use one of the gazillion web 
templating systems that already do this escaping for you.

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


Re: loop beats generator expr creating large dict!?

2006-10-03 Thread Ant

George Young wrote:
...
> I am puzzled that creating large dicts with an explicit iterable of
> key,value pairs seems to be slow.  I thought to save time by doing:
>
>palettes = dict((w,set(w)) for w in words)
>
> instead of:
>
>palettes={}
>for w in words:
>   palettes[w]=set(w)

In the generator case, you are first creating a tuple, and then
assigning the first element of the tuple as the key and the second
element as the value in the dictionary. In the loop, you are directly
setting the key and value in the dictionary.

Essentially by doing the generator (or comprehension), you are packing
and unpacking the key, value pairs for each word in your initial list,
all of which will have an overhead.

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


Re: I need Cryptogrphy in Python please .

2006-10-03 Thread MonkeeSage
NicolasG wrote:
> I need the modules source to use it with my web server.

I thought you were trying to compile and install the pyCrypto
extension? If that is the case, then download the installer from the
page I linked to.

Regards,
Jordan

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


Ctypes and freeing memory

2006-10-03 Thread Oliver Andrich
Hi everybody,

I am currently playing around with ctypes and a C library (libWand
from ImageMagick), and as I want to easily deploy it on Mac, Linux and
Windows, I prefer a ctypes solution over a C module. At least on
windows, I would have resource problems to compile the C module. So,
ctypes is the perfect choice for me.

But I am currently encountering a pattern inside the C library, that
has to be used to free memory. Coding in C I have to do the following

char *description;
long  severity;

description = MagickGetException(wand, &severity);
/*
do something with the description: print it, log it, ...
*/
description = (char *) MagickRelinquishMemory(description);
exit(-1); /* or something else what I want to after an exception occured */

So, this looks easy and is sensible from C's point of view. Now I try
to translate this to Python and ctypes.

dll.MagickGetException.argtypes = [c_long, POINTER(c_long)]
dll.MagickGetException.restype  = c_char_p

severity = c_long()
description = dll.MagickGetException(byref(severity))

# So far so good. The above works like a charm, but the problem follows now
# ctypes already converted the char * for description to a String object.
# That means description has arrived in an area under Python's control.

# these definitions are the easy part
dll.MagickRelinquishMemory.argtypes = [c_void_p]
dll.MagickRelinquishMemory.restype  = c_char_p

# but this obviously must cause problems and causes problems
dll.MagickRelinquishMemory(description)

So, my question is, how do I deal with this situation? Can I ignore
the call to MagickRelinquishMemory, cause Python takes care of the
resources already? Or is it impossible to use it at all, and I have to
think about a different solution?

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Howto pass Array/Hash into Function

2006-10-03 Thread Wijaya Edward

Hi,
 
How can I pass Array, Hash, and a plain variable
in to a function at the same time.
 
I come from Perl. Where as you probably know
it is done like this:
 
sub myfunc {
 
my ($plain_var, $hash_ref,$arref) = @_;
# Do sth with those variables
 
   return;
}
 
I wonder how can that be done in Python.
 
Regards,
Edward WIJAYA
SINGAPORE

 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.

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


Re: Howto pass Array/Hash into Function

2006-10-03 Thread MonkeeSage
Wijaya Edward wrote:
> I wonder how can that be done in Python.

def myfunc(plain_var, hash_ref, arref):
  # Do sth with those variables
  return

Regards,
Jordan

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


Re: Howto pass Array/Hash into Function

2006-10-03 Thread Wildemar Wildenburger
MonkeeSage wrote:
> Wijaya Edward wrote:
>> I wonder how can that be done in Python.
> 
> def myfunc(plain_var, hash_ref, arref):
>   # Do sth with those variables
>   return

At the risk of being a jerk (sorry, I'm really just curious):
Why isn't that obvious?

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


Re: Howto pass Array/Hash into Function

2006-10-03 Thread MonkeeSage
Wildemar Wildenburger wrote:
> MonkeeSage wrote:
> > Wijaya Edward wrote:
> >> I wonder how can that be done in Python.
> >
> > def myfunc(plain_var, hash_ref, arref):
> >   # Do sth with those variables
> >   return
>
> At the risk of being a jerk (sorry, I'm really just curious):
> Why isn't that obvious?
>
> wildemar (sorry)

I wondered that too and wasn't even going to answer, but then I thought
mabye the question was meant to be more general, like "what is the
syntax for passing objects to functions in python?"

Regards,
Jordan

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


Re: Howto pass Array/Hash into Function

2006-10-03 Thread Gabriel G

At Tuesday 3/10/2006 06:05, Wijaya Edward wrote:


How can I pass Array, Hash, and a plain variable
in to a function at the same time.

I come from Perl. Where as you probably know
it is done like this:

sub myfunc {

my ($plain_var, $hash_ref,$arref) = @_;
# Do sth with those variables

   return;
}


In Python your functions have formal arguments:

def myfunc(plain_var, some_dict, some_list):
# ...
return

You also have positional and keyword arguments, and default values. 
Read the Python tutorial 




Gabriel Genellina
Softlab SRL 






__
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas


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

Re: CGI -> mod_python

2006-10-03 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
>
> it is a kind of nooby question. Is there a way to transfer a CGI python
> script to mod_python without rewriting the code?

Had you used WebStack [1] to begin with, this migration would involve
changing a few lines of glue code. However, as others have pointed out,
WSGI may be an appropriate API to target for a modest rewrite of the
code, given substantial resemblances to aspects of the CGI API.

Paul

[1] http://www.python.org/pypi/WebStack

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


Re: app with standalone gui and web interface

2006-10-03 Thread Daniel Nogradi
> > What would the simplest way to make an application that has both a web
> > interface and runs from behind a web server but also can be used as a
> > standalone app with a gui? More precisely is it possible to avoid
> > creating an html/xml/whatever based web interface for the web version
> > and separately creating a gui (wxpython for example) for the
> > standalone version and instead create a graphical frontend at once
> > that can be used for both?
>
> I was experimenting with something roughly similar a couple of years
> ago. You might find it interesting. What I did may or may not work in
> your case. It depends on what you want to be able to do in the
> application.
>
> I built an application that consisted of some server side Java/JSPs
> that gave out XML. I used two stylesheets to transform the data into
> either HTML (for the web version) or another XML-format called wxWML
> (for the wxPython version). Desktop users accessed the application via
> a custom "webbrowser" that translates the wxWML to wxPython code which
> is executed to generate the GUI. This way, anyone with the wxBrowser
> installed could access the application as if it was a desktop app.
>
> But you should know that this was an experiment. We ended up not using
> it because it felt weird and because there was not much extra gain to
> be had from the desktop part. You should also know that the wxBrowser
> is a HUGE security hole which is a good reason not to use it.
>
> You can still download the code I wrote and a "tutorial" PDF from
> http://www.pulp.se/wx/ but I haven't touched it since last summer so
> I'm not sure it works with the latest version of wxPython. Also, I just
> noted that the example URL that I point to on that page doesn't work
> because I've moved my hosting since then, but that can be fixed.


Thanks for the suggestions, I'll look into both methods. Having a
local webserver seems pretty easy and convenient.

Johan, your way of doing it resembles XUL somewhat, although I can't
say I fully understand XUL I just took a look some days ago. Let me
see if I understand your approach:

If you want to have something very dynamical you do it the way you
described with the wxwml source getting parsed, converted to wxpython
and then run by python all at once. At the same time the webserver can
fetch the same wxwml source, convert it into html/xml and send that to
the web client. Now if one wants to bypass wxbrowser and the real time
conversion to wxpython, then, sacrificing some level of dynamicness,
why not convert the wxwml source 'statically' into wxpython, bundle
that as an app and at the same time convert it also to xml/html
'statically' and have that served by a webserver. In this way any time
the gui changes one needs to go through both convertions once, bundle
the desktop app again, update the webserver but there won't be any
security whole or any magic that is not pure python or not pure
html/xml. Does this sound reasonable or am I misunderstanding
something?

In fact something like that is the thing I'm looking for, some
language that can specify a gui and can be used to generate
'statically' both wxpython source (or some other widget set) or
html/xml source.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI -> mod_python

2006-10-03 Thread Jon Ribbens
In article <[EMAIL PROTECTED]>, Paul Boddie wrote:
>> it is a kind of nooby question. Is there a way to transfer a CGI python
>> script to mod_python without rewriting the code?
> 
> Had you used WebStack [1] to begin with, this migration would involve
> changing a few lines of glue code.

Or Jonpy ;-)

http://jonpy.sf.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Artificial Mind - Part One - Basic Architecture and Cognitive Structure is now available

2006-10-03 Thread tommak
It's a dream of human beings to build machines that can think and
behave like human beings.  The most important part of of such a machine
is an artificial mind that can emulate the cognitive processing of
human mind.

This book, "Next Generation Artificial Intelligence, Artificial Mind -
Part One - Basic Architecture and Cognitive Structure" introduces a
basic artificial mind architecture and computational model for
cognitive processing.  Inside the book, three important cognitive
process modeling components, mental objects network (MON),
associative-learning mechanisms and a concept formation principle are
introduced.  Based on the architecture and the computational model, one
can develop his own model of artificial mind according to his own
specific requirements.

The first edition of Artificial Mind - Part One is now available for
purchase from the author's personal web site. The price of the e-book
is USD7.00 (seven US dollars).  An evaluation edition of this e-book is
also available for download from the web site.

The author's personal web site:
http://www.geocities.com/tomwingmak/

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


Raw strings and escaping

2006-10-03 Thread Matthew Warren
Hi,

I would expect this to work,

rawstring=r'some things\new things\some other things\'

But it fails as the last backslash escapes the single quote.

..although writing this I think I have solved my own problem. Is \' the
only thing escaped in a raw string so you can place ' in a raw string?
Although I thought the correct thing in that case would be;

rawstring=r"rawstring'with single-quote"


This email is confidential and may be privileged. If you are not the intended 
recipient please notify the sender immediately and delete the email from your 
computer. 

You should not copy the email, use it for any purpose or disclose its contents 
to any other person.
Please note that any views or opinions presented in this email may be personal 
to the author and do not necessarily represent the views or opinions of Digica.
It is the responsibility of the recipient to check this email for the presence 
of viruses. Digica accepts no liability for any damage caused by any virus 
transmitted by this email.

UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK
Reception Tel: + 44 (0) 115 977 1177
Support Centre: 0845 607 7070
Fax: + 44 (0) 115 977 7000
http://www.digica.com

SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South 
Africa
Tel: + 27 (0) 21 957 4900
Fax: + 27 (0) 21 948 3135
http://www.digica.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Steve Holden
Paul Rubin wrote:
> "Giovanni Bajo" <[EMAIL PROTECTED]> writes:
> 
>>I just read this mail by Brett Cannon:
>>http://mail.python.org/pipermail/python-dev/2006-October/069139.html
>>where the "PSF infrastracture committee", after weeks of evaluation,
>>recommends using a non open source tracker (called JIRA - never
>>heard before of course) for Python itself.
>>
>>Does this smell "Bitkeeper fiasco" to anyone else than me?
> 
> 
> Sounds crazy, what's wrong with bugzilla?

Much the same as is wrong with the existing SourceForge system, I'd say.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Best way to handle large lists?

2006-10-03 Thread Chaz Ginger
I have a system that has a few lists that are very large (thousands or
tens of thousands of entries) and some that are rather small. Many times
I have to produce the difference between a large list and a small one,
without destroying the integrity of either list. I was wondering if
anyone has any recommendations on how to do this and keep performance
high? Is there a better way than

[ i for i in bigList if i not in smallList ]

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


Re: Raw strings and escaping

2006-10-03 Thread Rob Williscroft
Matthew Warren wrote in news:mailman.1152.1159872720.10491.python-
[EMAIL PROTECTED] in comp.lang.python:

> I would expect this to work,
> 
> rawstring=r'some things\new things\some other things\'

It in the docs:

http://docs.python.org/ref/strings.html#l2h-14>

...  Specifically, a raw string cannot end in a single backslash (since the 
backslash would escape the following quote character). Note also that a 
single backslash followed by a newline is interpreted as those two 
characters as part of the string, not as a line continuation. 

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


Re: Raw strings and escaping

2006-10-03 Thread Duncan Booth
"Matthew Warren" <[EMAIL PROTECTED]> wrote:

> I would expect this to work,
> 
> rawstring=r'some things\new things\some other things\'
> 
> But it fails as the last backslash escapes the single quote.
> 
> ..although writing this I think I have solved my own problem. Is \'
> the only thing escaped in a raw string so you can place ' in a raw
> string? Although I thought the correct thing in that case would be;
> 
> rawstring=r"rawstring'with single-quote"

You cannot end *any* string literal with an odd number of backslash 
characters. The "r" prefix changes how the escape sequences are interpreted 
after the string literal has been parsed, it doesn't change how the literal 
itself is actually parsed. See the Python Reference Manual, 2.4.1:

> When an "r" or "R" prefix is present, a character following a
> backslash is included in the string without change, and all
> backslashes are left in the string. For example, the string literal
> r"\n" consists of two characters: a backslash and a lowercase "n".
> String quotes can be escaped with a backslash, but the backslash
> remains in the string; for example, r"\"" is a valid string literal
> consisting of two characters: a backslash and a double quote; r"\" is
> not a valid string literal (even a raw string cannot end in an odd
> number of backslashes). Specifically, a raw string cannot end in a
> single backslash (since the backslash would escape the following quote
> character). Note also that a single backslash followed by a newline is
> interpreted as those two characters as part of the string, not as a
> line continuation. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to handle large lists?

2006-10-03 Thread Duncan Booth
Chaz Ginger <[EMAIL PROTECTED]> wrote:

> I have a system that has a few lists that are very large (thousands or
> tens of thousands of entries) and some that are rather small. Many times
> I have to produce the difference between a large list and a small one,
> without destroying the integrity of either list. I was wondering if
> anyone has any recommendations on how to do this and keep performance
> high? Is there a better way than
> 
> [ i for i in bigList if i not in smallList ]

How about:

smallSet = set(smallList)
something = [ i for i in bigList if i not in smallSet ]

Use timeit.py on some representative data to see what difference that 
makes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to handle large lists?

2006-10-03 Thread Paul Rubin
Chaz Ginger <[EMAIL PROTECTED]> writes:
> I have a system that has a few lists that are very large (thousands or
> tens of thousands of entries) and some that are rather small. Many times
> I have to produce the difference between a large list and a small one,
> without destroying the integrity of either list. I was wondering if
> anyone has any recommendations on how to do this and keep performance
> high? Is there a better way than
> 
> [ i for i in bigList if i not in smallList ]

diff = list(set(bigList) - set(smallList))

Note that doesn't get you the elements in any particular order.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Raw strings and escaping

2006-10-03 Thread Jon Ribbens
In article <[EMAIL PROTECTED]>, Matthew Warren wrote:
> I would expect this to work,
> 
> rawstring=r'some things\new things\some other things\'
> 
> But it fails as the last backslash escapes the single quote.

String constants in Python are weird - raw strings doubly so.
In a raw string, backslashes are not special - unless followed by
a quote character, when they simultaneously escape the quote and
also insert a literal backslash.

I presume there was originally some reason for this bizarre behaviour
- it'd be interesting to know what it is/was, if anyone knows?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: app with standalone gui and web interface

2006-10-03 Thread [EMAIL PROTECTED]
> Johan, your way of doing it resembles XUL somewhat, although I can't
> say I fully understand XUL I just took a look some days ago. Let me
> see if I understand your approach:

Yes it's a lot like XUL, but there are some major differences. The most
important one is that, at least back then, you had to use JavaScript.
Also, XUL had (has) a much more limited set of widgets and you can't
escape the surrounding Browser.

> If you want to have something very dynamical you do it the way you
> described with the wxwml source getting parsed, converted to wxpython
> and then run by python all at once. At the same time the webserver can
> fetch the same wxwml source, convert it into html/xml and send that to
> the web client. Now if one wants to bypass wxbrowser and the real time
> conversion to wxpython, then, sacrificing some level of dynamicness,
> why not convert the wxwml source 'statically' into wxpython, bundle
> that as an app and at the same time convert it also to xml/html
> 'statically' and have that served by a webserver. In this way any time
> the gui changes one needs to go through both convertions once, bundle
> the desktop app again, update the webserver but there won't be any
> security whole or any magic that is not pure python or not pure
> html/xml. Does this sound reasonable or am I misunderstanding
> something?
>
> In fact something like that is the thing I'm looking for, some
> language that can specify a gui and can be used to generate
> 'statically' both wxpython source (or some other widget set) or
> html/xml source.

Ok, there are ways to do that... sort of.

You could modify or extend the wxBrowser to do this but you should
really have a look at extending XRC (have a look at XRCed which comes
with wxPython if you don't know what it is). Even though it doesn't do
*everything* you want it's a good place to start.

An XRC-file is an XML-specification of a wx GUI which can be loaded by
a wxApp to generate a "static" GUI. However, if you want any sort of
functionality to go with your program you're going to have to find a
way to also include the equivalent of HTML script-tags that you can
hook into wx event-handlers. I don't think XRC has that.

Also, last time I looked, XRC is very sensitive so if you do change the
format here and there to include other stuff, make sure to remove it
before you try to parse it in the wxApp (it complains otherwise, or at
least it used to).

The wxBrowser does all of this for you, but at run time, there's
currently no way of packaging it all up in one big XML file that could
be saved as wxPython source. But it's sure doable. I don't know which
is easier but either way, I'm guessing that you're going to have to
write some code of your own.

If you decide to extend/modify the wxBrowser, let me know, I might be
able to help you out.

BR
Johan Lindberg
[EMAIL PROTECTED]

PS
You should also ask around at the wxPython-users list
(http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/wxPython-users).

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


Re: app with standalone gui and web interface

2006-10-03 Thread olive

I agree with Steve and I would advise to use an Ajax toolkit (such as
JQuery for example) which will help to make your UI act as a desktop
application (and even better if you are creative).
Olive.

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread [EMAIL PROTECTED]
Giovanni Bajo wrote:

> Does this smell "Bitkeeper fiasco" to anyone else than me?

I can't understand why people waste time arguing this stuff.

Use whatever tool is best at it's job... if it's not written in Python
it doesn't mean that Python is not good for the task, only that there
hasn't been any Python programmer that applied himself to the problem
hard enough.

And i dunno what the case against Trac is (it looks a fine tool for my
small projects) but probably it's not good enough for python.org

And BTW BitKeeper failed because Linus wanted to stop Tridge reverse
engineering BitKeeper, not because BK wasn't good.

Lorenzo

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


py2app console

2006-10-03 Thread James Stroud
Hello,

Does anyone know of the most straightforward way to get rid of the 
intensely annoying "console" window that py2app feels so compelled to 
create?

On a related but less important note, why would anyone want that stupid 
window in the first place?

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


Re: Raw strings and escaping

2006-10-03 Thread Duncan Booth
Jon Ribbens <[EMAIL PROTECTED]> wrote:

> I presume there was originally some reason for this bizarre behaviour
> - it'd be interesting to know what it is/was, if anyone knows?
> 
See the FAQ for the explanation:

http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash

The idea is that if you use raw strings for regular expressions you can 
write things like:

  pattern = r'[\'"]'

if the raw string simply ignored the backslash altogether it would be much 
harder to write regular expressions that contain both sorts of quotes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to handle large lists?

2006-10-03 Thread durumdara
Chaz Ginger írta:
> I have a system that has a few lists that are very large (thousands or
> tens of thousands of entries) and some that are rather small. Many times
> I have to produce the difference between a large list and a small one,
> without destroying the integrity of either list. I was wondering if
> anyone has any recommendations on how to do this and keep performance
> high? Is there a better way than
>
> [ i for i in bigList if i not in smallList ]
>
> Thanks.
> Chaz
>   
Hi !

If you have big list, you can use dbm like databases.
They are very quick. BSDDB, flashdb, etc. See SleepyCat, or see python help.

In is very slow in large datasets, but bsddb is use hash values, so it
is very quick.
The SleepyCat database have many extras, you can set the cache size and
many other parameters.

Or if you don't like dbm style databases, you can use SQLite. Also
quick, you can use SQL commands.
A little slower than bsddb, but it is like SQL server. You can improve
the speed with special parameters.

dd

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Ben Finney
Steve Holden <[EMAIL PROTECTED]> writes:

> Paul Rubin wrote:
> > "Giovanni Bajo" <[EMAIL PROTECTED]> writes:
> >>I just read this mail by Brett Cannon:
> >>http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> >>where the "PSF infrastracture committee", after weeks of evaluation,
> >>recommends using a non open source tracker (called JIRA - never
> >>heard before of course) for Python itself.
> >>
> >>Does this smell "Bitkeeper fiasco" to anyone else than me?
> > 
> > Sounds crazy, what's wrong with bugzilla?
>
> Much the same as is wrong with the existing SourceForge system, I'd say.

The existing SourceForge system runs on non-free software, which is a
significant differentiator from Bugzilla.

I would be greatly dismayed to see the PSF choosing to move critical
Python development data into a non-free system. I hope this
recommendation from the "PSF infrastructure committee" is rejected.

-- 
 \   "There is no reason anyone would want a computer in their |
  `\  home."  -- Ken Olson, president, chairman and founder of |
_o__)Digital Equipment Corp., 1977 |
Ben Finney

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


Manipulate PDFs

2006-10-03 Thread Weko Altamirano
Hi Everyone, am a developer using Zope and wanted to know if any of you have ever implemented a pdf generating/creating system using python? This just means mostly manipulating pdfs (create and/or edit) via web. If you guys have any suggestions or recommendations please post, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Python to use a non open source bug tracker?

2006-10-03 Thread Paul Boddie
Paul Rubin wrote:
> "Giovanni Bajo" <[EMAIL PROTECTED]> writes:
> >
> > Does this smell "Bitkeeper fiasco" to anyone else than me?

I probably said as much before, possibly to the distaste of some
individuals. Still, the BitKeeper story should serve as a reminder
about relinquishing control of infrastructure to some seemingly
benevolent third party with their own separate interests. It should
especially be a reminder to those who deem Torvalds-style "overt
pragmatism" to be virtuous in the face of supposedly ideological
realism.

Of course, there's presumably a huge gulf between the vendor in this
case and the vendor in the BitKeeper case, especially with respect to
draconian non-compete clauses and threats to sue one's own customers.
However, it's certainly not some kind of heresy to at least question
the wisdom of moving community resources and services around in such a
way. After all, this situation has been brought about because of a
dependence on a supposedly unreliable commercial third party.

> Sounds crazy, what's wrong with bugzilla?

Well, Bugzilla is a bit of a monster. ;-) Seriously, having installed
it, it seems like a relic of the early CGI period with a bunch of files
that you're supposed to throw in a CGI directory before performing
.htaccess surgery, which they admittedly do for you if you choose to
trust that particular method of deployment. Contrast that with various
other common Web applications which only put actual CGI programs within
the CGI directory, making the whole deployment much cleaner and easier
to troubleshoot/maintain, and you can see that there's a serious need
for some repackaging work.

Sure, there are scripts to help check dependencies, which meant a trip
to CPAN (not as joyous as its advocates would have you believe), and
there is a nice configuration system in Bugzilla's own Web interface
which helps you finish the job off (providing you don't forget
something in the 16 pages of settings), but there's always this nasty
suspicion that something somewhere probably isn't configured properly.
Finally, on the subject of the inner workings of Bugzilla, one is
presented with the amusement of diving into Perl to fix stuff:
something that not everyone is enthusiastic about.

As for Bugzilla's interface, it is telling that some open source
projects actually put a layer on top of Bugzilla in order to avoid the
complexity of the search interface, although it must be said that
recent versions don't seem to immediately throw up the page with 40 or
so controls on it, just to search for a bug. That said, the fact that
many open source projects continue to use Bugzilla would suggest that
they're either not interested in or aware of alternatives (quite
possible), or they're reasonably happy with it (also quite possible).

Paul

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


py_s60 HELP

2006-10-03 Thread vedran_dekovic
Hello,
I using py_s60 for calling from my program to phone,but I have one
problem.
When I want run py_s60 with python 2.4:

FIRST ERROR:

>>> import telephone
Traceback (most recent call last):
  File "", line 1, in -toplevel-
if e32.s60_version_info>=(3,0):
AttributeError: 'module' object has no attribute 's60_version_info'


SECOND ERROR:
>>> import telephone
Traceback (most recent call last):
  File "", line 1, in -toplevel-
import _telephone
ImportError: No module named _telephone

...I was search everywhere for that module but I can't find it



  THANKS FOR HELP!

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


was python implemented as a object oriented langage at the beginning ?

2006-10-03 Thread Bertrand Ballis
Hello,I heard a lot of people from the Ruby community claiming that Python, like Perl, was a scripting langagethat was changed aftewards to be object compatible, and that was making it not as good as Ruby, object-oriented from the begenning.
Is that true ?Thanks for your answersBertrand
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Howto pass Array/Hash into Function

2006-10-03 Thread Steve Holden
MonkeeSage wrote:
> Wildemar Wildenburger wrote:
> 
>>MonkeeSage wrote:
>>
>>>Wijaya Edward wrote:
>>>
I wonder how can that be done in Python.
>>>
>>>def myfunc(plain_var, hash_ref, arref):
>>>  # Do sth with those variables
>>>  return
>>
>>At the risk of being a jerk (sorry, I'm really just curious):
>>Why isn't that obvious?
>>
>>wildemar (sorry)
> 
> 
> I wondered that too and wasn't even going to answer, but then I thought
> mabye the question was meant to be more general, like "what is the
> syntax for passing objects to functions in python?"
> 
It wouldn't be obvious to someone who learned Perl as their first 
programming language because Perl chose to ignore the otherwise almost 
universal convention that formal parameters determine the arguments that 
a function or procedure can be calles with.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Oliver Andrich
Hi,

On 10/3/06, Giovanni Bajo <[EMAIL PROTECTED]> wrote:
> I just read this mail by Brett Cannon:
> http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> where the "PSF infrastracture committee", after weeks of evaluation, 
> recommends
> using a non open source tracker (called JIRA - never heard before of course)
> for Python itself.
>
> Does this smell "Bitkeeper fiasco" to anyone else than me?

No, this doesn't smell like the BK fiasco, it is just the decision to
use a certain tool. But it is easy to change or influence this
recommondation. Step up as an admin for Roundup. :)

Best regards,
Oliver
-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: py2app console

2006-10-03 Thread James Stroud
James Stroud wrote:
> Hello,
> 
> Does anyone know of the most straightforward way to get rid of the 
> intensely annoying "console" window that py2app feels so compelled to 
> create?
> 
> On a related but less important note, why would anyone want that stupid 
> window in the first place?
> 
> James

I should mention that this is the ridiculously pointless Tcl shell 
created when deploying a TkAqua application with py2app. Surely there 
has to be a better place to practice one's Tcl programming than from the 
console window of a bundled application that would otherwise be fit for 
end-users--except for the stupid Tcl console that no one will bother to 
use but is just frickin' desktop clutter.

## This is not the stdout console of the shell terminal, etc. ##

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


Re: Overriding builtin getattr method

2006-10-03 Thread Raja Raman Sundararajan
Hello Gabriel Genellina  and Diez B. Roggisch,
Thanks for sharing your opinions. I agree with Gabriel when he
talks about the separation between the presentation and the DB level
access and the drawbacks of introducing character manipulation. The
problem that I am facing right now is that the presentation layer uses
several different page rendering machines (about 12).
Some of them use the escaping techniques that presents browser reserved
characters to be  "unrunnable" <,> we just some examples, so far so
great. But the other presentation layer engines(about 9) used are basic
(optimized for fast rendering) and do not use such filtering/encoding
mechanisms. Since the amount of files that is used by the "basic"
rendering machines are quite high, I am forced to fix the problem in a
much lower level.

I have found a work around for it...since the pages presented by the
basic rendering machines knows about objects fetched from the DB and
the type of request(which presentation engine to use) generated, I
collect information about these in a struct. This struct also contains
information about the level of encoding needed.

I overrode __getattribute__ method (which is always called when
one fetches an attribute of an object) in the base class and introduced
encoding level in the class. The __getattribute__ then checks for the
level of encoding needed depending on the infor from the struct and
returns the encoded data to the presentation layer when needed. The
business object or the functional layer is unaffected as the default
value returned by the __getattribute__ is the unencoded data from the
DB.

Raja


Diez B. Roggisch skrev:

> >> I have data stored in the database which has special characters
> >> like <, > etc.
> >> Case 1: Whenever I wanted to present the output to a browser
> >>   I need to escape these special characters into the browser
> >> equivalent like <  > etc.( for example by using the cgi module)
> >> Case 2: Whenever I wanted to present the output to some client other
> >> than a browser, I wanted to present the data as it is stored in the
> >> database.
> >>
> >> For doing this I thought of overriding the __builtin__.__getattr__
> >> method.
> >> I am wondering if there is any other way of achieving this. I have
> >> loads of files that get the attribute values of objects stored in the
> >> database and I do not want to manually change the way of DB access in
> >> those files. I rather prefer a centralized way to achieve this.
>
> The centralized approach to this is certainly not achieved by
> overloading getattr alone - because even if it was possible to do so
> (which it isn't), the implementation needed a way to know when to use
> escaping or not. Which would be signaled by some means, e.g. a
> thread-local variable or even a global (shudder).
>
> This signal gets set in the code that decides that it wants the data
> escaped - or not. And thus the code looks like this:
>
> needs_escaping()
> work_with_objects()
> no_escaping_anymore()
>
> But that is fragile, think of work_with_objects() throwing an exception
> and the no_escaping_anymore() isn't called again.
>
> So the better approach is to gather the data as it is, and when you
> transform it to something that requires escaping, do it there.
>
> That means: the way to do it is to use one of the gazillion web
> templating systems that already do this escaping for you.
> 
> Diez

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


Re: Artificial Mind - Part One - Basic Architecture and Cognitive Structure is now available

2006-10-03 Thread Steve Holden
tommak wrote:
> It's a dream of human beings to build machines that can think and
> behave like human beings.  The most important part of of such a machine
> is an artificial mind that can emulate the cognitive processing of
> human mind.
> 
> This book, "Next Generation Artificial Intelligence, Artificial Mind -
> Part One - Basic Architecture and Cognitive Structure" introduces a
> basic artificial mind architecture and computational model for
> cognitive processing.  Inside the book, three important cognitive
> process modeling components, mental objects network (MON),
> associative-learning mechanisms and a concept formation principle are
> introduced.  Based on the architecture and the computational model, one
> can develop his own model of artificial mind according to his own
> specific requirements.
> 
> The first edition of Artificial Mind - Part One is now available for
> purchase from the author's personal web site. The price of the e-book
> is USD7.00 (seven US dollars).  An evaluation edition of this e-book is
> also available for download from the web site.
> 
> The author's personal web site:
> http://www.geocities.com/tomwingmak/
> 
I'm afraid you'll have to do a bit better than this feeble spam to 
persuade us that it wasn't written by the author of the work in question.

regards
  Steve

PS "Python Web Programming" is still available through all good 
bookstores ;)
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb   http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

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


Re: Raw strings and escaping

2006-10-03 Thread Fredrik Lundh
Matthew Warren wrote:

> I would expect this to work,
>
> rawstring=r'some things\new things\some other things\'
>
> But it fails as the last backslash escapes the single quote.

raw string literals are parsed in exactly the same way as ordinary string 
literals; it's
just the mapping from the string literal to the contents of the string object 
that differs.

see the documentation for details.

 



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


Re: was python implemented as a object oriented langage at the beginning ?

2006-10-03 Thread Fredrik Lundh
Bertrand Ballis wrote:

> I heard a lot of people from the Ruby community claiming that Python, like
> Perl, was a scripting langage that was changed aftewards to be object
> compatible, and that was making it not as good as Ruby, object-oriented
> from the begenning.
>
> Is that true ?

nope.

 



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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Paul Boddie
[EMAIL PROTECTED] wrote:
> Giovanni Bajo wrote:
>
> > Does this smell "Bitkeeper fiasco" to anyone else than me?
>
> I can't understand why people waste time arguing this stuff.

Because people care about it, I guess.

> Use whatever tool is best at it's job... if it's not written in Python
> it doesn't mean that Python is not good for the task, only that there
> hasn't been any Python programmer that applied himself to the problem
> hard enough.
>
> And i dunno what the case against Trac is (it looks a fine tool for my
> small projects) but probably it's not good enough for python.org

Perhaps, although I imagine that Trac would have a lot more uptake if
it handled more than just Subversion repositories. I don't know whether
Trac is monolithic or not, but there is a need for a wider range of
modular tools operating in the following areas:

  * Web-based source code browsing and searching for many repository
types; perhaps one per type, all providing a similar interface.
Currently, there's ViewVC which does CVS and Subversion browsing
(and limited searching), LXR which does CVS, Subversion and Git
searching (with arguably more limited browsing), OpenGrok which
seems to provide CVS, Subversion, RCS and SCCS browsing and
searching. Perhaps ViewVC just needs more attention.

  * Issue tracking: a huge area in which Trac, Bugzilla, Roundup and a
bunch of proprietary tools exist.

  * Documentation or content management: whilst arguably non-essential
to the management of a software project, I can see the benefit of
integrating documentation with the source code browser, especially.
And it's convenient if providing a service to users as well as
developers if things like downloadable files can be managed in a
way that is compatible with the rest of the solution.

  * Mailing list management/administration, feeds, summaries, reports.

I did briefly look at Trac to see whether I could hack in a WebStack
backend, and I'd do the same for ViewVC if I had the time, mostly
because such projects already duplicate a lot of effort just to permit
the deployment of the software on incompatible server solutions.
There's certainly a lot these solutions could learn from each other and
from lesser known solutions.

> And BTW BitKeeper failed because Linus wanted to stop Tridge reverse
> engineering BitKeeper, not because BK wasn't good.

That's a simplistic view of the situation. The BitKeeper vendor imposes
a non-compete clause on its users, which is in itself pretty
scandalous, and the various attempts to accomplish independent
interoperability with the BitKeeper service led to its proprietor
packing up his toys and going home. You might believe that having some
opportunistic company narrowly define what you can and cannot do,
despite a fairly loose relationship based on you just using their stuff
in your workplace, to be acceptable as long as you get to use such nice
stuff. Others, however, consider implications wider than whether
something is technically good, including whether or not something
brings with it all sorts of unacceptable restrictions on personal
freedoms. Considered through such broader criteria, one can assert that
BitKeeper certainly wasn't good at all.

Paul

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread A.M. Kuchling
On Tue, 03 Oct 2006 08:19:10 GMT, 
Giovanni Bajo <[EMAIL PROTECTED]> wrote:
> ... using a non open source tracker (called JIRA - never heard
> before of course) for Python itself.

Other projects do use it; see
 for a partial list, and a
link to the Apache Software Foundation's issue trackers.

> Does this smell "Bitkeeper fiasco" to anyone else than me?

The committee did expect this recommendation to be controversial.  :)

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


anyone make any non-wx python plugins for boa-constructor

2006-10-03 Thread [EMAIL PROTECTED]
 I was looking at vpython and it would seem to be an easy thing to
add to boa-constuctors classes but I am not sure if that is possible
within the boa-constructor interface.  Is it possible to do without
combining it with wxwindows??  Is there any examples besides the simple
one that comes with the software??  I haven't seen any in google.


http://www.dexrow.com

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Paul Rubin
Ben Finney <[EMAIL PROTECTED]> writes:
> The existing SourceForge system runs on non-free software, which is a
> significant differentiator from Bugzilla.

The SourceForge software, at least in some versions, is free software.
See for example http://savannah.gnu.org for an instantiation, which
may be a fork.  I never followed the saga much.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Martin v. Löwis
Giovanni Bajo schrieb:
 > I just read this mail by Brett Cannon:
> http://mail.python.org/pipermail/python-dev/2006-October/069139.html
> where the "PSF infrastracture committee", after weeks of evaluation, 
> recommends
> using a non open source tracker (called JIRA - never heard before of course)
> for Python itself.
> 
> Does this smell "Bitkeeper fiasco" to anyone else than me?

It's significantly different from the Bitkeeper fiasco in two important
ways:
1. Bitkeeper is a source revisioning system, so it is similar to CVS
   and Subversion. This project here is "just" the bug tracker, which is
   of lesser  importance. If we move to a different one some day, a
   certain amount of data lossage might be acceptable (e.g. we now
   likely lose the "history" of status changes and file attachments on
   each report). An export of all data is high on the requirements list,
   as Fredrik points out.
2. None of these systems require a specialized client. A plain
   web browser will do. IIRC, non-availibility of the Bitkeeper
   client (or: re-engineering of the existing one) was what really
   caused the fiasco. The same fiasco is not possible for the
   bug tracker.

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


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Martin v. Löwis
Ben Finney schrieb:
> I would be greatly dismayed to see the PSF choosing to move critical
> Python development data into a non-free system. 

Then volunteer to help operating the Roundup installation. It will
become reality if there are enough volunteers to keep it running.

> I hope this
> recommendation from the "PSF infrastructure committee" is rejected.

That is very very unlikely. Who would reject it, and why?

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


Re: Raw strings and escaping

2006-10-03 Thread Jon Ribbens
In article <[EMAIL PROTECTED]>, Duncan Booth wrote:
>> I presume there was originally some reason for this bizarre behaviour
>> - it'd be interesting to know what it is/was, if anyone knows?
>> 
> See the FAQ for the explanation:
> 
> http://www.python.org/doc/faq/general/#why-can-t-raw-strings-r-strings-end-with-a-backslash
> 
> The idea is that if you use raw strings for regular expressions you can 
> write things like:
> 
>   pattern = r'[\'"]'
> 
> if the raw string simply ignored the backslash altogether it would be much 
> harder to write regular expressions that contain both sorts of quotes.

Well, hardly *much* harder:

  pattern = r"""foo"""

Personally, I think that raw strings behaving as they do is
unexpected, unintuitive and unnecessary, but it's obviously too late
to change it now anyway ;-)

I think standard strings accepting backslash followed by an unexpected
character is also a mistake, but again it's too late to fix now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python to use a non open source bug tracker?

2006-10-03 Thread Martin v. Löwis
Paul Rubin schrieb:
> Sounds crazy, what's wrong with bugzilla?

Nobody offers to operate it: that's wrong. We put out a call
for trackers, and nobody (niemand, nirgendwo) was willing
to setup a bugzilla installation, work on an SF data import,
and offered to operate this installation for the period of
testing.

In addition, people expressed deep dislike of Bugzilla
in the early discussions. Some people just hate it, maybe
more so than the SF tracker.

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


Re: was python implemented as a object oriented langage at the beginning ?

2006-10-03 Thread MonkeeSage
 Bertrand Ballis wrote:
> I heard a lot of people from the Ruby community claiming that Python, like
> Perl, was a scripting langage that was changed aftewards to be object
> compatible, and that was making it not as good as Ruby, object-oriented
> from the begenning.

Sounds like a bunch of hooey on both counts ("alot of people claiming"
and "python not OO"). The python object system is closer to C++, ruby's
is closer to SmallTalk; but they are both OO (i.e., everything is an
object), and support all the OOP distinctives (i.e., encapsulation,
abstraction, &c) -- just because a language doesn't implement OO in the
exact same way as another doesn't mean it isn't OO -- it just means
it's a different language. Sounds like mabye you heard a few ruby
zealots who didn't know what they were talking about.

Regards,
Jordan

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


Re: I need Cryptogrphy in Python please .

2006-10-03 Thread hg
NicolasG wrote:
> Looking around for a Cryptography tool kit, the best recommendations I
> found about was for pyCrypto. I try to install it unsuccessfully in my
> windowsXP SP2 with python 2.4.3 and I get the following message :
> C:\Python24\pycrypto-2.0.1>python setup.py build
> running build
> running build_py
> running build_ext
> error: The .NET Framework SDK needs to be installed before building
> extensions f
> or Python.
> 
> I have installed .NET framework latest release.
> Unfortunately the pyCrypto project looks abandoned , I couldn't find an
> active mailing list and the last release are a couple of year old.
> 
> Can some one guide me how to fix the problem above or point me to
> another Cyrptography library that I can use easily ?
> 
> Thanks.
> 


I use pycrypto under *nix and Windows. Under windows, I compile it with
VC++ 2003 without any problem.

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


Re: loop beats generator expr creating large dict!?

2006-10-03 Thread David Isaac
Does George's example raise the question:
why do dictionaries not implement efficient creation
for two common cases?

- Making a dict from two sequences of the same length.
- Making a dict from a sequence and a function
  (as in George's example in this thread).

The current situation is:
use a loop because the obvious generator approach
is not efficient.  Something seems wrong here...

Cheers,
Alan Isaac


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


excepthook doesn't give exact line number

2006-10-03 Thread Hari Sekhon
Hi,

I'm wondering if anyone can please help me on figuring out a better way 
of doing an excepthook. I have a script which is using an excepthook to 
catch any uncaught exceptions - there usually aren't any except when I 
am messing with the code, like right now  :-) 

The problem is that the excepthook gives the line of the topmost called 
function rather that the actual line that generated the error the way 
you get it with a normal traceback.


import sys, traceback

def myexcepthook(type,value,tb):

   
exception_message = ( "\nLine no %s: %s - %s\n"
"\nStack Trace:\n\n%s\n" % 
(tb.tb_lineno,type,value,str(traceback.print_exc(2))) )
   


sys.excepthook = myexcepthook





So the tb object that is passed into the function gives the tb.tb_lineno 
as a line right near the end where the original topmost called function 
happens. This is a bit useless to me since I don't want to go looking 
for the exception manually through the entire code.

As you can see from my example, I have already used the traceback module 
which I usually use to give the normal traceback printout via 
traceback.print_exc(). Here it doesn't seem to work, it always give 
"None", likely because the excepthook has taken it or something.

Any guiding wisdom from the masters out there?

Much appreciated, thanks for reading.

-h

-- 
Hari Sekhon

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


Re: loop beats generator expr creating large dict!?

2006-10-03 Thread Fredrik Lundh
David Isaac wrote:

> The current situation is:  use a loop because the obvious generator
> approach is not efficient.

"not efficient" compared to what ?

 



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


Re: How Build VTK for Python 2.5 under Windows?

2006-10-03 Thread Sébastien Ramage
I've install MS Visual C++ toolkit 2003 and cmake
but I don't really know how it work.

there's somebody who can compile VTK for python 2.5 under windows for
me ?

thank you

(And sorry for my english, I'm French)

Seb



Sébastien Ramage wrote:
> Hello,
> I'm running on Windows and I want to test VTK but I don't understand
> how build it
>
> Somebody can help me to build VTK for Python 2.5 under Windows? (or
> Python 2.43 if python 2.5 is a problem)
>
> I have no C compiler but I can install one if it's free.
> 
> Thank you
> 
> Seb

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


Python components

2006-10-03 Thread Jorge Vilela
Hello group!We know that Python have many components not too knowledge.I think that I'm looking for one of them.I need embed a good document editor ( as Word or Writer ) in my small python application, for document editing.
It's to lawyers make important documents and control them using the application, that's the reason why need be a good editor (edit tables, border, paragraphs etc).I had though about anything that embed the Microsoft word/Open Office Writer in application, but now i think kinda impossible.
So, maybe exist some component for a rich editing documents.Do anyone know any?I'm using pyGTK, but dont care if it use any other grafic tool.ThanksJorge
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Manipulate PDFs

2006-10-03 Thread Simon Brunning
On 10/3/06, Weko Altamirano <[EMAIL PROTECTED]> wrote:
> Hi Everyone, am a developer using Zope and wanted to know if any of you have
> ever implemented a pdf generating/creating system using python? This just
> means mostly manipulating pdfs (create and/or edit) via web. If you guys
> have any suggestions or recommendations please post, thanks.

Does ReportLab do the trick for you?

-- 
Cheers,
Simon B,
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Operator += works once, fails if called again

2006-10-03 Thread Frederic Rentsch
John Machin wrote:
> Frederic Rentsch wrote:
>   
>> Hi all,
>>
>>I have a class Time_Series derived from list. It lists days and
>> contains a dictionary of various Lists also derived from list which
>> contain values related to said days. (e.g. Stock quotes, volumes traded,
>> etc.)
>>I defined an operator += which works just fine, but only once. If I
>> repeat the operation, it fails and leaves me utterly mystified and crushed.
>>
>> Craving to be uncrushed by a superior intelligence.
>>
>> Frederic
>>
>>
>> ---
>>
>> A test:
>>
>> 
> [perfection snipped]
>
>   
>> Perfect!
>>
>>  >>> TS1 += TS2# Second call
>>
>> Traceback (most recent call last):
>>   File "", line 1, in -toplevel-
>> TS += TS2
>>   File "c:\i\sony\fre\src\python\TIME_SERIES_7.py", line 1314, in __iadd__
>> return self.__add__ (other)
>>   File "c:\i\sony\fre\src\python\TIME_SERIES_7.py", line 1273, in __add__
>> Sum = copy.deepcopy (self)
>>   File "C:\PYTHON24\lib\copy.py", line 188, in deepcopy
>> y = _reconstruct(x, rv, 1, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 335, in _reconstruct
>> state = deepcopy(state, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 161, in deepcopy
>> y = copier(x, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 252, in _deepcopy_dict
>> y[deepcopy(key, memo)] = deepcopy(value, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 161, in deepcopy
>> y = copier(x, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 252, in _deepcopy_dict
>> y[deepcopy(key, memo)] = deepcopy(value, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 188, in deepcopy
>> y = _reconstruct(x, rv, 1, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 335, in _reconstruct
>> state = deepcopy(state, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 161, in deepcopy
>> y = copier(x, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 252, in _deepcopy_dict
>> y[deepcopy(key, memo)] = deepcopy(value, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 188, in deepcopy
>> y = _reconstruct(x, rv, 1, memo)
>>   File "C:\PYTHON24\lib\copy.py", line 320, in _reconstruct
>> y = callable(*args)
>>   File "C:\PYTHON24\lib\copy_reg.py", line 92, in __newobj__
>> 
>
> Oho! What's it doing there, in copy_reg.py?  Something has stashed away
> a reference to copy_reg.__newobj__, and the stasher is *not* the copy
> module 
>
>   
>> return cls.__new__(cls, *args)
>> TypeError: instancemethod expected at least 2 arguments, got 0
>> 
>
> >From a quick browse through the code for copy.py and copy_reg.py [Isn't
> open source a wonderful thing?], I'm guessing:
> (1) The "cls"  is *your* class. You can confirm that with a debugger
> (or by hacking in a print statement!).
> (2) You may need to read this in the copy docs:
> """
> Classes can use the same interfaces to control copying that they use to
> control pickling. See the description of module pickle for information
> on these methods. The copy module does not use the copy_reg
> registration module.
> """
> (3) You may need to read this in the pickle docs:
> """
> New-style types can provide a __getnewargs__() method that is used for
> protocol 2. Implementing this method is needed if the type establishes
> some internal invariants when the instance is created, or if the memory
> allocation is affected by the values passed to the __new__() method for
> the type (as it is for tuples and strings). Instances of a new-style
> type C are created using
>  obj = C.__new__(C, *args)
>  where args is the result of calling __getnewargs__() on the original
> object; if there is no __getnewargs__(), an empty tuple is assumed.
> """
> (4) You may need to debug your pickling/unpickling before you debug
> your deepcopying.
> (5) Look at function _copy_inst at line 134 in copy.py -- work out what
> it will do with your class instance, depending on what __magic__
> method(s) you have implemented.
>
> Hope some of this helps,
> John
>
>   

John,

Thank you very much for your suggestions. I followed them one by one and 
in the end found the cause of the problem to be a circular reference. 
Some species of contained Lists need a reference to the containing 
Time_Series and that circular reference trips up deepcopy.  Supposedly I 
can define my own __deepcopy__, but didn't understand whose method it is 
supposed to be. Time_Series.__deepcopy__  () doesn't make sens, nor does 
it work. Time_Series should be the argument of the method not the owner. 
Anyway, I managed without deepcopy making a new instance and loading it 
as I would, if it were the first one.

Thanks again

Frederic

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


Newbie question: python doesn't search the cwd for my module

2006-10-03 Thread izak marais
Hello AllI want to import a module I wrote to use it in a script. But, it is not in the same directory as the script I want to import it into. So my solution is to put the following piece of code in the script:import osos.chdir()import This generates an error: 'ImportError: no module named 'If I do the exact same code in interactive mode, using ipython it works fine, but when I try it in a script I get the error. I've even used os.listdir() after changing the directory to confirm that the module is in the cwd (and it is).Where am I going wrong?(I use windows XP, and enthought edition python2.4)ThanksIzak 
		Do you Yahoo!? Everyone is raving about the  all-new Yahoo! Mail.-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Best way to handle large lists?

2006-10-03 Thread Bill Williams
I don't know enough about Python internals, but the suggested solutions 
all seem to involve scanning bigList. Can this presumably linear 
operation be avoided by using dict or similar to find all occurrences of 
smallist items in biglist and then deleting those occurrences?

Bill Williams



In article <[EMAIL PROTECTED]>,
 Chaz Ginger <[EMAIL PROTECTED]> wrote:

> I have a system that has a few lists that are very large (thousands or
> tens of thousands of entries) and some that are rather small. Many times
> I have to produce the difference between a large list and a small one,
> without destroying the integrity of either list. I was wondering if
> anyone has any recommendations on how to do this and keep performance
> high? Is there a better way than
> 
> [ i for i in bigList if i not in smallList ]
> 
> Thanks.
> Chaz
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Howto pass Array/Hash into Function

2006-10-03 Thread Wijaya Edward

Thanks for your understanding Steve.
 
Furthermore, my related concern
is how does Python actually  deal with 'reference' in Perl.
But now, it is clear to me now that Python simply 
treats them as object.
 
Regards,
Edward WIJAYA
SINGAPORE



From: [EMAIL PROTECTED] on behalf of Steve Holden
Sent: Tue 10/3/2006 8:08 PM
To: [email protected]
Subject: Re: Howto pass Array/Hash into Function




It wouldn't be obvious to someone who learned Perl as their first
programming language because Perl chose to ignore the otherwise almost
universal convention that formal parameters determine the arguments that
a function or procedure can be calles with.

regards
  Steve




 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.

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


Re: Best way to handle large lists?

2006-10-03 Thread Hari Sekhon
I don't know much about the python internals either, so this may be the 
blind leading the blind, but aren't dicts much slower to work with than 
lists and therefore wouldn't your suggestion to use dicts be much 
slower? I think it's something to do with the comparative overhead of 
using keys in dicts rather than using positional indexes in lists/arrays...

At least that is what I thought.

Can anyone confirm this?

-h

Hari Sekhon



Bill Williams wrote:
> I don't know enough about Python internals, but the suggested solutions 
> all seem to involve scanning bigList. Can this presumably linear 
> operation be avoided by using dict or similar to find all occurrences of 
> smallist items in biglist and then deleting those occurrences?
>
> Bill Williams
>
>
>
> In article <[EMAIL PROTECTED]>,
>  Chaz Ginger <[EMAIL PROTECTED]> wrote:
>
>   
>> I have a system that has a few lists that are very large (thousands or
>> tens of thousands of entries) and some that are rather small. Many times
>> I have to produce the difference between a large list and a small one,
>> without destroying the integrity of either list. I was wondering if
>> anyone has any recommendations on how to do this and keep performance
>> high? Is there a better way than
>>
>> [ i for i in bigList if i not in smallList ]
>>
>> Thanks.
>> Chaz
>> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie question: python doesn't search the cwd for my module

2006-10-03 Thread Ben Finney
izak marais <[EMAIL PROTECTED]> writes:

> I want to import a module I wrote to use it in a script. But, it is
> not in the same directory as the script I want to import it into.

I can think of two sensible solutions.

One is to change the 'sys.path' list to include the directory where
you want Python to look for your module. This has the advantage that
it will work on all current versions of Python. It has the
disadvantage that modules with the same name in different directories
are not easy to differentiate.

import sys
sys.path.append("/path/to/the/directory")
import spam

The other way is to use absolute imports to be specific about where
the module should be imported from. This has the advantage that at
most one module will match the requested name for a given import. It
has the disadvantage of being a fairly new feature, introduced in
Python 2.5.

from __future__ import absolute_import
from ...path.to.the.directory import spam

See here for more information on absolute imports:

http://docs.python.org/whatsnew/pep-328.html>
http://www.python.org/peps/pep-0328.html>

-- 
 \   "I believe in making the world safe for our children, but not |
  `\our children's children, because I don't think children should |
_o__)  be having sex."  -- Jack Handey |
Ben Finney

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


Re: Ctypes and freeing memory

2006-10-03 Thread Chris Mellon
On 10/3/06, Oliver Andrich <[EMAIL PROTECTED]> wrote:
> Hi everybody,
>
> I am currently playing around with ctypes and a C library (libWand
> from ImageMagick), and as I want to easily deploy it on Mac, Linux and
> Windows, I prefer a ctypes solution over a C module. At least on
> windows, I would have resource problems to compile the C module. So,
> ctypes is the perfect choice for me.
>
> But I am currently encountering a pattern inside the C library, that
> has to be used to free memory. Coding in C I have to do the following
>
> char *description;
> long  severity;
>
> description = MagickGetException(wand, &severity);
> /*
> do something with the description: print it, log it, ...
> */
> description = (char *) MagickRelinquishMemory(description);
> exit(-1); /* or something else what I want to after an exception occured 
> */
>
> So, this looks easy and is sensible from C's point of view. Now I try
> to translate this to Python and ctypes.
>
> dll.MagickGetException.argtypes = [c_long, POINTER(c_long)]
> dll.MagickGetException.restype  = c_char_p
>
> severity = c_long()
> description = dll.MagickGetException(byref(severity))
>
> # So far so good. The above works like a charm, but the problem follows 
> now
> # ctypes already converted the char * for description to a String object.
> # That means description has arrived in an area under Python's control.
>
> # these definitions are the easy part
> dll.MagickRelinquishMemory.argtypes = [c_void_p]
> dll.MagickRelinquishMemory.restype  = c_char_p
>
> # but this obviously must cause problems and causes problems
> dll.MagickRelinquishMemory(description)
>
> So, my question is, how do I deal with this situation? Can I ignore
> the call to MagickRelinquishMemory, cause Python takes care of the
> resources already? Or is it impossible to use it at all, and I have to
> think about a different solution?
>

Not a ctypes expert but I can pretty much guaranteee that Python won't
correctly release that memory by itself. Are you sure that description
is actually a string object?

By my recollection it should be a c_char_p object, and if you pass it
to MagickRelinquishMemory ctypes should do the right thing.

If it doesn't, then you can use a more literal translation of the C
code, and use a c_void_p instead, using ctypes.string_at(description)
to get a string out of the buffer.


> Best regards,
> Oliver
>
> --
> Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Instantiating an object when the type is only known at runtime

2006-10-03 Thread Samuel
Hi,

I am trying to replace the eval() in the following code:

def myfunc(type, table):
module   = __import__(type)
type = 'module' + '.' + type
obj  = eval(type)
return obj(row[table.c.name], row[table.c.handle])

I am out of ideas. Any hints?

Thanks,
-Samuel

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


Re: Making sure script only runs once instance at a time.

2006-10-03 Thread Eric S. Johansson
MonkeeSage wrote:
> Eric S. Johansson wrote:
>> the problem with this solution is that it does not handle the read
>> nonexclusive/write exclusive locking model.  In this model, reads don't
>> block, they only register that the request is in process.  writes lock
>> request block until all outstanding reads have completed.  When there is
>> a write lock waiting, all subsequent reads lock requests block until the
>> write has completed.
> 
> I should have said "lock file" -- I'm not trying to do file locking for
> concurrent access to a file; I'm trying to provide a lock file to
> determine if an instance of a process is already spawned.

That difference was clear to me and I appreciate your comment clarifying 
the issue further.

I was trying to point out how there are more models of locking that we 
could use in Python than the single point lock as you had described. 
Unfortunately, most system locks are hard to get right and difficult to 
test so you're never quite sure until something breaks and then you know 
you did it wrong.

I really should grab the code you pasted and use it as a rewrite for 
portalocker.  Someday. 

--- eric

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


Re: Best way to handle large lists?

2006-10-03 Thread Sybren Stuvel
Bill Williams enlightened us with:
> I don't know enough about Python internals, but the suggested
> solutions all seem to involve scanning bigList. Can this presumably
> linear operation be avoided by using dict or similar to find all
> occurrences of smallist items in biglist and then deleting those
> occurrences?

And how would that beat O(n)? Every element of bigList has to be
scanned at one point, either to compare it to every earlier element in
bigList and eliminate it, or to compare it to every element in
smallList.

Run benchmarks on the suggestions, and see which is fastest for
yourself.

Sybren
-- 
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
-- 
http://mail.python.org/mailman/listinfo/python-list


Benchmarking Python's subroutines/function

2006-10-03 Thread Wijaya Edward

Hi,
 
How does one benchmark
multiple subroutines in Python?
Is there a built-in library for that?
 
--
Regards,
Edward WIJAYA
SINGAPORE

 Institute For Infocomm Research - Disclaimer -
This email is confidential and may be privileged.  If you are not the intended 
recipient, please delete it and notify us immediately. Please do not copy or 
use it for any purpose, or disclose its contents to any other person. Thank you.

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


Re: Best way to handle large lists?

2006-10-03 Thread Chaz Ginger
I've done that and decided that Python's 'list comprehension' isn't a
way to go. I was hoping that perhaps someone had some experience with
some C or C++ library that has a Python interface that would make a
difference.

Chaz

Sybren Stuvel wrote:
> Bill Williams enlightened us with:
>> I don't know enough about Python internals, but the suggested
>> solutions all seem to involve scanning bigList. Can this presumably
>> linear operation be avoided by using dict or similar to find all
>> occurrences of smallist items in biglist and then deleting those
>> occurrences?
> 
> And how would that beat O(n)? Every element of bigList has to be
> scanned at one point, either to compare it to every earlier element in
> bigList and eliminate it, or to compare it to every element in
> smallList.
> 
> Run benchmarks on the suggestions, and see which is fastest for
> yourself.
> 
> Sybren
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Best way to handle large lists?

2006-10-03 Thread Paul Rubin
Sybren Stuvel <[EMAIL PROTECTED]> writes:
> > I don't know enough about Python internals, but the suggested
> > solutions all seem to involve scanning bigList. Can this presumably
> > linear operation be avoided by using dict or similar to find all
> > occurrences of smallist items in biglist and then deleting those
> > occurrences?
> 
> And how would that beat O(n)? Every element of bigList has to be
> scanned at one point, either to compare it to every earlier element in
> bigList and eliminate it, or to compare it to every element in
> smallList.

Maybe the application should use sets instead of lists for these
collections.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Re: Ctypes and freeing memory

2006-10-03 Thread Oliver Andrich
On 10/3/06, Chris Mellon <[EMAIL PROTECTED]> wrote:
> Not a ctypes expert but I can pretty much guaranteee that Python won't
> correctly release that memory by itself. Are you sure that description
> is actually a string object?

I also think, that Python won't release the memory, and the returned
string isn't helpful either. :)

> If it doesn't, then you can use a more literal translation of the C
> code, and use a c_void_p instead, using ctypes.string_at(description)
> to get a string out of the buffer.

This works and is a great tip! Thanks a lot.

Best regards,
Oliver

-- 
Oliver Andrich <[EMAIL PROTECTED]> --- http://roughbook.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CGI -> mod_python

2006-10-03 Thread Eric S. Johansson
Thomas Jollans wrote:
> Not that I know of, but thanks to the WSGI (specified in PEP 333:
> http://www.python.org/dev/peps/pep-0333/) you should be able to convert
> your app to WSGI, which will run on mod_python, relatively easily
> (depending on your code; 'print' won't work anymore)

I assume this is the library one could use if you were running on Python 
2.3 or 2.4

http://cheeseshop.python.org/pypi/wsgiref

--- eric


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


Re: py2app console

2006-10-03 Thread Dave Opstad
In article <[EMAIL PROTECTED]>,
 James Stroud <[EMAIL PROTECTED]> wrote:

> Does anyone know of the most straightforward way to get rid of the 
> intensely annoying "console" window that py2app feels so compelled to 
> create?

I include this code in my apps:

if (sys.platform != "win32") and hasattr(sys, 'frozen'):
root.tk.call('console', 'hide')

That hides the console in py2app applications.

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


Re: Raw strings and escaping

2006-10-03 Thread Duncan Booth
Jon Ribbens <[EMAIL PROTECTED]> wrote:

> Well, hardly *much* harder:
> 
>   pattern = r"""foo"""

It means you have to always triple quote your raw strings or know in 
advance of writing the regular expression which of r'', r"", r'', 
r"" is most appropriate. The way it works at the moment you don't have 
to care, you just write the raw string knowing that with r'' you have to 
escape single quotes, r"" you have to escape double quotes and everything 
works as expected.

Its only when you start trying to use raw strings for things other than 
regular expressions that backslash at the end of the string can be a 
problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: loop beats generator expr creating large dict!?

2006-10-03 Thread Steven Bethard
David Isaac wrote:
> Does George's example raise the question:
> why do dictionaries not implement efficient creation
> for two common cases?
> 
> - Making a dict from two sequences of the same length.
> - Making a dict from a sequence and a function
>   (as in George's example in this thread).

Maybe you should lobby for dict comprehensions in Python 3000.  It 
already has set comprehensions:

 http://www.python.org/dev/peps/pep-3100/

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


Re: Resuming a program's execution after correcting error

2006-10-03 Thread Sheldon

MonkeeSage wrote:
> Georg Brandl wrote:
> > As I said before, this can be done by finding out where the error is raised,
> > what the cause is and by inserting an appropriate try-except-statement in
> > the code.
>
> I could be mistaken, but I *think* the OP is asking how to re-enter the
> stack at the same point as the exception exited from and continue with
> the execution as if the exception never happened. AFAIK, that isn't
> possible; however, given that he has a file to work from that indicates
> a portion of the state at the time of the exception, I think he may be
> able simulate that kind of functionality by reading in the file on
> exception and then returning a call to the function where the exception
> occured with the data from the file. Something like this mockup:
>
> def faulty_function(a, b, c=None):
>   if not c:
> c = 0
>   try:
> # modify c, write c to file...
> # oops hit an exception
> c += a / b
>   except:
> # read from the file here
> # c = ...
> # and fix the error
> b += 1
> return faulty_function(a, b, c)
>   return c
>
> print faulty_function(2, 0) # => 2
>
> Of course, it's probably much better to just fix the code and avoid the
> exception in the first place. ;)
>
> Regards,
> Jordan

Thanks Jordon,
I think you understood my problem best. I know now that this is not
possible but I would like to create an exception that saves all the
current variables when there is an error. I think pickle is the answer
but I never got it to work. My program is very large and it is being
modified often.
Any advice on how to save the variables.

/Sheldon

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


Re: excepthook doesn't give exact line number

2006-10-03 Thread Peter Otten
Hari Sekhon wrote:

> The problem is that the excepthook gives the line of the topmost called
> function rather that the actual line that generated the error the way
> you get it with a normal traceback.

A look into the traceback module shows that tracebacks are stored as a
linked list. Here's a way to get hold of its tail:

def tbiter(tb):
while tb is not None:
yield tb
tb = tb.tb_next

def last(items):
for  item in items:
pass
return item

# example usage
def myexcepthook(type, value, tb):
tb_tail = last(tbiter(tb))
print tb_tail.tb_lineno
 
Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >