def divide(a, b):
try:
return a / b
except:
x = 17
My smart exception handling before meeting "pass" :))
zipped_file.extractall(f'{file_path}')
zipped_file.close()
{k: v for d in [{ key: { 0: x[0], } for key in x["name"] } for x in items] for k, v in d.items()}
for x,x1 in enumerate(hack):
if hack[x] in letters:
exception +=1
ffs why
if student_id:
assignments = Assignment.objects.filter(week__in=weeks)
unenrolled_students = Wave.objects.filter(week__in=weeks).values_list('unenrolled_students', flat=True)
# Construct responses based on assignment type
Assignment.build_assignments_for_weeks(responses, assignments, students, unenrolled_students)
max_num_assessments = Assessment.build_assessments_for_weeks(responses)
Comment.build_comments_for_weeks(responses, weeks, students, unenrolled_students)
elif wave_id:
assignments = Assignment.objects.filter(week__in=weeks)
unenrolled_students = Wave.objects.filter(week__in=weeks).values_list('unenrolled_students', flat=True)
# Construct responses based on assignment type
Assignment.build_assignments_for_weeks(responses, assignments, students, unenrolled_students)
max_num_assessments = Assessment.build_assessments_for_weeks(responses)
Comment.build_comments_for_weeks(responses, weeks, students, unenrolled_students)
else:
# can't happen
pass
def possibilities():
alphabets=(n,o,r,t,h,e,a,s,u,w,m,y)
combinations=list()
for n in range(9,-1,-1):
for o in range(9,-1,-1):
for r in range(9,-1,-1):
for t in range(9,-1,-1):
for h in range(9,-1,-1):
for e in range(9,-1,-1):
for a in range(9,-1,-1):
for s in range(9,-1,-1):
for u in range(9,-1,-1):
for w in range(9,-1,-1):
for m in range(9,-1,-1):
for y in range(9,-1,-1):
if len(set([n,o,r,t,h,e,a,s,u,w,m,y]))==12:
north=10000*n + 1000*o +100*r +10*t +h
east=1000*e +100*a +10*s +t
south=10000*s + 1000*o +100*u +10*t +h
west=1000*w + 100*e +10*s +t
earth= 10000*e + 1000*a + 100*r +10*t +h
if north +east +south +west == earth:
combinations.append((north,east,south,west,earth))
return combinations
def dow_to_dict_from_self(self):
# res = {'name': self.name, 'enabled': self.enabled }
res = {'sun': 0, 'mon': 0, 'tue': 0, 'wed': 0, 'thr': 0, 'fri': 0,
'sat': 0,
'enabled': 0, 'dow': 0, 'name': 'untitled'}
if (int(self.days_of_week) & 0x01) == 0x01: # sun
res['sun'] = 1
if (int(self.days_of_week) & 0x02) == 0x02: # mon
res['mon'] = 1
if (int(self.days_of_week) & 0x04) == 0x04: # tue
res['tue'] = 1
if (int(self.days_of_week) & 0x08) == 0x08: # wed
res['wed'] = 1
if (int(self.days_of_week) & 0x10) == 0x10: # thr
res['thr'] = 1
res['thu'] = 1 # '%a' returns thu for Thursday
if (int(self.days_of_week) & 0x20) == 0x20: # fri
res['fri'] = 1
if (int(self.days_of_week) & 0x40) == 0x40: # sat
res['sat'] = 1
if (int(
self.days_of_week) & 0x40) == 0x80: # enabled # new enable#
# flag -- duplicate in db
res['enabled'] = 1
res['enabled'] = self.enabled # remove this
res['dow'] = self.days_of_week
res['name'] = self.name
return res
kept the original comments - they're very helpful
# Weird list cleanup
product = "{0}".format(list(product))
product = re.sub(r"\), \(+", "], [", product)
product = re.sub(r"\(+", "[", product)
product = product.replace(")]", "]]").replace(")", "")
product = ast.literal_eval(product)
I don't know why I get this strange fomat for this array of objects... Ok let's do it fast: 1 - Convert array in string 2 - Clean up string 3 - Convert string in array
product = None
for key in dictionary.keys():
if product is None:
product = dictionary[key]
else:
product = itertools.product(product, dictionary[key])
product = "{0}".format(list(product))
product = re.sub(r"\), \(+", "], [", product)
product = re.sub(r"\(+", "[", product)
product = product.replace(")]", "]]").replace(")", "")
product = ast.literal_eval(product)
Ok, I have a weird array of objects as output of itertools and I need an array of strings... 1 - Convert the array to string 2 - Clean it up with regex and replace 3 - Convert the string to array 4 - Problem solved
def __getCurlOutput (self, url, **kwargs):
curlcmd = "curl {0}".format(url)
for key, value in kwargs.items():
key = key.lower()
if key == "origin":
curlcmd += " -H 'Origin: {0}'".format(value)
elif key == "contenttype":
curlcmd += " -H 'Content-Type: {0}'".format(value)
elif key == "referer":
curlcmd += " -H 'Referer: {0}'".format(value)
elif key == "cookie":
curlcmd += " -H 'Cookie: {0}'".format(value)
elif key == "data":
curlcmd += " --data '{0}'".format(value)
elif key == "verbose":
if value == True:
curlcmd += " --verbose"
else:
curlcmd += " --silent"
elif key == "output":
curlcmd += " --output {0}".format(value)
else:
print "Unsupported key: {0}".format(key)
curlcmd += " 2>&1"
print curlcmd
curlout = subprocess.check_output(curlcmd,shell=True)
return curlout
for data1, data2 in zip(results, results[1:]):
assert data1 <= data1
if data1 == data1:
assert data1 >= data1
A nice loop for making sure that data1 is equal to data1!
return [word for word in words if any(all(ch in row for ch in word.lower()) for row in rows)]
Filtering words that can be typed using only one row of the keyboard.
try:
raise
except RuntimeError:
raise
try this in python3
def get_schema(self, schema: object) -> object:
"""Get the Schema class
"""
if isinstance(schema, str):
Schema = getattr(self.request["operation"], schema, None)
else:
Schema = schema
if Schema is None:
Schema = getattr(self, schema, None)
if Schema is None:
raise web.HTTPNotImplemented
return Schema
I don't even know what to say
# Create vpc peering connection
response = ec2.delete_vpc_peering_connection(peer_connection_id)
a part of AWS Landing Zone solution