Python Finite Automata library

What would be the most complete finite automata library for Python, which is able to do the basic manipulations such as: Minimization, Determinization of Nondeterministic Finite automata Union, Intersection, and Product of the languages generated by these automata, etc. All the libraries that I'm finding are either incomplete or do not work plug-and-play-wise. python-automata seems

Python有限自动机库

Python最完整的有限自动机库是什么,它能够完成如下基本操作: 最小化, 非确定性有限自动机的确定 由这些自动机生成的语言的联合,交集和产品等。 我发现的所有库都不完整,或者不能即插即用。 python-automata似乎能够完成你所要求的所有事情。 它缺少什么? 也许你想自己贡献一个缺失的功能? 如果您不介意使用底层C ++库,则可以使用这些Python绑定来尝试OpenFst。 PyFsa具有您列出的优化算法。

Python

I'm learning the Python programming language and I've came across something I don't fully understand. In a method like: def method(self, blah): def __init__(?): .... .... What does self do? What is it meant to be? Is it mandatory? What does the __init__ method do? Why is it necessary? (etc.) I think they might be OOP constructs, but I don't know very mu

蟒蛇

我正在学习Python编程语言,并且遇到了一些我不完全理解的东西。 在像这样的方法中: def method(self, blah): def __init__(?): .... .... self做什么? 这是什么意思? 它是强制性的吗? __init__方法有什么作用? 为什么有必要? (等等。) 我认为他们可能是面向对象的构造,但我不太了解。 在这个代码中: class A(object): def __init__(self): self.x = 'Hello' def meth

self, no self and cls

Yet another question on what the 'self' is for, what happens if you don't use 'self' and what's 'cls' for. I "have done my homework", I just want to make sure I got it all. self - To access an attribute of an object, you need to prefix the attribute name with the object name ( objname.attributename ). The same way self is used to access an attribute i

自我,没有自我和cls

还有一个问题是关于“自我”是什么,如果你不使用“自我”和什么是“自我”,会发生什么。 我“已经完成了我的功课”,我只是想确保我完成了所有工作。 self - 要访问对象的属性,需要在属性名称前添加对象名称( objname.attributename )。 self用于访问对象(类)本身内的属性。 因此,如果您没有在类方法中使用自变量前缀变量,则无法在类的其他方法或类之外访问该变量。 因此,如果您只想将该变量局部用于该方法,则可以忽略

Why accessing to class variable from within the class needs "self." in Python?

Possible Duplicate: Python 'self' explained I'm learning Python and I have a question, more theoretical than practical, regarding access class variables from method of this class. For example we have: class ExampleClass: x = 123 def example_method(self): print(self.x) Why is necessarily to write exactly self.x , not just x ? x belongs to namespace of the class

为什么从类中访问类变量需要“自我”。 在Python中?

可能重复: Python'自我'解释 我正在学习Python,我有一个问题,比实际更理论,关于这个类的方法的访问类变量。 例如我们有: class ExampleClass: x = 123 def example_method(self): print(self.x) 为什么必须写出完全的self.x ,而不仅仅是x ? x属于类的名称空间,使用它的方法也属于它。 我错过了什么? 这种风格背后有什么理由? 在C ++中,您可以编写: class ExampleClass { publi

Matplotlib and GTKAgg and OS X

I installed python 2.7 and matplotlib 1.1.1 on Mountain Lion via Macports and when I run the following: import matplotlib matplotlib.use('GTKAgg') import matplotlib.pyplot as plt on the last line I get the error messages below. After looking around on the internet the only "solution" I've seen is to use 'Agg' as the backend instead of 'GTKAgg', but when

Matplotlib和GTKAgg和OS X

我通过Macports在Mountain Lion上安装了Python 2.7和matplotlib 1.1.1,并且运行以下命令时: import matplotlib matplotlib.use('GTKAgg') import matplotlib.pyplot as plt 在最后一行,我会看到下面的错误消息。 在互联网上环顾四周后,我所看到的唯一“解决方案”就是使用'Agg'作为后端而不是'GTKAgg',但是当我这样做时它会运行(并且终止没有任何错误),但没有任何绘制。 上面的行在我的Wind

Problems with my BaseHTTPServer

I am trying to create my own functions in the subclass of BaseHTTPRequestHandler as such class Weblog(BaseHTTPServer.BaseHTTPRequestHandler): def do_HEAD(self): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() def do_GET(self): """Respond to a GET request.""" if self.path == '/': do_index() elif self.path == '/timestamp':

我的BaseHTTPServer存在问题

我试图在BaseHTTPRequestHandler的子类中创建自己的函数 类Weblog(BaseHTTPServer.BaseHTTPRequestHandler): def do_HEAD(self): self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() def do_GET(self): """Respond to a GET request.""" if self.path == '/': do_index() elif self.path == '/timestamp': do_entry() elif self.path

Retrieving python module path

I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from. How do I retrieve a module's path in python? import a_module print a_module.__file__ Will actually give you the path to the .pyc file that was loaded, at least on Mac OS X. So I guess you can do import os path = os.path.dirname(amodule.__file

检索python模块路径

我想检测模块是否已经改变。 现在,使用inotify很简单,你只需要知道你想从中获取通知的目录。 如何在python中检索模块的路径? import a_module print a_module.__file__ 实际上会给你加载的.pyc文件的路径,至少在Mac OS X上。所以我想你可以做 import os path = os.path.dirname(amodule.__file__) 你也可以试试 path = os.path.abspath(amodule.__file__) 获取目录以查找更改。 python中有inspect模块。 官方文

cv2.imread fails in script, not on command line

cv2.imread("some.jpg") fails to read many different jpgs. I have checked a million different things: Run the same exact code in a terminal - reads and opens images just fine I checked version numbers of both python and cv2 - they are exactly the same: 3.4.3 and 3.1.0 . Used complete paths to files. No difference Images exist: I've manually opened dozens to see if there'

cv2.imread在脚本中失败,而不是在命令行上

cv2.imread("some.jpg")无法读取许多不同的jpgs。 我检查了一百万种不同的东西: 在终端中运行相同的确切代码 - 读取并打开图像就好了 我检查了python和cv2的版本号 - 它们完全一样: 3.4.3和3.1.0 。 使用完整的文件路径。 没有不同 图像存在:我手动打开了几十个,看看是否有什么东西 时机:增加暂停只是为了确保这不是一个时间问题。 检查以确保img/filename与print(os.path.exists(filename)) # pri

Get my current path using a python script as a command

I put a python script to my /usr/local/bin to use as a command in bash. I want to use my bash working directory, but I only get the current directory where the script is executed. Is there a way to use the current directory as a command does? Eg with convert2ogg (as python script in /usr/local/bin) $ cd ~/Music $ convert2ogg *.mp3 import os,sys print("CWD: "+os.getcwd()) print("Script: "+s

使用python脚本作为命令获取当前路径

我把一个python脚本放在我的/usr/local/bin中作为bash中的命令使用。 我想使用我的bash工作目录,但是我只能得到执行脚本的当前目录。 有没有办法使用当前目录作为命令呢? 例如convert2ogg(如/ usr / local / bin中的python脚本) $ cd ~/Music $ convert2ogg *.mp3 import os,sys print("CWD: "+os.getcwd()) print("Script: "+sys.argv[0]) print(".EXE: "+os.path.dirname(sys.executable)) print("Script dir: "+ os

Finding path for corpus in NLTK

I am using the Natural Language Toolkit for python to write a program. In it I am trying to load a corpus of my own files. To do that I am using code to the following effect: from nltk.corpus import PlaintextCorpusReader corpus_root=(insert filepath here) wordlists=PlaintextCorpusReader(corpus_root, '.*') Let's say my file is called reader.py and my corpus of files is located in a directo

在NLTK中找到语料库的路径

我正在使用自然语言工具包来编写一个程序。 其中我正在尝试加载我自己文件的语料库。 要做到这一点,我使用代码来达到以下效果: from nltk.corpus import PlaintextCorpusReader corpus_root=(insert filepath here) wordlists=PlaintextCorpusReader(corpus_root, '.*') 假设我的文件名为reader.py,并且我的文件语料库位于与reader.py相同的目录中名为“corpus”的目录中。 我想知道一种通用的方法来查找上面的文件路径,