Skip to content

Tag: python

SyntaxError: invalid syntax upon importing modules

On my Debian distro, I am not sure if I corrupted my installation, but I get the following syntax error every time I import something with python. My file: Output: What I also don’t understand is that error is referencing a totally different file (ssl.py), which I created previously and has nothing to d…

Number of steps to reduce to zero

Hello I have this steps problem and I am trying to see where I can improve my code to get the number of steps it takes to reduce any integer down to zero. I’m sure you all know the process, but just for clarification…if the number is even, we divide by 2, adding a step, and if the number is

How do I extract tables from word via table titles?

I’m facing the problem of trying to extract data from word files in the form of tables. I have to iterate through 500 word files and extract a specific table in each file, but the table appears at a different point in each word file. This is the code I have: Which goes through all the files fine, but ge…

Create a pydantic model with dynamic keys

I want to create a Pydantic model for this structure: My first attempt was But this raises an exception: If i change Dict to dict, i don’t get the exception, but the resulting object yields an empty dict: what am i doing wrong? Answer You have a typo in model declaration. Use a colon instead of the equal sign…

Module not found error but I have pip installed the module

I have correctly pip installed the module, but I am still getting an error and I am not sure why. My Code: 21:from Crypto.Cipher import AES 22:from PIL import ImageGrab 23:from win32crypt import CryptUnprotectData Error is: File “main.py”, line 21, in ModuleNotFoundError: No module named ‘Cr…

Remove specific rows that contain dates Python

I have a dataset that has datetime values in it. I would like to remove all rows within a specific column that contain a certain year. All rows that contain 2027 should be removed. Data Desired Doing Any suggestion is appreciated. Error: AttributeError: Can only use .str accessor with string values! I believe…