Re: How does a method of a subclass become a method of the base class?
On 27Mar2023 12:03, Cameron Simpson wrote: On 27Mar2023 01:53, Jen Kris wrote: But that brings up a new question. I can create a class instance with x = BinaryConstraint(), That makes an instance of EqualityConstraint. Copy/paste mistake on my part. This makes an instance of BinaryConstraint. Apologies, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
On 27Mar2023 01:53, Jen Kris wrote: Thanks for your reply. You are correct about the class definition lines – e.g. class EqualityConstraint(BinaryConstraint). I didn’t post all of the code because this program is over 600 lines long. It's DeltaBlue in the Python benchmark suite. Doubtless. But the "class ...:" line is the critical thing. I’ve done some more work since this morning, and now I see what’s happening. But it gave rise to another question, which I’ll ask at the end. The call chain starts at EqualityConstraint(prev, v, Strength.REQUIRED) The class EqualityConstraint is a subclass of BinaryConstraint. The entire class code is: class EqualityConstraint(BinaryConstraint): def execute(self): self.output().value = self.input().value Ok, so it is effectively a BinaryConstraint with a single customised execute() method. Because EqualityConstraint is a subclass of BinaryConstraint, the init method of BinaryConstraint is called first. That is courtesy of the MRO: EqualityConstraint has no __init__, so the one found in BinaryConstraint is found and used. During that initialization (I showed the call chain in my previous message), it calls choose_method. When I inspect the code at "self.choose_method(mark):" in PyCharm, it shows: > This says that it found found the choose_method method in the BinaryConstraint class definition, but that it is _bound_ to the EqualityConstraint instance you're using (self). As EqualityConstraint is a subclass of BinaryConstraint it has bound the choose method from BinaryConstraint, apparently during the BinaryConstraint init process, and that’s the one it uses. So that answers my original question. Incorrectly, I think. __init__ does _nothing_ about other methods, if you mean "__init__" in the sentence above. The class definition results in an EqualityConstraint.__mro__ list of classes, which is where _every_ method is looked for _at call time_. But that brings up a new question. I can create a class instance with x = BinaryConstraint(), That makes an instance of EqualityConstraint. but what happens when I have a line like "EqualityConstraint(prev, v, Strength.REQUIRED)"? That makes an instance of EqualityConstraint. Is it because the only method of EqualityConstraint is execute(self)? I don't know what you're asking here. Is execute a special function like a class __init__? No. It's just a method. In a sense, __init__ isn't very special either. It is just _called_ during new instance setup as the final step. By that time, self is a fully set up instance of... whatever and the __init__ function is just being called to do whatever initial attribute setup every instance of that class needs. Python doesn't magicly call _all_ the __init__ methods of all the superclasses; it calls the first found. So for an EqualityConstraint it finds the one from BinaryConstraint because EqualityConstraint does not provide an overriding one of its own. If EqualityConstraint _did_ provide one, it might typically be structured as: class EqualityConstraint(BinaryConstraint): def __init__(self, prev, v, strength, something_extra): super().__init__(prev, v, strength) self.extra = something_extra So: - Python only calls _one_ __init__ method - in the example above, it finds one in EqualityConstraint and uses it - because Python calls _only_ that, in order to _also_ do the normal setup a BinaryConstraint needs, we pass the parameters used by BinaryConstraint to the new __init__ up the chain by calling super().__init__(BinaryConstraint-parameters-here) - we do our own special something with the something_extra That super().__init__() call is the _only_ thing which arranges that superclass inits get to run. This givens you full control to sompletely replace some superclass' init with a custom one. By calling super().__init__() we're saying we not replacing that stuff, we're running the old stuff and just doing something additional for our subclass. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
Cameron, Thanks for your reply. You are correct about the class definition lines – e.g. class EqualityConstraint(BinaryConstraint). I didn’t post all of the code because this program is over 600 lines long. It's DeltaBlue in the Python benchmark suite. I’ve done some more work since this morning, and now I see what’s happening. But it gave rise to another question, which I’ll ask at the end. The call chain starts at EqualityConstraint(prev, v, Strength.REQUIRED) The class EqualityConstraint is a subclass of BinaryConstraint. The entire class code is: class EqualityConstraint(BinaryConstraint): def execute(self): self.output().value = self.input().value Because EqualityConstraint is a subclass of BinaryConstraint, the init method of BinaryConstraint is called first. During that initialization (I showed the call chain in my previous message), it calls choose_method. When I inspect the code at "self.choose_method(mark):" in PyCharm, it shows: > As EqualityConstraint is a subclass of BinaryConstraint it has bound the choose method from BinaryConstraint, apparently during the BinaryConstraint init process, and that’s the one it uses. So that answers my original question. But that brings up a new question. I can create a class instance with x = BinaryConstraint(), but what happens when I have a line like "EqualityConstraint(prev, v, Strength.REQUIRED)"? Is it because the only method of EqualityConstraint is execute(self)? Is execute a special function like a class __init__? I’ve done research on that but I haven’t found an answer. I’m asking all these question because I have worked in a procedural style for many years, with class work limited to only simple classes, but now I’m studying classes in more depth. The three answers I have received today, including yours, have helped a lot. Thanks very much. Jen Mar 26, 2023, 22:45 by c...@cskk.id.au: > On 26Mar2023 22:36, Jen Kris wrote: > >> At the final line it calls "satisfy" in the Constraint class, and that line >> calls choose_method in the BinaryConstraint class. Just as Peter Holzer >> said, it requires a call to "satisfy." >> >> My only remaining question is, did it select the choose_method in the >> BinaryConstraint class instead of the choose_method in the UrnaryConstraint >> class because of "super(BinaryConstraint, self).__init__(strength)" in step >> 2 above? >> > > Basicly, no. > > You've omitting the "class" lines of the class definitions, and they define > the class inheritance, _not "__init__". The "__init__" method just > initialises the state of the new objects (which has already been created). > The: > > super(BinaryConstraint,_ self).__init__(strength) > > line simply calls the appropriate superclass "__init__" with the "strength" > parameter to do that aspect of the initialisation. > > You haven't cited the line which calls the "choose_method" method, but I'm > imagining it calls "choose_method" like this: > > self.choose_method(...) > > That searchs for the "choose_method" method based on the method resolution > order of the object "self". So if "self" was an instance of > "EqualityConstraint", and I'm guessing abut its class definition, assuming > this: > > class EqualityConstraint(BinaryConstraint): > > Then a call to "self.choose_method" would look for a "choose_method" method > first in the EqualityConstraint class and then via the BinaryConstraint > class. I'm also assuming UrnaryConstraint is not in that class ancestry i.e. > not an ancestor of BinaryConstraint, for example. > > The first method found is used. > > In practice, when you define a class like: > > class EqualityConstraint(BinaryConstraint): > > the complete class ancestry (the addition classes from which BinaryConstraint > inherits) gets flatterned into a "method resultion order" list of classes to > inspect in order, and that is stored as the ".__mro__" field on the new class > (EqualityConstraint). You can look at it directly as > "EqualityConstraint.__mro__". > > So looking up: > > self.choose_method() > > looks for a "choose_method" method on the classes in "type(self).__mro__". > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
On 26Mar2023 22:36, Jen Kris wrote: At the final line it calls "satisfy" in the Constraint class, and that line calls choose_method in the BinaryConstraint class. Just as Peter Holzer said, it requires a call to "satisfy." My only remaining question is, did it select the choose_method in the BinaryConstraint class instead of the choose_method in the UrnaryConstraint class because of "super(BinaryConstraint, self).__init__(strength)" in step 2 above? Basicly, no. You've omitting the "class" lines of the class definitions, and they define the class inheritance, _not "__init__". The "__init__" method just initialises the state of the new objects (which has already been created). The: super(BinaryConstraint,_ self).__init__(strength) line simply calls the appropriate superclass "__init__" with the "strength" parameter to do that aspect of the initialisation. You haven't cited the line which calls the "choose_method" method, but I'm imagining it calls "choose_method" like this: self.choose_method(...) That searchs for the "choose_method" method based on the method resolution order of the object "self". So if "self" was an instance of "EqualityConstraint", and I'm guessing abut its class definition, assuming this: class EqualityConstraint(BinaryConstraint): Then a call to "self.choose_method" would look for a "choose_method" method first in the EqualityConstraint class and then via the BinaryConstraint class. I'm also assuming UrnaryConstraint is not in that class ancestry i.e. not an ancestor of BinaryConstraint, for example. The first method found is used. In practice, when you define a class like: class EqualityConstraint(BinaryConstraint): the complete class ancestry (the addition classes from which BinaryConstraint inherits) gets flatterned into a "method resultion order" list of classes to inspect in order, and that is stored as the ".__mro__" field on the new class (EqualityConstraint). You can look at it directly as "EqualityConstraint.__mro__". So looking up: self.choose_method() looks for a "choose_method" method on the classes in "type(self).__mro__". Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
Based on your explanations, I went through the call chain and now I understand better how it works, but I have a follow-up question at the end. This code comes from the DeltaBlue benchmark in the Python benchmark suite. 1 The call chain starts in a non-class program with the following call: EqualityConstraint(prev, v, Strength.REQUIRED) 2 EqualityConstraint is a subclass of BinaryConstraint, so first it calls the __init__ method of BinaryConstraint: def __init__(self, v1, v2, strength): super(BinaryConstraint, self).__init__(strength) self.v1 = v1 self.v2 = v2 self.direction = Direction.NONE self.add_constraint() 3 At the final line shown above it calls add_constraint in the Constraint class, the base class of BinaryConstraint: def add_constraint(self): global planner self.add_to_graph() planner.incremental_add(self) 4 At planner.incremental_add it calls incremental_add in the Planner class because planner is a global instance of the Planner class: def incremental_add(self, constraint): mark = self.new_mark() overridden = constraint.satisfy(mark) At the final line it calls "satisfy" in the Constraint class, and that line calls choose_method in the BinaryConstraint class. Just as Peter Holzer said, it requires a call to "satisfy." My only remaining question is, did it select the choose_method in the BinaryConstraint class instead of the choose_method in the UrnaryConstraint class because of "super(BinaryConstraint, self).__init__(strength)" in step 2 above? Thanks for helping me clarify that. Jen Mar 26, 2023, 18:55 by hjp-pyt...@hjp.at: > On 2023-03-26 19:43:44 +0200, Jen Kris via Python-list wrote: > >> The base class: >> >> >> class Constraint(object): >> > [...] > >> def satisfy(self, mark): >> global planner >> self.choose_method(mark) >> >> The subclass: >> >> class UrnaryConstraint(Constraint): >> > [...] > >> def choose_method(self, mark): >> if self.my_output.mark != mark and \ >> Strength.stronger(self.strength, self.my_output.walk_strength): >> self.satisfied = True >> else: >> self.satisfied = False >> >> The base class Constraint doesn’t have a "choose_method" class method, >> but it’s called as self.choose_method(mark) on the final line of >> Constraint shown above. >> >> My question is: what makes "choose_method" a method of the base >> class, >> > > Nothing. choose_method isn't a method of the base class. > >> called as self.choose_method instead of >> UrnaryConstraint.choose_method? Is it super(UrnaryConstraint, >> self).__init__(strength) or just the fact that Constraint is its base >> class? >> > > This works only if satisfy() is called on a subclass of Constraint which > actually implements this method. > > If you do something like > > x = UrnaryConstraint() > x.satisfy(whatever) > > Then x is a member of class UrnaryConstraint and will have a > choose_method() method which can be called. > > >> Also, this program also has a class BinaryConstraint that is also a >> subclass of Constraint and it also has a choose_method class method >> that is similar but not identical: >> > ... > >> When called from Constraint, it uses the one at UrnaryConstraint. How >> does it know which one to use? >> > > By inspecting self. If you call x.satisfy() on an object of class > UrnaryConstraint, then self.choose_method will be the choose_method from > UrnaryConstraint. If you call it on an object of class BinaryConstraint, > then self.choose_method will be the choose_method from BinaryConstraint. > > hp > > PS: Pretty sure there's one "r" too many in UrnaryConstraint. > > -- > _ | Peter J. Holzer| Story must make more sense than reality. > |_|_) || > | | | h...@hjp.at |-- Charles Stross, "Creative writing > __/ | http://www.hjp.at/ | challenge!" > -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
Thanks to Richard Damon and Peter Holzer for your replies. I'm working through the call chain to understand better so I can post a followup question if needed. Thanks again. Jen Mar 26, 2023, 19:21 by rich...@damon-family.org: > On 3/26/23 1:43 PM, Jen Kris via Python-list wrote: > >> The base class: >> >> >> class Constraint(object): >> >> def __init__(self, strength): >> super(Constraint, self).__init__() >> self.strength = strength >> >> def satisfy(self, mark): >> global planner >> self.choose_method(mark) >> >> The subclass: >> >> class UrnaryConstraint(Constraint): >> >> def __init__(self, v, strength): >> super(UrnaryConstraint, self).__init__(strength) >> self.my_output = v >> self.satisfied = False >> self.add_constraint() >> >> def choose_method(self, mark): >> if self.my_output.mark != mark and \ >> Strength.stronger(self.strength, self.my_output.walk_strength): >> self.satisfied = True >> else: >> self.satisfied = False >> >> The base class Constraint doesn’t have a "choose_method" class method, but >> it’s called as self.choose_method(mark) on the final line of Constraint >> shown above. >> >> My question is: what makes "choose_method" a method of the base class, >> called as self.choose_method instead of UrnaryConstraint.choose_method? Is >> it super(UrnaryConstraint, self).__init__(strength) or just the fact that >> Constraint is its base class? >> >> Also, this program also has a class BinaryConstraint that is also a subclass >> of Constraint and it also has a choose_method class method that is similar >> but not identical: >> >> def choose_method(self, mark): >> if self.v1.mark == mark: >> if self.v2.mark != mark and Strength.stronger(self.strength, >> self.v2.walk_strength): >> self.direction = Direction.FORWARD >> else: >> self.direction = Direction.BACKWARD >> >> When called from Constraint, it uses the one at UrnaryConstraint. How does >> it know which one to use? >> >> Thanks, >> >> Jen >> > > Perhaps the key point to remember is that when looking up the methods on an > object, those methods are part of the object as a whole, not particually > "attached" to a given class. When creating the subclass typed object, first > the most base class part is built, and all the methods of that class are put > into the object, then the next level, and so on, and if a duplicate method is > found, it just overwrites the connection. Then when the object is used, we > see if there is a method by that name to use, so methods in the base can find > methods in subclasses to use. > > Perhaps a more modern approach would be to use the concept of an "abstract > base" which allows the base to indicate that a derived class needs to define > certain abstract methods, (If you need that sort of support, not defining a > method might just mean the subclass doesn't support some optional behavior > defined by the base) > > -- > Richard Damon > > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
On 3/26/23 1:43 PM, Jen Kris via Python-list wrote: The base class: class Constraint(object): def __init__(self, strength): super(Constraint, self).__init__() self.strength = strength def satisfy(self, mark): global planner self.choose_method(mark) The subclass: class UrnaryConstraint(Constraint): def __init__(self, v, strength): super(UrnaryConstraint, self).__init__(strength) self.my_output = v self.satisfied = False self.add_constraint() def choose_method(self, mark): if self.my_output.mark != mark and \ Strength.stronger(self.strength, self.my_output.walk_strength): self.satisfied = True else: self.satisfied = False The base class Constraint doesn’t have a "choose_method" class method, but it’s called as self.choose_method(mark) on the final line of Constraint shown above. My question is: what makes "choose_method" a method of the base class, called as self.choose_method instead of UrnaryConstraint.choose_method? Is it super(UrnaryConstraint, self).__init__(strength) or just the fact that Constraint is its base class? Also, this program also has a class BinaryConstraint that is also a subclass of Constraint and it also has a choose_method class method that is similar but not identical: def choose_method(self, mark): if self.v1.mark == mark: if self.v2.mark != mark and Strength.stronger(self.strength, self.v2.walk_strength): self.direction = Direction.FORWARD else: self.direction = Direction.BACKWARD When called from Constraint, it uses the one at UrnaryConstraint. How does it know which one to use? Thanks, Jen Perhaps the key point to remember is that when looking up the methods on an object, those methods are part of the object as a whole, not particually "attached" to a given class. When creating the subclass typed object, first the most base class part is built, and all the methods of that class are put into the object, then the next level, and so on, and if a duplicate method is found, it just overwrites the connection. Then when the object is used, we see if there is a method by that name to use, so methods in the base can find methods in subclasses to use. Perhaps a more modern approach would be to use the concept of an "abstract base" which allows the base to indicate that a derived class needs to define certain abstract methods, (If you need that sort of support, not defining a method might just mean the subclass doesn't support some optional behavior defined by the base) -- Richard Damon -- https://mail.python.org/mailman/listinfo/python-list
Re: How does a method of a subclass become a method of the base class?
On 2023-03-26 19:43:44 +0200, Jen Kris via Python-list wrote: > The base class: > > > class Constraint(object): [...] > def satisfy(self, mark): > global planner > self.choose_method(mark) > > The subclass: > > class UrnaryConstraint(Constraint): [...] > def choose_method(self, mark): > if self.my_output.mark != mark and \ > Strength.stronger(self.strength, self.my_output.walk_strength): > self.satisfied = True > else: > self.satisfied = False > > The base class Constraint doesn’t have a "choose_method" class method, > but it’s called as self.choose_method(mark) on the final line of > Constraint shown above. > > My question is: what makes "choose_method" a method of the base > class, Nothing. choose_method isn't a method of the base class. > called as self.choose_method instead of > UrnaryConstraint.choose_method? Is it super(UrnaryConstraint, > self).__init__(strength) or just the fact that Constraint is its base > class? This works only if satisfy() is called on a subclass of Constraint which actually implements this method. If you do something like x = UrnaryConstraint() x.satisfy(whatever) Then x is a member of class UrnaryConstraint and will have a choose_method() method which can be called. > Also, this program also has a class BinaryConstraint that is also a > subclass of Constraint and it also has a choose_method class method > that is similar but not identical: ... > When called from Constraint, it uses the one at UrnaryConstraint. How > does it know which one to use? By inspecting self. If you call x.satisfy() on an object of class UrnaryConstraint, then self.choose_method will be the choose_method from UrnaryConstraint. If you call it on an object of class BinaryConstraint, then self.choose_method will be the choose_method from BinaryConstraint. hp PS: Pretty sure there's one "r" too many in UrnaryConstraint. -- _ | Peter J. Holzer| Story must make more sense than reality. |_|_) || | | | h...@hjp.at |-- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
How does a method of a subclass become a method of the base class?
The base class: class Constraint(object): def __init__(self, strength): super(Constraint, self).__init__() self.strength = strength def satisfy(self, mark): global planner self.choose_method(mark) The subclass: class UrnaryConstraint(Constraint): def __init__(self, v, strength): super(UrnaryConstraint, self).__init__(strength) self.my_output = v self.satisfied = False self.add_constraint() def choose_method(self, mark): if self.my_output.mark != mark and \ Strength.stronger(self.strength, self.my_output.walk_strength): self.satisfied = True else: self.satisfied = False The base class Constraint doesn’t have a "choose_method" class method, but it’s called as self.choose_method(mark) on the final line of Constraint shown above. My question is: what makes "choose_method" a method of the base class, called as self.choose_method instead of UrnaryConstraint.choose_method? Is it super(UrnaryConstraint, self).__init__(strength) or just the fact that Constraint is its base class? Also, this program also has a class BinaryConstraint that is also a subclass of Constraint and it also has a choose_method class method that is similar but not identical: def choose_method(self, mark): if self.v1.mark == mark: if self.v2.mark != mark and Strength.stronger(self.strength, self.v2.walk_strength): self.direction = Direction.FORWARD else: self.direction = Direction.BACKWARD When called from Constraint, it uses the one at UrnaryConstraint. How does it know which one to use? Thanks, Jen -- https://mail.python.org/mailman/listinfo/python-list
Re: Patrick Sheehan: Major Issues with Python
On 3/25/2023 4:03 PM, Patrick Sheehan wrote: Hello, I have been working with the attached book (See photo) Photos do not come through on this list, so don't bother to attach any. Type or copy-paste any useful text. to try to learn Python and so far it has been a complete nightmare trying to get python installed and operating correctly. I have received a plethora of error messages and consulted youtube videos and chat groups to try to remedy the issues. I am using a computer that is running Windows 10. That's too bad. Normally a Python install on Windows is trouble free. Perhaps we can help. I have installed, and un-installed several versions of Python Please give more information. What versions of Python, where did you get it, how did you install it, what options if any did you choose during the installation? and was able to complete the first two lessons in the attached book, but could not complete lesson 3 (Turtledemo)...Some of the error messages I have received include: "This app cannot run on your PC"; "Unable to initialize device PRN"; “Python is not recognized as an internal or external command”: "Python was not found: run without arguments to install from Microsoft Store, or disable this shortcut from settings mange, app execution aliases:" You need to tell us just what you have done. What was this "lesson" supposed to do? Did you try to run it while you were working in PyCharm? Just how did you try to run the lesson? ...I have been at this for 4 days now at least three hours each day...Any information or help you can provide would be greatly appreciated. Additionally, I do have PyCharm installed (As you can tell, I am a beginner), is PyCharm the same thing as Python? Thank you in advance! No, PyCharm is an editor and Python IDE; it is not the same as Python. Python is a programming language. The problems you have been having could be caused by PyCharm not being set up to work with your installation of Python. To see if Python has been installed correctly, open a Windows console. If you don't know how, one way is to hit the Windows key and type "cmd". Windows will offer "Command Prompt". Hit the ENTER key to accept it, and a console window will open. (There are more convenient ways, but we don't need to get into them right now). In the console window, type (without the quotes) "py -V". You should see something like this (The first line is what I typed, the second line is the response): C:\Users\tom>py -V Python 3.10.9 If this works, Python has been installed and apparently working. If it is working, save the Python program from your lesson as a file with a name such as such as "lesson1.py". In an open console window. try to run it by typing py lesson1.py Instead of just "lesson1.py", you will either need to change directory (using the cd command) to the directory that contains that file, or you will need to use the full path to the file. For example, if the file is c:\temp\python\lesson1.py then run it by typing py c:\temp\python\lesson1.py Let us know how it goes. -- https://mail.python.org/mailman/listinfo/python-list
Re: Patrick Sheehan: Major Issues with Python
On 2023-03-25 20:03, Patrick Sheehan wrote: Hello, I have been working with the attached book (See photo) to try to learn Python and so far it has been a complete nightmare trying to get python installed and operating correctly. I have received a plethora of error messages and consulted youtube videos and chat groups to try to remedy the issues. I am using a computer that is running Windows 10. I have installed, and un-installed several versions of Python and was able to complete the first two lessons in the attached book, but could not complete lesson 3 (Turtledemo)...Some of the error messages I have received include: "This app cannot run on your PC"; "Unable to initialize device PRN"; “Python is not recognized as an internal or external command”: "Python was not found: run without arguments to install from Microsoft Store, or disable this shortcut from settings mange, app execution aliases:"...I have been at this for 4 days now at least three hours each day...Any information or help you can provide would be greatly appreciated. Additionally, I do have PyCharm installed (As you can tell, I am a beginner), is PyCharm the same thing as Python? Thank you in advance! This list strips attachments such as images, so I don't know which book you're referring to. I'd go for Python 3.11 and the installer "Windows installer (64-bit)" at https://www.python.org/downloads/release/python-3112/, i.e. "https://www.python.org/ftp/python/3.11.2/python-3.11.2-amd64.exe"; (assuming that it's a 64-bit PC). To run Python, the recommended way is to use the Python Launcher, py.exe (so type "py my_program.py" in a Command window), or just double-click on it if it's a GUI program. As for PRN, that's the printer. Does anyone use PRN these days? And, no, PyCharm is not the same thing as Python. PyCharm is an IDE (integrated development environment) for Python, but Python is its own thing. -- https://mail.python.org/mailman/listinfo/python-list
Re: Patrick Sheehan: Major Issues with Python
On 3/25/23 14:03, Patrick Sheehan wrote: Hello, I have been working with the attached book (See photo) to try to learn Python and so far it has been a complete nightmare trying to get python installed and operating correctly. I have received a plethora of error messages and consulted youtube videos and chat groups to try to remedy the issues. I am using a computer that is running Windows 10. I have installed, and un-installed several versions of Python and was able to complete the first two lessons in the attached book, but could not complete lesson 3 (Turtledemo)...Some of the error messages I have received include: "This app cannot run on your PC"; "Unable to initialize device PRN"; “Python is not recognized as an internal or external command”: "Python was not found: run without arguments to install from Microsoft Store, or disable this shortcut from settings mange, app execution aliases:"... If you installed the conventional way, use the command name "py" instead of "python" to run things from a command shell. Alternatively, you could try an installation of Python from the Microsoft Store (as the little stub program named python, which Microsoft preinstalls for the express purpose of giving you this hint). There are times when getting Python working without hassle is easier when going that route. You *can* add python to the search PATH, there's an option in the installer (you can rerun this from the Apps & features Settings applet)... in the screen for advanced options there's something that says "Add python to environment variables" or similar wording. >I have been at this for 4 days now at least three hours each day...Any information or help you can provide would be greatly appreciated. Additionally, I do have PyCharm installed (As you can tell, I am a beginner), is PyCharm the same thing as Python? No. It's an "integrated development environment" - editor, debugger, source control wrangler and many other things. It still needs to have a working Python installed. It will probably find the installed Python more easily than you will. The concept of an IDE is you can do all your programming work without leaving it - you don't have to hop between editor, command line, and invoke other tools. PyCharm is only one of many entrants in this space for Python programmers. It's excellent, but I find it rather, ummm, "bulky", for beginners - there are a ton of features you'll not use early on in your journey, and thus I find it makes it much harder to find the things you do need in menus, help, etc. Up to you whether you push ahead with using it now, or leave it for a bit later when you're doing more complex things. We have no idea what book you're using, by the way, as the list strips images and other attachments. In any case, there are hundreds of Python books out now, most of us don't know about a particular one (unless we wrote it :) ) -- https://mail.python.org/mailman/listinfo/python-list
Patrick Sheehan: Major Issues with Python
Hello, I have been working with the attached book (See photo) to try to learn Python and so far it has been a complete nightmare trying to get python installed and operating correctly. I have received a plethora of error messages and consulted youtube videos and chat groups to try to remedy the issues. I am using a computer that is running Windows 10. I have installed, and un-installed several versions of Python and was able to complete the first two lessons in the attached book, but could not complete lesson 3 (Turtledemo)...Some of the error messages I have received include: "This app cannot run on your PC"; "Unable to initialize device PRN"; “Python is not recognized as an internal or external command”: "Python was not found: run without arguments to install from Microsoft Store, or disable this shortcut from settings mange, app execution aliases:"...I have been at this for 4 days now at least three hours each day...Any information or help you can provide would be greatly appreciated. Additionally, I do have PyCharm installed (As you can tell, I am a beginner), is PyCharm the same thing as Python? Thank you in advance! Respectfully, Patrick Sheehan -- https://mail.python.org/mailman/listinfo/python-list