Python Code Samples



Filters


gaya38
Generate Random number within the range in python
gaya38 | 6 years, 6 months
import random
print random.uniform(10,500)
python
Connect to MySQL database with python mysql connector
kishore_kumar | 6 years
# pip install mysql-connector

from mysql import connector
python mysql mysql-connector
Run SQL update statement using python pyodbc
kishore_kumar | 5 years, 3 months
import pyodbc

conn = pyodbc.connect('Driver={SQL Server};'
pyodbc python
Get os details using python os
kishore_kumar | 6 years, 9 months
import os
print os.uname()
# Don't use os.system('uname -a'), its just executing "uname -a" comman
python python-os
Connect to mongo db using python and list of databases
kishore_kumar | 6 years, 1 month
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017")
pymongo python mongodb
Matrix transpose using list comprehensions in python
harika | 6 years, 2 months
a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
#Procedure1:--------
transposed = [[row[i] for row in a ] fo
List comprehensions in python basically reduce the loc. Check the difference between two procudures
python matrix list
sandeep
Shell Script to Generate the SSH key and display it on output screen also create virtualenv
sandeep | 6 years, 9 months
export PATH=$WORKSPACE/resources/chromedriver/mac:$WORKSPACE/venv/bin:/usr/local/bin:$PATH
export P
shell auto ssh key
Ramya
PYTHON: To download AWS ELB access log files from S3 bucket based on last modified time
Ramya | 5 years, 1 month
import boto3
import datetime
from datetime import datetime,timedelta,date
Before using this script, you need to set up AWS CLI first as below: ubuntu@ip-172-31-46-2:~$ aws
python boto3 s3
fetch all documents from mongo db collection using python
kishore_kumar | 6 years, 1 month
import pymongo

client = pymongo.MongoClient("mongodb://localhost:27017")
pymongo python mongodb
How to connect to PostgreSQL database and display list of tables in python
kishore_kumar | 6 years, 1 month
import psycopg2

conn = psycopg2.connect(host="localhost", database="mydb", user="kishore", passwo
python psycopg2 postgresql
Prev Next