473,385 Members | 1,465 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,385 software developers and data experts.

return None

Can I do a function which don't return anything?

The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing

Thanks
Jul 22 '05 #1
12 3564
Ximo wrote:
Can I do a function which don't return anything?

The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing


When you execute the statement

a = myfunction()

What do you want to be in a, if not None?
--
Michael Hoffman
Jul 22 '05 #2
Ximo wrote:
Can I do a function which don't return anything?

The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing


Nothing is None, or isnt?

You probably print the function, what you neednt, of course. You can just call it:

def x():
pass

print x() # calling with printing
x() # calling only

x() prints really nothing, even not None ;-)
--
geon
Vyjímka je pravidlo. Rekurzivní.
Jul 22 '05 #3
In article <3k************@individual.net>, Ximo <el*****@yahoo.es> wrote:
Can I do a function which don't return anything?

The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing


What do you mean by "don't return anything", as oppossed to returning
None? Let's say I had one of those functions, and did:

foo = noReturnValue()
print foo

what would you expect (want?) to happen?
Jul 22 '05 #4
On 2005-07-22, Roy Smith <ro*@panix.com> wrote:
In article <3k************@individual.net>, Ximo <el*****@yahoo.es> wrote:
Can I do a function which don't return anything?

The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing


What do you mean by "don't return anything", as oppossed to returning
None? Let's say I had one of those functions, and did:

foo = noReturnValue()
print foo

what would you expect (want?) to happen?


One supposes that if noReturnValue() really didn't return
anything, then the above code would cause an exception.

Personally, I don't really like the idea that falling off the
botton of a function implicitly returns None. It's just not
explicit enough for me. My preference would be that if the
function didn't execute a "return" statement, then it didn't
return anyting and attempting to use a return value would be an
error.

I suppose there probably is code out there that depends on the
implicit "return None" at the end of every function, so it's
too late to change things now.

--
Grant Edwards grante Yow! Is it FUN to be
at a MIDGET?
visi.com
Jul 22 '05 #5
On Fri, Jul 22, 2005 at 07:40:00PM +0200, Ximo wrote:
Can I do a function which don't return anything?

The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing

Define nothing :)
None is the representation of nothing in Python ;)

Andreas
Jul 22 '05 #6

"Ximo" <el*****@yahoo.es> wrote in message
news:3k************@individual.net...
Can I do a function which don't return anything?
No, if you mean like subroutines.
The question is that, if I do a function that have a return or without
return, it returns always "None", but i want that it doesnt return me
nothing


Why? An answer to that would help you maybe get better answers here.

Terry J. Reedy

Jul 23 '05 #7
Grant Edwards wrote:
[snip..]
Personally, I don't really like the idea that falling off the
botton of a function implicitly returns None. It's just not
explicit enough for me. My preference would be that if the
function didn't execute a "return" statement, then it didn't
return anyting and attempting to use a return value would be an
error.

I suppose there probably is code out there that depends on the
implicit "return None" at the end of every function, so it's
too late to change things now.

Yeah - I frequently rely on that behaviour, but purely our of laziness.

Best Regards,

Fuzzy
http://www.voidspace.org.uk/python

--
Grant Edwards grante Yow! Is it FUN to be
at a MIDGET?
visi.com


Jul 23 '05 #8
Grant Edwards wrote:
Personally, I don't really like the idea that falling off the
botton of a function implicitly returns None. It's just not
explicit enough for me. My preference would be that if the
function didn't execute a "return" statement, then it didn't
return anyting and attempting to use a return value would be an
error.


That's not a bad idea. I tend to prefer self-documenting code whenever
possible anyway, so if I a method ends that I don't intend to have a
useful return value, I don't have a return statement with an argument,
and if I intend a method that returns a useful value to return one that
might be None, I do so expliclitly, rather than having the logic fall
off the end of the function, making it unclear what was intended in the
first place.

--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Grab a club and join the chorus / Evolution is a state of mind
-- Oleta Adams
Jul 23 '05 #9
Grant Edwards wrote:
Personally, I don't really like the idea that falling off the
botton of a function implicitly returns None. It's just not
explicit enough for me. My preference would be that if the
function didn't execute a "return" statement, then it didn't
return anyting and attempting to use a return value would be an
error.


This is a bad idea. Classically, distinguishing between functions that
return things and functions that don't return things explicitly divides
the "callable object" space. From my CS101 class with its incredibly
exciting dive into the world of useless pseudocode, callables that
returned things were called 'functions' and callables that didn't were
called 'procedures'.

Some languages do make this distinction; QBASIC, for example, had
'gosub' separate from function calls.

What do you do for an early break from a function that still returns
not-even-None [ReallyNone], "return?" That looks and acts like a 'real'
return statement, and the distinction between
return-without-a-value-so-maybe-except and return-with-a-value is
suddenly magnified to real importance.

Further, and I consider this a truly damning case, look at decorater. A
naive "logging" decorator could be defined like this:

def logger(func):
def new_func(*args, **kwargs):
print '%s called with:' % func.__name__, args, kwargs
retval = func(*args,**kwargs)
print '%s returns:', retval
return retval
return new_func

This logger works without modification for both value and non-value
returning functions. Its output isn't quite as pretty for non-value
functions, but it works and the implementation is both simple and flexible.

With a function-schism, to keep its simple implementation 'logger' would
have to be rewritten as 'flogger' (same as current-logger, for use on
functions), and 'plogger' (for use on procedures). The downside here is
that if the function/method changed to or from a procedure, the
decorator would have to be switched.

Alternatively, the logger decorator could be longer and explicitly catch
the possible exception. But why should we have to write like that, for
a use-case that doesn't even represent a true error -- arguably not even
an exceptional case? Python's definitely not a B&D language, talk of
floggers aside.
Jul 24 '05 #10
Christopher Subich wrote:
print '%s returns:', retval

Not that it matters, but this line should be:
print '%s returns:' % func.__name__, retval
Jul 24 '05 #11
geon wrote:
Ximo wrote:
Can I do a function which don't return anything?

Nothing is None, or isnt?


A woodman was carrying a sack full of chopped wood on his back. His
sack was heavy and filled beyond its limit. The man, bent under his
bulky burden, was struggling not to drop any of the wood pieces as he
walked. However, the poor man couldn't avoid tripping over a stone on
the road and half of his load fell out of their precarious pile.
Another man happened to be passing by and saw the mishap.

`If I load those fallen pieces of wood back into your back sack, what
would you give me?' he asked.

`Nothing.' said the man carrying the wood.

`That's acceptable.' agreed the other man. He collected all the chopped
wood scattered on the road and crammed them back into the sack of the
woodman. When done, he asked for his payment. The woodman was baffled.

`I told you, I would give you nothing.' he said.

`Yes. And that's what I want. Nothing.' said the other, `Give me my
nothing!'

After some quarrel, the two men decided to let the qadi solve their
problem. Nasreddin Hodja was on duty at the time. He listened to both
men earnestly. Then he addressed the man who was expecting his payment
of nothing.

`My dear fellow, could you please lift the far right corner of that rug
on the floor and check what is underneath?' The man did as he was told
and looked under the rug.

`What do you see?' asked the Hodja.

`Nothing.' said the man.

'Well, there's your payment.' said the Hodja. 'Take it and go!'

--
John.

Jul 24 '05 #12
Repton wrote:
'Well, there's your payment.' said the Hodja. 'Take it and go!'


+1: the koan of None

"Upon hearing that, the man was enlightened."
Jul 25 '05 #13

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

Similar topics

1
by: Tung Wai Yip | last post by:
I've build the following utility. It works so far but I want to make sure I'm doing the right thing. I am running Python 2.3 on windows 2000. def execute(cmd): """ execute cmd in sub-process,...
47
by: Martin DeMello | last post by:
It seems to be a fairly common pattern for an object-modifying method to return None - however, this is often quite inconvenient. For instance def f(lst1, lst2): g((lst1 + lst2).reverse()) #...
6
by: mhenry1384 | last post by:
On WinXP, I am doing this nant.exe | python MyFilter.py This command always returns 0 (success) because MyFilter.py always succeeds. MyFilter.py looks like this while 1:
38
by: yomgui | last post by:
hello, is it legal to return inside a for loop or am I obliged to break out of the loop before returning ? thanks yomgui
11
by: ankyhe | last post by:
L = L=L.sort() L will refer to None, why L.sort() don't return the L? I want to ask why the designer of Python do so?
4
by: yaru22 | last post by:
In one of the examples in the book I'm reading, it says: def __init__(self): ... ... ... return It has nothing after "return". I expected it to have some number like 0 or 1.
3
by: Steven W. Orr | last post by:
When I go to create an object I want to be able to decide whether the object is valid or not in __init__, and if not, I want the constructor to return something other than an object, (like maybe...
13
by: Andrew | last post by:
Hi I was wondering if there is anyway with XML RPC to send a string of text from the server to the client with out calling return thus breaking my loop for example def somefunc(): for...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...

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.