0

How do I import a library within the same folder / directory?

I tried using this answer / solution, but Python throws this error:

user@computer:~/program$ python3 __init__.py
  File "__init__.py", line 102
    import .get_len
           ^
SyntaxError: invalid syntax
user@computer:~/program$ pwd
/home/user/program
Python 3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Note: user and computer are not real names.

100|        if args.mode == 'get-len':
101|            try:
102|                import .get_len
103|            except ImportError as error:
104|                msg = str(error)

File Tree

program_folder
| __init__.py
| get_len.py
| get_chart.py
| get_geo.py
Penguin
  • 93
  • 2
  • 10

0 Answers0