Namespaces and Scoping in Python

Mohd Mohtashim
Updated on 30-Jan-2020 06:28:56

557 Views

Variables are names (identifiers) that map to objects. A namespace is a dictionary of variable names (keys) and their corresponding objects (values).A Python statement can access variables in a local namespace and in the global namespace. If a local and a global variable have the same name, the local variable shadows the global variable.Each function has its own local namespace. Class methods follow the same scoping rule as ordinary functions.Python makes educated guesses on whether variables are local or global. It assumes that any variable assigned a value in a function is local.Therefore, in order to assign a value to a global variable within a ... Read More

Query to Know All Character Sets Supported by MySQL

vanithasree
Updated on 30-Jan-2020 06:23:43

149 Views

With the help of the following query we can see all the character sets supported by MySQL −mysql> Show Character Set; +-----------+-----------------------------+---------------------+--------+ | Charset   | Description                 | Default collation   | Maxlen | +---------- +-----------------------------+---------------------+--------+ | big5      | Big5 Traditional Chinese    | big5_chinese_ci     |      2 | | dec8      | DEC West European           | dec8_swedish_ci     |      1 | | cp850     | DOS West European           | cp850_general_ci   ... Read More

Check Default Character Sets of MySQL Databases

Nikitha N
Updated on 30-Jan-2020 06:21:34

126 Views

The query below will return the name of the database along with the default character set −mysql> SELECT SCHEMA_NAME 'Database', default_character_set_name 'charset' FROM information_schema.SCHEMATA; +--------------------+---------+ | Database           | Charset | +--------------------+---------+ | information_schema | utf8    | | gaurav             | latin1  | | menagerie          | latin1  | | mysql              | latin1  | | performance_schema | utf8    | | sample             | latin1  | | test               | latin1  | | tutorial           | latin1  | +--------------------+---------+ 8 rows in set (0.00 sec)

MySQL STR_TO_DATE Function Format String Returns

Nishtha Thakur
Updated on 30-Jan-2020 06:20:30

536 Views

If the specified format string and date string did not match then MySQL will return NULL value as output along with a warning. Following is an example to understand the same −mysql> Select STR_TO_DATE('20172810', '%Y, %d%m'); +------------------------------------+ | STR_TO_DATE('20172810', '%Y, %d%m') | +------------------------------------+ | NULL                               | +------------------------------------+ 1 row in set, 1 warning (0.00 sec)The query above returns NULL as output because the format string is having a comma (, ) after %Y but date string is not having any comma after 2017.mysql> Show Warnings\G ... Read More

Variable Length Arguments in Python

Mohd Mohtashim
Updated on 30-Jan-2020 06:19:40

6K+ Views

You may need to process a function for more arguments than you specified while defining the function. These arguments are called variable-length arguments and are not named in the function definition, unlike required and default arguments.SyntaxSyntax for a function with non-keyword variable arguments is this −def functionname([formal_args, ] *var_args_tuple ): "function_docstring" function_suite return [expression]An asterisk (*) is placed before the variable name that holds the values of all nonkeyword variable arguments. This tuple remains empty if no additional arguments are specified during the function call.Example Live Demo#!/usr/bin/python # Function definition is here def printinfo( arg1, *vartuple ): "This prints a variable passed arguments" ... Read More

Create MySQL Function to Calculate Duration in Years, Months, Days, Hours, Minutes, and Seconds

Govinda Sai
Updated on 30-Jan-2020 06:18:59

365 Views

Following is a MySQL function which calculates the duration in years, months, days, hours, minutes and seconds between two dates.mysql> DROP FUNCTION IF EXISTS Duration; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> DROP FUNCTION IF EXISTS Label123; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> DELIMITER // mysql> CREATE FUNCTION Duration( dtd1 datetime, dtd2 datetime ) RETURNS CHAR(128)    -> BEGIN    -> DECLARE yyr, mon, mmth, dy, ddy, hhr, m1, ssc, t1 BIGINT;    -> DECLARE dtmp DATETIME;    -> DECLARE t0 TIMESTAMP;    -> SET yyr = TIMESTAMPDIFF(YEAR, dtd1, dtd2);   ... Read More

Detect Point on Canvas After Rotation in HTML5

V Jyothi
Updated on 30-Jan-2020 06:15:29

292 Views

Whenever we work with canvas and want the canvas to be rotated, we need to translate point to draw point as per its rotation.A transform class can be made to detect point on the canvas after canvas rotationvar t = new Transform(); console.log(t.transformPoint(5,6)); //Transform point will be [5,6] t.rotate(1); // Same transformations can be applied that we did to the canvas console.log(t.transformPoint(5,6)); // Transformed point will be [-2.347, 7.449]

Draw Part of an Image Inside HTML5 Canvas

Rishi Rathor
Updated on 30-Jan-2020 06:14:59

522 Views

If you want to draw part of an image inside canvas, the image onload function only fires once when the image first loads into the browser. Let us see the example:$(document).ready(function () {    var cw1 = 200;    var ch1 = 300;    var ctx1 = $("#myCanvas")[0].getContext("3d");    var myImg1 = new Image();    myImg1.src = "http://oi62.tinypic.com/148yf7.jpg";    var Fpst = 60;    var Player1Tank = {       x: cw1 / 2,       w: 85,       h: 85,       Pos: 3,       draw: function () {       ... Read More

Circle Collision Detection in HTML5 Canvas

karthikeya Boyini
Updated on 30-Jan-2020 06:14:28

561 Views

If we want to check whether circles are colliding with each other or not, one way is by getting the distance between two centers of circles and subtracting the radius of each circle from that distanceWe also check if the distance is greater than 1. If we want to check it for 20 circles, then we need to calculate exact differences in distances. x/y positions of centers vs the radii.bs(x2 - x1) > (r2 + r1) abs(y2 - y1) > (r2 + r1)The circles cannot collide if the distance in X or Y between circle centers is greater than the ... Read More

Required Arguments in Python

Mohd Mohtashim
Updated on 30-Jan-2020 06:14:12

9K+ Views

Required arguments are the arguments passed to a function in correct positional order. Here, the number of arguments in the function call should match exactly with the function definition.To call the function printme(), you definitely need to pass one argument, otherwise it gives a syntax error as follows −Example Live Demo#!/usr/bin/python # Function definition is here def printme( str ): "This prints a passed string into this function" print str return; # Now you can call printme function printme()OutputWhen the above code is executed, it produces the following result −Traceback (most recent call last): File "test.py", line 11, in printme(); TypeError: ... Read More

Advertisements