Re: Definition of "property"

2021-05-31 Thread Irv Kalb
> On May 30, 2021, at 10:15 AM, Jon Ribbens via Python-list > wrote: > > On 2021-05-30, Irv Kalb wrote: >> I understand what a "property" is, how it is used and the benefits, >> but apparently my explanation hasn't made the light bulb go on for my

Definition of "property"

2021-05-30 Thread Irv Kalb
I am doing some writing (for an upcoming book on OOP), and I'm a little stuck. I understand what a "property" is, how it is used and the benefits, but apparently my explanation hasn't made the light bulb go on for my editor. The editor is asking for a definition of property. I've looked at m

Re: pygame font issue

2021-03-13 Thread Irv Kalb
You need to initialize the font system with this line before you attempt to load a font: pygame.font.init() Irv > On Mar 13, 2021, at 8:11 AM, MRAB wrote: > > On 2021-03-13 15:20, Quentin Bock wrote: >> Code that contains the problem: >> score_value = 0 >> font = pygame.font.SysFont('

Re: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread Irv Kalb
On Jan 26, 2021, at 5:28 PM, William Ray Wing via Python-list wrote: > > > >> On Jan 26, 2021, at 2:00 PM, C W wrote: >> >> Hello everyone, >> >> I'm a long time Matlab and R user working on data science. How do you >> troubleshooting/debugging in Python? >> > > Another approach is to run

Re: Debugging technique

2020-10-03 Thread Irv Kalb
This probably is not for you. But PyCharm has a panel that shows a stack trace. I created a video about debugging using the PyCharm debugger. Here is a YouTube link: https://www.youtube.com/watch?v=cxAOSQQwDJ4 Irv > On Oct 2, 2020, at 11:51 PM,

Re: Writing output of function to a csv file

2020-05-25 Thread Irv Kalb
> On May 25, 2020, at 11:25 AM, MRAB > wrote: > > On 2020-05-25 19:00, Ciarán Hudson wrote: >> Hi, >> In the code below, which is an exercise I'm doing in class inheritance, >> almost everything is working except outputting my results, which as the >> functio

Re: [Mostly OT] Feedback on Python homework using Canvas LMS

2020-03-16 Thread Irv Kalb
> On Mar 16, 2020, at 11:31 AM, Irv Kalb wrote: > > This is for anyone who teaches Python and uses the Canvas Learning Management > System (maybe a small group). > > I teach Python at two colleges in Silicon Valley in California. At both > schools we use Canvas. Overal

[Mostly OT] Feedback on Python homework using Canvas LMS

2020-03-16 Thread Irv Kalb
This is for anyone who teaches Python and uses the Canvas Learning Management System (maybe a small group). I teach Python at two colleges in Silicon Valley in California. At both schools we use Canvas. Overall, it works very well. I use it to post notes, sample programs, build tests, post h

Re: [Q] __init__ in class

2019-12-26 Thread Irv Kalb
> On Dec 26, 2019, at 3:11 AM, 황병희 wrote: > > in making class, why we should set "__init__"? so non-init class is > useless? actually i did fail to understand __init__'s meaning. what is > role of __init__ in class. > > sincerely, from python beginner. > > -- > ^고맙습니다 _地平天成_ 감사합니다_^))// > --

Re: How can i stop this Infinite While Loop - Python

2019-10-30 Thread Irv Kalb
> On Oct 30, 2019, at 4:55 AM, ferzan saglam wrote: > > I have tried many ways to stop the infinite loop but my program doesn't seem > to stop after 10 items! It keeps going...!) > > --- > total = 0 > while True:

join and split with empty delimiter

2019-07-17 Thread Irv Kalb
I have always thought that split and join are opposite functions. For example, you can use a comma as a delimiter: >>> myList = ['a', 'b', 'c', 'd', 'e'] >>> myString = ','.join(myList) >>> print(myString) a,b,c,d,e >>> myList = myString.split(',') >>> print(myList) ['a', 'b', 'c', 'd', 'e'] W

Re: Instance vs Class variable oddity

2019-05-17 Thread Irv Kalb
> On May 15, 2019, at 5:41 PM, Ben Finney wrote: > > Irv Kalb writes: > >> I just saw some code that confused me. The confusion has to do with >> class variables and instance variables. > > (Perhaps unrelated, but here's another confusion you may be suff

Re: Instance vs Class variable oddity

2019-05-15 Thread Irv Kalb
> On May 15, 2019, at 11:02 AM, Rob Gaddi > wrote: > > On 5/15/19 10:52 AM, Irv Kalb wrote: >> I just saw some code that confused me. The confusion has to do with class >> variables and instance variables. In order to understand it better, I built >> this ver

Instance vs Class variable oddity

2019-05-15 Thread Irv Kalb
I just saw some code that confused me. The confusion has to do with class variables and instance variables. In order to understand it better, I built this very small example: class Test: x = 0 def __init__(self, id): self.id = id self.show() def show(self):

Re: How to convert a train running program from synchronous to asynchronous?

2019-04-27 Thread Irv Kalb
> On Apr 26, 2019, at 4:18 AM, Arup Rakshit wrote: > > I have modelled which starts running once drivers and stations are assigned > to it. Otherwise, it doesn’t run, really don’t care if passengers are boarded > or not at this moment. :) I think this program can help me to introduce to > the

Re: How call method from a method in same class?

2019-04-01 Thread Irv Kalb
> On Apr 1, 2019, at 7:02 PM, Dave wrote: > > As classes get more complex, it is good to call a function to do some of the > processing, and make the code easier to follow. My question is how to do > that? I've attached some silly code to illustrate the point. The error is: > name 'validS

Re: exit 2 levels of if/else and execute common code

2019-02-11 Thread Irv Kalb
> On Feb 11, 2019, at 7:25 AM, Neal Becker wrote: > > I have code with structure: > ``` > if cond1: > [some code] > if cond2: #where cond2 depends on the above [some code] >[ more code] > > else: >[ do xxyy ] > else: > [ do the same xxyy as above ] > ``` > > So what's the best sty

Re: IDLE Default Working Directory

2018-11-16 Thread Irv Kalb
> On Nov 15, 2018, at 2:44 PM, eryk sun wrote: > > On 11/14/18, Irv Kalb wrote: >> >> When working with data files, I tell students to put their project (their >> main program and any other related files) in a folder. Then, in their calls >> to "open&

Re: IDLE Default Working Directory

2018-11-14 Thread Irv Kalb
> On Nov 13, 2018, at 6:04 PM, Christman, Roger Graydon wrote: > > On 13 Nov 2018, at 09:51, Bev in TX wrote: > >> On Nov 12, 2018, at 5:50 PM, Terry Reedy wrote: >> >> For me, open (command-O) opens 'Documents'. I presume it should be easy >> enough to mov

Re: Instance variables question

2018-04-16 Thread Irv Kalb
> On Apr 16, 2018, at 9:48 AM, duncan smith wrote: > > On 16/04/18 17:03, Irv Kalb wrote: >> I have been writing OOP code for many years in other languages and for the >> past few years in Python. I am writing new curriculum for a course on OOP >> in Python. In

Instance variables question

2018-04-16 Thread Irv Kalb
I have been writing OOP code for many years in other languages and for the past few years in Python. I am writing new curriculum for a course on OOP in Python. In order to see how others are explaining OOP concepts, I have been reading as many books and watching as many videos as I can. I've

Re: Style Q: Instance variables defined outside of __init__

2018-03-20 Thread Irv Kalb
> On Mar 19, 2018, at 10:27 AM, Ned Batchelder wrote: > > On 3/19/18 1:04 PM, Irv Kalb wrote: >> I am building some classes for use in future curriculum. I am using PyCharm >> for my development. On the right hand edge of the PyCharm editor window, >> you get

Style Q: Instance variables defined outside of __init__

2018-03-19 Thread Irv Kalb
I am building some classes for use in future curriculum. I am using PyCharm for my development. On the right hand edge of the PyCharm editor window, you get some little bars indicating warnings or errors in your code. I like this feature and try to clean up as many of those as I can. However

Re: urllib.request.urlopen fails with https - SOLVED

2018-03-16 Thread Irv Kalb
Thank you, thank you, thank you. That fixed it (at least on my computer, I'll see if I can do that at my school). Irv > On Mar 15, 2018, at 7:39 PM, Ned Deily wrote: > > On 2018-03-14 18:04, Irv Kalb wrote: >> File >> "/Library/Frameworks/Python.framework/Ve

Re: urllib.request.urlopen fails with https

2018-03-15 Thread Irv Kalb
On Mar 14, 2018, at 9:54 PM, Gregory Ewing wrote: > > Chris Angelico wrote: >> That means going back to the original problem: "how do we get a usable >> stock price API?". > > Does it have to be stock prices in particular? > Or just some simple piece of data that demonstrates > the principles of

urllib.request.urlopen fails with https (was: Re: Stock quote APi)

2018-03-14 Thread Irv Kalb
Thanks to Chris A and Roger C for their information. Very helpful and I am working on both of their suggestions. But now I've run into a new related problem. I still am trying to get stock information using Standard Library calls for now (although I understand that the requests module makes t

Re: Stock quote API ?

2018-03-11 Thread Irv Kalb
> 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 out to t

Stock quote API ?

2018-03-10 Thread Irv Kalb
Hi, I teach courses on beginning Python (Python3). In one of my topics, I explain how we can write simple programs that reach out to the internet and download data (request/response). I show a number of examples using: urllib.request.urlopen( ) to get things like weather data, currency ex

Re: Python Inheritance Terminology

2018-01-07 Thread Irv Kalb
Thanks for the confirmation, and for the link. Irv > On Jan 5, 2018, at 4:32 PM, Ben Finney wrote: > > Irv Kalb writes: > >> I'm doing some writing for an upcoming course on OOP using Python. > > Welcome, and congratulations for using Python in this work. &g

Python Inheritance Terminology

2018-01-05 Thread Irv Kalb
I'm doing some writing for an upcoming course on OOP using Python. I have been doing OOP programming for many years in many different languages, and I want make sure that I'm using the appropriate terminology in Python. I'd like to know if there are "official" or even standard terms that are

Re: acircle.getCenter() to (x,y) coordinates in Python

2017-12-23 Thread Irv Kalb
> On Dec 23, 2017, at 11:44 AM, G Yu wrote: > > My program has two circles: one stationary circle, drawn at a random > location; and one moving circle, consistently drawn in the same place in the > graphics window. > > > > Currently, acircle.getCenter() outputs this: > > > > > I don't u

Re: property decorator?

2017-12-21 Thread Irv Kalb
Thanks to Rob, Cameron, Ian, Chris and Kirill for the detailed explanations. Very helpful, Irv > On Dec 20, 2017, at 3:56 PM, Irv Kalb wrote: > > I am trying to work through the concept of the @property decorator with > respect to object oriented programming. > >

property decorator?

2017-12-20 Thread Irv Kalb
I am trying to work through the concept of the @property decorator with respect to object oriented programming. I believe that I understand how the @property and @.setter work - and that they are used to turn what looks like direct access to instance variables into method calls in an object.

Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-15 Thread Irv Kalb
> On Oct 14, 2017, at 6:46 PM, Ben Bacarisse wrote: > > Irv Kalb writes: > >> Thank you! > > You're welcome. > > >>> Just a data point... It works here: >>> >>> $ python3 t.py >>> Response is: b'156.99\n

Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread Irv Kalb
Thank you! > On Oct 14, 2017, at 12:10 PM, Ben Bacarisse wrote: > > Irv Kalb writes: > > Lots of detail snipped. I hope it won't matter... > >> > (_ssl.c:749)> >> >> Huh??? >> >> I've read a bunch of documentation, and it lo

Re: Python 2 -> 3, urllib.urlopen (corrected the case)

2017-10-14 Thread Irv Kalb
> On Oct 13, 2017, at 3:27 PM, Irv Kalb wrot > If I take the same program and just modify the print statement to add > parentheses, then try to run it in Python 3.6 (on a Mac): > > ... > import urllib > > # set the Yahoo finance url, set stock name, ask for last price

Python 2 -> 3, urllib.urlOpen

2017-10-13 Thread Irv Kalb
One of the colleges where I teach has just moved from Python 2 to Python 3. I am in the process of converting my beginning Python class from Python 2 to Python 3. Everything has gone smoothly, until I just tried to convert some code that imports and uses urllib.urlOpen to fetch data through an

Re: Introducing the "for" loop

2017-10-05 Thread Irv Kalb
//www.apress.com/us/book/9781484218686 <http://www.apress.com/us/book/9781484218686> They also have an eBook version available Amazon: https://www.amazon.com/Learn-Program-Python-Irv-Kalb/dp/148421868X/ref=sr_1_1?ie=UTF8&qid=1507250994&sr=8-1&keywords=kalb+python In retrospect, the on

Re: Easier way to do this?

2017-10-04 Thread Irv Kalb
I'm assuming from your posts that you are not a student. If that is the case, look at my solution below. > On Oct 4, 2017, at 9:42 AM, 20/20 Lab wrote: > > Looking for advice for what looks to me like clumsy code. > > I have a large csv (effectively garbage) dump. I have to pull out sales >

Re: Boolean Expressions

2017-09-26 Thread Irv Kalb
> > On Sep 26, 2017, at 3:23 PM, Cai Gengyang wrote: > > > I'm trying to understand the logic behind AND. I looked up Python logic tables > > False and False gives False > False and True gives False > True and False gives False > True and True gives True. > > So does that mean that the way 'a

Re: Python... feeding an instance as an argument into a new instance.

2017-09-02 Thread Irv Kalb
> On Sep 2, 2017, at 3:34 PM, Chris Roberts wrote: > > Perhaps someone here could help me to get this into perspective. > Somehow when we start to feed an instance as the argument in a new instance. > my head explodes.. > in this case... > a = Foo() > b = Bar(a) > So... > a is a 'Foo instance

Re: Python string replace the values

2017-09-01 Thread Irv Kalb
> On Sep 1, 2017, at 10:13 AM, Ganesh Pal wrote: > > In the fixed length string i.e "a",last 4 bits i.e "" should be > replaced by the user provided value ( the value is between 0001 + f f f f ) > . I intend to form final_string using a fixed_string and an user provided > user_string >

Re: Teaching the "range" function in Python 3

2017-06-30 Thread Irv Kalb
> On Jun 29, 2017, at 2:21 PM, Chris Angelico wrote: > > On Fri, Jun 30, 2017 at 6:57 AM, Irv Kalb wrote: >> I am wondering if other teachers have run into this. Is this a real >> problem? If so, is there any other way of explaining the concept without >>

Teaching the "range" function in Python 3

2017-06-29 Thread Irv Kalb
I teach Python at two colleges in Silicon Valley. I currently teach an introductory course on Python and most of my students have no programming background whatsoever. Up until now, my colleges have been using Python 2. But now, one of the colleges has made the jump to Python 3. So I am upda

Re: Need help with getting Key, Value out of dicts in lists

2017-04-09 Thread Irv Kalb
information. I was just hoping > to be more direct by matching the 'Value' of 'Key: Resource_group_id' and > pull back the 'Value' of 'Key: Name' and other tags as needed. > > Thanks, > > Kenton Brede > > > > > > On Sa

Re: Need help with getting Key, Value out of dicts in lists

2017-04-08 Thread Irv Kalb
if 'Name' in thisDict: # if thisDict has a key called 'Name' print ('Name is', thisDict['Dict']) if 'Billing' in thisDict: # if thisDict has a key called 'Billing' print ('Billing is', this

Re: Need help with getting Key, Value out of dicts in lists

2017-04-08 Thread Irv Kalb
> On Apr 8, 2017, at 5:55 PM, Kenton Brede wrote: > > This is an example of the data I'm working with. The key/value pairs may > come in any order. There are some keys like the 'Resource_group_id' key and > the 'Name' key which will always be present, but other lists may have > unique keys. >

Re: Disallowing instantiation of super class

2017-02-24 Thread Irv Kalb
> On Feb 24, 2017, at 1:24 AM, Steve D'Aprano > wrote: > > On Fri, 24 Feb 2017 11:19 am, Irv Kalb wrote: > >> Hi, >> >> I have built a set of three classes: >> >> - A super class, let's call it: Base > [...] >> I would like t

Re: Disallowing instantiation of super class

2017-02-23 Thread Irv Kalb
> On Feb 23, 2017, at 4:40 PM, MRAB wrote: > > On 2017-02-24 00:19, Irv Kalb wrote: >> Hi, >> >> I have built a set of three classes: >> >> - A super class, let's call it: Base >> >> - A class that inherits from Base, let's call

Re: Namedtuples problem

2017-02-23 Thread Irv Kalb
> On Feb 23, 2017, at 3:00 PM, Deborah Swanson > wrote: > > The weirdness is that > > group[0][4] > > gets the right answer, but > > group[[idx][records_idx[label]]], > where idx = 0 and records_idx[label]] = 4 If that's the case, then I think you need t

Disallowing instantiation of super class

2017-02-23 Thread Irv Kalb
Hi, I have built a set of three classes: - A super class, let's call it: Base - A class that inherits from Base, let's call that: ClassA - Another class that inherits from Base, let's call that: ClassB ClassA and ClassB have some code in their __init__ methods that set some instance variab

Overriding True and False ?

2017-01-29 Thread Irv Kalb
I teach intro to programming using Python. In my first assignment, students are asked to assign variables of different types and print out the values. One student (who really did not understand Booleans) turned in the following for his/her interpretation of Booleans (Python 2.7): True = 'sha