Giter Club home page Giter Club logo

python_reference's Introduction

A collection of useful scripts, tutorials, and other Python-related things


Python tips and tutorials [back to top]

  • A collection of not so obvious Python stuff you should know! [IPython nb]

  • Python's scope resolution for variable names and the LEGB rule [IPython nb]

  • Key differences between Python 2.x and Python 3.x [IPython nb]

  • A thorough guide to SQLite database operations in Python [Markdown]

  • Unit testing in Python - Why we want to make it a habit [Markdown]

  • Installing Scientific Packages for Python3 on MacOS 10.9 Mavericks [Markdown]

  • Sorting CSV files using the Python csv module [IPython nb]

  • Using Cython with and without IPython magic [IPython nb]

  • Parallel processing via the multiprocessing module [IPython nb]

  • Entry point: Data - using sci-packages to prepare data for Machine Learning tasks and other data analyses [IPython nb]

  • Awesome things that you can do in IPython Notebooks (in progress) [IPython nb]

  • A collection of useful regular expressions [IPython nb]

  • Quick guide for dealing with missing numbers in NumPy [IPython nb]

  • A random collection of useful Python snippets [IPython nb]

  • Things in pandas I wish I'd had known earlier [IPython nb]


Python and the web [back to top]

  • Creating internal links in IPython Notebooks and Markdown docs [IPython nb]

  • Converting Markdown to HTML and adding Python syntax highlighting [Markdown]


Algorithms and Data Structures [back to top]

This category has been moved to a separate GitHub repository rasbt/algorithms_in_ipython_notebooks


Plotting and Visualization [back to top]

The matplotlib-gallery in IPython notebooks has been moved to a separate GitHub repository matplotlib-gallery

Featured articles:


Benchmarks [back to top]
  • Simple tricks to speed up the sum calculation in pandas [IPython nb]

*More benchmarks can be found in the separate GitHub repository [One-Python-benchmark-per-day](https://github.com/rasbt/One-Python-benchmark-per-day)*

Featured articles:

  • (C)Python compilers - Cython vs. Numba vs. Parakeet [IPython nb]

  • Just-in-time compilers for NumPy array expressions [IPython nb]

  • Cython - Bridging the gap between Python and Fortran [IPython nb]

  • Parallel processing via the multiprocessing module [IPython nb]

  • Vectorizing a classic for-loop in NumPy [IPython nb]


Python and "Data Science" [back to top]

The "data science"-related posts have been moved to a separate GitHub repository pattern_classification

Featured articles:

  • Entry Point: Data - Using Python's sci-packages to prepare data for Machine Learning tasks and other data analyses [IPython nb]

  • About Feature Scaling: Standardization and Min-Max-Scaling (Normalization) [IPython nb]

  • Principal Component Analysis (PCA) [IPython nb]

  • Linear Discriminant Analysis (LDA) [IPython nb]

  • Kernel density estimation via the Parzen-window technique [IPython nb]


Useful scripts and snippets [back to top]


Other [back to top]


Links [back to top]


// News

  • Python subreddit - My favorite resource to catch up with Python news and great Python-related articles.

  • Python community on Google+ - A nice and friendly community to share and discuss everything about Python.

  • Python Weekly - A free weekly newsletter featuring curated news, articles, new releases, jobs etc. related to Python.


// Resources for learning Python


// My favorite Python projects and packages

  • The IPython Notebook - An interactive computational environment for combining code execution, documentation (with Markdown and LateX support), inline plots, and rich media all in one document.

  • matplotlib - Python's favorite plotting library.

  • NumPy - A library for multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays.

  • SciPy - A library that provides various useful functions for numerical computing, such as modules for optimization, linear algebra, integration, interpolation, ...

  • pandas - High-performance, easy-to-use data structures and data analysis tools build on top of NumPy.

  • Cython - C-extensions for Python, an optimizing static compiler to combine Python and C code.

  • Numba - A just-in-time specializing compiler which compiles annotated Python and NumPy code to LLVM (through decorators)

  • scikit-learn - A powerful machine learning library for Python and tools for efficient data mining and analysis.

python_reference's People

Contributors

frenchhorn avatar iiseymour avatar jongoodnow avatar kzhk75 avatar lacanlale avatar praveenmylavarapu avatar rachtsingh avatar rasbt avatar timgates42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python_reference's Issues

Slight lambda-in-closures issue

This is great stuff!

In the not-so-obvious python tutorial, one thing caught me eye - you say that the lambda-closure problem doesn't apply to generators, but it actually does. Your example appears to work because each function returned by the generator is going to return the current value of n, which indicates how far along in generator you've gotten. The list example fails because the whole list is evaluated; the generator example "succeeds" because when you call the ith function, n is still only equal to i. To see this in action:

>>> my_gen = (lambda:n for n in range(5))
>>> a = next(my_gen)
>>> a() # a() returns 0 because that's what n is right now
0
>>> a()
0
>>> # Advancing the generator increases n by one
>>> b = next(my_gen)
>>> b() # b returns 1, as expected
1
>>> a() # but now a returns 1, too
1
>>> # calling list(my_gen) will advance the generator to the end
>>> _ = list(my_gen)
>>> a(), b() # now n is 4
(4, 4)

More difference between range@py3 and xrange@py2

One thing I keeps telling people about range/xrange difference is that, the range in python3 implement the __contains__ method, which makes it very easy to test if a value is in range.

For example, in Python2, the following code is super slow:

x = 10000000 # a very large number
if x/2 in xrange(x):
    pass

But in Python3, the following code returns immediately:

x = 10000000 # a very large number
if x/2 in range(x):
    pass

To archive the same performance in Python2, one have to write the code like this:

x = 10000000 # a very large number
if 0 <= x/2 <= x-1:
    pass

%watermark addition.

FYI, IPython.sys_info() can be of help and give you commit hash or IPython and other stuff.

In [1]: import IPython
In [3]: print(IPython.sys_info())
{'commit_hash': b'4aea4a2',
 'commit_source': 'repository',
 'default_encoding': 'UTF-8',
 'ipython_path': '/Users/bussonniermatthias/ipython/IPython',
 'ipython_version': '3.0.0-dev',
 'os_name': 'posix',
 'platform': 'Darwin-11.4.2-x86_64-i386-64bit',
 'sys_executable': '/usr/local/opt/python3/bin/python3.4',
 'sys_platform': 'darwin',
 'sys_version': '3.4.0 (default, Apr  9 2014, 11:57:22) \n'
                '[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]'}

Workaround for HTML Conversion in Table of Contents

I found a workaround for an issue you describe in tutorials/table_of_contents_ipython.ipynb when converting internal links to an HTML format. Instead of being forced to put the id-anchor tag in a separate cell like you did in your notebook:

image

You can simply place a line break between the id-anchor and whatever text you'd like to include:

image

Which will render properly without actually including any line break visual:

image

Bad generated html

On http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/not_so_obvious_python_stuff.ipynb an anchor is closed in wrong place:

Chapter "Only the first clause of generators is evaluated immediately" is highlighted with the code altogether on mouse over.

See screenshot:
http://h.ctf.su/img/tmp.79rYIPXEi7Ua.png

Also chapter "Assigning types to variables as values" is the only chapter title highlighted on mouse over.

Checked on Chrome 34.0.1847.132 and firefox (linux).

PS: Wanted to patch it myself, but .ipynb syntax is mad. Also it seems HTML generated isn't good at all:

...
<a name="variable_types"></p>
</div>
</div>
</div>
...

Modifying a list while looping through it

A nice addition to your "not so obvious" notebook would be the modifying a list while looping through it pitfall. For instance, you might be tempted into believing that the following will remove all even values from the list a

>>> a = [1, 2, 3, 4, 5]
>>> for i in a:
...     if not i % 2:
...         a.remove(i)
...
>>> a
[1, 3, 5]

But if you try a different example:

>>> a = [2, 4, 5, 6]
>>> for i in a:
...     if not i % 2:
...         a.remove(i)
...
>>> a
[4, 5]

I'll leave it as an exercise for you to figure out exactly what is going on here.

Dictionaries will protect you from this by raising an exception if they change during iteration, but for lists, you should use a copy (for i in a[:]), or convert the for loop into a while loop.

Great notebook by the way!

PyBuilder

I would like to suggest to create a section "development tools".
There are many interesting tools in this area, for example PyBuilder

Printing database summary

I realize this post is fairly old, however I was wondering if you could please clarify.

It seems to me that in the functions you define in this section, you use the variable c for cursor within the function even though you pass the cursor object to the functions.

Could you please address this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.