3

So I have a main.py file inside /home/richard/projects/hello-python directory:

import sys
   sys.path.append('/home/richard/projects/hello-python')

   from Encode  import Ffmpeg
   x = Ffmpeg()
   x.encode()

I have then created a package in the /home/richard/projects/hello-python/Encode directory:

__init__.py
Ffmpeg.py

Init file is empty. Ffmpeg.py file contains:

class Ffmpeg(object):


   i = 150

   def __init__(self):
       print "i am constructor"

   def encode(self):
       print "hello world"

Now I run the main.py script like this:

python main.py

I get this output:

richard@richard-desktop:~/projects/hello-python$ python main.py 
Traceback (most recent call last):
  File "main.py", line 5, in <module>
    x = Ffmpeg()
TypeError: 'module' object is not callable
richard@richard-desktop:~/projects/hello-python$ 

I think there is some problem with my sys.path so my module cannot be imported correctly but I am not sure how to fix it.

1 Answer 1

7
from Encode.Ffmpeg import Ffmpeg
Sign up to request clarification or add additional context in comments.

2 Comments

And to answer why: the error you get states that Ffmpeg is seen as a module which is represented by the Ffmpeg.py file. You really wanted a class which is IN that module. Both names are the same which is nothing wrong but could be confusing.
The Python 3 stdlib generally uses the convention that file/module names are all lowercase (and changed just to avoid this sort of confusion with an uppercased class name that is otherwise the same. If you adopted this, the import would be from encode.ffmpeg import Ffmpeg.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.