All Go Rust Python PHP JavaScript
Chrome Dev Summit to secure your spot in workshops, office hours and learning lounges!

How to Get Name of Current Script in Python

In Python, using the __file__ is the easiest way to get name of current script. Using Module Attributes You can use __file__ to get the name of the current file. When used in the main module, this is the name of the script that was originally invoke...
Unused

How to Marshal / Unmarshal Json with a Custom Type Attribute in Go

In Golang, using the Unmarshal JSON function is the easiest way to Marshal / Unmarshal json with a custom type attribute. JSON (JavaScript Object Notation) is a lightweight data-interchange format. Using UnmarshalJSON Function Example on custom Unm...
aweis

How to Get Current Time in Milliseconds in Python

In Python, there are 3 ways to get current time in milliseconds. Using time Method The time.time() method returns the time in seconds since the epoch as a floating point number. For example, #!/usr/bin/python3 # Import module import time ms =...
Patcher56

How to Retrieve a Module's Path in Python

In Python, there are 2 ways to retrieve a module's path. Using __file__ Attribute You can retrieve a module's path using the __file__ attribute. For example, #!/usr/bin/python3 # Import module import os print(os.__file__) /usr/local/lib/pyt...
aweis

How to Get a Function Name as a String in Python

In Python, there are 2 ways to get a function name as a string. Using __name__ Attribute Using __qualname__ is the preferred method as it applies uniformly. It works on built-in functions as well: #!/usr/bin/python3 def my_func(): pass class...
ada

How to check if a variable exists in Python

In Python, there are 3 ways to check if a variable exists. Using locals Function The locals() function returns the dictionary of the current local symbol table. #!/usr/bin/python3 vName = 1 if 'vName' in locals(): print("exists") exists ...
Sambhav Khandelwal

How to Determine if an Object is Iterable in Python

In Python, there are 2 ways to determine if an object is iterable. Using Duck Typing Duck typing is a concept related to dynamic typing, where the type or the class of an object is less important than the methods it defines. When you use duck typing...
Unused

How to Check If an Object Is of a Given Type in Python

In Python, there are 2 ways to check if an object is of a given type. Using isinstance Method The isinstance(object, classinfo) method returns True if the object argument is an instance of the classinfo argument, or of a (direct, indirect, or virtua...
Unused

How to Know If an Object has an Attribute in Python

In Python, there are 4 ways to know if an object has an attribute. Using hasattr Method The arguments are an object and a string. The result is True if the string is the name of one of the object’s attributes, False if not. For example, #!/usr/...
ada

How to use the curl command in Linux

command line tool and library for transferring data with URLs. cURL (pronounced 'curl') is a computer software project providing a library (libcurl) and command-line tool (curl) for transferring data using various network protocols. The name ...

How to use the chown command in Linux

The chown command changes user ownership of a file, directory, or link in Linux. The command chown, an abbreviation of change owner, is used on Unix and Unix-like operating systems to change the owner of file system files, directories. cha...

How to use the Angular CLI build command line

Compiles an Angular app into an output directory named dist/ at the given output path.The command can be used to build a project of type "application" or "library". When used to build a library, a different builder is invoked, and only the ts-config,...

How to use the Docker-compose command line

This page provides the usage information for the docker-compose Command.The following show the Docker-Compose version information: Version information docker-compose version docker-compose -v docker-compose --version docker...

How to install clipboard.js

A modern approach to copy text to clipboard No Flash. No frameworks. --pname-- lets you easily copy text to the clipboard. At 3kb gzipped and no need for Flash, it’s a great lightweight way to allow your visitors to copy bits of text and code on your...

How to install LitElement

LitElement is a simple base class for creating fast, lightweight web components that work in any web page with any framework.--pname-- uses lit-html to render into shadow DOM, and adds API to manage properties and attributes. Properties are observed ...