473,574 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

test for None

How do you test for a function that returns nothing, and why doesn't
this work? Shouldn't X have to be either None or not?
x = None
for x in []:

.... if x is None:
.... print "X is None"
.... else:
.... print "X is not None"
....

Thanks,

rick

Apr 19 '06 #1
4 1893
BartlebyScriven er wrote:
How do you test for a function that returns nothing, and why doesn't
this work? Shouldn't X have to be either None or not?
x = None
for x in []: ... if x is None:
... print "X is None"
... else:
... print "X is not None"
...


No, because you're iterating over an empty list, which does nothing:
for x in []: print 'hi' ....


--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
The doors of Heaven and Hell are adjacent and identical.
-- Nikos Kazantzakis
Apr 19 '06 #2
I think I was trying for something like this, where the intervening for
iterates over a function that may or may not produce nothing:
x = None
for x in []: print x
if x is None:

print "x is still none because nothing happened"

Thanks,

rick

Apr 19 '06 #3
"BartlebyScrive ner" <rp*******@gmai l.com> writes:
How do you test for a function that returns nothing,
A function returns a single value (which may be a container for other
values). By default, with no 'return' statement, it returns the None
object.

What is it you're trying to do?
and why doesn't
this work? Shouldn't X have to be either None or not?


Yes.
x = None
Assigns the name 'x' to the None object.
for x in []:


Iterates over an empty list, which results in zero iterations;
i.e. does nothing.

Have you followed the tutorial through, running and understanding each
example, to get the basics of Python covered?

<URL:http://docs.python.org/tut/>

--
\ "I was trying to daydream, but my mind kept wandering." -- |
`\ Steven Wright |
_o__) |
Ben Finney

Apr 19 '06 #4
>> Have you followed the tutorial through, running and understanding each
example, to get the basics of Python covered?


Could be high time to try that again. At first it was way too much, so
I've been doing Dive Into Python and some others. But I will try the
Tutorial again, at least up to classes. Then I'm sure I'll have to
return to the books.

Thanks for your patience.

rick

Apr 19 '06 #5

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

Similar topics

1
1477
by: elmlish | last post by:
Hello all, I'm currently befuddled as to how to efficiently test for a positive re. match then use the results of that match in a function. Mostly what I've seen people do is to first test for the match, and then try matching again to get the results. This would seem to be pretty inefficient to me. I've tried making the match, then...
12
4040
by: Kamilche | last post by:
I was looking for a way to speed up detecting invalid characters in my TCP string, and thought of yet another use for the translate function! If you were to 'translate out' the bad characters, and compare string lengths afterwards, you would know whether or not the line contained invalid characters. The new method is more than 10x faster than...
0
2031
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally TestCase.skipIf(expr, msg): skips if expr is true These can be called either in setUp() or in the test methods. I also added reporting of skipped tests to...
18
1850
by: alex | last post by:
Hi there, how can I check if a variable is a structure (i.e. a list)? For my special problem the variable is either a character string OR a list of character strings line So how can I test if a variable 'a' is either a single character string or a list? I tried: if a is list:
0
2285
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** Invalid arguments to divll. at test_eng/Testout.pm line 30. ...propagated at t/polyser.t line 9. t/polyser.....dubious
6
2684
by: Ben Finney | last post by:
Howdy all, Summary: I'm looking for idioms in unit tests for factoring out repetitive iteration over test data. I explain my current practice, and why it's unsatisfactory. When following test-driven development, writing tests and then coding to satisfy them, I'll start with some of the simple tests for a class.
5
3542
by: Sakcee | last post by:
Hi I am trying to use pyUnit to create a framework for testing functions I am reading function name, expected output, from a text file. and in python generating dynamic test functions something like this class getUsStatesTest( unittest.TestCase ):
2
2417
by: Netkiller | last post by:
#!/usr/bin/python # -*- coding: utf-8 -*- """ Project: Network News Transport Protocol Server Program Description: 基于数据库的新闻组,实现BBS前端使用NNTP协议来访问贴子 Reference: NNTP协议: http://www.mibsoftware.com/userkt/0099.htm 正则表达式:...
2
2683
by: Pierre Rouleau | last post by:
Hi all, I have a consistent test case where os.popen3() hangs in Windows. The system hangs when retrieving the lines from the child process stdout. I know there were several reports related to os.popen3() hanging under Windows in this group before. I stumbled on a case where a piece of code works in some occasions and hangs consistently...
2
297
by: karoly.kiripolszky | last post by:
in my server i use the following piece of code: ims = self.headers if ims != None: t = int(ims) and i'm always getting the following error: t = int(ims) ValueError: invalid literal for int(): None
0
8044
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. ...
0
8230
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...
1
7810
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...
0
8096
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6451
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3739
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...
1
2240
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1337
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1056
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.