Tutorial by Examples: c

A generic class with the type parameter Type class MyGenericClass<Type>{ var value: Type init(value: Type){ self.value = value } func getValue() -> Type{ return self.value } func setValue(value: Type){ self.value = value }...
To install the latest version of a package named SomePackage: $ pip install SomePackage To install a specific version of a package: $ pip install SomePackage==1.0.4 To specify a minimum version to install for a package: $ pip install SomePackage>=1.0.4 If commands shows permission den...
To uninstall a package: $ pip uninstall SomePackage
To list installed packages: $ pip list # example output docutils (0.9.1) Jinja2 (2.6) Pygments (1.5) Sphinx (1.1.2) To list outdated packages, and show the latest version available: $ pip list --outdated # example output docutils (Current: 0.9.1 Latest: 0.10) Sphinx (Current: 1.1.2 Late...
Running $ pip install --upgrade SomePackage will upgrade package SomePackage and all its dependencies. Also, pip automatically removes older version of the package before upgrade. To upgrade pip itself, do $ pip install --upgrade pip on Unix or $ python -m pip install --upgrade pip on ...
When adding indented code blocks inside a list you first need a blank line, then to indent the code further. Different flavours of Markdown have different rules for this. StackExchange requires code to be indented by 8 characters instead of the usual 4. (Spaces replaced with * for clarity): 1...
A recursive function is simply a function, that would call itself. function factorial (n) { if (n <= 1) { return 1; } return n * factorial(n - 1); } The above function shows a basic example of how to perform a recursive function to return a factorial. Another...
import locale locale.setlocale(locale.LC_ALL, '') Out[2]: 'English_United States.1252' locale.currency(762559748.49) Out[3]: '$762559748.49' locale.currency(762559748.49, grouping=True) Out[4]: '$762,559,748.49'
First of all, we need to add our first Fragment at the beginning, we should do it in the onCreate() method of our Activity: if (null == savedInstanceState) { getSupportFragmentManager().beginTransaction() .addToBackStack("fragmentA") .replace(R.id.container, FragmentA.n...
Python 2.x2.7 "1deadbeef3".decode('hex') # Out: '\x1d\xea\xdb\xee\xf3' '\x1d\xea\xdb\xee\xf3'.encode('hex') # Out: 1deadbeef3 Python 3.x3.0 "1deadbeef3".decode('hex') # Traceback (most recent call last): # File "<stdin>", line 1, in <module> ...
sed -i s/"what to replace"/"with what to replace"/g $file We use -i to select in-place editing on the $file file. In some systems it is required to add suffix after -i flag which will be used to create backup of original file. You can add empty string like -i '' to omit the b...
ansible -i hosts -m ping targethost -i hosts defines the path to inventory file targethost is the name of the host in the hosts file
Define interface //In this interface, you can define messages, which will be send to owner. public interface MyCustomListener { //In this case we have two messages, //the first that is sent when the process is successful. void onSuccess(List<Bitmap> bitmapList); //And Th...
Here's how you can destructure a vector: (def my-vec [1 2 3]) Then, for example within a let block, you can extract values from the vector very succinctly as follows: (let [[x y] my-vec] (println "first element:" x ", second element: " y)) ;; first element: 1 , second ele...
Here's how you can destructure a map: (def my-map {:a 1 :b 2 :c 3}) Then, for example, within a let block you can extract values from the map very succinctly as follows: (let [{x :a y :c} my-map] (println ":a val:" x ", :c val: " y)) ;; :a val: 1 , :c val: 3 Notice th...
Let's say you have a vector like so: (def my-vec [1 2 3 4 5 6]) And you want to extract the first 3 elements and get the remaining elements as a sequence. This can be done as follows: (let [[x y z & remaining] my-vec] (println "first:" x ", second:" y "third:&quot...
Create a class inheriting from Exception: class FooException(Exception): pass try: raise FooException("insert description here") except FooException: print("A FooException was raised.") or another exception type: class NegativeError(ValueError): pass ...
If the mimetype of the HTTP request is application/json, calling request.get_json() will return the parsed JSON data (otherwise it returns None) from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/echo-json', methods=['GET', 'POST', 'DELETE', 'PUT']) ...
Python minimally evaluates Boolean expressions. >>> def true_func(): ... print("true_func()") ... return True ... >>> def false_func(): ... print("false_func()") ... return False ... >>> true_func() or false_func() true_func(...
public void iterateAndFilter() throws IOException { Path dir = Paths.get("C:/foo/bar"); PathMatcher imageFileMatcher = FileSystems.getDefault().getPathMatcher( "regex:.*(?i:jpg|jpeg|png|gif|bmp|jpe|jfif)"); try (Direc...

Page 135 of 826