<< Chapter < Page Chapter >> Page >

Setting the path with a batch file

Listing 1 shows the contents of a batch file named 1359-1050-01.bat containing four commands that :

  1. Reduce the clutter on the output screen (echo off) .
  2. Temporarily set the path to the location of the file named python.exe on my computer.
  3. Attempt to execute the Python script file named 1359-1050-01.py, which will be discussed later in this module.
  4. Pause onscreen and wait to be dismissed with the prompt "Press any key to continue . . ."
Listing 1 . Setting the path temporarily with a batch file.
echo off path=%path%;"C:\Program Files (x86)\Python34"python 1359-1050-01.py pause

The second command in Listing 1 is the important command for thissection of this module. It will temporarily set the path to the indicated folder. If you elect to use this approach, you will need toreplace the text inside the double quotes with the path to the folder containing the file named python.exe on your computer.

This approach appends the new path onto the environment variable named path on a temporary basis. It goes away as soon as you respond to the pause statement at the end or otherwise close the command-line window that appears when you execute the batch file.

Create a script file

Once you have the path variable properly set, or you know how to set it temporarily in a batch file, use the text editor of your choice andcreate a file named 1359-1050-01.py that contains the Python programming statements shown in Listing 2 . (You can give the file any name that you chooseprovided that the extension is .py and provided that you properly reflect the name in the third line of the batch file shown in Listing 1 .)

Listing 2 . Contents of the file named 1359-1050-01.py.
a=2 b=3a=2*a b=3*bc=a+b print(c)

You should recognize all of the statements in Listing 2 . Note, however, that in a script, they are not preceded by an interactive prompt (>>>).

Store this file in any folder on your hard drive. You may want to create a new directory for the sole purpose of storing Python script files.

Then create the corresponding batch file with the contents shown in Listing 1 and save it in the same folder as the script file. (If you have permanently set your path to support Python, you can omit the path command in Listing 1 .)

Run your script file

Once you have accomplished the above, double-click the batch file to execute it. The batch file will temporarily set the path and attempt to run your script.If all goes well, a command-line window will appear on your screen with contents similar to that shown in Figure 1 . (Note that I deleted some of the text on the first line for brevity. Your first line will be different anyway.)

Figure 1 . Screen output from running the script named 1359-1050-01.py.
M:\Baldwin\AA-School\...>echo off 13Press any key to continue . . .

The correct output

If you go back to the script file in Listing 2 and do the arithmetic, you will see that the output value of 13 produced by the program is correct.

If you got an output value of 13, -- congratulations -- you have just written and executed your first Python script. If not, try to figure out why.

Questions & Answers

How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
How can I make nanorobot?
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
how can I make nanorobot?
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Itse 1359 introduction to scripting languages: python. OpenStax CNX. Jan 22, 2016 Download for free at https://legacy.cnx.org/content/col11713/1.32
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Itse 1359 introduction to scripting languages: python' conversation and receive update notifications?