Best Python code snippet using tempest_python
volume.py
Source:volume.py
...19 new_volume = new_volume.read().decode(encoding = 'UTF-8')20 return new_volume.strip()21 else:22 pass23def show_volume(volume_string):24 if PULSEAUDIO_RUNNING:25 subprocess.Popen(['killall', 'xosd'], stderr=subprocess.PIPE).wait()26 subprocess.Popen(['killall', 'osd_cat'], stderr=subprocess.PIPE).wait()27 s = subprocess.Popen(['ponymix', 'is-muted'])28 s.wait()29 muted = ''30 if s.returncode != 1:31 muted = ' (Muted)'32 args = ['myxosd',33 '--barmode=percentage',34 '--percentage=%s' % volume_string,35 '--text=%s' % 'Volume: ' + volume_string + muted]36 subprocess.Popen(args)37 else:38 pass39def toggle_mute():40 if PULSEAUDIO_RUNNING:41 new_volume = subprocess.Popen(['ponymix', 'toggle'], stdout=subprocess.PIPE).stdout42 new_volume = new_volume.read().decode(encoding = 'UTF-8')43 return new_volume.strip()44 else:45 pass46delta = 547if len(sys.argv) <= 1:48 sys.exit(0)49action = sys.argv[1]50if action == 'incr':51 new_volume = adjust_volume(delta)52 show_volume(new_volume)53elif action == 'decr':54 new_volume = adjust_volume(-delta)55 show_volume(new_volume)56elif action == 'toggle':57 new_volume = toggle_mute()...
09Informal_interfaces.py
Source:09Informal_interfaces.py
...67 def volume_down(self):8 pass910 def show_volume(self):11 pass121314class RemoteControl(Controller):15 def __init__(self):16 self.__volume = 01718 def __get_volume(self):19 return self.__volume2021 def __set_volume(self, val: int):22 self.__volume = val2324 # these are the concrete implementations of the abstract methods25 def volume_up(self):26 if self.__get_volume() < 100:27 self.__set_volume(self.__get_volume() + 10)2829 def volume_down(self):30 if self.__get_volume() > 0:31 self.__set_volume(self.__get_volume() - 10)3233 def show_volume(self):34 print('Volume ', end='')35 for i in range(0, self.__get_volume(), 10):36 print('I', end='')37 print()383940def main():41 c = RemoteControl()4243 c.show_volume()44 for i in range(10):45 c.volume_up()46 c.show_volume()47 for i in range(5):48 c.volume_down()49 c.show_volume()5051 # Such informal interfaces are fine for small projects where only a52 # few developers are working on the source code. However, as projects53 # get larger and teams grow, this could lead to developers spending54 # countless hours looking for hard-to-find logic errors in the codebase!555657if __name__ == '__main__':
...
1_abstract-methods.py
Source:1_abstract-methods.py
1#example to show to make a method abstract 2class Container:3 def __init__(self,i):4 self.x = i5 def show_volume(self):6 raise NotImplementedError("Sub classes must impliment this method")7class Cube(Container):8 def __init__(self,a):9 Container.__init__(self,a)10 def show_volume(self):11 print("Volume of the cube is " + str(self.x*self.x*self.x))12class Cuboid(Container):13 def __init__(self,l,b,h):14 self.length = l15 self.bredth = b16 self.height = h 17 Container.__init__(self,l) 18 def show_volume(self):19 print("Volume of the cuboid is "+ str(self.length*self.bredth*self.height))20c1 = Cube(5)21c1.show_volume()22c2 = Cuboid(1,2,3)23c2.show_volume()24c32 = Container(9)...
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!!