Skip to content
Snippets Groups Projects
python.md 4.09 KiB
Newer Older
  • Learn to ignore specific revisions
  • rhatto's avatar
    rhatto committed
    [[!meta title="Python"]]
    
    ## Learning Python
    
    ### General
    
    * Everything is an object. Really? What about symbols like + - and =?
    * The `dir()` and `help()` functions are really useful.
    * Great idea: iteration protocol.
    * There are sequences and sum operations common for all types and specific type operations.
    
    ### Iteration and optimization
    
        In general, leading and trailing double underscores is the naming pattern
        Python uses for implementation details. The names without the underscores in
        this list are the callable methods on string objects.
    
    ### Polymorphism
    
    Python encourages polymorphism:
    
        This is related to the idea of polymorphism mentioned earlier, and it stems
        from Python’s lack of type declarations. As you’ll learn, in Python, we code to
        object interfaces (operations supported), not to types. That is, we care what
        an object does, not what it is. Not caring about specific types means that code
        is automatically applicable to many of them—any object with a compatible
        interface will work, regardless of its specific type. Although type checking is
        supported—and even required in some rare cases—you’ll see that it’s not usually
        the “Pythonic” way of thinking. In fact, you’ll find that polymorphism is
        probably the key idea behind using Python well.
    
    ### Numeric Display Formats
    
    * [14. Floating Point Arithmetic: Issues and Limitations — Python 2.7.13 documentation](https://docs.python.org/2/tutorial/floatingpoint.html)
    * [What Every Computer Scientist Should Know About Floating-Point Arithmetic](https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html)
    * [Floating-point arithmetic - Wikipedia](https://en.wikipedia.org/wiki/Floating-point_arithmetic).
    
        This floating-point limitation is especially apparent for values that cannot be
        represented accurately given their limited number of bits in memory.
    
        [...]
    
        fractions and decimals both allow more intuitive and accurate results than
        floating points sometimes can, in different ways—by using rational
        representation and by limiting precision
    
    
    rhatto's avatar
    rhatto committed
    ### Types
    
        More formally, there are three major type (and operation) categories in Python
        that have this generic nature:
    
        Numbers (integer, floating-point, decimal, fraction, others)
        Support addition, multiplication, etc.
        Sequences (strings, lists, tuples)
        Support indexing, slicing, concatenation, etc.
        Mappings (dictionaries)
        Support indexing by key, etc.
    
        [...]
    
        The major core types in Python break down as follows:
    
        Immutables (numbers, strings, tuples, frozensets)
        None of the object types in the immutable category support in-place changes,
        though we can always run expressions to make new objects and assign their
        results to variables as needed.
    
        Mutables (lists, dictionaries, sets, bytearray)
        Conversely, the mutable types can always be changed in place with operations
        that do not create new objects. Although such objects can be copied, in-place
        changes support direct modification.
    
    
    rhatto's avatar
    rhatto committed
    So remember that when [copying](https://stackoverflow.com/questions/2612802/how-to-clone-or-copy-a-list#2612815)
    or referencing a list.
    
    rhatto's avatar
    rhatto committed
    
    ## Implementations
    
    * [MicroPython - Python for microcontrollers](http://micropython.org/) ([compiling](https://github.com/micropython/micropython/wiki/Getting-Started).
    
    
    rhatto's avatar
    rhatto committed
    ## Libraries and applications
    
    rhatto's avatar
    rhatto committed
    
    
    rhatto's avatar
    rhatto committed
    * QGIS.
    
    rhatto's avatar
    rhatto committed
    * [SciPy.org — SciPy.org](https://www.scipy.org/) ([package](https://packages.debian.org/stable/python-scipy)).
    
    rhatto's avatar
    rhatto committed
    ## Frameworks
    
    * [Welcome | Flask (A Python Microframework)](http://flask.pocoo.org/) ([package](https://packages.debian.org/stretch/python-flask)).
    * Async: [asyncio](https://docs.python.org/3/library/asyncio.html), Twisted and Tornado.
    
    
    rhatto's avatar
    rhatto committed
    ## Test projects
    
    * [Arduino Blog » How close are we to doomsday? A clock is calculating it in real time](https://blog.arduino.cc/2013/03/27/how-close-are-we-to-doomsday-clock/) ([python code](https://github.com/tomschofield/Neurotic-Armageddon-Indicator/blob/master/NAI_SERVER/nai_scraper.py) to parse [Timeline from the Bulletin of the Atomic Scientists](http://thebulletin.org/timeline)).