[Tutor] monitor other running applications with Py

Che M pine508 at hotmail.com
Wed May 30 19:51:54 CEST 2007


Thanks for the pointers, Alan.  It seems perhaps a bit beyond my abilities 
for now, but something to keep in mind for the future if I get that far.  
And yes, the legal aspects are worth noting, though rest assured my wish for 
such a thing is for self-monitoring rather than other-monitoring, though I 
can see how it could get used nefariously if not cautious.

Best,
Che

>Date: Sun, 27 May 2007 15:54:11 +0100
>From: "Alan Gauld" <alan.gauld at btinternet.com>
>Subject: Re: [Tutor] monitor other running applications with Python?
>To: tutor at python.org
>Message-ID: <f3c63q$u2e$1 at sea.gmane.org>
>Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>	reply-type=original
>
>"Che M" <pine508 at hotmail.com> wrote
>
> > Hi, searched a bit for this but haven't found much.
> > Is it possible to use Python to monitor the use of
> > other applications?
>
>Yes, definitely.
>
> > At minimum, I wan't to know that the application was running
>
>Thats fairly easy using OS tools such as ps on Unix.
>You can dig a little deeper and use the system APIs such
>as the proc fiilesystem or the equivalent in the windows
>registry.
>
> > better would be some sense of the use or content, such
> > as whether the app was idle or the user was using it,
> > or, for a web browser, what URLs were visited and for
> > how long, etc.
>
>Thats possible but gets very OS specific and very low level too.
>On Windows you can catch Windows events and messages
>using some of the raw Win32 API calls from the ctypes module.
>(I've never used ctypes for anything this low level but it
>should be possible, I''ve certainly done it in C++ and Delphi
>on Win 9X). But its messy and fairly deep Windows magic
>and you will need to spend a fair bit of time experimenting
>and reading the docs on MSDN as well as the Win32 API
>help file.
>
> > Ideally I'd like a cross-platforms approach
>
>I doubt if that's possible except at the process monitoring
>level. For the kind of detail you want the bgestb you can
>do is have a common UI and pluggable modules based
>on the OS.
>
>Also beware legal implications. There are issues around
>personal privacy, data proptection etc and these vary between
>countries (and even states in the US). People are increasingly
>wary of Big Brother style monitoring. Detecting inappropriate
>use of the internet across a corporate firwall is generally
>considered OK but silently monitoring individuals brings you
>into murky legal waters.
>
>Finally, take a look at the stuff in the os package and the
>syslog module for Unix.
>
>HTH,
>
>--
>Alan Gauld
>Author of the Learn to Program web site
>http://www.freenetpages.co.uk/hp/alan.gauld
>
>
>
>------------------------------
>
>Message: 2
>Date: Sun, 27 May 2007 12:25:17 -0500
>From: adam urbas <adamurbas at hotmail.com>
>Subject: [Tutor] error message questions
>To: python tutor <tutor at python.org>
>Message-ID: <BAY103-W127AF8FBF014463458F350B1290 at phx.gbl>
>Content-Type: text/plain; charset="windows-1252"
>
>Hello all,I was wondering if there would be someone who would be able to 
>give me a list of error messages and their meanings.  I've attached this 
>test.py to illustrate my problem.  When I run the program, I am able to 
>enter all the data, yet it will not calculate.It says:can't multiply 
>sequence by non-int of type 'str'I really would like to know how to fix 
>this.I get a similar message with my other one, radiacir.py:can't multiply 
>sequence by non-int of type 'float'Please help!Thanks in advance,Adam
>_________________________________________________________________
>Change is good. See what?s different about Windows Live Hotmail.
>http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: 
>http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment.html
>-------------- next part --------------
>An embedded and charset-unspecified text was scrubbed...
>Name: test.py
>Url: 
>http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment-0001.pot
>-------------- next part --------------
>An embedded and charset-unspecified text was scrubbed...
>Name: radiacir.py
>Url: 
>http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment-0001.asc
>
>------------------------------
>
>Message: 3
>Date: Sun, 27 May 2007 12:49:04 -0500
>From: adam urbas <adamurbas at hotmail.com>
>Subject: Re: [Tutor] trouble with "if"
>To: Brian van den Broek <broek at cc.umanitoba.ca>
>Cc: python tutor <tutor at python.org>
>Message-ID: <BAY103-W7D614AA96749DD0D7BC0CB1290 at phx.gbl>
>Content-Type: text/plain; charset="windows-1252"
>
>Thank you for the help Brian.  I would like to ask you about these things.  
>Which one of the examples you gave would be most fool proof.> Date: Wed, 23 
>May 2007 13:40:09 -0400> From: broek at cc.umanitoba.ca> To: 
>adamurbas at hotmail.com> CC: tutor at python.org> Subject: Re: [Tutor] trouble 
>with "if"> > adam urbas said unto the world upon 05/23/2007 01:04 PM:> > 
>Sorry, I don't think Hotmail has turn off HTML.  If it does I> > havn't 
>been able to find it.  I think you're going to have to> > explain your 
>little bit of text stuff down there at the bottom.  I> > have no idea what 
>most of that means.  All my choice things are> > working now though.  I 
>think that is what you were trying to help> > me with.  What I used wasif 
>shape in["1","circle"]:and if shape ==> > "1" or shape =="circle":It works 
>perfectly fine now.Ya that little> > bit o' code is really puzzling.  I 
>wish I knew more about this> > python deal.  I understand the concept, but 
>not the rules or the> > techniques and things !
>  of that sort.  OK... I've got it... the> > data=raw_input('Feed Me!').  
>Ok I now understand that bit.  Then it> > says Feed Me!  and you put 42 
>(the ultimate answer to life the> > universe, everything).  OK, it won't 
>accept the <type 'str'> bit.> > it doesn't like the "<".  Well, I just 
>removed that bit and it> > said:Feed Me!  and I put 42, and it said >>> (I 
>guess it's> > satisfied now, with the whole feeding).  Well if I understood 
>what> > 'str' meant, then I could probably figure the rest out.  Well I> > 
>have to go do other things so I'll save the rest of this figuring> > out 
>till later.I shall return,Adam> Date: Wed, 23 May 2007 12:12:16> > -0400> 
>From: broek at cc.umanitoba.ca> To: adamurbas at hotmail.com> CC:> > 
>tutor at python.org> Subject: Re: [Tutor] trouble with "if"> > adam> > urbas 
>said unto the world upon 05/23/2007 11:57 AM:> > > > Hi all,>> > > > > I've 
>been working with this new program that I wrote.  I> > started out > > with 
>it on a Ti-83, which is much easier to!
>   program> > than python.  Now > > I'm trying to transfer the program t
>o python> > but its proving to be quite > > difficult.  I'm not sure what 
>the> > whole indentation thing is for.  And > > now I'm having trouble> > 
>with the if statement things. > > > > #"Circle Data Calculation> > 
>Program:"> > print "Welcome to the Circle Data Calcuation> > Program."> > 
>print> > > >     #"Menu 1:"> > print "Pick a shape:">> > > print "(NOTE: 
>You must select the number of the shape and not the> > shape > > itself)"> 
> > print "1 Circle"> > print "2 Square"> > print> > "3 Triangle"> > > >     
>#"User's Choice:"> > shape=raw_input("> ")>> > > > >         #"Select 
>Given:"> > if shape == 1:> >         print> > "Choose the given value:"> >  
>        print "1 radius"> >> > print "2 diameter"> >         print "3 
>circumference"> >> > print "4 area"> > > > #"User's Choice:"> > 
>given=raw_input("> ")> >> > > > if given == 1:> >         
>radius=raw_input("Enter Radius:")> >> > diameter=(radius*2)> >         
>circumference=(diameter*3.14)> >> > area=(radius**2*3.14)> >         !
>  print "Diameter:", diameter> >> > print "Circumference:", circumference> 
> >         print "Area:",> > area> > > > if given == 2:> >         
>diameter=raw_input("Enter> > Diameter:")> >         radius=(diameter/2)> >> 
> > circumference=(diameter*3.14)> >         area=(radius**2*3.14)> >> > 
>print "Radius:", radius> >         print "Circumference:",> > 
>circumference> >         print "Area:", area> > > > if given == 3:>> > >    
>      circumference=raw_input("Enter Circumference:")> >> > 
>radius=(circumference/3.14/2)> >         diameter=(radius*2)> >> > 
>area=(radius**2*3.14)> >         print "Radius:", radius> >> > print 
>"Diameter:", diameter> >         print "Area:", area> > > >> > if given == 
>4:> >         area=raw_input("Enter Area:")> >> > radius=(area/3.14)> >     
>      > > This is the whole program so> > far, because I haven't quite 
>finished it > > yet.  But I tried to> > get it to display another list of 
>options after you > > select a> > shape but it just does this.> > > > Pick!
>   a shape:> > 1 Circle> > 2> > Square> > 3 Triangle> >  >1> >  >1> >  >
> >>> > > > I'm not sure why> > it does that but I do know that it is 
>skipping the > > second list> > of options.> > > > Another of my problems 
>is that I can't figure> > out how to get it to > > accept two different 
>inputs for a> > selection.  Like I want it to accept > > both the number 1 
>and> > circle as circle then list the options for > > circle.  It won't> > 
>even accept words.  I can only get it to accept > > numbers.  It's> > quite 
>frustrating actually.> > > > Any advice would be greatly> > appreciated.> > 
>Thanks in advance,> > Adam> > > > > > > Adam,> >> > Could you send plain 
>text email rather than html, please? At least> > for > me, your code's 
>indentation is all messed up unless I take> > some steps > to rectify it.> 
> > The problem is that raw_input> > returns a string, and you are testing > 
>whether given is equal to> > integers. See if this helps make things 
>clear:> >  >>> data => > raw_input('Feed me!')> Feed me!42>  >>> 
>type(data)> <type 'str'>>> > >>> data == 42> !
>  False>  >>> int(data) == 42> True>  >>>> > Best,> >> > Brian vdB > > > 
>Adam,> > As you can see from the above, the way hotmail is formatting 
>things > makes the conversation a bit tricky :-) I'm only willing to spend 
>so > much time trying to sort through it, so I hope what follows helps.> >  
> >>> data = raw_input("Feed me!")> Feed me!42> > This calls the builtin 
>function raw_input with a parameter setting the > prompt to "Feed me!" and 
>assigns the result to data. Since I hit 42 > and then enter,> >  >>> data> 
>'42'> > Notice the quotes around 42. They indicate that the value of data 
>is a > string. That's what this tells us:> >  >>> type(data)> <type 'str'>> 
> > The string '42' is not the same as the integer 42:> >  >>> type(42)> 
><type 'int'>>  >>> '42' == 42> False> > So, when you had an if test that 
>was something like:> > if given == 1:>     # Do stuff here> > the equality 
>comparison was never going to work---given was a string > returned by 
>raw_input and no string is ever equa!
>  l to an integer.> > What I suggested was taking the string returned by
>  raw_input and > feeding it to int() to transform it from a string to an 
>integer, and > allow your if test to stand a chance:> >  >>> data = 
>raw_input("Feed me!")> Feed me!42>  >>> if data == 42:> ...   print 
>"Matches!"> ...>  >>> data = int(raw_input("Feed me!"))> Feed me!42>  >>> 
>if data == 42:> ...   print "Matches!"> ...> Matches!>  >>>> > There are 
>other ways, for instance:> >  >>> data = raw_input("Feed me!")> Feed me!42> 
>  >>> if data == '42':> ...   print "Matches!"> ...> Matches!>  >>>> > 
>Here, instead of transforming data to an int and then testing for > 
>equality with 42, I left data as a string and tested for equality with > 
>the string '42'.> > The way calling int() is a bit better, I think. If the 
>user enters a > few spaces, then 42 then a few more spaces, that way will 
>still work:> >  >>> data = int(raw_input("Feed me!"))> Feed me!    42>  >>> 
>if data == 42:> ...   print "Matches!"> ...> Matches!>  >>>> > because> >  
> >>> int('    42    ')> 42>  >>>> > whereas> > !
>   >>> '    42    ' == '42'> False> > > I hope there is some help in there 
>somewhere :-)> > Brian vdB
>_________________________________________________________________
>Change is good. See what?s different about Windows Live Hotmail.
>www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=TXT_TAGLM_HMWL_reten_changegood_0507
>-------------- next part --------------
>An HTML attachment was scrubbed...
>URL: 
>http://mail.python.org/pipermail/tutor/attachments/20070527/81f34a70/attachment.htm
>
>------------------------------
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>
>End of Tutor Digest, Vol 39, Issue 70
>*************************************

_________________________________________________________________
Catch suspicious messages before you open them—with Windows Live Hotmail. 
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_protection_0507



More information about the Tutor mailing list