0

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.

3
  • 3
    Are you just looking to create an empty file that has a python extention? Because then this should answer your question. Also python's file ending is .py, not .python. Commented Jul 16, 2015 at 13:49
  • Yes! I want to make a file with .py extension Commented Jul 16, 2015 at 13:54
  • Does this answer your question? How to create an empty file at the command line in Windows? Commented Oct 29, 2020 at 0:28

11 Answers 11

17
TYPE CON>test.py

To terminate, hit Ctrl+C or Ctrl+Z,Enter (Ctrl+Z = EOF).

Sign up to request clarification or add additional context in comments.

1 Comment

@GSurendarThina, if you want to create and edit a new file, just use notepad test.py. 64-bit Windows doesn't ship with a console text editor. The old edit DOS program is only available in 32-bit Windows, which has the NT Virtual DOS Machine (NTVDM).
4

To make a py file in cmd you can also use notepad test.py

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
2

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.

Comments

2

To create a new python file from the command prompt for windows(cmd), the command is:

echo> filename.py

4 Comments

Could you please edit your answer to make it more clear to others? As it stands, it looks more like a comment, not an answer.
i hope it is better now
It's better now. Is it enough though? 1) Which command interpreter do you use, cmd or powershell? 2) Why is there a dot right after echo? 3) Let's assume it's a typo, meaning a space is expected before the dot, but what's the point of using . as part of a Python program?
Oh thanks, the period after the echo was a mistake and i have included the command prompt i was referring to. Thanks for pointing it out
1

Use the command: touch fileName.py

1 Comment

Please add some more details to your answer, like a reference.
0

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 file with echo contents

Comments

0

You can use Node.js package called touch for creating python file in cmd

npm install touch-cli -g
touch filename.py

Comments

0

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

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

Works for me on Windows 10. To create and open a new .py file with:

  • IDLE: idle filename.py
  • PyCharm (LightEdit mode):pycharm64 filename.py

Comments

-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

Comments

-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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.