Okay, I am in the middle of creating a rather large console RPG. It'll include ability to equip armor, weapons, interacting with NPC's, battles, saving/loading characters, etc. I don't want to save all of my classes and functions in the same file, for easier readability. I have a few questions:
1) Can I import .py files that are in the same folder to a separate .py file?
2) How does this change py2exe? Do I just setup the script for the main one, or all?

Thanks in advance!

Recommended Answers

All 3 Replies

Say I had two files named file_one.py and file_two.py

file_one.py looks like this:

def hello():
    print "hello"

file_two.py can import and use file_one like so:

import file_one # Notice there is no .py file extension 

file_one.hello()

The output should be a console print out of "hello". However I do not use py2exe or windows for that matter so I can not help out in that area.

well for py2exe
just setup the script for the main py file

I'm not 100% sure, because IronPython has a compile to exe function, so I never use py2exe

Yes, py2exe also packages all the imported modules that your program needs.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.