background preloader

Snippets / tips

Facebook Twitter

Python format timedelta to string. IPython Tip Sheet. To make better use of ipython, do the following one-time operations: Edit your ~/.bashrc file, and add the following lines in some appropriate place: export LESS="-R" export EDITOR=emacs This will tell the pager program less to interpret "raw" control sequences appropriately, and to use emacs as your default editor in certain situations.

IPython Tip Sheet

IPython uses raw control sequences to make colored text in its displays. Start up a new terminal window to get the updated environment variables, or, alternatively, type . ~/.bashrc to update the current shell. Edit your ~/ipython/ipythonrc file, and search for the set of commands describing xmode. Comment out (using #) the lines for "xmode Plain" and "xmode Context", and uncomment the line for "xmode Verbose", to get more useful information about python errors. IPython "magic" commands are conventionally prefaced by %, but if the flag %automagic is set to on, then one can call magic commands without the preceding %. Python — Basics of Python Dictionary: Looping & Sorting.

Here some bits of info about python dictionaries & looping through them.

Python — Basics of Python Dictionary: Looping & Sorting

Extra special beginner stuff. What is a dictionary? A python dictionary is an extremely useful data storage construct for storing and retreiving key:value pairs. Many languages implement simple arrays (lists in python) that are keyed by a integer. For example, if you made a list [1, 2] – the first value would be retrieved via [1, 2][0]. A dictionary is a little more advanced in that the keys can be many other things than integers. Will I remember that my_list[3] is my phone number?

Major differences vs lists - Keys are any hashable object (say strings for simplicity) - Are NOT ordered (a list is by definition ordered) One way I like to think about them are as little variable containers. In fact, variables are very much related to dictionaries! Watch and see: Looping through dictionaries Now, if you did a little experimenting, you would see that if you loop through a dictionary you loop through its keys. Conclusion. Snyppets - Python snippets.

Pt This page contains a bunch of miscellaneous Python code snippets, recipes, mini-guides, links, examples, tutorials and ideas, ranging from very (very) basic things to advanced.

Snyppets - Python snippets

I hope they will be usefull to you. All snippets are kept in a single HTML page so that you can easily ❶save it for offline reading (and keep on a USB key) ❷search in it. Note that scripts that do some web-scraping may not work anymore due to website changes. The web is an evolving beast :-) (Don't forget to read my main Python page ( ): there is handful of other programs and a guides.)

Advertising To avoid dodgy websites,install WOT Send a file using FTP Piece of cake. XML tabledump to model. 744700 - minimal set of delicious.com backup source (using mongodb)- GitHub. David Ziegler's Blog - See Which Twitterers Don’t Follow You Back In Less Than 14 Lines of Python.