pypy

eval,exec和compile有什么区别?

不羁的心 提交于 2020-02-26 09:36:51
我一直在研究Python代码的动态评估,并遇到 eval() 和 compile() 函数以及 exec 语句。 有人可以解释一下 eval 和 exec 之间的区别,以及不同的 compile() 模式如何适应吗? #1楼 exec用于语句,不返回任何内容。 eval用于表达式,并返回表达式的值。 表达式表示“某事”,而语句表示“做某事”。 #2楼 exec 不是表达式:Python 2.x中的语句和Python 3.x中的函数。 它编译并立即评估字符串中包含的一条语句或一组语句。 例: exec('print(5)') # prints 5. # exec 'print 5' if you use Python 2.x, nor the exec neither the print is a function there exec('print(5)\\nprint(6)') # prints 5{newline}6. exec('if True: print(6)') # prints 6. exec('5') # does nothing and returns nothing. eval 是一个内置函数( 不是 语句),该函数对一个表达式求值并返回该表达式产生的值。 例: x = eval('5') # x <- 5 x = eval('%d + 6' % x) # x

Python面试题之Python面试题汇总

自闭症网瘾萝莉.ら 提交于 2020-02-24 09:00:44
在这篇文章中: Python基础篇 1:为什么学习Python 2:通过什么途径学习Python 3:谈谈对Python和其他语言的区别 Python的优势: 4:简述解释型和编译型编程语言 5:Python的解释器种类以及相关特点? 6:位和字节的关系 7:b、B、KB、MB、GB的关系 8:PE8规范 9:通过代码实现如下转换(进制之间转换) 10:请编写一个函数实现将IP地址转换成一个整数 11、python递归的最大层数?998 12:求结果(and or or) 运算符 13 :ascii、unicode、utf-8、gbk 区别 14:字节码和机器码的区别 15:三元运算写法和应用场景? 16:Python3和Python2的区别? 17:用一行代码实现数值交换 18:Python3和Python2中int和long区别 19:xrange和range的区别 20:文件操作时:xreadlines和readlines的区别? 21: 列列举布尔值为False的常见值? 22. 字符串、列表、元组、字典每个常用的5个方法? 23、 lambda表达式格式以及应用场景? 24. pass的作用 25. *arg和**kwarg作用 26. is和==的区别 27:谈谈Python的深浅拷贝?以及实现方法和应用场景。 28. Python垃圾回收机制? 29.

Data-structure used for regexes in the Python standard library (re module)

梦想与她 提交于 2020-02-23 07:14:14
问题 My question is: What is the data-structure implemented by the module re in Python (I am interested in any Python implementation, although I have only looked at the source code of CPython and Pypy). In case you wonder why am I interested, here there is more context: I have been trying to understand the implementation of the re python module. Currently, I am amazed about how fast it is for finding multiple patterns in a string, compared to other data structures I have used like Suffix Trees and

Eventlet or gevent or Stackless + Twisted, Pylons, Django and SQL Alchemy

[亡魂溺海] 提交于 2020-01-28 13:16:53
问题 We're using Twisted extensively for apps requiring a great deal of asynchronous io. There are some cases where stuff is cpu bound instead and for that we spawn a pool of processes to do the work and have a system for managing these across multiple servers as well - all done in Twisted. Works great. The problem is that it's hard to bring new team members up to speed. Writing asynchronous code in Twisted requires a near vertical learning curve. It's as if humans just don't think that way

django.db.utils.OperationalError: parser stack overflow

我的梦境 提交于 2020-01-25 12:54:18
问题 I have a re-usable django application which should support python2.7 , python 3.x and pypy . I developed it in python 2.7 at the beginning and all of my tests are worked very well. I also made them worked in python3.3 too. But I have a problem with python3.4 , pypy , pypy3 ; django.db.utils.OperationalError: parser stack overflow My tests run on sqlite3 . I check the trace, I just could guess that it is about query size. I couldn't find any solution to solve this problem. I overrided builtin

django.db.utils.OperationalError: parser stack overflow

ⅰ亾dé卋堺 提交于 2020-01-25 12:53:09
问题 I have a re-usable django application which should support python2.7 , python 3.x and pypy . I developed it in python 2.7 at the beginning and all of my tests are worked very well. I also made them worked in python3.3 too. But I have a problem with python3.4 , pypy , pypy3 ; django.db.utils.OperationalError: parser stack overflow My tests run on sqlite3 . I check the trace, I just could guess that it is about query size. I couldn't find any solution to solve this problem. I overrided builtin

django.db.utils.OperationalError: parser stack overflow

别来无恙 提交于 2020-01-25 12:52:23
问题 I have a re-usable django application which should support python2.7 , python 3.x and pypy . I developed it in python 2.7 at the beginning and all of my tests are worked very well. I also made them worked in python3.3 too. But I have a problem with python3.4 , pypy , pypy3 ; django.db.utils.OperationalError: parser stack overflow My tests run on sqlite3 . I check the trace, I just could guess that it is about query size. I couldn't find any solution to solve this problem. I overrided builtin

Why are there relative and absolut differences in performance among flow statements in CPython and pypy?

早过忘川 提交于 2020-01-16 12:00:09
问题 I'm reading the book Learning python (by Mark Lutz) and I use one of the programs shown in the book to measure the difference between flow statements. As I'm working in a project currently, I would like to know how faster pypy can be than my standard Python 3.7, which I guess is running in a C virtual machine. However, when I ran the program I was surprised to discover that there are hierarchical differences in relative and absolute performance among the flow statements depending on which

interpolate number sequence

…衆ロ難τιáo~ 提交于 2020-01-14 02:31:11
问题 I am trying to complete an uncomplete list of numbers, I couldn't find any pythonic way to do it. I have a sequence of days from 1 to 31, and for each day, I have a float value. #dictionnary{day: value} monthvalues = {1: 1.12, 2: 3.24, 3: 2.23, 5: 2.10, 7: 4.97} etc.. to 31st day but my data is uncomplete, and some days are missing! therefore I want to fill the missing picture mathematically this way: sample month1: {16: 2.00, 18: 4.00} #==> I want to add to the dictionnary 17: 3.00 sample

Does PyPy support gmpy2?

☆樱花仙子☆ 提交于 2020-01-06 23:52:11
问题 It seems from the discussions issue #60 and issue #40 that PyPy couldn't build gmpy before. All I intend to use currently is the probable prime is_prime code which is conveniently in gmpy2. I get the impression that the more calls to gmpy2 means less efficiency for PyPy. Is using gmpy2 possible currently, or do I have to use something like GMPY_CFFI? The error I get when using pip in PyPy is cannot open include file 'mpir.h' 回答1: You should use GMPY_CFFI. gmpy and gmpy2 rely on too many