Running test.py gives
Traceback (most recent call last):
File "test.py", line 3, in <module>
Map = Parser.Map(os.path[0] + "\\start.wmap")
TypeError: 'module' object is not subscriptable
Parser.py
import configparser
def StringIsNumber(String):
try:
int(String)
except:
return False
return True
class Map:
Parser = configparser.RawConfigParser()
MapURL = ""
def __init__(self, Map):
self.Parser.read(Map)
se开发者_StackOverflow中文版lf.MapURL = Map
def TileTypes(self):
#All numerical sections can be assumed to be tiles
return [n for n in self.Parser.sections() if StringIsNumber(n)]
test.py
import Parser
import os
Map = Parser.Map(os.path[0] + "\\start.wmap")
print(Map.TileTypes())
os.path
is a module and you are using it as a list i think you're looking for sys.path
.
That you can't get its properties using key/index lookup like something[property]
You try to subscript os.path, which is a module. Subscripting means you use square brackets upon an object. That is legal for e.g. a dict object, but not for a module.
The error is in os.path[...]
os.path
is a module. It's unclear what you think os.path[0]
is going to do for you, since it's not an iterable and has no 0th element.
精彩评论