Best Python code snippet using ATX
testg.py
Source:testg.py
...306307 if (j1>j1min):308 j2=310309 j7=580310 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))311 time.sleep(delay)312 313 j4=435314 j1=450315 j3=450316 317 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))318 time.sleep(delay)319 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))320 time.sleep(delay)321 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))322 time.sleep(delay)323 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))324 time.sleep(delay)325326327 j2=358328 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))329 time.sleep(delay)330 331 332 333334 335 j2=286336 j7=458337 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))338 time.sleep(delay)339 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))340 time.sleep(delay)341 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))342 time.sleep(delay)343344 345 j1=524346 j3=490347 j2=258348 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))349 time.sleep(delay)350 351 j7=500352 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))353 time.sleep(delay)354 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))355 time.sleep(delay)356 357 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))358 time.sleep(delay+3)359 j1=450360 j3=450361 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))362 time.sleep(delay)363 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))364 time.sleep(delay)365366367 368 369 print(j1)370 print (self.ser.readline())371 372373 374 375 376 def write_Left(self):377 global RightLeftCounter378 if (RightLeftCounter>0):379 RightLeftCounter -=stepsize380 self.ser.write(bytearray(RightLeftCounter))381 print(RightLeftCounter)382 print (self.ser.readline())383 384 def write_Right(self):385 global RightLeftCounter386 if (RightLeftCounter<180):387 RightLeftCounter +=stepsize388 self.ser.write(bytearray(RightLeftCounter))389 print(RightLeftCounter)390 print (self.ser.readline())391 def write_reset(self):392 global RightLeftCounter393 RightLeftCounter = 90394 print(RightLeftCounter)395 self.ser.write(bytearray(RightLeftCounter))396 print (self.ser.readline())397 398 def write_sweep(self):399 global RightLeftCounter400 for RightLeftCounter in range(0,180):401 print(RightLeftCounter)402 self.ser.write(bytearray(RightLeftCounter))403 print (self.ser.readline())404 time.sleep(0.01) # delays for 1 seconds405 RightLeftCounter = 90406 self.ser.write(bytearray(RightLeftCounter))407 408####################################################409 def convstr(self,n):410 if (n<100):411 return ('0'+str(n))412 else:413 return str(n)414415 416 def writej1_Left(self):417 global j1418 if (j1>j1min):419 j1 -=stepsize420 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))421 print(j1)422 print (self.ser.readline())423 424 def writej1_Right(self):425 global j1426 if (j1<j1max):427 j1 +=stepsize428 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))429 print(j1)430 print (self.ser.readline())431 def writej1_reset(self):432 global j1433 j1 = j1av434 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))435 print('j01'+self.convstr(j1))436 print (self.ser.readline())437 438 def writej1_sweep(self):439 global j1440 for j1 in range(0,180):441 print(j1)442 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))443 print (self.ser.readline())444 time.sleep(0.01) # delays for 1 seconds445 j1 = 90446 self.ser.write(bytearray('j01'+self.convstr(j1), 'utf8'))447448 ####################################################449450 def writej2_Left(self):451 global j2452 if (j2>j2min):453 j2 -=stepsize454 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))455 print(j2)456 print (self.ser.readline())457 458 def writej2_Right(self):459 global j2460 if (j2<j2max):461 j2 +=stepsize462 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))463 print(j2)464 print (self.ser.readline())465 def writej2_reset(self):466 global j2467 j2 = j2av468 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))469 print('j02'+self.convstr(j2))470 print (self.ser.readline())471 472 def writej2_sweep(self):473 global j2474 for j2 in range(0,280):475 print(j2)476 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))477 print (self.ser.readline())478 time.sleep(0.01) # delays for 1 seconds479 j1 = 90480 self.ser.write(bytearray('j02'+self.convstr(j2), 'utf8'))481482483 ####################################################484485 def writej3_Left(self):486 global j3487 if (j3>j3min):488 j3 -=stepsize489 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))490 print(j3)491 print (self.ser.readline())492 493 def writej3_Right(self):494 global j3495 if (j3<j3max):496 j3 +=stepsize497 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))498 print(j3)499 print (self.ser.readline())500 def writej3_reset(self):501 global j3502 j3 = j3av503 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))504 print('j03'+self.convstr(j3))505 print (self.ser.readline())506 507 def writej3_sweep(self):508 global j3509 for j3 in range(0,380):510 print(j3)511 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))512 print (self.ser.readline())513 time.sleep(0.01) # delays for 1 seconds514 j1 = 90515 self.ser.write(bytearray('j03'+self.convstr(j3), 'utf8'))516517 518 ####################################################519520 def writej4_Left(self):521 global j4522 if (j4>j4min):523 j4 -=stepsize524 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))525 print(j4)526 print (self.ser.readline())527 528 def writej4_Right(self):529 global j4530 if (j4<j4max):531 j4 +=stepsize532 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))533 print(j4)534 print (self.ser.readline())535 def writej4_reset(self):536 global j4537 j4 = j4av538 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))539 print('j04'+self.convstr(j4))540 print (self.ser.readline())541 542 def writej4_sweep(self):543 global j4544 for j4 in range(0,480):545 print(j4)546 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))547 print (self.ser.readline())548 time.sleep(0.01) # delays for 1 seconds549 j1 = 90550 self.ser.write(bytearray('j04'+self.convstr(j4), 'utf8'))551552 553 ####################################################554555 def writej5_Left(self):556 global j5557 if (j5>j5min):558 j5 -=stepsize559 self.ser.write(bytearray('j05'+self.convstr(j5), 'utf8'))560 print(j5)561 print (self.ser.readline())562 563 def writej5_Right(self):564 global j5565 if (j5<j5max):566 j5 +=stepsize567 self.ser.write(bytearray('j05'+self.convstr(j5), 'utf8'))568 print(j5)569 print (self.ser.readline())570 def writej5_reset(self):571 global j5572 j5 = j5av573 self.ser.write(bytearray('j05'+self.convstr(j5), 'utf8'))574 print('j05'+self.convstr(j5))575 print (self.ser.readline())576 577 def writej5_sweep(self):578 global j5579 for j5 in range(0,580):580 print(j5)581 self.ser.write(bytearray('j05'+self.convstr(j5), 'utf8'))582 print (self.ser.readline())583 time.sleep(0.01) # delays for 1 seconds584 j1 = 90585 self.ser.write(bytearray('j05'+self.convstr(j5), 'utf8'))586587####################################################588589 def writej6_Left(self):590 global j6591 if (j6>j6min):592 j6 -=stepsize593 self.ser.write(bytearray('j06'+self.convstr(j6), 'utf8'))594 print(j6)595 print (self.ser.readline())596 597 def writej6_Right(self):598 global j6599 if (j6<j6max):600 j6 +=stepsize601 self.ser.write(bytearray('j06'+self.convstr(j6), 'utf8'))602 print(j6)603 print (self.ser.readline())604 def writej6_reset(self):605 global j6606 j6 = j6av607 self.ser.write(bytearray('j06'+self.convstr(j6), 'utf8'))608 print('j06'+self.convstr(j6))609 print (self.ser.readline())610 611 def writej6_sweep(self):612 global j6613 for j6 in range(0,680):614 print(j6)615 self.ser.write(bytearray('j06'+self.convstr(j6), 'utf8'))616 print (self.ser.readline())617 time.sleep(0.01) # delays for 1 seconds618 j1 = 90619 self.ser.write(bytearray('j06'+self.convstr(j6), 'utf8'))620 621622 623 ####################################################624625 def writej7_Left(self):626 global j7627 if (j7>j7min):628 j7 -=stepsize629 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))630 print(j7)631 print (self.ser.readline())632 633 def writej7_Right(self):634 global j7635 if (j7<j7max):636 j7 +=stepsize637 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))638 print(j7)639 print (self.ser.readline())640 def writej7_reset(self):641 global j7642 j7 = j7av643 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))644 print('j07'+self.convstr(j7))645 print (self.ser.readline())646 647 def writej7_sweep(self):648 global j7649 for j7 in range(0,780):650 print(j7)651 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))652 print (self.ser.readline())653 time.sleep(0.01) # delays for 1 seconds654 j1 = 90655 self.ser.write(bytearray('j07'+self.convstr(j7), 'utf8'))656 657 ####################################################658659 def writej14_Left(self):660 global j14661 if (j14>j14min):662 j14 -=stepsize663 self.ser.write(bytearray('j14'+self.convstr(j14), 'utf8'))664 print(j14)665 print (self.ser.readline())666 667 def writej14_Right(self):668 global j14669 if (j14<j14max):670 j14 +=stepsize671 self.ser.write(bytearray('j14'+self.convstr(j14), 'utf8'))672 print(j14)673 print (self.ser.readline())674 def writej14_reset(self):675 global j14676 j14 = j14av677 self.ser.write(bytearray('j14'+self.convstr(j14), 'utf8'))678 print('j014'+self.convstr(j14))679 print (self.ser.readline())680 681 def writej14_sweep(self):682 global j14683 for j14 in range(0,1480):684 print(j14)685 self.ser.write(bytearray('j14'+self.convstr(j14), 'utf8'))686 print (self.ser.readline())687 time.sleep(0.01) # delays for 1 seconds688 j1 = 90689 self.ser.write(bytearray('j14'+self.convstr(j14), 'utf8'))690 691692 ####################################################693694 def writej15_Left(self):695 global j15696 if (j15>j15min):697 j15 -=stepsize698 self.ser.write(bytearray('j15'+self.convstr(j15), 'utf8'))699 print(j15)700 print (self.ser.readline())701 702 def writej15_Right(self):703 global j15704 if (j15<j15max):705 j15 +=stepsize706 self.ser.write(bytearray('j15'+self.convstr(j15), 'utf8'))707 print(j15)708 print (self.ser.readline())709 def writej15_reset(self):710 global j15711 j15 = j15av712 self.ser.write(bytearray('j15'+self.convstr(j15), 'utf8'))713 print('j015'+self.convstr(j15))714 print (self.ser.readline())715 716 def writej15_sweep(self):717 global j15718 for j15 in range(0,1580):719 print(j15)720 self.ser.write(bytearray('j15'+self.convstr(j15), 'utf8'))721 print (self.ser.readline())722 time.sleep(0.01) # delays for 1 seconds723 j1 = 90724 self.ser.write(bytearray('j15'+self.convstr(j15), 'utf8'))725 726727 728729 730731def main():732 ser = serial.Serial()733 ser.port = 'COM5'734 ser.baudrate = 9600735 ser.timeout = 0736 # open port if not already open737 if ser.isOpen() == False:738 ser.open()
...
AnalysisDBFactory2.py
Source:AnalysisDBFactory2.py
...67 68 print "Error %s:" % e.args[0]69 return False70 return True71 def convstr(self,tmpstr):72 if tmpstr is None:73 return tmpstr74 elif isinstance(tmpstr,int):75 return tmpstr76 else:77 return "'"+tmpstr+"'"78 def saveAnalysis(self,anaobj):79 """ Save Analysis Object """80 with self.con:81 82 cur = self.con.cursor() 83 data = {}84 85 id = self.convstr(anaobj.id)86 name = self.convstr(anaobj.name)87 owner = self.convstr(anaobj.owner)88 owner_email = self.convstr(anaobj.owner_email)89 90 current_status= self.convstr(anaobj.current_status)91 output_status = self.convstr(anaobj.output_status)92 input_files = self.convstr(anaobj.input_files)93 input_types = self.convstr(anaobj.input_types)94 input_dir = self.convstr(anaobj.input_dir)95 working_dir = self.convstr(anaobj.working_dir)96 output_dir = self.convstr(anaobj.output_dir)97 output_files = self.convstr(anaobj.output_files)98 output_types = self.convstr(anaobj.output_types)99 commands = self.convstr(anaobj.commands)100 output_str = self.convstr(anaobj.output_str)101 summary_data = self.convstr(anaobj.summary_data)102 runtype = self.convstr(anaobj.runtype)103 param = self.convstr(anaobj.param)104 queue = self.convstr(anaobj.queue)105 slurmid = self.convstr(anaobj.slurmid)106 cores = self.convstr(anaobj.cores)107 mempercore = self.convstr(anaobj.mempercore)108 date_created = self.convstr(anaobj.date_created)109 110 if id == None: # This is a new analysis111 112 sql = "insert into Analysis(Name,Owner,OwnerEmail,CurrentStatus,OutputStatus,InputDir,WorkingDir,OutputDir,RunType,Param,Queue,SlurmId,Cores,MemPerCore,DateCreated) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d,%d,%d,%s)" % (name,owner,owner_email,current_status,output_status,input_dir,working_dir,output_dir,runtype,param,queue,slurmid,cores,mempercore,date_created)113 114 cur = self.executeQuery(sql)115 116 id = cur.lastrowid117 118 anaobj.id = id119 120 logging.info("ID is %s" % id)121 else: # This is an updated analysis122 sql = "update Analysis set Name='%s', Owner='%s', OwnerEmail='%s', CurrentStatus='%s', OutputStatus='%s', InputDir='%s', WorkingDir='%s', OutputDir='%s', RunType='%s',Param='%s',Queue='%s',SlurmId=%d,Cores=%d, MemPerCore=%d where ID = %d" % (name,owner,owner_email,current_status,output_status,input_dir,working_dir,output_dir,runtype,param,queue,slurmid,cores,mempercore,id)...
zigzag-conversion.py
Source:zigzag-conversion.py
1class Solution:2 def convert(self, s: str, numRows: int) -> str:3 n = len(s)4 if n == 1 or numRows == 1:5 return s6 interval = (2*numRows) - 27 convstr = ""8 for i in range(numRows):9 for c in range(i,n,interval):10 convstr = convstr + s[c]11 if numRows-1 > i > 0 and c+interval-2*i < n:12 convstr = convstr + s[c+interval-2*i]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!