473,769 Members | 6,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2255
"agent-s" <sh*******@gmai l.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...@gmai l.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...@lexic on.netwrote:
On Feb 14, 4:15 pm, "agent-s" <shanek...@gmai l.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...@gmai l.comwrote:
On Feb 13, 9:37 pm, "John Machin" <sjmac...@lexic on.netwrote:
On Feb 14, 4:15 pm, "agent-s" <shanek...@gmai l.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******@lexic on.netwrote in message
news:11******** **************@ q2g2000cwa.goog legroups.com...

| On Feb 14, 5:45 pm, "agent-s" <shanek...@gmai l.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******@lexic on.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.e duwrote:
"John Machin" <sjmac...@lexic on.netwrote in message

news:11******** **************@ q2g2000cwa.goog legroups.com...

| On Feb 14, 5:45 pm, "agent-s" <shanek...@gmai l.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 "enlightenm ent" 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 "enlightenm ent" 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'.startswit h('K')
False


Feb 14 '07 #10

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

Similar topics

5
4489
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 <function func at 0x00DC6EB0>
10
3691
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. Andrew dalke@dalkescientific.com
22
1954
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 understand best (i.e. C returns non-zero as true, and zero as false), is there anything I should be aware of given Python's different approach? Namely any pitfalls or neat tricks that make the Python approach cool or save my butt. Thank you!
77
3952
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 reStructuredText source as it is today. Please discuss it here so I can see what issues people may have.
5
6776
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 cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9997
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5309
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.