Loading...
More Python Posts
my_list = [1, 2, 3, 4, 5]removed_element = my_list.pop(2) # Remove and return element at index 2print(removed_element) # 3print(my_list) # [1, 2, 4, 5]last_element = my_list.pop() # Remove and return the last elementprint(last_element) # 5print(my_list) # [1, 2, 4]
import subprocess #for the praat callsimport os #for ffmpeg and the pause call at the end#Even if we wanted all videos being rendered asynchronously, we couldn't see progress or errorsimport glob #for the ambiguous filesimport tempfileaudioFileDirectory = 'Audio Files'timeList = {}fileList = glob.glob(audioFileDirectory + '\\*.wav')pipeList = {}for fileName in fileList:arglist = ['Praat.exe', '--run', 'crosscorrelateMatch.praat', 'zeussound.wav', fileName, "0" , "300"]print(' '.join(arglist))pipe = subprocess.Popen(arglist, stdout=subprocess.PIPE)pipeList[fileName[len(audioFileDirectory)+1:-4]] = pipe #+1 because of back slash, -4 because .wav#for fileName, pipe in pipeList.items():# text = pipe.communicate()[0].decode('utf-8')# timeList[fileName] = float(text[::2])for fileName, pipe in pipeList.items():if float(pipe.communicate()[0].decode('utf-8')[::2]) > .0003: #.000166 is not a match, and .00073 is a perfect match. .00053 is a tested matcharglist = ['Praat.exe', '--run', 'crosscorrelate.praat', 'zeussound.wav', audioFileDirectory + '\\' + fileName + '.wav', "0" , "300"]print(' '.join(arglist))text = subprocess.Popen(arglist, stdout=subprocess.PIPE).communicate()[0].decode('utf-8')timeList[fileName] = float(text[::2])clipLength = 10for fileName, time in timeList.items():arglist = ['ffmpeg', '-i', '"'+fileName+'.mp4"', '-ss', str(time-clipLength), '-t', str(clipLength*2), '-acodec', 'copy' , '-vcodec', 'copy', '"ZEUS'+ fileName + '.mp4"']print(' '.join(arglist))os.system(' '.join(arglist))tempFile = tempfile.NamedTemporaryFile(delete=False)for fileName in glob.glob('ZEUS*.mp4'):tempFile.write(("file '" + os.path.realpath(fileName) + "'\n").encode());tempFile.seek(0)print(tempFile.read())tempFile.close()arglist = ['ffmpeg', '-safe', '0', '-f', 'concat', '-i', '"'+tempFile.name+'"', '-c', 'copy', 'ZeusMontage.mp4']print(' '.join(arglist))os.system(' '.join(arglist))os.unlink(tempFile.name) #Delete the temp file#print(timeList)os.system('PAUSE')
bytes_data = b'Hello, World!'string_data = bytes_data.decode('utf-8')print("String:", string_data)
primes=[]products=[]def prime(num):if num > 1:for i in range(2,num):if (num % i) == 0:return Falseelse:primes.append(num)return Truefor n in range(30,1000):if len(primes) >= 20:break;else:prime(n)for previous, current in zip(primes[::2], primes[1::2]):products.append(previous * current)print (products)
class Rectangle:passclass Square(Rectangle):passrectangle = Rectangle()square = Square()print(isinstance(rectangle, Rectangle)) # Trueprint(isinstance(square, Rectangle)) # Trueprint(isinstance(square, Square)) # Trueprint(isinstance(rectangle, Square)) # False
# question3.pyfrom itertools import productV='∀'E='∃'def tt(f,n) :xss=product((0,1),repeat=n)print('function:',f.__name__)for xs in xss : print(*xs,':',int(f(*xs)))print('')# this is the logic for part A (p\/q\/r) /\ (p\/q\/~r) /\ (p\/~q\/r) /\ (p\/~q\/~r) /\ (~p\/q\/r) /\ (~p\/q\/~r) /\ (~p\/~q\/r) /\ (~p\/~q\/~r)def parta(p,q,r) :a=(p or q or r) and (p or q or not r) and (p or not q or r)and (p or not q or not r)b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)c= a and breturn cdef partb(p,q,r) :a=(p or q and r) and (p or not q or not r) and (p or not q or not r)and (p or q or not r)b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)c= a and breturn cprint("part A:")tt(parta,3)print("part B:")tt(partb,3)