You are on page 1of 3

import os

#Write your code here


s=os.getcwd()

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()

with open('.hidden.txt','w') as outfile:


outfile.write(s)
with open('.hidden1.txt', 'w') as outfile:
outfile.write(q)
with open('.hidden2.txt', 'w') as outfile:
outfile.write(p)
with open('.hidden3.txt', 'w') as outfile:
outfile.write(w)

# 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)

# Print path of newly


# created file
print("Destination path:", dest)

with open('.hidden.txt','w') as outfile:


outfile.write(dest)

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)

with open('.hidden.txt','w') as outfile:


outfile.write(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)

#Write code here to store the object in pickle file


with open("test.pickle","wb") as outfile:
pickle.dump(myPlayer,outfile,protocol=pickle.HIGHEST_PROTOCOL)

del myPlayer

#Write code here to read the pickle file


with open("test.pickle","rb") as outfile:
data=pickle.load(outfile)
print(data.name)
print(data.runs)

safe_builtins = { 'range',
'complex',
'set',
'frozenset'}

class RestrictedUnpickler(pickle.Unpickler):

def find_class(self, module, name):


# Only allow safe classes from builtins.
if module == "builtins" and name in safe_builtins:
return getattr(builtins, name)
# Forbid everything else.
raise pickle.UnpicklingError("global '%s.%s' is forbidden" %
(module, name))

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=[]

for i,j in a.items():


datas=j
return 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

You might also like