-2
# randomize.py
import os
import sys 
import re
import shuti1
import json
import cProfile
import random

li = ["dog dot", "do don't", "dumb-dumb", "no match"]

for element in li: 
m = re.match("(d\w+)\W(d\w+)", element)
if m:
    print(m.groups())

for _, __ in enumerate(sys.path):
shuti1.initialize('Hello', '!', 'HackerEarth')
print __

while True:
li_random = random.choice(li)
print li_random
if li[0] in li_random:
    break
# shuti1.py
import sys 
import randomize
import collections
import math

from collections import Counter

class HackerEarth(object):
def __init__(self, name, role, hobby):
        self.name = name
        self.role = role
        self.hobby = hobby

def print_details(self):
    print "Name:", self.name
    print "Role:", self.role
    print "Hobby:", self.hobb

    cnt = Counter()
    for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
    cnt[word] += 1

def initialize(greet, character, company):
print greet, character, company

when i run the program i got the error like:

   Traceback (most recent call last):
   File "C:/Users/SAGAR/Desktop/randomize.py", line 5, in <module>
    import shuti1
   File "C:\Python34\shuti1.py", line 3, in <module>
    import randomize
   File "C:/Users/SAGAR/Desktop\randomize.py", line 18, in <module>
    shuti1.initialize('Hello', '!', 'HackerEarth')
   AttributeError: 'module' object has no attribute 'initialize'
MattDMo
  • 100,794
  • 21
  • 241
  • 231
Sagar Sinha
  • 375
  • 2
  • 8
  • 26

1 Answers1

1

I'm gonna take a guess that initialize is part of the HackerEarth class as you didn't indent much to be sure. If that's the case, initialize is not part of the module, it is part of the class, so you would need a HackerEarth object in order to call it.

If that isn't the case, it could be the cyclic imports that Peter Wood mentioned (sorry, don't know how to tag!). What that means is that you are importing shuti1.py into randomize.py and randomize.py into shuti1.py. This can be confirmed looking at the error message:

File "C:/Users/SAGAR/Desktop/randomize.py", line 5, in

import shuti1

File "C:\Python34\shuti1.py", line 3, in

import randomize

Lastly, it could be caused by an IDE if you are using one. Pycharm requires all imported files to be in the project or part of your python directory. Check for something like that if you can't fix it with the other 2 things.

Hope it helps

Matthew
  • 672
  • 4
  • 11