You are not logged in.

#1 2005-06-10 20:00:56

johnisevil
Member
From: Hamilton, ON Canada
Registered: 2003-08-07
Posts: 221
Website

Python help

I'm working on this script that refuses to work properly.  I'm attempting to get output from a module and display it as a string but instead I get the following:

>>> show_song
<function show_song at 0xb7c1be2c>

Any ideas when I'm getting this kind of output?

Offline

#2 2005-06-10 21:30:56

xerxes2
Member
From: Malmoe, Sweden
Registered: 2004-04-23
Posts: 1,249
Website

Re: Python help

is it threaded? otherwise it usually spits out more specific errors,


arch + gentoo + initng + python = enlisy

Offline

#3 2005-06-10 21:36:06

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: Python help

it actually looks like that isn't an error... looks like its a reference to the function, instead of calling the function.

maybe show_song() would work?

Dusty

Offline

#4 2005-06-10 21:44:24

johnisevil
Member
From: Hamilton, ON Canada
Registered: 2003-08-07
Posts: 221
Website

Re: Python help

This is what I'm trying to do (from the interpreter) to test it before I actually put it into a script.  Still no luck.

>>> import mpdclient
>>> connect = mpdclient.MpdController(port=6600)
>>> connect.stop()
>>> connect.play()
>>> connect.getCurrentSong
<bound method MpdController.getCurrentSong of <mpdclient.MpdController object at 0xb7c241ac>>
>>> connect.getCurrentSong()
<mpdclient.Song object at 0xb7c482ac>
>>>

Offline

#5 2005-06-10 21:46:51

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: Python help

johnisevil wrote:
>>> connect.getCurrentSong()
<mpdclient.Song object at 0xb7c482ac>
>>>

and? it's an object... you can't just print an object like that....
try "repr(connect.getCurrentSong())" or is it rep()... anyway... it's returning a Song object... look up the Song object and find the methods/members... I'm going to take a shot in the dark and say:

s=connect.getCurrentSong()
print s.title
print s.artist

Offline

#6 2005-06-10 21:47:41

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: Python help

connect.getCurrentSong() returns a song object, do:

song = connect.getCurrentSong()
dir(song)

this way you see all attributes/methods.

Offline

#7 2005-06-10 22:34:58

johnisevil
Member
From: Hamilton, ON Canada
Registered: 2003-08-07
Posts: 221
Website

Re: Python help

Thanks for the help guys, I'm in the process or relearning Python after almost 2 years of not using it so I'm starting off with my second Openbox pipe menu script.  This is how it turned out.

#!/usr/bin/env python

import mpdclient

connect = mpdclient.MpdController(port=6600)
song = connect.getCurrentSong()
status = connect.status()

print "<?xml version="1.0" encoding="UTF-8"?>"
print "<openbox_pipe_menu>"
if status.stateStr() == "stop":
  print "  <item label="Not playing"/>"
else:
  print "  <item label="Playing: %s - %s"/>" % (song.artist, song.title)
print "</openbox_pipe_menu>"

Offline

Board footer

Powered by FluxBB