This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ pip install marshmallow-dataclass==7.2.1 | |
| $ pip install dataclasses-json==0.3.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import dataclass | |
| @dataclass(frozen=True) | |
| class CreateUser: | |
| emailAddress: str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from model import CreateUser | |
| input_json_1 = '{"emailAddress": 1}' | |
| input_json_2 = '{"emailAddress": "joe"}' | |
| input_json_3 = '{"emailAddress": "[email protected]"}' | |
| new_user_1 = CreateUser.from_json(input_json_1) # CreateUser(emailAddress=1) | |
| new_user_2 = CreateUser.from_json(input_json_2) # CreateUser(emailAddress='joe') | |
| new_user_3 = CreateUser.from_json(input_json_3) # CreateUser(emailAddress='[email protected]') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import dataclass, field | |
| from dataclasses_json import dataclass_json | |
| import marshmallow.validate | |
| @dataclass_json | |
| @dataclass | |
| class CreateUser: | |
| emailAddress: str = field(metadata={"validate": marshmallow.validate.Email()}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import dataclass | |
| from dataclasses_json import dataclass_json | |
| @dataclass_json | |
| @dataclass | |
| class CreateUser: | |
| emailAddress: str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import dataclass, field | |
| import marshmallow_dataclass | |
| from dataclasses_json import dataclass_json | |
| import marshmallow.validate | |
| @dataclass_json | |
| @dataclass | |
| class CreateUser: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from model import CreateUser, CreateUserSchema | |
| input_json_1 = '{"emailAddress": 1}' | |
| input_json_2 = '{"emailAddress": "joe"}' | |
| input_json_3 = '{"emailAddress": "[email protected]"}' | |
| new_user_1 = CreateUser.from_json(input_json_1) # CreateUser(emailAddress=1) | |
| new_user_2 = CreateUser.from_json(input_json_2) # CreateUser(emailAddress='joe') | |
| new_user_3 = CreateUser.from_json(input_json_3) # CreateUser(emailAddress='[email protected]') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from dataclasses import field | |
| from marshmallow_dataclass import dataclass | |
| import marshmallow.validate | |
| @dataclass | |
| class CreateUser: | |
| emailAddress: str = field(metadata={"validate": marshmallow.validate.Email()}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import CreateUser | |
| final_new_user_1 = CreateUser.Schema().loads(input_json_1) # marshmallow.exceptions.ValidationError: {'emailAddress': ['Not a valid string.']} | |
| final_new_user_2 = CreateUser.Schema().loads(input_json_2) # marshmallow.exceptions.ValidationError: {'emailAddress': ['Not a valid email address.']} | |
| final_new_user_3 = CreateUser.Schema().loads(input_json_3) # CreateUser(emailAddress='[email protected]') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '''This python script is to extract each sheet in an Excel workbook as a new csv file''' | |
| import csv | |
| import xlrd | |
| import sys | |
| def ExceltoCSV(excel_file, csv_file_base_path): | |
| workbook = xlrd.open_workbook(excel_file) | |
| for sheet_name in workbook.sheet_names(): | |
| print 'processing - ' + sheet_name |