{"id":29062,"date":"2024-11-25T17:01:45","date_gmt":"2024-11-25T09:01:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/29062\/"},"modified":"2024-11-25T17:01:45","modified_gmt":"2024-11-25T09:01:45","slug":"%e8%af%a6%e8%a7%a3python%e8%87%aa%e5%ae%9a%e4%b9%89%e6%a8%a1%e5%9d%97%e3%80%81%e5%8c%85","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/29062\/","title":{"rendered":"\u8be6\u89e3python\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u5305"},"content":{"rendered":"<p>1\u3001\u4fdd\u5b58\u4e00\u4e2ahello.py\u6587\u4ef6\u5728f:\/data\/\u76ee\u5f55\u4e0b<\/p>\n<ul>\n<li>\n<p><span style=\"color: #ff0000\">hello.py<\/span><\/p>\n<\/li>\n<\/ul>\n<pre>&gt;&gt;&gt; def hello(x):    print x<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\n<p><span style=\"color: #ff0000\">\u76ee\u5f55<\/span><\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/013\/d65147672e5c01ded7517b7fd942621f-0.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u8be6\u89e3python\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u5305\u63d2\u56fe\" alt=\"\u8be6\u89e3python\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u5305\u63d2\u56fe\" \/><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>\n<p>\u5bfc\u5165<\/p>\n<\/li>\n<\/ul>\n<pre>&gt;&gt;&gt; import sys&gt;&gt;&gt; sys.path.append('F:\/data\/python') #\u6dfb\u52a0\u8def\u5f84\uff0c\u6b64\u6dfb\u52a0\u662f\u4e00\u6b21\u6027\u7684&gt;&gt;&gt; import hello&gt;&gt;&gt; hello.hello(5)  #\u8c03\u75285<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp;2\u3001\u4e0d\u6539\u53d8sys.path\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757\uff1a<\/p>\n<p>\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff1a\u5c06hello2.py\u6587\u4ef6\u653e\u5728D:\/Python27\/lib\/site-packages\u76ee\u5f55\u4e0b<\/p>\n<\/p>\n<pre>&gt;&gt;&gt; import sys,pprint&gt;&gt;&gt; pprint.pprint(sys.path)\r\n['', 'D:\\Python27\\Lib\\idlelib', 'F:\\data\\s', 'D:\\Python27', 'C:\\Windows\\system32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\\lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27\\lib\\site-packages']&gt;&gt;&gt; import hello2&gt;&gt;&gt; hello2.hello()\r\nhello,world!<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp;\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff1a\u5c06F:\/data\/python\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\uff08\u5728\u4e2d\uff0c\u6dfb\u52a0PYTHONPATH\u53d8\u91cf\uff0c\u518d\u5c06\u8def\u5f84\u6dfb\u52a0\u5230\u503c\u4e2d\uff09<\/p>\n<\/p>\n<pre>&gt;&gt;&gt; import sys&gt;&gt;&gt; import hello&gt;&gt;&gt; hello.hello(1)1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp;3\u3001\u81ea\u5b9a\u4e49\u5305\uff0c\u5bfc\u5165\u6a21\u5757<\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u5982\u4e0b\u76ee\u5f55\uff0cpytest\u4e3a\u5305\uff0c\u5c06\u8def\u5f84F: est\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cfPYTHONPATH\u4e2d\uff0cpytest\u5305\u4e2dinit.py\u6587\u4ef6\u662f\u5fc5\u8981\u7684\uff0c\u5185\u5bb9\u53ef\u4ee5\u4e3a\u7a7a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/000\/013\/d65147672e5c01ded7517b7fd942621f-1.png\" style=\"max-width:90%\" class=\"aligncenter\" title=\"\u8be6\u89e3python\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u5305\u63d2\u56fe1\" alt=\"\u8be6\u89e3python\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u5305\u63d2\u56fe1\" \/><\/p>\n<\/p>\n<pre>&gt;&gt;&gt; import sys&gt;&gt;&gt; from pytest import hello&gt;&gt;&gt; hello.hello(4)4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u8be6\u89e3python\u81ea\u5b9a\u4e49\u6a21\u5757\u3001\u5305 \u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4fdd\u5b58\u4e00\u4e2ahello.py\u6587\u4ef6\u5728f:\/data\/\u76ee\u5f55\u4e0b hello.py &gt;&gt;&gt; def hello(x): print x \u767b\u5f55\u540e\u590d\u5236 \u76ee\u5f55 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5bfc\u5165 &gt;&gt;&gt; import sys&gt;&gt;&gt; sys.path.append(&#8216;F:\/data\/python&#8217;) #\u6dfb\u52a0\u8def\u5f84\uff0c\u6b64\u6dfb\u52a0\u662f\u4e00\u6b21\u6027\u7684&gt;&gt;&gt; import hello&gt;&gt;&gt; hello.hello(5) #\u8c03\u75285 \u767b\u5f55\u540e\u590d\u5236 &nbsp;2\u3001\u4e0d\u6539\u53d8sys.path\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757\uff1a \u7b2c\u4e00\u79cd\u65b9\u6cd5\uff1a\u5c06hello2.py\u6587\u4ef6\u653e\u5728D:\/Python27\/lib\/site-packages\u76ee\u5f55\u4e0b &gt;&gt;&gt; import sys,pprint&gt;&gt;&gt; pprint.pprint(sys.path) [&#8221;, &#8216;D:\\Python27\\Lib\\idlelib&#8217;, &#8216;F:\\data\\s&#8217;, &#8216;D:\\Python27&#8217;, &#8216;C:\\Windows\\system32\\python27.zip&#8217;, &#8216;D:\\Python27\\DLLs&#8217;, &#8216;D:\\Python27\\lib&#8217;, &#8216;D:\\Python27\\lib\\plat-win&#8217;, &#8216;D:\\Python27\\lib\\lib-tk&#8217;, &#8216;D:\\Python27\\lib\\site-packages&#8217;]&gt;&gt;&gt; import hello2&gt;&gt;&gt; hello2.hello() hello,world! \u767b\u5f55\u540e\u590d\u5236 &nbsp;\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff1a\u5c06F:\/data\/python\u8def\u5f84\u6dfb\u52a0\u5230\u73af\u5883\uff08\u5728\u4e2d\uff0c\u6dfb\u52a0PYTHONPATH\u53d8\u91cf\uff0c\u518d\u5c06\u8def\u5f84\u6dfb\u52a0\u5230\u503c\u4e2d\uff09 &gt;&gt;&gt; import sys&gt;&gt;&gt; import hello&gt;&gt;&gt; hello.hello(1)1 \u767b\u5f55\u540e\u590d\u5236 &nbsp;3\u3001\u81ea\u5b9a\u4e49\u5305\uff0c\u5bfc\u5165\u6a21\u5757 \u9996\u5148\uff0c\u521b\u5efa\u5982\u4e0b\u76ee\u5f55\uff0cpytest\u4e3a\u5305\uff0c\u5c06\u8def\u5f84F: est\u6dfb\u52a0\u5230\u73af\u5883\u53d8\u91cfPYTHONPATH\u4e2d\uff0cpytest\u5305\u4e2dinit.py\u6587\u4ef6\u662f\u5fc5\u8981\u7684\uff0c\u5185\u5bb9\u53ef\u4ee5\u4e3a\u7a7a &gt;&gt;&gt; import [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-29062","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29062","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=29062"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/29062\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=29062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=29062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=29062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}