Sep-18-2021, 12:59 PM
I get what you are saying but this was the exercise I had to follow. I realize the get_html function is useless. Remember, I am following an exercise with specific criteria.
The instructor wanted us to do it this way and said, "This is not really the best example, etc...." He also said, that it is best to pass global parameters as an argument to the function, even if the global variable can be seen from inside the function. This allows for more self-expressing code.
You use a lot of shortcuts which is fine but for a better understanding, I would prefer to add a few extra lines of code. You did things like, call the function, then take the return into a list comprehension, etc... It works but it's a little difficult to understand. Well, I understand it but if someone uses your code they may not.
We can take our code and constantly refactor it to make it better but there comes a time when you must abandon it. You have much more experience with Python and coding in general than I do.
I was a web developer which is different. My strong points are SQL, rationalizing a database, optimizing it for speed, letting the database layer do most of the heavy lifting with triggers, constraints, etc... Session and cookie management, authentication and authorization, CSS, HTML 5, Javascript, etc...
I want to be as thorough as possible with Python. I have to understand the packages that are included with it such as Math, Collections, Sys, Os, etc.. Then I will move onto building a test website with no framework.
I mainly used VB.net with asp.net then I came across PHP and frameworks. The PHP frameworks aren't as difficult as Django. I briefly looked it over and it's overwhelming because it's not really a MVC.
Question:
How would someone go about creating instances of a class on the fly? or is it even necessary. Let's say it's for a GUI windows program.
A class called Hand which creates a new player for a Black Jack game. Let's say it looks something like this: How would I create instances on the fly to avoid name collision, a GUID?
The instructor wanted us to do it this way and said, "This is not really the best example, etc...." He also said, that it is best to pass global parameters as an argument to the function, even if the global variable can be seen from inside the function. This allows for more self-expressing code.
You use a lot of shortcuts which is fine but for a better understanding, I would prefer to add a few extra lines of code. You did things like, call the function, then take the return into a list comprehension, etc... It works but it's a little difficult to understand. Well, I understand it but if someone uses your code they may not.
We can take our code and constantly refactor it to make it better but there comes a time when you must abandon it. You have much more experience with Python and coding in general than I do.
I was a web developer which is different. My strong points are SQL, rationalizing a database, optimizing it for speed, letting the database layer do most of the heavy lifting with triggers, constraints, etc... Session and cookie management, authentication and authorization, CSS, HTML 5, Javascript, etc...
I want to be as thorough as possible with Python. I have to understand the packages that are included with it such as Math, Collections, Sys, Os, etc.. Then I will move onto building a test website with no framework.
I mainly used VB.net with asp.net then I came across PHP and frameworks. The PHP frameworks aren't as difficult as Django. I briefly looked it over and it's overwhelming because it's not really a MVC.
Question:
How would someone go about creating instances of a class on the fly? or is it even necessary. Let's say it's for a GUI windows program.
A class called Hand which creates a new player for a Black Jack game. Let's say it looks something like this: How would I create instances on the fly to avoid name collision, a GUID?
class Player: def __init__(self, name): self.name = name self.all_cards = [] def remove_one(self): return self.all_cards.pop(0) def add_cards(self, new_cards): if type(new_cards) == type([]): self.all_cards.extend(new_cards) else: self.all_cards.append(new_cards) def __str__(self): return f"Player {self.name} has {len(self.all_cards)} cards." p1 = Player("Matt") p2 = Player("Paul") # How would you create more players and create instances on the fly?