Newbee question : List of packages

2005-06-01 Thread Sébastien V.
Hello,

I'm quite new in Python and I discover every day very interesting new
packages in this newsgroup : Is there somewhere on the web a list (as
complete as possible) in which main features of external packages are listed
?

Sebastien


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


Re: running tkinter

2005-06-01 Thread Martin Franklin
Jim Anderson wrote:
> I have just installed Fedora Core 3 on my pc. Python runs
> fine, but when I try to run tkinter the tkinter library is
> not found. I tried installing python 2.4.1 and could not get
> tkinter to run there either.
> 
> When I look through the build directories for 2.4.1, I find
> a lib-tk, but I do not find anything for tcl. In past releases,
> my recollection is that tcl/tk were part of the release and
> that if TCL_LIBRARY and TK_LIBRARY environment variables were
> set right, then tkinter would work.
> 
> Are tcl/tk still supposed to be an intergrated part of the
> python release?
> 
> Do I have to download, configure, make, install tcl and tk
> packages to get tkinter running?
> 
> Thanks for any suggestions in advance.
> 
> Jim Anderson


On fedora tkinter is a separate package.

just do this (as root) and all will be well:-

yum install tkinter


Cheers,
Martin.

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


Re: pickle alternative

2005-06-01 Thread Andrew Dalke
simonwittber posted his test code.

I tooks the code from the cookbook, called it "sencode" and
added these two lines

dumps = encode
loads = decode


I then ran your test code (unchanged except that my newsreader
folded the "value = ..." line) and got

marshal enc T: 0.21
marshal dec T: 0.4
sencode enc T: 7.76
sencode dec T: 11.56

This is with Python 2.3; the stock one provided by Apple
for my Mac.

I expected the numbers to be like this because the marshal
code is used to make and read the .pyc files and is supposed
to be pretty fast.

BTW, I tried the performance approach I outlined earlier.
The numbers aren't much better

marshal enc T: 0.2
marshal dec T: 0.38
sencode2 enc T: 7.16
sencode2 dec T: 9.49


I changed the format a little bit; dicts are treated a bit
differently.


from struct import pack, unpack
from cStringIO import StringIO

class EncodeError(Exception):
pass
class DecodeError(Exception):
pass

def encode(data):
f = StringIO()
_encode(data, f.write)
return f.getvalue()

def _encode(data, write, pack = pack):
# The original code use the equivalent of "type(data) is list"
# I preserve that behavior

T = type(data)

if T is int:
write("I")
write(pack("!i", data))
elif T is list:
write("L")
write(pack("!L", len(data)))
# Assumes len and 'for ... in' aren't lying
for item in data:
_encode(item, write)
elif T is tuple:
write("T")
write(pack("!L", len(data)))
# Assumes len and 'for ... in' aren't lying
for item in data:
_encode(item, write)
elif T is str:
write("S")
write(pack("!L", len(data)))
write(data)
elif T is long:
s = hex(data)[2:-1]
write("B")
write(pack("!i", len(s)))
write(s)
elif T is type(None):
write("N")
elif T is float:
write("F")
write(pack("!f", data))
elif T is dict:
write("D")
write(pack("!L", len(data)))
for k, v in data.items():
_encode(k, write)
_encode(v, write)
else:
raise EncodeError((data, T))
  

def decode(s):
"""
Decode a binary string into the original Python types.
"""
buffer = StringIO(s)
return _decode(buffer.read)

def _decode(read, unpack = unpack):
code = read(1)
if code == "I":
return unpack("!i", read(4))[0]
if code == "D":
size = unpack("!L", read(4))[0]
x = [_decode(read) for i in range(size*2)]
return dict(zip(x[0::2], x[1::2]))
if code == "T":
size = unpack("!L", read(4))[0]
return tuple([_decode(read) for i in range(size)])
if code == "L":
size = unpack("!L", read(4))[0]
return [_decode(read) for i in range(size)]
if code == "N":
return None
if code == "S":
size = unpack("!L", read(4))[0]
return read(size)
if code == "F":
return unpack("!f", read(4))[0]
if code == "B":
size = unpack("!L", read(4))[0]
return long(read(size), 16)
raise DecodeError(code)



dumps = encode
loads = decode


I wonder if this could be improved by a "struct2" module
which could compile a pack/unpack format once.  Eg,

float_struct = struct2.struct("!f")

float_struct.pack(f)
return float_struct.unpack('?\x80\x00\x00')[0]
  which might the same as
return float_struct.unpack1('?\x80\x00\x00')



Andrew
[EMAIL PROTECTED]

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


Re: something like CPAN, PPMs?

2005-06-01 Thread deelan
Maurice LING wrote:
> Hi Alex,
> 
> I am actually working on something like that as an academic project. At 
> this stage, at least for the purpose of my scope, it will not be as 
> extensive as CPAN but a set of mechanisms for the same effect for Python.

don't foget to keep an eye on python's eggs:



and related blog posts:





HTH.

-- 
@prefix foaf:  .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog  .
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Software licenses and releasing Python programs for review

2005-06-01 Thread Robert Kern
poisondart wrote:

[John J. Lee:]
>>Secondly, do you think it's a bad thing for anybody to sell software
>>that makes use of the *concepts* in your code (provided that the use
>>of those concepts is not restricted by financial or other legal
>>means)?  If so, why?
>>
>>John
> 
> To be honest. I'm not sure. The knowledge that I learnt was all given
> to me freely, I just consolidated it into these programs. I feel that
> it would be unfair that along this chain of knowledge passing, one
> person decided to exploit the free system and harbour his knowledge for
> profit.

You can't copyright concepts and ideas. If someone wants to make 
commercial use of the knowledge, he can do so, and no license of yours 
can stop him.

What you can copyright is your expression of that knowledge in code. So 
let's be a little clearer about exactly the actions that you can forbid: 
the redistribution of *your code*. Not the use of the knowledge 
contained therein. Your choice of license can't affect the issues you 
seem to be basing your decision on.

As one academic to another, I am asking you to consider using an 
authentic Open Source license rather than one that forbids commercial 
redistribution (I don't think you've answered my question, yet, about 
whether you want to forbid commercial *use* as well, but I'm against 
that, too). You have every right to require that people redistributing 
your code to not profit thereby, but with an Open Source license, you 
have the opportunity to join a broader, more vibrant community. My 
experience with no-commercial-whatever academic projects is that they 
almost never develop a real community of code. The initial developer is 
the only developer, and the project languishes. Having a real Open 
Source license, especially one of the copyleft licenses like the GPL, 
encourages users to use the code, improve it, and gift the improvements 
back to the community.

You end up with a community of people freely contributing their 
expertise to the world. That's a lot more than what you alone could 
provide. But you can get the process started.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

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


Re: how to convert string to list or tuple

2005-06-01 Thread Duncan Booth
Steven Bethard wrote:

> Interestingly, I don't seem to be able to create a file object as a 
> class attribute in restricted mode:
> 
> py> class C(object):
> ... def __init__(self):
> ... self.f = file('temp.txt', 'w')
> ...
> py> eval('''[ cls for cls in
> {}.__class__.__bases__[0].__subclasses__() if cls.__name__ ==
> 'C'][0]().f.write("stuff")''', dict(__builtins__=None)) Traceback
> (most recent call last): 
>File "", line 1, in ?
>File "", line 0, in ?
> AttributeError: 'C' object has no attribute 'f'
> py> eval('''[ cls for cls in
> {}.__class__.__bases__[0].__subclasses__() if cls.__name__ ==
> 'C'][0]().__dict__''', dict(__builtins__=None)) {}
> 

Weird. I copied and paste your class and eval exactly (apart from deleting 
the ... prompts) and it worked exactly as expected: writing 'stuff' to 
temp.txt. (Python 2.4)

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


Re: pickle alternative

2005-06-01 Thread simonwittber

Andrew Dalke wrote:
> This is with Python 2.3; the stock one provided by Apple
> for my Mac.

Ahh that is the difference. I'm running Python 2.4. I've checked my
benchmarks on a friends machine, also in Python 2.4, and received the
same results as my machine.

> I expected the numbers to be like this because the marshal
> code is used to make and read the .pyc files and is supposed
> to be pretty fast.

It would appear that the new version 1 format introduced in Python 2.4
is much slower than version 0, when using the dumps function.

Thanks for your feedback Andrew!

Sw.

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


Re: avl tree

2005-06-01 Thread Zunbeltz Izaola
On Tue, 31 May 2005 22:40:19 +0200, Berthold Höllmann wrote:

> You can grab it from 
> 
>   
> 

Thanks i will play with it. But i have realize that what i need was
exactly a binary tree. I haven't used tree yet and i don't know if i 
can use the avl instaead an ordinary binary tree.
I have to construct a tree like this

 A

B  C

 A C A B

B C   A B   B C   A C


but i think i can construct a avl using left/right. Am I correct?

Thanks again,

Zunbeltz

> Please report any problems to me. I'll do my best to solve them.
> 
> Regards,
> Berthold

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


Re: scripting browsers from Python

2005-06-01 Thread Michele Simionato
This looks interesting, but I need an example here. What would be the
command
to open Konqueror to a given page and to post a form with given
parameters?
kde.org has tons a material, but I am getting lost and I don't find
anything
relevant to my simple problem.
  
   Michele Simionato

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


Re: Newbee question : List of packages

2005-06-01 Thread Simon Brunning
On 6/1/05, Sébastien V. <[EMAIL PROTECTED]> wrote:
> I'm quite new in Python and I discover every day very interesting new
> packages in this newsgroup : Is there somewhere on the web a list (as
> complete as possible) in which main features of external packages are listed

Try , or the (older)
.

That said, these days I usually just google for whatever I'm looking for.

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


Re: scripting browsers from Python

2005-06-01 Thread has
Simon Brunning wrote:
> On 31 May 2005 00:52:33 -0700, Michele Simionato
> <[EMAIL PROTECTED]> wrote:
> > I would like to know what is available for scripting browsers from
> > Python.
>
> I don't know of anything cross platform, or even cross browser, but on
> Windows, IE can be automated via COM

On OS X you can use appscript
, either
directly via the application's scripting interface if it has one or
indirectly by manipulating its GUI via GUI Scripting.

HTH

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


Help with Queues and Threading

2005-06-01 Thread Ognjen Bezanov
Hi, all

Thanks all of you who helped me with the threading and queues issue. I
am trying to get it working but I am having problems. When I try to run
the following:


cmddata = mediaplay.initcommandqueue()  #initiates the Queue to send
commands down

mediathread = threading.Thread( target=mediaplay.mainloop,
args=(cmddata) ) #starts the main loop, which will wait for a command
then execute it, Queue object passed to it.

threading.Thread.start(mediathread) # start the thread

I get the following error:

>>> Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python2.3/threading.py", line 436, in __bootstrap
self.run()
  File "/usr/lib/python2.3/threading.py", line 416, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: mainloop() argument after * must be a sequence



But if I run the loop directly (i.e. not using threads, just calling the
function) it works just fine. What could the problem be?

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


Re: Help with Queues and Threading

2005-06-01 Thread Paul Rubin
Ognjen Bezanov <[EMAIL PROTECTED]> writes:
> But if I run the loop directly (i.e. not using threads, just calling the
> function) it works just fine. What could the problem be?

You have to say args=(cmddata,) with the comma inside the parens,
to make a seqence instead of a parenthesized expression.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: DLL load failed: The specified procedure could not be found

2005-06-01 Thread Bill Davy
"John Machin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]

>> a) What "specified procedure "
>> b) SHIP was made by SWIG
>
> and so presumably was _SHIP ... therefore it appears that you might be 
> better off asking for help on the SWIG mailing list.

I will too.

>
>> c) Is there some way to find out which DLL and which procedure is 
>> involved?
>
> One would expect given the reported context (import _SHIP) that it has 
> found (somewhere!) a DLL called "_SHIP.pyd" and is looking in it 
> (unsuccessfully) for an entrypoint called "init_SHIP".
>
> The usual suspect here would be the C (or C++) compiler messing with the 
> name of the entrypoint; possible messes include underscores at the front 
> and/or frame size at the end e.g. "[EMAIL PROTECTED]" instead of just 
> "initfoo". 
> Possibly you are using a C[++] compiler that's not the one that SWIG 
> thinks you are using.
>
> But exactly which DLL? Given your "interesting" sys.path, it might be an 
> idea to run python with the -v argument, so you can see where all your 
> imports are resolved.

I've not been able to find where sys.path finds its components and would 
happily sort them out.  It does not seem to be PYTHONPATH or PATH or 
PYTHON_LIB.

I had to make Python as I wanted a debug build for Win32 (and hence 
E:\Bill\Python-2.4.1\PCbuild\python24_d.zip on sys.path though why the zip I 
have no idea).  I have discovered the symbol __debug__ is True for debug 
builds.

>
> Once you have worked out which _SHIP.pyd is the cause, you can inspect it 
> and determine what entrypoint(s) it has.
>
> HTH,
> John

Dear John (and all)

That's a great help, really.  A simple thing like reminding me of -v (give a 
man a fish, etc) will help now and hereafter.

So, now we can see what Python is trying to do:

Python 2.4.1 (#65, May 24 2005, 11:31:45) [MSC v.1310 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
# trying H:\Husky\HostPC\V1\SHIP\Debug\SHIP_d.pyd
# trying H:\Husky\HostPC\V1\SHIP\Debug\SHIP_d.dll
# trying H:\Husky\HostPC\V1\SHIP\Debug\SHIP.py
# H:\Husky\HostPC\V1\SHIP\Debug\SHIP.pyc matches 
H:\Husky\HostPC\V1\SHIP\Debug\SHIP.py
import SHIP # precompiled from H:\Husky\HostPC\V1\SHIP\Debug\SHIP.pyc
# trying H:\Husky\HostPC\V1\SHIP\Debug\_SHIP_d.pyd
#   clear[2] __name__
#   clear[2] __file__
Traceback (most recent call last):
  File "H:\Husky\HostPC\V1\SHIP\test1.py", line 15, in ?
import SHIP
  File "H:\Husky\HostPC\V1\SHIP\Debug\SHIP.py", line 5, in ?
import _SHIP
ImportError: DLL load failed: The specified procedure could not be found.
# clear __builtin__._

It's still not clear what procedure could not be found (surely not 
__file__?!).  However, the output from "dumpbin /exports 
H:\Husky\HostPC\V1\SHIP\Debug\_SHIP_d.pyd" is:

H:\Husky\HostPC\V1\SHIP\Debug>dumpbin /exports 
H:\Husky\HostPC\V1\SHIP\Debug\_SHIP_d.pyd
Microsoft (R) COFF Binary File Dumper Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.


Dump of file H:\Husky\HostPC\V1\SHIP\Debug\_SHIP_d.pyd

File Type: DLL

  Section contains the following exports for SHIP.pyd

   0 characteristics
429D76E4 time date stamp Wed Jun 01 09:50:44 2005
0.00 version
   1 ordinal base
   1 number of functions
   1 number of names

ordinal hint RVA  name

  10 1096 init_SHIP

  Summary

6000 .data
2000 .idata
3000 .rdata
2000 .reloc
1000 .rsrc
   2 .text

So _SHIP_d.pyd does export init_SHIP.

The odd thing there (to me) is the reference to "SHIP.pyd".  Is that coming 
from SHIP.def which has:
LIBRARY  "SHIP"

The thing that is really bugging me is that this was all working before the 
weekend :-(

I am also posting this to the SWIG mailing list as suggested.

TIA

Bill


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


Re: decimal numarray

2005-06-01 Thread chris

"km" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi all,
>  is there any support for decimal type in numarray module ?
> regards,
> KM

Still a noob but perhaps you can use gmpy, a wrapper for GMP arbitrary
precision library. I found it here  http://gmpy.sourceforge.net/

I just tried this and seemed to produce an array of gmpy.mpf types. Gmpy
also has support for arbirtrary length integers (mpz) and rationals (mpq).
Works for me. Hope this helps.

In [14]: sl=[gmpy.mpf(2)]*10

In [15]: sl
Out[15]:
[mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0'),
 mpf('2.e0')]

In [16]: x=array(sl)

In [17]: x
Out[17]: NumPy array, format: long
[2.0 ,2.0 ,2.0 ,2.0 ,2.0 ,2.0 ,2.0 ,2.0 ,2.0 ,2.0 ,]

In [18]: x[0]
Out[18]: mpf('2.e0')




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


Re: Seti-like program

2005-06-01 Thread Magnus Lycka
GMane Python wrote:
> I'd like to consider making a program which is 'seti-like' where I could run
> a command-line Python script to just 'do something', and then be able to
> launch a viewer program (maybe linux x11 or Windows, possibly over a network
> socket) using wxPython to be able to inter-act with it. (Start jobs, view
> queue of jobs, modify jobs, etc, or even just watch the work process).

It depends on your scope of course... If you want the whole framework
involved in a seti-like system, with distribution of tasks and load
balancing etc, I wouldn't try to build a new system like that. I'd use
something like Sun Grid Engine. Actually, I'd use Sun Grid Engine.

Of course, this might be overkill for you. Embedding a socket server
or even a little web server in your Python script might be enough if
you just need to monitor a working program, but for starting new jobs
and job queues etc, SGE is probably the path to follow.

See http://gridengine.sunsource.net/GEDomainFAQ.html

I don't think SGE works on Windows, but it works on the major Unix
dialects, including Linux and Mac OS/X. I'm sure you could write a
Python program that monitors and manages SGE from Windows if you like.

For some other options on distributed operation, see
http://www.thinkware.se/cgi-bin/thinki.cgi/UsingPythonWithOtherLanguages

Both CORBA implementations and simpler things like PYRO could help, but
these systems are more aimed at enabling communication between programs
running in a distributed fashion, and I don't think they target tasks
such as job queues, starting and stopping jobs, or load balancing etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with pointers

2005-06-01 Thread [EMAIL PROTECTED]
this might help..

http://effbot.org/zone/python-objects.htm

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


Re: Encryption with Python?

2005-06-01 Thread Anthra Norell
Thank you all, James, Dennis, Christos, Paul,

  Isn't it remarkable that it takes "foolishness" to earn "a little
respect".
  Anyway, even as I write this, my account balance stands unchanged at
... no, come to think of it, the account balance is definitely not a part of
the problem. I will volunteer the information, though, that the credit card
is a debit card and is good for up to the balance of the account. In
addition, I did contemplate a brute force attack. I also contemplated my
belief that it takes no more than a few lines of code to keep a teraflop
machine busy for a few billion years. So I would not discourage decoding
attempts but will state that the game as I understand it does not have any
implicit rules.

Regards

Frederic

(I am not the OP. The OP was Blake T. Garretson who never returned, but
whose problem I still consider the standard by which I wish my idea to be
judged. I never intended to dabble in commercial cryptography.)


- Original Message -
From: "Christos TZOTZIOY Georgiou" <[EMAIL PROTECTED]>
Newsgroups: comp.lang.python
To: 
Sent: Friday, May 27, 2005 11:52 AM
Subject: Re: Encryption with Python?


> On 26 May 2005 14:45:28 -0700, rumours say that Paul Rubin
>  might have written:
>
> >> That's all.  I see you took up the challenge and indirectly replied to
> >> my last question, and in good spirit I say you earned a little respect
> >> from me, at least for standing up to your words.  Now I hope no-one
> >> gives a try to your data (for your own sake :)
>
> >I don't think the challenge was really accepted.  The algorithm
> >changed between when you issued the challenge, and when the sensitive
> >data went up.  A good algorithm doesn't need to change depending on
> >the data.  I agree with the poster who said that the strength of
> >either one of the algorithms is irrelevant, if the keyspace is just 32
> >bits.
>
> You are correct; the algorithm changed, and the OP admitted it himself
> in the post with the encrypted credit card data.
>
> However, on a practical level: before posting, I did a quick comparison,
> and the only effective change to OP's algorithm was a the addition of a
> `random.shuffle(sequence)', which AFAIU has no practical consequences as
> to whether his algorithm is unbreakable or not.
>
> I could say that "hey, you changed the algorithm, and that means your
> previous declaration of unbreakability wasn't." but honestly I was
> overwhelmed by the audacity (and foolishness, if these are truly his
> credit card data) of Frederic.
>
>
>
> ObSF: DNA; The Restaurant At The End Of The Universe; Marvin the
> paranoid android faces a gigantic black tank in the H2G2 HQ.
> --
> TZOTZIOY, I speak England very best.
> "Be strict when sending and tolerant when receiving." (from RFC1958)
> I really should keep that in mind when talking with people, actually...
> --
> http://mail.python.org/mailman/listinfo/python-list

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


Re: working with pointers

2005-06-01 Thread Duncan Booth
Shane Hathaway wrote:

> Michael wrote:
>> sorry, I'm used to working in c++ :-p
>> 
>> if i do
>> a=2
>> b=a
>> b=0
>> then a is still 2!?
>> 
>> so when do = mean a reference to the same object and when does it
>> mean make a copy of the object??
> 
> To understand this in C++ terms, you have to treat everything,
> including simple integers, as a class instance, and every variable is
> a reference (or "smart pointer".)  The literals '0' and '2' produce
> integer class instances rather than primitive integers.  Here's a
> reasonable C++ translation of that code, omitting destruction issues:
> 
> class Integer
> {
> private:
> int value;
> public:
> Integer(int v) { value = v; }
> int asInt() { return value; }
> }
> 
> void test()
> {
> Integer *a, *b;
> a = new Integer(2);
> b = a;
> b = new Integer(0);
> }
> 
A closer translation would be:

const Integer CONST0(0);
const Integer CONST2(2);

void test()
{
const Integer *a, *b;
a = &CONST0;
b = a;
b = &CONST2;
}

The constant integers are created in advance, not when you do the 
assignment. Arithmetic may create new Integer objects, but when the result 
is a small integer it simply reuses an existing object.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are OOP's Jargons and Complexities?

2005-06-01 Thread Anno Siegel
Tassilo v. Parseval <[EMAIL PROTECTED]> wrote in comp.lang.perl.misc:
> Also sprach Dale King:
> 
> > David Formosa (aka ? the Platypus) wrote:
> >> On Tue, 24 May 2005 09:16:02 +0200, Tassilo v. Parseval
> >> <[EMAIL PROTECTED]> wrote: 
> >> 
> >>> [...] I haven't yet come across a language that is both statically and
> >>>strongly typed, in the strictest sense of the words. I wonder whether
> >>>such a language would be usable at all.
> >> 
> >> 
> >> Modula2 claims to be both statically typed and strongly typed.  And
> >> your wonder at its usablity is justified.
> >
> > I used a variant of Modula-2 and it was one of the best languages I have 
> > ever used. That strong, static type checking was a very good thing. It 
> > often took a lot of work to get the code to compile without error. 
> > Usually those errors were the programmers fault for trying to play fast 
> > and loose with data. But once you got it to compile it nearly always worked.
> 
> I am only familiar with its successor Modula-3 which, as far as I
> understand, is Modula-2 with uppercased keywords and some OO-notion
> bolted onto it (I still recall 'BRANDED' references). 
> 
> I have to say that doing anything with this language was not exactly a
> delight.

I've been through Pascal, Modula2 and Oberon, and I agree.

These languages had an axe to grind.  They were designed (by Niklas
Wirth) at a time of a raging discussion whether structured programming
(goto-less programming, mostly) is practical.  Their goal was to prove
that it is, and in doing so the restrictive aspects of the language
were probably a bit overdone.

In the short run they succeeded.  For a number of years, languages of
that family were widely used, primarily in educational programming
but also in implementing large real-life systems.

In the long run, the languages have mostly disappeared from the scene.
It has been discovered that "structured programming" is possible in
about any language.  It turns out that programmers prefer the
self-discipline it takes to do that in a liberal language over the
enforced discipline exerted by Papa Pascal and his successors.

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


Dr. Dobb's Python-URL! - weekly Python news and links (May 31)

2005-06-01 Thread Simon Brunning
QOTW: "Not tested but confident should be an oxymoron for a
programmer." - Peter Otten

(Asked "Is this unsurprising if I look at it right?") -  "Yes; in
general this is true across many domains for a very large number of
referents of "it" :-)" - John Machin

"Strong typing means there [are] a lot of variables whose names are
in ALL CAPS." - Paul Rubin


One common Python "gotcha" is that default argument values are
only evaluated once, at function definition time. David Isaac
wanted to know where the values are stored:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/b09b4e9a78162261

A new era in Python package management?
http://dirtsimple.org/2005/05/easyinstall-new-era-in-python-package.html

Markus would like to limit his Python script to a fixed percentage of
CPU usage:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/17f108407779536a

How do you drive-by-wire a car using Python? The Pegasus Team is
doing some very cool stuff with Python - but I'd want to see their
test results before going within a mile of the thing.

http://pegasusbridge.blogspot.com/2005/05/how-do-you-drive-by-wire-car-using.html

Michael Smith wanted to check poker-dice rolls to see if they were a
full house. Raymond Hettinger gives him general purpose card hand
detection code:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/1eb194f0547c0c49

George asks for help with a regexp to do quoted string parsing, then
is shown the light, and uses PyParsing instead.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/7756f2cca64a5def

Fuzzyman tells us how to build a Movable Python CD - that is, Python
that you can run straight off the CD without any installation - with
a custom set of packages:
http://www.voidspace.org.uk/python/weblog/arch_d7_2005_05_21.shtml#e48

Why is Python case-sensitive? Because mathematical notation is,
apparently:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6cd17bbab3d8ae80

Mark Williamson has difficulty generating API documentation.  Python
still needs a javadoc analogue that doesn't import code, it seems:



Gabor would like to be able to write to a single text file from
multiple processes simultaneously. This is hard.

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/475d065fa7871e63

Eval is unsafe at any speed. Duncan Booth takes on all comers and
shows that you can do dangerous things with eval regardless of
attempts to make it safe:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/cbcc21b95af0d9cc

Notable releases:
Twisted 2.0.1
http://twistedmatrix.com/
wxPython 2.6.0.1
http://wxpython.org/
IPython 0.6.14
http://ipython.scipy.org/



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
  

Re: Python as client-side browser script language

2005-06-01 Thread Magnus Lycka
Rune Strand wrote:
> What would it take to create a Firefox extension that enables Python as
> a script language in the browser - just like Javascript? Is it at all
> possible? Are the hundred good reasons not to bother?

There are certainly security issues. A simple implementation
that started a "normal" Python script fetched from a web page
on the shady parts of the web, could certainly create a real
mess. Ouch. Today, there are really no security features in
Python. Those that used to exist were remvoed since they weren't
considered good enough, and giving a false sense of security
wasn't considered a good idea...

Of course, one might suggest that it's the task of the browser,
and not of the scripting language, to provide a safe sandbox
where scripts can mess around and without causing havoc on
your computer. Such a system in the browser could be used to
grant different rights to different parts of the net, regardless
of what kind of scripting language the resources on those parts
of the net use. When Firefox has something like that, it's time
to start marketing Python for client side scripting I think.
-- 
http://mail.python.org/mailman/listinfo/python-list


Function Serialization

2005-06-01 Thread Mike Tammerman
I want to serialize a function using its pointer. For example

>>> s = """
... def square(number):
... return number**2
... """
>>> functions = {}
>>> exec s in functions
>>> f = functions['square']
>>> f


Then,
1. Serialize f,
2. Store it into a file a db.

One day later,
3. Retrieve from file or db,
4. Unserialize it
5. Use as it is a normal function, maybe I would set it to an object
with setattr

Any help will be very useful.

Mike

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


Re: Newbie Here

2005-06-01 Thread Kent Johnson
Mark Sargent wrote:
> Hi All,
> 
> I'm taking the plunge into Python. I'm currently following this tutorial,
> http://docs.python.org/tut/
> I am not a programmer in general, although I've learnt a bit of bash 
> scripting and some php/asp. I want to get into python to use it for 
> Linux/Unix related stuff. A question I have, is, those of you who use it 
> for the same things, what do you primarily use it for. Could you show me 
> some examples.? I find the hardest thing with programming, is not 
> remember the syntax/logic etc, but, when to use it. Perhaps that is also 
> a personal thing, but, I'd love to see some basic examples out there. 

As others have said, Python is very useful for a wide range of tasks. But you 
asked for simple 
examples. One thing I use Python for is simple file manipulations. I recently 
had to look through 
2,400 folders to see if they contained two specific files in a nested 
subfolder. This is easy to do 
in Python; below is my script.

Kent


''' Look in the warehouse for courses that are missing
 \output\html\saveres.htm and/or \output\html\readres.htm

 path module from http://www.jorendorff.com/articles/python/path/
'''

import path, sys

def checkCourses(basePath, out):
 ''' Iterate through the course / output / html folders rooted at basePath
 looking for missing files.
 '''
 for coursePath in basePath.dirs():
 htmlPath = coursePath / 'output' / 'html'
 if not htmlPath.exists():
 continue

 for fileName in [ 'saveres.htm', 'readres.htm' ]:
 aPath = htmlPath / fileName
 if not aPath.exists():
 print >>out, aPath
 print >>out

basePath = path.path(r'\\Amrnasfs1\QA\BS_and_SIMS\Content')

out = open('MissingFiles.txt', 'w')
checkCourses(basePath, out)
-- 
http://mail.python.org/mailman/listinfo/python-list


Another source of time for the logging package?

2005-06-01 Thread Skip Montanaro

I have code I run in both live and historical modes.  When running in
historical mode the input stream is a set of stored event sequences that
have their own timestamps.  When picking through the logfiles for a
particular run, I'd much prefer it if the timestamps in the logfile
generated with the logging package corresponded to the timestamps on the
stored events, not to wall clock time.  Looking at the code for the logging
package it's far from obvious that this is possible without some surgery.
Before I get out my scalpel, has anyone found a non-invasive way to do this
(or already done the surgery and would be willing to share it)?

Thanks,

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


AM_PATH_PYTHON - version problem

2005-06-01 Thread Uwe Mayer
Hi,

I use the GNU autotools for packaging my python applications. My problem is
that as I have both python2.3 and python2.4 installed the automake macros
always detects the newest version and sets it path variables accordingly. 

How can I package the program for different versions of Python? 
(i.e. for generating binary packages)

Any ideas?

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


Re: What are OOP's Jargons and Complexities?

2005-06-01 Thread David Formosa (aka ? the Platypus)
On Wed, 1 Jun 2005 06:09:43 +0200, Tassilo v. Parseval
<[EMAIL PROTECTED]> wrote: 

[...]

> I am only familiar with its successor Modula-3 which, as far as I
> understand, is Modula-2 with uppercased keywords and some OO-notion
> bolted onto it (I still recall 'BRANDED' references). 

Modula-2 also overused caps, I recall the irratation I found
programing it was irratating, streaching my finger to hit the shift
key or taking me hands of the home keys to bump the CAPSLOCK key
quick became phisically painfull.


-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Function Serialization

2005-06-01 Thread Michele Simionato
The simple way is to use shelve:

$ ipython
Python 2.4.1c2 (#2, Mar 19 2005, 01:04:19)
Type "copyright", "credits" or "license" for more information.

IPython 0.6.5 -- An enhanced Interactive Python.
?   -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help-> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import shelve

In [2]: sh=shelve.open("x.shelve")

In [3]: def f(): pass
   ...:

In [4]: sh["f"]=f

In [5]: sh.close()

In [6]: sh=shelve.open("x.shelve")

In [7]: sh["f"]
Out[7]: 

You may want to experiment a bit.

 Michele Simionato

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


Re: Stupid Newbie Question Concerning CGI and Reading Forward Slashes

2005-06-01 Thread Steve Holden
Joey C. wrote:
> Steve Holden wrote:
> 
>>It's not a common question, but it's relatively easily answered. You are
>>splitting everything but the filename off with os.path.split and then
>>complaining about the result! Once you stop doing that your problem is
>>solved.
> 
> 
> Thus, it's a stupid newbie question.  Thanks a lot for your help.  It
> seems I was just being plain stupid.
> 
Well that's not stupidity, just "over-programming" ;-)

Glad you are moving forward.

regards
  Steve

-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


Re: cgi help

2005-06-01 Thread Bruno Desthuilliers
nephish a écrit :
> Hey there,
> i am trying to write an online application using the cgi module.
> what i want to do is have an html form display a drop-down list and
> have the values of that list be the lines of text written in a file.

Simplest, Q&D solution :
1/ open the file for reading
2/ print out the beginning of the html tags for the dropdown (hint:  in 
html, it's )
3/ for each line in the file, print out the html tags and the line
4/ print out the end of the html
5/ close the file

which gives (first try, Q&D, naive implementation, no error handling, etc:

f = open("myfile.txt")
print ""
for line in f:
   print "%s" %  line.strip()
print ""
f.close()

Now there may be some conditions we want to handle: file doesnt exist or 
is not readable, file is empty, a line is empty, etc. A second try could 
be like:

try:
   f = open("myfile.txt")
except IOError, e:
   # TODO : handle error. in the meantime:
   print "could not open myfile.txt for reading : %s" % e
   sys.exit(1)
else:
   print ""
   for line in f:
 if line.strip():
   print "%s" %  line.strip()
print ""
f.close()

Well... This does not handle all potential problems, and we begin to 
have useless repetitions (here the 'line.strip()' expression). We need 
to stop and think a little bit.

This snippet tries to do too many things at once: reading a file line by 
line, and printing the html for a select. Since we won't use selects for 
huge lists (for obvious usability reasons), we can assume that working 
with an in-memory list will be ok. So we could split this in two parts: 
one that read the file and returns a cleaned-up, ready to use list, and 
one that output the needed html:

# first part
try:
   f = open("myfile.txt")
except IOError, e:
   # TODO : handle error. in the meantime:
   print "could not open myfile.txt for reading : %s" % e
   sys.exit(1)
else:
   options = filter(None, [line.strip() for line in f])
   f.close()

   # second part:
   if options:
 print ""
 for line in options:
   print "%s" %  line
 print ""
   else:
 # Err ? what should we do here ?
 print "no selectable option here"

Hmm... Better, but still not ok. We can already guess that both parts 
can be useful indepently of each other, in in other contexts. So why not 
making this a little be generic ?

def listFrom(openedFile):
   return  filter(None, [line.strip() for line in openedFile])

def printSelect(name, options):
   print "" % name
   for line in options:
 print "%s" %  line
   print ""


def printSelectFromFile(name, path):
   try:
 f = open(path)
   except IOError, e:
 # TODO : handle error. in the meantime:
 print "could not open %s for reading : %s" % (path, e)
 sys.exit(1)
   else:
 options = listFrom(f)
 f.close()
 if options:
   printDropdownList(name, options)
 else:
   print "no selectable option here"

Well, this could of course be much more improved, but this will depend 
on stuffs specific to your application, so I'll leave it up to you...

> this would be updated almost every time the site is visited.
Err... Better take care of concurrent access...

> i have been sucessful in writing text to a file from an html form. but
> i need to access this so it can be selected.
> is there a way to do this? i have found limited info on how to really
> use the cgi module.  

AFAICT, there's nothing related to the cgi module in your problem.

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


NSLU2 and python - a love story ?

2005-06-01 Thread Thomas W
Has anybody done any work using Python on the Linksys NSLU2[1][2]? I'm
especially interested in stuff related to compiling additional modules,
like PIL. There are allready a bunch of stuff available in the current
replacement-firmware, but PIL seems to be missing.

If you haven't heard about the NSLU2-box yet start with the references
below and then google for it. It's very small, quiet, cheap and runs a
complete linux system, with python available ( and MySQL, PostgreSQL,
Apache etc etc ). It's very cool =)

Anyway, any information related to python and the nslu2-box are of
interest.

Regards,
Thomas

References :
[1] : http://www.nslu2-linux.org/
[2] :
http://www.linksys.com/products/product.asp?grid=35&scid=43&prid=640

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


ConfigParser, mapping one key to multiple values

2005-06-01 Thread Thomas Guettler
Hi,

I need a config like this:

[sync files]
ignore=".*/foodir/.*\.pyc"
ignore=".*/foodir/.*~"
...

The ConfigParser of the standard library can't handle this,
because one key maps to multiple values.
Is there a simple and lightweight config parser which can
handle this?

 Thomas

PS: Needs to be compatible with Python 2.3

-- 
Thomas Güttler, http://www.thomas-guettler.de/


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


Re: Another source of time for the logging package?

2005-06-01 Thread Ames Andreas
Skip Montanaro wrote:

> Before I get out my scalpel, has anyone found a non-invasive way to
> do this (or already done the surgery and would be willing to share
> it)?

While I'm not sure you would call the following 'non-invasive' I've
used it in a similar situation:

class MyLogRecord(logging.LogRecord):
def __init__(*args, **kwargs):
logging.LogRecord.__init__(self, *args, **kwargs)
self.created = time_warp() # get the time you need

class MyLogger(logging.Logger):
def makeRecord(self, *args, **kwargs):
return MyLogRecord(*args, **kwargs)

Then I call

logging.setLoggerClass(MyLogger)

before the relevant loggers are created.


HTH,

aa


-- 
Andreas Ames | Programmer | Comergo GmbH | 
Voice:  +49 69 7505 3213 | andreas . ames AT comergo . com
-- 
http://mail.python.org/mailman/listinfo/python-list


xml processing

2005-06-01 Thread Jeff Elkins
I've like to use python to maintain a small addressbook which lives on a Sharp 
Zaurus. This list will never grow beyond 200 or so entries. I've installed 
pyxml.

Speaking generally, given a wxpython app to do data entry, 
I'm planning to:

1. parse the addressbook file, loading its data into an array.
2. Perform any edit operations within the array.
3. Write out a finished xml file from the array when I'm done.

Is this reasonable? Better, smarter ways to accomplish this?

Thanks for any advice.

Jeff Elkins





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


python 2.4: tarfile tell() and seek() seem to be broeken

2005-06-01 Thread N. Volbers
Hello everyone,

I noticed that when you open a zipped tarball using 'tarfile' and if you
then get the pseudo-file descriptor fd for a file via 'extractfile', then
fd.tell() is broken in the following way:

- before reading anything from fd, fd.tell() will return 0 (that's still
ok)
- after reading a line via fd.readline(), fd.tell() will return a
value different from 0 (still ok, I guess)
- subsequent calls of fd.readline() and fd.tell() will yield the correct
lines but always the same value from fd.tell().  

fd.seek() seems to be unaffected from this strange behaviour.

Is there a mistake on my side or does this need fixing?

Best regards,

Niklas Volbers.


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


Elementtree and CDATA handling

2005-06-01 Thread alainpoint
I am experimenting with ElementTree and i came accross some
(apparently) weird behaviour.
I would expect a piece of XML to be read, parsed and written back
without corruption (except for the comments and PI which have purposely
been left out). It isn't however the case when it comes to CDATA
handling.
I have the following code:
text="""
Document



// 0) then
   {
   return 1
   }
}
//]]>



"""

from elementtree import ElementTree
tree = ElementTree.fromstring(text)
ElementTree.dump(tree)

Running the above piece of code yields the following:


Document



//
function matchwo(a,b)
{
if (a < b && a > 0) then
   {
   return 1
   }
}
//




There are two problems: the //

Monitoring a USB-drive / Card-reader using python?

2005-06-01 Thread Thomas W
I want to monitor a given USB-device, like a Memory Card-reader, and
when a memory card is inserted I want to move the data on the card to a
different location on the filesystem ( or do something else with the
files).

Does anybody know how to do this ( on Linux and/or windows ) or if it's
even do-able ?

Thomas

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


Re: Elementtree and CDATA handling

2005-06-01 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> There are two problems: the //

RE: Monitoring a USB-drive / Card-reader using python?

2005-06-01 Thread Tim Golden
[Thomas W]
| I want to monitor a given USB-device, like a Memory Card-reader, and
| when a memory card is inserted I want to move the data on the 
| card to a
| different location on the filesystem ( or do something else with the
| files).
| 
| Does anybody know how to do this ( on Linux and/or windows ) 
| or if it's
| even do-able ?

It can be done on Windows using the WM_DEVICECHANGE
I'll try to hunt out some code... OK, it's a bit long,
but if you Google this group for "wm_devicechange"
you'll find some code I posted which works for USB
sticks and CD-ROMs.

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: Generalized Linear Least Squares Problems

2005-06-01 Thread Colin J. Williams
Tim Leslie wrote:
> On 31 May 2005 03:12:49 -0700, venkat <[EMAIL PROTECTED]> wrote:
> 
>>Hi,
>>
>>I want to solve linear least sqaure problem( min||c-Ax||2 subject to
>>Bx=d ). How do I do it in python. lapack has a routine for doing this
>>(DGGLSE). Can I access this from python?
>>
> 
> 
> Check out scipy, in particular the linear algebra package.
> 
> http://www.scipy.org/documentation/apidocs/scipy/scipy.linalg.html
> 
> Cheers,
> 
> Tim
>  
Or you could try numarray, available for use with Python 2.4
 
http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=32367&release_id=329948

Colin W.
> 
>>TIA,
>>venkat.
>>
>>--
>>http://mail.python.org/mailman/listinfo/python-list
>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with pointers

2005-06-01 Thread Leif K-Brooks
Duncan Booth wrote:
> The constant integers are created in advance, not when you do the 
> assignment.

But that's just an optimization, not Python's defined behavior. It seems
more useful to me to think of all integers as being created at
assignment time, even if CPython doesn't actually do that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to convert string to list or tuple

2005-06-01 Thread Fuzzyman
flyaflya wrote:
> a = "(1,2,3)"
> I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',',
> '2', ',', '3', ')') not (1,2,3)

Probably a bit late... but there's always listquote - It's part of the
pythonutils module.

http://www.voidspace.org.uk/python/pythonutils.html

It will turn strings to lists, including nested lists.

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python

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


Re: Another source of time for the logging package?

2005-06-01 Thread Skip Montanaro

>> Before I get out my scalpel, has anyone found a non-invasive way to
>> do this (or already done the surgery and would be willing to share
>> it)?

Ames> While I'm not sure you would call the following 'non-invasive'
Ames> I've used it in a similar situation:

Ames> class MyLogRecord(logging.LogRecord):
Ames> def __init__(*args, **kwargs):
Ames> logging.LogRecord.__init__(self, *args, **kwargs)
Ames> self.created = time_warp() # get the time you need
...

Excellent!  Works like a charm.  Thanks,

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


Unhappy with numarray docs

2005-06-01 Thread Matt Feinstein
I spent all day yesterday trying to figure out how to do file IO in
the numarray module-- I -did- (I think) figure it all out, eventually,
but it's left me in a rather sour mood.

1. The basic functions and methods: fromfile, fromstring, tofile, and
tostring, are buried, in non-alphabetical order, in two chapters that
list -all- the functions and methods. This is not user-friendly. The
explanations themselves, once I found them, are OK, but a line or two
of sample code is always nice. File IO is a real-world necessity in an
environment where most people use Matlab and/or IDL. And is it
obvious, btw, that reading data should be a function? What if I want
to read into a buffer?

2. The memmap documentation is screwed up in a more serious fashion. I
was able to deduce relatively rapidly that

from numarray.memmap import *

was needed for some of the example code. But I didn't immediately have
the degree of clairvoyance needed to figure out that

import numarray.numarryall as num

was required for the critical step of associating an array with a
MemmapSlice. Grr.

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: AM_PATH_PYTHON - version problem

2005-06-01 Thread Colin J. Williams
Uwe Mayer wrote:
> Hi,
> 
> I use the GNU autotools for packaging my python applications. My problem is
> that as I have both python2.3 and python2.4 installed the automake macros
> always detects the newest version and sets it path variables accordingly. 
> 
> How can I package the program for different versions of Python? 
> (i.e. for generating binary packages)
> 
> Any ideas?
> 
> Thanks,
> Ciao
> Uwe 
wxPython provides a method for linking to different Python versions.

Robin Dunn's approach might help.

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


Fredericksburg, VA ZPUG June 8

2005-06-01 Thread Gary Poster
Please join us June 8, 7:30-9:00 PM, for the inaugural meeting of the  
Fredericksburg, VA Zope and Python User Group ("ZPUG"). Tres Seaver,  
architect of the Zope Content Management Framework, will present.  
Further meetings are planned for the second Wednesday of every month.  
Location will be at the Zope Corporation offices.

Further details below, and at
http://www.zope.org/Members/poster/fxbgzpug_announce.

Gary

-

Fredericksburg, VA ZPUG: second Wednesday of every month, 7:30-9:00

First meeting: June 8, 7:30.

Speaker: Tres Seaver, architect of the Zope Content Management
Framework (CMF).

Topic: Selenium (automated cross-platform, cross-browser application
browser tests, http://selenium.thoughtworks.com/index.html), as
integrated with Zope 2 in Zelenium (http://www.zope.org/Members/
tseaver/Zelenium).

Location: Zope Corporation offices (http://tinyurl.com/duoab or
http://maps.google.com/maps?q=Zope+Corporation,+513+Prince+Edward
+Street,+Fredericksburg,+VA
+22401&ll=38.298600,-77.457900&spn=0.032410,0.068500&hl=en)

Parking: Zope Corporation parking lot; entrance on Prince Edward Street.

Future topics: As desired (and offered) by participants, within the
constraints of having to do with Python.  Possible topics include
presentations referencing Zope 3, Zope 2, Twisted Framework, core
Python topics, Python and XML,  Zope Object Database (ZODB),
Macintosh OS X application development with Python, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: xml processing

2005-06-01 Thread Magnus Lycka
Jeff Elkins wrote:
> I've like to use python to maintain a small addressbook which lives on a 
> Sharp 
> Zaurus. This list will never grow beyond 200 or so entries. I've installed 
> pyxml.
> 
> Speaking generally, given a wxpython app to do data entry, 
> I'm planning to:
> 
> 1. parse the addressbook file, loading its data into an array.
> 2. Perform any edit operations within the array.
> 3. Write out a finished xml file from the array when I'm done.
> 
> Is this reasonable? Better, smarter ways to accomplish this?

Why XML?

I guess the simplest solution whould be to use pickle.

Saving:
 >>> import pickle
 >>> l = []
 >>> l.append(('Alan', '1st Street', 123456))
 >>> l.append(('Ben', '2nd Street', 234567))
 >>> l.append(('Clark', '3rd Street', 345678))
 >>> f = open('phonebook','w')
 >>> pickle.dump(l, f)
 >>> f.close()

Loading:
 >>> import pickle
 >>> f2 = open('phonebook')
 >>> l = pickle.load(f2)
 >>> f2.close()
 >>> for item in l:
print item


('Alan', '1st Street', 123456)
('Ben', '2nd Street', 234567)
('Clark', '3rd Street', 345678)

The file looks like this:
 >>> print open('phonebook').read()
(lp0
(S'Alan'
p1
S'1st Street'
p2
I123456
tp3
a(S'Ben'
p4
S'2nd Street'
p5
I234567
tp6
a(S'Clark'
p7
S'3rd Street'
p8
I345678
tp9
a.
 >>>

Ok, the file content might not seem completely obvious, but it's
not really so difficult to parse it, and it's certainly less verbose
than XML. Above all, much less code.

BTW, cPickle is faster than pickle, but I suspect it doesn't matter
with such a small amount of data. It's easy to replace "import pickle"
with "import cPickle as pickle" to try it out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: working with pointers

2005-06-01 Thread Duncan Booth
Leif K-Brooks wrote:

> Duncan Booth wrote:
>> The constant integers are created in advance, not when you do the 
>> assignment.
> 
> But that's just an optimization, not Python's defined behavior. It seems
> more useful to me to think of all integers as being created at
> assignment time, even if CPython doesn't actually do that.
> 

Alternatively think of all integers as existing all of the time, whether or 
not they are referenced.

Yes, it is just an optimisation, but it is one which results in an 
observable difference in behaviour. i.e. if all integers are created as 
they are needed you will never share integers.

Of course, if all integers existed all of the time then I guess you might 
expect 'a==b' to always imply 'a is b', so my interpretation is differently 
inaccurate.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are OOP's Jargons and Complexities?

2005-06-01 Thread Matthias Buelow
Anno Siegel wrote:

> I've been through Pascal, Modula2 and Oberon, and I agree.
> In the short run they succeeded.  For a number of years, languages of
> that family were widely used, primarily in educational programming
> but also in implementing large real-life systems.

With a few relaxations and extensions, you can get a surprisingly useful
language out of the rigid Pascal, as evidenced by Turbo Pascal, one of
the most popular (and practical) programming languages in the late 80ies
/ start of the 90ies.

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


Re: scripting browsers from Python

2005-06-01 Thread Jeff Epler
I wanted to have a Python program make my browser do a POST.  I am using
Firefox on Linux.

Here's what I did:
* Prepare a HTML page on the local disk that looks like this:


http://www.example.com/cgi-bin/example.cgi";>






Submitting form...



* Point the webbrowser at it.  In my case, the webbrowser module didn't work 
immediately so I 
  just used os.system() with a hardcoded browser name for it

Jeff


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

Re: xml processing

2005-06-01 Thread Jeff Elkins
On Wednesday 01 June 2005 09:51 am, Magnus Lycka wrote:
> Jeff Elkins wrote:
> > I've like to use python to maintain a small addressbook which lives on a
> > Sharp Zaurus. This list will never grow beyond 200 or so entries. I've
> > installed pyxml.
> >
> > Speaking generally, given a wxpython app to do data entry,
> > I'm planning to:
> >
> > 1. parse the addressbook file, loading its data into an array.
> > 2. Perform any edit operations within the array.
> > 3. Write out a finished xml file from the array when I'm done.
> >
> > Is this reasonable? Better, smarter ways to accomplish this?
>
> Why XML?
>
> I guess the simplest solution whould be to use pickle.

The Zaurus addressbook app depends on an xml datafile, so I'm stuck with that 
format. I just want to to maintenence and data entry on the PC for ease of 
use vs typing on the Zaurus' tiny keyboard. I could just edit the raw xml 
file, then copy it to the Zaurus, but I'd like to have something a little 
spiffier...

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


PySol not working on WinXP, SP2

2005-06-01 Thread Ivan Van Laningham
Hi All--
I've been using PySol-4.40 for years, because that was the last Windows
installer version I could find.  My wife's been using it for almost the
same length of time.  That version's worked just fine on W98, W98SE, W2K
(server included), and WinXP SP1.

I upgraded to SP2 and pysol fails silently.  Running 'python pysol.pyw'
gives me this error: 

Traceback (most recent call last):

  File "pysol.pyw", line 64, in ?

imp.load_compiled("__main__", sys.argv[0])

ImportError: Bad magic number in C:\Program
Files\PySol-4.40\data\pysol.pyc

I can't find any later version on google, although I turned up a thread
on this list regarding running pysol in a later version on W98.  I also
found http://avitous.net/software/pysol-windows/py23.shtml but the
version he has REQUIRES ActiveState python 2.2, even though he says he's
put together a version for 2.3--and of course, I'm running Python 2.4.

My wife's going to be force to upgrade to SP2 some of these days, and
she won't be happy if her solitaire doesn't work.  Does anyone have a
working version?  Anyone know what happened to Markus ... Oberhumer?

Metta,
Ivan
--
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to convert string to list or tuple

2005-06-01 Thread Steven Bethard
Duncan Booth wrote:
> Steven Bethard wrote:
> 
> 
>>Interestingly, I don't seem to be able to create a file object as a 
>>class attribute in restricted mode:
>>
>>py> class C(object):
>>... def __init__(self):
>>... self.f = file('temp.txt', 'w')
>>...
>>py> eval('''[ cls for cls in
>>{}.__class__.__bases__[0].__subclasses__() if cls.__name__ ==
>>'C'][0]().f.write("stuff")''', dict(__builtins__=None)) Traceback
>>(most recent call last): 
>>   File "", line 1, in ?
>>   File "", line 0, in ?
>>AttributeError: 'C' object has no attribute 'f'
>>py> eval('''[ cls for cls in
>>{}.__class__.__bases__[0].__subclasses__() if cls.__name__ ==
>>'C'][0]().__dict__''', dict(__builtins__=None)) {}
> 
> Weird. I copied and paste your class and eval exactly (apart from deleting 
> the ... prompts) and it worked exactly as expected: writing 'stuff' to 
> temp.txt. (Python 2.4)

So, I played around with this a little bit.  If I start up a new 
interpreter and type it in like above, I get the behavior you do.  What 
I had actually done (abbreviated) was:

py> class C(object):
... pass
...
py> class C(object):
... def __init__(self):
... self.f = file('temp.txt', 'w')
...
py> eval('''[ cls for cls in {}.__class__.__bases__[0].__subclasses__() 
if cls.__name__ == 'C'][0]().f.write("stuff")''', dict(__builtins__=None))
Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 0, in ?
AttributeError: 'C' object has no attribute 'f'

And the problem with this is that both __main__.C objects are now 
subclasses of object:

py> eval('''[ cls for cls in {}.__class__.__bases__[0].__subclasses__() 
if cls.__name__ == 'C']''', dict(__builtins__=None))
[, ]

So I was getting the wrong __main__.C object.  Sorry for the confusion!

Now, even using this technique, *your* code can't call the file constructor:

py> class C(object):
... def __init__(self):
... self.file = file
...
py> eval('''[ cls for cls in {}.__class__.__bases__[0].__subclasses__() 
if cls.__name__ == 'C'][-1]().file("temp.txt", "w")''', 
dict(__builtins__=None))
Traceback (most recent call last):
   File "", line 1, in ?
   File "", line 0, in ?
IOError: file() constructor not accessible in restricted mode

But unless the person eval-ing your code *only* writes immaculate code I 
can see that you can probably screw them. ;)  I wonder why 
__subclasses__ isn't a restricted attribute...  Is it ever used for 
something that isn't evil? ;)

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


Re: xml processing

2005-06-01 Thread Steven Bethard
Jeff Elkins wrote:
> I've like to use python to maintain a small addressbook which lives on a 
> Sharp 
> Zaurus. This list will never grow beyond 200 or so entries. I've installed 
> pyxml.

If you're not committed to pyxml, you might consider using ElementTree:

http://effbot.org/zone/element-index.htm

I find it *way* easier to work with.

> 
> Speaking generally, given a wxpython app to do data entry, 
> I'm planning to:
> 
> 1. parse the addressbook file, loading its data into an array.
> 2. Perform any edit operations within the array.
> 3. Write out a finished xml file from the array when I'm done.
> 
> Is this reasonable? Better, smarter ways to accomplish this?

Seems pretty reasonable.  Another option might be to parse the 
addressbook file into an XML object and then modify the XML object 
itself.  E.g.:

tree = ElementTree(file="...")
elem = tree.getroot()
for node in elem.findall("..."):
 node.text = "..."

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


Re: Unhappy with numarray docs

2005-06-01 Thread Scott David Daniels
Matt Feinstein wrote:
> I spent all day yesterday trying to figure out how to do file IO in
> the numarray module-- I -did- (I think) figure it all out, eventually,
> but it's left me in a rather sour mood.
> 
>  Grr.
Propose some fixes to the documents that will make this easier for
the next one in line.  You don't even need to get it exactly right;
the person after you can fix the mistakes you make.  This is the
process we use for this.  See this as an opportunity to contribute,
not simply a frustration about how much you overpaid for the product.

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


Re: Unhappy with numarray docs

2005-06-01 Thread Matt Feinstein
On Wed, 01 Jun 2005 08:11:36 -0700, Scott David Daniels
<[EMAIL PROTECTED]> wrote:

>Propose some fixes to the documents that will make this easier for
>the next one in line.  You don't even need to get it exactly right;
>the person after you can fix the mistakes you make.  This is the
>process we use for this.  See this as an opportunity to contribute,
>not simply a frustration about how much you overpaid for the product.

Which is why I was specific about what I didn't like about the
documentation and why I didn't like it. Seriously, what more should I
do? It's plainly inappropriate for me to write documentation for a
module that I'm still struggling to learn.

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intellisense and the psychology of typing

2005-06-01 Thread Robert C.Martin
On 26 May 2005 09:31:12 -0700, [EMAIL PROTECTED] wrote:

>Yesterday I typed in some C++ code that called a function with two
>ints. Intellisense (auto-complete) helpfully told me that the first
>formal parameter was called "frontLight" and the second "ringLight". It
>occurred to me that I'm getting some semantic help here on top of the
>obvious type safety. It seems to me that the existance of this kind of
>support is tied to the static typing nature of  C++.
>
>I've always been interested in the psychology behind those heated
>"static" vs. "dynamic" (quotes to avoid another lengthy discussion
>about manifest, latent, explicit, ...) typing debates. So I googled
>"Intellisense static dynamic typing" and tried to get a view of the
>collective mental landscape of this subject. It appears that the
>threads that talk about Intellisense soon run dry. I'm wondering if
>this is because:
>
>1) Intellisense is really just another crutch that does more harm than
>good? There were a few hardcore defenders of this position but not
>many.
>
>2) Intellisense is really useful but hard to implement well in IDEs for
>dynamic languages? Can anyone comment on the status of
>Intellisense-like tools for dynamic-language IDEs?
>
>3) Users of dynamic languages are always developing/debugging running
>programs where the current type of a variable is known and hence
>Intellisense is possible again? My own limited experience with dynamic
>languages (Ruby) is limited to edit-run cycles.
>
>Any opinions?

Static typing is a strong enabler of certain intelisense functions;
but not all, nor even most.  A good IDE for a dynamically typed
language can make quite a few inferences to decide how to suggest
intellisense.  That said, statically typed languages will always have
better intellisense than dynamically typed languages.

Indeed, one of the reasons that I have not switched to Ruby as my
standard language is the wonderful tools available with "IntelliJ" for
Java and "ReSharper" for C#.


-
Robert C. Martin (Uncle Bob)  | email: [EMAIL PROTECTED]
Object Mentor Inc.| blog:  www.butunclebob.com
The Agile Transition Experts  | web:   www.objectmentor.com
800-338-6716   


"The aim of science is not to open the door to infinite wisdom, 
 but to set a limit to infinite error."
-- Bertolt Brecht, Life of Galileo
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: anygui,anydb, any opinions?

2005-06-01 Thread Thomas Bartkus
"rzed" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]

> So what do you think? What's wrong with the picture? Why isn't
> there a greater priority to work in this direction?

   > What's wrong with the picture?

Just one teeny little item.

The Python world lacks the phenomenally successful development models
enjoyed by the now ancient Turbo Pascal, Delphi and  Visual Basic.
AND
If the likes of Visual Basic can have it, then it becomes really, *really*
hard to convince the world that Python is a serious, professional system.

At some point, one has to break out of theory and produce!
Or challenge the theory with some hard questions.

Thomas Bartkus


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


using builtin array

2005-06-01 Thread shama . bell
Is it possible to join/append 2 arrays defined with different
typecodes?

What typecode should i use to generate the following output.

data1 = array('h', '\0', 6)
data2 = array('L', '\0', 25)

for i in range( 6):
data1[0] = 0xFF
data2[1] = 0x00
data1[2] = 0x00
data1[3] = 0x00
data1[4] = 0x00
data1[5] = 0x00

for i in range( 2):
data2[0] = 0xF0F0F0F0
data2[1] = 0x

Output should be...
(0xFF 0x00 0x00 0x00 0x00 0x00 0xF0F0F0F0 0x)

Thank You,
-SB

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


Re: Unhappy with numarray docs

2005-06-01 Thread Fernando Perez
Matt Feinstein wrote:

> On Wed, 01 Jun 2005 08:11:36 -0700, Scott David Daniels
> <[EMAIL PROTECTED]> wrote:
> 
>>Propose some fixes to the documents that will make this easier for
>>the next one in line.  You don't even need to get it exactly right;
>>the person after you can fix the mistakes you make.  This is the
>>process we use for this.  See this as an opportunity to contribute,
>>not simply a frustration about how much you overpaid for the product.
> 
> Which is why I was specific about what I didn't like about the
> documentation and why I didn't like it. Seriously, what more should I
> do? It's plainly inappropriate for me to write documentation for a
> module that I'm still struggling to learn.

Just a suggestion: post your message on the numeric discussion list (where
numarray is also discussed).  Most of the num* developers only check c.l.py on
occasion, so it's very easy that your message will be simply missed by the
appropriate people, which would be a shame.  They are generally very
responsive to user requests and constructive criticism.

best,

f

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


Question about mutexes

2005-06-01 Thread Jan Danielsson
In OS/2 C, I would do this:

main()
{
...
DosCreateMutexSem(NULL, &hmtx, 0UL, FALSE);
...
}

thread()
{
...
DosRequestMutexSem(hmtx);

Locked!

DosReleaseMutexSem(hmtx);
...
}

How would I go about doing that in Python?

I figured this part out:

lockobj = mutex()

lockobj.lock(foo, "bar")

Locked!

lockobj.unlock()


Now, what (and more importantly: WHY?!) - is foo and "bar" for?

   I have written a dummyfunction for foo which does nothing when
called, but I fail to see the point of its existence. Could someone
provide an example when this would be useful?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about mutexes

2005-06-01 Thread Reinhold Birkenfeld
Jan Danielsson wrote:
> In OS/2 C, I would do this:
> 
> main()
> {
> ...
> DosCreateMutexSem(NULL, &hmtx, 0UL, FALSE);
> ...
> }
> 
> thread()
> {
> ...
> DosRequestMutexSem(hmtx);
> 
> Locked!
> 
> DosReleaseMutexSem(hmtx);
> ...
> }
> 
> How would I go about doing that in Python?

I think you will want to create a threading.Lock object.

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


Re: ignoring SIGPIPE in a python script?

2005-06-01 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 Dan Stromberg <[EMAIL PROTECTED]> wrote:

> I have a python script that sometimes gets a SIGPIPE signal, and errors
> out.  And I want it to just terminate as though it had hit EOF.
> 
> I'm running:
> 
>signal.signal(signal.SIGPIPE,signal.SIG_IGN)
> 
> ...in the main function, but the script is still erroring out on sigpipe
> when the consumer to its producer terminates early.
> 
> Am I going to have to code in a handful of exceptions, and then
> conditionalize what happens in those exception handlers, to get the
> desired behavior?
> 
> ISTR hearing that although bash notifies one of SIGPIPE errors, tcsh
> generally silently ignores them.  From this, I conclude that it might be
> reasonable for my script to ignore SIGPIPE.

This is a little idiosyncracy of Python's.  You can restore
the default signal handler,
   signal.signal(signal.SIGPIPE, signal.SIG_DFL)

and it will behave like a normal UNIX application.  These other
applications aren't precisely ignoring SIGPIPE, though.  If you
think about what that would look like, I guess it would mean they
would continue to write output, since it's truly a rare application
that checks its output (especially since it's usually buffered.)
The SIGPIPE signal just aborts the program.  Not really very
much like EOF at all.

You could install your own handler, but it would probably make
about as much sense to just trap the exception.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


metaclass that inherits a class of that metaclass?

2005-06-01 Thread ironfroggy
Hoping this isn't seeming too confusing, but I need to create a
metaclass and a class using that metaclass, such that one of the bases
of the metaclass is the class created with that metaclass. I can't
figure out a way to do this, even after trying to add the class as a
base after the classes have been created.

Is there some way I can get this to work properly?

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


Re: Unhappy with numarray docs

2005-06-01 Thread Matt Feinstein
On Wed, 01 Jun 2005 09:55:14 -0600, Fernando Perez
<[EMAIL PROTECTED]> wrote:

>Just a suggestion: post your message on the numeric discussion list (where
>numarray is also discussed).  Most of the num* developers only check c.l.py on
>occasion, so it's very easy that your message will be simply missed by the
>appropriate people, which would be a shame.  They are generally very
>responsive to user requests and constructive criticism.

Done. Thanks for the suggestion.

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread infidel
Why in the name of all that is holy and just would you need to do such
a thing?

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


How can i craft my own ip packets in python

2005-06-01 Thread ionel
er pointers please? :)

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


Re: Question about mutexes

2005-06-01 Thread Jan Danielsson
Reinhold Birkenfeld wrote:
[---]
>>How would I go about doing that in Python?
> 
> I think you will want to create a threading.Lock object.

It would seem so. Thanks for the tip!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread ironfroggy
because they are representing a seperate typing system outside of
python, to which I am creating a bridge. The metaclass represents the
types of this other system and the class represents the most basic
object type, but since the types the metaclass represent are also
objects, this is the only way i see to represent the relationship
properly.

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


Re: cgi help

2005-06-01 Thread nephish
whoa, thanks
been trying to figgure this out for a week.
cant wait to try it this weekend.
thanks again.

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


Re: Elementtree and CDATA handling

2005-06-01 Thread Terry Reedy

"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> you're confusing the external representation of something with the 
> internal
> data model.
>
> consider this:
>
>>>> "hello"
>>>> 'hello'
>>>> "hell\x6f"
>>>> "hell\157"
>>>> "hell" + "o"
>>>> 'h' 'e' 'l' 'l' 'o'
>
> the above are six ways to write the same string literal in Python.

Minor nit: I believe 'hell' + 'o' is two string literals and a runtime 
concatenation operation.  Perhaps you meant 'hell' 'o', without the '+', 
which I believe is joined to one literal at parsing or compilation time.

> all these result
> in a five-character string containing the letters "h", "e", "l", "l", and 
> "o".
> if you type the above at a python prompt,
> you'll find that Python echoes the strings back as
> 'hello' in all six cases.

Nit aside, this is a valuable point that bears repeating.  Another example 
of one internal versus multiple external that confuses many is the 
following:
 1.1 == 1.1001 # True

The mapping of external to internal is many-to-one for both strings and 
floats and therefore *cannot* be exactly inverted!  (Or round-tripped.) So 
Python has to somehow choose one of the possible external forms that would 
generate the internal form.

Terry J. Reedy




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


Information about Python Codyng Projects Ideas

2005-06-01 Thread M1st0
Hi to All!

I would like to join the Google summer code program
(http://code.google.com/summerofcode.html).
>From the sponsored links I have choose to help The Python Software
Foundation, because I like a lot the language.
I have read the proposed Ideas from

http://wiki.python.org/moin/CodingProjectIdeas

And the more interesting for me were those about Optimization.

MemoryUsageProfiler
ProfileReplacementProject
SpeedUpInterpreterStartup

But I many of this there are very few information or nothing about of
what is really needed.
I am taking a Master in Computer Science so I know many of the issues
in this topics, but I would like some hints and every usefull
information.

I hope that here is the right place for this kind of discussion.

Kind Regards

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


Pressing A Webpage Button

2005-06-01 Thread Elliot Temple
How do I make Python press a button on a webpage?  I looked at  
urllib, but I only see how to open a URL with that.  I searched  
google but no luck.

For example, google has a button how would i make a script to press that button?

Just for fun, is there any way to do the equivalent of typing into a  
text field like the google search field before hitting the button?   
(I don't actually need to do this.)

If someone could point me in the right direction it'd be appreciated.

-- Elliot Temple
http://www.curi.us/


---
[This E-mail scanned for viruses by Declude Virus]

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


Re: Pressing A Webpage Button

2005-06-01 Thread Brian Beck
Elliot Temple wrote:
> How do I make Python press a button on a webpage?  I looked at
> urllib, but I only see how to open a URL with that.  I searched
> google but no luck.

Check out mechanize: http://wwwsearch.sourceforge.net/mechanize/

--
Brian Beck
Adventurer of the First Order

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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread infidel
I don't think that makes any sense.  How could you possibly create such
a circular relationship between things in any language?  Besides, if I
understand metaclasses at all, only other metaclasses can be bases of a
metaclass.

Why not use python classes to represent the other system's types with a
python metaclass as the "type" type?

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


Re: What's wrong with Zope 3 ?

2005-06-01 Thread Kay Schluehr


Wolfram Kraus wrote:
> Kay Schluehr wrote:
> > The last downloadable release is from november 2004. The Windows
> > installer is configured for Python 2.3(!). The Zope.org main page
> > announces Zope 2.8 beta 2. Is it stillborn?
> >
> > Kay
> >
> What you see is not Zope 3, it is Zope X 3. To quote from the X3
> information page: "Zope X3 3.0 is for developers. If you are expecting
> an end-user application, this is not for you."

Yes I noticed this almost 8 months ago, read a bit of the documentation
and articles published that time, regarded it as interesting and
considered it for future development. But since then absolutely nothing
happened. No project plan, no time-schedule, no subsequent releases.

> The current stable brance is Zope2.X If you want to incorporate some
> functionalty from X3 in Zope 2.X, do a search for "Five"

No, I do not want to migrate components from a new major release
backwards, as well as I do not want to migrate applications from WinXP
to Win98. This seems to be the wrong development process direction.

Regards,
Kay

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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread Kristian Zoerhoff
On 1 Jun 2005 09:41:53 -0700, infidel <[EMAIL PROTECTED]> wrote:
> Why in the name of all that is holy and just would you need to do such
> a thing?

Is anyone else amused that this came from the mouth of someone named "Infidel"?

-- 
Kristian

kristian.zoerhoff(AT)gmail.com
zoerhoff(AT)freeshell.org
-- 
http://mail.python.org/mailman/listinfo/python-list


PyTables Error: ...import *

2005-06-01 Thread benjamin . scott
Hello,

I am using an XP box and Python 2.3 (Enthought Edition).  I am getting
the same error with both of the .exe's listed on sourceforge:

tables-1.0.win32-py2.3.exe
tables-1.0.LB.win32-py2.3.exe

Note that the installation seems to go fine.  Although, when I run the
test_all.py file it seems to fall over due to references to numarray; I
am using Numeric.

I am trying to follow the PyTables User Guide:

http://pytables.sourceforge.net/html-doc/

Per installation instructions I copied the 3 prereq files as noted
here:

http://pytables.sourceforge.net/html-doc/x420.html#subsection2.2.1

I am getting an error in the following section:

http://pytables.sourceforge.net/html-doc/c474.html#subsection3.1.1

In particular, "from tables import *" gives the following error:

Traceback (most recent call last):
 File "", line 1, in -toplevel-
   from tables import *
 File "...\site-packages\tables\__init__.py", line 33, in
-toplevel-
   from tables.hdf5Extension import\
ImportError: No module named hdf5Extension

Note that the only file with the name "hdf5Extension" in the
"...\site-packages\tables\" directory has the extension ".pyd", not
".py" or ".pyc".

Suggestions?

Thanks in advance,

-Ben

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


Re: Newbie learning OOP

2005-06-01 Thread Terry Hancock
On Sunday 29 May 2005 03:18 pm, John Machin wrote:
> LenS wrote:
> > Trying to learn OOP concepts and decided to use Python for this
> > purpose.  I have coded the following CLASS and it seems to work fine.
> > Any comments on the code or suggestions would be appreciated.

> A practical problem: not everbody's name can be shoe-horned into the 
> first/initial/last model. You face catastrophic loss of information.
> 
> Some examples, with "last" name in capitals:
> 
> J. Edgar HOOVER -> J E HOOVER
> Rip J. VAN WINKLE -> Rip J VAN
> Jean Paul DE LA SALLE -> Jean P DE
> DE LA SALLE, Jean Paul -> LA S DE
> MAO Tse Tung -> Tse T MAO # or MAO T Tung
> MAO Tse-tung -> Tse-tung M  # or an IndexError
> MAO Zedong -> Zedong M  # or an IndexError
> Vigdis ERIKSDOTTIR -> Vigdis E  # and lost the gender, too
> Gunnlaug ILLUGASON Ormstunga -> Gunnlaug I Ormstunga # nickname 
> "Snakestongue"
> Ivan Denisovich SHUKHOV -> Ivan D SHUKHOV # and lost father's "first" 
> name, too
> Friedrich Heinrich Karl VON UND ZU HOHENLOHE -> Friedrich H Karl
> NGUYEN Thi Thanh Van -> Thi T NGUYEN
> # "Thi" means "female" and "Nguyen" is the "last" name of about 50% of 
> the Vietnamese population ...

While I might say something snide about unnecessarily crucifying a piece
of "toy" code for learning OOP, this is *really* nice set of test cases! Thank
you, I'm saving this for reference.  :-)

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


unsigned long to unsigned char

2005-06-01 Thread [EMAIL PROTECTED]
Hello,

Is it possible to convert unsigned long( 4 bytes) to unsigned char(1
byte), so that i could define a common array for both.

import array
temp = array('B', '\0' * 512)

for i in range( 2):
temp[0] = 0xFF
temp[1] = 0x

Thanks,
-Ashton

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


Re: NSLU2 and python - a love story ?

2005-06-01 Thread Terry Reedy

"Thomas W" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> If you haven't heard about the NSLU2-box yet start with the references
> below and then google for it. It's very small, quiet, cheap and runs a
> complete linux system, with python available ( and MySQL, PostgreSQL,
> Apache etc etc ). It's very cool =)
> [1] : http://www.nslu2-linux.org/
> [2] :
> http://www.linksys.com/products/product.asp?grid=35&scid=43&prid=640

The Linksys product literature [2] never mentions the word Linux, so I 
gather a) that it is an add-on and b) that the user group [1] is quite 
unofficial.  For those curious, the price is about $100.

The product lit also says 0 about the internal hardware but I found this: 
http://www.nslu2-linux.org/wiki/Info/CPUOverview.  266 Mhtz, 32 Mb Ram + 8 
MB flash, which is pretty minimal these days.  So unless one wants it for 
the designed purpose (or similar), it is not obviously cheap.

I am curious what Python application you have in mind.

Terry J. Reedy




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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread ironfroggy
because i need the representations of the other systems types to
themselves be python classes, and so i need a metaclass to make sure
they follow certain rules. This metaclass is for that system what type
is for python, and type is an object, which is a type. same thing, no?

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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread infidel
"God made me an atheist, who are you to question His wisdom?"

-- Saint Infidel the Skeptic

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


idiom for constructor?

2005-06-01 Thread Mac
Is there a nice Python idiom for constructors which would expedite the
following?

class Foo:
  def __init__(self, a,b,c,d,...):
self.a = a
self.b = b
self.c = c
self.d = d
...

I would like to keep the __init__ parameter list explicit, as is,
rather than passing in a dictionary, as I want the code to be explicit
about what arguments it expects... in effect enforcing the right number
of arguments.

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


Re: Seti-like program

2005-06-01 Thread Irmen de Jong
Magnus Lycka wrote:

> Both CORBA implementations and simpler things like PYRO could help, but
> these systems are more aimed at enabling communication between programs
> running in a distributed fashion, and I don't think they target tasks
> such as job queues, starting and stopping jobs, or load balancing etc.

Indeed, not directly. But it would be possible to create such a thing.

And the latest Pyro (3.5 beta, at the moment) contains an interesting
example that automatically partitions a computation task, distributes
the parts among available 'processor' objects, and aggregates the
result. I have supplied a sorting task and a md5 'cracking' task.
It is perhaps not really what was asked, but I think it is at least
a bit relevant to this topic.

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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread infidel
> because i need the representations of the other systems types to
> themselves be python classes, and so i need a metaclass to make sure
> they follow certain rules. This metaclass is for that system what type
> is for python

I think that's exactly the same thing I just said.  More or less.
Although depending on exactly what you mean by "follow certain rules",
you might only need a common base class rather than a metaclass.

> same thing, no?

Uh, no, I don't think so.  type is, from my trivial understanding, the
base type and base metaclass for everything else in python.  Saying
"type is an object" is only confusing you into thinking it is a
subclass of object, which is not the case.  object is a class, which I
believe has type as it's metaclass (though I could be mistaken - this
gets terribly confusing very quickly).

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


Re: Python analog of Ruby on Rails?

2005-06-01 Thread Nick Vargish
bruno modulix <[EMAIL PROTECTED]> writes:

> Err... Looks like I've seen this before, but where ???

Don't know, but it looks sort of familiar...

Nick

-- 
# sigmask  (lambda deprecation version) 20041028 || feed this to a python
print ''.join([chr(ord(x)-1) for x in 'Ojdl!Wbshjti!=ojdlAwbshjti/psh?'])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread Kay Schluehr
ironfroggy wrote:
> because they are representing a seperate typing system outside of
> python, to which I am creating a bridge.

Since a type-hierarchy is a tree also a subtree of it is a
type-hierarchy. You only have to map the root of a sub-hierarchy of
Python classes to the root of the hierarchy of the other typing system
and create an isomorphism between types. For exactly the same reason
you can map Pythons type hierarchy onto a sub-hierarchy of it. This
might not be completely sufficient because there are functions that
operate on types ( like mro(), isinstance(), type() etc. ). Those must
be mapped as well to counterparts of the other type-system. In
contemporary CS slang this is called a 'Functor of Categories' with
objects that are types ( and boolean values like True, False ) and
arrows that are type aware functions like those listed above.

Kay

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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread Just
In article <[EMAIL PROTECTED]>,
 "infidel" <[EMAIL PROTECTED]> wrote:

> [ ... ]  type is, from my trivial understanding, the
> base type and base metaclass for everything else in python.  Saying
> "type is an object" is only confusing you into thinking it is a
> subclass of object, which is not the case. 

Sure is:

   >>> type.__bases__
   (,)

> object is a class, which I
> believe has type as it's metaclass (though I could be mistaken - this
> gets terribly confusing very quickly).

Correct:

   >>> object.__class__
   

type also has type as its metaclass:

   >>> type.__class__
   

In other words, type is an instance of itself.

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


Re: Information about Python Codyng Projects Ideas

2005-06-01 Thread Rob Cowie
Ha,

I've just headed over here to ask the same thing!

Any good ideas not listed on the wiki?

I too am taking a Masters in Computer Science, however my first degree
was not purely CS - mostly microbiology, so I'm not yet what one would
call an expert

Cheers

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


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread infidel
Oh great, just when I thought I was starting to grok this mess.

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


BUG pythonw vs subprocess

2005-06-01 Thread Robin Becker
There seems to be a problem with calling subprocesses from a script run 
with pythonw rather than python. The error doesn't seem to be a function 
of using pythonw.exe rather than python.exe in the Popen call, but we 
seem to get an error when pythonw is used to execute the script proc0.py

C:\Tmp>cat proc0.py
#proc0.py
import sys
from subprocess import Popen, PIPE
sys.stderr = sys.stdout = open('out.txt','w')
job = Popen('pythonw.exe -u proc1.py',stdout=PIPE,stderr=PIPE)
print 'pid',job.pid
out,err=job.communicate()
print 'out', out
print 'err', err
#end of proc0.py

C:\Tmp>cat proc1.py
#proc1.py
import sys, os
print 'sys.executable', sys.executable
print 'sys.argv', sys.argv
print 'stdout IN THE CHILD', os.getpid()
print >>sys.stderr, 'stderr IN THE CHILD', os.getpid()
#end of proc1

C:\Tmp>python proc0.py

C:\Tmp>cat out.txt
pid 1156
out sys.executable c:\python\pythonw.exe
sys.argv ['proc1.py']
stdout IN THE CHILD 1156

err stderr IN THE CHILD 1156


C:\Tmp>pythonw proc0.py

C:\Tmp>cat out.txt
Traceback (most recent call last):
   File "proc0.py", line 5, in ?
 job = Popen('pythonw.exe -u proc1.py',stdout=PIPE,stderr=PIPE)
   File "c:\python\lib\subprocess.py", line 549, in __init__
 (p2cread, p2cwrite,
   File "c:\python\lib\subprocess.py", line 609, in _get_handles
 p2cread = self._make_inheritable(p2cread)
   File "c:\python\lib\subprocess.py", line 650, in _make_inheritable
 DUPLICATE_SAME_ACCESS)
WindowsError: [Errno 6] The handle is invalid

C:\Tmp>
-- 
Robin Becker
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: idiom for constructor?

2005-06-01 Thread Chris Green
"Mac" <[EMAIL PROTECTED]> writes:

> Is there a nice Python idiom for constructors which would expedite the
> following?
>
> class Foo:
>   def __init__(self, a,b,c,d,...):
> self.a = a
> ...

You could try:

class Foo:
   def __init__(self,a,b,c,d):
   args = locals()
   for arg in args.keys():
   if name!='self':
  self.__dict__[arg] = args[arg]

I don't think it saves you a whole lot of typing (and gains you a lot
of ugly complexity).  I find as soon as I do this, I then want to
manipulate a,b,c,d .

You might look to see if you can customize your editor to use
templates/interaction and then inserts the right text for you.
-- 
Chris Green <[EMAIL PROTECTED]>
"Yeah, but you're taking the universe out of context."
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: metaclass that inherits a class of that metaclass?

2005-06-01 Thread infidel
Ok, forget everything I've said.  The more I think about this the less
I understand it.  I'm way out of my league here.

sitting-down-and-shutting-up-ly y'rs,

infi

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


Re: Pressing A Webpage Button

2005-06-01 Thread Steve M
Do you actually need to 'press' the button? Or do you just need the
effect that pressing the button would bring about (e.g., submitting a
Google search query and receiving the results page)?

If the latter, then you might want to search for, e.g., "html form get
post" and check out some results. Pushing the button is often just
loading a URL with parameters.

For example, go to Google and type "html form get post" into the search
box and press Submit. Now look at the URL you are visiting in your
location bar, the URL of the search results. It will be something like:

http://www.google.com/search?hl=en&q=html+form+get+post&btnG=Google+Search

If you were to load that URL directly (without having gone to the
Google homepage, typed "html form get post" in the text entry box and
pressed submit) the exact same effect would happen. Filling in the box
and clicking the submit button is just the user-friendly way of
constructing that URL.

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


Re: using builtin array

2005-06-01 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:
> Is it possible to join/append 2 arrays defined with different
> typecodes?
> 
> What typecode should i use to generate the following output.
> 
> data1 = array('h', '\0', 6)
> data2 = array('L', '\0', 25)
> 
> for i in range( 6):
> data1[0] = 0xFF
> data2[1] = 0x00
> data1[2] = 0x00
> data1[3] = 0x00
> data1[4] = 0x00
> data1[5] = 0x00
> 
> for i in range( 2):
> data2[0] = 0xF0F0F0F0
> data2[1] = 0x
> 
> Output should be...
> (0xFF 0x00 0x00 0x00 0x00 0x00 0xF0F0F0F0 0x)


An arry has one typecode that applies to all its elements - so what you 
want can't be done.

But you can use two lists and the module struct to create a string that 
resembles the memory layout you want.


data1 = [0] * 6
data2 = [0L] * 25

struct.pack("b" * len(data1) + "l" * len(25), *(data1 + data2))

But I think you should give us more information on what you actually 
want to accomplish, as I've got the impression that you try to force 
things in awy that is not optimal.

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


Re: Python as client-side browser script language

2005-06-01 Thread Paul Rubin
Magnus Lycka <[EMAIL PROTECTED]> writes:
> Of course, one might suggest that it's the task of the browser,
> and not of the scripting language, to provide a safe sandbox
> where scripts can mess around and without causing havoc on
> your computer. Such a system in the browser could be used to
> grant different rights to different parts of the net, regardless
> of what kind of scripting language the resources on those parts
> of the net use. When Firefox has something like that, it's time
> to start marketing Python for client side scripting I think.

Huh?  The language itself has to provide the sandbox.  If the
browser's control over the script language is so fine-grained as to
control every attribute access then the browser and the language are
no longer separate.  Remember that scripts have to be able to see
certain DOM elements but not others, and some of them have to be
read-only, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Elementtree and CDATA handling

2005-06-01 Thread and-google
Alain <[EMAIL PROTECTED]> wrote:

> I would expect a piece of XML to be read, parsed and written back
> without corruption [...]. It isn't however the case when it comes
> to CDATA handling.

This is not corruption, exactly. For most intents and purposes, CDATA
sections should behave identically to normal character data. In a real
XML-based browser (such as Mozilla in application/xhtml+xml mode), this
line of script would actually work fine:

> if (a < b && a > 0) {

The problem is you're (presumably) producing output that you want to be
understood by things that are not XML parsers, namely legacy-HTML web
browsers, which have special exceptions-to-the-rule like "

creating a hex value

2005-06-01 Thread David Bear
I have a file that I need to parse. Items in it are delimited by a hex 15
(0x015). I know it must be trivial to assign a hex value to a variable but
I'm not seeing it in my python essential ref. how can I do

delim = 0x15
while:
ln = file.read()
if ln[0] == delim:
do something

I've looked at the hex function but it doesn't sound like what I want.

-- 
David Bear
-- let me buy your intellectual property, I want to own your thoughts --
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BUG pythonw vs subprocess

2005-06-01 Thread Paul Rubin
I thought pythonw didn't provide a console and so it could be that
stdin and stdout aren't connected to anything.  Popen therefore doesn't
make sense.  You have to use sockets or something.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >