[Tutor] Can Python monitor web browser content

2013-01-25 Thread 3n2 Solutions
Hello,

I was wondering if Python can monitor web browser content.
Specifically, I'm connected to a Machine to Machine device
(essentially a Gateway) and monitoring its activity on a web browser
(either IE or Chrome). There are certain parameters like RSSI
(received signal strength indicator ) that I would like to monitor
(read and record) for a one minute period. Is this possible in Python?
If not, what can achieve this?

I'm using Python 2.7 on Windows 7

Thank you!
Tim
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Can Python monitor web browser content

2013-01-25 Thread Alan Gauld

On 25/01/13 17:52, 3n2 Solutions wrote:


I was wondering if Python can monitor web browser content.


Browsers just display html text and Python can read html so
yes you can do it by getting your program to emulate a browser.

Look at the standard library modules urllibm htmllib and htmlParser.
Or for more adventurous parsing try the external module BeautifulSoup, 
it tends to handle badly formed html better and is arguably easier to 
use than the standard options..


On Windows you can also read the content of IE using COM
but that's probably not the best approach.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calculate hours

2013-01-25 Thread शंतनू
Reply inline.

On 23/01/13 8:22 AM, anthonym wrote:
> Hello All,
>
> I originally wrote this program to calculate and print the employee
> with the most hours worked in a week.  I would now like to change this
> to calculate and print the hours for all 8 employees in ascending order.
>
> The employees are named employee 0 - 8
>
> Any ideas?
>
> Thanks,
> Tony
>
> Code below:
>
>
>
> # Create table of hours worked
>
> matrix = [
> [2, 4, 3, 4, 5, 8, 8],
> [7, 3, 4, 3, 3, 4, 4],
> [3, 3, 4, 3, 3, 2, 2],
> [9, 3, 4, 7, 3, 4, 1],
> [3, 5, 4, 3, 6, 3, 8],
> [3, 4, 4, 6, 3, 4, 4],
> [3, 7, 4, 8, 3, 8, 4],
> [6, 3, 5, 9, 2, 7, 9]]
>


===
s = [sum(x) for x in matrix]
for q in sorted([(x,y) for x,y in enumerate(s)],
key=operator.itemgetter(1)):
print("Employee %d has worked %d hours" % (q[0], q[1]))
===

Output:

Employee 2 has worked 20 hours
Employee 1 has worked 28 hours
Employee 5 has worked 28 hours
Employee 3 has worked 31 hours
Employee 4 has worked 32 hours
Employee 0 has worked 34 hours
Employee 6 has worked 37 hours
Employee 7 has worked 41 hours


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Calculate hours

2013-01-25 Thread Peter Otten
शंतनू wrote:

> s = [sum(x) for x in matrix]
> for q in sorted([(x,y) for x,y in enumerate(s)],
> key=operator.itemgetter(1)):
> print("Employee %d has worked %d hours" % (q[0], q[1]))
 
A minor simplification:

s = (sum(x) for x in matrix)
for q in sorted(enumerate(s), key=operator.itemgetter(1)):
print("Employee %d has worked %d hours" % q)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] lambda

2013-01-25 Thread anthonym
Hello All,

I have the code below that I used to create a simple tic tac toe game for
class.  I am learning Python but have programmed in C+ before so I brought
over a lambda and found that it worked in Python.  Unfortunately I don't
think my classmates will understand the use of lambda here but I am having
are hard time converting that to strictly python.

Let me know if it can be done.

Thanks

from tkinter import *

def ttt(r,c):
global player
if player == 'X':
b[r][c].configure(text = 'X')
player = 'O'
else:
b[r][c].configure(text = 'O')
player = 'X'

root = Tk()

b = [[0, 0, 0],
 [0, 0, 0],
 [0, 0, 0]]

for i in range(3):
for j in range(3):
b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
 command = lambda r=i,c=j: ttt(r,c))
b[i][j].grid(row = i, column = j)

player = 'X'

mainloop()



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lambda

2013-01-25 Thread Alan Gauld

On 25/01/13 23:57, anthonym wrote:


I don't think my classmates will understand the use of lambda here but I
am having are hard time converting that to strictly python.


lambdas are strictly python but they can be easily reanslated into a 
named function as


lambda p: expr

becomes

def f(p):
   return expr

so in your case

>  b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
>   command = lambda r=i,c=j: ttt(r,c))

becomes

def bCmd(r=i,c=j):
return ttt(r,c)

b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
 command = bCmd)

Your problem of course is that you need i and j to be dynamically 
defined so you need to create and call a function that returns a 
function like this


def buttonFunMaker(i,j):
def func(x=i,y=j):
return ttt(x,y)
return func

b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
 command = buttonFunMaker(i,j))

Personally I prefer the lambda...

HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lambda

2013-01-25 Thread Danny Yoo
On Fri, Jan 25, 2013 at 4:57 PM, anthonym  wrote:

> I have the code below that I used to create a simple tic tac toe game for
> class.  I am learning Python but have programmed in C+ before so I brought
> over a lambda and found that it worked in Python.  Unfortunately I don't
> think my classmates will understand the use of lambda here but I am having
> are hard time converting that to strictly python.


The code is expressing the idea of referring to a function, not to
call it immediately, but rather to pass it as a value for someone else
to call.  This is something that's expressible in C++ too.

http://en.wikipedia.org/wiki/C%2B%2B11#Lambda_functions_and_expressions

But you probably won't see this in beginner-level code.

Dealing with functions as values is important to learn, though, if you
want to build an intermediate mastery of programming.  The concept is
a key component to things like event-driven programming, where you
tell some other system what to do when certain things happen.  That
"what to do" is usually expressed by passing the thing a function
value.

In traditional C++, the kind of C++ you'd see several years ago, you
can do the same sort of thing by passing around objects that have a
virtual method.  In that way, you can have a "function-like" value
that can be passed and called.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lambda

2013-01-25 Thread anthonym
Thanks Alan.  I prefer the lambda too.  Especially given how much code I
saved.  I forgot about i and j being dynamic and the call function.


On 1/25/13 4:14 PM, "Alan Gauld"  wrote:

>On 25/01/13 23:57, anthonym wrote:
>
>> I don't think my classmates will understand the use of lambda here but I
>> am having are hard time converting that to strictly python.
>
>lambdas are strictly python but they can be easily reanslated into a
>named function as
>
>lambda p: expr
>
>becomes
>
>def f(p):
>return expr
>
>so in your case
>
> >  b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
> >   command = lambda r=i,c=j: ttt(r,c))
>
>becomes
>
>def bCmd(r=i,c=j):
> return ttt(r,c)
>
>b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
>  command = bCmd)
>
>Your problem of course is that you need i and j to be dynamically
>defined so you need to create and call a function that returns a
>function like this
>
>def buttonFunMaker(i,j):
> def func(x=i,y=j):
> return ttt(x,y)
> return func
>
>b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
>  command = buttonFunMaker(i,j))
>
>Personally I prefer the lambda...
>
>HTH
>
>-- 
>Alan G
>Author of the Learn to Program web site
>http://www.alan-g.me.uk/
>
>___
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lambda

2013-01-25 Thread eryksun
On Fri, Jan 25, 2013 at 7:14 PM, Alan Gauld  wrote:
>
> Your problem of course is that you need i and j to be dynamically defined so
> you need to create and call a function that returns a function like this
>
> def buttonFunMaker(i,j):
> def func(x=i,y=j):
> return ttt(x,y)
> return func
>
> b[i][j] = Button(font=('Aerial', 56), width=3, bg='yellow',
>  command = buttonFunMaker(i,j))

With a function call you no longer need the default parameter hack
(i.e. x=i, y=j). You can make a closure over the local i and j in
buttonFunMaker:

def buttonFunMaker(i, j):
def func():
return ttt(i, j)
return func

or:

def buttonFunMaker(i, j):
return lambda: ttt(i, j)

With only lambda expressions, this structure is a bit awkward:

command=(lambda i, j: lambda: ttt(i, j))(i, j)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] lambda

2013-01-25 Thread Alan Gauld

On 26/01/13 01:22, eryksun wrote:


With a function call you no longer need the default parameter hack
(i.e. x=i, y=j). You can make a closure over the local i and j in
buttonFunMaker:

 def buttonFunMaker(i, j):
 def func():
 return ttt(i, j)
 return func


Good catch!


 def buttonFunMaker(i, j):
 return lambda: ttt(i, j)


Since the point was to get away from lambda I discounted this option, 
but it was my first instinct! :-)


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Cheese shop tutorial mirror

2013-01-25 Thread Per Fagrell
Hello,

I'm interested in uploading a module to pypi, but with the python wiki down
after the hack there's no access to the Cheese shop tutorial. Does anyone
have a mirror or reasonable facsimile that could be used until the wiki is
back on-line and repopulated?

Best regards,
Per Fagrell
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Help!

2013-01-25 Thread Carpenter, Steven
To Whom it May Concern,
I'm trying to get this code working. Here's my question:
Consider a triangle with sides of length 3, 7, and 9. The law of cosines states 
that given three sides of a triangle (a, b, and c) and angle C between sides a 
and b: Write Python code to calculate the three angles in the triangle.
Here's my code:
# Calculate the angles in a triangle
# Imports the Math data
import math
# Sets up the different angles with corresponding letters
# The first angle is a
a = 3
# The second angle is b
b = 7
# The third angle is c
c = 9
# Calculates angle "C"
print(math.acos(((a**2)+(b**2)-(c**2))/(2(a*b
Here's my output:
Traceback (most recent call last):
  File "E:\Programming\Problem4.py", line 12, in 
print(math.acos(((a**2)+(b**2)-(c**2))/(2(a*b
TypeError: 'int' object is not callable

Steven Carpenter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] sqlite search

2013-01-25 Thread Roger
Hello,

I am very new to python. Wrote a small program to use on my android phone using 
pickle/shelve to access  data.
That worked fine but i realised it would be better to use sqlite as a database 
to more easily modify the data.
I havent got a clue about sqlite, have a book but cant find the answer
My problem is this. i can access data by putting characters to search for in 
the program but i want it to be a variable that i can search for characters i 
input from keypad.
I am guessing its a syntax problem?
At the moment this works to search for everything beginning with A

sql = "SELECT * FROM plants WHERE genus LIKE 'A%'";

cursor.execute(sql);

slt =cursor.fetchone();


What i really need is to search for everything beginning with two letters from 
an input command___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor