Back to Coding

How Do You Make a Script Take Input?

How Do You Make a Script Take Input?
AI Tutorials Team 31 March 2026

The first script has the folder name, the date range and the settings written into it. That works exactly once, and changing them means editing the code, which is the point at which most people's scripts stop being used.

What are the ways to take input?

  • Asking during the run. The script pauses and waits for you to type something.
  • Command line arguments. Supplied when you start the script.
  • A settings file. Values kept separately and read at the start.
  • Environment variables. Used mainly for credentials.

Which should a beginner use?

Asking during the run, first, because it is the simplest and the feedback is immediate. Command line arguments come next and are worth learning once you run something regularly, since they let you repeat a run without retyping.

A settings file makes sense when there are more than three or four values.

What is the mistake everybody makes?

Forgetting that input arrives as text. Type the number five and you get the character five, not the value, and adding one to it produces an error or joins them together depending on the language.

Converting input to the type you need, immediately, is the habit that prevents a whole category of confusion.

What should you do with unexpected input?

Check it before using it. A script that asks for a folder should confirm the folder exists; one that asks for a number should confirm it received one. Without that, a typo produces a failure several lines later where the cause is not obvious.

Add checks on every input. If the folder does not exist, or the value is not a number, print a clear message saying what was wrong and stop, rather than continuing with a bad value.

Why stop rather than guess?

Because guessing is how a script does something unintended. A missing folder that gets created silently, or an invalid date that defaults to today, both produce a result that looks successful and is wrong.

Failing clearly is a feature rather than a limitation.

Where should credentials go?

Never in the script. Passwords and keys typed into code end up in copies, in screenshots and in anything you share, and this is the single most common way a beginner exposes something.

Environment variables or a separate file that is excluded from sharing are the standard answers, and asking how to do that for your setup is worth the two minutes.

What about defaults?

Useful and worth being careful with. A default that makes the common case quick is good; a default that silently applies when you meant to supply something is how the wrong folder gets processed.

Printing what values are being used, at the start of the run, resolves this entirely.

What is the small habit worth adopting?

Have the script announce what it is about to do before doing it. Reading a line saying it will process forty files in a named folder, and writing results to another named folder, catches the wrong-input error at the only moment when it is still free to fix.