File: pyedit-products/unzipped/docetc/examples/RunCode-examples/testRunCodeCapture.py

# Untitled3.py, but also write files to script's dir 3 ways to verify context.
# These 3 files should show up (be written or rewtitten) in this script's dir. 
# This also tests a command-line argument and 2 stdin input lines (numbers all).

import sys, os

poopyheads = input('How many poopyheads? ')            # input line
for i in range(int(poopyheads)):
    print('my brother is a', 'poopyhead' * (i+1))

print()
buttheads = sys.argv[1]                                # command-line arg
for i in range(int(buttheads)):
    print('my brother is a', 'butthead' * (i+1))

print()
chuckleheads = input('How many chuckleheads? ')        # input line
for i in range(int(chuckleheads)):
    print('my brother is a', 'chucklehead' * (i+1))


# all 3 files should show up in same dir as script
myfilelessext = os.path.splitext(__file__)[0]
mybasename    = os.path.basename(myfilelessext)

dotname = 'testRunCodeCapture-savedot.txt'
absname = myfilelessext + '-saveabs.txt'
relname = mybasename + '-saverel.txt'

open(dotname, 'w').write('ph: ' + poopyheads)
open(absname, 'w').write('bh: ' + sys.argv[1])
open(relname, 'w').write('ch: ' + chuckleheads)



[Home page] Books Code Blog Python Author Train Find ©M.Lutz