Professional Documents
Culture Documents
os.mkdir('New Folder')
os.chdir('/projects/challenge/New Folder')
q=os.getcwd()
os.rename('/projects/challenge/New Folder','/projects/challenge/New Folder2')
p=os.getcwd()
os.rmdir('/projects/challenge/New Folder2')
os.chdir('/projects/challenge/')
w=os.getcwd()
# Source path
source = os.path.join('/projects/challenge/New Dir/newww.txt')
# Destination path
destination = os.path.join('/projects/challenge/')
# Copy the content of
# source to destination
dest = shutil.copy(source,destination)
import pickle
import os
data={
"a":[5,9],
"b":[5,6],
"c":["Pickle is","helpful"]
}
#Dump file in pickle
with open("test.pkl","wb") as outfile:
pickle.dump(data,outfile)
del data
#Read data back from pickle
with open("test.pkl","rb") as outfile:
data=pickle.load(outfile)
print(data)
pickles = []
for root,dirs,files in os.walk("./"):
# root is the dir we are currently in, f the filename that ends on ...
pickles.extend( (os.path.join(root,f) for f in files if
f.endswith(".pkl")) )
pickles=str(pickles)
print(pickles)
class Player:
def __init__(self, name , runs):
self.name=name
self.runs=runs
#Write code here to access value for name and runs from class PLayer
myPlayer=Player('dhoni',10000)
del myPlayer
safe_builtins = { 'range',
'complex',
'set',
'frozenset'}
class RestrictedUnpickler(pickle.Unpickler):
def restricted_loads(s):
"""Helper function analogous to pickle.loads()."""
return RestrictedUnpickler(io.BytesIO(s)).load()
def func1(a):
try:
x=restricted_loads(pickle.dumps(a))
return x
except pickle.UnpicklingError :
s=traceback.format_exc()
return s
def func2(s):
try:
x=restricted_loads(pickle.dumps(slice(0, 8, 3)))
return s[x]
except pickle.UnpicklingError :
s=traceback.format_exc()
return s
def func1(value):
a=json.loads(value)
datas=[]
def func1(value):
a=json.dumps(json.loads(value))
b=json.loads(a)
return b
response = requests.get('https://api.github.com')
try:
a=response.status_code
b=response.encoding
c=response.text
print(a)
print(b)
print(c)
def func1(y,m,d,ms,se,da,mi):
input_date = datetime.date(y,m,d)
input_date1 = datetime.datetime( y,m,d,ms,se,da,mi)
t = input_date1 - datetime.timedelta(microseconds=1, seconds=2,
days=3,minutes=2)
day = t.day
year= t.strftime("%Y")
month =t.month
minute=t.minute
second=t.second
return input_date,input_date1,t,day,year,month,minute,second
def func2(y,m,d,ms,se,da,mi):
if m>mi:
mi+=1
if mi>m:
mi-=3
s='%a %b %d %H %M: %S %Y'
x=datetime.datetime(y,m,d,ms,se,da,mi)
q=x.strftime(s)
z=datetime.datetime.strptime(q,s)
return x,q,z