You are not logged in.
Pages: 1
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
is it threaded? otherwise it usually spits out more specific errors,
arch + gentoo + initng + python = enlisy
Offline
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
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
>>> 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
connect.getCurrentSong() returns a song object, do:
song = connect.getCurrentSong()
dir(song)
this way you see all attributes/methods.
Offline
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
Pages: 1