
PEP 257 -- Docstring Conventions What is a Docstring? A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the __doc__ special attribute of that object. All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings. Public methods (including the __init__ constructor) should also have docstrings. A package may be documented in the module docstring of the __init__.py file in the package directory. String literals occurring elsewhere in Python code may also act as documentation. String literals occurring immediately after a simple assignment at the top level of a module, class, or __init__ method are called "attribute docstrings".String literals occurring immediately after another docstring are called "additional docstrings". Please see PEP 258, "Docutils Design Specification" , for a detailed description of attribute and additional docstrings. Multi-line Docstrings
Pythonic Perambulations 11.13. sqlite3 — DB-API 2.0 interface for SQLite databases — Python 2.7.9 documentation SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle. The sqlite3 module was written by Gerhard Häring. To use the module, you must first create a Connection object that represents the database. import sqlite3conn = sqlite3.connect('example.db') You can also supply the special name :memory: to create a database in RAM. Once you have a Connection, you can create a Cursor object and call its execute() method to perform SQL commands: The data you’ve saved is persistent and is available in subsequent sessions: import sqlite3conn = sqlite3.connect('example.db')c = conn.cursor() Usually your SQL operations will need to use values from Python variables. Note
Python — Basics of Python Dictionary: Looping & Sorting | Useful Stuff. Here some bits of info about python dictionaries & looping through them. 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. 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. Note that this is the equivalent of looping through “my_dict.keys()” What about getting the values? Conclusion
Python filter() In simple words, filter() method filters the given iterable with the help of a function that tests each element in the iterable to be true or not. The syntax of filter() method is: filter(function, iterable) filter() Parameters filter() method takes two parameters: function - function that tests if elements of an iterable return true or false If None, the function defaults to Identity function - which returns false if any elements are false iterable - iterable which is to be filtered, could be sets, lists, tuples, or containers of any iterators Return value from filter() filter() method returns an iterator that passed the function check for each element in the iterable. filter() method is equivalent to: # when function is defined (element for element in iterable if function(element)) # when function is None (element for element in iterable if element) Example 1: How filter() works for iterable list? Output The filtered vowels are: a e i o The filtered elements are: 1 a True 0
guaranteed-stable sort with the decorate-sort-undecorate idiom ( "decorate-sort-undecorate" is a general and common idiom that allows very flexible and speedy sorting of Python sequences. An auxiliary list is first built (the 'decorate' step) where each item is made up of all sort-keys (in descending order of significance) of the corresponding item of the input sequence (must include all of the information in the whole corresponding item, and/or an index to it so we can fetch it back [or reconstruct it] in the third step). This is then sorted by its builtin sort method without arguments. This 'naturally' supplies a sorted _copy_, but if the input-sequence is a list we can just assign to its "include everything" slice to get in-place effect. This recipe specifically demonstrates using this to achieve a stable sort (where items that compare equal keep the same relative order in the result list as they had in the input sequence).
Debugging Python Code on the Raspberry Pi with Wing IDE - Wingware Python IDE May 06, 2015 Wing IDE is an integrated development environment that can be used to develop and debug Python code running on the Raspberry Pi. Wing provides auto-completion, call tips, a powerful debugger, and many other features that help you write, navigate, and understand Python code. Introduction The Raspberry Pi is not really capable of running Wing IDE itself, but you can set up Wing IDE on a computer connected to the Raspberry Pi to work on and debug Python code remotely. To do this, you will first need (1) a network connection between the Raspberry Pi and the computer where Wing IDE will be running, and (2) a way to share files between the two computers. The easiest way to connect the Raspberry Pi to your network is with ethernet, or see the instructions at the end of Using Wing IDE with Raspberry Pi for configuring a wifi connection. For file sharing, use Samba, or simply transfer a copy of your files to the Raspberry Pi using scp or rsync. Installing and Configuring the Debugger
Python MySQL Database Access The Python standard for database interfaces is the Python DB-API. Most Python database interfaces adhere to this standard. You can choose the right database for your application. Python Database API supports a wide range of database servers such as − GadFlymSQLMySQLPostgreSQLMicrosoft SQL Server 2000InformixInterbaseOracleSybase Here is the list of available Python database interfaces: Python Database Interfaces and APIs .You must download a separate DB API module for each database you need to access. The DB API provides a minimal standard for working with databases using Python structures and syntax wherever possible. Importing the API module.Acquiring a connection with the database.Issuing SQL statements and stored procedures.Closing the connection We would learn all the concepts using MySQL, so let us talk about MySQLdb module. What is MySQLdb? MySQLdb is an interface for connecting to a MySQL database server from Python. How do I Install MySQLdb? #! Database Connection Example #! #! #! #! #! #! #!
operators - What is the name of ** in python Iterate over a list in Python - GeeksforGeeks View Discussion Improve Article Save Article Like Article List is equivalent to arrays in other languages, with the extra benefit of being dynamic in size. There are multiple ways to iterate over a list in Python. Method #1: Using For loop Python3 Output: Method #2: For loop and range()In case we want to use the traditional for loop which iterates from number x to number y. Iterating using the index is not recommended if we can iterate over the elements (as done in Method #1). Method #4: Using list comprehension (Possibly the most concrete way). Method #5: Using enumerate()If we want to convert the list into an iterable list of tuples (or get the index based on a condition check, for example in linear search you might need to save the index of minimum element), you can use the enumerate() function. Note: Even method #2 can be used to find the index, but method #1 can’t (Unless an extra variable is incremented every iteration) and method #5 gives a concise representation of this indexing.
Python: Lambda Functions Python supports the creation of anonymous functions (i.e. functions that are not bound to a name) at runtime, using a construct called "lambda". This is not exactly the same as lambda in functional programming languages, but it is a very powerful concept that's well integrated into Python and is often used in conjunction with typical functional concepts like filter(), map() and reduce(). This piece of code shows the difference between a normal function definition ("f") and a lambda function ("g"): As you can see, f() and g() do exactly the same and can be used in the same ways. The following code fragments demonstrate the use of lambda functions. The above code defines a function "make_inrementor" that creates an anonymous function on the fly and returns it. You can now create multiple different incrementor functions and assign them to variables, then use them independent from each other. The following takes this a step further. In the second example, map() is used to convert our list.
What is the python3 equivalent of "python -m SimpleHTTPServer" Query Language: INSERT Small. Fast. Reliable.Choose any three. [Top] insert-stmt: expr: literal-value: raise-function: type-name: signed-number: select-stmt: common-table-expression: compound-operator: join-clause: join-constraint: join-operator: ordering-term: result-column: table-or-subquery: with-clause: cte-table-name: The INSERT statement comes in three basic forms. The first form (with the "VALUES" keyword) creates one or more new rows in an existing table. The optional conflict-clause allows the specification of an alternative constraint conflict resolution algorithm to use during this one INSERT command. The optional "database-name." prefix on the table-name is support for top-level INSERT statements only.