-1

I have defined a class with a static method. But when I call it, it produces an error saying that two args are being passed when only one is required. I have defined other static methods in other classes, and called them the same way, and they have worked fine. I can perhaps post source code tomorrow, but for now, I only have Internet access from my phone, which does not have the source code.

Is there some common error that produces the sort of thing I am seeing?

  • 2
    What is the language? Anyway, if you have no source code, you should have waited to post until you did, otherwise your question will likely be closed. –  Dec 20 '14 at 05:28
  • Sorry, I was dictating my question: "I have to find" should have read "I have defined" – Gene Callahan Dec 20 '14 at 05:38
  • Sorry, python. I am trying to work this problem out now on the computer with no Internet access, and just trying to see if there is a common cause of this sort of thing. I sincerely wish I could post source code at this moment, but the computer with the code has no Internet access at this moment. – Gene Callahan Dec 20 '14 at 05:40

1 Answers1

0

Are you sure you're calling the method with

ClassName.Method();

and not

ClassInstance.Method();

?

Coding Orange
  • 548
  • 4
  • 7
  • Yes, coding orange, i am calling it the same way I am calling all my other static class instances. In this case, self.props = pa.PropArgs.get_props(prog_nm) where pa is a package andPropArgs a class in that package – Gene Callahan Dec 20 '14 at 05:46
  • [link](http://stackoverflow.com/questions/735975/static-methods-in-python) It looks like you may not be defining it quite right. It is a rather icky syntax. And you're sure you're using the same python version as before? – Coding Orange Dec 20 '14 at 05:49
  • Yes, clearly I am doing something subtle wrong. But all this code is running in Python 3.4. And my other class method definitions work fine in 3.4. So what I am asking is, has anyone else encountered this type of error, and what is the settled thing I am doing wrong? – Gene Callahan Dec 20 '14 at 05:59
  • I will type in by hand the method definition: – Gene Callahan Dec 20 '14 at 06:00
  • @classmethod (nl) def get_props(prog_nm): some code – Gene Callahan Dec 20 '14 at 06:04
  • http://stackoverflow.com/questions/12179271/python-classmethod-and-staticmethod-for-beginner?rq=1 important excerpt: Though classmethod and staticmethod are quite similar, there's a slight difference in usage for both entities: classmethod must have a reference to a class object as the first parameter, whereas staticmethod can have no parameters at all. – Coding Orange Dec 20 '14 at 06:08
  • Thanks, codingorange: I tried redefining the method as a static method, but I get the exact same result. – Gene Callahan Dec 20 '14 at 06:15
  • Here is the line blowing up: self.props = pa.PropArgs.get_props("nm") – Gene Callahan Dec 20 '14 at 06:19
  • pa is a package name. PropArgs is aclass in that pkg. get_props is defined as a class method in that class. My cold seems identical to numerous other instances of me doing this that work. I understand that I have made a mistake somewhere: I just want to know if anyone has seen this sort of mistake before? – Gene Callahan Dec 20 '14 at 06:22
  • Sorry, I don't think I can tell what your problem is. I do hope you figure it out though! – Coding Orange Dec 20 '14 at 06:23
  • Sorry for all the weird words above: I am dictating my comments from my phone. – Gene Callahan Dec 20 '14 at 06:33
  • Ok, so I simply hard-coded the value of PROG_NM in the line self.props = pa.PropArgs.get_props("fashion.py") – Gene Callahan Dec 20 '14 at 06:40
  • Now i get 'PropArgs' object has no attribute 'PropArgs' here, I think, is the key to my error: what does this mean? – Gene Callahan Dec 20 '14 at 06:41
  • I just tried eliminating import prop_args as pa and using the whole module name instead. This made my error revert back to the previous one: the wrong number of positional arguments. What is going on here? Changing between a module name and an "as" module name gives different error messages? – Gene Callahan Dec 20 '14 at 06:48
  • Aargh: now i just eliminated the pkg name before the static method name, and the code works fine! But i have no idea what the difference is! – Gene Callahan Dec 20 '14 at 07:00
  • Ok, The code now seems to be working fine, but I still have no idea what I originally did wrong, or why the various tweaks I performed produced different error messages. – Gene Callahan Dec 20 '14 at 08:32
  • And I am no coding newbie: I have programmed in C, C++, Pascal, object Pascal, lisp, awk, Perl, Java, and another half a dozen languages I have probably forgotten. But what I just went through in getting this code to work is really bizarre to me. – Gene Callahan Dec 20 '14 at 08:35