【发布时间】:2015-08-31 15:46:42
【问题描述】:
我正在学习 python,我有一个包含 5 或 6 个 python 文件的教程文件夹。其中一个包含正则表达式函数,例如file_regex.py。问题是当我执行文件夹中的任何其他文件时,总是执行file_regex.py,从而给出file_regex.py 的输出。我没有在任何其他文件中导入 file_regex.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�<module>s
我有两个问题:
- 为什么
__pycache__文件夹只为file_regex.py文件创建 - 如何删除
__pycache__文件夹或解决此问题(我尝试使用python -B file1.py命令编译python文件,但没有成功)
P.S:我在 miniconda 环境(python 3.x)中工作,如果有帮助的话
【问题讨论】:
-
__pycache__存储字节码的缓存副本。仅当您明确导入file_regex.py模块时,该模块的缓存字节码才会被加载。没有您明确请求,__pycache__中的任何内容都不会自动加载。 -
但是,其余文件没有导入 file_regex.py 文件..
-
依赖可以传递。使用
-v开关运行 Python 以查看执行时的所有导入。
标签: python regex python-3.x memcached miniconda