-
Notifications
You must be signed in to change notification settings - Fork 1
/
Python 2
340 lines (257 loc) · 13.7 KB
/
Python 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<!DOCTYPE HTML>
<html lang="zh-TW">
<head>
<!--Setting-->
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-siteapp">
<meta http-equiv="Cache-Control" content="no-transform">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta name="apple-mobile-web-app-capable" content="Tin Blog">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no,email=no,adress=no">
<meta name="browsermode" content="application">
<meta name="screen-orientation" content="portrait">
<meta name="theme-version" content="1.3.0">
<meta name="root" content="/">
<link rel="dns-prefetch" href="http://s2339956.github.io">
<!--SEO-->
<meta name="keywords" content="{{ page.keywords }}" />
<meta name="description" content=" Python 神奇的 Join 使用
最近開始嘗試寫 blog, 記錄一些過程但每次都必須要輸入一些指令 生成 部署實在讓我有點煩, 懶惰癌無限擴張自己寫了一個 python 的小軟件讓..." />
<meta name="robots" content="all" />
<meta name="google" content="all" />
<meta name="googlebot" content="all" />
<meta name="verify" content="all" />
<!--Title-->
<title>
Python join 語法使用 |
Tin Blog
</title>
<link rel="alternate" href="/atom.xml" title="Tin Blog" type="application/atom+xml">
<link rel="icon" href="/img/favicon.png">
<link rel="stylesheet" href="/css/bootstrap.min.css?rev=3.3.7.css">
<link rel="stylesheet" href="/css/font-awesome.min.css?rev=4.7.0.css">
<link rel="stylesheet" href="/css/style.css?rev=@@hash.css">
<div class="hide">
<script type="text/javascript">
var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cspan class='cnzz_stat_icon_1263868967 hide' %3E%3Cscript%20src%3D%22https%3A%2F%2Fs95.cnzz.com%2Fz_stat.php%3Fweb_id%3D1272564536%22%3E%3C%2Fscript%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1263868967%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
</script>
</div>
<script>
(function(i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-109722991-1', 'auto');
ga('send', 'pageview');
</script>
<meta name="generator" content="Hexo 5.2.0"></head>
<!--[if lte IE 8]>
<style>
html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低,为了你更好的阅读体验,请更新浏览器的版本或者使用其他现代浏览器,比如Chrome、Firefox、Safari等。</div>
<![endif]-->
<body>
<header class="main-header" style="background-image:url(
https://hexo-theme-snippet-1251680922.cos.ap-beijing.myqcloud.com/img/banner.jpg)"
>
<div class="main-header-box">
<a class="header-avatar" href="/" title='Tin'>
<img src="/img/avatar.jpg" alt="logo头像" class="img-responsive center-block">
</a>
<div class="branding">
<!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
<h2>
星星給予仰望者光芒
</h2>
</div>
</div>
</header>
<nav class="main-navigation">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="navbar-header"><span class="nav-toggle-button collapsed pull-right" data-toggle="collapse" data-target="#main-menu" id="mnav">
<span class="sr-only"></span>
<i class="fa fa-bars"></i>
</span>
<a class="navbar-brand" href="http://s2339956.github.io">
Tin Blog</a>
</div>
<div class="collapse navbar-collapse" id="main-menu">
<ul class="menu">
<li role="presentation" class="text-center">
<a href="/"><i class="fa fa-home"></i>
首頁</a>
</li>
<li role="presentation" class="text-center">
<a href="/archives/"><i class="fa fa-archive"></i>
彙整</a>
</li>
<li role="presentation" class="text-center">
<a href="/about/"><i class="fa fa-user"></i>
About</a>
</li>
<li role="presentation" class="text-center">
<a href="/archives/"><i class="fa fab fa-line"></i>
時間軸</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<section class="content-wrap">
<div class="container">
<div class="row">
<main class="col-md-8 main-content m-post">
<p id="process"></p>
<article class="post">
<div class="post-head">
<h1 id="Python join 語法使用">
Python join 語法使用
</h1>
<div class="post-meta">
<span class="categories-meta fa-wrap">
<i class="fa fa-folder-open-o"></i>
</span>
<span class="fa-wrap">
<i class="fa fa-tags"></i>
<span class="tags-meta">
<a class="tag-none-link" href="/tags/Python/" rel="tag">Python</a>
</span>
</span>
<span class="fa-wrap">
<i class="fa fa-clock-o"></i>
<span class="date-meta">
2017/11/19</span>
</span>
<span class="fa-wrap">
<i class="fa fa-eye"></i>
<span id="busuanzi_value_page_pv"></span>
</span>
</div>
<p class="fa fa-exclamation-triangle warning">
本文于<strong>
1380</strong>
天之前發表,文章内容可能已經過時。
</p>
</div>
<div class="post-body post-content">
<p> Python 神奇的 Join 使用</p>
<a id="more"></a>
<p>最近開始嘗試寫 blog, 記錄一些過程<br>但每次都必須要輸入一些指令 生成 部署<br>實在讓我有點煩, 懶惰癌無限擴張<br>自己寫了一個 python 的小軟件<br>讓我只要確認路徑正確, 按下確定, 就能讓它自己完成這些小事情<br>就剛好使用了, 這個方法來打印出相關資訊</p>
<h3 id="展示一下用法"><a href="#展示一下用法" class="headerlink" title="展示一下用法"></a>展示一下用法</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 為自己 Hexo 的安装路徑</span></span><br><span class="line">hexo_install_folder = self.userinput</span><br><span class="line">target_folder_path = str(hexo_install_folder + <span class="string">'/source/_posts/'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 當前目錄下所有 檔案名稱 是個陣列 Array</span></span><br><span class="line">cur_filename_list = os.listdir(cur_folder_path)</span><br><span class="line">print(cur_filename_list) <span class="comment"># 直接打印 是沒問題的</span></span><br><span class="line"><span class="comment"># label 顯示相關訊息</span></span><br><span class="line">self.displayText[<span class="string">"text"</span>] = <span class="string">" "</span>.join(str(x) <span class="keyword">for</span> x <span class="keyword">in</span> cur_filename_list)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="解釋"><a href="#解釋" class="headerlink" title="解釋"></a>解釋</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 這邊結果會是 例如: 一個空格 加上 名稱</span></span><br><span class="line"><span class="comment">## 具體運作是, 取得 cur_filename_list 每一個內容 轉 String, 然後在前面加上 "空格"</span></span><br><span class="line"><span class="comment">## 再把他們都串起來, 變成一個字串</span></span><br><span class="line"><span class="comment">## 簡單來說 就是</span></span><br><span class="line"><span class="comment">## 返回值</span></span><br><span class="line"><span class="comment">## 回傳通過指定的字串連接陣列中元素後生成的新字串</span></span><br><span class="line"><span class="string">" "</span>.join(str(x) <span class="keyword">for</span> x <span class="keyword">in</span> cur_filename_list)</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<hr>
</div>
<div class="post-footer">
<div>
轉載聲明:
商業轉載請聯繫作者獲得授權, 非商業轉載請註明出處 © <a href="" target="_blank">TinXie</a>
</div>
<div>
</div>
</div>
</article>
<div class="article-nav prev-next-wrap clearfix">
<a href="/2017-11-19-21-37.html" class="pre-post btn btn-default" title='2017-11-19-21:37'>
<i class="fa fa-angle-left fa-fw"></i><span class="hidden-lg">上一篇</span>
<span class="hidden-xs">
2017-11-19-21:37</span>
</a>
<a href="/Obj-C-%E5%8B%95%E6%85%8B%E5%8F%96%E5%BE%97-Class-%E5%B1%AC%E6%80%A7%E5%90%8D%E7%A8%B1-and-%E5%B1%AC%E6%80%A7%E8%B3%AA%E5%80%BC.html" class="next-post btn btn-default" title='Obj-C 動態取得 Class 屬性名稱 and 屬性質值'>
<span class="hidden-lg">下一篇</span>
<span class="hidden-xs">
Obj-C 動態取得 Class 屬性名稱 and 屬性質值</span><i class="fa fa-angle-right fa-fw"></i>
</a>
</div>
<div id="comments">
<link rel="stylesheet" href="https://cdn.bootcss.com/gitalk/1.4.1/gitalk.min.css">
<script src="//cdn.bootcss.com/gitalk/1.4.1/gitalk.min.js"></script>
<script src="//cdn.bootcss.com/blueimp-md5/2.9.0/js/md5.min.js"></script>
<div id="gitalk-container"></div>
<script type="text/javascript">
var gitalk = new Gitalk({
// Gitalk配置
language: "zh-TW",
clientID: "963ce46b3653bea85cac",
clientSecret: "e3e6d59e4e9b0b7c7d639a92decbdfecc771e67e",
repo: "s2339956.github.is",
owner: "s2339956",
admin: ["s2339956"],
id: md5(location.pathname),
distractionFreeMode: true
});
gitalk.render('gitalk-container');
</script>
</div>
</main>
<aside id="article-toc" role="navigation" class="col-md-4">
<div class="widget">
<h3 class="title">
文章目錄
</h3>
<ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B1%95%E7%A4%BA%E4%B8%80%E4%B8%8B%E7%94%A8%E6%B3%95"><span class="toc-text">展示一下用法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%A3%E9%87%8B"><span class="toc-text">解釋</span></a></li></ol>
</div>
</aside>
</div>
</div>
</section>
<footer class="main-footer">
<div class="container">
<div class="row">
</div>
</div>
</footer>
<a id="back-to-top" class="icon-btn hide">
<i class="fa fa-chevron-up"></i>
</a>
<div class="copyright">
<div class="container">
<div class="row">
<div class="col-sm-12">
<div class="busuanzi">
訪問量:
<strong id="busuanzi_value_site_pv">
<i class="fa fa-spinner fa-spin"></i>
</strong>
|
訪客數:
<strong id="busuanzi_value_site_uv">
<i class="fa fa-spinner fa-spin"></i>
</strong>
</div>
</div>
<div class="col-sm-12">
<span>Copyright ©
2017
</span> |
<span>
Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
</span> |
<span>
Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
</span>
</div>
</div>
</div>
</div>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script src="/js/app.js?rev=@@hash.js"></script>
</body>
</html>