Questions tagged [python-object]

102 questions
1
vote
1 answer

Python: from timestamp to datetime

I have the following dataframe: df = pd.DataFrame({'user': ['Andrea', 'Gioele'], 'year': [1983, 2014], 'month': [11, 1], 'day': [8, 11]} ) Then I create the date for every row in two…
Andrea Ianni
  • 829
  • 12
  • 24
1
vote
0 answers

creating two non-nested objects on the same text using element tree with python

I have some text to convert from excel to xml adding the objects “Scope” and “Cue” to some parts of that text. When object “Cue” is present, object “Scope” must be present. However, they are not nested: they can be in different parts of the text…
norpa
  • 127
  • 2
  • 16
1
vote
1 answer

Unicode representation of an object back into an object (in python)

FYI - this is program uses Django but I am NOT tagging it as such because it is not a django problem. The django code is here for context ~~The Background~~ I uncovered a bug that I had in a program. In short, I am using urlparse.urlparse to get…
Adam Hopkins
  • 6,837
  • 6
  • 32
  • 52
0
votes
3 answers

How do I create two objects in Python with different identities but the same value?

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 == and is operators and I want to actually see the…
0
votes
1 answer

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: raise ValueError("Missing name!") self.name = name …
0
votes
1 answer

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 edited before. The problem is: I don't wanna test for every…
0
votes
1 answer

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 add_node(self, obj) : node =…
0
votes
0 answers

django-filter python class sub function under __init__ function not receive value return

I'm coding a django project that use django-filter: filter.py: import django_filters from myApp.models import MyRunStats class MyRunStatsFilter(django_filters.FilterSet): def gen_choice(filed): return tuple((l, l) for l in…
William
  • 3,724
  • 9
  • 43
  • 76
0
votes
0 answers

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. Unfortunately my current code only returns…
Remi
  • 33
  • 5
0
votes
2 answers

What is the value of . 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 is foobar2) #prints False. Why? On the one…
lamc
  • 347
  • 2
  • 5
0
votes
1 answer

i have an error python OOP. Python magic method __div__()

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): return (self.x / other.x) n1 = add_object(24) n2 =…
0
votes
1 answer

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 I would like to pickle. So I…
phollox
  • 323
  • 3
  • 13
0
votes
0 answers

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 attributes and are dependent on each others): class…
0
votes
1 answer

How to move ContextFilter class for logging to separate module?

I have ContextFilter Class in my python script which I am using to have a counter variable in log formatter. It works as expected and prints value of incremented variable in log. But when I try to move this Class to a custom module that I have…
300
  • 965
  • 1
  • 14
  • 53
0
votes
0 answers

Cython cannot convert to Python object

cdef class Y: cdef double* _ptr def __cinit__(self, double* ptr): self._ptr = ptr cdef class X: cdef double* _ptr def __cinit__(self): # some magic with _ptr self._y = Y(self._ptr) Cannot…
kebabdubai
  • 67
  • 6