我面临这个错误,我的函数被说成是没有定义的尽管我已经正确定义并调用函数,这是我得到的错误,请帮助:在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中调用函数时出错“函数未定义”相关推荐

  1. c ++ 函数的esp指针_在C ++中通过指针访问成员函数

    c ++ 函数的esp指针 Create a class along with data member and member functions and then access the member ...

  2. python怎么选取不连续的列_用pandas中的DataFrame时选取行或列的方法

    如下所示: import numpy as np import pandas as pd from pandas import Sereis, DataFrame ser = Series(np.ar ...

  3. MySQL用函数统计记录总数_在mysql中使用COUNT 或者SUM函数计算记录总数

    count函数的作用 想要真正的理解count函数,我们就必须明白count函数的作用. 作用一:统计某一列非空(not null)值得数量,即统计某列有值得结果数,使用count(col),其中co ...

  4. python读取xml文件信息失败_通过XML读取XML文件时出错。

    我试图用python读取XML文件xml.etree但有时对于某些文件,我在解析文件时会出现内存错误.我的XML文件大小是912Mb,这个问题与文件大小有关吗?在 代码:from xml.etree ...

  5. python中format函数用法简书_从Python安装到语法基础,这才是初学者都能懂的爬虫教程...

    Python和PyCharm的安装:学会Python和PyCharm的安装方法 变量和字符串:学会使用变量和字符串的基本用法 函数与控制语句:学会Python循环.判断语句.循环语句和函数的使用 Py ...

  6. python 描述符有什么用_介绍python描述符的意义

    你也许经常会听到「描述符」这个概念,但是由于大多数的程序员很少会使用到他,所以可能你并不太清楚了解它的原理,python视频教程栏目将详细介绍 推荐(免费):python视频教程 但是如果你想自己的事 ...

  7. python基础语法加爬虫精进_从Python安装到语法基础,这才是初学者都能懂的爬虫教程...

    Python和PyCharm的安装:学会Python和PyCharm的安装方法 变量和字符串:学会使用变量和字符串的基本用法 函数与控制语句:学会Python循环.判断语句.循环语句和函数的使用 Py ...

  8. Matlab函数打包为.jar后在java中调用出现错误:Exception:com.mathworks.toolbox.javabuilder.MWException: An error occur

    Matlab函数打包为.jar后在java中调用出现错误:Exception:com.mathworks.toolbox.javabuilder.MWException: An error occur ...

  9. shell调用python脚本传递命名关键字参数_关于python:将字典作为关键字参数传递给函数...

    我想使用字典在python中调用函数. 这是一些代码: d = dict(param='test') def f(param): print(param) f(d) 这打印{'param': 'tes ...

  10. python中execute函数_在excel中调用python函数

    效果: 通过excel引用在py文件中写好的load_settle()函数,可以快捷的获取对应的历史结算价. 使用方法: 1.首先安装office,我用的是2016版本. 2.安装python,推荐使 ...

最新文章

  1. Redis 笔记(12)— 单线程架构(非阻塞 IO、多路复用)和多个异步线程
  2. <a>标签带参数跳转并在下一个页面接收
  3. 【Android FFMPEG 开发】FFMPEG 获取 AVStream 音视频流 ( AVFormatContext 结构体 | 获取音视频流信息 | 获取音视频流个数 | 获取音视频流 )
  4. 009_JMS中的事务
  5. 捕获异常_SpringBoot的异常处理全局异常捕获(图文资料)
  6. OpenCV—矩阵数据类型转换cv::convertTo
  7. 三个角度来解决无线路由故障
  8. Python list 和 tuple 使用小记
  9. bom .dom_MicroProfile 2.2 BOM导入支持
  10. android item三种,Android RecyclerView中的ItemDecoration的几种绘制方法
  11. 2017.3.13 木棍分割 思考记录
  12. Android开发技术周报 Issue#9
  13. mysql 5.6 参数详解
  14. 世界上增福最快的方法!【错过就可惜了】
  15. One to One 的数据库模型设计与NHibernate配置
  16. SQL SERVER: 合并相关操作(Union,Except,Intersect)
  17. linux设置ipsan_Linux下IP SAN共享存储操作记录
  18. Reinforcement Learning——Chapter 2 Multi-armed Bandits
  19. 我开始搞研发管理和项目管理了,发现最难管理的还是人
  20. 网易云音乐android面试题,# 每日一道面试题 # 如何测试网易云音乐 app 语音识别功能?...

热门文章

  1. win10系统,使用Windows照片查看器打开图片
  2. navicat下载安装教程
  3. arduino的pinMode()函数
  4. 换个角度深入理解GlusterFS
  5. Excel如何对多分隔符号数据进行分列
  6. matlab小波变换,图像处理
  7. Excel表格合并两列数据且保留全部内容
  8. 解决笔记本电脑有线耳机插入无反应的情况
  9. 东方欲晓,莫道君行早。踏遍青山人未老,风景这边独好。
  10. ue4使用Niagara粒子实现下雨效果,使用蓝图调节雨量