Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2008

    getID3, os.path.isfile and string


    An error has occured with my code. I use the function getID3 who has published in this page.

    My code (I have also copied the function getID3) :

    def getID3(filename):
    	fp = open(filename, 'r')
    	fp.seek(-128, 2)
    	fp.read(3) # TAG iniziale
    	title = fp.read(30)
    	artist = fp.read(30)
    	album = fp.read(30)
    	year = fp.read(4)
    	comment = fp.read(28)
    	return {'title':title, 'artist':artist, 'album':album, 'year':year}
    target="E:\\mpfiles\\artistes\\" + info['artist'] + ".xml"
    if (os.path.isfile(target)):
    	#i edit target, it's not a problem
    	#i create target and i edit, it's not a problem
    I want create a file in the directory E:\mpfiles\artistes, called the-name-of-the-artiste.xml (where the-name-of-the-artiste is replaced) only if this file don't exist. That's why I use the method : os.path.isfile(target), but i have an error :

    File "E:...mycode.py" line 20
    if (os.path.isfile(target)):
    File "c:\resource\ntpath.py", line 156, in isfile
    TypeError:stat() argument 1 must be (encoded string without NULL bytes), not str
    I think that the problem is the encoding of target, but i don't make a success of this problem. I have try to change os.path.isfile(target) in os.path.isfile(str(target)) or os.path.isfile(unicode(target)) but the error is always here (for unicode(target), the error print the same message except the last word replaced by unicode)
    Can you help me please?

    nb:i'm french, i hope my english is not too bad!

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Deva, Romania

    Re: getID3, os.path.isfile and string

    From what I understand your problem is only checking if the file exists. If so, you can try the following:

    for f in os.listdir("E:\\mpfiles\\artistes"):
       if(f==info['artist'] + ".xml"):
           #You edit it
           #You crerate and edit it, just like you said
    This code creates a list of all the files in the directory "E:\\mpfiles\\artistes" and checks if the one you want to edit is among them.

  3. #3
    Registered User
    Join Date
    Apr 2008

    Re: getID3, os.path.isfile and string

    Yes, it's a solution, i test and i say you if it's ok!

    Umhhh, it's ok, but the same problem is now for another isfile(target) (that i don't change), and for an open(target).
    Target is always : target="E:\\mpfiles\\artistes\\" + info['artist'] + ".xml"
    Last edited by r4ph43l; 2008-04-08 at 10:42.

  4. #4
    Registered User
    Join Date
    Apr 2008

    Re: getID3, os.path.isfile and string

    I have the solution.
    The problem is there are null bytes ('\0') in my target, and we cannot search or create a file with a name with null bytes.
    I have also coded a function which delete null bytes in a string :

    def sans_null(string):
        for i in string.split('\0'):
        return tmp
    and we can use it :

    This run! If this can help someone...

Similar Threads

  1. Send string data from symbian to .net
    By ahlmans in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2008-01-16, 13:40
  2. How to use Gauge/Process Bar when using HttpConnection?
    By Tanya in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2006-12-28, 07:59
  3. global root overflow(please help)
    By sushant_125 in forum Mobile Java Networking & Messaging & Security
    Replies: 3
    Last Post: 2004-05-14, 08:24
  4. Personal
    By JSmith77 in forum PersonalJava
    Replies: 4
    Last Post: 2003-07-30, 12:52
  5. D211 new linux driver 1.04 not working !!
    By franz_meyer in forum Multimodecards
    Replies: 1
    Last Post: 2002-12-12, 08:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts