trying to learn python

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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
find quote
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,917
Joined: Dec 2004
Reputation: 17
Post: #3
indentation

For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
find quote
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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')]
find quote
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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
find quote
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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
find quote
stanley87 Offline
Skilled Python Coder
Posts: 555
Joined: Sep 2006
Reputation: 2
Location: Chch, New Zealand
Post: #7
get a great program called "PyScripter" - this checks ur code for syntax + indentation errors

:-)
find quote
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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
find quote
Nuka1195 Offline
Skilled Python Coder
Posts: 3,917
Joined: Dec 2004
Reputation: 17
Post: #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/
find quote
ocwasere Offline
Junior Member
Posts: 31
Joined: Jul 2005
Reputation: 0
Post: #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
find quote
Post Reply