Best Python code snippet using slash
parameter_server.py
Source:parameter_server.py  
...49                print(f'{l._address}:{l._port}')50        if len(self.parameters) > 0:51            print(' --- Parameters ---')52            for p in self.parameters:53                print(f'{p.get_full_address()} -- {str(p.value)}')54                for c in p._value_callbacks:55                    print(f'callback:  {c.__name__}')56        57        if len(self.bundles) > 0:58            print(' --- Bundles ---')59            for name, instances in self.bundles.items():60                print(f'name: {name} instances: {instances.keys()}')61                for instance_id,params in instances.items():62                    print(f'{instance_id} -----------')63                    for p in params:64                        print(f'{instance_id}:: {p.get_full_address()} -- {str(p.value)}')65#                         for c in p._value_callbacks:66#                             print(f'callback:  {c.__name__}')67    68    def monitor_server(self, timeout: float = 30):69        timeAccum = 0.070        while timeAccum < timeout or timeout == 0:71            timeAccum += 0.172            time.sleep(0.1)73#             yield74        75    def register_parameter(self, p):76        for existing in self.parameters:77            if existing.get_full_address() == p.get_full_address():78                print(f"Parameter {new_param.get_full_address()} already registered")79                return80        p.observers.append(self)81        self.parameters.append(p)82        83        self.dispatcher.map(p.get_full_address(), self.set_parameter_value, p,84                           needs_reply_address = True)85        86    87    def register_bundle_parameter(self, p, bundle_name :str, bundle_id : str):88        if not bundle_name in self.bundles:89            self.bundles[bundle_name] = {}90        if not bundle_id in self.bundles[bundle_name]:91            self.bundles[bundle_name][bundle_id] = []92        93        for existing in self.bundles[bundle_name][bundle_id]:94            if existing.get_full_address() == p.get_full_address():95                print(f"Parameter {p.get_full_address()} already registered in bundle {bundle_name}:{bundle_id}")96                return97        self.bundles[bundle_name][bundle_id].append(p)98        99        p.parent_bundle = (bundle_name, bundle_id)100        101        p.observers.append(self)102    def get_parameter(self, name):103        for p in self.parameters:104            if p.name == name:105                return p106            107        return None108    109    def get_parameter_from_bundle(self, bundle_name, bundle_id, name):110        for p in self.bundles[bundle_name][bundle_id]:111            if p.name == name:112                return p113        return None114    def register_parameters(self, params):115        for p in params:116            self.register_parameter(p)117            118    def request_all_parameter_values(self):119        self.app_connection.request_all_parameter_values()120    121    def request_parameters(self):122        self.app_connection.request_parameters()123        124    def default_osc_handler(self, client_address, addr, p: str, *args):125        for bundle_name, bundles in self.bundles.items():126            for bundle_id, params in bundles.items():127                prefix = f'/{bundle_name}/{bundle_id}'128                129                if addr.find(prefix) == 0:130                    for p in params:131                        bundle_param_name = prefix + p.get_full_address()132                        if bundle_param_name == addr:133                    134                            p.set_value(p, client_address)135                    #         if not p[0].value == args[0]:136                    #             p[0].value = args[0]137                    #        print("got parameter message " + str(addr) + str(args))138    139    def set_parameter_value(self, client_address, addr, p: str, *args):140        # TODO there should be a way to select whether to relay duplicates or not, perhaps depending on a role141        p[0].set_value(args[0], client_address)142#         if not p[0].value == args[0]:143#             p[0].value = args[0]144        print("got parameter message " + str(addr) + str(args))145        146    def add_listener(self, ip: str, port: int):147        print("Register listener " + ip + ":" + str(port))148        for l in self.listeners:149            if l._address == ip and l._port == port:150                print("Already registered ignoring request.")151                return152        self.listeners.append(udp_client.SimpleUDPClient(ip, port))153        154    def server_thread_function(self, ip: str, port: int):155        port_to_try = port156        self.server = None157        while not self.server and port_to_try < port + 100:158            try:159                self.server = osc_server.ThreadingOSCUDPServer(160                  (ip, port_to_try), self.dispatcher)161                self.server.timeout = 1.0162            except Exception as e:163                port_to_try += 1164                print(f"Now trying port {port_to_try}")165        166        if not self.server:167            print("Error. Could not find free port for Parameter Server")168            return169        170        print("Parameter server started on {}".format(self.server.server_address))171        while self.running:172            self.server.handle_request()173            174        self.server.server_close()175        print("Closed parameter server")176        self.server = None177        178    def _send_parameter_value(self, p, source_address):179        for l in self.listeners:180            parent_prefix = ''181            if p.parent_bundle:182                parent_prefix = f'/{p.parent_bundle[0]}/{p.parent_bundle[1]}'183            184            print("Sending " + parent_prefix + p.get_full_address() + " from " + str(source_address))185            print("******* to " + l._address)186            if not source_address or not source_address[0] == l._address:187                l.send_message(parent_prefix + p.get_full_address(), p.value)188            else:189                print("Blocked return message for " + source_address[0])190                pass191            ...shipping_label.py
Source:shipping_label.py  
...30            'get_street': self.get_street,31            'get_street2': self.get_street2,32            'get_full_address': self.get_full_address,33        })34    def get_full_address(self, partner):35        address = partner.street and partner.street + ' / ' or ''36        address += partner.street2 and partner.street2 + ' / ' or ''37        address += partner.city and partner.city.name + ' / ' or ''38        address += partner.state_id and partner.state_id.name + ' / ' or ''39        address += partner.zip and partner.zip.name + ' / ' or ''40        address += partner.country_id and partner.country_id.name + ' / ' or ''41        if address:42            address = address[:-3]43        return address44    def get_street(self, partner):45        return partner.street or ''46    def get_street2(self, partner):47        return partner.street2 or ''48    def get_address(self, partner):...OOP Case study.py
Source:OOP Case study.py  
...3        self.house_no=house_no 4        self.street=street5        self.city=city6        self.country=country7    def get_full_address(self):8        return "H. No. "+str(self.house_no)+", Street "+str(self.street)+", "+str(self.city)+" "+str(self.country)9    def __str__(self):10        return self.get_full_address()11class Employee:12    def __init__(self, id=1,name=None):13        self.id=id14        self.name=name15        self.current_address=None16        self.permanent_address=None17    def set_current_address(self ,house_no, street, city, country):18        self.current_address=Address(house_no, street, city,country)19    def set_permanent_address(self,house_no, street, city,country):20        self.permanent_address=Address(house_no, street, city,country)21    def get_current_address(self):22        if self.current_address is None:23            return None24        return self.current_address.get_full_address()25    def get_permanent_address(self):26        if self.permanent_address is None:27            return None28        return self.permanent_address.get_full_address()29    def __str__(self):30        return str(self.id)+" "+self.name+" "+self.get_permanent_address() 31class Lecturer(Employee): 32    def __init__(self):33        super().__init__(1 , "Mr. Bigshot")34    def __str__(self):35        return "Lecturer: "+super().__str__()36    37if __name__ == "__main__": 38    # Uncomment these to test out your code before run.py local 39    40    a = Address() 41    a.house_no = 2 42    a.street = 3 43    a.city = "Peshawar"44    a.country = "Pakistan"45    print(a.get_full_address())46    print(a)47    e = Employee() 48    e.set_current_address(1, 2, "Cape Town", "South Africa")49    print(e.get_current_address()) 50    e.set_permanent_address(4, 19, "Cape Town", "South Africa")51    print(e.get_permanent_address())52    print(e)53    l = Lecturer() 54    l.set_permanent_address(44, 24, "KL", "Malaysia")55    print(l.get_permanent_address())...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!!
