ANN: SCSIPYTHON added to Sourceforge

2006-03-23 Thread sam
I have updated and moved my SCSI diagnostic tools from starship to
sourceforge. I will be still maintaining these files at both locations
as long as starship exists. These tools allow low level tests to be
conducted on storage devices under the Windows operating system. These
routines access all storage devices through the Windows SCSIPASSTHROUGH
layer, which maps all storage devices (SCSI,IDE/ATA,USB,PCMCIA,DVD,CD)
to look like a SCSI device that is accessed using SCSI command
descripter blocks.
The move to Sourceforge also places the sourcecode,and files under CVS
control.


Starship link:
http://starship.python.net/crew/samschul

Sourceforge link:
https://sourceforge.net/projects/scsipython

Sam Schulenburg

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

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: Using PyExcelerator

2006-03-23 Thread rbsharp
I would agree with the author, pyExcelerator is good at writing Excel
but xlrd is better at reading. I was recently forced to use them in
tandem because pyExcelerator had problems reading an Excel sheet and
xlrd had no problems.

greetings,

Richard Sharp

John Machin wrote:
 On 23/03/2006 9:01 AM, [EMAIL PROTECTED] wrote:
  I have just installed PyExcelerator, and now want to use it to read
  Excel spreadsheets with a variable number of rows and columns and with
  multiple sheets. Unfortunately, no documentation seems to accompany
  PyExcelerator. Does anyone know of a good source of documentations
  and/or examples? The author provides some examples, but these tend to
  involve writing data into spreadsheets one cell at a time.
 

 Thomas,
 Look at pyExcelerator's tools/xls2*.py for examples
 or
 Look at the xlrd package (which doesn't *write* xls files, but does read
 them tolerably well -- even if I do say so myself -- and has documentation).
 http://cheeseshop.python.org/pypi/xlrd

 What do you mean by with a variable number of rows and columns?
 
 Cheers,
 John

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


Re: import random module

2006-03-23 Thread Just
In article [EMAIL PROTECTED],
 Carl Banks [EMAIL PROTECTED] wrote:

 Ben Finney wrote:
  DataSmash [EMAIL PROTECTED] writes:
   * random.py:
  
   import random
 
  Now that you've tripped over this ambiguity of Python's current
  'import' behaviour, you may be interested to know that the behaviour
  will change to solve this:
 
  URL:http://www.python.org/dev/peps/pep-0328/
 
 I don't believe this change will solve the problem at hand, at least
 there's nothing in the PEP that says it will.  import random is an
 absolute import even in random.py is in the current directory, because
 current directory is in sys.path.  Unless there's a change sys.path
 planned, the shadowing should still happen.

Correct. See also http://python.org/sf/946373 for more explanations and 
also more of the same confusion.

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


where is os.path.expanduser?

2006-03-23 Thread Kevin F
where is this code looking for the .imap file?  I am on OSX and am not 
sure where to put the file it is looking for.

f = open(os.path.expanduser('~/.imap'))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: don't understand popen2

2006-03-23 Thread Martin P. Hellwig
Donn Cave wrote:
cut
 
 Anyway, it seems unlikely he would get that INVARG error for this
 reason.  That's an error from the host operating system, not the
 interpreter, and it mostly likely refers to the file descriptor.
 Since it works for me, I guess his problem is basically this:
 
 | (python 2.4 + win32 extensions on XPProSP2)
 
   Donn Cave, [EMAIL PROTECTED]

Thank you for your suggestion.

I shuffled it a bit around and executed it on my BSD box and there 
indeed it works, if I use that exactly program (well not the path var of 
course) on NT it has no error but it still not gives the expected 
results. So I guess that pipes,std-in, std-out  std-err work that 
different on NT then on other POSIX systems.

The lucky thing is that the code where I am exercising for must run on a 
BSD system so my immediately problem is dealt with, but I'm still 
curious how to get this working on NT.

I posted my new code and the results under my sep.

-- 
mph

popen_test.py
#! /usr/local/bin/python
import popen2

std_out, std_in = popen2.popen2(F:\coding\pwSync\popen_test\testia.py)
std_in.writelines(test\n)
std_in.flush()
std_in.close()
x=std_out.readlines()
print(x)
-

testia.py
#! /usr/local/bin/python
someline = raw_input(something:)

if someline == 'test':
 print(yup)
else:
 print(nope)
-


results on NT:
F:\coding\pwSync\popen_testpopen_test.py
[]


results on BSD:
%./popen_test.py
['something:yup\n']
%
-- 
http://mail.python.org/mailman/listinfo/python-list


os.path.expanduser ... where is this?

2006-03-23 Thread Kevin F
I have a code that opens an .imap file in os.path.expanduser.

Unfortunately, I am on OS X and have no idea where that directory is.

I am wondering how I can change this code to just open the .imap file in 
the directory where the code is saved.

f = open(os.path.expanduser('~/.imap'))


p.s. anyone know where os.path.expanduser opens up on OSX?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Server.sendmail with no to_addrs parameter.

2006-03-23 Thread Tim Roberts
EdWhyatt [EMAIL PROTECTED] wrote:

Ok, totally unrelated, and on that subject, I will make sure I always
have a recipient in the To: field. - hey it works if I do that anyway!

OK, I'm a bit concerned that the answer to the original question has been
lost.  The difference between the SMTP envelope and the message content is
an important one, and that's the key point here.  If this is obvious to
everyone involved, I apologize.

The actual content of an e-mail message, including the message headers, has
absolute nothing to do with the delivery of the message.  That's all just a
convention that we have developed to allow messages to be read by humans.
All of the To:, Cc:, and Bcc: headers are there for you, the human (well,
and your helper, the e-mail reader).  SMTP doesn't care one whit about
them.

The smtplib.sendmail method has three parameters: sender, recipient list,
and content.  SMTP could not care less about the content.  You can skip ALL
of the headers (as long as you leave a blank line), and it will be
delivered just fine.  It won't be RFC 822 compliant, but SMTP doesn't care.
SMTP is RFC 821.  Your message will get delivered, although the recipients
e-mail reader might croak on it.

SMTP cares about the sender and the recipient list.  Going off the deep
end, consider this Python snippet:

   msg = \
To: [EMAIL PROTECTED]
Subject: This is the RFC-822 part

Hello, mom!

   s = smtplib.SMTP('localhost')
   s.sendmail( [EMAIL PROTECTED], [[EMAIL PROTECTED],[EMAIL PROTECTED]], 
msg )

Note that the To: address is not listed in the sendmail parameters.  Now,
here is a simulated SMTP script for this message:

MAIL FROM: [EMAIL PROTECTED]
RCPT TO: [EMAIL PROTECTED]
RCPT TO: [EMAIL PROTECTED]
DATA
To: [EMAIL PROTECTED]
Subject: This is the RFC-822 part

Hello, mom!
.

Those first four commands are SMTP, generated from the first two parameters
to sendmail, and those are the ONLY things that determine where this
message will be delivered.  The are called the envelope.  Note that the
actual recipients' names do not appear in the message body AT ALL.  At the
other end, Mr. One at Foo, Inc., might be surprised to receive a message
that does not appear to have been addressed to him, but SMTP doesn't care.

So, the way a BCC works is that the address goes into the envelope (in the
to_addrs list), but not in the message body.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where is os.path.expanduser?

2006-03-23 Thread Peter Otten
Kevin F wrote:

 where is this code looking for the .imap file?  I am on OSX and am not
 sure where to put the file it is looking for.
 
 f = open(os.path.expanduser('~/.imap'))

Your interactive interpreter has the answer

 import os
 os.path.expanduser(~)
'/home/peter'

that will most likely differ from the one given above.

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


Re: Can't get the real contents form page in internet as the tag no-chche

2006-03-23 Thread Tim Roberts
dongdong [EMAIL PROTECTED] wrote:

using web browser can get page's content formally, but when use
urllib2.open(http://tech.163.com/2004w11/12732/2004w11_1100059465339.html;).read()

the result is

htmlheadMETA HTTP-EQUIV=REFRESH
CONTENT=0;URL=http://tech.163.com/04/1110/12/14QUR2BR0009159H.html;
META http-equiv=Pragma
content=no-cache/HEADbody?y?ú'ò?aò3??.../body/html

,I think the reson is the no-cache, are there person would help me?

No, that's not the reason.  The reason is that this includes a redirect.

As an HTML consumer, you are supposed to parse that content and notice the
meta http-equiv tag, which says here is something that should have been
one of the HTTP headers.

In this case, it wants you to act as though you saw:
Refresh: 0;URL=http://tech.163.com/04/1110/12/14QUR2BR0009159H.html
Pragma: no-cache

In this case, the Refresh header means that you are supposed to go fetch
the contents of that new page immediately.  Try using urllib2.open on THAT
address, and you should get your content.

This is one way to handle a web site reorganization and still allow older
URLs to work.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: where is os.path.expanduser?

2006-03-23 Thread Kevin F
Peter Otten wrote:
 Kevin F wrote:
 
 where is this code looking for the .imap file?  I am on OSX and am not
 sure where to put the file it is looking for.

 f = open(os.path.expanduser('~/.imap'))
 
 Your interactive interpreter has the answer
 
 import os
 os.path.expanduser(~)
 '/home/peter'
 
 that will most likely differ from the one given above.
 
 Peter
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Michael Spencer wrote:
 Bruno Desthuilliers wrote:
 
(snip)
 
 BTW, there may be other use case for per-instance descriptors... 
 
 
 Agreed.  Per-instance descriptors could be interesting (that's why the
 subject line caught my attention).
 But your solution involves a custom __getattribute__ in the class, which
 I would always avoid if possible (and I gather you're uneasy about it too).

I'm not uneasy about overriding __getattribute__, just about overriding
it that way -

 Here, I don't see why that's better than having a descriptor in the
 class and, if it needs per-instance behavior, then make it dependent on
 something provided by the instance.

Each instance will need it's own set of descriptors. The class is used
as a decorator for many controller functions. The descriptors are used
to encapsulate some gory implementation details about how to get such or
such object from the framework (they of course depend on instance
specific data, but that's not the point).

 e.g.,
 class DummyDescriptor1(object):
   def __get__(self, obj, objtype=None):
 if isinstance(obj, objtype):
 return obj.foo.__get__(obj)
 else:
 return self
 
 class MyClass4(object):
   baaz = DummyDescriptor1()
   def __init__(self, foo, bar = None):
 self.foo = foo
 self.bar = bar

This would imply a decorator subclass and a descriptor subclass for each
and every controller function - which is what I'm trying to avoid.

(snip)

-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


IMAP mailwatcher w/Tkinter

2006-03-23 Thread Kevin F
I've been trying to implement this script, it polls an IMAP inbox for 
unread messages and displays the sender and subject in a scrollable 
window using Tkinter.  However, when I try to change the search 
parameters on line 55 from 'unread' (UNSEEN) to 'read' (SEEN), the 
tkinter window doesn't even pop up anymore.

Any idea how to change the parameters of this program and yet still keep 
it functional?







my code: (if you can't see line 55, search for 'UNSEEN')




#!/usr/bin/env python
import imaplib, string, sys, os, re, rfc822
from Tkinter import *

PollInterval = 60 # seconds

def getimapaccount():
 try:
 f = open(('info.imap'))
 except IOError, e:
 print 'Unable to open ~/.imap: ', e
 sys.exit(1)
 global imap_server, imap_user, imap_password
 try:
 imap_server, imap_user, imap_password = string.split(f.readline())
 except ValueError:
 print 'Invalid data in ~/.imap'
 sys.exit(1)
 f.close()

class msg: # a file-like object for passing a string to rfc822.Message
 def __init__(self, text):
self.lines = string.split(text, '\015\012')
self.lines.reverse()
 def readline(self):
try: return self.lines.pop() + '\n'
except: return ''

class Mailwatcher(Frame):
 def __init__(self, master=None):
 Frame.__init__(self, master)
 self.pack(side=TOP, expand=YES, fill=BOTH)
 self.scroll = Scrollbar(self)
 self.list = Listbox(self, font='7x13',
 yscrollcommand=self.scroll.set,
 setgrid=1, height=6, width=80)
 self.scroll.configure(command=self.list.yview)
 self.scroll.pack(side=LEFT, fill=BOTH)
 self.list.pack(side=LEFT, expand=YES, fill=BOTH)

 def getmail(self):
self.after(1000*PollInterval, self.getmail)
 self.list.delete(0,END)
try:
M = imaplib.IMAP4(imap_server)
M.login(imap_user, imap_password)
except Exception, e:
self.list.insert(END, 'IMAP login error: ', e)
return

try:
result, message = M.select(readonly=1)
if result != 'OK':
raise Exception, message
typ, data = M.search(None, '(UNSEEN)')
for num in string.split(data[0]):
try:
f = M.fetch(num, '(BODY[HEADER.FIELDS (SUBJECT FROM)])')
m = rfc822.Message(msg(f[1][0][1]), 0)
subject = m['subject']
except KeyError:
f = M.fetch(num, '(BODY[HEADER.FIELDS (FROM)])')
m = rfc822.Message(msg(f[1][0][1]), 0)
subject = '(no subject)'
fromaddr = m.getaddr('from')
if fromaddr[0] == : n = fromaddr[1]
else: n = fromaddr[0]
text = '%-20.20s  %s' % (n, subject)
self.list.insert(END, text)
len = self.list.size()
if len  0: self.list.see(len-1)
except Exception, e:
self.list.delete(0,END)
print sys.exc_info()
self.list.insert(END, 'IMAP read error: ', e)
M.logout()


getimapaccount()
root = Tk(className='mailwatcher')
root.title('mailwatcher')
mw = Mailwatcher(root)
mw.getmail()
mw.mainloop()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Use of Python with GDAL. How to speed up ?

2006-03-23 Thread Julien Fiore
Thank you Serge for this generous reply,

Vectorized code seems a great choice to compute the distance. If I
understand well, vectorized code can only work when you don't need to
access the values of the array, but only need to know the indices. This
works well for the distance, but I need to access the array values in
the openness function.

As regards array.array, it seems a bit complicated to reduce all my 2D
arrays to 1D arrays because I am working with the gdal library, which
works only with 'numeric' arrays.

Julien

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


Re: Per instance descriptors ?

2006-03-23 Thread bruno at modulix
Steven Bethard wrote:
 bruno at modulix wrote:
 
 Hi

 I'm currently playing with some (possibly weird...) code, and I'd have a
 use for per-instance descriptors, 
(snip)


 class MyClass2(MyClass1):
 def __getattribute__(self, key):
 v = MyClass1.__getattribute__(self, key)
 if hasattr(v, '__get__'):
 return v.__get__(self, self.__class__)
 return v

 And it *seems* to work just fine:

 mc2 = MyClass2(bar='foo')
 mc2.baaz
 -  'foo'

 Now the question: is there any obvious (or non-obvious) drawback with
 this approach ?
 
 
 Don't know if this matters, but if you override __getattribute__, you'll
 slow down all attribute accesses to this object.

Yes, I know, but this shouldn't be a major annoyance here.

  If this matters, you
 could write something like:
 
 class MyClass(object):
 def __init__(self, bar=None):
 if bar is not None:
 self.bar = bar
 def __getattr__(self, name):
 if name == 'baaz':
 return self.bar
 elif name == 'bar':
 return 'no bar'

Don't focus on the dummy example I gave - the real descriptors are doing
something a bit less stupid !-)

 Could you explain again why you don't want baaz to be a class-level
 attribute?

Because the class is a decorator for many controller functions, and each
controller function will need it's own set of descriptors, so I don't
want to mess with the class.

Think of the decorator as a prototype, each controller function
customizing it according to it's need  - this customisation including
the decorator instance attaching descriptors and methods to itself
according to parameters passed at __init__ time. The decorator instance
also passes itself as first arg to the controller function - which then
practically become an instance method too.

Don't tell me, I know this is a somewhat weird architecture, and it
could mostly be done with more conventional subclassing. BTW, this was
how a first implementation worked, and it required almost twice more
code than the new one I'm experimenting, without being half as flexible.

As I said, it's mostly syntactic sugar, but what, I'm lazy enough to
spend time on writing code that will allow me to write less code in the
end !-)


-- 
bruno desthuilliers
python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in '[EMAIL PROTECTED]'.split('@')])
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __slots__

2006-03-23 Thread Ziga Seilnacht
David Isaac wrote:
 1. Without a __dict__ variable,
 instances cannot be assigned new variables not listed in the __slots__
 definition.

 So this seemed an interesting restriction to impose in some instances,
 but I've noticed that this behavior is being called by some a side effect
 the reliance on which is considered unPythonic.  Why?

If you want to restrict  attribute asignment, you should use the
__setattr__ special method, see:
http://docs.python.org/ref/attribute-access.html

 2. What is a simple example where use of slots has caused subtle problems,
 as some claim it will?

The first point is true only if all bases use __slots__:

 class A(object):
... pass
...
 class B(A):
... __slots__ = ('spam',)
...
 b = B()
 b.eggs = 1
 b.eggs
1

 3. What is a simple example of a Pythonic use of __slots__ that does NOT
 involved the creation of **many** instances.

 Thanks,
 Alan Isaac

Ziga

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


Integrating python with smalltalk

2006-03-23 Thread nelson
Hi all,
  sorry if it isn't the right group (and sorry for the cross post, but
it's a cross- question :P ), but i'm not sure where to post. I have a
python library and i want to be able to call it from smalltalk (the
squeak implementation in particular..). I was just wondering if there
is a standard mechanism to do it. On windows i know i can create in
python a COM server and call it from smalltalk, but i wonder if there
is a more general solution (platform independent).

thanks for any advice,
  nelson

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


Probelem about image size and dimensions

2006-03-23 Thread gongcheng_g
I got a piece of python script to upload file and it can upload it to
different folders on server depend on the type of file is image or not.
but I also want to restrict the size and dimensions of file if it is a
image file.Could anyone help me out?


Parameter List:id, file, title='',folder

REQUEST=context.REQUEST
content_type=file.headers['Content-Type']
if content_type.find('image')!=-1: #.find() is a method in Python2.0


destination=context.restrictedTraverse('/cheng/rvdpas/uploadImage/'+folder)
destination.manage_addImage(id, file, title)\


else:

destination=context.restrictedTraverse('/cheng/rvdpas/uploadDocument/'+folder)
destination.manage_addFile(id, file, title)


return 'Finished'

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


Strange metaclass behaviour

2006-03-23 Thread Christian Eder
Hi,

I think I have discovered a problem in context of
metaclasses and multiple inheritance in python 2.4,
which I could finally reduce to a simple example:

Look at following code:

class M_A (type) :

 def __new__ (meta, name, bases, dict) :
print M.__new__, meta, name, bases
return super (M_A, meta).__new__ (meta, name, bases, dict)

class M_B (M_A) : pass

class A (object) : __metaclass__ = M_A

class B (object) : __metaclass__ = M_B

class D (A, B) : pass


One would expect that either
1) D inherits the metaclass M_A from A
2) or python raises the well known Metatype conflict among bases
error

Instead, if you run this code, you get the following output:

M.__new__ class '__main__.M_A' A (type 'object',)
M.__new__ class '__main__.M_B' B (type 'object',)
M.__new__ class '__main__.M_A' D (class '__main__.A', class
'__main__.B')
M.__new__ class '__main__.M_B' D (class '__main__.A', class
'__main__.B')

This means that when class D gets defined, the __new__ from M_A
get executed twice (first from M_A, then from M_B), which should not happen.
This suggests that either
1) cooperative supercalls do not work here
2) the metaclass of EACH of the bases of D does it's work independently
when D is defined.

Does anyone have a detailed explanation here ?
Is this problem already known ?

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


Re: Probelem about image size and dimensions

2006-03-23 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote:

 I got a piece of python script to upload file and it can upload it to
 different folders on server depend on the type of file is image or not.
 but I also want to restrict the size and dimensions of file if it is a
 image file.Could anyone help me out?


Use PIL, the python imaging library. Load your image, check its sizes and
proceed accordingly.

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-23 Thread [EMAIL PROTECTED]
Hello,

The solution that would have the most utility would be one where the
elements are generated one-by-one, loop-like, so that they can be used
in the body of a loop, and to avoid the fact that even with exclusion
the cardinality of the target set EX^n could be in the millions even
with a full list of wc's, that is, a list containing at least one wc of
every length in 2..(n-1). I don't know enough Lisp, Haskell or
Qi/Prolog to know if the solutions so far can be modified to do this.
The Python program is too slow for large sets.

Walter Kehowski

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


Re: Linear regression in NumPy

2006-03-23 Thread nikie
Although I think it's worth reading, it only covers the fundamental
structure (what arrays are, what ufuncs are..) of NumPy. Neither of the
functions dicussed in this thread (polyfit/linear_least_squares) is
mentioned in the file.

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-23 Thread Dinko Tenev
Dirk Thierbach wrote:
 If more time during preprocessing is allowed, another idea is to
 treat the wildcard expressions as regular expressions, convert
 each into a finite state machine, construct the intersection of
 all these state machines, minimize it and then swap final and non-final
 states.

Given the requirements, did you mean taking the *union* and swapping
states?  Or maybe swapping states first, and then taking the
intersection?

 Then you can use the resulting automaton to efficiently
 enumerate S^n - W. In the above case, the resulting FSM would have just
 three states.

I don't see immediately how exactly this is going to work.  Unless I'm
very much mistaken, a FSA in the classical sense will accept or reject
only after the whole sequence has been consumed, and this spells
exponential times.  For improved asymptotic complexity in this case,
you need to be able to at least reject in mid-sequence, and that calls
for a slightly different concept of a FSA -- is this what you meant?

Cheers,

Dinko

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


Re: Can't get the real contents form page in internet as the tag no-chche

2006-03-23 Thread Diez B. Roggisch
dongdong wrote:

 using web browser can get page's content formally, but when use

urllib2.open(http://tech.163.com/2004w11/12732/2004w11_1100059465339.html;).read()
 
 the result is
 
 htmlheadMETA HTTP-EQUIV=REFRESH
 CONTENT=0;URL=http://tech.163.com/04/1110/12/14QUR2BR0009159H.html;
 META http-equiv=Pragma
 content=no-cache/HEADbody?y?ú'ò?aò3??.../body/html
 
 ,I think the reson is the no-cache, are there person would help me?

No, the reason is the META HTTP-EQUIV=REFRESH
CONTENT=0;URL=http://tech.163.com/04/1110/12/14QUR2BR0009159H.html;

that redirects you to the real site. Extract that url from the page and
request that. Or maybe you can use webunit, which acts more like a real
http-client with interpreting such content.

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

Re: Probelem about image size and dimensions

2006-03-23 Thread ChengGong
Thank you for your reply. I have been learning python only 2 weeks.
According what u said. I tried to import Image  but there 's an error
on the server.
here is the message
Error Type: ImportError
Error Value: import of Image is unauthorized

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


Re: Good thread pool module

2006-03-23 Thread Rene Pijlman
Dennis Lee Bieber:
Raymond Hettinger:
 Because of the GIL, thread pools are not as useful in Python as you
 might expect -- they execute one at a time and do not take advantage of
 hyper-threading or multiple processors.  If that kind of efficiency is

   If the task is I/O bound (something like a web spider?), seems
they'd still be useful...

Yes, I use a thread pool for that. But async I/O may be a more efficient
solution (e.g. Twisted).

-- 
René Pijlman

Wat wil jij leren?  http://www.leren.nl
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Probelem about image size and dimensions

2006-03-23 Thread Diez B. Roggisch
ChengGong wrote:

 Thank you for your reply. I have been learning python only 2 weeks.
 According what u said. I tried to import Image  but there 's an error
 on the server.
 here is the message
 Error Type: ImportError
 Error Value: import of Image is unauthorized

Are you by chance running under ZOPE? Then you'll need a so-called
ExternalMethod for your code to import restricted modules.

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


Re: Server.sendmail with no to_addrs parameter.

2006-03-23 Thread Arne Ludwig
Sorry to have caused all that confusion. The quote from RFC822 I gave
is really confusing and is indeed not relevant to the original
question. As Tim pointed out, the to_addrs parameter in
smtplib.py::sendmail is translated to the SMTP RCPT TO and thus must
contain all the intended recipients whether they are logically To, CC,
Bcc. That parameter cannot be empty, and that is not a restriction in
Python, but a restriction of the nature of email: No recipient, no
transmission.

It is true that even with RFC 822 it was allowed to have NO To: line,
but NOT an empty To: line, while it was allowable to have an empty Bcc:
line. This was the quote I gave.

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


Re: Can't get the real contents form page in internet as the tag no-chche

2006-03-23 Thread dongdong
oh~~~! offer my  thanks to Tim Roberts  and all persons above!
 I see now, it's the different url causes!
 contents can only be got from the later (real ) url.
 I made a mistick not to look at the different urls  taking effect.

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


Re: Windows getting local ip address

2006-03-23 Thread Erno Kuusela
The traditional right way (tm) to do this is to call getsockname() on
the (a?) socket that's connected to the guy you want to tell your
address to. This picks the right address in case you have several. If
you don't have a socket handy, you can make a connectionless UDP
socket and connect() it to a suitable place - this won't result in any
packets on the wire. NAT breaks it of course, but then you couldn't
easily be contacted from outside the NAT anyway.

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


Re: Probelem about image size and dimensions

2006-03-23 Thread ChengGong
Diez,

I asked the administrator that they won't allow me to import Image and
PIL in Zope.
I am wondering that how can I get the height and width and the size of
the image in this situation?
Can I just use dtmlto get Image's addtributs?

Cheng

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


question: how to clare the absolute url in a html file

2006-03-23 Thread dongdong
is there any lib to help to clear the absolute url in a html file? for
example, 'http://www.sina.com/' should be clear ,but /image/asd.gif
should be reserved.

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


RELEASED Python 2.4.3, release candidate 1

2006-03-23 Thread Anthony Baxter
On behalf of the Python development team and the Python 
community, I'm happy to announce the release of Python 2.4.3 
(release candidate 1).

Python 2.4.3 is a bug-fix release. See the release notes at 
the website (also available as Misc/NEWS in the source 
distribution) for details of the more than 50 bugs squished 
in this release, including a number found by the Coverity 
Scan project.

Assuming no major problems crop up, a final release of 
Python 2.4.3 will follow in about a week's time.

For more information on Python 2.4.3, including download 
links for various platforms, release notes, and known issues, 
please see:

http://www.python.org/2.4.3/

Highlights of this new release include:

  - Bug fixes. According to the release notes, at least 50 
have been fixed since 2.4.2.

Highlights of the previous major Python release (2.4) are 
available from the Python 2.4 page, at

http://www.python.org/2.4/highlights.html

On a personal note, according to my records this is the 25th 
release of Python I've made as release manager.

So enjoy this silver anniversary release,
Anthony

Anthony Baxter
[EMAIL PROTECTED]
Python Release Manager
(on behalf of the entire python-dev team)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Probelem about image size and dimensions

2006-03-23 Thread Diez B. Roggisch
ChengGong wrote:

 Diez,
 
 I asked the administrator that they won't allow me to import Image and
 PIL in Zope.
 I am wondering that how can I get the height and width and the size of
 the image in this situation?
 Can I just use dtmlto get Image's addtributs?

No. At least not easily. You'd have to write the whole image-header loading
yourself. Which is certainly more than a two-week-old python coder is
capable of.

If I were you I'd pester your sysadmins to allow you to create an external
method - after all it is _their_ job to make you happy as a developer -
IMHO.

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


Re: question: how to clare the absolute url in a html file

2006-03-23 Thread Diez B. Roggisch
dongdong wrote:

 is there any lib to help to clear the absolute url in a html file? for
 example, 'http://www.sina.com/' should be clear ,but /image/asd.gif
 should be reserved.

Built-in string-manipulation is your friend:

abcdef/ghi.replace(abcdef, )


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


Re: Windows getting local ip address

2006-03-23 Thread Arne Ludwig
That man is a genius:

 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
 s.connect((gmail.com,80))
 print s.getsockname()
('192.168.0.174', 2768)
 s.close()

Should work on Windows as well.

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


Simple but fundamental: How to import a jython class?

2006-03-23 Thread aziz . hammadi
I wrote a jython class bus I can not use it in another jython script
:-(
Example:
-- X.py--
class X:
 def hello():
 print Hello


-- Y.py--
import X
x = X()
x.hello()


I get TypeError: call of non function (module 'X')
Both files are in the same directory.

Tanks!

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


Re: question: how to clare the absolute url in a html file

2006-03-23 Thread dongdong
to Diez B. Roggisch :
 no, I won't to  use this way, its efficiency is very low as I need to
replace all the 'a href=http:.//'  tags into whitespace.
I think whether there is any lib's function to do this.

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


Re: Simple but fundamental: How to import a jython class?

2006-03-23 Thread Frank Schenk
[EMAIL PROTECTED] wrote:
 I wrote a jython class bus I can not use it in another jython script
 :-(
 Example:
 -- X.py--
 class X:
  def hello():
  print Hello
 
 
 -- Y.py--
 import X
 x = X()
 x.hello()
 
 
 I get TypeError: call of non function (module 'X')
 Both files are in the same directory.

try
from X import X
or
x = X.X()


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


PIL: Breaking/Wrapping lines automatically

2006-03-23 Thread Jorge Godoy

Hi!


Is there something I can do in PIL to restrict a line to a certain size and
have it to break/wrap into a newline automatically?  (Or by using some code, of
course...)

I'm trying to add information to barcodes and since the label space is fixed
I'd like to use all the horizontal space I can and since I'm with two or three
lines of free space I'd like to use them as well.


TIA,
-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some info

2006-03-23 Thread Fulvio
Alle 22:14, mercoledì 22 marzo 2006, Sybren Stuvel ha scritto:

 different partitions might have, though. Then again, it all depends on
 the filesystems in use.
Then I should make some extra programming to catch these info, according to 
which OS will run it :-(
Regarding the names, CDROMs DVD have a label, which might be written during 
the burning process. Also partition have name, which can be written by fdisk, 
or in MS windows properties.
Just a comparison :  Imaging something like WhereIsIt (Windows) Gwhere 
(Linux), but in my opinion I'd like to give it free and less weak (as the 
before-mentioned programs).

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


Re: Remote teamwork anecdotes

2006-03-23 Thread Ed Leafe
On Mar 20, 2006, at 9:51 PM, Alex Martelli wrote:

 While what *I* want, ideally, is pair programming -- somebody sitting
 right at my side, alternating with me in controlling keyboard and  
 mouse,
 and in verbalizing what he or she is coding -- that's part of the huge
 productivity boost I observe in a co-located team... that pair
 programming works SO much better that way, that even with the best
 remote cooperation tools (subethaedit onwards).

I've often noticed that programming for me is akin to composing  
music. Now let me start by saying that while I can hum pretty well,  
I'm not a musician of any sort, so this is based upon the experiences  
related to me by others who are (btw, there seems to be a very large  
overlap between programmers and musicians...).

I can be mulling over a particular problem for hours, sometimes  
days, and do nothing but write some pseudo-code or a couple of trial  
programs that don't really do what is needed. Then, at some  
unpredictable point, clarity sets in and I see the solution. After  
that, it's just a matter of transferring that into code (for which  
Python is by far the best language, as it doesn't get in my way).

The people I know who write music tell me of a similar process: they  
play a few bars or write a few words, but it doesn't feel quite  
right. Then either a particular musical hook comes to mind, or a set  
of words that solidifies the image of what they were feeling, and  
after that the song is written in their head and just needs to be  
transferred to tape (or bits, as is more common these days).

I can't wake up one day and plan my day like this: 9-12, write some  
killer algorithm; 12-1, run errands and eat lunch; 1-3, add algorithm  
to existing code and refactor; etc. Nor can the musicians I know plan  
of writing the first stanza of a song in the morning, the second  
after lunch, and the chorus in the evening.

The other similarity is that some musicians tend to be more creative  
when off by themselves, while the rest seem to feed off of jamming  
together with others. Most of them strongly prefer one or the other;  
rarely do they employ both. The comparison to programmers would be  
that I seem to resemble the former type, while you seem to resemble  
the latter.

I strongly agree on the benefit of code review, though, especially  
in my case where things tend to get written more or less  
unconsciously. While the main problem may be addressed well, there  
are either side/end cases that still need to be addressed, or there  
is an opportunity to refactor to make it fit in much better with the  
project as a whole. A partner who is not emotionally immersed in the  
code can usually see these things better than the person who created  
the code.

 Wanna talk debugging?  I think solo debugging is even worse than solo
 programming -- when I just CAN'T have a debugging partner for a
 sufficiently nasty bug (race conditions are the worst, but there are
 many other categories vying for that title;-), I'll turn to one of my
 beloved plushies (I'm firmly convinced the baby tiger is by far the  
 most
 effective debugging partner for most bugs, though Tux the Penguin  
 has a
 knack for helping spot bugs that aren't MY fault but rather the
 compiler's c -- since I've been using Python for most of my coding  
 for
 years, poor Tux hasn't seen much action recently) -- I talk out  
 loud to
 the plushy-partner to make narratives out of expected and observed
 occurrences.  But a *LIVE* partner, actively checking out the  
 coherence
 of my narratives and challenging them and proposing alternatives,  
 is 10
 times more effective... the plushies don't even talk back (except in
 debugging sessions that have gone on for *FAR* too long;-).

OK, we part ways on the plushie thing, but here I have to agree with  
you: a second set of eyes (and brain patterns) helps immeasurably  
when debugging. I think the key here is having to explain what you  
did and what you thought the code should have done to someone else  
clarifies the problem, whether it's explaining it to someone else in  
the room, or trying to explain it in an email to a list like this. I  
can't even begin to count the number of times that I've been stuck,  
and decided to post the problem to a list for help, and in the  
process of composing the email, figured out what my mistake was!  
Those netiquette guidelines for posting intelligently aren't to help  
the readers of the post; they're to help you form your scattered  
thoughts into a coherent picture, and more often than not, if it's a  
bug that I've created rather than a gap in my understanding, the  
process of writing the email is all I need.

I guess if there's a point to all of this, it's that good  
programming is a creative process, and that you need to identify what  
works and doesn't work for you. There is no one-size-fits-all  
approach that is the best.


Building files within a package

2006-03-23 Thread schwehr
Hi All,

I am creating a python package that contains a whole pile of functions
that build lookup tables.  Since these lookup tables will not be
changing, I would like to have setup.py create a lut_static.py fie from
the lookup table code (lut.py).  What is the best way to do this so
that when I install the package the static tables get build?  It
basically looks like this

foo-py-0.1
   setup.py
   foo
  lut.py
  lut_static.py - want to generate this from lut.py

For development, it is easy enough for me to have a Makefile in foo
that creates lut_static.py when ever lut.py is changed, but I would
like to make setup.py handle this so if someone tweaks the lut.py and
reinstalls it, they don't have to know about foo/Makefile

Thanks!
-kurt

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-23 Thread Dr.Ruud
[EMAIL PROTECTED] schreef:

 The solution that would have the most utility would be one where the
 elements are generated one-by-one, loop-like, so that they can be used
 in the body of a loop, and to avoid the fact that even with exclusion
 the cardinality of the target set EX^n could be in the millions even
 with a full list of wc's, that is, a list containing at least one wc
 of every length in 2..(n-1). I don't know enough Lisp, Haskell or
 Qi/Prolog to know if the solutions so far can be modified to do this.
 The Python program is too slow for large sets.

Use a bitmapping, see also
  news:[EMAIL PROTECTED]

Detect the exclusions with a bitwise AND.

-- 
Affijn, Ruud

Gewoon is een tijger.
echo 014C8A26C5DB87DBE85A93DBF |perl -pe 'tr/0-9A-F/JunkshoP cartel,/'

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


Re: Simple but fundamental: How to import a jython class?

2006-03-23 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

I wrote a jython class bus I can not use it in another jython script
 :-(
 Example:
 -- X.py--
 class X:
 def hello():
 print Hello


 -- Y.py--
 import X
 x = X()
 x.hello()

 I get TypeError: call of non function (module 'X')
 Both files are in the same directory.

after you've done import X, the name X refers to the namespace of the
module X.py, not the class (or any other object) in that module.  to access
the class, use dot notation:

x = X.X()

/F 



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


Re: don't understand popen2

2006-03-23 Thread Sion Arrowsmith
Martin P. Hellwig [EMAIL PROTECTED] wrote:
std_out, std_in = popen2.popen2(F:\coding\pwSync\popen_test\testia.py)
 ^^
Your problem is, I suspect, nothing to do with popen2(), which is
supported by the fact that the only thing other than OS different
between this and your working BSD version is the path:
 F:\coding\pwSync\popen_test\testia.py
'F:\\coding\\pwSync\\popen_test\testia.py' 

Try:
std_out, std_in = popen2.popen2(F:/coding/pwSync/popen_test/testia.py)
or:
std_out, std_in = popen2.popen2(F:\\coding\\pwSync\\popen_test\\testia.py)
(and please avoid the abuse of raw strings for Windows paths).

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Simple but fundamental: How to import a jython class?

2006-03-23 Thread aziz . hammadi
Thanks Frank. It works :_)

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


Re: COM Client / Server creation?

2006-03-23 Thread Dan
What went wrong...
Operator Error. My appologies. If typed in correctly the example works
perfectly. I was using the PythonWin shell and when I started to type
in it suggested CDispatch and I typed that in. I will be looking to
pick up a copy of the book if I continue to use Python. I still do not
know if it will be sufficient to my purposes. It looks like a very
powerful scripting language. Dan

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


Re: Breaking/Wrapping lines automatically

2006-03-23 Thread Fredrik Lundh
Jorge Godoy wrote:
 Is there something I can do in PIL to restrict a line to a certain size and
 have it to break/wrap into a newline automatically?  (Or by using some
 code, of course...)

there's no standard function for this purpose, no.

here's a somewhat rough implementation, based on a WCK demo:

http://effbot.python-hosting.com/file/stuff/sandbox/pil/textwrap.py

a somewhat better approach would be to use collect words as long as
they fit, and write each line as a single string.

/F 



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


Re: Can XML-RPC performance be improved?

2006-03-23 Thread Sion Arrowsmith
 [EMAIL PROTECTED] wrote:
Diez Sion Arrowsmith wrote:
 I've got an established client-server application here where there
 is now a need to shovel huge amounts of data (structured as lists of
 lists) between the two, and the performance bottleneck has become
 the amount of time spent parsing XML ...
Diez CORBA. Or TCP/IP directly. I know that isn't really the answer
Diez you're looking for - but there is an overhead parsing XML, and
Diez that can't go away.
Ah, but if both ends of the pipe happen to be running Python, you can
cheat. ;-)  Run your list through marshal.dumps() before passing it to
xmlrpclib, then undo the marshalling on the other end.
 [ ... ]
If you can swing it, I'd be willing to bet you a beer your XML parsing time
will all but disappear.

I wouldn't take you up on that bet, because I'd already considered
that as a likely solution, and while I was asking here another member
of the team went away and implemented it for me. Except with cPickle
(as suggested elsewhere in the thread) -- we've got DateTime objects
in there, which marshal chokes on. Initial tests show you'd've
comfortably won your beer: 16s XML parsing down to 0.5s parsing plus
1.5s unpickling.

If you're not using xmlrpclib with some sort of C helper (like sgmlop), try
that as well.  Big difference parsing XML in C and Python.

Diez edited out the bit where I said we were using sgmlop and worried
about what it would be like if we weren't 8-)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: don't understand popen2

2006-03-23 Thread Fredrik Lundh
Sion Arrowsmith wrote:

 F:\coding\pwSync\popen_test\testia.py
 'F:\\coding\\pwSync\\popen_test\testia.py'

this might make it more obvious that something's not quite right with that
string literal:

 print F:\coding\pwSync\popen_test\testia.py
F:\coding\pwSync\popen_test estia.py

/F 



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


Re: datetime iso8601 string input

2006-03-23 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
 Why not
 
 dt = datetime.datetime(*time.strptime(s, %Y-%m-%dT%H:%M:%S)[0:6])
 
 ?

Maybe due to neglection of the 7th commandment?
Most of the other commandments can be ignored while
coding Python, but the 7th certainly applies here.

http://www.lysator.liu.se/c/ten-commandments.html

As I've written before, the ISO 8601 spec contains
many variations in date formats. Making a full ISO
8601 parser is probably possible if we ignore time
deltas, but it's hardly worth the effort. Writing
something that parses a few percent of the possible
ISO 8601 messages and calling that an ISO 8601
parser seems silly to me.

With code like Skip's above it's obvious what kind
of strings are handled. In typical applications, one
such format is enough, and this needs to be properly
specified. In a recent case I wrote the spec like
this:

The timestamp shall be an ISO 8601 combination of
UTC date and time with complete representation in
extended format, with representation of fractions
of seconds with up to six decimals preceeded by a
full stop as decimal sign.
E.g. 2005-06-20T13:42:55.2425Z

Despite my verbosity here, someone who didn't follow
the example, would still be able to write ISO 8601
strings following the requirements above that we
won't parse, since I didn't actually write that dates
should be written as year-month-day.

For a brief summary of some of the allowed variation
see http://hydracen.com/dx/iso8601.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question: how to clare the absolute url in a html file

2006-03-23 Thread Diez B. Roggisch
dongdong wrote:

 to Diez B. Roggisch :
  no, I won't to  use this way, its efficiency is very low as I need to
 replace all the 'a href=http:.//'  tags into whitespace.
 I think whether there is any lib's function to do this.

Why do you think it is slow? It repelaces _all_ occurrences, in one sweep.
What do you expect to become faster?

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


Re: Breaking/Wrapping lines automatically

2006-03-23 Thread Jorge Godoy
Fredrik Lundh [EMAIL PROTECTED] writes:

 Jorge Godoy wrote:
 Is there something I can do in PIL to restrict a line to a certain size and
 have it to break/wrap into a newline automatically?  (Or by using some
 code, of course...)

 there's no standard function for this purpose, no.

 here's a somewhat rough implementation, based on a WCK demo:

 http://effbot.python-hosting.com/file/stuff/sandbox/pil/textwrap.py

 a somewhat better approach would be to use collect words as long as
 they fit, and write each line as a single string.

Then I'd have to have some means to determine the width of the char (I'm using
a TrueType font due to my need of using Unicode text) to calculate how many
words I can put on a single line... 

I'll take a look at the page above.


Thanks!

-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Breaking/Wrapping lines automatically

2006-03-23 Thread Jorge Godoy
Jorge Godoy [EMAIL PROTECTED] writes:

 Then I'd have to have some means to determine the width of the char (I'm using
 a TrueType font due to my need of using Unicode text) to calculate how many
 words I can put on a single line... 

Hmmm...  It looks like your code does that!  Thanks!  I'll give it a try
here. 

-- 
Jorge Godoy  [EMAIL PROTECTED]

Quidquid latine dictum sit, altum sonatur.
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
-- 
http://mail.python.org/mailman/listinfo/python-list


Convert Word .doc to Acrobat .pdf files

2006-03-23 Thread kbperry
Hi all,

Background:
I need some help.  I am trying to streamline a process for one of our
technical writers.  He is using Perforce (version control system), and
is constantly changing his word documents, and then converts them to
both .pdf and Web page format (to publish to the web).  He has a
licensed copy of Adobe Acrobat Professional (7.x).

Questions:
Does Acrobat Pro, have some way to interface with it command-line (I
tried searching, but couldn't find anything)?  Is there any other good
way to script word to pdf conversion?

Note:  The word documents do contain images, and lots of stuff besides
just text.

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


Re: Probelem about image size and dimensions

2006-03-23 Thread ChengGong
Hi Diez,

They do not allow me to do what u said above.
so I do not have any idea what is supposed to do.
however i am think that if I can get the id of the image, i have chance
to modify it.
This is what i programed but it is an empty page, I but it in images
folder
dtml-var standard_html_header

h1File Library/h1

table
  tr
tha href=dtml-URL0;?sort=nameFile/a/th
tha href=dtml-URL0;?sort=dateLast Modified/a/th
   /tr

dtml-if expr=_.has_key('sort') and sort=='date'
  dtml-in expr=objectValues(['Image'])
   sort=bobobase_modification_time reverse
tr
   tda href=dtml-absolute_url;dtml-var
title_or_id/a/td
   tddtml-var bobobase_modification_time fmt=aCommontd
/tr
  /dtml-in
dtml-else
  dtml-in expr=objectValues(['Image']) sort=id
tr
   tda href=dtml-absolute_url;dtml-var
title_or_id/a/td
   tddtml-var bobobase_modification_time fmt=aCommontd
/tr
  /dtml-in
/dtml-if

/table

dtml-var standard_html_footer

is there any mistake?
How ever thank you alot Diez. Your comments and suggestion are helpful.

P.S. i am doing my internship in a commercial company:(, create
external method is not allowed in my situation

Cheng

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


Re: Server applications - avoiding sleep

2006-03-23 Thread rodmc
Hi Lev,

Sounds interesting. As I am quite new to Python an example program
would be most welcome. My email address is contained in the message.

Best,

rod

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


Re: Probelem about image size and dimensions

2006-03-23 Thread ChengGong
Is that because I can not import PIL ? then i can not use codes above
to show all image id?

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


Re: Strange metaclass behaviour

2006-03-23 Thread Ziga Seilnacht
Christian Eder wrote:
 Hi,

 I think I have discovered a problem in context of
 metaclasses and multiple inheritance in python 2.4,
 which I could finally reduce to a simple example:

I don't know if this is a bug; but I will try to expain
what is happening; here is an example similar to yours:

 class M_A(type):
... def __new__(meta, name, bases, dict):
... print 'metaclass:', meta.__name__, 'class:', name
... return super(M_A, meta).__new__(meta, name, bases, dict)
...
 class M_B(M_A):
... pass
...
 class A(object):
... __metaclass__ = M_A
...
metaclass: M_A class: A
 class B(object):
... __metaclass__ = M_B
...
metaclass: M_B class: B

So far everything is as expected.

 class C(A, B):
... __metaclass__ = M_B
...
metaclass: M_B class: C

If we explicitly declare that our derived class inherits
from the second base, which has a more derived metaclass,
everything is OK.

 class D(A, B):
... pass
...
metaclass: M_A class: D
metaclass: M_B class: D

Now this is where it gets interesting; what happens
is the following:
 - Since D does not have a __metaclass__ attribute,
   its type is determined from its bases.
 - Since A is the first base, its type (M_A) is called;
   unfortunately this is not the way metaclasses are
   supposed to work; the most derived metaclass should
   be selected.
 - M_A's __new__ method calls the __new__ method of the
   next class in MRO; that is, super(M_1, meta).__new__
   is equal to type.__new__.
 - In type.__new__, it is determined that M_A is not
   the best type for D class; it should be actually M_B.
 - Since type.__new__ was called with wrong metaclass
   as the first argument, call the correct metaclass.
 - This calls M_B.__new__, which again calls type.__new__,
   but this time with M_B as the first argument, which
   is correct.

As I said, I don't know if this is a bug or not,
but you can achieve what is expected if you do the
following in your __new__ method (warning, untested code):

 from types import ClassType
 class AnyMeta(type):
... 
... Metaclass that follows type's behaviour in metaclass
resolution.
...
... Code is taken from Objects/typeobject.c and translated to
Python.
... 
... def __new__(meta, name, bases, dict):
... winner = meta
... for cls in bases:
... candidate = type(cls)
... if candidate is ClassType:
... continue
... if issubclass(winner, candidate):
... continue
... if issubclass(candidate, winner):
... winner = candidate
... continue
... raise TypeError(metaclass conflict: ...)
... if winner is not meta and winner.__new__ !=
AnyMeta.__new__:
... return winner.__new__(winner, name, bases, dict)
... # Do what you actually meant from here on
... print 'metaclass:', winner.__name__, 'class:', name
... return super(AnyMeta, winner).__new__(winner, name, bases,
dict)
...
 class OtherMeta(AnyMeta):
... pass
...
 class A(object):
... __metaclass__ = AnyMeta
...
metaclass: AnyMeta class: A
 class B(object):
... __metaclass__ = OtherMeta
...
metaclass: OtherMeta class: B
 class C(A, B):
... pass
...
metaclass: OtherMeta class: C

 Does anyone have a detailed explanation here ?
 Is this problem already known ?
 
 regards
 chris

I hope that above explanation helps.

Ziga

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


Re: Default/editable string to raw_input

2006-03-23 Thread Sion Arrowsmith
Sybren Stuvel  [EMAIL PROTECTED] wrote:
Paraic Gallagher enlightened us with:
 While I agree in principal to your opinion, the idea is that an
 absolute moron would be able to configure a testcell with smallest
 amount of effort possible.
Then explain to me why learning how to use your program to edit the
file is easier than using an already familiar program.

You're assuming that the tester is already familiar with a text
editor. And then they would have to learn the syntax of the
configuration file, and the parameters available. A point-and-
drool interface requires no such learning.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Can XML-RPC performance be improved?

2006-03-23 Thread Sion Arrowsmith
 [EMAIL PROTECTED] wrote:
Steve I suppose there *was* a good reason for using XML-RPC in the
Steve first place?
I don't know about the OP, but in my case it was a drop-dead simple
cross-language RPC protocol.

I am the OP and *I* don't know if there was a good reason for using
XML-RPC in the first place. It's someone else's code, and they're
no longer with the company. I can see it being justifiable at the
time: (a) single developer writing both server and client doesn't
need to think about the implemention of their communication (b) in
the future there may be other clients in other languages (as above)
and (c) up until recently, the volume of data being passed back and
forth wasn't high enough for XML parsing performance to be of much
significance. I've known XML parsing makes XML-RPC suck since, er,
before XML-RPC was invented. (At about the same time that SOAP was
being developed, we developed a prototype component system using
XML for message passing, then threw it away when it was clear that
the XML parsing was a major bottleneck.)

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  Frankly I have no feelings towards penguins one way or the other
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Help: why python odbc module can not fetch all over?

2006-03-23 Thread zxo102
Hi Dennis,

Thanks for your effort. I really appreciate it.  It works for me
now.

Ouyang

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


python/py2exe running in background

2006-03-23 Thread Astan Chee
Hi,
Im using py2exe to convert my python scripts to .exe. Im trying to get 
my scripts and .exes to only run (utilize full CPU) when my PC is idle 
(kinda like [EMAIL PROTECTED]).
Do i only need to modify GIL parameters or is there more to acomplishing 
this?
Thanks

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


definition of sub-functions in the hotshot profiler

2006-03-23 Thread Lars Woetmann
what is the definition of sub-functions in the hotshot profiler? and just
as important what is not sub-functions

from the output I can see that functions I made and functions in
/usr/lib/python2.4/textwrap.py is considered sub-functions, but I call a
lot of other functions in the python library and they are not in the
output, so how come textwrap is?


--code

import hotshot, hotshot.stats
prof = hotshot.Profile(openAnswerWindow.prof)
prof.runcall(self.openAnswerWindow)
prof.close()
stats = hotshot.stats.load(openAnswerWindow.prof)
stats.sort_stats('time', 'calls')
stats.print_stats()

--output

 195 function calls in 0.005 CPU seconds

   Ordered by: internal time, call count

ncalls tottime percall  cumtime  percall filename:lineno(function)
 1 0.0010.0010.0050.005 
/home/lars/skole/scriptsprog/rapport/code/m/kw/KeywordWindow.py:399(openAnswerWindow)
18 0.0010.0000.0020.000 m/kw/AnswerWindow.py:22(setText)
 9 0.0010.0000.0010.000 
include/FancyListViewItem.py:7(__init__) 
 1 0.0000.0000.0030.003 m/kw/AnswerWindow.py:53(setQuestionItem)
18 0.0000.0000.0010.000 
/usr/lib/python2.4/textwrap.py:292(wrap) 
18 0.0000.0000.0000.000 /usr/lib/python2.4/textwrap.py:265(wrap)
 9 0.0000.0000.0010.000 m/kw/AnswerWindow.py:11(__init__)
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:94(__init__)
 9 0.0000.0000.0010.000 
/home/lars/skole/scriptsprog/rapport/code/include/IntColumnListViewItem.py:7(__init__)
36 0.0000.0000.0000.000 m/kw/AnswerWindow.py:29(text)
 1 0.0000.0000.0000.000 
/home/lars/skole/scriptsprog/rapport/code/m/kw/QuestionSetModel.py:378(getAllAnswers)
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:131(_split) 
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:114(_munge_whitespace) 
18 0.0000.0000.0000.000 
/usr/lib/python2.4/textwrap.py:192(_wrap_chunks)
 2 0.0000.0000.0000.000 m/kw/AnswerWindow.py:48(setTitle) 
 1 0.0000.0000.0000.000 m/kw/AnswerWindow.py:71(clearAll) 
 0 0.000 0.000  profile:0(profiler)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange metaclass behaviour

2006-03-23 Thread Michele Simionato
Ziga Seilnacht wrote:
  - Since D does not have a __metaclass__ attribute,
its type is determined from its bases.
  - Since A is the first base, its type (M_A) is called;
unfortunately this is not the way metaclasses are
supposed to work; the most derived metaclass should
be selected.
  - M_A's __new__ method calls the __new__ method of the
next class in MRO; that is, super(M_1, meta).__new__
is equal to type.__new__.
  - In type.__new__, it is determined that M_A is not
the best type for D class; it should be actually M_B.
  - Since type.__new__ was called with wrong metaclass
as the first argument, call the correct metaclass.
  - This calls M_B.__new__, which again calls type.__new__,
but this time with M_B as the first argument, which
is correct.

This is a very good explanation and it should go somewhere in the
standard docs.
I remember I spent a significant amount of time and effort to reach the
same conclusion
a while ago, and now I have already started to forget eveything a again
:-(
Anyway, I will bookmark this post for future reference ;)

Michele Simionato

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


Re: SWIGing problem

2006-03-23 Thread Jaap Spies
Robert Kern wrote:
 Tommy Grav wrote:
 
This might not be the venue to ask this but I do not know where else to
turn. 
I am trying to install a package that is swig'ed from some C code. 
Unfortunately the readme file isn't to informative.  Does anyone
know which libraries to link to to remove the undefined symbols
below?

[EMAIL PROTECTED] Python/pynovas - ld -dynamic novas_wrap.o libnovas.a -lm
-lpython -o _novas.so
ld: Undefined symbols:
_fprintf$LDBLStub
_printf$LDBLStub
dyld_stub_binding_helper
restFP
saveFP
 
 
 Ouch! Are they really not using distutils to build the extension modules? Even
 when you fix the specific issue above (if you're on OS X, add -lcc_dynamic to
 the link line; otherwise, I don't know), you're still probably going to have
 other problems. distutils knows how to build Python extensions modules. The
 pynovas Makefile doesn't.
 

I did not use distutils, because I do not know how :-)! Maybe in the 
next release of PyNOVAS.

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


wxpython error message?

2006-03-23 Thread Kenneth Xie
I made some mistake in my codes, so there was a window with a text field
appeared. But before I could read the message in the text field, the
window disappeared. So I can't figure out what's the problem with my codes.
What should I do to make the message window last a little longer?

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

Re: removing file by inode

2006-03-23 Thread Grant Edwards
On 2006-03-23, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 is it possible to remove a file by it's inode and not it's filename
 using Python?

What do you mean remove a file?

-- 
Grant Edwards   grante Yow!  Life is a POPULARITY
  at   CONTEST! I'm REFRESHINGLY
   visi.comCANDID!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Convert Word .doc to Acrobat .pdf files

2006-03-23 Thread Thomas Guettler
I wrote a script which uses OpenOffice. It can
convert and read a lot of formats.

#!/usr/bin/env python
#Old: !/optlocal/OpenOffice.org/program/python
# (c) 2003-2006 Thomas Guettler http://www.tbz-pariv.de/

# OpenOffice1.1 comes with its own python interpreter.
# This Script needs to be run with the python from OpenOffice1:
#   /opt/OpenOffice.org/program/python 
# Start the Office before connecting:
# soffice -accept=socket,host=localhost,port=2002;urp;
#
# With OpenOffice2 you can use the default Python-Interpreter (at least on SuSE)
#

# Python Imports
import os
import re
import sys
import getopt

default_path=/usr/lib/ooo-2.0/program
sys.path.insert(0, default_path)

# pyUNO Imports
try:
import uno
from com.sun.star.beans import PropertyValue
except:
print This Script needs to be run with the python from OpenOffice.org
print Example: /opt/OpenOffice.org/program/python %s % (
os.path.basename(sys.argv[0]))
print Or you need to insert the right path at the top, where uno.py is.
print Default: %s % default_path

raise
sys.exit(1)



extension=None
format=None

def usage():
scriptname=os.path.basename(sys.argv[0])
print Usage: %s [--extension pdf --format writer_pdf_Export] files
All files or directories will be converted to HTML.

You must start the office with this line before starting
this script:
  soffice -accept=socket,host=localhost,port=2002;urp;

 If you want to export to something else, you need to use give the extension 
*and*
 the format.
 
 For a list of possible export formats see
 http://framework.openoffice.org/files/documents/25/897/filter_description.html

 or

 /opt/OpenOffice.org/share/registry/data/org/openoffice/Office/TypeDetection.xcu

 or

 grep -ri MYEXTENSION 
/usr/lib/ooo-2.0/share/registry/modules/org/openoffice/TypeDetection/
 the format is node oor:name=FORMAT ...

 Attention: Writer (.xls) needs an other export format than Writer (.doc)
Example: calc_pdf_Export instead of writer_pdf_Export
   % (scriptname)

def do_dir(dir, desktop):
# Load File
dir=os.path.abspath(dir)
if os.path.isfile(dir):
files=[dir]
else:
files=os.listdir(dir)
files.sort()
for file in files:
if file.startswith(.):
continue
file=os.path.join(dir, file)
if os.path.isdir(file):
do_dir(file, desktop)
else:
do_file(file, desktop)

def do_file(file, desktop):
file_l=file.lower()

global format
if extension==html:
if file_l.endswith(.xls):
format=HTML (StarCalc)
elif file_l.endswith(.doc):
format=HTML (StarWriter)
else:
print %s: unkown extension % file
return

assert(format)
assert(extension)

file_save=%s.%s % (file, extension)
properties=[]
p=PropertyValue()
p.Name=Hidden
p.Value=True
properties.append(p)
doc=desktop.loadComponentFromURL(
file://%s % file, _blank, 0, tuple(properties));
if not doc:
print Failed to open '%s' % file
return
# Save File
properties=[]
p=PropertyValue()
p.Name=Overwrite
p.Value=True
properties.append(p)
p=PropertyValue()
p.Name=FilterName
p.Value=format
properties.append(p)
p=PropertyValue()
p.Name=Hidden
p.Value=True
try:
doc.storeToURL(
file://%s % file_save, tuple(properties))
print Created %s % file_save
except ValueError:
import sys
import traceback
import cStringIO
(exc_type, exc_value, tb) = sys.exc_info()
error_file = cStringIO.StringIO()
traceback.print_exception(exc_type, exc_value, tb,
  file=error_file)
stacktrace=error_file.getvalue()
print Failed while writing: '%s' % file_save
print stacktrace
doc.dispose()
 
def init_openoffice():
# Init: Connect to running soffice process
context = uno.getComponentContext()
resolver=context.ServiceManager.createInstanceWithContext(
com.sun.star.bridge.UnoUrlResolver, context)
try:
ctx = resolver.resolve(

uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext)
except:
print Could not connect to running openoffice.
usage()
sys.exit(1)
smgr=ctx.ServiceManager
desktop = smgr.createInstanceWithContext(com.sun.star.frame.Desktop,ctx)
return desktop

def main():
try:
opts, args = getopt.getopt(sys.argv[1:], , [
extension=, format=])
except getopt.GetoptError,e:
print e
usage()
sys.exit(1)

global extension
global format
for o, a in opts:
if o==--extension:
extension=a
assert(not extension.startswith(.))
elif o==--format:
format=a
else:
raise(Internal Error, undone option: %s 

path to modules per import statement

2006-03-23 Thread AndyL
Hi,
is there any way to specify the path to modules within import statement 
(like in Java)?

For instance: import my.path.module would load module from 
./my/path/module.py?

Thx,
A.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strange metaclass behaviour

2006-03-23 Thread Michele Simionato
Christian Eder wrote:
 Hi,

 I think I have discovered a problem in context of
 metaclasses and multiple inheritance in python 2.4,
 which I could finally reduce to a simple example:

 Look at following code:

 class M_A (type) :

  def __new__ (meta, name, bases, dict) :
 print M.__new__, meta, name, bases
 return super (M_A, meta).__new__ (meta, name, bases, dict)

 class M_B (M_A) : pass

 class A (object) : __metaclass__ = M_A

 class B (object) : __metaclass__ = M_B

 class D (A, B) : pass


 One would expect that either
 1) D inherits the metaclass M_A from A
 2) or python raises the well known Metatype conflict among bases
 error

No, there is no conflict in this case: since M_B is a subclass of M_A,
the
metaclass of D is M_B. I don't think this is bug either: the fact is
that
type.__new__ works differently from object.__new__, so that it is
called twice in this case. Not sure if it could be avoided.

Speaking of the metatype conflict, I realized a while ago that it is
possible
to avoid it automatically even at the pure Python level, without
changing
the C code for type.__new__. However, the solution is too complicate.
According
to the Zen of Python If the implementation is hard to explain, it's a
bad idea,
thus I have never used it.

Still, it is an interesting exercise if you are willing to risk the
melting of your brain,
so here is the code ;)

# noconflict.py
Deep, **DEEP** magic to remove metaclass conflicts.

``noconflict`` provides the ``safetype`` metaclass, the mother of
conflict-free
metaclasses. I you do

from noconflict import safetype as type

on top of your module, all your metaclasses will be conflict safe.
If you override ``__new__`` when you derive from ``safetype``,
you should do it cooperatively.

import inspect, types, __builtin__
try: set # python version = 2.4
except NameError: # python version = 2.3
   from sets import Set as set

def skip_redundant(iterable, skipset=None):
   Redundant items are repeated items or items in the original
skipset.
   if skipset is None: skipset = set()
   for item in iterable:
   if item not in skipset:
   skipset.add(item)
   yield item

memoized_metaclasses_map = {}

# utility function
def remove_redundant(metaclasses):
   skipset = set([types.ClassType])
   for meta in metaclasses: # determines the metaclasses to be skipped
   skipset.update(inspect.getmro(meta)[1:])
   return tuple(skip_redundant(metaclasses, skipset))

##
## now the core of the module: two mutually recursive functions ##
##

def get_noconflict_metaclass(bases, left_metas, right_metas):
Not intended to be used outside of this module, unless you know
what you are doing.
# make tuple of needed metaclasses in specified priority order
metas = left_metas + tuple(map(type, bases)) + right_metas
needed_metas = remove_redundant(metas)

# return existing confict-solving meta, if any
if needed_metas in memoized_metaclasses_map:
  return memoized_metaclasses_map[needed_metas]
# nope: compute, memoize and return needed conflict-solving meta
elif not needed_metas: # wee, a trivial case, happy us
meta = type
elif len(needed_metas) == 1: # another trivial case
meta = needed_metas[0]
# check for recursion, can happen i.e. for Zope ExtensionClasses
elif needed_metas == bases:
raise TypeError(Incompatible root metatypes, needed_metas)
else: # gotta work ...
metaname = '_' + ''.join([m.__name__ for m in needed_metas])
meta = classmaker()(metaname, needed_metas, {})
memoized_metaclasses_map[needed_metas] = meta
return meta

def classmaker(left_metas=(), right_metas=()):
def make_class(name, bases, adict):
metaclass = get_noconflict_metaclass(bases, left_metas,
right_metas)
return metaclass(name, bases, adict)
return make_class

#
## and now a conflict-safe replacement for 'type'  ##
#

__type__=__builtin__.type # the aboriginal 'type'
# left available in case you decide to rebind __builtin__.type

class safetype(__type__):
Overrides the ``__new__`` method of the ``type`` metaclass,
making the
generation of classes conflict-proof.
def __new__(mcl, *args):
nargs = len(args)
if nargs == 1: # works as __builtin__.type
return __type__(args[0])
elif nargs == 3: # creates the class using the appropriate
metaclass
n, b, d = args # name, bases and dictionary
meta = get_noconflict_metaclass(b, (mcl,), right_metas=())
if meta is mcl: # meta is trivial, dispatch to the default
__new__
return super(safetype, mcl).__new__(mcl, n, b, d)
else: # non-trivial 

encoding problems (é and è)

2006-03-23 Thread bussiere bussiere
hi i'am making a program for formatting string,
or
i've added :
#!/usr/bin/python
# -*- coding: utf-8 -*-

in the begining of my script but

 str = str.replace('Ç', 'C')
str = str.replace('é', 'E')
str = str.replace('É', 'E')
str = str.replace('è', 'E')
str = str.replace('È', 'E')
str = str.replace('ê', 'E')


doesn't work it put me  and , instead of remplacing é by E


if someone have an idea it could be great

regards
Bussiere
ps : i've added the whole script under :






__




#!/usr/bin/python
# -*- coding: utf-8 -*-
import fileinput, glob, string, sys, os, re

fichA=raw_input(Entrez le nom du fichier d'entree : )
print (\n)
fichC=raw_input(Entrez le nom du fichier de sortie : )
print (\n)
normalisation1 = raw_input(Normaliser les adresses 1 (ex : Avenue-
AV) (O/N) ou A pour tout normaliser \n)
normalisation1 = normalisation1.upper()

if normalisation1 != A:
print (\n)
normalisation2 = raw_input(Normaliser les civilités (ex :
Docteur- DR) (O/N) \n)
normalisation2 = normalisation2.upper()
print (\n)
normalisation3 = raw_input(Normaliser les Adresses 2 (ex :
Place- PL) (O/N) \n)
normalisation3 = normalisation3.upper()


normalisation4 = raw_input(Normaliser les caracteres / et - (ex :
/ -   ) (O/N) \n )
normalisation4 = normalisation4.upper()

if normalisation1 == A:
normalisation1 = O
normalisation2 = O
normalisation3 = O
normalisation4 = O


fiA=open(fichA,r)
fiC=open(fichC,w)


compteur = 0

while 1:

ligneA=fiA.readline()



if ligneA == :

break

if ligneA != :
str = ligneA
str = str.replace('a', 'A')
str = str.replace('b', 'B')
str = str.replace('c', 'C')
str = str.replace('d', 'D')
str = str.replace('e', 'E')
str = str.replace('f', 'F')
str = str.replace('g', 'G')
str = str.replace('h', 'H')
str = str.replace('i', 'I')
str = str.replace('j', 'J')
str = str.replace('k', 'K')
str = str.replace('l', 'L')
str = str.replace('m', 'M')
str = str.replace('n', 'N')
str = str.replace('o', 'O')
str = str.replace('p', 'P')
str = str.replace('q', 'Q')
str = str.replace('r', 'R')
str = str.replace('s', 'S')
str = str.replace('t', 'T')
str = str.replace('u', 'U')
str = str.replace('v', 'V')
str = str.replace('w', 'W')
str = str.replace('x', 'X')
str = str.replace('y', 'Y')
str = str.replace('z', 'Z')

str = str.replace('ç', 'C')
str = str.replace('Ç', 'C')
str = str.replace('é', 'E')
str = str.replace('É', 'E')
str = str.replace('è', 'E')
str = str.replace('È', 'E')
str = str.replace('ê', 'E')
str = str.replace('Ê', 'E')
str = str.replace('ë', 'E')
str = str.replace('Ë', 'E')
str = str.replace('ä', 'A')
str = str.replace('Ä', 'A')
str = str.replace('à', 'A')
str = str.replace('À', 'A')
str = str.replace('Á', 'A')
str = str.replace('Â', 'A')
str = str.replace('Ä', 'A')
str = str.replace('Ã', 'A')
str = str.replace('â', 'A')
str = str.replace('Ä', 'A')
str = str.replace('ï', 'I')
str = str.replace('Ï', 'I')
str = str.replace('î', 'I')
str = str.replace('Î', 'I')
str = str.replace('ô', 'O')
str = str.replace('Ô', 'O')
str = str.replace('ö', 'O')
str = str.replace('Ö', 'O')
str = str.replace('Ú','U')
str = str.replace('  ', ' ')
str = str.replace('   ', ' ')
str = str.replace('', ' ')



if normalisation1 == O:
str = str.replace('AVENUE', 'AV')
str = str.replace('BOULEVARD', 'BD')
str = str.replace('FAUBOURG', 'FBG')
str = str.replace('GENERAL', 'GAL')
str = str.replace('COMMANDANT', 'CMDT')
str = str.replace('MARECHAL', 'MAL')
str = str.replace('PRESIDENT', 'PRDT')
str = str.replace('SAINT', 'ST')
str = str.replace('SAINTE', 'STE')
str = str.replace('LOTISSEMENT', 'LOT')
str = str.replace('RESIDENCE', 'RES')
str = str.replace('IMMEUBLE', 'IMM')
str = str.replace('IMEUBLE', 'IMM')
str = str.replace('BATIMENT', 'BAT')

if normalisation2 == O:
str = str.replace('MONSIEUR', 'M')
str = str.replace('MR', 'M')
str = str.replace('MADAME', 'MME')
str = str.replace('MADEMOISELLE', 'MLLE')
str = str.replace('DOCTEUR', 'DR')
str = str.replace('PROFESSEUR', 'PR')
str = str.replace('MONSEIGNEUR', 'MGR')
str = str.replace('M ME','MME')


if normalisation3 == O:
str = str.replace('PLACE', 

Re: Strange metaclass behaviour

2006-03-23 Thread Christian Eder
Ziga Seilnacht wrote:

 I hope that above explanation helps.
 

Thanks for your support.
I now understand what happens here,
but I'm not really happy with the situation.
Your solution is a nice workaround, but in a quite 
huge and complex class framework with a lot a custom 
metaclasses you don't want this code in each __new__ 
function. And in fact each __new__ which does not contain this
fix-code (and which is not completely side-effect free) might
break if someone adds additional classes deeps down in the 
inheritance hierarchy (which is exactly what happened
for me). And this is clearly not what one should expect in
context of multiple inheritance and cooperative supercalls.

Raising a metatype conflict among bases error might be a 
perfectly acceptable behavior here (though it would be better if 
python resolves the conflict as your code does), but 
double-executing code is not in my humble opinion.

Is this worth a bug-report on sourceforge ?

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


Re: Convert Word .doc to Acrobat .pdf files

2006-03-23 Thread Duncan Booth
kbperry wrote:

 Hi all,
 
 Background:
 I need some help.  I am trying to streamline a process for one of our
 technical writers.  He is using Perforce (version control system), and
 is constantly changing his word documents, and then converts them to
 both .pdf and Web page format (to publish to the web).  He has a
 licensed copy of Adobe Acrobat Professional (7.x).
 
 Questions:
 Does Acrobat Pro, have some way to interface with it command-line (I
 tried searching, but couldn't find anything)?  Is there any other good
 way to script word to pdf conversion?

As I remember, Acrobat monitors a directory and converts anything it
finds there, so you don't need to script Acrobat at all, just script
printing the documents. However, it sounds as though you are talking
about running Acrobat on a server and his license probably doesn't
permit that. 

Alternatively use OpenOffice: it will convert word documents to
pdf or html and can be scripted in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Default/editable string to raw_input

2006-03-23 Thread Sybren Stuvel
Sion Arrowsmith enlightened us with:
 You're assuming that the tester is already familiar with a text
 editor.

Indeed. Someone working on a test suite sounded like someone who knows
how to work with a text editor.

 And then they would have to learn the syntax of the configuration
 file, and the parameters available.

True. Thorough comments and a clear syntax help a long way.

 A point-and-drool interface requires no such learning.

But that's not what you get with raw_input().

Sybren
-- 
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself? 
 Frank Zappa
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: path to modules per import statement

2006-03-23 Thread [EMAIL PROTECTED]
For instance: import my.path.module would load module from
./my/path/module.py?

Yeah, just do that. I don't understand the question, it works just like
this today.

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


Re: wxpython error message?

2006-03-23 Thread Larry Bates
Kenneth Xie wrote:
 I made some mistake in my codes, so there was a window with a text field
 appeared. But before I could read the message in the text field, the
 window disappeared. So I can't figure out what's the problem with my codes.
 What should I do to make the message window last a little longer?
 
 Thank you.

This might help:

http://wingware.com/pipermail/wingide-users/2004-November/001984.html

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

[no subject]

2006-03-23 Thread cm012b5105










Hi there i am hoping some one could help me out with a small problem
i am in the process of learning python. I am trying
to write an interactive programme,
This is a short example.
if s = raw_input
(hello whats your name? )
if s=='carmel':
print Ahh the bosss
wife

What i would like to know is what if she dont write carmel she rights say carm
short of me writing if s=='carm': on a new line is
there a shorter way of doing this so i can cover all
angles on how she might write her name.
Thanks nige








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

Re: path to modules per import statement

2006-03-23 Thread [EMAIL PROTECTED]
As an example, let's say you have a main module at /usr/code/Main.py
and you have a module you'd like to import at /usr/code/util/Util.py,
you can do this:

import util.Util

If you are using PyDev and Eclipse to develop your Python code, you can
set the base directory to reference module imports from.

You can also tweak your PYTHONPATH if you want to import modules from
other directory structures.

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


Re: path to modules per import statement

2006-03-23 Thread Arne Ludwig
Maybe he means: sys.path.append('/my/path')

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


Python has a new Logo

2006-03-23 Thread Xah Lee
Python has a new logo!

See http://python.org/

And it is a fantastic logo.

   Xah
   [EMAIL PROTECTED]
 ∑ http://xahlee.org/

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

Re: Python has a new Logo

2006-03-23 Thread Felipe Almeida Lessa
Em Qui, 2006-03-23 às 07:43 -0800, Xah Lee escreveu:
 Python has a new logo!

Really? :)

 See http://python.org/
 
 And it is a fantastic logo.

LOL, sorry for the trolling, but we already had loads of (good)
discussions about it some time ago...

-- 
Felipe.

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

Re: removing file by inode

2006-03-23 Thread Arne Ludwig
Good answer. :)  I seriously doubt it is possible except for the
trivial solution:

def remove_a_file(inode):
 os.system (find / -inum %d | xargs rm -f % (inode))

PS. Don't blame me if this function destroys your hard disk. I wrote it
off the top of my head.

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


Re: Convert Word .doc to Acrobat .pdf files

2006-03-23 Thread kbperry
Thanks for the replys!

I need to stick with Word (not my choice, but I would rather keep
everything like he has it).

Duncan,
I was just trying the printing thing.  When installing Adobe Acrobat,
it installs a printer called Adobe PDF, and I have been trying to
print to there, but the Save window keeps popping up.  I need to
figure out a way to keep it in the background.

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


Re: encoding problems (é and è)

2006-03-23 Thread Christoph Zwerschke
bussiere bussiere wrote:
 hi i'am making a program for formatting string,
 i've added :
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
 in the begining of my script but
 
  str = str.replace('Ç', 'C')
 ...
 doesn't work it put me  and , instead of remplacing é by E

Are your sure your script and your input file *is* actually encoded with 
utf-8? If it does not work as expected, it is probably latin-1, just 
like your posting. Try changing the coding to latin-1. Does it work now?

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


Re: Programming challenge: wildcard exclusion in cartesian products

2006-03-23 Thread Dirk Thierbach
Dinko Tenev [EMAIL PROTECTED] wrote:
 Dirk Thierbach wrote:
 If more time during preprocessing is allowed, another idea is to
 treat the wildcard expressions as regular expressions, convert
 each into a finite state machine, construct the intersection of
 all these state machines, minimize it and then swap final and non-final
 states.

 Given the requirements, did you mean taking the *union* and swapping
 states?  Or maybe swapping states first, and then taking the
 intersection?

Whatever the requirements were. Take your pick. :-)

 Then you can use the resulting automaton to efficiently
 enumerate S^n - W. In the above case, the resulting FSM would have just
 three states.

 I don't see immediately how exactly this is going to work.  Unless I'm
 very much mistaken, a FSA in the classical sense will accept or reject
 only after the whole sequence has been consumed, and this spells
 exponential times.  

Exponential in respect to what? You just recursively walk the
automaton for every word of length n, so at most you'll have to check
every word in S^n once. Hence, the complexity is not worse than the
generate and test approach (it's in fact better, since testing is
trivial).

However, if the result set is simple (as in the example), then the
result FSM will have states that won't have transitions for every
letters, so I guess the average case will be a lot better.

 For improved asymptotic complexity in this case,
 you need to be able to at least reject in mid-sequence, 

One can do that if there is no valid transition out of some state.

I guess one could even optimize on that: In the minimal automaton,
every state has some transition sequence that will end up in a final
state. Annotate each state with the minimum number of steps for
such a sequence. While walking the automaton, keep the maximum
number of letters to produce in a variable. If this number is small
then the number in the annotation, stop and backtrace.

This should guarantee that only those states are visited that really
produce some output. 

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


Re: question: how to clare the absolute url in a html file

2006-03-23 Thread Arne Ludwig
Perhaps this is what he means:

re.sub(http://[^/]*/,/,http://palle.fi/wing/walla.htm;)
'/wing/walla.htm'

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


Re: Python has a new Logo

2006-03-23 Thread Xah Lee
is there larger versions of the logo?

and, any usage restrictions?

i also like to find out the the artist name. Any pointer is
appreciated. Thanks.

   Xah
   [EMAIL PROTECTED]
 ∑ http://xahlee.org/

Felipe Almeida Lessa wrote:
 Em Qui, 2006-03-23 às 07:43 -0800, Xah Lee escreveu:
  Python has a new logo!

 Really? :)

  See http://python.org/
 
  And it is a fantastic logo.

 LOL, sorry for the trolling, but we already had loads of (good)
 discussions about it some time ago...
 
 -- 
 Felipe.

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

Re: encoding problems (é and è)

2006-03-23 Thread Larry Bates
Seems to work fine for me.

 x=éÇ
 x=x.replace('é','E')
'E\xc7'
 x=x.replace('Ç','C')
 x
'E\xc7'
 x=x.replace('Ç','C')
 x
'EC'

You should also be able to use .upper() method to
uppercase everything in the string in a single statement:

tstr=ligneA.upper()

Note: you should never use 'str' as a variable as
it will mask the built-in str function.

-Larry Bates

bussiere bussiere wrote:
 hi i'am making a program for formatting string,
 or
 i've added :
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
 in the begining of my script but
 
  str = str.replace('Ç', 'C')
 str = str.replace('é', 'E')
 str = str.replace('É', 'E')
 str = str.replace('è', 'E')
 str = str.replace('È', 'E')
 str = str.replace('ê', 'E')
 
 
 doesn't work it put me  and , instead of remplacing é by E
 
 
 if someone have an idea it could be great
 
 regards
 Bussiere
 ps : i've added the whole script under :
 
 
 
 
 
 
 __
 
 
 
 
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 import fileinput, glob, string, sys, os, re
 
 fichA=raw_input(Entrez le nom du fichier d'entree : )
 print (\n)
 fichC=raw_input(Entrez le nom du fichier de sortie : )
 print (\n)
 normalisation1 = raw_input(Normaliser les adresses 1 (ex : Avenue-
 AV) (O/N) ou A pour tout normaliser \n)
 normalisation1 = normalisation1.upper()
 
 if normalisation1 != A:
 print (\n)
 normalisation2 = raw_input(Normaliser les civilités (ex :
 Docteur- DR) (O/N) \n)
 normalisation2 = normalisation2.upper()
 print (\n)
 normalisation3 = raw_input(Normaliser les Adresses 2 (ex :
 Place- PL) (O/N) \n)
 normalisation3 = normalisation3.upper()
 
 
 normalisation4 = raw_input(Normaliser les caracteres / et - (ex :
 / -   ) (O/N) \n )
 normalisation4 = normalisation4.upper()
 
 if normalisation1 == A:
 normalisation1 = O
 normalisation2 = O
 normalisation3 = O
 normalisation4 = O
 
 
 fiA=open(fichA,r)
 fiC=open(fichC,w)
 
 
 compteur = 0
 
 while 1:
 
 ligneA=fiA.readline()
 
 
 
 if ligneA == :
 
 break
 
 if ligneA != :
 str = ligneA
 str = str.replace('a', 'A')
 str = str.replace('b', 'B')
 str = str.replace('c', 'C')
 str = str.replace('d', 'D')
 str = str.replace('e', 'E')
 str = str.replace('f', 'F')
 str = str.replace('g', 'G')
 str = str.replace('h', 'H')
 str = str.replace('i', 'I')
 str = str.replace('j', 'J')
 str = str.replace('k', 'K')
 str = str.replace('l', 'L')
 str = str.replace('m', 'M')
 str = str.replace('n', 'N')
 str = str.replace('o', 'O')
 str = str.replace('p', 'P')
 str = str.replace('q', 'Q')
 str = str.replace('r', 'R')
 str = str.replace('s', 'S')
 str = str.replace('t', 'T')
 str = str.replace('u', 'U')
 str = str.replace('v', 'V')
 str = str.replace('w', 'W')
 str = str.replace('x', 'X')
 str = str.replace('y', 'Y')
 str = str.replace('z', 'Z')
 
 str = str.replace('ç', 'C')
 str = str.replace('Ç', 'C')
 str = str.replace('é', 'E')
 str = str.replace('É', 'E')
 str = str.replace('è', 'E')
 str = str.replace('È', 'E')
 str = str.replace('ê', 'E')
 str = str.replace('Ê', 'E')
 str = str.replace('ë', 'E')
 str = str.replace('Ë', 'E')
 str = str.replace('ä', 'A')
 str = str.replace('Ä', 'A')
 str = str.replace('à', 'A')
 str = str.replace('À', 'A')
 str = str.replace('Á', 'A')
 str = str.replace('Â', 'A')
 str = str.replace('Ä', 'A')
 str = str.replace('Ã', 'A')
 str = str.replace('â', 'A')
 str = str.replace('Ä', 'A')
 str = str.replace('ï', 'I')
 str = str.replace('Ï', 'I')
 str = str.replace('î', 'I')
 str = str.replace('Î', 'I')
 str = str.replace('ô', 'O')
 str = str.replace('Ô', 'O')
 str = str.replace('ö', 'O')
 str = str.replace('Ö', 'O')
 str = str.replace('Ú','U')
 str = str.replace('  ', ' ')
 str = str.replace('   ', ' ')
 str = str.replace('', ' ')
 
 
 
 if normalisation1 == O:
 str = str.replace('AVENUE', 'AV')
 str = str.replace('BOULEVARD', 'BD')
 str = str.replace('FAUBOURG', 'FBG')
 str = str.replace('GENERAL', 'GAL')
 str = str.replace('COMMANDANT', 'CMDT')
 str = str.replace('MARECHAL', 'MAL')
 str = str.replace('PRESIDENT', 'PRDT')
 str = str.replace('SAINT', 'ST')
 str = str.replace('SAINTE', 'STE')
 str = str.replace('LOTISSEMENT', 'LOT')
 str = str.replace('RESIDENCE', 'RES')
 str = str.replace('IMMEUBLE', 'IMM')
 str = 

Re: Convert Word .doc to Acrobat .pdf files

2006-03-23 Thread Duncan Booth
kbperry wrote:

 Thanks for the replys!
 
 I need to stick with Word (not my choice, but I would rather keep
 everything like he has it).

That shouldn't be a problem: you can use stick with Word for editing the 
documents and just use OpenOffice to do the conversion.

 
 Duncan,
 I was just trying the printing thing.  When installing Adobe Acrobat,
 it installs a printer called Adobe PDF, and I have been trying to
 print to there, but the Save window keeps popping up.  I need to
 figure out a way to keep it in the background.
 
I'm afraid its a while since I used Acrobat to generate PDF files. I think 
there are configuration options to tell it to do the conversion 
automatically and not prompt you, but I can't remember where.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python has a new Logo

2006-03-23 Thread [EMAIL PROTECTED]
Yawn. Go start indenting, and stop using Perl. If Python has such a
nice logo, why waste any more time with Perl?

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


Re: Linear regression in NumPy

2006-03-23 Thread Robert Kern
nikie wrote:
 Although I think it's worth reading, it only covers the fundamental
 structure (what arrays are, what ufuncs are..) of NumPy. Neither of the
 functions dicussed in this thread (polyfit/linear_least_squares) is
 mentioned in the file.

Both functions are described in the full book. Were you just looking at the
sample chapter?

-- 
Robert Kern
[EMAIL PROTECTED]

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

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


Re: raw_input (was no subject)

2006-03-23 Thread Tim Williams (gmail)
On 23/03/06, cm012b5105 [EMAIL PROTECTED] wrote:



















Hi there i am hoping some one could help me out with a small problem
i am in the process of learning python. I am trying
to write an interactive programme,
This is a short example.
if s = raw_input
(hello what's your name? )
if s=='carmel
':
print Ahh the boss's
wife

What i would like to know is what if she dont write 
carmel she rights say carm
short of me writing if s=='carm': on a new line is
there a shorter way of doing this so i can cover all
angles on how she might write her name.
Thanks nige
 s = raw_input (hello what's your name? )
Traceback ( File interactive input, line 1
 if s = raw_input (hello what's your name? )
 ^
SyntaxError: invalid syntax


 s = raw_input (hello what's your name? ) # carmel
 if s=='carmel':
...  print Ahh the boss's wife
...  
Ahh the boss's wife
 

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

Re: multiple assignment

2006-03-23 Thread Steven Bethard
Anand wrote:
 Wouldn't it be nice to say
 id, *tokens = line.split(',')

 id, tokens_str = line.split(',', 1)
 
 But then you have to split tokens_str again.
 
 id, tokens_str = line.split(',', 1)
 tokens = tokens_str.split(',')

Sorry, it wasn't clear that you needed the tokens from the original post.

If you're interested in this, the best route is to write up a PEP and 
provide an implementation.  The new AST in Python makes this kind of 
thing a bit easier.

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


Re: Per instance descriptors ?

2006-03-23 Thread Steven Bethard
bruno at modulix wrote:
 Steven Bethard wrote:
 Could you explain again why you don't want baaz to be a class-level
 attribute?
 
 Because the class is a decorator for many controller functions, and each
 controller function will need it's own set of descriptors, so I don't
 want to mess with the class.

So you're trying to add property-like attributes to functions?  That is, 
you want something like:

@my_decorator
def f(...):
 ...

f.foo # calls f._get_foo()


in another post, bruno at modulix wrote:
  This would imply a decorator subclass and a descriptor subclass for
  each and every controller function - which is what I'm trying to
  avoid.

So you only want one decorator?  Doesn't that mean that all functions 
will have the same attributes?  But if that were true you would only 
need one descriptor for all controller functions, so I must not be 
understanding that right.

Can you give a little more realistic code sample?  I'm still not sure 
what it is you really want to do.  Don't worry about showing the 
implementation you're thinking of.  Just show me how you want to use 
these things and what it ought to look like.


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


raw_input

2006-03-23 Thread cm012b5105










Hi there i am hoping some one could help me out with a small problem
i am in the process of learning python. I am trying
to write an interactive programme,

This is a short
example.









if s = raw_input
(hello what's your name? )
if s=='carmel ':
print Ahh the boss's
wife









What i would like to know is what if she doesnt write carmel she rights say carm
short of me writing if s=='carm': on a new line is
there a shorter way of doing this so i can cover all
angles on how she might write her name.
Thanks nigeps I appologise
for my earlier thread






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

Confused: appending to a list

2006-03-23 Thread DataSmash
I'm confused.  Why is it that when I say while len(list)  5:, I get
5 items in my list.
If I say while len(list)  6:, I get 6 items in the list and so on.
I would think if I said less than 5, I would get 4 items.
Can anyone explain this?
Thanks.
R.D.


# Start an empty list
list = []
while len(list)  5:
# Get a random number between 1  100
num = random.randint(1,100)
# Make sure there are no duplicates
if num not in list:
# Append each number to the list
list.append(num)
print list

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


Re: Confused: appending to a list

2006-03-23 Thread Felipe Almeida Lessa
Em Qui, 2006-03-23 às 08:31 -0800, DataSmash escreveu:
 I'm confused.  Why is it that when I say while len(list)  5:, I get
 5 items in my list.

while len(list)  5: implies that the loop will stop only when
len(list) = 5.

HTH,

-- 
Felipe.

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

Re: removing file by inode

2006-03-23 Thread Grant Edwards
On 2006-03-23, Arne Ludwig [EMAIL PROTECTED] wrote:

 Good answer. :)  I seriously doubt it is possible except for the
 trivial solution:  [...]

I don't know if there is a Linux equivalent, but under SunOS
there was a way to delete a file given it's i-node.  And that's
all it did was delete the file itself and mark the i-node as
free.  It didn't remove any directory entries referring to the
i-node.

It left your filesystem in a rather broken state, so you had to
run fsck afterwards.  

-- 
Grant Edwards   grante Yow!  I have a very good
  at   DENTAL PLAN. Thank you.
   visi.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Confused: appending to a list

2006-03-23 Thread Diez B. Roggisch
DataSmash wrote:

 I'm confused.  Why is it that when I say while len(list)  5:, I get
 5 items in my list.
 If I say while len(list)  6:, I get 6 items in the list and so on.
 I would think if I said less than 5, I would get 4 items.
 Can anyone explain this?

Yes - you loop until the condition is _not_ fullfilled anymore. Which means
that if the list has a length of five, the len(l)  6 is true, and
appending makes it len(l) == 6 - which then will fail your condition.

So - you need to loop one time less, by doing

while len(l)  6 - 1:
...

diez

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


  1   2   3   >