python中空格用什么表示_Python:在函数名称中使用空格?

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----------------------------------------

解决方案

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值