PDA

View Full Version : trying to learn python


ocwasere
2007-04-07, 21:36
hello i am trying to learn python i was doing ok

can somone please tell me why this don't work from
5.6 Looping Techniques (http://www.python.org/doc/current/tut/node7.html)

thanks

knights = {'gallahad': 'the pure', 'robin': 'the brave'}
for k, v in knights.iteritems():
print k, v

i get this error

19:18:02 M: 36392960 INFO: Q:\scripts\test.py
19:18:02 M: 36392960 INFO: ", line
19:18:02 M: 36392960 INFO: 13
19:18:02 M: 36392960 INFO:
19:18:02 M: 36392960 INFO:
19:18:02 M: 36392960 INFO: for k, v in knights.iteritems():
19:18:02 M: 36392960 INFO:
19:18:02 M: 36392960 INFO: ^
19:18:02 M: 36392960 INFO: SyntaxError
19:18:02 M: 36392960 INFO: :
19:18:02 M: 36392960 INFO: invalid syntax

ocwasere
2007-04-07, 22:43
got it to work from a funtion but

knights={'gallahad': 'the pure', 'robin': 'the brave'}

import xbmcgui
ACTION_PREVIOUS_MENU = 10

# why doesn't this work here
#
# for k, v in knights.iteritems():
# print k, v


class MyClass(xbmcgui.Window):
def __init__(self):
# Begin setting up the GUI background
self.pic = xbmcgui.ControlImage(0,0,0,0,'')
self.addControl(self.pic)
self.test1()
self.test2()

def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()

def test1(self):
for x in knights.keys():
print x, knights[x]

def test2(self):
for k, v in knights.iteritems():
print k, v

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay

Nuka1195
2007-04-07, 23:15
indentation

ocwasere
2007-04-07, 23:31
indentation

thanks for your reply

i have had the indentation error and corrected it
but this error is invalid syntax

can i ask another quesion

why doesn't a directory keep its order
params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
print params.items()
[('pwd', 'secret'), ('database', 'master'), ('uid', 'sa'), ('server', 'mpilgrim')]

ocwasere
2007-04-08, 03:25
why doesn't a directory keep its order
params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
print params.items()
[('pwd', 'secret'), ('database', 'master'), ('uid', 'sa'), ('server', 'mpilgrim')]

found out why here
Python Dictionaries don't have order (http://blogamundo.net/py4lx/counting.html)

ocwasere
2007-04-08, 03:35
please can you tell me whats wrong with the indentation of the code in red

knights={'gallahad': 'the pure', 'robin': 'the brave'}

import xbmcgui
ACTION_PREVIOUS_MENU = 10

# why doesn't this work here
#
# for k, v in knights.iteritems():
# print k, v


class MyClass(xbmcgui.Window):
def __init__(self):
# Begin setting up the GUI background
self.pic = xbmcgui.ControlImage(0,0,0,0,'')
self.addControl(self.pic)
self.test1()
self.test2()

def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()

def test1(self):
for x in knights.keys():
print x, knights[x]

def test2(self):
for k, v in knights.iteritems():
print k, v

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay

stanley87
2007-04-08, 03:44
get a great program called "PyScripter" - this checks ur code for syntax + indentation errors

:-)

ocwasere
2007-04-08, 04:03
get a great program called "PyScripter" - this checks ur code for syntax + indentation errors

:-)

thanks for the link, but i have not got python installed on my pc
i am using notepad and the xbmc log file
can you tell me whats wrong with the indentation for the code in red

thanks

Nuka1195
2007-04-08, 08:55
the code in red is commented out, so unless you post it the exact way you want, how could we possible tell you. maybe it's a mix of tabs and spaces.

ocwasere
2007-04-08, 13:29
the code in red is commented out, so unless you post it the exact way you want, how could we possible tell you. maybe it's a mix of tabs and spaces.

thanks again for your reply

to rephase my question should the for loop statement in red work if so
can you tell me whats wrong with it
thanks

knights={'gallahad': 'the pure', 'robin': 'the brave'}

import xbmcgui
ACTION_PREVIOUS_MENU = 10

# why doesn't this work here

for k, v in knights.iteritems():
print k, v


class MyClass(xbmcgui.Window):
def __init__(self):
# Begin setting up the GUI background
self.pic = xbmcgui.ControlImage(0,0,0,0,'')
self.addControl(self.pic)
self.test1()
self.test2()

def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()

def test1(self):
for x in knights.keys():
print x, knights[x]

def test2(self):
for k, v in knights.iteritems():
print k, v

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay

ocwasere
2007-04-08, 16:50
big thanks to Nuka1195 for making me look at indentation

big thanks to stanley87 for making me look at PyScripter

i have now install python and got Alexpoet's XBMC Emulator Scripts working :D what a difference a day makes

question to stanley87 when i close PyScripter after using this code blow i get
"PyScripter.exe has encountered a problem and needs to close. We are sorry for the inconvenience."
but it run fine in the pythons IDLE
just wondering if you have encountered any problems with PyScripter.
other than the error when i close PyScripter its cool.
thanks for making me see the light

knights={'gallahad': 'the pure', 'robin': 'the brave'}

import xbmcgui

try: Emulating = xbmcgui.Emulating
except: Emulating = False

ACTION_PREVIOUS_MENU = 10

# got to this work was indentation error

for k, v in knights.iteritems():
print k, v


class MyClass(xbmcgui.Window):
def __init__(self):
if Emulating: xbmcgui.Window.__init__(self)
# Begin setting up the GUI background
self.pic = xbmcgui.ControlImage(0,0,0,0,'background.png')
self.addControl(self.pic)
self.test1()
self.test2()

def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()

def test1(self):
for x in knights.keys():
print x, knights[x]

def test2(self):
for k, v in knights.iteritems():
print k, v

mydisplay = MyClass()
mydisplay .doModal()
del mydisplay

Nuka1195
2007-04-08, 17:04
i would get a hold of XBMC_PC.exe (T3ch builds include it) and use that to test scripts that run in XBMC.

ocwasere
2007-04-08, 17:10
i would get a hold of XBMC_PC.exe (T3ch builds include it) and use that to test scripts that run in XBMC.

thanks i will try that later to night going to sit in the garden to get some rays now :cool:

been playing with XBMC Emulator Scripts now thats cool
is XBMC_PC.exe like that

any links for help setting XBMC_PC.exe up or is it get and go

stanley87
2007-04-09, 13:39
XBMC_PC.exe = XBMC running on your PC - its not a full port but very good for testing scripts and skins.

zimberto
2007-05-14, 08:50
XBMC_PC.exe isn't in the fat 2.0.1 T3CH distro. :confused2:

Asteron
2007-05-14, 19:09
you have to get a recent cvs release to see it.