Skip to content

Tag: python

Close bus in python-can

I am using python-can to send CAN messages like this: The script works fine, but when I run it for a 2nd time, it results in an error, because the bus is still open from the previous time. I think I need something like this at the end of my script: However, this does not exist and I can’t seem

How to include condition in composite list comprehension?

I would like to flatten a list but keep NaNs. The following base code works when there are no NaNs: Now if I have the following case it will break: which makes sense, but I need this border case to be handled and I’m not sure how to add the special case condition in the list comprehension above. How can

Filtering out rows based on other rows using pandas

I have a dataframe that looks like this: I can’t seem to figure out a way to filter out certain rows based on the following condition: If there are two entries under the same companyId, as is the case for 198236 and 153421, I want to keep only the entry where type is actual. If there is only one entry

Regex – How to account for random spacing/line breaks in a term

I am using Python and have the following regular expression to extract text from text files: My issue is specifically with the last term, “Pursuant to the requirements of the Securities Exchange Act of 1934”. In the text files, this sentence is sometimes spaced randomly and starts different parts …

How to pause a pynput event listener

I am trying to make a program that will read the user’s inputs and if it detects a certain key combination, it will type a special character. Currently I am testing and I want the script to just output a ‘+’ after each character that the user types. I am using the pynput event listener to de…