pythonfunction

Python: Use spaces in a function name?


I am writing a python scripts to call a function.

Normally function are called:

def myCall():
    print "Hello World"

But I would like to name/use the function as:

def my Call():
    print "I did it!"

I knew the world will start thinking why the programmer name the function this ways. Just replace the "space" with "under score" or something else! Hm... but that's not how I want the script to work.

Any suggestion to call the function with "space"?

-------------------------------------------ADD-ON----------------------------------------

Ok guys! I am going to explain how my script works. Specifically why I use space in a function name. There are a lot of curosity in this page, thus I place this add-on to explain why I did it.

I hope this will help everyone understand why I did this :)

Cheer with Respect!

E.g.

===============
Welcome Menu
===============
1. Option 1
2. Option 2
3. Option 3
4. Option 4

I have a user main menu and the main will constantly update every to check before it display the options above

array = ["Option 1", "Option 2", "Option 3", "Option 4"]

The checking are done because when some variable (declare in front the script) are missing, the specific option confirm would not work.

E.g.

for x in range(a) 
    print "Menu Option

I place my menu in a loop (Meaning print once only), The counting of the number in the menu are separated from the string option are auto increment each when there is 1 more element in the array to print the counting. The Option variable are place in the array.

The user will select what he/she want in the options. Let said the user select "Option 1", it will goes to the array (array = ["Option 1", "Option 2", "Option 3", "Option 4"]) to check which position.

Remember the array are not FIXED!!! It change depend on the variable declare in the front of the script.

All vaildation are done to prevent errors, crash, etc!

Finally, I have write a function (with space)

And in the loop, it will call the function (with space). The function will need to link back to the array to change.

-------------------------------------------ADD-ON----------------------------------------


Solution

  • Do you need to call it in the conventional way?

    Here's a function name with spaces (and punctuation!)

    >>> def _func():
        print "YOOOO"
    
    
    >>> globals()['Da func name!!1'] = _func
    
    >>> globals()['Da func name!!1']()
    YOOOO