Python is an interactive and object-oriented programming language. It’s well-regarded for its simplicity and easy syntax that is comparable to the English language. This tutorial will guide you step by step on how to create a Python file using the PowerShell command line.
Step 1: Open the PowerShell
Firstly, you need to open your PowerShell window. You can do this by searching for PowerShell in your system search or by using the “Windows Key + X” shortcut and select PowerShell (Admin).
Step 2: Navigate to the desired directory
After opening PowerShell, navigate to the directory where you want to create your Python file. You can do this with the “cd” command followed by the directory path. For instance:
1 |
cd C:\Users\YourName\Desktop\ |
Step 3: Create the Python File
You can easily create a Python file using the “New-Item” command followed by the desired name of your file and the extension .py. For example, if you wish to create a Python file named “demo”, you can type:
1 |
New-Item demo.py |
This command will create a new Python file named “demo.py” in the location you specified in Step 2.
Step 4: Verify the Python File Creation
After executing the command, verify if the Python file has been created in the desired directory. You can do this using the “ls” or “dir” command in PowerShell:
1 |
ls |
After executing the “ls” command, if the Python file has been created successfully, you will see “demo.py” listed amongst the files in the current directory.
Here is the full code:
1 2 3 |
cd C:\Users\YourName\Desktop\ New-Item demo.py ls |
Conclusion
Congratulations! You have just learned how to create a Python file in PowerShell. This process is straightforward and quick, allowing you to work more efficiently with Python in your coding projects. It may take a bit of practice to get used to the PowerShell commands if you’re new, but with time, it will start to come naturally. Keep coding!