lk-geimfari / mimesis

Mimesis is a robust data generator for Python that can produce a wide range of fake data in multiple languages.
https://mimesis.name
MIT License
4.44k stars 336 forks source link

How i can create two telephones for one person? #292

Closed 4kpt closed 6 years ago

4kpt commented 6 years ago
from mimesis import Personal
a = Personal("en")
b = Personal("en")
assert a.telephone('+#-(###)-###-####') == b.telephone('+#-(###)-###-####')
lk-geimfari commented 6 years ago

@4kpt You can't create two similar telephones when you create two instances. Theoretical it is possible, but the probability is very small.

You can use following format, which is much easier, because here no need create two instances of Personal:

>>> from mimesis import Personal
>>> per = Personal('en')
>>> a = b = per.telephone('+#-(###)-###-####')
>>> a == b
True

Or, maybe this decision does not suit for you? If not, why?

4kpt commented 6 years ago

I need two different telephones like work phone and home phone. How can i get it?

lk-geimfari commented 6 years ago

@4kpt There are bug with generating telephone by mask which has been fixed in version 1.0.0. I'll publish new version in next week.

Try use this:

>>> from mimesis import Code
>>> code = Code()
>>> a = code.custom_code('+#-(###)-###-####')
>>> b = code.custom_code('+#-(###)-###-####')
>>> a
'+3-(289)-022-8253'
>>> b
'+3-(504)-942-9931'
>>> 

We have seriously improved the library in version 1.0.0 and these inconveniences should pay off by clearer API.

4kpt commented 6 years ago

But i need use usa-specific phone number like Person("en").telephone... Why create new Person instance return old person telephone?

lk-geimfari commented 6 years ago

@4kpt We have discussed why in #286. It's a bug related to code.Code.custom_code: details.

lk-geimfari commented 6 years ago

@4kpt If you are really really need usa-specific phone numbers, then you can use this workaround:

>>> import random

>>> from mimesis import Personal, Code
>>> code = Code()
>>> masks = Personal('en').data['telephone_fmt']
>>> a = code.custom_code(mask=random.choice(masks))
4kpt commented 6 years ago

Thanks.