>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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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 )
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
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
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
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.\
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
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
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
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
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
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
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):
>>
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-
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
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,
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
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
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
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
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
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
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
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 (
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
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
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
"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
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
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
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&
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
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)
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
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
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,
50 matches
Mail list logo