This same function has been written in several languages. . . Not in NetRexx that I know of. /* Some original comments have been marked with REXX comments tags Let’s take a look at an example program that uses some of the program flow
which was discussed in this chapter. The example program simply makes use of an
external text file to manage a list of players on a sports team. You will see
how to follow proper program structure and use spacing effectively in this
example. You will also see file utilization in action, along with utilization
of the raw_input() function. */ /*Listing 3-26. # import os module */. import os
# Create empty dictionary
player_dict = {}
# Create an empty string
enter_player = ''
# Enter a loop to enter inforation from keyboard -- NB: obviously 'information'
while enter_player.upper() != 'X':
print 'Sports Team Administration App'
# If the file exists, then allow us to manage it, otherwise force creation.
if os.path.isfile('players.txt'):
enter_player = raw_input("Would you like to create a team or manage an existing team?\n (Enter 'C' for create, 'M' for manage, 'X' to exit) ")
else:
# Force creation of file if it does not yet exist.
enter_player = 'C'
# Check to determine which action to take. C = create, M = manage, X = Exit and Save
if enter_player.upper() == 'C':
# Enter a player for the team
print 'Enter a list of players on our team along with their position'
enter_cont = 'Y'
# While continuing to enter new player's, perform the following
while enter_cont.upper() == 'Y':
# Capture keyboard entry into name variable
name = raw_input('Enter players first name: ')
# Capture keyboard entry into position variable
position = raw_input('Enter players position: ')
# Assign position to a dictionary key of the player name
player_dict[name] = position
enter_cont = raw_input("Enter another player? (Press 'N' to exit or 'Y' to continue)")
else:
enter_player = 'X'
# Manage player.txt entries
elif enter_player.upper() == 'M':
# Read values from the external file into a dictionary object
print
print 'Manage the Team'
# Open file and assign to playerfile
playerfile = open('players.txt','r')
# Use the for-loop to iterate over the entries in the file
for player in playerfile:
# Split entries into key/value pairs and add to list
playerList = player.split(':')
# Build dictionary using list values from file
player_dict[playerList[0]] = playerList[1]
# Close the file
playerfile.close()
print 'Team Listing'
print '++++++++++++'
# Iterate over dictionary values and print key/value pairs
for i, player in enumerate(player_dict):
print 'Player %s Name: %s -- Position: %s' %(i, player, player_dict[player])
else:
# Save the external file and close resources
if player_dict:
print 'Saving Team Data...'
# Open the file
playerfile = open('players.txt','w')
# Write each dictionary element to the file
for player in player_dict:
playerfile.write('%s:%s\n' % (player.strip(),player_dict[player].strip()))
# Close file
playerfile.close() _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Hello Robert,
1.) Would you mind to tell us *in which Languge* yoiur included program *is written* ? 2.) Could you send me, please the players.txt file? 3.) Then I dould send you the NetRexx Version back using (using my RexxFile and RexxMsg methods, which are very similar, by the way!) Kind regards, from Vienna, Thomas. ======================================================== Am 30.09.2011 02:00, schrieb Robert Hamilton:
--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org) _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Thomas Schneider, Vienna, Austria (Europe) :-)
www.thsitc.com www.db-123.com |
On Fri, Sep 30, 2011 at 6:57 PM, Thomas Schneider <[hidden email]> wrote: --
It looks like the Python example that can be found here: http://www.jython.org/jythonbook/en/1.0/OpsExpressPF.html. Regards, Hugh _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Hugh,
thanks a lot for the hint. Never looke at Python etc up for now (to many other still opened issues). Bob, Do you have a 'players.txt' file as a startup ? Thomas. ======================================================== .Am 30.09.2011 20:50, schrieb Hugh Sweeney:
--
Thomas Schneider (Founder of www.thsitc.com) Member of the Rexx Languge Asscociation (www.rexxla.org) Member of the NetRexx Developer's Team (www.netrexx.org) _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Thomas Schneider, Vienna, Austria (Europe) :-)
www.thsitc.com www.db-123.com |
Free forum by Nabble | Edit this page |