473,396 Members | 1,770 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.

python not returning true

I have a function, generally described as so:

def function(args):
if condition:
if condition2:
function(args+1)
elif condition3:
print "text"
return True
else:
return False

which is used in:

if function(args):
print "ok"
so here basically "text" will print out when condition3 is true but it
will not print out "ok" when condition3 is true. When it's true it
should print out borth "text" and "ok"

Feb 14 '07 #1
13 2225
"agent-s" <sh*******@gmail.comwrites:
I have a function, generally described as so:

def function(args):
if condition:
if condition2:
function(args+1)
elif condition3:
print "text"
return True
else:
return False
You've simplified this, presumably to make the code more
clear. Unfortunately what remains isn't executable, so we can't see
the behaviour that confuses you.

Please write a minimal example that demonstrates the behaviour you
want explained.

--
\ "I doubt, therefore I might be." -- Anonymous |
`\ |
_o__) |
Ben Finney

Feb 14 '07 #2
On Feb 14, 4:15 pm, "agent-s" <shanek...@gmail.comwrote:
I have a function, generally described as so:
def function(args):
if condition:
if condition2:
function(args+1)
return None
elif condition3:
print "text"
return True
else:
return False
else:
return None

There are two cases, indicated above, where you don't explicitly do a
"return", so you fall off the end of the function, and Python returns
None.

Then when the function's caller tests the returned value, None is
treated as logically false.
which is used in:

if function(args):
print "ok"

so here basically "text" will print out when condition3 is true but it
will not print out "ok" when condition3 is true. When it's true it
should print out borth "text" and "ok"
In the second last sentence, it is difficult to determine what you
think is expected behaviour and what you say is the actual behaviour.
In the last sentence, what does the first "it" refer to?

If the knowledge about returning None doesn't help you, try some
standard(??) techniques like inserting print statements or debugger
break-points.

HTH,
John

Feb 14 '07 #3
On Tue, 13 Feb 2007 21:15:19 -0800, agent-s wrote:
I have a function, generally described as so:
[snip function]
which is used in:

if function(args):
print "ok"

so here basically "text" will print out when condition3 is true but it
will not print out "ok" when condition3 is true. When it's true it
should print out borth "text" and "ok"
Thank you for sharing. Do you have an actual question?


--
Steven D'Aprano

Feb 14 '07 #4
On Feb 13, 9:37 pm, "John Machin" <sjmac...@lexicon.netwrote:
On Feb 14, 4:15 pm, "agent-s" <shanek...@gmail.comwrote:
I have a function, generally described as so:
def function(args):
if condition:
if condition2:
function(args+1)

return None elif condition3:
print "text"
return True
else:
return False

else:
return None

There are two cases, indicated above, where you don't explicitly do a
"return", so you fall off the end of the function, and Python returns
None.

Then when the function's caller tests the returned value, None is
treated as logically false.
which is used in:
if function(args):
print "ok"
so here basically "text" will print out when condition3 is true but it
will not print out "ok" when condition3 is true. When it's true it
should print out borth "text" and "ok"

In the second last sentence, it is difficult to determine what you
think is expected behaviour and what you say is the actual behaviour.
In the last sentence, what does the first "it" refer to?

If the knowledge about returning None doesn't help you, try some
standard(??) techniques like inserting print statements or debugger
break-points.

HTH,
John
Thanks! That was exactly what it was. I solved it by using "return
function(args+1)" instead of simply "function(args+1)."

btw Steven you are so witty I hope to one day pwn noobs on newsgroups
too.

Feb 14 '07 #5
On Feb 14, 5:45 pm, "agent-s" <shanek...@gmail.comwrote:
On Feb 13, 9:37 pm, "John Machin" <sjmac...@lexicon.netwrote:
On Feb 14, 4:15 pm, "agent-s" <shanek...@gmail.comwrote:
I have a function, generally described as so:
def function(args):
if condition:
if condition2:
function(args+1)
return None elif condition3:
print "text"
return True
else:
return False
else:
return None
There are two cases, indicated above, where you don't explicitly do a
"return", so you fall off the end of the function, and Python returns
None.
Then when the function's caller tests the returned value, None is
treated as logically false.
which is used in:
if function(args):
print "ok"
so here basically "text" will print out when condition3 is true but it
will not print out "ok" when condition3 is true. When it's true it
should print out borth "text" and "ok"
In the second last sentence, it is difficult to determine what you
think is expected behaviour and what you say is the actual behaviour.
In the last sentence, what does the first "it" refer to?
If the knowledge about returning None doesn't help you, try some
standard(??) techniques like inserting print statements or debugger
break-points.
HTH,
John

Thanks! That was exactly what it was. I solved it by using "return
function(args+1)" instead of simply "function(args+1)."
That takes care of only 1 of the two cases of returning None instead
of True/False.
>
btw Steven you are so witty I hope to one day pwn noobs on newsgroups
too.
Wit has nothing to do with it. The fact that you are a Python noob is
also irrelevant. Your problem statement was unintelligible, as is your
response. What does "pwn" mean?

Feb 14 '07 #6

"John Machin" <sj******@lexicon.netwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...

| On Feb 14, 5:45 pm, "agent-s" <shanek...@gmail.comwrote:
| btw Steven you are so witty I hope to one day pwn noobs on newsgroups
| too.

Sorry, but you are 'pwning' yourself here ;-)

| Wit has nothing to do with it. The fact that you are a Python noob is
| also irrelevant. Your problem statement was unintelligible, as is your
| response. What does "pwn" mean?

I believe that it is a misspelling of 'own' used by pvp (person versus
person, as opposed to person versus monster) gamers to demonstrate their
in-ness. But perhaps agent-s can enlightenment us further.

Terry Jan Reedy (occasional, non-elite gamer)

Feb 14 '07 #7
"John Machin" <sj******@lexicon.netwrites:
What does "pwn" mean?
http://en.wikipedia.org/wiki/Pwn
Feb 14 '07 #8
On Feb 14, 7:02 pm, "Terry Reedy" <tjre...@udel.eduwrote:
"John Machin" <sjmac...@lexicon.netwrote in message

news:11**********************@q2g2000cwa.googlegro ups.com...

| On Feb 14, 5:45 pm, "agent-s" <shanek...@gmail.comwrote:
| btw Steven you are so witty I hope to one day pwn noobs on newsgroups
| too.

Sorry, but you are 'pwning' yourself here ;-)
And the referent of "you" would be .....?
>
| Wit has nothing to do with it. The fact that you are a Python noob is
| also irrelevant. Your problem statement was unintelligible, as is your
| response. What does "pwn" mean?

I believe that it is a misspelling of 'own' used by pvp (person versus
person, as opposed to person versus monster) gamers to demonstrate their
in-ness. But perhaps agent-s can enlightenment us further.
So "enlightenment" has been verbed, has it? I didn't realise that the
language had been transitioned so far :-)

Cheers,
John

Feb 14 '07 #9

On Feb 14, 2007, at 3:08 AM, John Machin wrote:
So "enlightenment" has been verbed, has it? I didn't realise that the
language had been transitioned so far :-)
*ALL* nouns may be verbed ;-)

-michael
---
# Something just doesn't seem right in those
# "Every kiss begins with 'K'" commercials.
>>'Every Kiss'.startswith('K')
False


Feb 14 '07 #10
Michael Bentley <rm****@gmail.comwrites:
# Something just doesn't seem right in those
# "Every kiss begins with 'K'" commercials.
>'Every Kiss'.startswith('K')
False
>>kisses = ["kiss", "kiss", "kiss", "kiss", "kiss"]
kisses == [kiss for kiss in kisses
... if kiss.startswith("k")]
True

Happy St. Valentine's Day, everyone.

--
\ "Experience is that marvelous thing that enables you to |
`\ recognize a mistake when you make it again." -- Franklin P. |
_o__) Jones |
Ben Finney

Feb 14 '07 #11
On 2007-02-14, Terry Reedy <tj*****@udel.eduwrote:
>| Wit has nothing to do with it. The fact that you are a Python noob is
| also irrelevant. Your problem statement was unintelligible, as is your
| response. What does "pwn" mean?

I believe that it is a misspelling of 'own' used by pvp (person versus
person, as opposed to person versus monster) gamers to demonstrate their
in-ness. But perhaps agent-s can enlightenment us further.
Mis-spelling things is witty now? Wow. I've been witty all
these years and didn't even know it...

--
Grant Edwards grante Yow! I'm EXCITED!! I want
at a FLANK STEAK WEEK-END!! I
visi.com think I'm JULIA CHILD!!
Feb 14 '07 #12

"John Machin" <sj******@lexicon.netwrote in message
news:11*********************@l53g2000cwa.googlegro ups.com...
|| | On Feb 14, 5:45 pm, "agent-s" <shanek...@gmail.comwrote:
| | btw Steven you are so witty I hope to one day pwn noobs on
newsgroups
| | too.
| >
| Sorry, but you are 'pwning' yourself here ;-)
|
| And the referent of "you" would be .....?

agent-s, as I though was obvious.

Feb 15 '07 #13
Wow. I didn't realize you guys took this so seriously.

Feb 23 '07 #14

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

Similar topics

5
by: Eric | last post by:
The following example will explain what i want to do: >>> def func(): print "true" >>> rules=(func,) >>> for rule in rules: rule I expect the final function to print true, but instead i have...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
22
by: James H. | last post by:
Greetings! I'm new to Python and am struggling a little with "and" and "or" logic in Python. Since Python always ends up returning a value and this is a little different from C, the language I...
77
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.