1

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)

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

4 Comments

Awesome! I tried it right below my icon specification, and it worked. Many thanks.
actually, I thought that this would work in the same manner for py2exe, but it did not. I wrote this: distutils.core.setup( windows=[ {'script': 'hangman.py', 'icon_resources': [(1, 'HangIcon.ico')], 'other_resources': [(1, '2of12inf.txt')]} ],
Your question says you are using py2app. If you wanted a py2exe specific answer make sure to say so :)
I wanted a py2app answer, and I had figured that once I understood that, I could figure out the py2exe answer - but I wasn't able to. I will post a new thread, I guess.
2

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

2 Comments

Thank you for responding. as "jdi" said, the correct way to do it is specifying it as options = { "resources": ["myfile.txt"] }.
@user1104215: Both methods work. Be sure to click the green check mark next to the answer that works for you.
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.