Advertisement
Guest User

Untitled

a guest
Feb 13th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 11.10 KB | None | 0 0
  1.  
  2. In [106]: import faker
  3.  
  4. In [107]: f = faker.Faker()
  5.  
  6. In [108]: f.address
  7. Out[108]: <bound method Provider.address of <faker.providers.address.en_US.Provider object at 0x7fb13c8f9cf8>>
  8.  
  9. In [109]: f.address()
  10. Out[109]: '85599 Adam Coves\nJamesville, AS 30441'
  11.  
  12. In [110]: f.address()
  13. Out[110]: '5034 Harrington Fall Apt. 741\nTinaborough, CA 04084'
  14.  
  15. In [111]: f.address()
  16. Out[111]: '7701 Mark Glens Apt. 687\nNew Kristafort, DE 51109'
  17.  
  18. In [112]: f.address()
  19. Out[112]: 'USCGC Carroll\nFPO AA 19647'
  20.  
  21. In [113]: f.address()
  22. Out[113]: '55810 Barbara Field Apt. 090\nLake Anthony, IA 50583'
  23.  
  24. In [114]: f.ascii_email
  25. Out[114]: <bound method Provider.ascii_email of <faker.providers.internet.en_US.Provider object at 0x7fb13c916898>>
  26.  
  27. In [115]: f.ascii_email()
  28. Out[115]: 'anna01@ruiz-moore.com'
  29.  
  30. In [116]: f.ascii_email()
  31. Out[116]: 'rmadden@hotmail.com'
  32.  
  33. In [117]: f.ascii_email()
  34. Out[117]: 'sanchezfelicia@gmail.com'
  35.  
  36. In [118]: f.bank_country()
  37. Out[118]: 'GB'
  38.  
  39. In [119]: f.century
  40. Out[119]: <bound method Provider.century of <faker.providers.date_time.en_US.Provider object at 0x7fb13c906a20>>
  41.  
  42. In [120]: f.century()
  43. Out[120]: 'III'
  44.  
  45. In [121]: f.century()
  46. Out[121]: 'XVI'
  47.  
  48. In [122]: f.century()
  49. Out[122]: 'XVIII'
  50.  
  51. In [123]: f.city
  52. Out[123]: <bound method Provider.city of <faker.providers.address.en_US.Provider object at 0x7fb13c8f9cf8>>
  53.  
  54. In [124]: f.city()
  55. Out[124]: 'Port Danielle'
  56.  
  57. In [125]: f.city()
  58. Out[125]: 'Gallowayshire'
  59.  
  60. In [126]: f.city()
  61. Out[126]: 'Port Colton'
  62.  
  63. In [127]: f.city()
  64. Out[127]: 'East Vanessamouth'
  65.  
  66. In [128]: f.city()
  67. Out[128]: 'West Crystal'
  68.  
  69. In [129]: f.city()
  70. Out[129]: 'Lake Ravenburgh'
  71.  
  72. In [130]: f.first_name()
  73. Out[130]: 'Shannon'
  74.  
  75. In [131]: f.first_name()
  76. Out[131]: 'Ronald'
  77.  
  78. In [132]: f.first_name()
  79. Out[132]: 'Cassandra'
  80.  
  81. In [133]: f.first_name()
  82. Out[133]: 'Jonathan'
  83.  
  84. In [134]: f.last_name()
  85. Out[134]: 'Waters'
  86.  
  87. In [135]: f.last_name()
  88. Out[135]: 'Villegas'
  89.  
  90. In [136]: f.last_name()
  91. Out[136]: 'Johnson'
  92.  
  93. In [137]: f.last_name()
  94. Out[137]: 'Chen'
  95.  
  96. In [138]: f.last_name()
  97. Out[138]: 'Wright'
  98.  
  99. In [139]:
  100.  
  101. In [139]: f.day_of_week()
  102. Out[139]: 'Wednesday'
  103.  
  104. In [140]: f.day_of_week()
  105. Out[140]: 'Sunday'
  106.  
  107. In [141]: f.day_of_week()
  108. Out[141]: 'Friday'
  109.  
  110. In [142]: f.day_of_week()
  111. Out[142]: 'Friday'
  112.  
  113. In [143]: f.paragraph()
  114. Out[143]: 'Feel control suddenly wind. Shoulder way common we hour.'
  115.  
  116. In [144]: f.paragraph()
  117. Out[144]: 'Bed head thing test discussion thousand admit. State long hear agreement.'
  118.  
  119. In [145]: f.paragraph()
  120. Out[145]: 'Risk huge program memory. Radio light fact prevent. Voice past decision.'
  121.  
  122. In [146]: mytext = f.paragraph?
  123. Signature: f.paragraph(nb_sentences=3, variable_nb_sentences=True, ext_word_list=None)
  124. Docstring:
  125. :returns: A single paragraph. For example: 'Sapiente sunt omnis. Ut
  126.    pariatur ad autem ducimus et. Voluptas rem voluptas sint modi dolorem amet.'
  127.  
  128. Keyword arguments:
  129. :param nb_sentences: around how many sentences the paragraph should contain
  130. :param variable_nb_sentences: set to false if you want exactly ``nb``
  131.     sentences returned, otherwise the result may include a number of
  132.     sentences of ``nb`` +/-40% (with a minimum of 1)
  133. :param ext_word_list: a list of words you would like to have instead of
  134.     'Lorem ipsum'.
  135.  
  136. :rtype: str
  137. File:      ~/.local/lib/python3.6/site-packages/faker/providers/lorem/__init__.py
  138. Type:      method
  139.  
  140. In [147]: mytext = f.paragraph(10)
  141.  
  142. In [148]: mytext
  143. Out[148]: 'Middle amount too political else prepare possible. Mrs such recognize party church fine probably. Use carry hospital real act different. A girl drug establish. Worry sort other modern language positive. Itself significant onto alone. Her capital that coach writer drive rock.'
  144.  
  145. In [149]: mytext.count('M')
  146. Out[149]: 2
  147.  
  148. In [150]: mytext.count('a')
  149. Out[150]: 18
  150.  
  151. In [151]: len(mytext)
  152. Out[151]: 275
  153.  
  154. In [152]: mytext.count('.')
  155. Out[152]: 7
  156.  
  157. In [153]: mytext.count('?')
  158. Out[153]: 0
  159.  
  160. In [154]: mytext.count('!')
  161. Out[154]: 0
  162.  
  163. In [155]: class Tv:
  164.      ...:     def __init__(self):
  165.      ...:         self.model = ''
  166.      ...:         self.size = ''
  167.      ...:         self.color = ''
  168.      ...:         self.is_smart = False
  169.      ...:        
  170.  
  171. In [156]:
  172.  
  173. In [156]: meetingroomtv = Tv()
  174.  
  175. In [157]: meetingroomtv.model = 'LG'
  176.  
  177. In [158]: meetingroomtv.color = 'Black'
  178.  
  179. In [159]: meetingroomtv.size = '50inch'
  180.  
  181. In [160]:
  182.  
  183. In [160]:
  184.  
  185. In [160]: meetingroomtv.model
  186. Out[160]: 'LG'
  187.  
  188. In [161]: meetingroomtv.color
  189. Out[161]: 'Black'
  190.  
  191. In [162]: meetingroomtv.size = '50inch'
  192.  
  193. In [163]: class Tv:
  194.      ...:     def __init__(self):
  195.      ...:         self.model = ''
  196.      ...:         self.size = ''
  197.      ...:         self.color = ''
  198.      ...:         self.is_smart = False
  199.      ...:     def power_on(self):
  200.      ...:         print("starting tv...")
  201.      ...:        
  202.  
  203. In [164]: meetingroomtv = Tv()
  204.  
  205. In [165]: meetingroomtv.size = '50inch'
  206.  
  207. In [166]: meetingroomtv.color = 'Black'
  208.  
  209. In [167]: meetingroomtv.power_on()
  210. starting tv...
  211.  
  212. In [168]:
  213.  
  214. In [168]: class Tv:
  215.      ...:     def __init__(self, usermodel, usersize, usercolor, useris_smart):
  216.      ...:         self.model = usermodel
  217.      ...:         self.size = usersize
  218.      ...:         self.color = usercolor
  219.      ...:         self.is_smart = useris_smart
  220.      ...:     def power_on(self):
  221.      ...:         print("starting tv...")
  222.      ...:        
  223.      ...:        
  224.  
  225. In [169]: meetingroomtv = Tv('LG', '50', 'black', False)
  226.  
  227. In [170]: meetingroomtv.power_on()
  228. starting tv...
  229.  
  230. In [171]: class Tv:
  231.      ...:     def __init__(self, usermodel, usersize, usercolor, useris_smart=False)
  232.      ...: :
  233.      ...:         self.model = usermodel
  234.      ...:         self.size = usersize
  235.      ...:         self.color = usercolor
  236.      ...:         self.is_smart = useris_smart
  237.      ...:     def power_on(self):
  238.      ...:         print("starting tv...")
  239.      ...:        
  240.      ...:        
  241.  
  242. In [172]:
  243.  
  244. In [172]: meetingroomtv = Tv('LG', '50', 'black')
  245.  
  246. In [173]: meetingroomtv.is_smart
  247. Out[173]: False
  248.  
  249. In [174]: meetingroomtv = Tv('LG', '50', 'black', True)
  250.  
  251. In [175]: meetingroomtv.is_smart
  252. Out[175]: True
  253.  
  254. In [176]: meetingroomtv.model
  255. Out[176]: 'LG'
  256.  
  257. In [177]: class Tv:
  258.      ...:     def __init__(self, usermodel, usersize, usercolor, useris_smart=False)
  259.      ...: :
  260.      ...:         self.model = usermodel
  261.      ...:         self.size = usersize
  262.      ...:         self.color = usercolor
  263.      ...:         self.is_smart = useris_smart
  264.      ...:     def power_on(self):
  265.      ...:         print("starting tv...")
  266.      ...:        
  267.      ...:     def about(self):
  268.      ...:         print('model: ', self.model)
  269.      ...:         print('size: ', self.size)
  270.      ...:         print('color: ', self.color)
  271.      ...:         print('is smart: ?', self.is_smart)
  272.      ...:        
  273.  
  274. In [178]: meetingroomtv = Tv('LG', '50', 'black', True)
  275.  
  276. In [179]: meetingroomtv.power_on()
  277. starting tv...
  278.  
  279. In [180]: class Tv:
  280.      ...:     def __init__(self, usermodel, usersize, usercolor, useris_smart=False)
  281.      ...: :
  282.      ...:         self.model = usermodel
  283.      ...:         self.size = usersize
  284.      ...:         self.color = usercolor
  285.      ...:         self.is_smart = useris_smart
  286.      ...:     def power_on(self):
  287.      ...:         print("starting ", self.model, " tv ...")
  288.      ...:        
  289.      ...:     def about(self):
  290.      ...:         print('model: ', self.model)
  291.      ...:         print('size: ', self.size)
  292.      ...:         print('color: ', self.color)
  293.      ...:         print('is smart: ?', self.is_smart)
  294.      ...:        
  295.  
  296. In [181]:
  297.  
  298. In [181]: meetingroomtv = Tv('LG', '50', 'black', True)
  299.  
  300. In [182]: meetingroomtv.power_on()
  301. starting  LG  tv ...
  302.  
  303. In [183]: meetingroomtv.about()
  304. model:  LG
  305. size:  50
  306. color:  black
  307. is smart: ? True
  308.  
  309. In [184]: class Human:
  310.      ...:     def __init__(self, name, age):
  311.      ...:         self.name = name
  312.      ...:         self.age = age
  313.      ...:     def sleep(self):
  314.      ...:         print(self.name, " is sleeping now..")
  315.      ...:     def eat(self):
  316.      ...:         print(self.name, " is eating now..")
  317.      ...:     def watch_tv(self, tv):
  318.      ...:         tv.power_on()
  319.      ...:         tv.about()
  320.      ...:         print(self.name, ' is watching tv now...')
  321.      ...:        
  322.  
  323. In [185]: h = Human('ahmed', 500)
  324.  
  325. In [186]: h.sleep()
  326. ahmed  is sleeping now..
  327.  
  328. In [187]: h.eat()
  329. ahmed  is eating now..
  330.  
  331. In [188]: h.sleep()
  332. ahmed  is sleeping now..
  333.  
  334. In [189]: h.watch_tv(meetingroomtv)
  335. starting  LG  tv ...
  336. model:  LG
  337. size:  50
  338. color:  black
  339. is smart: ? True
  340. ahmed  is watching tv now...
  341.  
  342. In [190]: import faker
  343.  
  344. In [191]: class MyFaker:
  345.      ...:     def __init__(self):
  346.      ...:         pass
  347.      ...:     def email(self):
  348.      ...:         return "abc@gmail.com"
  349.      ...:    
  350.  
  351. In [192]: myf = MyFaker()
  352.  
  353. In [193]: myf.email()
  354. Out[193]: 'abc@gmail.com'
  355.  
  356. In [194]: myf.email()
  357. Out[194]: 'abc@gmail.com'
  358.  
  359. In [195]: myf.email()
  360. Out[195]: 'abc@gmail.com'
  361.  
  362. In [196]: myf.email()
  363. Out[196]: 'abc@gmail.com'
  364.  
  365. In [197]: myf.email()
  366. Out[197]: 'abc@gmail.com'
  367.  
  368. In [198]: import random
  369.  
  370. In [199]: class MyFaker:
  371.      ...:     def __init__(self):
  372.      ...:         pass
  373.      ...:     def email(self):
  374.      ...:         emails = ['abc.@gmail.com', 'xyz@yahoo.com']
  375.      ...:         return random.choice(emails)
  376.      ...:    
  377.      ...:    
  378.  
  379. In [200]: myf = MyFaker()
  380.  
  381. In [201]: myf.email()
  382. Out[201]: 'abc.@gmail.com'
  383.  
  384. In [202]: myf.email()
  385. Out[202]: 'abc.@gmail.com'
  386.  
  387. In [203]: myf.email()
  388. Out[203]: 'abc.@gmail.com'
  389.  
  390. In [204]: myf.email()
  391. Out[204]: 'abc.@gmail.com'
  392.  
  393. In [205]: myf.email()
  394. Out[205]: 'xyz@yahoo.com'
  395.  
  396. In [206]: myf.email()
  397. Out[206]: 'abc.@gmail.com'
  398.  
  399. In [207]: myf.email()
  400. Out[207]: 'xyz@yahoo.com'
  401.  
  402. In [208]: class MyFaker:
  403.      ...:     def __init__(self):
  404.      ...:         pass
  405.      ...:     def email(self):
  406.      ...:         emails = ['abc.@gmail.com', 'xyz@yahoo.com']
  407.      ...:         return random.choice(emails)
  408.      ...:    
  409.      ...:     def some_number(self):
  410.      ...:         return random.choice(range(0,100))
  411.      ...:    
  412.  
  413. In [209]: myf = MyFaker()
  414.  
  415. In [210]: myf.some_number()
  416. Out[210]: 90
  417.  
  418. In [211]: myf.some_number()
  419. Out[211]: 80
  420.  
  421. In [212]: myf.some_number()
  422. Out[212]: 30
  423.  
  424. In [213]: myf.some_number()
  425. Out[213]: 40
  426.  
  427. In [214]: myf.some_number()
  428. Out[214]: 99
  429.  
  430. In [215]: myf.some_number()
  431. Out[215]: 73
  432.  
  433. In [216]:
  434.  
  435. In [216]: myf.some_number()
  436. Out[216]: 36
  437.  
  438. In [217]: class Todo:
  439.      ...:     def __init__(self):
  440.      ...:         self.tasks = []
  441.      ...:     def add(self):
  442.      ...:         newtask = input('new task? ')
  443.      ...:         self.tasks.append(newtask)
  444.      ...:        
  445.  
  446. In [218]: class Todo:
  447.      ...:     def __init__(self, userowner):
  448.      ...:         self.tasks = []
  449.      ...:         self.owner = userowner
  450.      ...:     def add(self):
  451.      ...:         newtask = input('new task? ')
  452.      ...:         self.tasks.append(newtask)
  453.      ...:        
  454.  
  455. In [219]:
  456.  
  457. In [219]: t = Todo('ahmed')
  458.  
  459. In [220]: t.add()
  460. new task? sleep
  461.  
  462. In [221]: t.add()
  463. new task? eat
  464.  
  465. In [222]: t.tasks
  466. Out[222]: ['sleep', 'eat']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement