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

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 Get the Size of a File in Python

In Python, there are 3 ways to get the size of a file. Using os.path.getsize Method The os.path.getsize() method returns the size, in bytes, of path. Raise OSError if the file does not exist or is inaccessible. For example, #!/usr/bin/python3 #...
aweis

How to Copy a File in Go

In Golang, there are 2 ways to copy a file. Using io.Copy Function You can copy a file using the io.Copy() function. For example, package main import ( "io" "os" ) // Copy the src file to dst. func Copy(src, dst string) error { in, err...
Unused

How to Get File Creation and Modification Dates Times in Python

In Python, there are 3 ways to get file creation and modification dates times. Using os.path Function The os.path.getmtime() function returns the time of last modification of path. The os.path.getctime() function returns the system’s ctime which, o...
Patcher56

How to Get File Length in Go

In Golang, there are 2 ways to get file length. Using file.Stat Function Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. See the followin...
ada

How to Access Command-Line Arguments in Go

In Golang, there are 2 ways to access command-line arguments passed to a program. Using os.Args Variable You can access the command-line arguments using the os.Args variable. Note that the first value in this slice is the path to the program, and o...
Unused

How to Append Text to a File in Go

In Golang, using the os.O_APPEND flag is the easiest way to append text to a file Using os.OpenFile Function OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc...
ada

How to Access Command Line Parameters in Rust

In Rust, there are 2 ways to access command line parameters. Using std::env::args Function This function actually returns the arguments that this program was started with. See the following example: use std::env; fn main() { for arg in env::...
Patcher56

How To Install Rust in Linux

In Rust, there are two ways to install rust in Linux.Running the following in your terminal If you’re running macOS, Linux, or another Unix-like OS. To download Rustup and install Rust, run the following in your terminal, then follow the on-screen i...
pooriabt

How to fetch data from url in Python

Fetch Internet Resources Using The urllib Package.Fetching URLs The simplest way to use urllib.request is as follows: #!/usr/bin/env python3 # Import datetime module import urllib.request with urllib.request.urlopen('https://google.com') as respon...
pooriabt

How to convert string to json in Python

Converting Json to string in Python.Decoding JSON To convert string to json in Python, use the json.loads() function. The json.loads() is a built-in Python function that accepts a valid json string and returns a dictionary to access all elements. The...
pooriabt

How to convert interface to int64 in Go

Interface variable conversion in Golang.Type Assertion To convert interface to int64 in Go, Using Type Assertion. A type assertion provides access to an interface value's underlying concrete value. package main import "fmt" // t := i.(T) // t, ok ...
ada

How to convert interface to string in Go

Type casting an interface to a string in go.Using fmt.Sprintf Function To convert interface to string in Go, use fmt.Sprintf function. Sprintf formats according to a format specifier and returns the resulting string. package main import "fmt" var ...
pooriabt

How to use the gzip command in Linux

Compress or uncompress FILEs. Gzip reduces the size of the named files using Lempel-Ziv coding (LZ77). Whenever possible, each file is replaced by one with the extension .gz, while keeping the same ownership modes, access and modi‐ficati...

How to use the df command in Linux

Show information about the file system on which each FILE resides, or all file systems by default. df (abbreviation for disk free) is a standard Unix command used to display the amount of available disk space for file systems on which the invoking us...