<< 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 does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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?

Ask