{"id":12776,"date":"2020-12-29T10:43:45","date_gmt":"2020-12-29T18:43:45","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12776"},"modified":"2023-12-01T04:06:26","modified_gmt":"2023-12-01T12:06:26","slug":"python-create-directory","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-create-directory\/","title":{"rendered":"Python Create Directory: A How-To Guide"},"content":{"rendered":"\n<p><em>The Python os.mkdir() method creates a blank directory on your file system. You cannot use this method to create a folder in a folder that does not exist. The os.mkdirs() method recursively creates a blank directory.<\/em><\/p>\n\n\n\n<p>Files let you store data outside a program that can be referenced by a program in the future. When you\u2019re working with files, you may decide to create a new directory in which a file should be stored.<\/p>\n\n\n\n<p>That\u2019s where the Python os module comes in. The os module includes two methods called <em>os.mkdir()<\/em> and <em>os.mkdirs()<\/em> which can be used to create directories in Python.<\/p>\n\n\n\n<p>This tutorial will explore how to create a directory in Python using the <em>os.mkdir()<\/em> and <em>os.mkdirs()<\/em> methods. We will also use a few examples to show how these methods work.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<label for=\"ez-toc-cssicon-toggle-item-69db6f511fe3f\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #000000;color:#000000\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #000000;color:#000000\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69db6f511fe3f\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#python-os-refresher\" >Python os Refresher<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#python-create-directory\" >Python Create Directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#python-create-multiple-directories\" >Python Create Multiple Directories<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"python-os-refresher\"><\/span>Python os Refresher<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Before you can work with files in Python, you need to import the os module. The os module is built-in to Python. It contains a number of methods that can be used to interface with a computer\u2019s underlying operating system.<\/p>\n\n\n\n<p>In this case, we are interested in the os module\u2019s file system methods, which can be used to work with files. We can use a <a href=\"https:\/\/careerkarma.com\/blog\/python-import\/\">Python import statement<\/a> to import os into our program:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"python-create-directory\"><\/span>Python Create Directory<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The <em>os.mkdir()<\/em> method can be used to create a single directory. For example, if we were creating a program that needs a new folder to store its outputs, we would use <em>os.mkdir()<\/em>.<\/p>\n\n\n\n<p>The syntax for the <em>os.mkdir()<\/em> method is as follows:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>os.mkdir(path, access)<\/pre><\/div>\n\n\n\n<p>The <em>os.mkdir()<\/em> function takes in two parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>path<\/strong> is the file path at which you want to create your directory (required)<\/li><li><strong>access<\/strong> refers to the access rights you want to grant your directory (optional)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Python os.mkdir() Example<\/h3>\n\n\n\n<p>Let\u2019s explore an example to showcase how to use the <em>os.mkdir()<\/em> method.<\/p>\n\n\n\n<p>Say we are creating a program that analyzes a list of math student test scores. This program stores whether each student has passed the latest test.<\/p>\n\n\n\n<p>To start, we want to create a directory where our data will be stored. This will ensure that our data will be separate from the rest of our program.<\/p>\n\n\n\n<p>Here\u2019s the code we could use to create a directory for our data:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import os\n\npath = &quot;\/home\/school\/math\/grades\/final&quot;\n\nos.mkdir(path)\n\nprint(&quot;\/home\/school\/math\/grades\/final has been created.&quot;)<\/pre><\/div>\n\n\n\n<p>Our code creates a new directory called <em>final<\/em> in the <em>\/home\/school\/math\/grades<\/em> folder in our operating system. Then, it returns the message:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/home\/school\/math\/grades\/final has been created.<\/pre><\/div>\n\n\n\n<p>The <em>mkdir()<\/em> method can only be used to create one directory at a time. We could not create a folder called <em>final<\/em> and then create a folder within <em>final<\/em> called <em>jan2020.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">os.mkdir() Permissions Example<\/h3>\n\n\n\n<p>We can use the optional <em>access<\/em> parameter to specify the permissions we want our directory to have. By default, the access permissions for the directory <em>mkdir()<\/em> creates is 777. This means the directory is readable and writable by the owner and all other users.<\/p>\n\n\n\n<p>But what if we want to set our own permissions?<\/p>\n\n\n\n<p>Say that our operating system is accessible to multiple teachers, and we only want to grant write access to the owner. We need to use the 755 permission. This permission states a file is readable and accessible by all users. But, only the owner can write to the file.<\/p>\n\n\n\n<p>Here\u2019s the code we could use to create a working directory with custom permissions:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import os\n\npath = &quot;\/home\/school\/math\/grades\/final&quot;\naccess = 0o755\n\nos.mkdir(path, access)\n\nprint(&quot;\/home\/school\/math\/grades\/final has been created.&quot;)<\/pre><\/div>\n\n\n\n<p>We have created a target directory called <em>\/home\/school\/math\/grades\/final.<\/em> This directory has the access permission 755. This means that our file can be read by all users, but only the owner can write to the file. Then, our program prints the message:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/home\/school\/math\/grades\/final has been created.<\/pre><\/div>\n\n\n\n<p>It\u2019s important to note that our <em>access<\/em> variable is equal to <em>0o755<\/em> in our code. We have done this because access rights use the octal prefix, and so we need to specify <em>0o<\/em> before our access parameter.<\/p>\n\n\n\n<p>To learn how to check if a file or directory exists, check out our tutorial on <a href=\"https:\/\/careerkarma.com\/blog\/python-check-if-file-exists\/\">checking if files exist in Python<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"python-create-multiple-directories\"><\/span>Python Create Multiple Directories<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The Python <em>os.makedirs()<\/em> method recursively creates folders. You can use this method to create a folder inside a folder that does not exist. os.mkdirs() accepts one argument: the path of the folder you want to create.<\/p>\n\n\n\n<p>Let&#8217;s take a look at the syntax for os.mkdirs():<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>os.mkdirs(path, access)<\/pre><\/div>\n\n\n\n<p>This method accepts the same arguments as os.mkdir().<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Python os.mkdirs() Example<\/h3>\n\n\n\n<p>There are often cases where we need to create directories that exist within other new directories.<\/p>\n\n\n\n<p>For instance, say we are creating a program that stores our math student test score data. Instead of storing all of our data in one folder, we could store data in multiple folders.<\/p>\n\n\n\n<p>Each folder would correspond with the year and month of the test. Storing data in this way would make our files easier to find if and when we want to refer back to them.<\/p>\n\n\n\n<p>Let\u2019s use our school math test example to illustrate how the <em>os.makedirs()<\/em> method works.<\/p>\n\n\n\n<p>The specifications of our program have changed. Now we want to store data in folders depending on the year and month of the test. We could accomplish this task using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import os\n\npath = &quot;\/home\/school\/math\/grades\/2020\/02&quot;\naccess = 0o755\n\nos.mkdir(path, access)\n\nprint(&quot;\/home\/school\/math\/grades\/2020\/02 has been created.&quot;)<\/pre><\/div>\n\n\n\n<p>Let\u2019s say that we do not yet have a <em>2020<\/em> folder or an <em>02<\/em> folder. This code would first create the <em>2020<\/em> folder, then it would create the folder called <em>02<\/em> within <em>2020<\/em>. We assign this folder the access permissions 755.<\/p>\n\n\n\n<p>After our program creates our folder, it prints out the message:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/home\/school\/math\/grades\/2020\/02 has been created.<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Creating a directory is a common operation in Python when you\u2019re working with files. The <em>os.mkdir()<\/em> method can be used to create a single directory, and the <em>os.makedirs()<\/em> method can be used to create multi-level directories.<\/p>\n\n\n\n<p>This tutorial discussed how to use both <em>os.mkdir()<\/em> and <em>os.makedirs()<\/em> to create folders in Python. We also explored an example of each of these methods in action.<\/p>\n\n\n\n<p>Are you interested in learning more about Python? Check out our complete <a href=\"https:\/\/careerkarma.com\/blog\/how-to-learn-python\/\">How to Learn Python guide<\/a> for expert tips and advice on how to learn this programming language.<\/p>\n","protected":false},"excerpt":{"rendered":"The Python os.mkdir() method creates a blank directory on your file system. You cannot use this method to create a folder in a folder that does not exist. The os.mkdirs() method recursively creates a blank directory. Files let you store data outside a program that can be referenced by a program in the future. When&hellip;","protected":false},"author":240,"featured_media":12778,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-12776","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Create Directory: A How-To Guide: A Tutorial | Career Karma<\/title>\n<meta name=\"description\" content=\"To create a new directory in Python code, you can use the mkdir() or mkdirs() methods. Learn how to use these file methods with this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Create Directory: A How-To Guide\" \/>\n<meta property=\"og:description\" content=\"To create a new directory in Python code, you can use the mkdir() or mkdirs() methods. Learn how to use these file methods with this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-29T18:43:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:06:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"750\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python Create Directory: A How-To Guide\",\"datePublished\":\"2020-12-29T18:43:45+00:00\",\"dateModified\":\"2023-12-01T12:06:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\"},\"wordCount\":1015,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\",\"name\":\"Python Create Directory: A How-To Guide: A Tutorial | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg\",\"datePublished\":\"2020-12-29T18:43:45+00:00\",\"dateModified\":\"2023-12-01T12:06:26+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"To create a new directory in Python code, you can use the mkdir() or mkdirs() methods. Learn how to use these file methods with this article.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-create-directory\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg\",\"width\":1000,\"height\":750},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-create-directory\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Create Directory: A How-To Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Create Directory: A How-To Guide: A Tutorial | Career Karma","description":"To create a new directory in Python code, you can use the mkdir() or mkdirs() methods. Learn how to use these file methods with this article.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/python-create-directory\/","og_locale":"en_US","og_type":"article","og_title":"Python Create Directory: A How-To Guide","og_description":"To create a new directory in Python code, you can use the mkdir() or mkdirs() methods. Learn how to use these file methods with this article.","og_url":"https:\/\/careerkarma.com\/blog\/python-create-directory\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-12-29T18:43:45+00:00","article_modified_time":"2023-12-01T12:06:26+00:00","og_image":[{"width":1000,"height":750,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python Create Directory: A How-To Guide","datePublished":"2020-12-29T18:43:45+00:00","dateModified":"2023-12-01T12:06:26+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/"},"wordCount":1015,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-create-directory\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/","url":"https:\/\/careerkarma.com\/blog\/python-create-directory\/","name":"Python Create Directory: A How-To Guide: A Tutorial | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg","datePublished":"2020-12-29T18:43:45+00:00","dateModified":"2023-12-01T12:06:26+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"To create a new directory in Python code, you can use the mkdir() or mkdirs() methods. Learn how to use these file methods with this article.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-create-directory\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/turned-on-white-laptop-computer-968631-1.jpg","width":1000,"height":750},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-create-directory\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Create Directory: A How-To Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12776"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12776\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12778"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}