Re: spaces at ends of filenames or directory names on Win32

2006-02-24 Thread Tim Roberts
rtilley <[EMAIL PROTECTED]> wrote:
>
>For example... tell windows to move a file named ' XXX ' (one space 
>before and one space after the filename). Windows will complain that 
>file 'XXX' does not exist. It's correct of course, 'XXX' does not exist, 
>but ' XXX ' does indeed exist.

Are you sure you're doing it right?  It works for me.  Notice that I have
"x.c" and " x.c " in the same directory at the same time.

C:\tmp\x>copy ..\x.c .
1 file(s) copied.

C:\tmp\x>dir
 Volume in drive C has no label.
 Volume Serial Number is 70CF-E8F4

 Directory of C:\tmp\x

02/24/2006  11:48 PM  .
02/24/2006  11:48 PM  ..
02/22/2006  10:49 PM   539 x.c
   1 File(s)539 bytes
   2 Dir(s)  50,937,999,360 bytes free

C:\tmp\x>copy x.c " x.c "
1 file(s) copied.

C:\tmp\x>dir
 Volume in drive C has no label.
 Volume Serial Number is 70CF-E8F4

 Directory of C:\tmp\x

02/24/2006  11:48 PM  .
02/24/2006  11:48 PM  ..
02/22/2006  10:49 PM   539  x.c
02/22/2006  10:49 PM   539 x.c
   2 File(s)  1,078 bytes
   2 Dir(s)  50,937,999,360 bytes free

C:\tmp\x>erase " x.c "

C:\tmp\x>dir
 Volume in drive C has no label.
 Volume Serial Number is 70CF-E8F4

 Directory of C:\tmp\x

02/24/2006  11:49 PM  .
02/24/2006  11:49 PM  ..
02/22/2006  10:49 PM   539 x.c
   1 File(s)539 bytes
   2 Dir(s)  50,937,999,360 bytes free

C:\tmp\x>
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza & Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Modifying body of select message in a 'mbox' file.

2006-02-24 Thread Michael March
I am been playing with the 'email' and 'mailbox' modules trying to read
in an email at a time from an mbox file, add something to the body of a
message and then write that change back out in 'mbox' format again.

Is there any code floating around out there that allows you to take a
message from 'mailbox', modify it with 'email' and then write it back
out via 'mailbox' again?

thanks!

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


Re: Optimize flag question

2006-02-24 Thread Steve Holden
Olivier Langlois wrote:
> Hi,
> 
>  
> 
> This is my first post on the list. I played with the –O flag option and 
> I found the hard way that it was breaking the scripts I am using because 
> they rely on the assert statement that the optimize flag remove. From 
> there, I tried to find more information on the effect that this flag has 
> on scripts but I have not found much…
> 
>  
> 
> So my question is: what are the ‘optimizations’ that the Python 
> interpreter is doing when you specify the optimize flag and is there 
> anything I should be cautious about when using it?
> 
It's not wise to write your program to rely on an assertion error being 
raised, or an assert statement having a side effect, since (as you have 
discovered) when you request optimization the assert statements are 
effectively removed from your program.

Could you outline the code that needs to be in to make the program work, 
so we can assess the errors for ourselves?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: python-list/python-dev quoting style

2006-02-24 Thread Michael Hoffman
[me]
Does anyone have a script to convert more conventional USENET quoting 
style... to the commonly used python-dev/python-list style...

[me]
>>I think this style is *much* clearer and cleaner. It does require a
>>lot more hand editing though, although this encourages more judicious
>>quoting.

[Aahz]
> It requires enough effort that I either skip it or don't respond.  Keep
> that in mind if you want people to respond to your posts.

Perhaps, but if doing so will make it easier for, say, Tim Peters to 
respond to my post, you choosing not to respond is a burden I will have 
to bear.

 > I also notice many people trimming too much context.

I notice this too. Also people trimming not enough. With any means of 
quoting.

 > And who is "me", anyway?

It's hard to believe that you don't understand who "me" is in a 
conversation between two people, one of whom is identified as "Aahz" and 
is attributed words you yourself wrote.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trolling for New Web Host . . .

2006-02-24 Thread Steve Holden
Ben Wilson wrote:
> I've had the same web host (imhosted.com) for the past three years, and
> have had decent service. However, I'm also trying to learn Python the
> hard way--by doing. So, I figured I'd write a few Python CGIs
> (non-Zope). Unfortunately, my web host does not have mod_python. They
> only way I can run a python script is by using the .cgi extension. I'm
> not sure if I want to stick with my host and just call my apps
> index.cgi, or if I should move to a new server. If I were to move to a
> new server, which would you recomend, and why?
> 
I'd recommend that you don't change anything until you have good reason 
- a business relationship that works is to be valued above a notional 
speed gain in a currently non-existent web application.

If you're just learning, CGI is fine. Migrate to mod_python when you 
start to feel limited by CGI, or when you discover a specific need for 
mod_python's neat functionality.

The only other advice I'd give you is to download Python on to your 
desktop or laptop machine and do some of your learning locally. It's 
quite difficult to debug through a web interface if you don't know what 
you're doing (and remember the cgitb module is your friend).

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: python-list/python-dev quoting style

2006-02-24 Thread Aahz
In article <[EMAIL PROTECTED]>,
Michael Hoffman  <[EMAIL PROTECTED]> wrote:
>[me]
>>>Does anyone have a script to convert more conventional USENET quoting 
>>>style... to the commonly used python-dev/python-list style...
>
>[Aahz]
>> Blech.  Stick with the standard Usenet quoting style for both!
>
>I think this style is *much* clearer and cleaner. It does require a
>lot more hand editing though, although this encourages more judicious
>quoting.

It requires enough effort that I either skip it or don't respond.  Keep
that in mind if you want people to respond to your posts.  I also notice
many people trimming too much context.  And who is "me", anyway?
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: mimicing pg 398 of practical python

2006-02-24 Thread MARK LEEDS



i should have mentioned that i am on 
linux
and using python 2.4. my apologies.
 

  - Original Message - 
  From: 
  MARK 
  LEEDS 
  To: python-list@python.org 
  Sent: Friday, February 24, 2006 10:00 
  PM
  Subject: mimicing pg 398 of practical 
  python
  
  I am trying to duplicate the sunspots graph on 
  page 398 of Practical Python. I don''t
  have those reportlab modules so i downloaded them 
  from their website  and tried to put them somewhere
  ( not clear where i should  put them ) and 
  then i added that place to my sys.path
  by doig sys.path.append inside the same program. 
  but, i still got the error that
  it doesn't know about thsis module ?
   
  does anyone have really good directions on how to 
  download the reportlab stuff
  so that it works. the book, practical python is 
  amazing but this part is a little
  unclear. thanks a lot.
   
  or maybe thre is an easier graphics package to 
  use that is already inside python.
  i'm a beginner. thanks.
   
   
          
                  
                  
                  
      mark
  
  

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

mimicing pg 398 of practical python

2006-02-24 Thread MARK LEEDS



I am trying to duplicate the sunspots graph on page 
398 of Practical Python. I don''t
have those reportlab modules so i downloaded them 
from their website  and tried to put them somewhere
( not clear where i should  put them ) and 
then i added that place to my sys.path
by doig sys.path.append inside the same program. 
but, i still got the error that
it doesn't know about thsis module ?
 
does anyone have really good directions on how to 
download the reportlab stuff
so that it works. the book, practical python is 
amazing but this part is a little
unclear. thanks a lot.
 
or maybe thre is an easier graphics package to use 
that is already inside python.
i'm a beginner. thanks.
 
 
        
                
                
                
    mark
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: webmail-SquirrelMail Fetcher In Python

2006-02-24 Thread Paul Rubin
<[EMAIL PROTECTED]> writes:
> I wish I could do that; however our IT department is ... Zelis ... About
> security; it's a school district, so lots of confidential data, etc, etc
> (their reason).
> Oh well, I'll look for an imap server on the network if I can, but I doubt
> I'll find it normally.
> If anyone else has any other info, I'd appreciate it.

Tell your IT dept that Squirrelmail is a security sieve.  Check the
standard ports (143, 993) for the imap server.  Yeah, you could
screen-scrape the messages from squirrelmail if you really had to, but
it doesn't seem worth it.  Are they at least running squirrelmail over
TLS if they're so security conscious?
-- 
http://mail.python.org/mailman/listinfo/python-list


webmail-SquirrelMail Fetcher In Python

2006-02-24 Thread brandon.mcginty
Thanks for your help.
I wish I could do that; however our IT department is ... Zelis ... About
security; it's a school district, so lots of confidential data, etc, etc
(their reason).
Oh well, I'll look for an imap server on the network if I can, but I doubt
I'll find it normally.
If anyone else has any other info, I'd appreciate it.


THX Much,
Brandon McGinty

> -Original Message-
> From: 
> [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED]
> rg] On Behalf Of Paul Rubin
> Sent: Friday, February 24, 2006 7:54 PM
> To: python-list@python.org
> Subject: Re: webmail-SquirrelMail Fetcher In Python
> 
> 
> <[EMAIL PROTECTED]> writes:
> > I've been looking on the net for a program to gather 
> e-mails from the
> > squirrelmail interface, and haven't found any.
> > My office only allows me to get e-mail access via webmail, at least
> > when I'm outside of the corperate network.
> 
> Squirrelmail is an IMAP client so there must be an IMAP server on the
> server side somewhere.  Why not talk to your IT dept about accessing
> it with a normal mail client instead of messing with screen scraping
> madness.  Squirrelmail is pretty messy and I gave up on it long ago.
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> -- 
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.375 / Virus Database: 268.1.0/269 - Release 
> Date: 2/24/2006
>  
> 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.1.0/269 - Release Date: 2/24/2006
 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.1.0/269 - Release Date: 2/24/2006
 

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


Re: list assignment using concatenation "*"

2006-02-24 Thread Steve R. Hastings
I suggest you should build your list using a list comprehension:

>>>a = [[0]*3 for i in range(3)]
>>>a
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>>a[0][1] = 1
[[0, 1, 0], [0, 0, 0], [0, 0, 0]]

-- 
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha

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


Re: PyGTK + Glade = weird problem

2006-02-24 Thread sapo
Anyway, now i tried in my glade app and i m getting this error when i
try to show the window:

GtkWarning: gtk_paint_flat_box: assertion `style->depth ==
gdk_drawable_get_depth (window)' failed

here is the code:

class main:
def __init__(self):
self.principal = gtk.glade.XML("scc.glade")
self.w_cadcli = self.principal.get_widget("w_cadcli")
dic = {"on_principal_destroy" : self.DestroyFunction,
   "on_sair_activate" : self.DestroyFunction,
   "on_w_cadcli_destroy" : self.show_hide_window,
   "on_cadcli_activate" : self.show_hide_window}
self.principal.signal_autoconnect(dic)
principal = self.principal.get_widget("principal")
gtk.main()

def DestroyFunction(self,*args):
gtk.main_quit()

def show_hide_window(self,obj,event=None):
#if the second window is open hide it, if dont show it
if self.w_cadcli.get_property("visible") == True:
self.w_cadcli.hide()
else:
self.w_cadcli.show()
return True

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


Re: PyGTK + Glade = weird problem

2006-02-24 Thread sapo
Man, you saved my day.

I spent all day writing and rewriting stuff, i asked several times on
the #python channel on irc.freenode.org, asked in the ubuntuforums,
asked all people i know that uses python.. and nobody solved it.

And it was a very simple and stupid thing!

thanx a lot it worked perfectly!

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


Re: PyGTK + Glade = weird problem

2006-02-24 Thread gsteff
Sorry about that.  Your problem is that the show_hide_janela method is
setup to be called both on  a gtk signal ("destroy") and an
event("delete_event").  Callback methods for events take a slightly
different signature than signals; they take one extra argument, which
represents the triggering event.  When you close the window, the
delete_event is triggered, which calls show_hide_janella, but the call
fails, because show_hide_janella is called with 3 arguments, when its
only expecting 2.  So, to fix the code you have posted in the thread
you linked, replace the line

def show_hide_janela(self,obj):

with the line

def show_hide_janela(self,obj, event=None):

The modified code works on my machine.  Hope this helps,

Greg

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


Re: A C-like if statement

2006-02-24 Thread Kay Schluehr

Paul Rubin wrote:
> "Kay Schluehr" <[EMAIL PROTECTED]> writes:
> > Hmm. A statement has side-effects but it returns no value. And yes, you
> > can create a name within an expression producing a value in Python,
> > using a list/generator comprehension. The solution to Bob's problem
> > would look like this:
> >
> > if (I for I in (a.find("3"),) ) != -1:
> >  print "It's here: ", I
> > else:
> >  print "No 3's here"
>
> I think that works for list comprehensions but not generator
> comprehensions.  With generator comprehensions, the index variable's
> scope is limited to the comprehension.

Right. It becomes even more ugly yet:

if [I for I in ("1,2,3".find("3"),) ] != [-1]:
 print "It's here: ", I
else:
 print "No 3's here"

> With list comprehensions
> there's a wart in that the index variable is still around afterwards.

Definitely, but index variable survival is nothing that entered Python
with list-comps:

for k in range(2):
print k

>>> k
1

Kay

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


Re: PyGTK + Glade = weird problem

2006-02-24 Thread gsteff
Oops- I didn't read your question carefully enough.  That's probably
not the problem.

Greg

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


Re: PyGTK + Glade = weird problem

2006-02-24 Thread gsteff
We'd need to see your "scc.glade" file to be sure, but basically,
calling the "show" method on the "w_cadcli" object only shows it, not
the objects it contains.  Again, to be clear, showing a container
object doesn't automatically show the objects it contains.  In glade,
use the "common" tab of the property editor to make sure that the
"visible" property is set to "Yes" for all of the widgets in the
windows you want to show.  In general, if you always do that, you'll be
able to show or hide the entire window by simply calling "show" or
"hide" on the window object, like you're trying to do.

But this is just a guess; post your "scc.glade" file if the above
advice doesn't work.

Greg

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


unicode question

2006-02-24 Thread Edward Loper
I would like to convert an 8-bit string (i.e., a str) into unicode,
treating chars \x00-\x7f as ascii, and converting any chars \x80-xff
into a backslashed escape sequences.  I.e., I want something like this:

 >>> decode_with_backslashreplace('abc \xff\xe8 def')
u'abc \\xff\\xe8 def'

The best I could come up with was:

   def decode_with_backslashreplace(s):
   "str -> unicode"
   return (s.decode('latin1')
.encode('ascii', 'backslashreplace')
.decode('ascii'))

Surely there's a better way than converting back and forth 3 times?  Is
there a reason that the 'backslashreplace' error mode can't be used with 
codecs.decode?

 >>> 'abc \xff\xe8 def'.decode('ascii', 'backslashreplace')
Traceback (most recent call last):
   File "", line 1, in ?
TypeError: don't know how to handle UnicodeDecodeError in error callback

-Edward

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


Re: webmail-SquirrelMail Fetcher In Python

2006-02-24 Thread Paul Rubin
<[EMAIL PROTECTED]> writes:
> I've been looking on the net for a program to gather e-mails from the
> squirrelmail interface, and haven't found any.
> My office only allows me to get e-mail access via webmail, at least
> when I'm outside of the corperate network.

Squirrelmail is an IMAP client so there must be an IMAP server on the
server side somewhere.  Why not talk to your IT dept about accessing
it with a normal mail client instead of messing with screen scraping
madness.  Squirrelmail is pretty messy and I gave up on it long ago.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: why don't many test frameworks support file-output?

2006-02-24 Thread kanchy kang

one question for you:
have anyone teach you how to listen to other's idea before?

this mail-list is only for exchanging idea, and aslo i provided my 
suggestion or "practice" or idea for test framework. if what i said is 
wrong, you can point it out as you like.

did i order anybody, or you?

you are the man not likely to listening to others.
if i would hire some, i don't think you are.
if you are some software's author, i would not use the software.
just because you are the man not likely to listening to others.

hehe



From: Scott David Daniels <[EMAIL PROTECTED]>
To: python-list@python.org
Subject: Re: why don't many test frameworks support file-output?
Date: Fri, 24 Feb 2006 07:43:20 -0800

kanchy kang wrote:
>
> I don't think redirecting stdout to a file is a good resolution.
Nobody is suggesting:
 python program.py >output
or
 program.py >output

What is being suggested is:
 import sys
 import module
 original, sys.stdout = sys.stdout, open('output', 'w')
 try:
 module.main()
 finally:
 result, sys.stdout = sys.stdout, original
 size = result.tell()
 result.close()
 print size, 'bytes written to file "output"'

If, however, you want everyone else to conform to your personal idea
of "best practices," then hire them and tell them to do it your way.

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


_
Don’t just search. Find. Check out the new MSN Search! 
http://search.msn.click-url.com/go/onm00200636ave/direct/01/


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

webmail-SquirrelMail Fetcher In Python

2006-02-24 Thread brandon.mcginty
Hi all,
I've been looking on the net for a program to gather e-mails from the
squirrelmail interface, and haven't found any.
My office only allows me to get e-mail access via webmail, at least when I'm
outside of the corperate network.
I'm wondering if anyone's found something like the screen-scrapers made for
the webmail system for MSOutlook, or another, farely simple, program that I
could edit to work with squirrelmail?
Sorry if I'm posting incorrectly or anything.
Also, I'm still a noob at python, so please go easy on me if this is very
obvious.

Thanks,
Brandon McGinty
[EMAIL PROTECTED]

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.1.0/269 - Release Date: 2/24/2006
 

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


Re: Pure python implementation of string-like class

2006-02-24 Thread bearophileHUGS
Maybe you can create your class using an array of 'L' with the array
standard module.

Bye,
bearophile

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


Re: list assignment using concatenation "*"

2006-02-24 Thread Steve R. Hastings
> if I do:
> 
> a = [ [0] * 3 ] * 3
> a[0][1] = 1
> 
> I get
> 
> a = [[0,1,0],[0,1,0],[0,1,0]]

The language reference calls '*' the "repetition" operator.  It's not
making copies of what it repeats, it is repeating it.

Consider the following code:

>>> a = []
>>> b = []
>>> a == b
True
>>> a is b
False
>>>
>>> a = b = []
>>> a is b
True
>>> a.append(1)
>>> a
[1]
>>> b
[1]


Each time you use [], you are creating a new list.  So the first code sets
a and b to two different new lists.

The second one, "a = b = []", only creates a single list, and binds both a
and b to that same list.

In your example, first you create a list containing [0, 0, 0]; then you
repeat the same list three times.

>>> a = [[0]*3]*3
>>> a
[[0, 0, 0], [0, 0, 0], [0, 0, 0]]
>>> a[0] is a[1]
True
>>> a[0] is a[2]
True

When you run [0]*3 you are repeating 0 three times.  But 0 is not mutable.
When you modify a[0] to some new value, you are replacing a reference to
the immutable 0 with some new reference.  Thus, [0]*3 is a safe way to
create a list of three 0 values.

When you have a list that contains three references to the same mutable,
and you change the mutable, you get the results you discovered.
-- 
Steve R. Hastings"Vita est"
[EMAIL PROTECTED]http://www.blarg.net/~steveha

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


list assignment using concatenation "*"

2006-02-24 Thread liquid
If I do:

a = [ [0,0,0], [0,0,0], [0,0,0] ]
a[0][1] = 1

I get:

a = [ [0,1,0],[0,0,0],[0,0,0] ]

as expected

But if I do:

a = [ [0] * 3 ] * 3
a[0][1] = 1

I get

a = [[0,1,0],[0,1,0],[0,1,0]]

AFAIC, "*" is supposed to generate multiple copies of the given token.
Therefore I thought both cases would be the same, but they are not.

Can anyone explain to me what exactly is going on in the second case?

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


Re: Playing with modules

2006-02-24 Thread jjcassidy
> You're going to have to create the home.base module somewhere. If you
> want to put in that some code that basically imports another module's
> namespace into the home.base module's namespace, then that may do what
> you want.

Thanks, Jonathon, but I think I've tried what you are saying. I've
tried doing this a couple different ways.

I suppose that what I could do is go somewhat explicit, and instead of
trying to exploit the natural import language, create a method for this
such as home.use('base') which could use even use the tracestack, get
the current frame's globals and stick the entry { 'base':  }
into the currect scope and just make that part of the "API".

But I was wondering whether I could fool or "backend" the normal import
mechanism. Even in Java, I can write my own class loader which can
quick compile Java snippets and load the anonymous byte code.

Thanks, 

John

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


PyGTK + Glade = weird problem

2006-02-24 Thread sapo
Hi all, i ve started learning pygtk with glade, i m just making some
test stuff. but i got some problems with simple things.

I designed 2 windows on glade, then exported it and loaded in the
python script, the second window is hidden by default, then i wrote a
function to show it up, ok it shows, them i wrote another function to
hide it.. ok it hides...

But in the second time i show the window.. the window appear EMPTY,
with just the title and NOTHING inside..

This is well explained here:

http://ubuntuforums.org/showthread.php?p=768219

Hope someone can help me, i tried irc, forums, googled a lot.. but
nothing solves my problem, even rewriting the code by hand results on
the same thing!

thanx for any help

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


Pure python implementation of string-like class

2006-02-24 Thread Akihiro KAYAMA

Hi all.

I would like to ask how I can implement string-like class using tuple
or list. Does anyone know about some example codes of pure python
implementation of string-like class?

Because I am trying to use Python for a text processing which is
composed of a large character set. As the character set is wider than
UTF-16(U+10), I can't use Python's native unicode string class.

So I want to prepare my own string class, which provides convenience
string methods such as split, join, find and others like usual string
class, but it uses a sequence of integer as a internal representation
instead of a native string.  Obviously, subclassing of str doesn't
help.

The implementation of each string methods in the Python source
tree(stringobject.c) is far from python code, so I have started from
scratch, like below:

def startswith(self, prefix, start=-1, end=-1):
assert start < 0, "not implemented"
assert end < 0, "not implemented"
if isinstance(prefix, (str, unicode)):
prefix = MyString(prefix)
n = len(prefix)
return self[0:n] == prefix

but I found it's not a trivial task for myself to achive correctness
and completeness. It smells "reinventing the wheel" also, though I
can't find any hints in google and/or Python cookbook.

I don't care efficiency as a starting point. Any comments are welcome.
Thanks.

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


Re: Playing with modules

2006-02-24 Thread Jonathan Gardner
You're going to have to create the home.base module somewhere. If you
want to put in that some code that basically imports another module's
namespace into the home.base module's namespace, then that may do what
you want.

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


Re: python-list/python-dev quoting style

2006-02-24 Thread Michael Hoffman
[me]
>>Does anyone have a script to convert more conventional USENET quoting 
>>style... to the commonly used python-dev/python-list style...

[Aahz]
> Blech.  Stick with the standard Usenet quoting style for both!

I think this style is *much* clearer and cleaner. It does require a lot 
more hand editing though, although this encourages more judicious quoting.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module written in C does not repond to Ctrl-C interruption.

2006-02-24 Thread Bo Peng
Daniel Dittmar wrote:
> 
> You could set up your own signal handler when entering the C extension. 
> This should abort the extension (tricky) and call the Python signal 
> handler.

This can be done under linux using things in signal.h but I am not
sure whether or not there is a portable way to do it (max, win32).
Does anybody know a quick way under windows?

Bo

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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-02-24 Thread Jonathan Gardner
On database portability...

While it is noble to try to have a generic interface to these
libraries, the end result is that the databases are always different
enough that the interface just has to work differently. My experience
in going from one database to another is that you should revisit your
entire database interface anyway. (I remember going from Sybase to
Oracle when we had Perl's DBI way back when. It was still very, very
messy.)

So, pick a good module, learn it inside and out, and plan on using a
completely different module if you use a different database, with
perhaps at least a slightly different interface.

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


Re: How to move optparse from main to function?

2006-02-24 Thread Jason Drew
You're welcome!

As usual, each of us is free to write the code whichever way works best
for the particular problem at hand. That's why the module documentation
often avoids advocating here-is-the-one-best-way-to-do-it.  I just like
sticking all the option setup stuff in a single function because it's
conceptually all the same and it makes the main() function or whatever
read shorter. It's partly down to experience, what little of it I can
claim.

Good luck!

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


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread Larry Bates
[EMAIL PROTECTED] wrote:
> Hi all,
> 
> I've spent all morning trying to work this one out:
> 
> I've got the following string:
> 
> 04/01/2006Wednesday 09:1412:4412:5017:5808:14
> 
> from which I'm attempting to extract the date, and the five times from
> into a list. Only the very last time is guaranteed to be there so it
> should also work for a line like:
> 
> 03/01/2006TuesdayAnnual_Holiday08:00
> 
> My Python regular expression to match that is currently:
> 
> digs = re.compile(
> r'(\d{2}\/\d{2}\/\d{4}).*?(?:(\d+\:\d+)).*$' )
> 
> which first extracts the date into group 1
> then matches the tags between the date and the first instance of a time
> into group 2
> then matches the first instance of a time into group 3
> but then group 4 grabs all the remaining string.
> 
> I've tried changing the time pattern into
> 
> (?:(\d+\:\d+))+
> 
>  but that doesn't seem to mean "grab one or more cases of the previous
> regexp."
> 
> Any Python regexp gurus with a hint would be greatly appreciated.
> 
> M@
> 
This works:

import BeautifulSoup

test = '04/01/2006' \
   'Wednesday'  \
   ' ' \
   '09:14'  \
   '12:44'  \
   '12:50'  \
   '17:58'  \
   ' ' \
   ' ' \
   ' ' \
   ' ' \
   '08:14'

c=BeautifulSoup.BeautifulSoup(test)
times=[]
for i in c.childGenerator():
if i.contents[0] == " ": continue
times.append(i.contents[0])

date=times.pop(0)
day=times.pop(0)

print "date=", date
print "day=", day
print "times=", times

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


Optimize flag question

2006-02-24 Thread Olivier Langlois








Hi,

 

This is my first post on the list. I played with the –O
flag option and I found the hard way that it was breaking the scripts I am
using because they rely on the assert statement that the optimize flag remove. From
there, I tried to find more information on the effect that this flag has on
scripts but I have not found much…

 

So my question is: what are the ‘optimizations’
that the Python interpreter is doing when you specify the optimize flag and is
there anything I should be cautious about when using it?

 

Thank you,

Olivier Langlois

http://www.quazal.com

 






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

Re: Multiple versions of Python / PythonWin on the same machine?

2006-02-24 Thread Fuzzyman

[EMAIL PROTECTED] wrote:
> I have Python 2.1 / PythonWin 2.1 installed on my machine because I
> need it for use with ESRI's ArcGIS Desktop software, but I want to play
> with a more recent version of Python.
>
> Is it safe to install more than one version of Python / PythonWin on
> the same machine? I don't want the latest release to wipe out the old
> one.

An alternative technique is to use Movable Python which doesn't need to
be installed. This gives you a portable programming environment for
Python 2.4 (or 2.3 or 2.2) which  you can carry from machine to machine
on a USB key.

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

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

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


Re: Is Forth for real?

2006-02-24 Thread rickman

[EMAIL PROTECTED] wrote:
> rickman wrote:
> > The original post seems to be missing, but my answer to the title
> > question is, No, Forth is not real.
> 
> Not for real, for Integer.

:-)

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


Re: Multiple versions of Python / PythonWin on the same machine?

2006-02-24 Thread Olivier
[EMAIL PROTECTED] a écrit :
> 
> Is it safe to install more than one version of Python / PythonWin on
> the same machine?

Sure, it is, just specify a different path for the installer. You'll 
probably want to create two scripts python21.bat and python24.bat and 
put them in your path to launch the relevant version at will.

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


Problem solved: Re: time.sleep(1) sometimes runs for 200 seconds under windows

2006-02-24 Thread Paul Probert
Thanks everyone for your help.
   It was the "Abouttime.exe" program, a time synch utility. To get the 
problem, you have to run it as a service, and possibly it has to have 
trouble connecting to its time servers. It would cause time.sleep(1) to 
sometimes block for 200 seconds. Not "about" 200 seconds but always 
within 199 to 202 seconds. Very strange, but it is good to have the 
problem gone.

Enjoy the weekend!

Paul Probert
University of Wisconsin

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


Re: Best python module for Oracle, but portable to other RDBMSes

2006-02-24 Thread Olivier
[EMAIL PROTECTED] a écrit :
> I'm a little confused about what's out there for database modules at:
> 
>   http://python.org/topics/database/modules.html
> 
> What I'd like to do is use Python to access an Oracle 9.X database for
> exporting a series of tables into one aggregated table as a text file,
> for import into a mainframe database. The catch is that I'd like to
> write code that wouldn't need to be changed (much) if we switched from
> Oracle to some other RDBMS (still need to export out as a text file for
> import to the mainframe database.
> 
> Looks like I'd probably want to use something that conforms to the
> DB-API 2.0. 


You want to use cx_Oracle :

http://www.python.net/crew/atuining/cx_Oracle/index.html

which is nowadays the very best python Oracle driver.

Olivier



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


Re: "Temporary" Variable

2006-02-24 Thread darthbob88
Reply to all: I realize that naming a variable "spam" is not entirely
kosherized. It was originally named secret, but I renamed it in a fit
of whimsy. The language is named after Monty Python's Flying Circus, is
it not? Remember the Spam Sketch.
http://en.wikipedia.org/wiki/Spam_sketch
I thank you for finding the problem; I thought it might involve string
v int comparisons when Comrade D'Eprano's code went wonky. Many thanks,
and good luck to you.
PS: As for the inappropriate naming, the Swedes tried to sell their
vacuums under the motto "Nothing sucks like an Electrolux."

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


Multiple versions of Python / PythonWin on the same machine?

2006-02-24 Thread dananrg
I have Python 2.1 / PythonWin 2.1 installed on my machine because I
need it for use with ESRI's ArcGIS Desktop software, but I want to play
with a more recent version of Python.

Is it safe to install more than one version of Python / PythonWin on
the same machine? I don't want the latest release to wipe out the old
one.

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


Best python module for Oracle, but portable to other RDBMSes

2006-02-24 Thread dananrg
I'm a little confused about what's out there for database modules at:

  http://python.org/topics/database/modules.html

What I'd like to do is use Python to access an Oracle 9.X database for
exporting a series of tables into one aggregated table as a text file,
for import into a mainframe database. The catch is that I'd like to
write code that wouldn't need to be changed (much) if we switched from
Oracle to some other RDBMS (still need to export out as a text file for
import to the mainframe database.

Looks like I'd probably want to use something that conforms to the
DB-API 2.0. On the module list, I see DCOracle2, but it hasn't been
updated since 2001. Anyone here use this module, and does it work with
both Oracle 9.2 and Oracle 10g? Are there other DB-API 2.0 compliant
modules I should be looking at? What are the advantages and
disadvantages of the ones that can access Oracle 9.2 and Oracle 10g
databases?

Thanks in advance.

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


PyWeek Python Game Programming Challenge, The Second!

2006-02-24 Thread richard
The date for the second PyWeek challenge has been set: Sunday 26th March
to Sunday 2nd April (00:00UTC to 00:00UTC). 

The PyWeek challenge invites entrants to write a game in one week from
scratch either as an individual or in a team. Entries must be developed
in Python, during the challenge, and must incorporate some theme chosen
at the start of the challenge.


REGISTRATION IS NOW OPEN --

To register for the challenge, visit:

   http://www.pyweek.org/

Some of the challenge website isn't finished yet. I hope to have it completed 
in the next week. This includes management of team entries.


PLANNING FOR THE CHALLENGE --

Make sure you have working versions of the libraries you're going to use.
The rules page has a list of libraries and other resources.

Make sure you can build packages to submit as your final submission (if
you're going to use py2exe, make sure you know how to use it and that it
works).

If you don't have access to Linux, Windows or a Mac to test on, contact
friends, family or other competitors to find someone who is able to test
for you.


-- 
Visit the PyWeek website:
  http://www.pyweek.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption

2006-02-24 Thread dirvine
perfect thanks a lot and I can be cross platform too. cool

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


Re: A C-like if statement

2006-02-24 Thread Paul Rubin
"Kay Schluehr" <[EMAIL PROTECTED]> writes:
> Hmm. A statement has side-effects but it returns no value. And yes, you
> can create a name within an expression producing a value in Python,
> using a list/generator comprehension. The solution to Bob's problem
> would look like this:
> 
> if (I for I in (a.find("3"),) ) != -1:
>  print "It's here: ", I
> else:
>  print "No 3's here"

I think that works for list comprehensions but not generator
comprehensions.  With generator comprehensions, the index variable's
scope is limited to the comprehension.  With list comprehensions
there's a wart in that the index variable is still around afterwards.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.sleep(1) sometimes runs for 200 seconds under windows

2006-02-24 Thread Bryan Olson
Paul Probert wrote:
[...]
> Its happening roughly 4 times a day total on our 20 machines, ie about 
> once every 5 days on a given machine.

Do they all have similar anti-virus programs? Some of those can
freeze out other tasks from time to time. Just one more candidate.


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


Reading from socket file handle took too long

2006-02-24 Thread Etienne Desautels

Hi,

I'm working on project where I need to grab video from an Axis IP  
camera. This camera send a stream of a multipart message on HTTP. I  
write this code (at the bottom of the message) to read and uncompress  
each jpeg images. I call nextFrame() 24 times per seconds (or every  
0,0416 sec.) to read the next image that arrived.

Everything works well but one thing. My problem is that running  
nextFrame() took, most of the time, more then 0,0414 sec. so my video  
is lagging. I monitor every call and I found that the culprit is when I  
read from the socket file handle. It's the only bottleneck in my code.  
I try different approaches to the problem but I always hit the same  
problem.

I don't think it's normal that read() take more then 0,04 sec to read  
1000 bytes from memory (the socket file handle). How can I avoid this  
problem ?

I'm on Linux 2.6 (last Ubuntu) with python 2.4 on P4 2.3.

Thanks

Etienne


CODE
 


class Axis:
url = ""
user = "user"
password = "password"
header = {}
header["Authorization"] = "Basic " + b64encode(user + ":" + password)
http = urllib2.HTTPHandler()
state = 0
limit = 1000
imageData = None
sizeX = 352
sizeY = 240
fps = 24
compression = 25

def startGrab(self):
try:
url = self.url + "/axis-cgi/mjpg/video.cgi?resolution=" 
+  
str(self.sizeX) \
+ "x" + str(self.sizeY) + "&compression=" \
+ str(self.compression) + "&req_fps=" + str(self.fps)
req = urllib2.Request(url, None, self.header)
self.fh = self.http.http_open(req)
self.buffer = ""
self.state = 1
except:
self.state = 0

def stopGrab(self):
self.fh.close()
self.state = 0

def nextFrame(self):
if self.state:
try:
temp = self.fh.read(self.limit) # <-- TAKE A 
LOT OF TIME
self.buffer += temp
boundary = self.buffer.find("\r\nContent-Type: 
image/jpeg\r\n") + 30
if boundary >= 30:
end = 
self.buffer.find("\r\n\r\n--myboundary", boundary) + 2
if end >= 2:
image = 
Image.open(StringIO(self.buffer[boundary:end]))
self.imageData = 
image.tostring("raw",image.mode,0,-1)
self.buffer = self.buffer[end:]

except:
pass

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


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread plahey
Doesn't this do what you want?

import re

DATE_TIME_RE =
re.compile(r'((\d{2}\/\d{2}\/\d{4})|(\d{2}:\d{2}))<\/td>')

test = '04/01/2006' \
   'Wednesday'  \
   ' ' \
   '09:14'  \
   '12:44'  \
   '12:50'  \
   '17:58'  \
   ' ' \
   ' ' \
   ' ' \
   ' ' \
   '08:14'

out = [m[0] for m in DATE_TIME_RE.findall(test)]

for m in out:
print m

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


unsubscribe

2006-02-24 Thread Mandy Owens
Can you please unsubscribe me from this list?  

Thank you,

Mandy Owens
JNetDirect
(703) 880-3842
www.jnetdirect.com
 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On
Behalf Of Steve Holden
Sent: Friday, February 24, 2006 4:16 PM
To: python-list@python.org
Subject: PyCon blog

Relaxing in the complete absence of any responsibility for the
organization, I am for the first time trying to record impressions of
each of the PyCon sessions I attend in my blog.

   http://holdenweb.blogspot.com/

Any reactions will be received with interest.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: a little more help with python server-side scripting

2006-02-24 Thread John Salerno
Paul Boddie wrote:

> To sum up:
> 
>  1. Copy the three line "CGI with Python" example, save it as
> yourfile.py, upload it, test it. If it works, celebrate and move
> on to step 2. If it doesn't, move on to step 2 anyway. ;-)
> 
>  2. Copy the Web page example from the Microsoft link, save it
> as yourfile.asp and also as yourfile.html, upload them, test
> them. If one of them works, celebrate and note down whether
> you should be using .asp or .html on the end of your filenames.
> If both of them work, celebrate more vigorously! If neither work,
> try and tell us what went wrong.

Thank you. I'm going to study your response and give it all a try!  :)
-- 
http://mail.python.org/mailman/listinfo/python-list


PyCon blog

2006-02-24 Thread Steve Holden
Relaxing in the complete absence of any responsibility for the 
organization, I am for the first time trying to record impressions of 
each of the PyCon sessions I attend in my blog.

   http://holdenweb.blogspot.com/

Any reactions will be received with interest.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: remote module importing (urlimport)

2006-02-24 Thread Jure Vrscaj
ajones wrote:

>What plans do you have for security in this? I would think that in
>order to trust this over the network you would at least need a
>certificate identifying the server as well as some method of verifying
>package contents.
>
>Either way, cool stuff.
>
>  
>
I'm currently fighting with recursive import problems, haven't really 
thought of security that much... I guess if this supported ssl layer 
with http and/or secure ftp, providing that you trust the machine 
hosting your modules, it would be a start (for hobby use).

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


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread Paul McGuire
Here's a (surprise!) pyparsing solution.  -- Paul
(Get pyparsing at http://pyparsing.sourceforge.net.)

data = [
"""04/01/2006Wednesday 09:1412:4412:5017:5808:14""",
"""03/01/2006TuesdayAnnual_Holiday08:00"""
]

from pyparsing import *

startTD,endTD = makeHTMLTags("TD")
startTD = startTD.suppress()
endTD = endTD.suppress()
dayOfWeek = oneOf("Sunday Monday Tuesday Wednesday Thursday Friday
Saturday")
nbsp = Literal(" ")
time = Combine(Word(nums,exact=2) + ":" + Word(nums,exact=2))
date = Combine(Word(nums,exact=2) + "/" + Word(nums,exact=2) + "/" +
Word(nums,exact=4))

entry = ( startTD + date.setResultsName("date") + endTD +
  startTD + dayOfWeek.setResultsName("dayOfWeek") + endTD +
  startTD + ( Suppress(nbsp) |
Word(alphanums+"_").setResultsName("name") ) + endTD +
  OneOrMore(startTD + (Suppress(nbsp) | time) + endTD
).setResultsName("dates")
  )

for d in data:
res = entry.parseString(d)
print res.date
print res.dayOfWeek
print res.name
print res.dates
print


Returns:

04/01/2006
Wednesday

['09:14', '12:44', '12:50', '17:58', '08:14']

03/01/2006
Tuesday
Annual_Holiday
['08:00']

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


Re: execfile error exception line number?

2006-02-24 Thread André

Brian Blais wrote:
> Hello,
>
> I'd like to do the following:
>
> import sys
> try:
>   execfile("somefile.py")
> except:
>   s=sys.exc_info()
>   print "Error '%s' happened on line %d" % (s[1],s[2].tb_lineno)
>
How about this:
=== input: 
try:
execfile("somefile.py")
except Exception, info:
print "Error '%s' happened on line %d" % (info[0], info[1][1])
 output: 
Error 'invalid syntax' happened on line 3
=== somefile.py is =
print 3
print 3
prnt 5
print 6
=


André

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


Quality Labs release PDbSeed - Database-driven testing in Python

2006-02-24 Thread Mandy Owens



 Exciting new announcement in the 
Python community!  Read more information about PDbSeed and 
Quality Labs @ www.qualitylabs.org/pdbseed/Quality Labs, an open-source repository 
that hosts projects which address software quality, just released PDbSeed, a database seeding and 
verification tool written in Python.  PDbSeed performs an operation, such 
as DELETE or INSERT, on a database using an XML dataset file for 
input/output.PDbSeed is useful in unit tests that interact with a 
database.  Typically, one would use PDbSeed in the unit tests setup and 
teardown to ensure that the database's state is consistent across execution of 
tests.PDbSeed:is an open-source 
LGPL-licensed projectis written in Pythonhas been tested with Python 
version 2.3 and 2.4supports MySQLborrows many ideas from DbUnit, and makes them available for 
PythonDownload version 0.7 here. 

 
Please let me know if you have any additional 
questions regarding this annoucement.
Kind Regards,
Mandy Owens
Marketing Manager
JNetDirect
(703) 880-3842
www.jnetdirect.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Using ElementTree to tidy up an XML string to my liking

2006-02-24 Thread Heikki Toivonen
[EMAIL PROTECTED] wrote:
> Yes I am but, I'm using a DOM Serializer in Firefox which for some
> reason turns myCamelNames into MYCAMELNAMES for the nodenames. I'll
> therefore need to control the case-spelling of these things as I'm
> formatting the XML string.

I am almost certain there is something wrong you are doing in Mozilla if
that is happening. My first guess is that you are really doing HTML even
thought you think you are doing XML, and therefore Mozilla converts your
stuff to uppercase. Without seeing the source it is hard to say. I would
advice you write to the Mozilla forums for advice on that.

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


Re: ls files --> list packer

2006-02-24 Thread kpp9c
that is nice but the little further wrinkle, which i have no idea
how to do, would be to have the contents of each directory packed into
a different list since you have no idea before hand how many lists
you will need (how many subdirs you will enounter)  ... well that is
where the hairy part comes in...

-kp--

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


Re: a little more help with python server-side scripting

2006-02-24 Thread Paul Boddie
John Salerno wrote:
>
> Well, I appreciate the help. I'm trying to figure it out, but it seems
> like with each new post, there is some new technology being mentioned or
> new method to do what I'm trying to do.

Let's just consolidate what we've learned here. Your provider says that
you can serve up two different things; the first one being...

 bits of Python code that are embedded within an HTML file

... (this being from a message you quoted), although they don't really
make themselves totally clear, because they then say...

 that after mapping .html will no
 longer be call as normal html file to be loaded on the browser as the
 IIS server now will parse .html with the Python executable engine.
 Your user will need to embed the Python coding into each of the .html
 file in order for it to be load properly on the browser.

...which sounds like ASP to me, noting that the "Python executable
engine" is probably the Active Scripting engine which can work with
Python. So let's call that the "ASP with Python" route.

Now, the other thing they said you could serve up are Python scripts:

 Save your python script as .py file on the wwwroot and
 you may call the scripts using http://www.yourdomain.com/yourfile.py

What these scripts have to do when they run is to output some text
which consists of some headers and the text of a Web page that will
appear in your browser (and you can test them yourself before you
upload them by seeing if they output the expected stuff when you run
them). Let's call this the "CGI with Python" route.

> I guess I'm not well-versed
> enough in Python to even attempt this kind of thing yet. I didn't
> realize it would be this complicated. I guess I hoped it would be as
> easy as including some PHP code and letting the server detect the .php
> extension and handle it all. I'm going to try to solidify the basics
> first, then move on to web programming a little later.

Well, guessing at your configuration from what the support people have
said, it may be simpler to just test things with the "CGI with Python"
option first. So, if you take a CGI program such as one from this
page...

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52220

...like this one...

#!/usr/bin/python
import cgi
cgi.test()

...save it as yourfile.py, upload it as instructed above, and then
visit your site (also as instructed above), you should see some test
output from Python. (Again, you can check the output by running
yourfile.py locally and seeing that it prints out some HTML to the
screen.)

If you want to do the PHP-style thing - the "ASP with Python" option -
then you probably need to make a Web page, similar to that described
here...

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494

...save it as yourfile.html (given what they said in their response to
you, although most people thought it should be yourfile.asp - why not
try both?!), upload it, and then visit your site (as instructed above,
but remembering that you're looking for a file called yourfile.html or
yourfile.asp instead of yourfile.py).

If the yourfile.html thing doesn't work but the yourfile.asp does, then
forget about what they said about HTML files and .html and remapping
things: just call your "ASP with Python" files names with .asp on the
end.

To sum up:

 1. Copy the three line "CGI with Python" example, save it as
yourfile.py, upload it, test it. If it works, celebrate and move
on to step 2. If it doesn't, move on to step 2 anyway. ;-)

 2. Copy the Web page example from the Microsoft link, save it
as yourfile.asp and also as yourfile.html, upload them, test
them. If one of them works, celebrate and note down whether
you should be using .asp or .html on the end of your filenames.
If both of them work, celebrate more vigorously! If neither work,
try and tell us what went wrong.

Good luck!

Paul

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


Re: What are COM-enabled applications?

2006-02-24 Thread Cameron Laird
In article <[EMAIL PROTECTED]>,
Duncan Booth  <[EMAIL PROTECTED]> wrote:
>Cameron Laird wrote:
>
>> Python has good COM abilities.  While, to my surprise, I just
>> realized that I'm unaware of anyone having put together a COM
>> "explorer" with Python, it would be a straightforward project.
>
>Don't the tools that come with Python's COM support do enough for you?
>
>...\lib\site-packages\win32com\client\combrowse.py for example. (Or inside 
>PythonWin it is on the Tools menu).

I was quibbling about the difference between a polished application
and a toolkit; please, I don't want anyone to think that I AT ALL
disparage the achievement of win32.  

Another recommendation for the original poster:  http://www.python.org/windows/win32com/QuickStartClientCom.html >.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyQt - multiple window instances?

2006-02-24 Thread gregarican
Diez B. Roggisch wrote:

> > The window isn't being created as a new class instance or anything.
>
>
> Yes it is. QWidget() creates a new instance of QWidget.
>
>  > The
>
>
>
> > main class is the application main window as a whole and this
> > particular window is just part of that class. I have typed data into
> > the window, then tried to open up a new window. But when I do the
> > window where I have typed data disappears and is replaced by a new
> > window that's blank. What's the easiest way to keep a reference to the
> > old window?
>
>
> By putting it into a list for example?
> 
> Diez 

Perfect! Thanks for the tip. That worked perfectly.

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


Trolling for New Web Host . . .

2006-02-24 Thread Ben Wilson
I've had the same web host (imhosted.com) for the past three years, and
have had decent service. However, I'm also trying to learn Python the
hard way--by doing. So, I figured I'd write a few Python CGIs
(non-Zope). Unfortunately, my web host does not have mod_python. They
only way I can run a python script is by using the .cgi extension. I'm
not sure if I want to stick with my host and just call my apps
index.cgi, or if I should move to a new server. If I were to move to a
new server, which would you recomend, and why?

Regards,
Ben Wilson

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


Re: Exception not raised

2006-02-24 Thread Diez B. Roggisch
> This code are inside a method into class that have no try/except. And 
> called from a method inside a wx.Frame derivate. The other strange thing 
> is that if I try the same code just before the "caller" to that method, 
> it raise an exception:

So maybe the C-layer of wx in-between doesn't propagate the exception for 
whatever reason? Fact is: pythons 
exception-handling is core part of the language and an error in there 
_extremely_ improbable . So I suggest you cut down 
your example until it is self-contained with only a few dozen lines and still 
produces your observed behavior. Otherwise 
no one will be able to help you.

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


Re: Is python very slow compared to C

2006-02-24 Thread igouy

Magnus Lycka wrote:
> Isaac Gouy wrote:
> >>I think it is wrong to call Python "very slow" just because it is slower
> >>than some other language or languages, for the same reason it would be
> >>wrong to describe the population of the UK as "very low" because 60
> >>million people is a smaller number than China or India's one billion plus.
> >>Doing so merely reinforces the premature optimizer's message that any
> >>language that isn't C (and sometimes Lisp) is "not fast enough".
> >
> > There was some context: Is python very slow compared to C?
>
> But that is a stupid context. It doesn't really tell us
> anything. Slow at what?

As I said: We can make /the missing context/ in the OP's question more
obvious...


>
> No one writes a program for the purpose of doing loops,
> comparing integers, setting up stack frames or jumping
> between instructions.
>
> The context for programming typically involves solving some
> problem or executing a function that matters to the user.
>
> It's just as database benchmarks. TPC C benchmarks tells us
> how fast a certain database is at performing TPC C benchmarks.
> Does that tell you anything about how fast it will be compared
> to competing products for your real world problem? Probably
> not. Which ever product you choose, you might end up with
> situations where a particular function is too slow. You can
> typically solve this either by changing the code or the
> configuration of the server. Sometimes you have to rethink
> your system and solve the problem in another way. Changing
> from e.g. DB2 to Oracle is unlikely to have more impact than
> these smaller changes. It's the same thing with most software
> development.
>
> >> The benchmark you pointed to are of limited use for application
> >> developers. (Their value to language designers is another story.)
> >
> > Limited use for what purpose?
>
> They are more or less useless for anyone who wants to decide
> what programming language to use in a real world situation.

Good that's more explicit.

One of the program contributors told me they do something quite similar
to fasta, k-nucleotide and reverse-complement in their real world
situation.

Isn't it possible that someone would look through The Computer Language
Shootout programs and decide that language X was unusable convoluted
gobbledegook?


> It's simply stupid to implement sorting algorithms in Python.
> It's there already. Solving Ackermann's is also rather far
> from what people typically want to achieve.

What "sorting algorithm" are you talking about?
There isn't one on http://shootout.alioth.debian.org/gp4/

Solving Ackermann's? Well if that was really the point then the
programs would be allowed to use memoization rather than simple
recursion.


> If people actually
> had the time and resources to create real software products,
> (i.e. things that take man-months to create) from the same
> spec, and developed e.g. ten programs each each ten different
> programming languages in cleanroom conditions, we'd probably
> learn something useful about the usefulness of a certain type
> of programs with certain programming languages in certain
> conditions, but only in these conditions. I'm rather certain
> that aspects such as team size, development methodology etc
> will influence the relative ratings of programs.
>
> I'm not saying that the typical toy benchmarks are completely
> useless. They might tell us things about particular language
> features that should be improved, or give us clues that a
> certain way of solving a particular problem etc, but they
> don't really help Joe Newbie Programmer who wants to write
> yet another web site toolkit.

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


Re: PyQt - multiple window instances?

2006-02-24 Thread Diez B. Roggisch
gregarican schrieb:
> The window isn't being created as a new class instance or anything.

Yes it is. QWidget() creates a new instance of QWidget.

 > The
> main class is the application main window as a whole and this
> particular window is just part of that class. I have typed data into
> the window, then tried to open up a new window. But when I do the
> window where I have typed data disappears and is replaced by a new
> window that's blank. What's the easiest way to keep a reference to the
> old window?

By putting it into a list for example?


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


Re: editor for Python on Linux

2006-02-24 Thread Ben Wilson
You know, I have that for Perl, but seem never to have set up folding
for Python. I must remedy this tonight.

Ben

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


Re: MySQLdb slow on MySQL 5

2006-02-24 Thread Jarek Zgoda
Magnus Lycka napisał(a):

> For those who don't know, Oracle bought a small Finnish
> company which developed the transaction-aware table-
> backend for MySQL. As far as I understand, this means
> nothing for GPL licensed MySQL installations, but if
> MySQL sells commercial MySQL-database with transaction
> support, I guess they need to share their incomes with
> Oracle now, and I suppose Oracle is completely in charge
> of future development and price setting for InnoDB. Of
> course, MySQL has support for swapping table backends,
> and the logical next step might be to use the major open
> source transactional low level database Berkeley DB,
> which is also dual licensed, and developed by SleepyCat.
> Unfortuantely, Oracle just bought them... I'm sure there
> are other ways out though. MySQL owns MaxDB, which was
> previously SAP DB, a derivate ot the German Adabas D.
> I'm not sure how easy it is to rip out the table back-
> end of that though. I guess it's not built to be a
> separate component.

They just hired Jim Starkey. Perhaps MySQL AB hopes he will write a
transactional engine for MySQL, as he previously wrote one for Interbase
(which is known to be one of the best a man could imagine).

Anyway, we got far off topic, so we better go somewhere else.

-- 
Jarek Zgoda
http://jpa.berlios.de/
-- 
http://mail.python.org/mailman/listinfo/python-list


Python/Spyce outputting

2006-02-24 Thread Kenny
I am accessing a database through python and displaying it through the
web using spyce. My goal is to get a table on my webpage that displays
the queries that I am doing but in a table format that looks good
rather than the raw text output. Is there a reference out there that
can help me do that?

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


Re: PyQt - multiple window instances?

2006-02-24 Thread gregarican
The window isn't being created as a new class instance or anything. The
main class is the application main window as a whole and this
particular window is just part of that class. I have typed data into
the window, then tried to open up a new window. But when I do the
window where I have typed data disappears and is replaced by a new
window that's blank. What's the easiest way to keep a reference to the
old window?

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


Re: A C-like if statement

2006-02-24 Thread Kay Schluehr

Roy Smith wrote:
> Bob Greschke <[EMAIL PROTECTED]> wrote:
> >I miss being able to do something like this in Python
> >
> >1f (I = a.find("3")) != -1:
> >print "It's here: ", I
> >else:
> >print "No 3's here"
> >
> >where I gets assigned the index returned by find() AND the if statement gets
> >to do its job in the same line.  Then you don't have to have another like
> >that specifically gets the index of the "3".  Is there a way to do this in
> >Python?
>
> It is a deliberate and fundamental design decision in Python that
> assignment is a statement, not an expression with side effects.  This
> means you often need an "extra" line compared to a classic C "assign
> and test" idiom such as you have above.  I, like you, often miss the
> compactness of the C idiom, but there it is.

Hmm. A statement has side-effects but it returns no value. And yes, you
can create a name within an expression producing a value in Python,
using a list/generator comprehension. The solution to Bob's problem
would look like this:

if (I for I in (a.find("3"),) ) != -1:
 print "It's here: ", I
else:
 print "No 3's here"


Kay

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


Re: PyQt - multiple window instances?

2006-02-24 Thread Diez B. Roggisch
gregarican schrieb:
> I have an PyQt app were I need one of the windows to be able to be
> opened more than one at a time. When I try to open it I only get one
> instance at the same time. The main class is the QWidget() class with a
> QGridLayout() displaying the various window components.
> 
> Is there a certain flag I need to set or different constructor I need
> to use to allow the window to be opened more than one at a time?

No. Must be something you're doing - I guess it might be that you should keep a 
reference to the old windows, otherwise 
they might go away when garbage-collected.

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


PyQt - multiple window instances?

2006-02-24 Thread gregarican
I have an PyQt app were I need one of the windows to be able to be
opened more than one at a time. When I try to open it I only get one
instance at the same time. The main class is the QWidget() class with a
QGridLayout() displaying the various window components.

Is there a certain flag I need to set or different constructor I need
to use to allow the window to be opened more than one at a time?

Here's a brief snippet of the code that displays the window:

def new_showing(self):
""" This method creates a new contact showing record. """

if self.flag == 'KNOWN':
try:
test_contact = self.entry_id
except:
QMessageBox.warning(self, "Qt CRAM", "There is no
contact record loaded.\nPlease select a contact record first.")
return

self.new_show_widget=QWidget()
self.new_show_widget.resize(240, 280)
self.new_show_widget.setCaption('Qt CRAM - Contact Showings')

# Define the Qt layout to be used for the window.
self.new_show_grid=QGridLayout(self.new_show_widget, 8, 2)

# bunch of widgets displaying stuff

self.new_show_widget.show()

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


Playing with modules

2006-02-24 Thread jjcassidy
I know that this is not particularly "pythonic", but I would like to
mess with modules a bit.

I would like to develop a modular module which allows different
services to plug themselves into the module and become the
implementation for a named module.

Say I have a suite of "cassidy.blah.blah.blah" modules. As it's not
really my intention to brand everything, I want to remap all these
modules as "home". Thus if someone (eventually) likes my code for
x, but does not want the whole cassidy avalanche, and just wants
something simple to do home.x, they can provide their own
implementation or create a wrapper class to existing functionality
which does the work.

My problem is that this code fails all the time that I have tried to do
this.

import home.base

Does anybody know of a way to "fool" python into thinking that my suite
is actually this neutrally named suite called "home"? 

Thanks, 

John

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


Re: How to send an email with non-ascii characters in Python

2006-02-24 Thread Sybren Stuvel
Lad enlightened us with:
> and can give me an example of  Python code that can send such
> email??

Not really, but I'm sure this will help you. In fact, my last name has
an umlaut on the 'u'. This is the From header in my emails, encoded in
Latin-1:

From: Sybren =?iso-8859-1?Q?St=FCvel?= <[EMAIL PROTECTED]>

You must ensure that there are no spaces in the specially encoded
part. So if I'd encode my first name too, it would be:

=?iso-8859-1?Q?Sybren?= =?iso-8859-1?Q?St=FCvel?=

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: MySQLdb slow on MySQL 5

2006-02-24 Thread Magnus Lycka
Gerhard Häring wrote:
>> Oh well, Oracle will probably kill MySQL soon. 
> 
> Did you read too much Slashdot to spread such FUD?

:) I guess I should have used half a smiley, since I
was only half serious. Buying InnoBase OY was...an
interesting move. Cheap too! It's a while since I visited /.

For those who don't know, Oracle bought a small Finnish
company which developed the transaction-aware table-
backend for MySQL. As far as I understand, this means
nothing for GPL licensed MySQL installations, but if
MySQL sells commercial MySQL-database with transaction
support, I guess they need to share their incomes with
Oracle now, and I suppose Oracle is completely in charge
of future development and price setting for InnoDB. Of
course, MySQL has support for swapping table backends,
and the logical next step might be to use the major open
source transactional low level database Berkeley DB,
which is also dual licensed, and developed by SleepyCat.
Unfortuantely, Oracle just bought them... I'm sure there
are other ways out though. MySQL owns MaxDB, which was
previously SAP DB, a derivate ot the German Adabas D.
I'm not sure how easy it is to rip out the table back-
end of that though. I guess it's not built to be a
separate component.

Anyway, it's annoying with a product that so clearly do
things their own way, instead of the right way. It would
have been one thing if it had been something in a niche
of its own like SQLite, or something novel, such as an
object-relational database ten years ago, but what they've
done is often just non-standard without being better, and
in many aspects buggy and lacking features.

 From a market point of view, I do think that they have
been refreshing, and it was probably good for PostgreSQL
to have competition too, but I would have liked a somewhat
stronger interest in the SQL standard from those guys.

 From this perspective I don't think Monty and Mårten are
better than Bill and Bullmer over in Redmond. They create
vendor lock-in, and a warped view of how things are supposed
to work among many naive developers. While it's obviously
more of an industrial strength product (in its own way) it
does remind me a lot of MS Access / JET. "Let's do something
similar to SQL, and call it SQL, but don't bother looking
at any standards, let's just code what pops up in our minds."

It's one thing if Oracle fails to comply to all standards,
with strange things as treating empty strings as nulls. At
least they can claim that their product had a large installed
base before the standards were set... Hm... That's actually
a rather crappy excuse too... That's what varchar2 was for.

> MySQL 5 could be described as one, according to the feature list, and if 
> you use a transactional table type.

Neither you nor I choose DBMS by ticking off checkboxes
in a list...

> I myself won't bother with it because PostgreSQL is still more 
> featureful that MySQL 5, has a much longer track record with these 
> features proven stable and a more liberal licensing.

How surprising! ;^) Me too by the way... I've had quite a
happy cooperation with Oracle, Informix, Ingres, Mimer,
Sybase and DB2 too. They all have their problems, but I
prefer them to MySQL any day.
-- 
http://mail.python.org/mailman/listinfo/python-list


ReadEventLog doesn't return, CPU usage increases

2006-02-24 Thread Jeff Quandt
Title: ReadEventLog doesn't return, CPU usage increases






This is running Python 2.3 on windows 2003/windows xp.


I have written a script to display and filter the Win32 event log in a scrolling list to the command line (it also does some summary tasks).  It uses the win32evtlog.ReadEventLog to seek or scan the event log based on filter parameters.  It is supposed to run until the user kills it, so there are repeated calls to ReadEventLog.  

The problem is that after the script has run from some time (usually several hours), the call to ReadEventLog seems to hang and the CPU usage increases dramatically (from nil to 30-50%).  The script does not exit this stage, and has to be broken manually with Ctrl-C.  I've tried closing and reopening the event log handle after it has been open for an hour.  I've added explicit calls to the garbage collector.  Neither helped at all.

I realize that this is an API call, so it may not be a python issue.  But I have seen this type of behavior on other scripts (not event loggers), but they were test/debug tools and weren't important enough to track down the issue.

Any help would be appreciated.


code example:


    def OpenLog( self ):

    #

    #open event log

    #

    self.mHandle  = win32evtlog.OpenEventLog( self.mComputer

    , self.mLogType

    )

    if not self.mHandle:

    raise ValueError, "invalid handle"


    self.mLogOpenTmst = time.time()


    def CloseLog( self ):


    win32evtlog.CloseEventLog( self.mHandle )


    def ReadLog( self ):


    self.mFlags = win32evtlog.EVENTLOG_FORWARDS_READ|win32evtlog.EVENTLOG_SEEK_READ

    vEventScon  = win32evtlog.ReadEventLog( self.mHandle

  , self.mFlags

  , self.mLogOffset

  )

    #

    # if not found, try again in 5 seconds

    #

    if not vEventScon:


    #

    # If we've had the log open for more than 1 hour, dump it and reopen

    #

    if ( time.time() > (self.mLogOpenTmst + 3600) ):

    self.CloseLog()

    self.OpenLog()


    time.sleep( 5 )

    return bOk


    #

    # snip...

    # manipulate event records here

    #


#

# main

#

OpenLog

Ok = 1

while Ok:

    Ok = ReadLog()

CloseLog()


Jeff



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

Re: Exception not raised

2006-02-24 Thread Michele Petrazzo
Michele Petrazzo wrote:
> Michele Petrazzo wrote:
>> Hi list, I have a strange error on my software on win 2k/xp and
>> debian 3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython:
> 

Opss, I forgot some words :)

> Just for give evidence to my _failed_ tests, my a debugger (eric3), it

with a debugger (not my a debugger)

> see the exception, so it break with a KeyError!
> And the same code, no!

And the same code, exceute inside a terminal, no...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: time.sleep(1) sometimes runs for 200 seconds under windows

2006-02-24 Thread Roel Schroeven
Dennis Lee Bieber schreef:
> On Fri, 24 Feb 2006 08:44:49 -0600, Paul Probert <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
>> This is now our leading suspect. All the affected machines have 
>> "abouttime.exe" running as a service, something our sysadmin put in a 
>> few years ago. We are currently disabling this and now waiting for the 
>> proof.
> 
>   Hmmm, I wonder how compatible that is with WinXP -- since XP already
> has an internet time synch built into the date/time preferences page
> (need admin privs to view).

It's easily disabled. I disable it and use NTP for Windows instead on 
machines I control since it works much better.

>   Pre-XP may not have had such...

Windows 2000 had it too, but there was no GUI to configure it; you had 
to manually edit the registry.

-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

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


Re: Exception not raised

2006-02-24 Thread Michele Petrazzo
Michele Petrazzo wrote:
> Hi list, I have a strange error on my software on win 2k/xp and
> debian 3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython:

Just for give evidence to my _failed_ tests, my a debugger (eric3), it
see the exception, so it break with a KeyError!
And the same code, no!

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


Re: KPanelApplet using Python

2006-02-24 Thread Varun Hiremath
On Fri, 24 Feb, 2006 at 09:55:59AM -0800, David Boddie wrote:
> Varun Hiremath wrote:
> 
> > I was wondering if there is any way to make KDE PanelApplets
> > using Python. I have made a small window using Qt, kdeui nad
> > kdecore libs. Now I want to add it to the KDE kicker. Can I
> > get any help regarding this matter.
> 
> The other responses in this thread have covered solutions that use
> the system tray, and you may want to try something like that with
> the KSystemTray class in kdeui. It's available in PyKDE, so you
> shouldn't have any trouble adding new items to kicker that way.
> 
> However, you asked specifically about Panel Applets. Unfortunately,
> they are a lot more difficult to implement in Python because you
> need to write a library in C++ to load them. Some of us in the
> PyQt/PyKDE community did some work towards that, and had working
> applets but, as far as I know, they don't work with recent releases.
> 
> You might get some additional help or advice about this if you try
> mailing the PyKDE list:
> 
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
> 
> Good luck!
> 
> David

Hi,
Actually I want to fetch some text from a HTML Page and then display it using 
KPanelApplet.I am using BeautifulSoup for Parsing the HTML Page which I can do 
easily in Python . Now I don't want to switch to C++ because Parsing there will 
be tough. Can you suggest me some other way to do this.

Thank You


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

-- 
---
Varun Hiremath
461, Jamuna Hostel
IIT Madras,
Chennai - 600 036
mob : +919840299732
---
My Webpage : http://www.ae.iitm.ac.in/~ae03b032
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a little more help with python server-side scripting

2006-02-24 Thread John Salerno
Magnus Lycka wrote:

> Listen John. This will be the last time I respond
> to this thread, since you just ask more and more
> instead of digesting all the information you are
> given. Why should we spend time on answers if you
> don't read them properly anyway.

Well, I appreciate the help. I'm trying to figure it out, but it seems 
like with each new post, there is some new technology being mentioned or 
new method to do what I'm trying to do. I guess I'm not well-versed 
enough in Python to even attempt this kind of thing yet. I didn't 
realize it would be this complicated. I guess I hoped it would be as 
easy as including some PHP code and letting the server detect the .php 
extension and handle it all. I'm going to try to solidify the basics 
first, then move on to web programming a little later.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python-list/python-dev quoting style

2006-02-24 Thread Aahz
In article <[EMAIL PROTECTED]>,
Michael Hoffman  <[EMAIL PROTECTED]> wrote:
>Does anyone have a script to convert more conventional USENET quoting 
>style like this:
>
>John wrote:
>> Jacob Jingleheimer Schmidt <[EMAIL PROTECTED]> wrote in message-id 
> on 29 February 2004:
>>> Lambda is the best Python feature ever!
>>
>> I disagree.
>
>to the commonly used python-dev/python-list style like this:
>
>[Jacob Jingleheimer Schmidt]
>>> Lambda is the best Python feature ever!
>
>[John]
>> I disagree.

Blech.  Stick with the standard Usenet quoting style for both!
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"19. A language that doesn't affect the way you think about programming,
is not worth knowing."  --Alan Perlis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANN] httpy 0.9.0 -- a sane and robust HTTP library for Python

2006-02-24 Thread Claudio Grondi
Rene Pijlman wrote:
> Chad Whitacre:
> 
>>I am pleased to announce the first public release of httpy -- a sane and 
>>robust HTTP library for Python. With httpy, you write "responders," and 
>>put them on the network with "couplers." Here is a trivial responder:
>>
>>  import httpy
>>
>>  class Responder:
>>def respond(request):
>>  raise httpy.Response(200, "Greetings, program!")
>>
>>
>>And here is how to couple it:
>>
>>  responder = Responder()
>>  coupler = httpy.couplers.StandAlone(responder)
>>  coupler.go()
>>
>>httpy is so amazing, in fact, that with it I was able to write an entire 
>>wiki in only 20 seconds!
> 
> 
> Now that's what I call a short learning curve. So can this replace Zope
> then? Or mod_python? Apache? CGI? All of those?
> 
The example given does not run on my system:

Traceback (most recent call last):
   File "HowToUse_httpy.py", line 7, in ?
 coupler = httpy.couplers.StandAlone(responder)
   File 
"C:\Python24\Lib\site-packages\httpy\couplers\standalone\coupler.py", 
line 36, in __init__
 responder = add_api(responder, root, uri)
   File "C:\Python24\Lib\site-packages\httpy\couplers\utils.py", line 
24, in add_api
 verifyObject(IResponder, responder, tentative=True)
   File "C:\Python24\Lib\site-packages\httpy\_zope\interface\verify.py", 
line 96, in verifyObject
 return _verify(iface, candidate, tentative, vtype='o')
   File "C:\Python24\Lib\site-packages\httpy\_zope\interface\verify.py", 
line 88, in _verify
 raise BrokenMethodImplementation(name, mess)
httpy._zope.interface.exceptions.BrokenMethodImplementation: The 
implementation of respond violates its contract
 because implementation doesn't allow enough arguments.

What are the requirements? Zope?

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


Re: datetime iso8601 string input

2006-02-24 Thread Magnus Lycka
Rubic wrote:
> Yeah, it's a trivial function that's rewritten for each new project
> that passes datetime objects as strings <0.2 wink>.  On the basis of it
> being a trivial convenience, I could propose removing hundreds of
> "redundant" functions from the library.  ;-)

I think the big issue is that it solves such a microscopic part
of the convert-strings-to-datetimes problem. Believe me, I know,
I'm writing parsers for IATA timetable data now. There is a
distinct smell of punch cards, telex machines and handwritten
forms in this standard... Like writing 112233 instead of 2006-
02-11 22:33, and let the parser guess month and year from context.

If I have gotten a time into a datetime object I'll keep it there
if I'm in control. If I'm not in control, I'd be very lucky if
the string replresentation was in the One True Format.

Since I feel that the datetime module largely replaces the
older time module, I'd really like to see a strptime in the
datetime module though. Then I guess I could often drop use of
the old time module. (If it wasn't for the sad fact that we need
to support Python 2.2 a little longer...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using ElementTree to tidy up an XML string to my liking

2006-02-24 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
> Yes I am but, I'm using a DOM Serializer in Firefox which for some
> reason turns myCamelNames into MYCAMELNAMES for the nodenames. I'll
> therefore need to control the case-spelling of these things as I'm
> formatting the XML string.

I realize that it's difficult to make sure that every user of your
system has a corrected Firefox, but it seems to me that there is
a bug in that DOM Serializer, and that it would be good to mend
that.

Concerning element names, it's your coice of course, but I agree
more and more with Guido and PEP008 that camelCase is ugly. (Not
that ALLCAPS is better...)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: editor for Python on Linux

2006-02-24 Thread Robert Boyd
On 2/19/06, Mladen Adamovic <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I wonder which editor or IDE you can recommend me for writing Python
> programs. I tried with jEdit but it isn't perfect.
>

I know you said in the thread that you had problems with jEdit for
Python, and didn't care for Emacs or Vi(m).

Still -- in my experience, I've used jEdit for Python for about the
past 5 years, and never had a problem with jEdit's indentation. I did
not set up as a full-fledged IDE with code completion or module
browsing -- I never got the jpydebug plugin working to my
satisfaction. I think jEdit is an excellent editor.

I've tried pretty much all of the well-known editor/IDE options.
Komodo is nice to work with, but expensive (I code for pay, so can't
use the cheap license) compared to even WingIDE. Also, I don't like
the Komodo module browser. The latest pydev for Eclipse is greatly
improved. But with Eclipse you get all the overhead of a
projects-requiring IDE, which may feel like overkill if you're writing
small scripts. Plus, for the Python stuff to work, you have to import
files into a project that's defined as a Python project (not true for
the other full-blown IDEs). For fast and small (opposite of Eclipse),
Scite is nice, but auto-completion can only use words that exist in
the opened file, not the available methods in your namespace.

Despite all the good choices, I have gone back to my old standby, Vim,
alongside IPython.  If you dislike the vim way of editing, there's a
user-friendlier version of Vim called Cream. With vim plus IPython,
you get syntax highlighting, auto-indent, code completion, code
browser (tags), interactive help, ability to run your code and drop
into a debugger, file explorer, etc (and I haven't even gotten all the
vim Python tools installed yet). Add winpdg if you like a more GUI
debugger, and you've got the makings of a great development
environment.

If you really _have_ to have a full-blown IDE with a modern-looking
GUI, with dockable windows and all that, try the Komodo and WingIDE
trials. If you aren't coding for a living, you might want to pay the
price for a non-professional license. Try Eclipse with pydev, too. But
for your intended purpose, you might decide you can use a
lighter-weight setup.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KPanelApplet using Python

2006-02-24 Thread Varun Hiremath
On Fri, 24 Feb, 2006 at 05:51:55AM -0800, [EMAIL PROTECTED] wrote:
I want to make a PanelApplet and not a systray application. I tried KSystemTray 
and it works flawlessly but I want to add a widget to the taskbar like knews or 
kweather. I am trying to use the pyKDE's KPanelApplet class but I don't know 
exactly how to use it. I need some help regarding this.

Thank You

-- 
---
Varun Hiremath
461, Jamuna Hostel
IIT Madras,
Chennai - 600 036
mob : +919840299732
---
My Webpage : http://www.ae.iitm.ac.in/~ae03b032
---
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KPanelApplet using Python

2006-02-24 Thread David Boddie
Varun Hiremath wrote:

> I was wondering if there is any way to make KDE PanelApplets
> using Python. I have made a small window using Qt, kdeui nad
> kdecore libs. Now I want to add it to the KDE kicker. Can I
> get any help regarding this matter.

The other responses in this thread have covered solutions that use
the system tray, and you may want to try something like that with
the KSystemTray class in kdeui. It's available in PyKDE, so you
shouldn't have any trouble adding new items to kicker that way.

However, you asked specifically about Panel Applets. Unfortunately,
they are a lot more difficult to implement in Python because you
need to write a library in C++ to load them. Some of us in the
PyQt/PyKDE community did some work towards that, and had working
applets but, as far as I know, they don't work with recent releases.

You might get some additional help or advice about this if you try
mailing the PyKDE list:

http://mats.imk.fraunhofer.de/mailman/listinfo/pykde

Good luck!

David

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


Re: Module written in C does not repond to Ctrl-C interruption.

2006-02-24 Thread Daniel Dittmar
Diez B. Roggisch wrote:
> """
> Although Python signal handlers are called asynchronously as far as the
> Python user is concerned, they can only occur between the ``atomic''
> instructions of the Python interpreter. This means that signals arriving
> during long calculations implemented purely in C (such as regular
> expression matches on large bodies of text) may be delayed for an arbitrary
> amount of time. 
> """
> 
> So - no workaround here, unless you patch python.

You could set up your own signal handler when entering the C extension. 
This should abort the extension (tricky) and call the Python signal handler.

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


Re: Exception not raised

2006-02-24 Thread Michele Petrazzo
Diez B. Roggisch wrote:
> Not here:
> 
> t_fields = {}
> #code
> def test():
>   print type(t_fields), 11 in t_fields
>   print t_fields[11]
>   print "I'm here"
> 
> print "ok"
> test()
> print "ok"
> #end code
> 
> Gives me 
> 
> KeyError: 11

Also on my environ when I try this 4 line code. My project, where that 
strangeness happen has 500/600 + K of code.

> 
> 
> So - whatever you do, there must be some other code capturing that
> exception. 

This code are inside a method into class that have no try/except. And 
called from a method inside a wx.Frame derivate. The other strange thing 
is that if I try the same code just before the "caller" to that method, 
it raise an exception:

#code extract alway from the big project:

class errorHappen(object):
  def methodError(self, t_fields):
   print type(t_fields), 11 in t_fields
   print t_fields[11]
   print "I'm here"


def myF(wx.Frame):
    init 
  self._e = errorHappen()

def caller(self):
  d = dict(dictionary with 50/100 keys)
  #if here I try d[11], I'll KeyError
  self._e.methodError(d) #here I don't see the exeception


>Maybe you don't use dict, but a subclass of it?

All my dict are created as
d = dict()

and populate by: d.update(other_dict) or for k, val in iter: d[k] = val

> 
> Diez


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


Re: Tkinter canvas size determination

2006-02-24 Thread Dean Allen Provins
Martin:

Martin Franklin wrote:
> Dean Allen Provins wrote:
> 
>> Cameron:
>>
>> Cameron Laird wrote:
>>
>>> In article <[EMAIL PROTECTED]>,
>>> Dean Allen Provins  <[EMAIL PROTECTED]> wrote:
>>>
 I need to determine the size of a canvas while the process is running.
 Does anyone know of a technique that will let me do that?
>>>
>>> .
>>> .
>>> .
>>> Does
>>>   >>> import Tkinter
>>>   >>> c = Tkinter.Canvas()
>>>   >>> c.create_oval(13, 51, 80, 130)
>>>   1
>>>   >>> c.pack()
>>>   >>> print c.cget("width")
>>>   284
>>> help?
>>>
>>> There are actually several different notions of the size of a
>>> canvas.  The example abovve should be a good starting point,
>>> though. 
>>> There's also a mailing list specifically for Tkinter >> http://tkinter.unpythonic.net/wiki/mailing_20lists  >; that
>>> might interest you.
>>
>>
>> I tried the "cget" function, and it returned the width that I had used
>> when creating the canvas - even though the canvas was wider than that
>> value at display time (and also after manually resizing the window).
>>
>> To your knowledge, is there a method to determine the current dimensions?
>>
>> Thanks,
>>
>> Dean
> 
> 
> 
> Dean,
> 
> Look at the winfo_* methods of Tkinter widgets, I think the one you want
> is called winfo_reqheight / winfo_reqwidth or something very similar
> pydoc Tkinter.Canvas will sort that out
> 
> Martin

Thanks.  That is exactly what I needed.  I tried it, and it returned the
desired values.

Regards,

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


Re: Exception not raised

2006-02-24 Thread Larry Bates
Michele Petrazzo wrote:
> Hi list, I have a strange error on my software on win 2k/xp and debian
> 3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython:
> 
> python, on a piece of code doesn't raise a KeyError on a dict (that
> don't have that key), but the strange thing is that the try/except code
> see that exception. Other strange thing is that other exceptions are
> raised!
> 
> Simple example extract from my code:
> 
> #code
> def test():
>  print type(t_fields), 11 in t_fields
>  print t_fields[11]
>  print "I'm here"
> 
> print "ok"
> test()
> print "ok"
> #end code
> 
> Output:
> 
> ok
>  False
> 
> Here I see only one "ok" and not the "I'm here". The interpreter stop to
> run here, but the application continue to work!
> 
> Other try:
> 
> #code
> def test():
>  try:
>   print type(t_fields), 11 in t_fields
>   print t_fields[11]
>  except KeyError, ex:
>   print "Error",  ex
> #end code
> 
> Output:
> 
> ok
>  False
> Error 11
> ok
> 
> Here the output is ok, so python see that exception inside the
> try/except and print it.
> 
> Last try:
> 
> #code
> def test()
>  print type(t_fields), 11 in t_fields
>  print dont_exist
>  print t_fields[11]
> #end code
> 
> Output:
> 
> ok
>  False
> File "conn.py", line 231, in test
> print dont_exist
> NameError: global name 'dont_exist' is not defined
> 
> 
> So all the exception are raised except the KeyError outside the try/except!
> 
> I don't know what can be.
> 
> Thanks to all that can help me.
> Michele

When I run your first example I get:

>>>  False
Traceback (most recent call last):
  File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
exec codeObject in __main__.__dict__
  File "C:\Documents and Settings\larry\My Documents\junk.py", line 14, in ?
test()
  File "C:\Documents and Settings\larry\My Documents\junk.py", line 8, in test
print t_fields[11]
KeyError: 11
>>>

I don't know why you see anything different than a traceback when you
try to access t_fields[11] (which doesn't exist).

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


Re: Exception not raised

2006-02-24 Thread Diez B. Roggisch
Michele Petrazzo wrote:

> Simple example extract from my code:
> 
> #code
> def test():
> print type(t_fields), 11 in t_fields
> print t_fields[11]
> print "I'm here"
> 
> print "ok"
> test()
> print "ok"
> #end code
> 
> Output:
> 
> ok
>  False
> 
> Here I see only one "ok" and not the "I'm here". The interpreter stop to
> run here, but the application continue to work!


Not here:

t_fields = {}
#code
def test():
  print type(t_fields), 11 in t_fields
  print t_fields[11]
  print "I'm here"

print "ok"
test()
print "ok"
#end code

Gives me 

python2.4 /tmp/test.py
ok
 False
Traceback (most recent call last):
  File "/tmp/test.py", line 9, in ?
test()
  File "/tmp/test.py", line 5, in test
print t_fields[11]
KeyError: 11


So - whatever you do, there must be some other code capturing that
exception. Maybe you don't use dict, but a subclass of it?

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


Re: remote module importing (urlimport)

2006-02-24 Thread ajones
What plans do you have for security in this? I would think that in
order to trust this over the network you would at least need a
certificate identifying the server as well as some method of verifying
package contents.

Either way, cool stuff.

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


Exception not raised

2006-02-24 Thread Michele Petrazzo
Hi list, I have a strange error on my software on win 2k/xp and debian
3.1 with py 2.3.5 / 2.4.1 + twisted + wxpython:

python, on a piece of code doesn't raise a KeyError on a dict (that
don't have that key), but the strange thing is that the try/except code
see that exception. Other strange thing is that other exceptions are raised!

Simple example extract from my code:

#code
def test():
  print type(t_fields), 11 in t_fields
  print t_fields[11]
  print "I'm here"

print "ok"
test()
print "ok"
#end code

Output:

ok
 False

Here I see only one "ok" and not the "I'm here". The interpreter stop to
run here, but the application continue to work!

Other try:

#code
def test():
  try:
   print type(t_fields), 11 in t_fields
   print t_fields[11]
  except KeyError, ex:
   print "Error",  ex
#end code

Output:

ok
 False
Error 11
ok

Here the output is ok, so python see that exception inside the
try/except and print it.

Last try:

#code
def test()
  print type(t_fields), 11 in t_fields
  print dont_exist
  print t_fields[11]
#end code

Output:

ok
 False
File "conn.py", line 231, in test
 print dont_exist
NameError: global name 'dont_exist' is not defined


So all the exception are raised except the KeyError outside the try/except!

I don't know what can be.

Thanks to all that can help me.
Michele
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread matteosartori
Yes, it's easier to read without a doubt. I just wondered if i was
failing to do what i was trying to do because it couldn't be done or
because i hadn't properly understood what i was doing. Alas, it was
probably the latter.

Thanks for your help,

M@

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


Re: a little more help with python server-side scripting

2006-02-24 Thread Magnus Lycka
John Salerno wrote:
> But isn't this code:
> 
> Response.Write('Python Test')
> Response.write('Smaller heading')
> 
> written using ASP instead of Python?

Listen John. This will be the last time I respond
to this thread, since you just ask more and more
instead of digesting all the information you are
given. Why should we spend time on answers if you
don't read them properly anyway.

I understand that you are confused, but you need to
analyze the material you have been provided. ASP is
not a programming language. The code above shows the
Python ASP API.

Most ASP developers use VBScript, and since ASP is one
of those technologies Microsoft tosses at clueless
people, I'm sure many people who use VBScript in ASP
don't understand the distinction, and those who hire
ASP developers or buy web site development often don't.
These guys will probably also think that Sun's language
Java and Netscape Corp's JavaScript are the same things
too. Clueless.

The example is a bit boring of course, since it doesn't
show anything except a few calls that probably look
almost the same in most languages that can be used in
ASP. If there had just been a loop or something...

Whatever web tool kit you use, there will be an API
that you must learn. An interface for communicating with
these mechanisms that provide the web server interface.

In the web context, there is some sort of request made
from a browser (or spider or whatever) and based on that,
the Python script (CGI, ASP, SkunkWeb PSP or whatever)
must handle the request (if there are parameters to care
about) and produce some kind of response.

In a CGI script, you work on a very low level, and need
to print content-type headers, error codes etc. In ASP,
your API takes care of the details, and you just print
the "meat". This abstraction is managed through the
Response object. I'm sure you can find plenty of help
on the web. Use google.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Franz Steinh�usler
On Fri, 24 Feb 2006 07:21:04 -0500, John Zenger
<[EMAIL PROTECTED]> wrote:

>Franz Steinhaeusler wrote:
>> 
>> Thank you all for the replies.
>> But I still don't have a solution.
>> 
>> Of course with more lines it is possible, 
>> but it would be fine to have a "oneliner".
>
>re.sub(r"\s+[\n\r]+", lambda x: x.expand("\g<0>"). \
> lstrip(" \t\f\v"),text).rstrip()
>
>...where "text" is the unsplit block of text with mysterious line-endings.
>
>But I think your code is a lot easier to read.  :)

Hello John,

perfect, thank you,

but as you said, this is somehow not so easy to grasp.
(At least for me). :-)



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


Re: Unintended inheritance

2006-02-24 Thread Kay Schluehr

Alex Martelli wrote:
> Kay Schluehr <[EMAIL PROTECTED]> wrote:
>...
> > To prevent unintended inheritance C# introduced a relatively complex
> > contract semantics using three modifiers virtual, override and new. Is
> > this issue serious for Python programmers, in particular for those
> > working in larger projects ( Twisted, Zope ... ) or is it not? If not,
> > why not?
>
> I have not found it to be a particular problem (in C++ as well as in
> Python or Java), because subclasses' coupling to superclasses is too
> strong anyway to expect everything to just work smoothly when the
> superclass's interface is changed, and even the most semidecent of
> unittests easily catch this specific problem -- obviously all subclasses
> must be recompiled and tested when a superclass's interface is changed
> in any way. Other kinds of coupling are subtler and more problematic
> (not so much in Python as in C++, I'd say, but it's arguable).
>
> Lakos' book on large-scale design for C++ has good advice on dependency
> control, which boils down to (WAY oversimplifying): each component must
> expose to all others only unchanging abstract interfaces; anything
> depending on anything beyond an abstract interface (as a subclass must)
> must be in the same component as what it depends on.  Inheritance, while
> way handy, introduces too-strong coupling (==dependencies) to be freely
> used across independently developed and maintained components; and any
> change in interface (I would argue, in fact, most any change in
> PROTOCOL, which is a stronger constraint) must occur on new, separate
> interfaces (which may well extend the existing ones, of course).
>
> Yes, frameworks (separately developed, large components which are
> *supposed* to be used via inheritance by separately developed and
> maintained components) are quite problematic in terms of Lakos' rules
> and guidelines (if you're at all interested in these subjects you should
> surely read Lakos' book, anyway: no summary can do it justice). But I
> believe (with no real-world experience of C#, admittedly) that they will
> remain essentially just as problematic with C#'s complex rules -- a new
> release of a framework, which changes protocols, will still be able to
> break uncountable independently developed and maintained smaller
> components, and the fact that the compiler catches the breakage (if, of
> course, the other components DO get recompiled) rather than relying on
> semidecent unittests is scant consolation -- there's still no bound to
> the amount of work that may be needed to repair the wreckage.
>
>
> Alex

Interesting statement, Alex, as always. I've found an interview with
Anders Hejlsberg from 2003 on Artima where he defended his C# design
decisions with regard to the problem of "unintended inheritance":

http://www.artima.com/intv/nonvirtual.html

A strange twist is Anders exemplification of "pragmatism" with which
Bruce Eckel seems to agree emphatically. I would indeed assume the
exact opposite: laisser faire by pragmatists and expressive control by
academics. I'm also not sure what I should think about the confusing
use of the word "versioning" that is placed concretely by Bruce Eckel (
"DLL hell" ) but more metaphorically by Anders. His remarks about the
difference of ingoing and outgoing interfaces are interesting but
remain a little underdeveloped. 

Kay

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


Re: editor for Python on Linux

2006-02-24 Thread Lee Phillips
The indentation-based folding in vim makes it great
for python; other folding editors might be almost as
good.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread johnzenger
You can check len(sanesplit) to see how big your list is.  If it is <
2, then there were no  's, so move on to the next line.

It is probably possible to do the whole thing with a regular
expression.  It is probably not wise to do so.  Regular expressions are
difficult to read, and, as you discovered, difficult to program and
debug.  In many cases, Python code that relies on regular expressions
for lots of program logic runs slower than code that uses normal
Python.

Suppose "words" contains all the words in English.  Compare these two
lines:

foobarwords1 = [x for x in words if re.search("foo|bar", x) ]
foobarwords2 = [x for x in words if "foo" in x or "bar" in x ]

I haven't tested this with 2.4, but as of a few years ago it was a safe
bet that foobarwords2 will be calculated much, much faster.  Also, I
think you will agree, foobarwords2 is a lot easier to read.

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


  1   2   3   >