-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython-exeche-evalyu-ju.html
More file actions
157 lines (135 loc) · 6.3 KB
/
python-exeche-evalyu-ju.html
File metadata and controls
157 lines (135 loc) · 6.3 KB
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
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<link rel="short icon" href="http://softing.qiniudn.com/20140603011448867_easyicon_net_128.ico" type="image/x-ico">
<meta charset="utf-8">
<title>python exec和eval语句</title>
<meta name="author" content="tulpar">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link href="/favicon.png" rel="icon"> -->
<link href="/theme/css/main.css" media="screen, projection"
rel="stylesheet" type="text/css">
<script src="/theme/js/modernizr-2.0.js"></script>
<script src="/theme/js/ender.js"></script>
<script src="/theme/js/octopress.js" type="text/javascript"></script>
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic"
rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic"
rel="stylesheet" type="text/css">
</head>
<body>
<header role="banner"><hgroup>
<h1><a href="/">Dreaming</a></h1>
</hgroup></header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
</ul>
<ul class="main-navigation">
<li class="active">
<a href="/category/it.html">It</a>
</li>
<li >
<a href="/category/life.html">Life</a>
</li>
</ul></nav>
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">python exec和eval语句</h1>
<p class="meta"><time datetime="2014-07-02T00:00:00+08:00" pubdate>Wed 02 July 2014</time></p>
</header>
<div class="entry-content"><h5>exec语句用来执行储存在字符串或文件中的Python语句。例如,我们可以在运行时生成一个包含Python代码的字符串,然后使用exec语句执行这些语句。下面是一个简单的例子。</h5>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">exec</span> <span class="err">'</span><span class="n">print</span> <span class="s">"Hello World"</span><span class="err">'</span>
<span class="n">Hello</span> <span class="n">World</span>
</pre></div>
<h6>eval语句用来计算存储在字符串中的有效Python表达式。下面是一个简单的例子。</h6>
<div class="highlight"><pre><span class="o">>>></span> <span class="n">eval</span><span class="p">(</span><span class="err">'</span><span class="mi">2</span><span class="o">*</span><span class="mi">3</span><span class="err">'</span><span class="p">)</span>
<span class="mi">6</span>
</pre></div></div>
<footer>
<p class="meta">
<span class="byline author vcard">
Posted by <span class="fn">tulpar</span>
</span>
<time datetime="2014-07-02T00:00:00+08:00" pubdate>Wed 02 July 2014</time> <span class="categories">
<a class="category" href="/tag/python.html">Python</a>
</span>
</p><div class="sharing">
</div> </footer>
</article>
<!-- Duoshuo Comment BEGIN -->
<div class="ds-thread"></div>
<script type="text/javascript">
var duoshuoQuery = {short_name:"tlbog"};
(function() {
var ds = document.createElement('script');
ds.type = 'text/javascript';ds.async = true;
ds.src = 'http://static.duoshuo.com/embed.js';
ds.charset = 'UTF-8';
(document.getElementsByTagName('head')[0]
|| document.getElementsByTagName('body')[0]).appendChild(ds);
})();
</script>
<!-- Duoshuo Comment END -->
</div>
<aside class="sidebar">
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/xie-bo-ke-jiao-ben.html">写博客脚本</a>
</li>
<li class="post">
<a href="/gong-zuo-shi-de-sui-bi.html">工作时的随笔</a>
</li>
<li class="post">
<a href="/ce-shi-wen-zhang.html">测试文章</a>
</li>
<li class="post">
<a href="/djangokai-qi-the-sites-framework.html">Django开启 the sites framework</a>
</li>
<li class="post">
<a href="/django-17shi-yong.html">Django 1.7试用</a>
</li>
</ul>
</section>
<section>
<h1>Categories</h1>
<ul id="recent_posts">
<li><a href="/category/it.html">It</a></li>
<li><a href="/category/life.html">Life</a></li>
</ul>
</section>
<section>
<h1>Tags</h1>
<a href="/tag/mysql.html">Mysql</a>, <a href="/tag/tmux.html">Tmux</a>, <a href="/tag/fan-qiang.html">翻墙</a>, <a href="/tag/linux.html">Linux</a>, <a href="/tag/edx.html">Edx</a>, <a href="/tag/virtualbox.html">VirtualBox</a>, <a href="/tag/wo-ai-wo-jia.html">我爱我家</a>, <a href="/tag/userena.html">userena</a>, <a href="/tag/xadmin.html">Xadmin</a>, <a href="/tag/shell.html">Shell</a>, <a href="/tag/python.html">Python</a>, <a href="/tag/djangopython.html">Django,python</a>, <a href="/tag/ssh.html">ssh</a>, <a href="/tag/ubuntu.html">Ubuntu</a>, <a href="/tag/git.html">Git</a>, <a href="/tag/ce-shi.html">测试</a>, <a href="/tag/ueditor.html">Ueditor</a>, <a href="/tag/github.html">Github</a>, <a href="/tag/socketio.html">Socket.io</a>, <a href="/tag/django.html">Django</a>, <a href="/tag/du-shu.html">读书</a>, <a href="/tag/bo-ke.html">博客</a>, <a href="/tag/ngrok.html">ngrok</a> </section>
<section>
<h1>Social</h1>
<ul>
<li><a href="http://izda.com" target="_blank">ئىزدە</a></li>
<li><a href="http://www.google.com" target="_blank">Google</a></li>
<li><a href="http://www.zhihu.com/" target="_blank">知乎</a></li>
<li><a href="http://www.douban.com/" target="_blank">豆瓣</a></li>
</ul>
</section>
<section>
<h1>Blogroll</h1>
<ul>
<li><a href="https://github.com/tulpar008" target="_blank">My Github</a></li>
<li><a href="#" target="_blank">tulpar008@gmail.com</a></li>
</ul>
</section>
</aside> </div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013-2015 - tulpar -
<span class="credit">Powered by <a href="http://getpelican.com">Pelican</a></span>
</p></footer>
</body>
</html>