Search code examples
pythonregexpython-3.xmemcachedminiconda

__pycache__ folder executes each time i run any other file in the folder


I am learning python and I have a tutorial folder with 5 or 6 python files. One of them contained regex functions say file_regex.py. The problem is when I execute any other file in the folder, always file_regex.py is executed thus giving the output of file_regex.py. I am not importing file_regex.py in any of the other files.

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)

This is because of the __pycache__ folder created which has a .pyc file for file_regex.py file.

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

I have two questions:

  1. Why does the __pycache__ folder created only for file_regex.py file
  2. How can I delete __pycache__ folder or a solution to this problem (I tried compiling the python file with python -B file1.py command, which didn't work)

P.S: I work in miniconda environment (python 3.x), if that helps


Solution

  • I actually named the file as regex.py. when I deleted the __pycache__ folder and changed the file name to file_regex.py the __pycache__ folder didn't show up again and the problem was solved.