__每次运行文件夹中的任何其他文件时,pycache_uu文件夹都会执行

2024-09-20 22:52:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习python,我有一个包含5到6个python文件的教程文件夹。其中一个包含regex函数,比如file_regex.py。问题是,当我执行文件夹中的任何其他文件时,总是执行file_regex.py,从而给出{}的输出。我没有导入文件_正则表达式.py在其他文件里。在

file_regex.py

import re

sentence = ''' Jessica_is_27 year7s old, whereas John is 12 but Stephanie is 12 and Marco is 50 years '''

ages = re.findall(r'\d{1,3}', sentence)

names = re.findall('[A-Z][a-z]+', sentence) test = re.findall('\W', sentence)

print(ages)

print(names)

print(test)

这是因为创建的__pycache__文件夹中有一个.pyc文件,用于file_regex.py文件。在

regex.cpython-23.pyc

� Vo�U�@sjddlZdZejde�Zejde�Zejde�Zee�ee�ee�dS)�NzX Jessica_is_27 year7s old, whereas John is 12 but Stephanie is 12 and Marco is 50 years z\d{1,3}z[A-Z][a-z]+z\W)�re�sentence�findallZages�names�test�print�rr�!/home/sivasurya/tutorial/regex.py�s

我有两个问题:

  1. 为什么__pycache__文件夹只为file_regex.py文件创建
  2. 如何删除__pycache__文件夹或解决此问题的方法(我尝试使用python -B file1.py命令编译python文件,但没有成功)

注:我在miniconda环境(python3.x)中工作,如果有帮助的话


Tags: 文件pytestre文件夹namesissentence
2条回答

This is because of the __pycache__ folder . . .

这是不正确的。__pycache__文件夹的存在与文件是否运行无关。它只保存编译后的文件,不包含其他内容。在

如果您的file_regex.py继续执行,这是因为其他文件

import file_regex

或者

^{pr2}$

在他们身上。在

我实际上把这个文件命名为regex.py。当我删除__pycache__文件夹并将文件名改为file_regex.py时,__pycache__文件夹没有再次出现,问题就解决了。在

相关问题 更多 >

    热门问题