0

I'm trying to use Python faker and fake-factory for Data masking in my application. I have executed the following test python script but getting syntax error. Please help me out.

#faker script files
# coding=utf-8

from faker import Factory
fake=Factory.create()

fake.name()
fake.address()
fake.text()

for _ in range(0,10):
    print fake.name()

Error message:invalid syntax on fake

saran
  • 3
  • 6
  • do you installed faker ??? pip install faker – ignacio.saravia Dec 13 '16 at 19:04
  • Hello Roberto, I have installed faker in my local. Please check the log for the installation. I have used pip. – saran Dec 13 '16 at 19:10
  • What version of python you use??? in python 2.7.x it's works perfectly – ignacio.saravia Dec 13 '16 at 19:13
  • I m using 3.5.2 version. I'm totally new to faker and not sure what else I need to make this work. – saran Dec 13 '16 at 19:16
  • What's the name of file? it's call "fake.py" ?? – ignacio.saravia Dec 13 '16 at 19:20
  • are you talking about the installation package file.? if so, here it is. AppData\Local\Programs\Python\faker\fake-factory-0.7.2\faker\factory.py – saran Dec 13 '16 at 19:26
  • No, the name of script file and the directory ubication – ignacio.saravia Dec 13 '16 at 19:27
  • Path : \AppData\Local\Programs\Python\faker\fake-factory-0.7.2\faker\tests and fakenametest.py is the file – saran Dec 13 '16 at 19:34
  • do you create the directory "faker\test" ? move the file the another directory – ignacio.saravia Dec 13 '16 at 19:36
  • the dir faker/test was already there. I just created the scripts under that folder. Now I moved them to desktop. – saran Dec 13 '16 at 19:43
  • and now? show the same error ? – ignacio.saravia Dec 13 '16 at 19:51
  • Yes. It's the same error again. I will clean up the faker folder and reinstall again. – saran Dec 13 '16 at 19:57
  • Reinstalled the faker component again in python. Here is the folder : AppData\Local\Programs\Python\Python35-32\Lib\site-packages\faker and tried again. But still facing the same error. – saran Dec 13 '16 at 20:08
  • i have checked in the GitHub (https://github.com/joke2k/faker) and I tried to run the dependencies but the following file is not available at faker. Is that a problem? Here is the command used `code` $ pip install -r faker/tests/requirements.txt `code` – saran Dec 13 '16 at 20:11
  • Hello Rob, I just installed python 2.7 and it worked fine. There seems to be an issue with Faker - python 3.5. Thanks for your help anyway. I have got someone from twitter who used Faker and she suggested me to use Python 2.7. Unfortunately I do not know why it dint work with Python 3.5. I will give an update as soon as I get the answer.. – saran Dec 14 '16 at 19:24
  • Excelent saran, – ignacio.saravia Dec 14 '16 at 20:54

1 Answers1

0

You are using the print syntax incorrectly. The reason this worked on 2.x and not 3.x is that the way print works changed across versions. The one of you currently have is the python 2.x method.

Try :

for _ in range(0,10):
    print (fake.name()) # Put the call in parentheses
0xsegfault
  • 2,899
  • 6
  • 28
  • 58