automatic html generation for documentation?

2006-02-24 Thread Lonnie Princehouse
I plan on writing some documentation that will consist of blocks of
commentary with interspersed snippets of syntax-colored Python code and
the occaisional image.

Does anyone know of a package that will take a high level description
of what I just described and auto-generate clean-looking web pages,
including syntax coloring?   I'm already using epydoc for API reference
generation; what I'm looking for here is just something to help out
with the narrative so I don't have to spend lots of time fiddling with
HTML.

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


Re: Python vs. Lisp -- please explain

2006-02-24 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 But Lisp isn't dynamically typed exactly the way Python is.
 Python documents ways to manipulate the internals of objects at
 runtime.  It is possible to add, change or delete methods and slots
 by directly changing the hashtable they're stored in.  While CLOS
 does permit a certain amount of runtime redefinition, it is not as
 completely free wheeling and unpredicatable.

Although CLOS is now part of the Lisp standard I haven't generally
thought of it as describing the language semantics.  It's more like a
library routine.  Python's standard library generally doesn't provide
documented ways of mucking around with the internal structure of
library classes.  CLOS (or something close to it) similarly can and
has been implemented as a Lisp macro package independent from the rest
of the Lisp system.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ls files -- list packer

2006-02-24 Thread kpp9c
cool i just tried:

 import os
snd_filelist = [f for f in os.listdir('/Users/foo/snd') if 
f.endswith('.aif')]


and it worked! and will take a huge bite out of my big script ... which
i make by doing an ls
in the terminal and editing (boo hoo)

one one lc and one import!

cool..

that other sillyness i mentioned is not strickly required  ... just
dreaming but i know involves some kind of os walk type thing prolly ...
meanwhile this is so exciting!

Thank you

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


Re: Python vs. Lisp -- please explain

2006-02-24 Thread Torsten Bronger
Hallöchen!

Peter Mayne [EMAIL PROTECTED] writes:

 Torsten Bronger wrote:

 Another example: is Java the bytecode, which is compiled from
 Java the language, interpreted or not? Even when the HotSpot
 JIT cuts in?

 It is partly interpreted and partly compiled.  That's why it's
 faster than Python.

 But Python is partly interpreted and partly compiled too

 It's byte-compiled for a VM, that's not the same, and you know
 it.

 Do you mean that Python is byte-compiled for a VM, and not Java,
 or vice-versa?

I mean Python is byte-compiled for a VM.

 I agree that the distinction between interpreted and compiled
 languages is not as clear as between positiv and negative
 numbers, however, neither anybody has claimed that so far, nor it
 is necessary.  It must be *practical*, i.e. a useful rule of
 thumb for decision making.  If you really know all implications
 (pros and cons) of interpreted languages, it's are very useful
 rule in my opinion.

 So what kind of practical decisions are you trying to make?

Which language should I use for my project.

 What kind of implications are useful to you?

Speed, ease of programming, necessity to learn/use a secondary
language, issues with distributing, portability.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ls files -- list packer

2006-02-24 Thread kpp9c
gosh i could even use other string methods like startswith to take all
the files in a given directory which i have organized with a prefix and
have them stuffed in different lists  ... i think ...

snd_filelist = [f for f in os.listdir('/Users/foo/snd') if
f.endswith('.aif')  f.startswith('r')]

\m/ (.) \m/

yeah!

runnin' to the interpreta now...

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


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Franz Steinhaeusler
On Thu, 23 Feb 2006 14:46:20 +0100, Franz Steinhaeusler
[EMAIL PROTECTED] wrote:

Hello, I need a regularexpression, which trims trailing whitespaces.

While with unix line endings, it works; 
but not with Window (Dos) CRLF's:

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.

-- 
Franz Steinhaeusler
-- 
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:
   Ok, seems like the verdict is that the server doesn't have mod_python
 nor does it detect the .psp extension. It can, however, detect the .py 
 extension. But does this mean I can simply include Python code in my 
 HTML files, and then give my HTML files a .py extension? I don't know 
 how to test this because I don't know how to write inline code yet. Is 
 it something like:

No, you can't do that. From your descriptions, it seems that Python
is set up as a CGI language, just as one would use Perl etc. This
means that if you have an URL ending with x.py, the web server will
do these things when you request this URL from the server:

1. Set up a number of environment variables which are useful for the
python script it will call. Very important if the URL was invoked
from an HTML form, which I don't suspect will happen on your site.
2. Invoke Python with your script. Basically it should call
python.exe -u x.py
3. Read the data that x.py sends to stdout, e.g. print statements
etc. Provided that this output looks ok, it will send it to the
browser, otherwise it will typically send ERROR 500 (internal
server error) instead.

You were given a CGI script already that printed out environment
variables. I got the impression that you tried that out. If you
set the environment variables shown by that CGI script using the
SET command at a Windows command prompt, and then execute your
python script at that command prompt, it has to print something like


Content-type: text/html

html
blah blah whatever
/html


There is no magic beyond this. Try renaming an HTML file to .py
and invoke Python with that. It will just say SyntaxError! The
change isn't big though! You just need to make the HTML content
into a big string (surround it with ) and print the content-type
line, an empty line and this big string, and you have a start.

You have already been provided with all the information you need.
I think you need to look closely at the information Paul and several
others have given you instead of just asking more questions, and
really start using it. You won't get anywhere otherwise.

The other option is ASP. You have been given information about
that already. Be aware that ASP does not imply VBScript. You can
use Python in ASP as long as that's enabled. It seems to be exactly
what you are asking for, so I don't understand why you seem to reject
it. Don't you like the file name endings?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Temporary Variable

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 00:24:25 +, Jeffrey Schwab wrote:

 Steven D'Aprano wrote:
 On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote:
 
 My comments inserted inline.
 
 
 
#!/usr/bin/python
#simple guessing game, with numbers
import random
spam = random.randint(1, 100)
 
 
 It is bad programming practice to give variables uninformative joke names.
 
 Lighten up.  This isn't the middle of a 100-KLOC corporate monstrosity, 
 it's a 1/2-page usenet post.

The original poster is also a newbie who was having trouble with the
difference between strings and ints. If Guido called a variable spam,
I wouldn't presume to correct him. When Newbie McNew does it, it might
very well be because he doesn't know any better.

Just out of curiosity, when do you think is the right time to begin
teaching programmers good practice from bad? Before or after they've
learnt bad habits?



-- 
Steven.

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


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Martin Franklin
Franz Steinhaeusler wrote:
 On Thu, 23 Feb 2006 14:46:20 +0100, Franz Steinhaeusler
 [EMAIL PROTECTED] wrote:
 
 Hello, I need a regularexpression, which trims trailing whitespaces.

 While with unix line endings, it works; 
 but not with Window (Dos) CRLF's:
 
 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.
 


Then I clearly don't understand your problem... it seems we gave
you several ways of skinning your cat... but none of them 'worked'?
I find that hard to believe... perhaps you can re-state you problem
or show us your more than one line solution...(so that we might learn
from it)


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


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

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 17:49:31 -0600, Larry Bates wrote:

 Steven D'Aprano wrote:
 On Thu, 23 Feb 2006 14:30:22 -0600, Larry Bates wrote:
 
 How about not naming files with leading and trailing spaces on
 the Mac?  Seems like a bad habit that needs breaking ;-).
 
 Why is it a bad habit? Because *Windows* is primitive enough that it can't
 cope with leading and trailing spaces? I don't see why Windows' lack is
 Mac users' problem.
 
 
 It is a problem because the poster says it is a problem for him.

Absolutely.

Now read my statement again. Why is it a problem for the Mac _users_?

I use Linux, Windows and Mac, in varying amounts. I'm fully aware of the
problems of transferring files from one platform to another. When it
affects _me_, I may choose to dumb down to the lowest common denominator
so as to save _me_ problems. But wearing my user hat, if a developer came
to me telling me I had to avoid using features on my platform of choice in
order to make his life easier, I'd say to him So why exactly are we
paying you the big bucks? That's your problem, you solve it.



-- 
Steven.

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


Re: Temporary Variable

2006-02-24 Thread bonono

Steven D'Aprano wrote:
 Just out of curiosity, when do you think is the right time to begin
 teaching programmers good practice from bad? Before or after they've
 learnt bad habits?
When you have authority over the coding guideline. Naming things is not
something limited to programming and most people know the importance of
choosing the appropriate ones. If on the other hand some names have
been chosen that have actual side effect(in python program), like
builtin function names, it is appropriate to point that out, though I
don't see that case here.

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


Re: PYTHONPATH?

2006-02-24 Thread Diez B. Roggisch
Dr. Pastor wrote:

 Several Documents about Python
 refer to PYTHONPATH.
 I could not find such variable.
 (Python 2.4.2, IDLE 1.1.2, Windows XP)
 How should/could I nominate a Directory to be
 the local Directory?
 Thanks for any guidance.

It's a so called environment-variable. You can set these in some obscure
windows dialog in the system-preferences on a per-system or per-user base.
Or you start using cygwin (lots of good other reasons for that), and do

export PYTHONPATH=/whatever

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


Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 20:41:52 -0600, Terry Hancock wrote:

 On Fri, 24 Feb 2006 09:14:53 +1100
 Steven D'Aprano [EMAIL PROTECTED] wrote:
 There are *reasons* why Python discourages functions with
 side-effects. Side-effects make your code hard to test and
 harder to debug.
 
 You of course meant expressions with side-effects.  Python
 is pretty good at making functions with side-effects. At
 least it is if you want them. ;-)

Yes, of course I meant that.

However, functions with side-effects are also discouraged. Unless
side-effects are the correct way to do whatever it is you are trying to
do, in which case they are encouraged.

*wink*


-- 
Steven.

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


Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Thu, 23 Feb 2006 16:49:09 -0800, bonono wrote:

 
 Steven D'Aprano wrote:
 On Thu, 23 Feb 2006 12:04:38 -0700, Bob Greschke wrote:

  try:
 i = a.find(3)
 print It's here: , i
  except NotFound:
 print No 3's here
 
  Nuts.  I guess you're right.  It wouldn't be proper.  Things are added or
  proposed every day for Python that I can't even pronounce, but a simple 'if
  (I = a.find(3)) != -1' isn't allowed.  Huh.  It might be time to go back
  to BASIC. :)

 There are *reasons* why Python discourages functions with side-effects.
 Side-effects make your code hard to test and harder to debug.

 
 test.index(a)
 Traceback (most recent call last):
   File pyshell#0, line 1, in -toplevel-
 test.index(a)
 ValueError: substring not found
 test.find(a)
 -1


Did you have a point?

In case you haven't been following the entire thread, the original bit of
code above (the try block using the find method) wasn't mine. It just
happened to be quoted in my post.


Now that's a Python wart: using  for the prompt for interactive
sessions. It makes it ambiguous when posting code in email or newsgroups,
especially once the code gets quoted a few times.


-- 
Steven.

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


python-list/python-dev quoting style

2006-02-24 Thread Michael Hoffman
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 
gratuitous-detail 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.
-- 
Michael Hoffman
-- 
http://mail.python.org/mailman/listinfo/python-list


Exception-handling

2006-02-24 Thread Odd-R.
I have come over a strange problem regarding exceptions
This is my code:

try:
  #some operation
except Exception, info:
  #some message
except:
  #??

When executing my code, I get to the last block here. This
I find rather strange, because I thought Exception would catch
all exceptions. But this is obviously not the case here.

What is this, and how can I get a hold of what causes the exception?

Thanks!



-- 
Har du et kjøleskap, har du en TV
så har du alt du trenger for å leve

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


Re: MySQLdb slow on MySQL 5

2006-02-24 Thread Magnus Lycka
[EMAIL PROTECTED] wrote:
   I'm not calling COMMIT at all.

Then you must be using autocommit if your records stay in
the table. An DB-API 2.0 compliant adapter should turn off
autocommit by default! Does MyISAM even support proper
commit handling?

Oh well, Oracle will probably kill MySQL soon. Good! I'd
use a real database system. It hurts my Swedish heart that
one of the best known Swedish software products is so bad.

It's one thing for some more inventive product like Skype
to pave its own path, but to build something called an
SQL database with such a complete disregard of the SQL
standard seems like Microsoft in the 80's or 90's to me.

If you must have a Swedish database server, use Mimer,
otherwise PostgreSQL 8.2 is a good open source alternative,
and all the major vendors have gratis versions now.
Oracle is a resource hog, and a pain to download and
install though.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unexpected timing results

2006-02-24 Thread Magnus Lycka
Steven D'Aprano wrote:
 It looks like the time function under Linux at least is very slow.

Perhaps you should try doing the same thing in C.
Then you can see whether the problem is in the
wrapper or in the system call.
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-02-24 Thread Magnus Lycka
kanchy kang wrote:
 i browsed the following frameworks briefly: nose, OOBTest,
 testosterone,  py.test, Sancho ... and found out they do support 
 imediate screen-output only.

Look at TextTest.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime iso8601 string input

2006-02-24 Thread Magnus Lycka
Rubic wrote:
 I can understand why datetime can't handle
 arbitrary string inputs, but why not just
 simple iso8601 format -- i.e. the default
 output format for datetime?

Have you actually read the ISO 8601 standard?
If you have, you would know that parsing valid
ISO 8601 is fairly close to handling arbitrary
strings...

I suspect this absence is quite deliberate.

There are so many possible string formats that
are used and prefered in different situations,
and various loop holes with time zones and DST
etc, that it's probably better to let the
programmer take full responsibility over this
instead of providing a 10% solution.

ater all, it isn't very hard to use for instance
time.strptime() with some appropriate format,
and build datetime objects from that. Then
the programmer is in control.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A C-like if statement

2006-02-24 Thread bonono

Steven D'Aprano wrote:
 On Thu, 23 Feb 2006 16:49:09 -0800, bonono wrote:

 
  Steven D'Aprano wrote:
  On Thu, 23 Feb 2006 12:04:38 -0700, Bob Greschke wrote:
 
   try:
  i = a.find(3)
  print It's here: , i
   except NotFound:
  print No 3's here
  
   Nuts.  I guess you're right.  It wouldn't be proper.  Things are added or
   proposed every day for Python that I can't even pronounce, but a simple 
   'if
   (I = a.find(3)) != -1' isn't allowed.  Huh.  It might be time to go 
   back
   to BASIC. :)
 
  There are *reasons* why Python discourages functions with side-effects.
  Side-effects make your code hard to test and harder to debug.
 
 
  test.index(a)
  Traceback (most recent call last):
File pyshell#0, line 1, in -toplevel-
  test.index(a)
  ValueError: substring not found
  test.find(a)
  -1


 Did you have a point?

It was about your side-effect talk, if you failed to see it, that is
fine.

BTW, it seems that the term side-effect of function used is a bit
different from my understanding of how it is in general used in this
field.

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


Re: Exception-handling

2006-02-24 Thread Diez B. Roggisch
Odd-R. wrote:

 I have come over a strange problem regarding exceptions
 This is my code:
 
 try:
   #some operation
 except Exception, info:
   #some message
 except:
   #??
 
 When executing my code, I get to the last block here. This
 I find rather strange, because I thought Exception would catch
 all exceptions. But this is obviously not the case here.
 
 What is this, and how can I get a hold of what causes the exception?

You can throw everything as an exception. I _think_ that is frowned upon
these days, but it is there so it will happen.

However, you can use

import sys

try:
   raise foo
except:
   print sys.exc_info()[1]


to get a hold on what's being caught by the exception handler.

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


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

2006-02-24 Thread Lad
Can anyone give an example how to send email with non-ascii characters(
both in subject and body).
I would like to use windows-1250 code page
Thank you
L.B.

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


Re: Unexpected timing results

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 10:11:18 +0100, Magnus Lycka wrote:

 Steven D'Aprano wrote:
 It looks like the time function under Linux at least is very slow.
 
 Perhaps you should try doing the same thing in C.
 Then you can see whether the problem is in the
 wrapper or in the system call.

Good idea.

Now, has anyone got a copy of Learning C for Dummies I can borrow?

*chagrined smile*


-- 
Steven.

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


Re: ls files -- list packer

2006-02-24 Thread Singletoned
Try using The Path module:
http://www.jorendorff.com/articles/python/path/.

I wrote a little script to traverse a directory structure which you
could use.  (You just pass a function to it and it runs it on each file
in the directory.  You want it to run on each directory instead, so
I've changed it a little for you).

import path

def traverse(directory, function, depth=0, onfiles=True, ondirs=False):
   thedir = path.path(directory)
   if onfiles == True:
  for item in thedir.files():
  function(item, depth)
   if ondirs == True:
  for item in thedir.dirs():
 function(item, depth)
   for item in thedir.dirs():
   traverse(item, function, depth+1, onfiles, ondirs)

You can use it like so:

def printaifs(thedir, depth):
   print thedir.name
   for item in thedir.files(*.aif'):
  print \t + item

traverse(r/Users/foo/snd, printaifs, onfiles=False, ondirs=True)

NB: I've quickly adapted this whilst away from an installation of
Python, so it is untested, but should mostly work, unless there's a
typo.

Hope this helps at least a little...

Ed

PS The Python Tutor list tends to be a much better place to discuss
this kind of stuff.  If you haven't yet encountered Kent and Alan's
help, then you have a joyous experience ahead of you.

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


Re: Exception-handling

2006-02-24 Thread Rene Pijlman
Odd-R.:
I thought Exception would catch all exceptions. 

Try this:

import sys

try:
pass # your code here
except:
e = sys.exc_value()

Either to catch everything, or to get a hold on e.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-02-24 Thread Lad
Sybren,
and can give me an example of  Python code that can send such email??

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


Re: Unexpected timing results

2006-02-24 Thread Roel Schroeven
Steven D'Aprano schreef:
 On Fri, 24 Feb 2006 10:11:18 +0100, Magnus Lycka wrote:
 
 Steven D'Aprano wrote:
 It looks like the time function under Linux at least is very slow.
 Perhaps you should try doing the same thing in C.
 Then you can see whether the problem is in the
 wrapper or in the system call.
 
 Good idea.
 
 Now, has anyone got a copy of Learning C for Dummies I can borrow?
 
 *chagrined smile*

First, for reference, the Python version on the machine I used for 
testing (Debian 3.1, P4 3GHz):

timer1:  0.36007809639
timer2:  3.18800234795

On Windows the difference is much less.

C (compiled with gcc 3.3.5 without optimizations) (see below for the code):

timer1: 0.000603
timer2: 2.624557

I think it looks like the problem is in the system call.



C code:

#include stdio.h
#include sys/time.h
#include time.h

void func(void)
{
}

double gettime()
{
 struct timeval tv;
 gettimeofday(tv, NULL);
 return tv.tv_sec + tv.tv_usec/1e6;
}

double timer1(void)
{
 double t0, t1;
 int i;
 t0 = gettime();
 for (i = 0; i  10; ++i)
 {
 func();
 }
 t1 = gettime();
 return t1 - t0;
}

double timer2(void)
{
 int i;
 double t = 0.0;
 double t0, t1;
 for (i = 0; i  100; ++i)
 {
 t0 = gettime();
 func();
 t1 = gettime();
 t += t1 - t0;
 }
 return t;
}

int main(void)
{
 printf(timer1: %lf\n, timer1());
 printf(timer2: %lf\n, timer2());
 return 0;
}




-- 
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: Temporary Variable

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 01:50:40 -0800, bonono wrote:

 Steven D'Aprano wrote:
 Just out of curiosity, when do you think is the right time to begin
 teaching programmers good practice from bad? Before or after they've
 learnt bad habits?
 
 When you have authority over the coding guideline. 

By that logic, only senators and other government ministers are allowed
to tell people Committing murder is strongly discouraged, don't do it,
because only they have authority over what is made law and what is not.

I don't need to be Guido van Rossum to know that calling a dict
myFloat is a terrible idea. Your suggestion that one needs somehow to be
authorized (by whom?) before you are allowed to point out poor programming
practice not only goes against the entire community ethos of
comp.lang.python, but is offensive in the extreme.


 Naming things is not
 something limited to programming and most people know the importance of
 choosing the appropriate ones. 

Most people. Let's not mention the Chevy Nova (it won't go) then,
will we? 

Car manufacturers seem to have a talent for not just choosing
bad names, but for getting them horribly, horribly wrong. I suggest
you google on Opel Ascona, Buick LaCrosse, Honda Fitta, Mitsubishi
Pajero, and the Mazda LaPuta, to discover just why those cars went over
like lead balloons in places like Spain, Finland and Quebec.

But I digress. What of those that don't know the importance of choosing
appropriate names? We should just let them shoot themselves in the foot,
even when it is obvious to Blind Freddy that they are struggling with some
really basic concepts, and that they probably don't even know the gun is
loaded?


 If on the other hand some names have
 been chosen that have actual side effect(in python program), like
 builtin function names, it is appropriate to point that out, 

By your earlier logic, that should only be permitted to those who have
authority to create builtins, certainly not the likes of you and me. 


-- 
Steven.

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


Re: PYTHONPATH?

2006-02-24 Thread Magnus Lycka
Dr. Pastor wrote:
 Several Documents about Python refer to PYTHONPATH.

If you need to import libraries into Python, that don't reside in the
standard locations in your Python installation, you need to define
a PYTHONPATH environment variable in the operating system, which
points out this directory.

Defining this is done in the same way as defining PATH etc.

 I could not find such variable.

Do you need it for anything?

 (Python 2.4.2, IDLE 1.1.2, Windows XP)
 How should/could I nominate a Directory to be the local Directory?

import os
os.chdir('c:/somedir')

Another way is to start python from there, e.g. from the
command prompt (nothing beats a command prompt!) you would do:

cd some\local\directory
python myscript.py (... or just python ...)

Note that backslash in a Python string literal denotes an escape
sequence. In Python 'c:\temp' means 'c' ':' tab 'e' 'm' 'p', since
'\t' is the escape sequence for a tab. You can use 'c:/temp' (ok
for  Windows APIs) r'c:\temp' (r for raw string, i.e. don't use
escape sequences) or 'c:\\temp' (\\ is the escape sequence for
backslash).

Also note, that the way to use libraries from an arbitrary
directory without setting PYTHONPATH, is not with os.chdir,
but by doing this:

import sys
sys.path.append('c:/somedir')
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ls files -- list packer

2006-02-24 Thread Magnus Lycka
kpp9c wrote:
 that other sillyness i mentioned is not strickly required  ... just
 dreaming but i know involves some kind of os walk type thing prolly ...

os.walk isn't exactly rocket science... Something similar to this?

  import os
  for dir, dirs, files in os.walk('.'):
... txt_files = [x for x in files if x.endswith('.txt')]
... if txt_files:
... print dir, txt_files
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-02-24 Thread Magnus Lycka
Paul Probert wrote:
 Yes, I'm doing this:
   .
  oldtime=time.time()
  time.sleep(1)
  newtime=time.time()
  dt=newtime-oldtime
   if dt  2:
   print 'dt=',dt,' time=',time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss')
 Its happening roughly 4 times a day total on our 20 machines, ie about 
 once every 5 days on a given machine.

So, it happens roughly one time out of 400 000 sleeps?

With an operating system such as Windows, this is
probably something you can expect to happen, although
I'm surprised if such long lag times as 200 s are typical.

If you need real time characteristics, you should
probably use a real time operating system, not Windows.

The operating system can schedule jobs as it likes,
and your sleep is obviously just the right time to hand
off the CPU to some other process.

Of course, if something takes 200 seconds, it's typically
because some process is waiting for IO, and if it's waiting
for IO, the CPU should be used by other processes, such as
yours.

Perhaps you can use the event log or some performance
measurement tools to check if something else on the system
happens to coincide with your long delays.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 02:02:02 -0800, bonono wrote:

  test.index(a)
  Traceback (most recent call last):
File pyshell#0, line 1, in -toplevel-
  test.index(a)
  ValueError: substring not found
  test.find(a)
  -1


 Did you have a point?

 It was about your side-effect talk, if you failed to see it, that is
 fine.
 
 BTW, it seems that the term side-effect of function used is a bit
 different from my understanding of how it is in general used in this
 field.

What side effect?

Returning magic values (e.g. -1 to indicate not found) is not a
side-effect in any terminology I've come across. 

A side-effect would be if s.index(substr) not only returned the index as
promised, but also (say) appended substr to a list somewhere. 

Side-effects aren't always bad (import, for example, does all its work by
side-effect). But they are generally frowned upon, and in functional
languages they are verboten.


-- 
Steven.

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


Re: Unexpected timing results

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 10:51:09 +, Roel Schroeven wrote:

[snip]

 I think it looks like the problem is in the system call.

Thank you Roel for going the extra mile. I appreciate the unexpected bonus.


-- 
Steven.

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


Re: PYTHONPATH?

2006-02-24 Thread Tombo
Said obscure dialog is here:
My Computer  Properties  Advanced (tab)  Environment Variables

You probably want a new system variable.

You can check the value by starting a new terminal window and typing:

echo %PYTHONPATH%

Cheers
Tombo

Diez B. Roggisch wrote:
 Dr. Pastor wrote:

  Several Documents about Python
  refer to PYTHONPATH.
  I could not find such variable.
  (Python 2.4.2, IDLE 1.1.2, Windows XP)
  How should/could I nominate a Directory to be
  the local Directory?
  Thanks for any guidance.

 It's a so called environment-variable. You can set these in some obscure
 windows dialog in the system-preferences on a per-system or per-user base.
 Or you start using cygwin (lots of good other reasons for that), and do
 
 export PYTHONPATH=/whatever
 
 Diez

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


Re: Python vs. Lisp -- please explain

2006-02-24 Thread Paul Boddie
Torsten Bronger wrote:

 Peter Mayne [EMAIL PROTECTED] writes:
  What kind of implications are useful to you?

 Speed, ease of programming, necessity to learn/use a secondary
 language, issues with distributing, portability.

Indeed. Given the various convenient arguments about what interpreted
means (and how Python is simultaneously the same as and yet quite
different to Lisp), you'd think that the average C/C++/Lisp programmer
would have to be quite familiar with microcode to finish off a fair
number of their projects.

Paul

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


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Franz Steinhaeusler
On Thu, 23 Feb 2006 17:41:47 +, Martin Franklin
[EMAIL PROTECTED] wrote:

Franz Steinhaeusler wrote:
 On Thu, 23 Feb 2006 13:54:50 +, Martin Franklin
 [EMAIL PROTECTED] wrote:
 
 r=erewr\r\nafjdskl 
 'erewr\r\nafjdskl'

 2) Unix
 r=erewr\nafjdskl 
 'erewr\nafjdskl'
 why not use string methods strip, rstrip and lstrip

 
 because this removes only the last spaces,
 r
 'erewr\r\nafjdskl '
 r.rstrip()
 'erewr\r\nafjdskl'
 
 I want:
 'erewr\r\nafjdskl'
 
 or for unix line endings
 'erewr\nafjdskl'
 


how about one of these variations

print 'erewr\r\nafjdskl '.replace( , )
print 'erewr\r\nafjdskl '.strip( \t)



Version 1:

 w='erewr\r\nafjdskl '.replace( , )
 w
'erewr\r\nafjdskl'
 w='erewr\nafjdskl '.replace( , )
 w
'erewr\nafjdskl'
 w='word1 word2   \nafjdskl '.replace( , )
 w
'word1word2\nafjdskl'
 

it replaces all spaces, not only the trailing whitespaces.


version 2:

 w = 'erewr\r\nafjdskl '.strip( \t)
 w
'erewr\r\nafjdskl'
 w = 'erewr\nafjdskl '.strip( \t)
 w
'erewr\nafjdskl'
 w = 'word1 word2\nafjdskl '.strip( \t)
 w
'word1 word2\nafjdskl'
 

I found a solution (not the most beautiful, but for 
my purpose sufficiently good.)
Given: a file has no mixed lineendings, so it is either
a dos or unix file (mac line endings not respected).


swin=erewr \r\nafjdskl 
sunix=erewr \nafjdskl 

Dos Line endings (at least on '\r' included)?
r is contents of a file:

helpchar = ''
if r.find('\r') != -1:
helpchar = '\r'
retrailingwhitespacelf = re.compile('(?=\S)[ \t'+helpchar+']+$',
re.MULTILINE)
newtext, n = retrailingwhitespace.subn(helpchar, r)
if n  1:
   r = newtext


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


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Franz Steinhaeusler
On Fri, 24 Feb 2006 12:36:01 +0100, Franz Steinhaeusler
[EMAIL PROTECTED] wrote:

if n  1:

if n  0: (of course) :-)

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


Re: Pickling/unpickling Cookie.SimpleCookie fails with protocol=2

2006-02-24 Thread Georg Brandl
Erwin S. Andreasen wrote:
 Pickling a Cookie.SimpleCookie (or SmartCookie) when using protocol=2
 seems to do something very strange. Protocol 0/1 work fine:
 
 $ python2.4
 Python 2.4.2 (#2, Nov 20 2005, 17:04:48) 
 [GCC 4.0.3 2005 (prerelease) (Debian 4.0.2-4)] on linux2
 Type help, copyright, credits or license for more information.
 
 import cPickle, Cookie
 cPickle.loads(cPickle.dumps(Cookie.SimpleCookie('hi=there')))
 SimpleCookie: hi='there'
 
 Protocol 2 however:
 
 pickle.loads(pickle.dumps(Cookie.Cookie('hi=there'),2))
 SmartCookie: hi=Morsel: hi='there'
 
pickle.loads(pickle.dumps(Cookie.Cookie('hi=there'),2))['hi'].__dict__
 
 {'coded_value':
 'ccopy_reg\\012_reconstructor\\012p1\\012(cCookie\\012Morsel\\012p2\\012c__builtin__\\012dict\\012p3\\012(dp4\\012S\'comment\'\\012p5\\012S\'\'\\012sS\'domain\'\\012p6\\012S\'\'\\012sS\'version\'\\012p7\\012S\'\'\\012sS\'secure\'\\012p8\\012S\'\'\\012sS\'path\'\\012p9\\012S\'\'\\012sS\'expires\'\\012p10\\012S\'\'\\012sS\'max-age\'\\012p11\\012S\'\'\\012stRp12\\012(dp13\\012S\'coded_value\'\\012p14\\012S\'there\'\\012p15\\012sS\'value\'\\012p16\\012g15\\012sS\'key\'\\012p17\\012S\'hi\'\\012p18\\012sb.',
 'value': Morsel: hi='there', 'key': 'hi'}
 
 
 I can't really say what goes wrong here, but it looks like a bug to me
 -- comments? I guess I'll have to go to protocol 0 for this, or not
 serialize the cookie but re-parse it on the other side (this pickle
 gets passed down a UNIX socket together with the file descriptor of a
 request, in a load balancing system).

You can report a bug at SourceForge.

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


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

2006-02-24 Thread [EMAIL PROTECTED]
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.

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


Re: A C-like if statement

2006-02-24 Thread Kent Johnson
Steven D'Aprano wrote:
 Now that's a Python wart: using  for the prompt for interactive
 sessions. It makes it ambiguous when posting code in email or newsgroups,
 especially once the code gets quoted a few times.

So change it. My pythonstartup.py contains:

import sys
sys.ps1 = '  '
sys.ps2 = ' ... '

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


Re: A C-like if statement

2006-02-24 Thread Antoon Pardon
Op 2006-02-23, Roy Smith schreef [EMAIL PROTECTED]:
 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.

The only motivation I have heard for this decision is to easily
find typo related bugs. I can hardly find that a fundamental
design decision.

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


KPanelApplet using Python

2006-02-24 Thread Varun Hiremath
Hi,
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.

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

2006-02-24 Thread Gerhard Häring
Magnus Lycka wrote:
 [EMAIL PROTECTED] wrote:
I'm not calling COMMIT at all.
 
 Then you must be using autocommit if your records stay in
 the table. An DB-API 2.0 compliant adapter should turn off
 autocommit by default! Does MyISAM even support proper
 commit handling? [...]

No, it doesn't. And COMMIT is then simply a no-op if it doesn't raise an 
error already.

 Oh well, Oracle will probably kill MySQL soon. 

Did you read too much Slashdot to spread such FUD?

 [...] I'd use a real database system.

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

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.

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


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread John Zenger
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(\g0). \
 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.  :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KPanelApplet using Python

2006-02-24 Thread wjzrules
I am not a Python expert, but I am using KDE on my workstation at home
and a big Python fan ;)

A couple of days ago I was thinking the same and found how to create
systray apps for Windows!
You can make this kind of apps with wxPython.

When I was at home and behind my KDE desktop I tried the Windows code
and it worked flawlessly in KDE. It was integrating into the kicker
without problems.

This was the thread that helped me out:
http://groups.google.com/group/comp.lang.python/tree/browse_frm/thread/2113ca0f132f2f49/96f32dcd5e6f96ae

Try to play with the code and you will see it will work :)

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


Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 06:45:41 -0500, Kent Johnson wrote:

 Steven D'Aprano wrote:
 Now that's a Python wart: using  for the prompt for interactive
 sessions. It makes it ambiguous when posting code in email or newsgroups,
 especially once the code gets quoted a few times.
 
 So change it. My pythonstartup.py contains:
 
 import sys
 sys.ps1 = '  '
 sys.ps2 = ' ... '

Sure, I can change my prompt. And you can change yours. And Bob can change
his. And Freddy doesn't bother. And now we've all got different prompts,
and nobody knows what's what...

It is good to be able to set your own prompt when needed. But it is also
good to have a common default prompt. And it would be good for that common
default prompt to NOT clash with email quoting standards. Therefore that
the prompt actually does clash is a wart.

That's my opinion. Yours may differ.



-- 
Steven.

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


Re: Temporary Variable

2006-02-24 Thread Jeffrey Schwab
Steven D'Aprano wrote:
 On Fri, 24 Feb 2006 00:24:25 +, Jeffrey Schwab wrote:
 
 
Steven D'Aprano wrote:

On Thu, 23 Feb 2006 12:05:59 -0800, darthbob88 wrote:

My comments inserted inline.




#!/usr/bin/python
#simple guessing game, with numbers
import random
spam = random.randint(1, 100)


It is bad programming practice to give variables uninformative joke names.

Lighten up.  This isn't the middle of a 100-KLOC corporate monstrosity, 
it's a 1/2-page usenet post.
 
 
 The original poster is also a newbie who was having trouble with the
 difference between strings and ints. If Guido called a variable spam,
 I wouldn't presume to correct him. When Newbie McNew does it, it might
 very well be because he doesn't know any better.

Sorry if I snapped at you.  But you didn't correct him, as he what he 
did wasn't wrong.  You just talked down to him.

 Just out of curiosity, when do you think is the right time to begin
 teaching programmers good practice from bad? Before or after they've
 learnt bad habits?

I'm not convinced the OP has a bad habit.  Frankly, I prefer postings 
that have a sense of humor.  I wouldn't want to see this turned into a 
purely techical forum.

import random
print , .join(['spam' for i in range(random.randint(1, 9))] +
['bacon', 'eggs', 'and']), 'spam'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A C-like if statement

2006-02-24 Thread Roy Smith
In article [EMAIL PROTECTED],
 Steven D'Aprano [EMAIL PROTECTED] wrote:

 Side-effects aren't always bad (import, for example, does all its work by
 side-effect). But they are generally frowned upon, and in functional
 languages they are verboten.

How do you do any I/O in a functional language if side effects are 
verboten?  For that matter, how does a functional program ever stop running?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: datetime iso8601 string input

2006-02-24 Thread Rubic
Magnus,

Thanks for your reply.  I wasn't clear in my
prior post.  Rather than support the entire
range of iso8601 formats, how about *just* the
format that datetime emits?  Call it the
parse_datetime() function.  Then it would be
possible to take the output string of a datetime
object and read it back in to round-trip the
data.

 now = str(datetime.datetime.now())
 now
'2006-02-24 06:58:23.737586'
 datetime.parse_datetime(now)
datetime.datetime(2006, 2, 24, 6, 58, 23, 737586)

Jeff Bauer
Rubicon, Inc.

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


problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread per9000
Dear Black Knight,

I have no quarrel with you sir Knight, but I must import your parents.


SHORT VERSION:

I tried three variants of from ../brave.py import sir_robin, one
works. I want to use it in a py-file to execute command-line-style and
that does not work.

Can someone please give me, not a bucket with the desert(s) on top, but
just the thin chocolate?

/per9000 (per nine thousand at gmail dot com)


LONG VERSION:

Since I do not want to use absoute paths I want to import a file from
two folders up and then one down.

This problem seems to be discussed in:
http://starship.python.net/pipermail/python-au/2005/000543.html
I tried following it but I did not understand and/or try hard enough
and/or my father smells of elderberrys.

So...

...first I tried this: from ../brave.py import sir_robin (and
variants)

But all I got was syntax or import error(s).

--

Then I tried to fool python by walking the path up with os.chdir('..')
in the line-by-line interpreter.
This (surprisingly) worked just fine.

C:\my\holy\grail\that_old_bridgepython
 import os
 os.chdir('../../py_scripts')
 os.getcwd()
'C:\\my\\holy\\py_scripts'
 from raw2nice_def import raw2nice
 os.listdir('.')
['raw2nice_def.py', 'raw2nice_def.pyc', 'temp']
 raw2nice
function raw2nice at 0x00A28230

--

When I tried putting this into a program to execute command-line-style:

the interesting code:

import os
cwd = os.getcwd()
os.chdir('../../py_scripts')
print os.listdir('.')
from raw2nice_def.py import raw2nice
os.chdir(cwd)

output:

 C:\another_bridge\python\python.exe rawhtml2nicehtml_template.py
['raw2nice_def.py', 'raw2nice_def.pyc', 'temp']
Traceback (most recent call last):
  File C:my\holy\grail\that_old_bridge\rawhtml2nicehtml_template.py,
line 10, in ?
from raw2nice_def.py import raw2nice
ImportError: No module named raw2nice_def.py

The worst part here is that os.listdir('.') returns ['raw2nice_def.py',
'raw2nice_def.pyc', 'temp'] - meaning (to me) that Python really should
feel my nice file but somehow still does not see it.

To me this also means that python::command_line does not concurr with
python::line_by_line(!?!)

Can someone please give me, not a bucket with the desert(s) on top, but
just the thin chocolate?

/per9000 (per nine thousand at gmail dot com)

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


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread Kent Johnson
per9000 wrote:
from raw2nice_def import raw2nice

 --
 
 When I tried putting this into a program to execute command-line-style:
 
 from raw2nice_def.py import raw2nice
 
 output:
 
C:\another_bridge\python\python.exe rawhtml2nicehtml_template.py
 
 ['raw2nice_def.py', 'raw2nice_def.pyc', 'temp']
 Traceback (most recent call last):
   File C:my\holy\grail\that_old_bridge\rawhtml2nicehtml_template.py,
 line 10, in ?
 from raw2nice_def.py import raw2nice
 ImportError: No module named raw2nice_def.py

Maybe it will work without the .py extension which is the correct form 
for an import (and what worked from the command line).

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


Re: A C-like if statement

2006-02-24 Thread Rene Pijlman
Roy Smith:
How do you do any I/O in a functional language if side effects are 
verboten?  

The user is a function. Output is its parameter, input its return value.
The user is not allowed to maintain state ;-)

For that matter, how does a functional program ever stop running?

By returning to the caller.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread Tim Williams (gmail)
On 24 Feb 2006 05:10:37 -0800, per9000 [EMAIL PROTECTED] wrote:
SHORT VERSION:I tried three variants of from ../brave.py import sir_robin, oneworks. I want to use it in a py-file to execute command-line-style andthat does not work.Can someone please give me, not a bucket with the desert(s) on top, but
just the thin chocolate?
Add the absolute path to a file called python.pth in your c:\python2x directory 
using the format: 

C:\my\holy\py_scripts (newline) 
for *each* directory and subdirectory

Then simply import the module as normal

from raw2nice_def import raw2nice

HTH :)

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

Re: A C-like if statement

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 08:03:49 -0500, Roy Smith wrote:

 In article [EMAIL PROTECTED],
  Steven D'Aprano [EMAIL PROTECTED] wrote:
 
 Side-effects aren't always bad (import, for example, does all its work by
 side-effect). But they are generally frowned upon, and in functional
 languages they are verboten.
 
 How do you do any I/O in a functional language if side effects are 
 verboten?  For that matter, how does a functional program ever stop running?

Fair enough.

But still, ignoring unavoidable cases like writing to a file, the ideal of
functional languages is for side-effects to not exist.



-- 
Steven.

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


Re: A C-like if statement

2006-02-24 Thread Diez B. Roggisch
Roy Smith wrote:

 In article [EMAIL PROTECTED],
  Steven D'Aprano [EMAIL PROTECTED] wrote:
 
 Side-effects aren't always bad (import, for example, does all its work by
 side-effect). But they are generally frowned upon, and in functional
 languages they are verboten.
 
 How do you do any I/O in a functional language if side effects are
 verboten?  For that matter, how does a functional program ever stop
 running?

Using Monads. Which basically starts carrying around explicit state in an
implicit manner. But that is restricted to very few, specific portions of
the program. 

Diez
-- 
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 Rene Pijlman
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?

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: KPanelApplet using Python

2006-02-24 Thread [EMAIL PROTECTED]
Another way to do it is to use ksystraycmd which is included with your
KDE. Some usage info is covered in my tutorial:
http://xmelegance.org/customising-window-behaviour/html/customising-window-behaviour.html

Rich.

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


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread per9000
Thanks,

I added an environment variable PYTHONPATH and added the holy folder
with my script in. Works just perfectly.

But still: is there a way around this? (It is a lot easier to add
../../ in my code than make everyone else add this variable).

/per9000

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


How to tell an object's class?

2006-02-24 Thread Edward K. Ream
 Hi,



I would like to create a dictionary of all the classes that exist while my 
app is running.  This is the best I can do:



def defineClassesDict (self):



self.allClassesDict = {}



for z in gc.get_objects():

t = type(z)

if t == types.ClassType:

name = z.__name__

elif t == types.InstanceType:

name = z.__class__.__name__

elif repr(t).startswith('class'): # A wretched kludge.

name = z.__class__.__name__

elif t == types.TypeType:

name =z.__name__

else:

name = None

if name:

self.allClassesDict [name] = z



This works, but it relies on a wretched (and slow) kludge, namely the test:



repr(t).startswith('class')



There seems to be a hole in the types module.  Can anyone suggest a better 
approach?  Thanks.



Edward

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


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

2006-02-24 Thread Peter Hansen
Magnus Lycka wrote:
 With an operating system such as Windows, this is
 probably something you can expect to happen, although
 I'm surprised if such long lag times as 200 s are typical.

No way.  I mean, I'm the biggest critic of Windows operating systems 
when used in realtime environments (at least with my customers), but 
there's no way you should probably expect a 200s delay to happen.

(You can't guarantee it won't, but seeing it on a regular basis is 
sending a clear message that something *else* is going on.  Dennis' 
guess seems a good one.)

 If you need real time characteristics, you should
 probably use a real time operating system, not Windows.

Quite true.  I doubt the OP needs that though.

-Peter

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


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread plahey
You don't _need_ to go the PYTHONPATH route (although that works).

Re-read Carsten's post (particularly step 1, see section 6.1.1).

You can use:

sys.path.append('..')
from brave import sir_robin

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


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread Carsten Haese
On Fri, 2006-02-24 at 09:10, per9000 wrote:
 Thanks,
 
 I added an environment variable PYTHONPATH and added the holy folder
 with my script in. Works just perfectly.
 
 But still: is there a way around this? (It is a lot easier to add
 ../../ in my code than make everyone else add this variable).

Yes.

From http://docs.python.org/tut/node8.html#SECTION00811:

Actually, modules are searched in the list of directories given by the
variable sys.path [...]. This allows Python programs that know what
they're doing to modify or replace the module search path.


In other words, your script may simply append other module locations
such as ../.. to sys.path.

-Carsten.


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


Re: datetime iso8601 string input

2006-02-24 Thread Peter Hansen
Rubic wrote:
 Thanks for your reply.  I wasn't clear in my
 prior post.  Rather than support the entire
 range of iso8601 formats, how about *just* the
 format that datetime emits?  Call it the
 parse_datetime() function.  Then it would be
 possible to take the output string of a datetime
 object and read it back in to round-trip the
 data.
 
  now = str(datetime.datetime.now())
  now
 '2006-02-24 06:58:23.737586'
  datetime.parse_datetime(now)
 datetime.datetime(2006, 2, 24, 6, 58, 23, 737586)
 
 Jeff Bauer
 Rubicon, Inc.

If that's truly all you want, then it's a near trivial function to 
write.  One of those throw-away functions you tend to whip up a few 
dozen times on every project, hardly noticing because you're using 
Python and it's so easy to do.

-Peter

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


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

2006-02-24 Thread Paul Probert
Grant Edwards wrote:

Time to dowload a linux CD then, eh?

  

We are looking at that very seriously. The big hurdle is that we run a 
lot of laboratory hardware that has no support under linux. A world 
where there is no more Kazaa or sasser seems like it would be wonderful, 
though.

Paul Probert
University of Wisconsin

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


Re: regular expresson for Unix and Dos Lineendings wanted

2006-02-24 Thread Tim Williams (gmail)
On 24/02/06, John Zenger [EMAIL PROTECTED] wrote:
Franz Steinhaeusler wrote: Thank you all for the replies. But I still don't have a solution.re.sub(r\s+[\n\r]+, lambda x: x.expand(\g0). \ lstrip( \t\f\v),text).rstrip()
But I think your code is a lot easier to read.:)
How about:

 linesep = '\n'
 text = 'erewr \t \r\nafjdskl \r\n \r\npythonlist' 
 linesep.join([ x.rstrip() for x in text.replace('\r\n','\n').replace('\r','\n').split('\n') ])
'erewr\nafjdskl\n\npythonlist'

Which right-strips the line endings, tabs and spaces from the ends of
lines in a string derived from either Windows, Mac and Unix or
mixed files 

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

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

2006-02-24 Thread Claudio Grondi
Claudio Grondi wrote:
 Paul Probert wrote:
 
 Peter Hansen wrote:

 Are you saying that you believe the time.sleep(1) call is actually 
 blocking for 200 seconds?
 With such rare occurrence it is very hard to tell what is going on. 
 Usually I put such strange things on a list of curiosities I don't want 
 to know the reason of, because it is in my eyes not worth the effort. 
 Maybe it is even a common problem not yet detected by me, because I have 
 never run this kind of tests for such a long time.
 Starting today, I can tell you statistically not earlier than in one 
 week, if I have the same problem on my machines (currently I am running 
 only one or two at the same time).

Here the intermediate results on my Windows XP machine connected to the 
Internet via very fast digital phone line connection (network 
card/digital-converter box/phone-line):

dt= 1.125  time= 2006_02_24_11h_36m_15s
dt= 9.20200014114  time= 2006_02_24_12h_46m_49s
dt= 1.1876376  time= 2006_02_24_14h_43m_32s

The code used:

import time
while True:
   oldtime=time.time()
   time.sleep(1.0)
   newtime=time.time()
   dt=newtime-oldtime
   if dt  1.1:
 print 'dt=',dt,' time=',time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss')

running in a command line console parallel to usual daily business on 
the computer.

The yesterday night run (5 hours) gave max. 1.125 sec., so I am 
surprized to see the 9 seconds already after only two hours today.

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


Re: make a class instance from a string ?

2006-02-24 Thread Mike Woodhouse
Is there anything particularly bad with

obj = eval(classname + ())

?

It appears to work, but I'm a noobie so I could be missing something
nasty, in which any edication would be gratefully received.

Mike

-- 
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:

 The other option is ASP. You have been given information about
 that already. Be aware that ASP does not imply VBScript. You can
 use Python in ASP as long as that's enabled. It seems to be exactly
 what you are asking for, so I don't understand why you seem to reject
 it. Don't you like the file name endings?

Maybe I'm misunderstanding what is meant when you say to use ASP. I'm 
thinking that it involves having to learn another language (such as C# 
with ASP.NET), instead of writing my code in Python. Is that not the case?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-02-24 Thread Paul Probert
Dennis Lee Bieber wrote:

On Thu, 23 Feb 2006 15:56:09 -0600, Paul Probert [EMAIL PROTECTED]
declaimed the following in comp.lang.python:


  

  Thanks for the reply. I should have mentioned, this happens to just 
about every machine in our collection of about 20 machines. Each is of a 
different age, and the hardware is completely diverse. Each has either 
of NT4, win2k, or XP installed. They all belong to our domain



   Any chance they all tend to have slow clocks, and are getting bitten
by a semi-random NTP time update; my machine tends to run the NTP update
at 7-day intervals (including time of day), counting from the last
successful synchronization.
  

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.
Thanks!

Paul Probert
University of Wisconsin

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


Re: pyserial

2006-02-24 Thread Mimi
Thanks Peter,
 because you have understood my need: a little understanding of
readlines() function.

# Following snippets of code is running in infinitive loop, but it is
not
   necessary too be worried about processor utilization because the
   readline waits for the data on the serial port and the code
continues
   to run when data occurs or when timeout passes.
#

my python script tries to read a lot of data (the histograms)  and that
can take many times (3 min) to download one file. and data do not
arrived in the same time you can wait few seconds between data ( data
response for the same command).
do you think that readlines() function will wait until all data are
arrived or when the timeout expired ?
if the data take more time, the readlines() will wait or will break on
the timeout ?
with hyperterminal the data are echoed when they arrived and you can
see that they do not arrived all the same time.
the timeout is reset when the first data arrived or it is only ignored
?

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


Re: Python vs. Lisp -- please explain

2006-02-24 Thread Kay Schluehr

Torsten Bronger wrote:
 Hallöchen!

 Paul Boddie [EMAIL PROTECTED] writes:

  Kay Schluehr wrote:
 
  I would say yes, it is still proper Python in that each RPython
  program is also a CPython program.
 
  I suppose it depends on which direction you're coming from, in
  that many Python programs just wouldn't be able to run in
  RPython. But then I can understand the convenience of having a
  subset of Python that is executable by CPython, but which can also
  be inspected and processed for other purposes, and whose programs
  maintain their semantics in both situations.

 I'm still afraid of the following scenario: Eventually, people might
 regard RPython plus type declarations (or something similar) as
 first-class Python because it's faster and runs on more
 implementations, so they try to stick to it.  So effectively you
 would have changed Python.

I wonder why you believe that it would run on more platforms? This
assertion is justifiable with regard of tiny target hardware - but
else? I do think that RPython++ could be a viable replacement for C
as a systems programming language BECAUSE it is connected closely to
Python. It is a kind of upside-down evolution: a low level language
emerges from a more high level language. We currently know only the
other side of the story. RPython would just be the common denominator
or the language interface. Gilad Bracha suggested optional type systems
for dynamic languages[1] but as it seems to me RPython would be a fine
candidate for a declarative layer, not Python.

 Maybe I misunderstood something because I could not follow all of
 Kay's text but I think one should not change Python or create a
 look-alike to allow for better implementations.  The language should
 fit my brain rather than an implementation.

It should first of all fit the diversity of a programmers needs. C was
never considered as a hostile brother of Python so why should it be
Pythons own son?

Kay

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


Re: pyserial

2006-02-24 Thread Mimi
thanks philippe,
Hi will take care for the that.

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


Re: problem(s) with import from parent dir: from ../brave.py import sir_robin

2006-02-24 Thread per9000
...and there was much rejoicing... Even better, thanks - you guys are
the best.

import string, time, sys
sys.path.append(../../py_scripts)

Works just nice, and yes, I removed the env.variable before I tried it
:-D

/Per9000

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


Re: Pickling/unpickling Cookie.SimpleCookie fails with protocol=2

2006-02-24 Thread Erwin S. Andreasen
Erwin S. Andreasen [EMAIL PROTECTED] writes:

 Pickling a Cookie.SimpleCookie (or SmartCookie) when using protocol=2
 seems to do something very strange. Protocol 0/1 work fine:

Oh well, it seems that it's a well-known bug that has been around for
more than 2 years:

http://sourceforge.net/tracker/index.php?func=detailaid=826897group_id=5470atid=105470

http://sourceforge.net/tracker/index.php?func=detailaid=964868group_id=5470atid=105470

-- 
===
[EMAIL PROTECTED]London, E14
URL:http://www.andreasen.org/ *   
===

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


Re: datetime iso8601 string input

2006-02-24 Thread Rubic
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.  ;-)

Never mind.  I'll drop it.

Jeff Bauer
Rubicon, Inc.

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


Re: Tkinter canvas size determination

2006-02-24 Thread Dean Allen Provins
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 URL:
 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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python vs. Lisp -- please explain

2006-02-24 Thread Torsten Bronger
Hallöchen!

Kay Schluehr [EMAIL PROTECTED] writes:

 Torsten Bronger wrote:

 [...]

 I'm still afraid of the following scenario: Eventually, people
 might regard RPython plus type declarations (or something
 similar) as first-class Python because it's faster and runs on
 more implementations, so they try to stick to it.  So effectively
 you would have changed Python.

 I wonder why you believe that it would run on more platforms?

I meant the following: RPython programs will run on all Python
implementations, *plus* the environments where only RPython is
possible.

 This assertion is justifiable with regard of tiny target hardware
 - but else? I do think that RPython++ could be a viable
 replacement for C as a systems programming language BECAUSE it is
 connected closely to Python.

Ah, okay.  This was a vision that I didn't understand from previous
postings.

 [...]

 Maybe I misunderstood something because I could not follow all of
 Kay's text but I think one should not change Python or create a
 look-alike to allow for better implementations.  The language
 should fit my brain rather than an implementation.

 It should first of all fit the diversity of a programmers needs. C
 was never considered as a hostile brother of Python so why should
 it be Pythons own son?

Because I think it would be tempting to add all necessary declations
in order to make one's code working with the fastest Python
implementation available.  After all, mostly we know the types,
although currently we don't declare them.  It's a purely
psychological issue: People want to create valueable code,
pythonistas even more so, ignoring that eventually it may turn out
that this was not a good idea.  Current Python *forces* us to keep
the code as flexible as possible.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetusICQ 264-296-646
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] Mod_python 3.2.8 (security)

2006-02-24 Thread Gregory (Grisha) Trubetskoy

The Apache Software Foundation and The Apache HTTP Server Project are
pleased to announce the release of version 3.2.8 of mod_python.

This release addresses a vulnerability in mod_python's FileSession
object whereby a carefully crafted session cookie could potentially
permit an attacker to execute code on the server.

FileSession was introduced in mod_python 3.2.7 released on February 15
2006 and is not enabled by default, therefore only a very small number
of installations, if any, are likely to be affected by this issue.

There are no other changes or improvements from the previous version in
this release.

Mod_python is available for download from:

http://httpd.apache.org/modules/python-download.cgi

For more information about mod_python visit http://www.modpython.org/

Regards,

Gregory Trubetskoy

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


Re: Tkinter canvas size determination

2006-02-24 Thread Martin Franklin
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 URL:
 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










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


chrtohex

2006-02-24 Thread luca72
Hello again my friends

here's my new problem.

How i can translate chr in to hex or int to integer value?

Best Regards

Luca

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


Re: pyFltk-1.1

2006-02-24 Thread kpd
Andreas,

Congratulations, it's a well polished release.

For those not familiar with FLTK, there are many examples in the
Python24/pytfltk/test directory.

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


Regular expression fun. Repeated matching of a group Q

2006-02-24 Thread matteosartori
Hi all,

I've spent all morning trying to work this one out:

I've got the following string:

td04/01/2006/tdtdWednesday/tdtdnbsp;/tdtd09:14/tdtd12:44/tdtd12:50/tdtd17:58/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtd08:14/td

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:

td03/01/2006/tdtdTuesday/tdtdAnnual_Holiday/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtdnbsp;/tdtd08:00/td

My Python regular expression to match that is currently:

digs = re.compile(
r'td(\d{2}\/\d{2}\/\d{4})/td.*?(?:td(\d+\:\d+)/td).*$' )

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

(?:td(\d+\:\d+)/td)+

 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@

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


Re: chrtohex

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

 Hello again my friends
 
 here's my new problem.
 
 How i can translate chr in to hex or int to integer value?

print %x % ord('a')

Diez


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


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

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

 The other option is ASP. You have been given information about
 that already. Be aware that ASP does not imply VBScript. You can
 use Python in ASP as long as that's enabled. It seems to be exactly
 what you are asking for, so I don't understand why you seem to reject
 it. Don't you like the file name endings?


 Maybe I'm misunderstanding what is meant when you say to use ASP. I'm 
 thinking that it involves having to learn another language (such as C# 
 with ASP.NET), instead of writing my code in Python. Is that not the 
 case?
 
 See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494
 
 The last example on this page is exactly what you have been asking for.
 
 Kent

But isn't this code:

Response.Write('Python Testbr')
Response.write('h3Smaller heading/hr')

written using ASP instead of Python?
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-02-24 Thread Scott David Daniels
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


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

2006-02-24 Thread Kent Johnson
John Salerno wrote:
 Kent Johnson wrote:
 
 John Salerno wrote:

 Magnus Lycka wrote:

 The other option is ASP. You have been given information about
 that already. Be aware that ASP does not imply VBScript. You can
 use Python in ASP as long as that's enabled. It seems to be exactly
 what you are asking for, so I don't understand why you seem to reject
 it. Don't you like the file name endings?



 Maybe I'm misunderstanding what is meant when you say to use ASP. I'm 
 thinking that it involves having to learn another language (such as 
 C# with ASP.NET), instead of writing my code in Python. Is that not 
 the case?


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

 The last example on this page is exactly what you have been asking for.

 Kent
 
 
 But isn't this code:
 
 Response.Write('Python Testbr')
 Response.write('h3Smaller heading/hr')
 
 written using ASP instead of Python?

No, it's Python code that calls the Write() method on the Response 
object that is exposed by ASP.

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


stop a doctest execution

2006-02-24 Thread Tarek Ziadé
Hello,

is there a simple way to stop a doctest execution within its code ?

my use case is to abort the execution of part of the doc, given an arbitrary condition.
That could be: existence of a third party package or whatever.

Adding tests throughout the doctest does not look good.

Maybe it's time to implement the 'exit' builtin ? ;)

Failed example:
 exit
Expected nothing
Got:
 'Use Ctrl-D (i.e. EOF) to exit.'


Tarek-- Tarek Ziadé | Association AfPy | www.afpy.orgSite personnel | http://programmation-python.org
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: make a class instance from a string ?

2006-02-24 Thread Scott David Daniels
Mike Woodhouse wrote:
 Is there anything particularly bad with
   obj = eval(classname + ())
 It appears to work, but I'm a noobie so I could be missing something
 nasty, in which any edication would be gratefully received.

It is a little too indirect.  Usually wanting to use eval or exec
means your code is probably not properly structured (a code smell).
You can pass classes around as values; you typically needn't work with
their names.  If the name comes from outside, a dictionary of names to
classes means you can re-implement your code without being tightly
coupled to your I/O formats.  If you still want to use the name
I'd go with:
 globals()[classname]()
over eval, but it is your code.

Here's a danger to think about:
Suppose your source of class names has:
 '__import__(os).system(delete critical.file)'
for a class name?


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


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

2006-02-24 Thread johnzenger
There's more to re than just sub.  How about:

sanesplit = re.split(r/tdtd|td|/td, text)
date = sanesplit[1]
times = times = [time for time in sanesplit if re.match(\d\d:\d\d,
time)]

... then date contains the date at the beginning of the line and
times contains all your times.

-- 
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:
 Maybe I'm misunderstanding what is meant when you say to use ASP. I'm 
 thinking that it involves having to learn another language (such as C# 
 with ASP.NET), instead of writing my code in Python. Is that not the case?

Nope. Just like CGI, ASP is language agnostic. It's a Microsoft
standard for embedding code in HTML pages. Look at the references
earlier in the thread and/or google for Python ASP.

Of course, the catch here is that your ISP might not have
enabled Python as a scripting language on the servers...

Finally, it's my impression that your ambition is to use some
kind of scripting to get a uniform look and navigation etc in
your web pages. This might not require any kind of dynamic
web site.

In that case I'd suggest that you simply make build some
Python tool on your own computer that builds a static version
of your entire web site in the safe and free environment of
your home. If you want to change something, you simply edit
a file at home, rebuild your site and upload the new files.

I've built a few sites like that, and if you don't really
need to serve anything but static pages, it's probably your
best bet.
  - It'll give you a snappy site. It just serves static pages.
  - You don't rely on any particular technology from your ISP,
they just need FTP etc so that you can upload your files,
and a plain web server.
  - You have the original content at home, so you always have
a backup of your web site.
  - You can use whatever tools you like to create your data
without involving your ISP.

Personally, I think HTML is a crappy language to write text
in. I prefer to use something like reST, see 
http://docutils.sourceforge.net/rst.html

 From reST there are convenient tools to get both HTML and
PDF documents--good for CVs etc. The standard tool doesn't
make room for those custom headers or footers though. There
is some help there though. Look here:
http://docutils.sourceforge.net/docs/user/links.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: make a class instance from a string ?

2006-02-24 Thread Steven D'Aprano
On Fri, 24 Feb 2006 06:37:27 -0800, Mike Woodhouse wrote:

 Is there anything particularly bad with
 
 obj = eval(classname + ())
 
 ?
 
 It appears to work, but I'm a noobie so I could be missing something
 nasty, in which any edication would be gratefully received.

In your own code, that you control? Nothing particularly bad.

In your public web application, using classname supplied by some anonymous
remote user? It could be bad:

obj = eval((lambda : os.system('ls')) + ())

only, instead of 'ls', imagine a more... serious shell command.

Using eval is like running a small piece of Python code. If you control
the code (or to be precise, the expression) then it is no more dangerous
than any other code you choose to run.

On the other hand, if you give access to your system to anonymous users,
you have to assume some of them will be malicious, and they will be a lot
more inventive searching for security holes than you.


-- 
Steven.

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


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

2006-02-24 Thread Gerard Flanagan
John Salerno wrote:
 Kent Johnson wrote:
  John Salerno wrote:
  Magnus Lycka wrote:
 
  The other option is ASP. You have been given information about
  that already. Be aware that ASP does not imply VBScript. You can
  use Python in ASP as long as that's enabled. It seems to be exactly
  what you are asking for, so I don't understand why you seem to reject
  it. Don't you like the file name endings?
 
 
  Maybe I'm misunderstanding what is meant when you say to use ASP. I'm
  thinking that it involves having to learn another language (such as C#
  with ASP.NET), instead of writing my code in Python. Is that not the
  case?
 
  See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B276494
 
  The last example on this page is exactly what you have been asking for.
 
  Kent

 But isn't this code:

 Response.Write('Python Testbr')
 Response.write('h3Smaller heading/hr')

 written using ASP instead of Python?


Here's a demo script called 'tut1.asp' located in
'site-packages\win32comext\axscript\Demos\client\asp':

HTML

SCRIPT Language=Python RUNAT=Server

for i in range(3,8):
  Response.Write(FONT SIZE=%dHello World!!BR % i)

/SCRIPT

/HTML

###

and here is 'CreateObject.asp' from the same directory:

HTML

SCRIPT Language=Python RUNAT=Server

# Just for the sake of the demo, our Python script engine
# will create a Python.Interpreter COM object, and call that.

# This is completely useless, as the Python Script Engine is
# completely normal Python, and ASP does not impose retrictions, so
# there is nothing the COM object can do that we can not do natively.

o = Server.CreateObject(Python.Interpreter)

Response.Write(Python says 1+1= + str(o.Eval(1+1)))

/SCRIPT

/HTML


Gerard

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


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

2006-02-24 Thread matteosartori
Thanks,

The date = sanesplit[1] line complains about the list index being out
of range, which is probably due to the fact that not all lines have
the td in them, something i didn't explain in the previous post.

I'd need some way of ensuring, as with the pattern I'd concocted, that
a valid line actually starts with a td containing a / separated date
tag.

As an aside, is it not actually possible to do what I was trying with a
single pattern or is it just not practical?

M@

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


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

2006-02-24 Thread Scott David Daniels
Paul Probert wrote:
 Yes, I'm doing this:
   .
  oldtime=time.time()
  time.sleep(1)
  newtime=time.time()
  dt=newtime-oldtime
   if dt  2:
   print 'dt=',dt,' time=',time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss')
 Its happening roughly 4 times a day total on our 20 machines, ie about 
 once every 5 days on a given machine.

Well, you have a guess about the time updates that may well tell you
all.  Because of that guess, you might want to try:

   oldtime = time.time()
   time.sleep(1)
   newtime = time.time()
   delta = newtime - oldtime
   if not .5  delta  2:
   print 'delta=%s, from=%s, time=%s' % (
   delta, time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss',
time.gmtime(oldtime)),
   time.strftime('%Y_%m_%d_%Hh_%Mm_%Ss',
time.gmtime(newtime)))

to see if you get time running backwards as well.

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


Re: pyserial

2006-02-24 Thread Petr Jakes
I can recommend you to read pyserial documentation and look to the
examples. Browsing through this discussion group can help you a lot as
well.
Generally if the timeout is set to 0 (zero) the code will wait and wait
and wait till the data will arrive to the serial port (if there is not
data on the serial port, you can wait forever and you can think your
code is frozen :) )
Because of that, you can set the timeout, so after some time of waiting
for the data (when the data do not arrive) the code continues on the
next line.

Try to experiment a little bit with some simple and short code first,
so you will be able to understand how to communicate with the serial
port.
HTH
Petr Jakes

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


groupwise send mail

2006-02-24 Thread ericoneal
Can someone give me an idea as to why this is not working?  The
Recipients.Add line doesnt cause an error, but my recipients arent
being used.  The email never gets sent because there is no recipeients.

Thanks,
Eric


import win32com.client
gwApp = win32com.client.Dispatch('NovellGroupWareSession')
acct1 = gwApp.Login(NDS:\\Tree_Name,user.context, )
oMail = acct1.MailBox.Messages.Add (GW.Message.Mail, Draft)
oMail.fromtext = Python Hazmat Script
oMail.Recipients.Add([EMAIL PROTECTED])
oMail.Subject.PlainText = Script error
oMail.BodyText.PlainText = The Python Hazmat script failed
oMail.send
gwApp.quit

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


Re: chrtohex

2006-02-24 Thread Scott David Daniels
luca72 wrote:
 Hello again my friends
 
 here's my new problem.
 
 How i can translate chr in to hex or int to integer value?
 
 Best Regards
 
 Luca
 
By demonstrating that you have tried to solve the problem yourself.
See:
 http://www.catb.org/~esr/faqs/smart-questions.html

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


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

2006-02-24 Thread Diez B. Roggisch
Bo Peng wrote:

 Dear list,
 
 I have not done a thorough test, but it occurs to me that
 
 1. python code can be interrupted by Ctrl-C.
 2. A C module, if I add a main() function and run independently, can be
 interrupted by Ctrl-C.
 3. If I load the C module in python and run, the program will not
 respond to Ctrl-C interruption. I have to kill python explicitly.
 
 If this is a known behavior or just a special case of mine? Any fix to
 it? I am using python 2.3.4 under Redhat EL4 with gcc 3.3.4.

I fear it is a known behavior and not easy to fix. See the module signal
docs:


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.

Diez
-- 
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  td'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   >