Reputation: 27
I'm trying to learn Python from a tutorial. I'm supposed to create a folder using mkdir
, but when I try that, I see this result:
> python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> mkdir mystuff
File "<stdin>", line 1
mkdir mystuff
^
SyntaxError: invalid syntax
I couldn't figure this out from the tutorial. What is wrong here, and how do I fix it?
Upvotes: 1
Views: 7896
Reputation: 11
Exit from Python first by typing quit()
and pressing the Enter key, and then use the mkdir mystuff
command. This command should be used outside of python.
Upvotes: 1
Reputation: 280778
The command mkdir mystuff
needs to be used from the system command line, not Python.
Upvotes: 5
Reputation: 11
Before running the mkdir command, press Ctrl+Z to exit Python. It should look like this:
> python
ActivePython 2.6.5.12 (ActiveState Software Inc.) based on
Python 2.6.5 (r265:79063, Mar 20 2010, 14:22:52) [MSC v.1500 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z
> mkdir mystuff
> cd mystuff
The screen will display ^Z
to indicate that Ctrl+Z was pressed.
Upvotes: 1
Reputation: 1849
To create a new folder from within Python, use:
import os
os.mkdir(path)
To run the shell command from within Python, use:
os.system('mkdir path')
Upvotes: 2
Reputation: 2019
mkdir
is used at the command line to make a directory (folder). For example, mkdir mystuff
makes a directory named mystuff
.
This needs to be run with the command line, not python.
Upvotes: -1