You are on page 1of 1

1)import os.

path
#to check if the file exists
open(file.txt,'w')
os.path.isfile(file.txt)

32 bit or 64 bit
2)import struct
struct.calcsize("P")*8)

3)import platform
import os
os.name
platform.system
platform.release

4) to get site packages


import site
print(site.getsitepackages())

5) from subprocess import call


call(["ls","-l"])

6)to get full path of file executing


import os
os.path.realpath(__file__)
7)to find cpu usage:
import multiprocessing
multiprocessing.cpu_count()
8)to list all files in a list directory:
from os import listdir
form os.path import isfile,join
files_list=[f for f in listdir('dir') if isfile(join('dir',f))]
9)import cProfile
def sum():
print(1+2)
cProfile.run(sum())
10) from __future__ import print_function
import sys
def eprint(*args,**kwargs):
print(*args,file=sys.stderr, **kwargs)
eprint("abc","efg","xyz",sep="--")
11) to access environment variables:
import os
os.environ
os.environ['HOME']
12)to get the current username
import getpass
getpass.getuser()
13)import socket
host_name= socket.gethostname()
14) from http.client import HTTPConnection
conn=HTTPConnection("url")
conn.request("GET","/")
result= conn.getresponse()
result.read()
15) import subprocess
returned_text= subprocess.check_output("

You might also like