Τη Πέμπτη, 6 Ιουνίου 2013 10:03:02 μ.μ. UTC+3, ο χρήστης Lele Gaifax έγραψε:
> Νικόλαος Κούρας <nikos.gr...@gmail.com> writes:
> 
> 
> 
> > ...
> 
> > # Load'em
> 
> > for fullpath in path:
> 
> >     try:
> 
> > ...
> 
> >
> 
> > The error is:
> 
> > [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173]   File 
> > "files.py", line 64
> 
> > [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173]     for fullpath 
> > in path
> 
> > [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173]                   
> >      ^
> 
> > [Thu Jun 06 21:10:23 2013] [error] [client 79.103.41.173] SyntaxError: 
> > invalid syntax
> 
> >
> 
> >
> 
> > Doesn't os.listdir( ...) returns a list with all filenames?
> 
> 
> 
> You should *read* and *understand* the error message! 
> 
> 
> 
> This is the same kind of confusion you had when I pointed you at the
> 
> missing closing bracket some day ago, when you missed the meaning of the
> 
> error and assume it's source is related to something completely
> 
> different...
> 
> 
> 
> In the specific case, your line 64 is missing an ending colon (":").
> 
> 
> 
> ciao, lele.

Oh my God, was that simple and i was smashing my head to see where did i made a 
synatx error. Missed the colon! Well the error shoudl ahve said "Hey man, you 
missed a colon!", that would help a lot.

Now the error afetr fixithg that transformed to:

[Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173]     filename = 
fullpath.replace( '/home/nikos/public_html/data/apps/', '' )
[Thu Jun 06 22:13:49 2013] [error] [client 79.103.41.173] TypeError: expected 
bytes, bytearray or buffer compatible object


but htats becaus eof these lines:

# Give the path as a bytestring so that we'll get the filenames as bytestrings
path = os.listdir( b'/home/nikos/public_html/data/apps/' )

# iterate over all filenames in the apps directory
for fullpath in path:
        # Grabbing just the filename from path
        filename = fullpath.replace( '/home/nikos/public_html/data/apps/', '' )

i can remove the bianry openign from os.listdir but then this will not work.
MRAB has told me that i need to open those paths and filenames as bytestreams 
and not as unicode strings.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to