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'\u2018' ,#LEFT SINGLE QUOTATION MARK
u'\u2019' ,#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
python调用函数出现未定义_在python中调用函数时出错“函数未定义”相关推荐
- c ++ 函数的esp指针_在C ++中通过指针访问成员函数
c ++ 函数的esp指针 Create a class along with data member and member functions and then access the member ...
- python怎么选取不连续的列_用pandas中的DataFrame时选取行或列的方法
如下所示: import numpy as np import pandas as pd from pandas import Sereis, DataFrame ser = Series(np.ar ...
- MySQL用函数统计记录总数_在mysql中使用COUNT 或者SUM函数计算记录总数
count函数的作用 想要真正的理解count函数,我们就必须明白count函数的作用. 作用一:统计某一列非空(not null)值得数量,即统计某列有值得结果数,使用count(col),其中co ...
- python读取xml文件信息失败_通过XML读取XML文件时出错。
我试图用python读取XML文件xml.etree但有时对于某些文件,我在解析文件时会出现内存错误.我的XML文件大小是912Mb,这个问题与文件大小有关吗?在 代码:from xml.etree ...
- python中format函数用法简书_从Python安装到语法基础,这才是初学者都能懂的爬虫教程...
Python和PyCharm的安装:学会Python和PyCharm的安装方法 变量和字符串:学会使用变量和字符串的基本用法 函数与控制语句:学会Python循环.判断语句.循环语句和函数的使用 Py ...
- python 描述符有什么用_介绍python描述符的意义
你也许经常会听到「描述符」这个概念,但是由于大多数的程序员很少会使用到他,所以可能你并不太清楚了解它的原理,python视频教程栏目将详细介绍 推荐(免费):python视频教程 但是如果你想自己的事 ...
- python基础语法加爬虫精进_从Python安装到语法基础,这才是初学者都能懂的爬虫教程...
Python和PyCharm的安装:学会Python和PyCharm的安装方法 变量和字符串:学会使用变量和字符串的基本用法 函数与控制语句:学会Python循环.判断语句.循环语句和函数的使用 Py ...
- Matlab函数打包为.jar后在java中调用出现错误:Exception:com.mathworks.toolbox.javabuilder.MWException: An error occur
Matlab函数打包为.jar后在java中调用出现错误:Exception:com.mathworks.toolbox.javabuilder.MWException: An error occur ...
- shell调用python脚本传递命名关键字参数_关于python:将字典作为关键字参数传递给函数...
我想使用字典在python中调用函数. 这是一些代码: d = dict(param='test') def f(param): print(param) f(d) 这打印{'param': 'tes ...
- python中execute函数_在excel中调用python函数
效果: 通过excel引用在py文件中写好的load_settle()函数,可以快捷的获取对应的历史结算价. 使用方法: 1.首先安装office,我用的是2016版本. 2.安装python,推荐使 ...
最新文章
- Redis 笔记(12)— 单线程架构(非阻塞 IO、多路复用)和多个异步线程
- <a>标签带参数跳转并在下一个页面接收
- 【Android FFMPEG 开发】FFMPEG 获取 AVStream 音视频流 ( AVFormatContext 结构体 | 获取音视频流信息 | 获取音视频流个数 | 获取音视频流 )
- 009_JMS中的事务
- 捕获异常_SpringBoot的异常处理全局异常捕获(图文资料)
- OpenCV—矩阵数据类型转换cv::convertTo
- 三个角度来解决无线路由故障
- Python list 和 tuple 使用小记
- bom .dom_MicroProfile 2.2 BOM导入支持
- android item三种,Android RecyclerView中的ItemDecoration的几种绘制方法
- 2017.3.13 木棍分割 思考记录
- Android开发技术周报 Issue#9
- mysql 5.6 参数详解
- 世界上增福最快的方法!【错过就可惜了】
- One to One 的数据库模型设计与NHibernate配置
- SQL SERVER: 合并相关操作(Union,Except,Intersect)
- linux设置ipsan_Linux下IP SAN共享存储操作记录
- Reinforcement Learning——Chapter 2 Multi-armed Bandits
- 我开始搞研发管理和项目管理了,发现最难管理的还是人
- 网易云音乐android面试题,# 每日一道面试题 # 如何测试网易云音乐 app 语音识别功能?...