MySQL query to display columns name first name, last name as full name in a single column?

AmitDiwan
Updated on 01-Oct-2019 06:49:29

11K+ Views

For this, use CONCAT() method in MySQL. Let us first create a table −mysql> create table DemoTable (    FirstName varchar(50),    LastName varchar(50) ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'Brown'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('David', 'Miller'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('John', 'Doe'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values('Adam', 'Smith'); Query OK, 1 row affected (0.25 sec)Display all records from the table using select statement ... Read More

How to use pip to install python modules in easy way?

Rajendra Dharmkar
Updated on 01-Oct-2019 06:48:40

1K+ Views

If you have Python 2 >=2.7.9 or Python 3 >=3.4 installed from python.org, you will already have pip and setuptools, but will need to upgrade to the latest version:On Linux or macOS:pip install -U pip setuptoolsOn Windows:python -m pip install -U pip setuptoolsIf you’re using a Python install on Linux that’s managed by the system package manager (e.g "yum", "apt-get" etc…), and you want to use the system package manager to install or upgrade pip, then see: https://packaging.python.org/guides/installing-using-linux-tools/Otherwise:Download get-pip.py from https://bootstrap.pypa.io/get-pip.py. Run python get-pip.py. This will install or upgrade pip.Now you can use pip to install python packages. For example, ... Read More

How to alter column type of multiple columns in a single MySQL query?

AmitDiwan
Updated on 01-Oct-2019 06:47:21

558 Views

To alter column type of multiple columns in a single MySQL query, the syntax is as follows −alter table yourTableName modify column yourColumnName 1 yourDataType1, modify column yourColumnName 2 yourDataType2, . . N;Let us first create a table −mysql> create table DemoTable (    Id varchar(100),    FirstName text,    LastName text ); Query OK, 0 rows affected (0.52 sec)Let us check the description of table −mysql> desc DemoTable;This will produce the following output −+-----------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | ... Read More

How to set up your python development environment on AWS?

Rajendra Dharmkar
Updated on 01-Oct-2019 06:45:55

268 Views

You need to have Python, pip, virtualenv, awswebcli and a SSH client installed to set up your Python Development Environment on AWS. You can follow instructions at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html to install these.Once you have all those installed, you need to set up a virtual environment so that your global packages do not get polluted. Use the following command to set up a virtual environment:$ virtualenv -p python2.7 /tmp/hello-world Running virtualenv with interpreter /usr/bin/python2.7 New python executable in /tmp/hello-world/bin/python2.7 Also creating executable in /tmp/hello-world/bin/python Installing setuptools, pip...done.Once your virtual environment is ready, start it by running the activate script located in the ... Read More

What is the convention for structuring Python modules?

Rajendra Dharmkar
Updated on 01-Oct-2019 06:44:20

108 Views

Here is a sample project that shows a very good way to structure your projects: https://github.com/kennethreitz/samplemod. The project is about creating the "sample" module. The directory structure looks as follows:README.rst LICENSE setup.py requirements.txt sample/__init__.py sample/core.py sample/helpers.py docs/conf.py docs/index.rst tests/test_basic.py tests/test_advanced.pyThe README.rst file: This file is for giving a brief description of the module, how to set it up, how to use it, etc.LICENSE: Contains license text and any copyright claims.setup.py: It is Python's answer to a multi-platform installer and makes file. If you’re familiar with command-line installations, then make && make install translates to python setup.py build && python setup.py ... Read More

How to install Python modules in Cygwin?

Rajendra Dharmkar
Updated on 01-Oct-2019 06:43:25

1K+ Views

While installing cygwin, make sure you install the python/python-setuptools from the list. This will install "easy_install" package. Once you have easy_install, you can use it to install pip. Type the following command:$ easy_install-a.b pipYou must replace a.b with your python version which can be 2.7 or 3.4 or whatever else. Now you can use pip to install the module you want. For example, To install the latest version of "SomeProject":$ pip install 'SomeProject'To install a specific version:$ pip install 'SomeProject==1.4'To install greater than or equal to one version and less than another:$ pip install 'SomeProject>=1,Read More

How to encapsulate Python modules in a single file?

Rajendra Dharmkar
Updated on 01-Oct-2019 06:42:13

563 Views

You cannot, in general encapsulate Python modules in a single file. Because doing so would destroy the module searching method that python uses (files and directories). If you are not able to install modules on a machine(due to not having enough permissions), you could use either virtualenv or save the module files in another directory and use the following code to allow Python to search for modules in the given module:>>> import os, sys >>> file_path = 'AdditionalModules/' >>> sys.path.append(os.path.dirname(file_path)) >>> # Now python also searches AdditionalModules folder for importing modules as we have set it on the PYTHONPATH.You can ... Read More

How do I find the location of Python module sources?

Manogna
Updated on 30-Sep-2019 09:02:50

10K+ Views

For a pure python module you can find the location of the source files by looking at the module.__file__. For example,  >>> import mymodule >>> mymodule.__file__ C:/Users/Ayush/mymodule.py  Many built in modules, however, are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, you can't see the source. You can manually go and check the PYTHONPATH variable contents to find the directories from where these built in modules are being imported.  Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to ... Read More

What are valid python identifiers?

Pythonista
Updated on 30-Sep-2019 09:00:47

673 Views

An identifier in a Python program is name given to various elements in it, such as keyword, variable, function, class, module, package etc. An identifier should start with either an alphabet (lower or upper case) or underscore (_). More than one alpha-numeric characters or underscore may follow.Keywords are predefined. They are in lowercase. They can not be used for any other purpose.By convention, name of class starts with uppercase alphabet. Whereas others start with lowercase alphabet.Single underscore in the beginning of a variable name is used to indicate a private variable.Two underscores in beginning indicate that the variable is strongly ... Read More

Why is indentation important in Python?

Malhar Lathkar
Updated on 30-Sep-2019 09:00:06

681 Views

Many a times it is required to treat more than one statements in a program as a block. Different programming languages use different techniques to define scope and extent of block of statements in constructs like class, function, conditional and loop. In C and C++ for example, statements inside curly brackets are treated as a block. Python uses uniform indentation to mark block of statements.Before beginning of block symbol : is used. First and subsequent statements in block are written by leaving additional (but uniform) whitespace (called indent) . In order to signal end of block, the whitespace is dedented. ... Read More

Advertisements