Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44878 > unrolled thread

Why sfml does not play the file inside a function in this python code?

Started bycheirasacan@gmail.com
First post2013-05-07 02:27 -0700
Last post2013-05-07 19:03 +0200
Articles 7 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Why sfml does not play the file inside a function in this python code? cheirasacan@gmail.com - 2013-05-07 02:27 -0700
    Re: Why sfml does not play the file inside a function in this python code? MRAB <python@mrabarnett.plus.com> - 2013-05-07 11:53 +0100
      Re: Why sfml does not play the file inside a function in this python code? cheirasacan@gmail.com - 2013-05-07 06:56 -0700
        Re: Why sfml does not play the file inside a function in this python code? MRAB <python@mrabarnett.plus.com> - 2013-05-07 15:57 +0100
          Re: Why sfml does not play the file inside a function in this python code? cheirasacan@gmail.com - 2013-05-07 13:02 -0700
        Re: Why sfml does not play the file inside a function in this python code? Chris Angelico <rosuav@gmail.com> - 2013-05-08 01:06 +1000
        dist-packages or site-packages  in Python 3.2 ? Vincent Vande Vyvre <vincent.vandevyvre@swing.be> - 2013-05-07 19:03 +0200

#44878 — Why sfml does not play the file inside a function in this python code?

Fromcheirasacan@gmail.com
Date2013-05-07 02:27 -0700
SubjectWhy sfml does not play the file inside a function in this python code?
Message-ID<69b77965-5ff5-4c6f-a73d-0826b06353f0@googlegroups.com>
from tkinter import *
import sfml


window = Tk()
window.minsize( 640, 480 )


def sonido():
    file = sfml.Music.from_file('poco.ogg')
    file.play()


test = Button ( window, text = 'Sound test', command=sonido )
test.place ( x = 10, y = 60)

window.mainloop()




Using Windows 7, Python 3.3, sfml 1.3.0 library, the file it is played if i put it out of the function. ¿ what am i doing wrong ? Thanks.

[toc] | [next] | [standalone]


#44879

FromMRAB <python@mrabarnett.plus.com>
Date2013-05-07 11:53 +0100
Message-ID<mailman.1402.1367924006.3114.python-list@python.org>
In reply to#44878
On 07/05/2013 10:27, cheirasacan@gmail.com wrote:
> from tkinter import *
> import sfml
>
>
> window = Tk()
> window.minsize( 640, 480 )
>
>
> def sonido():
>      file = sfml.Music.from_file('poco.ogg')
>      file.play()
>
>
> test = Button ( window, text = 'Sound test', command=sonido )
> test.place ( x = 10, y = 60)
>
> window.mainloop()
>
>
>
>
> Using Windows 7, Python 3.3, sfml 1.3.0 library, the file it is played if i put it out of the function. ¿ what am i doing wrong ? Thanks.
>
Perhaps what's happening is that sonido starts playing it and then
returns, meaning that there's no longer a reference to it ('file' is
local to the function), so it's collected by the garbage collector.

If that's the case, try keeping a reference to it, perhaps by making
'file' global (in a simple program like this one, using global should
be OK).

[toc] | [prev] | [next] | [standalone]


#44893

Fromcheirasacan@gmail.com
Date2013-05-07 06:56 -0700
Message-ID<85771dda-4289-4cfb-a96f-23809664913e@googlegroups.com>
In reply to#44879
El martes, 7 de mayo de 2013 12:53:25 UTC+2, MRAB  escribió:
> On 07/05/2013 10:27, cheirasacan@gmail.com wrote:
> 
> > from tkinter import *
> 
> > import sfml
> 
> >
> 
> >
> 
> > window = Tk()
> 
> > window.minsize( 640, 480 )
> 
> >
> 
> >
> 
> > def sonido():
> 
> >      file = sfml.Music.from_file('poco.ogg')
> 
> >      file.play()
> 
> >
> 
> >
> 
> > test = Button ( window, text = 'Sound test', command=sonido )
> 
> > test.place ( x = 10, y = 60)
> 
> >
> 
> > window.mainloop()
> 
> >
> 
> >
> 
> >
> 
> >
> 
> > Using Windows 7, Python 3.3, sfml 1.3.0 library, the file it is played if i put it out of the function. � what am i doing wrong ? Thanks.
> 
> >
> 
> Perhaps what's happening is that sonido starts playing it and then
> 
> returns, meaning that there's no longer a reference to it ('file' is
> 
> local to the function), so it's collected by the garbage collector.
> 
> 
> 
> If that's the case, try keeping a reference to it, perhaps by making
> 
> 'file' global (in a simple program like this one, using global should
> 
> be OK).

Thanks. A global use of 'sonido' fix the problem. The garbage collector must be the point. But this code is part of a longer project. What can i do to fix it without the use of globals? I will use more functions like this, and i would like to keep learning python as well good programming methodology.
Thanks.

[toc] | [prev] | [next] | [standalone]


#44895

FromMRAB <python@mrabarnett.plus.com>
Date2013-05-07 15:57 +0100
Message-ID<mailman.1413.1367938681.3114.python-list@python.org>
In reply to#44893
On 07/05/2013 14:56, cheirasacan@gmail.com wrote:
> El martes, 7 de mayo de 2013 12:53:25 UTC+2, MRAB  escribió:
>> On 07/05/2013 10:27, cheirasacan@gmail.com wrote:
>> > from tkinter import *
>> > import sfml
>> >
>> > window = Tk()
>> > window.minsize( 640, 480 )
>> >
>> > def sonido():
>> >      file = sfml.Music.from_file('poco.ogg')
>> >      file.play()
>> >
>> > test = Button ( window, text = 'Sound test', command=sonido )
>> > test.place ( x = 10, y = 60)
>> >
>> > window.mainloop()
>> >
>> > Using Windows 7, Python 3.3, sfml 1.3.0 library, the file it is played if i put it out of the function. � what am i doing wrong ? Thanks.
>> >
>>
>> Perhaps what's happening is that sonido starts playing it and then
>> returns, meaning that there's no longer a reference to it ('file' is
>> local to the function), so it's collected by the garbage collector.
>>
>> If that's the case, try keeping a reference to it, perhaps by making
>> 'file' global (in a simple program like this one, using global should
>> be OK).
>
> Thanks. A global use of 'sonido' fix the problem. The garbage collector must be the point. But this code is part of a longer project. What can i do to fix it without the use of globals? I will use more functions like this, and i would like to keep learning python as well good programming methodology.
> Thanks.
>
Presumably the details of the window are (or will be) hidden away in a
class, so you could make 'file' an attribute of an instance.

Also, please read this:

http://wiki.python.org/moin/GoogleGroupsPython

because gmail insists on adding extra linebreaks, which can be somewhat
annoying.

[toc] | [prev] | [next] | [standalone]


#44901

Fromcheirasacan@gmail.com
Date2013-05-07 13:02 -0700
Message-ID<6339279e-4f8e-43c8-bb04-b6607d7db4a1@googlegroups.com>
In reply to#44895
El martes, 7 de mayo de 2013 16:57:59 UTC+2, MRAB  escribió:
> On 07/05/2013 14:56, cheirasacan@gmail.com wrote:
> 
> > El martes, 7 de mayo de 2013 12:53:25 UTC+2, MRAB  escribió:
> 
> >> On 07/05/2013 10:27, cheirasacan@gmail.com wrote:
> 
> >> > from tkinter import *
> 
> >> > import sfml
> 
> >> >
> 
> >> > window = Tk()
> 
> >> > window.minsize( 640, 480 )
> 
> >> >
> 
> >> > def sonido():
> 
> >> >      file = sfml.Music.from_file('poco.ogg')
> 
> >> >      file.play()
> 
> >> >
> 
> >> > test = Button ( window, text = 'Sound test', command=sonido )
> 
> >> > test.place ( x = 10, y = 60)
> 
> >> >
> 
> >> > window.mainloop()
> 
> >> >
> 
> >> > Using Windows 7, Python 3.3, sfml 1.3.0 library, the file it is played if i put it out of the function. � what am i doing wrong ? Thanks.
> 
> >> >
> 
> >>
> 
> >> Perhaps what's happening is that sonido starts playing it and then
> 
> >> returns, meaning that there's no longer a reference to it ('file' is
> 
> >> local to the function), so it's collected by the garbage collector.
> 
> >>
> 
> >> If that's the case, try keeping a reference to it, perhaps by making
> 
> >> 'file' global (in a simple program like this one, using global should
> 
> >> be OK).
> 
> >
> 
> > Thanks. A global use of 'sonido' fix the problem. The garbage collector must be the point. But this code is part of a longer project. What can i do to fix it without the use of globals? I will use more functions like this, and i would like to keep learning python as well good programming methodology.
> 
> > Thanks.
> 
> >
> 
> Presumably the details of the window are (or will be) hidden away in a
> 
> class, so you could make 'file' an attribute of an instance.
> 
> 
> 
> Also, please read this:
> 
> 
> 
> http://wiki.python.org/moin/GoogleGroupsPython
> 
> 
> 
> because gmail insists on adding extra linebreaks, which can be somewhat
> 
> annoying.

 The reply is very useful. I will keep learning.
 Thanks for all.

[toc] | [prev] | [next] | [standalone]


#44896

FromChris Angelico <rosuav@gmail.com>
Date2013-05-08 01:06 +1000
Message-ID<mailman.1414.1367939186.3114.python-list@python.org>
In reply to#44893
On Wed, May 8, 2013 at 12:57 AM, MRAB <python@mrabarnett.plus.com> wrote:
> Also, please read this:
>
> http://wiki.python.org/moin/GoogleGroupsPython
>
> because gmail insists on adding extra linebreaks, which can be somewhat
> annoying.

Accuracy correction: It's nothing to do with gmail, which is what I
use (via python-list subscription). It's just Google Groups.

ChrisA

[toc] | [prev] | [next] | [standalone]


#44897 — dist-packages or site-packages in Python 3.2 ?

FromVincent Vande Vyvre <vincent.vandevyvre@swing.be>
Date2013-05-07 19:03 +0200
Subjectdist-packages or site-packages in Python 3.2 ?
Message-ID<mailman.1415.1367946643.3114.python-list@python.org>
In reply to#44893
Hi,

I've one machine with python3.2 (on Ubuntu 12.04), in the folder 
/usr/lib/python3.2 it is a subfolder dist-packages, maybe created at the 
install or created when I've installed the binding pyexiv2, I don't know.

Now, I've installed a new machine, again with Ubuntu 12.04 and therefore 
python3.2.
This new install hasn't any *-packages subfolder in /usr/lib/python3.2

Today I install PyQt5, the make and make install are executed without 
error but when I try:

 >>> from PyQt5 import QtGui
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
ImportError: No module named PyQt5

I go to check in /usr/lib/python3.2 and I see the install of PyQt5 has 
created a subfolder site-packages.
Is this naming dist-packages/site-packages critical for Python? (My 
intuition is yes!)

So, I've tried with:
 >>> sys.path.append('/usr/lib/python3.2/site_packages')
and, also, created a file __init__.py in /site-packages but that's not 
solved the problem.

Thanks for your advices.
-- 
Vincent V.V.
Oqapy <https://launchpad.net/oqapy> . Qarte 
<https://launchpad.net/qarte> . PaQager <https://launchpad.net/paqager>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web