不明白为什么找不到这个文件错误

时间:2017-01-27 02:26:55

标签: python python-2.7

# filename variables
import os
import re

filename = 'randomtext.txt'
newfilename = 'result.txt'

# read the file
if os.path.exists(filename):
    data = open(filename, 'r')
    phonenumber = data.read()
else:
    print "File not found."
    print (os.getcwd())
    print os.path.isfile("C:\Users\Lisbeth Salander\Desktop\python\randomtext.txt")
    raise SystemExit

# regex = regular expression to remove extract indian phone numbers
# It will remove counry code of any indian number eg: +91-9818249892 will become 9818249892
# the lenght number should be 1o digits only

r = re.compile(r'(!(\!+?\![91]?\-?))?\d{10}')
results = r.findall(phonenumber)
extracted_phonenumber = ""
for x in results:
    extracted_phonenumber += str(x) + "\n"


# function to write file
def writefile():
    f = open(newfilename, 'w')
    f.write(extracted_phonenumber)
    f.close()


# removing duplicates

content = open(newfilename, 'r').readline()
content_set = set(content)
cleandata = open('clean_result.txt', 'w')

for line in content_set:
    cleandata.write(line)

print "File written."

但即使我已将我的文件粘贴在上面的目录中 什么可能出错请告诉我?

这是以下错误代码

C:\Python27\python.exe "C:/Users/Lisbeth Salander/Desktop/python/practice.py"
File not found.
C:\Users\Lisbeth Salander\Desktop\python
False

处理完成,退出代码为0

P.s我使用python 2.7,我已经评论了我的代码以便于理解,如果有更多的建议,请告诉我将不胜感激。我正在创建一个工具来从一个静态文件中读取电话号码

0 个答案:

没有答案