Imported or executed?

S

Stephan Schulz

Hi All,

I've written a Python replacement of fixbb, as shell/awk script that
will create tightly fitting bounding boxes for PostScript files.

Most of the functionality is encapsulated in a small function called
fixbb(filename). I'm importing this into other code via 'import'.

A few lines of code for command line handling make the module into a
freestanding program. For simplicity and ease of maintenance, I would
rather keep library and program as a single file.

However, the command line code is also executed when the module is
imported, not only when the stand-alone program is executed. That is
not, of course, intended (or working).

Is there a (portable, standard) way for the program/module to find out
if it is imported or executed stand-alone?

You can find the code at
http://www.eprover.org/SOFTWARE/utilities.html

Bye,

Stephan
 
J

Jeff Shannon

Stephan said:
Is there a (portable, standard) way for the program/module to find out
if it is imported or executed stand-alone?

def fixbb(*filelist):
# ...

if __name__ == '__main__':
# Executed stand-alone
fixbb(sys.argv[1:])

(Obviously, you'd probably want to do more command-line checking than
this...)

Jeff Shannon
Technician/Programmer
Credit International
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top