Re: calculating on matrix indices

2006-02-16 Thread Robert Kern
Brian Blais wrote:
> Colin J. Williams wrote:
> 
>> Brian Blais wrote:
>>
>>> 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 are you trying to do?  It is most unlikely that you need Boolean
>> values in x[idx]

[Apologies for piggybacking.]

Boolean arrays are perfectly valid indices and do exactly what the OP wants.

In [25]: t[idx]
Out[25]:
array([  5.1,   5.2,   5.3,   5.4,   5.5,   5.6,   5.7,   5.8,   5.9,
 6. ,   6.1,   6.2,   6.3,   6.4,   6.5,   6.6,   6.7,   6.8,
 6.9,   7. ,   7.1,   7.2,   7.3,   7.4,   7.5,   7.6,   7.7,
 7.8,   7.9,   8. ,   8.1,   8.2,   8.3,   8.4,   8.5,   8.6,
 8.7,   8.8,   8.9,   9. ,   9.1,   9.2,   9.3,   9.4,   9.5,
...

In [28]: (t[idx] == compress(idx, t)).all()
Out[28]: True

When used as indices, Boolean arrays are treated as arrays of Boolean values,
not 0s and 1s. Arrays of 0s and 1s used as indices would get the first and
second values of an array, respectively, as I think you were expecting.

In [35]: t[idx.astype(int)]
Out[35]:
array([ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,
0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0.1,  0.1,  0.1,  0.1,
0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,  0.1,
 ...

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
 Are the graves of dreams allowed to die."
  -- Richard Harter

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


Re: Seaching Active Directory via ADO

2006-02-16 Thread LittlePython
Never mind , I know what's wrong ... need to use the right account. It works
great and is a great example .. thx


"LittlePython" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Do you know what this may mean?
>
> C:\Documents and Settings\Administrator\Desktop\pytest>ADOSeach.py
> Traceback (most recent call last):
>   File "C:\Documents and
Settings\Administrator\Desktop\pytest\ADOSeach.py",
> lin
> e 6, in ?
> rs,rc=c.Execute("""
>   File "", line 3, in Execute
>   File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
258,
> in
> _ApplyTypes_
> result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType,
> argTypes
> ) + args)
> pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Provider',
> 'Tabl
> e does not exist.', None, 1240640, -2147217865), None)
>
> C:\Documents and Settings\Administrator\Desktop\pytest>
> "Roger Upole" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > 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: Seaching Active Directory via ADO

2006-02-16 Thread LittlePython
Do you know what this may mean?

C:\Documents and Settings\Administrator\Desktop\pytest>ADOSeach.py
Traceback (most recent call last):
  File "C:\Documents and Settings\Administrator\Desktop\pytest\ADOSeach.py",
lin
e 6, in ?
rs,rc=c.Execute("""
  File "", line 3, in Execute
  File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 258,
in
_ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType,
argTypes
) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Provider',
'Tabl
e does not exist.', None, 1240640, -2147217865), None)

C:\Documents and Settings\Administrator\Desktop\pytest>
"Roger Upole" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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: calculating on matrix indices

2006-02-16 Thread Brian Blais
Colin J. Williams wrote:
> Brian Blais wrote:
>> 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 are you trying to do?  It is most unlikely that you need Boolean 
> values in x[idx]
> 

in this example, as in many that I would do in matlab, I want to replace part 
of a 
vector with values from another vector.  In this case, I want x to be zero from 
t=0 
to 5, and then have a value of exp(-t/tau) for t>5.  I could do it with an 
explicit 
for-loop, but that would be both inefficient and unpython-like.  For those who 
know 
matlab, what I am doing here is:

t=0:.1:20;
idx=find(t>5);
tau=5;

x=zeros(size(t));
x(idx)=exp(-t(idx)/tau)


is that clearer?  I am sure there is a nice method to do this in python, but I 
haven't found it in the python or numpy docs.


thanks,

bb


-- 
-

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


Re: Open Relay Test

2006-02-16 Thread Steve Holden
D wrote:
> Hi all .. how could one test to see if an open relay exists on a
> specific email server?
> 
I bet spammers would love someone to answer that question for them. You 
wouldn't be planning spam, by any chance?

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006  www.python.org/pycon/

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


Re: getting the line just before or after a pattern searched

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

> 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

If the file's of reasonable size, read it all into memory into a list of
lines with a .readlines method call, then loop with an index over said
list and when you find your pattern at index i use i-1, i+1, and so on
(just check that the resulting i+N or i-N is >=0 and http://mail.python.org/mailman/listinfo/python-list


Re: [Numpy-discussion] Re: calculating on matrix indices

2006-02-16 Thread Bill Baxter
Howdy,On 2/17/06, Brian Blais <[EMAIL PROTECTED]> wrote:
Colin J. Williams wrote:> Brian Blais wrote:>> 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')This was the line causing the type error.  t is type double (float64).  'f' makes x be type float32.  That causes the assignment below to fail.  Replacing that line with
 x=zeros(len(t),'d')
should work.  Or the zeros_like() that Travis suggested. 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)>>You could also use    idx=where(t>5)In place of    idx=(t>5)
Although in this case it probably doesn't make much difference, where(expr) is more directly equivalent to matlab's find(expr).See http://www.scipy.org/Wiki/NumPy_for_Matlab_Users
 for more Matlab equivalents.  And consider contributing your own, if you have some good ones that aren't there already.--bb
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: calculating on matrix indices

2006-02-16 Thread Travis E. Oliphant
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)
> tau=5
> x[idx]=exp(-t[idx]/tau)  # <---this line is wrong (gives a TypeError)

Hi Brian,

Just to let you know, you are more likely to get good answers by mailing 
[EMAIL PROTECTED] then posting to this list.

The indexing technique you are using is actually fine.  The trouble you 
are having is that t is a double-precision array (and thus so is 
exp(-t[idx]/tau)  while x is a single-precision array.

Compare:

x.dtype.name
t.dtype.name

Because you are trying to store something with greater precision into an 
array with less precision you get a TypeError.

So, either change x to be double precision:

x = zeros(len(t), float)

#the default Python float is doubleprecision

or change t to be single precision:

t = arange(0,20,.1,dtype=single)

Good luck,

-Travis

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


ANN: Release of NumPy 0.9.5

2006-02-16 Thread Travis E. Oliphant
NumPy is the successor to both Numeric and Numarray.  It builds from and 
uses code from both.

More information can be found at the following links

http://numeric.scipy.org
http://www.scipy.org
http://sourceforge.net/project/showfiles.php?group_id=1369&package_id=175103

Highlights of Release:

  -  Unicode arrays are now always UCS4 even on narrow Python builds
  -  Many improvements and bugfixes to dtype objects
  -  Improvements to numpy.distutils
  -  Optimized dot function improved so copies are no longer made for 
transposed arrays

  -  Many more bug-fixes

Full release notes at

http://sourceforge.net/project/shownotes.php?release_id=394206&group_id=1369


Best regards,


-Travis Oliphant


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


Re: embedding python in HTML

2006-02-16 Thread Rene Pijlman
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.

I've used Cheetah:
http://www.cheetahtemplate.org/

Our BDFL seems to prefer Django:
http://www.artima.com/weblogs/viewpost.jsp?thread=146606

There's also PSP:
http://www.ciobriefings.com/psp/

And many more:
http://wiki.python.org/moin/WebProgramming

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


Re: days since epoch

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

> hi
> how can i get the number of days since epoch using the time module?
> or do i have to manually do the arithmetic?

Try the datetime module -- better suited to computing days, than the
time module, IMHO.


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


Re: question about scope

2006-02-16 Thread Sibylle Koczian
John Salerno schrieb:
> 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?
> 

Nested functions, I should think. Absolutely silly, but working example:

>>> def outer():
arg_in = 2
def inner():
x = arg_in * 3
return x
return inner()
>>> outer()
6

Seen from the inside of "inner" x is local, arg_in is in the enclosing
function.



-- 
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg
e-mail : [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


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

2006-02-16 Thread Paul Rubin
"szabi" <[EMAIL PROTECTED]> writes:
> 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)

f(*a+[4]) seems to work.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Copying zlib compression objects

2006-02-16 Thread [EMAIL PROTECTED]
No comments?

I found a small bug in TarFile.snapshot() / restore() - they need to
save and restore self.inodes as well.

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


Re: looping over more than one list

2006-02-16 Thread Dylan Moreland
> 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

Always look in itertools for stuff like this:

http://docs.python.org/lib/itertools-functions.html#l2h-1392

for c1, c2 in itertools.izip(s1, s2):
...

I haven't profiled it, but it makes sense that this would be fast.

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


Mac OS X Installation Problem

2006-02-16 Thread Matt
Hi Everybody,

1) Does OS X have a thing like the Add/Remove Programs control panel on 
Windows XP?

My Tiger system had Python v2.3.5 on it and I threw the files in the trash and 
installed v2.4.1, which is working fine as far as I can tell. However, when I 
type python at the command line, I get "command not found" so,

2) How do I get OS X to recognize python at the command line?

Thanks,
Matt



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


Re: Databases and python

2006-02-16 Thread Dan Stromberg
On Wed, 15 Feb 2006 23:37:31 -0800, 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

I think I could ditch the "word ID to word" table, but I think I'll
probably eventually need the "filename ID to filename" table, so when I
pull a list of filename ID's by word I can get back the filenames.

> You're going to want an index on pretty much every column in this
> database. That's because you're going to lookup by any one of these
> columns for the corresponding value.

I do need some pretty heavy indexing.

In fact, so far everything seems to be clicking along pretty well, except
the part that I'm having trouble indexing - the per-word list of
filenames.  And that's because I already have one relation (word
number -> filenames' numbers) that's complicating getting another relation
for the list of filenames (just filename ID to '', but it'd be s much
faster if I could nest the relations somehow).

> 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. Let's say you
> are scanning your files. You won't need an index on the filename-to-ID
> table. That's because you are just putting data in there. The word-to-ID
> table needs an index on the word, but not ID (you're not looking up by
> ID yet.) And the word ID-to-filename ID table doesn't need any indexes
> yet either. So build up the data without the indexes. Once your scan is
> complete, then build up the indexes you'll need for regular operation.
> You can probably incrementally add data as you go.

Interesting thought!  I think I need to ponder this a bit more.

I think the filename <-> filename number tables are pretty inexpensive,
and the word <-> word number tables seem pretty inexpensive too.  I think
it's primarily the word number to filename numbers table that's messing
up the performance really bad, and that's probably because the list of
filename numbers is growing so large in some cases, and adding a filename
to a word tends to be O(n), n==the number of filenames already on the word.

May I ask: In what representation would you keep this word number to
filename numbers relation stashed away until later, to build your indexes
from more rapidly in a later pass?  Are you thinking to keep them all in
memory, or store them in a flat file somehow?

> As far as filename ID and word IDs go, just use a counter to generate
> the next number. If you use base255 as the number, you're really not
> going to save much space.

That's basically what I'm doing - incrementing a counter for each word,
except I'm converting that counter to base255.  The base255 representation
of that counter brings the following benefits:

1) Converting a set of numbers to a string, without losing number
boundaries, becomes just mapping them to base255, and
string.joinfields'ing them.

2) Converting a string to a set of numbers, again without losing number
boundaries, is just string.splitfields'ing them, and mapping them from
base255 back to a list or set of numbers.

3) The numbers can be arbitrarily large, unlike with a, say, 4 or 8 byte
fixed-length record representation

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

Sigh.  I was afraid of that. :-S

I'm thinking though...  what if I were to use the current representation
for words that don't appear in that many files, and a table for each word
that has >= 1000 (or whatever threshold) filenames associated with it...?

That should greatly cut down on the number of tables, while still giving
the more efficient representation for the words that need it.

Or not?


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


Re: Installing python on lynxOS

2006-02-16 Thread Donn Cave
Quoth "Bryce" <[EMAIL PROTECTED]>:
| 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.

If you look about 50 lines up from there, you'll see that it's
conditional on the WITH_THREAD preprocessor macro.

If it's not defined because LynxOS doesn't have threads or at any
rate there isn't a usable thread implementation among the existing
thread_xyz.c options, you might be able to get past this problem by
writing a trivial version of the function for the case where WITH_THREAD
is not defined.  I haven't looked at it, to know for sure what would
be appropriate - maybe it was put inside WITH_THREAD in error, in the
first place, for all I know.

If you think you probably should be getting threads, then look at
pyconfig.h to verify this.

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


Numarray - Using Integers Efficiently for Boolean Values

2006-02-16 Thread andrewfelch
Below is the code to/from Boolean arrays and Unsigned integers.  On my
Pentium 4, functions such as "bitwise_and" are 32 times faster when run
on 32-bit integers instead of the entire-byte-consuming-Boolean.

Good luck all:-)

uint32Mask =
numarray.array([0x0001,0x0002,0x0004,0x0008, \

0x0010,0x0020,0x0040,0x0080, \

0x0100,0x0200,0x0400,0x0800, \

0x1000,0x2000,0x4000,0x8000, \

0x0001,0x0002,0x0004,0x0008, \

0x0010,0x0020,0x0040,0x0080, \

0x0100,0x0200,0x0400,0x0800, \

0x1000,0x2000,0x4000,0x8000], numarray.UInt32)
uint32MaskInner = numarray.copy.deepcopy(uint32Mask)
uint32MaskInner.shape = [32,1]
uint32MaskOuter = numarray.copy.deepcopy(uint32Mask)
uint32MaskOuter.shape = [1,32]

def BoolToUInt32(myArr):
if myArr.size()%32 != 0:
print "Size is: ", myArr.size()
return
numarray.matrixmultiply(numarray.reshape(myArr,[myArr.size()/32,32]),uint32MaskInner).flat

def UInt32ToBool(myArr,destination=None):
if destination == None:
destination = numarray.zeros([myArr.size()*32],numarray.Bool)
#return
numarray.bitwise_and(numarray.reshape(myArr,[myArr.size(),1]),uint32MaskOuter).flat
#else:
destination.shape = [myArr.size(),32]

numarray.bitwise_and(numarray.reshape(myArr,[myArr.size(),1]),uint32MaskOuter,destination)
destination.shape = [destination.size()]
return destination





Test of code:
>>> import numarray
>>> gram.UInt32ToBool(ni)
array([1, 0, 0, ..., 0, 0, 0], type=Bool)
>>> numarray.all(numarray.equal(n,gram.UInt32ToBool(gram.BoolToUInt32(n
1
>>> n
array([1, 0, 0, ..., 0, 0, 0], type=Bool)
>>> n.shape
(1024,)
>>> numarray.all(numarray.equal(n,gram.UInt32ToBool(gram.BoolToUInt32(n
1

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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


[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


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


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


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


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


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


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


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


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


[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

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


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


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


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


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

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


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


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


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


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

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


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


  1   2   >