Skip to main content

New answers tagged

0 votes

Is there a way in a class function to return an instance of the class itself?

I had exactly this problem today and found that this works: from __future__ import annotations class a(type): def __init__(self, n): self.n = n def foo() -> a: return a(...
Tony van der Peet's user avatar
Best practices
0 votes
0 replies
0 views

Class inheritence vs one class being element of the another

Very interesting insight, thank you!
Drake Vimes's user avatar
0 votes

Multi-select individuals and assign a class in Protege

There is unforetunately no way to achieve this in Protege. You will have to assign the class for each individual.
Henriette Harmse's user avatar
Best practices
1 vote
0 replies
0 views

Class inheritence vs one class being element of the another

It's been a few decades since I programmed in C++, but as far as I recall, C++ allows multiple inheritance. Most other languages, like Java or C#, only allow single inheritance. If for no other ...
Mark Seemann's user avatar
Best practices
1 vote
0 replies
0 views

Class inheritence vs one class being element of the another

This is the old 'is-a' versus 'has-a' question. Only you can answer it, for your two specific classes. Is B a kind of A? or does A just have-a B? Is class B really a subtype of class A? or is it just ...
user207421's user avatar
  • 312k
Advice
0 votes
0 replies
0 views

Review of my UML class diagram for a student social network (database design)

I don't see too much non-French here. A lot of these terms are written the same in English and French. For as far as I can see this is a fully French model. That is also a bit of a problem, since the ...
Geert Bellekens's user avatar
Advice
0 votes
0 replies
0 views

Review of my UML class diagram for a student social network (database design)

What you should fix first of all, is that mixture of French and English in your naming of entities and properties.
C3roe's user avatar
  • 98.1k
Advice
0 votes
0 replies
0 views

Review of my UML class diagram for a student social network (database design)

You should design the database before the software's class structure. Currently, you're missing keys/ids for many of your objects-- but the importance of this depends on what you plan to use the ...
W Forbes's user avatar
2 votes
Accepted

Create a custom cast (that also accepts $null)

tl;dr You can only achieve what you want via a constructor, not also with a cast. Thus, your only options are: # Method syntax [Checkbox]::new($null).ToString() # New-Object alternative (more ...
mklement0's user avatar
  • 455k
0 votes

Why would I use an ID selector instead of a class?

The other differences are already answered but I also want to add one which is not listed in this answer lists and that is: - IDs in HTML can also be used to create bookmarks (fragment navigation) ...
Meet Rajpal's user avatar
1 vote

Undefined symbols for architecture x86_64: "operator<<"

I have just had the exact same issue, and seeing as this question, which is as yet unanswered, helped me see the issue, I decided to post an answer. For hours I just could not see what my particular ...
Greenonline's user avatar
  • 1,405
Best practices
1 vote
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

For reasons I don't want to get into, Okay, let's play a guessing game...
Marce Puente's user avatar
  • 1,200
Best practices
0 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

You could leave __init__ as I have defined it so that it cannot be called. Take what you would have wanted to put in __init__ in a new function _init: lass MyClass(): def __init__(self): ...
Booboo's user avatar
  • 46.2k
Best practices
0 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

I do need to use __init__ internally however, so I do need to parse the error with a kwarg as in the other answers.
Ben's user avatar
  • 613
Best practices
1 vote
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

Verified that it creates a new class each time: def init_from(c): class MyClass: def __init__(self, a, b): self._a = a self._b = b return MyClass(c-3, c+3) x1 =...
J Earls's user avatar
  • 2,908
Best practices
0 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

Doesn't this create a new version of the MyClass class every time you call init_from?
J Earls's user avatar
  • 2,908
Best practices
0 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

The other answers are probably the best pythonic practice. but if you really want to enforce the caller, you can try using the inspect feature to verify the caller's stack frame: #!/usr/bin/env ...
J Earls's user avatar
  • 2,908
Best practices
2 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

You can hide the whole class inside a factory function: def init_from(c): class MyClass(): a = None b = None def __init__(self, a, b): self.a = a ...
quamrana's user avatar
  • 39.6k
Best practices
3 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

You cannot prevent someone from calling obj = MyClass(), but you can raise an exception if somebody does. You can by pass calling the __init__ method as follows: class MyClass(): def __init__(self)...
Booboo's user avatar
  • 46.2k
Best practices
2 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

you can only disable it by passing False as keyword argument and and True keyword argument in your @classmethod definition class MyClass: def __init__(self, value, _from_factory=False): # ...
DirtyHands's user avatar
Best practices
2 votes
0 replies
0 views

Indicate to Python user that the __init__ constructor should only be used by the class

__init__ always exists and you can't hide it. What I'd do is add a kwarg __private, which defaults to false throws an exception if it's false. Within your own classes factory methods, you then just ...
Toothy's user avatar
  • 26
0 votes

Run Pytest Classes in Custom Order

It might be a personal preference, but I find this structure easier to understand and modify. You can assign an integer to each test, depending on the method name, class name, or file name. The tests ...
Eric Duminil's user avatar
  • 54.6k
0 votes

Fields in Scala Constructor

Yes, there is a small difference. class Days(days: AnyVal): val n: AnyVal = days days is just a constructor parameter. You manually define n as a fields. Only n is accessible from outside. class ...
Leonardodlsv's user avatar
0 votes

ArrayList error, Exception in thread "main" java.lang.NullPointerException

Initialize your list Perhaps you neglected to establish an empty list to hold your destinations. In this example, we use new ArrayList<>() to establish a new empty list on the same line where we ...
Basil Bourque's user avatar
-2 votes

ArrayList error, Exception in thread "main" java.lang.NullPointerException

Array list is part of the java.util package and implements the List interface. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified (if you ...
Zoom's user avatar
  • 1

Top 50 recent answers are included