Overblog Tous les blogs Top blogs Beauté, Santé & Remise en forme Tous les blogs Beauté, Santé & Remise en forme
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU
http://xxviw.over-blog.com/

xxviw.over-blog.com/

Publicité

Python 2 7 3 1



Many beginning Python users are wondering with which version of Python they should start. My answer to this question is usually something along the lines 'just go with the version your favorite tutorial was written in, and check out the differences later on.'

Python 2 reached the end of life on January 1, 2020. Python 3 has been available since 2008, but converting from 2 to 3 has been slow because of dependencies on libraries that were not available in Python 3 initially, earlier versions of python 3 were slower than python 2 and also because Python 2 was working quite well for many people. Switching between Python 2 and Python 3 environments¶ You can easily maintain separate environments for Python 2 programs and Python 3 programs on the same computer, without worrying about the programs interacting with each other. Switching to an environment is called activating it.

After considering declining support for Python 2 programming language and added benefits from upgrades to Python 3, it is always advisable for a new developer to select Python version 3. However, if a job demands Python 2 capabilities, that would be an only compelling reason to use this version. (mysql-connector-python-2.1.8-py2.7-windows-x86-32bit.msi) MD5: 84de80bf841f3df72b3a2bd18e37446e Signature Windows (x86, 64-bit), MSI Installer Python 3.4: 2.1.8.

Python 2 7 3 1

But what if you are starting a new project and have the choice to pick? I would say there is currently no 'right' or 'wrong' as long as both Python 2.7.x and Python 3.x support the libraries that you are planning to use. However, it is worthwhile to have a look at the major differences between those two most popular versions of Python to avoid common pitfalls when writing the code for either one of them, or if you are planning to port your project.

Sections
  • The print function
  • Integer division
  • Unicode
  • xrange
    • The __contains__ method for range objects in Python 3
  • Raising exceptions
  • Handling exceptions
  • The next() function and .next() method
  • For-loop variables and the global namespace leak
  • Comparing unorderable types
  • Parsing user inputs via input()
  • Returning iterable objects instead of lists
  • Banker's Rounding
The __future__ module

Python 3.x introduced some Python 2-incompatible keywords and features that can be imported via the in-built __future__ module in Python 2. It is recommended to use __future__ imports it if you are planning Python 3.x support for your code. For example, if we want Python 3.x's integer division behavior in Python 2, we can import it via

More features that can be imported from the __future__ module are listed in the table below:

featureoptional inmandatory ineffect
nested_scopes2.1.0b12.2PEP 227:Statically Nested Scopes
generators2.2.0a12.3PEP 255:Simple Generators
division2.2.0a23.0PEP 238:Changing the Division Operator
absolute_import2.5.0a13.0PEP 328:Imports: Multi-Line and Absolute/Relative
with_statement2.5.0a12.6PEP 343:The 'with' Statement
print_function2.6.0a23.0PEP 3105:Make print a function
unicode_literals2.6.0a23.0PEP 3112:Bytes literals in Python 3000
(Source: [https://docs.python.org/2/library/__future__.html](https://docs.python.org/2/library/__future__.html#module-__future__))

The print function

Very trivial, and the change in the print-syntax is probably the most widely known change, but still it is worth mentioning: Python 2's print statement has been replaced by the print() function, meaning that we have to wrap the object that we want to print in parantheses.

Python 2 doesn't have a problem with additional parantheses, but in contrast, Python 3 would raise a SyntaxError if we called the print function the Python 2-way without the parentheses.

Python 2
Python 3

Note:

Printing 'Hello, World' above via Python 2 looked quite 'normal'. However, if we have multiple objects inside the parantheses, we will create a tuple, since print is a 'statement' in Python 2, not a function call.

Integer division

This change is particularly dangerous if you are porting code, or if you are executing Python 3 code in Python 2, since the change in integer-division behavior can often go unnoticed (it doesn't raise a SyntaxError).
So, I still tend to use a float(3)/2 or 3/2.0 instead of a 3/2 in my Python 3 scripts to save the Python 2 guys some trouble (and vice versa, I recommend a from __future__ import division in your Python 2 scripts).

Python 2
Python 3

Unicode

Python 2 has ASCII str() types, separate unicode(), but no byte type.

Now, in Python 3, we finally have Unicode (utf-8) strings, and 2 byte classes: byte and bytearrays.

Python 2
Python 3

xrange

The usage of xrange() is very popular in Python 2.x for creating an iterable object, e.g., in a for-loop or list/set-dictionary-comprehension.
The behavior was quite similar to a generator (i.e., 'lazy evaluation'), but here the xrange-iterable is not exhaustible - meaning, you could iterate over it infinitely.

Thanks to its 'lazy-evaluation', the advantage of the regular range() is that xrange() is generally faster if you have to iterate over it only once (e.g., in a for-loop). However, in contrast to 1-time iterations, it is not recommended if you repeat the iteration multiple times, since the generation happens every time from scratch!

In Python 3, the range() was implemented like the xrange() function so that a dedicated xrange() function does not exist anymore (xrange() raises a NameError in Python 3).

Python 2
Python 3
The __contains__ method for range objects in Python 3

Another thing worth mentioning is that range got a 'new' __contains__ method in Python 3.x (thanks to Yuchen Ying, who pointed this out). The __contains__ method can speedup 'look-ups' in Python 3.x range significantly for integer and Boolean types.

Based on the timeit results above, you see that the execution for the 'look up' was about 60,000 faster when it was of an integer type rather than a float. However, since Python 2.x's range or xrange doesn't have a __contains__ method, the 'look-up speed' wouldn't be that much different for integers or floats:

Below the 'proofs' that the __contain__ method wasn't added to Python 2.x yet:

Note about the speed differences in Python 2 and 3

Some people pointed out the speed difference between Python 3's range() and Python2's xrange(). Since they are implemented the same way one would expect the same speed. However the difference here just comes from the fact that Python 3 generally tends to run slower than Python 2.

Raising exceptions

Where Python 2 accepts both notations, the ‘old' and the ‘new' syntax, Python 3 chokes (and raises a SyntaxError in turn) if we don't enclose the exception argument in parentheses:

Python 2
Python 3

The proper way to raise an exception in Python 3:

Handling exceptions

Also the handling of exceptions has slightly changed in Python 3. In Python 3 we have to use the 'as' keyword now

Python 2
Python 3

The next() function and .next() method

Python

Since next() (.next()) is such a commonly used function (method), this is another syntax change (or rather change in implementation) that is worth mentioning: where you can use both the function and method syntax in Python 2.7.5, the next() function is all that remains in Python 3 (calling the .next() method raises an AttributeError).

Python 2
Python 3

For-loop variables and the global namespace leak

Good news is: In Python 3.x for-loop variables don't leak into the global namespace anymore!

This goes back to a change that was made in Python 3.x and is described in What's New In Python 3.0 as follows:

'List comprehensions no longer support the syntactic form [.. for var in item1, item2, ..]. Use [.. for var in (item1, item2, ..)] instead. Also note that list comprehensions have different semantics: they are closer to syntactic sugar for a generator expression inside a list() constructor, and in particular the loop control variables are no longer leaked into the surrounding scope.'

Python 2
Python 3

Comparing unorderable types

Another nice change in Python 3 is that a TypeError is raised as warning if we try to compare unorderable types.

Python 2
Python 3

Parsing user inputs via input()

Fortunately, the input() function was fixed in Python 3 so that it always stores the user inputs as str objects. In order to avoid the dangerous behavior in Python 2 to read in other types than strings, we have to use raw_input() instead.

Python 2
Python 3

Returning iterable objects instead of lists

As we have already seen in the xrange section, some functions and methods return iterable objects in Python 3 now - instead of lists in Python 2.

Since we usually iterate over those only once anyway, I think this change makes a lot of sense to save memory. However, it is also possible - in contrast to generators - to iterate over those multiple times if needed, it is only not so efficient.

And for those cases where we really need the list-objects, we can simply convert the iterable object into a list via the list() function.

Python 2
Python 3

Some more commonly used functions and methods that don't return lists anymore in Python 3:

  • zip()

  • map()

  • filter()

  • dictionary's .keys() method

  • dictionary's .values() method

  • dictionary's .items() method

Banker's Rounding

Python 3 adopted the now standard way of rounding decimals when it results in a tie (.5) at the last significant digits. Now, in Python 3, decimals are rounded to the nearest even number. Although it's an inconvenience for code portability, it's supposedly a better way of rounding compared to rounding up as it avoids the bias towards large numbers. For more information, see the excellent Wikipedia articles and paragraphs:

Python 2
Python 3
Python 2 7 3 10

More articles about Python 2 and Python 3

Here is a list of some good articles concerning Python 2 and 3 that I would recommend as a follow-up.

// Porting to Python 3

// Pro and anti Python 3

Latest version

Released:

PyInstaller bundles a Python application and all its dependencies into a single package.

Project description

PyInstaller bundles a Python application and all its dependencies into a singlepackage. The user can run the packaged app without installing a Pythoninterpreter or any modules.

Help keeping PyInstaller alive:Maintaining PyInstaller is a huge amount of work.PyInstaller development can only continueif users and companies provide sustainable funding. Seehttp://www.pyinstaller.org/funding.html for how to support PyInstaller.

Documentation:https://pyinstaller.readthedocs.io/
Website:http://www.pyinstaller.org/
Code:https://github.com/pyinstaller/pyinstaller
Donate, Fund:http://www.pyinstaller.org/funding.html

PyInstaller reads a Python script written by you. It analyzes your codeto discover every other module and library your script needs in order toexecute. Then it collects copies of all those files – including the activePython interpreter! – and puts them with your script in a single folder, oroptionally in a single executable file.

PyInstaller is tested against Windows, Mac OS X, and GNU/Linux.However, it is not a cross-compiler:to make a Windows app you run PyInstaller in Windows; to makea GNU/Linux app you run it in GNU/Linux, etc.PyInstaller has been used successfullywith AIX, Solaris, FreeBSD and OpenBSD,but is not tested against them as part of the continuous integration tests.

Main Advantages

  • Works out-of-the-box with any Python version 3.5-3.9.
  • Fully multi-platform, and uses the OS support to load the dynamic libraries,thus ensuring full compatibility.
  • Correctly bundles the major Python packages such as numpy, PyQt5,PySide2, Django, wxPython, matplotlib and others out-of-the-box.
  • Compatible with many 3rd-party packages out-of-the-box. (All the requiredtricks to make external packages work are already integrated.)
  • Libraries like PyQt5, PySide2, wxPython, matplotlib or Django are fullysupported, without having to handle plugins or external data files manually.
  • Works with code signing on OS X.
  • Bundles MS Visual C++ DLLs on Windows.

Installation

PyInstaller is available on PyPI. You can install it through pip:

Requirements and Tested Platforms

  • Python:
  • 3.5-3.9
  • tinyaes 1.0+ (only if using bytecode encryption).Instead of installing tinyaes, pip install pyinstaller[encryption] instead.
  • Windows (32bit/64bit):
  • PyInstaller should work on Windows 7 or newer, but we only officially support Windows 8+.
  • We don't support Python installed from the Windows store when not using virtual environments due topermission errorsthat can't easily be fixed.
  • GNU/Linux (32bit/64bit)
  • ldd: Console application to print the shared libraries requiredby each program or shared library. This typically can be found inthe distribution-package glibc or libc-bin.
  • objdump: Console application to display information fromobject files. This typically can be found in thedistribution-package binutils.
  • objcopy: Console application to copy and translate object files.This typically can be found in the distribution-package binutils,too.
  • Mac OS X (64bit):
  • Mac OS X 10.13 (High Sierra) or newer.

Usage

Basic usage is very simple, just run it against your main script:

For more details, see the manual.

Untested Platforms

The following platforms have been contributed and any feedback orenhancements on these are welcome.

  • FreeBSD
  • ldd
  • Solaris
  • ldd
  • objdump
  • AIX
  • AIX 6.1 or newer. PyInstaller will not work with staticallylinked Python libraries.
  • ldd
  • PowerPC GNU/Linux (Debian)

Before using any contributed platform, you need to build the PyInstallerbootloader, as we do not ship binary packages. Download PyInstallersource, and build the bootloader:

Then install PyInstaller:

or simply use it directly from the source (pyinstaller.py).

Support

See http://www.pyinstaller.org/support.html for how to find help as well asfor commercial support.

Funding

Maintaining PyInstaller is a huge amount of work.PyInstaller development can only continueif users and companies provide sustainable funding. Seehttp://www.pyinstaller.org/funding.html for how to support PyInstaller.

Changes in this Release

You can find a detailed list of changes in this releasein the change log section of the manual. Ipad in usa kaufen 2018.

Release historyRelease notifications | RSS feed

4.1

4.0

3.6

3.5

3.4

3.3.1

3.3

3.2.1

3.2

3.1.1

3.1

3.0

2.1

2.0

1.5.1

1.5

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyinstaller, version 4.1
Filename, sizeFile typePython versionUpload dateHashes
Filename, size pyinstaller-4.1.tar.gz (3.5 MB) File type Source Python version None Upload dateHashes
Close
Hashes for pyinstaller-4.1.tar.gz
Hashes for pyinstaller-4.1.tar.gz
AlgorithmHash digest
SHA256954ae81de9a4bc096ff02433b3e245b9272fe53f27cac319e71fe7540952bd3d
MD5460df9d5125df109a23cd7be8d0e1a3a
BLAKE2-2569eedfbdad7f5d8f794c901076b814b8e9f5ce31d32c0bc3b63ddd27b61db9530
Latest version

Released:

Python interface for YARA

Project description

yara-python

With this library you can use YARA fromyour Python programs. It covers all YARA's features, from compiling, savingand loading rules to scanning files, strings and processes.

Here it goes a little example:

Installation

The easiest way of installing YARA is by using pip:

But you can also get the source from GitHub and compile it yourself:

Notice the --recursive option used with git. This is important becausewe need to download the yara subproject containing the source code forlibyara (the core YARA library). It's also important to note that the twomethods above link libyara statically into yara-python. If you want to linkdynamically against a shared libyara library use:

For this option to work you must build and installYARA separately before installingyara-python.

Documentation

Find more information about how to use yara-python athttps://yara.readthedocs.org/en/latest/yarapython.html.

Release historyRelease notifications | RSS feed

4.0.2

4.0.1

4.0.0

Starcraft 2 come out. 3.11.0

3.10.0

Python27 32-bit Version

3.9.0

3.8.1

3.8.0

3.7.0

3.6.3

3.6.2

3.6.1

3.6.0

3.5.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for yara-python, version 4.0.2
Filename, sizeFile typePython versionUpload dateHashes
Filename, size yara_python-4.0.2-cp35-cp35m-win32.whl (747.5 kB) File type Wheel Python version cp35 Upload dateHashes
Filename, size yara_python-4.0.2-cp35-cp35m-win_amd64.whl (1.1 MB) File type Wheel Python version cp35 Upload dateHashes
Filename, size yara_python-4.0.2-cp36-cp36m-win32.whl (747.5 kB) File type Wheel Python version cp36 Upload dateHashes
Filename, size yara_python-4.0.2-cp36-cp36m-win_amd64.whl (1.1 MB) File type Wheel Python version cp36 Upload dateHashes
Filename, size yara_python-4.0.2-cp37-cp37m-win32.whl (747.5 kB) File type Wheel Python version cp37 Upload dateHashes
Filename, size yara_python-4.0.2-cp37-cp37m-win_amd64.whl (1.1 MB) File type Wheel Python version cp37 Upload dateHashes
Filename, size yara_python-4.0.2-cp38-cp38m-win32.whl (747.5 kB) File type Wheel Python version cp38 Upload dateHashes
Filename, size yara_python-4.0.2-cp38-cp38m-win_amd64.whl (1.1 MB) File type Wheel Python version cp38 Upload dateHashes
Filename, size yara-python-4.0.2.tar.gz (405.9 kB) File type Source Python version None Upload dateHashes
Close
Hashes for yara_python-4.0.2-cp35-cp35m-win32.whl
Hashes for yara_python-4.0.2-cp35-cp35m-win32.whl
AlgorithmHash digest
SHA2567c8fc1275c77551bdef057b5b5b243896ca21b42e15ed9416884bffe4bec584b
MD54000e0e4df58a89a53659dd30878592a
BLAKE2-256210d522ec9d664657384e37dc93e5370061555885db8314fc5539ecb77b2f0be
Close
Hashes for yara_python-4.0.2-cp35-cp35m-win_amd64.whl
Hashes for yara_python-4.0.2-cp35-cp35m-win_amd64.whl
AlgorithmHash digest
SHA256a8f403a9c9180532258ca3f01c04b9fb12907003bd0840524c7188c10f6989ae
MD5e9eb7cd2d5bace490e931b7fdcf1390b
BLAKE2-256a9bdda0308f209df9ee1c0b17731cc25e5692341f48f52668e5f7cc14bb09fd8
Close
Hashes for yara_python-4.0.2-cp36-cp36m-win32.whl
Hashes for yara_python-4.0.2-cp36-cp36m-win32.whl
AlgorithmHash digest
SHA256b34cf660918e90351829ae68c7dd3bd4927cd39a4f05fc37966da50abbbb9468
MD5940f310015cf634e3d51a55bac81c5b6
BLAKE2-2567a5af26128f10a7f2350623c51896bb40eca14a9930186984c9b17c83cf924dd
Close
Hashes for yara_python-4.0.2-cp36-cp36m-win_amd64.whl
Hashes for yara_python-4.0.2-cp36-cp36m-win_amd64.whl
AlgorithmHash digest
SHA256cd18d31cd044a7e383c63617f4a1c7047209b14312ab527a3741eaca79f3f88c
MD55d34705f74f63f5e381c2ba45ae7bd8b
BLAKE2-25699d50d2746c5567e5ce999da0a94f3215315d81beb0ffbe452cf37502dda5a34
Close
Hashes for yara_python-4.0.2-cp37-cp37m-win32.whl
Hashes for yara_python-4.0.2-cp37-cp37m-win32.whl
AlgorithmHash digest
SHA256b0aa7135fef4ef2ede35d425ff777feeed174f3171faa520daa7bd99b54e082b
MD50d4092ddfcbfae5cc2ae40645c8b4d58
BLAKE2-256c0c42c4e22bf9941dd87868114af1ede69ec8652830dc828b8e7ff3b15492774
Close
Hashes for yara_python-4.0.2-cp37-cp37m-win_amd64.whl
Hashes for yara_python-4.0.2-cp37-cp37m-win_amd64.whl
AlgorithmHash digest
SHA2563843ffead5b88a62582173f74f7277c0765b1d60ae55583ab95b31361fc24715
MD5f866ef9ad88aaf4280c9ab5485542360
BLAKE2-256a22b08e41537a1ed09a45e839d0055ebdd31c1a5f0d2ebf4819a8cfe9a75354d
Close
Hashes for yara_python-4.0.2-cp38-cp38m-win32.whl
Hashes for yara_python-4.0.2-cp38-cp38m-win32.whl
AlgorithmHash digest
SHA256da37edad1e724cf586be0c78451cc3e3e3673b28676ed423e750f5cb793f22ee
MD58ce64e8583523638bef578b245714ae5
BLAKE2-2566aeeb2332f1f22c69eb063a8cc26925b9749b8964b3cd9040f99095ea89fec17
Close
Hashes for yara_python-4.0.2-cp38-cp38m-win_amd64.whl
Python Generate Array 0 1 2 3 4 5 6 7 8 9
Hashes for yara_python-4.0.2-cp38-cp38m-win_amd64.whl
AlgorithmHash digest
SHA2562199f11e3f14dd176a4ccf3e9d46a366f9a8723cd95066eb4e22625d1774da3e
MD59e10873a08fefd029d857f9dec30008d
BLAKE2-256a1f4572ec37bca6019d6666351f36a3809d4c46510e2c9c3a3f8ac4c7f670704
Python 2 7 3 1 Hour
Close
Hashes for yara-python-4.0.2.tar.gz
Hashes for yara-python-4.0.2.tar.gz
AlgorithmHash digest
SHA256c446e15a7ef1de56129eb311b3a920417ea3c3b4806b6ba979136bf861fa51d9
MD5efb4061b02a5b1556e34d24cd4790b3c
BLAKE2-2565f3223a3234978d746acfad00f306b13446a1935c52ec74a033416f457328239




Publicité
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article