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.

G Surendar Thina
  • 36
  • 1
  • 1
  • 7
  • 3
    Are you just looking to create an empty file that has a python extention? Because then [this](http://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line) should answer your question. Also python's file ending is `.py`, not `.python`. – SuperBiasedMan Jul 16 '15 at 13:49
  • Yes! I want to make a file with .py extension – G Surendar Thina Jul 16 '15 at 13:54
  • Does this answer your question? [How to create an empty file at the command line in Windows?](https://stackoverflow.com/questions/1702762/how-to-create-an-empty-file-at-the-command-line-in-windows) – AMC Oct 29 '20 at 00:28

6 Answers6

16
TYPE CON>test.py

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

Victor Yan
  • 3,339
  • 2
  • 28
  • 28
  • 4
    @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). – Eryk Sun Jul 16 '15 at 16:20
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.

1

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

andrewJames
  • 19,570
  • 8
  • 19
  • 51
  • 2
    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](/help/how-to-answer). – Community Oct 10 '21 at 15:21
1

Use the command: touch fileName.py

andrewJames
  • 19,570
  • 8
  • 19
  • 51
-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

yavuzx
  • 1
-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.stack.imgur.com/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.