200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > python调用函数出现未定义_在python中调用函数时出错“函数未定义”

python调用函数出现未定义_在python中调用函数时出错“函数未定义”

时间:2019-05-20 04:18:06

相关推荐

python调用函数出现未定义_在python中调用函数时出错“函数未定义”

我面临这个错误,我的函数被说成是没有定义的尽管我已经正确定义并调用函数,这是我得到的错误,请帮助:在python中调用函数时出错“函数未定义”

文件“split_text.py”,行80,在 split_pun(字)#passing词的价值split_pun函数删除标点但是这给了我一个错误 NameError:名字“split_pun”没有定义

这里是代码:

"""

Natural Language Toolkit: Urdu Language POS-Tagged (not yet) Corpus Reader

"""

import re

from six import string_types

from nltk.tag import str2tuple, map_tag

import os.path

from nltk.corpus.reader.util import *

from nltk.corpus.reader.api import *

class UrduCorpusReader(CorpusReader):

def words(self, fileids=None): #function for word tokenization

"""

List of words, one per line. Blank lines are ignored.

"""

words_list = []

for filepath in self.abspaths(fileids=fileids):

# print(filepath)

data = open(filepath, 'r').read()

data = data.replace('\n',' ')

words_list = data.split(' ')

#print(words_list) #printing the words after tokenization

return words_list

def split_pun(self,ifile): #function for punctuation removal

punctuations = [

u'\u06D4', # arabic full stop

'.',

u'\u061F', # Arabic question mark

u'\u061B', #ARABIC SEMICOLON

u'\u066D', #ARABIC FIVE POINTED STAR

u'\u' ,#LEFT SINGLE QUOTATION MARK

u'\u' ,#Right Single Quotation Mark

u'\u0027' ,#APOSTROPHE

'/',

':',

';',

'-',

'*',

')',

'(',

'/'

]

f = open(ifile,'r')

text = f.readlines()

f.close()

for x in range(0,len(text)):

s1 = ''.join(ch for ch in s if ch not in punctuations)

print(s1)

return s1

def raw(self, fileids=None):

if fileids is None:

fileids = self._fileids

elif isinstance(fileids, string_types):

fileids = [fileids]

return concat([self.open(f).read() for f in fileids])

if '__main__' == __name__:

word = ' '

corpus_root = os.path.abspath('../test_data')

wordlists = UrduCorpusReader(corpus_root, '.*')

print("Loaded corpus with file IDs: ")

print(wordlists.fileids())

list1 = wordlists.fileids()

for infile in (wordlists.fileids()):

print(infile)

word = wordlists.words(infile) #calling the words function and the save its output

split_pun(word) #passing the value of words function in split_pun to remove punctuation but this gives me an error

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。