Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 12:56 PM, iMath wrote: > 在 2013年1月29日星期二UTC+8下午9时33分26秒,Steven D'Aprano写道: >> iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns >> [] ? Because you are iterating over an empty list, []. That list >> comprehension is the equivalent of: result = [

Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread iMath
在 2013年1月29日星期二UTC+8下午9时33分26秒,Steven D'Aprano写道: > iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns > [] ? Because you are iterating over an empty list, []. That list > comprehension is the equivalent of: result = [] for name in []: > result.append( os.path.join(r'E:

Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Dave Angel
On 01/29/2013 08:21 AM, iMath wrote: why [os.path.join(r'E:\Python', name) for name in []] returns [] ? please explain it in detail ! [ os.path.join(r'E:\Python', name) for name in [] ] It'd be nice if you would explain what part of it bothers you. Do you know what a list comprehension is?

Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Steven D'Aprano
iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? Because you are iterating over an empty list, []. That list comprehension is the equivalent of: result = [] for name in []: result.append( os.path.join(r'E:\Python', name) ) Since you iterate over an empty

Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Jean-Michel Pichavant
- Original Message - > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? > please explain it in detail ! > -- > http://mail.python.org/mailman/listinfo/python-list > You're mapping an empty list. "for name in []" JM -- IMPORTANT NOTICE: The contents of this email an

Re: [os.path.join(r'E:\Python', name) for name in []] returns []

2013-01-29 Thread Chris Angelico
On Wed, Jan 30, 2013 at 12:21 AM, iMath wrote: > why [os.path.join(r'E:\Python', name) for name in []] returns [] ? > please explain it in detail ! That's a list comprehension. If you're familiar with functional programming, it's like a map operation. Since the input list (near the end of the com

Re: os.path.join doubt

2011-02-03 Thread Westley Martínez
On Thu, 2011-02-03 at 17:57 -0600, Thomas L. Shinnick wrote: > At 05:33 PM 2/3/2011, Westley Martínez wrote: > > > On Thu, 2011-02-03 at 23:11 +, Steven D'Aprano wrote: > > > > > On Thu, 03 Feb 2011 > > > 07:58:55 -0800, Ethan Furman wrote: > > > > Steven D'Aprano wrote: > > > [snip] > > >

Re: os.path.join doubt

2011-02-03 Thread Thomas L. Shinnick
At 05:33 PM 2/3/2011, Westley Martínez wrote: On Thu, 2011-02-03 at 23:11 +, Steven D'Aprano wrote: On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote: > Steven D'Aprano wrote: [snip] Yes. Is there a problem? All those paths should be usable from Windows. If you find it ugly to see path

Re: os.path.join doubt

2011-02-03 Thread Westley Martínez
On Thu, 2011-02-03 at 23:11 +, Steven D'Aprano wrote: > On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote: > > > Steven D'Aprano wrote: > >> BTW, Windows accepts / as well as \ as a path separator. You will have > >> far fewer headaches if you use that. > > > > Just because Windows acce

Re: os.path.join doubt

2011-02-03 Thread Steven D'Aprano
On Thu, 03 Feb 2011 07:58:55 -0800, Ethan Furman wrote: > Steven D'Aprano wrote: >> BTW, Windows accepts / as well as \ as a path separator. You will have >> far fewer headaches if you use that. > > Just because Windows accepts / doesn't make it a good idea... No. Windows accepting slashes as th

Re: os.path.join doubt

2011-02-03 Thread Ethan Furman
Steven D'Aprano wrote: BTW, Windows accepts / as well as \ as a path separator. You will have far fewer headaches if you use that. Just because Windows accepts / doesn't make it a good idea... Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32 Type "help",

Re: os.path.join doubt

2011-02-03 Thread Westley Martínez
'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' is a valid path. .. means parent, not 'go back a directory'. But you should really be trying this: p1 = os.environ['HOMEPATH'] p2 = os.path.join(p1, 'Pictures', 'images', 'my.jpg') On Wed, 2011-02-02 at 20:46 -0800, harryos wrote: > In win

Re: os.path.join doubt

2011-02-03 Thread Nobody
On Thu, 03 Feb 2011 06:31:49 +, Steven D'Aprano wrote: > On Wed, 02 Feb 2011 20:46:12 -0800, harryos wrote: > >> In windows ,I tried this >> >> p1 = "C:\Users\me\Documents" >> p2 = "..\Pictures\images\my.jpg" Don't do this; backslash is significant within Python string literals. If want to

Re: os.path.join doubt

2011-02-02 Thread Steven D'Aprano
On Wed, 02 Feb 2011 20:46:12 -0800, harryos wrote: > In windows ,I tried this > > p1 = "C:\Users\me\Documents" > p2 = "..\Pictures\images\my.jpg" > > print os.path.join(p1,p2) > This gives > 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' > > I expected I would get > 'C:\\Users\\me\\Pi

Re: os.path.join doubt

2011-02-02 Thread Chris Rebert
On Wed, Feb 2, 2011 at 8:46 PM, harryos wrote: > In windows ,I tried this > > p1 = "C:\Users\me\Documents" > p2 = "..\Pictures\images\my.jpg" > > print os.path.join(p1,p2) > This gives > 'C:\\Users\\me\\Documents\\..\\Pictures\\images\\my.jpg' > > I expected I would get > 'C:\\Users\\me\\Pictures\

Re: os.path.join

2009-10-19 Thread Ethan Furman
Ethan Furman wrote: Following closely on the heels of the whole sum()ing strings debate, I think I found an error -- at least, it's not documented to behave this way... def uncompress_job(job_num, save_path='z:\\old_jobs', restore_path='z:\\orders'): d

Re: os.path.join

2007-05-03 Thread Tim Roberts
Elliot Peele <[EMAIL PROTECTED]> wrote: >On Tue, 2007-05-01 at 19:27 -0700, 7stud wrote: >> On May 1, 7:36 pm, Elliot Peele <[EMAIL PROTECTED]> wrote: >> > Why does os.path.join('/foo', '/bar') return '/bar' rather than >> > '/foo/bar'? That just seems rather counter intuitive. >> > >> > Elliot >>

Re: os.path.join

2007-05-02 Thread half . italian
On May 2, 12:36 am, Ant <[EMAIL PROTECTED]> wrote: > On May 2, 8:03 am, [EMAIL PROTECTED] wrote: > > > On May 1, 11:10 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > ... > > > I think it's a bug, but because it should raise TypeError instead. > > > The right usage is os.path.join(*pathparts) > ... >

Re: os.path.join

2007-05-02 Thread Ant
On May 2, 8:03 am, [EMAIL PROTECTED] wrote: > On May 1, 11:10 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> ... > > I think it's a bug, but because it should raise TypeError instead. > > The right usage is os.path.join(*pathparts) ... > Wow. What exactly is that * operator doing? Is it only used in

Re: os.path.join

2007-05-02 Thread Gabriel Genellina
En Wed, 02 May 2007 04:03:56 -0300, <[EMAIL PROTECTED]> escribió: > On May 1, 11:10 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> > wrote: >> The right usage is os.path.join(*pathparts) > > Wow. What exactly is that * operator doing? Is it only used in > passing args to functions? Does it just e

Re: os.path.join

2007-05-02 Thread half . italian
On May 1, 11:10 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Wed, 02 May 2007 02:31:43 -0300, <[EMAIL PROTECTED]> escribió: > > > A better question is why this doesn't work. > > pathparts = ["/foo", "bar"] > os.path.join(pathparts) > > ['/foo', 'bar'] > > > This should return a

Re: os.path.join

2007-05-01 Thread Gabriel Genellina
En Wed, 02 May 2007 02:31:43 -0300, <[EMAIL PROTECTED]> escribió: > A better question is why this doesn't work. > pathparts = ["/foo", "bar"] os.path.join(pathparts) > ['/foo', 'bar'] > > This should return a string in my opinion. I think it's a bug, but because it should raise TypeErro

Re: os.path.join

2007-05-01 Thread Gabriel Genellina
En Wed, 02 May 2007 01:23:45 -0300, Elliot Peele <[EMAIL PROTECTED]> escribió: > On Tue, 2007-05-01 at 19:27 -0700, 7stud wrote: >> On May 1, 7:36 pm, Elliot Peele <[EMAIL PROTECTED]> wrote: >> > Why does os.path.join('/foo', '/bar') return '/bar' rather than >> > '/foo/bar'? That just seems rat

Re: os.path.join

2007-05-01 Thread half . italian
On May 1, 9:23 pm, Elliot Peele <[EMAIL PROTECTED]> wrote: > On Tue, 2007-05-01 at 19:27 -0700, 7stud wrote: > > On May 1, 7:36 pm, Elliot Peele <[EMAIL PROTECTED]> wrote: > > > Why does os.path.join('/foo', '/bar') return '/bar' rather than > > > '/foo/bar'? That just seems rather counter intuitiv

Re: os.path.join

2007-05-01 Thread Elliot Peele
On Tue, 2007-05-01 at 19:27 -0700, 7stud wrote: > On May 1, 7:36 pm, Elliot Peele <[EMAIL PROTECTED]> wrote: > > Why does os.path.join('/foo', '/bar') return '/bar' rather than > > '/foo/bar'? That just seems rather counter intuitive. > > > > Elliot > > join( path1[, path2[, ...]]) > Join one or m

Re: os.path.join

2007-05-01 Thread Elliot Peele
On Tue, 2007-05-01 at 21:26 -0500, Michael Bentley wrote: > On May 1, 2007, at 8:36 PM, Elliot Peele wrote: > > > Why does os.path.join('/foo', '/bar') return '/bar' rather than > > '/foo/bar'? That just seems rather counter intuitive. > > It's the leading slash in '/bar'. os.path.join('/foo', '

Re: os.path.join

2007-05-01 Thread 7stud
On May 1, 7:36 pm, Elliot Peele <[EMAIL PROTECTED]> wrote: > Why does os.path.join('/foo', '/bar') return '/bar' rather than > '/foo/bar'? That just seems rather counter intuitive. > > Elliot join( path1[, path2[, ...]]) Join one or more path components intelligently. If any component is an abso

Re: os.path.join

2007-05-01 Thread Michael Bentley
On May 1, 2007, at 8:36 PM, Elliot Peele wrote: > Why does os.path.join('/foo', '/bar') return '/bar' rather than > '/foo/bar'? That just seems rather counter intuitive. It's the leading slash in '/bar'. os.path.join('/foo', 'bar') returns '/foo/bar'. -- http://mail.python.org/mailman/listi

Re: os.path.join - Isn't working

2006-01-27 Thread Gregory Piñero
Wow, sorry I sent that a little too fast. I just had to remove the \\ before the graphics. Thus this did work: os.path.join('C:\\Documents and Settings\\Gregory','graphics\\knight\\been hit e0001.bmp') -Greg On 1/27/06, Gregory Piñero <[EMAIL PROTECTED]> wrote: > Would someone mind explaining