没有括号调用函数! [英] Calling Function Without Parentheses!
问题描述
多么糟糕的调试噩梦!我只是花了两个小时来运行我的脚本通过
调试器,在日志语句中填写等等,跟踪我的问题。
我调用了一个没有结束括号的函数。我确定希望
当我尝试执行以下操作时,Python会捕获它:
MyFunc
而不是:
MyFunc()
aaaaaaaaaaaa。
< blockquote>
Kamilche>我调用了一个没有结束括号的函数。我确定
Kamilche>当我尝试执行以下操作时,WISH Python会捕获它:
Kamilche> MyFunc
Kamilche>而不是:
Kamilche> MyFunc()
Google for pychecker。
Skip
Kamilche写道:什么是调试噩梦!我只是花了两个小时来运行我的脚本通过调试器,在日志语句中等等,跟踪
我的问题。
我调用了一个没有结束括号的函数。当我尝试执行以下操作时,我确实会想要使用Python来捕获它:
MyFunc
而不是:
MyFunc()
你是前Pascal程序员,不是吗? ;-)
在Python中,它不是错误,因为你可以做以下事情:
def simpson(f,a,b):
...." Simpson'对[a,b]上f的积分的规则近似。 ;
....返回(b - a)*(f(a)+ 4 * f((a + b)/ 2.0)+ f(b))/ 6.0
.... simpson(math.sin,0.0,math.pi)#注意,math.sin是一个函数
2.0943951023931953
Kamilche写道:多么糟糕的调试噩梦!我只是花了两个小时来运行我的脚本通过调试器,在日志语句中等等,跟踪
我的问题。
我调用了一个没有结束括号的函数。当我尝试执行以下操作时,我确实会想要使用Python来捕获它:
MyFunc
而不是:
MyFunc()
aaaaaaaaaaa。
Aaaaaaaaaaa确实如此。您必须使用极其旧版本的
pychecker。我在Python22目录中的版本给出了与当前版本相同的
结果;见下文。
C:\ junk>输入noparens.py
[bangs插入以击败谷歌的lstrip()
!def bar():
! foo
!def foo():
! alist = []
! alist.sort
C:\ junk> pychecker noparens.py
C:\ junk> c:\ python24 \ python.exe
c:\ python22 \Lib\site-packages \ pychecker \ checker.py noparens.py
处理noparens ...
警告......
noparens.py:2:声明似乎没有效果
noparens.py:5 :声明似乎没有效果
What a debug nightmare! I just spent HOURS running my script through
the debugger, sprinkling in log statements, and the like, tracking down
my problem.
I called a function without the ending parentheses. I sure do WISH
Python would trap it when I try to do the following:
MyFunc
instead of:
MyFunc()
aaaaaaaaaaaah.
Kamilche> I called a function without the ending parentheses. I sure do
Kamilche> WISH Python would trap it when I try to do the following:
Kamilche> MyFunc
Kamilche> instead of:
Kamilche> MyFunc()
Google for pychecker.
Skip
Kamilche wrote:What a debug nightmare! I just spent HOURS running my script through
the debugger, sprinkling in log statements, and the like, tracking down my problem.
I called a function without the ending parentheses. I sure do WISH
Python would trap it when I try to do the following:
MyFunc
instead of:
MyFunc()
You''re a former Pascal programmer, aren''t you? ;-)
In Python, it''s not an error, because you can do things like:
def simpson(f, a, b): .... "Simpson''s Rule approximation of the integral of f on [a, b]."
.... return (b - a) * (f(a) + 4 * f((a + b) / 2.0) + f(b)) / 6.0
.... simpson(math.sin, 0.0, math.pi) # Note that math.sin is a function
2.0943951023931953
Kamilche wrote:What a debug nightmare! I just spent HOURS running my script through
the debugger, sprinkling in log statements, and the like, tracking down my problem.
I called a function without the ending parentheses. I sure do WISH
Python would trap it when I try to do the following:
MyFunc
instead of:
MyFunc()
aaaaaaaaaaaah.
Aaaaaaaaaaaah indeed. You must be using an extremely old version of
pychecker. The version I have in my Python22 directory gave the same
results as the current one; see below.
C:\junk>type noparens.py
[bangs inserted to defeat Google''s lstrip()
!def bar():
! foo
!def foo():
! alist = []
! alist.sort
C:\junk>pychecker noparens.py
C:\junk>c:\python24\python.exe
c:\python22\Lib\site-packages\pychecker\checker.py noparens.py
Processing noparens...
Warnings...
noparens.py:2: Statement appears to have no effect
noparens.py:5: Statement appears to have no effect
这篇关于没有括号调用函数!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!