More Rewrite Request Within SocketServer?

2005-05-27 Thread John Abel
OK, I'm guessing what I was after ( see below ) isn't possible.  Does 
anyone know of an easy way of having verify_request inform the request 
handler of certain events, say client is unauthorised?  I thought of 
having it set a flag, and referring to it from the handler class ( 
self.server.hostAllowed for example ), but that wouldn't work quite 
right in a threaded server.

Any ideas?

J

 Original Message 
Subject:ReWrite Request Within SocketServer?
Date:   Wed, 25 May 2005 17:04:53 +0100
From:   John Abel <[EMAIL PROTECTED]>
To: python-list@python.org



Hi!

I may be missing something simple, but is there a way to have 
verify_request change the request before it gets processed by the 
RequestHandlerClass?

Regards

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



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


Re: More Rewrite Request Within SocketServer?

2005-05-27 Thread Paul Rubin
John Abel <[EMAIL PROTECTED]> writes:
> OK, I'm guessing what I was after ( see below ) isn't possible.  Does
> anyone know of an easy way of having verify_request inform the request
> handler of certain events, say client is unauthorised?  I thought of
> having it set a flag, and referring to it from the handler class (
> self.server.hostAllowed for example ), but that wouldn't work quite
> right in a threaded server.

I'd think you could do that.  Isn't the new thread already started
when the verify method runs?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: More Rewrite Request Within SocketServer?

2005-05-27 Thread John Abel
Paul Rubin wrote:

>John Abel <[EMAIL PROTECTED]> writes:
>  
>
>>OK, I'm guessing what I was after ( see below ) isn't possible.  Does
>>anyone know of an easy way of having verify_request inform the request
>>handler of certain events, say client is unauthorised?  I thought of
>>having it set a flag, and referring to it from the handler class (
>>self.server.hostAllowed for example ), but that wouldn't work quite
>>right in a threaded server.
>>
>>
>
>I'd think you could do that.  Isn't the new thread already started
>when the verify method runs?
>  
>
Unfortunately not.  verify_request is called before process_request 
which launches the thread ( in the ThreadingMixIn version ).  Unless I 
passed the flag as an argument to the thread, and then had it reset.  
Hm, worth thinking about,

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


Re: Running a python program during idle time only

2005-05-27 Thread Shane Hathaway
Mike Meyer wrote:
> On a completely different topic, this looks like the wrong way to solve
> the problem. You want to update a search engine based on changes to the
> underlying file system. The right way to do this isn't to just keep
> rescanning the file system, it's to arrange things so that your scanner
> gets notified of any changes made to the file system. I did something like 
> this for my web site search engine, but that's hooked into the SCM that's
> used for propogating changes to the web site. I know someone is working
> on patches to the FreeBSD kernel to make this kind of thing work. It would
> seem that some of the "backup" facilities that worked by keeping a mirror
> of the disk on separate media would have to have used such hooks, but maybe
> not.

I think you're right that filesystem change notification is what Carlos
needs.

If you're interested in using Linux, Carlos, "inotify" is a new kernel
module that can notify your program of filesystem changes.  It's not
folded into the mainline kernel yet, but it's a clean patch.

http://www.edoceo.com/creo/inotify/

I don't know if Windows has anything like it.  I'd be interested to hear
if it does.

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


Re: More Rewrite Request Within SocketServer?

2005-05-27 Thread Paul Rubin
John Abel <[EMAIL PROTECTED]> writes:
> Unfortunately not.  verify_request is called before process_request
> which launches the thread ( in the ThreadingMixIn version ).  Unless I
> passed the flag as an argument to the thread, and then had it reset.
> Hm, worth thinking about,

If verify_request is finished before the new thread starts, then I'd
think it could set a flag and the new thread could find it.  You get a
race condition only if both threads are trying to mess with the flag
simultaneously.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a python program during idle time only

2005-05-27 Thread John Abel
Shane Hathaway wrote:

>Mike Meyer wrote:
>  
>
>>On a completely different topic, this looks like the wrong way to solve
>>the problem. You want to update a search engine based on changes to the
>>underlying file system. The right way to do this isn't to just keep
>>rescanning the file system, it's to arrange things so that your scanner
>>gets notified of any changes made to the file system. I did something like 
>>this for my web site search engine, but that's hooked into the SCM that's
>>used for propogating changes to the web site. I know someone is working
>>on patches to the FreeBSD kernel to make this kind of thing work. It would
>>seem that some of the "backup" facilities that worked by keeping a mirror
>>of the disk on separate media would have to have used such hooks, but maybe
>>not.
>>
>>
>
>I think you're right that filesystem change notification is what Carlos
>needs.
>
>If you're interested in using Linux, Carlos, "inotify" is a new kernel
>module that can notify your program of filesystem changes.  It's not
>folded into the mainline kernel yet, but it's a clean patch.
>
>http://www.edoceo.com/creo/inotify/
>
>I don't know if Windows has anything like it.  I'd be interested to hear
>if it does.
>
>Shane
>  
>
Using the PyWin32 extensions, you can register an event with the kernel, 
and then have the script sleep.  If I can remember how, I'll post some 
code.  It's been a while since I coded specific Win32 stuff.

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


Re: how to accomplish dl progress bars?

2005-05-27 Thread Edvard Majakari
"flamesrock" <[EMAIL PROTECTED]> writes:

> Certain web applications, everything from wget to downloader for X has
> this nifty feature I'd like to accomplish in python.
>
> Its the progress bar/time elapsed/time remaining scheme
>
> Filename  | Progress| Speed (kB/s) | T/Elapsed | T/Remaining
> 
> blah.bin  |-->45%   | 56.6 |   02:39   |   02:45
> file2.bz2 |--->33%  | 35.0 |   05:22   |   11:24
> etc   |>60% | 47.5 |   00:14   |   00:08

See python cookbook. The idea is simply to print out stuff and when updating,
erase previous characters eg. using '\r' ASCII code. Python Cookbook has a
progress bar implementation, you could use that as a basis for your code
(speed, t/elapsed and t/remaining are technically no different; if you can do
a progress bar, you can do those others as well).

-- 
# Edvard Majakari   Software Engineer
# PGP PUBLIC KEY available  Soli Deo Gloria!

$_ = '456476617264204d616a616b6172692c20612043687269737469616e20'; print
join('',map{chr hex}(split/(\w{2})/)),uc substr(crypt(60281449,'es'),2,4),"\n";
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a python program during idle time only

2005-05-27 Thread John Abel
John Abel wrote:

>Shane Hathaway wrote:
>
>  
>
>>Mike Meyer wrote:
>> 
>>
>>
>>
>>>On a completely different topic, this looks like the wrong way to solve
>>>the problem. You want to update a search engine based on changes to the
>>>underlying file system. The right way to do this isn't to just keep
>>>rescanning the file system, it's to arrange things so that your scanner
>>>gets notified of any changes made to the file system. I did something like 
>>>this for my web site search engine, but that's hooked into the SCM that's
>>>used for propogating changes to the web site. I know someone is working
>>>on patches to the FreeBSD kernel to make this kind of thing work. It would
>>>seem that some of the "backup" facilities that worked by keeping a mirror
>>>of the disk on separate media would have to have used such hooks, but maybe
>>>not.
>>>   
>>>
>>>  
>>>
>>I think you're right that filesystem change notification is what Carlos
>>needs.
>>
>>If you're interested in using Linux, Carlos, "inotify" is a new kernel
>>module that can notify your program of filesystem changes.  It's not
>>folded into the mainline kernel yet, but it's a clean patch.
>>
>>http://www.edoceo.com/creo/inotify/
>>
>>I don't know if Windows has anything like it.  I'd be interested to hear
>>if it does.
>>
>>Shane
>> 
>>
>>
>>
>Using the PyWin32 extensions, you can register an event with the kernel, 
>and then have the script sleep.  If I can remember how, I'll post some 
>code.  It's been a while since I coded specific Win32 stuff.
>
>J
>  
>
Couldn't find my code, but this page has various ways of doing it on Win32.

http://tgolden.sc.sabren.com/python/win32_how_do_i/watch_directory_for_changes.html

HTH

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


Re: More Rewrite Request Within SocketServer?

2005-05-27 Thread John Abel
Paul Rubin wrote:

> If verify_request is finished before the new thread starts, then I'd
>
>think it could set a flag and the new thread could find it.  You get a
>race condition only if both threads are trying to mess with the flag
>simultaneously.
>  
>
Hmm, I think you're right.  Thanks!

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


Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Duncan Booth
Dennis Lee Bieber wrote:

> On 26 May 2005 17:33:33 -0700, "Elliot Temple" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
> 
>> Thanks for the link on case sensitivity.  I'm curious about the person
>> who found case sensitivity useful though: what is it useful for?
>> 
>  Making a language run faster on slow machines since the syntax
> parsing doesn't have to do the equivalent of upper or lower casing
> anything that is not a string literal before checking for keywords or
> identifiers.
> 
>  Consider the time spent by languages like Ada and Fortran when
> they have to do case normalization every time you compile.
> 
That isn't a good argument for case sensitivity. You really aren't going to 
be able to measure a slowdown in compilation speed just because the 
compiler has to lowercase all the identifiers before using them.

What I consider good arguments for case sensitivity are:

Consistency. I've used non-case sensitive languages where the same variable 
was spelled sometimes with capitals and sometimes without. Forcing you to 
choose one case and stick to it is, IMHO a good thing. Worse, I've used 
Visual Basic where the editor will gratuitously change the case of a 
variable you just typed in because there is another occurrence of the same 
name somewhere else in a different case.

Conventions such as capitalising class names, or camelCasing can be useful. 
Again this only applies if they are used consistently.

Interoperability. Like it or not, there are other case sensitive systems 
out there. I once had the misfortune to use a Microsoft Access database 
(where lookups on indexed fields are case insensitive) to store records 
indexed by a case sensitive medical coding system. Codes in that system do 
exist which differ from other completely unrelated conditions only by the 
case of the code. The only way to handle this in a case insensitive system 
is to somehow escape each case sensitive code.

That particular example wouldn't necessarily apply to a case insensitive 
programming language, but plenty of others would: e.g. using a remote 
procedure call system to call a (case sensitive) function on another 
system.

In all such cases, the case insensitive system is the 'poor relation', it 
is the one where you have to introduce workrounds in order to communicate 
with the case sensitive system. Going in the other direction (calling a 
case insensitive function from a case sensitive system) you simply have to 
invent a convention (e.g. lowercase everything) and stick by it.

There are arguments that, especially for beginners, case sensitivity 
introduces an extra level of complexity, but the cost of losing this 
complexity would be to make Python a poor relation amongst programming 
languages.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ftplib fails when directory name contains spaces

2005-05-27 Thread Manu
Oops..It was my mistake :(.
Directory name with spaces work by default.

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


Re: Running a python program during idle time only

2005-05-27 Thread John Abel
Shane Hathaway wrote:

>Mike Meyer wrote:
>  
>
>>On a completely different topic, this looks like the wrong way to solve
>>the problem. You want to update a search engine based on changes to the
>>underlying file system. The right way to do this isn't to just keep
>>rescanning the file system, it's to arrange things so that your scanner
>>gets notified of any changes made to the file system. I did something like 
>>this for my web site search engine, but that's hooked into the SCM that's
>>used for propogating changes to the web site. I know someone is working
>>on patches to the FreeBSD kernel to make this kind of thing work. It would
>>seem that some of the "backup" facilities that worked by keeping a mirror
>>of the disk on separate media would have to have used such hooks, but maybe
>>not.
>>
>>
>
>I think you're right that filesystem change notification is what Carlos
>needs.
>
>If you're interested in using Linux, Carlos, "inotify" is a new kernel
>module that can notify your program of filesystem changes.  It's not
>folded into the mainline kernel yet, but it's a clean patch.
>
>http://www.edoceo.com/creo/inotify/
>
>I don't know if Windows has anything like it.  I'd be interested to hear
>if it does.
>
>Shane
>  
>
As an alternative to inotify there's this 
http://oss.sgi.com/projects/fam/, with various libraries ( Perl, Python, 
etc ).

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


Re: Writing a bytecode interpreter (for TeX dvi files)

2005-05-27 Thread Andreas Lobinger
Aloha,

Jonathan Fine wrote:
> I'm writing some routines for handling dvi files.
> In case you didn't know, these are TeX's typeset output.
> These are binary files containing opcodes.
> I wish to write one or more dvi opcode interpreters.
> Are there any tools or good examples to follow for
> writing a bytecode interpreter?

As far as i know, dvi is a very straight forward format, commands
followed by parameters, no conditionals, no loops.
For similar designs i used something like the following approach:

s = file('a.dvi','r').read() # read complete file to string

while s:
command = ord(s[0])

 if command < 128:
#typeset command
s = s[1:]
 elif command = 139:
#bop command
param = s[:40]
#interpret param
   c = struct.unpack('D',param[:3])
#consume s
s = s[41:]
 else:
#undefined command
s = s[1:]

You can work directly on strings, or convert to a list. If you don't
want long if/elif lists, you can use a dict as a dispatcher (python
cookbook has an example?). For most of the commands you can use
a lookup table for the parameter list length.
TeX §591 claims, that dvi is stricly interpretable from front to end.
The description in Tex§585++ can be transcripted to struct definitions
easily.

Wishing a happy day
LOBI

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


[OT] Re: Python analog of Ruby on Rails?

2005-05-27 Thread d'yeux le pair
Shane Hathaway a écrit :
> 
> BTW, here's the proper response to that religious thread that keeps
> invading this list:
> 
> python -c 'print sum([ord(c) for c in "HOLYBIBLE"])'
> 
> I'm Christian and I think it's funny. ;-)

Aha. Notice that the Original Sin story admits a defensible reading
while equating the Holy Bible to the (in)famous tree.

Some background:
> 
> http://scriptures.lds.org/rev/13/16-18#16

Given context(s), I particularly like the solution (in .sig format) :

666?? -- 666 ~ .666 ~  2/3 ~ 1-1/3 ~ tertium non datur ~ the excluded middle
  ~ "either you are with us, or you are against us"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What are OOP's Jargons and Complexities?

2005-05-27 Thread Piet van Oostrum
> "Xah Lee" <[EMAIL PROTECTED]> (XL) wrote:

>XL> Joe: lang x is strongly typed
>XL> Dave: you mean statically typed?
>XL> John: no no, that's weakly typed.

That should have been `weekly typed', according to the link below.
Maybe there is also `daily typed' or `monthly typed'?

>XL> http://xahlee.org/UnixResource_dir/writ/jargons.html

-- 
Piet van Oostrum <[EMAIL PROTECTED]>
URL: http://www.cs.uu.nl/~piet [PGP]
Private email: [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption with Python?

2005-05-27 Thread TZOTZIOY
On 26 May 2005 14:45:28 -0700, rumours say that Paul Rubin
 might have written:

>> That's all.  I see you took up the challenge and indirectly replied to
>> my last question, and in good spirit I say you earned a little respect
>> from me, at least for standing up to your words.  Now I hope no-one
>> gives a try to your data (for your own sake :)

>I don't think the challenge was really accepted.  The algorithm
>changed between when you issued the challenge, and when the sensitive
>data went up.  A good algorithm doesn't need to change depending on
>the data.  I agree with the poster who said that the strength of
>either one of the algorithms is irrelevant, if the keyspace is just 32
>bits.

You are correct; the algorithm changed, and the OP admitted it himself
in the post with the encrypted credit card data.

However, on a practical level: before posting, I did a quick comparison,
and the only effective change to OP's algorithm was a the addition of a
`random.shuffle(sequence)', which AFAIU has no practical consequences as
to whether his algorithm is unbreakable or not.

I could say that "hey, you changed the algorithm, and that means your
previous declaration of unbreakability wasn't." but honestly I was
overwhelmed by the audacity (and foolishness, if these are truly his
credit card data) of Frederic.



ObSF: DNA; The Restaurant At The End Of The Universe; Marvin the
paranoid android faces a gigantic black tank in the H2G2 HQ.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list


Xml writing in Python and verifying using XSD

2005-05-27 Thread Prashanth Ellina
Hi,

I need to write some data to an xml file. I have an XML Schema defined.
I would like to use some mechanism of writing the data to the xml file
and having exceptions thrown back to me when the data is invalid.

I have looked at xml.dom and xml.dom.minidom but could not figure out
what to do to include xml validation using the xsd while writing.

Any ideas?

Thanks in advance,
Prashanth Ellina

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


CygWin ODBC

2005-05-27 Thread Simon Faulkner
Hi All,

I am new to Cygwin and am hoping that someone here will be able to tell 
me how to get ODBC running in Python on Cygwin.

Maximum gratefullness...


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


struct unpack newline

2005-05-27 Thread grant
Hi All,

I am pretty new to python and am having a problem
intepreting binary data using struct.unpack.
I am reading a file containing binary packed data
using open with "rb". All the values are coming through
fine when using (integer1,) = struct.unpack('l', line[86:90])
except when line[86:90] contains "carriage-return" "linefeed"
which are valid binary packed values. Error = unpack
string size dows not match format. It seems that
struct, instead of reading 4 bytes for line[86:90]
only reads 2 bytes if the second byte is CR or LF.

Thanks
Grant

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


Re: struct unpack newline

2005-05-27 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

> I am pretty new to python and am having a problem
> intepreting binary data using struct.unpack.
> I am reading a file containing binary packed data
> using open with "rb". All the values are coming through
> fine when using (integer1,) = struct.unpack('l', line[86:90])
> except when line[86:90] contains "carriage-return" "linefeed"
> which are valid binary packed values. Error = unpack
> string size dows not match format. It seems that
> struct, instead of reading 4 bytes for line[86:90]
> only reads 2 bytes if the second byte is CR or LF.

verifying that struct doesn't care about newlines is of course
pretty trivial:

>>> import struct
>>> struct.unpack("l", "\0\0\0\0")
(0,)
>>> struct.unpack("l", "\0\r\0\0")
(3328,)
>>> struct.unpack("l", "\0\n\0\0")
(2560,)

have you verified that len(line) really is what you think?

>>> struct.unpack("l", "\0\r\n\0")
(658688,)
>>> struct.unpack("l", "\0\n\0")
Traceback (most recent call last):
  File "", line 1, in ?
struct.error: unpack str size does not match format

 



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


Re: Intellisense and the psychology of typing

2005-05-27 Thread EventHelix.com
Intellisense does improve programmer productivity as
you do not have to keep opening header files to refer
to the interfaces. In VC++ the intellisense display
also shows the function header comment, so you have
full access to the information about the interface.

Deepa
--
EventStudio 2.5 - http://www.EventHelix.com/EventStudio
Model in Plain Text; Generate Sequence Diagrams in PDF/Word

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


[ANN] pylint 0.7

2005-05-27 Thread Sylvain Thénault
Hello all !

I'm pleased to announce a new release of PyLint. I've been promising a
1.0 release some time ago, but it appears I've not enough time yet to
do the polishing I wish, and since the latest (0.6.4) release has a
few really annoying bugs (mainly related to options handling), I
eventually decided to make this intermediate release. It mainly
targets bug fixes but as the main pylint package has moved (it's not
anymore a logilab'subpackage), I've made a 0.7 instead of a
0.6.5. Some others fixes and minor enhancements are included (see
below for a more detailed list), and this release should be really
stable. Please send any bugs or comments on the mailing list.


What's new ?

* WARNING: pylint is no longer a logilab subpackage. Users may have to
  manually remove the old logilab/pylint directory.

* this time, real fix of the "disable-msg in the config file" problem,
  test added to unittest_lint

* fix a bug in the variables checker which may causing some false
  positives when variables are defined and used within the same
  statement (test func_noerror_defined_and_used_on_same_line)

* fix bug with --list-messages and python -OO

* fix possible false positive for W0201

* introduce a new --additional-builtins option to handle user defined
  builtins 

* --reports option has now -r as short alias, and -i for --include-ids


What is pylint ?


Pylint is a python tool that checks if a module satisfy a coding
standard. Pylint can be seen as another pychecker since nearly all
tests you can do with pychecker can also be done with Pylint. But
Pylint offers some more features, like checking line-code's length,
checking if variable names are well-formed according to your coding
standard, or checking if declared interfaces are truly implemented,
and much more (see http://www.logilab.org/projects/pylint/ for the
complete check list). The big advantage with Pylint is that it is
highly configurable, customizable, and you can easily write a small
plugin to add a personal feature.

The usage it quite simple :

$ pylint mypackage.mymodule


This command will output all the errors and warnings related to the
tested code (here : mypackage.mymodule), will dump a little summary at
the end, and will give a mark to the tested code.

Pylint is free software distributed under the GNU Public Licence.


Home page
-
http://www.logilab.org/projects/pylint

Download

ftp://ftp.logilab.org/pub/pylint

Mailing list

mailto://[EMAIL PROTECTED]

Enjoy !
-- 
Sylvain Thénault   LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org

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


Re: struct unpack newline

2005-05-27 Thread Richard Brodie

<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]

> except when line[86:90] contains "carriage-return" "linefeed"
> which are valid binary packed values.

You probably don't want to be reading binary data a
line at a time, if that's what you're doing.


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


Incrementing letters

2005-05-27 Thread Michael
Hi,
I've got a string s, and i want to shift all the letters up by one, eg a->b,
b->c  z->a
In c++ i can do this quite simply with

if(C == 'z') C='a';
else C++;

but i can't work out how to do this this in python??

Regards

Michael


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


Re: Incrementing letters

2005-05-27 Thread Heiko Wundram
Am Freitag, 27. Mai 2005 13:31 schrieb Michael:
> if(C == 'z') C='a';
> else C++;

if C == "z":
  C = "a"
else:
  C = chr(ord(C)+1)

-- 
--- Heiko.
  see you at: http://www.stud.mh-hannover.de/~hwundram/wordpress/


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

Re: Strange Execution Times

2005-05-27 Thread John Machin
Elliot Temple wrote:
> 
> On May 26, 2005, at 3:22 PM, John Machin wrote:
> 
>>
>> Then post your summarised results back to the newsgroup for the  
>> benefit of all -- there's this vague hope that folk actually read  
>> other peoples' posts before firing off questions :-)
> 
> 
> Here is my new version.  It runs in about .65 seconds.  The trick?   
> Reading lines one at a time.  Please let me know if there's any bad  
> coding practices in it!
> 
> 

> for line in f:
> start, end = line.find(p1) + adjust, line.find(p2)
> if end != -1:
> digest = md5.new(line[start:end]).hexdigest()
> out.write(line[:start] + digest + line[end:])
> else:
> out.write(line)
> 

Hmmm ... simple, elegant *and* runs fast!

Only two minor points:

1. Your code assumes that there can be no more than one password per 
line and that there are no "syntax errors". I'd add at least a comment 
to that effect.

2. The scan for p2 is wasted if the scan for p1 finds nothing. If p1 is 
found, you scan for p2 from the beginning of the line. Depending on the 
average length of a line, etc, that could make a difference. Try this:

for line in f:
 start = line.find(p1)
 if start == -1:
 out.write(line)
 else:
 start += adjust
 end = line.find(p2, start)
 if end == -1:
 raise CannotHappenError
 digest = md5.new(line[start:end]).hexdigest()
 out.write(line[:start] + digest + line[end:])

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Strings for a newbie

2005-05-27 Thread Malcolm Wooden
I'm trying to get my head around Python but seem to be failing miserably. I 
use RealBasic on a Mac and find it an absolute dream! But PythonUGH!

I want to put a sentence of words into an array, eg "This is a sentence of 
words"

In RB it would be simple:

Dim s as string
Dim a(-1) as string
Dim i as integer

s = "This is a sentence of words"
For i = 1 to CountFields(s," ")
  a.append NthField(s," ",i)
next

That's it an array a() containing the words of the sentence.

Now can I see how this is done in Python? - nope!

UGH!

Malcolm
(a disillusioned Python newbie) 


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


Re: Strings for a newbie

2005-05-27 Thread Mage
Malcolm Wooden wrote:

>In RB it would be simple:
>
>Dim s as string
>Dim a(-1) as string
>Dim i as integer
>
>s = "This is a sentence of words"
>For i = 1 to CountFields(s," ")
>  a.append NthField(s," ",i)
>next
>
>That's it an array a() containing the words of the sentence.
>
>Now can I see how this is done in Python? - nope!
>  
>

s = "This is a sentence of words"
print s.split(' ')

Mage


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


Re: Strings for a newbie

2005-05-27 Thread John Machin
Malcolm Wooden wrote:
> I'm trying to get my head around Python but seem to be failing miserably. I 
> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!
> 
> I want to put a sentence of words into an array, eg "This is a sentence of 
> words"
> 
> In RB it would be simple:
> 
> Dim s as string
> Dim a(-1) as string
> Dim i as integer
> 
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
>   a.append NthField(s," ",i)
> next
> 
> That's it an array a() containing the words of the sentence.
> 
> Now can I see how this is done in Python? - nope!
> 
> UGH!
> 
> Malcolm
> (a disillusioned Python newbie) 
> 
> 


 >>> s = "This is a sentence of words"
 >>> a = s.split()
 >>> a
['This', 'is', 'a', 'sentence', 'of', 'words']
 >>>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings for a newbie

2005-05-27 Thread Wolfram Kraus
Malcolm Wooden wrote:
> I'm trying to get my head around Python but seem to be failing miserably. I 
> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!
> 
> I want to put a sentence of words into an array, eg "This is a sentence of 
> words"
> 
> In RB it would be simple:
> 
> Dim s as string
> Dim a(-1) as string
> Dim i as integer
> 
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
>   a.append NthField(s," ",i)
> next
> 
> That's it an array a() containing the words of the sentence.
> 
> Now can I see how this is done in Python? - nope!
> 
> UGH!
> 
> Malcolm
> (a disillusioned Python newbie) 
> 
> 
Use split:

 >>> s = "This is a sentence of words"
 >>> s.split()
['This', 'is', 'a', 'sentence', 'of', 'words']

See:
http://www.python.org/doc/2.4.1/lib/string-methods.html#l2h-202

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


Re: Incrementing letters

2005-05-27 Thread Wolfram Kraus
Heiko Wundram wrote:
> Am Freitag, 27. Mai 2005 13:31 schrieb Michael:
> 
>>if(C == 'z') C='a';
>>else C++;
> 
> 
> if C == "z":
>   C = "a"
> else:
>   C = chr(ord(C)+1)
> 
According to the OP's problem (with the assumption that only characters 
  from a-z are given) he might even try a lil LC:
 >>> s = "shiftthis"
 >>> ''.join([chr(((ord(x)-ord('a')+1)%26)+ord('a')) for x in s])
'tijguuijt'


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


Re: Strings for a newbie

2005-05-27 Thread Sergei Organov
"Malcolm Wooden" <[EMAIL PROTECTED]> writes:

> I'm trying to get my head around Python but seem to be failing miserably. I 
> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!
> 
> I want to put a sentence of words into an array, eg "This is a sentence of 
> words"
> 
> In RB it would be simple:

Simple?! 7 lines of code for such a trivial task is simple?!

> Dim s as string
> Dim a(-1) as string
> Dim i as integer
> 
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
>   a.append NthField(s," ",i)
> next
> 
> That's it an array a() containing the words of the sentence.
> 
> Now can I see how this is done in Python? - nope!

from string import split
s = "This is a sentence of words"
a = split(s)

or,

s = "This is a sentence of words"
a = s.split()

or even

a = "This is a sentence of words".split()

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


Re: Incrementing letters

2005-05-27 Thread Duncan Booth
Michael wrote:

> Hi,
> I've got a string s, and i want to shift all the letters up by one, eg
> a->b, b->c  z->a
> In c++ i can do this quite simply with
> 
> if(C == 'z') C='a';
> else C++;
> 
> but i can't work out how to do this this in python??

>>> import string
>>> upone = string.maketrans(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')
>>> string.translate("I've got a string s", upone)
"J'wf hpu b tusjoh t"
>>> 

Note the difference though: the Python code does what you said you wanted, 
whereas your sample code corrupts punctuation.
-- 
http://mail.python.org/mailman/listinfo/python-list


VIRUS WARNING W32/Mydoom.O@mm

2005-05-27 Thread viruscontrol
This is a notice from Architec hosting. You sent an email infected with a 
virus. Please take action and clean your computerReceived: (qmail 16811 
invoked from network); 27 May 2005 12:23:38 -
Received: from unknown (HELO python.org) (81.199.115.158)  by 
server8.architec.co.uk with SMTP; 27 May 2005 12:23:38 -
From: python-list@python.org
To: [EMAIL PROTECTED]
Subject: Delivery failed
Date: Fri, 27 May 2005 13:31:32 +0100
MIME-Version: 1.0
Content-Type: multipart/mixed;  
boundary="=_NextPart_000_0003_EF0D45FE.86BC9EEE"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.

Content-Type: text/plain;   charset=us-ascii
Content-Transfer-Encoding: 7bit

Content-Type: application/octet-stream; name="[EMAIL PROTECTED]"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;filename="[EMAIL PROTECTED]"

-=_NextPart_000_0003_EF0D45FE.86BC9EEE--


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


Re: Strings for a newbie

2005-05-27 Thread Malcolm Wooden
Sorry John but that don't do it for me. Just get errors comming back


"John Machin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Malcolm Wooden wrote:
>> I'm trying to get my head around Python but seem to be failing miserably. 
>> I use RealBasic on a Mac and find it an absolute dream! But 
>> PythonUGH!
>>
>> I want to put a sentence of words into an array, eg "This is a sentence 
>> of words"
>>
>> In RB it would be simple:
>>
>> Dim s as string
>> Dim a(-1) as string
>> Dim i as integer
>>
>> s = "This is a sentence of words"
>> For i = 1 to CountFields(s," ")
>>   a.append NthField(s," ",i)
>> next
>>
>> That's it an array a() containing the words of the sentence.
>>
>> Now can I see how this is done in Python? - nope!
>>
>> UGH!
>>
>> Malcolm
>> (a disillusioned Python newbie)
>
>
> >>> s = "This is a sentence of words"
> >>> a = s.split()
> >>> a
> ['This', 'is', 'a', 'sentence', 'of', 'words']
> >>> 


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


Re: Strings for a newbie

2005-05-27 Thread John Machin
Malcolm Wooden wrote:
> Sorry John but that don't do it for me. Just get errors comming back
> 
> 
> "John Machin" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 

>>
>s = "This is a sentence of words"
>a = s.split()
>a
>>
>>['This', 'is', 'a', 'sentence', 'of', 'words']
>>

Malcolm,

What errors did you get? Please post a copy of what you see on your 
screen; my palantir is on the fritz :-)

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


write to the same file from multiple processes at the same time?

2005-05-27 Thread gabor
hi,

what i want to achieve:
i have a cgi file, that writes an entry to a text-file..
like a log entry (when was it invoked, when did his worke end).
it's one line of text.

the problem is:
what happens if 2 users invoke the cgi at the same time?

and it will happen, because i am trying now to stress test it, so i will 
start 5-10 requests in parallel and so on.

so, how does one synchronizes several processes in python?

first idea was that the cgi will create a new temp file every time,
and at the end of the stress-test, i'll collect the content of all those 
files. but that seems as a stupid way to do it :(

another idea was to use a simple database (sqlite?) which probably has 
this problem solved already...

any better ideas?

thanks,
gabor
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Xml writing in Python and verifying using XSD

2005-05-27 Thread Diez B. Roggisch
Prashanth  Ellina wrote:

> Hi,
> 
> I need to write some data to an xml file. I have an XML Schema defined.
> I would like to use some mechanism of writing the data to the xml file
> and having exceptions thrown back to me when the data is invalid.
> 
> I have looked at xml.dom and xml.dom.minidom but could not figure out
> what to do to include xml validation using the xsd while writing.
> 
> Any ideas?

Use StringIO to capture the output of your writings, and use a
xsd-validating parser (not sure which one, but google should help) to
reread that. Or a temporary file.

Apart from that I don't see much chances - which has nothing to do with
python but with xml itself: xml isn't suited for streams, because of the
opening/closing tags  - and noone can forsee if an opened tag in the stream
is closed in the future. Only after you finished the writing of that
document itself you can do that.

Similar arguments apply to DOMs. A DTD/XSD might require a certain element
to have a childelement. But when creating the element it has no childs - so
the document would be invalid. In the end you can only validate a finished
dom tree. So the only thing that could be tried is to feed that dom tree
instead of a xml string to a validation process - but if that's doable I'm
not  sure, and it doesn't buy you too much performance gain. So stick with
the write/validate process described above.

-- 
Regards,

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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Paul Rubin
gabor <[EMAIL PROTECTED]> writes:
> so, how does one synchronizes several processes in python?
> 
> first idea was that the cgi will create a new temp file every time,
> and at the end of the stress-test, i'll collect the content of all
> those files. but that seems as a stupid way to do it :(

There was a thread about this recently ("low-end persistence
strategies") and for Unix the simplest answer seems to be the
fcntl.flock function.  For Windows I don't know the answer.
Maybe os.open with O_EXCL works.

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


Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Szabolcs Nagy
i found case sensitivity very useful

1. variables can be stored in a dict (think about  __dict__, globals())
and dict type should be case sensitive

2. It's necessary when i write short scripts and i use one letter
names. (eg. when i playing with linear algebra i always use a,b,c for
vectors and A,B,C for matrices).  I dont want to think about "more than
one letter" names when i run that script only once. And usually this is
the case with python (at least when i use it in interpreted mode).

3.  i write sometimes:
class Foo:
...
foo = Foo()

and i think it's readable and makes sense.

4. actually i never wanted to use 'foo', 'Foo' and 'FOO' for the same
variable and i can't imagine a situation when it's useful. it makes the
code less readable so i think the language should force the programmer
not to use different names for the same variable.

nsz

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


Re: Strings for a newbie

2005-05-27 Thread Malcolm Wooden
my actual code is:

  for x in range(len(l)):
h = string.split(l[x])

where the sentence string is in an array of one element 'l'
Error is:

Traceback (most recent call last):
  File "", line 34, in ?
  File "", line 27, in SentenceText
  File "C:\PYTHON22\lib\string.py", line 122, in split
return s.split(sep, maxsplit)
AttributeError: 'list' object has no attribute 'split'


"John Machin" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Malcolm Wooden wrote:
>> Sorry John but that don't do it for me. Just get errors comming back
>>
>>
>> "John Machin" <[EMAIL PROTECTED]> wrote in message 
>> news:[EMAIL PROTECTED]
>>
>
>>>
>>s = "This is a sentence of words"
>>a = s.split()
>>a
>>>
>>>['This', 'is', 'a', 'sentence', 'of', 'words']
>>>
>
> Malcolm,
>
> What errors did you get? Please post a copy of what you see on your 
> screen; my palantir is on the fritz :-)
>
> Cheers,
> John 


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


Re: Strings for a newbie

2005-05-27 Thread John Machin
Malcolm Wooden wrote:
> my actual code is:
> 
>   for x in range(len(l)):
> h = string.split(l[x])
> 
> where the sentence string is in an array of one element 'l'
> Error is:
> 
> Traceback (most recent call last):
>   File "", line 34, in ?
>   File "", line 27, in SentenceText
>   File "C:\PYTHON22\lib\string.py", line 122, in split
> return s.split(sep, maxsplit)
> AttributeError: 'list' object has no attribute 'split'
> 
Can't tell from that -- do you have "import string" above that, or what?

Please post the whole file, which BTW you should not call "string".
In any case you should not be using the string module; it's old and 
deprecated. Use string methods instead. Why are you using Python 2.2??

I have to go now; it's way past bedtime at this longitude. Like I said, 
post the *whole* file; others will be able to straighten you out when 
they see the gory detail :-)

Cheers,
John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Roy Smith
gabor <[EMAIL PROTECTED]> wrote:
> so, how does one synchronizes several processes in python?

This is a very hard problem to solve in the general case, and the answer 
depends more on the operating system you're running on than on the 
programming language you're using.

On the other hand, you said that each process will be writing a single line 
of output at a time.  If you call flush() after each message is written, 
that should be enough to ensure that the each line gets written in a single 
write system call, which in turn should be good enough to ensure that 
individual lines of output are not scrambled in the log file.

If you want to do better than that, you need to delve into OS-specific 
things like the flock function in the fcntl module on unix.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Peter Hansen
Roy Smith wrote:
> gabor <[EMAIL PROTECTED]> wrote:
> On the other hand, you said that each process will be writing a single line 
> of output at a time.  If you call flush() after each message is written, 
> that should be enough to ensure that the each line gets written in a single 
> write system call, which in turn should be good enough to ensure that 
> individual lines of output are not scrambled in the log file.

Unfortunately this assumes that the open() call will always succeed, 
when in fact it is likely to fail sometimes when another file has 
already opened the file but not yet completed writing to it, AFAIK.

> If you want to do better than that, you need to delve into OS-specific 
> things like the flock function in the fcntl module on unix.

The OP was probably on the right track when he suggested that things 
like SQLite (conveniently wrapped with PySQLite) had already solved this 
problem.

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


Re: Strings for a newbie

2005-05-27 Thread Wolfram Kraus
Malcolm Wooden wrote:
> my actual code is:
> 
>   for x in range(len(l)):
> h = string.split(l[x])
> 
> where the sentence string is in an array of one element 'l'
> Error is:
> 
> Traceback (most recent call last):
>   File "", line 34, in ?
>   File "", line 27, in SentenceText
>   File "C:\PYTHON22\lib\string.py", line 122, in split
> return s.split(sep, maxsplit)
> AttributeError: 'list' object has no attribute 'split'
> 

What is l[x]? Are you sure that l[x] is a string? Do a print before the 
split to see what l[x] is. Oh, and no need for range here, if l is a list:

for x in l:
  print x
  h = x.split()

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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Paul Rubin
Peter Hansen <[EMAIL PROTECTED]> writes:
> The OP was probably on the right track when he suggested that things
> like SQLite (conveniently wrapped with PySQLite) had already solved
> this problem.

But they haven't.  They depend on messy things like server processes
constantly running, which goes against the idea of a cgi that only
runs when someone calls it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings for a newbie

2005-05-27 Thread Malcolm Wooden
Yes Sergei, as 3 of the lines are Dim statements, the real code is just 4 
lines, a totally logical. It's not the amout of code thats a probelm, it's 
following the logic and structure thats important. As I said Python.. UGH!

Malcolm


"Sergei Organov" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> "Malcolm Wooden" <[EMAIL PROTECTED]> writes:
>
>> I'm trying to get my head around Python but seem to be failing miserably. 
>> I
>> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!
>>
>> I want to put a sentence of words into an array, eg "This is a sentence 
>> of
>> words"
>>
>> In RB it would be simple:
>
> Simple?! 7 lines of code for such a trivial task is simple?!
>
>> Dim s as string
>> Dim a(-1) as string
>> Dim i as integer
>>
>> s = "This is a sentence of words"
>> For i = 1 to CountFields(s," ")
>>   a.append NthField(s," ",i)
>> next
>>
>> That's it an array a() containing the words of the sentence.
>>
>> Now can I see how this is done in Python? - nope!
>
> from string import split
> s = "This is a sentence of words"
> a = split(s)
>
> or,
>
> s = "This is a sentence of words"
> a = s.split()
>
> or even
>
> a = "This is a sentence of words".split()
>
> -- 
> Sergei. 


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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Roy Smith
Peter Hansen <[EMAIL PROTECTED]> wrote:
> The OP was probably on the right track when he suggested that things 
> like SQLite (conveniently wrapped with PySQLite) had already solved this 
> problem.

Perhaps, but a relational database seems like a pretty heavy-weight 
solution for a log file.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Jp Calderone
On 27 May 2005 06:21:21 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> 
wrote:
>Peter Hansen <[EMAIL PROTECTED]> writes:
>> The OP was probably on the right track when he suggested that things
>> like SQLite (conveniently wrapped with PySQLite) had already solved
>> this problem.
>
>But they haven't.  They depend on messy things like server processes
>constantly running, which goes against the idea of a cgi that only
>runs when someone calls it.

SQLite is an in-process dbm.

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


Copy paste in entry widget

2005-05-27 Thread Michael Onfrek
Hi,
is copy, paste, cut of selection possible in entry widget? Docs say
selection must be copied by default, in my programm it doesn't work.
Regards, M.O.

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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread fraca7
gabor a écrit :

> [snip]

Try this:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __init__() not called automatically

2005-05-27 Thread Simon Brunning
On 26 May 2005 11:54:33 -0400, Roy Smith <[EMAIL PROTECTED]> wrote:
> And the correlary wart in Python is that the first argument to a
> method is not required to be called "self".  The vast majority of
> people use "self", but every once in a great while you run into some
> yahoo who feels this is the right place to express his creativity and
> call it "this", or "obj", or some other obfuscation.

To be fair, it's easy to use 'this' by accident if you've recently
been working with Java. I've done it myself. It takes me an hour or to
reset my brain, and for a short while, there are bloody 'this'es,
braces and semi-colons everywhere.

Sanity soon returns, though.

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


RE: Strings for a newbie

2005-05-27 Thread Marc Boeren

Hi Malcolm,

> It's not the amout of code thats a probelm, it's following the
> logic and structure thats important.
> As I said Python.. UGH!

Do you find 

.. s = "This is a sentence of words"
.. a = s.split(' ')

less readable or logical than 

.. s = "This is a sentence of words"
.. For i = 1 to CountFields(s," ")
.. a.append NthField(s," ",i)
.. next



It seems you actual problem is more in this code you posted:

.. for x in range(len(l)):
.. h = string.split(l[x])

where l[x] does not evaluate to a string and thus it can't be split.
To find the value of l[x], just do 

.. for x in range(len(l)):
.. print l[x]
.. h = string.split(l[x])

and see what the print statement returns.
note that the code from Wolfram makes this a bit more readable:

.. for x in l:
..   print x
..   h = x.split()

Also note that you can play around with stuff like this in the
interactive interpreter, so you are not carrying around the whole of the
program you're writing. This makes experimenting with python a bit
easier as it's a quick way to check how things work. Whenever you see
code on this list that is prepended by >>> it means it is probably
copy/pasted from the interactive interpreter, so you know it actually
works (Johns example):

.. >>>s = "This is a sentence of words"
.. >>>a = s.split()
.. >>>a
.. 
.. ['This', 'is', 'a', 'sentence', 'of', 'words']

Have fun, Marc.

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


a html parse problem

2005-05-27 Thread cheng
hi,all

if the html like:
 
 

if i use:
def handle_starttag(self, tag, attrs):
if tag == 'meta':
   self.attr = attrs
self.headers += ['%s' % (self.attr)]
self.attr = ''

will get the output:
[('name', 'description'), ('content', 'a test page')]

[('name', 'keywords'), ('content', 'keyword1 keyword2')]

is it some way that only take the content like " a test page, keyword1
, keywork2"

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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Paul Rubin
Jp Calderone <[EMAIL PROTECTED]> writes:
> >But they haven't.  They depend on messy things like server processes
> >constantly running, which goes against the idea of a cgi that only
> >runs when someone calls it.
> 
> SQLite is an in-process dbm.

http://www.sqlite.org/faq.html#q7

(7) Can multiple applications or multiple instances of the same
application access a single database file at the same time?

Multiple processes can have the same database open at the same
time. Multiple processes can be doing a SELECT at the same
time. But only one process can be making changes to the database
at once.

But multiple processes changing the database simultaneously is
precisely what the OP wants to do.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strings for a newbie

2005-05-27 Thread Kalle Anka
Malcolm Wooden  dtptypes.com> writes:

> Yes Sergei, as 3 of the lines are Dim statements, the real code is just 4 
> lines, a totally logical. It's not the amout of code thats a probelm, it's 
> following the logic and structure thats important. As I said Python.. UGH!

Since I both use RB and Python I can say the the "logic and structure" 
(if you by that means the semantics)  is more or less the exactly the 
same in RB and Python. The only major difference is that in RB you 
have to declare the type.

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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Gerhard Haering
On Fri, May 27, 2005 at 09:27:38AM -0400, Roy Smith wrote:
> Peter Hansen <[EMAIL PROTECTED]> wrote:
> > The OP was probably on the right track when he suggested that things 
> > like SQLite (conveniently wrapped with PySQLite) had already solved this 
> > problem.
> 
> Perhaps, but a relational database seems like a pretty heavy-weight 
> solution for a log file.

On the other hand, it works ;-)

-- Gerhard
-- 
Gerhard Häring - [EMAIL PROTECTED] - Python, web & database development


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Brian van den Broek
Duncan Booth said unto the world upon 2005-05-27 04:24:



> There are arguments that, especially for beginners, case sensitivity 
> introduces an extra level of complexity, but the cost of losing this 
> complexity would be to make Python a poor relation amongst programming 
> languages.


Well, this is just one man's anecdote, but Python was my first 
language since some BASIC many moons ago, and the case sensitivity 
neither got in my way, nor felt complex. Perhaps Python beginners with 
background in case insensitive languages do experience it differently.

At any rate, since the sequence of characters 'somename' and 
'SomeName' are different sequences, treating them as different names 
strikes me as the obviously right thing to do.

Best to all,

Brian vdB

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


Re: Strings for a newbie

2005-05-27 Thread Kalle Anka
Malcolm Wooden  dtptypes.com> writes:

> I want to put a sentence of words into an array, eg "This is a sentence of 
> words"
> 
> In RB it would be simple:
> 
> Dim s as string
> Dim a(-1) as string
> Dim i as integer
> 
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
>   a.append NthField(s," ",i)
> next
> 
> That's it an array a() containing the words of the sentence.
> 
> Now can I see how this is done in Python? - nope!

Compare this RB code

  dim s as String
  dim a(-1) as String
  
  s = "This is a sentence of words"
  a = s.split()

with the python code

>>> s = "This is a sentece of words"
>>> s.split()
['This', 'is', 'a', 'sentece', 'of', 'words']
>>> 


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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread jean-marc
Sorry, why is the temp file solution 'stupid'?, (not
aesthetic-pythonistic???) -  it looks OK: simple and direct, and
certainly less 'heavy' than any db stuff (even embedded)

And  collating in a 'official log file' can be done periodically by
another process, on a time-scale that is 'useful' if not
instantaneous...

Just trying to understand here...

JMD

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


Re: Incrementing letters

2005-05-27 Thread Wolfram Kraus
Duncan Booth wrote:
> Michael wrote:
> 
> 
>>Hi,
>>I've got a string s, and i want to shift all the letters up by one, eg
>>a->b, b->c  z->a
>>In c++ i can do this quite simply with
>>
>>if(C == 'z') C='a';
>>else C++;
>>
>>but i can't work out how to do this this in python??
> 
> 
import string
upone = string.maketrans(
> 
> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
> 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')
> 
string.translate("I've got a string s", upone)
> 
> "J'wf hpu b tusjoh t"
> 
> 
> Note the difference though: the Python code does what you said you wanted, 
> whereas your sample code corrupts punctuation.

Wow, that's quite nice. You really learn something new every day :-)
A minor improvement: Use string.ascii_letters as the first parameter for 
string.maketrans

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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Jp Calderone
On 27 May 2005 06:43:04 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid> 
wrote:
>Jp Calderone <[EMAIL PROTECTED]> writes:
>> >But they haven't.  They depend on messy things like server processes
>> >constantly running, which goes against the idea of a cgi that only
>> >runs when someone calls it.
>>
>> SQLite is an in-process dbm.
>
>http://www.sqlite.org/faq.html#q7
>
>(7) Can multiple applications or multiple instances of the same
>application access a single database file at the same time?
>
>Multiple processes can have the same database open at the same
>time. Multiple processes can be doing a SELECT at the same
>time. But only one process can be making changes to the database
>at once.
>
>But multiple processes changing the database simultaneously is
>precisely what the OP wants to do.

Er, no.  The OP precisely wants exactly one process to be able to write at a 
time.  If he was happy with multiple processes writing simultaneously, he 
wouldn't need any locking mechanism at all >:)

If you keep reading that FAQ entry, you discover that SQLite implements its own 
locking mechanism internally, allowing different processes to *interleave* 
writes to the database, and preventing any data corruption which might arise 
from simultaneous writes.

That said, I think an RDBM is a ridiculously complex solution to this simple 
problem.  A filesystem lock, preferably using the directory or symlink trick 
(but flock() is fun too, if you're into that sort of thing), is clearly the 
solution to go with here.

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


Re: a html parse problem

2005-05-27 Thread bruno modulix
cheng wrote:
> hi,all
> 
> if the html like:
>  
>  
> 
> if i use:
> def handle_starttag(self, tag, attrs):
> if tag == 'meta':
>self.attr = attrs
> self.headers += ['%s' % (self.attr)]
> self.attr = ''



> will get the output:
> [('name', 'description'), ('content', 'a test page')]
> 
> [('name', 'keywords'), ('content', 'keyword1 keyword2')]

> is it some way that only take the content like " a test page, keyword1
> , keywork2"

And put it where ?-)

Well, it may looks like this:

  def handle_starttag(self, tag, attrs):
if tag == 'meta':
try:
self.content.append(attrs['content'])
except KeyError:
pass
self.headers += ['%s' % attr]

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


Re: Strings for a newbie

2005-05-27 Thread bruno modulix
Malcolm Wooden wrote:
> I'm trying to get my head around Python but seem to be failing miserably. I 
> use RealBasic on a Mac and find it an absolute dream! But PythonUGH!

Strange enough, Rb was one of my first languages, and last time I played
with it, I founhd it was close to a nightmare when compared to Python...

> 
> I want to put a sentence of words into an array, eg "This is a sentence of 
> words"
> 
> In RB it would be simple:
> 
> Dim s as string
> Dim a(-1) as string
> Dim i as integer
> 
> s = "This is a sentence of words"
> For i = 1 to CountFields(s," ")
>   a.append NthField(s," ",i)
> next
> 
> That's it an array a() containing the words of the sentence.


Ho, yes, so simple... only seven lines...


> Now can I see how this is done in Python? - nope!

Why not ?

a = "This is a sentence of words".split()

Now *this* is simplicity, my friend...

> UGH!
>
> Malcolm
> (a disillusioned Python newbie) 
> 
So I'll leave you to your disi^M^M^Mdelusion...

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


Re: Strings for a newbie

2005-05-27 Thread bruno modulix
Malcolm Wooden wrote:
(top post corrected)
> 
> "John Machin" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
> 
>>Malcolm Wooden wrote:
>>
(snip useless rant)
>>>
>>>I want to put a sentence of words into an array, eg "This is a sentence 
>>>of words"
>>>
>>>In RB it would be simple:
>>>
(snip 'simple' example)
>>>
(snip other useless rant)
>>
>s = "This is a sentence of words"
>a = s.split()
>a
>>
>>['This', 'is', 'a', 'sentence', 'of', 'words']
>>
> Sorry John but that don't do it for me. Just get errors comming back

http://www.catb.org/~esr/faqs/smart-questions.html

Strange enough, I used variations of the above code - which is a pretty
common Python idiom - in tens and tens of working applications...

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


Re: Is Python suitable for a huge, enterprise size app?

2005-05-27 Thread Dieter Maurer
"Fredrik Lundh" <[EMAIL PROTECTED]> writes on Tue, 24 May 2005 22:38:05 +0200:
> ...
> nothing guarantees that, of course.  but I've never seen that
> happen. and I'm basing my comments on observed behaviour in
> real systems, not on theoretical worst-case scenarios.

I observed in real systems (Zope) that the system got slower
and slower as the amount of allocated memory increased -- although
the OS was far from its memory resource limits (and virtual memory size
was not much larger then resident memory size). Flushing caches
(and thereby releasing most memory) did not speed up things
but restarting did.

I do not understand this observed behaviour.

> every
> time I've seen serious fragmentation, it's been related to leaks,
> not peak memory usage.

An analysis did not reveal serious leaks, in the cases mentioned above.


Dieter

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


Re: python24.zip

2005-05-27 Thread Dieter Maurer
"Martin v. Löwis" <[EMAIL PROTECTED]> writes on Tue, 24 May 2005 23:58:03 +0200:
> ... 10.000 failing opens -- a cause for significant IO during startup ? ...

> So I would agree that IO makes a significant part of startup, but
> I doubt it is directory reading (unless perhaps you have an
> absent NFS server or some such).

We noticed the large difference between warm and cold start even when
we run from a zip archive. We expected that the only relevant IO would
go to the zip archives and therefore, we preloaded them to the
OS cache (by reading them sequentially) before the Python start.
To our great surprise, this did not significantly reduced Python's
(cold) startup time. We concluded that there must be other IO
not directed to the zip archives, started investigating and found
the 10.000 opens to non-existing files as the only other
significant IO contingent


Dieter

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


Re: python24.zip

2005-05-27 Thread Dieter Maurer
Scott David Daniels <[EMAIL PROTECTED]> writes on Wed, 25 May 2005 07:10:00 
-0700:
> ...
> I'll bet this means that the 'zope.zip', 'python24.zip' would drop
> you to "about 12500 - 1 = 2500" failing opens.  That should be
> an easy test: sys.path.insert(0, 'zope.zip') or whatever.
> If that works and you want to drop even more, make a copy of zope.zip,
> update it with python24.zip, and call the result python24.zip.

We can not significantly reduce the amount of opens further:

  Each module import from a zip archive opens the archive.
  As we have about 2.500 modules, we will get this order of opens
  (as long as we use Python's "zipimporter").

The "zipimporter" uses a sequence of "stat"s to determine
whether it can handle a path item: it drops the last
component until it gets an existing file object and then
checks that it is indeed a zip archive.
Adding a cache for this check could save an additional few
hundreds of opens.


Dieter

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


Re: Case Sensitive, Multiline Comments

2005-05-27 Thread John Roth
"Duncan Booth" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Dennis Lee Bieber wrote:
>
>> On 26 May 2005 17:33:33 -0700, "Elliot Temple" <[EMAIL PROTECTED]>
>> declaimed the following in comp.lang.python:
>>
>>> Thanks for the link on case sensitivity.  I'm curious about the person
>>> who found case sensitivity useful though: what is it useful for?
>>>
>>  Making a language run faster on slow machines since the syntax
>> parsing doesn't have to do the equivalent of upper or lower casing
>> anything that is not a string literal before checking for keywords or
>> identifiers.
>>
>>  Consider the time spent by languages like Ada and Fortran when
>> they have to do case normalization every time you compile.
>>
> That isn't a good argument for case sensitivity. You really aren't going 
> to
> be able to measure a slowdown in compilation speed just because the
> compiler has to lowercase all the identifiers before using them.

Actually it is, but you have to get out of ASCII into the wider world
of all of the real languages out there. Something I heard from one of the
people who invented XML is that it originally started out as case
insensitive, and they had quite an extensive discussion about it. When they
made it case sensitive, one of the basic tools sped up by a factor of three.
Doing case translations in Unicode following all of the rules for all of the
world's languages is, for want of a better world, a real bitch.

John Roth 

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


Re: Incrementing letters

2005-05-27 Thread Simon Brunning
On 5/27/05, Michael <[EMAIL PROTECTED]> wrote:
> Hi,
> I've got a string s, and i want to shift all the letters up by one, eg a->b,
> b->c  z->a
> In c++ i can do this quite simply with
> 
> if(C == 'z') C='a';
> else C++;
> 
> but i can't work out how to do this this in python??

Here's one that works on multiple character strings, with carrying.
Rather silly, really.



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


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread Grant Edwards
On 2005-05-27, Peter Hansen <[EMAIL PROTECTED]> wrote:
> Roy Smith wrote:
>> gabor <[EMAIL PROTECTED]> wrote:
>> On the other hand, you said that each process will be writing a single line 
>> of output at a time.  If you call flush() after each message is written, 
>> that should be enough to ensure that the each line gets written in a single 
>> write system call, which in turn should be good enough to ensure that 
>> individual lines of output are not scrambled in the log file.
>
> Unfortunately this assumes that the open() call will always succeed, 
> when in fact it is likely to fail sometimes when another file has 
> already opened the file but not yet completed writing to it, AFAIK.

Not in my experience.  At least under Unix, it's perfectly OK
to open a file while somebody else is writing to it.  Perhaps
Windows can't deal with that situation?

-- 
Grant Edwards   grante Yow!  FOOLED you! Absorb
  at   EGO SHATTERING impulse
   visi.comrays, polyester poltroon!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Incrementing letters

2005-05-27 Thread Dan Sommers
On Fri, 27 May 2005 16:10:32 +0200,
Wolfram Kraus <[EMAIL PROTECTED]> wrote:

> Duncan Booth wrote:

> import string
> upone = string.maketrans(
>> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
>> 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')
>> 
> string.translate("I've got a string s", upone)

>> "J'wf hpu b tusjoh t"

>> Note the difference though: the Python code does what you said you
>> wanted, whereas your sample code corrupts punctuation.

> Wow, that's quite nice. You really learn something new every day :-) A
> minor improvement: Use string.ascii_letters as the first parameter for
> string.maketrans

And use string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ] for the
second parameter to string.maketrans.

Regards,
Dan

-- 
Dan Sommers

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


cpu usage limit

2005-05-27 Thread mmf
Hi.

My problem:
How can I make sure that a Python process does not use more that 30% of
the CPU at any time. I only want that the process never uses more, but
I don't want the process being killed when it reaches the limit (like
it can be done with resource module).

Can you help me?

Thanks in advance.

Best regards,
Markus

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


Re: cpu usage limit

2005-05-27 Thread rbt

mf wrote:
> Hi.
> 
> My problem:
> How can I make sure that a Python process does not use more that 30% of
> the CPU at any time. I only want that the process never uses more, but
> I don't want the process being killed when it reaches the limit (like
> it can be done with resource module).
> 
> Can you help me?
> 
> Thanks in advance.
> 
> Best regards,
> Markus
> 

Are you looping during a cpu intensive task? If so, make it sleep a bit 
like this:

for x in cpu_task:
 time.sleep(0.5)
 do(x)
-- 
http://mail.python.org/mailman/listinfo/python-list


passing C++ parameters to a function

2005-05-27 Thread Stormbringer
Greetings,

I was trying to use pyopengl - which is imported into python using SWIG
- when I stumbled upon the following function with the C++ definition:

void glShaderSourceARB(GLhangleARB shader, GLuint number_strings, const
GLcharARB** strings, Glint * length);

this is imported inside pyopengl, looks something like this :

# This file was created automatically by SWIG.
# Don't modify this file, modify the SWIG interface instead.
# This file is compatible with both classic and new-style classes.

import _shader_objects

[...]

glShaderSourceARB = _shader_objects.glShaderSourceARB


Now I am at a loss here, I need to call this function but can't figure
out a quick way to convert my argumets to this list of string pointers
and pointer to int. Could anyone more experienced in SWIG-usage and/or
pyopengl internals give me some hints ?

Thanks,
Andrei

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


Re: Incrementing letters

2005-05-27 Thread Duncan Booth
Dan Sommers wrote:

> Wolfram Kraus <[EMAIL PROTECTED]> wrote:
> 
>> Duncan Booth wrote:
> 
>> import string
>> upone = string.maketrans(
>>> 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
>>> 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')
>>> 
>> string.translate("I've got a string s", upone)
> 
>>> "J'wf hpu b tusjoh t"
> 
>>> Note the difference though: the Python code does what you said you
>>> wanted, whereas your sample code corrupts punctuation.
> 
>> Wow, that's quite nice. You really learn something new every day :-) A
>> minor improvement: Use string.ascii_letters as the first parameter for
>> string.maketrans

Yes, my first attempt at responding did that, but I changed it because that 
makes the assumption that string.ascii_letters is in a specific order (did 
you know that lowercase came first and uppercase second without checking?)

> 
> And use string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ] for the
> second parameter to string.maketrans.
> 
Bzzt. Wrong answer. Look closely at the middle of the string.

I did have:

>>> upone = string.maketrans(string.ascii_letters,
'z'+string.ascii_lowercase[:-1] +
'Z' + string.ascii_uppercase[:-1])

but as I said, that makes too many assumptions for my liking about the 
contents of those variables.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CygWin ODBC

2005-05-27 Thread Steve Holden
Simon Faulkner wrote:
> Hi All,
> 
> I am new to Cygwin and am hoping that someone here will be able to tell 
> me how to get ODBC running in Python on Cygwin.
> 
> Maximum gratefullness...
> 
> 
> Simon

There's a trick to this which involves recompiling from source. If you 
aren't experienced with Unix/Linux this might seem a bit intimidating.

The latest version I worked on is mxODBC 2.0.7. If Egenix have released 
something later it may incorporate these changes. Sorry they aren't 
"diff -c" format.

I also remember the need in the past to rename some ".cpp" files to 
".c", but I believe this has now been done in the distributions.

regards
  Steve

diff -rc egenix-mx-commercial-2.0.7/mxCOMMERCIAL.py 
egenix-mx-commercial-2.0.7cygwin/mxCOMMERCIAL.py
*** egenix-mx-commercial-2.0.7/mxCOMMERCIAL.py  Wed Dec  1 13:10:27 2004
--- egenix-mx-commercial-2.0.7cygwin/mxCOMMERCIAL.pySat Dec 18 
09:56:27 2004
***
*** 55,61 
   packages = ['mx.ODBC',
   'mx.ODBC.Misc']

! if sys.platform[:3] == 'win':
   packages[len(packages):] = [

   'mx.ODBC.Windows'
--- 55,61 
   packages = ['mx.ODBC',
   'mx.ODBC.Misc']

! if sys.platform[:3] == 'win' or sys.platform == 'cygwin':
   packages[len(packages):] = [

   'mx.ODBC.Windows'
***
*** 89,95 
   #
   ext_modules = []

! if sys.platform[:3] == 'win':
   ext_modules[len(ext_modules):] = [

   Extension('mx.ODBC.Windows.mxODBC',
--- 89,95 
   #
   ext_modules = []

! if sys.platform[:3] == 'win' or sys.platform == 'cygwin':
   ext_modules[len(ext_modules):] = [

   Extension('mx.ODBC.Windows.mxODBC',
***
*** 167,173 

   ]

! if sys.platform[:3] == 'win':
   data_files[len(data_files):] = [

   'mx/ODBC/Windows/COPYRIGHT',
--- 167,173 

   ]

! if sys.platform[:3] == 'win' or sys.platform == 'cygwin':
   data_files[len(data_files):] = [

   'mx/ODBC/Windows/COPYRIGHT',

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

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


Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Duncan Booth
John Roth wrote:

> Doing case translations in Unicode following all of
> the rules for all of the world's languages is, for want of a better
> world, a real bitch. 
> 

Fair point, although that is true for anything, not just case translations.
Fortunately, unlike Ecmascript, Python doesn't allow arbitrary unicode 
characters in identifiers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intellisense and the psychology of typing

2005-05-27 Thread Brian Beck
Well, there are two distinct features of IntelliSense as you know it.
One is auto-completion and the other is contextual help.

Auto-completion is included almost all beefy Python IDE's.

Contextual help is included even in IDLE, where if you begin typing a
function call, its docstring pops up around where you are typing.
Since many functions have dynamic arguments, I think this really is the
best solution, since the implementor of the function knows what would
be the most helpful to show.  Open the interactive IDLE prompt and type
max(, iter(, help(, for example -- although most of those are pretty
minimal.

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


Re: cpu usage limit

2005-05-27 Thread garabik-news-2005-05
rbt <[EMAIL PROTECTED]> wrote:
> 
> mf wrote:
>> Hi.
>> 
>> My problem:
>> How can I make sure that a Python process does not use more that 30% of
>> the CPU at any time. I only want that the process never uses more, but
>> I don't want the process being killed when it reaches the limit (like
>> it can be done with resource module).
>> 
>> Can you help me?
>> 
>> Thanks in advance.
>> 
>> Best regards,
>> Markus
>> 
> 
> Are you looping during a cpu intensive task? If so, make it sleep a bit 
> like this:
> 
> for x in cpu_task:
> time.sleep(0.5)
> do(x)

or like this (untested!)

finished = False
while not finished:
  before = time.time()
  do(x) # sets finished if all was computed
  after = time.time()
  delta = after-before
  time.sleep(delta*10/3.)

now the trick: do(x) can be a single piece of code, with strategically placed 
yield's
all over



-- 
 ---
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__garabik @ kassiopeia.juls.savba.sk |
 ---
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Incrementing letters

2005-05-27 Thread Rocco Moretti
Dan Sommers wrote:
> On Fri, 27 May 2005 16:10:32 +0200,
> Wolfram Kraus <[EMAIL PROTECTED]> wrote:
> 
> 
>>Duncan Booth wrote:
> 
> 
>>import string
>>upone = string.maketrans(
>>>
>>>'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
>>>'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA')
>>>
>>>
>>string.translate("I've got a string s", upone)
>  
> 
>>Wow, that's quite nice. You really learn something new every day :-) A
>>minor improvement: Use string.ascii_letters as the first parameter for
>>string.maketrans
> 
> 
> And use string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ] for the
> second parameter to string.maketrans.
> 

Not quite:

 >>> string.ascii_letters[ 1 : ] + string.ascii_letters[ 0 ]
'bcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZa'

i.e. you get 'z' -> 'A' and 'Z' -> 'a'

Another issue is locale settings and special characters - what should be 
done with accented letters? Preserve letter, or shift and loose accent?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cpu usage limit

2005-05-27 Thread Markus Franz
> Are you looping during a cpu intensive task? If so, make it sleep a bit 
> like this:
> 
> for x in cpu_task:
> time.sleep(0.5)
> do(x)

No, I don't use an intensive loop. I have about 1200 lines of code 
inside a process - is there nothing like

xyz.setlimit(xyz.cpu, 0.30)

???

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


Re: cpu usage limit

2005-05-27 Thread rbt
[EMAIL PROTECTED] wrote:
> rbt <[EMAIL PROTECTED]> wrote:
> 
>>mf wrote:
>>
>>>Hi.
>>>
>>>My problem:
>>>How can I make sure that a Python process does not use more that 30% of
>>>the CPU at any time. I only want that the process never uses more, but
>>>I don't want the process being killed when it reaches the limit (like
>>>it can be done with resource module).
>>>
>>>Can you help me?
>>>
>>>Thanks in advance.
>>>
>>>Best regards,
>>>Markus
>>>
>>
>>Are you looping during a cpu intensive task? If so, make it sleep a bit 
>>like this:
>>
>>for x in cpu_task:
>>time.sleep(0.5)
>>do(x)
> 
> 
> or like this (untested!)
> 
> finished = False
> while not finished:

Why don't you just write 'while True'??? 'while not false' is like 
saying 'I am not unemployed by Microsoft' instead of saying 'I am 
employed by Microsoft'. It's confusing, complex and unnecessary. Lawyers 
call it circumlocution (talking around the truth).

>   before = time.time()
>   do(x) # sets finished if all was computed
>   after = time.time()
>   delta = after-before
>   time.sleep(delta*10/3.)
> 
> now the trick: do(x) can be a single piece of code, with strategically placed 
> yield's
> all over
> 
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: cpu usage limit

2005-05-27 Thread Grant Edwards
On 2005-05-27, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

>>> How can I make sure that a Python process does not use more that 30% of
>>> the CPU at any time. I only want that the process never uses more, but
>>> I don't want the process being killed when it reaches the limit (like
>>> it can be done with resource module).

>> Are you looping during a cpu intensive task? If so, make it sleep a bit 
>> like this:
>> 
>> for x in cpu_task:
>> time.sleep(0.5)
>> do(x)
>
> or like this (untested!)
>
> finished = False
> while not finished:
>   before = time.time()
>   do(x) # sets finished if all was computed
>   after = time.time()
>   delta = after-before
>   time.sleep(delta*10/3.)
>
> now the trick: do(x) can be a single piece of code, with
> strategically placed yield's all over

Since you have no way of knowing that your process was the only
one running between the two calls to time.time(), you're
placing an upper bound on how much CPU time you're using, but
the actual usage is unknown and may be much lower on a heavily
loaded machine.

Running for 100ms and sleeping for 333ms results in an upper
limit of 25% rather than 30%.  Sleeping for (delta * 7.0/3.0)
gives a 30% upper bound.

All that aside, it seems to me that this situation is analogous
to when people waste all sorts of effort trying to write clever
applications that cache parts of files or other data structures
in main memory with backing store on disk. They end up with a
big, complicated, buggy app that's slower and requires more
resources than a far simpler app that lets the OS worry about
memory management.

IOW, you're probably better off not trying to write application
code that tries to out-think your OS.  Use whatever prioritizing
scheme your OS kernel provides for setting up a low priority
"background" task, and let _it_ worry about divvying up the CPU.
That's what it's there for, and it's got a far better picture
of resource availability and demand.

-- 
Grant Edwards   grante Yow!  Yow! It's a hole
  at   all the way to downtown
   visi.comBurbank!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: CygWin ODBC

2005-05-27 Thread Simon Faulkner
Steve Holden wrote:
> Simon Faulkner wrote:
> 
>> Hi All,
>>
>> I am new to Cygwin and am hoping that someone here will be able to 
>> tell me how to get ODBC running in Python on Cygwin.
>>
>> Maximum gratefullness...
>>
>>
>> Simon
> 
> 
> There's a trick to this which involves recompiling from source. If you 
> aren't experienced with Unix/Linux this might seem a bit intimidating.
> 
> The latest version I worked on is mxODBC 2.0.7. If Egenix have released 
> something later it may incorporate these changes. Sorry they aren't 
> "diff -c" format.
> 
> I also remember the need in the past to rename some ".cpp" files to 
> ".c", but I believe this has now been done in the distributions.
> 
> regards
>  Steve

Cheers Steve, I will try that next week  Ta :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python24.zip

2005-05-27 Thread Steve Holden
Dieter Maurer wrote:
> Steve Holden <[EMAIL PROTECTED]> writes on Sun, 22 May 2005 16:19:10 -0400:
> 
>>...
>>Indeed I have written PEP 302-based code to import from a relational
>>database, but I still don't believe there's any satisfactory way to
>>have [such a hooked import mechanism] be a first-class component of an
>>architecture that specifically requires an os.py to exist in the file
>>store during initialization.
>>
>>
>>I wasn't asking for an import hook mechanism (since I already knew
>>these to exist), but for a way to allow such mechanisms to be the sole
>>import support for certain implementations.
> 
> 
> We do not have "os.py" (directly) on the file system.
> It lives (like everything else) in a zip archive.
> 
> This works because the "zipimporter" is put on
> "sys.path_hook" before the interpreter starts executing Python code.
> 
> Thus, all you have to do: use a different Python startup
> and ensure that you special importer (able to import e.g. "os")
> is already set up, before you start executing Python code.
> 
It might help others like me if you were to document this setup, as I 
was unable to persuade the interpreter to start without producing the 
dire-sounding warning messages I mentioned in the bug report.

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

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


Re: Case Sensitive, Multiline Comments

2005-05-27 Thread Elliot Temple
One other interesting thing about case sensitivity I don't think  
anyone has mentioned: in Python keywords are all lowercase already  
(the way I want to type them).  In some other languages, they aren't...

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


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

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


Re: python24.zip

2005-05-27 Thread Steve Holden
Martin v. Löwis wrote:
> Scott David Daniels wrote:
> 
Is the interpreter unable to call "C" functions ("stat" for example)
to determine whether an object exists before it puts it on "path".
>>>
>>>
>>>What do you mean, "unable to"? It just doesn't.
>>
>>In fact, the interpreter doesn't necessarily know when it is
>>affecting the path.
> 
> 
> Now I remember what makes this stuff really difficult: PEP 302
> introduces path hooks (sys.path_hooks), allowing imports from
> other sources than files. So the items on sys.path don't have
> to be directory or file names at all, and importing from them
> may still succeed if though stat fails.
> 
This new feature also makes the strategy of looking in the filestore for 
"os.py" somewhat dubious, hence my bug report.

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

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


Inheritance, polymorphism, and introspection in Python

2005-05-27 Thread combinational.logic $ soc-ip.com
The following website (http://www.soc-ip.com/weblog) has an example of
inheritance, polymorphism, and introspection in Python.  The example
shows a simple classification system for microprocessors.  Hopefully
someone will find this interesting / useful.

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


lambda a plusieurs arguments

2005-05-27 Thread nico
Bonjour,

Comment faire une fonction lambda a plusieurs arguments ?

>>> (lambda a:a+1)(2)
3
>>> f=(lambda (a,b):a+b)
>>> f(5,6)
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: () takes exactly 1 argument (2 given)
>>> f((5.6))
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 1, in 
TypeError: unpack non-sequence

pourquoi ca ne marche pas ? je ne comprends pas le message d'erreur !

Merci.


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


Re: Strings for a newbie

2005-05-27 Thread Steve Holden
Malcolm Wooden wrote:
> Yes Sergei, as 3 of the lines are Dim statements, the real code is just 4 
> lines, a totally logical. It's not the amout of code thats a probelm, it's 
> following the logic and structure thats important. As I said Python.. UGH!
> 
> Malcolm
> 
Yes, the weirdest thing about the whole language is the way it jumps off 
the Internet and forces you to use it ... :-) (Which is my way of saying 
  that if you are happy with RealBasic then there's no need to pick 
Python up in the first place).

I can quite see why you would prefer

s = "This is a sentence of words"
For i = 1 to CountFields(s," ")
   a.append NthField(s," ",i)
next

to

s = "This is a sentence of words"
a = s.split()

How dare Python be shorter than RealBasic and easier to understand? 
(although you should check the validity of the Python code against a 
RealBasic interpreter. You might be surprised.) You also said

> my actual code is:
> 
>   for x in range(len(l)):
> h = string.split(l[x])
> 
> where the sentence string is in an array of one element 'l'
> Error is:
> 
> Traceback (most recent call last):
>   File "", line 34, in ?
>   File "", line 27, in SentenceText
>   File "C:\PYTHON22\lib\string.py", line 122, in split
> return s.split(sep, maxsplit)
> AttributeError: 'list' object has no attribute 'split'
> 
> 

and then wondered why you got error messages trying to apply "split()" 
to some list. This is equivalent to saying "somebody told me to hammer 
this nail in, but my screwdriver won't hammer things".

Those who don't *want* to understand will find ways not to. Those who 
*do* want to understand will engage on a dialog until their problems are 
solved.

The fact that you don't even use the split() method that RealBasic makes 
available means you are overlooking the fact that the two languages are 
actually identical (modulo a few declarations) for your problem!

python-ugh-indeed-ly y'rs  - steve
-- 
Steve Holden+1 703 861 4237  +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/

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


Does Python have a Template::Extract equivalent from Perl's CPAN

2005-05-27 Thread [EMAIL PROTECTED]
Hi All,

I already searched this newsgroup and google groups to see if I could
find a Python equivalent to Perl's Template::Extract, but didn't find
anything leading to a Python module that had similar functionality.  I
am a big fan of Python as an OO language and use it for many system
admin utilities, webdev and even MS Excel AddIn development, but I have
found that Perl's Template::Extract is so invaluable to my web scraping
utilities that I can not migrate this very old code base over to Python
yet since there is nothing that I can easily port it over to without
making my web scrapers very brittle to website redesigns.  I while I
think Perl is a wonderful language in its own right I would rather just
code more of my codebase in Python than Perl to make my coding more
efficient.

If anyone knows of a Python module that has the same features of
Template::Extract please let me (and maybe the group) know.  If nobody
is not aware of any module, I would be interested in developing one for
the Python public.  Please let me know if anyone else is interested and
I can setup a sf.net project to get this rolling (unless anyone knows
of an sf.net like website that offers Subversion instead of CVS?).

Thanks!

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


Re: Does Python have a Template::Extract equivalent from Perl's CPAN

2005-05-27 Thread [EMAIL PROTECTED]
should have read, "if nobody is aware of any module..." not "if nobody
is not aware...".

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


Re: Does Python have a Template::Extract equivalent from Perl's CPAN

2005-05-27 Thread combinational.logic $ soc-ip.com
Can you please elaborate on how to use Python for MS Excel AddIn
development?  Is this easy to do?  I would love to be able to create
custom extensions to Excel using python!  IMHO Python is much better
than Perl due to its OOP features.

Cheers,
  CL

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


Re: lambda a plusieurs arguments

2005-05-27 Thread Jp Calderone
On Fri, 27 May 2005 19:38:33 +0200, nico <[EMAIL PROTECTED]> wrote:
>Bonjour,
>
>Comment faire une fonction lambda a plusieurs arguments ?
>
 (lambda a:a+1)(2)
>3
 f=(lambda (a,b):a+b)
 f(5,6)
>Traceback (most recent call last):
>  File "", line 1, in ?
>TypeError: () takes exactly 1 argument (2 given)
 f((5.6))
 ^--- ,

>>> f((5, 6))
11
>>>

Aussi,

>>> f = lambda a, b: a + b
>>> f(5, 6)
11
>>>

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


distutils, 'scripts' and Windows

2005-05-27 Thread George van den Driessche
Hi folks,

I'm looking at packaging a project I'm working on using distutils. The 
project is for Windows and contains a COM server which needs 
registration, so the installer needs to be a little more complicated 
than usual. Looking at the options for the bdist_wininst command to 
distutils, I see it's possible to specify
  --install-script=
which ought to do the trick. But to use this, myinstallscript itself 
must first be installed by passing
  scripts='myinstallscript'
to distutils.core.setup in setup.py. That will copy myinstallscript 
into a particular location (C:\Python24\Scripts in my case) and leave 
it there forever. Which raises a couple of questions:

- Why is myinstallscript left there forever? The documentation makes 
some vague reference to needing it for uninstalling packages, but then 
I can't actually find a way to uninstall packages.

- What is the use of the Scripts directory on Windows? It's not added 
to my PATH, so unless I do that myself it won't do anything like it's 
meant to on other platforms.

- Should I supply myinstallscript, or myinstallscript.py? I suspect the 
latter, since that's the only way to give files types on Windows.

- Is there some other better way to perform post-installation actions? 
Would it work out of a binary generated from bdist_wininst?

- Should I even be using distutils? It doesn't really matter that much 
where the files are installed because the COM server can register 
itself to run out of whatever location it happens to be in.

Thanks,
George

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


Python/Excel AddIn (was:Re: Does Python have a Template::Extract equivalent from Perl's CPAN)

2005-05-27 Thread Paul McNett
Please start a new thread when appropriate.

combinational.logic $ soc-ip.com wrote:
> Can you please elaborate on how to use Python for MS Excel AddIn
> development? Is this easy to do?  I would love to be able to create
> custom extensions to Excel using python!  IMHO Python is much better
> than Perl due to its OOP features.

Do you mean automating Excel sheets using Python? If so, you need to get 
a COM interface from Python (see Mark Hammond's win32all Python 
extensions for this), and you need to figure out the proper com calls, 
which is easiest by going into Excel and recording a macro, and then 
taking a look at the vbscript the macro recorded.

-- 
Paul McNett
http://paulmcnett.com

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


Re: What are OOP's Jargons and Complexities?

2005-05-27 Thread James Stroud
On Friday 27 May 2005 02:15 am, Piet van Oostrum wrote:
> > "Xah Lee" <[EMAIL PROTECTED]> (XL) wrote:
> >
> >XL> Joe: lang x is strongly typed
> >XL> Dave: you mean statically typed?
> >XL> John: no no, that's weakly typed.
>
> That should have been `weekly typed', according to the link below.
> Maybe there is also `daily typed' or `monthly typed'?
>
> >XL> http://xahlee.org/UnixResource_dir/writ/jargons.html

"""
If mathematicians are designing computer languages, they would probably just 
called such thing _pure functions_. The term conveys the meaning, without the 
“lamba” abstruseness.
"""

Proposing "jargon" to cure "jargon". Good job! Of course nothing will ever 
rival "jargonize", the crown jewl of all "jargon".

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list

Determine if windows drive letter is hard drive or optical from python?

2005-05-27 Thread mh
Hi Folks-

I'm trying to do a simple emulation of unix "locate" functionality in
python for windows.

Problem is I don't want to crawl/index optical drives.  Do any of the
windows people out there know how I can determine:

1. How many drives are on the system?  (I could just iterate over the
alphabet os.path.exists("%s:\\"%letter) ... is there a "windows" way of
doing it?)

2. More importantly for those drives that exist, how do I determine if
it is actually a harddrive?

thanks

matt

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


Re: lambda a plusieurs arguments

2005-05-27 Thread Sébastien Boisgérault
Nico,

[EMAIL PROTECTED] seems to be a good place to post
questions related to Python if you intend to use
french.

-> http://www.aful.org/wws/arc/python/

((
des questions rédigées en français sont plus
à leur place sur des liste de diffusions
nationales ...
))

Regards,

SB

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


  1   2   >