2

I know that this question will recieve some fairly strong comments but I'm going to post it anyway.

I'm working on a project in Python. My simple reasons for choosing Python are the available librtaries and it is cross platform and open source. My problem is that I really enjoy coding with the very verbose, descriptive method names of Objective C. The type of functions that I have to write can have fairly complex arguments and I find that with the Objective C approach I'm not having to constantly refer back to other pieces of dicumentation to make sure I'm using the right arguments with the right functions.

Is there any way of using the Objective C style for calling functions with Python? I am aware this probably doesn't suit recommended coding styles for Python, but it does suit what I am doing right now so I'd like to try and find a way of doing it if possible.

1 Answer 1

4

If you mean, "can I write the call with square brackets instead of round ones and put them around the object and method names instead of after and omit the commas", then no.

If you mean "can I make verbose, descriptive method names", then of course you can; you can do that in any language worth mentioning.

I think what you really mean is "can I use keyword arguments as in [myObject frobnicateWithHax:42 Foo:23 Bar:69]?". Yes; in Python, this is spelled myObject.frobnicateWith(hax=42, foo=23, bar=69). On the function-definition side, there are a number of ways to make it work, depending on exactly what you want; see the documentation (or a good reference or tutorial) for default arguments and kwargs.

Honestly, Google answers this kind of question better than SO, once you know a little bit about what these kinds of language features are called.

Sign up to request clarification or add additional context in comments.

3 Comments

@Rudy See this question
Note that in Python you'd almost certainly drop the With in the name, and just call my_object.frobnicate(hax=42, foo=23, bar=69). Note that your function definition doesn't need to use defaults or kwargs -- just the names are enough, for example: def frobnicate(self, hax, foo, bar): ...
I mentioned Google for a reason... try 'python kwargs' and see what you get. @ben this is all true, at least assuming you don't want to force the caller to specify the names. :) Which wouldn't be very Pythonic :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.