0

I'm making a __init__.py and when running a script importing from another directory it give me a weird error

  File "C:/Users/####/Desktop/Roague\data\__init__.py", line 1
    data/
        ^
SyntaxError: invalid syntax

And I thought I was making an error so I corrected it and it still gives me an error and I keep getting an error, here is my __init__.py

data/
    __init__.py
    libtcodpy.py
    properties.py

Here is the file I import my library with

import libtcodpy as libtcod
import data.properties

#SCREEN DEMENTIONS
SCREEN_WIDTH = 80
SCREEN_HEIGHT = 50



#Characters and objects
player = Object(SCREEN_WIDTH/2,SCREEN_HEIGHT/2, 'P', libtcod.red, 0)
objects = [player]

#Init and Mainloop
libtcod.console_init_root(SCREEN_WIDTH, SCREEN_HEIGHT, 'Roague', False)#Init the root console
libtcod.console_set_custom_font('arial10x10.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_TCOD)
#Load up a font
while not libtcod.console_is_window_closed():
    #Loop through the objects and draw them
    for object in objects:
        object.draw_object()


    libtcod.console_flush()

    for object in objects:
        object.delete()

Is there a way to fix this?

YoungerDryas
  • 114
  • 2
  • 10
  • What does your `__init__.py` look like? – ronakg Jun 05 '15 at 05:02
  • what's your file that you import your library look like? – user1269942 Jun 05 '15 at 05:04
  • @Krillis - its very important that you post the code within __init__.py. Without that people wont be able to analyse the exact problem areas. – Pralhad Narsinh Sonar Jun 05 '15 at 05:04
  • Either you're doing something very meta, or you are very confused. The contents of __init__.py is an informal file listing? – Dave Jun 05 '15 at 05:05
  • @Pralhad Narsinh Sonar That is the exact contents – YoungerDryas Jun 05 '15 at 05:07
  • 4
    http://stackoverflow.com/questions/448271/what-is-init-py-for is a good place to start. See "an example" part way down. The directory/file structure that you list is a common way to represent your packages but not what should be inside __init__.py – user1269942 Jun 05 '15 at 05:09
  • more SO goodness: http://stackoverflow.com/questions/1944569/how-do-i-write-good-correct-package-init-py-files – user1269942 Jun 05 '15 at 05:16
  • What you want here is just a completely empty file. Unless you want to have something besides modules (functions, types, variables, constants, …) directly in `data`, you don't need anything at all in `data/__init__.py`. – abarnert Jun 05 '15 at 07:28

2 Answers2

0

I had the same issue (though i am running a newer version of Python). The problem was that i made the __init__.py file by choosing the "File-> Save As..." option in the Python Shell.

You can solve it by either making a blank text file and save it as __init__.py or by making a new file from the python shell and then save it as __init__.py.

PS: Don't forget the underscores before and after "init".

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
Akenaten
  • 91
  • 9
0

Your __init__.py should look like this:

It's an empty file.

Why? Because __init__.pys are just python files that get imported when a user imports your package. You can place metadata in them such as __version__ and __author__. So in the end, it may look like this:

__author__ = ["First Last <email>"]
__version__ = "1.0.0"
theX
  • 1,008
  • 7
  • 22