By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

Write a Source File with a lot of directions attached

P: 10
So here is the question:

Write a python source file that defines functions, printForward(list), printReverse(list), and getLength(list), which prints the elements of a list (one element on each line) in order, prints the elements of a list in reverse order, and returns the number of elements in the list, respectively. Write another Python source file (which can be executed from the command line) that imports the original module and demonstrates its functions by calling them.

I'm not really sure where to begin. Can anyone help point me in the right direction......
Nov 30 '06 #1
Share this Question
Share on Google+
3 Replies


bartonc
Expert 5K+
P: 6,596
First, you need tell your operating system (is it windows?) where python is.
Next, you need a directory (folder) to put your modules into.
After that, you need to be able to start a command line (which depend on your OS) and cd (change directory) to that folder.

If you need help with any of these, just say so.

Once you have that, save a text document named anythingyouwant.py (for example).
In that module define your functions like this:
Expand|Select|Wrap|Line Numbers
  1. def somefunction(arguments):
  2.     pass # put you code here
Then in a second file calledfromcmdline.py (for example) write
Expand|Select|Wrap|Line Numbers
  1. import sys
  2. import anythingyouwant
  3.  
  4. anythingyouwant.somefunction(sys.argv[1:])
Then on the command line write

python calledfromcmdline.py here is a list of args
Dec 1 '06 #2

P: 10
I'm sorry to be slow, but I understand the first part...but where does the printForward(list), printReverse(list), etc. come in? Or is that the functions I'm supposed to be writing? Thank you again for the help.
Dec 1 '06 #3

bartonc
Expert 5K+
P: 6,596
Once you have that, save a text document named anythingyouwant.py (for example).
In that module define your functions like this:

Expand|Select|Wrap|Line Numbers
  1. def printForward(arguments):
  2.     for word in arguments:
  3.         print word
  4.  
  5.  

Then in a second file calledfromcmdline.py (for example) write


import sys
import anythingyouwant

anythingyouwant.printForward(sys.argv[1:])


Then on the command line write

python calledfromcmdline.py here is a list of args
Dec 1 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.