Comments (4)
Ah, so I've been poking around the test files, and found this:
https://github.com/scikit-hep/pyhepmc/blob/main/tests/test_from_hepevt.py#L17
So I gather that it's not actually a constructor classmethod.
The naming here is a bit confusing, as .from_xxx()
always implies to me it's a classmethod, rather than an instance method which does some inplace operation.
Anyway, I'm sorted now, thank you! (I'll leave open in case you want to add some more docs for numpy stuff etc.)
from pyhepmc.
Sorry for the late reply. I agree that it would be more pythonic if from_hepevt
was a classmethod. I am not sure if there is a way to fix this at this point, but if it is possible to have both a classmethod and a method with the same name then I am happy to fix this. The potential classmethod from_hepevt
then needs two additional optional arguments momentum_unit
and length_unit
.
Perhaps import_hepevt
would have been a better name?
The numpy-friendlyness is discussed here: https://scikit-hep.org/pyhepmc/examples/processing.html
from pyhepmc.
For the record, this works
class Foo:
def from_bar(*args, **kwargs):
if isinstance(args[0], Foo):
print("method", args[1:], kwargs)
else:
print("classmethod", args, kwargs)
from pyhepmc.
Sorry I missed this! I can see from the docs on the numpy stuff, it's mainly regarding computation rather than IO, which is a bit different to my use-case, but cool neverthless. :)
Also, fun example! Though, I think this would be closer to accessing it as a staticmethod? Decorated classmethods receive the class type constructor as the first argument, whereas if you were to do
Foo.from_bar("spam")
The first argument here would be "spam", not the Foo
constructor. So, it seems more like a staticmethod, to me. I guess you could still use it as though it were one, but as in your example, you would need to specifically point it to Foo
. Probably that's not an issue, unless you subclass it. :)
from pyhepmc.
Related Issues (14)
- numpy is not listed as dependency HOT 8
- Time-like component of four vector apparently in wrong position HOT 1
- ValueError: vector::_M_default_append HOT 7
- Is it deat or alive (or undead?) HOT 1
- fill_genevent_from_hepevt not adding particles HOT 2
- Set up a "hook" for Zenodo to mint DOIs HOT 2
- Add wrapper for Setup C++ class
- Simpler saving of visualizations
- pyiostream improvements
- Reading file using pyhepmc (pythia6_simple.dat) HOT 2
- Make pyhepmc.open wrappable
- Use `open` without `with` HOT 1
- Wrong visualization
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyhepmc.