Ich sehe gerade das es kleine Probleme gibt wenn ich das folgende Script unter Windows ausführen will:
Code: Alles auswählen
#!/usr/bin/python
import plugins.imports
import types
import os
class pyEnv(object):
def __init__(self):
self.commands = {}
for plugin in self.plugins:
plugin = __import__(os.path.join('plugins', plugin))
for key, value in plugin.__dict__.iteritems():
if type(value) == types.FunctionType:
self.register_command(key, value)
def register_command(self, command, callback):
if not self.commands.has_key(command):
self.commands[command] = callback
def parse(self, string):
tokens = string.split()
command = tokens[0].lower()
if self.commands.has_key(command):
try:
self.commands[command](tokens[1:], self)
except (TypeError):
try:
self.commands[command](tokens[1:])
except (Exception), error:
print 'Error: %s' % error
@property
def plugins(self):
plugins = []
for file in os.listdir(os.path.join('plugins')):
if not file.startswith('__') and file.endswith('.py'):
plugins.append(file.split('.py')[0])
return plugins
pyenv = pyEnv()
while True:
command = str(raw_input('>>> '))
if command:
pyenv.parse(command)
(Ja einen Ordner Plugin gibts im gleichen Verzeichnis).
Ich habe das Script genauso wie unter Ubuntu mit Eclipse und PyDev starten wollen.
Selbst wenn ich es manuell mit dem Python Interpreter starte bekomme ich diese Fehlermeldung. Aber ich dachte ich hatte das script dank "os" möglichst cross-platform gehalten?
PS:
Die erste import Zeile könnt ihr eigentlich ignorieren. Dort lasse ich nur einen __init__.py ausführen die in dem plugins.imports ordner liegt und dann diesen ordner an den sys.path anhängen damit die pyEnv einigermaßen portable bleibt.
MfG,
CracKPod