Re: IDLE history, Python IDE, and Interactive Python with Vim

2005-02-04 Thread TZOTZIOY
On Wed, 02 Feb 2005 20:45:48 -0600, rumours say that Ashot
[EMAIL PROTECTED] might have written:

I have been frustrated for quite some time with a lack of a history  
command in IDLE (in fact with IDLE in general).  Often I'll develop new  
code at the command line, testing each line as I go.  Currently I have to  
copy and paste, removing outputs and the  at each line.
Is it perhaps possible to make some kind of hack to do this (dump a  
command history)?

I am not quite sure if it's exactly what you need, but, apart from moving to
previous lines and pressing Enter, do you know about Alt-P and Alt-N?
-- 
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


Re: how to generate SQL SELECT pivot table string

2005-02-04 Thread McBooCzech
Tahnks a lot. Michalels sequence works flawlessly. And it is really
elegant :)

John Machin wrote:
A few quick silly questions:
Have you read the Python tutorial?
Do you read this newsgroup (other than answers to your own questions)?
Could you have done this yourself in a language other than Python?
Of course I have read (or still reading) Python tuorial and newsgroup
(No kidding:). And I am able to done this in VBA for example. But I am
not able to write such a elegant construction. Tanks a lot.

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


Re: Calling a method using an argument

2005-02-04 Thread C Gillespie
Dear All,

Many thanks

Colin
C Gillespie [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Dear All,

 I have a simple class
 class hello:
 def world(self):
 return 'hello'
 def test(self,arg):
 return self.arg

 When I want to do is:
 hello.test('world')
 'hello'

 i.e. pass the method name as an argument. How should I do this?

 Thanks

 Colin




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


Re: ANN: PyDev 0.9.0 released

2005-02-04 Thread Michele Petrazzo
Fabio Zadrozny wrote:
Hi All,
PyDev - Python IDE (Python development enviroment for Eclipse) version 
0.9.0 has just been released.

This release supports python 2.4 and has PyLint 0.6 integrated.
Code completion had some improvements too.
Check the homepage for more details (http://pydev.sourceforge.net/).
Regards,
Fabio Zadrozny
--
Software Developer
ESSS - Engineering Simulation and Scientific Software
www.esss.com.br
This page on your site, don't exist!
http://pydev.sourceforge.net/Features.html
modify the link in:
http://pydev.sourceforge.net/features.html
Bye,
Michele
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 binaries for accessing PostgreSQL from Windows?

2005-02-04 Thread Gerhard Haering
On Fri, Feb 04, 2005 at 02:24:50AM -0800, Frank Millman wrote:
 Hi all
 
 The subject line says it all.
 
 I have been using pypgsql to access PostgreSQL from Linux and from
 Windows, and it works fine.
 
 I am upgrading to Python 2.4. I can recompile pypgsql for Linux, but I
 do not have a Windows compiler. SourceForge has a binary for Python
 2.3, which is the one I have been using. It does not have one for 2.4.
 
 I tried the psycopg site, but it does not seem to have binaries at all.
 
 Does anyone know if either of these will be available in binary form
 for Python 2.4 on Windows?

http://ghaering.de/pypgsql/

These are SSL-enabled dynamically linked and need the PostgreSQL client
libraries installed. I recommend the ones from PgAdmin3, which have SSL
support. They were only tested with these.

-- Gerhard


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

Re: continuous plotting with Tkinter

2005-02-04 Thread Martin Blume
Russell E. Owen schrieb

 I have a number-crunching application that spits out
 a lot of numbers. Now I'd like to pipe this into a
 python app and plot them using Tkinter, such as:
 $ number_cruncher | myplot.py
 But with Tkinter once  I call Tkinter's mainloop() I
 give up my control of the app and I can't continue to
 read in data from stdin.  Or can I? If so, how?

 One way is to use a thread to read the numbers, then
 make them available to the main thread via a Queue
 object, which you poll for new values.

I already tinkered with threads, yet it didn't work.
I'll try again.


 Another option is to use a Tk-compatible file or socket
 of some kind which triggers a callback when data comes
 in. See

htttp://www.astro.washington.edu/rowen/TkinterSummary.html#FileHand
lers

 some ideas on this.

Thanks, I'll look.

Martin


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


python equivalent to haskells iterate.

2005-02-04 Thread Graeme Caldwell
Subject: equivalent to Haskell's iterate function.

While reading through "Two Dozen Short Lessons in Haskell". I came across the following function:

 decimalNumeralFromInteger x = reverse [d | (s,d) - takeWhile(/=(0,0)) (sdPairs x)]
 where
 sdPairs x = iterate nextDigit (x `divMod` 10) nextDigit(xShifted,d) = xShifted `divMod` 10

What this does is takes as a paramter a decimal integer and convertsit to a sequence in which each member is numeral from each position inthe integer.e.g. decimalNumberFromInteger 543654= [5,4,3,6,5,4]

As Python's the language I am most interested in becoming proficientin(still a way to go) , I rewrote this in Python. I was trying to preserve the functional aspects of the Haskell, and wanted a python function that would let me repeatedly apply a function(lambda or otherwise) to its own result obviously this is easy to do using a while loop but I wanted a more elegant solution,as in the Haskel code above.I found that there are plenty of functions that allow one to iterate over a sequence(itertools module), but could not find a equivalent to Haskell's iterate.The best that I could come up with was:
 
def decimalNumeralFromInteger(x): list = []x = divmod(x,10) while x  (0,0): list.append(x[1]) x = divmod(x[0], 10) return list

which seems a bit clunky by comparison. My question is does such a function exist.

If the answer is obvious and in the docs, excoriation is expectedand deserved. Also I know it's not really an important issue and theabove function is adequate to the task, but I'm curious if it can bedone the Haskell way and if not, why.
		 ALL-NEW 
Yahoo! Messenger 
- all new features - even more fun! 
 -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression match objects - compact syntax?

2005-02-04 Thread Diez B. Roggisch
Johann C. Rocholl wrote:

 
 How do you people handle this?

Usually we don't bothe too much. But it has been suggested to do something
like this:

class Matcher:
def __init__(self, rex):
   self.rex = rex

def match(self, s):
   self.m = self.rex.match(s)
   return not self.m is None

Then you can do

m = Matcher(rex)

if m.match(line):
print m.m


Of course you can enhance the class mather so that all methods it does not
define by itself are delegated to self.m, which would be more convient. But
I'm currently too lazy to write that down :)
-- 
Regards,

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


making symlinks with distutils

2005-02-04 Thread Michele Simionato
I want to distribute a pure Python package with this structure:

mypackage
 __init__.py
 module1.py
 module2.py
 ...
 myexecutable.py

In particular, myexecutable.py is a script which is intended to be used
from the command line via the shebang trick. I want to distribute on
Unices.
and I want a symlink

/usr/bin/myexecutable - package-path/mypackage/myexecutable.py

to be made at installation time, when the user runs python setup.py
install.

What is the recommanded way to do that? Do I need a postinstallation
script or something like that?

I could do that in various way, but I don't see the obvious one,
maybe because I am not a Dutch ;)


 Michele Simionato

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


Re: making symlinks with distutils

2005-02-04 Thread Sylvain Thenault
On Fri, 04 Feb 2005 02:45:34 -0800, Michele Simionato wrote:

 I want to distribute a pure Python package with this structure:
 
mypackage
 __init__.py
 module1.py
 module2.py
 ...
 myexecutable.py
 
 In particular, myexecutable.py is a script which is intended to be used
 from the command line via the shebang trick. I want to distribute on
 Unices.
 and I want a symlink
 
 /usr/bin/myexecutable - package-path/mypackage/myexecutable.py
 
 to be made at installation time, when the user runs python setup.py
 install.
 
 What is the recommanded way to do that? Do I need a postinstallation
 script or something like that?
 
 I could do that in various way, but I don't see the obvious one, maybe
 because I am not a Dutch ;)

i'm not sure there is a standard way to do so with distutils.
My current way to handle executable scripts is to have a run() function in
the myexecutable.py module, and then to have a very simple myexecutable
script with the following content:

#!/usr/bin/python
from mypackage import myexecutable
myexecutable.run()

And then register this script using distutils'scripts keyword argument. 
This has the advantage that I can also create a very simple .bat file for
windows users without code duplication.

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


Converting a string to a function pointer

2005-02-04 Thread Håkan Persson
Hi.
I am trying to convert a string into a function pointer.
Suppose I have the following:
from a import a
from b import b
from c import c
funcString = GetFunctionAsString()
and funcString is a string that contains either a, b or c.
How can I simply call the correct function?
I have tried using getattr() but I don't know what the first (object) 
argument should be in this case.

Thanks,
Håkan Persson
--
http://mail.python.org/mailman/listinfo/python-list


Re: IPython colors in windows

2005-02-04 Thread Ashot
yea, I've done that. It must be something subtle, as the colors and tab  
completion works.
On Thu, 03 Feb 2005 20:31:37 -0800, DogWalker [EMAIL PROTECTED] wrote:

Ashot [EMAIL PROTECTED] said:
On 3 Feb 2005 19:18:33 -0800, James [EMAIL PROTECTED] wrote:
Ashot wrote:
I am using IPython in windows and the LightBG setting doesn't
correctly
because the background of the text is black even if the console
background
is white.  Anyone know whats going on?  Thanks.
--
==
Ashot Petrosian
University of Texas at Austin, Computer Sciences
(views expressed are solely my own)
==
Did you try installing readline for windows?
http://newcenturycomputers.net/projects/readline.html
yea I've installed that and ctypes.  The color and tab completion work,
its just that colored get displayed with black background, it almost  
works
so its very frustrating..

Did you try the following (from the manual)?:
Input/Output prompts and exception tracebacks
You can test whether the colored prompts and tracebacks work on your  
system interactively by typing '%colors Linux' at the prompt (use  
'%colors LightBG' if your terminal has a light background). If the input  
prompt shows garbage like:
[0;32mIn [[1;32m1[0;32m]: [0;00m
 instead of (in color) something like:
 In [1]:
  this means that your terminal doesn't properly handle color escape  
sequences. You can go to a 'no color' mode by typing '%colors NoColor'.

  You can try using a different terminal emulator program. To  
permanently set your color preferences, edit the file  
$HOME/.ipython/ipythonrc and set the colors option to the desired value.

--
==
Ashot Petrosian
University of Texas at Austin, Computer Sciences
(views expressed are solely my own)
==
--
http://mail.python.org/mailman/listinfo/python-list


Re: Possible additions to the standard library? (WAS: About standard library improvement)

2005-02-04 Thread Daniel Bickett
Fredrik Lundh wrote:
 your DeleteKeyAll operation would fit nicely in such an interface, but I'm not
 sure it belongs in the low-level interface, and a higher-level interface 
 consisting
 of just one helper would seem a bit odd.on the other hand, it's about time
 someone wrote that winreg module... (hint).

I wasn't aware that was even on our plate ;) Is the intent for it just
to have wrappers around the _winreg functions, or were there things
planned for it?

-- 
Daniel Bickett
dbickett at gmail.com
http://heureusement.org/
-- 
http://mail.python.org/mailman/listinfo/python-list


walktree browser filenames problem

2005-02-04 Thread dimitri pater
Hello,

I use the following script to list the files and download files from
my website (99% of the code is from
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/200131).
The problem is that the filenames are cut off in the status bar of the
browser because of the white space (eg 'hello.pdf' works, but 'hello
there.pdf' is displayed as hello).
The filenames are displayed correctly in the main page of the browser.
I tried several things, maybe somebody knows how to do it?

script: (sorry for the long list)

#! /usr/bin/python

import os, sys
import cgi
print Content-type: text/html
print
print pre

try:
import cgitb
cgitb.enable()
except:
sys.stderr = sys.stdout

print /pre

def walktree(top = ../upload, depthfirst = True):
import os, stat, types
names = os.listdir(top)
if not depthfirst:
yield top, names
for name in names:
try:
st = os.lstat(os.path.join(top, name))
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
for (newtop, children) in walktree (os.path.join(top,
name), depthfirst):
yield newtop, children
if depthfirst:
yield top, names

def makeHTMLtable(top, depthfirst=False):
from xml.sax.saxutils import escape # To quote out things like amp;
ret = ['table class=fileList\n']
for top, names in walktree(top):
ret.append('   trtd class=directory%s/td/tr\n'%escape(top))
for name in names:
ret.append('   trtd class=filea
href=http://e-bench.serpia.com/upload/%s%s/a/td/tr\n' %
(escape(name),escape(name)))
ret.append('/table')
return ''.join(ret) # Much faster than += method

def makeHTMLpage(top, depthfirst=False):
return '\n'.join(['!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN',
  'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd;',
  'html'
  'head',
  '   titleSearch results/title',
  '   style type=text/css',
  '  table.fileList { text-align: left; }',
  '  td.directory { font-weight: bold; }',
  '  td.file { padding-left: 4em; }',
  '   /style',
  '/head',
  'body',
  'h1Documenten e-bench/h1',
  makeHTMLtable(top, depthfirst),
  'BRBRHRBA
HREF=http://e-bench.serpia.com;Home/A/B',
  'h5To do: escape chars verwijderen/h5',
  'h5.../h5',
  'h5Aparte HTML template maken als in upload.py/h5',
  '/body',
  '/html'])
   
if __name__ == '__main__':
if len(sys.argv) == 2:
top = sys.argv[1]
else: top = '.'
print makeHTMLpage('../upload')

-- 
Please visit dimitri's website: www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread JanC
Paul Rubin schreef:

 I don't know that the browser necessarily renders that faster than it
 renders a table,

Simple tables aren't slow, but tables-in-tables-in-tables-in-tables-in-
tables are.

-- 
JanC

Be strict when sending and tolerant when receiving.
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.4 binaries for accessing PostgreSQL from Windows?

2005-02-04 Thread Josef Meile
Hi Frank
I tried the psycopg site, but it does not seem to have binaries at all.
Does anyone know if either of these will be available in binary form
for Python 2.4 on Windows?
For psycopg, there is a site with binaries for windows:
http://www.stickpeople.com/projects/python/psycopg/
Regards,
Josef
--
http://mail.python.org/mailman/listinfo/python-list


Re: IDLE history, Python IDE, and Interactive Python with Vim

2005-02-04 Thread http://www.stani.be
I think SPE has exactly what you need. Next to the shell there is the
session, which has only the commands typed on the interactive prompt.

Stani

http://spe.pycs.net

Ashot wrote:
 This is sort of both Python and Vim related (which is why I've posted
to
 both newsgroups).

 Python related:
 --
 I have been frustrated for quite some time with a lack of a history
 command in IDLE (in fact with IDLE in general).  Often I'll develop
new
 code at the command line, testing each line as I go.  Currently I
have to
 copy and paste, removing outputs and the  at each line.
 Is it perhaps possible to make some kind of hack to do this (dump a
 command history)?

 Idle in general isn't that great IMO, so I was wondering also if
there are
 better alternatives out there?  What do people use mostly?  I've
tried
 something called pyCrust, but this too didn't have history and some
other
 things I was looking for.  On a more general note, although the
agility
 and simplicity of Python make programming tools like an IDE less
 necessary, it still seems that Python is lacking in this departement.
 The
 PyDev plug-in for Eclipse seems like good step in this direction,
although
 I haven't tried it yet.  Does anyone have any experience with this,
or
 perhaps can point me to other tools.

 Vim related:
 --
 Ideally, it would be nice to have a command mapped to a keystroke
that can
 append the last executed command to a file.  Even better would be a
system
 that would integrate the file editing and interactive command line
tool
 more seamlessly.  Something along the lines of a debugger + file
editor
 + command line utility, where file editor = vim.  I know that vim has
a
 utility for running python commands from its command prompt, but I
have
 had a hard time getting this to work in windows and haven't explored
it.
 Has anyone seen/tried a system along these lines, perhaps
incorporating
 the python debugger (pdb)?  I can see something that will run the
file you
 are editing in vim up to the cursor or a mark with a set_trace at the
line
 you are editing.


 Any info is appreciated, thanks.

 --
 Ashot Petrosian
 University of Texas at Austin, Computer Sciences

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


Re: advice needed for simple python web app

2005-02-04 Thread Fred Pacquier
Dan Perl [EMAIL PROTECTED] said :

 This is exactly the kind of summary that I think should be in a 
 WebProgrammingShootOut (see another one of my postings in this thread)
 but I failed to find such a summary.  Thanks, Brian!  Anyone can add
 to the list? 

I myself am also into (very) simple web apps and hence simple, easy-to-
learn web frameworks.

CherryPy is a very nice kit, still simple enough but already (IMO) 
somewhat on the powerful, batteries-included side for a beginner -- and, 
as you noted, a bit under-documented at the moment.

There are a couple of others that will get you started without too much 
effort (in part because simplicity is one of their design points) and 
without limiting you too much either : Karrigell by Pierre Quentel and 
Snakelets by Irmen de Jong.

They're somewhat similar in scope and concept : it will be mostly a 
matter of which one 'fits your brain' best. Myself I settled on 
Snakelets, not least because it has some of the better docs out there.
 
 BTW, there are other people who seem to have been also confused by the
 wide spectrum of choices for this problem: 

That's an old debate in the Python world, yes. The one true way to do 
it motto of the language itself doesn't apply to its web frameworks :)

See the recent Ruby on Rails threads for a discussion of whether this 
is good or bad...

-- 
YAFAP : http://www.multimania.com/fredp/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: walktree browser filenames problem

2005-02-04 Thread Richard Brodie

dimitri pater [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]

 The problem is that the filenames are cut off in the status bar of the
 browser because of the white space (eg 'hello.pdf' works, but 'hello
 there.pdf' is displayed as hello).

urllib.quote() should do the trick. You need to follow the rules for
encoding URIs as well as the HTML ones.


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


Re: Converting a string to a function pointer

2005-02-04 Thread John Machin
On Fri, 04 Feb 2005 12:01:35 +0100, Håkan Persson [EMAIL PROTECTED]
wrote:

Hi.

I am trying to convert a string into a function pointer.
Suppose I have the following:

from a import a
from b import b
from c import c

funcString = GetFunctionAsString()

and funcString is a string that contains either a, b or c.
How can I simply call the correct function?
I have tried using getattr() but I don't know what the first (object) 
argument should be in this case.

Try this:

 from sys import exit
 globals()
{'__builtins__': module '__builtin__' (built-in), '__name__':
'__main__', 'exit': built-in function exit, '__doc__': None}
 afunc = globals()[exit]

Do you really need to use the from X import Y style? Consider the
following alternative:

 import sys
 afunc = getattr(sys, exit)



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


Re: Weekly Python Patch/Bug Summary

2005-02-04 Thread David Fraser
Kurt B. Kaiser wrote:
Patch / Bug Summary
___
Patches :  284 open ( +4) /  2748 closed ( +1) /  3032 total ( +5)
Bugs:  804 open ( +1) /  4812 closed (+13) /  5616 total (+14)
RFE :  167 open ( +0) /   142 closed ( +1) /   309 total ( +1)
I wonder if it would be possible to include the status of the closed 
bugs ... if a patch has been refused thats very different to it being 
included. I usually end up opening the page to see what has happened, 
would be nice if it was in the mail...

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


Re: Learning Python for a new beginner

2005-02-04 Thread Nick Coghlan
Lisa Horton wrote:
I hear that Python is one of the easiest languages to learn. It is
easier than PHP or Pearl? Is it as useful as those two? I am attracted
to Python as a first language, but I just want to be sure I will be
able to use it.
Opinions, thoughts, thanks!
I suggest grabbing the 2.4 Python interpreter and the tutorial from 
www.python.org (if you're on Windows, the tutorial is included with the installer).

There are also resources like Dive into Python that may be useful.
With respect to PHP, I have no opinion, since I've never needed to use it. With 
respect to Perl, I find it to be such an inconsistent dog's breakfast that I 
have the docs page open whenever I have to write or read it. With Python, I 
first used it for one subject at University, and was able to pick it back up a 
few years later without even looking at the documentation.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: making symlinks with distutils

2005-02-04 Thread Michele Simionato
From what I see in the docs, registering a script just normalize the
shebang line, but does not install it in
/usr/bin, nor make any symbolic links, so it is not
what I am looking for.
I guess I need to add a os.link(src, dst) somewhere in the
setup.py script or in a postinstallation script but I am not exactly
sure where.

 M.S.

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


what version of pyQt are compatible with QT 3.1.1 educational ?

2005-02-04 Thread Fabrice H
hello
I have QT 3.1.1 educational on my computer (Win XP)
I tried to install several version of pyQt (PyQt edu 3.13 Edu, PyQt
edu 3.6, PyQT non-commercial 4.13, but I still can't import qt module.

when I enter :
import qt
I have the following message :
Import Error : DLL Load failed : cannot find the specified module

do you have any idea please ?

thanks a million in advance !!

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


Re: walktree browser filenames problem

2005-02-04 Thread dimitri pater
thanks!
now it works:
ret.append('   trtd class=filea
href=http://e-bench.serpia.com/upload/%s%s/a/td/tr\n' %
(urllib.quote(escape(name)),escape(name)))

bye,
Dimitri


On Fri, 4 Feb 2005 11:45:17 -, Richard Brodie [EMAIL PROTECTED] wrote:
 
 dimitri pater [EMAIL PROTECTED] wrote in message
 news:[EMAIL PROTECTED]
 
  The problem is that the filenames are cut off in the status bar of the
  browser because of the white space (eg 'hello.pdf' works, but 'hello
  there.pdf' is displayed as hello).
 
 urllib.quote() should do the trick. You need to follow the rules for
 encoding URIs as well as the HTML ones.
 
 --
 http://mail.python.org/mailman/listinfo/python-list
 


-- 
Please visit dimitri's website: www.serpia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: what version of pyQt are compatible with QT 3.1.1 educational ?

2005-02-04 Thread Phil Thompson
 hello
 I have QT 3.1.1 educational on my computer (Win XP)

That doesn't sound like you are conforming to Trolltech's Educational
License. To quote:

 The product may only be used on school hardware and on the school's
premises.

 I tried to install several version of pyQt (PyQt edu 3.13 Edu, PyQt
 edu 3.6, PyQT non-commercial 4.13, but I still can't import qt module.

 when I enter :
 import qt
 I have the following message :
 Import Error : DLL Load failed : cannot find the specified module

 do you have any idea please ?

As it's a binary package, the educational version of PyQt supports the
version of Qt that was current at the time. I think PyQt v3.7 to v3.11
supported that version of Qt.

Phil

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


Re: making symlinks with distutils

2005-02-04 Thread Sylvain Thenault
On Fri, 04 Feb 2005 04:01:25 -0800, Michele Simionato wrote:

From what I see in the docs, registering a script just normalize the
 shebang line, but does not install it in /usr/bin, nor make any symbolic
 links, so it is not what I am looking for.

Actually it does install it is $PREFIX/bin.

-- 
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: python equivalent to haskells iterate.

2005-02-04 Thread Nick Coghlan
Graeme Caldwell wrote:
What this does is takes as a paramter a decimal integer and converts
it to a sequence in which each member is numeral from each position in
the integer.
For this specific problem, the builtin 'str' is your best bet:
  digit_list = map(int, str(val))
(If you only want to display the digits, you can use list(str(val)) to leave 
them as strings rather than converting back to an int)

However, that doesn't really fit with the general 'iterate' question you were 
asking. For that, something like a generator function is likely to help:

  def digits(val):
if val:
  while val:
val, digit = divmod(val, 10)
yield digit
else:
  yield 0
  digit_list = list(reversed(list(digits(val
Basically, I think the 'yield' keyword and generator functions are likely what 
you are looking for when it comes to easily building iterators.

However, continuing on with the attempt to write Haskell in Python, making the 
generator function 'dumber' by eliminating its knowledge of the termination 
condition gets us closer to the original:

  from itertools import takeWhile
  def next_digit(val):
while 1:
  val, digit = divmod(val, 10)
  yield digit
  digit_list = list(reversed(list(
 takewhile(lambda digit: digit, next_pair(val)
For cases where you don't need to do an assignment each time through the loop 
(e.g. by dividing by progressively larger multiples of 10 instead of using 
repeated division), you can ditch the function and use a generator expression 
instead:

  from itertools import takewhile, count
  digit_list = reversed(
 list(
   takewhile(
 lambda digit: digit,
 (((val // (10 ** i)) % 10) for i in count())
   )
 )
   )
Usually you're going to be better served by making the generator function 
smarter if you're going to be writing one anyway, though.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: making symlinks with distutils

2005-02-04 Thread Michele Simionato
Sylvain Thenault:
 Actually it does install it is $PREFIX/bin.

Aha! And how do I set $PREFIX? Is it a Unix environment variable or is
it
a keyword argument in setup? Something like setup( prefix=/usr) ?

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


dynamic func. call

2005-02-04 Thread Aljosa Mohorovic
can i do something like this:

s = myFunction
a = s() # equals to: a = myFunction()


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


Re: Extreme Python

2005-02-04 Thread John Roth
Sigh. Another mailing list to
subscribe to. Why do we
need this? Especially why do
we need it at Google?
I'd rather not Balkanize things and
keep the XP and Python issues away
from the two lists involved. If there are
Python specific issues, they're
quite welcome on either this list/newsgroup
or on the regular extremeprogramming
list.
John Roth
PyFIT maintainer.
Extremeprogramming mailing list moderator (1 of 7)
[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
Hello all,
I've created a web/email group for topics related to both Extreme
Programming (or other Agile methodologies) and Python. If you're
interested, please visit
http://groups-beta.google.com/group/extreme-python/ and subscribe. Or
just post directly to [EMAIL PROTECTED] Hope to see you
there!
Troy Frever
Extreme Programmer and Coach
Aviarc Corporation
--
http://mail.python.org/mailman/listinfo/python-list


Re: Why does super() require the class as the first argument?

2005-02-04 Thread Nick Coghlan
Kevin Smith wrote:
I can create a super() that does this as follows:
_super = super
def super(obj, cls=None):
if cls is None:
return _super(type(obj), obj)
return super(cls, obj)
I guess I'm just not sure why it wasn't done that way in the first place.
Because it doesn't work. As Chris pointed out, it leads to infinite 
recursion:
Py class A(object):
...   def blow_the_stack(self):
... print Well, not yet
...
Py class B(A):
...   def blow_the_stack(self):
... print Perhaps here
... super(type(self), self).blow_the_stack()
...
Py class C(B):
...   pass
...
Py A().blow_the_stack()
Well, not yet
Py B().blow_the_stack()
Perhaps here
Well, not yet
Py C().blow_the_stack()
Perhaps here
infinite recursion traceback snipped
  File stdin, line 4, in blow_the_stack
RuntimeError: maximum recursion depth exceeded
Basically, the first argument to super() says find this type in the supplied 
objects method resolution order, and then move on to the next type in the 
order. Getting this wrong (e.g. by providing a type earlier in the MRO, as 
B.blow_the_stack does by providing type(C()) above) is what leads to the 
infinite recursion.

It *is* possible to eliminate the explicit class argument, but it takes a bit 
(*cough*) of work:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286195

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic func. call

2005-02-04 Thread Ola Natvig
Aljosa Mohorovic wrote:
can i do something like this:
s = myFunction
a = s() # equals to: a = myFunction()

a = locals()[x]()
locals() returns a dictionary with string keys that you can use
--
--
 Ola Natvig [EMAIL PROTECTED]
 infoSense AS / development
--
http://mail.python.org/mailman/listinfo/python-list


Re: making symlinks with distutils

2005-02-04 Thread Sylvain Thenault
On Fri, 04 Feb 2005 04:59:51 -0800, Michele Simionato wrote:

 Sylvain Thenault:
 Actually it does install it is $PREFIX/bin.
 
 Aha! And how do I set $PREFIX? Is it a Unix environment variable or is it
 a keyword argument in setup? Something like setup( prefix=/usr) ?

it's a command line argument of the install command:

python setup.py install --prefix=~/

or

python setup.py install --home=~/

(the difference between --home and --prefix is that the former will
install library in $PREFIX/lib/pythonX.Y/site-packages while the latter
will install it in $PREFIX/lib/python/

-- 
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: OT: why are LAMP sites slow?

2005-02-04 Thread Steve Holden
Paul Rubin wrote:
Skip Montanaro [EMAIL PROTECTED] writes:
It's more than a bit unfair to compare Wikipedia with Ebay or
Google.  Even though Wikipedia may be running on high-performance
hardware, it's unlikely that they have anything like the underlying
network structure (replication, connection speed, etc), total number
of cpus or monetary resources to throw at the problem that both Ebay
and Google have.  I suspect money trumps LAMP every time.

I certainly agree about the money and hardware resource comparison,
which is why I thought the comparison with 1960's mainframes was
possibly more interesting.  You could not get anywhere near the
performance of today's servers back then, no matter how much money you
spent.  Re connectivity, I wonder what kind of network speed is
available to sites like Ebay that's not available to Jane Webmaster
with a colo rack at some random big ISP.  Also, you and Tim Danieliuk
both mentioned caching in the network (e.g. Akamai).  I'd be
interested to know exactly how that works and how much difference it
makes.
It works by distributing content across end-nodes distributed throughout 
the infrastructure. I don't think Akamai make any secret of their 
architecture, so Google (:-) can help you there.

Of course it makes a huge difference, otherwise Google wouldn't have 
registered their domain name as a CNAME for an Akamai node set.

[OB PyCon] Jeremy Hylton, a Google employee and formerly a PythonLabs 
employee, will be at PyCon. Why don;t you come along and ask *him*?

But the problems I'm thinking of are really obviously with the server
itself.  This is clear when you try to load a page and your browser
immediately get the static text on the page, followed by a pause while
the server waits for the dynamic stuff to come back from the database.
Serving a Slashdotting-level load of pure static pages on a small box
with Apache isn't too terrible (Slashdotting = the spike in hits
that a web site gets when Slashdot's front page links to it).  Doing
that with dynamic pages seems to be much harder.  Something is just
bugging me about this.  SQL servers provide a lot of capability (ACID
for complicated queries and transactions, etc). that most web sites
don't really need.  They pay the price in performance anyway.
Well there's nothing wrong with caching dynamic content when the 
underlying database isn't terribly volatile and there is no critical 
requirement for the absolute latest data. Last I heard Google weren't 
promising that their searches are up-to-the-microsecond in terms of 
information content.

In terms on a network like Google's talking about the server doesn't 
really make sense: as Sun Microsystems have been saying for about twenty 
years now, the network is the computer. There isn't a server, it's 
a distributed service with multiple centers of functionality.

We also know Google has thousands of CPUs (I heard 5,000 at one point and
that was a couple years ago).

It's at least 100,000 and probably several times that ;-).  I've heard
every that search query does billions of cpu operations and crunches
through 100's of megabytes of data (search on apple banana and there
are hundreds of millions of pages with each word, so two lists of that
size must be intersected).  100,000 was the published number of
servers several years ago, and there were reasons to believe that they
were purposely understating the real number.
So what's all this about the server, then? ;-)
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Kartic
Paul Rubin said the following on 2/3/2005 10:00 PM:
I have the idea that the Wikipedia implementers know what they're doing,
but I haven't looked into it super closely.
Absolutely, hence my disclaimer about not viewing the Mediawiki code.
Hmm, I wasn't aware that Apache 2.x gave any significant speedups
over 1.3 except under Windows.  Am I missing something?
Architectural differences. Apache 1.3 spawns a new process for every 
request and before you know, it brings your resources to their knees. I 
don't know what effect Apache 1.3-Win32 has on Windows. Apache 2.x from 
what little I have used is pretty stable on windows and resource 
friendly. (I use Freebsd for serious work)

Hmm, I'm not familiar with Nevow.  Twisted is pretty neat, though
confusing.  I don't see how to scale it to multiple servers though.
I'm asking this question mainly as it relates to midrange or larger
sites, not the very simplest ones (e.g. on my personal site I just use
Python cgi's, which are fine for the few dozen or so hits a week that
they get).  So, the complexity of twisted is acceptable.

True - That is why I can't wait for the twisted sessions during PyCon 
'05 :-)


Yes, good point about html tables, though I'm concerned primarily
about server response.  (It's off-topic, but how do you use CSS to get
the effect of tables?)
My thinking is that all these pieces must fit in well. For example, your 
server response might have been good but the table-driven site could be 
slowing your browser down. The best way to test whether it is the server 
 response that is slow and/or table-driven page is to load that page in 
Lynx.

The CSS way is using div placement of the elements. Actually div 
gives better control over placement than with HTML tables. And with CSS, 
since you style the various HTML tags, you can create different skins 
for your site too. This is definitely OT, like you said, but if you are 
interested, please contact me directly. I don't pretend to be a CSS 
expert but I can help you as much as I can.

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


Re: Is there a market for python developers?

2005-02-04 Thread Nick Coghlan
Paul Rubin wrote:
2) Can using Python make you more marketable as a programmer?
Certainly it can.  You can often get things done faster in Python than
in other languages, and getting things done always helps your
marketability.  Lots of times the customer just needs to get some task
completed, and they don't care whether you use Python or some other
language.  And using Python can result in such a big productivity gain
as to really help you score points with your employer or customer.
Hear, hear! I'm primarily working as a hardware interface engineer, yet a lot of 
the code I write at the moment is in Python. . .

Why?
Because I can write powerful test apps *really* quickly, and nobody really cares 
what language they're written in (the important thing is whether or not the 
hardware is doing the right thing, and Python makes it possible to automate both 
the execution of the tests and the post-analysis of the generated data).

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: [EVALUATION] - E01: The Java Failure - May Python Helps?

2005-02-04 Thread Markus Wankus
Fredrik Lundh wrote:
Markus Wankus wrote:

Google his name - he has been banned from Netbeans and Eclipse (and Hibernate, and others...) for 
good reason.  Can you imagine how much of a Troll you need to be to *actually* get banned from 
the newsgroups of open source projects such as those?

have Pythoneers ever banned anyone from a public forum?  it's not like
we haven't seen trolls and crackpots before, you know.
/F 

I know - which is why it is even more amazing he can get banned from 
other open source groups similarly tolerant as this one...

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


Re: Converting a string to a function pointer

2005-02-04 Thread Steve Holden
Håkan Persson wrote:
Hi.
I am trying to convert a string into a function pointer.
Suppose I have the following:
from a import a
from b import b
from c import c
funcString = GetFunctionAsString()
and funcString is a string that contains either a, b or c.
How can I simply call the correct function?
I have tried using getattr() but I don't know what the first (object) 
argument should be in this case.

Thanks,
Håkan Persson

Well, one really horrible way would be
  getattr(sys.modules['__main__'], funcString)
and, of course, if you were going to use it a lot you could optimize 
slightly with

  this = sys.modules['__main__']
followed later by
  this = getattr(this, funcString)
Overall, however, it might be better to set uip a mapping for the 
functions you need to be accessible. This has the further merits that

  a) You can heve different, and/or multiple names for a function
  b) You can trap errors more easily
  c) erm, I forgot the third advantage, consider this the Spanish
 Inquisition in reverse :-)
So:
funcMap = {
  a: a,
  A: a,
  b: b,
  exoticName: c }
  ...
  funcString = GetFunctionAsString()
  try:
f = funcMap(funcString)
  except KeyError:
print No such function
raise SomethingElse
  result = f(args)
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Al Dykes
In article [EMAIL PROTECTED],
Tim Daneliuk  [EMAIL PROTECTED] wrote:
Paul Rubin wrote:

SNIP

 I've only worked on one serious site of this type and it was SAJO
 (Solaris Apache Java Oracle) rather than LAMP, but the concepts are
 the same.  I just feel like something bogus has to be going on.  I
 think even sites like Slashdot handle fewer TPS than a 1960's airline
 reservation that ran on hardware with a fraction of the power of one
 of today's laptops.

I worked for an Airline computer reservation system (CRS) for almost a
decade. There is nothing about today's laptops that remotely comes close
to the power of those CRS systems, even the old ones. CRS systems are
optimized for extremely high performance I/O and use an operating system
(TPF) specifically designed for high-performance transaction processing.

Web servers are very sessions oriented: make a connection-pass the unit
of work-drop the connection. This is inherently slow (and not how high
performance TP is done). Moreover, really high perfomance requires a
very fine level of I/O tuning on the server - at the CRS I worked for,
they performance people actually only populated part of the hard drives
to minimize head seeks.

The point is that *everything* has to be tuned for high performance
TP - the OS, the language constructs (we used assembler for most things),
the protocols, and the overall architecture.  THis is why, IMHO,
things like SOAP a laughable - RPC is a poor foundation for reliable,
durable, and high-performance TP.  It might be fine for sending an
order or invoice now and then, but sustained throughput of the sort
I think of as high performance is likely never going to be accomplished
with session-oriented architectures.

For a good overview of TP design, see Jim Gray's book, Transaction Processing:
Concepts and Techniques.

P.S. AFAIK the first CRS systems of any note came into being in the 1970s not
  the 1960s, but I may be incorrect in the matter.
-- 

Tim Daneliuk [EMAIL PROTECTED]
PGP Key: http://www.tundraware.com/PGP/




My recollection is that online reservations were in use ca. 1970, and I
know that the operating system was called ACP, renamed to TPF.
Googleing for that finds that online reservation systems stared in the
50's and ran on 7000 gear in the 60's.  

http://www.blackbeard.com/tpf/Sabre_off_TPF/some_highlights_from_sabre_history.htm

I was in banking in th 80's. I recall that circa 1990 hitting 1000 DB
trans/sec was the holy grail on a million $ mainframe.  My bank bought
what was called the last TPF sale about 1991.  It was used as a
message router to conect transactions from thousands ATMs and
teller stations to the right backend system necessary to make a bank
merger work.  


-- 

a d y k e s @ p a n i x . c o m 

Don't blame me. I voted for Gore.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Dave Brueck
Steve Holden wrote:
Paul Rubin wrote:
Skip Montanaro [EMAIL PROTECTED] writes:
It's more than a bit unfair to compare Wikipedia with Ebay or
Google.  Even though Wikipedia may be running on high-performance
hardware, it's unlikely that they have anything like the underlying
network structure (replication, connection speed, etc), total number
of cpus or monetary resources to throw at the problem that both Ebay
and Google have.  I suspect money trumps LAMP every time.

I certainly agree about the money and hardware resource comparison,
which is why I thought the comparison with 1960's mainframes was
possibly more interesting.  You could not get anywhere near the
performance of today's servers back then, no matter how much money you
spent.  Re connectivity, I wonder what kind of network speed is
available to sites like Ebay that's not available to Jane Webmaster
with a colo rack at some random big ISP.  Also, you and Tim Danieliuk
both mentioned caching in the network (e.g. Akamai).  I'd be
interested to know exactly how that works and how much difference it
makes.
It works by distributing content across end-nodes distributed throughout 
the infrastructure. I don't think Akamai make any secret of their 
architecture, so Google (:-) can help you there.
They definitely didn't make it a secret - they patented it. The gist of their 
approach was to put web caches all over the place and then have their DNS 
servers resolve based on where the request was coming from - when your browser 
asks their DNS server where whatever.akamai.com is, they try to respond with a 
web cache that is topologically close.

Of course it makes a huge difference, otherwise Google wouldn't have 
registered their domain name as a CNAME for an Akamai node set.
Yes and no - web caching can be very beneficial. Web caching with Akamai may or 
may not be worth the price; their business was originally centered around the 
idea that quality bandwidth is expensive - while still true to a degree, prices 
have fallen a ton in the last few years and continue to fall.

And who knows what sort of concessions they made to win the Google contract (not 
saying that's bad, just realize that Akamai would probably even take a loss on 
the Google contract because having Google as a customer makes people conclude 
that their service must make a huge difference ;-) ).

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


Re: IPython colors in windows

2005-02-04 Thread Claudio Grondi
Hi,

I have watched this thread hoping to get an
hint on my problem, but it seems I didn't.

My problem is, that the background of part of
the error messages is always black
(e.g. after typing In [1]: sdfsdf)
and my monitor failes to show the red, green
texts on black background clearly enough
to see it (I can read it after selection, which
inverts the colors).
I have tried to play with PyColorize.py,
LightBGColors = ColorScheme(
'LightBG',{
token.NUMBER : Colors.Cyan,
token.OP : Colors.Blue,
token.STRING : Colors.Blue,
tokenize.COMMENT : Colors.Red,
token.NAME   : Colors.White, # Colors.Black,
token.ERRORTOKEN : Colors.Red,

_KEYWORD : Colors.Green,
_TEXT: Colors.Blue,

'normal' : Colors.White # Colors.Normal  # color off (usu.
Colors.Normal)
}
but without success.
How can I get rid of the black background
---

exceptions.NameError Traceback (most
recent call last)
in with quotation marks marked areas?
Where is the color of the background of this
areas defined?
The color scheme seems to handle only the
text colors, not the background.

Claudio

Ashot [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 yea, I've done that. It must be something subtle, as the colors and tab
 completion works.
 On Thu, 03 Feb 2005 20:31:37 -0800, DogWalker [EMAIL PROTECTED]
wrote:

  Ashot [EMAIL PROTECTED] said:
 
  On 3 Feb 2005 19:18:33 -0800, James [EMAIL PROTECTED] wrote:
 
 
  Ashot wrote:
  I am using IPython in windows and the LightBG setting doesn't
  correctly
  because the background of the text is black even if the console
  background
  is white.  Anyone know whats going on?  Thanks.
 
  --
  ==
  Ashot Petrosian
  University of Texas at Austin, Computer Sciences
  (views expressed are solely my own)
  ==
 
  Did you try installing readline for windows?
  http://newcenturycomputers.net/projects/readline.html
 
 
  yea I've installed that and ctypes.  The color and tab completion work,
  its just that colored get displayed with black background, it almost
  works
  so its very frustrating..
 
 
  Did you try the following (from the manual)?:
 
  Input/Output prompts and exception tracebacks
 
 
  You can test whether the colored prompts and tracebacks work on your
  system interactively by typing '%colors Linux' at the prompt (use
  '%colors LightBG' if your terminal has a light background). If the input
  prompt shows garbage like:
  [0;32mIn [[1;32m1[0;32m]: [0;00m
   instead of (in color) something like:
   In [1]:
this means that your terminal doesn't properly handle color escape
  sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
 
 
You can try using a different terminal emulator program. To
  permanently set your color preferences, edit the file
  $HOME/.ipython/ipythonrc and set the colors option to the desired value.



 --
 ==
 Ashot Petrosian
 University of Texas at Austin, Computer Sciences
 (views expressed are solely my own)
 ==


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


Re: global variables

2005-02-04 Thread Nick Coghlan
A Steve wrote:
A Steve wrote:
A Steve wrote:
There we go, much clearer ;)
Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


regular expression match collection

2005-02-04 Thread [EMAIL PROTECTED]
Hello,

For example I have a string : Halo by by by
Then I want to take and know the possition of every by
how can I do it in python?

I tried to use:

  p = re.compile(rby)
  m = p.search(Helo by by by)
  print m.group() # result by
  print m.span()  # result (5,7)

How can I get the information of the other by ?

Sincerely Yours,
Pujo Aji

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


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Fredrik Lundh
Tim Daneliuk wrote:

 THis is why, IMHO, things like SOAP a laughable - RPC is a poor
 foundation for reliable, durable, and high-performance TP.  It might be
 fine for sending an order or invoice now and then, but sustained through-
 put of the sort I think of as high performance is likely never going to be
 accomplished with session-oriented architectures.

does 50 gigabytes per day, sustained, count as high performance in your book?

/F 



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


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Al Dykes
In article [EMAIL PROTECTED],
Tim Daneliuk  [EMAIL PROTECTED] wrote:
Paul Rubin wrote:

 Tim Daneliuk [EMAIL PROTECTED] writes:
 
I worked for an Airline computer reservation system (CRS) for almost a
decade. There is nothing about today's laptops that remotely comes close
to the power of those CRS systems, even the old ones. CRS systems are
optimized for extremely high performance I/O and use an operating system
(TPF) specifically designed for high-performance transaction processing.
 
 
 Yeah, I've been interested for a while in learning a little bit about
 how TPF worked.  Does Gray's book that you mention say much about it?

I honestly do not recall.  TPF/PAARS is an odd critter unto itself
that may not be covered by much of anything other than IBM docs.

I've seen it covered in some textbook, possibly something by Tanenbaum. 
I imagine it's in the ACM literature and the IBM Systems Journal.  

If we move this thread to alt.folklore.computers we'll get lots of
good info.

-- 

a d y k e s @ p a n i x . c o m 

Don't blame me. I voted for Gore.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: dynamic func. call

2005-02-04 Thread Tim Jarman
Aljosa Mohorovic wrote:

 can i do something like this:
 
 s = myFunction
 a = s() # equals to: a = myFunction()

Functions are first-class objects in Python, so you can do:

def myFunction():
# whatever

which creates a function object and binds the name myFunction to it. Then:

s = myFunction

just binds the name s to your function object, and therefore:

a = s()

is the same as:

a = myFunction()


-- 
Website: www DOT jarmania FULLSTOP com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice needed for simple python web app

2005-02-04 Thread Dan Perl

Paul Rubin http://[EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 If you're just trying to get a conceptual understanding of web
 programming, I suggest you start with cgi.

 Next you might want to read Philip and Alex's Guide to Web Publishing:

  http://philip.greenspun.com/panda/

 It's out of date and the examples use Tcl and Oracle instead of
 Python, but it's still a good explanation of how database-driven web
 sites work.  The rest (like languages frameworks) is just a matter of
 picking some implementation parameters.

This matches pretty much what I've decided to do.  I'll start with cgi and 
CGIHTTPServer because I'll learn more from that and then move to a 
framework, quite likely CherryPy, although by that time I may change my 
choice.  Philip Greenspun's book looks good and I'll have to go through it. 
Thanks for the advice. 


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


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Al Dykes
In article [EMAIL PROTECTED],
Dave Brueck  [EMAIL PROTECTED] wrote:
Paul Rubin wrote:
 How would you go about building such a site?  Is LAMP really the right
 approach?

Two major problems I've noticed, don't know if they are universal, but they 
sure 
hurt the performance:

1) Some sites have not put any thought into caching - i.e. the application 
server is serving up images or every single page is dynamically generated even 
though all (or most) of it is static such that most of the requests just 
aren't 
cacheable.

2) Because a database is there, it gets used, even when it shouldn't, and it 
often gets used poorly - bad or no connection pooling, many trips to the 
database for each page generated, no table indices, bizarro database schemas.

Overall I'd say my first guess is that too much is being generated on the fly, 
often because it's just easier not to worry about cacheability, but a good web 
cache can provide orders of magnitude improvement in performance, so it's 
worth 
some extra thought.

One project we had involved the users navigating through a big set of data, 
narrowing down the set by making choices about different variables. At any 
point 
it would display the choices that had been made, the remaining choices, and 
the 
top few hits in the data set. We initially thought all the pages would have to 
be dynamically generated, but then we realized that each page really 
represented 
a distinct and finite state, so we went ahead and built the site with Zope + 
Postgres, but made it so that the URLs were input to Zope and told what state 
to 
generate.

The upshot of all this is that we then just ran a web spider against Zope any 
time the data changed (once a week or so), and so the site ended up feeling 
pretty dynamic to a user but pretty much everything came straight out of a 
cache.

-Dave


A couple years ago the Tomshardware.com website was reengeneered to
cache everything possible with great performance improvement. They wrote 
a nice article about the project, which I assume is still online.  I don't

-- 

a d y k e s @ p a n i x . c o m 

Don't blame me. I voted for Gore.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Dave Brueck
Fredrik Lundh wrote:
Tim Daneliuk wrote:

THis is why, IMHO, things like SOAP a laughable - RPC is a poor
foundation for reliable, durable, and high-performance TP.  It might be
fine for sending an order or invoice now and then, but sustained through-
put of the sort I think of as high performance is likely never going to be
accomplished with session-oriented architectures.

does 50 gigabytes per day, sustained, count as high performance in your book?
In and of itself, no. But really, the number is meaningless in transaction 
processing without some idea of the size and content of the messages (i.e. if 
it's binary data that has to be base64 encoded just to make it work with SOAP) 
because what's most interesting is the number of transactions that can be handled.

If 50 GB/day is just a measurement of the throughput of the data transport 
layer, then that's fairly low - less than 5Mbps!

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


Re: regular expression match collection

2005-02-04 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote:

 For example I have a string : Halo by by by
 Then I want to take and know the possition of every by
 how can I do it in python?

 I tried to use:

  p = re.compile(rby)
  m = p.search(Helo by by by)
  print m.group() # result by
  print m.span()  # result (5,7)

 How can I get the information of the other by ?

 import re
 p = re.compile(by)
 for m in p.finditer(Helo by by by):
... print m.span()
...
(5, 7)
(8, 10)
(11, 13)

/F 



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


Re: making symlinks with distutils

2005-02-04 Thread TZOTZIOY
On 4 Feb 2005 04:01:25 -0800, rumours say that Michele Simionato
[EMAIL PROTECTED] might have written:

I guess I need to add a os.link(src, dst) somewhere in the
setup.py script or in a postinstallation script but I am not exactly
sure where.

Since you want to make a symbolic link, you probably want to use os.symlink()
and not os.link(), but that seems to be the least of your troubles.
-- 
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


Re: regular expression match collection

2005-02-04 Thread Steve Holden
[EMAIL PROTECTED] wrote:
Hello,
For example I have a string : Halo by by by
Then I want to take and know the possition of every by
how can I do it in python?
I tried to use:
  p = re.compile(rby)
  m = p.search(Helo by by by)
  print m.group() # result by
  print m.span()  # result (5,7)
How can I get the information of the other by ?
Sincerely Yours,
Pujo Aji
You need re.findall() (or, equivalently, the findall() method of an re).
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression match collection

2005-02-04 Thread P
[EMAIL PROTECTED] wrote:
Hello,
For example I have a string : Halo by by by
Then I want to take and know the possition of every by
how can I do it in python?
[ match.start() for match in p.finditer(Helo by by by) ]
see:
http://mail.python.org/pipermail/python-list/2004-December/255013.html
--
Pádraig Brady - http://www.pixelbeat.org
--
--
http://mail.python.org/mailman/listinfo/python-list


Re: regular expression match collection

2005-02-04 Thread [EMAIL PROTECTED]
Thanks you...

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


Re: mounting a filesystem?

2005-02-04 Thread Larry Bates
There is smbmount, but I don't know what type of
filesystem you are looking for.
http://redclay.altervista.org/
Larry Bates
Dan Stromberg wrote:
Is there a python module that can mount a filesystem?
More specifically, a loopback filesystem with a particular offset, under
linux?
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list


Re: bytecode obfuscation

2005-02-04 Thread Gabriel Cooper

snacktime wrote:
Also, I'm curious how much demand their is for this application in the
Python world.  The application replaces online credit card
processors(Verisign, Authorizenet) by providing a platform that
connects directly to the bank networks for credit card processing, and
also provides other features such as recurring billing, reporting,
etc..  Everything except the libraries that actually connect to the
bank networks would be open source, and those libraries aren't
something that you would even want to touch anyways.
 

Personally, I would avoid running any software that processed my users' 
credit cards that wasn't open source. Not to say I wouldn't use it, but 
it would have to come from a known-reliable source with their full 
backing to imply the security of their name. e.g. If it was a bytecode 
library downloadable directly from bankofamerica.com. The risk of 
devious programming is too high to bother. So I pay Verisign or 
Authorizenet one cent on the dollar. In exchange, my clients' identities 
aren't being stolen.

Hope this help,
Gabriel.
--
http://mail.python.org/mailman/listinfo/python-list


Re: test_socket.py failure

2005-02-04 Thread x2164
Nick Coghlan [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
   Marc, it is possible that there was a change between 
   glibc-2.2.4 and 2.2.5 that would account for the 
   difference in behaviour.  I think i'll write a little
   test program in C to check out getservbyname's return
   values in a little more controled environment.  I'll
   post the results tomorrow.

 The other question is which C library Python is actually
 using on your system. 
 Maybe it's picking up whatever installed the funky man page
 which doesn't 
 mention NULL proto arguments.

 So, find your Python 2.4 binary and run ldd python24 to
 see which shared C 
 library it is linking to.

 For me, it's /lib/tls/libc.so.6. Running that library directly
 prints out the 
 message about GNU C library 2.3.3.


 hey Nick,


 The man pages are probably from orignal system installation
 so i used your ldd technique which says that the python
 executable was compiled against glibc-2.2.5.

 I'm going to check the diff for 2.2.4-2.2.5 and look for
 anything getservbyname related.

 Below i'm including the source code for a little
 program to exercise getservbyname.  On this system
 if 'NULL' is passed as the protocal then 'NULL' is
 returned.

 I wonder if writing some code around the call to
 getservbyname in Modules/socketmodule.c to test
 for a call with the NULL argument would be
 appropriate.  Could you show the output from my
 included program when NULL is passed as
 an argument?  Probably would be good to know
 what the call returns on your system before
 trying to get mine to mimic it.


 Ok, back to grep'ing.


 pete jordan
 x2164 mailcity com






/*
 *This program just test what happens when getservbyname
 *is passed a NULL pointer argument for the name and proto
 *paramenters.
 * 
 *The compilation line i used:
 *
 *gcc getserv.c -o getserv
 *
 *and just type 'getserv' at a prompt.
 *
 *Just pass 'service name, protocol name' to
 *'get_print' to check if combination is found.
 */


#include stdio.h
#include netdb.h
#include netinet/in.h


void get_print( const char *, const char * );

int main()
{
get_print( daytime, tcp );
get_print( daytime, udp );
get_print( daytime, NULL );
get_print( NULL, tcp );
get_print( NULL, NULL );
get_print( ithkl, tcp );
get_print( echo, ddp );

return ;
}



void get_print( const char *name, const char *proto )
{
struct servent*result = NULL ;

result = getservbyname( name, proto );

printf( \n  getservbyname call:  getservbyname( %s , %s ) \n,
 name, proto ); 

printf(  getservbyname returned:\n);

if ( result == NULL )
   printf(\t\t\t   NULL - end of 'services' file reached or\n
  \t\t\t  error occured.\n\n);
   else
 {
   printf( \t\t\t   s_name = %s \n, result-s_name );
   printf( \t\t\t   s_port = %d \n, ntohs(result-s_port) );
   printf( \t\t\t   s_proto = %s \n, result-s_proto );
   printf( \n );
  }

}

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


Re: forms, xslt and python

2005-02-04 Thread Uche Ogbuji
Firstly, that isn't an XML file.  You're missing quotes around
attribute values.

Secondly, your question is very unclear.  Are you looking for an XSLT
way to correlate the correct_answer attribute to the alternative
element in corresponding order?  Are you looking for a Python means to
do this?


--
Uche OgbujiFourthought, Inc.
http://uche.ogbuji.nethttp://4Suite.orghttp://fourthought.com
Use CSS to display XML -
http://www.ibm.com/developerworks/edu/x-dw-x-xmlcss-i.html
Introducing the Amara XML Toolkit -
http://www.xml.com/pub/a/2005/01/19/amara.html
Be humble, not imperial (in design) -
http://www.adtmag.com/article.asp?id=10286Querying WordNet as XML -
http://www.ibm.com/developerworks/xml/library/x-think29.html
Manage XML collections with XAPI -
http://www-106.ibm.com/developerworks/xml/library/x-xapi.html
Default and error handling in XSLT lookup tables -
http://www.ibm.com/developerworks/xml/library/x-tiplook.html
Packaging XSLT lookup tables as EXSLT functions -
http://www.ibm.com/developerworks/xml/library/x-tiplook2.html

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


How to enable Python Scripts with MS IIS Web Server?

2005-02-04 Thread syed_saqib_ali



Hi. I have MS Windows Server 2003, Enterprise Edition.
It has MS Management Console 2.0, Version 5.2
and IIS Manager 6.0



I have a directory called myDirs. Within this directory are 2 files:
1) index.pl (a perl script)
2) index.py (a python script whose first line is
#!C:\Python21\pythonw.exe)

The webserver is listening on port 8080.

When I point my browser to http://localhost:8080/myDirs/index.pl, it
works... I see the output of the perl script.

HOWEVER,
When I point my browser to http://localhost:8080/myDirs/index.py, it
simply shows the python file as text. It doesn't interpret it at all.

How Can I get it to interpret the python file using the interpreter and
display the output in the browser?

Please explain each step in careful/excruciating detail because I'm a
windows Newbie.


-Saqib Ali

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


Re: exporting mesh from image data

2005-02-04 Thread John Hunter
 Fernando == Fernando Perez [EMAIL PROTECTED] writes:

Fernando I hope you posted this on the VTK list with a CC to
Fernando Prabhu as well...  The hopes of a positive reply there
Fernando are, I suspect, a fair bit higher.  The scipy list would
Fernando be a good idea, too.

Hey Fernando, 

I did get some help from Prabu off list.  The suggestion was to use a
vtkDelaunay3D to mesh the isosurface points into a volume, which
returns an unstructured grid, and then iterate over this structure to
get the volume, face, vertex and connectivity information out.  I've
implemented this and we're in the process of testing it with some
simple geometries.  If/when I get something tested and working, I'll
post it.

Thanks for the links,
JDH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Jack Diederich
On Thu, Feb 03, 2005 at 10:09:49PM -0800, Paul Rubin wrote:
 aurora [EMAIL PROTECTED] writes:
  I'm lost. So what do you compares against when you said LAMP is slow?
  What  is the reference point? Is it just a general observation that
  slashdot is  slower than we like it to be?
[reordered Paul's email a bit]

  If you mean MySQL or SQL database in general is slow, there are truth
  in  it. The best thing about SQL database is concurrent access,
  transactional  semantics and versatile querying. Turns out a lot of
  application can  really live without that. If you can rearchitect the
  application using  flat files instead of database it can often be a
  big bloom.
 
 This is the kind of answer I had in mind.

*ding*ding*ding*  The biggest mistake I've made most frequently is using
a database in applications.  YAGNI.  Using a database at all has it's
own overhead.  Using a database badly is deadly.  Most sites would
benefit from ripping out the database and doing something simpler.
Refactoring a database on a live system is a giant pain in the ass,
simpler file-based approaches make incremental updates easier.

The Wikipedia example has been thrown around, I haven't looked at the
code either;  except for search why would they need a database to
look up an individual WikiWord?  Going to the database requires reading
an index when pickle.load(open('words/W/WikiWord')) would seem sufficient.

 Yes, that's the basic observation, not specifically Slashdot but for
 lots of LAMP sites (some PHPBB sites are other examples) have the same
 behavior.  You send a url and the server has to grind for quite a
 while coming up with the page, even though it's pretty obvious what
 kinds of dynamic stuff it needs to find.  Just taking a naive approach
 with no databases but just doing everything with in-memory structures
 (better not ever crash!) would make me expect a radically faster site.
 For a site like Slashdot, which gets maybe 10 MB of comments a day,
 keeping them all in RAM isn't excessive.  (You'd also dump them
 serially to a log file, no seeking or index overhead as this happened.
 On server restart you'd just read the log file back into ram).

You're preaching to the choir, I don't use any of the fancy stuff in
Twisted but the single threaded nature means I can keep everything in
RAM and just serialize changes to disk (to survive a restart).
This allows you to do very naive things and pay no penalty. My homespun
blogging software isn't as full featured as Pybloxsom but it is a few 
hundred times(!) faster.  Pybloxsom pays a high price in file stats
because it allows running under CGI.  Mine would too as a CGI but it
isn't so *shrug*.

  A lot of these is just implementation. Find the right tool and the
  right design for the job. I still don't see a case that LAMP based
  solution is inherently slow.
 
 I don't mean LAMP is inherently slow, I just mean that a lot of
 existing LAMP sites are observably slow.

A lot of these are just implementation.  Going the dumb non-DB way won't
prevent you from making bad choices but if a lot of bad choices are made
simply because of the DB (my assertion) dropping the DB would avoid
some bad choices.  I think Sourceforge has one table for all project's
bugs  patches.  That means a never used project's bugs take up space
in the index and slow down access to the popular projects.  Would a
naive file-based implementation have been just as bad?  maybe.

If there is interest I'll follow up with some details on my own LAMP
software which does live reports on gigs of data and - you guessed it -
I regret it is database backed.  That story also involves why I started
using Python (the prototype was in PHP).

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


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Jeffrey Froman
M.E.Farmer wrote:

 Div is a block level tag and span isn't.
 You can also group them  together and nest them.

One caveat here -- I don't believe you can (should) nest a div inside a
span, or for that matter, nest any block-level element inside an inline
element.

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


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Jeffrey Froman
Paul Rubin wrote:

 I don't know that the browser necessarily renders that faster than it
 renders a table, but there's surely less crap in the HTML, which is
 always good.  I may start using that method.

Using tables for layout is also a cardinal faux pas if you care about
accessibility, as such tables can really mess up things like screenreader
software for the sight-impaired.

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


Re: IPython colors in windows

2005-02-04 Thread km
Hi all,

Have u tried Colors0.1 module from python.org ? 

KM

On Fri, Feb 04, 2005 at 07:21:29AM -0800, Fuzzyman wrote:
 Are you really using the readline module from newcenturycomputers ?
 I've got a feeling that's broken and you need to use the Gary Bishop
 one with IPython
 
 Sorry if this is spurious... (restricted internet access, so I can't
 check for you... but the correct one is linked to from the IPython
 site).
 
 Regards,
 
 Fuzzy
 http://www.voidspace.org.uk/python/index.shtml
 
 Claudio Grondi wrote:
  Hi,
 
  I have watched this thread hoping to get an
  hint on my problem, but it seems I didn't.
 
  My problem is, that the background of part of
  the error messages is always black
  (e.g. after typing In [1]: sdfsdf)
  and my monitor failes to show the red, green
  texts on black background clearly enough
  to see it (I can read it after selection, which
  inverts the colors).
  I have tried to play with PyColorize.py,
  LightBGColors = ColorScheme(
  'LightBG',{
  token.NUMBER : Colors.Cyan,
  token.OP : Colors.Blue,
  token.STRING : Colors.Blue,
  tokenize.COMMENT : Colors.Red,
  token.NAME   : Colors.White, # Colors.Black,
  token.ERRORTOKEN : Colors.Red,
 
  _KEYWORD : Colors.Green,
  _TEXT: Colors.Blue,
 
  'normal' : Colors.White # Colors.Normal  # color off
 (usu.
  Colors.Normal)
  }
  but without success.
  How can I get rid of the black background
 
 ---
  
  exceptions.NameError Traceback
 (most
  recent call last)
  in with quotation marks marked areas?
  Where is the color of the background of this
  areas defined?
  The color scheme seems to handle only the
  text colors, not the background.
 
  Claudio
 
  Ashot [EMAIL PROTECTED] schrieb im Newsbeitrag
  news:[EMAIL PROTECTED]
   yea, I've done that. It must be something subtle, as the colors and
 tab
   completion works.
   On Thu, 03 Feb 2005 20:31:37 -0800, DogWalker
 [EMAIL PROTECTED]
  wrote:
  
Ashot [EMAIL PROTECTED] said:
   
On 3 Feb 2005 19:18:33 -0800, James [EMAIL PROTECTED] wrote:
   
   
Ashot wrote:
I am using IPython in windows and the LightBG setting doesn't
correctly
because the background of the text is black even if the
 console
background
is white.  Anyone know whats going on?  Thanks.
   
--
==
Ashot Petrosian
University of Texas at Austin, Computer Sciences
(views expressed are solely my own)
==
   
Did you try installing readline for windows?
http://newcenturycomputers.net/projects/readline.html
   
   
yea I've installed that and ctypes.  The color and tab
 completion work,
its just that colored get displayed with black background, it
 almost
works
so its very frustrating..
   
   
Did you try the following (from the manual)?:
   
Input/Output prompts and exception tracebacks
   
   
You can test whether the colored prompts and tracebacks work on
 your
system interactively by typing '%colors Linux' at the prompt (use
'%colors LightBG' if your terminal has a light background). If
 the input
prompt shows garbage like:
[0;32mIn [[1;32m1[0;32m]: [0;00m
 instead of (in color) something like:
 In [1]:
  this means that your terminal doesn't properly handle color
 escape
sequences. You can go to a 'no color' mode by typing '%colors
 NoColor'.
   
   
  You can try using a different terminal emulator program. To
permanently set your color preferences, edit the file
$HOME/.ipython/ipythonrc and set the colors option to the desired
 value.
  
  
  
   --
   ==
   Ashot Petrosian
   University of Texas at Austin, Computer Sciences
   (views expressed are solely my own)
   ==
 
 -- 
 http://mail.python.org/mailman/listinfo/python-list

-- 

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


Thread in python

2005-02-04 Thread [EMAIL PROTECTED]
Hello, is any one knows websites which give a python thread tutorial ?

Sincerely Yours,
Pujo Aji

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


Re: Thread in python

2005-02-04 Thread Kartic
[EMAIL PROTECTED] wrote:
 Hello, is any one knows websites which give a python thread tutorial
?

 Sincerely Yours,
 Pujo Aji

Pujo Aji,

I have not come across a tutorial but found this link rather helpful -
http://www.faqts.com/knowledge_base/index.phtml/fid/263 - to get
started.

Also, there are good recipes in ASPN -
http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Threads

And last but not least, the chapter on Threads in Python Standard
Library by Fredrik Lundh - http://effbot.org/zone/books.htm

Thanks,
-Kartic

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


Re: ANN: Frog 1.3 released (python 'blog' application)

2005-02-04 Thread Jorey Bump
Irmen de Jong [EMAIL PROTECTED] wrote in news:41fcf53b
[EMAIL PROTECTED]:

 I've just uploaded the Frog 1.3 release.
 
 Frog is a blog (web log) system written in 100% Python.
 It is a web application written for Snakelets.
 It outputs XHTML, is fully unicode compatible, small,
 and doesn't require a database.
 
 Frog 1.3 uses the same storage format as 1.2 so no conversion
 is required. If you encounter bugs or problems, or want to give
 some feedback, please let me know.

Very nice. I downloaded the complete version and ran it within Cygwin 
without any problems, except that the simple file browser is not included. 
The Files link returns a 404 error.

Are there any plans to include a per user file manager? This would allow 
file management for a large user base, where ftp uploads would be 
impractical and unsafe. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Steve Holden
Jack Diederich wrote:
On Thu, Feb 03, 2005 at 10:09:49PM -0800, Paul Rubin wrote:
aurora [EMAIL PROTECTED] writes:
I'm lost. So what do you compares against when you said LAMP is slow?
What  is the reference point? Is it just a general observation that
slashdot is  slower than we like it to be?
[reordered Paul's email a bit]

If you mean MySQL or SQL database in general is slow, there are truth
in  it. The best thing about SQL database is concurrent access,
transactional  semantics and versatile querying. Turns out a lot of
application can  really live without that. If you can rearchitect the
application using  flat files instead of database it can often be a
big bloom.
This is the kind of answer I had in mind.

*ding*ding*ding*  The biggest mistake I've made most frequently is using
a database in applications.  YAGNI.  Using a database at all has it's
own overhead.  Using a database badly is deadly.  Most sites would
benefit from ripping out the database and doing something simpler.
Refactoring a database on a live system is a giant pain in the ass,
simpler file-based approaches make incremental updates easier.
The Wikipedia example has been thrown around, I haven't looked at the
code either;  except for search why would they need a database to
look up an individual WikiWord?  Going to the database requires reading
an index when pickle.load(open('words/W/WikiWord')) would seem sufficient.
[...]
I don't mean LAMP is inherently slow, I just mean that a lot of
existing LAMP sites are observably slow.

A lot of these are just implementation.  Going the dumb non-DB way won't
prevent you from making bad choices but if a lot of bad choices are made
simply because of the DB (my assertion) dropping the DB would avoid
some bad choices.  I think Sourceforge has one table for all project's
bugs  patches.  That means a never used project's bugs take up space
in the index and slow down access to the popular projects.  Would a
naive file-based implementation have been just as bad?  maybe.
If there is interest I'll follow up with some details on my own LAMP
software which does live reports on gigs of data and - you guessed it -
I regret it is database backed.  That story also involves why I started
using Python (the prototype was in PHP).
Having said all this, I'd happily campaign for a relational backend to 
MoinMoin if it would speed up the execrably slow performance we 
currently see on the python.org wiki. I haven't investigated why 
response times went up so much, but I have a distinct feeling it's to do 
with a new release.

regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Thread in python

2005-02-04 Thread Steve Holden
Kartic wrote:
[EMAIL PROTECTED] wrote:
Hello, is any one knows websites which give a python thread tutorial
?
Sincerely Yours,
Pujo Aji

Pujo Aji,
I have not come across a tutorial but found this link rather helpful -
http://www.faqts.com/knowledge_base/index.phtml/fid/263 - to get
started.
Also, there are good recipes in ASPN -
http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Threads
And last but not least, the chapter on Threads in Python Standard
Library by Fredrik Lundh - http://effbot.org/zone/books.htm
Thanks,
-Kartic
http://starship.python.net/crew/aahz/OSCON2001/index.html
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Python CGI -- ASP Request

2005-02-04 Thread crystal1
This question may be simple, so please bear with me.
We have a mainly ASP VBScript website running on IIS. I've installed 
Python and created a CGI form which takes text input and produces a 
string of URLs. The CGI page works fine.

Currently, when submitting the form the user is redirected to the CGI 
file's embedded html page. I would like for the user to submit the form 
and be brought back to the originating VB/ASP page with the 
%=Request(RESULT)% tag filled in with the links generated in the CGI 
form.

This seems so simple, but I can't think of an alternative to a 
non-manual form submission in the CGI, or an ugly and slow redirect 
page...

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


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Paul Rubin
Kartic [EMAIL PROTECTED] writes:
  Hmm, I wasn't aware that Apache 2.x gave any significant speedups
  over 1.3 except under Windows.  Am I missing something?
 
 Architectural differences. Apache 1.3 spawns a new process for every
 request and before you know, it brings your resources to their knees. 

Oh but it doesn't spawn new processes like that, at least if it's
configured correctly.  It uses pre-forking, which means it spawns a
bunch of processes when you first start it running, and those
processes persist and serve requests (up to N simultaneously, where N
is the no. of processes).  Sort of like a traditional DB connection
pool.

 The CSS way is using div placement of the elements. Actually div
 gives better control over placement than with HTML tables. And with
 CSS, since you style the various HTML tags, you can create different
 skins for your site too. This is definitely OT, like you said, but
 if you are interested, please contact me directly. I don't pretend to
 be a CSS expert but I can help you as much as I can.

I have some interest in this but I should probably just read up on it,
if it's what everyone is doing these days.  Clearly I'm behind the
times about this stuff.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: advice needed for simple python web app

2005-02-04 Thread Paul Rubin
Dan Perl [EMAIL PROTECTED] writes:
 This matches pretty much what I've decided to do.  I'll start with cgi and 
 CGIHTTPServer because I'll learn more from that and then move to a 
 framework, quite likely CherryPy, although by that time I may change my 
 choice.  Philip Greenspun's book looks good and I'll have to go through it. 
 Thanks for the advice. 

You might also look at the docs for HTML::Mason (www.masonhq.com) to
get a look at a reasonably mature template system, even if you don't
plan to use it (because it's in Perl and not Python).  I'm not sure if
CherryPy is directly comparable.  I haven't yet used any of the Python
template systems.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Computing class variable on demand?

2005-02-04 Thread Steven Bethard
fortepianissimo wrote:
Thank you so much about this useful tip! I learned the new decorator
feature of 2.4 simply because of your post.
Unfortunately I don't have luxury right now to run Python 2.4 (for what
I'm doing anyways). You mentioned the way to do decorator in 2.3. Still
I have a question here. Here is Scott David Daniels's code for lazy
initialization:
class Lazy (object):
def __init__ (self, calculate_function):
self._calculate = calculate_function
def __get__ (self, obj, _=None):
if obj is None:
return self
value = self._calculate(obj)
setattr(obj, self._calculate.func_name, value)
return value
The problem I run into using this for *instance* variables is: the
setattr() call won't work with a class with __slots__ defined - it
simply produces error that the attribute we want to modify is
read-only. Is there a workaround of this problem?
Sounds like you're declaring the class variables in your __slots__ too. 
 Is this true?  I don't think that's necessary -- __slots__ is only for 
used for instances.  So, for example, this code should work okay:

py class Foo(object):
... __slots__ = ['baz']
... class __metaclass__(type):
... def bar(self):
... print 'slow initialization'
... return 'apple'
... bar = LazyAttribute(bar)
... def __init__(self, baz):
... self.baz = baz
...
py f = Foo(1)
py f.baz
1
py f.bar
Traceback (most recent call last):
  File interactive input, line 1, in ?
AttributeError: 'Foo' object has no attribute 'bar'
py f.__class__.bar
slow initialization
'apple'
py Foo.bar
'apple'
Note that if you want to reference the class variable, you have to 
specficially go through the class, instead of counting on the instance 
lookup as classes without __slots__ can.  But as long as you don't 
declare 'bar' as a slot, you should still be able to access Foo.bar.

Note that you probably don't want to have 'bar' as both a class variable 
and an instance variable -- then the instance variable will just hide 
the class variable...

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


Re: dynamic func. call

2005-02-04 Thread [EMAIL PROTECTED]
Try this:

def myfunc():
  print helo

s = myfunc()
a = eval(s)

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


Re: Learning Python for a new beginner

2005-02-04 Thread Piet
Hi Lisa,
 I hear that Python is one of the easiest languages to learn. It is
 easier than PHP or Pearl?
Most people think so, though personal experiences can vary. I played
around wit hPerl for some time but never got really far. Python, on
the other hand, attracted me from the first minute.
Don´t be fooled: Learning and mastering Python requires work and
brains, but that is the price you have to pay anyways. It helps you to
develop at your personal pace from beginner to advanced, and it does
so without throwing completely new constructs in your brain every day.
It comes bundled with some built-in tools for writing, editing and
running programs, good and user-friendly documentation (which appears
to be better organized than Perl´s doc), and a lot of built-in
functions to handle data structures and files in an easily tractable,
easily remembered way. By learning Python, you will also learn some
advanced concepts (if you want) that could help you to understand the
basics of more advanced languages like C++ and Java. Combine that with
fine community support and a lot of free third-party modules (you
won´t need all of them on your first day, but it is nice to know that
they are out there), and I would say that you have all you need in the
best way you can get to start your programming career.


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


MDaemon Warning - virus found: Returned mail: Data format error

2005-02-04 Thread Automatic Email Delivery Software

*** WARNING **
Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado 
un fichero anexo(s) infectado(s).  Por favor revise el reporte de abajo.

AttachmentVirus name   Action taken
--
tis.zip   Email-Worm.Win32.Mydoom.m Removed


**


The original message was received at Fri, 4 Feb 2005 18:30:02 +0100
from python.org [222.131.140.165]

- The following addresses had permanent fatal errors -
python-list@python.org

- Transcript of session follows -
... while talking to mail server 90.160.46.39:
 DATA
 400-aturner; %MAIL-E-OPENOUT, error opening !AS as output
 400-aturner; -RMS-E-CRE, ACP file create failed
 400

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

Re: IPython colors in windows

2005-02-04 Thread Claudio Grondi
I use this one,
http://heanet.dl.sourceforge.net/sourceforge/uncpythontools/readline-1.7.win
32.exe
which I assume is the right one.

Any other ideas?

Claudio

Fuzzyman [EMAIL PROTECTED] schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
 Are you really using the readline module from newcenturycomputers ?
 I've got a feeling that's broken and you need to use the Gary Bishop
 one with IPython

 Sorry if this is spurious... (restricted internet access, so I can't
 check for you... but the correct one is linked to from the IPython
 site).


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


Re: returning True, False or None

2005-02-04 Thread Alex Martelli
Steven Bethard [EMAIL PROTECTED] wrote:

 I have lists containing values that are all either True, False or None,
 e.g.:
 
  [True,  None,  None,  False]
  [None,  False, False, None ]
  [False, True,  True,  True ]
  etc.
 
 For a given list:
 * If all values are None, the function should return None.
 * If at least one value is True, the function should return True.
 * Otherwise, the function should return False.
 
 Right now, my code looks like:
 
  if True in lst:
  return True
  elif False in lst:
  return False
  else:
  return None
 
 This has a light code smell for me though -- can anyone see a simpler
 way of writing this?

What about...:

for val in lst:
if val is not None:
return val
return None

or the somewhat fancy/clever:

for val in (x for x in lst if x is not None):
return val
return None


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


Re: returning True, False or None

2005-02-04 Thread Raymond Hettinger
Steven Bethard
 For a given list:
 * If all values are None, the function should return None.
 * If at least one value is True, the function should return True.
 * Otherwise, the function should return False.
 . . .
 Right now, my code looks like:

  if True in lst:
  return True
  elif False in lst:
  return False
  else:
  return None

 This has a light code smell for me though -- can anyone see a simpler
 way of writing this?


return max(lst)


Raymond Hettinger


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


Re: returning True, False or None

2005-02-04 Thread Jeremy Bowers
On Fri, 04 Feb 2005 10:48:44 -0700, Steven Bethard wrote:

 I have lists containing values that are all either True, False or None, 
 e.g.:
 
  [True,  None,  None,  False]
  [None,  False, False, None ]
  [False, True,  True,  True ]
  etc.
 
 For a given list:
 * If all values are None, the function should return None.
 * If at least one value is True, the function should return True.
 * Otherwise, the function should return False.
 
 Right now, my code looks like:
 
  if True in lst:
  return True
  elif False in lst:
  return False
  else:
  return None

Yes, I see the smell, you are searching the list multiple times. You
could bail out when you can:

seenFalse = False
for item in list:
if item: return True
if item is False: seenFalse = True
if seenFalse:
return False
return None

But I'd submit that if four item lists are your common case, that your
original code is significantly easier to understand what it is doing. This
can be alleviated with an appropriate comment on the chunk of code I gave
you, though.

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


Re: Collapsing a list into a list of changes

2005-02-04 Thread Alan McIntyre
Your first example is along the lines of what I was thinking when I said 
elegant.  :)   I was looking for something that I could drop into one 
or two lines of code; I may not do that if I'm writing code that will 
have to be maintained, but it's still nice to know how to do it.

Thanks :)
Alan
Steven Bethard wrote:
Well, this does about the same thing, but using enumerate and a list 
comprehension:

py lst = [0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5]
py [item for i, item in enumerate(lst) if i == 0 or item != lst[i-1]]
[0, 1, 2, 3, 2, 4, 5]
Similar code that doesn't check 'if i == 0' each time through:
py itr = enumerate(lst)
py itr.next()
(0, 0)
py [lst[0]] + [item for i, item in itr if item != lst[i-1]]
[0, 1, 2, 3, 2, 4, 5]
I don't know if either of these is really more elegant though...
Steve
--
http://mail.python.org/mailman/listinfo/python-list


(no subject)

2005-02-04 Thread Dan Smyth




Hey,

I'm trying to compile a version of Python on an SGI 
machine that is running IRIX 6.5. When I run the configure option for 
version 2.4 I get this error:


configure: WARNING: stropts.h: present but cannot 
be compiledconfigure: WARNING: stropts.h: check for 
missing prerequisite headers?configure: WARNING: stropts.h: see the Autoconf 
documentationconfigure: WARNING: stropts.h: section 
"Present But Cannot Be Compiled"configure: WARNING: stropts.h: proceeding 
with the preprocessor's resultconfigure: WARNING: stropts.h: in the future, 
the compiler will take precedenceconfigure: WARNING: 
## - ##configure: 
WARNING: ## Report this to the python lists. 
##configure: WARNING: ## 
- ##
and when I run the configure option for version 
2.3.4 I get this same error plus this additional one:

configure: WARNING: stropts.h: present but cannot 
be compiledconfigure: WARNING: stropts.h: check for missing prerequisite 
headers?configure: WARNING: stropts.h: proceeding with the preprocessor's 
resultconfigure: WARNING: ## 
 ##configure: 
WARNING: ## Report this to [EMAIL PROTECTED]. ##configure: 
WARNING: ##  
##

Do you know what is happening here? 
Thanks.

Dan Smyth
Brigham Young University

Dan Gaidin -- Tai Shar Phoenix"Dovie'andi se 
tovya sagain"
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Collapsing a list into a list of changes

2005-02-04 Thread Steven Bethard
Alan McIntyre wrote:
Hi all,
I have a list of items that has contiguous repetitions of values, but 
the number and location of the repetitions is not important, so I just 
need to strip them out.  For example, if my original list is 
[0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5], I want to end up with [0,1,2,3,2,4,5].

Here is the way I'm doing this now:
def straightforward_collapse(myList):
collapsed = [myList[0]]
for n in myList[1:]:
if n != collapsed[-1]:
collapsed.append(n)
return collapsed
Is there an elegant way to do this, or should I just stick with the code 
above?
Here's a solution that works for iterables other than lists:
py def collapse(iterable):
... enumeration = enumerate(iterable)
... _, lastitem = enumeration.next()
... yield lastitem
... for i, item in enumeration:
... if item != lastitem:
... yield item
... lastitem = item
...
py lst = [0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5]
py list(collapse(lst))
[0, 1, 2, 3, 2, 4, 5]
Again, I'm still not sure I'd call this more elegant...
STeVe
--
http://mail.python.org/mailman/listinfo/python-list


Re: returning True, False or None

2005-02-04 Thread Steve Holden
Steven Bethard wrote:
I have lists containing values that are all either True, False or None, 
e.g.:

[True,  None,  None,  False]
[None,  False, False, None ]
[False, True,  True,  True ]
etc.
For a given list:
* If all values are None, the function should return None.
* If at least one value is True, the function should return True.
* Otherwise, the function should return False.
Right now, my code looks like:
if True in lst:
return True
elif False in lst:
return False
else:
return None
This has a light code smell for me though -- can anyone see a simpler 
way of writing this?

STeVe
That code looks like a pretty solid implementation of the spec to me. 
There isn't a strict need for the last else, of course, which may be the 
smell you detect.

If you wanted to get clever you could write something like
for i in True, False:
  if i in lst:
return i
return False
but frankly I think that's more obscure, and saves you pretty much nothing.
regards
 Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005  http://www.pycon.org/
Steve Holden   http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: returning True, False or None

2005-02-04 Thread Michael Spencer
Steven Bethard wrote:
I have lists containing values that are all either True, False or None, 
e.g.:

[True,  None,  None,  False]
[None,  False, False, None ]
[False, True,  True,  True ]
etc.
For a given list:
* If all values are None, the function should return None.
* If at least one value is True, the function should return True.
* Otherwise, the function should return False.
Right now, my code looks like:
if True in lst:
return True
elif False in lst:
return False
else:
return None
This has a light code smell for me though -- can anyone see a simpler 
way of writing this?

STeVe
max(lst)  ;-)
Michael
--
http://mail.python.org/mailman/listinfo/python-list


Re: returning True, False or None

2005-02-04 Thread Steve Juranich
 This has a light code smell for me though -- can anyone see a simpler 
 way of writing this?

How's about:

def ntf(x, y):
 if x is None and y is None: return None
 if x == True or y == True: return True
 return False
# Then...
reduce(ntf, list of stuff)

You might need to make sure that you initialize your reduce call the
right way with the optional third argument.

HTH

-- 
Stephen W. Juranich
Science Applications Intl. Corp. (SAIC)
Tucson, AZ
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Collapsing a list into a list of changes

2005-02-04 Thread Alan McIntyre
I think you're right; sometimes I'm susceptible to the I can do that in 
one line of code temptation. :)

Since this current bit of code will probably end up in something that's 
going to be maintained, I will probably stick with the straightforward 
method just to be nice to the maintainer (especially if it's me!).

Jeremy Bowers wrote:
I think that's pretty elegant; I read it and immediately understood what
you were doing. There may be some performance tweaks you could make if you
were doing this to large lists, and my instincts say to re-write it as an
iterator if you use it a lot like:
for item in collapse(yourList):
but other than that which may not even apply, straightforward is
generally a *good* thing, don't you think? :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: advice needed for simple python web app

2005-02-04 Thread Jeff Reavis
You might also want to try out Spyce.
http://spyce.sourceforge.net/index.html

It works in proxy mode, with mod_python, or even as cgi.

Some examples:
http://spyce.sourceforge.net/eg.html

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


Re: returning True, False or None

2005-02-04 Thread Steven Bethard
Raymond Hettinger wrote:
Steven Bethard
For a given list:
* If all values are None, the function should return None.
* If at least one value is True, the function should return True.
* Otherwise, the function should return False.
 . . .
Right now, my code looks like:
if True in lst:
return True
elif False in lst:
return False
else:
return None
This has a light code smell for me though -- can anyone see a simpler
way of writing this?

return max(lst)
Very clever!  Thanks!
Steve
--
http://mail.python.org/mailman/listinfo/python-list


Re: OT: why are LAMP sites slow?

2005-02-04 Thread Maciej Mróz
Kartic wrote:
Paul Rubin said the following on 2/3/2005 7:20 PM:
LAMP = Linux/Apache/MySQL/P{ython,erl,HP}.  Refers to the general
class of database-backed web sites built using those components.  This
being c.l.py, if you want, you can limit your interest to the case the
P stands for Python.
I notice that lots of the medium-largish sites (from hobbyist BBS's to
sites like Slashdot, Wikipedia, etc.)  built using this approach are
painfully slow even using seriously powerful server hardware.  Yet
compared to a really large site like Ebay or Hotmail (to say nothing
of Google), the traffic levels on those sites is just chickenfeed.
If you are talking about Wikipedia as a prime example, I agree with you 
that it is *painfully* slow.

And the reason for that I probably because of the way the language is 
used (PHP) (this is a shot in the dark as I have not looked into 
Mediawiki code), and compounded by probably an unoptimized database. I 
don't want to start flame wars here about PHP; I use PHP to build client 
sites and like it for the easy building of dynamic sites but the 
downside is that there is no memory...every page is compiled each time 
a request is made. I doubt if Wikipedia site uses an optimizer (like 
Zend) or caching mechanisms. Optimizers and/or PHP caches make a huge 
performance difference.
Mmcache (which is both optimizer and shared memory caching library for 
php) can do _miracles_. One of my company servers uses Apache 
1.3/php/mmcache to serve about 100 GB of dynamic content a day (it could 
do more but website does not have enough visitors to stress it :) ).
There's also memcached, much more of interest to readers of this list - 
iirc it has Python API.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Collapsing a list into a list of changes

2005-02-04 Thread Alan McIntyre
Jack,
I'm not using 2.4 yet; still back in 2.3x. :)  Thanks for the examples, 
though - they are clear enough that I will probably use them when I upgrade.

Thanks,
Alan
Jack Diederich wrote:
If you are using python2.4,

import itertools as it
[x[0] for (x) in it.groupby([0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5])]
[0, 1, 2, 3, 2, 4, 5]
Since this is 2.4 you could also return a generator expression.

def iter_collapse(myList):
...   return (x[0] for (x) in it.groupby([0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5]))
... 

i = iter_collapse([0,0,1,1,1,2,2,3,3,3,2,2,2,4,4,4,5])
i
generator object at 0xb7df6b2c
list(i)
[0, 1, 2, 3, 2, 4, 5]

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


Converting strings to dates

2005-02-04 Thread Chermside, Michael
I'm trying to convert a string back into a datetime.date.

First I'll create the string:


Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on
win32
Type help, copyright, credits or license for more information.
 import time, datetime
 a_date = datetime.date.today()
 s = str(a_date)
 print s
2005-02-04

Now I convert it back:

 new_date = datetime.date.fromtimestamp(
... time.mktime(time.strptime(s, '%Y-%m-%d')))
 new_date
datetime.date(2005, 2, 4)


WOW, that's ugly. Is there a more concise way to do this?

-- Michael Chermside


This email may contain confidential or privileged information. If you believe 
you have received the message in error, please notify the sender and delete the 
message without copying or disclosing it.

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


Re: returning True, False or None

2005-02-04 Thread Mick Krippendorf
Steven Bethard wrote:
 I have lists containing values that are all either True, False or
 None, e.g.:
 
  [True,  None,  None,  False]
  [None,  False, False, None ]
  [False, True,  True,  True ]
  etc.
 
 For a given list:
 * If all values are None, the function should return None.
 * If at least one value is True, the function should return True.
 * Otherwise, the function should return False.

Try:

  max(lst)

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


Re: returning True, False or None

2005-02-04 Thread Brian van den Broek
Alex Martelli said unto the world upon 2005-02-04 13:02:
Steven Bethard [EMAIL PROTECTED] wrote:

I have lists containing values that are all either True, False or None,
e.g.:
[True,  None,  None,  False]
[None,  False, False, None ]
[False, True,  True,  True ]
etc.
For a given list:
* If all values are None, the function should return None.
* If at least one value is True, the function should return True.
* Otherwise, the function should return False.
Right now, my code looks like:
SNIP OP's code
This has a light code smell for me though -- can anyone see a simpler
way of writing this?

What about...:
for val in lst:
if val is not None:
return val
return None
or the somewhat fancy/clever:
for val in (x for x in lst if x is not None):
return val
return None
Alex
These don't do what the OP desired.
. test_case = [False, True,  True,  True ]
. def alexs_funct(lst):
.for val in lst:
.if val is not None:
.return val
.return None
 alexs_funct(test_case)
False
But, by the 'spec', it ought return True.
Best,
Brian vdB
A mere newbie, quite pleased with himself for finding a problem with 
'bot code -- next scheduled to occur mid 2011 :-)

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


Persistence design [was: RE: OT: why are LAMP sites slow?]

2005-02-04 Thread Robert Brewer
Jack Diederich wrote:
 *ding*ding*ding*  The biggest mistake I've made most 
 frequently is using
 a database in applications.  YAGNI.  Using a database at all has it's
 own overhead.  Using a database badly is deadly.  Most sites would
 benefit from ripping out the database and doing something simpler.
 Refactoring a database on a live system is a giant pain in the ass,
 simpler file-based approaches make incremental updates easier.
 
 The Wikipedia example has been thrown around, I haven't looked at the
 code either;  except for search why would they need a database to
 look up an individual WikiWord?  Going to the database 
 requires reading
 an index when pickle.load(open('words/W/WikiWord')) would 
 seem sufficient.
 
...
 
 If there is interest I'll follow up with some details on my own LAMP
 software which does live reports on gigs of data and - you 
 guessed it -
 I regret it is database backed.  That story also involves why 
 I started
 using Python (the prototype was in PHP).

I'd be interested, if only selfishly to hear more potential use cases
for *my* projects. ;)

One of my goals for Dejavu* (my ORM) is to abstract persistence to the
point that you can easily test your actual, live dataset against many
potential storage mechanisms (i.e. multiple DB's, but also shelve,
etc.). I need to finish the migration tools, but it's well on the way.


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]

* http://www.aminus.org/rbre/python
--
http://mail.python.org/mailman/listinfo/python-list


bicyclerepairman python24 windows idle :(

2005-02-04 Thread EuGeNe
Hi there,
I am no expert but wanted to give bicyclerepairman 0.9 a go just to see 
what a refactoring browser is and does. Followed every step of the 
install, I think, but idle doesn't start with the RepairMan section in 
config-extensions.def ... is it incompatible with 2.4?

Thanks for your help.
--
EuGeNe
[
www.boardkulture.com
www.actiphot.com
www.xsbar.com
]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting strings to dates

2005-02-04 Thread Kartic
py  import time
py date_str = time.strftime('%Y-%m-%d', time.localtime())
py date_str
'2005-02-04'
py time.strptime(date_str, '%Y-%m-%d')
(2005, 2, 4, 0, 0, 0, 4, 35, -1)

That work?

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


Re: advice needed for simple python web app

2005-02-04 Thread Ant

 You might also look at the docs for HTML::Mason (www.masonhq.com) to
 get a look at a reasonably mature template system, even if you don't
 plan to use it (because it's in Perl and not Python).  I'm not sure
if
 CherryPy is directly comparable.  I haven't yet used any of the
Python
 template systems.

Mason is available for python

http://www.myghty.org/

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


Re: Thread in python

2005-02-04 Thread Aahz
In article [EMAIL PROTECTED],
Steve Holden  [EMAIL PROTECTED] wrote:

http://starship.python.net/crew/aahz/OSCON2001/index.html

Thanks!  But while that's still good (for the code, if nothing else), it
ought to be at least supplemented with
http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code -- 
not in reams of trivial code that bores the reader to death.  --GvR
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >