105 questions
0
votes
1
answer
42
views
Python( Gotcha?) - Element gets appended to multiple list items, in a list of list [duplicate]
I've recently hit a gotcha in Python. I've added a minimal example. Can somebody tell me what is happening?
a = [list()] * 3
print(a)
#[[], [], []]
a[0].append(1)
print(a)
#Out - [[1], [1], [1]]
#...
-1
votes
1
answer
68
views
How to extract each value seperately from the object 'best_params_' returned by gridsearch method by sklearn?
I am using gridsearch in sklearn using the following code
How should I extract each numeric value i.e. 44.984326689694534 or 0.2811768697974237 from the object grid.best_params_?
param_grid= {'gamma': ...
0
votes
0
answers
82
views
How to call Inner Class?
Is there any difference between call Person.Name() and self.Name() despite Person.Name() being more readable?
class Person:
class Name:
def __init__(self, first_name, last_name):
...
0
votes
0
answers
130
views
Handling of long living python objects in docker container, remote controll of objects
I am developing a design which works on top of a docker network topology. It emulates netwrok elements talking to each other using udp packets.
On host the big controller script is executed. It brings ...
0
votes
3
answers
1k
views
How do I create two objects in Python with different identities but the same value? [duplicate]
I can't seem to be able to create two strings that have the same value but different identities.
I'm using PyCharm 2023.1 and I'm very new to Python, I've just learned about the difference between == ...
0
votes
1
answer
64
views
Attribute error when trying to going back and forth between functions in Python
I'm getting the error "AttributeError: 'NoneType' object has no attribute 'name'" for the code below:
class Student:
def __init__(self, name, house):
if not name:
...
0
votes
1
answer
125
views
Django: How to create "Published" and "Last edited" fields?
I'm writing a blog for my portfolio and I wanna compare (in the Django template) the date I published an article with the date I edited it in order to display the "Edit date" only if it was ...
0
votes
1
answer
49
views
Dynamically set Node, Python3 - BinaryTree module
I was experimenting with graphs in python and i felt into a problem.
Here is the code :
class IspNetwork :
def __init__(self) -> None:
self.root : Node = Node("isp")
def ...
0
votes
0
answers
24
views
Including another object inside an object and calling a specific value
I'm trying to make a simple 5v5 sport management, but I'm not sure how can I link players to teams, in order to make the overall rating of the team be the sum of the players rating / amount of players....
0
votes
2
answers
206
views
What is the value of <object name>.<method name> in Python?
Consider the following code.
class Foo:
def bar(self, x):
pass
foo1 = Foo()
foo2 = Foo()
foobar1 = foo1.bar
foobar2 = foo2.bar #What are foobar1 and foobar2?
print(foobar1 ...
3
votes
2
answers
2k
views
type(x) is list vs type(x) == list
In Python, suppose one wants to test whether the variable x is a reference to a list object. Is there a difference between if type(x) is list: and if type(x) == list:? This is how I understand it. (...
0
votes
1
answer
105
views
i have an error python OOP. Python magic method __div__() [duplicate]
I have "TypeError: unsupported operand type(s) for /: " for this code
class add_object:
def __init__(self, num) -> None:
self.x = num
def __div__(self, other):
...
0
votes
1
answer
234
views
in Python/iPython, is there any way to access or call an object or variable properties from solely its name within a list?
I have a Jupyter Notebook. I know it's not optimal for large works but for many circumstances, is the tool I have to use.
After some computations, I end up with several pandas DataFrame in memory that ...
0
votes
0
answers
77
views
Accessing other classes attributes in Python
I want to design specific class hierarchy consisting of three classes: Certificate, Organization, User. Both Certificate and Organization seem to me to be kinda "equal" (they are each others ...
1
vote
4
answers
996
views
how to create a python object where every attribute is None
I'm not sure if this can be done, but I would like an object where you can query any attribute, and it just returns None, instead of an error.
eg.
>>> print(MyObject.whatever)
None
>>&...