Databases and python

2006-02-16 Thread Dan Stromberg

I've been putting a little bit of time into a file indexing engine in
python, which you can find here:
http://dcs.nac.uci.edu/~strombrg/pyindex.html

It'll do 40,000 mail messages of varying lengths pretty well now, but I
want more :)

So far, I've been taking the approach of using a single-table database
like gdbm or dbhash (actually a small number of them, to map filenames to
numbers, numbers to filenames, words to numbers, numbers to words,
and numbered words to numbered filenames), and making each entry keyed by
a word, and under the word in the database is a null terminated list of
filenames (in http://dcs.nac.uci.edu/~strombrg/base255.html representation).

However, despite using http://dcs.nac.uci.edu/~strombrg/cachedb.html module
to make the database use faster, bringing in psyco, and studying various
python optimization pages, the program just isn't performing like I'd like
it to.

And I think it's because despite the caching and minimal representation
conversion, it's still just too slow converting linear lists to arrays
back and forth and back and forth.

So this leads me to wonder - is there a python database interface that
would allow me to define a -lot- of tables?  Like, each word becomes a
table, and then the fields in that table are just the filenames that
contained that word.  That way adding filenames to a word shouldn't bog
down much at all.

-But-, are there any database interfaces for python that aren't going to
get a bit upset if you try to give them hundreds of thousands of tables?

Thanks!

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


How to run shell commands within python

2006-02-16 Thread fileexit
How can I execute shell commands from within python.  Specifically, I
am looking for something like the shell "cat".  But this also made me
wonder how to execute shell commands anyway, just if i needed to do
that in the future.

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


text encodings -> subprocess.Popen or -> labelmarkup (pygtk)

2006-02-16 Thread calmar
Hi all,

first of all, I have to say I have hardly no knowledge about that
issue.

on the program there, I have it like that:


,---
| obj = unicode(newcomment, 'utf-8')
| newcomment = obj.encode('latin-1')
|
| pipe = subprocess.Popen(tot, stdout=subprocess.PIPE,\
|stderr=subprocess.PIPE, shell=False)
`---

that seems to work with that construction above.

Then I think, 'what' kind of encoding I can send to an external program,
depends also on that program? Or on the environment? If, then how could
I get that environemnt? (the programs runs also under MS windows)

Well, maybe someone has some hints about encodings issues like that, and
what I can send to external commands?

thanks a lot
calmar



-- 
  calmar

  (o_  It rocks: LINUX + Command-Line-Interface
  //\
  V_/_ http://www.calmar.ws
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to run shell commands within python

2006-02-16 Thread Fredrik Lundh
"fileexit" wrote:

> thanks... i was to hasty to post this question, i found a good answer
> here:
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/ffdab847125f81b6

that's an old thread, and Python has grown a few more ways to
deal with shell commands since then.  if os.system isn't good en-
ough for you, subprocess is the preferred alternative:

http://www.python.org/doc/lib/module-subprocess.html

(also note that most trivial shell commands are better done in
python.  most uses of cat, for example, can be trivially emulated
with one or two lines of python...)





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


Re: How to run shell commands within python

2006-02-16 Thread Juho Schultz
fileexit wrote:
> How can I execute shell commands from within python.  Specifically, I
> am looking for something like the shell "cat".  But this also made me
> wonder how to execute shell commands anyway, just if i needed to do
> that in the future.
> 
You can use os.system() for that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pop line from file

2006-02-16 Thread Sinan Nalkaya
i am unix platform, now searching for the mkfifo topics.
thank you all.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Poisson Distribution (for a newbie)

2006-02-16 Thread Jeremy Sanders
[EMAIL PROTECTED] wrote:

> I want to mimic such kind of distribution using poison traffic ( a bell
> shaped curve). I looked into wikipedia and some other tutorials but I
> wasn't sure how many parameter does the above kind of distribution
> would require.

I've used numarray's poisson distribution generator, which was very useful.
There may well be something similar in NumPy/Numeric/SciPy.

e.g.

from numarray.random_array import poisson

for i in xrange(100):
 print poisson(10)

Where 10 is the mean.

Jeremy

-- 
Jeremy Sanders
http://www.jeremysanders.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text encodings -> subprocess.Popen or -> labelmarkup (pygtk)

2006-02-16 Thread Fredrik Lundh
"calmar" wrote:

> Then I think, 'what' kind of encoding I can send to an external program,
> depends also on that program?

the encoding is a mapping between raw bytes and their actual meaning,
and a program usually only sees the bytes, so it's entirely up to the pro-
gram to interpret what you send to it.

many programs defaults to the system's "global" default encoding for text
input; you can use the "getpreferredencoding" function in the locale module
to figure out what it is set to:

http://docs.python.org/lib/module-locale.html





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


Re: web crawler in python or C?

2006-02-16 Thread Fuzzyman

abhinav wrote:
> It is DSL broadband 128kbps.But thats not the point.What i am saying is
> that would python be fine for implementing fast crawler algorithms or
> should i use C.

But a web crawler is going to be *mainly* I/O bound - so language
efficiency won't be the main issue. There are several web crawler
implemented in Python.

> Handling huge data,multithreading,file
> handling,heuristics for ranking,and maintaining huge data
> structures.What should be the language so as not to compromise that
> much on speed.What is the performance of python based crawlers vs C
> based crawlers.Should I use both the languages(partly C and python).How

If your data processing requirements are fairly heavy you will
*probably* get a speed advantage coding them in C and accessing them
from Python.

The usdual advice (which seems to be applicable to you), is to
prototype in Python (which will be much more fun than in C) then test.

Profile to find your real bottlenecks (if the Python one isn't fast
enough - which it may be), and move your bottlenecks to C.

All the best,

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

> should i decide what part to be implemented in C and what should be
> done in python?
> Please guide me.Thanks.

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


Re: How to run shell commands within python

2006-02-16 Thread Szabolcs Nagy
use subprocess module

from subprocess import call
call(['cmd', 'arg1', 'arg2'], stdin='...', stdout='...')
eg:
call(['ls', '-l'])

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


Re: Encryption

2006-02-16 Thread Robert J. Hansen
Honestly, the best thing you can do when it comes to writing crypto
code is _not_ write crypto code.  It's far better to instead use
pre-existing, trusted, scrutinized, audited code.  You'll probably be
better served looking for a Python interface to OpenSSL, which will
provide you with all the algorithms you'll want and then some.

pyopenssl might be what you're looking for, it might not.  I've never
used it, but that looks like the place to start.

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


Re: HTTP & tcl

2006-02-16 Thread Fuzzyman

alf wrote:
> Hi
>
> I would like to convert the wctpXml-1.3.py program to Tcl (line by
> line).
> See http://sourceforge.net/project/showfiles.php?group_id=29217
> This program sends pages using WCTP.  I know nothing about Python or
> XML but this program is small and seems straightforward and I am sure
> that I will be able to figure it out - with a little help ;-)
> Currently I am stuck in not being able to identify the Tcl equivalent
> of Python's "putrequest", as in:
> h = httplib.HTTP("wctp.skytel.com",80)
> h.putrequest("POST","/wctp")
>

You'll get more help on Tcl syntax in a Tcl group. :-)

Of the HTTP object, the Python documentation says :

The HTTP class is retained only for backward compatibility with 1.5.2.
It should not be used in new code. Refer to the online docstrings for
usage.

(Meaning that you will find more help on the use of that module in the
source code - which can also be accessed through Python's pydoc
feature).


I assume it does what the newer ``HTTPConnection`` class does. The
putrequest method does the following :

putrequest( request, selector[, skip_host[, skip_accept_encoding]])

This should be the first call after the connection to the server has
been made. It sends a line to the server consisting of the request
string, the selector string, and the HTTP version (HTTP/1.1). To
disable automatic sending of Host: or Accept-Encoding: headers (for
example to accept additional content encodings), specify skip_host or
skip_accept_encoding with non-False values. Changed in version 2.4:
skip_accept_encoding argument added.

In other words - you're creating an HTTP connection and request. You'll
need to find an 'equivalent' library for Tcl and convert the request
using hte semantics of whatever library you choose.


All the best,

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

> Thanks
> alf

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


Re: %SystemDrive%

2006-02-16 Thread Atanas Banov
Bryan Olson wrote:
> To get it with the \, you might use:
>
>  os.path.abspath(os.environ['SYSTEMDRIVE'])

wrong!
the result is incorrect if the current directory is different from the
root.

>>> os.chdir("c:\\winxp")
>>> os.path.abspath(os.environ['SYSTEMDRIVE'])
'c:\\winxp'

if you really want it with backslash at the end, why not just add it

os.environ['SYSTEMDRIVE'] + '\\'

is it too simple?!

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


Job advert: Your help needed

2006-02-16 Thread Paul Boots
Hi All,

I hope you guys don't mind me posting this to the list, but ...

We are looking for a programmer on a very short term to help us write
a relative simple, yet very specialised, command line application for 
our post production pipeline for a  television show shot in HD (dpx 
files) using Viper cameras.

The program needs to do the following:

- take 3 argument: an EDL and two directories, source and destination.
- based on the edit decisions it should look in the source directory
   and find the corresponding dpx files based on the timecode information
   contained in the dpx  header and copy those files to the destionation
   directory
- the program must create a log file that shows which timecodes could
   not be resolved as well as the edit decision that contained that
   timecode.

There are allready parts of code that could be used to create the
application, which are python code to handle edl and c code that handles
reading the dpx files.  This code can only be used when you are willing
to travel to our location (Iceland).

You (the programmer) should understand film/television  postproduction. 
When you are willing to travel there is a good change we have more 
application that you can build for us.

When you are interested, or know someone who might be, please contact
me directly for further information and to discuss business details.

Best regards,

Paul Boots
[EMAIL PROTECTED]
+354 664 1748
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Databases and python

2006-02-16 Thread Rene Pijlman
Dan Stromberg:
>is there a python database interface that would allow me to define a 
>-lot- of tables?  Like, each word becomes a table, and then the fields 
>in that table are just the filenames that contained that word.

Give ZODB a try. 
http://www.zope.org/Wikis/ZODB/FrontPage
http://www.python.org/workshops/2000-01/proceedings/papers/fulton/zodb3.html

My first attempt would be: a BTree with the word as key, and a 'list of
filenames' as value.
http://www.zope.org/Wikis/ZODB/FrontPage/guide/node6.html#SECTION00063

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


Re: Databases and python

2006-02-16 Thread bruno at modulix
Jonathan Gardner wrote:
> I'm no expert in BDBs, but I have spent a fair amount of time working
> with PostgreSQL and Oracle. It sounds like you need to put some
> optimization into your algorithm and data representation.
> 
> I would do pretty much like you are doing, except I would only have the
> following relations:
> 
> - word to word ID
> - filename to filename ID
> - word ID to filename ID
> 
> You're going to want an index on pretty much every column in this
> database. 

stop !

I'm not a db expert neither, but putting indexes everywhere is well
known DB antipattern. An index is only useful if the indexed field is
discriminant enough (ie: there must be the less possible records having
the same value for this field). Else, the indexed lookup may end up
taking far more time than a simple linear lookup.  Also, indexes slow
down write operations.

> That's because you're going to lookup by any one of these
> columns for the corresponding value.
> 
> I said I wasn't an expert in BDBs. But I do have some experience
> building up large databases. In the first stage, you just accumulate
> the data. Then you build the indexes only as you need them.

Yes. And only where it makes sens.

(snip)

> And your idea of hundreds of thousands of tables? Very bad. Don't do
> it.

+100 on this


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


Re: PyXML SAX Q?

2006-02-16 Thread Alan Kennedy
[EMAIL PROTECTED]
> is it possible to use SAX to parse XML that is not in a file but in a
> large string?
> If I open my XML file and read the content into a string variable. Is
> there a way I can pass it to the PyXML Sax handler?
> The reason I want to know is that I need to parse XML that is generated
> by a process on a Unix system. I can connect to the process via a
> socket and the the XML but I need to store the XML somewhere before I
> can parse it.
> I could dump it to a file first and then hand it to the parser but that
> seems unefficient.
>
> Maybe I could read the XML from the socket directly into the parser.

You can find exactly what you need in this old thread about incremental
XML parsing.

Parsing XML streams
http://groups.google.com/group/comp.lang.python/msg/e97309244914343b?

--
alan kennedy
--
email alan:  http://xhaus.com/contact/alan

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


Re: Unexpected behaviour of getattr(obj, __dict__)

2006-02-16 Thread Christos Georgiou
On Tue, 14 Feb 2006 22:24:12 -0500, rumours say that "Terry Reedy"
<[EMAIL PROTECTED]> might have written:

> id(Parrot.f) == id(Parrot.f)
>> True
> id(Parrot.__dict__) == id(Parrot.__dict__)
>> True
>
>A wrapper is created and passed to id() which returns an int object while 
>releasing the wrapper back to the free list.  Then another wrapper is 
>created in the same chunk of memory and passed to id, which returns an int 
>of the same value for comparison.  The language ref only guarantees 
>uniqueness of ids at any particular instant and allows reuse of ids of 
>deallocated objects.
>
>I half seriously think the lib ref entry for id() should have a warning 
>that naive use can mislead.

Actually, you more-or-less just wrote what could (I also think should) be
included in the docs.
-- 
TZOTZIOY, I speak England very best.
"Dear Paul,
please stop spamming us."
The Corinthians
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: FreeImagePy 1.2.2

2006-02-16 Thread Michele Petrazzo
FreeImagePy 1.2.2 is available at freeimagepy.sf.net

What is?
   It' a python wrapper for FreeImage, Open Source library for developers
who would like to support popular graphics image formats.

How work?
   It use a binary freeimage library present on the system and ctypes.

Major changes from 1.2.0:
  New convertToPil function:
   i = FreeImagePy.Image("myImage.ext")
   pil = i.convetToPil()
  Some bugs solved

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


Re: multi/double dispatch, multifunctions once again

2006-02-16 Thread bruno at modulix
AndyL wrote:
> Hi,
(OT : please repeat the question in the body of the post...)

> Where I can find a module supporting that?

http://peak.telecommunity.com/DevCenter/PyConGenericFunctions

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


pymssql and date format

2006-02-16 Thread eight02645999
hi
i am using pymmsql to query a date column in MSSQL database table.
However the result shows for example
(datetime.datetime(2006, 2, 16, 17, 50, 19) which is supposed to be
2006-02-16 17:50:19.000
anyway to correct query a date column using pymssql so that it gives
the correct date format? thanks

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


Re: multiple inheritance

2006-02-16 Thread Thomas Girod
thanks, you pointed exactly on what distrurbed me. I'll see what I can
do with cooperative methods.

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


Re: web crawler in python or C?

2006-02-16 Thread Paul Rubin
"abhinav" <[EMAIL PROTECTED]> writes:
> It is DSL broadband 128kbps.But thats not the point.

But it is the point.

> What i am saying is that would python be fine for implementing fast
> crawler algorithms or should i use C.Handling huge
> data,multithreading,file handling,heuristics for ranking,and
> maintaining huge data structures.What should be the language so as
> not to compromise that much on speed.What is the performance of
> python based crawlers vs C based crawlers.Should I use both the
> languages(partly C and python).How should i decide what part to be
> implemented in C and what should be done in python?  Please guide
> me.Thanks.

I think if you don't know how to answer these questions for yourself,
you're not ready to take on projects of that complexity.  My advice
is start in Python since development will be much easier.  If and when
you start hitting performance problems, you'll have to examine many
combinations of tactics for dealing with them, and switching languages
is just one such tactic.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: apache mod_python problem

2006-02-16 Thread Ido Yehieli
Hi Graham, thank you for that link but it didn't help.
I've followed the instructions, yet In the 'basic-content-handler'
section, after getting to the point where it says to add this to the
main Apache configuration file:


AllowOverride FileInfo


I replaced /some/directory with the correct directory and restarted
apache2 and stilll get the same response - firwfox asks to save the
response to a file. Does it matter where in the apache2 configuration
file I've located these 3 lines? I've just added them at the end, just
before the last line: 

Thank you in advance,
Ido.

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


Re: any ftpd written in python?

2006-02-16 Thread garabik-news-2005-05
Kenneth Xie <[EMAIL PROTECTED]> wrote:
> I need a simple ftpd example in pure python. Is there already such a 
> ftpd available?
> Thank you very much in advance.

self-advertising: http://melkor.dnp.fmph.uniba.sk/~garabik/pyftpd.html
it is a bit dated and I do not develop it anymore, but as a base of your
own server software it can be quite good.

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

Extend/embedd python problem?

2006-02-16 Thread Mile Blenton

Hello all,

I am considering python as a 'scripting' language to be used
in my application where users must be able to write their own 
code to access application data, use the application mechanisms
to gather various data and basicly must be able to control the 
application itself.

Currently, to accomplish this task, my app uses my custom C-like 
language and my bytecode interpreter. In this case I am able to 
control the execution of a single 'instruction' in my interpreter
and interpret the user code when I want. It also enables me to support 
multiple 'user tasks' (not a system LWP-like tasks, but a higher-level
concurrent execution simulation - each task has it's own interpreter 
and each interpreter is executed every n-th iteration for example). 

I have glanced at the python/C api ref manual and know I can
use the 'PyRun_InteractiveOne' to execute a single python 
statement, but am not sure if there's a way to 'precompile'
python code and prepare it for execution so I can interpret
the precompiled statements one-by-one, similarly to my custom
interpreter.

I noticed the 'Py_CompileString' but am not sure what to do and 
how to interact with 'PyObject*' it returns me - how do I run it, 
can I interrupt it when it's executing, can I run it on 
per-statement basis'?

Any help or pointers where to look for answers to my questions is
grately apreciated.

Thanks,
Regards,
  Mario


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


Re: apache mod_python problem

2006-02-16 Thread Ido Yehieli
please ignore that last message, the instructions on that webpage
worked, it was my fault.

Thanks,
Ido.

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


Re: Excel and TrackChanges

2006-02-16 Thread pierre_py
If i move the Save after the HighlightChangesOptions it will popup a
message saying it can only be used when workbook is saved.

The problem is actually not only in python, i figured out that the
samples in msdn (which do the same) don't work in VBA also (if i give
my macros a shortcut).

I have now fixed-it with ApplyAllChanges(), which gives me thing i need
(i need the track changes just to create a log file of whats
happening).

thanks

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


Re: Embedding an Application in a Web browser

2006-02-16 Thread paron
>From the OP:
As for the application it has to be able display simple animated
graphics such as circles, lines and squares. However if someone clicks
on a shape it should open up another application, such as Word. Thanks,

Rod

Python Newbie 

The application itself can sit on the local
users computer, rather than actually being downloaded via the web. It
will be retrieving data from a variety of sources.

I was thinking that the security provisions might make it difficult for
the script in the browser to interact with the OS. If that is "simple"
to get around, then I agree, Karrigell is overkill.

OTOH, Karrigell makes it simple to interact with the local machine's
OS, and especially if you are a beginner at Python. YMMV, of course.
Thanks for offering your opinion.

Ron

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


MySQL

2006-02-16 Thread rodmc
I need to write a Python application which connects to a MySQL 5.0
database. Can anyone point me in the right direction or a compatible
library?

Best,

rod

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


Re: MySQL

2006-02-16 Thread Wolfram Kraus
rodmc wrote:
> I need to write a Python application which connects to a MySQL 5.0
> database. Can anyone point me in the right direction or a compatible
> library?
> 
> Best,
> 
> rod
> 

See http://sourceforge.net/projects/mysql-python


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


Visual Report Editor

2006-02-16 Thread Pawel
Hello,
I plan to make Visual Reporting Editior, a new product for
corporate-class systems. Data will be in XML and in my application,
designer should be able to make fascinating templates of reports. I
will use Python and MSVS 2005 Pro. My question is, which libaries will
be useful in my job. I plan to buy Qt and make visual layer of
application using Qt. I'm making businessplan soI have to decide which
tool will be useful. Is Qt best choice, maybe I should buy something
different?

Pawel

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


Re: web crawler in python or C?

2006-02-16 Thread gene tani

Paul Rubin wrote:
> "abhinav" <[EMAIL PROTECTED]> writes:

> > maintaining huge data structures.What should be the language so as
> > not to compromise that much on speed.What is the performance of
> > python based crawlers vs C based crawlers.Should I use both the
> > languages(partly C and python).How should i decide what part to be
> > implemented in C and what should be done in python?  Please guide
> > me.Thanks.
>
> I think if you don't know how to answer these questions for yourself,
> you're not ready to take on projects of that complexity.  My advice
> is start in Python since development will be much easier.  If and when
> you start hitting performance problems, you'll have to examine many
> combinations of tactics for dealing with them, and switching languages
> is just one such tactic.

There's another potential bottleneck, parsing HTML and extracting the
text you want, especially when you hit pages that don't meet HTML 4 or
XHTML spec.
http://sig.levillage.org/?p=599

Paul's advice is very sound, given what little info you've provided.

http://trific.ath.cx/resources/python/optimization/
(and look at psyco, pyrex, boost, Swig, Ctypes for bridging C and
python, you have a lot of options.  Also look at Harvestman, mechanize,
other existing libs.

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


Re: Databases and python

2006-02-16 Thread Bryan Olson
Dan Stromberg wrote:
> I've been putting a little bit of time into a file indexing engine
[...]

> So far, I've been taking the approach of using a single-table database
> like gdbm or dbhash [...] and making each entry keyed by
> a word, and under the word in the database is a null terminated list of
> filenames (in http://dcs.nac.uci.edu/~strombrg/base255.html representation).
> 
[...]
> the program just isn't performing like I'd like it to.
 >
> And I think it's because despite the caching and minimal representation
> conversion, it's still just too slow converting linear lists to arrays
> back and forth and back and forth.

I think I follow. The straightforward method of building the
list of files associated with a word is order n**2 time. On each
new entry, you look up the entire string, append one file-id to
it, and write the new version back.

> So this leads me to wonder - is there a python database interface that
> would allow me to define a -lot- of tables?  Like, each word becomes a
> table, and then the fields in that table are just the filenames that
> contained that word.  That way adding filenames to a word shouldn't bog
> down much at all.

Well, you could use simple files instead of fancy database tables.

Below is a demo of an alternate technique that uses bsddb B-Trees,
and puts both the word and the file-id in the key. I don't know
how efficient it is for real data, but at least the time won't grow
as Theta(n**2).

--Bryan



import bsddb
import urllib


def add_words_from_file(index, fname, word_iterator):
 """ Pass the open-for-write bsddb B-Tree, a filename, and a list
 (or any interable) of the words in the file.
 """
 fname = urllib.quote_plus(fname)
 s = set()
 for word in word_iterator:
 if word not in s:
 s.update(word)
 key = '%s %s' % (urllib.quote_plus(word), fname)
 index[key] = ''
 index.sync()


def lookup(index, word):
 """ Pass the B-Tree (as built with add_words_from_file) and a
 word to look up. Returns list of files containing the word.
 """
 word = urllib.quote_plus(word)
 fname_list = []
 try:
 current = index.set_location(word)
 while True:
 (key, _) = current
 (w, fname) = key.split()
 if w != word:
 break
 fname_list.append(urllib.unquote_plus(fname))
 current = index.next()
 except KeyError:
 pass
 return fname_list


def test():
 index = bsddb.btopen('junktest.bdb', 'n')
 data =[
 ('bryfile.txt', 'nor heed the rumble of a distant drum'),
 ('junkfile.txt', 'this is the beast, the beast so sly'),
 ('word file.txt', 'is this the way it always is here in Baltimore')
 ]
 for (fname, text) in data:
 words = text.split()
 add_words_from_file(index, fname, words)

 for word in ['is', 'the', 'heed', 'this', 'way']:
 print '"%s" is in files: %s' % (word, lookup(index, word))

test()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: web crawler in python or C?

2006-02-16 Thread gene tani

abhinav wrote:
> Hi guys.I have to implement a topical crawler as a part of my
> project.What language should i implement

Oh, and there's some really good books out there, besides the Orilly
Spidering Hacks.  Springer Verlag has a couple books on "Text Mining"
and at least a couple books with "web intelligence" in the title.
Expensive but worth it.

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


Re: Visual Report Editor

2006-02-16 Thread Diez B. Roggisch
Pawel wrote:

> Hello,
> I plan to make Visual Reporting Editior, a new product for
> corporate-class systems. Data will be in XML and in my application,
> designer should be able to make fascinating templates of reports. I
> will use Python and MSVS 2005 Pro. My question is, which libaries will
> be useful in my job. I plan to buy Qt and make visual layer of
> application using Qt. I'm making businessplan soI have to decide which
> tool will be useful. Is Qt best choice, maybe I should buy something
> different?

If you do have the money, Qt is what you want to get. I've been
cross-OS-developing with it for Win, Linux and MacOs and it never let me
down. Even if you don't need cross-platform, the toolchain alone together
with the really good design are worth it.

Currently the move to Qt4 in the PyQt community is done, you might consider
waiting until that is reasonably stable or go for the early snapshots and
then buy stuff when its released.

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


OT- wxPython mailing list problems

2006-02-16 Thread Franz Steinhaeusler
Sorry about asking here, 
but has anyone experienced, that no 
message can be sent to the mailing list?

Neither with Gmane, nor with Google mail.

I always get this reply:

from [EMAIL PROTECTED]

"""
Hi. This is the qmail-send program at sunsite.dk.
I'm afraid I wasn't able to deliver your message to the following
addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<[EMAIL PROTECTED]>:
ezmlm-reject: fatal: List address must be in To: or Cc: (#5.7.0)


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


Re: Embedding an Application in a Web browser

2006-02-16 Thread Paul Boddie
Atanas Banov wrote:
> paron wrote:
> > I forgot -- I like the idea of Kerrigell, too. It runs on top of
> > CherryPy, and lets you use python either in the server (which is just a
> > little program on your local machine) or embedded in the html pages, or
> > in a Kerrigell service, which is an application server based on Python.
>
> oh sure, why make it simple, when we can make it difficult?!

I don't see how running a local Web application server is more
difficult than messing around with ActiveX and/or Active Scripting (or
whatever it's called). Remember that Python already has various HTTP
server classes in the standard library, and making use of these classes
is very easy. I'd rather do that than touch ActiveX with a very long
stick, and the Active Scripting stuff, whilst amusing, is a known
security concern.

> your solution is like using a sledgehammer to crack a nut!
>
> "... I keep hearing the sound of nuts being pulverized..."
> http://www.bobcongdon.net/blog/2005/11/java-sledgehammer.html

Why am I not surprised that the first three words of the quoted blog
article are "David Heinemeier Hansson"? Few people contributing to
comp.lang.python would suggest J2EE as a solution here, so I don't
quite see what relevance this particular hype echo from the blogosphere
has in this case, especially since running BaseHTTPServer isn't exactly
like running JBoss.

Sure, to have animated graphics is likely to stretch any Web-based
interface, despite recent support for things like SVG and
"destandardised" innovations like canvases in Web browsers. But if
cross-platform portability ever becomes an issue, the vanilla Web
application option is quite possibly the best route; whilst one can
embed Python in Konqueror with the right packages today, and whilst
support for Python scripting in Mozilla is coming along, it'll be a
long time before any piece of Python code will be able to run on more
than one of these configurations without modification. And beyond
Active Scripting, who can really be sure what Internet Explorer will
eventually support?

Paul

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


Re: any ftpd written in python?

2006-02-16 Thread Jean-Paul Calderone
On Thu, 16 Feb 2006 14:07:55 +0800, Kenneth Xie <[EMAIL PROTECTED]> wrote:
>I need a simple ftpd example in pure python. Is there already such a
>ftpd available?
>Thank you very much in advance.

Twisted includes an FTP server:

  [EMAIL PROTECTED]:~$ mkdir a a/b a/c a/d
  [EMAIL PROTECTED]:~$ mktap ftp --root a
  [EMAIL PROTECTED]:~$ twistd -f ftp.tap 
  [EMAIL PROTECTED]:~$ ftp localhost 2121
  Connected to kunai.
  220 Twisted SVN-Trunk FTP Server
  Name (localhost:exarkun): anonymous
  331 Guest login ok, type your email address as password.
  Password:
  230 Anonymous login ok, access restrictions apply.
  Remote system type is UNIX.
  Using binary mode to transfer files.
  ftp> ls
  200 PORT OK
  125 Data connection already open, starting transfer
  drwxr-xr-x   2 exarkun   exarkun  4096 Feb 16 14:15 b
  drwxr-xr-x   2 exarkun   exarkun  4096 Feb 16 14:15 c
  drwxr-xr-x   2 exarkun   exarkun  4096 Feb 16 14:15 d
  226 Transfer Complete.
  ftp> quit
  221 Goodbye.

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


Re: Visual Report Editor

2006-02-16 Thread Michele Petrazzo
Pawel wrote:
> Hello,

Hi Pawel,

> I plan to make Visual Reporting Editior, a new product for 
> corporate-class systems. Data will be in XML and in my application, 
> designer should be able to make fascinating templates of reports. I 
> will use Python and MSVS 2005 Pro.

What are MSVS 2005 Pro ?

> My question is, which libaries will be useful in my job. I plan to
> buy Qt and make visual layer of application using Qt. I'm making
> businessplan soI have to decide which tool will be useful. Is Qt best
> choice, maybe I should buy something different?

Qt has a "strange" license for a graphical toolkit, it is release under
GPL/commercial license, so if you want to include your new Reporting
Editior into a commercial product, you have to pay a license for it.
Different thing is if you use wx or gtk, that has other, more
"permissive" licenses.

I (my company), for our project, has create a "Reporting Editior" based
on wx, following the pySketch tool, but now has about all the code
rewrite. It has some little problems with the auto-resizeable objects
(text only for now), that, into the engine that should compose the page,
not are displayed correctly.

On the other hand has a lot of worker functions, like:
- model-view framework
- object-like develop, so it's simple to add new drawing objects

- xml read and save
- multi-page size (A4, A3, etc...)
- multi-block (head, title, text [more that one], food, end)
- align-resize object
- infinite undo-redo
- image support
- multi-layer (9 layers)
- text block wrap, align right/left/center vertically/horrizontally
- more other...

Now I haven't the mind and the time for solve the problems, but if you
want to complete it, or help me to do it, I'll send you the code, so
after we'll a new -open source (do you like wxWidgets license? [LGPL] )-
*Visual Reporting Editior*

> 
> Pawel
> 

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


mod_python help!

2006-02-16 Thread treelife
I'm getting and internal server error when | run the following
mod_python script.  I am actually trying to run Django.

Script:

from mod_python import apache

def handler(req):
req.content_type = 'text/plain'
req.write("Under Construction")
return apache.OK

Here is some other relevant info.  Hope this is not too much:

Debian 3.x/python2.3.5/mod_python3.1.3/Apache2.0.54

from the command line test:

>>> import  mod_python.psp

Traceback ( most recent call last ):
   File "", line 1,in ?
  File "/usr/lib/python2.3/site-packages/mod_python/psp.py",line20, in
?
import apache,Session,util,-psp

File "/usr/lib/python2.3/site-packages/mod_python/apache.py,line28,in ?
import _apache

ImportError: No Module named _apache

...

Virtual Server Configuration

NameVirtualHost *


ServerName www.wyah-webs.com
ServerAlias wyah-webs.com  *.wyah-webs.com
DocumentRoot /var/www/wyah-webs
ServerAdmin [EMAIL PROTECTED]


Options FollowSymLinks
AllowOverride None

DirectoryIndex index.html mptest.py

AddHandler  mod_python .py
PythonHandler mptest
PythonDebug On



   
   SetHandler mod_python
   PythonHandler django.core.handlers.modpython
   SetEnv DJANGO_SETTINGS_MODULE ard_proj.settings
   PythonDebug On
   

   
   SetHandler none
   

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/

AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all


ErrorLog /var/log/apache2/www.wyah-webs.com_error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog /var/log/apache2/www.wyah-webs.com_access.log combined
ServerSignature On
#Alias /doc/ "/usr/share/doc/"
#
#Options Indexes MultiViews FollowSymLinks
#AllowOverride None
#Order deny,allow
#Deny from all
#Allow from 127.0.0.0/255.0.0.0 ::1/128
#


...
main server configuration

# Based upon the NCSA server configuration files originally by Rob
McCool.
# Changed extensively for the Debian package by Daniel Stone
<[EMAIL PROTECTED]>
# and also by Thom May <[EMAIL PROTECTED]>.

# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the LockFile documentation
# (available at
http://www.apache.org/docs/mod/core.html#lockfile>);
# you will save yourself a lot of trouble.

ServerRoot "/etc/apache2"

# The LockFile directive sets the path to the lockfile used when Apache
# is compiled with either USE_FCNTL_SERIALIZED_ACCEPT or
# USE_FLOCK_SERIALIZED_ACCEPT. This directive should normally be left
at
# its default value. The main reason for changing it is if the logs
# directory is NFS mounted, since the lockfile MUST BE STORED ON A
LOCAL
# DISK. The PID of the main server process is automatically appended to
# the filename.

LockFile /var/lock/apache2/accept.lock

# PidFile: The file in which the server should record its process
# identification number when it starts.

PidFile /var/run/apache2.pid

# Timeout: The number of seconds before receives and sends time out.

Timeout 300

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.

KeepAlive On

# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited
amount.
# We recommend you leave this number high, for maximum performance.

MaxKeepAliveRequests 100

# KeepAliveTimeout: Number of seconds to wait for the next request from
the
# same client on the same connection.

KeepAliveTimeout 15

##
## Server-Pool Size Regulation (MPM specific)
##

# prefork MPM
# StartServers . number of server processes to start
# MinSpareServers .. minimum number of server processes which are
kept spare
# MaxSpareServers .. maximum number of server processes which are
kept spare
# MaxClients ... maximum number of server processes allowed to
start
# MaxRequestsPerChild .. maximum number of requests a server process
serves

StartServers 5
MinSpareServers  5
MaxSpareServers 10
MaxClients  20
MaxRequestsPerChild  0


# pthread MPM
# StartServers . initial  number of server processes to start
# MaxClients ... maximum  number of server processes allowed to
start
# MinSpareThreads .. minimum  number of worker threads which 

Re: ANN: FreeImagePy 1.2.2

2006-02-16 Thread Claudio Grondi
Michele Petrazzo wrote:
> FreeImagePy 1.2.2 is available at freeimagepy.sf.net
> 
> What is?
>   It' a python wrapper for FreeImage, Open Source library for developers
>who would like to support popular graphics image formats.
> 
> How work?
>   It use a binary freeimage library present on the system and ctypes.
> 
> Major changes from 1.2.0:
>  New convertToPil function:
>   i = FreeImagePy.Image("myImage.ext")
>   pil = i.convetToPil()
>  Some bugs solved
> 
> Michele Petrazzo

Knowing some details about PIL and as good as no details about 
FreeImage, I would like in this context to become enlightened by the 
answer to the question, when does it make sense to use FreeImage instead 
of PIL?
 From what I know up to now I can't see any use for FreeImage :-( .

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


Re: web crawler in python or C?

2006-02-16 Thread Andrew Gwozdziewycz
On 15 Feb 2006 21:56:52 -0800, abhinav <[EMAIL PROTECTED]> wrote:
> Hi guys.I have to implement a topical crawler as a part of my
> project.What language should i implement
> C or Python?

Why does this keep coming up on here as of late? If you search the
archives, you can find numerous posts about spiders. One interesting
fact is that google itself starting with their spiders in python.
http://www-db.stanford.edu/~backrub/google.html I'm _sure_ it'll work
for you.



--
Andrew Gwozdziewycz <[EMAIL PROTECTED]>
http://ihadagreatview.org
http://plasticandroid.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: FreeImagePy 1.2.2

2006-02-16 Thread Andrew Gwozdziewycz
> Knowing some details about PIL and as good as no details about
> FreeImage, I would like in this context to become enlightened by the
> answer to the question, when does it make sense to use FreeImage instead
> of PIL?
>  From what I know up to now I can't see any use for FreeImage :-( .

both freeimagepy and freeimage are released under the GPL, PIL is not.

--
Andrew Gwozdziewycz <[EMAIL PROTECTED]>
http://ihadagreatview.org
http://plasticandroid.org
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANN] pyqonsole-0.2.0

2006-02-16 Thread Alexandre Fayolle
Logilab has released pyqonsole-0.2.0

Pyqonsole is a X Window terminal written in Python. The code is based
on konsole, and it uses the Qt toolkit. It is mainly meant for use by
Python application developpers who would like to embed a terminal in
their application, but it can be used as a not blazingly fast XTerm
replacement.

Download: http://www.logilab.org/projects/pyqonsole
Mailing List: http://www.logilab.org/mailinglists/python_projects

-- 
Alexandre Fayolle  LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Retrait du projet de loi DADVSI: http://eucd.info/petitions/index.php?petition=2


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

looping over more than one list

2006-02-16 Thread Iain King
When I loop over one list I use:

for item in items:
print item

but often I want to loop through two lists at once, and I've been doing
this like I would in any other language - creating an index counter and
incrementing it.
For example, (completely arbitrary), I have two strings of the same
length, and I want to return a string which, at each character
position, has the letter closest to 'A' from each of the original
strings:

def lowest(s1,s2):
s = ""
for i in xrange(len(s1)):
s += lowerChar(s1[i],s2[i])
return s

this seems unpythonic, compared to something like:

def lowest(s1,s2):
s = ""
for c1,c2 in s1,s2:
s += lowerChar(c1,c2)
return s

this doesn't work - s1,s2 becomes a tuple.  Is there a way to do this
that I'm missing?  I don't see it in the docs.

This works:

def lowest(s1,s2):
s = ""
for c1,c2 in [x for x in zip(s1,s2)]:
s += lowerChar(c1,c2)
return s

but it's hardly any more elegant than using a loop counter, and I'm
guessing it's performance is a lot worse - I assume that the zip
operation is extra work?

Iain

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


Some general questions about using "stdin","stdout"....

2006-02-16 Thread asdsd sir
Hi!I'm new in Python and i'd like to ask some general questions about 
stdin,stdout...

Firstly...

if we type like something like :
   cat "file.txt"|python somefile.py

#somefile.py
import sys
 text=sys.stdin.read()


...then "sys.stdin.read()" will read from "cat"s stdout...
However,if i type inside a program,something like

#someprog.py
import sys
   print "hello"|sys.stdin.read()

.the screen hangs..why is that?isn't the same situation as "cat"?

in addition to this...
Why can't i "write" to the stdin?
Isn't it being used as a file object like all the others?
for example
sys.stdin.close() or
open('sys.stdin','w+') or
sys.stdin.write("something") etc... don't work...

At last,let's consider "sys.stdin.read(3)"
If i type that,the program "waits" for me to type some characters,and then 
prints the first three...
However,doesn't this action actually include a "writing" to stdin and  then 
a "reading" from that?

I'm really confused...
Any help would be highly appreciated...
Thanks a lot.

_
Free blogging with MSN Spaces  http://spaces.msn.com/?mkt=nl-be

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


Re: Win32_Process.Create -- not starting process

2006-02-16 Thread abcd
Tim,
I am skipping using the batch file and only executing the python
script directly...and so far it works fine.

So now I have:
pid, retVal =
wmi.WMI("1.2.3.4").new("Win32_Process").Create(CommandLine="c:\python\python.exe
c:\some_script.py")

Thanks again...not sure why when using the batch file to start it
wouldnt always work, but as long is it works now!

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


Re: Visual Report Editor

2006-02-16 Thread Paul McNett
Pawel wrote:
> I plan to make Visual Reporting Editior, a new product for
> corporate-class systems. Data will be in XML and in my application,
> designer should be able to make fascinating templates of reports. I
> will use Python and MSVS 2005 Pro. My question is, which libaries will
> be useful in my job. I plan to buy Qt and make visual layer of
> application using Qt. I'm making businessplan soI have to decide which
> tool will be useful. Is Qt best choice, maybe I should buy something
> different?

Before you go to all that work, please take a look at the Dabo Report 
Designer, which uses wxPython for the UI and ReportLab for the PDF 
generation.

There's a 23-minute screencast here which may give you an idea if its 
design is compatible with yours:

http://dabodev.com/documentation

It isn't complete and I could certainly use help making it so.

-- 
Paul


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


Installing packages in /usr/local

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

I use the Suse 10.0 RPM of Python 2.4.  Unfortunately, it doesn't
seem to look for packages in /usr/local because "prefix" and
"exec_prefix" in site.py are the same (namely usr/).

I have my own packages in /usr/local/lib/python/site-packages.  (Due
to easier backup, I don't want to change that.)  What is the best
way to make Python look there?

I tried PYTHONPATH but I had trouble with a Python cron job which
didn't have the proper environment.  I could edit site.py manually,
however, I wonder whether there is a cleaner way?

Tschö,
Torsten.

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


Re: ANN: FreeImagePy 1.2.2

2006-02-16 Thread Szabolcs Nagy
eg.: .dds (compressed texture file format) widely used in 3d games but
not accessible in pil

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


Re: Encryption

2006-02-16 Thread Larry Bates
dirvine wrote:
> HI hope you can help (know you can).
> 
> I am looking for a very strong AIS or better symetrical encryption in
> python. Any suggestions ideas welcome. I have spent a lot of time
> looking everywhere at pycrypto and many others but is a wee bit of a
> minefield out there. Anyone have any experience of a true encryption
> (not xor or anything weak). I am looking for something strong enough to
> encrypt your credit card info and publish file on website (no not
> actually do that but have encryption strong enough if you did).
> 
> Many thanks and if I have missed obvious docs please take it easy on me
> - I am new here :-)
> 
Take a look here.  This package works perfectly for us.

http://www.amk.ca/python/code/crypto

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


Re: looping over more than one list

2006-02-16 Thread EleSSaR^
Iain King si è profuso/a a scrivere su comp.lang.python tutte queste
elucubrazioni: 

[cut]

I think you should take a look at the zip() function.

You can use for with it like this:

for elem1, elem2, elem3 in zip(list1, list2, list3):




-- 
Alan Franzoni <[EMAIL PROTECTED]>
-
Togli .xyz dalla mia email per contattarmi.
Rremove .xyz from my address in order to contact me.
-
GPG Key Fingerprint:
5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: FreeImagePy 1.2.2

2006-02-16 Thread Michele Petrazzo
Claudio Grondi wrote:
> Knowing some details about PIL and as good as no details about 
> FreeImage, I would like in this context to become enlightened by the 
> answer to the question, when does it make sense to use FreeImage 
> instead of PIL?

Into some little environments, like tiff with G3/G4 compressions and
multi-page files.

> From what I know up to now I can't see any use for FreeImage :-( .
> 

Like I say to freeimagepy site, I start to wrote it *only* because I
needed a simple python library for manipulate fax images (G3/G4) that
PIL can't. I need it into my python fax client [hylapex] that it's
connect to hylafax server.

Of course, It wouldn't be a PIl replacement ;)!

> Claudio

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


Re: Is empty string cached?

2006-02-16 Thread Peter Hansen
Farshid Lashkari wrote:
> However, the following commands add to my confusion:
> 
>  >> a = 'wtf?'
>  >> b = 'wtf?'
>  >> a is b
> False
> 
> So how are string literals cached? Is there an explanation somewhere? Is 
> it some freaky voodoo, and I should just assume that a string literal 
> will always generate a new object?

A few comments (which I hope are correct, but which I hope you will read 
then mostly ignore since you probably shouldn't be designing based on 
this stuff anyway):

1. What you see at the interactive prompt is not necessarily what will 
happen in a compiled source file.  Try the above test with and without 
the question mark both at the interactive prompt and in source and see.

2. The reason for the difference with ? is probably due to an 
optimization relating to looking up attribute names and such in 
dictionaries.  wtf? is not a valid attribute, so it probably isn't 
optimized the same way.

2.5. I think I had a third comment like the above but after too little 
sleep last night it seems it's evaporated since I began writing...

3. As Steve or someone said, these things are implementation details 
unless spelled out explicitly in the language reference, so don't rely 
on them.

4. If you haven't already written your code and profiled and found it 
lacking in performance and proving that the cause is related to whether 
or not you hoisted the string literal out of the loop, you're wasting 
your time and this is a good opportunity to begin reprogramming your 
brain not to optimize prematurely.  IMHO.  FWIW. :-)

-Peter

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


Re: MySQL

2006-02-16 Thread rodmc
Hi Wolfram,

Thanks for the tip, after some server issues I am pleased to say the
library appears to work perfectly with MySQL 5. 

Best,

rod

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


[ANN] Pydev and Pydev Extensions 1.0.2 release

2006-02-16 Thread Fabio Zadrozny
Hi All,

Pydev and Pydev Extensions 1.0.2 have been released

Check http://www.fabioz.com/pydev for details on Pydev Extensions

and http://pydev.sf.net has for details on Pydev

Highlights in Pydev Extensions:
---

- New feature in the debugger: the console is available for probing when 
in 'suspendend mode'
- New feature in code analysis: Provided a way to consider tokens that 
should be in the globals
- Halt fix when too many matches where found in the go to definition.
- Code analysis minor bugs fixed.
- Error when opening browser fixed.


Highlights in Pydev:
---

- Jython debugging now working.
- Code coverage does not report docstrings as not being executed.
- Freeze when making a 'step-in' fixed in the debugger.
- Grammar generated with javacc version 4.0


Cheers,

Fabio

-- 
Fabio Zadrozny
--
Software Developer

ESSS - Engineering Simulation and Scientific Software
www.esss.com.br

Pydev Extensions
http://www.fabioz.com/pydev

PyDev - Python Development Enviroment for Eclipse
http://pydev.sf.net
http://pydev.blogspot.com


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


Determing whether two ranges overlap

2006-02-16 Thread Robin Haswell
Hey guys

I was wondering if you could give me a hand with something. If I have two
tuples that define a range, eg: (10, 20), (15, 30), I need to determine
whether the ranges overlap each other. The algo needs to catch:

(10, 20) (15, 25)
(15, 25) (10, 20)
(10, 25) (15, 20)
and
(15, 20) (10, 25)

I can think of lots of ways to do this but it's in a tight loop so I need
it to be as efficient as possible. Any help welcome :-)

Cheers

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


Re: Safe Python Execution

2006-02-16 Thread Alex Martelli
Graham <[EMAIL PROTECTED]> wrote:

> I've been messing around with trying to get a small sandbox like
> environment where i could execute python code in a "safe" way.
> Basically what the old restricted execution module attempted to do.
> I've written a small amount of code to get custom interpreter running,
> but i'm not really sure if its safe.
> 
> The way i'm controlling functionality is with some games and exec, so
> if 'code' was the text code you wanted to execute i run:
> 
> exec code in {'__builtins__':None"}
> 
> obviously this doesn't give you much to play with, but it does remove
> file access and importing as far as i can tell. Can anyone think of a
> hack around this? I assume if it was this easy it would be a module
> already but i figured i would ask.

I suggest compiling the code and examining the names used in the code
object (co_names attribute of the code object which compile returns) --
refuse to execute the code if it mentions, defines or uses any special
name (starting and ending with two underscores).  That, plus removing
almost all builtins as you do here, should be a good start.


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


Re: Determing whether two ranges overlap

2006-02-16 Thread Steven D'Aprano
On Thu, 16 Feb 2006 15:22:15 +, Robin Haswell wrote:

> Hey guys
> 
> I was wondering if you could give me a hand with something. If I have two
> tuples that define a range, eg: (10, 20), (15, 30), I need to determine
> whether the ranges overlap each other. The algo needs to catch:
> 
> (10, 20) (15, 25)
> (15, 25) (10, 20)
> (10, 25) (15, 20)
> and
> (15, 20) (10, 25)


What do you mean "catch"? Do you expect the algorithm to recognise these
combinations as special and return something different?

I'm going to assume that there are no magic values that need to be caught,
because I don't know what that means, and just proceed as if the task is
to compare two tuples of the form (x1, x2) where x1 <= x2.

# warning: untested!
def isoverlap((x1,x2), (y1,y2)):
"""Given two numeric ranges, returns a flag True or False
indicating whether they overlap.

Assumes that the ranges are ordered (smallest,largest). If 
that assumption is wrong, incorrect results may occur."""

# Fully overlapping cases:
# x1 <= y1 <= y2 <= x2
# y1 <= x1 <= x2 <= y2
# Partially overlapping cases:
# x1 <= y1 <= x2 <= y2
# y1 <= x1 <= y2 <= x2
# Non-overlapping cases:
# x1 <= x2 < y1 <= y2
# y1 <= y2 < x1 <= x2

return not (x2 < y1 or y2 < x1)



> I can think of lots of ways to do this but it's in a tight loop so I
> need it to be as efficient as possible.

"Efficient as possible" in what way? Least memory used? Smallest
number of bytes of source code? Fastest performance?

Assuming you need fastest performance, the general method to do that is to
write it in hand-tuned assembly language, taking care to use all the
tricks to optimize it for the particular CPU you are running on. If you
can find a way to push the processing into any high-end graphics
processors you might have, that typically will speed it up even more. It
is still, sometimes, possible for the best assembly programmers to just
barely outperform optimizing C compilers, or so I'm told.

If you are willing to set your sights just a little lower, and rather than
aiming for the absolute fastest code possible, settle for code which is
fast enough, the usual technique is to stick to Python. Write different
functions implementing the various methods you can think of, and then time
them with the timeit module. Pick the fastest. Is it fast enough that
performance is satisfactory? If so, then you are done.

Here is a technique that may speed your code up a little: it is quicker to
find local variables than global. So, instead of this:

def main():
... code here ...
while condition:
flag = isoverlap(t1, t2)
... code ...

you can gain a little speed by making a local reference to the function:

def main():
... code here ...
iso = isoverlap  # make a local reference for speed
while condition:
flag = iso(t1, t2)
... code ...


If your code is still too slow, you might speed it up with Psycho, or you
may need to write a C extension. Either way, you won't know if the code is
fast enough until you actually run it.


-- 
Steven.

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


Re: question about scope

2006-02-16 Thread Fuzzyman

John Salerno wrote:
[snip..]
>
> Thanks guys. It seems like nested functions were what the authors had in
> mind, so that makes a lot more sense now.
>
> But as far as ifs and loops, is there such a thing as scope in them? For
> example, if I assign a variable within an if statement, is it usable
> anywhere else?

Defining a variable in a loop, or within an 'if block' doesn't change
scope, so the variables are useable in the same way as variables
outside the loop. Obviously if you define them within an if block, they
may *not* be defined, so using them could raise a NameError.

if False:
test = 'something'
print test

All the best,

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

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


RE: Determing whether two ranges overlap

2006-02-16 Thread Tim Golden
[Robin Haswell]

| I was wondering if you could give me a hand with something. 
| If I have two
| tuples that define a range, eg: (10, 20), (15, 30), I need to 
| determine
| whether the ranges overlap each other. The algo needs to catch:
| 
| (10, 20) (15, 25)
| (15, 25) (10, 20)
| (10, 25) (15, 20)
| and
| (15, 20) (10, 25)
| 
| I can think of lots of ways to do this but it's in a tight 
| loop so I need
| it to be as efficient as possible. Any help welcome :-)

Don't know about efficient, but:

x = 10, 20
y = 15, 25

(x[0] <= y[1]) and (x[1] >= y[0])

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

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


Re: is socket thread safe?

2006-02-16 Thread Carl J. Van Arsdall
Bryan Olson wrote:
> Carl J. Van Arsdall wrote:
>   
>> Steve Horsley wrote:
>>
>> 
>>> [EMAIL PROTECTED] wrote:
>>>  
>>>
>>>   
 thread1:
 while 1:
 buf = s.read()
 process(buf)

 thread2:
 while 1:
 buf = getdata()
 s.write(buf)
 
>>> It is safe, but watch out for this gotcha: If thread B calls s.close() 
>>> while thread A is blocked in s.read(), thread A will never return from 
>>> the read. My preferred solution is to set socket timeout to a few 
>>> seconds, and loop checking a status flag so I know when to quit.
>>>   
>
> Certainly one needs timeouts to avoid hanging should the remote
> side stop. Sockets don't have a read() method, and hanging on
> recv() doesn't seem to have anything to do with close().
>
> I didn't find any definitive doc, so I tested using Python
> sockets on Linux (Debian/Ubuntu current) and WinXP. A recv()
> started before the close() will block/return just as if
> close() were never called. The close() neither triggers recv()
> to abort, nor prevents it from receiving data and detecting
> shutdown.
>
>
>   
>> I think a better thing would be to use something like a condition object 
>> to tie the two threads together and not use any polling loops.
>>
>> i.e.  consumer goes to sleep while data buffer is empty, producer 
>> produces and signals condition object, consumer wakes up and consumes.
>> 
>
> I can infer two producer-consumer relationships from the example,
> but they don't allow a condition object; the writer's consumer and
> the reader's producer are on the remote end of the socket. The
> socket will already handle the blocking and wake-up.
>
>   
>> To take this a step further, you have a status flag that is set to 
>> something like QUIT or CONSUME and when the condition is triggered wake 
>> up, then examine the status flag to determine if the consumer should 
>> then quit, consume, or whatever else you'd want your consumer thread to do.
>> 
>
> What problem are you trying to solve? Normal socket sending, receiving,
> and shutdown discipline work fine. When the writer is done writing, it
> should call sock.shutdown(socket.SHUT_WR). When the reader gets zero
> bytes from recv(nonzero), that means the remote end has finished
> writing, so the reader may call sock.shutdown(socket.SHUT_RD).
>   
Doh! I read the word threads and got carried away not even realizing 
sockets.  Well, looks like today i'll just have to remember to drink my 
coffee

:-D

-c

-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: How to run shell commands within python

2006-02-16 Thread Donn Cave
In article <[EMAIL PROTECTED]>,
 "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

> (also note that most trivial shell commands are better done in
> python.  most uses of cat, for example, can be trivially emulated
> with one or two lines of python...)

Though the knowledge required to do this may be more trivial
for some of us than others!  "cat" probably doesn't have much
going for it that a naive implementation would miss - some
versions will recreate "holes", but most applications will never
miss this.  You can replace "mv" with os.rename() if you don't
care that it will fail when the destination is on a different
filesystem.  Etc.

   Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some general questions about using "stdin","stdout"....

2006-02-16 Thread Dan
Hello.

If you're new to Python, then input/output isn't the best place to
start. Begin with the tutorial:
  http://docs.python.org/tut/tut.html
Other documentation is also linked to from there.

However, I will briefly answer your questions.

>   print "hello"|sys.stdin.read()

In Python the | operator has a different meaning than in a shell. In
Python it means "bitwise or":

>>> print 5 | 9
13


> Why can't i "write" to the stdin?

There may be some contorted way to do that under Unix, but it's not a
good idea. You can pipe input to your program from a shell (as you've
already done), but it's not a good idea to redirect input from within
your program.

You can accomplish the same thing like this:

   if i_want_to_redirect_input:
  my_input_source = open('file.txt')
   else:
  my_input_source = sys.stdin
   # Now read from my_input_source instead of stdin.

-- 
  They had a big meeting, drank some beer and had some pizza and
  decided 'A' would be 65.
   - Jim Greenly, professor at Georgia Institute of Technology


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


Re: Determing whether two ranges overlap

2006-02-16 Thread Fredrik Lundh
Robin Haswell wrote:

> I was wondering if you could give me a hand with something. If I have two
> tuples that define a range, eg: (10, 20), (15, 30), I need to determine
> whether the ranges overlap each other. The algo needs to catch:
>
> (10, 20) (15, 25)
> (15, 25) (10, 20)
> (10, 25) (15, 20)
> and
> (15, 20) (10, 25)
>
> I can think of lots of ways to do this but it's in a tight loop so I need
> it to be as efficient as possible. Any help welcome :-)

how about:

def overlap(a, b):
return a[1] > b[0] and a[0] < b[1]





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


Re: pythonic way of 'b = list(a); b.append(4)"

2006-02-16 Thread Heiko Wundram
szabi wrote:
> a = [1, 2, 3]
> f(*a, 4)

f(*(a+[4]))

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


Re: Some general questions about using "stdin","stdout"....

2006-02-16 Thread Diez B. Roggisch
asdsd sir wrote:

> Hi!I'm new in Python and i'd like to ask some general questions about
> stdin,stdout...
> 
> Firstly...
> 
> if we type like something like :
>cat "file.txt"|python somefile.py
> 
> #somefile.py
> import sys
>  text=sys.stdin.read()
> 
> 
> ...then "sys.stdin.read()" will read from "cat"s stdout...
> However,if i type inside a program,something like
> 
> #someprog.py
> import sys
>print "hello"|sys.stdin.read()
> 
> .the screen hangs..why is that?isn't the same situation as "cat"?

Obviously not... The stdin is a read-only file that you can read from the
data that is passed via a pipe to your application. You did tha piping by
using

cat "file.txt" | python somefile.py

That establihes the pipe between cat's stdout(!) and python's stdin. That's
the reason that | is called "pipe" or "pipe-operator" in the SHELL(!)

print "hello"|sys.stdin.read()

OTH is inside python, and | is not the pipe-operator, but the binary
or-operator. Consider this:

>>> print 1 | 2
3

But:
>>> print "hello" | "some other string"
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unsupported operand type(s) for |: 'str' and 'str'


So you don't write something to stdin by that. Instead it waits endlessly,
trying to read something that is piped to it from the outside. But if that
was the case, it would puke on you with the above error message.

> in addition to this...
> Why can't i "write" to the stdin?
> Isn't it being used as a file object like all the others?
> for example
> sys.stdin.close() or
> open('sys.stdin','w+') or
> sys.stdin.write("something") etc... don't work...

Because it is defined that way. I suggest you read up on unix piping to
grasp the concepts behind it - python only follows these.


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


Re: is socket thread safe?

2006-02-16 Thread Carl J. Van Arsdall
Jean-Paul Calderone wrote:
> On Wed, 15 Feb 2006 12:59:03 -0800, "Carl J. Van Arsdall" <[EMAIL PROTECTED]> 
> wrote:
>   
>> Steve Horsley wrote:
>> 
>>> [EMAIL PROTECTED] wrote:
>>>
>>>   
 thread1:
 while 1:
 buf = s.read()
 process(buf)

 thread2:
 while 1:
 buf = getdata()
 s.write(buf)


 
>>> It is safe, but watch out for this gotcha: If thread B calls
>>> s.close() while thread A is blocked in s.read(), thread A will
>>> never return from the read. My preferred solution is to set
>>> socket timeout to a few seconds, and loop checking a status flag
>>> so I know when to quit.
>>>
>>>
>>>   
>> I think a better thing would be to use something like a condition object
>> to tie the two threads together and not use any polling loops.
>>
>> i.e.  consumer goes to sleep while data buffer is empty, producer
>> produces and signals condition object, consumer wakes up and consumes.
>> 
>
> What makes you think process isn't implemented to notify a condition, and 
> getdata isn't implemented to wait on one? :)
>
>   
I think it was the "loop checking status flag" comment that threw me off 
*shrug*   8)

-carl

-- 

Carl J. Van Arsdall
[EMAIL PROTECTED]
Build and Release
MontaVista Software

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


Re: pythonic way of 'b = list(a); b.append(4)"

2006-02-16 Thread Peter Otten
szabi wrote:

> I have a list of three values and want to call a function with four
> parameters. I would like
> to write something like:
> 
> a = [1, 2, 3]
> f(*a, 4)
> 
> This is syntactically wrong, so is there a function which appends a
> value to a list and
> returns the new value, so that I could write something like this:
> 
> f(list(a).functional_append(4))
> 
> I can't modify 'a'.

Two more options: if you know the name of the function's fourth parameter
you can mix keyword and positional arguments

>>> def f(a, b, c, d):
... return "f(a=%r, b=%r, c=%r, d=%r)" % (a, b, c, d)
...
>>> a = [1, 2, 3]
>>> f(d=42, *a)
'f(a=1, b=2, c=3, d=42)'

or you can use partial function application:

>>> def partial(f, *left):
... def w(*right):
... return f(*left+right)
... return w
...
>>> partial(f, *a)(42)
'f(a=1, b=2, c=3, d=42)'

A generalized version of partial() will become part of the standard library
in Python 2.5.

Peter

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


Re: question about scope

2006-02-16 Thread Fredrik Lundh
John Salerno wrote:

> But my real question is this, which is related to the above:
>
> "Name references search at most four scopes: local, then enclosing
> functions (if any), then global, then built-in."
>
> I understand what global and built-in are, and I thought I understood
> the concept of local too, but when I got to this sentence (and the
> previous sentence), I became confused about the first two scopes. What's
> the difference between 'local' and 'enclosing functions'?

consider a nested function:

var1 = "global"

def outer():

var2 = "enclosing"

def inner():

var3 = "local"

print var1, var2, var3

inner() # call it

inside "inner", var1 refers to the global variable, var2 to the enclosing
variable (which is local to "outer"), and var3 to the local variable.

"enclosing scope locals" are also called "free variables".





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


Re: web crawler in python or C?

2006-02-16 Thread Steven D'Aprano
On Wed, 15 Feb 2006 21:56:52 -0800, abhinav wrote:

> Hi guys.I have to implement a topical crawler as a part of my
> project.What language should i implement
> C or Python?Python though has fast development cycle but my concern is
> speed also.I want to strke a balance between development speed and
> crawler speed.Since Python is an interpreted language it is rather
> slow.

Python is no more interpreted than Java. Like Java, it is compiled to
byte-code. Unlike Java, it doesn't take three weeks to start the runtime
environment. (Okay, maybe it just *seems* like three weeks.)

The nice clean distinctions between "compiled" and "interpreted" languages
haven't existed in most serious programming languages for a decade or
more. In these days of tokenizers and byte-code compilers and processors
emulating other processors, the difference is more of degree than kind.

It is true that standard Python doesn't compile to platform dependent
machine code, but that is rarely an issue since the bottleneck for most
applications is I/O or human interaction, not language speed. And for
those cases where it is a problem, there are solutions, like Psycho.

After all, it is almost never true that your code must run as fast as
physically possible. That's called "over-engineering". It just needs to
run as fast as needed, that's all. And that's a much simpler problem to
solve cheaply.



> The crawler which will be working on huge set of pages should be
> as fast as possible.

Web crawler performance is almost certainly going to be I/O bound. Sounds
to me like you are guilty of trying to optimize your code before even
writing a single line of code. What you call "huge" may not be huge to
your computer. Have you tried? The great thing about Python is you can
write a prototype in maybe a tenth the time it would take you to do the
same thing in C. Instead of trying to guess what the performance
bottlenecks will be, you can write your code and profile it and find the
bottlenecks with accuracy.


> One possible implementation would be implementing
> partly in C and partly in Python so that i can have best of both
> worlds.

Sure you can do that, if you need to. 

> But i don't know to approach about it.Can anyone guide me on
> what part should i implement in C and what should be in Python?

Yes. Write it all in Python. Test it, debug it, get it working. 

Once it is working, and not before, rigorously profile it. You may find it
is fast enough.

If it is not fast enough, find the bottlenecks. Replace them with better
algorithms. We had an example on comp.lang.python just a day or two ago
where a function which was taking hours to complete was re-written with a
better algorithm which took only seconds. And still in Python.

If it is still too slow after using better algorithms, or if there are no
better algorithms, then and only then re-write those bottlenecks in C for
speed.



-- 
Steven.

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


Re: looping over more than one list

2006-02-16 Thread Alex Martelli
Iain King <[EMAIL PROTECTED]> wrote:
   ...
> This works:
> 
> def lowest(s1,s2):
> s = ""
> for c1,c2 in [x for x in zip(s1,s2)]:
> s += lowerChar(c1,c2)
> return s
> 
> but it's hardly any more elegant than using a loop counter, and I'm
> guessing it's performance is a lot worse - I assume that the zip
> operation is extra work?

1. [x for x in whateverlist]   just doesn't make sense!  If you need a
copy of whateverlist, just use list(whateverlist).  When you don't need
a copy, like here, just use whateverlist.  I.e., loop this way:

  for c1, c2 in zip(s1, s2):

2. performance is destroyed by building up a big list with a += of many
small pieces.  Use cStringIO (some people prefer it for style reasons)
or (what most people do) ''.join a list where you've accumulated the
results.

3. this case is ideal for build-in function map.

The body of the function could be just one statement:

  return ''.join(map(lowerChar, s1, s2))

This probably gives best performance.

Also consider a genexp and avoiding the unpacking/repacking a la:

  return ''.join(lowerChar(*cs) for cs in zip(s1, s2))

or better:

import itertools

and then

  return ''.join(lowerChar(*cs) for cs in itertools.izip(s1, s2))

or

  return ''.join(itertools.imap(lowerChar, s1, s2))

If you care about performance, use module timeit from the standard
library to measure cases of interest.

If you don't (not especially) then the first solution looks neat,
elegant, readable, and concise.

But never build up substantial strings with a loop of += of small
strings: that's O(N squared) and will MAKE you care about performance
even where you otherwise wouldn't!-)


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


Re: looping over more than one list

2006-02-16 Thread Tim Chase
> def lowest(s1,s2):
> s = ""
> for i in xrange(len(s1)):
> s += lowerChar(s1[i],s2[i])
> return s
> 
> this seems unpythonic, compared to something like:
> 
> def lowest(s1,s2):
> s = ""
> for c1,c2 in s1,s2:
> s += lowerChar(c1,c2)
> return s

If I understand correctly, something like

for c1,c2 in zip(s1,s2):

is what you're looking for.  It will gracefully stop when it 
reaches the end of the shortest input. (in your indexed 
example above, if s2 is shorter than s1, it will likely 
throw an out-of-bounds exception)

For your example, I'd use

def lowest(s1,s2):
   return ''.join([lowerChar(c1,c2) for c1,c2 in zip(s1,s2)])

which seems to do what you describe (I understand that 
appending to strings is an inefficient operation and is 
better done with a join like this)

-tkc






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


mod_python and open HTTP connection

2006-02-16 Thread Charles
Hello, I'm think about using mod_python for a project but I need to make  
sure: Does mod_python time out after a minute ? (I hope not). If I leave  
an HTTP connection open so that the content keeps loading inside the  
browser window indefinately, and if I close the browser window, the  
mod_python process is terminated, right?
Thanks,

-- 
Charles.

Desenvolvimento e criação de sites: www.auriance.com
Hospedagem de sites e servidores dedicados: www.auriance.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonic way of 'b = list(a); b.append(4)"

2006-02-16 Thread szabi
The question was perfectly answered by Heiko Wundram:
f(*(a+[4]))

I know python is not a lawnmower but a programming language. I can
solve a lot of problems, but I prefer short, clear and nice solutions
to long and/or too powerful ones. So, my problem with my solution (b =
list(a); b.append(4)) was the same as with the others' involving
functions.

Actually what I missed is the fact that the + operator works fine with
lists...
With '+' I can solve everything. Ok, _almost_ everything :)

Thanks for everybody!

Szabi

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


Re: Is empty string cached?

2006-02-16 Thread Farshid Lashkari
> A few comments (which I hope are correct, but which I hope you will read 
> then mostly ignore since you probably shouldn't be designing based on 
> this stuff anyway):

Thanks for the info Peter. My original question wasn't due to any 
observed performance problems. I was just being curious :)

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


Re: Safe Python Execution

2006-02-16 Thread gene tani

Jean-Paul Calderone wrote:
> On Thu, 16 Feb 2006 07:59:03 -0800, Alex Martelli <[EMAIL PROTECTED]> wrote:
> >Graham <[EMAIL PROTECTED]> wrote:
> >
> >> I've been messing around with trying to get a small sandbox like
> >> environment where i could execute python code in a "safe" way.
> >> Basically what the old restricted execution module attempted to do.
> >> I've written a small amount of code to get custom interpreter running,
> >> but i'm not really sure if its safe.
> >>
> >> The way i'm controlling functionality is with some games and exec, so
> >> if 'code' was the text code you wanted to execute i run:
> >>
> >> exec code in {'__builtins__':None"}
> >>
> >> obviously this doesn't give you much to play with, but it does remove
> >> file access and importing as far as i can tell. Can anyone think of a
> >> hack around this? I assume if it was this easy it would be a module
> >> already but i figured i would ask.
> >
> >I suggest compiling the code and examining the names used in the code
> >object (co_names attribute of the code object which compile returns) --
> >refuse to execute the code if it mentions, defines or uses any special
> >name (starting and ending with two underscores).  That, plus removing
> >almost all builtins as you do here, should be a good start.
>
> A good start, perhaps, but still in need of a good finish.
>
> """
> exec 'print ' + ''.join(map(chr, [
> 95, 95, 98, 117, 105, 108, 116, 105, 110, 115, 95, 95]))
> """
>
> You can come up with a long list of restrictions to impose, and maybe that 
> will be good enough.  But making it /perfect/ is a Herculean task, as is 
> maintaining it as new Python releases are made, and auditing it every time 
> you add a new piece of code to your system.
>

What about what's in zope, :
http://svn.zope.org/Zope3/trunk/src/zope/security/untrustedinterpreter.txt?view=auto

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


Re: embedding python in HTML

2006-02-16 Thread bruno at modulix
John Salerno wrote:
> Rene Pijlman wrote:
> 
>> John Salerno:
>> [Python alternative for PHP]
>>
>>> So to do this with Python, do I simply integrate it into the HTML as
>>> above, with no extra steps? 
>>
>>
>> You'd need something like the PHP engine, that understands Python rather
>> than PHP.
> 
> 
> My web server can run Python, fortunately. Now that they've turned it on
> for me, I wanted to try it out, but I didn't know how to go about
> writing a bit of code to stick into an HTML file.

You've got to understand that Python is *not* a 'ServerPage' language
(-> php, asp, jsp etc) in itself. Your server can now run python, fine,
but *how* ? CGI ? FastCGI ? mod_python ? other ? (hint: it's probably
just plain old CGI...)


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


Re: Merging two lists of data (Pythonic way)

2006-02-16 Thread SMB

"Jonathan Gardner" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> codes = map(lambda x: x[0], list1)
> for d in list2:
>  if d['code'] in codes:
>d['VERIFIED'] = 1
>
> Is this what you were looking for?
>

That is exactly what I was looking for.  I will have to take a look at map.

Thank you very much 


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


Re: question about scope

2006-02-16 Thread Steven D'Aprano
On Thu, 16 Feb 2006 15:18:29 +, John Salerno wrote:

> What's an example of a local scope without 
> having a function definition? Loops and if statements, perhaps?

List comprehensions: [2*x+1 for x in range(50)]

Lambdas: map(lambda y: y-2, [1,2,4,8,16,32])

At the moment the x in list comprehensions are exported to the rest of the
local scope, but that (mis)feature is officially going to be removed in
future versions of Python.


-- 
Steven.

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


Re: Merging two lists of data (Pythonic way)

2006-02-16 Thread Paul Rubin
"SMB" <[EMAIL PROTECTED]> writes:
> What I am doing is looking for a pythonic way to parse the LIST2 "code" 
> values and make appropriate changes to to each dictionary if the "code" 
> value is the first element of a list in LIST1.
> 
> The final result may look like this given that the change is adding a new 
> key/value of "VERIFIED"/1 for the matches.

Untested:

from sets import Set
vvals = Set(a[0] for a in LIST1)# get all the List1 first elt. values
for d in LIST2:
   if d['code'] in vvals:
  d['VERIFIED'] = 1

> I know I could do this with two for loops, but am looking for a better 
> solution maybe involving list comprehension.

I think if list1 is potentially long, the main thing is to avoid n**2
running time, which means use a set or dict to do the lookups, like
above.
-- 
http://mail.python.org/mailman/listinfo/python-list


Seaching Active Directory via ADO

2006-02-16 Thread LittlePython
I am have trouble finding a simple working example of  using ADO to search
Active Directory. I am hoping someone could point me to a generic working
script that connects to AD and pulls up a recordset to help me get started
into the right direction in learning ADO, ADSI on Python.


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


Installing python on lynxOS

2006-02-16 Thread Bryce
I'm trying to install python2.4.2 onto lynxOS 4.0.0. with gcc 2.95.3.
I was wondering if anyone who has done this before could give me some
pointers.

I'm currently getting the following error when running make:

gcc -o python Module/python.o libpython2.4.a -lsocket -lm
called2:ld returned 1 exit status
libpython2.4.a(pystate.o):In function 'PyThreadState_New':
Python2.4.2/pystate.c:191: undefined reference to
'_PyGILState_NoteThreadState'
called2:ld returned 1 exit status

I checked pystate.c and the function _PyGILState_NoteThreadState is
defined in the file, so I'm a bit lost here.

-- 
Bryce

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


Re: question about scope

2006-02-16 Thread John Salerno
John Salerno wrote:

> I understand what global and built-in are, and I thought I understood 
> the concept of local too, but when I got to this sentence (and the 
> previous sentence), I became confused about the first two scopes. What's 
> the difference between 'local' and 'enclosing functions'?

I guess maybe I jumped the gun. Here's some stuff later in the chapter 
that I think explains it for me:

--
Note that the second 'E' scope lookup layer -- enclosing defs or lambdas 
-- technically can correspond to more than one lookup layer. It only 
comes into play when you nest functions within functions.*

* The scope lookup rule was known as the "LGB" rule in the first edition 
of this book. The enclosing def layer was added later in Python, to 
obviate the task of passing in enclosing scope names explicitly -- 
something usually of marginal interest to Python beginners.
--
-- 
http://mail.python.org/mailman/listinfo/python-list


calculating on matrix indices

2006-02-16 Thread Brian Blais
Hello,

In my attempt to learn python, migrating from matlab, I have the following 
problem. 
Here is what I want to do, (with the wrong syntax):

from numpy import *

t=arange(0,20,.1)
x=zeros(len(t),'f')

idx=(t>5)
tau=5
x[idx]=exp(-t[idx]/tau)  # <---this line is wrong (gives a TypeError)

#--

what is the best way to replace the wrong line with something that works: 
replace all 
of the values of x at the indices idx with exp(-t/tau) for values of t at 
indices idx?

I do this all the time in matlab scripts, but I don't know that the pythonic 
preferred method is.



thanks,

bb


-- 
-

 [EMAIL PROTECTED]
 http://web.bryant.edu/~bblais
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: calculating on matrix indices

2006-02-16 Thread Colin J. Williams
Brian Blais wrote:
> Hello,
> 
> In my attempt to learn python, migrating from matlab, I have the 
> following problem. Here is what I want to do, (with the wrong syntax):
> 
> from numpy import *
> 
> t=arange(0,20,.1)
> x=zeros(len(t),'f')
> 
> idx=(t>5)# <---this produces a Boolean array, probably not 
> what you want.
> tau=5
> x[idx]=exp(-t[idx]/tau)  # <---this line is wrong (gives a TypeError)
> 
> #--
> 
> what is the best way to replace the wrong line with something that 
> works: replace all of the values of x at the indices idx with 
> exp(-t/tau) for values of t at indices idx?
> 
> I do this all the time in matlab scripts, but I don't know that the 
> pythonic preferred method is.
> 
> 
> 
> thanks,
> 
> bb
> 
> 
Brian,

What are you trying to do?  It is most unlikely that you need Boolean 
values in x[idx]

Colin W.

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


Queue.Queue()

2006-02-16 Thread john peter
 what happens behind the scenes when i create a Queue.Queue() without specifying  a maxsize?  does a block of space gets allocated initially then  dynamically "expanded" as needed?  if so, what is the default size  of the initial space? is it  always better to specify a big enough maxsize initially for efficiency purposes, or  does it matter much? Thanks in advance for any help/detail  __Do You Yahoo!?Tired of spam?  Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- 
http://mail.python.org/mailman/listinfo/python-list

Re: Merging two lists of data (Pythonic way)

2006-02-16 Thread Lonnie Princehouse
You might consider writing two classes to represent the values in list1
and list2.  It might be more Pythonic than sloshing around all of those
lists and dictionaries.

But as it is, it looks like you want to find matching pairs of lists
and dictionaries from list1 and list2, respectively:

# index dictionaries from LIST2 by 'code' element.
# (assumption: no two dicts have the same "code" value)
lookup_table = dict( [(d['code'], d) for list in LIST2] )

# iterate over LIST1, matching list1 elements with corresponding list2
elements
pairs = [( L, lookup_table[L[0]]) for L in LIST1 if L[0] in
lookup_table]

# make whatever kind of modifications you want
for list_item, dictionary_item in pairs:
dictionary_item['VERIFIED'] = list_item[2]  # or something




And- If you're using Python 2.4, you can get more efficient memory
usage out of this by using generator expressions instead of list
comprehensions.

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


Re: Seaching Active Directory via ADO

2006-02-16 Thread Roger Upole
You could also accomplish the same thing using the
Command object, but this way is usually more concise
for plain Sql.

 Roger

"LittlePython" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> I notice there is no adodb.command. This is not required?
> Thx for the example!
> "Roger Upole" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Here's a short example that uses ADO to search for a
> > user by wildcard.
> >
> > import win32com.client
> > c = win32com.client.Dispatch("ADODB.Connection")
> > c.Open("Provider=ADSDSOObject")
> >
> > rs,rc=c.Execute("""
> > SELECT adspath, title, name
> > From 'LDAP://DC=yourdomain, DC=COM'
> > where objectClass='user' and name='Roger*'
> > """)
> >
> > while not rs.EOF:
> > for f in rs.Fields:
> > print f.Name, f.Value
> > rs.MoveNext()
> >
> > hth
> >   Roger
> >
> > "LittlePython" <[EMAIL PROTECTED]> wrote in message
> > news:[EMAIL PROTECTED]
> > > Thanks but I was looking more for ADO com object than ADSI or ldap.
> > > For some strange reason it is very hard to locate any working scripts
> that
> > > use ADO  to connect and search AD. Is there an issue with ADO and
python
> > > when connecting to AD?
> > > I have try to build one myself with no luck. I think my problem is
with
> > > adodb.command calls.
> > >
> > > Thanks for your response.
> > >
> > > "alex23" <[EMAIL PROTECTED]> wrote in message
> > > news:[EMAIL PROTECTED]
> > > > Heya,
> > > >
> > > > There are a couple of examples on the O'Reilly site. These two are
> > > > taken from 'Active Directory Cookbook', the first uses a COM object
> > > > while the second uses a native LDAP module:
> > > >
> > > >
> > >
> >
>
http://www.rallenhome.com/books/adcookbook/src/18.6-rootdse_python_com.py.tx
> > > t
> > > >
> > >
> >
>
http://www.rallenhome.com/books/adcookbook/src/18.6-rootdse_python_ldap.py.t
> > > xt
> > > >
> > > > This might give you a start.
> > > >
> > > > - alex23
> > > >
> > >
> > >
> >
> >
> >
> > == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet
> News==
> > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+
> Newsgroups
> > = East and West-Coast Server Farms - Total Privacy via Encryption
> =
>
>



== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet 
News==
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ 
Newsgroups
= East and West-Coast Server Farms - Total Privacy via Encryption =
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Databases and python

2006-02-16 Thread Dan Stromberg
On Thu, 16 Feb 2006 13:45:28 +, Bryan Olson wrote:

> Dan Stromberg wrote:
>> I've been putting a little bit of time into a file indexing engine
> [...]
> 
>> So far, I've been taking the approach of using a single-table database
>> like gdbm or dbhash [...] and making each entry keyed by
>> a word, and under the word in the database is a null terminated list of
>> filenames (in http://dcs.nac.uci.edu/~strombrg/base255.html representation).
>> 
> [...]
>> the program just isn't performing like I'd like it to.
>  >
>> And I think it's because despite the caching and minimal representation
>> conversion, it's still just too slow converting linear lists to arrays
>> back and forth and back and forth.
> 
> I think I follow. The straightforward method of building the
> list of files associated with a word is order n**2 time. On each
> new entry, you look up the entire string, append one file-id to
> it, and write the new version back.

Yes, essentially, with the twist that the most recently used words are
kept cached in memory, so they don't have to be converted from string to
list and back to string every time a filename is added to a word.

>> So this leads me to wonder - is there a python database interface that
>> would allow me to define a -lot- of tables?  Like, each word becomes a
>> table, and then the fields in that table are just the filenames that
>> contained that word.  That way adding filenames to a word shouldn't bog
>> down much at all.
> 
> Well, you could use simple files instead of fancy database tables.

That's an interesting thought.  Perhaps especially if australopithecine
were saved in a filename like:

~/indices/au/st/ra/lo/pi/th/ec/in/e 

> Below is a demo of an alternate technique that uses bsddb B-Trees,
> and puts both the word and the file-id in the key. I don't know
> how efficient it is for real data, but at least the time won't grow
> as Theta(n**2).

Perhaps I'm missing something, but is it not roughly O(1) for
individual insertions, but O(n*m) (n == number of files, m == number of
words) for lookups?

> --Bryan
> 
> 
> 
> import bsddb
> import urllib
> 
> 
> def add_words_from_file(index, fname, word_iterator):
>  """ Pass the open-for-write bsddb B-Tree, a filename, and a list
>  (or any interable) of the words in the file.
>  """
>  fname = urllib.quote_plus(fname)
>  s = set()
>  for word in word_iterator:
>  if word not in s:
>  s.update(word)
>  key = '%s %s' % (urllib.quote_plus(word), fname)
>  index[key] = ''
>  index.sync()
> 
> 
> def lookup(index, word):
>  """ Pass the B-Tree (as built with add_words_from_file) and a
>  word to look up. Returns list of files containing the word.
>  """
>  word = urllib.quote_plus(word)
>  fname_list = []
>  try:
>  current = index.set_location(word)
>  while True:
>  (key, _) = current
>  (w, fname) = key.split()
>  if w != word:
>  break
>  fname_list.append(urllib.unquote_plus(fname))
>  current = index.next()
>  except KeyError:
>  pass
>  return fname_list
> 
> 
> def test():
>  index = bsddb.btopen('junktest.bdb', 'n')
>  data =[
>  ('bryfile.txt', 'nor heed the rumble of a distant drum'),
>  ('junkfile.txt', 'this is the beast, the beast so sly'),
>  ('word file.txt', 'is this the way it always is here in Baltimore')
>  ]
>  for (fname, text) in data:
>  words = text.split()
>  add_words_from_file(index, fname, words)
> 
>  for word in ['is', 'the', 'heed', 'this', 'way']:
>  print '"%s" is in files: %s' % (word, lookup(index, word))
> 
> test()

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


question about scope

2006-02-16 Thread John Salerno
Here's a sentence from Learning Python:

"Names not assigned a value in the function definition are assumed to be 
enclosing scope locals (in an enclosing def), globals (in the enclosing 
module's namespace) or built-in (in the predefined __builtin__ names 
module Python provides."

I have trouble reading this sentence. First, I don't understand if the 
word 'enclosing' is a verb or an adjective. The whole flow of the 
sentence seems convoluted.

But my real question is this, which is related to the above:

"Name references search at most four scopes: local, then enclosing 
functions (if any), then global, then built-in."

I understand what global and built-in are, and I thought I understood 
the concept of local too, but when I got to this sentence (and the 
previous sentence), I became confused about the first two scopes. What's 
the difference between 'local' and 'enclosing functions'? I thought that 
the only way to create a local namespace was if there *was* a function 
definition, so now I'm confused by the apparent difference that the 
authors are referring to. What's an example of a local scope without 
having a function definition? Loops and if statements, perhaps?

And feel free to dissect that first sentence up above, because I just 
don't get it.

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


getting the line just before or after a pattern searched

2006-02-16 Thread s99999999s2003
hi

i have a file something like this

abcdefgh
ijklmnopq
12345678
rstuvwxyz
.
.
.
12345678
.

whenever i search the file and reach 12345678, how do i get the line
just above and below ( or more than 1 line above/below) the pattern
12345678 and save to variables? thanks

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


Pyserial never read

2006-02-16 Thread luca72
Hello at all
sorry for my english but i'm Italian.
I use pyserial to communicate via rs232 with an extarnal device called
smartmouse.
I write the exact line that i want , but when i read i read only the
echo ond not the other bytes.
When i meke the same project with delphi i solve this problem with the
call of the sleep.
But in python it don't work.
Have you got some ideas for solve my problem?

Best Regards

Luca

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


pythonic way of 'b = list(a); b.append(4)"

2006-02-16 Thread szabi
Hi!

I have a list of three values and want to call a function with four
parameters. I would like
to write something like:

a = [1, 2, 3]
f(*a, 4)

This is syntactically wrong, so is there a function which appends a
value to a list and
returns the new value, so that I could write something like this:

f(list(a).functional_append(4))

I can't modify 'a'.

Thanks,
Szabi

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


Re: embedding python in HTML

2006-02-16 Thread John Salerno
bruno at modulix wrote:

> You've got to understand that Python is *not* a 'ServerPage' language
> (-> php, asp, jsp etc) in itself. Your server can now run python, fine,
> but *how* ? CGI ? FastCGI ? mod_python ? other ? (hint: it's probably
> just plain old CGI...)

So does that mean I need to have something further on the server? Or is 
this something I can do on my end? How do I find out what I need?
-- 
http://mail.python.org/mailman/listinfo/python-list


Open Relay Test

2006-02-16 Thread D
Hi all .. how could one test to see if an open relay exists on a
specific email server?

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


Re: %SystemDrive%

2006-02-16 Thread Bryan Olson
Atanas Banov wrote:
> Bryan Olson wrote:
> 
>>To get it with the \, you might use:
>>
>> os.path.abspath(os.environ['SYSTEMDRIVE'])
> 
> 
> wrong!
> the result is incorrect if the current directory is different from the
> root.

Oops, sorry. I should know better than to code from what I
think I vaguely remember.


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


Sendmail "ok" signal?

2006-02-16 Thread Gaz
Hey. I looked at the Sendmail help and did not find a property where i
can get an "ok" signal when the email is finally sent. I need something
like that to show a "Processing, please stand by" screen when the
server is sending an email, and when the email is out, another screen
appears with an "Email sent" message.

Do you know an alternative to the "ok" from the sendmail to do this?

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


Re: multiple inheritance

2006-02-16 Thread Thomas Girod
That's perfect. thanks.

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


  1   2   >