Re: templates

2006-01-31 Thread thakadu
I haven't got around to trying HTMLTemplate yet but it is on my list of
things to do. It would be great to see how it compares in perfomance
and simplicity to PyMeld and other DOM approaches.

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


Re: templates

2006-01-31 Thread thakadu
Yes I looked at that but I did not benchmark it. Basically it seems to
convert the Meld or part of a Meld into a %s template in any case and I
already knew that %s performace was very good. So if I had used PyMeld
combined with %s then sure it would be much faster but I wanted to
benchmark a pure PyMeld approach against a pure %s approach.

You are right thought that this could significantly speed things up if
one was prepared to use a dual approach (less clean but I would still
use it if it was convenient).

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


Re: templates

2006-01-31 Thread thakadu
I would like to give a few more specifics about my "benchmarking". The
web page had about 10  simple fields and a table of roughly 30 table
rows. The method of generation the table rows was exactly the same as
the example in the PyMeld documentation ie you create the Meld, you
make a copy of a prototypr row instance, you generate your new rows,
which may have replaceable fields inside them, and finally you replace
the single prototype row with all the new rows you have generated. The
same test using the same data with Cheetah and native templates
resulted in (on an oldish 600Mhz box):
PyMeld: +-300ms
Cheetah: +-30ms
Native %s: +- 5ms
On newer hardware obviously the times will be very different but this
particular application has to be able to scale to very large tables.
I did not try PyMeldLite because the HTML I am using is exactlty that:
HTML and not XHTML. Again I am not criticising PyMeld, I love its
simplicity and clean api and the code is easily understandable so I
will probably take a look at it again at some time. Also its great that
it works with any snippet of HTML code it does not even have to be
valid HTML and I get a lot of invalid HTML from the designers.
Regarding Cheetah, I was using Cheetah 1.0. There is a 2.0 Release
Candidate out but I didnt want to be using anything in RC status for a
production site.

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


Re: templates

2006-01-30 Thread thakadu
I have used PyMeld (http://www.entrian.com/PyMeld/) which is one of
very few that gives a 100% separation of code and presentation, in fact
PyMeld is not strictly speaking a template system at all.
I have also used Cheetah. (http://www.cheetahtemplate.org/) However for
a recent project (http://muti.co.za) I ended up using Python's built in
%s templating engine. The reason for this was performance. The %s
native system is extremely fast. In my somewhat informal benchmarks
PyMeld was two orders of magnitude and Cheetah one order of magnitude
slower than Python native templates.
I don't mean to criticze these two systems, they are both excellent,
and I probably could have spent some time trying to figure out why they
were so much slower but in the end it was quicker for me to go with
something I knew was super fast. I did try compiling the Cheetah
templates which provided a small performace boost but it was still much
slower than native templates. (I also tried the new $ based native
template system in Python 2.4 but it doesnt have the flexible
formatting support that the % one has)

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


Re: Indentation/whitespace

2006-01-16 Thread thakadu
Yes, thats what you have to do. And that was my original point, you
cannot just paste and go, you have to first reformat.

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


Re: Indentation/whitespace

2006-01-16 Thread thakadu
>It just has to be consistent within a *single* block.

Correct, and therein lies the problem I am describing.
If someone has used two spaces and you paste into
the SAME block where you are using four spaces
you will break your code.

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


Re: Indentation/whitespace

2005-12-24 Thread thakadu
>That's hardly Python's fault. That's a problem with lousy browsers,
>editors etc. which add word-wrapping or remove whitespace. >Complain to the
>browser developers.

While I have no doubt that there are lousy browsers out there, the
problem is not only with browsers, but also I agree with you its not
Python's fault. The issue is that the code I am pasting may have used a
DIFFERENT indentation scheme, so lets say I used four spaces and the
code I am pasting used two spaces, or worse yet, a tab, that is where
the problem arises. Now assuming that the browser and the copy and
paste buffers dont screw up the indentation, when I paste that code
into my editor that is where the problem arises. Sure if everyone stuck
to the recommended 4 spaces in the style guide it would help. But even
then in the context of your program you may be a further level of
indentation.
I dont know if trying to make the editor any cleverer would help
either. You could get it to simply replace the indentation in the newly
pasted code to the same as the surrounding code, (and there may even be
some Python modes that do that already) but that may not always be what
you wanted!

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


Re: Indentation/whitespace

2005-12-23 Thread thakadu
I consider myself a fairly experienced Python coder and although I am
not "uncomfortable" with significant whitespace there are a few places
where I do find it annoying and I wouldnt mind an alternate block
delimitation syntax.  I would prefer something like the ruby "end"
though rather than '{' and '}'. The place I find it annoying is in
pasting snippets of code from say web pages. I very often google for a
piece of code and then paste it into my editor and almost always the
pasted piece of code has different indentation and causes a compiler
error. Sometimes in vim "100==" fixes it but very often not. It would
be nice if you could use an "end" delimiter for quick experimentation
with code and then later on go and remove the "end" and fix the
indentation.

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


Re: Indentation/whitespace

2005-12-23 Thread thakadu
It is not really unique to Python as I have pointed out on this or
other forums before. The Occam (OCCAM?) language also uses significant
whitespace in much the same way as Python and there may also be others.

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


Re: bsddb185 question

2005-11-23 Thread thakadu
Martin you are great!

If I had just opened the file with f=bsddb185.hashopen('filename',''w')
it would have worked the first time.
So now I will create wrapper classes around the file classes of
bsddb185 and create the methods that I need to keep it consistent
with bsddb. Another small difference I noted is that bsddb seems
to auto sync() while bsddb185 does not, this is not a big issue though.

Thanks very much for all your input!

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


Re: bsddb185 question

2005-11-22 Thread thakadu
Thanks Martin

However the line:
del db[key]
results in an error: (1, 'Operation not permitted')
(only tested on Python 2.3.5)
Could this be because the .del() method of the dictionary
has not been implemented either? In fact in my tests
any attempt at altering the db by use of normal dictionary
methods fails with the same error. e.g.
db['newkey']='newvalue' causes the same error.
(again, only tested on Python 2.3.5)
So it seems only those methods listed by dir()
have been implemented, which is what I would expect.

Thanks for your info on the rules for interface implementation
in Python. That is an interesting difference. I have grown to
like the rules for java interface implementation because you
are guaranteed that all defined methods for the interface have
been implemented. That is what is meant by "implementing" an
interface in java. Although I dont deny the Python way may also
have its advantages, just different ones!

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


Re: bsddb185 question

2005-11-22 Thread thakadu
Ok but if you read my original post I already said that! The issue is
that I have an application that needs to share data with
an existing Berekeley db 1.85 database and applications
in perl. Sure if I was creating the database myself I would use the
newer bsddbmodule but I can't require the perl code be rewritten, so is
there
any way in Python to read and write to a legacy 1.85 Berkely
db?

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


Re: bsddb185 question

2005-11-22 Thread thakadu
It seems it doesnt implement ALL of the dictionary interface though.
dir({}) yields many more methods than dir(bsddb185.open(f)).
So bsddb185 is missing many of the methods that I am used
to in bsddb. I mentioned some above that are missing, pop()
in particular would be useful in my situation but there are
others as well.
>From a java perspective I believe that its not possible to omit certain
methods when implementing an interface, I am not sure about Python
though.

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


bsddb185 question

2005-11-21 Thread thakadu
I have an application that needs to create and delete
records in a Berkeley DB version 1.85 database.
If I use the bsdddb185 module I dont see any
of the record manipulation methods in there that
are available in the newer bsddb module.
(put(), get(), pop() etc)

I know the docs say that one should always use
the newer bsddb module however it appears that the bsddb module
is unable to open version 1.85 databases.

So it seems I am forced to use the bsddb185 module
which does not have convenient record level methods.
Am I missing something here or have others eperienced
tha same?

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


Re: HTML generation vs PSP vs Templating Engines

2005-11-16 Thread thakadu
I just do the following:

I store the form data as a pickeled dictionary. Then I create my
HTML form with something like this:

HTMLout="""..
..


'''

where the field1, field2 etc era the fields on my form.

Then finally:

print HTMLout % dict

where dict has all the values that I previously pickled.
You have to do some additional trickery for  type fields
and checkboxes and so on but its really not difficult.

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


Re: fcntl.flock() not working when called from a function

2005-11-04 Thread thakadu
Thank you both for your replies. You are both quite correct and upon
testing I get the desired results. I was mistakenly expecting the
execution of the function to block at the fcntl.flock(f,fcntl.LOCK_EX)
line.
But I am slowly getting my head around it. 

Thanks

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


Re: Python and Lotus Notes

2005-11-04 Thread thakadu
I have had success with jython using the notes.jar classes, for
example:

import lotus.domino
import java.io
import java.net
import java.lang
import java.util

lotus.notes.NotesThread.sinitThread()
S = lotus.notes.Session.newInstance();
db=S.getDatabase("server/domain","domlog.nsf")
agent=db.getAgent("DeleteOldDocs")
for x in range(50):
print x
result=agent.runOnServer()
print "res %d" % result

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


fcntl.flock() not working when called from a function

2005-11-04 Thread thakadu
The following code works as expected when run in the main body of a
python script (ver 2.3.5) on OpenBSD v3.8. but when it is in the body
of a function definition it does not work. It does not raise any errors
but it simply does not block as expected. I have repeated this in both
a cgi envirnoment and a non-cgi environment. I also have repeated it
under OpenBSD 3.6 Python Version 2.3.4. To test this you need to run
the code from two shells or if testing the cgi version from two
browsers.
The first call to flock() should pass without blocking while the second
call should block.
I have tried varying the file open mode by using 'r', 'r+', 'w', 'rw',
'w+', and always I get the same results.
Does anyone have an idea why this would work in the main body of the
script but not in a function?

This code works if in the main body of a script:

import fcntl
f=open('/tmp/lockfile')
fcntl.flock(f,fcntl.LOCK_EX)

but this does not work:

import fcntl

def lock():
f=open('/tmp/lockfile')
fcntl.flock(f,fcntl.LOCK_EX)

lock()

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


Re: Simple prototype text editor in python

2005-10-07 Thread thakadu
Thanks for everyones advice. I finally went
for a very basic BSD style template that
I found somewhere. Its really short and
easy to understand, at least to me!

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


Re: Simple prototype text editor in python

2005-10-06 Thread thakadu
Thanks Robert

I have packaged it up with distutils and included the
license in the README.txt file.
I think I am missing something as I have only
seen a place (under submissions) on
http://python.org/pypi?%3Aaction=submit_form
to submit the PKG_INFO file, or to submit a url manually
but nowhere to actually upload the distribution file. (the tar.gz file)

Am I looking in the wrong place? Or is it acceptable to post a .tar.gz
file in place of the PKG_INFO file?

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


Re: Simple prototype text editor in python

2005-10-06 Thread thakadu
Hi Viktor

At the moment I dont have any web site where I can
upload it. Do you or anyone have any suggestions or
know of any web sites where one can post python code?
If not please email me and I will send you the code by email.

Regarding the license I have not yet decided what type
of license (if any, since its very few lines of code)  but probably
will be GPL or BSD style. I have no former experience in
licensing code so any suggestions will be welcome there as well.
(For one, do you know if simply stating somewhere in the
code "This is licensed under blah blah" is sufficient
to consider the code licensed?)

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