Re: [Tutor] PI

2011-05-25 Thread memilanuk

On 05/25/2011 09:21 PM, David Merrick wrote:

How do I can access to the math module to use PI?

area = math.pi * pow(3,2)
Traceback (most recent call last):
   File "", line 1, in 
 area = math.i * pow(3,2)
NameError: name 'math' is not defined



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


[Tutor] Better way to compare values?

2011-08-28 Thread memilanuk

Hello,

Recently picked back up the Python bug, and have started chipping away 
at the warm-up exercises over @ codingbat.com.


I'm getting thru the basic stuff okay, but I'm getting a feeling that 
maybe I'm not doing things the 'right' way, even though the results are 
correct.


Specifically, checking if value 'a' OR value 'b' equal a certain number...

The example that I'm on at the moment (like I said, starting over at the 
basics)...


http://codingbat.com/prob/p124984

My solution:

'''
Given 2 ints, a and b, return True if one if them is 10 or if their sum 
is 10.


makes10(9, 10) = True
makes10(9, 9) = False
makes10(1, 9) = True
'''

def makes10(a, b):
if (a == 10) or (b == 10):
#print('Yep!')
return(True)

elif a + b == 10:
#print('Si!')
return(True)

else:
#print('Nein!')
return(False)

makes10(10,9)
#makes10(9,9)
#makes10(1,9)



In particular, the 'if (a == 10) or (b == 10): line... is there a 
shorter/more compact/more correct (i.e. pythonic) way of testing to see 
if a OR b is equal to 10?


Thanks,

Monte

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


Re: [Tutor] Better way to compare values?

2011-08-28 Thread memilanuk




There's a few things that can make this a lot shorter. To address your
primary question first, the python idiom for this is like so:

if 10 in (a, b):

it constructs a tuple containing the variables a and b, then checks if
the number ten is inside that tuple. simple and straightforward. Now,
or's aren't limited to just two operands. you can chain multiple or's
together to make this function even shorter, like so:

if a == 10 or b == 10 or a + b == 10:


That's pretty much what the 'book' solution was (found the 'Show 
Solution' button staring me in the face shortly after posting my 
question here.


def makes10(a,b)
return(a == 10 or b == 10 or a + b == 10)




So, all said and done, the solution to your problem in idiomatic
python looks like this:

def makes10(a, b):
 return 10 in (a, b, a + b)



Something else I learned from this... for some reason I had the idea in 
my head that 'return' was a function like print() i.e. 'return()'. 
Obviously not, from your example and from others that I dug up in the 
Python docs.


Thanks for the detailed explanation - it was very clear and easy to 
follow!  What I had originally been thinking was something like 'a && b' 
or 'a || b'... but that was probably some cross-pollenation from earlier 
dabbling in PHP or something ;)


Thanks,

Monte

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


Re: [Tutor] ?!

2015-04-21 Thread memilanuk

On 04/21/2015 04:17 AM, Ryan Scholes wrote:

  Hi,

Didn't really understand the instructions on the website but is this the right 
email address for help?



It can be...

Some very smart, experienced and helpful folks here - some are even all 
three! ;)


Generally speaking... they aren't going to do your (home) work for 
you... try to provide some code to show what you've tried, and specific 
questions as to what you're having trouble with.



--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] https://trinket.io

2015-05-21 Thread memilanuk

On 05/21/2015 01:02 AM, Albert-Jan Roskam via Tutor wrote:

Not sure whether I like this better than IPython Notebook, though.



I was given to understand that the target use / demographic was a bit 
different than with iPython...


Monte


--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] question / decision tree

2015-08-03 Thread memilanuk

On 08/03/2015 02:38 AM, matej taferner wrote:

Or maybe should I go with the tkinter?



As a final product of this decision tree "app" I need a clickable buttons
ready to be embedded into the website which will guide customer(s) to
desired answer(s).


The two aren't exactly compatible.  Tkinter is for stand-alone desktop 
applications.  While they can run a call to open a browser to an 
appropriate web page, if everything else is already on the web site it 
seems like it would make sense to do the front-end the same way, rather 
than have to deploy a separate application.



--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] Run Python 2.7 on Android Tablet

2015-11-10 Thread memilanuk

On 11/10/2015 01:32 PM, Laura Creighton wrote:

In a message of Tue, 10 Nov 2015 12:38:27 -0500, "Ken Hammer" writes:



My MIT OCW 6.00SC course is installed on a Windows 8.1 desktop machine.

I'd like to study and explore away from my office and desk on my tablet running 
Android 4.2.2.  Possible?

thanks,  Ken


Yes.
use Python Anywhere in a browser on your tablet.

https://www.pythonanywhere.com/




https://mail.python.org/mailman/listinfo/tutor



Or koding.io... but PythonAnywhere is nicer for straight-up python.

--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


[Tutor] flask/sqlite3 problem - 'OperationalError: no such table'?

2013-09-18 Thread memilanuk

Hello there,

I'm working thru a Flask tutorial, and when I get to the portion for 
querying the database (sqlite3) for the existing posts, i.e. 'SELECT * 
FROM posts', I get an error that says there is no such table 'posts' in 
my database.  Yet I can query said db file from either the sqlite3 
command-line client, or from the python interactive interpreter, and run 
the same query and get the expected results.  I've looked at this 'til 
I'm about ready to go cross-eyed... I'm sure it must be something simple 
that I'm missing, but I can't seem to spot it.  Below is the tail end of 
the traceback error message, followed by the code from the file in 
question.  Any help would be much appreciated.


Thanks,

Monte


Traceback (most recent call last):
...
return test(*args, **kwargs)
  File 
"/home/monte/Dropbox/Documents/Programming/python/flask/blog/blog.py", 
line 57, in main

cur = g.db.execute('SELECT * FROM posts')
OperationalError: no such table: posts




# blog.py - application module

from flask import Flask, render_template, request, session, flash, 
redirect, url_for, g

from functools import wraps
import sqlite3

# Configuration
DATABASE = 'fblog.db'
USERNAME = 'admin'
PASSWORD = 'admin'
SECRET_KEY = 'hard to guess'

app = Flask(__name__)

app.config.from_object(__name__)


def connect_db():
#return sqlite3.connect(app.config['DATABASE'])
return sqlite3.connect('fblog.db')

 Other functions not shown for brevity 

@app.route('/main')
@login_required
def main():
g.db = connect_db()
cur = g.db.execute('SELECT * FROM posts')
posts = [dict(title=row[0], post=row[1]) for row in cur.fetchall()]
g.db.close()
return render_template('main.html', posts=posts)

if __name__ == '__main__':
app.run(debug=True)

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


Re: [Tutor] flask/sqlite3 problem - 'OperationalError: no such table'?

2013-09-18 Thread memilanuk

Sheeesh...

After reading your message, I realized I was running the script from 
inside a new-to-me IDE (pycharm), and started wondering if somehow a 
path or working directory was not what I thought it might be.  I closed 
out the IDE window, and ran the script directly from the terminal - 
success!  After that I went thru and did some digging through the 
settings for this particular 'project' in pycharm, and found an option 
for the working directory, which was set to a different folder.  I fixed 
that and everything is off and running again.  Looks like I need to do 
some more reading up on projects in pycharm before I shoot myself in the 
foot again...


Thanks,

Monte

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


Re: [Tutor] What are your favourite unofficial resources

2014-06-29 Thread memilanuk

On 06/29/2014 03:41 PM, Alan Gauld wrote:

I'm looking for tips for an appendix to a book that
I'm working on.

What are the best unofficial (ie not python.org)
resources for people who have learned the basics
but are not experts yet? ie Typical tutor list
"graduates"...

I'm thinking about web sites, blogs, books, videos etc.
Anything that might be worth knowing about.

I've got a few of my own - Activestate, O'Reilly,
ByteOfPython, PythonChallenge, ShowMeDo etc.

But I thought the tutor list readers might be an
interesting source of alternatives that I hadn't
thought of, or even heard of.

All contributions considered :-)



Some stuff that I've bookmarked over time... not all of which I've 
actually go around to making use of :(


http://interactivepython.org/courselib/static/pythonds/index.html

http://rosettacode.org/wiki/Rosetta_Code

http://rosalind.info/problems/locations/

http://nullege.com/

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


Re: [Tutor] Why is Quick Search at docs.Python.org so useless?

2014-07-06 Thread memilanuk

On 07/05/2014 11:53 AM, Mark Lawrence wrote:


As I said it's a known problem, but then so are the 4600 bugs at
bugs.python.org.  So why bother spending the time making the search
useful when there is a well known workaround


Because it's supposed to be the first place new (and old) users go to 
find their answers.


Because the work-around isn't published right *there* where people who 
aren't 'in the know' would expect to find it.


Because it looks kind of sketchy that the search function of the main 
documentation section of *the* primary web site for a programming 
language doesn't work right, and hasn't for some time even though its a 
'well-known' issue because it isn't considered a sexy enough problem to 
be addressed.


In my mind, that doesn't say very many *good* things about that language...

And before you say, 'Go for it, fix it yourself'... I'm one of those 
new-ish folks myself, and you probably don't want me tinkering around 
anywhere near the guts of any search engine ;)






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


[Tutor] dict.get() vs. dict.get

2014-07-31 Thread memilanuk
What is the difference between dict.get() and dict.get as shown in the 
code below:


counts = dict()

for line in input_file:
words = line.split()
if len(words) == 0:
continue
else:
if words[0] != 'From:':
continue
else:
counts[words[1]] = counts.get(words[1], 0) + 1

max_key = max(counts, key=counts.get)
max_value = counts[max_key]

print max_key, max_value

I know the former (counts.get()) is supposed to return a value for a key 
if it exists, or else return the default value (in this case '0').  That 
part of the code is checking to see if the value contained in words[1] 
exists as a key in the dictionary counts or not; either way increment 
the associated value by +1.


The latter (counts.get) reflects some code I found online [1]:

print max(d.keys(), key=lambda x: d[x])

or even shorter (from comment):

print max(d, key=d.get)

that is to replace manually looping through the dict to find the max 
value like this:


max_value = None
max_key = None

for key, value in counts.items():
if max_value is None or max_value < value:
max_value = value
max_key = key

print max_key, max_value


So... the similarity between dict.get() and dict.get as used here is 
kinda confusing me.  When I do a search for 'dict.get' in the python 
docs or on google all I normally find is stuff referring to 'dict.get()'.


Any pointers would be much appreciated.


[1] 
http://stackoverflow.com/questions/12402015/print-the-key-of-the-max-value-in-a-dictionary-the-pythonic-way

--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] Python functions are first-class citizens

2014-07-31 Thread memilanuk

On 07/31/2014 08:22 PM, Ben Finney wrote:

memilanuk  writes:

>> So... the similarity between dict.get() and dict.get as used here is
>> kinda confusing me.
>
> I hope that helps. They are the same function; but the former is
> *calling* the function object, and optionally using the return value;
> the latter is referring to the function object *as* a value.

Conceptually, that makes sense.  Practically... having a little trouble 
getting my head around it - see below.




max_key = max(counts, key=counts.get)


This specifies ‘counts.get’, without calling it. The expression
‘counts.get’ evaluates to that function object.

That value is then used as the value for the ‘key’ parameter when
calling ‘max’ here.


Been reading a bit more in the mean time, trying to grok that 'key' 
parameter for max()... and of course the python docs for max(iterable, 
key=) refer to the docs for list.sort() ;)


Kind of diverging off the original question a bit... but since it did 
include the max() code in it... I'm having a bit of difficulty with the 
whole 'key=' parameter when combined with counts.get here.


So counts is the iterable, and counts.get is the key used to iterate 
through it?


I guess I'm not getting how the whole key, function object bit works 
here in actual practice.


if we have

counts = {'a':1, 'b':22, 'c':100}

then counts.get('b') should return 22.  I got that much.

And counts.get is just an uncalled version of that:

foo = counts.get
foo('b')

should return 22 as well.  Think I got that as well.

Where things are going pear-shaped is how counts.get can function as a 
'key' when we don't actually supply () (or anything inside them) to 
specify what k,v pair we want, and how that relates back to the iterable 
for max(), counts?


Monte


--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python functions are first-class citizens

2014-08-01 Thread memilanuk

On 07/31/2014 11:46 PM, Ben Finney wrote:


The ‘max’ function can be told how to determine the ordering of items,
by specifying a key parameter. The parameter is specified by giving a
value; that value is a function.


Hmmm... might just have had a break-thru here: so max() iterates thru 
counts, which because its the only non-keyword argument provided has to 
be an iterable (if I'm reading this correctly:
https://docs.python.org/3/library/functions.html?highlight=max#max). It 
takes each dict key ('a', 'b', 'c'), feeds them in turn to counts.get() 
like so: counts.get('a'), counts.get('b'), counts.get('c'), which should 
return the corresponding dict values (1, 22, 100), and then max() 
returns the highest value seen.


Is that about right?

Monte

--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Python functions are first-class citizens

2014-08-01 Thread memilanuk

On 08/01/2014 01:33 AM, Ben Finney wrote:


Ah! Now I get a better idea why you're confused. There are two distinct
uses of “key” going on.


Ahhh... no.  Yes, I realize there were two different uses of 'key' and 
no, I didn't think they were necessarily the same.




* There is no guarantee all the items will be seen. ‘max’ could very
   well decide it's got the largest item and return it at any point. It's
   an implementation detail how it does that.


What?!?  Are you serious?  Under what kind of conditions?



Broadly, you should consider the ‘max’ function a black box.


Yeah, I'm starting to see that...



--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Good Text Editor/IDE for Python

2014-09-03 Thread memilanuk

On 09/01/2014 07:36 PM, Juan Christian wrote:

Forget guys, we have the true winner, Anaconda
(https://sublime.wbond.net/packages/Anaconda)

Anaconda turns your Sublime Text 3 in a full featured Python development
IDE including autocompletion, code linting, IDE features, autopep8
formating, McCabe complexity checker and Vagrant for Sublime Text 3
using Jedi, PyFlakes, pep8, PyLint, pep257 and McCabe that will never
freeze your Sublime Text 3.



Weird that they would pick that name given the potential for confusion 
with this:


https://store.continuum.io/cshop/anaconda/

...unless there is some relation there that I'm missing?  I'll admit, I 
haven't downloaded/installed the Anaconda version of python myself as of 
yet.



--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Good Text Editor/IDE for Python

2014-09-03 Thread memilanuk

On 09/03/2014 12:49 AM, Alan Gauld wrote:


I can see how it happened, after all anaconda is a snake too
so its an "obvious" name for a Python related project...


True... but about 15 seconds of due diligence searching google 
beforehand for 'python anaconda' is all they had to do to avoid the name 
conflict.




--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] Some shameless self promotion

2014-11-03 Thread memilanuk

On 11/02/2014 05:22 PM, Alan Gauld wrote:

For anyone who might be interested

http://www.amazon.com/Python-Projects-Laura-Cassell/dp/111890866X

A book aimed at those who have just finished their first python tutorial
and are wondering what to do next...



Do you know if there are any plans for an electronic version i.e. pdf or 
kindle?



--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] Some shameless self promotion

2014-11-04 Thread memilanuk

On 11/03/2014 11:41 PM, Alan Gauld wrote:

On 04/11/14 00:55, memilanuk wrote:

On 11/02/2014 05:22 PM, Alan Gauld wrote:

For anyone who might be interested

http://www.amazon.com/Python-Projects-Laura-Cassell/dp/111890866X

A book aimed at those who have just finished their first python tutorial
and are wondering what to do next...



Do you know if there are any plans for an electronic version i.e. pdf or
kindle?


I assume so but I'm only the author and that's a decision
for the publishers! :-)




Well, maybe as one of the authors you can poke 'em a bit.  So far the 
only version listed on Amazon or Wrox's site is paperback.


--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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


Re: [Tutor] looking for a Python feature for computer teaching

2014-12-14 Thread memilanuk
I believe that Spyder (lightweight IDE often included in scientific 
python builds like Anaconda, WinPython, python(x,y)) has a variable 
explorer pane... I'd guess you could 'step' thru the program in debugger 
mode and watch the variables change in the explorer window.


https://code.google.com/p/spyderlib/

https://pythonhosted.org/spyder/variableexplorer.html

--
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com

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