Reputation: 36
I tried the following code to create a python file of the name "test.py"
edit test.py
This command is not recognised as an internal command. Please suggest me an alternative code for creating a new python file using command line in windows. I have my python already installed in my computer and I have set the path variable too also.
Thanks.
Upvotes: 0
Views: 116837
Reputation: 598
Works for me on Windows 10. To create and open a new .py file with:
idle filename.py
pycharm64 filename.py
Upvotes: 0
Reputation: 11
To create new files using cmd i found these two ways
First way: enter this command in cmd
notepad "text.py"
like what I did on my laptop
C:\Users\MAM\Desktop>notepad "text.py"
but it will ask to create one and you should accept to create one.
Second way:
You can type tis command in cmd to create a new file withot asking you to create one.
echo > test.py
like below
C:\Users\MAM\Desktop>echo > test.py
hope it help
Upvotes: 0
Reputation: 11
To create a new python file from the command prompt for windows(cmd), the command is:
echo> filename.py
Upvotes: 1
Reputation: 181
You can use Node.js package called touch for creating python file in cmd
npm install touch-cli -g
touch filename.py
Upvotes: 0
Reputation: 1458
Given that you are in the working directory, you can create Python file via Windows cmd
using following command:
echo print("Hello") > myFile.py
Echo
prints the text as an argument and >
points to the file instead of printing the line in the command prompt. As a result this will create a file with the print statement
Upvotes: 0
Reputation: 1
You can do it two ways you can activate the created virtual environment on cmd and then type in notepad filename.py or if you want to use an advanced text editor such as sublime What you can do is you can download & install the sublime text editor on your system, suppose if you install sublime text editor copy the path of the folder of sublime text editor on to the environment variables on the system.
[you can see my sublime exe file name is subl from the image link below]
you can see the image by clicking this link https://i.sstatic.net/NRFJE.png
so I just activate the virtual environment and type in subl filename.py in cmd so it opens the sublime text editor then type in your code and save it and after that you can run it by typing in filename.py. In this way you can create a file in virtual environment using notepad or other text editors.
Upvotes: -1
Reputation: 1
if you want to create a new python file in your current directory using a terminal, you can use the following commands.
Windows:
python > fileName.py
Mac:
python3 > fileName.py
Upvotes: -1
Reputation: 21
To create a new python file in your current working directory(cwd) use the following command in your terminal:-type NUL > 'test.py'
1.Here I have created a new python file named "test".....Here 'NUL' stands for an empty file.
2.In above command you can use any name that you want.....but be careful to mention the extension,like in our case(.py).
3.Using this command you can create new file of any type in your cwd.
4.After typing this command.....cmd might prompt an error.....but check in your directory....there will be a new file present.
Upvotes: 2
Reputation: 3509
TYPE CON>test.py
To terminate, hit Ctrl+C or Ctrl+Z,Enter (Ctrl+Z = EOF).
Upvotes: 17