RE: Context without manager

2023-11-27 Thread David Raymond via Python-list
> I *must* do: > > with device_open() as device: >device.do_something() > > Nevertheless, I _need_ to have a class > where the device is opened in the __init__() > and used in some methods. > > Any ideas? Perhaps take a look at contextlib.ExitStack and see if you can do something with it.

RE: Initialising a Config class

2023-04-11 Thread David Raymond
Not sure if I'm fully understanding the question. But one option instead of making everything class attributes is to just define __getattr__ for when it doesn't find an attribute. Won't work for every single valid section and option name (because of spaces, name overlaps, etc) but should cover

RE: Problem with __sub__

2023-03-23 Thread David Raymond
I believe your problem is __rsub__, not __sub__. When you havethen that uses the "r" version of the operators. In your __rsub__ (used when you have - ) you instead return - which is backwards. Notice how the final return should also be -4,95 and not the +4,95 it's returning. > If on

RE: Debugging reason for python running unreasonably slow when adding numbers

2023-03-15 Thread David Raymond
> Then I'm very confused as to how things are being done, so I will shut > up. There's not enough information here to give performance advice > without actually being a subject-matter expert already. Short version: In this specific case "weights" is a 5,147 element list of floats, and "input" is

RE: Debugging reason for python running unreasonably slow when adding numbers

2023-03-15 Thread David Raymond
> Or use the sum() builtin rather than reduce(), which was > *deliberately* removed from the builtins. The fact that you can get > sum() without importing, but have to go and reach for functools to get > reduce(), is a hint that you probably shouldn't use reduce when sum > will work. Out of

RE: How to escape strings for re.finditer?

2023-02-28 Thread David Raymond
> I wrote my previous message before reading this.  Thank you for the test you > ran -- it answers the question of performance.  You show that re.finditer is > 30x faster, so that certainly recommends that over a simple loop, which > introduces looping overhead.  >>     def

RE: Find 6-letter words that are hidden (embedded) within

2023-02-24 Thread David Raymond
> Find 6-letter words that are hidden (embedded) within each row of letters. > The letters are in the correct order. > > 1. JSOYOMFUBELR > 2. SCDUARWDRLYE > 3. DASNAGEFERTY > 4. CLULOOTSCEHN > 5. USENEARSEYNE > The letters are in the correct order.

RE: Parallel(?) programming with python

2022-08-08 Thread David Raymond
>> But, an easier and often >> better option for concurrent data access is use a (relational) >> database, then the appropriate transaction isolation levels >> when reading and/or writing. >> > > That would obviusly save some coding (but would introduce the need to > code the interaction with the

Pip upgrade causing issues in 3.10

2022-07-19 Thread David Raymond
So after a long while I'm finally getting around to upgrading to 3.10 on Windows from 3.9, and my first pip upgrade is causing issues with the installation. Problem seems to be that I run pip from a command prompt in the Scripts folder, and it seems pip is trying to completely remove the

RE: Changing calling sequence

2022-05-12 Thread David Raymond
>>def TempsOneDay(*dateComponents): >>if len(dateComponents) == 3: >>year, month, date = dateComponents >>elif len(dateComponents) == 1 and isinstance(dateComponents[0], >> datetime.date): >>year, month, date = (dateComponents[0].year, dateComponents[0].month, >>

RE: Changing calling sequence

2022-05-11 Thread David Raymond
>> I have a function that I use to retrieve daily data from a >> home-brew database. Its calling sequence is; >> >> def TempsOneDay( year, month, date ): >> >> After using it (and its friends) for a few years, I've come to >> realize that there are times where it would be advantageous to >>

RE: One-liner to merge lists?

2022-02-22 Thread David Raymond
> Is there a simpler way? >>> d = {1: ['aaa', 'bbb', 'ccc'], 2: ['fff', 'ggg']} >>> [a for b in d.values() for a in b] ['aaa', 'bbb', 'ccc', 'fff', 'ggg'] >>> -- https://mail.python.org/mailman/listinfo/python-list

RE: frozenset can be altered by |=

2021-11-22 Thread David Raymond
>> (venv_3_10) marco@buzz:~$ python >> Python 3.10.0 (heads/3.10-dirty:f6e8b80d20, Nov 18 2021, 19:16:18) >> [GCC 10.1.1 20200718] on linux >> Type "help", "copyright", "credits" or "license" for more information. >> >>> a = frozenset((3, 4)) >> >>> a >> frozenset({3, 4}) >> >>> a |= {5,} >> >>> a

RE: on writing a while loop for rolling two dice

2021-08-30 Thread David Raymond
> def how_many_times(): > x, y = 0, 1 > c = 0 > while x != y: > c = c + 1 > x, y = roll() > return c, (x, y) Since I haven't seen it used in answers yet, here's another option using our new walrus operator def how_many_times(): roll_count = 1 while (rolls := roll())[0]

RE: How do you debug in Python? Coming from a Matlab and R user. I'm already aware of pdb.

2021-01-27 Thread David Raymond
In regards to the various comments about adding in print() calls what I've found myself doing is to basically always use the logging module, and use logging.debug() for those. Somewhere at the top of the script I'll have a line like... DEBUG = False ...and when initializing the handler to

RE: primitive password cracker

2021-01-07 Thread David Raymond
I think you might want to check out itertools.product() https://docs.python.org/3.9/library/itertools.html#itertools.product import itertools import string passe = 'pass' for p in itertools.product(string.ascii_lowercase, repeat = 4): p = "".join(p) if p == passe: print("Found

RE: Are there Python ways to execute queries on PostgreSQL without getting data over?

2020-10-19 Thread David Raymond
> Are there Python ways to execute queries on PostgreSQL without getting data > over? > > Are there ways just to fire off PostgreSQL queries and not get data into > Python? > > Regards, > > David What is your use case for this? Normally when you do basic things like an UPDATE/DELETE, etc

RE: [RELEASE] Python 3.8.6 is now available

2020-09-29 Thread David Raymond
> Python 3.8.6 is the sixth maintenance release of Python 3.8. Go get it here: > https://www.python.org/downloads/release/python-386/ > Just a quick note that there still seem to be a few places on the website which are still showing

RE: grouping and sorting within groups using another list

2020-09-02 Thread David Raymond
Would it be something as simple as: rows.sort(key = lambda x: (x[0], x[3], x[4], sort_list.index(x[6]))) -Original Message- From: Python-list On Behalf Of Larry Martell Sent: Wednesday, September 2, 2020 1:55 PM To: Python Subject: grouping and sorting within groups using another

RE: Didn't understand the output of the following Python 3 code with reduce function?

2020-08-28 Thread David Raymond
All the numbers in the nums list don't matter and aren't used. Only the first number, and how many there are. https://docs.python.org/3.8/library/functools.html#functools.reduce Basically it's doing ADDS(1, 2) which returns 2 that 2 gets fed back into ADDS(2, 3) which returns 3 that 3 gets fed

RE: Final statement from Steering Council on politically-charged commit messages

2020-08-18 Thread David Raymond
> Do I agree with the PR, not exactly. However, I do think we as a community > should be accommodating to people > Whose use of the English language differs from the standard as long as the > meaning is clear. Remember that the problem isn't the change in wording of the PEP. That's all well and

RE: Python Scripts

2020-07-21 Thread David Raymond
Remember to reply-all, so that python-list is included and can still see responses and offer help. If Python won't open them, then how do you know the scripts work? They work on someone else's computer you mean? Please provide the basics then so we can try to help out. What OS are you using?

RE: Python Scripts

2020-07-21 Thread David Raymond
> im having problems when running python scripts > > When running the scripts it always closes immediately If you're running it in Windows, and running it by double clicking on a .py file, then it will pop up a console window while it's running, and then immediately close that window when the

RE: how to let argument be optional falling back to certain integer

2020-06-22 Thread David Raymond
> This is true. I have written 0 as false in C so many times. But > clearly for me times have changed... I now look at numbers as a thing > in their own special class not to be confused as truth-values. (So much > so that I fell for this.) But I confess I still think of numbers as all >

RE: Is there anything in the script which could cause it to not run its full course please?

2020-05-04 Thread David Raymond
Not necessarily the cause of your problem, but if you're going to compare dates it should be as objects, or as text as year-month-day. Here you're comparing dates as text in day-month-year format. So January first comes before May 4th 2020 "01-01-" < "04-05-2020" ... 04-05-2020

RE: Multiprocessing queue sharing and python3.8

2020-04-06 Thread David Raymond
= mp.Pool(initializer = pool_init, initargs = (mp_comm_queue,)) ... -Original Message- From: David Raymond Sent: Monday, April 6, 2020 4:19 PM To: python-list@python.org Subject: RE: Multiprocessing queue sharing and python3.8 Attempting reply as much for my own understanding. Are you

RE: Multiprocessing queue sharing and python3.8

2020-04-06 Thread David Raymond
Attempting reply as much for my own understanding. Are you on Mac? I think this is the pertinent bit for you: Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See

RE: PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

2020-03-19 Thread David Raymond
For dictionaries it'd even be more useful: d = { 'first_name': 'Frances', 'last_name': 'Allen', 'email': 'fal...@ibm.com' } fname, lname = d[['first_name', 'last_name']] Why not do this? import operator first_last = operator.itemgetter("first_name",

RE: Please solve this problem

2020-03-09 Thread David Raymond
> It was a problem and it was solved. > Check the second or third e-mail in the thread. > > Thank you. The first email was blank, The second email was from the same person and just said "Rply if solved" The third was a sarcastic reply to the blank emails with just: "Solved, answer is:" The

RE: threading

2019-12-04 Thread David Raymond
100 increments happen very fast, and means each thread will probably complete before the main thread has even started the next one. Bump that up to 1_000_000 or so and you'll probably trigger it. I did a test with a print(x) at the start of test() to see what the number was when each thread

RE: How to delay until a next increment of time occurs ?

2019-11-13 Thread David Raymond
I just used .perf_counter() as it's "a clock with the highest available resolution to measure a short duration" The general simplified idea was run it whenever the time is 0 modulo your interval. So you ask how long until that next time. Run whenever the time is 0 modulo .0003 Current time is

RE: How to delay until a next increment of time occurs ?

2019-11-13 Thread David Raymond
Maybe something along the lines of this? timeInterval = 0.0003 time.sleep(timeInterval - (time.perf_counter() % timeInterval)) -Original Message- From: Python-list On Behalf Of R.Wieser Sent: Wednesday, November 13, 2019 11:12 AM To: python-list@python.org Subject: Re: How to delay

RE: Syntax Suggestion: Pass Function Definition as Argument

2019-11-07 Thread David Raymond
Here is it rewritten using the proposal: ``` #Definition def myFoo (str1, str2, foo, str = " "): print( foo(str = str1), foo(str = str2) ) #Call myFoo ("hello", "world!"): str = list(str)[0].upper() + str[1:] return str ``` Are you looking for multi-line

RE: How execute at least two python files at once when imported?

2019-11-06 Thread David Raymond
"Why is importing modules in parallel bad?" In general I'd say that "import foo" is supposed to be there because you want the classes, functions, variables etc. in foo to be available in your current program. A module should never run a whole bunch of time consuming stuff when it's imported.

RE: Calculations and Variables

2019-10-31 Thread David Raymond
How are you getting any value at all? You are trying to do math on string values just like in your infinite loop question. This should raise TypeError: unsupported operand type(s) for /: 'str' and 'str' Also, tips are usually given as percentages. Here with a tip value of 9 you're saying that

RE: Exception

2019-09-24 Thread David Raymond
I believe the idea is that previously, if you were handling an exception, and your handling code caused its own exception, then you would get no info about the original exception. So all useful information about the original problem would get lost because of an oopsie in the handling code. So

RE: Weird Python Bug

2019-09-13 Thread David Raymond
2 comments: First: Deleting from a list while you're iterating over it is a bad idea. Your first iteration gives nums[0] which is 72. But then you delete that and (in effect) everything moves up. So now the 4 is in the nums[0] slot. Your second iteration returns nums[1] which is now the 82

RE: Python/SQLite best practices

2019-08-05 Thread David Raymond
"What's the advantage of this over letting the connection object do that for you? As the context manager exits, it will automatically either commit or roll back. If you want to guarantee closing _as well_, then you can do that, but you can at least use what already exists." After review I guess I

RE: Python/SQLite best practices

2019-08-05 Thread David Raymond
Not a full expert, but some notes: I believe the default Connection context manager is set up for the context to be a single transaction, with a commit on success or a rollback on a failure. As far as I know it does NOT close the connection on exiting the context manager. That only happens

RE: Xml File Error

2019-07-30 Thread David Raymond
Is that the correct path to the file, without any typos? os.path.abspath and os.path.join don't do any checking on whether their resulting path exists. So if there is a typo or error in your path it doesn't get reported until you actually try and open it by running ElementTree.parse You can

RE: Boolean comparison & PEP8

2019-07-29 Thread David Raymond
I think the other part of the discussion to be had here is: how do you name your booleans? As with other things, "x", and "greeting" aren't really the best names. "greeting" sounds like it should hold what the greeting _is_, not whether or not there _should be_ a greeting. If it were something

RE: Threading Keyboard Interrupt issue

2019-05-29 Thread David Raymond
That's a little weird, and my running it works slightly differently. Please paste exactly what you're running (no time import and true being lowercase for example means we couldn't copy and paste it and have it immediately run) In your script, the main thread hits y.start() which completes

RE: More CPUs doen't equal more speed

2019-05-23 Thread David Raymond
You really need to give more info on what you're doing in doit() to know what's going on. Are you using subprocess, threading, multiprocessing, etc? Going off of what you've put there those nested for loops are being run in the 1 main thread. If doit() kicks off a program and doesn't wait for

RE: PYTHONHASHSEED VALUE

2019-05-14 Thread David Raymond
What is the test case actually checking for, and why? One of the main aspects of a set is that it's unordered. So something checking to make sure the order of an unordered object is some static value seems like it's testing for the wrong thing. -Original Message- From: Python-list

RE: break out of a program

2019-04-19 Thread David Raymond
The normal way of saying you want to exit the whole program is with sys.exit() https://docs.python.org/3.7/library/sys.html#sys.exit You can optionally give it the return code/exit status you want the interpreter to give to the OS when it exits. -Original Message- From: Python-list

RE: I want understand how this word wrap program playing on input

2019-04-04 Thread David Raymond
> Yep, spotted that too! :-) BTW, your fix also a bug: the last word on a > line won't be followed by a space (off-by-one). The easiest fix for that > is to add 1 to line_length initially, another little trick. > Or, equivalently, to reset current_line_length to -1, which is an elegant > hack.

RE: I want understand how this word wrap program playing on input

2019-04-04 Thread David Raymond
The function is constructing a list of the lines, which it will combine at the end. Answering the questions in reverse order: 3. Also why that `if` test is required there. The if statement is saying "I don't have room on my current line for the next word, so time to start a new line" 2. In the

RE: Losing words

2019-04-01 Thread David Raymond
https://docs.python.org/3.7/library/socket.html#socket.socket.send .send returns the number of bytes that it actually succeeded in sending. From the docs: "Applications are responsible for checking that all data has been sent; if only some of the data was transmitted, the application needs to

RE: What is the difference between "ws.Messagebeep(1)" and "ws.Messagebeep(-1)" ?

2019-03-21 Thread David Raymond
I'm assuming by ws you mean winsound? Check the docs: https://docs.python.org/3.7/library/winsound.html winsound.MessageBeep(type=MB_OK) Call the underlying MessageBeep() function from the Platform API. This plays a sound as specified in the registry. The type argument specifies which

RE: System Beep?

2019-03-08 Thread David Raymond
I believe you added an extra D there. winsound, not winDsound -Original Message- From: Steve [mailto:Gronicus@SGA.Ninja] Sent: Friday, March 08, 2019 3:16 PM To: David Raymond; python-list@python.org Subject: RE: System Beep? = RESTART: C:\Gork\Med Insulin codes

RE: System Beep?

2019-03-08 Thread David Raymond
Windows has the built in winsound module that lets you set frequency and duration, not sure about other OS's. https://docs.python.org/3.7/library/winsound.html -Original Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of Steve

RE: in a pickle

2019-03-06 Thread David Raymond
https://docs.python.org/3.7/library/pickle.html#pickling-class-instances includes 2 notes, which I think are the relevant ones: When a class instance is unpickled, its __init__() method is usually not invoked. The default behaviour first creates an uninitialized instance and then restores the

RE: confusion with os.chmod() and follow_symlinks

2019-02-22 Thread David Raymond
Not sure, but the way I read it follow_symlinks = True is the default behavior of systems that don't allow you to set it, and being able to set it to False is the special bit. So "allowing follow_symlinks" means it "allows you to change it to whatever you want", not "allows it to be True"

RE: Convert a list with wrong encoding to utf8

2019-02-14 Thread David Raymond
Next question is how did you _insert_ those names into the database previously? Are the names showing up ok using any other tool to look at them? The error might have been on insert and you're just seeing weird stuff now because of that. Maybe, where instead of giving it the text and letting

RE: I cannot seem to write time/date to the file.

2019-02-12 Thread David Raymond
DateReading.write = (nowTimeDate2 + "\n") You're re-assigning the write method to be a string here. You want to call the method with the string as the argument. DateReading.write(nowTimeDate2 + "\n") -Original Message- From: Python-list

RE: more pythonic way

2019-02-11 Thread David Raymond
My non-expert vote is for if month is None: month = datetime.date.today().month Because you're checking for your default value, not whether the boolean version of what they did give you is True or False. It's explicit, it's not reliant on any __bool__() function implementations or

RE: timezones

2019-02-07 Thread David Raymond
I'd say if the documentation mentions it, but doesn't say why, then we're not gonna be able to do much better for you as far as "why" goes. http://pytz.sourceforge.net/ "Unfortunately using the tzinfo argument of the standard datetime constructors "does not work" with pytz for many timezones."

RE: Loop with else clause

2019-02-05 Thread David Raymond
As mentioned somewhere, "readability counts", so why not just go with exactly what you said... if len(nominees) > 0:#if a condition exists for nominee in nominees: #the loop should be executed print(nominee) else:#but if not

time.strftime question on 0 as argument

2019-01-28 Thread David Raymond
https://docs.python.org/3.7/library/time.html#time.strftime In the docs there is "0 is a legal argument for any position in the time tuple; if it is normally illegal the value is forced to a correct one." and yet if given 0 for the year/first item in the tuple it raises a ValueError. Is that a

RE: Pythonic Y2K

2019-01-18 Thread David Raymond
Reminds me of a similar problem that didn't get noticed until it did actually hit: In 2007 the first time a group of F-22's crossed the international date line every computer system in the aircraft crashed, losing comms, navigation, avionics, and a host of other systems. Fortunately their

RE: Pythonic Y2K

2019-01-18 Thread David Raymond
Which brings up the assumption that this whole A.D. thing is gonna stick around for more than a few millennia and isn't just a fad. Sloppy to just use positive for A.D. and negative for B.C. without a discrete unit for Age. What happens when Sauron is defeated and the Third Age is declared? Or

RE: How can I find the indices of an array with float values in python?

2019-01-10 Thread David Raymond
Maybe something along the lines of... indices = [i for i, val in enumerate(x) where 0 <= val <= 15000] -Original Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of Madhavan Bomidi Sent: Thursday, January 10, 2019 12:05 PM To:

RE: subprocess : AttributeError: 'Popen' object has no attribute 'read'

2019-01-03 Thread David Raymond
Agreeing with the other poster that it's probably not the best way to handle it. But for the sake of helping with subprocess: https://docs.python.org/3.7/library/subprocess.html#popen-objects Popen Objects don't have read() as the error says. That's on their .stdout and .stderr streams. So

RE: Variable number of arguments

2018-12-17 Thread David Raymond
argparse works fine on 3.x https://docs.python.org/3.6/library/argparse.html You can't really have back to back _positional_ arguments with nargs = "+" as it won't be able to tell where you meant one group to end and the next to begin. You'd have to call it with switches like script.py -if

RE: Why do integers compare equal to booleans?

2018-11-16 Thread David Raymond
A boolean type didn't come about until version 2.3, and even now they still inherit from integers. Some links for you: https://docs.python.org/3.7/whatsnew/2.3.html#pep-285-a-boolean-type https://docs.python.org/3.7/library/stdtypes.html#boolean-values

RE: Windows file associations fix

2018-11-13 Thread David Raymond
ing happily now. Again, many thanks for the replies. -Original Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of eryk sun Sent: Friday, November 09, 2018 6:43 PM To: Python Subject: Re: Windows file associations fix On 11/9/18, Dav

Windows file associations fix

2018-11-09 Thread David Raymond
Would some kind person be so good as to point me to instructions on how to fix Windows file associations and default programs for the various Python extensions (.py/.pyw/etc)? I know I've fixed this before after installing a new version, but didn't save the instructions, and apparently my

RE: [OT] master/slave debate in Python

2018-09-26 Thread David Raymond
...Think about how you treat your computers - you have the power to discard them if they do not work correctly, or even if you just want to get a newer one. You have the power to kick them across the room and nobody will arrest you. Maybe you don't do those things (I would hope you don't kick

RE: [SPAM] Type error: not enough arguments for format string

2018-09-19 Thread David Raymond
My first bet at the culprit is the space between the % and (message)s, they should be together like you have them for asctime. -Original Message- From: Python-list [mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of synch1...@gmail.com Sent: Wednesday,

RE: Why emumerated list is empty on 2nd round of print?

2018-09-06 Thread David Raymond
The actual "enumerate" object is really just holding a current index and a reference to the original list. So if you alter the original list while you're iterating through it you'll see the changes. If you want a full copy then you can just wrap it with list() Python 3.7.0 (v3.7.0:1bf9cc5093,

RE: How to sort over dictionaries

2018-08-30 Thread David Raymond
Remember to check what the res["date"] types actually are. If they're just text, then it looked like they were in M/D/Y format, which won't sort correctly as text, hence you might want to include using datetime.strptime() to turn them into sortable datetimes. -Original Message- From:

RE: How to sort over dictionaries

2018-08-29 Thread David Raymond
Well, that's a list of... somethings. So I'm assuming you mean sort a list of dictionaries? foo.sort(key = lambda x: time.strptime(x["date"], "%d-%m-%Y %H:%M")) with , reverse = True in the sort if you want it sorted in reverse -Original Message- From: Python-list

RE: Python Postgresql complete guide

2018-08-23 Thread David Raymond
Looks good. Having used psycopg2 a fair amount, here are some suggestions I have on extra things to cover or emphasize. -Postgres specific things like remembering to "set search_path to blargh, public;" etc as needed before querying. -An example case of cur.fetchone() returning None, or more

RE: ignoring some default fields from SimpleJsonFormatter

2018-08-21 Thread David Raymond
https://docs.python.org/3.7/library/logging.html#logging.Logger.debug https://docs.python.org/3.7/library/logging.html#logging.Formatter.format Basically your Formatter string doesn't include %(anotherfield1)s in it anywhere, so that gets ignored. To have a variable number of those in there

RE: How to pass Python command line options (vs arguments) when running script directly vs via Python interpreter?

2018-08-15 Thread David Raymond
So what are you saying is an option vs an argument? Because I see no distinction whatsoever. When you run something you give it a bunch of strings. That's it. There is nothing magical about putting a dash in front of a letter, nothing magical about putting in a string that might possibly also

RE: Dealing with errors in interactive subprocess running python interpreter that freeze the process

2018-08-01 Thread David Raymond
A couple notes: -I think the Python interpreter actually sends its output to stderr, so to capture it you'd probably want it to go to the same place as stdout, so use stderr = subprocess.STDOUT -You're only reading 1 line out output for each thing, so if 1 command creates multiple lines of

RE: Python Console Menu

2018-07-31 Thread David Raymond
Take a look at the subprocess module for how to "spawn new processes, connect to their input/output/error pipes, and obtain their return codes." https://docs.python.org/2/library/subprocess.html -Original Message- From: Python-list

RE: Python bug in ArcGIS - Urban Network analysis tool

2018-07-30 Thread David Raymond
A note that Arc may have installed its own version of Python, which it is using from within its own tools. For example, I've got a full Python installation in C:\Python27\ArcGIS10.2 which Arc installed on top of a preexisting installation in C:\Python27. So you may need to explicitly run it

RE: Checking whether type is None

2018-07-24 Thread David Raymond
https://docs.python.org/3.7/library/constants.html "None The sole value of the type NoneType..." "x is None" and "type(x) is type(None)" are equivalent because of that. I think though that the better way to do the first tests would be to use isinstance