Re: Socket Performance

2008-03-14 Thread castironpi
> > Well, lets say you have a situation where you're going to be
> > alternating between sending large and small chunks of data. Is the
> > solution to create a NetworkBuffer class and only call send when the
> > buffer is full, always recv(8192)?
>
>         Or create a protocol where the first 16 bits (in network byte order)
> contain a length value for the subsequent data, and use a receive
> process that consists of:
>
> leng = ntoh(socket.recv(2))
> data = socket.receive(leng)
>
> (the send can combine the length with the data into a single packet)

Are two 'sends' guaranteed to arrive as at least two 'receives'?

Send-3:  xxx
Send-3:  yyy
Receive-6:  xxxyyy

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


Re: Spaces in path name

2008-03-14 Thread David S
Hi,

Using "C:\Program Files\apache-ant-1.7.0\bin\ant.bat" just gives me the same 
result.

David

"Dennis Lee Bieber" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Fri, 14 Mar 2008 04:37:12 GMT, "David S" <[EMAIL PROTECTED]>
> declaimed the following in comp.lang.python:
>
>
>> If I cut the path statement here and paste it next to a windows XP 
>> command
>> prompt ant is invoked.
>>
>> The python code here is
>> if not os.path.isfile(ANT_CMD):
>> error('"%s" does not exist' % ANT_CMD)
>>
> Any chance the /filename/ is something like "ant.exe"
>
 pyt = "e:/python24/python"
 if not os.path.isfile(pyt):
> ... print "%s does not exist" % pyt
> ...
> e:/python24/python does not exist
 pyt = "e:/python24/python.exe"
 if not os.path.isfile(pyt):
> ... print "%s does not exist" % pyt
> ...

>
> Remember, under Windows, files with certain extensions are
> executable /without/ needing the extension on the command line -- unlike
> Linux...
>
> My eclipse install has: ant.bat, ant.cmd, and ant.jar files, and
> which (if they are in the same directory) gets picked when the extension
> is not specified is beyond my current knowledge -- might depend on the
> order of the extensions specified in the
>
> C:\Documents and Settings\Dennis Lee Bieber>echo %pathext%
> .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.pyw;.py;.pyo;.pyc;.tcl
>
> (okay, the ant.jar won't be picked )
>
> -- 
> Wulfraed Dennis Lee Bieber KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/ 


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


Re: Socket Performance

2008-03-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote:
[Dennis Lee Bieber had written:]
>> Or create a protocol where the first 16 bits (in network byte order)
>> contain a length value for the subsequent data, and use a receive
>> process that consists of:
>>
>> leng = ntoh(socket.recv(2))
>> data = socket.receive(leng)
>>
>> (the send can combine the length with the data into a single packet)
> 
> Are two 'sends' guaranteed to arrive as at least two 'receives'?

No. Nor are they guaranteed to arrive as at least most two.

> Send-3:  xxx
> Send-3:  yyy
> Receive-6:  xxxyyy

Can happen, though I think the problem with Dennis's code is the
other way. The recv in

leng = ntoh(socket.recv(2))

might return one byte of data, not two. The latter recv is similar.


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


Re: Socket Performance

2008-03-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote:
> Well, lets say you have a situation where you're going to be
> alternating between sending large and small chunks of data. Is the
> solution to create a NetworkBuffer class and only call send when the
> buffer is full, always recv(8192)?

Buffering can often improve performance, but with the above we'd
to too quick to prematurely jump to an as yet unwarranted conclusion.

You measured the one-large and many-small cases, but not the case
you actually have. You might be able to take various measurements
and generally characterize speed as a function of the number of
calls and the size of the send. I wouldn't be surprised if the
result is well approximated by a time per call plus a time per
byte.

In optimization, guessing is bad. Where you cannot reason with
mathematical rigor, measure. Where you can derive a purely
analytic result, taking the occasional measurements still isn't a
bad idea (but don't tell my algorithms students).

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


Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Peter Otten
Dave Kuhlman wrote:

> Arnaud Delobelle wrote:
> 
>> 
>> 4.  Both points above follow from the fact that foo.bar is really a
>> function call that returns a (potentially) new object: in fact what
>> really happens is something like
> 
> Arnaud and Imri, too -
> 
> No.  foo.bar is *not* really a function/method call.
> 
>> 
>> Foo.__dict__['bar'].__get__(foo, Foo).
>> 
>> So every time foo.bar is executed an object is (or may be) created,
>> with a new id.
>> 
>> HTH
> 
> I appreciate the help, but ...
> 
> Actually, it does not help, because ...
> 
> My understanding is that foo.bar does *not* create a new object.  All it
> does is return the value of the bar attribute of object foo.  What new
> object is being created?

If the attribute has a __get__() method that's completely under the
attribute's control:

>>> class Bar(object):
... def __get__(self, *args):
... print "__get__%s" % (args,)
... return self.next()
... def next(self):
... self.count += 1
... return self.count
... count = -1
...
>>> class Foo(object):
... bar = Bar()
... def __repr__(self): return "foo"
...
>>> foo = Foo()
>>> foo.bar
__get__(foo, )
0
>>> foo.bar
__get__(foo, )
1
>>> foo.bar
__get__(foo, )
2
>>> getattr(foo, "bar")
__get__(foo, )
3

Peter

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


Re: Spaces in path name

2008-03-14 Thread Bryan Olson
David S wrote:
> I get
> 
> ERROR: ""C:\Program Files\apache-ant-1.7.0\bin\ant"" does not exist
> 
> If I cut the path statement here and paste it next to a windows XP command 
> prompt ant is invoked.
> 
> The python code here is
> if not os.path.isfile(ANT_CMD):
> error('"%s" does not exist' % ANT_CMD)

There you don't want the quotes within the string. On my MS-Win box:

   >>> import os
   >>> os.path.isfile(r'C:\Program Files\Windows NT\dialer.exe')
   True
   >>> print os.path.isfile(r'"C:\Program Files\Windows NT\dialer.exe"')
   False


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


Re: Spaces in path name

2008-03-14 Thread Bryan Olson
David S wrote:

> Using "C:\Program Files\apache-ant-1.7.0\bin\ant.bat" just gives me the same 
> result.

Did you try the raw string, with the .bat extension? As in:

   r'C:\Program Files\apache-ant-1.7.0\bin\ant.bat'


After Microsoft started allowing blanks in paths, it took them years to
fix many common cases where their own software choked on the paths. I
got into the habit of installing everything under c:\bin rather than
C:\Program Files. I still do that just to avoid writing essays into
my PATH variable.


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


Re: Need Script For read multiple files(.txt) from a folder

2008-03-14 Thread Chris
On Mar 14, 8:36 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Thu, 13 Mar 2008 21:28:18 -0700 (PDT), jai_python
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
> > hi frenz I  Need a Python Script For read multiple files(.txt) from a
> > folder and write it in a single text file
>
>         If you are on windows, just open a command prompt and use the
> standard copy command...
>
> C:\Documents and Settings\Dennis Lee Bieber>copy /?
> Copies one or more files to another location.
>
> COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
>      [+ source [/A | /B] [+ ...]] [destination [/A | /B]]
>
>   source       Specifies the file or files to be copied.
>   /A           Indicates an ASCII text file.
>   /B           Indicates a binary file.
>   /D           Allow the destination file to be created decrypted
>   destination  Specifies the directory and/or filename for the new
> file(s).
>   /V           Verifies that new files are written correctly.
>   /N           Uses short filename, if available, when copying a file
> with a
>                non-8dot3 name.
>   /Y           Suppresses prompting to confirm you want to overwrite an
>                existing destination file.
>   /-Y          Causes prompting to confirm you want to overwrite an
>                existing destination file.
>   /Z           Copies networked files in restartable mode.
>
> The switch /Y may be preset in the COPYCMD environment variable. This
> may be overridden with /-Y on the command line.  Default is to prompt on
> overwrites unless COPY command is being executed from within a batch
> script.
>
> To append files, specify a single file for destination, but multiple
> files for source (using wildcards or file1+file2+file3 format).
>
> C:\Documents and Settings\Dennis Lee Bieber>
>
>         Note that last paragraph "To append files"
> --
>         Wulfraed        Dennis Lee Bieber               KD6MOG
>         [EMAIL PROTECTED]             [EMAIL PROTECTED]
>                 HTTP://wlfraed.home.netcom.com/
>         (Bestiaria Support Staff:               [EMAIL PROTECTED])
>                 HTTP://www.bestiaria.com/

If you want to go that route you could also do: type *.txt >
output_file.txt
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need Script For read multiple files(.txt) from a folder

2008-03-14 Thread martin . laloux
use the glob module

import os, glob
dor = the path you want
for dir, subdir, files in os.walk(dor):
for file in files:
  if glob.fnmatch.fnmatch(file,"*.txt"):
   do what you want
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a file with $SIZE

2008-03-14 Thread Bryan Olson
Robert Bossy wrote:
> [EMAIL PROTECTED] wrote:
>> Robert Bossy wrote:  
>>> Indeed! Maybe the best choice for chunksize would be the file's buffer
>>> size... 

That bit strikes me as silly.

>>> I won't search the doc how to get the file's buffer size because
>>> I'm too cool to use that function and prefer the seek() option since
>>> it's lighning fast regardless the size of the file and it takes near to
>>> zero memory.
>>
>> But what platforms does it work on / not work on?
>>   
> Posix. 

Posix is on the does-work side, just to be clear.

   http://www.opengroup.org/onlinepubs/95399/functions/fseek.html

> It's been ages since I touched Windows, so I don't know if XP and 
> Vista are posix or not.

I tried on WinXP, with both an NTFS and FAT32 disk, and it worked
on both.

I found some Microsoft documentation noting: "On some
platforms, seeking past the end of a file and then doing a write
operation results in undefined behavior."
 
http://msdn2.microsoft.com/en-us/library/system.io.filestream.seek(VS.71).aspx


> Though, as Marco Mariani mentioned, this may create a fragmented file. 
> It may or may not be an hindrance depending on what you want to do with 
> it, but the circumstances in which this is a problem are quite rare.

Writing zeros might also create a fragmented and/or compressed file.
Using random data, which is contrary to the stated requirement but
usually better for stated application, will prevent compression but
not prevent fragmentation.

I'm not entirely clear on what the OP is doing. If he's testing
network throughput just by creating this file on a remote server,
the seek-way-past-end-then-write trick won't serve his purpose.
Even if the filesystem has to write all the zeros, the protocols
don't actually send those zeros.


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


Re: List mutation method gotcha - How well known?

2008-03-14 Thread Jarek Zgoda
Lie napisał(a):

>> foo = [1,2,3,4]
>> x = foo.append(5)
>> print x
>>
>> What will be the output (choose one):
>>
>> 1)  [1,2,3,4]
>> 2)  [1,2,3,4,5]
>> 3)  That famous picture of Albert Einstein sticking out his tongue
>> 4)  Nothing - no output
>> 5)  None of the above
>>
>> I undertake to summarise answers posted to complete this "survey".
> 
> I think I'll choose 3. Well, no, I suppose the correct behavior
> _should_ be undefined (i.e. what it returns is an implementation
> details that should not be relied on). The fact that it returns None
> is just a "coincidence" that happens to happen every time you tested
> it (you can't prove by ignorance)

I think in Python there's no notion of "void" return type. Deliberate
choice to return None for functions that modify objects in place seems
to be OK as long as it is used consistently and documented. Which is the
case.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass the workspace ?

2008-03-14 Thread Stef Mientki
Thanks, Gary and Dennis,

Dennis Lee Bieber wrote:
> On Thu, 13 Mar 2008 21:35:42 +0100, Stef Mientki
> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>
>
>   
>> The result of globals and locals in the file is eaxctly the same and 
>> none of them mentions 'NewVar' and 'beer'
>> The result of tree_globs and tree_locals is exactly the same and both 
>> doesn't contain 'NewVar' and 'beer'
>> Maybe it's very simple after reading the manual,
>> but apperently I'm missing the essential clue.
>> What am I missing ?
>>
>> 
>   Use of globals() and locals() vs globals and locals?
>   
Well I get an error with that.
But you both give me some ideas, and it's working now:
- I don't need the locals
- from the file where the execute is launched, you must use the normal 
dictionary call

 tree_globs = {}
 tree_globs [ 'NewVar' ] = 24
 filename = self.Get_Editor_Filename (nodename)
 execfile ( filename, tree_globs )
 print self.tree_globs['NewVar']
 print self.tree_globs['beer']

where the code in the executed file is:

beer = 'testje'

the output I get is:

24
testje

and the "self.tree_globs" travels perfectly though all the files executed.

cheers,
Stef
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: app runs fine with interpreter, but not under py2exe

2008-03-14 Thread Doug Morse
Harald,

Great suggestion, thanks!  Unfortunately, "no help there".  Adding "import
multiarray" to Precision.py where you suggested (i.e., before the "from
multiarray import zeros" line) did not fix the problem.  I'm getting the same
exception and traceback as before except, of course, on line 19 now instead of
line 18.

Doug


On Thu, 13 Mar 2008 11:46:41 -0700 (PDT), GHUM <[EMAIL PROTECTED]>
wrote:
>  Doug,
> 
> > Precision.py is part of the Numeric package.  AFAIKT, the problem is during
> > the module initialization.  The first lines of Precision.py are:
> >
> > from multiarray import zeros
> > import string
> >
>  [.]
>  and your program is crashing on the
> 
>  lst.append( (zeros( (1,), t ).itemsize()*8, t) )   <-- Line 18
> 
>  line... Please, try the following:
> 
>  import multiarray
>  from multiarray import zeros
>  import string
> 
>  (adding the line "import multiarray" before zeros are imported from
>  it)
> 
>  I used this workaround with various packages I py2exed - maybe it also
>  works for you?
> 
>  please keep us updated,
> 
>  Harald
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating a file with $SIZE

2008-03-14 Thread Robert Bossy
Bryan Olson wrote:
> Robert Bossy wrote:
>   
>> [EMAIL PROTECTED] wrote:
>> 
>>> Robert Bossy wrote:  
>>>   
 Indeed! Maybe the best choice for chunksize would be the file's buffer
 size... 
 
>
> That bit strikes me as silly.
>   
The size of the chunk must be as little as possible in order to minimize 
memory consumption. However below the buffer-size, you'll end up filling 
the buffer anyway before actually writing on disk.


>> Though, as Marco Mariani mentioned, this may create a fragmented file. 
>> It may or may not be an hindrance depending on what you want to do with 
>> it, but the circumstances in which this is a problem are quite rare.
>> 
>
> Writing zeros might also create a fragmented and/or compressed file.
> Using random data, which is contrary to the stated requirement but
> usually better for stated application, will prevent compression but
> not prevent fragmentation.
>
> I'm not entirely clear on what the OP is doing. If he's testing
> network throughput just by creating this file on a remote server,
> the seek-way-past-end-then-write trick won't serve his purpose.
> Even if the filesystem has to write all the zeros, the protocols
> don't actually send those zeros.
Amen.

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


Re: merging intervals repeatedly

2008-03-14 Thread Robert Bossy
Magdoll wrote:
>> One question you should ask yourself is: do you want all solutions? or
>> just one?
>> If you want just one, there's another question: which one? the one with
>> the most intervals? any one?
>> 
>
> I actually don't know which solution I want, and that's why I keep
> trying different solutions :P
>   
You should think about what is your data and what is probably the "best" 
solution.


>> If you want all of them, then I suggest using prolog rather than python
>> (I hope I won't be flamed for advocating another language here).
>> 
>
> Will I be able to switch between using prolog & python back and forth
> though? Cuz the bulk of my code will still be written in python and
> this is just a very small part of it.
>   
You'll have to popen a prolog interpreter and parse its output. Not very 
sexy.
Moreover if you've never done prolog, well, you should be warned it's a 
"different" language (but still beautiful) with an important learning 
curve. Maybe not worth it for just one single problem.


>> If you have a reasonable number of intervals, you're algorithm seems
>> fine. But it is O(n**2), so in the case you read a lot of intervals and
>> you observe unsatisfying performances, you will have to store the
>> intervals in a cleverer data structure, see one of 
>> these:http://en.wikipedia.org/wiki/Interval_treehttp://en.wikipedia.org/wiki/Segment_tree
>> 
>
> Thanks! Both of these look interesting and potentially useful :)
>   
Indeed. However these structures are clearly heavyweight if the number 
of intervals is moderate. I would consider them only if I expected more 
than several thousands of intervals.

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


Re: call by reference howto????

2008-03-14 Thread Antoon Pardon
On 2008-03-13, Terry Reedy <[EMAIL PROTECTED]> wrote:
>
> "Antoon Pardon" <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
>| On 2008-02-28, Steven D'Aprano <[EMAIL PROTECTED]> 
> wrote:
>| > On Thu, 28 Feb 2008 02:02:19 +0200, Tamer Higazi wrote:
>| >
>| >> Hi!
>| >> Can somebody of you make me a sample how to define a function based on
>| >> "call by reference" ???
>| >
>| > Python doesn't do call by reference. Nor does it do call by value. 
> Please
>| > pay no attention to anyone who says it does.
>|
>| Whatever python has for a calling convention, it is close enough that
>| naming it "call by reference" gives people a reasonable idea of what
>| is going on.
>
> But it is also different enough to mislead people.

IMO the confusing come more from people expecting the assignment to
be some kind of mutating operation. 

>| AFAICS people don't have a problem with understanding the calling
>| convention of python. They have a problem understanding the
>| assignment semantics.
>
> The calling convention is cross-namespace assignment.  So one cannot 
> understand calls without understanding assignment.

In that case I find it very strange that when this question comes
up, I see so few attempts to explain how the assignment acctually
works.

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


RE: Huge problem gettng MySQLdb to work on my mac mini running Macosx 10.5 Leopard

2008-03-14 Thread Robert Rawlins
Geert,

I've not seen this issue myself, however, you might get a little more luck
asking over on the MySQLdb mailing list as this seems to be more an issue
with the db than your python code. It might be worth posting your question
there too as it'll heighten your chances of finding someone who knows
MySQLdb inside out.

http://mail.python.org/mailman/listinfo/db-sig

Cheers,

Robert

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
On Behalf Of geert
Sent: 14 March 2008 10:36
To: [email protected]
Subject: Huge problem gettng MySQLdb to work on my mac mini running Macosx
10.5 Leopard

Hi all,

I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as 64-bit.

MySQLdb installs with the usual warnings after applying the various
patches I found here and there. These patches consist of altering
_mysql.c and site.cfg.

Basically, my problem boils down to this:

  File "", line 1, in 
  File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line
19, in 
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in

  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in
__bootstrap__
ImportError: dynamic module does not define init function (init_mysql)


Has anyone solved this? I been hunting around for 2 weeks now, and my
deadline is looming grimly on the horizon :)

Geert

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

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


Huge problem gettng MySQLdb to work on my mac mini running Macosx 10.5 Leopard

2008-03-14 Thread geert
Hi all,

I have a mac mini running maocosx 10.5 leopard I want to deploy a
django project on. My backend is MySQL, and I have it running as a 64-
bit app. Of course, apache2 is also running as 64-bit.

MySQLdb installs with the usual warnings after applying the various
patches I found here and there. These patches consist of altering
_mysql.c and site.cfg.

Basically, my problem boils down to this:

  File "", line 1, in 
  File "build/bdist.macosx-10.5-i386/egg/MySQLdb/__init__.py", line
19, in 
  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 7, in

  File "build/bdist.macosx-10.5-i386/egg/_mysql.py", line 6, in
__bootstrap__
ImportError: dynamic module does not define init function (init_mysql)


Has anyone solved this? I been hunting around for 2 weeks now, and my
deadline is looming grimly on the horizon :)

Geert

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


Re: call by reference howto????

2008-03-14 Thread Antoon Pardon
On 2008-03-13, Steven D'Aprano <[EMAIL PROTECTED]> wrote:
> On Thu, 13 Mar 2008 08:54:43 +, Paul Rudin wrote:
>
>>> Whatever python has for a calling convention, it is close enough that
>>> naming it "call by reference" gives people a reasonable idea of what is
>>> going on.
>> 
>> Quite. The thing is not to get hung up with the label - but to
>> understand what actually happens.
>
> Agreed. And I think the best way to do that is to use the same terms that 
> other languages use to get very different behaviour indeed.
>
> "Python is call by reference, but this doesn't work like call by 
> reference in all the other languages I've used:
>
> def negate(n):
> n = -n
>
> x = 2
> negate(x)
> assert x == -2
>
> Is this a bug, or is Python actually call by value?"

> And now comes the explanations that Python is actually call by value, but 
> the values being copied are *pointers* (ignoring Jython, IronPython and 
> PyPy); or that Python is really call by reference, but different 
> "things" (it's never quite clear what exactly) happen depending on 
> whether the arguments are mutable or immutable;

Which is wrong. The same thing happens with mutable and immutable
objects. What one needs to understand is:

Right after the call, x and n are the same object.
After the assigment x and n no longer are the same object.
The assignment doesn't negate the original object. It creates a
new object with the negative value of the original while the latter
remains bound to x.

As long as the person who has trouble with this behaviour doesn't
understand that the assignment is not a mutating operator. Your
explanation will get you nowhere. The trouble is mosly caused
because people see a line like n = -n and interpret this more
or less as the object bound to n has the negated value after
the assignment. That is why they think x should be -2 in your
example.

> or that if you define 
> reference broadly enough, everything is a reference; or that if you 
> define value broadly enough, everything is a value; or if schools would 
> just stop teaching kiddies C and start teaching them Lisp, call by 
> reference semantics would be understood in a different way, or or or or...


> And thus, by insisting that there are two and only two calling 
> conventions, no matter how many different kinds of calling behaviour 
> actually exist, we ensure that we'll be having this same *&$%^*# argument 
> when Python 4000 comes out.

But you seem to make the same kind of mistake, but with regard to
assignments. You seem to implicitly assume there is only one kind
of assignment and by trying to start from there and trying to
explain what goes on in terms of different calling conventions
you will ensure the same argument just as well.

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


request for Details about Dictionaries in Python

2008-03-14 Thread Saideep A V S
Hello Sir,

   I am a beginner level programmer in Python. I am in search of a
function for 'On-Disk' Dictionaries which is similar to On-Disk Hash tables
in Perl (i.e., tie function in Perl).


  Could anyone help me with the concept. I have also searched the net, but
was not successful in finding any related.

Awaiting your Solutions.

Thanks in Advance.

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

Re: sorting question

2008-03-14 Thread Steven D'Aprano
On Thu, 13 Mar 2008 22:37:00 -0500, "Andrew Rekdal" wrote:

> Seems 'KEYBOARDS' works nicely

in reply to a post from "jcnbp8k" who wrote:

> > That's easy solved, the word is keyboards.

Hmmm... using my incredible powers of deduction, I predict that the word 
is "keyboards".


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


How to import custom python file in python server page (psp) ?

2008-03-14 Thread James Yu
Hi folks,

I prepared a python script for dynamically get the absolute paths of the
files in certain folder.
Then I tried to invoke that function from my web server in a .psp file like
this:

  1 
  2 
  3 asdfasdfasdfa
  4 
  5 <%
  6 import glob
  7 import os
  8 *import Helper
*  9
 10 body = ''
 11 top = 'asdfasdfasdfa'
 12 links = {}
 13 *Helper.GetLinks(top=top)
* 14 *paths = Helper.GenLinkPath(links)
* 15 body = paths
 16 %>
 17 <%=body%>
 18 
 19 

However, this is the error message I received when I open the page in a
browser:

> Mod_python error: "PythonHandler mod_python.psp"
>
> Traceback (most recent call last):
>
>   File "/usr/lib/python2.5/site-packages/mod_python/apache.py", line 299,
> in HandlerDispatch
> result = object(req)
>
>   File "/usr/lib/python2.5/site-packages/mod_python/psp.py", line 302, in
> handler
> p.run()
>
>   File "/usr/lib/python2.5/site-packages/mod_python/psp.py", line 213, in
> run
> exec code in global_scope
>
>   File "/var/www/.cyu021/.pic/index.psp", line 8, in
> import Helper
>
> ImportError: No module named Helper


*PS. I put Helper.py and index.psp in the same dir
*
Thanks in advance,
-- 
This is a UTF-8 formatted mail
---
James C.-C.Yu
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: escape string to store in a database?

2008-03-14 Thread Bryan Olson
[EMAIL PROTECTED] wrote:
> how would this work with UPDATE
> command? I get this error:
> 
> cmd = "UPDATE items SET content = ? WHERE id=%d" % id
> 
> self.cursor.execute(cmd, content)
> pysqlite2.dbapi2.ProgrammingError: Incorrect number of bindings
> supplied. The c
> rrent statement uses 1, and there are 0 supplied.

The error message implies that 'content' is an empty sequence.
Even when the SQL takes exactly one parameter, the second
argument is a sequence containing the parameter. You can use
a one-element list, written [someparam], or a one-tuple
(someparam,).


> Sqlite site doesn't give any details on using parameter bindings in
> UPDATE command, I'm
> going to look around some more..

To make effective use of Python's Sqlite3 module, I need three
references: the Python DB API v2 spec, the Sqlite3 module's doc,
and the Sqlite database doc.

 http://www.python.org/dev/peps/pep-0249/
 http://docs.python.org/lib/module-sqlite3.html
 http://www.sqlite.org/docs.html

With all three, parameter binding is still under-specified, but
only a little.

Those new to the relational model and to SQL will need sources
on those as well. On the model, I think the foundational paper
has held up well over the decades:

   Codd, E.F. "A Relational Model of Data for Large Shared
   Data Banks". /Communications of the ACM/ Volume 13 number
   6, June 1970; pages 377–387.

It is currently available on line at:

   http://www.seas.upenn.edu/~zives/03f/cis550/codd.pdf


Anyone have a particularly good and easily accessible
source to recommend on SQL?


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


Re: How to send a var to stdin of an external software

2008-03-14 Thread Benjamin Watine
Bryan Olson a écrit :
> I wrote:
>> [...] Pipe loops are tricky business.
>>
>> Popular solutions are to make either the input or output stream
>> a disk file, or to create another thread (or process) to be an
>> active reader or writer.
> 
> Or asynchronous I/O. On Unix-like systems, you can select() on
> the underlying file descriptors. (MS-Windows async mechanisms are
> not as well exposed by the Python standard library.)
> 

Hi Bryan

Thank you so much for your advice. You're right, I just made a test with 
a 10 MB input stream, and it hangs exactly like you said (on 
cat.stdin.write(myStdin))...

I don't want to use disk files. In reality, this script was previously 
done in bash using disk files, but I had problems with that solution 
(the files wasn't always cleared, and sometimes, I've found a part of 
previous input at the end of the next input.)

That's why I want to use python, just to not use disk files.

Could you give me more information / examples about the two solutions 
you've proposed (thread or asynchronous I/O) ?

Thank you !

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


Re: Spaces in path name

2008-03-14 Thread David S
Hi,

Gets me further but still seems to be issue with space after 'Program' as 
code tries to run 'C:\Program'. Don't understand what is going on here...

using "java.exe" from "C:\Program Files\Java\jdk1.6.0_01"
using "C:\Program Files\apache-ant-1.7.0\bin\ant.bat" for building
Building from E:\Red5\red5_server\install\windows
Cleaning old directories...
Compiling Java 1.5 version...
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
Traceback (most recent call last):
  File "installer.py", line 132, in 
main()
  File "installer.py", line 128, in main
builder.build()
  File "installer.py", line 70, in build
self.compile(self.ant_cmd, os.path.join(red5_root, 'build.xml'), '1.5', 
'cle
an', 'installerdist')
  File "installer.py", line 26, in compile
assert os.system('%s -quiet -Djava.target_version=%s -buildfile %s%s' % 
(ant
, version, script, args)) == 0
AssertionError


"Bryan Olson" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> David S wrote:
>> I get
>>
>> ERROR: ""C:\Program Files\apache-ant-1.7.0\bin\ant"" does not exist
>>
>> If I cut the path statement here and paste it next to a windows XP 
>> command prompt ant is invoked.
>>
>> The python code here is
>> if not os.path.isfile(ANT_CMD):
>> error('"%s" does not exist' % ANT_CMD)
>
> There you don't want the quotes within the string. On my MS-Win box:
>
>   >>> import os
>   >>> os.path.isfile(r'C:\Program Files\Windows NT\dialer.exe')
>   True
>   >>> print os.path.isfile(r'"C:\Program Files\Windows NT\dialer.exe"')
>   False
>
>
> -- 
> --Bryan 


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


Re: app runs fine with interpreter, but not under py2exe

2008-03-14 Thread Peter Otten
Doug Morse wrote:

> from multiarray import zeros
> import string
> 
> typecodes = {'Character':'c', 'Integer':'1sil', 'UnsignedInteger':'bwu',
> 'Float':'fd', 'Complex':'FD'}
> 
> def _get_precisions(typecodes):
>     lst = []
>     for t in typecodes:
>         lst.append( (zeros( (1,), t ).itemsize()*8, t) )   <-- Line 18
>     return lst
> 
> def _fill_table(typecodes, table={}):
>     for key, value in typecodes.items():
>         table[key] = _get_precisions(value)
>     return table
> 
> _code_table = _fill_table(typecodes)
>
> I can't find any reason why line 18 is throwing a "data type not
> understood" error.  It doesn't seem to have anything to do with dynamic
> importing, but I can't be sure.  I would note that "zeros" is a built-in
> function found in the "python dll" multiarray.pyd (in the Numeric module
> directory).

I don't know why, but your module seems to use numpy's multiarray instead of
Numeric's:

>>> from multiarray import zeros
>>> zeros((1,), "1")
array([0], '1')
>>> from numpy.core.multiarray import zeros
>>> zeros((1,), "1")
Traceback (most recent call last):
  File "", line 1, in 
TypeError: data type not understood

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

anydbm and sync'ing

2008-03-14 Thread Torsten Bronger
Hallöchen!

A TurboGears process opens a DB file with anydbm and keeps it open.
The the same time, this file is updated by another process.  How can
I tell the TurboGears process to fetch the new values?  my_db.sync()
didn't help -- apparently, it only *writes* to the DB file but
doesn't read new data from it.

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
  Jabber ID: [EMAIL PROTECTED]
   (See http://ime.webhop.org for further contact info.)
-- 
http://mail.python.org/mailman/listinfo/python-list


The best computer solutions

2008-03-14 Thread [EMAIL PROTECTED]
http://r8p.org/upload/213.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Spaces in path name

2008-03-14 Thread Tim Golden
David S wrote:
> Gets me further but still seems to be issue with space after 'Program' as 
> code tries to run 'C:\Program'. Don't understand what is going on here...

Slight apologies as I haven't followed this thread closely, but using 
the Acrobat Reader executable, which is, I think, good enough for the
purposes of illustration:


import os
import subprocess

filename = r"C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.exe"
doc = r"C:\Program Files\Adobe\Reader 8.0\Resource\ENUtxt.pdf"

print os.path.isfile (filename)

os.system (filename + " " + doc)

os.system ('"%s" "%s"' % (filename, doc))

subprocess.call ([filename, doc])



os.path.isfile succeeds
os.system (filename) fails as your code does
os.system ('"%s"' ...) fails even though both strings are requoted
subprocess.call (filename) succeeds

The latter, at least, is because the subprocess module
has some special-case handling for exactly this situation
on MS Windows, while os.system doesn't.

Now, ultimately, I don't know if this really helps your
exact situation but it least it should be clear what will
and what won't work. Conclusion: use subprocess.call if
you can.

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


Re: sorting question

2008-03-14 Thread Stefan Behnel
Steven D'Aprano wrote:
> On Thu, 13 Mar 2008 22:37:00 -0500, "Andrew Rekdal" wrote:
> 
>> Seems 'KEYBOARDS' works nicely
> 
> in reply to a post from "jcnbp8k" who wrote:
> 
>>> That's easy solved, the word is keyboards.
> 
> Hmmm... using my incredible powers of deduction, I predict that the word 
> is "keyboards".

Ah, come on, you spoiled it!

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


Re: Huge problem gettng MySQLdb to work on my mac mini running Macosx 10.5 Leopard

2008-03-14 Thread martin . laloux
look at
http://groups.google.be/group/comp.lang.python/browse_thread/thread/d75a491b8dbc3880/0ca1fb7f7deca194?hl=fr&lnk=gst&q=laloux#0ca1fb7f7deca194

There is a macpython list that you can consult at
http://www.nabble.com/Python---pythonmac-sig-f2970.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I iterate over items in a dict grouped by N number of elements?

2008-03-14 Thread Arnaud Delobelle
On Mar 14, 1:34 am, Noah <[EMAIL PROTECTED]> wrote:
> What is the fastest way to select N items at a time from a dictionary?
> I'm iterating over a dictionary of many thousands of items.
> I want to operate on only 100 items at a time.
> I want to avoid copying items using any sort of slicing.
> Does itertools copy items?
>
> This works, but is ugly:
>
> >>> from itertools import *
> >>> D = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 
> >>> 'j':10}
> >>> N = 3
> >>> for G in izip(*[chain(D.items(), repeat(None, N-1))]*N):

This solution matches exactly the one proposed in itertools.  The
following is an extract from 
http://docs.python.org/lib/itertools-functions.html.

Note, the left-to-right evaluation order of the iterables is
guaranteed. This makes possible an idiom for clustering a data series
into n-length groups using "izip(*[iter(s)]*n)". For data that doesn't
fit n-length groups exactly, the last tuple can be pre-padded with
fill values using "izip(*[chain(s, [None]*(n-1))]*n)".

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


Re: This actually works.

2008-03-14 Thread Dustan
On Mar 13, 6:19 pm, "Dotan Cohen" <[EMAIL PROTECTED]> wrote:
> On 14/03/2008, Dustan <[EMAIL PROTECTED]> wrote:
>
> >  you.screw()
>
> Ah, you are pushing sex pills.
>
> >  self.thank(God, encapsulation)
>
> And bibles? Interesting combination.
>
> >  not self.want_to_know(you.screw.func_code)
>
> Unsubscribe? I know better...
>
> Dotan Cohen
>
> http://what-is-what.comhttp://gibberish.co.il
> א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת
>
> A: Because it messes up the order in which people normally read text.
> Q: Why is top-posting such a bad thing?

SyntaxError: invalid syntax
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: List mutation method gotcha - How well known?

2008-03-14 Thread Dustan
On Mar 13, 1:56 pm, yoz <[EMAIL PROTECTED]> wrote:
> This will cause a hidden feature of python and the OS, known as the
> 'python easter egg', to activate - erasing all data on the hard disk and
> then reporting how many bytes of data are left.
>
> Usually "None" ;-} - This really is a 'gotcha' (Aren't you sorry you
> cheated and typed this in !!)
>
> So the answer is 5 ?

Good one. You got a smile out of me.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: request for Details about Dictionaries in Python

2008-03-14 Thread Gerardo Herzig
Saideep A V S wrote:

>Hello Sir,
>
>   I am a beginner level programmer in Python. I am in search of a
>function for 'On-Disk' Dictionaries which is similar to On-Disk Hash tables
>in Perl (i.e., tie function in Perl).
>
>
>  Could anyone help me with the concept. I have also searched the net, but
>was not successful in finding any related.
>
>Awaiting your Solutions.
>
>Thanks in Advance.
>
>Saideep
>
>  
>
I guess you are looking for shelve
http://docs.python.org/lib/module-shelve.html

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


Re: Creating a file with $SIZE

2008-03-14 Thread Bryan Olson
Robert Bossy wrote:
> Bryan Olson wrote:
>> Robert Bossy wrote:  
 Robert Bossy wrote:   
> Indeed! Maybe the best choice for chunksize would be the file's buffer
> size... 
>>
>> That bit strikes me as silly.
>>   
> The size of the chunk must be as little as possible in order to minimize 
> memory consumption. However below the buffer-size, you'll end up filling 
> the buffer anyway before actually writing on disk.

First, which buffer? The file library's buffer is of trivial size,
a few KB, and if we wanted to save even that we'd use os.open and
have no such buffer at all. The OS may set up a file-specific
buffer, but again those are small, and we could fill our file much
faster with larger writes.

Kernel buffers/pages are dynamically assigned on modern operating
systems. There is no particular buffer size for the file if you mean
the amount of kernel memory holding the written data. Some OS's
do not buffer writes to disk files; the write doesn't return until
the data goes to disk (though they may cache it for future reads).

To fill the file fast, there's a large range of reasonable sizes
for writing, but user-space buffer size - typically around 4K - is
too small. 1 GB is often disastrously large, forcing paging to and
from disk to access the memory. In this thread, Matt Nordhoff used
10MB; fine size today, and probably for several years to come.

If the OP is writing to a remote disk file to test network
throughput, there's another size limit to consider. Network file-
system protocols do not steam very large writes; the client has to
break a large write into several smaller writes. NFS version 2 had
a limit of 8 KB; version 3 removed the limit by allowing the server
to tell the client the largest size it supports. (Version 4 is now
out, in hundreds of pages of RFC that I hope to avoid reading.)


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


Re: Update pytz timezone definitions

2008-03-14 Thread Matt Nordhoff
_robby wrote:
> I am looking at using pytz in a scheduling application which will be
> used internationally. I would like to be able to update the definition
> files that pytz uses monthly or bi-monthly.
> 
> As far as I can tell, pytz seems to be updated (fairly) regularly to
> the newest tzdata, but I don't want to have to update my pytz, just
> it's definitions.
> 
> http://www.twinsun.com/tz/tz-link.htm says that pytz "compiles tz
> source into Python." Does this mean that there is already a method for
> updating the definitions?
> 
> Any help would be greatly appreciated, even if it is to point out
> something obvious which I over looked.
> 
> - Robby

pytz's build process is rather complicated (e.g., a list of all time
zones is appended to pytz/__init__.py). I really don't think it would be
worth the effort.

python-dateutil [1] [2] provides time zone support similar to pytz's,
among other features. It keeps the time zone files in a tarball and I'm
pretty sure it would be easy to update.

I still don't get why you'd want to go to the effort though. Upgrading
the whole package is easy. It's not like pytz gets a new API every version.

[1] 
[2] 
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Dave Kuhlman a écrit :
> Arnaud Delobelle wrote:
> 
>> 4.  Both points above follow from the fact that foo.bar is really a
>> function call that returns a (potentially) new object: in fact what
>> really happens is something like
> 
> Arnaud and Imri, too -
> 
> No.  foo.bar is *not* really a function/method call.
> 
>> Foo.__dict__['bar'].__get__(foo, Foo).
>>
>> So every time foo.bar is executed an object is (or may be) created,
>> with a new id.
>>
>> HTH
> 
> I appreciate the help, but ...
> 
> Actually, it does not help, because ...
> 
> My understanding is that foo.bar does *not* create a new object.

Given your implementation, foo.bar *does* create a new object on each 
lookup. This object is an instancemethod instance, that is, a thin 
wrapper around Foo, foo and Foo.__dict__['bar']. Foo.__dict__['bar'] is 
a function instance, it's an attribute of class Foo, and the function 
class implements the descriptor protocol. So when bar is looked on a Foo 
instance, bar.__get__ is called with foo and Foo as arguments, and 
returns an instancemethod instance that has .im_self bound to foo, 
.im_class bound to Foo, and .im_func bound to Foo.__dict__['bar'].


>  All it
> does is return the value of the bar attribute of object foo.

Yes. But since function bar is a descriptor, foo.bar is a computed 
attribute, which value is a newly created instancemethod object.

>  What new
> object is being created?

An instancemethod.

> If I have:
> 
> class Foo(object):
> def bar(self): pass
> 
> 
> And I do:
> 
> foo = SomeClass()
> 
> then:
> 
> foo.bar
> 
> should return the same (identical) object everytime, no?  yes?

No.

> I'm still confused.

Then you have to learn how attribute lookup works in Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Mel a écrit :
(snip)
> (What Diez said.)  From what I've seen, f.bar creates a bound method 
> object by taking the unbound method Foo.bar and binding its first 
> parameter with f. 

Nope. it's Foo.__dict__['bar'] (that is, the function bar defined in the 
namespace of class Foo) that creates a bound instancemethod object when 
looked up on a Foo instance - or an unbound instancemethod object when 
looked up on Foo. FWIW, types.UnboundMethodType and types.MethodType are 
both aliases to instancemethod type.


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


Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Erik Max Francis a écrit :
> Dave Kuhlman wrote:
> 
>> Basically, the above code is saying that foo.foobar is not the same as
>> getattr(foo, 'foobar').
> 
> Python promises that the behavior is the same.  It does not promise that 
> the _objects_ will be the same, which is what `is` determines.  That is, 
> you're not doing a useful test here.

FWIW, two methods are "the same" if they have identical (function, obj, 
cls) attributes. Looks like the equality test is correctly implemented:

 >>> foo.bar == foo.bar
True

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


Urgent : How to do memory leaks detection in python ?

2008-03-14 Thread Pradeep Rai
Dear All,

I am working on the python tools that process a huge amount of GIS data.
These tools encountering the problem of memory leaks.

Please suggest what are the different ways to detect the memory leaks in
python ?

This is very critical problem for me. Help needed urgently.

Thanks & Regards,

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

find string in file

2008-03-14 Thread fminervino
Hi friends !!

I'm neophite about python, my target is to create a programa that
find  a specific string in text file.
How can do it?

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


Urgent : How to do memory leaks detection in python ?

2008-03-14 Thread Pradeep Rai
Dear All,

I am working on the python tools that process a huge amount of GIS data.
These tools encountering the problem of memory leaks.

Please suggest what are the different ways to detect the memory leaks in
python ?

This is very critical problem for me. Help needed urgently.

Thanks & Regards,

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

Re: find string in file

2008-03-14 Thread kaerbuhez
On 14 mar, 14:25, [EMAIL PROTECTED] wrote:
> Hi friends !!
>
> I'm neophite about python, my target is to create a programa that
> find  a specific string in text file.
> How can do it?
>
> Thanks
> fel

$ cat text.txt
aaa
bbb
ccc
ddd
aaa bbb
ccc ddd
aaa bbb ccc ddd
aaa eee
bbb eee
ccc eee
ddd eee
$ cat bin/find_string.py
import sys
file_name=sys.argv[1]
searched_string=sys.argv[2]
result= [(line_number+1, line) for line_number, line in
enumerate(open(file_name)) if searched_string in line]
print result
$ python bin/find_string.py text.txt eee
[(8, 'aaa eee\n'), (9, 'bbb eee\n'), (10, 'ccc eee\n'), (11, 'ddd eee
\n')]
$ python bin/find_string.py text.txt aaa
[(1, 'aaa\n'), (5, 'aaa bbb\n'), (7, 'aaa bbb ccc ddd\n'), (8, 'aaa eee
\n')]
$ python bin/find_string.py text.txt ddd
[(4, 'ddd\n'), (6, 'ccc ddd\n'), (7, 'aaa bbb ccc ddd\n'), (11, 'ddd
eee\n')]
$
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: find string in file

2008-03-14 Thread Tim Chase
> I'm neophite about python, my target is to create a programa that
> find  a specific string in text file.
> How can do it?

 >>> FNAME1 = 'has.txt'
 >>> FNAME2 = 'doesnt_have.txt'
 >>> TEXT = 'thing to search for'
 >>> TEXT in file(FNAME1).read()
True
 >>> TEXT in file(FNAME2).read()
False

or that may not be what your teacher wants, but if you give the 
homework problem and what you've tried, we might be able to give 
you some more quality guidance. :)

The above is *really* *bad* code...horribly suboptimal especially 
as files get large.  It only returns a boolean value.  You might 
prefer to enumerate the file's contents and, if any line contains 
the search-text, return that line offset without reading the rest 
of the file.

-tkc



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


Urgent : How to do memory leaks detection in python ?

2008-03-14 Thread Pradeep Rai
Dear All,

I am working on the python tools that process a huge amount of GIS data.
These tools encountering the problem of memory leaks.

Please suggest what are the different ways to detect the memory leaks in
python ?

This is very critical problem for me. Help needed urgently.

Thanks & Regards,

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

Re: find string in file

2008-03-14 Thread Michael Wieher
2008/3/14, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> Hi friends !!
>
> I'm neophite about python, my target is to create a programa that
> find  a specific string in text file.
> How can do it?
>
> Thanks
> fel
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

If your only goal is to find a string in a file, just use grep
>grep -i 'string' filename

its a standard linux command =)

But if you must use python

data=file(filename,'r').read()
if string in data:
   return True
return False
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: request for Details about Dictionaries in Python

2008-03-14 Thread Gerardo Herzig
Saideep A V S wrote:

>Hello Sir,
>
>   Thank You a ton. I was looking for this function. As far what I've
>understood from the "Shelve" module is that, there would be no memory
>wastage and the whole transactions would be done from and to the file we
>specify. Am I right?.
>
>  My actual task is to build a basic dictionary for two languages and store
>word and its meaning in another language in a file and must be able to
>access it through on-disk Hash tables. as these would be saving memory space
>for a huge data.
>
>so, I hope shelve is the right one, I am searching for., I shall try out
>with the function.
>
>
>Thank You once again.
>
>Cheers,
>Saideep
>
>  
>
Plz remember allways reply to the python group also. They are many many 
many ones to know more than i do!
Well, i dont quite think that it would be "no memory wastage", since 
when you read/write from disk, there is memory involved in the process.

I *really* believe that, when data goes huge, a *real* database (like 
postgres, and others) has to come and play the game.

Hope that helps

Gerardo


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


Re: find string in file

2008-03-14 Thread Roman Dodin


On 14 mar, 14:25, [EMAIL PROTECTED] wrote:
>> Hi friends !!
>>
>> I'm neophite about python, my target is to create a programa that
>> find  a specific string in text file.
>> How can do it?
>>
>> Thanks
>> fel
>> 
>
>
>   
One more way to do this

f = codecs.open("log.txt", 'r', "utf_16_le")
lines = f.readlines()
for line in lines:
   if(line.find("my string to find")!=-1):
  print line
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: request for Details about Dictionaries in Python

2008-03-14 Thread Michael Wieher
2008/3/14, Gerardo Herzig <[EMAIL PROTECTED]>:
>
> Saideep A V S wrote:
>
> >Hello Sir,
> >
> >   Thank You a ton. I was looking for this function. As far what I've
> >understood from the "Shelve" module is that, there would be no memory
> >wastage and the whole transactions would be done from and to the file we
> >specify. Am I right?.
> >
> >  My actual task is to build a basic dictionary for two languages and
> store
> >word and its meaning in another language in a file and must be able to
> >access it through on-disk Hash tables. as these would be saving memory
> space
> >for a huge data.
> >
> >so, I hope shelve is the right one, I am searching for., I shall try out
> >with the function.
> >
> >
> >Thank You once again.
> >
> >Cheers,
> >Saideep
> >
> >
> >
> Plz remember allways reply to the python group also. They are many many
> many ones to know more than i do!
> Well, i dont quite think that it would be "no memory wastage", since
> when you read/write from disk, there is memory involved in the process.
>
> I *really* believe that, when data goes huge, a *real* database (like
> postgres, and others) has to come and play the game.
>
> Hope that helps
>
> Gerardo
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>

I'm not sure if a well-written file/seek/read algorithm is faster than a
relational database...
sure a database can store relations and triggers and all that, but if he's
just doing a lookup for static data, then I'm thinking disk IO is faster for
him?  not sure
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Urgent : How to do memory leaks detection in python ?

2008-03-14 Thread Michael Wieher
2008/3/14, Pradeep Rai <[EMAIL PROTECTED]>:
>
> Dear All,
>
> I am working on the python tools that process a huge amount of GIS data.
> These tools encountering the problem of memory leaks.
>
> Please suggest what are the different ways to detect the memory leaks in
> python ?
>
> This is very critical problem for me. Help needed urgently.
>
> Thanks & Regards,
>
> Pradeep
>

Python doesn't have memory leaks.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: app runs fine with interpreter, but not under py2exe

2008-03-14 Thread Doug Morse
Peter,

Genius!  You nailed it -- thanks!

py2exe is apparently getting confused by the fact that packages "Numeric" and
"numpy" both have files multiarray.pyd and umath.pyd.  It copies just one of
each -- from $PYTHONHOME/Lib/site-packages/numpy/core -- and puts both of them
into the top-level of the created "dist" directory.  Also, there are no such
files as multiarray.pyc and umath.pyc in my python installation, but py2exe
seems to create these (in the dist and dist/numpy/core directories) -- they
are small (e.g., 526 bytes) and I'm guessing that they are stubs that simply
point python to the matching .pyd that py2exe relocated.

So, by using the --skip-archive option to py2exe (i.e., python setup.py py2exe
--skip-archive) to create the dist and build directories, and then within the
dist directory hierarchy removing all the occurrances of multiarray.pyc and
umath.pyc, and then moving dist/multiarray.pyd and dist/umath.pyd to the
dist/numpy/core directory, and finally by copying multiarray.pyd and umath.pyd
from $PYTHONHOME/Lib/site-packages/Numeric to the dist directory, I am able to
get my application to run correctly and as a standalone executable.  HOORAH!!!

Just for completeness and perhaps a bit of additional clarity, here's a
limited directory listing of what the steps in the previous paragraph produce:

morse> find dist | egrep "(multia|umath)" | xargs ls -l
-rwxr-xr-x 1 morse None  26624 Nov 28  2006 dist/multiarray.pyd
-rwxr-xr-x 1 morse None 348160 Nov  8 16:16 dist/numpy/core/multiarray.pyd
-rwxr-xr-x 1 morse None 192512 Nov  8 16:16 dist/numpy/core/umath.pyd
-rwxr-xr-x 1 morse None  54272 Nov 28  2006 dist/umath.pyd
morse>

(This is still WinXP; I'm just using the Cygwin bash and fileutils here.
Also, note that there are NO multiarray.pyc or umath.pyc files.)

So, my next step will be to try to not use the --skip-archive option and then
make these same modifications regarding multiarray.pyd and umath.pyd to the
py2exe-generated library.zip file and see if I can get things running that way
as well (and in so doing reduce my "dist" directory by about 10mg).  I may
also try creating a dist/Numeric subdirectory and moving dist/multiarray.pyd
and dist/umath.pyd to this dist/Numeric subdirectory -- for the goal of more
accurately mirroring the actual file/directory structure found in
$PYTHONHOME/Lib/site-packages.

Again, thanks to everyone for their assistance, esp. Harald and Peter.

Is this something I should pursue getting the py2exe folks to fix / work with
them on fixing?  In investigating this issue, I noted that a lot of other
py2exe problems seem to revolve around confusions when duplicate files exist
in different modules.  I wouldn't thinking that getting py2exe to pay better
attention to the containing modules when building it's dependency tree would
be that difficult (or is it)?

Cheers,
Doug


On Fri, 14 Mar 2008 12:39:23 +0100, Peter Otten <[EMAIL PROTECTED]> wrote:
>  Doug Morse wrote:
> 
> > from multiarray import zeros
> > import string
> > 
> > typecodes = {'Character':'c', 'Integer':'1sil', 'UnsignedInteger':'bwu',
> > 'Float':'fd', 'Complex':'FD'}
> > 
> > def _get_precisions(typecodes):
> >     lst = []
> >     for t in typecodes:
> >         lst.append( (zeros( (1,), t ).itemsize()*8, t) )   <-- Line 18
> >     return lst
> > 
> > def _fill_table(typecodes, table={}):
> >     for key, value in typecodes.items():
> >         table[key] = _get_precisions(value)
> >     return table
> > 
> > _code_table = _fill_table(typecodes)
> >
> > I can't find any reason why line 18 is throwing a "data type not
> > understood" error.  It doesn't seem to have anything to do with dynamic
> > importing, but I can't be sure.  I would note that "zeros" is a built-in
> > function found in the "python dll" multiarray.pyd (in the Numeric module
> > directory).
> 
>  I don't know why, but your module seems to use numpy's multiarray instead of
>  Numeric's:
> 
> >>> from multiarray import zeros
> >>> zeros((1,), "1")
>  array([0], '1')
> >>> from numpy.core.multiarray import zeros
> >>> zeros((1,), "1")
>  Traceback (most recent call last):
>File "", line 1, in 
>  TypeError: data type not understood
> 
>  Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to send a var to stdin of an external software

2008-03-14 Thread Floris Bruynooghe
On Mar 14, 11:37 am, Benjamin Watine <[EMAIL PROTECTED]> wrote:
> Bryan Olson a écrit :
>
> > I wrote:
> >> [...] Pipe loops are tricky business.
>
> >> Popular solutions are to make either the input or output stream
> >> a disk file, or to create another thread (or process) to be an
> >> active reader or writer.
>
> > Or asynchronous I/O. On Unix-like systems, you can select() on
> > the underlying file descriptors. (MS-Windows async mechanisms are
> > not as well exposed by the Python standard library.)
>
> Hi Bryan
>
> Thank you so much for your advice. You're right, I just made a test with
> a 10 MB input stream, and it hangs exactly like you said (on
> cat.stdin.write(myStdin))...
>
> I don't want to use disk files. In reality, this script was previously
> done in bash using disk files, but I had problems with that solution
> (the files wasn't always cleared, and sometimes, I've found a part of
> previous input at the end of the next input.)
>
> That's why I want to use python, just to not use disk files.
>
> Could you give me more information / examples about the two solutions
> you've proposed (thread or asynchronous I/O) ?

The source code of the subprocess module shows how to do it with
select IIRC.  Look at the implementation of the communicate() method.

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


Re: escape string to store in a database?

2008-03-14 Thread jim-on-linux

> > --
> > Carsten
> > Haesehttp://informixdb.sourceforge.net
>
> Thanks for the reply, Carsten, how would
> this work with UPDATE command? I get this
> error:
>
> cmd = "UPDATE items SET content =
> ? WHERE id=%d" % id

try this;

("update items set contents = (?) where id 
=(?)", [ x, y] )
put your data in a list 

or

("update items set contents = (?) where id 
=%d ", [ x] )


below statement "uses 1" refers to the one 
(?) , 0 supplied, means no list or none in 
list.

jim-on-linux
http://www.inqvista.com
>
> self.cursor.execute(cmd, content)
> pysqlite2.dbapi2.ProgrammingError:
> Incorrect number of bindings supplied. The
> c
> rrent statement uses 1, and there are 0
> supplied.
>
> Sqlite site doesn't give any details on
> using parameter bindings in UPDATE
> command, I'm
> going to look around some more.. -ak
-- 
http://mail.python.org/mailman/listinfo/python-list


how to parse a wiki markup file

2008-03-14 Thread Vinay Aiya
hello,
Anyone can help me how to extract the data from wiki file using python
i.e is there any WIKIPARSER package and documentation to from parsing on
wiki file .
-- 
http://mail.python.org/mailman/listinfo/python-list

RE: Urgent : How to do memory leaks detection in python ?

2008-03-14 Thread Bronner, Gregory
This is not entirely true:
Symptoms of increasing memory usage are either because
 
a) you are keeping too much data around in user accessable memory
(likely)
b) you are creating self-referential structures that are not garbage
collected (also likely)
c) You have memory leaks in underlying C extension modules.
 
For category a), you are on your own.
For category b), you can use various methods in the gc module to print
out everything that is still 'live'. You can also recompile python to
build a list of all objects that are still live.
For category c), a tool like valgrind or purify often helps. Create a
simple example rather than trying to run it on your whole application.
 
 



From: Michael Wieher [mailto:[EMAIL PROTECTED] 
Sent: Friday, March 14, 2008 10:16 AM
To: [email protected]
Subject: Re: Urgent : How to do memory leaks detection in python ?




2008/3/14, Pradeep Rai <  >: 

Dear All,



I am working on the python tools that process a huge amount of
GIS data. These tools encountering the problem of memory leaks. 



Please suggest what are the different ways to detect the memory
leaks in python ?



This is very critical problem for me. Help needed urgently.



Thanks & Regards,

Pradeep


Python doesn't have memory leaks.


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
- - - -

This message is intended only for the personal and confidential use of the 
designated recipient(s) named above.  If you are not the intended recipient of 
this message you are hereby notified that any review, dissemination, 
distribution or copying of this message is strictly prohibited.  This 
communication is for information purposes only and should not be regarded as an 
offer to sell or as a solicitation of an offer to buy any financial product, an 
official confirmation of any transaction, or as an official statement of Lehman 
Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  
Therefore, we do not represent that this information is complete or accurate 
and it should not be relied upon as such.  All information is subject to change 
without notice.


IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this 
communication (including any attachments) is not intended or written to be used 
and cannot be used for the purpose of (i) avoiding U.S. tax related penalties 
or (ii) promoting, marketing or recommending to another party any transaction 
or matter addressed herein.
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: app runs fine with interpreter, but not under py2exe

2008-03-14 Thread Doug Morse
Hi,

Well, my attempt to not use the --skip-archive option didn't get very far,
as I quickly noticed that "library.zip" does NOT contain ANY .pyd files.
I'm guessing that they can't be in library.zip for a reason (i.e., they are
DLL files, essentially, and thus must be readily available to be loaded
into memory).

Is there a work-around for this, then?  That is, is there a way to either
(a) tell py2exe how to *correctly* handle multiple multiarray.pyd and
umath.pyd files or (b) perhaps rename one set of the .pyd files -- say the
numpy/core versions -- to say multiarray2.pyd and umath2.pyd, and then
manual create the "stub"-like .pyc files that py2exe creates to point to
these alternate .pyd files and then place these stubs in
library.zip/numpy/core?  Or am I just hoping for too much here and am going
to be stuck with using the --skip-archive option?

Thanks,
Doug


On Fri, 14 Mar 2008 14:37:32 + (UTC), Doug Morse <[EMAIL PROTECTED]> wrote:
>  Peter,
> 
>  Genius!  You nailed it -- thanks!
> 
>  py2exe is apparently getting confused by the fact that packages "Numeric"
>  ...
>  
> 
> So, my next step will be to try to not use the --skip-archive option and
> then make these same modifications regarding multiarray.pyd and umath.pyd
> to the py2exe-generated library.zip file and see if I can get things
> running that way as well (and in so doing reduce my "dist" directory by
> about 10mg).  I may also try creating a dist/Numeric subdirectory and
> moving dist/multiarray.pyd and dist/umath.pyd to this dist/Numeric
> subdirectory -- for the goal of more accurately mirroring the actual
> file/directory structure found in $PYTHONHOME/Lib/site-packages.
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: catching object

2008-03-14 Thread Igor V. Rafienko
[ [EMAIL PROTECTED] ]


[ ... ]

> I think inheritance is meant in reference to the Exception tree here. So, 
> the uppermost class is `BaseException`. Python 3 gives this exception 
> when trying to handle `object`::
> 
> TypeError: catching classes that do not inherit from BaseException is 
> not allowed


I realise that exceptions should inherit from Exception, but the
question is more "why isn't an instance of ValueError a match for
object, when ValueError is a subclass of object (at least in 2.5)

[ ... ]


> > So, why doesn't object match ValueError (or any other exception for that
> > matter). I am aware of "except:", but in my particular situation it is
> > eh... unsuitable.
> 
> Why so?


I am writing a function that takes a function and an exception list
arguments and returns a new function that calls the original while
trapping the specified arguments. One of the applications is to make a
wrapper that ignores all of the exceptions. I thought that specifying
the exception list containing object would suffice to cover that.
Alas, no joy.

[ ... ]





ivr
-- 
<+Kaptein-Dah> igorr: for få parenteser
<+Kaptein-Dah> igorr: parenteser virker som lubrication under iterasjon
<+Kaptein-Dah> igorr: velkjent
-- 
http://mail.python.org/mailman/listinfo/python-list

%x unsigned?

2008-03-14 Thread Hrvoje Niksic
The %x conversion specifier is documented in
http://docs.python.org/lib/typesseq-strings.html as "Unsigned
hexadecimal (lowercase)."  What does "unsigned" refer to?

>>> '0x%x' % 10
'0xa'
>>> '0x%x' % -10
'0x-a'

Is this a bug or is %x misdocumented?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %x unsigned?

2008-03-14 Thread D'Arcy J.M. Cain
On Fri, 14 Mar 2008 16:00:07 +0100
Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> The %x conversion specifier is documented in
> http://docs.python.org/lib/typesseq-strings.html as "Unsigned
> hexadecimal (lowercase)."  What does "unsigned" refer to?
> 
> >>> '0x%x' % 10
> '0xa'
> >>> '0x%x' % -10
> '0x-a'
> 
> Is this a bug or is %x misdocumented?

I think it is working exactly as documented.  It says that it displays
unsigned numbers.  If you give it a negative number you get undefined
behaviour.  Are you saying that the docs could be a little clearer?

-- 
D'Arcy J.M. Cain <[EMAIL PROTECTED]> |  Democracy is three wolves
http://www.druid.net/darcy/|  and a sheep voting on
+1 416 425 1212 (DoD#0082)(eNTP)   |  what's for dinner.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %x unsigned?

2008-03-14 Thread Richard Brodie

"Hrvoje Niksic" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> The %x conversion specifier is documented in
> http://docs.python.org/lib/typesseq-strings.html as "Unsigned
> hexadecimal (lowercase)."  What does "unsigned" refer to?

It's obsolete, a fallout of int/long int unification.
See http://www.python.org/dev/peps/pep-0237/



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


ANN: Leo 4.4.8 beta 2 released

2008-03-14 Thread Edward K Ream
Leo 4.4.8 beta 2 is available at:
http://sourceforge.net/project/showfiles.php?group_id=3458&package_id=29106

This version features a new ipython plugin that provides a two-way bridge
between Leo and IPython.  See 
http://webpages.charter.net/edreamleo/IPythonBridge.html

Leo is a text editor, data organizer, project manager and more. See:
http://webpages.charter.net/edreamleo/intro.html

The highlights of Leo 4.4.8:

- Leo's source code is now managed by bzr.
  See the Bzr link below.
- Leo's discussion is now hosted by Google Groups:
  See the Forum link below.
- The first, third, fifth etc. arguments to g.es and g.es_print
  can now be translated using Python's gettext.gettext function.
- Completed ILeo: a bridge between IPython and Leo.
  See http://webpages.charter.net/edreamleo/IPythonBridge.html
- Added support for arguments to minibuffer commands.
- @menu trees can now refer to commands created by
  @command and @button nodes
- Added support for common @commands nodes in settings files.

Links:
--
Leo:  http://webpages.charter.net/edreamleo/front.html
Forum:http://groups.google.com/group/leo-editor
Download: http://sourceforge.net/project/showfiles.php?group_id=3458
Bzr:  http://code.launchpad.net/leo-editor/
Quotes:   http://webpages.charter.net/edreamleo/testimonials.html

Edward K. Ream   email:  [EMAIL PROTECTED]
Leo: http://webpages.charter.net/edreamleo/front.html



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


Re: urllib proxy support confusion

2008-03-14 Thread Mark Dickinson
On Mar 11, 11:35 am, Grant Edwards <[EMAIL PROTECTED]> wrote:
> Reading through the doc athttp://docs.python.org/lib/module-urllib.html,
> there are several paragraphs (including code examples) showing
> how you specify what proxies to use when calling urlopen():

See http://bugs.python.org/issue2288
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: %x unsigned?

2008-03-14 Thread Jonathan Gardner
On Mar 14, 8:00 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> The %x conversion specifier is documented 
> inhttp://docs.python.org/lib/typesseq-strings.htmlas "Unsigned
> hexadecimal (lowercase)."  What does "unsigned" refer to?
>
> >>> '0x%x' % 10
> '0xa'

Somewhat unrelated, but have you seen the # modifier?
>>> '%#x' % 10
'0xa'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Monitoring SSHd and web servers?

2008-03-14 Thread Jonathan Gardner
On Mar 13, 11:32 pm, Gilles Ganault <[EMAIL PROTECTED]> wrote:
> I'd like to monitor connections to a remote SSH and web server. Does
> someone have some code handy that would try to connect every 5mn, and
> print an error if the script can't connect?

from time import sleep
while True:
  # Try to connect. May want to spawn a subprocess running a simple
shell script
  # Handle success / failure appropriately
  sleep 5*60 # Sleep for 5 minutes

What you monitor is up to you. At a basic level, you can see if the
server is accepting connections. At a higher level, see if you can get
a page or see if you can login as a specific person. At a higher
level, you may want to check what is on the page or what happens when
you log in. It's all up to you.


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


Re: find string in file

2008-03-14 Thread eMko
An of course, you can use a regular expression. (Module "re").
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Monitoring SSHd and web servers?

2008-03-14 Thread Shane Geiger
I would recommend using a tried-and-true solution for making sure your
uptime of various services is maximized (if that's what your goal is).

Running a local "daemon-monitoring daemon" is one option--monit does a
good job.  Checking services over the network, as nagios does well, is
another solution.



Jonathan Gardner wrote:
> On Mar 13, 11:32 pm, Gilles Ganault <[EMAIL PROTECTED]> wrote:
>   
>> I'd like to monitor connections to a remote SSH and web server. Does
>> someone have some code handy that would try to connect every 5mn, and
>> print an error if the script can't connect?
>> 
>
> from time import sleep
> while True:
>   # Try to connect. May want to spawn a subprocess running a simple
> shell script
>   # Handle success / failure appropriately
>   sleep 5*60 # Sleep for 5 minutes
>
> What you monitor is up to you. At a basic level, you can see if the
> server is accepting connections. At a higher level, see if you can get
> a page or see if you can login as a specific person. At a higher
> level, you may want to check what is on the page or what happens when
> you log in. It's all up to you.
>
>
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

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


Re: Need Script For read multiple files(.txt) from a folder

2008-03-14 Thread Jeff Schwab
Chris wrote:
> On Mar 14, 8:36 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>> On Thu, 13 Mar 2008 21:28:18 -0700 (PDT), jai_python
>> <[EMAIL PROTECTED]> declaimed the following in comp.lang.python:
>>
>>> hi frenz I  Need a Python Script For read multiple files(.txt) from a
>>> folder and write it in a single text file
>> If you are on windows, just open a command prompt and use the
>> standard copy command...
>>
>> C:\Documents and Settings\Dennis Lee Bieber>copy /?
...
> If you want to go that route you could also do: type *.txt >
> output_file.txt

On Unix, cygwin, etc:

   cat dir/*.txt > output.txt

Or if you need "deep" copy:

   cat $(find dir -name '*.txt') > output.txt

You could write a portable solution in Python (as in Martin Laloux's 
post), but most modern command-line environments have similar (but not 
identical) support for globbing and redirecting files.  If you're 
getting the glob pattern from a user, they may expect subtly 
platform-dependent behaviors, in which case portability might not as 
important as native feel.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: request for Details about Dictionaries in Python

2008-03-14 Thread Matt Nordhoff
Michael Wieher wrote:
> I'm not sure if a well-written file/seek/read algorithm is faster than a
> relational database...
> sure a database can store relations and triggers and all that, but if
> he's just doing a lookup for static data, then I'm thinking disk IO is
> faster for him?  not sure

I would think that rolling your own solution would get complicated
enough that it would be easier to just use SQLite or something. If you
wanted to go to the effort, you could probably get something faster, but
if SQLite is fast enough, who cares?

Hmm, if Perl's on-disk hash tables are good, maybe someone should port
them to Python, or maybe someone already has.

Also, for translations, maybe there's a good library already available.
-- 
-- 
http://mail.python.org/mailman/listinfo/python-list


Thousand Seperator

2008-03-14 Thread ewanfisher
I'm trying to find some code that will turn:

100 -> 100
1000 -> 1,000
100 -> 1,000,000
-1000 -> -1,000

I know that can be done using a regular expression. In Perl I would do
something like:

sub thousand {
$number = reverse $_[0];
$number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;
return scalar reverse $number;
}

But I cannot find how to do this in Python.

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


Re: request for Details about Dictionaries in Python

2008-03-14 Thread Tim Golden
Matt Nordhoff wrote:
> Michael Wieher wrote:
>> I'm not sure if a well-written file/seek/read algorithm is faster than a
>> relational database...
>> sure a database can store relations and triggers and all that, but if
>> he's just doing a lookup for static data, then I'm thinking disk IO is
>> faster for him?  not sure
> 
> I would think that rolling your own solution would get complicated
> enough that it would be easier to just use SQLite or something. If you
> wanted to go to the effort, you could probably get something faster, but
> if SQLite is fast enough, who cares?

I would concur with this, in general. It may be that, for some
very particular situations some specialised storage format is
superior, but it's *very* easy to start writing your lean and
mean data storage / algorithm / thingy only to run into *exactly*
the same issues which the guys who wrote the existing ones have
already hit and solved. Problems scaling; concurrency; robustness
to error conditions and network / hardware issues &c.

And in any case, the usual wisdom applies here: rather than guess
which is faster, try it. (There is no "guess": only "try" ;) Using
say SQLite (possibly in memory mode) and get some figures. Then
do the same with a shelve solution or some prototype of your own
devising and see where the gains are.

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


Re: Thousand Seperator

2008-03-14 Thread Paul Rubin
[EMAIL PROTECTED] writes:
> 100 -> 100
> 1000 -> 1,000
> 100 -> 1,000,000
> -1000 -> -1,000

def sep(n):
  if n<0: return '-' + sep(-n)
  if n<1000: return str(n)
  return '%s,%03d' % (sep(n//1000), n%1000)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thousand Seperator

2008-03-14 Thread Eddie Corns
[EMAIL PROTECTED] writes:

>I'm trying to find some code that will turn:

>100 -> 100
>1000 -> 1,000
>100 -> 1,000,000
>-1000 -> -1,000

>I know that can be done using a regular expression. In Perl I would do
>something like:

>sub thousand {
>$number = reverse $_[0];
>$number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;
>return scalar reverse $number;
>}

>But I cannot find how to do this in Python.

Look at the locale module.  If you're producing the numbers yourself then they
get printed in that format otherwise you can convert them to numbers first.

Eddie

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


Some thoughts on defining built-in types

2008-03-14 Thread Leszek Dubiel







To define a one-element set you write: 

    >>> set([1])

To define one-element tuple you write: 

    >>> (1,)

Wouldn't it be better to write: 
    
    >>> tuple(1)

? To make life easy Python gives us some powerfull syntax to define
some builtin types. For example: 
    
    >>> [1, 2]            # defines a list
    >>> (1, 2, 3)            # defines a tuple
    >>> { 'a': 1, 'b': 34 }        # defines a hash

But some of chars [], (), {} are used in arithmetic expressions, for
example: 

    >>> x = (1 + 3) / 2
    >>> p = mylist[3]
    >>> v = hsh['a']

and Python is clever enough to distingquish between (1 + 3) and (1, 3).
Objects of type "set" and "tuple" seem to be odd, because: 

    -- you have to use "set" to define all sets
    -- you have to use ugly (1,) to define a tuple

For me it would be much clearer to: 

    -- have functions set(), tuple(), list(), dictionary() for special
purposes
    -- have some special syntax to define these types

I think that Python interpreter is smart enouth to dsitinguish between
arithmetic _expression_ (1) and tuple (1,), so it could probably
distinguish "set" and "dictionary":
    
    >>> {'a', 'b', 'c'}        # it is a set
    >>> {'a':1, 'b':2, 'c':3}    # it is a dictionary




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

Re: Problem with exec

2008-03-14 Thread Justus Schwabedal

On Mar 14, 2008, at 4:41 AM, [EMAIL PROTECTED] wrote:

> On Mar 14, 9:47 am, Justus Schwabedal <[EMAIL PROTECTED]>
> wrote:
> [snipped]
>> However when I do this:
>>
>> bash-3.2$ cat execBug2.py
>> #! /usr/bin/python
>> header="""
>> from scipy import randn
>> def f():
>> return randn()
>> """
>> def g():
>> exec header
>> return f()
>> print "g() =",g()
>> bash-3.2$ ./execBug2.py
>> g() =
>> Traceback (most recent call last):
>>   File "./execBug2.py", line 10, in 
>> print "g() =",g()
>>   File "./execBug2.py", line 9, in g
>> return f()
>>   File "", line 4, in f
>> NameError: global name 'randn' is not defined
>> bash-3.2$ ???
>>
>> I get this global name error. I can fix it with adding some line like
>> "global randn" but I don't want to do this. I want to do exactly  
>> what  I wrote: Import the function scipy.randn in the local  
>> namespace of the
>>
>> function "g" so that "return f()" makes sense. Can anybody help me  
>> out?
>> Yours Justus
>
> Maybe using an explicit namespace is good enough for your needs:
>
> #! /usr/bin/python
> header="""
> from scipy import randn
> def f():
> return randn()
> """
> def g():
> n = {}
> exec header in n
> return n['f']()
> print "g() =",g()
>
>
> (i don't understand the issues, but I can cut-and-paste with the best
> of them)
> -- 
> http://mail.python.org/mailman/listinfo/python-list

That's what I was looking for: It's probably even a faster solution  
than declaring all the imports global, isn't it?

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


Re: Thousand Seperator

2008-03-14 Thread Shane Geiger
http://aspn.activestate.com/ASPN/docs/ActivePython/2.4/python/lib/decimal-recipes.html
 



Eddie Corns wrote:
> [EMAIL PROTECTED] writes:
>
>   
>> I'm trying to find some code that will turn:
>> 
>
>   
>> 100 -> 100
>> 1000 -> 1,000
>> 100 -> 1,000,000
>> -1000 -> -1,000
>> 
>
>   
>> I know that can be done using a regular expression. In Perl I would do
>> something like:
>> 
>
>   
>> sub thousand {
>>$number = reverse $_[0];
>>$number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;
>>return scalar reverse $number;
>> }
>> 
>
>   
>> But I cannot find how to do this in Python.
>> 
>
> Look at the locale module.  If you're producing the numbers yourself then they
> get printed in that format otherwise you can convert them to numbers first.
>
> Eddie
>
>   


-- 
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

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


"Open with IDLE" Missing

2008-03-14 Thread fireball
I installed Parallels Desktop and Win XP Pro on my iMac for testing 
purposes. I installed Python 2.5.2, wxPython, and PythonCard. I cannot 
get the "Open with IDLE" in an Explorer window to work. All the registry 
entries are there too.

Any ideas?

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


RIP: Joseph Weizenbaum

2008-03-14 Thread Aahz
Creator of Eliza:

http://www-tech.mit.edu/V128/N12/weizenbaum.html
-- 
Aahz ([EMAIL PROTECTED])   <*> http://www.pythoncraft.com/

"It is easier to optimize correct code than to correct optimized code."
--Bill Harlan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Monitoring SSHd and web servers?

2008-03-14 Thread Pacman
Gilles Ganault <[EMAIL PROTECTED]> wrote:
>I'd like to monitor connections to a remote SSH and web server. Does
>someone have some code handy that would try to connect every 5mn, and
>print an error if the script can't connect?

This script has been pretty reliable for us for the past few years,
much more reliable than the expect script it replaced.

  #!/usr/bin/python
  import sys
  import pexpect 
  quiet = open("/dev/null", "rw")
  sys.stdin = quiet
  sys.stdout = quiet
  sys.stderr = quiet 
  smtp = pexpect.spawn("telnet " + sys.argv[1] + " 25")
  smtp.expect('220', timeout=120)
  smtp.sendline("quit\n^]q")

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


Re: Thousand Seperator

2008-03-14 Thread Jeroen Ruigrok van der Werven
-On [20080314 18:11], [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
>But I cannot find how to do this in Python.

I am not sure of your goal, but if you need this for localization purposes,
look at Babel (http://babel.edgewall.org/). In particular
http://babel.edgewall.org/wiki/ApiDocs/babel.numbers

We make use of the Unicode CLDR information to provide locale-specific
formatting.

-- 
Jeroen Ruigrok van der Werven  / asmodai
イェルーン ラウフロック ヴァン デル ウェルヴェン
http://www.in-nomine.org/ | http://www.rangaku.org/
When we have not what we like, we must like what we have...
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Thousand Seperator

2008-03-14 Thread Paul M¢Nett
Eddie Corns wrote:
> [EMAIL PROTECTED] writes:
> 
>> I'm trying to find some code that will turn:
> 
>> 100 -> 100
>> 1000 -> 1,000
>> 100 -> 1,000,000
>> -1000 -> -1,000
> 
>> I know that can be done using a regular expression. In Perl I would do
>> something like:
> 
>> sub thousand {
>>$number = reverse $_[0];
>>$number =~ s/(\d\d\d)(?=\d)(?!d*\.)/$1,/g;
>>return scalar reverse $number;
>> }
> 
>> But I cannot find how to do this in Python.
> 
> Look at the locale module.  If you're producing the numbers yourself then they
> get printed in that format otherwise you can convert them to numbers first.

Specifically:

import locale
locale.setlocale(locale.LC_ALL, '')
for trial in (100, 1000, 100, -1000):
print trial, locale.format("%0f", trial, True)

If that results in no comma separators, then you may need to set the 
locale specifically, such as:

 >>> locale.setlocale(locale.LC_ALL, 'en_us')
'en_us'
 >>> for trial in (100, 1000, 10, -1000):
... print trial, locale.format("%.0f", trial, True)
...
100 100
1000 1,000
10 100,000
-1000 -1,000

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


Re: List mutation method gotcha - How well known?

2008-03-14 Thread Lie
On Mar 14, 4:57 pm, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> Lie napisa³(a):
>
>
>
> >> foo = [1,2,3,4]
> >> x = foo.append(5)
> >> print x
>
> >> What will be the output (choose one):
>
> >> 1)  [1,2,3,4]
> >> 2)  [1,2,3,4,5]
> >> 3)  That famous picture of Albert Einstein sticking out his tongue
> >> 4)  Nothing - no output
> >> 5)  None of the above
>
> >> I undertake to summarise answers posted to complete this "survey".
>
> > I think I'll choose 3. Well, no, I suppose the correct behavior
> > _should_ be undefined (i.e. what it returns is an implementation
> > details that should not be relied on). The fact that it returns None
> > is just a "coincidence" that happens to happen every time you tested
> > it (you can't prove by ignorance)
>
> I think in Python there's no notion of "void" return type. Deliberate
> choice to return None for functions that modify objects in place seems
> to be OK as long as it is used consistently and documented. Which is the
> case.

No, there is no need for "void" return type, what I meant is that
everything that's not said in the documentation should be assumed to
be an implementation detail, a method or a function that doesn't say
anything about its return type should be assumed to return an
implementation detail (which basically means: Don't rely on this). The
fact that list.append returns none is just a coincidence, you might
encounter another list.append that returns different thing some time
in the future, or the far future, or perhaps at the end of the
galaxy's life.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Joseph Weizenbaum

2008-03-14 Thread Reedick, Andrew
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:python-
> [EMAIL PROTECTED] On Behalf Of Aahz
> Sent: Friday, March 14, 2008 2:05 PM
> To: [email protected]
> Subject: RIP: Joseph Weizenbaum
> 
> Creator of Eliza:
> 
> http://www-tech.mit.edu/V128/N12/weizenbaum.html
> --

How do you feel about creator of Eliza?



*

The information transmitted is intended only for the person or entity to which 
it is addressed and may contain confidential, proprietary, and/or privileged 
material. Any review, retransmission, dissemination or other use of, or taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you received this in error, 
please contact the sender and delete the material from all computers. GA621


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


Custom Exception Value?

2008-03-14 Thread erikcw
Hi,

When I use sys.exc_info() on one of my custom exception classes, the
"message"/value isn't returned.  But it is when I use a built in
exception.

Example:

In [32]: class Test(Exception):
   : def __init__(self, x):
   : self.value = x
   : def __str__(self):
   : return repr(self.value)
   :
   :
In [39]: try:
   : raise Test('mess')
   : except:
   : sys.exc_info()
   :
   :
Out[39]: (, Test(), )

In [40]: try:
   : 1/0
   : except:
   : sys.exc_info()
   :
   :
Out[40]:
(,
 ZeroDivisionError('integer division or modulo by zero',),
 )


Wy does the output of ZeroDivisionError appear in sys.exc_info() but
for test it is just Test() (should be Test('mess') right??)

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


Re: Handling global variables (Newbie)

2008-03-14 Thread MRAB
On Mar 13, 4:25 am, "David S" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have an error occurring at
> self.build_root = os.path.abspath(os.path.split(__file__)[0])
>
> The error states 'NameError: global name '__file__' is not defined'
>
> In Python 2.5 I ran my script as a module in IDLE gui. How does _file_ get
> defined?
>
Do you perhaps mean '__name__'?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ZSI and attachments

2008-03-14 Thread Dieter Maurer
Laszlo Nagy <[EMAIL PROTECTED]> writes on Tue, 11 Mar 2008 15:59:36 +0100:
> I wonder if the newest ZSI has support for attachments? Last time I
> checked (about a year ago) this feature was missing. I desperately
> need it. Alternatively, is there any other SOAP lib for python that
> can handle attachments?

The ZSI 2.0 documentation says:

   "...It can also be used to build applications using SOAP Messages with 
Attachments"

I never did it and do not know how ZSI supports this.
You probably will get a more informed answer on
mailto:[EMAIL PROTECTED],
the ZSI mailing list.

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


Re: unitests don't run under pdb

2008-03-14 Thread Amit Gupta
On Feb 20, 8:51 pm, Miki <[EMAIL PROTECTED]> wrote:
> Hello Amit,
>
>
>
> > python testname.py : the unitests runs as usual and I get the
> > following results:
> > --
> > Ran 2 tests in 0.024s
>
> > OK
> > 
>
> > However, if I do "python -mpdbtestnames.py": I get
> > ython -mpdbtestnames.py> /s/nd6/amit/pyiglu/testnames.py(1)()
>
> > -> importunittest
> > (Pdb) c
>
> > --
> > Ran 0 tests in 0.000s
>
> > OK
> > ---
>
> IIRCunittestchecks the __main__ module for tests to run. Once you
> run python with "-mpdb" the __main__ module ispdband not your
> script.
>
> HTH,
> --
> Miki <[EMAIL PROTECTED]>http://pythonwise.blogspot.com

Ok, Sorry for late reply on this.

So What do I do, if my testcase if failing because of an uncaught
exception and I want to run it in pdb.

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


Re: Custom Exception Value?

2008-03-14 Thread Arnaud Delobelle
On Mar 14, 6:47 pm, erikcw <[EMAIL PROTECTED]> wrote:
> Hi,
>
> When I use sys.exc_info() on one of my custom exception classes, the
> "message"/value isn't returned.  But it is when I use a built in
> exception.
>
> Example:
>
> In [32]: class Test(Exception):
>    :     def __init__(self, x):
>    :         self.value = x
>    :     def __str__(self):
>    :         return repr(self.value)
>    :
>    :
> In [39]: try:
>    :     raise Test('mess')
>    : except:
>    :     sys.exc_info()
>    :
>    :
> Out[39]: (, Test(),  0xb7802e8c>)
>
> In [40]: try:
>    :     1/0
>    : except:
>    :     sys.exc_info()
>    :
>    :
> Out[40]:
> (,
>  ZeroDivisionError('integer division or modulo by zero',),
>  )
>
> Wy does the output of ZeroDivisionError appear in sys.exc_info() but
> for test it is just Test() (should be Test('mess') right??)

Three ways to do it right:

* Override __repr__() rather than __str__

or forget about __repr__() and instead:

* call super(Test, self).__init__(x) from within Test.__init__()

or even

* self self.args = (x,) within Test.__init__()

HTH

--
Arnaud

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


Re: How to import custom python file in python server page (psp) ?

2008-03-14 Thread Joshua Kugler
James Yu wrote:

> Hi folks,
> 
> I prepared a python script for dynamically get the absolute paths of the
> files in certain folder.
> Then I tried to invoke that function from my web server in a .psp file
> like this:
> 
>   1 
>   2 
>   3 asdfasdfasdfa
>   4 
>   5 <%
>   6 import glob
>   7 import os
>   8 *import Helper
> *  9
>  10 body = ''
>  11 top = 'asdfasdfasdfa'
>  12 links = {}
>  13 *Helper.GetLinks(top=top)
> * 14 *paths = Helper.GenLinkPath(links)
> * 15 body = paths
>  16 %>
>  17 <%=body%>
>  18 
>  19 
> 
> However, this is the error message I received when I open the page in a
> browser:
> 
>> Mod_python error: "PythonHandler mod_python.psp"
>>
>> Traceback (most recent call last):
>>
>>   File "/usr/lib/python2.5/site-packages/mod_python/apache.py", line 299,
>> in HandlerDispatch
>> result = object(req)
>>
>>   File "/usr/lib/python2.5/site-packages/mod_python/psp.py", line 302, in
>> handler
>> p.run()
>>
>>   File "/usr/lib/python2.5/site-packages/mod_python/psp.py", line 213, in
>> run
>> exec code in global_scope
>>
>>   File "/var/www/.cyu021/.pic/index.psp", line 8, in
>> import Helper
>>
>> ImportError: No module named Helper
> 
> 
> *PS. I put Helper.py and index.psp in the same dir
> *
> Thanks in advance,


What is the import path?  The current directory in PSP might not be the
directory in which the .psp file resides.  Print out sys.path before you
import your helper module to see what paths you're dealing with.

j

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


Re: ZSI and attachments

2008-03-14 Thread Waldemar Osuch
On Mar 11, 8:59 am, Laszlo Nagy <[EMAIL PROTECTED]> wrote:
>   Hi All,
>
> I wonder if the newest ZSI has support for attachments? Last time I
> checked (about a year ago) this feature was missing. I desperately need
> it. Alternatively, is there any other SOAP lib for python that can
> handle attachments?
>
Does this help?
http://trac.optio.webfactional.com/browser/soaplib/trunk/examples/binary.py
-- 
http://mail.python.org/mailman/listinfo/python-list


Installing Python2.4 on RHEL4?

2008-03-14 Thread Eric B.
Hi,

I appologize if this is slightly OT, but I am really struggling to figure 
out how to install Python2.4 on RHEL4.  To make matters worse, the RHEL4 
machine is a 64bit architecture.

I search pyvault, but they only have for .i386.  Does anyone know where / 
how I can find Python2.4 for RHEL4 x64?

If there is a better place to be asking this question, please let me know, 
and I will redirect my queries elsewhere.

Thanks so much.

Eric 



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


Re: Installing Python2.4 on RHEL4?

2008-03-14 Thread Jarek Zgoda
Eric B. pisze:

> I appologize if this is slightly OT, but I am really struggling to figure 
> out how to install Python2.4 on RHEL4.  To make matters worse, the RHEL4 
> machine is a 64bit architecture.
> 
> I search pyvault, but they only have for .i386.  Does anyone know where / 
> how I can find Python2.4 for RHEL4 x64?

If you would not find a binary Python 2.4 package, you can always build
your own and package it. Why not?

-- 
Jarek Zgoda
http://zgodowie.org/

"We read Knuth so you don't have to" - Tim Peters
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Installing Python2.4 on RHEL4?

2008-03-14 Thread Eric B.
"Jarek Zgoda" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Eric B. pisze:
>
>> I appologize if this is slightly OT, but I am really struggling to figure
>> out how to install Python2.4 on RHEL4.  To make matters worse, the RHEL4
>> machine is a 64bit architecture.
>>
>> I search pyvault, but they only have for .i386.  Does anyone know where /
>> how I can find Python2.4 for RHEL4 x64?
>
> If you would not find a binary Python 2.4 package, you can always build
> your own and package it. Why not?

Because I don't have a development x64 environment to build it. :(  Only a
production server with no compilation tools on it.
Hence my need to ideally find a binary x64 distribution of it.

Unless someone knows of a way to build a 64bit distribution from within a 
32bit system?

Thanks,

Eric




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


Re: Ping and ARP on both Win and Linux in Python

2008-03-14 Thread Rune Strand
On Mar 13, 9:14 pm, "Mauro \"Baba\" Mascia" <[EMAIL PROTECTED]> wrote:
> Hi, this is my question:
>
> I want to know if several switch (about 50) in a big lan are up and then
> know their MAC addresses to do a list that contains host name, ip and mac.
> I know only the range of their IP addresses (the host name it's simply
> to know using socket.gethostn.
>
> The first idea it's to ping all ip, parse the response and then execute
> the command "arp -a" and parse the response.
> However this way depends on the operating system and the ping response
> depends too from the language.
>
> Another way it's to open the main page of the switch and parse the HTML
> code where i can find the MAC address.
> However this way depends on the particular brand's switch.
>
> I know (or better i think) that there is a third way: make ping and arp
> building the packets with socket and so on (but i dont have understand
> in what way do this).
>
> Any suggestion?
>
> (i've already search in google, found many sources but a lot of them
> don't works or don't do what im trying to do...)
>
> Regards,
> Mauretto.

There are several Ping /ICMP implentations in Python. I did something
similar using a python ping module and parsing the arp cache. A
different approach may be to use SNMP. I believe there are Python
tools around.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Network server- / client-side messaging

2008-03-14 Thread castironpi
On Mar 2, 3:43 pm, [EMAIL PROTECTED] wrote:
> '''
> Last time, we left off at:
> '''
>
> class InterfaceClientSide( ClientSide ):
>         message= MessageDec()
>         incremental= message.incremental()
>         settings= AYT( .5, 3 )
>         user_act= message.out()
>         def __init__( self, image ):
>                 self._image= image
>                 ClientSide.__init__( self )
>         def on_scale( self, *args ):
>                 change= self._whatchange(
>                         self.on_scale, *args )
>                 self.user_act( change )
>         def on_rotate( self, *args ):
>                 change= self._whatchange(
>                         self.on_rotate, *args )
>                 self.user_act( change )
>         @incremental( 1 )
>         def layout_return( self, layoutchange ):
>                 renderchange( layoutchange )
>         @incremental( 2 )
>         def layout_return( self, layoutchange ):
>                 renderchange( layoutchange )
>         @message
>         def time_estimate( self, etc ):
>                 report( etc )
>
> class InterfaceServerSide( ServerSide ):
>         message= MessageDec()
>         incremental= message.incremental()
>         settings= AYT( .5, 3 )
>         time_estimate= message.out()
>         layout_return= incremental()
>         def __init__( self, image ):
>                 self._image= image
>                 ServerSide.__init__( self )
>         @message.intervene()
>         def user_act( self, change ):
>                 etc= self.calculateeta( change )
>                 self.time_estimate( etc )
>                 preliminary= self.calculation()
>                 preliminary_change= whatchange( preliminary )
>                 self.layout_return( preliminary_change )
>                 completed= self.other_calculation()
>                 completed_change= whatchange( completed )
>                 self.layout_return( completed_change )
>                 self.layout_return.finish()
>
> '''
> Another use ClientSide and ServerSide should support is a peer-to-peer
> chat-and-game server.  And that said, it's not clear that there's any
> distinction between ServerSide and ClientSide anyway, depending on
> exactly how the listen and connect methods abstract.  How much of the
> implementation do they share?  Most.
>
> You could mark 'time_estimate' as incremental( 3 ); they're separated
> for illustration purposes.
>
> One remaining question is how to intervene in user_act, if a second
> change arrives before the previous complete.  You could combine the
> earlier change parameter in the new call and throw an exception in the
> thread handling the earlier one at its first loss of control--- and
> maybe even at once with settrace!  That tends to be costly.  Not to
> mention, change has already entered derived-class space.  ServerSide
> should make sure it's easy enough to address the issue on one's own,
> and @message.nonintervene() is available too.
> '''

The issues over here this week were delta vs. state-- if there is a
unifiable way to specify constraints on which is cheaper given what,
and transmit it, -- and, partial inheritance of not just methods,
data: overriding 'message' and wanting -its- derivatives-- user_act,
time_estimate-- to know it, without redefining.

Obvious solutions can be redundant.  self.message.layout_return is;
get 'layout_return' into the class definition.  It's immediately easy
to receive the 'ServerSide' instance as a parameter-- less so to get
both it and the 'message' instance.  If we can, MessageDec can include
data, but is still constrained by overriding 'message'.  Conclusion?
Might as well include some data in MessageDec.  How well does message=
MessageDec( ServerSide.send ) settle?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Joseph Weizenbaum

2008-03-14 Thread castironpi
On Mar 14, 1:47 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:python-
> > [EMAIL PROTECTED] On Behalf Of Aahz
> > Sent: Friday, March 14, 2008 2:05 PM
> > To: [EMAIL PROTECTED]
> > Subject: RIP: Joseph Weizenbaum
>
> > Creator of Eliza:
>
> >http://www-tech.mit.edu/V128/N12/weizenbaum.html
> > --
>
> How do you feel about creator of Eliza?

What is Eliza?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to send a var to stdin of an external software

2008-03-14 Thread bryanjugglercryptographer
Floris Bruynooghe wrote:
> Benjamin Watine wrote:
> > Could you give me more information / examples about the two solutions
> > you've proposed (thread or asynchronous I/O) ?
>
> The source code of the subprocess module shows how to do it with
> select IIRC.  Look at the implementation of the communicate() method.

And here's a thread example, based on Benjamin's code:

import subprocess
import thread

def readtobox(pipe, box):
box.append(pipe.read())

cat = subprocess.Popen('cat', shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE)

myVar = str(range(100)) # arbitrary test data.

box = []
thread.start_new_thread(readtobox, (cat.stdout, box))
cat.stdin.write(myVar)
cat.stdin.close()
cat.wait()
myNewVar = box[0]

assert myNewVar == myVar
print len(myNewVar), "bytes piped around."


--
--Bryan

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


Re: Joseph Weizenbaum

2008-03-14 Thread Roel Schroeven
[EMAIL PROTECTED] schreef:
> On Mar 14, 1:47 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
>>> Subject: RIP: Joseph Weizenbaum
>>> Creator of Eliza:
>>> http://www-tech.mit.edu/V128/N12/weizenbaum.html
>>> --
>> How do you feel about creator of Eliza?
> 
> What is Eliza?

Does that question interest you?

-- 
The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

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



Re: Joseph Weizenbaum

2008-03-14 Thread castironpi
On Mar 14, 5:16 pm, Roel Schroeven <[EMAIL PROTECTED]>
wrote:
> [EMAIL PROTECTED] schreef:
>
> > On Mar 14, 1:47 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> >>> Subject: RIP: Joseph Weizenbaum
> >>> Creator of Eliza:
> >>>http://www-tech.mit.edu/V128/N12/weizenbaum.html
> >>> --
> >> How do you feel about creator of Eliza?
>
> > What is Eliza?
>
> Does that question interest you?

He had a dream about a pillow.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Joseph Weizenbaum

2008-03-14 Thread Brian Blais


On Mar 14, 2008, at Mar 14:5:59 PM, [EMAIL PROTECTED] wrote:


On Mar 14, 1:47 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:

Subject: RIP: Joseph Weizenbaum



Creator of Eliza:



http://www-tech.mit.edu/V128/N12/weizenbaum.html
--


How do you feel about creator of Eliza?


What is Eliza?


You: What is Eliza?
Eliza: Does that question interest you?

(http://www-ai.ijs.si/eliza/eliza.html)





bb

--
Brian Blais
[EMAIL PROTECTED]
http://web.bryant.edu/~bblais



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

  1   2   >