Re: pygame music, cant read mp3?



On Mon, 2008-05-05 at 07:32 -0700, globalrev wrote:
On 5 Maj, 16:29, globalrev <skanem...@xxxxxxxx> wrote:
On 5 Maj, 16:09, globalrev <skanem...@xxxxxxxx> wrote:



On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick.walc...@xxxxxxxxx>
wrote:

2008/5/5, globalrev <skanem...@xxxxxxxx>:

pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')

Are you sure that:

os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?

Check it with python.

--
Regards,
Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
import os
os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True

False

but...it is there....

os.path.exists('C:\Python25\myPrograms\pygameProgs\dront.mp3') == True

False

does it matter if i use / or \? which si recommended?

i can find .png image in the same folder and when i just change
filename from snake.png to example1.mp3 it is false.

i renamed the file once, could that have anything to do with it?

\\ or \ or / all works.


the title of the mp3 is a long number still. i mena if i go to
properties the name is example1.mpg but the title if i go to details
is stillt he old one.


Now I'm confused. What is the name of the *file* on the filesystem?
You can verify this using

os.listdir('C:/Python25/myPrograms/pygameProgs')

As for the question of \\ vs. \ vs. /: Windows will accept forward
slashes, but you may run into trouble later on down the line if windows
treats one of your forward slashes as a command line option. The native
format is to use backslashes as separators, but backslashes need to be
escaped in python's regular string literals, because of escape
sequences. Single backslashes seem to be working for you, but that's
only because you've been lucky in not having escape characters following
your backslash. Particularly, x, n, t, u, and U will cause trouble.
Probably others.

Cut'n'paste example:

$ python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
'\efoo'
'\\efoo'
'\dfoo'
'\\dfoo'
'\ufoo'
'\\ufoo'
'\uabcd'
'\\uabcd'
u'\uabcd'
u'\uabcd'
u'\ufoo'
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position
0-4: end of string in escape sequence
'\xfoo'
ValueError: invalid \x escape
'\nfoo'
'\nfoo'
print '\nfoo'

foo


Notice that the \ gets doubled (escaped) automatically by python in many
of the instances, but not for the \n, and an exception gets raised for
\u (in unicode strings only), and for \x (in regular strings too). It's
safer just to escape your strings yourself. So 'C:\\foo' is always
better than 'C:\foo', even though the latter may sometimes work. Better
still is to create a list of directories, and use os.path.join(dirlist)
as follows:

directory = ['C:','Python25','myPrograms','pygameProgs','dront.mp3']
os.path.join(directory)

Then python can worry about the gritty details, and you don't have to.

--
Oook,
J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill

.



Relevant Pages

  • Re: Unrecognized escape sequences in string literals
    ... If you don't know what your string literals are, ... Adding escape codes into the string literal doesn't change this ... extra effort required to defeat the compiler (forcing the programmer to ... And if you saw that in Python, you'd also know that there are some ...
    (comp.lang.python)
  • Re: more on unescaping escapes
    ... without the quotes in the file so my parser can read it as a single ... string. ... It really is a tab that gets stored there, not the escape for one. ... if you give python an unknown escape it passes it leaves it ...
    (comp.lang.python)
  • Re: Unrecognized escape sequences in string literals
    ... if he could just look at the string literal and know. ... friend is a programmer. ... If you don't know what a backslash escape is going to do, ... That's an enormous difference from Python, ...
    (comp.lang.python)
  • Re: more on unescaping escapes
    ... I need to use the \x20 because of my parser. ... it's not really a problem of what happens when you assign a string ... It really is a tab that gets stored there, not the escape for one. ... if you give python an unknown escape it passes it leaves it ...
    (comp.lang.python)
  • Re: String escaping
    ... return $string; ... it would escape any backslashes already in the string. ...
    (comp.lang.perl.misc)