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


Groups > comp.lang.python > #10615

Re: list comprehension to do os.path.split_all ?

Date 2011-07-31 07:40 +0200
From Michael Poeltl <michael.poeltl@univie.ac.at>
Subject Re: list comprehension to do os.path.split_all ?
References (2 earlier) <mailman.1595.1311888735.1164.python-list@python.org> <879a920c-d06a-4413-9566-6c9f0b737235@glegroupsg2000goo.googlegroups.com> <4E33169E.90307@web.de> <20110730002315.GA799@horus.cms.at> <CAM1e3vqKe25W1Q7-61R3-UyHSL1sfpbcCrbp5KKEpKnaTEyr7Q@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1687.1312090839.1164.python-list@python.org> (permalink)

Show all headers | View raw


* Michael Torrie <torriem@gmail.com> [2011-07-31 03:44]:
> On Jul 29, 2011 6:33 PM, "Michael Poeltl" <michael.poeltl@univie.ac.at>
> wrote:
> >
> > what about this?
> > >>> ' '.join('/home//h1122/bin///ghi/'.split('/')).split()
> > ['home', 'h1122', 'bin', 'ghi']
> > >>>
> 
> Doesn't work on filenames with spaces in them.
you are right; me, I never put spaces into my filenames and so I didn't
think of this possibility.

so there is another idea, which will not work on dirnames 'with spacs in
them' ;-)
>>> p = '/path//to///file/i am a file'
>>> ' '.join(os.path.split(p)[0].split('/')).split().__add__([os.path.split(p)[1]])
['path', 'to', 'file', 'i am a file']
>>>
-- 
Michael Poeltl
Computational Materials Physics      voice: +43-1-4277-51409
Univ. Wien, Sensengasse 8/12         fax:   +43-1-4277-9514 (or 9513) 
A-1090 Wien, AUSTRIA   cmp.mpi.univie.ac.at 
-----------------------------------------------------------------
slackware-12.2/ubuntu-10.10 | vim-7.3 | python-3.2.1 | mutt-1.5.18 | elinks-0.12

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

list comprehension to do os.path.split_all ? gry <georgeryoung@gmail.com> - 2011-07-28 13:18 -0700
  Re: list comprehension to do os.path.split_all ? Stefaan Himpe <stefaan.himpe@gmail.com> - 2011-07-28 22:32 +0200
  Re: list comprehension to do os.path.split_all ? Neil Cerutti <neilc@norwich.edu> - 2011-07-28 20:36 +0000
    Re: list comprehension to do os.path.split_all ? Ethan Furman <ethan@stoneleaf.us> - 2011-07-28 14:03 -0700
  Re: list comprehension to do os.path.split_all ? Alan Meyer <ameyer2@yahoo.com> - 2011-07-28 16:40 -0400
    Re: list comprehension to do os.path.split_all ? TheSaint <no@nowhere.net.no> - 2011-07-29 22:29 +0800
  Re: list comprehension to do os.path.split_all ? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-28 14:44 -0600
  Re: list comprehension to do os.path.split_all ? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-28 14:47 -0600
  Re: list comprehension to do os.path.split_all ? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-28 15:04 -0600
  Re: list comprehension to do os.path.split_all ? Alexander Kapps <alex.kapps@web.de> - 2011-07-28 23:06 +0200
  Re: list comprehension to do os.path.split_all ? Emile van Sebille <emile@fenx.com> - 2011-07-28 14:15 -0700
  Re: list comprehension to do os.path.split_all ? Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-28 15:31 -0600
    Re: list comprehension to do os.path.split_all ? Carl Banks <pavlovevidence@gmail.com> - 2011-07-29 12:30 -0700
      Re: list comprehension to do os.path.split_all ? Alexander Kapps <alex.kapps@web.de> - 2011-07-29 22:22 +0200
      Re: list comprehension to do os.path.split_all ? Michael Poeltl <michael.poeltl@univie.ac.at> - 2011-07-30 02:23 +0200
      Re: list comprehension to do os.path.split_all ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-07-30 10:55 +1000
      Re: list comprehension to do os.path.split_all ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-07-29 22:17 -0700
      Re: list comprehension to do os.path.split_all ? Michael Poeltl <michael.poeltl@univie.ac.at> - 2011-07-31 07:40 +0200
  Re: list comprehension to do os.path.split_all ? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-07-28 21:15 -0700
    Re: list comprehension to do os.path.split_all ? Neil Cerutti <neilc@norwich.edu> - 2011-07-29 12:40 +0000
      Re: list comprehension to do os.path.split_all ? Hrvoje Niksic <hniksic@xemacs.org> - 2011-07-31 08:42 +0200

csiph-web