Re: How to make Python run as fast (or faster) than Julia
On 24/02/2018 02:46, Steven D'Aprano wrote: Take the Fibonacci double-recursion benchmark. Okay, it tests how well your language does at making millions of function calls. Why? How often do you make millions of function calls? Very often. Unless you are writing code 1970s style with everything in one big main function. I've done some tests with my interpreter [sorry, Ned], on one real task: Total number of byte-code calls: 3.2 million Total number of real x64 calls: 520 million On this specific benchmark: 48 million and 580 million. Changing the way those x64 calls were made (using a different call convention), made some byte-code programs take up to 50% longer to execute. [In this interpreter, each byte-code, no matter what it is, is dispatched via a function call.] For most application code, executing the function is far more costly than the overhead of calling it, and the call overhead is dwarfed by the rest of the application. Any actual figures? In the case of interpreters, you want to optimise each byte-code, and one way of doing that is to write a small program which features that byte-code heavily. And then you start tweaking. It is true that when working with heavy-duty data, or offloading work to external, non-byte-code functions, then the byte-code execution overheads are small. But Python's weakness is when it /is/ executing actual algorithms using actual byte-code. And actually, performance of CPython does seem to have improved tremendously over the years. So some people have their eye on the ball. Clearly not you. If you have a language with tail recursion elimination, you can bet that's its benchmarks will include examples of tail recursion and tail recursion will be a favoured idiom in that language. If it doesn't, it won't. Benchmarks need to be honest. But Fibonacci I think can't use that optimisation (although gcc seems to have found another way of not that much work). -- bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: How to make Python run as fast (or faster) than Julia
On 24/02/2018 02:05, Steven D'Aprano wrote: On Fri, 23 Feb 2018 19:25:35 +, bartc wrote: Python is 10 times slower than a competitor = doesn't matter My language is 1.5 times slower than the big boys' = matters a great deal As for Python's order-of-magnitude speed difference, thank you for being generous. Actually that comparison was with a competitor, ie. another dynamic language, because I understand such languages work in different fields from the Cs and C++s. I'm sure there must be some that are faster (years since I've looked at the field), but I vaguely had in mind mine. Although since then, CPython has gotten faster. Note that there are JIT-based implementations now which can give very good results (other than PyPy) with dynamic languages. My own efforts are still byte-code based so are unlikely to get any faster. But they are also very simple. So it is quite possible to get practical work done and be a competitive, useful language despite being (allegedly) a thousand or more times slower than C. Of course. I've been using a dynamic scripting language as an adjunct to my compiled applications since the mid 80s. Then they were crude and hopelessly slow (and machines were a lot slower too), but they could still be tremendously useful with the right balance. But the faster they are, the more work they can take over. -- bartc -- https://mail.python.org/mailman/listinfo/python-list
read Unicode characters one by one in python2
Here shows some code for reading Unicode characters one by one in python2. Is it the best code for reading Unicode characters one by one in python2? https://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8#Python -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
SQLObject 3.6.0
Hello! I'm pleased to announce version 3.6.0, the first stable release of branch 3.6 of SQLObject. What's new in SQLObject === Contributor for this release is Michael S. Root. Minor features -- * Close cursors after using to free resources immediately instead of waiting for gc. Bug fixes - * Fix for TypeError using selectBy on a BLOBCol. PR by Michael S. Root. Drivers --- * Extend support for oursql and Python 3 (requires our fork of the driver). * Fix cursor.arraysize - pymssql doesn't have arraysize. * Set timeout for ODBC with MSSQL. * Fix _setAutoCommit for MSSQL. Documentation - * Document extras that are available for installation. Build - * Use ``python_version`` environment marker in ``setup.py`` to make ``install_requires`` and ``extras_require`` declarative. This makes the universal wheel truly universal. * Use ``python_requires`` keyword in ``setup.py``. For a more complete list, please see the news: http://sqlobject.org/News.html What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, Firebird, Sybase, MSSQL and MaxDB (also known as SAPDB). Python 2.7 or 3.4+ is required. Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Download: https://pypi.python.org/pypi/SQLObject/3.6.0 News and changes: http://sqlobject.org/News.html StackOverflow: https://stackoverflow.com/questions/tagged/sqlobject Example === Create a simple class that wraps a table:: >>> from sqlobject import * >>> >>> sqlhub.processConnection = connectionForURI('sqlite:/:memory:') >>> >>> class Person(SQLObject): ... fname = StringCol() ... mi = StringCol(length=1, default=None) ... lname = StringCol() ... >>> Person.createTable() Use the object:: >>> p = Person(fname="John", lname="Doe") >>> p >>> p.fname 'John' >>> p.mi = 'Q' >>> p2 = Person.get(1) >>> p2 >>> p is p2 True Queries:: >>> p3 = Person.selectBy(lname="Doe")[0] >>> p3 >>> pc = Person.select(Person.q.lname=="Doe").count() >>> pc 1 Oleg. -- Oleg Broytmanhttp://phdru.name/p...@phdru.name Programmers don't die, they just GOSUB without RETURN. -- https://mail.python.org/mailman/listinfo/python-list
How to extract the raw bytes of the decoded unicode?
Hi, I can extracted the encoded value as bytes. But is there a way to extracted the decoded value (for á, it is C1)? Thanks. $ cat ./dumpunicode.py #!/usr/bin/env python3 while True: c = sys.stdin.read(1) if c: print(c) print('0x' + ''.join(['%x' % x for x in reversed(bytes(c, encoding='utf-8'))])) else: break $ ./dumpunicode.py <<< á á 0xa1c3 0xa -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
Re: read Unicode characters one by one in python2
On Sat, Feb 24, 2018 at 10:17:35AM -0600, Peng Yu wrote: > Here shows some code for reading Unicode characters one by one in > python2. Is it the best code for reading Unicode characters one by one > in python2? > > https://rosettacode.org/wiki/Read_a_file_character_by_character/UTF8#Python This seems off, because in Python2 you can also specify an encoding. However, you seem to be asking about reading the console which comes with more caveats. So, what is it ? Karsten -- GPG key ID E4071346 @ eu.pool.sks-keyservers.net E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346 -- https://mail.python.org/mailman/listinfo/python-list
How to only get \n for newline without the single quotes?
I would like to just get the escaped string without the single quotes. Is there a way to do so? Thanks. >>> x='\n' >>> print repr(x) '\n' -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
Re: How to only get \n for newline without the single quotes?
On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: > I would like to just get the escaped string without the single quotes. > Is there a way to do so? Thanks. > x='\n' print repr(x) > '\n' Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. >>> x='/n' >>> print(repr(x)) '/n' >>> print(repr(x).strip("'")) /n >>> Python 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x='/n' >>> print repr(x) '/n' >>> print repr(x).strip("'") /n >>> -- GNU/Linux user #557453 "There are only 10 types of people in the world... those who understand Binary... and those who don't." -Spike -- https://mail.python.org/mailman/listinfo/python-list
Re: How to only get \n for newline without the single quotes?
On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list wrote: > On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: > >> I would like to just get the escaped string without the single quotes. >> Is there a way to do so? Thanks. >> > x='\n' > print repr(x) >> '\n' > > Python 3.5.3 (default, Jan 19 2017, 14:11:04) > [GCC 6.3.0 20170118] on linux > Type "help", "copyright", "credits" or "license" for more information. x='/n' print(repr(x)) > '/n' print(repr(x).strip("'")) > /n > > Python 2.7.13 (default, Nov 24 2017, 17:33:09) > [GCC 6.3.0 20170516] on linux2 > Type "help", "copyright", "credits" or "license" for more information. x='/n' print repr(x) > '/n' print repr(x).strip("'") > /n I was looking for something builtin python. There is not such a builtin way? -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
Re: How to only get \n for newline without the single quotes?
On Sat, Feb 24, 2018 at 1:08 PM, Peng Yu wrote: > On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list > wrote: >> On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: >> >>> I would like to just get the escaped string without the single quotes. >>> Is there a way to do so? Thanks. >>> >> x='\n' >> print repr(x) >>> '\n' >> >> Python 3.5.3 (default, Jan 19 2017, 14:11:04) >> [GCC 6.3.0 20170118] on linux >> Type "help", "copyright", "credits" or "license" for more information. > x='/n' > print(repr(x)) >> '/n' > print(repr(x).strip("'")) >> /n > >> >> Python 2.7.13 (default, Nov 24 2017, 17:33:09) >> [GCC 6.3.0 20170516] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. > x='/n' > print repr(x) >> '/n' > print repr(x).strip("'") >> /n > > > I was looking for something builtin python. There is not such a builtin way? Also, this is not printed as \f or \e. I'd like things like \a, \b, ... \v be printed as such. Is there a way to do so in python? >>> print repr('\f') '\x0c' >>> print repr('\e') '\\e' -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
Re: How to only get \n for newline without the single quotes?
On 2/24/18 2:08 PM, Peng Yu wrote: On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list wrote: On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote: I would like to just get the escaped string without the single quotes. Is there a way to do so? Thanks. x='\n' print repr(x) '\n' Python 3.5.3 (default, Jan 19 2017, 14:11:04) [GCC 6.3.0 20170118] on linux Type "help", "copyright", "credits" or "license" for more information. x='/n' print(repr(x)) '/n' print(repr(x).strip("'")) /n Python 2.7.13 (default, Nov 24 2017, 17:33:09) [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. x='/n' print repr(x) '/n' print repr(x).strip("'") /n I was looking for something builtin python. There is not such a builtin way? Peng, your last three questions all make me wonder what larger problem you are working on. These all sound like there might be an easier way. Can you take a step back and tell us about the big picture? --Ned. -- https://mail.python.org/mailman/listinfo/python-list