Skip to content

Tag: python

Python ibm_db equivalent of db2look

SO I am using ibm_db library for fetch necessary information. Now I want to get the full table creation script along with index and all. I can see there is one db2look command to generate the same Is there an equivalent thing in ibm_db? Answer No, there is not an exact equivalent in the python ibm_db for the …

Get all permutations of bool array

I need all permutations of a bool array, the following code is inefficient, but does what I want: However it is inefficient and fails for long arrays. Is there a more efficent implementation? Answer What about sampling the combinations of indices of the True values: Output:

move files to subdirectories that are named on part of the filenames

I have a few data files in a directory, and I want to move them to the subdirectories based on their filenames. Let’s say we created the first directory named “20220322_170444,” and it should contain the first four files only because in the next file the “el” is less than the pre…

Extract all matches unless string contains

I am using the re package’s re.findall to extract terms from strings. How can I make a regex to say capture these matches unless you see this substring (in this case the substring “fake”). I attempted this via a anchored look-ahead solution. Current Output: Desired Output I could accomplish …

How to do with Pydantic regex validation?

I’m trying to write a validator with usage of Pydantic for following strings (examples): 1.1.0, 3.5.6, 1.1.2, etc.. I’m failing with following syntax: Can anyone help me out what regex syntax should look like? Answer The error you are facing is due to type annotation. As per https://github.com/pyd…