简体   繁体   中英

Check whether a string contains a None Type value python

I am writing to a csv file in Python. But when I try to open and read it I get:

TypeError: expected string or Unicode object, NoneType found

My question is, how can I check before I write something whether my string contains a None type value.

Thanks

You can use is not (which is recommended to compare with singletons like None ):

if some_string is not None:
    # write

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM