awesome slugify and unicode

W

wxjmfauth

Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a écrit :
I thought this blog might interest some of you

http://pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html



--

My fellow Pythonistas, ask not what our language can do for you, ask

what you can do for our language.

This is not "unicode", only string manipulations.
The same work could be done with, let say, cp1252.
The difference lies in the repertoires of characters
to be handled.

A better way is to work with normalization() and/or
with methods like .translate() with dedicated
tables; the hard task being the creation of these tables.

Shortly, very naive.

jmf
 
M

Mark Lawrence

Le mercredi 22 janvier 2014 20:23:55 UTC+1, Mark Lawrence a écrit :

This is not "unicode", only string manipulations.
The same work could be done with, let say, cp1252.
The difference lies in the repertoires of characters
to be handled.

A better way is to work with normalization() and/or
with methods like .translate() with dedicated
tables; the hard task being the creation of these tables.

Shortly, very naive.

jmf

You'll have to excuse my ignorance of this stuff. How do I express the
following in cp1252?

def test_musical_notes():
txt = "Is ♬ ♫ ♪ ♩ a melody or just noise?"
assert slugify(txt) == "Is-a-melody-or-just-noise"
assert slugify_unicode(txt) == "Is-a-melody-or-just-noise"
 
W

wxjmfauth

Le jeudi 23 janvier 2014 10:14:48 UTC+1, Mark Lawrence a écrit :
You'll have to excuse my ignorance of this stuff. How do I express the

following in cp1252?



def test_musical_notes():

txt = "Is ♬ ♫ ♪ ♩ a melody or justnoise?"

assert slugify(txt) == "Is-a-melody-or-just-noise"

assert slugify_unicode(txt) == "Is-a-melody-or-just-noise"



--

My fellow Pythonistas, ask not what our language can do for you, ask

what you can do for our language.

I wrote: The same work could be done with, let say, cp1252.
Understand: The same work (string manipulation) ...
Would something like this not be more informative?

cp1252 analogy.

Again, not a "unicode" question, more "how to handle strings in a judiciousway?"

jmf
 
C

Chris Angelico

cp1252 analogy.


Again, not a "unicode" question, more "how to handle strings in a judicious way?"

I don't want a cp1252 analogy, I want the exact same thing implemented
in cp1252. You said the same work could be done there. That work
includes dealing with musical notes. How are you going to do that?

ChrisA
 
M

Mark Lawrence

Le jeudi 23 janvier 2014 10:14:48 UTC+1, Mark Lawrence a écrit :

I wrote: The same work could be done with, let say, cp1252.
Understand: The same work (string manipulation) ...
Would something like this not be more informative?


cp1252 analogy.


Again, not a "unicode" question, more "how to handle strings in a judicious way?"

jmf

Now I'm really confused. I thought that the musical notes I've shown
above are represented as unicode characters. So I'd like to see how you
jmf would represent them in cp1252. Instead you give me an example
showing a simple string manipulation which simply strips the characters
that I want to see, then an even simpler example, clearly not what I've
asked for.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top