473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Write a Source File with a lot of directions attached

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
3 1057
bartonc
6,596 Expert 4TB
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
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
6,596 Expert 4TB
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

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

Similar topics

7
by: Olivier Mandavy | last post by:
Hello, i'm looking for guidelines about what are the comments to be written at the beginning of source files. Thanks a lot. Olivier
3
by: Farooq Khan | last post by:
why does Response.Write in a method of code-beind class when called from inpage code (i.e in <%---%>), after creating object of that class, fails when called while it works perfectly ok while...
8
by: mosscliffe | last post by:
I am an old programmer, but a newbie to Visual Web Developer 2005 - Express Edition I have an .aspx Form Page with an attached Master File and an attached css file. I have scanned a text...
5
by: randy1200 | last post by:
Microsoft seems to do a great job of using very nice button graphics for standard functions like Print, Print Preview, Close, etc. Can anyone point me to a source on the web for standard button...
4
windows_mss
by: windows_mss | last post by:
When I Select Source & Destination Dynamically, Path Getting Scatter Across The Map... hi, i can able to get the Correct Route and Path for the corresponding Source and destination, like...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
25
by: mereba | last post by:
Hello My country Ghana is changing its currency. I want to write a small programme in C++ that can covert from the old currency into the new one. I would like this programme to run behind a simple...
10
by: cjard | last post by:
I have a client and server that enjoy the following simple dialogue: Client connects Client sends request Server sends response Client disconnects This is the way it must be. The response...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.