Re: A question on modification of a list via a function invocation

2017-09-04 Thread ROGER GRAYDON CHRISTMAN
>Does a poor job AFAIAC of explaining the difference between foo and bar in foll def foo(x): x += 2 def bar(x): x.append(2) a=10 b=[10] foo(a) a >10 bar(b) b >[10, 2] Or with just one function: >>> def baz(x,y): x += y >>> a = 10 >>> b = [10] >>> baz(a

Re: A question on modification of a list via a function invocation

2017-09-06 Thread ROGER GRAYDON CHRISTMAN
On 5 Sep 2017 14:28:44, wlfr...@ix.netcom.com (Dennis Lee Bier) wrote: > On 5 Sep 2017 17:57:18 GMT, https://webmail.psu.edu/webmail/retrieve.cgi?mailbox=inbox&start_num=14200&limit=50&sort=0&display=4×tamp=20170906045729&mid=mailman%2e%2e1504662834%2e2732%2epython%2dlist%40python%2eorg#";>r.

Re: Simple game board GUI framework

2017-09-11 Thread ROGER GRAYDON CHRISTMAN
I would echo the recommendation of teaching something you are already familiar with doing. Perhaps you can find a different class hierarchy to work with. I remember that the first time I really began to grok OOP was in a text-based MUD environment. In the application area, clearly everything w

Re: [Tutor] beginning to code

2017-09-13 Thread ROGER GRAYDON CHRISTMAN
I have not yet mastered how to respond to a particular note in a threadwith the mailer that I use, so this is not in response to anyone in particular,but just to some of the sentiments as a whole. > if x:> # do something Completely out of context, I would dislike it just because it is far too

Re: Even Older Man Yells at Whippersnappers

2017-09-19 Thread ROGER GRAYDON CHRISTMAN
I recall giving a quiz to my college students sometime back around the late nineties which had a little bit of arithmetic involved in the answer. It's been too long ago to still have the exact details, but I remember a couple solutions that would be of the form: 5 + 10 + 1*2 And then the student

Re: [Tutor] beginning to code

2017-09-23 Thread ROGER GRAYDON CHRISTMAN
On Fri, Sep 22, 2017 12:03 PM, Dennis Lee Bier wrote:> On Fri, 22 Sep 2017 23:30:34 +1000, Steve D'Aprano > declaimed the following: > >The exercise is to demonstrate pass by reference semantics. That requires > >demonstrating the same semantics as the Pascal swap procedure: > > > >procedure swa

Re: python console menu level looping

2017-09-25 Thread ROGER GRAYDON CHRISTMAN
On Mon, Sep 24, 2017 09:41 PM, Daiyue Weng wrote: > Hi, I tried to make a menu using print statements in Python 3. The code is >as follows, > >print('insert data into: ') >data_insert_method = ['new collection', 'existing collection'] >for index, elem in enumerate(data_insert_method): >print(ind

Re: Call by binding [was re: [Tutor] beginning to code]

2017-09-25 Thread ROGER GRAYDON CHRISTMAN
I would claim that these two paragraphs do not agree. What is stored in the variable in Pascal? In declared variables and value parameters, the value itself. Let's just temporarily stipulate that for reference parameters and pointer variables actually store a pointer to the object. Where is it r

Re: Aliasing [was Re: [Tutor] beginning to code]

2017-09-26 Thread ROGER GRAYDON CHRISTMAN
On Tue, Sep 26, 2017 12:00 PM, Steve D'Aprano wrote: > > a = 1 >> b = a >> b = 2 >> >> a is not 2. > < snip > int main () { > int a; > int& b = a; // reference variable or alias > > a = 1; > printf("a: %d, alias b: %d\n", a, b); > b = 2; > printf("a: %d, alias b: %d\n", a, b); > r

Re: Aliasing [was Re: [Tutor] beginning to code]

2017-09-27 Thread ROGER GRAYDON CHRISTMAN
On Tue, Sep 26, 2017 11:00 PM, Steve D'Aprano wrote: > The critical distinction here is whether the names refer to each other: > >a <---> b > >or whether they merely refer to the same value: > >a ---> [ value ] <--- b > > >Python uses the second model. Var parameters in Pascal and references in C

Re: Beginners and experts

2017-09-30 Thread ROGER GRAYDON CHRISTMAN
Not in response to any particular note, but to the thread as a whole. Regarding how beginners make tweaks and changes at random, hoping that the bug will disappear, where experts tend to be a bit more methodical in their bug-fixing. Here at academia I have taught a little bit of partial correctne

Re: when is the filter test applied?

2017-10-03 Thread ROGER GRAYDON CHRISTMAN
On Tue, Oct 3, 2017 15:38:42, Neal Becker wrote: > I'm not certain that it isn't behaving as expected - my code is quite >complicated. > >On Tue, Oct 3, 2017 at 11:35 AM Paul Moore wrote: > >> My intuition is that the lambda creates a closure that captures the >> value of some_seq. If that value

Re: Python-list Digest, Vol 169, Issue 5

2017-10-04 Thread ROGER GRAYDON CHRISTMAN
On Wed, Oct 4, 2017 14:54, Chris Angelico wrote: > On Wed, Oct 4, 2017 at 2:48 PM, Steve D'Aprano > wrote: >> On Wed, 4 Oct 2017 01:40 pm, Chris Angelico wrote: >> >> You know, you don't HAVE to economize on letters. It's okay to call >> your parameters "prompt" instead of "prmt". Remember, tha

Re: The "loop and a half"

2017-10-04 Thread ROGER GRAYDON CHRISTMAN
I teach a course in programming to students who have no plans to be programmers, scientists, or engineers.And I deliberately lied today about the for loop. In my lecture slide, I said that the for loop could only be used if you had a collection of values (e.g. list, tuple, dict, string, or ran

Re: newb question about @property

2017-10-04 Thread ROGER GRAYDON CHRISTMAN
On Wed, Oct 4, 2017 14:03 PM, bartc wrote > "A property, in some object-oriented programming languages, is a special >sort of class member, intermediate in functionality between a field (or >data member) and a method." > >But Python has some problems just in using fields. If you wanted say a

Re: Python-list Digest, Vol 169, Issue 7

2017-10-05 Thread ROGER GRAYDON CHRISTMAN
On Wed, Oct 4, 2017 22:42 Stefan Ram (r...@zedat.fu-berlin.de) wrote: > Steve D'Aprano writes: >>So, "bottom-up" in this case means: iterators should be >>taught before for-loops. >>Why? > > The syntax for is (from memory): > >for in : > > . As an example, I might show: > >for i in range( 3 )

Re: Introducing the "for" loop

2017-10-06 Thread ROGER GRAYDON CHRISTMAN
On Thu, Oct 5, 2017 7:45 PM, breamore...@gmail.com wrote: > On Friday, October 6, 2017 at 2:05:58 AM UTC+1, Irv Kalb wrote: >> >> The range function is discussed after that. >> > >FWIW range isn't a function in Python 3. From https://docs.python.org/3/library/functions.html#func-range "Rathe

Re: Pedagogical style [was Re: The "loop and a half"]

2017-10-06 Thread ROGER GRAYDON CHRISTMAN
On Thu, Oct 5, 2017 8:18 PM, Ben Bacarisse wrote: > Steve D'Aprano writes: > >> There's no link to the original paper, only to secondary sources that discuss >> it, e.g.: >> >> http://phys.org/pdf128266927.pdf > > >> [1] Anecdotes are not data, but for what it is worth, just in the last two >> d

Re: Lies in education [was Re: The "loop and a half"]

2017-10-11 Thread ROGER GRAYDON CHRISTMAN
Actually, FORTRAN and COBOL and Algol (for its control structures) Trying to support both of the first two was entertaining -- when you declared a variable, it wasn't enough to say it was an Integer: you had to also declare whether it was represented in Binary or Decimal, and also specify the desir

Re: how to replace multiple char from string and substitute new char

2017-10-12 Thread ROGER GRAYDON CHRISTMAN
On Thu, Oct 12, 2017, Iranna Mathapati wrote: > >Hi Team, > > >How to replace multipal char from string and substitute with new char with >one line code > >Ex: > >str = "9.0(3)X7(2) " ===> 9.0.3.X7.2 > >need to replace occurrence of '(',')' with dot(.) chars > >output: > > 9.0.3.X7.\

Re: Python-list Digest, Vol 169, Issue 23

2017-10-12 Thread ROGER GRAYDON CHRISTMAN
On Thu, Oct 12, 2017 08:05 AM, Steve D'Aprano wrote:> On Wed, 11 Oct 2017 10:57 pm, Stefan Ram wrote: > >> FWIW, in is book "Touch of Class" (2009) Bertrand >Meyer writes: >> >> |Such instructions are just the old goto in sheep's clothing. >> |Treat them the same way as the original: >> | >> |/To

Re: Python-list Digest, Vol 169, Issue 23

2017-10-12 Thread ROGER GRAYDON CHRISTMAN
The opinions I give in this post are not as strong as the opinions I expressed before about the loop claiming to count all the way to 2**64. But I'll give them anyway. I don't mind having return's inside an if statement, when the function ends with that if statement. It becomes very clear then

Re: Lies in education [was Re: The "loop and a half"]

2017-10-13 Thread ROGER GRAYDON CHRISTMAN
On Sat, Oct 14, 2017, Gregory Ewing wrote: > Message: 5 >Date: Sat, 14 Oct 2017 01:54:49 +1300 >From: Gregory Ewing >To: python-list@python.org >Subject: Re: Lies in education [was Re: The "loop and a half"] >Message-ID: >Content-Type: text/plain; charset=ISO-8859-1; format=flowed > >Neil Cerutti

Re: Save non-pickleable variable?

2017-10-21 Thread ROGER GRAYDON CHRISTMAN
On Sat, Oct 21, 2017, Israel Brewster wrote: > tldr: I have an object that can't be picked. Is there any way to do a >"raw" dump of the binary data to a file, and re-load it later? > >Details: I am using a java (I know, I know - this is a python list. I'm >not asking about the java - honest!) libr

Just a quick question about main()

2017-10-27 Thread ROGER GRAYDON CHRISTMAN
While teaching my introductory course in Python, I occasionally see submissions containing the following two program lines, even before I teach about functions and modules: if __name__ = '__main__': ... main() When I ask about it, I hear things like they got these from other instructors, or from

Re: Coding style in CPython implementation

2017-10-29 Thread ROGER GRAYDON CHRISTMAN
NOTE: The case in question was never comparing to True; it was comparing to NULL. There is no "No: if x == None" below, because None is not Boolean. Similarly comparing a pointer to NULL is not the same as comparing it to a Boolean. So I would favor the "Explicit is better than Implicit" in th

Re: why it append one more letter after decode?

2017-10-30 Thread ROGER GRAYDON CHRISTMAN
On Sun, Oct 29, 2017 11:06 PM, Ho Yeung Lee wrote: > if run these function to decode in python interactive console, >it can decode correct, > >but when run with a big project, it append a letter Y > > >On Monday, October 30, 2017 at 9:48:36 AM UTC+8, Ho Yeung Lee wrote: >> def leftrotate(l, n): >>

Reading a remove csv file

2017-11-02 Thread ROGER GRAYDON CHRISTMAN
Just a quick question on how best to read a remote CSV file. So far, I tried: filelink = urllib.request.urlopen(path) dictread = csv.DictReader(filelink) for row in dictread:... But I'm running into the difference between strings and bytes. I'd like to squeeze a note that talks about the utf-

FW: Reading a remove csv file

2017-11-02 Thread ROGER GRAYDON CHRISTMAN
I have a partial answer to my own question: This seems to work for me: --- link = urllib.request.urlopen(urlpath) data = link.read().decode('utf-8').split('\n') reader = csv.DictReader(data) for row in reader: --- I think here my concern is that now 'data' is now a variable in my program's memor

Re: replacing 'else' with 'then' in 'for' and 'try'

2017-11-06 Thread ROGER GRAYDON CHRISTMAN
Just a little two-cent opinion from the peanut gallery: I've been following all the discussion on this go by, sometimes getting a bit heated at times, and just sitting nice and safe and secure in my little ivory tower, where I simply tell my students to not use 'break'. As a stodgy educator,

Re: Ideas about how software should behave

2017-11-09 Thread ROGER GRAYDON CHRISTMAN
On Thu, Nov 9, 2017, Gregory Ewing wrote:> But ideas are not software -- they don't actively >*do* anything, so trying to anthropomorphise them >doesn't really work. Generally true. I just remember the notable exception: Colorless green ideas sleep furiously. That case of anthropomorphism w

Re: Shoulid constants be introduced to Python?

2017-11-16 Thread ROGER GRAYDON CHRISTMAN
On Thu, Nov 16, 2017, Saeed Baig wrote: > Message: 7 >Date: Thu, 16 Nov 2017 17:16:11 +1100 >From: Saeed Baig >To: python-list@python.org >Subject: Should constants be introduced to Python? >Message-ID: <5d4da7b2-504a-4a3a-bace-ffadea1d2...@icloud.com> >Content-Type: text/plain; charset=utf-8

Re: Problem in defining multidimensional array matrix and regression

2017-11-19 Thread ROGER GRAYDON CHRISTMAN
On Sun, 19 Nov 2017, shalu.ash...@gmail.com wrote: > Hi, All, > >I have 6 variables in CSV file. One is rainfall (dependent, at >y-axis) and others are predictors (at x). I want to do multiple >regression and create a correlation matrix between rainfall (y) and >predictors (x; n1=5). Thus I want to

Re: Python-list Digest, Vol 170, Issue 34

2017-11-27 Thread ROGER GRAYDON CHRISTMAN
I'll answer your question with a couple questions: Why do you expect to get the results you seem to expect? What part of your code should repeat (and why)? A key factor in recognizing the difference between 'if' and 'while' is knowing what effect they have on the indented statements that follow

Re: Python-list Digest, Vol 170, Issue 34

2017-11-27 Thread ROGER GRAYDON CHRISTMAN
I'll answer your question with a couple questions: Why do you expect to get the results you seem to expect? What part of your code should repeat (and why)? A key factor in recognizing the difference between 'if' and 'while' is knowing what effect they have on the indented statements that follow

Re: Python-list Digest, Vol 171, Issue 7

2017-12-06 Thread ROGER GRAYDON CHRISTMAN
I think I also came up with 4 as "the most frequent number". It is unclear ot me how you came up with 3.36 as the most common number, because I tried rolling a six-sided die myself several times, and somehow 3.36 didn't come up even once! On Wed, Dec 6, 2017, D'Arcy Cain wrote: > On 12/05/2017 0

Re: Python-list Digest, Vol 171, Issue 7

2017-12-06 Thread ROGER GRAYDON CHRISTMAN
On Wed, Dec 6, 2017, ssghotra1997 wrote: import random def rollDie(num): sides = {'One':0, 'Two':0,'Three':0,'Four':0,'Five':0,'Six':0} for i in range(num): rolls = int(random.randint(1, 6) if rolls == 1: sides['One'] += 1 if rolls == 2: si

Re: Python homework

2017-12-13 Thread ROGER GRAYDON CHRISTMAN
On Wed, Dec 13, 2017, Lorenzo Sutton wrote: > On 05/12/17 06:33, nick martinez2 via Python-list wrote: >> I have a question on my homework. My homework is to write a program in >which >> the computer simulates the rolling of a die 50 times and then prints >> (i). the most frequent side of the die (

Re: Python Learning

2017-12-16 Thread ROGER GRAYDON CHRISTMAN
On Sat, Dec 16, 2017, Bill wrote: > Varun R wrote: >> Hi All, >> >> I'm new to programming, can anyone guide me, how to start learning python programming language,...plz suggest some books also. >> >> Thanks all > >Are you sure you want to learn Python first? >Python does enough things "behind the

Re: Python Learning

2017-12-16 Thread ROGER GRAYDON CHRISTMAN
On Sat, Dec 16, 2017, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Dec 16, 2017 at 11:41 PM, Marko Rauhamaa wrote: >> r...@zedat.fu-berlin.de (Stefan Ram): >> As a start, one should learn: >> >> 1.) how to install Python >> (if not already installed) >> >> 2.) how to st

Re: RFC: Proposal: Deterministic Object Destruction

2018-02-28 Thread ROGER GRAYDON CHRISTMAN
On Wed, Feb 28, 2018, Rick Johnson wrote: > On Wednesday, February 28, 2018 at 5:02:17 PM UTC-6, Chris Angelico wrote: > >> Here's one example: reference cycles. When do they get detected? >> Taking a really simple situation: >> >> class Foo: >> def __init__(self): >> self.self = self

Is duck-typing misnamed?

2016-08-27 Thread ROGER GRAYDON CHRISTMAN
"If it walks like a duck, quacks like a duck,... " so there is indeed precedence for this so-called 'duck typing' but wouldn't it be more Pythonic to call this 'witch typing'? "How do you know she is a witch?" "She looks like one." etc. I do grant that ultimately, the duck does come into

Re: Is duck-typing misnamed?

2016-08-27 Thread ROGER GRAYDON CHRISTMAN
hon.org wrote: > On 26Aug2016 19:58, ROGER GRAYDON CHRISTMAN wrote: >>"If it walks like a duck, quacks like a duck,... " >>so there is indeed precedence for this so-called 'duck typing' >> >>but wouldn't it be more Pythonic to call this 'witch

Linear Time Tree Traversal Generator

2016-09-20 Thread ROGER GRAYDON CHRISTMAN
I am trying to find a better (i.e. more efficient) way to implement a generator that traverses a tree. The current model of the code (which is also used by a textbook I am teaching from does this) def __iter__(node): for x in iter(node._left): yield x yield node

Re: Linear Time Tree Traversal Generator

2016-09-20 Thread ROGER GRAYDON CHRISTMAN
On Tue, Sep 20, 2016 at 9:46 AM, ROGER GRAYDON CHRISTMAN <https://webmail.psu.edu/webmail/retrieve.cgi?mailbox=inbox&mid=CAO1D73Eho37guUZkM6Kk9Nu5WB43oN721G33XGNis0LhSu7xVQ%40mail%2egmail%2ecom&cmd=view&start_num=10800&limit=50&sort=0&display=4&headers=default&

Re: Linear Time Tree Traversal Generator

2016-09-21 Thread ROGER GRAYDON CHRISTMAN
Since I was asked how I got different running times for my two code fragments, I'll try to apply them to a very simple tree: 4 2 6 1 3 5 7 >def __iter__(node): > for x in iter(node._left): > yield x > yield node._value > for x in iter(nod

Namespace for timeit

2016-10-14 Thread ROGER GRAYDON CHRISTMAN
Trying to use timeit within a function: def test(name, sorter, size): """Tests and times the sorting algorithm on given array size""" print(name,end='\t') array = [0]*size for i in range(size): array[i] = randrange(20) timeit('sorter( array, size )', number=1)

Re: Stock quote AP

2018-03-12 Thread ROGER GRAYDON CHRISTMAN
On Mon, Mar 12, 2018 12:00 PM, Irv Kalb wrote: > > On Mar 10, 2018, at 9:26 PM, Chris Angelico wrote: >> >> On Sun, Mar 11, 2018 at 4:18 PM, Irv Kalb wrote: >> Hi, >> >> I teach courses on beginning Python (Python3). In one of my >topics, I explain how we can write simple programs that reach

Re: What is not working with my "map" usage?

2018-09-22 Thread ROGER GRAYDON CHRISTMAN
On Sat, Sep 22, 2018, Victor (vhnguy...@yahoo.com) wrote Let me use a different input args and display them below. Basically, I am hoping to add up all elements of each nested list. So at first it should start with [1,11,111] ==> 1+11+111 = 123. But instead, it appears to take the 1st element f

Re: Who are the "spacists"?

2017-03-18 Thread ROGER GRAYDON CHRISTMAN
Just a couple minor notes from my experience: 1) Some of the course management software I use doesn't like me typing tab characters. When I want to post sample code into a course page using this software, tabs are either ignored or does something really broken (like post an incomplete file). So,