python get environment variable example code

An environment variable is simply a variable its values defined outside the application in this section we are going to explore how to get value of environment variable in python .so first we have to check how to set environment variable in python after that how to get that environment variable value.”print(os.environ)” is used to print all the value of all environment variable.

To work with environment variables in Python is the same like working with dictionaries. first you need to import the os module.

import os

/* To get the value of all environment variable value in python */

 

print(os.environ)

 

/* To set the environment variable value by name in python */

# To Set environment variables in python

os.environ['EMAIL'] = '[email protected]' 

os.environ['USER_ID'] = '4568'




/* To get the environment variable value by name in python */

 


# To get environment variables in python

import os
USER_EMAIL = os.environ.get('EMAIL') 
print(USER_EMAIL)
USER_ID = os.environ.get('USER_ID') 
print(USER_ID)

python if else in one line like ternary operator

Being a programmer we heard about conditional expressions ,an expression that give you true or false result based on a condition ,here in python how we are going to deal with  ‘  python if else in one line  ‘ ,so let we check how to create an if else statement in one line

suppose we  have below if else statement

if x > 100:
   y = 1
else:
   y = 0
so how to convert above if else statement using python if else one in line
y= 1 if x > 100 else 0

This is simple way to write if else one in line using python

See more

x if cond else y
in simple if condiotion is true the value is x otherwise y

see example

y= "prime" if x =7 else "Non prime"

print(y)

jQuery code to copy input value to clipboard

Here we are going to explore jQuery code to copy input value to clipboard,Fortunately we have jQuery library function to copy value to clipboard see the code in details to copy input value to clipboard

 
document.execCommand("copy");

Now see in details jQuery code to copy input value to clipboard

Suppose i have an input field with id result_value

<input type="text" size="12" class="result_input" id="result_value" value="jQuery code to copy input value to clipboard">

I have to copy the the value to clipborad

<script>
(function ( $ ) {
$.fn.copy_text = function() {
$( ".result_value" ).blur(function() {
$("#result_value").select();
document.execCommand("copy");
});
}; 
}( jQuery ));
$('input').copy_text();
</script>

In simple  jQuery code to copy input value to clipboard

$( ".result_value" ).blur(function() {
$("#result_value").select();
document.execCommand("copy");
});

See Demo
copy input value to clipboard

How to convert AWS .pem key to putty .ppk key

Here I have AWS key .pem , to connect with putty in windows we need the .ppk format ,so here i have to convert AWS .pem key to putty .ppk key ,in simple have to convert .pem to .ppk

How convert AWS .pem key to putty .ppk key for that we have lots of software available, here am going to show with the help of  PuTTYgen

1 Download .pem (Privacy Enhanced Mail) from  AWS , is a base64 container format for encoding keys and certificates

 

2 ) Download PuTTYgen from online and install

 

3) Open PuTTYgen

convert AWS .pem key to putty .ppk key

4) Click Load button and load the .pem files

convert AWS .pem key to putty .ppk key

5) Click “save private key ” button and save your ppk files

so you converted AWS .pem key to Putty Private Key(ppk) or in simple .pem to .ppk