Sunday 7 January 2018

python - ValueError: Attempted relative import in non-package

I have two Python files, one stored in the location
/Python/plata.py, and another in the location
/Python/tao/mock.py. This is what my
plata.py file looks
like::



def
printSomething():
print 'This is a
test.'



I'm
trying to import the printSomething() function inside my
mock.py file as
follows:



from . import
plata

plata.printSomething()


However,
this is the error I'm
encountering:




Traceback
(most recent call last):
File "/home/manas/Python/tao/mock.py", line 1, in

from . import plata
ValueError: Attempted relative
import in
non-package


I've
included the __init__.py files in locations
/Python/__init__.py and
/Python/tao/__init__.py as well. However, I'm still
encountering the same error.



What seems to be
wrong here?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...