Pythonã¡ã¢ : fakerã§ãã¹ããã¼ã¿ãçæãã
faker
fakerã¨ããPythonããã±ã¼ã¸ã使ç¨ããã¨ãã¹ããã¼ã¿ãç°¡åã«çæãããã¨ãã§ãããPHP Faker, Perl Faker, Ruby Fakerã«ã¤ã³ã¹ãã¤ã¢ãããã¨ã®ãã¨ã
ã¤ã³ã¹ãã¼ã«
pipã§ã¤ã³ã¹ãã¼ã«ã§ããã®ã§ä¸è¨ã³ãã³ããå®è¡ã
$ pip install faker
$ faker --help usage: faker [-h] [--version] [-o output] [-l LOCALE] [-r REPEAT] [-s SEP] [-i [INCLUDE [INCLUDE ...]]] [fake] [fake argument [fake argument ...]] faker version 0.7.18 positional arguments: fake name of the fake to generate output for (e.g. profile) fake argument optional arguments to pass to the fake (e.g. the profile fake takes an optional list of comma separated field names as the first argument) optional arguments: -h, --help show this help message and exit --version show program's version number and exit -o output redirect output to a file -l LOCALE, --lang LOCALE specify the language for a localized provider (e.g. de_DE) -r REPEAT, --repeat REPEAT generate the specified number of outputs -s SEP, --sep SEP use the specified separator after each output -i [INCLUDE [INCLUDE ...]], --include [INCLUDE [INCLUDE ...]] list of additional custom providers to user, given as the import path of the module containing your Provider class (not the provider class itself) supported locales: bg_BG, bs_BA, cs_CZ, de_AT, de_DE, dk_DK, el_GR, en, en_AU, en_CA, en_GB, en_TH, en_US, es, es_ES, es_MX, fa_IR, fi_FI, fr_CH, fr_FR, hi_IN, hr_HR, hu_HU, it_IT, ja_JP, ko_KR, la, lt_LT, lv_LV, ne_NP, nl_BE, nl_NL, no_NO, pl_PL, pt_BR, pt_PT, ru_RU, sk_SK, sl_SI, sv_SE, th_TH, tr_TR, uk_UA, zh_CN, zh_TW
使ãæ¹ï¼ã³ãã³ã
ã¤ã³ã¹ãã¼ã«ãæåãã¦ããã°faker
ã³ãã³ãã使ããããã«ãªã£ã¦ããã
åºæ¬çã«ã¯faker
ã®å¾ã«çæããããã¼ã¿ãæå®ããã
$ faker address ç¦å²¡çå©å³¶æç½éå°7ä¸ç®8çª5å· ã¢ã¼ãã³é·é949
-l
ã§ãã±ã¼ã«ãæå®ãããã¨ãå¯è½ã
$ faker -l de_DE address Rainer-Weinhage-Ring 9/3 88040 Peine
ãã¼ã¿ã«ãã£ã¦ã¯ä½¿ç¨ããå±æ§ã ããæå®ãããã¨ãå¯è½ã
$ faker profile {'name': 'æ¨æ ç¥å®', 'company': 'æéä¼ç¤¾ äºé«', 'ssn': '074-74-2984', 'website': ['https://miyake.jp/'], 'birthdate': '2017-02-01', 'current_location': (Decimal('23.967602'), Decimal('-162.041080')), 'residence': '大éªåºæ¨ªæµå¸æ¸å¡åºæ¹¯å®®25ä¸ç®17çª1å· ãã¬ã¹æ´¥ä¹ æ¸çº909', 'job': 'Investment analyst', 'mail': '[email protected]', 'sex': 'F', 'address': 'é岡çæ±æ±åºè¤é10ä¸ç®27çª14å· å¤ªç°ã¶è°·ã¯ã¬ã¹ã103', 'username': 'kimuratakuma', 'blood_group': 'A-'} $ faker profile ssn,birthdate {'birthdate': '2002-07-30', 'ssn': '317-80-6184'}
è¤æ°çæããå ´åã¯-r
ã§æ°å¤ãæå®ããã-s
ã¯ã»ãã¬ã¼ã¿ãæå®ãããªãã·ã§ã³ã
$ faker -r=3 -s=";" name åç° æ¶¼å¹³; é«æ© ç綾; æå±± è¡å¤ªé;
çæå¯è½ãªãã¼ã¿ã®ä¸è¦§ã¯ä¸è¨ãªã³ã¯ã§ç¢ºèªã§ããã
Language ja_JP — Faker 0.7.18 documentation
ã¾ãã¯ä¸è¨ã³ãã³ããå®è¡ããã
$ python -m faker ### faker.providers.address fake.random_sample(elements=('a', 'b', 'c'), length=None) # ['c'] fake.zipcode() # 133-3925 fake.country_code() # NZ fake.address() # å²éçãããéå¸ä¸ã輪19ä¸ç®5çª5å· ãã¬ã¹å¤å½åºé417 fake.street_suffix() # Street ãâ¦çç¥â¦
使ãæ¹ï¼ã³ã¼ã
ã¤ã³ãã¼ãã¨åæåã¯ä¸è¨ã³ã¼ããåç §ã
from faker import Factory fake = Factory.create('ja_JP') # ã¾ã㯠from faker import Faker fake = Faker('ja_JP')
å¾ã¯fake.name()
ã®ããã«çæããããã¼ã¿ãæå®ããã°ããã
追è¨ï¼mimesisã使ãæ¹æ³ãããã
wonderwall.hatenablog.com