How to split with "\" character, and licence copyleft mirror of ©

Tim Chase python.list at tim.thechases.com
Sun Sep 1 20:34:16 EDT 2013


On 2013-09-01 17:03, materile11 at gmail.com wrote:
> Hello everybody
> I'm trying to run this: 
> 
> <code>
> >>> a = 'E:\Dropbox\jjfsdjjsdklfj\sdfjksdfkjslkj\flute.wav'
> >>> a.split('\')
> 
> SyntaxError: EOL while scanning string literal
> </code>
> 
> I think that the character '\' is the problem, but unfortunately
> I'm developing a small app for windows and I need to show only the
> name of the .wav file, in this case 'flute.wav'.

To directly answer your question, you need to escape the "\" so it's

  a.split('\\')

That said, it's far better to use Python's built-ins to do the
processing for you:

  >>> import os
  >>> print os.path.basename(a)
  flute.wav

which does what you want *and* works cross-platform:

  [on Linux]
  >>> a = '/home/tkc/path/to/flute.wav'
  >>> print os.path.basename(a)
  flute.wav

> I also want to know how to mirror a character, in my case this one
> ©, because I'll use the Copyleft

This can't be done in much of a general way:  Unicode doesn't specify
this character, and the URL you provided suggests combining two
Unicode characters to get ↄ⃝  Unfortunately, (1) it requires a
display that knows how to produce that, which many terminals can't;
and (2) it's purely visual, not semantic.  If that's what you really
want, you should be able to use:

  copyleft_symbol = u"\u2184\u20DD"

Just be aware that it may not always display the way you expect it to.

-tkc






More information about the Python-list mailing list