py2app 应用程序中的捆绑文本文件 (python)
我最近学习了Python(2.7),并一直在用AI制作一些简单的棋盘游戏,例如练习。我目前正在制作一款智能刽子手游戏,需要包含字典文件。 (我有一个文本文件,每行都有一个新单词)。我成功地将 py2app 用于其他东西,例如: connect-four.zzl.org 但不幸的是,它没有当我为新的 Hangman 程序运行 py2app 时,似乎不包含我的文本文件。任何人都可以帮我弄清楚如何包含此文件,以便该程序可以像我链接到的四连棋游戏一样分发?
非常感谢。 (我正在运行 OS X 10.7,如有必要,可以提供任何其他必要的信息)
I recently learned Python (2.7) and have been making some simple board games with AIs and such as practice. I am currently making an intelligent hangman game which necessitates the inclusion of a dictionary file. (I have a text file which has a new word on each line). I used py2app successfully for other stuff such as this: connect-four.zzl.org but unfortunately, it doesn't seem to include my text file when I run py2app for my new hangman program. Can anyone help me figure out how to include this file so that the program can be distributed like the connect four game I linked to?
Thank You very much. (I am running OS X 10.7 and can provide any other necessary info if necessary)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在选项中指定一个资源键,其中包含要包含的资源列表。当您的应用程序运行时,这将是当前目录
options = { "resources": ["myfile.txt"] }
http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html#option-reference
如果您使用资源标志py2applet 它将创建该密钥
Specify a resources key in your options that contains a list of resources to include. This will be the current directory when your app runs
options = { "resources": ["myfile.txt"] }
http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html#option-reference
If you use the resources flag with py2applet it will creates that key
来自 py2app 的帮助文档:
因此,假设您有
hangman.py
和hangman.txt
运行:$ py2applet --make-setuphangman.pyhangman.txt
From the help document for py2app:
So presuming you have
hangman.py
andhangman.txt
run:$ py2applet --make-setup hangman.py hangman.txt
一种非常简单的方法是将字典添加为在运行时导入的 python 模块(变量)。该字典将像任何其他模块一样嵌入到您的 exe 中。
A very simple way is to add your dictionary as a (variable in a) python module that you import at run time. The dictionary will be embedded in your exe as any other module.