Where can I find the _sre.py python built-in module? [closed]

2024/9/8 10:25:10

I am studying the python regular expression (re.py) source code.

In re.py they imported the module sre_compile:

import sre_compile

and I look at the module sre_compile there they imported the module _sre in the line 13

import _sre, sys

I searched for the module _sre.py but I could not find it anywhere, I even tried to
locate _sre.py in my shell.

In the end I tried to locate it with the python interpreter. I imported _sre and I was trying to look for the __file__ attribute of _sre but it gave me the following error:

AttributeError: 'module' object has no attribute '__file__'

Where can I find the _sre module source code?

Answer

_sre is the C-extension that implements most of the re module functionality. C-extensions usually do not have a __file__ attribute.

As such you are looking for the _sre.c source file instead.

https://en.xdnf.cn/q/72582.html

Related Q&A

When numba is effective?

I know numba creates some overheads and in some situations (non-intensive computation) it become slower that pure python. But what I dont know is where to draw the line. Is it possible to use order of …

How to launch a Windows shortcut using Python

I want to launch a shortcut named blender.ink located at "D://games//blender.ink". I have tryed using:-os.startfile ("D://games//blender.ink")But it failed, it only launches exe fil…

Providing context in TriggerDagRunOperator

I have a dag that has been triggered by another dag. I have passed through to this dag some configuration variables via the DagRunOrder().payload dictionary in the same way the official example has don…

Install gstreamer support for opencv python package

I have built my own opencv python package from source. import cv2 print(cv2.__version__)prints: 3.4.5Now the issue I am facing is regarding the use of gstreamer from the VideoCapture class of opencv. I…

How to use query function with bool in python pandas?

Im trying to do something like df.query("column == a").count()but withdf.query("column == False").count()What is the right way of using query with a bool column?

Text Extraction from image after detecting text region with contours

I want to build an OCR for an image using machine learning in python. I have preprocessed image by converting it to grayscale , applied otsu thresholding . I then used the contours to find the text re…

Pyinstaller executable fails importing torchvision

This is my main.py:import torchvision input("Press key")It runs correctly in the command line: python main.pyI need an executable for windows. So I did : pyinstaller main.pyBut when I launche…

Embedding Python in C: Having problems importing local modules

I need to run Python scripts within a C-based app. I am able to import standard modules from the Python libraries i.e.:PyRun_SimpleString("import sys")But when I try to import a local module …

Primitive Calculator - Dynamic Approach

Im having some trouble getting the correct solution for the following problem: Your goal is given a positive integer n, find the minimum number ofoperations needed to obtain the number n starting from …

Cant pickle : attribute lookup builtin.function failed

Im getting the error below, the error only happens when I add delay to process_upload function, otherwise it works without a problem.Could someone explain what this error is, why its happening and any…