Skip to content

Latest commit

 

History

History
47 lines (25 loc) · 1.92 KB

README.md

File metadata and controls

47 lines (25 loc) · 1.92 KB

I have 12+ micro services to be migrated from python2.X and I will be listing complete details of porting issues whatever is not listed in the below and how to address them as well with examples, Keep watching this section

python-2-To-3

Tips for Migrating Python 2.7.x to 3.x from python community

Here are some snippets for yo to focus on while migrating

class SomeClassWithoutBaseClass:          ==> class SomeClassWithoutBaseClass(object):

base_product.validate = lambda (payload): payload  	==>  base_product.validate = lambda payload : payload
event = {k: to_str(v) for k, v in event.items()}  	==> event = {k: to_str(v) for k, v in list(event.items())}
for key, value in upstream_catalog.iteritems():			==>   for key, value in upstream_catalog.items():
        merged_catalog.setdefault(key, value)	merged_catalog.setdefault(key, value)

VOUCHER_PATTERN = '[\d\l]{{{length}}}'         ==>   VOUCHER_PATTERN = r'[\d\l]{{{length}}}'

map(lambda item: item.someFunc(), results)  		==> 		list(map(lambda item: item.someFunc(), results))


cashed = int(round((float(cash) / tot_amt) * 100))  	==> cashed = int(round((float(cash) // tot_amt) * 100))


for keytuple in purchases_products.keys():   	==>  for keytuple in list(purchases_products.keys():


return products_by_id.values()    			==> return list(products_by_id.values())


return unicode(self.template).format(**self.kwargs) 	==> return str(self.template).format(**self.kwargs)


try:
    # py3 moved to collections package
    from collections import UserDict        # noqa
except ImportError:
    from UserDict import UserDict           # noqa