473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

None

Hi NG

def executer(func, para):
func(para)

def foo():
print "function without parameter"

def bar(a):
print "function with 1 parameter"
print a

#executer(foo, None) #error

executer(bar, 100)

print type(foo)
print type(bar)
#seem to have the same type, though one takes parameter and the other doesnt
does this mean that None *is* a value
some special value to show that variable cant be initialized with more
appreciate value
at this stage?

is there a way to allow parameterless functions as parameter in executer?

--
Daniel
Jul 18 '05 #1
4 2376

"Daniel Schüle" <fo************@yahoo.de> wrote in message
news:bo**********@news.rz.uni-karlsruhe.de...
Hi NG

def executer(func, para):
func(para)

def foo():
print "function without parameter"

def bar(a):
print "function with 1 parameter"
print a

#executer(foo, None) #error

executer(bar, 100)

print type(foo)
print type(bar)
#seem to have the same type, though one takes parameter and the other doesnt

does this mean that None *is* a value
some special value to show that variable cant be initialized with more
appreciate value at this stage?
None is an object like any other object in Python. It's conventional
uses are as a return value from functions that don't return a value,
and as an initial value for optional function parameters. These are
conventional; they are not mandated by the language (except that
the return statement without parameters does return None.)
is there a way to allow parameterless functions as parameter in executer?
I'm not sure what you mean by this question. Functions are first class
objects, so you can, of course, pass them to other functions. There
are numerous examples in the standard library of methods which
take functions as a parameter. Look at, for example, the map(),
reduce() and filter() built-in functions, and also at the .sort() method
of lists.

John Roth
--
Daniel

Jul 18 '05 #2
Daniel Schüle wrote:

def executer(func, para):
func(para)

def foo():
print "function without parameter"

def bar(a):
print "function with 1 parameter"
print a

#executer(foo, None) #error

executer(bar, 100)
[...]
is there a way to allow parameterless functions as parameter in executer?


You can change executer() to accept and pass and arbitrary number of
arguments:

def executer(func, *args):
func(*args)

executer(bar, 100)
executer(foo)

However, excecuter(foo, None) will still fail. See
http://www.python.org/doc/current/tut/node6.html for the details.

As an aside, do the newsgroup - and yourself - a favour and increase your
block indent to 4 spaces.

Peter
Jul 18 '05 #3
> def executer(func, para):
func(para)

def foo():
print "function without parameter"
How about:

def foo(arg=None):
if arg is not None:
raise TypeError
print "function without parameter"

def bar(a):
print "function with 1 parameter"
print a

#executer(foo, None) #error

executer(bar, 100)

print type(foo)
print type(bar)
#seem to have the same type, though one takes parameter and the other doesnt
does this mean that None *is* a value
some special value to show that variable cant be initialized with more
appreciate value
at this stage?

is there a way to allow parameterless functions as parameter in executer?

I sometimes run in to this situation when creating callback functions.
What if I want to call the function standalone, and not as a callback?

I just use this trick and set the extra parameters to default to None.

Jul 18 '05 #4
thank you all for answears
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: M-a-S | last post by:
Can anybody explain this: Python 2.3 (#46, Jul 29 2003, 18:54:32) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> >>> None = 3 <stdin>:1: SyntaxWarning:...
28
by: The Eternal Squire | last post by:
PEP: 336 Title: Make None Callable Version: $Revision: 1.1 $ Last-Modified: $Date: 2004/11/03 16:58:30 $ Author: Andrew McClelland Status: Draft Type: Standards Track Content-Type: text/plain...
6
by: Leif K-Brooks | last post by:
In Python 2.4, although None can't be directly assigned to, globals() can still be; however, that won't change the value of the expression "None" in ordinary statements. Except with the eval...
35
by: Steven Bethard | last post by:
I have lists containing values that are all either True, False or None, e.g.: etc. For a given list: * If all values are None, the function should return None.
16
by: gaudetteje | last post by:
I just read in the 'What's New in Python 2.4' document that the None data type was converted to a constant: http://python.org/doc/2.4/whatsnew/node15.html """ # None is now a constant; code...
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
2
by: spifster | last post by:
Hello all, I am building a collapsable tree using Javascript with DOM in IE. In order to make collapsed cells disappear I have been hiding the text. The cells collapse but still leave borders...
8
by: micklee74 | last post by:
hi i wish to map None or "None" values to "". eg a = None b = None c = "None" map( <something> , if i in ("None",None) ]) I can't seem to find a way to put all values to "". Can anyone...
18
by: Alan G Isaac | last post by:
>>None >= 0 False True Explanation appreciated. Thanks, Alan Isaac
15
by: cssExp | last post by:
hello, Rather than going on a wild explanation on what's the the problem, it'll be much quicker and easier if i let you look at it yourself, so I'll post my page source (actual contents taken out,...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.