Re: System tray Icon

2005-10-24 Thread Mike C. Fletcher
I have a sample up here:

http://blog.vrplumber.com/scripts/recordingdevices.py

using wxPython.  The sample application is Linux-specific, but it should 
give you a fairly good idea of how to use the system tray icon control 
in wxPython.

HTH,
Mike

Mike Pippin wrote:

> How would I have an app run with just a system tray Icon??? any help 
> would be greatly appreciated. I have no clue where to start.

-- 

  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com

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


Re: Binding a variable?

2005-10-24 Thread Paul Dale

Thanks everyone for your comments and suggestions!

I haven't quite decided which approach I'll take, but it's nice to have 
some options.

Paul

Tom Anderson wrote:

>On Fri, 21 Oct 2005, Paul Dale wrote:
>
>  
>
>>Is it possible to bind a list member or variable to a variable such that
>>
>>temp = 5
>>list = [ temp ]
>>temp == 6
>>list
>>
>>would show
>>
>>list = [ 6 ]
>>
>>
>
>As you know by now, no. Like any problem in programming, this can be 
>solved with a layer of abstraction: you need an object which behaves a bit 
>like a variable, so that you can have multiple references to it. The 
>simplest solution is to use a single-element list:
>
>  
>
temp = [None] # set up the list
temp[0] = 5
list = [temp]
temp[0] = 6
list


>[[6]]
>
>I think this is a bit ugly - the point of a list is to hold a sequence of 
>things, so doing this strikes me as a bit of an abuse.
>
>An alternative would be a class:
>
>class var:
>   def __init__(self, value=None):
>   self.value = value
>   def __str__(self): # not necessary, but handy
>   return "<<" + str(self.val) + ">>"
>
>  
>
temp = var()
temp.value = 5
list = [temp]
temp.value = 6
list


>[<<6>>]
>
>This is more heavyweight, in terms of both code and execution resources, 
>but it makes your intent clearer, which might make it worthwhile.
>
>tom
>
>  
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: output from external commands

2005-10-24 Thread darren kirby
quoth the James Colannino:
> Hey everyone.  First off, I'm new to the list.  I had had a little bit
> of experience with Perl before discovering Python.  The more Python I
> learn, the more I love it :)  I just have a quick question to ask.  I
> know that this is probably a simple question, but I've been googling
> around, and partly because I'm not sure exactly what to search for, I've
> been unsuccessful at finding an answer.  What I'd like to do is be able
> to take the output of an external command and assign it as an array of
> strings.  So, for example, in Perl I could do something like:
>
> @files = `ls`;
>
> So I guess I'm looking for something similiar to the backticks in Perl.
> Forgive me if I've asked something that's a bit basic for this list.
> Any help would be greatly appreciated :)  Thanks very much in advance.

If all you want is filenames this will work:
>>> import glob
>>> files = ["%s" % f for f in glob.glob("*")]

Else use os.popen to iterate over lines of output:
>>> import os
>>> for line in os.popen("ls -l").readlines():
>>> . . . process(line)

Or check out subprocess if you have 2.4..

> James
>
> --
> My blog: http://www.crazydrclaw.com/
> My homepage: http://james.colannino.org/

-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972


pgpPYTSvHOmSy.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Set an environment variable

2005-10-24 Thread Eric Brunel
On Fri, 21 Oct 2005 20:13:32 -, Grant Edwards <[EMAIL PROTECTED]> wrote:

> On 2005-10-21, Mike Meyer <[EMAIL PROTECTED]> wrote:
>> Grant Edwards <[EMAIL PROTECTED]> writes:
>>> My point: the OP wanted to know how to export an environment
>>> variable to a child process.  Either of the lines of code above
>>> will do that, so what's with all the shellular shenanigans?
>>
>> Actually, the OP didn't say he wanted to export a variable to a child
>> process. He said he wanted to know how to do the equivalent of "export
>> SYMBOL=value", which got intreprted as "setting a variable in the
>> parent shell."
>
> The only think you can export an environment variable to is a
> child process

Well, you know that, and I know that too. From my experience, many people 
don't...

> so I thought it obvious that was what he was
> doing with the "export" command example.

Well, when I first read the OP's message, I thought it was obvious he wanted to 
export the variable to the parent shell. Re-reading it, it was actually not so 
obvious, so my apologies for not having included an example using 
os.environment...
-- 
python -c "print ''.join([chr(154 - ord(c)) for c in 
'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Syntax across languages

2005-10-24 Thread Fredrik Lundh
Tom Anderson wrote:

> This is taken from the AI 754 standard, i take it? :)
>
> Seriously, that's horrible. Fredrik, you are a bad man, and run a bad
> railway.
>
> However, looking at the page the OP cites, the only mention of that
> operator i can find is in Dylan, and in Dylan, it's nothing to do with
> approximate FP equality - it means 'not identical', which we can spell "is
> not".
>
> What would approximate FP equality even mean? How approximate?

so you don't really know what it is, but you're sure that "looks the same
when printed using a well-defined algorithm" can never be the answer ?





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


Re: create user message for wxPython

2005-10-24 Thread Frithiof Andreas Jensen

"James Hu" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hi,

> There are 2 wxPython application, A and B and need to exchange msg.

I do not think that wx even has a mechanism for sending events between
applications.?

You need some other tool, like a socket, a named pibe, some windows specific
event queue library (gack!), or maybe a toolkit like PYRO, SPREAD e.t.c.
depending on your *reason* for needing this in the first place.

I am partial to PYRO myself.

... and you do need an event loop in any case to map from:

 "remote event" <-> "message protocol" <-> "local event"

... at least that makes it easier to test than "raw" event's which are
harder to control.


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


Re: Python vs Ruby

2005-10-24 Thread bruno modulix
Michael Ekstrand wrote:
> On Friday 21 October 2005 07:07, bruno modulix wrote:
> 
Python is more like Java.
>>
>>
>>Err... Python is more like what Java would have been if Java was a
>>smart dynamic hi-level object oriented language !-)
>>
> 
> 
> +1. Python is easily applicable to most of the problem domain of Java, 
> but solves problems much more elegantly. It just isn't shipped embedded 
> in all leading browsers :-(.

It's been a long time since I last saw a Java applet on a website.


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


Re: IDE recommendation please

2005-10-24 Thread Adriaan Renting
"kery" <[EMAIL PROTECTED]> 10/23/05 9:33 am >>> 
>Alex Martelli wrote: 
>>microsnot <[EMAIL PROTECTED]> wrote: 
>> 
> 
>Any suggestions for Linux, specifically SuSE or perhaps Red Hat? 
> 
>Thanks in advance, 
>Kery 
> 

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


Re: [OT] Python vs Ruby

2005-10-24 Thread bruno modulix
Scott David Daniels wrote:
> bruno modulix wrote:
> 
>> ... Another language that failed to make it to the mainstream but is
>> worth giving a try is Smalltalk - the father of OOPLs (Simula being the
>> GrandFather). 
> 
> I would say Simula is the forefather of modern OOPLs, and Smalltalk is
> the toofather.

Err... I'm afraid I don't understand this last word (and google have not
been of much help here)



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


New User

2005-10-24 Thread thatchmatic
I just downloaded and I think installed python.  I am not sure if I 
did cause it does'nt respond to the commands that the read me file 
told me to use.  Also can someone suggest a trial program I can maybe 
write for fun?

Thanks.



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


Re: testing '192.168.1.4' is in '192.168.1.0/24' ?

2005-10-24 Thread [EMAIL PROTECTED]
thanks, that is basically what I am doing and since it is a recipe, I
would assume there is no standard library module for it.

Peter Hansen wrote:
> [EMAIL PROTECTED] wrote:
> > Is there standard library modules handling this ? currently I need to
> > turn it into a long integer and do the shift and compare.
>
> A little Googling turned up this:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440560
> 
> -Peter

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


Re: Python vs Ruby

2005-10-24 Thread bruno modulix
Alex Martelli wrote:
(snip)
> Here's a tiny script showing some similarities and differences:
> 
> def f()
>   i = 0
>   while i < 100
> j = 923567 + i
> i += 1
>   end
> end
> 
> f()
> 
> comment out the 'end' statements, and at colons

s/at/add/

> at the end of the def
> and while statements, and this is also valid Python.  

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


Re: Python vs Ruby

2005-10-24 Thread Iain King

Tom Anderson wrote:
> On Fri, 21 Oct 2005, vdrab wrote:
>
> > You can tell everything is well in the world of dynamic languages when
> > someone posts a question with nuclear flame war potential like "python
> > vs. ruby" and after a while people go off singing hymns about the beauty
> > of Scheme...
>
> +1 QOTW
>
> > I love this place.
>
> Someone should really try posting a similar question on c.l.perl and
> seeing how they react ...
> 
> tom

SSsh! Xah Lee might be listening!

Iain

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


Re: testing '192.168.1.4' is in '192.168.1.0/24' ?

2005-10-24 Thread Christoph Haas
On Monday 24 October 2005 10:21, [EMAIL PROTECTED] wrote:
> thanks, that is basically what I am doing and since it is a recipe, I
> would assume there is no standard library module for it.

Well, http://py.vaults.ca/~x/parnassus/apyllo.py/126307487 lists a few.
I had used IPy in the past. But somehow nothing so far was a decent
substitute for Perl's Net::IP.

 Christoph
-- 
~
~
".signature" [Modified] 1 line --100%--1,48 All

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


Re: New User

2005-10-24 Thread Fredrik Lundh
"thatchmatic" wrote:

> I just downloaded and I think installed python.  I am not sure if I
> did cause it does'nt respond to the commands that the read me file
> told me to use.  Also can someone suggest a trial program I can maybe
> write for fun?

what happens when you type

python

at a command prompt ?

if you get a

>>>

prompt, what happens if you type print "hello" at that prompt?

>>> print "hello"

if that appears to do what it says, what happens if you type

>>> import this

if all this seems to do something other than printing "syntax error" or
"unknown command" or similar stuff, point your browser to this page:

http://docs.python.org/tut/tut.html

and work through the first few chapters.

otherwise, post the error messages.





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


Re: New User

2005-10-24 Thread Christoph Haas
On Sunday 23 October 2005 03:46, thatchmatic wrote:
> I just downloaded and I think installed python.  I am not sure if I
> did cause it does'nt respond to the commands that the read me file
> told me to use.  Also can someone suggest a trial program I can maybe
> write for fun?

Try http://diveintopython.org/installing_python/shell.html

Otherwise please provide more information so we can help.

 Christoph
-- 
~
~
".signature" [Modified] 1 line --100%--1,48 All

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


Re: Zope and Persistence

2005-10-24 Thread bruno modulix
[EMAIL PROTECTED] wrote:
> I don't know if this is the appropriate place to post a Zope question

Nope. You'd better use the zope mailing-list for this.


> but I figure many here are familiar with it. I'm confused about the
> role of the ZMI when it comes to development.

As it's name implies, the ZMI is a *management* interface. Real Zope
developpement is better made with filesystem "Products" (Zope components).

> I want to write a simple
> script that logs page hits. 

That's a typical case of reinventig the square wheel. Ever looked at
/log/Z2.log ? It's an apache-like access
log. And there are a whole lot of tools for building stats from apache
access logs.


> I wrote it in what was called a Script
> (Python) resource in the ZMI. When I access the page it gives an error
> saying that this file cannot import Persistence, etc. 

Why would you import Persistence in a Python Script ? This is already a
persistent object.

> This makes sense
> but where would I put this script 

Whereever seems to fit - this depends on your application.

> and how would I invoke it? 

Like any other Zope object.

> It is only
> supposed to store an integer in Data.fs. Thanks.

This is another problem, and I think you'd better start with the zope book.

But for you current use case, first have a look at Zope's access log.


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


Re: Tricky Areas in Python

2005-10-24 Thread bruno modulix
PyPK wrote:
> hmm Thats one thing. Also I was thinking of something like benefites of
> python over other languages.

That's fairly context-dependant *and* subjective.

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


Re: Tricky Areas in Python

2005-10-24 Thread Steven D'Aprano
Alex Martelli wrote:

> I like to present code that seems like it should work, but has some kind
> of relatively subtle problem, either of correctness in some corner case,
> or of performance, etc -- and I ask them what they would say if they
> were to code-review that code, or how they would help a student who came
> to them with that code and complaints about it not working, &c.

[snip]

> Not sure whether you think this count as "tricky"... they're typically
> problems that do come up in the real world, from (e.g.):
> for string_piece in lots_of_pieces:
> bigstring += string_piece
> (a typical performance-trap) to
> for item in somelist:
> if isbad(item):
> somelist.remove(item)
> (with issues of BOTH correctness and performance), to

Those two are easy. However, and this is where I show 
my hard-won ignorance, and admit that I don't see the 
problem with the property examples:

> class Sic:
> def getFoo(self): ...
> def setFoo(self): ...
> foo = property(getFoo, setFoo)
> to
> class Base(object)
> def getFoo(self): ...
> def setFoo(self): ...
> foo = property(getFoo, setFoo)
> 
> class Derived(Base):
> def getFoo(self): 

Unless the answer is "Why are you using setters and 
getters anyway? This isn't Java you know."

Oh wait! Yes I do... the setter doesn't actually take 
an argument to set the property too. Is that it, or 
have a missed a cunningly hidden deeper problem?


-- 
Steven.

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


several interpreters and suspend script

2005-10-24 Thread Mike
Hello All,

I'm working ( and a beginner ) with mixing Python scripting and C++.

And I need some little help.  :)
I've searched on the net, but found no answer. So I ask you directly.

Globally, I'd like to do 2 things.

The first, when I'm in the program, I call a script, which call a function 
to open a window.
And when the window is opened the script should stop / wait, until the 
window closes, and then continue.
Does any function exists to do this ?

#-
import MyModule

def ok_cb():
global w
MyModule.Warning_All( "closing window" )
w.Close() #after here, the script should continue

#create the window
w = MyModule.cPythonWindow( "win", U"win", 0 )

#add some buttons, and when we push one, the function ok_cb is called
w.AddActionButton( "ok", "OK", ok_cb )
w.AddIntegerButton( "int", "Nb", 2541, ok_cb )

#open the window
w.Open() #we should stay here until the callback ends (when we push a 
button) and the window close

#it should show this message when the window closes and not directly 
after the window is created
MyModule.Warning_All( "exiting script" )
#-

The second problem ( which is in relation with the first ) is when we have 2 
non-modal windows, at the same time.
If the 2 scripts stops/are suspended, all the variables in the scripts must 
be totally independent.
So, I'd like that the 2 "spaces" of these scripts are independent.
I wanted to use the Py_NewInterpreter() but it failed in 
PyThreadState_Swap() with this error : "PyFatalError("Invalid thread state 
for this thread");".
So I use 2 dictionaries for each script, but is it sufficient?
What about the call stack ? Where/how is it saved ?

//-
class cPython
{
public:
virtual ~cPython();
cPython();
public:
int Run( const char* iArgs );

void Module( const char* iModuleName, PyMethodDef* iModuleMethod );
void Dictionary( const char* iModuleName );

private:
PyObject*  mMainModule;
PyObject*  mGlobalDictionary;
PyObject*  mLocalDictionary;
};
void
cPython::Module( const char* iModuleName, PyMethodDef* iModuleMethod )
{
mMainModule = Py_InitModule( iModuleName, iModuleMethod );
PyDict_Merge( PyModule_GetDict( mMainModule ), PyModule_GetDict( 
PyImport_AddModule( "__main__" ) ), true );
}
void
cPython::Dictionary( const char* iModuleName )
{
mGlobalDictionary = PyDict_Copy( PyModule_GetDict( mMainModule ) );
PyDict_SetItemString( mGlobalDictionary, iModuleName, mMainModule );

mLocalDictionary = PyDict_Copy( PyModule_GetDict( mMainModule ) );
}
int
cPython::Run( const char* iArgs )
{
PyObject* run_string = PyRun_String( iArgs, Py_file_input, 
mGlobalDictionary, mLocalDictionary );
Py_XDECREF( run_string );
return 0;
}


cPython pyt;
pyt.Module( L"MyModule", sgMethods ); //create the module "MyModule"
InitPythonProject( pyt.Module() );  //add the "class" project in the 
module "MyModule"
InitPythonLayer( pyt.Module() );  //add the "class" layer in the module 
"MyModule"
InitPythonWindow( pyt.Module() );  //add the "class" window in the 
module "MyModule"
pyt.Dictionary( L"MyModule );   //create the 2 dictionary

pyt.Run( L"MyPath/MyFile.py" );
//-

If I create more python objects, the dictionaries are different but not the 
module( there is no copy of the module for the next python object ), right?
And can this make problems for globals variables or callstack for each 
suspended script ?

Here, that's all  :)

So, if you have any suggestions ( or even solutions ).

Thanks for reading

Regards


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


Re: IDE recommendation please

2005-10-24 Thread Franz Steinhaeusler
On Sun, 23 Oct 2005 14:54:38 +1000, microsnot
<[EMAIL PROTECTED]> wrote:

>I'm new to Python but am wondering what IDE Python developers use? 

I use DrPython ;)

>I use Mac
>OS X 10.4.2. I have PythonIDE which comes with MacPython but I don't think
>that has even rudimentary "intellisense". 

DrPython has a "Code Completition" plugin.
It combines "Autocompletion" and "Calltips"


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


Re: IDE recommendation please

2005-10-24 Thread Franz Steinhaeusler
On 23 Oct 2005 18:39:17 -0700, "Brendan" <[EMAIL PROTECTED]> wrote:

>As mentioned, there isn't a whole lot.  I've beta tested Komodo, and it
>looks promising.  SPE might start working now that stani has a mac.
>
>For now I use TextWrangler - a free text editor with good python
>support.  http://www.barebones.com/products/textwrangler/index.shtml
>
>For interactive python, I use PyCrust (though the terminal works just
>as well)

I second want to encourage the use of PyCrust.
If you hit '(', you will get a calltip, the same
is on '.' for code completion.
If you are for example on:
I myself made a patch for getting calltips and Code Completion
on demand, that means, you don't have to go back and clear
the already typed text and enter '(' or '.' again.
I assigned them to Ctrl-Space (code completion) and
Ctrl-Shift-Space for calltips.


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


Re: wxPython advice

2005-10-24 Thread Miki Tebeka
Hello vpr,

> I've written a p2p program using socketserver that's nice and quick.
> I'd like to give the user a tray applet (part of the p2p service) that
> will allow the user to activate / deactivate / config and exit the
> service.
> However I'm starting to bang my head on the mainloop funtions that
> manage
> wx and socket events.
> 
> Anyone been down this road that can give me some advice
One common solution is to do all the work in a "worker thread" and keep the
GUI responsive to command.

Note that Python don't have native support to pause/resume threads. You'll
need to get your thread to check for new state every now and then. (Usually
this means keep transactions small) or use processes instead of threads
(see http://home.pacbell.net/ouster/threads.pdf).

You might want to use async socket reading as well.

HTH.
--

Miki Tebeka <[EMAIL PROTECTED]>
http://tebeka.bizhat.com
The only difference between children and adults is the price of the toys


pgpHBwZbzOv3s.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Antoon Pardon
Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> It would be better if cmp would give an indication it
>> can't compare two objects instead of giving incorrect
>> and inconsistent results.
>
> If two objects aren't totally comparable, then using 'cmp' on them is 
> ill-defined to begin with.

Where is that documented?

> The Standard Thing To Do is throw an 
> exception; see the Highly Obscure Case of the Complex Numbers.
>
> >>>1 == 1j
> False
> >>>1 != 1j
> True
> >>>1 < 1j
> Traceback (most recent call last):
>File "", line 1, in ?
> TypeError: cannot compare complex numbers using <, <=, >, >=

I would say this is the wrong answer. The right answer should
be False IMO.

Especially in the following case do I think the TypeError is
the wrong answer:

>>> 3 + 0j < 2 + 0j
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: cannot compare complex numbers using <, <=, >, >=
>>> 

Look at sets:

>>> set([1]) <=  set([2])
False
>>> set([2]) <= set([1])
False
>>> 


> >>>cmp(1j,1j)
> 0
> >>>cmp(1,1j)
> Traceback (most recent call last):
>File "", line 1, in ?
> TypeError: cannot compare complex numbers using <, <=, >, >=
>
> So using the well-known case of complex numbers, the semantics are 
> already well-defined.

I think one can argue against this, but I'm willing to leave this
as it is for complex numbers. But I think the situation with sets
should be trated differently than currently.

> >>> class Incomparable:
> ... def __cmp__(self,other):
> ... raise TypeError("cannot compare Incomparables using <, 
><=, >, >=")
> ... def __eq__(self,other):
> ... return self is other
> ... def __neq__(self,other):
> ... return self is not other
> >>> a1 = Incomparable()
> >>> a2 = Incomparable()
> >>> a1 == a1
> 1 # I'm running on python 2.2.3 at the moment, so hence the 1.
> >>> a2 == a2
> 1
> >>> a1 == a2
> 0
> >>> a1 < a2
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 3, in __cmp__
> TypeError: cannot compare Incomparables using <, <=, >, >=
> >>> cmp(a1,a2)
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 3, in __cmp__
> TypeError: cannot compare Incomparables using <, <=, >, >=
>
>
> So your use-case is already well-defined, and rather simple.  Make 
> __cmp__ raise an exception of your choice,

That is not well defined. It doesn't allow to distinghuish between
something went wrong in __cmp__ and and answer that indicates the
only usefull thing you can say is that they are unequal.

Besides I find the following result inconsistent:

>>> set([1]) <= set([1,2])
True
>>> cmp(set([1]), set([1,2]))
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: cannot compare sets using cmp()

The first set is smaller than the second so acoording to the
documentation, I should get a negative number as a result.

> and define rich comparators 
> only for the comparisons that are supported.  If, as you say in another 
> post, "some" pairs in D cross D are comparable on an operator but not 
> all of them (and further that this graph is not transitive),

I was talking about partial orders, partial orders are transitive
and python still doesn't handle them right.

> then your 
> _ONLY_ choices, no matter your implementation, is to return some 
> possibly inconsistent result (a < b == 1, b < c == 1, a < c == 0) or 
> raise an exception for unapplicable comparisons.
>
> This isn't a Python problem; this is a problem from formal mathematics.

I think it is python's problem if python gives the wrong results.

when a < b then cmp(a,b) should give a negative number as a result.
Python sometimes does not!

when not a < b then cmp(a,b) should not give a negative number as
a result. Python sometimes does!

I think those are python problems.

> Personally, I'd favor the "raise an exception" case, which is exactly 
> what will happen if you define rich comparisons and let cmp throw an 
> exception.

But I don't want cmp to raise an exception when the two elements are
comparable.

That cmp(set([1]), set([2])) would raise an exception, I can understand,
although I would prefer it returned None, but why should
cmp(set([1]), set([1,2])) raise an exception. There is a perfectly
well defined answer for this.

> Operators that assume comparable objects, like sort, also 
> almost always assume a total order -- inconsistent operations can give 
> weird results, while throwing an exception will at least (usually) give 
> some sort of error that can be caught.

No it wont. the sort method will happily sort a list of sets.

>>> lst
[set([1]), set([2])]
>>> lst.sort()

I agree that it would have been better if an exception had been in
raised in the sort method here.

> Another poster mentioned the B-tree example, and that isn't solvable in 
> this case -- B-trees assume a total order, but by their nature aren't 
> explicit about checking for it; inserting a "par

Setting a Limit to the Maximum Size of an Upload

2005-10-24 Thread Joey C.
Hello,
I'm designing a small "briefcase" program that will allow me to quickly
upload, download, and delete files in a briefcase.  The only real
things that I have left to do are to design a method for checking if
the file exists, preventing it from overwriting files from other
directories, and setting a user-configurable maximum limit on the
file's size.  The former two, I can handle by myself with no problem.
However, the I'm having a little trouble with.

thefile = params["upfile.file"]
if os.path.getsize(thefile) <= conf["upmax"]:
print "File Size Okay." #Add Functions Later...
else:
print "File Too Large." #Here, too.

CGItb reported the following error:
TypeError: coercing to Unicode: need string or buffer, instance found
  args = ('coercing to Unicode: need string or buffer, instance
found',)

This seems like an incredibly simple problem, but I just can't seem to
wrap my mind around it.  Thank you for your help.

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


Re: Setting a Limit to the Maximum Size of an Upload

2005-10-24 Thread Fredrik Lundh
"Joey C." wrote:

> thefile = params["upfile.file"]
> if os.path.getsize(thefile) <= conf["upmax"]:
>print "File Size Okay." #Add Functions Later...
> else:
>print "File Too Large." #Here, too.
>
> CGItb reported the following error:
> TypeError: coercing to Unicode: need string or buffer, instance found
>  args = ('coercing to Unicode: need string or buffer, instance
> found',)

cgitb probably also reported what line you got that error for, and the values
of the variables involved.  can you perhaps post that information too?

 



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


Re: Tricky Areas in Python

2005-10-24 Thread Kent Johnson
Steven D'Aprano wrote:
> Alex Martelli wrote:

> Those two are easy. However, and this is where I show my hard-won 
> ignorance, and admit that I don't see the problem with the property 
> examples:
> 
>> class Base(object)
>> def getFoo(self): ...
>> def setFoo(self): ...
>> foo = property(getFoo, setFoo)
>>
>> class Derived(Base):
>> def getFoo(self): 
> 
> 
> Unless the answer is "Why are you using setters and getters anyway? This 
> isn't Java you know."
> 
> Oh wait! Yes I do... the setter doesn't actually take an argument to set 
> the property too. Is that it, or have a missed a cunningly hidden deeper 
> problem?

Derived.getFoo() will not override the use of Base.getFoo() to access the 
attribute foo.

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


Re: High Order Messages in Python

2005-10-24 Thread Kent Johnson
[EMAIL PROTECTED] wrote:
> counting that out(regardless whether it is (dis)advantage or not), what
> else a block can do but not a named function ?

My limited understanding is that the advantage is
- simpler syntax
- high level of integration into the standard library (*many* methods that take 
closure arguments). Blocks are used not just for iteration but for the kinds of 
things shown in the examples to PEP 343 http://www.python.org/peps/pep-0343.html

For example to open a file and read from it uses two closures, one to wrap a 
block with the file open/close, one to iterate lines (from the pickaxe book):

File.open("testfile") do |file|
  file.each_line { |line| puts line }
end

Kent

> 
> Alex Martelli wrote:
> 
>>[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>>
>>
>>>could someone enlighten me what is the advantage of block over named
>>>function ?
>>>
>>>One thing that I can see a difference may be lexical scope ?
>>
>>"Yes, but" -- according to the latest Ruby book, the "mixed lexical
>>scope" of blocks is a highly controversial notion in the Ruby community;
>>so I wouldn't necessarily count it as an _advantage_ of Ruby blocks...
>>
>>
>>Alex
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE recommendation please

2005-10-24 Thread microsnot

> Fast install: just go to the update manager (inside the help menu) and add
> update site: http://pydev.sf.net/updates/ (eclipse should do the rest)

Too easy! Thanks.

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


Re: High Order Messages in Python

2005-10-24 Thread [EMAIL PROTECTED]
thanks. Seems that my programs are very simple and don't need these
feature yet.

Kent Johnson wrote:
> [EMAIL PROTECTED] wrote:
> > counting that out(regardless whether it is (dis)advantage or not), what
> > else a block can do but not a named function ?
>
> My limited understanding is that the advantage is
> - simpler syntax
> - high level of integration into the standard library (*many* methods that 
> take closure arguments). Blocks are used not just for iteration but for the 
> kinds of things shown in the examples to PEP 343 
> http://www.python.org/peps/pep-0343.html
>
> For example to open a file and read from it uses two closures, one to wrap a 
> block with the file open/close, one to iterate lines (from the pickaxe book):
>
> File.open("testfile") do |file|
>   file.each_line { |line| puts line }
> end
>
> Kent
>
> >
> > Alex Martelli wrote:
> >
> >>[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >>
> >>
> >>>could someone enlighten me what is the advantage of block over named
> >>>function ?
> >>>
> >>>One thing that I can see a difference may be lexical scope ?
> >>
> >>"Yes, but" -- according to the latest Ruby book, the "mixed lexical
> >>scope" of blocks is a highly controversial notion in the Ruby community;
> >>so I wouldn't necessarily count it as an _advantage_ of Ruby blocks...
> >>
> >>
> >>Alex
> > 
> >

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


Re: Microsoft Hatred FAQ

2005-10-24 Thread Antoon Pardon
Op 2005-10-23, David Schwartz schreef <[EMAIL PROTECTED]>:
>
> "Roedy Green" <[EMAIL PROTECTED]> wrote in 
> message news:[EMAIL PROTECTED]
>
>> On Sat, 22 Oct 2005 16:10:24 -0700, "David Schwartz"
>> <[EMAIL PROTECTED]> wrote or quoted :
>
>>>If the deal didn't give you more than it cost you, all you had to do 
>>> was
>>>say 'no'. I understand the frustration at being forced to pay for 
>>>something
>>>what it is worth.
>
>> The choice was go along with MS arm twisting or go out of business.
>
> Only because the product they were providing you was so important you 
> were unable to do business without it.
>
>> I call that extortion.
>
> Microsoft had something you need so badly that you could not go into 
> business without it. So they demanded from you that you pay them what their 
> software was actually worth to you. That is not extortion. Everyone who 
> sells something tries to get the maximum possible value for it.

If a company wants to be paid for things it didn't deliver, then I think
that is extortion. Microsoft want te be paid a license on windows for
P.C.'s that were sold without windows.

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


Re: Embedded Python - Sharing memory among scripts, threads

2005-10-24 Thread adsheehan
Any ideas?

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


Re: Tricky Areas in Python

2005-10-24 Thread Fredrik Lundh
Steven D'Aprano wrote:

> Those two are easy. However, and this is where I show
> my hard-won ignorance, and admit that I don't see the
> problem with the property examples:

>> class Base(object)
>> def getFoo(self): ...
>> def setFoo(self): ...
>> foo = property(getFoo, setFoo)
>>
>> class Derived(Base):
>> def getFoo(self): 

the property call in Base binds to the Base.getFoo and Base.setFoo method
*objects*, not the names, so overriding getFoo in Derived won't affect the foo
property.

to get proper dispatching for accessors, you need to add an extra layer:

def getFoo(self): ...
def setFoo(self, ...): ...
def getFooDispatcher(self): self.getFoo() # use normal lookup
def setFooDispatcher(self, ...): self.setFoo(...) # use normal 
lookup
foo = property(getFooDispatcher, setFooDispatcher)

this gotcha is the motivation for this proposal:

http://article.gmane.org/gmane.comp.python.devel/72348

(see that thread for more on this topic)

 



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


Re: [OT] Python vs Ruby

2005-10-24 Thread Scott David Daniels
bruno modulix wrote:
> Scott David Daniels wrote:
>>bruno modulix wrote:
>>>... Another language that failed to make it to the mainstream but is
>>>worth giving a try is Smalltalk - the father of OOPLs (Simula being the
>>>GrandFather). 
>>I would say Simula is the forefather of modern OOPLs, and Smalltalk is
>>the toofather.
> Err... I'm afraid I don't understand this last word (and google have not
> been of much help here)

Sorry, I was being too cute by half.  If Simula is the fore father
(4 away) then Smalltalk is half as far (2) away.  Hence the "toofather."
"Toofather" by analogy with the homophones "fore" and "four" we use the
homophones "two" and "too".

--Scott David Daniels
[EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list


ABOUT FIND

2005-10-24 Thread Shi Mu
I got confused by the following information from the help for "FIND":
find(s, *args)
 find(s, sub [,start [,end]]) -> in

what does *args mean (especially the '*')?

also, in the sub, why put a comma before start?

what does 'in' mean?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: IDE recommendation please

2005-10-24 Thread microsnot
> Just look in the archives of the Pythonmac mailinglist. We have
> discussed this very subject intensively recently, with a pretty
> extensive review of the different IDEs available.

Looking through the mailing list. Any specific subject/dates I should be
looking for?

>> Suggestions for plugins for Eclipse would also be nice.
> 
> Err, Eclipse (imho) is a H-O-G.

Couldn't agree more... But all so useful for Java.

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


Re: IDE recommendation please

2005-10-24 Thread microsnot
> Mac users of SPE collected money for me to buy a Mac. This means that
> in the near future SPE will be especially improved for Mac. So feedback
> from Mac users is more than welcome and will probably be taken into
> account. SPE is a free, open source IDE with a lot of features like a
> debugger, UML diagrams and a GUI designer.

Sounds good and the price is right. :D
I think I'll wait until you get the Mac and get the installer ready as I'm a
bit of a clutz when it comes to the shell. :)

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


Re: ABOUT FIND

2005-10-24 Thread Fredrik Lundh
Shi Mu wrote:

>I got confused by the following information from the help for "FIND":
> find(s, *args)

what "FIND" ?

>>> help(str.find)
Help on method_descriptor:

find(...)
S.find(sub [,start [,end]]) -> int

Return the lowest index in S where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

maybe it's string.find?  (that's a backwards compatibility thing; new code
should use the corresponding method instead).

>>> help(string.find)
Help on function find in module string:

find(s, *args)
find(s, sub [,start [,end]]) -> in

Return the lowest index in s where substring sub is found,
such that sub is contained within s[start,end].  Optional
arguments start and end are interpreted as in slice notation.

Return -1 on failure.

> what does *args mean (especially the '*')?

help() uses introspection to find the function signature, so the first find()
you're seeing is probably how the function is declared, while the second
one comes from the help string itself.  I guess string.find looks like this:

def find(s, *args):
return s.find(*args)

here, the first "*args" means "take a variable number of arguments, and put
the extra arguments in the args variable", the second means "call this method
with arguments taken from the args variable")

but this is an implementation detail (and a limitation in the help system), and
nothing you need to bother with when *using* the find method/function.

> also, in the sub, why put a comma before start?

it means that you should put a comma *between* sub and start if you provide
a start argument, but not add an extra comma if you're only providing a sub
argument.

this would probably be easier to read:

S.find(sub,  [start, [end]]) -> int

but if the help text looked like that, some nincompoop would most likely 
complain
that it was broken since you're not really supposed to write:

S.find(sub,)

(not that it matters in this case; Python ignores trailing commas in function 
calls,
but they look a bit silly).

> what does 'in' mean?

the method help text says "int", so it looks like a typo, or a cut/paste error.

 



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


Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Steve Holden
Antoon Pardon wrote:
> Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>:
> 
>>Antoon Pardon wrote:
>>
>>>It would be better if cmp would give an indication it
>>>can't compare two objects instead of giving incorrect
>>>and inconsistent results.
>>
>>If two objects aren't totally comparable, then using 'cmp' on them is 
>>ill-defined to begin with.
> 
> 
> Where is that documented?
> 
> 
>>The Standard Thing To Do is throw an 
>>exception; see the Highly Obscure Case of the Complex Numbers.
>>
>>
>1 == 1j
>>
>>False
>>
>1 != 1j
>>
>>True
>>
>1 < 1j
>>
>>Traceback (most recent call last):
>>   File "", line 1, in ?
>>TypeError: cannot compare complex numbers using <, <=, >, >=
> 
> 
> I would say this is the wrong answer. The right answer should
> be False IMO.
> 
Well in that case it's time to declare Principia Mathematica obsolete. 
The real numbers are a two-dimensional field, and you are proposing to 
define an ordering for it.

This is a snail that really shoudn't be salted at all.

> Especially in the following case do I think the TypeError is
> the wrong answer:
> 
> 
3 + 0j < 2 + 0j
> 
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: cannot compare complex numbers using <, <=, >, >=
> 
Here you seem to be asking for special-case code to detect complex 
numbers that are on the real line. Mathematically speaking this is an 
infintesimal subset of the complex plane, so you are expecting a lot. 
And presumably next you would argue that "since (3+0j) < (2+0j) returns 
False so should (3+1j) < (2+2j)".

I think you should find something more productive to do with our time. 
And mine ;-)
> 
> Look at sets:
> 
> 
set([1]) <=  set([2])
> 
> False
> 
set([2]) <= set([1])
> 
> False
> 
Set orderingd are explicitly documented as being based on proper 
subsetting. This is an abuse of the operators to make subset tests more 
convenient rather than a definition of an ordering.
> 
[...]
The rest of your post does highlight one or two inconsistencies, but I 
don't frankly see yor proposed solutions making anything better.

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

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


Re: Redirect os.system output

2005-10-24 Thread jas
Any other ideas? or examples of using subprocess to do what I was
asking?


Kent Johnson wrote:
> jas wrote:
> > I would like to redirect the output from os.system to a variable, but
> > am having trouble.  I tried using os.popen(..).read() ...but that
> > doesn't give me exactly what i want.
>
> Here is an example using subprocess:
> http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en&;
>
> Kent
>
> >
> > ..this is windows by the way.
> >
> > For example:
> > tmp = os.popen("hostname").read()
> >
> > ...works as expected.
> >
> > however,
> >
> > tmp = os.popen("cmd").read()
> > ...i would like to have access to the cmd process...i.e. enter commands
> > like a normal command line. os.system() allows this, but i dont want
> > output to the screen..i wanna store it to a variable.  then send
> > content of variable elsewhere,  receive more input and submit it.
> > almost emulate the windows command prompt.
> > 
> > any ideas?
> >

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


Re: New User

2005-10-24 Thread Steve Holden
thatchmatic wrote:
> I just downloaded and I think installed python.  I am not sure if I 
> did cause it does'nt respond to the commands that the read me file 
> told me to use.  Also can someone suggest a trial program I can maybe 
> write for fun?
> 
> Thanks.
> 
> 
> 
1: http://www.python.org/doc/faq/windows.html

2: Depends on your definition of fun, of course :-)
How about a program to print the average of a set
of numbers you type in?

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

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


Re: Python vs Ruby

2005-10-24 Thread Michele Simionato
Alex Martelli wrote:
> ... remember Pascal's "Lettres Provinciales",
> and the famous apology about "I am sorry that this letter is so long,
> but I did not have the time to write a shorter one"!-)

This observation applies to code too. I usually spend most of my time
in making short programs
that would have been long. This means:

cutting off non-essential features (and you can discover that a feature
is non essential only after having implemented it)

and/or

rethinking the problem to a superior level of abstraction (only
possible after you have implented
the lower level of abstraction).

 Michele Simionato

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


Re: output from external commands

2005-10-24 Thread Kent Johnson
darren kirby wrote:
> quoth the James Colannino:
>>So, for example, in Perl I could do something like:
>>
>>@files = `ls`;
>>
>>So I guess I'm looking for something similiar to the backticks in Perl.
>>Forgive me if I've asked something that's a bit basic for this list.
>>Any help would be greatly appreciated :)  Thanks very much in advance.
> 
> 
> If all you want is filenames this will work:
> 
import glob
files = ["%s" % f for f in glob.glob("*")]

or
import os
files = os.listdir('.')

Python has built-in support for many file manipulations, see the os, os.path 
and shutil modules.

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


Re: [OT] Python vs Ruby

2005-10-24 Thread Neil Hodgson
Scott David Daniels:

> Sorry, I was being too cute by half.  If Simula is the fore father
> (4 away) then Smalltalk is half as far (2) away.  Hence the "toofather."
> "Toofather" by analogy with the homophones "fore" and "four" we use the
> homophones "two" and "too".

We could smear the homophones further and say OCaml is the "nextfather".

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


Re: testing '192.168.1.4' is in '192.168.1.0/24' ?

2005-10-24 Thread Peter Hansen
[EMAIL PROTECTED] wrote:
> thanks, that is basically what I am doing and since it is a recipe, I
> would assume there is no standard library module for it.

Well, since a Google search for "site:docs.python.org subnet" turns up 
nothing, one would assume not, but it would be hard to prove it without 
an exhaustive review of the source code. ;-)

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


Small utility program for the windows

2005-10-24 Thread Iyer, Prasad C

Hi,
I am trying to create a small utility program which would be configured
in registry. Something like this
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\*\shell\ShortCut\command]
@="\"python C:\\workspace\\python\\Tut\\ShortCut.py\""


It gives me access denied exception when I try it.
Can anyone help me out.
Following is the code

from Tkinter import *
import sys

class BaseClass(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid()
self.createWidget()
def createWidget(self):
self.text=Text(self, width=20, height=3)
self.text.grid(row=0,column=0)
Button(self, text="ok", command=self.addText).grid(row=1,
column=0)
def addText(self):
print "hello world"

baseClass=BaseClass()
print sys.argv[0]
for i in range(0, len(sys.argv)):
print sys.argv[i]
baseClass.mainloop()



I have to modify the code further so that it takes argument.

This message contains information that may be privileged or confidential and is 
the property of the Capgemini Group. It is intended only for the person to whom 
it is addressed. If you are not the intended recipient,  you are not authorized 
to read, print, retain, copy, disseminate,  distribute, or use this message or 
any part thereof. If you receive this  message in error, please notify the 
sender immediately and delete all  copies of this message.

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


Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Antoon Pardon
Op 2005-10-24, Steve Holden schreef <[EMAIL PROTECTED]>:
> Antoon Pardon wrote:
>> 
>set([1]) <=  set([2])
>> 
>> False
>> 
>set([2]) <= set([1])
>> 
>> False
>> 
> Set orderingd are explicitly documented as being based on proper 
> subsetting. This is an abuse of the operators to make subset tests more 
> convenient rather than a definition of an ordering.

It *is* a definition of an ordering.

For something to be an ordering it has to be anti symmetric and transitive.

The subset relationships on sets conform to these conditions so it is a 
(partial)
ordering. Check your mathematic books, Why you would think this is abuse is 
beyond me.

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


[ANN] Python API InformixDB-2.0 released

2005-10-24 Thread Carsten Haese
Hi everybody,

Thanks to significant code contributions by Daniel Smertnig, I am proud
to announce release 2.0 of the Informix implementation of the Python
DB-API, a mere 5 weeks after release 1.5.

Downloads and info at http://informixdb.sourceforge.net/

This release features the following improvements over InformixDB-1.5:

* Full compliance with version 2 of the DB-API specification, including
many useful optional features suggested by the specification.

* Improved documentation: Command line help and HTML manual.

* Improved portability: The module now builds painlessly on Windows, and
a binary installer for Python 2.4 is provided.

Note that this release requires Python 2.2 or better, and it breaks
backwards compatibility with version 1 of the DB-API specification. If
either of these are a problem for you, you may still use InformixDB-1.5,
but I strongly recommend upgrading as I won't develop InformixDB-1.5 any
further.

Best regards,

Carsten Haese.


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


Print in PythonWin

2005-10-24 Thread Shi Mu
In the PythonWin's interactive window,
why sometimes I need type the command two times to make it work?
for example, I execute "print testList" two times to make it work.
Why?
>>> print testList
>>> print testList
['w', 'e', ' ', 'w', 'a', 'n', 't', ' ', 't', 'o', ' ', 'l', 'e', 'a',
'r', 'n', ' ', 'p', 'y', 't', 'h', 'o', 'n']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Redirect os.system output

2005-10-24 Thread jas
I see that, although I don't totall grasp the code.  However, I am
looking to basically emulate a command prompt.  i.e. everything u see
in the windows command prompt should be displayed back in python.

How can I do it without files?

Kent Johnson wrote:
> jas wrote:
> > Any other ideas? or examples of using subprocess to do what I was
> > asking?
>
> Actually I thought I was giving an example of what you were asking:
> - on windows
> - send a series of commands to a command process
> - capture the result to a variable
>
> The example I referenced sends a series of HELP commands to cmd.exe, captures 
> the output of the commands and saves it to a file.
>
> What did I miss?
>
> Kent
>
> >
> >
> > Kent Johnson wrote:
> >
> >>jas wrote:
> >>
> >>>I would like to redirect the output from os.system to a variable, but
> >>>am having trouble.  I tried using os.popen(..).read() ...but that
> >>>doesn't give me exactly what i want.
> >>
> >>Here is an example using subprocess:
> >>http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en&;
> >>
> >>Kent
> >>
> >>
> >>>..this is windows by the way.
> >>>
> >>>For example:
> >>>tmp = os.popen("hostname").read()
> >>>
> >>>...works as expected.
> >>>
> >>>however,
> >>>
> >>>tmp = os.popen("cmd").read()
> >>>...i would like to have access to the cmd process...i.e. enter commands
> >>>like a normal command line. os.system() allows this, but i dont want
> >>>output to the screen..i wanna store it to a variable.  then send
> >>>content of variable elsewhere,  receive more input and submit it.
> >>>almost emulate the windows command prompt.
> >>>
> >>>any ideas?
> >>>
> > 
> >

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


Re: Microsoft Hatred FAQ

2005-10-24 Thread axel
In comp.lang.perl.misc David Schwartz <[EMAIL PROTECTED]> wrote:
 
> <[EMAIL PROTECTED]> wrote in message 
> news:[EMAIL PROTECTED]
 
>> In comp.lang.perl.misc David Schwartz <[EMAIL PROTECTED]> wrote:
>>> "Mike Meyer" <[EMAIL PROTECTED]> wrote in message
 
 Sorry, but nobody but the government actually owns property. In most
 places, you can't make non-trivial changes to "your" property without
 permission from the government. They even charge you rent on "your"
 property, only they call it "property tax".
 
>>>I see you are a totalitarianist or perhaps a communist. If you want to
>>> live in America and discuss things that are relevent to America, let me
>>> know.
 
>> Why would you say that - Mike Meyer made a point to which you have
>> obviously no answer. Or do you deny that his comments on this matter
>> of property are true?
 
>His comments are not applicable to America. They are applicable to a 
> country where the government owns the economy.
 
>No reply is needed to his comments except to point out that they only 
> apply to a communist or totalitarian state. We don't have one here, so his 
> argument doesn't apply.

The last time I looked, property taxes were enforced in many states of
the USA. Do you deny this?
 
>I am not saying "because you are a communist, your argument is wrong". I 
> am saying, "because your argument is based upon communist or totalitarian 
> premises about the relationship between the government and the economy, it 
> does not apply to the United States, and we were talking about the United 
> States."
 
Then you are sadly deluded if you think that the US government does not
make decisions on the economy.

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


Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Steven D'Aprano
On Mon, 24 Oct 2005 09:23:58 +, Antoon Pardon wrote:

> Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>:
>> Antoon Pardon wrote:
>>> It would be better if cmp would give an indication it
>>> can't compare two objects instead of giving incorrect
>>> and inconsistent results.
>>
>> If two objects aren't totally comparable, then using 'cmp' on them is 
>> ill-defined to begin with.
> 
> Where is that documented?

Surely that is so obvious, it doesn't need documenting? If comparisons
aren't defined between two things ("which is longer, water or fire?") then
comparing them is ill-defined.

On second thoughts... no, I don't believe it is so obvious. People are
used to thinking about comparisons in the context of numbers and strings,
and it won't hurt to remind them that not every pair of objects can be
compared.

>> The Standard Thing To Do is throw an 
>> exception; see the Highly Obscure Case of the Complex Numbers.
>>
>> >>>1 == 1j
>> False
>> >>>1 != 1j
>> True
>> >>>1 < 1j
>> Traceback (most recent call last):
>>File "", line 1, in ?
>> TypeError: cannot compare complex numbers using <, <=, >, >=
> 
> I would say this is the wrong answer. The right answer should
> be False IMO.

I'm afraid that mathematically you are wrong. Greater and less than is not
defined for complex numbers.

I think I see where you are coming from: you are reading "1 < 1j" as "is
one less than one*j", the answer to which is "no". That's a sensible
answer to a sensible question, except for two problems:

(1) you will upset the mathematical purists, who argue that the English
sentence is not quite the same as the mathematical relation; and

(2) you will upset the programmers, since your suggestion would create a
whole class of gotchas and bugs, where people wrongly assume that since
1<1j is False, 1>1j should be True.

This is one case where practicality *is* purity.


> Especially in the following case do I think the TypeError is the wrong
> answer:
> 
 3 + 0j < 2 + 0j
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: cannot compare complex numbers using <, <=, >, >=

That's an interesting case. A mathematical purist might argue that
ordering is not defined for complex numbers, even if the imaginary
component is zero. A *different* purist might argue:

3 = 3+0j
2 = 2+0j

then since 3 > 2 it should also be true that 3+0j > 2+0j.

I can see merit in both arguments, but I'm inclined to go with the second
argument, if and only if the imaginary component is exactly zero. I take
comfort in the fact that mathematicians allow continued fractions with
zero terms even though dividing by zero is verboten.


> Look at sets:
> 
 set([1]) <=  set([2])
> False
 set([2]) <= set([1])
> False

No, sorry, you are making a mistake. In the context of sets, the <
operator doesn't mean "less than", it means "is a subset of". It is
correct to say neither "set([1]) is a subset of set([2])" nor vice versa
is true. Both are false.

By analogy, one can ask, "is the cat inside the box?" and get the answer
"No", but this does not imply that therefore the box must be inside the
cat.


[snip]

>> So your use-case is already well-defined, and rather simple.  Make
>> __cmp__ raise an exception of your choice,
> 
> That is not well defined. It doesn't allow to distinghuish between
> something went wrong in __cmp__ and and answer that indicates the only
> usefull thing you can say is that they are unequal.

Agreed there: there should be a distinct exception for trying to compare
incomparable objects, rather than ValueError or TypeError.


> Besides I find the following result inconsistent:
> 
 set([1]) <= set([1,2])
> True
 cmp(set([1]), set([1,2]))
> Traceback (most recent call last):
>   File "", line 1, in ?
> TypeError: cannot compare sets using cmp()
> 
> The first set is smaller than the second so acoording to the
> documentation, I should get a negative number as a result.

No, the first expression tests whether set([1]) is a subset of set([1,2]),
not whether it is "smaller". Smaller and bigger aren't defined for sets.
Informally, we can say that one set is smaller than another if it has
fewer members, but that's only one possible definition of "smaller" out of
many.

Think, for example, of the set of all US military forces. That has one
member. Compare it to the set of all US presidents whose surname is or was
Bush. That set has two members. Do you think it is sensible definition of
"smaller" to say that the set of US military forces is smaller than the
set of Presidents called Bush?


[snip]

>> then your
>> _ONLY_ choices, no matter your implementation, is to return some
>> possibly inconsistent result (a < b == 1, b < c == 1, a < c == 0) or
>> raise an exception for unapplicable comparisons.
>>
>> This isn't a Python problem; this is a problem from formal mathematics.
> 
> I think it is python's problem if python gives the wrong results.
> 
> when a < b then cmp(a,b) should give a negative nu

difference after remove

2005-10-24 Thread Shi Mu
Is there any difference if I remove the '/'
from the following statement?
intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\
 [1,2,5,3,9,1,1,1,9,1],\
 [0,0,5,1,1,1,9,7,7,7]]
print intMatrix2
I removed one '\' and it still works.
So what is the use of '\'?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Redirect os.system output

2005-10-24 Thread jas
Ok, I tried this...

C:\>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess as sp
>>> p = sp.Popen("cmd", stdout=sp.PIPE)
>>>
>>> result = p.communicate("ipconfig")
'result' is not recognized as an internal or external command,
operable program or batch file.

>>>

basically I was opening to send the "ipconfig" command to cmd.exe and
store the result in the "result" variable.  But you can see there was
an error with result.

Ideas?

jas wrote:
> I see that, although I don't totall grasp the code.  However, I am
> looking to basically emulate a command prompt.  i.e. everything u see
> in the windows command prompt should be displayed back in python.
>
> How can I do it without files?
>
> Kent Johnson wrote:
> > jas wrote:
> > > Any other ideas? or examples of using subprocess to do what I was
> > > asking?
> >
> > Actually I thought I was giving an example of what you were asking:
> > - on windows
> > - send a series of commands to a command process
> > - capture the result to a variable
> >
> > The example I referenced sends a series of HELP commands to cmd.exe, 
> > captures the output of the commands and saves it to a file.
> >
> > What did I miss?
> >
> > Kent
> >
> > >
> > >
> > > Kent Johnson wrote:
> > >
> > >>jas wrote:
> > >>
> > >>>I would like to redirect the output from os.system to a variable, but
> > >>>am having trouble.  I tried using os.popen(..).read() ...but that
> > >>>doesn't give me exactly what i want.
> > >>
> > >>Here is an example using subprocess:
> > >>http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en&;
> > >>
> > >>Kent
> > >>
> > >>
> > >>>..this is windows by the way.
> > >>>
> > >>>For example:
> > >>>tmp = os.popen("hostname").read()
> > >>>
> > >>>...works as expected.
> > >>>
> > >>>however,
> > >>>
> > >>>tmp = os.popen("cmd").read()
> > >>>...i would like to have access to the cmd process...i.e. enter commands
> > >>>like a normal command line. os.system() allows this, but i dont want
> > >>>output to the screen..i wanna store it to a variable.  then send
> > >>>content of variable elsewhere,  receive more input and submit it.
> > >>>almost emulate the windows command prompt.
> > >>>
> > >>>any ideas?
> > >>>
> > > 
> > >

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


Re: How to separate directory list and file list?

2005-10-24 Thread Gonnasi
Lots of thanks for your help, My code can return the right result now.

Thanks again!

On Sun, 23 Oct 2005 17:27:49 +0200, "Fredrik Lundh"
<[EMAIL PROTECTED]> wrote:

>"Gonnasi" wrote:
>
>> With
>> >glob.glob("*")
>>
>> or
>> >os.listdir(cwd)
>>
>> I can get a combined file list with directory list, but I just wanna a
>> bare file list, no directory list. How to get it?
>
>use os.path.isfile on the result.
>
>for file in glob.glob("*"):
>if not os.path.isfile(file):
>continue
>... deal with file ...
>
>for file in os.listdir(cwd):
>file = os.path.join(cwd, file)
>if not os.path.isfile(file):
>continue
>... deal with file ...
>
>files = map(os.path.isfile, glob.glob("*"))
>
>files = (file for file in os.listdir(cwd) if 
> os.path.isfile(os.path.join(cwd, file)))
>
>etc.
>
>
>
>

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


Turn $6 Into 15, 000.oo In 30 Days Or Less Using Paypal 100% Legal!!! "Noreply"

2005-10-24 Thread dreamer
It Will WorkÂ… If you do as I have done! Just Do It! follow the 4 stepsÂ…
$6.00 to $15,000.00 in 30 days!
Steps: Follow the Logic, Just Do it and It will workÂ… $$$ in 4 easy stepsÂ…
1. Set Up a Free Paypal Account. 2. Send $1.00 to six Email Accounts from
your Paypal Account 3. Delete email address #1 and add your email address as
#6. Move all others #2-#6 up one number 4. Copy and Post this entire Letter
to Newsgroups, Messages Boards etcÂ…
Copy this exactly for you guidance to completing steps 1-4. You are in
Business for yourself and you are Creating an E-mail List Company TURN $6
INTO $15,000 IN ONLY 30 DAYS...HERES HOW!
PAYPAL VERIFIES THAT THIS $6 INVESTMENT SCHEME IS 100% LEGAL AND IS A BIG
HIT THIS YEAR SEE THEIR NOTE BELOW OR ASK THEM DIRECTLY... THIS SCHEME MIGHT
TAKE 15-30 MINUTES AND JUST $6, BUT IT IS 100% WORTH IT TO MAKE THOUSANDS SO
QUICKLY. THIS IS NOT ANOTHER SCAM THAT TAKES LOTS OF YOUR HARD EARNED MONEY;
THIS IS A NO RISK INVESTMENT THAT WILL MAKE YOU THOUSANDS OF DOLLARS VERY
EASILY AND QUICKLY.
>From PayPal:
"Dear Member, it has come to our attention that there is a paypal scheme
floating around at the moment you may have heard or seen the $6 scheme. You
may have even taken part in it well we have been asked a lot of questions
about this scheme the answer is yes it does work and yes it is safe to use
providing you follow the rules it is legal and has made a big hit on the
internet this year. If you would like to take part in this scheme or would
like a bit more information then please see the attached file that was
kindly donated to us. Thank you for using PayPal!"
TURN $6 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! This is a Money Scheme and
Not, I repeatÂ… This is Not a Scam!!!
You have most likely seen or heard about this project on TV programs such as
20/20 and Oprah, or you may have read about it in the Wall Street Journal.
If not, here it is below - revealed to you in step-by-step detail. This
program is by no means new. It has been in existence in many forms for at
least a decade. But in the early days, it required a lot more time and
effort, as well as an investment of a few hundred dollars. However thanks to
PayPal and the Internet, the investment is now virtually ZERO! And what's
more, the entire process is FASTER, EASIER, and MORE LUCRATIVE than it has
EVER been! Below is the email sent to me:
How to Turn $6 into $15,000 in 30 Days with PayPal I WAS SHOCKED WHEN I SAW
HOW MUCH MONEY CAME FLOODING INTO MY PAYPAL ACCOUNT I turned $6 into $14,706
within the first 30 days of operating the business plan that I am about to
reveal to you free of charge. If you decide to take action on the following
instructions, I will GUARANTEE that you will enjoy a similar return! STILL
NEED PROOF? Here are just 3 testimonials from the countless individuals who
decided to invest nothing more than $6 and half an hour of their time to
participate in this program:
"What an amazing plan! I followed your instructions just 3 weeks ago, and
although I haven't made 15 grand yet, I'm already up to $9,135. I'm
absolutely gob smacked." -Pam Whittemore , Ohio
"Well, what can I say?... THANK YOU SO MUCH! I sent 40 e-mail's out like you
said and then I just forgot about the whole thing. To be honest, I didn't
really think anything would come of it. But when I checked my paypal account
a week later, there was over $5,000 in After 30 days I now have over $11,000
to spend! I can't thank you enough!"-Juan Tovar, NY,NY
"I was shocked when I saw how much money came flooding into my paypal
account. Within 3 weeks my account balance has ballooned to $12,449. At
first I thought there had been some sort of error with my account!" -Richard
Barrie , Boulder,CO
The only things you will need are: An email address. A Business PayPal
account with at least $6 deposited in it, and just 15 to 30 minutes of your
time. This program takes just half an hour to set up. After that, there is
absolutely no work whatsoever to do on your part. You have absolutely
NOTHING to lose, and there is NO LIMIT to the amount of income you can
generate from this one single business program.
Let's get started, just follow the instructions exactly as set out below and
then prepare yourself for a HUGE influx of cash over the next 30 days!
Here's what you need to do. . .
REQUIREMENTS
#1) an email address #2) a Premier or Business PayPal account
(It's simple and free to get a Premier or Business account, if you need help
doing it just email me.)
Now follow the steps: 1-4

Follow these easy steps EXACTLY and just watch what happens
STEP #1 - Setting up your FREE PayPal Account
It's extremely safe and very easy to set up a FREE PayPal account! Copy and
paste this to the address bar https://www.paypal.com (notice the secure
"https" within the link)
Be sure to sign up for a free PREMIER or BUSINESS account (and not just a
PERSONAL account) otherwise you won't be able to receive credit card
payments from other people.
STEP #2

Re: Redirect os.system output

2005-10-24 Thread Kent Johnson
jas wrote:
> Any other ideas? or examples of using subprocess to do what I was
> asking?

Actually I thought I was giving an example of what you were asking:
- on windows
- send a series of commands to a command process
- capture the result to a variable

The example I referenced sends a series of HELP commands to cmd.exe, captures 
the output of the commands and saves it to a file.

What did I miss?

Kent

> 
> 
> Kent Johnson wrote:
> 
>>jas wrote:
>>
>>>I would like to redirect the output from os.system to a variable, but
>>>am having trouble.  I tried using os.popen(..).read() ...but that
>>>doesn't give me exactly what i want.
>>
>>Here is an example using subprocess:
>>http://groups.google.com/group/comp.lang.python/msg/9fa3a3c287e8e2a3?hl=en&;
>>
>>Kent
>>
>>
>>>..this is windows by the way.
>>>
>>>For example:
>>>tmp = os.popen("hostname").read()
>>>
>>>...works as expected.
>>>
>>>however,
>>>
>>>tmp = os.popen("cmd").read()
>>>...i would like to have access to the cmd process...i.e. enter commands
>>>like a normal command line. os.system() allows this, but i dont want
>>>output to the screen..i wanna store it to a variable.  then send
>>>content of variable elsewhere,  receive more input and submit it.
>>>almost emulate the windows command prompt.
>>>
>>>any ideas?
>>>
> 
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-24 Thread Roedy Green
On Mon, 24 Oct 2005 12:35:13 GMT, [EMAIL PROTECTED] wrote,
quoted or indirectly quoted someone who said :

>I see that you cannot make a reasoned argument against the fact that
>property in the form of houses is taxed in America.

And what has his inability to do that to your satisfaction got to do
with the price of eggs?
-- 
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Microsoft Hatred FAQ

2005-10-24 Thread axel
In comp.lang.perl.misc David Schwartz <[EMAIL PROTECTED]> wrote:
 
>This is about whether we're talking *ABOUT* America, you idiot. It's as 
> if he said the press has no freedom, and I replied, "if you want to talk 
> about some country where that's true, fine, but this discussion presumed 
> America as the basis".
 
>Remember, he is the one who said the government owned the economy. That 
> may be true in some countries, but it's simply *FALSE* in this country. Our 
> government has limited powers and ownership of the economy is not one of 
> them.

I see that you cannot make a reasoned argument against the fact that
property in the form of houses is taxed in America.

Also may I remind you that these newsgroups are international.

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


Re: Redirect os.system output

2005-10-24 Thread Steve Holden
jas wrote:
> Ok, I tried this...
> 
> C:\>python
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
import subprocess as sp
p = sp.Popen("cmd", stdout=sp.PIPE)

result = p.communicate("ipconfig")
> 
> 'result' is not recognized as an internal or external command,
> operable program or batch file.
> 
> 
> 
> basically I was opening to send the "ipconfig" command to cmd.exe and
> store the result in the "result" variable.  But you can see there was
> an error with result.
> 
It looks to me like the line you thought you were typing at the Python 
command interpreter actually got snagged by the command processor you 
just ran, which presumably is taking its input from the console just 
like Python is.

> Ideas?
> 
Haven't used subprocess much yet, but I will just mention that this kind 
of thing always looks easy in principle and turns out to be surprisingly 
gnarly and difficult in practice.

I'm not suggesting you shouldn't continue, but you are going to learn a 
*lot* as you proceed. Good luck.

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

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


Re: Would there be support for a more general cmp/__cmp__

2005-10-24 Thread Antoon Pardon
Op 2005-10-24, Steven D'Aprano schreef <[EMAIL PROTECTED]>:
> On Mon, 24 Oct 2005 09:23:58 +, Antoon Pardon wrote:
>
>> Op 2005-10-21, Christopher Subich schreef <[EMAIL PROTECTED]>:
>>> Antoon Pardon wrote:
 It would be better if cmp would give an indication it
 can't compare two objects instead of giving incorrect
 and inconsistent results.
>>>
>>> If two objects aren't totally comparable, then using 'cmp' on them is 
>>> ill-defined to begin with.
>> 
>> Where is that documented?
>
> Surely that is so obvious, it doesn't need documenting? If comparisons
> aren't defined between two things ("which is longer, water or fire?") then
> comparing them is ill-defined.
>
> On second thoughts... no, I don't believe it is so obvious. People are
> used to thinking about comparisons in the context of numbers and strings,
> and it won't hurt to remind them that not every pair of objects can be
> compared.

I also think there is the problem that people aren't used to partial
ordering. There is an ordering over sets, it is just not a total
ordering. But that some pairs are uncomparable (meaning that neither
one is smaller or greater) doesn't imply that comparing them is
ill defined.

>>> The Standard Thing To Do is throw an 
>>> exception; see the Highly Obscure Case of the Complex Numbers.
>>>
>>> >>>1 == 1j
>>> False
>>> >>>1 != 1j
>>> True
>>> >>>1 < 1j
>>> Traceback (most recent call last):
>>>File "", line 1, in ?
>>> TypeError: cannot compare complex numbers using <, <=, >, >=
>> 
>> I would say this is the wrong answer. The right answer should
>> be False IMO.
>
> I'm afraid that mathematically you are wrong. Greater and less than is not
> defined for complex numbers.
>
> I think I see where you are coming from: you are reading "1 < 1j" as "is
> one less than one*j", the answer to which is "no". That's a sensible
> answer to a sensible question, except for two problems:
>
> (1) you will upset the mathematical purists, who argue that the English
> sentence is not quite the same as the mathematical relation; and
>
> (2) you will upset the programmers, since your suggestion would create a
> whole class of gotchas and bugs, where people wrongly assume that since
> 1<1j is False, 1>1j should be True.
>
> This is one case where practicality *is* purity.

Well it is a wrong assumption is general. There is nothing impure about
partial ordering. 

>> Look at sets:
>> 
> set([1]) <=  set([2])
>> False
> set([2]) <= set([1])
>> False
>
> No, sorry, you are making a mistake. In the context of sets, the <
> operator doesn't mean "less than", it means "is a subset of". It is
> correct to say neither "set([1]) is a subset of set([2])" nor vice versa
> is true. Both are false.

That is IMO irrelevant. The subset relationship is an ordering and as
such has all characteristics of other orderings like "less than",
except that the subset relationship is partial and the less than
relationship is total. How it is called "subset" vs "less than" is
IMO irrelevant. It is about mathematical characteristics.

> By analogy, one can ask, "is the cat inside the box?" and get the answer
> "No", but this does not imply that therefore the box must be inside the
> cat.

Bad analogy, this doesn't define a mathematical ordering, the subset
relationship does.

>> 
> set([1]) <= set([1,2])
>> True
> cmp(set([1]), set([1,2]))
>> Traceback (most recent call last):
>>   File "", line 1, in ?
>> TypeError: cannot compare sets using cmp()
>> 
>> The first set is smaller than the second so acoording to the
>> documentation, I should get a negative number as a result.
>
> No, the first expression tests whether set([1]) is a subset of set([1,2]),
> not whether it is "smaller".

This is quibling with words. Both test whether one comes before the
other is a certain order.

> Smaller and bigger aren't defined for sets.

It is not about smaller or bigger, it is about the general concept
of (mathematical) order. Whether you call this order, subset or
less than is not important. 

>>> then your
>>> _ONLY_ choices, no matter your implementation, is to return some
>>> possibly inconsistent result (a < b == 1, b < c == 1, a < c == 0) or
>>> raise an exception for unapplicable comparisons.
>>>
>>> This isn't a Python problem; this is a problem from formal mathematics.
>> 
>> I think it is python's problem if python gives the wrong results.
>> 
>> when a < b then cmp(a,b) should give a negative number as a result.
>> Python sometimes does not!
>> 
>> when not a < b then cmp(a,b) should not give a negative number as a
>> result. Python sometimes does!
>> 
>> I think those are python problems.
>
> I think you need to give examples of where < or > *defined as comparisons*
> returns the wrong results. The examples from sets do not count, because
> the operators aren't being used for comparisons.

IMO they count, because the subset relationship is a mathematical order
relation just as less than is one.

>>> Personally, I'd favor the "ra

Re: difference after remove

2005-10-24 Thread Christoph Haas
On Monday 24 October 2005 15:02, Shi Mu wrote:
> Is there any difference if I remove the '/'
> from the following statement?

You probably mean '\' instead of '/'.

> intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\
>  [1,2,5,3,9,1,1,1,9,1],\
>  [0,0,5,1,1,1,9,7,7,7]]
> print intMatrix2
> I removed one '\' and it still works.
> So what is the use of '\'?

It's a line continuation character. But you can omit it if it's clear to
the interpreter that the line must continue - like when using brackets.

 Christoph
-- 
~
~
".signature" [Modified] 1 line --100%--1,48 All

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


Re: difference after remove

2005-10-24 Thread Steve Holden
Shi Mu wrote:
> Is there any difference if I remove the '/'
\
> from the following statement?
> intMatrix2 = [[1,1,2,4,1,7,1,7,6,9],\
>  [1,2,5,3,9,1,1,1,9,1],\
>  [0,0,5,1,1,1,9,7,7,7]]
> print intMatrix2
> I removed one '\' and it still works.
> So what is the use of '\'?

You only need line continuations if you aren't inside brackets, braces 
or parentheses. Inside these paired delimiters Python assumes you know 
what you are doing and will continue the statement or expression on the 
next line.

  >>> print "This is a continued"\
  ...   " statement"
This is a continued statement
  >>>

Note that Python *knew* the statement was complete at the end of the 
second line.

Inside an extended string literal (""" or ''') it has the effect of 
removing the newline that would otherwise appear in the string.

  >>> print repr("""This string has a
  ... newline in it""")
'This string has a\nnewline in it'
  >>> print repr("""There is no \
  ... newline in this string""")
'There is no newline in this string'
  >>>

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

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


more than 100 capturing groups in a regex

2005-10-24 Thread Joerg Schuster
Hello,

Python regular expressions must not have more than 100 capturing
groups. The source code responsible for this reads as follows:


# XXX:  get rid of this limitation!
if p.pattern.groups > 100:
raise AssertionError(
"sorry, but this version only supports 100 named groups"
)

I have been waiting a long time now for Python to get rid of this
limitation.
I could make a program of mine a lot faster with an easy hack if Python
did not have it.

My question is: Does anyone know if the problem is going to be fixed in
the next few months or so? Or is there a way to circumvent it?


Jörg Schuster

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


Re: Redirect os.system output

2005-10-24 Thread jas
doesn't sound to encouraging :)

How about something with os.popen?

in = os.popen("cmd", "w")
in.write("hostname")

I tried this, and I get "IOError: [Errno 22] Invalid Argument"

I am not sure why this isnt working.

Steve Holden wrote:
> jas wrote:
> > Ok, I tried this...
> >
> > C:\>python
> > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
> > on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> import subprocess as sp
> p = sp.Popen("cmd", stdout=sp.PIPE)
> 
> result = p.communicate("ipconfig")
> >
> > 'result' is not recognized as an internal or external command,
> > operable program or batch file.
> >
> >
> >
> > basically I was opening to send the "ipconfig" command to cmd.exe and
> > store the result in the "result" variable.  But you can see there was
> > an error with result.
> >
> It looks to me like the line you thought you were typing at the Python
> command interpreter actually got snagged by the command processor you
> just ran, which presumably is taking its input from the console just
> like Python is.
>
> > Ideas?
> >
> Haven't used subprocess much yet, but I will just mention that this kind
> of thing always looks easy in principle and turns out to be surprisingly
> gnarly and difficult in practice.
>
> I'm not suggesting you shouldn't continue, but you are going to learn a
> *lot* as you proceed. Good luck.
>
> regards
>   Steve
> [...]
> --
> Steve Holden   +44 150 684 7255  +1 800 494 3119
> Holden Web LLC www.holdenweb.com
> PyCon TX 2006  www.python.org/pycon/

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


Re: write a loopin one line; process file paths

2005-10-24 Thread John Thingstad
On Wed, 19 Oct 2005 11:48:01 +0200, Xah Lee <[EMAIL PROTECTED]> wrote:

> Thanks a lot for various notes. Bonono?
>
> I will have to look at the itertools module. Just went to the doc
> http://www.python.org/doc/2.4.1/lib/module-itertools.html
> looks interesting.
>
>> But I believe Python is designed for easy to code and read and maintain
>> in mind.
>
>> One has to admit that without some training, FP is not very
>> intuitive, my head spin when I see haskell code. A for loop is easier
>> to understand.
>
> This i'm not sure. Of the past couple of years i increasingly developed
> a theory (probably well-known among proper experts), that the
> difficulty of human feats of various forms, are primarily a perception
> and familiarity thing. This may be getting off topic, but i wrote an
> essay expresising much of the idea using Juggling as a example:
> Difficulty Perceptions in Human Feats
>  http://xahlee.org/Periodic_dosage_dir/t2/juggling.html
>
> likewise, i think this applies to mental feats as well. In particular,
> i think that whether imperative code or functional code is easier for
> the mind is almost ENTIRELY dependent on which one the person is more
> familiar with, coulped with a innate attitude one may have picked up.
>
>> Well, if you want clean FP, you can always try haskell which is getting
>> better and better in terms of real world module support(file system,
>> network etc).
>
> oh Haskell, my love! I am really going to learn it now. (maybe i'll
> start A-Java-Haskell-A-Day) This month i just learned and read about
> how Perl 6 is implemented in Haskell! (because one Taiwaness hacker
> single-handedly by happenstance tried to do it, as a by-product of
> learning Haskell) This Pugs (Perl6 in Haskell) really brought two
> rather incompatible communities together somewhat for mutual exchange.
> (the learning, on the surface, is politely said to be mutual, but i'm
> pretty sure it's mostly Perlers learning from the Haskell folks)
>
> ... there is a sentiment among the elite tech-geeking morons, early on
> imbued by the concept of troll, so that they in general don't
> communicate and learn from any other language except their own.
> Anything cross-posted is considered as troll, and the inter-language
> communication has been essentially completely cut off. Basically, the
> only ones generating all the garbage posts are these troll-criers
> themselves. (will have to flesh out on this particular point of
> net-sociology in a essay some other day.)
>
>  Xah
>  [EMAIL PROTECTED]
> ∑ http://xahlee.org/
>

Honestly.. "your programming skills suck"

John

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: write a loopin one line; process file paths

2005-10-24 Thread Graham Fawcett
Xah Lee wrote:
> Dear Peter Hansen,
> My messages speak themselfs. You and your cohorts's stamping of it does
> not change its nature. And if this is done with repetitiousness, it
> gives away your nature.

Taunt not the cohorts of Peter Hansen!

Graham

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


Re: newbie question about SocketServer

2005-10-24 Thread [EMAIL PROTECTED]
After further playing - it seems that the server_close() just takes
time to execute.  I have found that if I wait a while (1-3 seconds) the
second connection will fail as well.  Locking is already built into my
handler class - so I'll just use it to prevent further connections
until server_close() completes.

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


Re: output from external commands

2005-10-24 Thread Mike Meyer
darren kirby <[EMAIL PROTECTED]> writes:
> If all you want is filenames this will work:
 import glob
 files = ["%s" % f for f in glob.glob("*")]

What's the point of doing "%s" % f? How is this different from just
file = [f for f in glob.glob("*")]?

   http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Execute C code through Python

2005-10-24 Thread Ernesto

Fredrik Lundh wrote:
> "Ernesto" wrote:
>
> > Thanks.  Can anyone provide an example of using *subprocess* to run
> > helloWorld.C through the python interpreter.
>
> compile helloWorld, and run:
>
> import subprocess
> subprocess.call("helloWorld")
>
> (any special reason why you couldn't figure this out yourself, given the
> example provided by gsteff ?)
>
> 

There is a reason (though it is not special).  I'm new to Python.  I
looked at all the documentation on subprocess, as well as popen.  I
couldn't figure it out, so I thought an example (which I thank you for
providing) would help me along (which it did).  Is there a special
reason for you having a problem with me asking for help?  I thought
that's what this group is for.

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


Read/Write from/to a process

2005-10-24 Thread jas
Hi,
  I would like to start a new process and be able to read/write from/to
it.  I have tried things like...

import subprocess as sp
p = sp.Popen("cmd.exe", stdout=sp.PIPE)
p.stdin.write("hostname\n")

however, it doesn't seem to work.  I think the cmd.exe is catching it.

I also tried
f = open("out.txt", "w")
sys.stdout = f
os.system("cmd.exe")

..but out.txt didn't contain any output from cmd.exe

So, how can I create a process (in this case, cmd.exe) on Windows and
be able to read/write from/to it?

Thanks

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


importing pickle modlue execute the code twice ??

2005-10-24 Thread ychaouche
Hi !

i am having a strange experience with the pickle module. I use
python2.4 and i really don't understand what is happening on ! take a
look at this :


import pickle
print "hello"


hello
hello




#import pickle
print "hello"


hello


I just don't get it.

Thank you for any advice or help !

Y.Chaouche

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


Re: Set an environment variable

2005-10-24 Thread Grant Edwards
On 2005-10-24, Eric Brunel <[EMAIL PROTECTED]> wrote:

>> The only think you can export an environment variable to is a
>> child process
>
> Well, you know that, and I know that too. From my experience,
> many people don't...

True.  Using Unix for 20+ years probably warps one's perception
of what's obvious and what isn't.

-- 
Grant Edwards   grante Yow!  My face is new, my
  at   license is expired, and I'm
   visi.comunder a doctor's care
-- 
http://mail.python.org/mailman/listinfo/python-list


Python/Apache Oddness On OSX

2005-10-24 Thread John Abel
Hi,

I'm running Python 2.3.5/2.4.2 on OSX 10.4.2, and am trying to run CGI 
scripts using the builtin Apache.  For ease, I've symlinked my custom 
modules into the /Library/Python/2.3/site-packages directory, and they 
import OK via command line python.  However, when I perform the import 
from a cgi script, python fails to find the module.  It is definately 
something to do with the symlink, as the CGI works OK if I copy the 
directory into site-packages.  Is there some oddness with Python/Apache 
and symlink imports?

Any pointers would be most useful.

Thanks

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


Re: Execute C code through Python

2005-10-24 Thread Fredrik Lundh
Ernesto wrote:

>> > Thanks.  Can anyone provide an example of using *subprocess* to run
>> > helloWorld.C through the python interpreter.
>>
>> compile helloWorld, and run:
>>
>> import subprocess
>> subprocess.call("helloWorld")
>>
>> (any special reason why you couldn't figure this out yourself, given the
>> example provided by gsteff ?)
>
> There is a reason (though it is not special).  I'm new to Python.  I
> looked at all the documentation on subprocess, as well as popen.  I
> couldn't figure it out, so I thought an example (which I thank you for
> providing) would help me along (which it did).

as I noted in the part of my reply that you didn't read, the person you replied 
to
(gsteff) also provided an example.  Since his post didn't contain any other 
text, I
did find it a bit strange that you missed that part of his message, but still 
managed
to reply to it.

 



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


Re: importing pickle modlue execute the code twice ??

2005-10-24 Thread Fredrik Lundh
"ychaouche" wrote:

> i am having a strange experience with the pickle module. I use
> python2.4 and i really don't understand what is happening on !
> take a look at this :
>
> 
> import pickle
> print "hello"
> 
> 
> hello
> hello
> 

did you perhaps name your test program "pickle.py" ?

 



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


Re: High Order Messages in Python

2005-10-24 Thread Alex Martelli
Kent Johnson <[EMAIL PROTECTED]> wrote:
   ...
> For example to open a file and read from it uses two closures, one to wrap
> a block with the file open/close, one to iterate lines (from the pickaxe
> book):
> 
> File.open("testfile") do |file|
>   file.each_line { |line| puts line }
> end

Good example -- Ruby blocks are used both for iteration, and for
non-iterative wrapping of a single action with "try-finally" semantics.

Python's generators, up to 2.4, don't really support the non-iterative
part of this well, and have other limitations (they can get values "out"
with yield, but can't easily or naturally get results back "in"...).  In
the forthcoming 2.5, Python generators will be enriched with enough
functionality for these purposes, and a new statement "with" to clearly
indicate the non-iterative case (while "for" indicates iteration).

So, in Python 2.5, the above snippet may become, in Python:

with opening("testfile") as my_file:
for line in my_file:
print line,

The fact that 2.5 will acquire extra functionality to "round out"
generators &c to the power of Ruby blocks may be taken as a clear
indication that, right now (Ruby 1.8.* vs Python 2.4.*), Ruby's blocks
are somewhat more powerful.  As for the differences in style that will
remain when Python 2.5 is born, we'll be back to "personal taste" level
issues, it appears to me.


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


Re: Microsoft Hatred FAQ

2005-10-24 Thread Terry Hancock
On Saturday 22 October 2005 05:44 pm, Tim Tyler wrote:
> Microsoft still comes in at number 2 - on:
> http://dmoz.org/Society/Issues/Business/Allegedly_Unethical_Firms/
> Few companies are more despised than Microsoft.

Wrong URL?
No such list appears at that site, although it does link to several
different lists and topic-related sites. The two lists I happened
to check are years out of date (one was from 1994!) and do not even
list Microsoft.

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Tricky Areas in Python

2005-10-24 Thread Alex Martelli
Steven D'Aprano <[EMAIL PROTECTED]> wrote:
   ...
> my hard-won ignorance, and admit that I don't see the 
> problem with the property examples:
> 
> > class Sic:
> > def getFoo(self): ...
> > def setFoo(self): ...
> > foo = property(getFoo, setFoo)

Sorry for skipping the 2nd argument to setFoo, that was accidental in my
post.  The problem here is: class Sic is "classic" ("legacy",
"old-style") so property won't really work for it (the setter will NOT
trigger when you assign to s.foo and s is an instance of Sic).

> > to
> > class Base(object)
> > def getFoo(self): ...
> > def setFoo(self): ...
> > foo = property(getFoo, setFoo)
> > 
> > class Derived(Base):
> > def getFoo(self): 
> 
> Unless the answer is "Why are you using setters and 
> getters anyway? This isn't Java you know."

Nope, that's not a problem -- presumably the "..." bodies DO something
useful, and they do get nicely dressed in attribute syntax.  The
problem, as others have indicated, is that overriding doesn't work as
one might expect -- the solution, in Python 2.4 and earlier, is to use
one extra level of indirection:
def __getFoo(self): return self.getFoo()
def getFoo(self): ...
foo = property(__getFoo)
so the name lookup for 'getFoo' on self happens when you access s.foo
(for s being an instance of this here-sketched class) and overriding
works just as expected.  This can be seen as the simplest possible use
case for the "Template Method" Design Pattern, btw;-)


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


Re: Python vs Ruby

2005-10-24 Thread Alex Martelli
Michele Simionato <[EMAIL PROTECTED]> wrote:

> Alex Martelli wrote:
> > ... remember Pascal's "Lettres Provinciales",
> > and the famous apology about "I am sorry that this letter is so long,
> > but I did not have the time to write a shorter one"!-)
> 
> This observation applies to code too. I usually spend most of my time
> in making short programs
> that would have been long. This means:

Absolutely true.

> cutting off non-essential features (and you can discover that a feature
> is non essential only after having implemented it)

This one is difficult if you have RELEASED the program with the feature
you now want to remove, sigh.  You end up with lots of "deprecated"s...
somebody at Euro OSCON was saying that this was why they had dropped
Java, many years ago -- each time they upgraded their Java SDK they
found out that half their code used now-deprecated features.

Still, I agree that (once in a while) accepting backwards
incompatibility by removing features IS a good thing (and I look
forwards a lot to Python 3.0!-).  But -- the "dream" solution would be
to work closely with customers from the start, XP-style, so features go
into the code in descending order of urgence and importance and it's
hardly ever necessary to remove them.

> and/or
> 
> rethinking the problem to a superior level of abstraction (only
> possible after you have implented
> the lower level of abstraction).

Yep, this one is truly crucial.

But if I had do nominate ONE use case for "making code smaller" it would
be: "Once, And Only Once" (aka "Don't Repeat Yourself").  Scan your code
ceaselessly mercilessly looking for duplications and refactor just as
mercilessly when you find them, "abstracting the up" into functions,
base classes, etc...


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


Re: more than 100 capturing groups in a regex

2005-10-24 Thread skip
Joerg> Or is there a way to circumvent [capturing groups limitation]?

Sure, submit a patch to SourceForge that removes the restriction.

I've never come anywhere close to creating regular expressions that need to
capture 100 groups even though I generate regular expressions from a
higher-level representation.  I suspect few will have hit that limit.
Perhaps explain what motivates you to want to capture that many groups.
Other people may be able to suggest alternatives.  And remember:

Some people, when confronted with a problem, think "I know, I'll use
regular expressions." Now they have two problems. --Jamie Zawinski

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


Re: testing '192.168.1.4' is in '192.168.1.0/24' ?

2005-10-24 Thread gry
There was just recently announced -- iplib-0.9:
http://groups.google.com/group/comp.lang.python.announce/browse_frm/thread/e289a42714213fb1/ec53921d1545bf69#ec53921d1545bf69

 It appears to be pure python and has facilities for dealing with
netmasks. (v4 only).

-- George

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


Re: Microsoft Hatred FAQ

2005-10-24 Thread Terry Hancock
On Monday 24 October 2005 08:19 am, Roedy Green wrote:
> On Mon, 24 Oct 2005 12:35:13 GMT, [EMAIL PROTECTED] wrote,
> quoted or indirectly quoted someone who said :
> 
> >I see that you cannot make a reasoned argument against the fact that
> >property in the form of houses is taxed in America.
> 
> And what has his inability to do that to your satisfaction got to do
> with the price of eggs?

Funny you should ask that.  Taxation, mostly in the form of income tax
supports a system of farm subsidies in the United States, that pays
farmers for surplus product, thus artificially elevating the price of
several farm products, including milk, cheese, and (you guessed it) eggs.

The purpose of this (ostensibly anyway) is to keep family farmers in
business, because that is viewed as a social benefit in itself (I happen
to agree with this statement, even if it does mean I pay more for eggs --
though the price is still one of the lowest globally, because the US has
such a large natural surplus of agricultural products owing to arable
land and mostly good weather).

Of course it does produce one of the most notorious examples of wastage --
much of that surplus is allowed to rot (or at least this *was* true at one
time, I haven't fact-checked that in over a decade).  It has been proposed
that most of that food should instead go to foreign aid, or to programs
within the US for eliminating poverty. Certainly some of it does, I
have no idea what the current balance is, though.

The ability to do this, moreover represents the philosophical point
that the government "owns" the economy, in that it has the right,
representing the interests of the people, to pursue public good by
manipulating the economy. In other words, we do not believe in the
formal concept of a laissez faire economy, nor in the idea of "anarchic
libertarianism".

People who do support the latter kind of idea frequently say that a
company should be "allowed to do anything to pursue profit, as long
as it isn't illegal".  But of course, they usually turn around and
say that "there is no natural law". The combination of the two philosophies
is nonsensical -- if law consists only of artificial constraints, then
there is no natural basis for arguing what the law "should" allow. Hence,
only the will of the people matters, which means any form of monopoly
restriction is entirely within the powers of a democratic government
to pursue.

Since this includes ANY economic system from "laissez faire capitalism"
to "pure communism", it has no persuasive power whatsoever, and should
be dropped.

If on the other hand, you believe (as I do), that State law is an
embodiment, backed up by State power, to implement the best approximation
we can manage of "natural law" (i.e. law as evident to at least a
consensus of human minds, albeit through transcendental rather than
empirical derivation), then there IS a basis for arguing what laws
"should" be.  But you can't make arguments about what law "should"
be if you don't acknowledge that law is measured against some external
standard.

This is of course, another result of the Human tendency to confuse
"NULL" with "ZERO".  The absence of an external system of evaluating
law, does not mean that all laws must be negated. It equates to having
no basis for prefering them to exist or not, and thus abdicating all
right to change them.  People who believe this really need, therefore,
to shut up.

;-D

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: Python vs Ruby

2005-10-24 Thread Jorge Godoy
[EMAIL PROTECTED] (Alex Martelli) writes:

> forwards a lot to Python 3.0!-).  But -- the "dream" solution would be
> to work closely with customers from the start, XP-style, so features go
> into the code in descending order of urgence and importance and it's
> hardly ever necessary to remove them.

We do that often with two of our customers here.  After the first changes,
they asked for more.  And them some other and when it finally ended, the
project was like we had suggested, but instead of doing this directly, the
client wanted to waste more money... :-(  Even if we earnt more money, I'd
rather have the first proposal accepted instead of wasting time working on
what they called "essential features". 

> But if I had do nominate ONE use case for "making code smaller" it would
> be: "Once, And Only Once" (aka "Don't Repeat Yourself").  Scan your code
> ceaselessly mercilessly looking for duplications and refactor just as
> mercilessly when you find them, "abstracting the up" into functions,
> base classes, etc...

And I'd second that.  Code can be drastically reduced this way and even
better: it can be made more generic, more useful and robustness is improved. 

-- 
Jorge Godoy  <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tricky Areas in Python

2005-10-24 Thread Steven Bethard
Alex Martelli wrote:
> 
>>>class Base(object)
>>>def getFoo(self): ...
>>>def setFoo(self): ...
>>>foo = property(getFoo, setFoo)
>>>
>>>class Derived(Base):
>>>def getFoo(self): 
>>
[snip]
> the solution, in Python 2.4 and earlier, is to use
> one extra level of indirection:
> def __getFoo(self): return self.getFoo()
> def getFoo(self): ...
> foo = property(__getFoo)
> so the name lookup for 'getFoo' on self happens when you access s.foo
> (for s being an instance of this here-sketched class) and overriding
> works just as expected.

Another solution (for those of you scoring at home) would be to use a 
property-like descriptor that delays the name lookup until the time of 
the method call, e.g.

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442418
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/408713

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


Re: Python vs Ruby

2005-10-24 Thread Michele Simionato
Alex Martelli:
> Michele Simionato:
>> cutting off non-essential features (and you can discover that a feature
>> is non essential only after having implemented it)

> This one is difficult if you have RELEASED the program with the feature
> you now want to remove, sigh.

Yeah, but I used the wrong word "features", which typically means "end
user features".
Instead, I had in mind "developer features", i.e. core features that
will be called later
in "client" code (I am in a framework mindset here).

Typically I start with a small class, then the class becomes larger as
I add features that will
be useful for client code, then I discover than the class has become
difficult to mantain.
So I cut the features and and I implement them outside the class and
the class becomes
short again.

However, I *cannot* know from the beginning what is the minimal set of
features
needed to make short the client code until I write a lot of client
code. I can make things short
only after I have made things long. I think this applies to me, to you,
to Pascal and to
everybody in general. It is impossible to start from the beginning with
the short program,
unless you already know the solution (that means, you have already
written the long
version in the past). Still, some naive people think there is a silver
bullet or an easy way
to avoid the hard work. They are naive ;)

Michele Simionato

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


Re: Redirect os.system output

2005-10-24 Thread Kent Johnson
jas wrote:
> Ok, I tried this...
> 
> C:\>python
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
> on win32
> Type "help", "copyright", "credits" or "license" for more information.
> 
import subprocess as sp
p = sp.Popen("cmd", stdout=sp.PIPE)

result = p.communicate("ipconfig")
> 
> 'result' is not recognized as an internal or external command,
> operable program or batch file.
> 
> 
> 
> basically I was opening to send the "ipconfig" command to cmd.exe and
> store the result in the "result" variable.  But you can see there was
> an error with result.

This works for me:
import subprocess as sp
p = sp.Popen("ipconfig", stdout=sp.PIPE)
result = p.communicate()[0]
print result

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


Re: Redirect os.system output

2005-10-24 Thread jas
Kent,
  Yes, your example does work.  So did os.popen...however, the problem
is specific to "cmd.exe".
   Have you tried that yet?

Thanks!

Kent Johnson wrote:
> jas wrote:
> > Ok, I tried this...
> >
> > C:\>python
> > Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
> > on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> import subprocess as sp
> p = sp.Popen("cmd", stdout=sp.PIPE)
> 
> result = p.communicate("ipconfig")
> >
> > 'result' is not recognized as an internal or external command,
> > operable program or batch file.
> >
> >
> >
> > basically I was opening to send the "ipconfig" command to cmd.exe and
> > store the result in the "result" variable.  But you can see there was
> > an error with result.
>
> This works for me:
> import subprocess as sp
> p = sp.Popen("ipconfig", stdout=sp.PIPE)
> result = p.communicate()[0]
> print result
> 
> Kent

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


Re: output from external commands

2005-10-24 Thread Peter Hansen
Mike Meyer wrote:
> darren kirby <[EMAIL PROTECTED]> writes:
> 
>>If all you want is filenames this will work:
>>
>import glob
>files = ["%s" % f for f in glob.glob("*")]
> 
> 
> What's the point of doing "%s" % f? How is this different from just
> file = [f for f in glob.glob("*")]?

Answering narrowly, the difference is that using "%s" calls str() on the 
items in the result list, while your suggestion does not.  ("Why not 
just use str(f) instead of the less clear '%s' % f?" would be a valid 
question too though.)

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


Re: Python variables are bound to types when used?

2005-10-24 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote:
> the page was written before the "type/class unification" in Python 2.2,
> at a time where the word "type" had a stricter meaning (referring to C-
> level types, not user-level classes).

Gotcha.  Thanks.

That writeup is definitely on my required reading list for new Python
programmers.

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


Re: Read/Write from/to a process

2005-10-24 Thread jas
Thanks, that is certainly a start.  As you mentioned, the "cd" could is
an issue.

Perhaps checking to see if the line ends with ">" is sufficient?

Dennis Lee Bieber wrote:
> On 24 Oct 2005 07:20:42 -0700, "jas" <[EMAIL PROTECTED]> declaimed the
> following in comp.lang.python:
>
> > Hi,
> >   I would like to start a new process and be able to read/write from/to
> > it.  I have tried things like...
> >
> > import subprocess as sp
> > p = sp.Popen("cmd.exe", stdout=sp.PIPE)
> > p.stdin.write("hostname\n")
> >
> > however, it doesn't seem to work.  I think the cmd.exe is catching it.
>
>   One: you didn't read any of the "returned" output...
>
>   Two: the output only seems to be available upon EOF, which means the
> spawned command processor has to exit first... Though you CAN read one
> character at a time, and then have to build lines and expected prompt
> strings...
>
>
> This seems to work:
> -=-=-=-=-=-=-=-=-
> import subprocess
> import os
>
> PROMPT = os.getcwd() + ">"
>
> def getLine(proc):
> ld = []
> while True:
> c = proc.stdout.read(1)
> if c == "\r": continue  #skip Windows 
> if c != "\n": ld.append(c) #save all but 
> if c is None or c == "\n" or c == ">": break
> ln = "".join(ld)
> return ln
>
> p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stdin =
> subprocess.PIPE)
>
> print " START of captured output"
> while True:
> ln = getLine(p)
> print ln
> if ln == PROMPT: break
> print " END of captured output"
>
> p.stdin.write("ipconfig\n")
> print " START of captured output"
> while True:
> ln = getLine(p)
> print ln
> if ln == PROMPT: break
> print " END of captured output"
>
> p.stdin.write("dir\n")
> print " START of captured output"
> while True:
> ln = getLine(p)
> print ln
> if ln == PROMPT: break
> print " END of captured output"
>
> p.stdin.write("exit\n")
> -=-=-=-=-=-=-=-=-=-
> E:\UserData\Dennis Lee Bieber\My Documents>python script1.py
>  START of captured output
> Microsoft Windows XP [Version 5.1.2600]
> (C) Copyright 1985-2001 Microsoft Corp.
>
> E:\UserData\Dennis Lee Bieber\My Documents>
>  END of captured output
>  START of captured output
> ipconfig
>
> Windows IP Configuration
>
>
> Ethernet adapter Local Area Connection:
>
> Connection-specific DNS Suffix  . :
> IP Address. . . . . . . . . . . . : 192.168.1.100
> Subnet Mask . . . . . . . . . . . : 255.255.255.0
> IP Address. . . . . . . . . . . . : fe80::211:11ff:fee1:f303%4
> Default Gateway . . . . . . . . . : 192.168.1.1
>
> Tunnel adapter Teredo Tunneling Pseudo-Interface:
>
> Connection-specific DNS Suffix  . :
> IP Address. . . . . . . . . . . . :
> 3ffe:831f:4004:1956:0:fbde:bd0a:e50b
> IP Address. . . . . . . . . . . . : fe80::5445:5245:444f%5
> Default Gateway . . . . . . . . . : ::
>
> Tunnel adapter Automatic Tunneling Pseudo-Interface:
>
> Connection-specific DNS Suffix  . :
> IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2
> Default Gateway . . . . . . . . . :
>
> E:\UserData\Dennis Lee Bieber\My Documents>
>  END of captured output
>  START of captured output
> dir
>  Volume in drive E is Data
>  Volume Serial Number is 2626-D991
>
>  Directory of E:\UserData\Dennis Lee Bieber\My Documents
>
> 10/24/2005  09:23 AM
>   .
> 10/24/2005  09:23 AM
>   ..
> 07/25/2005  10:39 PM
>   .metadata
> 10/06/2005  09:54 AM
>   Ada Progs
> 08/13/2005  02:01 PM
>   Agent Data
> 10/21/2005  09:29 AM   421,820 apress_offer.pdf
> 07/03/2005  11:36 AM   132 cp.py
> 07/17/2005  12:25 PM
>   Cyberlink
> 07/06/2005  09:32 AM   102,400 db1.mdb
> 07/26/2005  12:20 AM26,614 eclipse_code.xml
> 10/24/2005  01:08 AM
>   Eudora
> 06/24/2005  08:50 PM   667 fake_oosums.ads
> 06/24/2005  08:50 PM   695 fake_oosums.ali
> 09/06/2005  09:01 PM
>   Genealogy
> 07/13/2005  10:56 PM
>   HomeSite
> 05/08/2005  01:05 PM
>   Investing
> 10/21/2005  10:04 PM
>   Java Progs
> 08/04/2005  10:13 PM   162 main.py
> 10/11/2005  10:43 PM
>   My Downloads
> 05/01/2005  10:31 AM
>   My eBooks
> 04/22/2005  12:09 AM
>   My Music
> 07/10/2005  11:43 AM
>   My Pictures
> 06/29/2005  11:55 PM
>   My PSP Files
> 05/23/2005  09:30 AM
>   My Videos
> 05/01/2005  12:49 PM
>   Office Documents
> 06/27/2005  03:19 PM 7,961,778
> org.eclipse.jdt.doc.user.I20050627-1435.pdf
> 06/27/2005  03:19 PM 6,791,109
> org.eclipse.platform.doc.user.I20050627-1435.pdf
> 10/11/2005  10:52 PM56 oth_tsr_rm_750.ram
> 07/20/2005  09:32 AM   108,457 parkerred15yc.jpg
> 09/03/2005  10:36 PM
>   Pytho

Re: Read/Write from/to a process

2005-10-24 Thread jas
actually, i can't check for ">" only because if you a dir, a line can
end with a > but is not the end of the output

jas wrote:
> Thanks, that is certainly a start.  As you mentioned, the "cd" could is
> an issue.
>
> Perhaps checking to see if the line ends with ">" is sufficient?
>
> Dennis Lee Bieber wrote:
> > On 24 Oct 2005 07:20:42 -0700, "jas" <[EMAIL PROTECTED]> declaimed the
> > following in comp.lang.python:
> >
> > > Hi,
> > >   I would like to start a new process and be able to read/write from/to
> > > it.  I have tried things like...
> > >
> > > import subprocess as sp
> > > p = sp.Popen("cmd.exe", stdout=sp.PIPE)
> > > p.stdin.write("hostname\n")
> > >
> > > however, it doesn't seem to work.  I think the cmd.exe is catching it.
> >
> > One: you didn't read any of the "returned" output...
> >
> > Two: the output only seems to be available upon EOF, which means the
> > spawned command processor has to exit first... Though you CAN read one
> > character at a time, and then have to build lines and expected prompt
> > strings...
> >
> >
> > This seems to work:
> > -=-=-=-=-=-=-=-=-
> > import subprocess
> > import os
> >
> > PROMPT = os.getcwd() + ">"
> >
> > def getLine(proc):
> > ld = []
> > while True:
> > c = proc.stdout.read(1)
> > if c == "\r": continue  #skip Windows 
> > if c != "\n": ld.append(c) #save all but 
> > if c is None or c == "\n" or c == ">": break
> > ln = "".join(ld)
> > return ln
> >
> > p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stdin =
> > subprocess.PIPE)
> >
> > print " START of captured output"
> > while True:
> > ln = getLine(p)
> > print ln
> > if ln == PROMPT: break
> > print " END of captured output"
> >
> > p.stdin.write("ipconfig\n")
> > print " START of captured output"
> > while True:
> > ln = getLine(p)
> > print ln
> > if ln == PROMPT: break
> > print " END of captured output"
> >
> > p.stdin.write("dir\n")
> > print " START of captured output"
> > while True:
> > ln = getLine(p)
> > print ln
> > if ln == PROMPT: break
> > print " END of captured output"
> >
> > p.stdin.write("exit\n")
> > -=-=-=-=-=-=-=-=-=-
> > E:\UserData\Dennis Lee Bieber\My Documents>python script1.py
> >  START of captured output
> > Microsoft Windows XP [Version 5.1.2600]
> > (C) Copyright 1985-2001 Microsoft Corp.
> >
> > E:\UserData\Dennis Lee Bieber\My Documents>
> >  END of captured output
> >  START of captured output
> > ipconfig
> >
> > Windows IP Configuration
> >
> >
> > Ethernet adapter Local Area Connection:
> >
> > Connection-specific DNS Suffix  . :
> > IP Address. . . . . . . . . . . . : 192.168.1.100
> > Subnet Mask . . . . . . . . . . . : 255.255.255.0
> > IP Address. . . . . . . . . . . . : fe80::211:11ff:fee1:f303%4
> > Default Gateway . . . . . . . . . : 192.168.1.1
> >
> > Tunnel adapter Teredo Tunneling Pseudo-Interface:
> >
> > Connection-specific DNS Suffix  . :
> > IP Address. . . . . . . . . . . . :
> > 3ffe:831f:4004:1956:0:fbde:bd0a:e50b
> > IP Address. . . . . . . . . . . . : fe80::5445:5245:444f%5
> > Default Gateway . . . . . . . . . : ::
> >
> > Tunnel adapter Automatic Tunneling Pseudo-Interface:
> >
> > Connection-specific DNS Suffix  . :
> > IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2
> > Default Gateway . . . . . . . . . :
> >
> > E:\UserData\Dennis Lee Bieber\My Documents>
> >  END of captured output
> >  START of captured output
> > dir
> >  Volume in drive E is Data
> >  Volume Serial Number is 2626-D991
> >
> >  Directory of E:\UserData\Dennis Lee Bieber\My Documents
> >
> > 10/24/2005  09:23 AM
> >   .
> > 10/24/2005  09:23 AM
> >   ..
> > 07/25/2005  10:39 PM
> >   .metadata
> > 10/06/2005  09:54 AM
> >   Ada Progs
> > 08/13/2005  02:01 PM
> >   Agent Data
> > 10/21/2005  09:29 AM   421,820 apress_offer.pdf
> > 07/03/2005  11:36 AM   132 cp.py
> > 07/17/2005  12:25 PM
> >   Cyberlink
> > 07/06/2005  09:32 AM   102,400 db1.mdb
> > 07/26/2005  12:20 AM26,614 eclipse_code.xml
> > 10/24/2005  01:08 AM
> >   Eudora
> > 06/24/2005  08:50 PM   667 fake_oosums.ads
> > 06/24/2005  08:50 PM   695 fake_oosums.ali
> > 09/06/2005  09:01 PM
> >   Genealogy
> > 07/13/2005  10:56 PM
> >   HomeSite
> > 05/08/2005  01:05 PM
> >   Investing
> > 10/21/2005  10:04 PM
> >   Java Progs
> > 08/04/2005  10:13 PM   162 main.py
> > 10/11/2005  10:43 PM
> >   My Downloads
> > 05/01/2005  10:31 AM
> >   My eBooks
> > 04/22/2005  12:09 AM
> >   My Music
> > 07/10/2005  11:43 AM
> >   My Pictures
> > 06/29/2005  11:55 PM
> >   My PSP Files
> > 05/23/2005 

Re: output from external commands

2005-10-24 Thread James Colannino
Kent Johnson wrote:

>import os
>files = os.listdir('.')
>

Thanks, that's good to know.  I still need to use os.popen() for a few 
things, but I'll be needing filenames also, so when I try to get 
filenames I'll use the above.

James

-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"If Carpenters made houses the way programmers design programs, the first 
woodpecker to come along would destroy all of civilization." --Computer Proverb

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


Re: Read/Write from/to a process

2005-10-24 Thread jas
What about having a thread which reads from subprocess.Popen()'s
stdout...instead of read/write, read/write.  just always read, and
write when needed?

any comments on that idea?

jas wrote:
> actually, i can't check for ">" only because if you a dir, a line can
> end with a > but is not the end of the output
>
> jas wrote:
> > Thanks, that is certainly a start.  As you mentioned, the "cd" could is
> > an issue.
> >
> > Perhaps checking to see if the line ends with ">" is sufficient?
> >
> > Dennis Lee Bieber wrote:
> > > On 24 Oct 2005 07:20:42 -0700, "jas" <[EMAIL PROTECTED]> declaimed the
> > > following in comp.lang.python:
> > >
> > > > Hi,
> > > >   I would like to start a new process and be able to read/write from/to
> > > > it.  I have tried things like...
> > > >
> > > > import subprocess as sp
> > > > p = sp.Popen("cmd.exe", stdout=sp.PIPE)
> > > > p.stdin.write("hostname\n")
> > > >
> > > > however, it doesn't seem to work.  I think the cmd.exe is catching it.
> > >
> > >   One: you didn't read any of the "returned" output...
> > >
> > >   Two: the output only seems to be available upon EOF, which means the
> > > spawned command processor has to exit first... Though you CAN read one
> > > character at a time, and then have to build lines and expected prompt
> > > strings...
> > >
> > >
> > > This seems to work:
> > > -=-=-=-=-=-=-=-=-
> > > import subprocess
> > > import os
> > >
> > > PROMPT = os.getcwd() + ">"
> > >
> > > def getLine(proc):
> > > ld = []
> > > while True:
> > > c = proc.stdout.read(1)
> > > if c == "\r": continue  #skip Windows 
> > > if c != "\n": ld.append(c) #save all but 
> > > if c is None or c == "\n" or c == ">": break
> > > ln = "".join(ld)
> > > return ln
> > >
> > > p = subprocess.Popen("cmd.exe", stdout=subprocess.PIPE, stdin =
> > > subprocess.PIPE)
> > >
> > > print " START of captured output"
> > > while True:
> > > ln = getLine(p)
> > > print ln
> > > if ln == PROMPT: break
> > > print " END of captured output"
> > >
> > > p.stdin.write("ipconfig\n")
> > > print " START of captured output"
> > > while True:
> > > ln = getLine(p)
> > > print ln
> > > if ln == PROMPT: break
> > > print " END of captured output"
> > >
> > > p.stdin.write("dir\n")
> > > print " START of captured output"
> > > while True:
> > > ln = getLine(p)
> > > print ln
> > > if ln == PROMPT: break
> > > print " END of captured output"
> > >
> > > p.stdin.write("exit\n")
> > > -=-=-=-=-=-=-=-=-=-
> > > E:\UserData\Dennis Lee Bieber\My Documents>python script1.py
> > >  START of captured output
> > > Microsoft Windows XP [Version 5.1.2600]
> > > (C) Copyright 1985-2001 Microsoft Corp.
> > >
> > > E:\UserData\Dennis Lee Bieber\My Documents>
> > >  END of captured output
> > >  START of captured output
> > > ipconfig
> > >
> > > Windows IP Configuration
> > >
> > >
> > > Ethernet adapter Local Area Connection:
> > >
> > > Connection-specific DNS Suffix  . :
> > > IP Address. . . . . . . . . . . . : 192.168.1.100
> > > Subnet Mask . . . . . . . . . . . : 255.255.255.0
> > > IP Address. . . . . . . . . . . . : fe80::211:11ff:fee1:f303%4
> > > Default Gateway . . . . . . . . . : 192.168.1.1
> > >
> > > Tunnel adapter Teredo Tunneling Pseudo-Interface:
> > >
> > > Connection-specific DNS Suffix  . :
> > > IP Address. . . . . . . . . . . . :
> > > 3ffe:831f:4004:1956:0:fbde:bd0a:e50b
> > > IP Address. . . . . . . . . . . . : fe80::5445:5245:444f%5
> > > Default Gateway . . . . . . . . . : ::
> > >
> > > Tunnel adapter Automatic Tunneling Pseudo-Interface:
> > >
> > > Connection-specific DNS Suffix  . :
> > > IP Address. . . . . . . . . . . . : fe80::5efe:192.168.1.100%2
> > > Default Gateway . . . . . . . . . :
> > >
> > > E:\UserData\Dennis Lee Bieber\My Documents>
> > >  END of captured output
> > >  START of captured output
> > > dir
> > >  Volume in drive E is Data
> > >  Volume Serial Number is 2626-D991
> > >
> > >  Directory of E:\UserData\Dennis Lee Bieber\My Documents
> > >
> > > 10/24/2005  09:23 AM
> > >   .
> > > 10/24/2005  09:23 AM
> > >   ..
> > > 07/25/2005  10:39 PM
> > >   .metadata
> > > 10/06/2005  09:54 AM
> > >   Ada Progs
> > > 08/13/2005  02:01 PM
> > >   Agent Data
> > > 10/21/2005  09:29 AM   421,820 apress_offer.pdf
> > > 07/03/2005  11:36 AM   132 cp.py
> > > 07/17/2005  12:25 PM
> > >   Cyberlink
> > > 07/06/2005  09:32 AM   102,400 db1.mdb
> > > 07/26/2005  12:20 AM26,614 eclipse_code.xml
> > > 10/24/2005  01:08 AM
> > >   Eudora
> > > 06/24/2005  08:50 PM   667 fake_oosums.ads
> > > 06/24/2005  08:50 PM   695 fake_oosums.ali
> > > 09/06/2005  09:01 PM
> > >   Genealogy
> > > 07/13/2005  10:56 PM 

Re: Tricky Areas in Python

2005-10-24 Thread beza1e1
let me try.

1) ''.join(lots_of_pieces)

2) This doesn't even work, if something is removed, the list is too
short. So:
[x for x in somelist if not isbad(x)]
well, list comprehension is Python 2.4 and 2.3 is the standard in many
OSes, so it is possibly not the most portable solution
I had to look up the syntax, because i never use it in my code, yet.

3+4) I never used property - had to look it up. So i learned something
:)

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


Re: python gc performance in large apps

2005-10-24 Thread Chris Lambacher
A couple of strategic gc.collect() calls can be useful.  You can also tweak
how the garbage collector gets run by changing settings in the gc module.

-Chris
On Fri, Oct 21, 2005 at 04:13:09PM -0400, Robby Dermody wrote:
> 
> Hey guys (thus begins a book of a post :),
> 
> I'm in the process of writing a commercial VoIP call monitoring and 
> recording application suite in python and pyrex. Basically, this 
> software sits in a VoIP callcenter-type environment (complete with agent 
> phones and VoIP servers), sniffs voice data off of the network, and 
> allows users to listen into calls. It can record calls as well. The 
> project is about a year and 3 months in the making and lately the 
> codebase has stabilized enough to where it can be used by some of our 
> clients. The entire project has about 37,000 lines of python and pyrex 
> code (along with 1-2K lines of unrelated java code).
> 
> Now, some disjointed rambling about the architecture of this software. 
> This software has two long-running server-type components. One 
> component, the "director" application, is written in pure python and 
> makes use of the twisted, nevow, and kinterbasdb libraries (which I 
> realize link to some C extensions). The other component, the 
> "harvester", is a mixture of python and pyrex, and makes use of the 
> twisted library, along with using the C libs libpcap and glib on the 
> pyrex end. Basically, the director is the "master" component. A single 
> director process interacts with users of the system through a web and/or 
> pygtk client application interface and can coordinate 1 to n harvesters 
> spread about the world. The harvester is the "heavy lifter" component 
> that sniffs the network traffic and sifts out the voice and signalling 
> data. It then updates the director of call status changes, and can 
> provide users of the system access to the data. It records the data to 
> disk as well. The scalibility of this thing is really cool: given a 
> single director sitting somewhere coordinating the list of agents, 
> multiple harvester can be placed anywhere there is voice traffic. A user 
> that logs into the director can end up seeing the activity of all of 
> these seperate voice networks presented like a single giant mesh.
> 
> Overall, I have been very pleased with python and the 3rd party 
> libraries that I use (twisted, nevow, kinterbasdb and pygtk). It is a 
> joy to program with, and I think the python community has done a fine 
> job. However, as I have been running the software lately and profiling 
> its memory usage, the one and only Big Problem I have seen is that of 
> the memory usage. Ideally, the server application(s) should be able to 
> run indefinitely, but from the results I'm seeing I will end up 
> exhausting the memory on a 2 GB machine in 2 to 3 days of heavy load.
> 
> Now normally I would not raise up an issue like this on this list, but 
> based on the conversations held on this list lately, and the work done 
> by Evan Jones (http://evanjones.ca/python-memory.html), I am led to 
> believe that this memory usage -- while partially due to some probably 
> leaks in my program -- is largely due to the current python gc. I have 
> some graphs I made to show the extent of this memory usage growth:
> 
> http://public.robbyd.fastmail.fm/iq-graph1.gif
> 
> http://public.robbyd.fastmail.fm/iq-graph-director-rss.gif
> 
> http://public.robbyd.fastmail.fm/iq-graph-harv-rss.gif
> 
> The preceding three diagrams are the result of running the 1 director 
> process and 1 harvester process on the same machine for about 48 hours. 
> This is the most basic configuration of this software. I was running 
> this application through /usr/bin/python (CPython) on a Debian 'testing' 
> box running Linux 2.4 with 2GB of memory and Python version 2.3.5. 
> During that time, I gathered the resident and virtual memory size of 
> each component at 120 second intervals. I then imported this data into 
> MINITAB and did some plots. The first one is a graph of the resident 
> (RSS) and virtual memory usage of the two applications. The second one 
> is a zoomed in graph of the director's resident memory usage (complete 
> with a best fit quadratic), and the 3rd one is a zoomed in graph of the 
> harvester's resident memory usage.
> 
> To give you an idea of the network load these apps were undergoing 
> during this sampling time, by the time 48 hours had passed, the 
> harvester had gathered and parsed about 900 million packets. During the 
> day there will be 50-70 agents talking. This number goes to 10-30 at night.
> 
> In the diagrams above, one can see the night-day separation clearly. At 
> night, the memory usage growth seemed to all but stop, but with the 
> increased call volume of the day, it started shooting off again. When I 
> first started gathering this data, I was hoping for a logarithmic curve, 
> but at least after 48 hours, it looks like the usage increase is almost 
> linear. (Although logarit

Extention String returning

2005-10-24 Thread Tuvas
I have been writing a program that is designed to return an 8 byte
string from C to Python. Occasionally one or more of these bytes will
be null, but the size of it will always be known. How can I write an
extention module that will return the correct bytes, and not just until
the null? I would think there would be a fairly  easy way to do this,
but, well... Thanks!

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


Re: Extention String returning

2005-10-24 Thread jepler
I think that you want to use
return PyString_FromStringAndSize(buf, 8);

Jeff


pgp3nNxegNjmk.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Extention String returning

2005-10-24 Thread Jp Calderone
On 24 Oct 2005 11:28:23 -0700, Tuvas <[EMAIL PROTECTED]> wrote:
>I have been writing a program that is designed to return an 8 byte
>string from C to Python. Occasionally one or more of these bytes will
>be null, but the size of it will always be known. How can I write an
>extention module that will return the correct bytes, and not just until
>the null? I would think there would be a fairly  easy way to do this,
>but, well... Thanks!

Use PyString_FromStringAndSize instead of PyString_FromString.

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


Re: Extention String returning

2005-10-24 Thread Fredrik Lundh
"Tuvas" wrote:

> I have been writing a program that is designed to return an 8 byte
> string from C to Python. Occasionally one or more of these bytes will
> be null, but the size of it will always be known. How can I write an
> extention module that will return the correct bytes, and not just until
> the null? I would think there would be a fairly  easy way to do this,
> but, well... Thanks!

return PyString_FromStringAndSize(buffer, bytes);

or

return Py_BuildValue("s#", buffer, bytes);





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


  1   2   >