py2app 应用程序中的捆绑文本文件 (python)

发布于 2024-12-21 13:18:30 字数 341 浏览 4 评论 0原文

我最近学习了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

若无相欠,怎会相见 2024-12-28 13:18:30

在选项中指定一个资源键,其中包含要包含的资源列表。当您的应用程序运行时,这将是当前目录

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

何时共饮酒 2024-12-28 13:18:30

来自 py2app 的帮助文档

第一步是为您的脚本创建一个 setup.py 文件。 setup.py
是“项目文件”,它告诉 setuptools 所需的一切
知道构建您的应用程序。我们将使用 py2applet 脚本来完成
那:

$ py2applet --make-setup MyApplication.py

编写setup.py

如果您的应用程序具有图标(.icns 格式)或数据文件
它需要,您还应该将它们指定为 py2applet 的参数。

因此,假设您有 hangman.pyhangman.txt 运行:

$ py2applet --make-setuphangman.pyhangman.txt

From the help document for py2app:

The first step is to create a setup.py file for your script. setup.py
is the "project file" that tells setuptools everything it needs to
know to build your application. We'll use the py2applet script to do
that:

$ py2applet --make-setup MyApplication.py

Wrote setup.py

If your application has an icon (in .icns format) or data files that
it requires, you should also specify them as arguments to py2applet.

So presuming you have hangman.py and hangman.txt run:

$ py2applet --make-setup hangman.py hangman.txt

流年里的时光 2024-12-28 13:18:30

一种非常简单的方法是将字典添加为在运行时导入的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文