-1

私は python を学んでおり、5 つまたは 6 つの python ファイルを含むチュートリアル フォルダーがあります。それらの 1 つには正規表現関数 say が含まれていまし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__を含むフォルダーが作成されたためです。.pycfile_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

2 つの質問があります。

  1. ファイル__pycache__専用に作成されたフォルダーはなぜfile_regex.py
  2. __pycache__この問題のフォルダーまたは解決策を削除するにはどうすればよいですか (python -B file1.pyコマンドを使用して python ファイルをコンパイルしようとしましたが、うまくいきませんでした)

PS: 私は miniconda 環境 (python 3.x) で作業しています。

4

3 に答える 3

0

私は実際にファイルにregex.py. フォルダーを削除し__pycache__てファイル名をフォルダーに変更するとfile_regex.py__pycache__再び表示されなくなり、問題は解決しました。

于 2015-08-31T17:37:42.123 に答える