trying to learn python
#1
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

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
Reply
#2
got it to work from a funtion but

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

import xbmcgui
ACTION_PREVIOUS_MENU = 10

[color=Red]#       why doesn't this work here
#
#     for k, v in knights.iteritems():
#        print k, v[/color]


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
Reply
#3
indentation
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#4
Nuka1195 Wrote: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')]
Reply
#5
ocwasere Wrote: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
Reply
#6
please can you tell me whats wrong with the indentation of the code in red

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

import xbmcgui
ACTION_PREVIOUS_MENU = 10

[color=Red]#       why doesn't this work here
#
#     for k, v in knights.iteritems():
#        print k, v[/color]


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
Reply
#7
get a great program called "PyScripter" - this checks ur code for syntax + indentation errors

:-)
Reply
#8
stanley87 Wrote: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
Reply
#9
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.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#10
Nuka1195 Wrote: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

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

import xbmcgui
ACTION_PREVIOUS_MENU = 10

[color=Red]#       why doesn't this work here

     for k, v in knights.iteritems():
        print k, v[/color]


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
Reply
#11
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 Big Grin 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

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

import xbmcgui

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

ACTION_PREVIOUS_MENU = 10

#       [color=red]got to this work     was indentation error[/color]

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
Reply
#12
i would get a hold of XBMC_PC.exe (T3ch builds include it) and use that to test scripts that run in XBMC.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#13
Nuka1195 Wrote: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
Reply
#14
XBMC_PC.exe = XBMC running on your PC - its not a full port but very good for testing scripts and skins.
Reply
#15
XBMC_PC.exe isn't in the fat 2.0.1 T3CH distro. :confused2:
Reply

Logout Mark Read Team Forum Stats Members Help
trying to learn python0