Skip to content

shafeequ/python-2-To-3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 

Repository files navigation

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
    

About

Tips for Migrating Python 2.7.x to 3.x

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published