Binx
Binx

Reputation: 414

Importing Other Python Files - Calling Path

I am trying to follow @Eric Leschinski exmaple 7 solution on how to import other python files. I belive he is using a Linux base operating system since his path are in the format of el@apollo:/home.... I am using Windows and am not quite sure how to replicate his solution in regards to the paths. I don't quite understand the @ and $ symbols and if I need to change them?

D:\Echo\herp\__init__.py:

D:\Echo\herp$ touch__init__.py
D:\Echo\herp$ ls
__init__.py

D:\Echo\herp\derp\__init__.py:

D:\Echo\herp\derp$ touch__init__.py
D:\Echo\herp\derp$ ls
__init__.py

D:\Echo\herp\derp\yolo.py:

def skycake():
  print("SkyCake evolves to stay just beyond the cognitive reach of " + "the bulk of men. SKYCAKE!!")

D:\Echo\main.py

from herp.derp.yolo import skycake
skycake()
Traceback (most recent call last):
  File "D:/Echo/main.py", line 1, in <module>
    from herp.derp.yolo import skycake
  File "D:\Echo\herp\__init__.py", line 1
    D:\Echo\herp$ touch__init__.py
                                 ^
SyntaxError: unexpected character after line continuation character

Upvotes: 0

Views: 41

Answers (1)

furas
furas

Reputation: 143097

You understood it in wrong way.

el@apollo:/home/el/foo5/herp$ touch __init__.py
el@apollo:/home/el/foo5/herp$ ls
__init__.py

el@apollo:/home... is Linux console prompt which shows that it has to be executed in console.

touche __init__.py is Linux command touch which creates empty file __init__.py.

ls is Linux command to display files in folder and it displays __init__.py (which you see in last line)

All this is only to show how to create empty files __init__.py in console in Linux.

You have to remove all lines from files __init__.py - they have to be empty.


But you show link to question which is 11 years old, and answer is 7 years old, and in current Python it may not be needed. You should rather show original problem because it may need totally different solution - like using relative paths, or adding script's folder to sys.path before import

Upvotes: 1

Related Questions