{"id":691,"date":"2013-02-28T16:50:01","date_gmt":"2013-02-28T13:50:01","guid":{"rendered":"http:\/\/www.fatihacar.com\/blog\/?p=691"},"modified":"2013-02-28T16:50:48","modified_gmt":"2013-02-28T13:50:48","slug":"python-commands-and-functions","status":"publish","type":"post","link":"http:\/\/www.fatihacar.com\/blog\/python-commands-and-functions\/","title":{"rendered":"Python Commands and Functions"},"content":{"rendered":"<p><strong>Take value from user.<\/strong><\/p>\n<blockquote><p>\n<strong>input(&#8220;Enter a number : &#8220;) <\/strong><br \/>\n<strong>raw_input(&#8220;Enter a character : &#8220;)<\/strong>\n<\/p><\/blockquote>\n<p><strong>Counters<\/strong><\/p>\n<blockquote><p>\n<strong>range(100)<\/strong> # write from 0 to 100<br \/>\n<strong>range(100,200)<\/strong> # write from 100 to 200<br \/>\n<strong>range(100,200,2)<\/strong> # write from 100 to 200 as 2 by 2<br \/>\n<strong>len(&#8220;Fatih&#8221;)<\/strong> # character count result 5\n<\/p><\/blockquote>\n<p><strong>File and Directory Operations<\/strong><\/p>\n<blockquote><p>\n<strong>listdir(&#8220;\/home&#8221;\/)<\/strong> # list all file or directory in \/home\/ directory<\/p>\n<p>a=os.listdir(&#8220;\/home\/&#8221;)<br \/>\nfor files in a:<br \/>\n   print files<\/p>\n<p><strong>getcwd()<\/strong> # show current directory<br \/>\n<strong>chdir(&#8220;\/var\/lib&#8221;)<\/strong> # change directory<br \/>\n<strong>mkdir(&#8220;test&#8221;)<\/strong> # create directory<br \/>\n<strong>makedirs(&#8220;\/test\/test1\/test2&#8221;)<\/strong> # create nested directories<br \/>\n<strong>rmdir(&#8220;test&#8221;)<\/strong> # remove directory<br \/>\n<strong>removedirs(&#8220;\/test\/test1\/test2&#8221;)<\/strong> # remove directories<br \/>\n<strong>open(&#8220;test.txt&#8221;,&#8221;w&#8221;)<\/strong> # create file and <strong>delete all exist<\/strong> values and open with write mode<br \/>\n<strong>open(&#8220;test.txt&#8221;,&#8221;a&#8221;)<\/strong> # open exist file with append mode<br \/>\n<strong>open(&#8220;test.txt&#8221;,&#8221;r&#8221;)<\/strong> # open exist file with read mode<\/p>\n<p>file_a.open(&#8220;test.txt&#8221;,&#8221;w&#8221;)<br \/>\nfile_a.write(&#8220;Hello World with Python !&#8221;)<br \/>\nfile_a.close()<\/p>\n<p>file_a.open(&#8220;test.txt&#8221;,&#8221;r&#8221;)<br \/>\nfile_a.read()<br \/>\nfile_a.readlines() # read line by line<\/p>\n<p><strong>remove(&#8220;test.txt&#8221;)<\/strong> # delete file<br \/>\n<strong>rename(&#8220;test.txt&#8221;,&#8221;test1234.txt&#8221;)<\/strong> # rename file<br \/>\n<strong>str(a)<\/strong> # convert to string<br \/>\n<strong>int(a)<\/strong> # convert to integer<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Take value from user. input(&#8220;Enter a number : &#8220;) raw_input(&#8220;Enter a character : &#8220;) Counters range(100) # write from 0 to 100 range(100,200) # write from 100 to 200 range(100,200,2) # write from 100 to 200 as 2 by 2 len(&#8220;Fatih&#8221;) # character count result 5 File and Directory Operations listdir(&#8220;\/home&#8221;\/) # list all file&#8230;<\/p>\n","protected":false},"author":37,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[97],"tags":[31,35,33,22],"class_list":["post-691","post","type-post","status-publish","format-standard","hentry","category-python","tag-linux-administration","tag-programming","tag-python","tag-system-administration"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p39NFI-b9","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/691","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/comments?post=691"}],"version-history":[{"count":2,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/691\/revisions"}],"predecessor-version":[{"id":693,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/posts\/691\/revisions\/693"}],"wp:attachment":[{"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/media?parent=691"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/categories?post=691"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fatihacar.com\/blog\/wp-json\/wp\/v2\/tags?post=691"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}