ascii « string « Python Data Type Q&A

Home
Python Data Type Q&A
1.array
2.date
3.dictionary
4.Format
5.integer
6.List
7.numpy
8.regex
9.string
10.tuple
Python Data Type Q&A » string » ascii 

1. How do I convert a list of ascii values to a string in python?    stackoverflow.com

I've got a list in a Python program that contains a series of numbers, which are themselves ASCII values. How do I convert this into a "regular" string that I ...

2. How to check if a string in Python is in ASCII?    stackoverflow.com

I am fighting with Python to understand how do I check whether a string is in ASCII or not. I am aware of ord(), however when I try ord('é'), I have TypeError: ...

3. How do I treat an ASCII string as unicode and unescape the escaped characters in it in python?    stackoverflow.com

For example, if I have a unicode string, I can encode it as an ASCII string like so:

>>> u'\u003cfoo/\u003e'.encode('ascii')
'<foo/>'
However, I have e.g. this ASCII string:
'\u003foo\u003e'
... that I want to turn into ...

4. Python string prints as u['String']    stackoverflow.com

This will surely be an easy one but it is really bugging me. I have a script that reads in a webpage and uses BeutifulSoup to parse it. From the soup ...

5. What is the most efficient way in Python to convert a string to all lowercase stripping out all non-ascii alpha characters?    stackoverflow.com

I have a simple task I need to perform in Python, which is to convert a string to all lowercase and strip out all non-ascii non-alpha characters. For example:

"This is a ...

6. How to replace non ascii characters in string?    stackoverflow.com

I have a string that looks like so:

6 918 417 712
The clear cut way to trim this string (as I understand Python) is simply to say the string is in a variable called s, we ...

7. encoding a string to ascii    stackoverflow.com

I have a long string that I want to encode to ascii. I'm doing:

s = s.encode('ascii', 'replace')
but I get:
'ascii' codec can't decode byte 0xc3 in position 2646: ordinal not in range(128)
(I've ...

8. Python: How to get StringIO.writelines to accept unicode string?    stackoverflow.com

I'm getting a

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 34: ordinal not in range(128)
on a string stored in 'a.desc' below as it contains the '£' character. It's ...

9. An equivalent to string.ascii_letters for unicode strings in python 2.x?    stackoverflow.com

In the "string" module of the standard library,

string.ascii_letters ## Same as string.ascii_lowercase + string.ascii_uppercase
is
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
Is there a similar constant which would include everything that is considered a letter in unicode? ...

10. 'ASCII' to Unicode error in python when attempting to read a latin-1 encoded string    stackoverflow.com

I'm having a problem when trying to apply a regular expression to some strings encoded in latin-1 (ISO-8859-1). What I'm trying to do is send some data via HTTP POST from ...

11. How to convert an UTF string with scandinavian characters to ASCII?    stackoverflow.com

I would like to convert this string

foo_utf = u'nästy chäräctörs with å and co.' # unicode
into this
foo_ascii = 'nästy chäräctörs with å and co.' # ASCII
. Any idea how to do this ...

12. parsing a string of ascii text into separate variables    stackoverflow.com

I have a piece of text that gets handed to me like:

here is line one\n\nhere is line two\n\nhere is line three
What I would like to do is break this ...

13. Python: how to print range a-z?    stackoverflow.com

1. Print a-n: a b c d e f g h i j k l m n 2. Every second in a-n: a c e g i k m 3. Append a-n to ...

14. Convert Python string to its ASCII representants    stackoverflow.com

How do I convert a string in Python to its ASCII hex representants? Example: I want to result '\x00\x1b\xd4}\xa4\xf3\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' in 001bd47da4f3.

15. How to make a Python string out of non-ascii "bytes"    stackoverflow.com

I need to create a Python string consisting of non-ascii bytes to be used as a command buffer in a C module. I can do that if I write the string by ...

16. Python convert mixed ASCII code to String    stackoverflow.com

I am retrieving a value that is set by another application from memcached using python-memcached library. But unfortunately this is the value that I am getting:

>>> mc.get("key")
'\x04\x08"\nHello'
Is it possible to ...

17. Obfuscating Strings with ASCII and base 128    stackoverflow.com

Suppose a string is a number system where each thing, it can be a char, DEL or any ASCII thing, has a corresponding number according to this ASCII table. ...

18. Removing Extended Ascii with retention of text    stackoverflow.com

How can a covert an string containing the extended ascii to represent a number raised to a power while retaining the exponent value? For example, if the string is 'm\xb3/h' which ...

19. Python: string.uppercase vs. string.ascii_uppercase    stackoverflow.com

This might be a stupid question but I don't understand what's the difference between string.uppercase and string.ascii_uppercase in the string module. Printing the docstring of both the function prints same thing. ...

20. How do I check if a string is unicode or ascii?    stackoverflow.com

What do I have to do in Python to figure out which encoding?

21. Comparing string in Python: String X is ASCII, and String Y is UTF    stackoverflow.com

I have a rather weird problem: How do I compare strings (using Python ) that where String X is ASCII and String Y is in UTF or Unicode? Currently, when I am comparing ...

22. Converting string to ascii using ord()    stackoverflow.com

I must preface this by saying that I am a neophyte (learning), so please waive the omission of the obvious in deference to a man who has had limited exposure to ...

23. Compress a series of 1s and 0s into the shortest possible ascii string    stackoverflow.com

How could you convert a series of 1s and 0s into the shortest possible form consisting of URL safe ascii characters? eg.

s = '00100101000101111010101'
compress(s)
Resulting in something like: Ysi8aaU And obviously: decompress(compress(s)) == s (I ask this ...

24. Compile Syntax Error: non ASCII letters in a string    stackoverflow.com

I have a python file that contains a long string of HTML. When I compile & run this file/script I get this error:

_SyntaxError: Non-ASCII character '\x92' in file   C:\Users...\GlobalVars.py ...

25. Python - generate derangements of string.ascii_lowercase    stackoverflow.com

I have found some algorithms online to generate derangements in Python but they're all exponential in complexity and as a result I can't get them to converge with a set of ...

26. how to: Twisted privmsg to accept non-ascii strings    stackoverflow.com

I have an IRC bot written in python that uses Twisted. It can print non-ascii strings without a problem with self.msg(channel, str.encode('utf-8'). However, I get exceptions when a non-ascii string is being received ...

27. convert string into ASCII code    stackoverflow.com

I need to convert string into ASCII code. I'm using python. I did as below:

b1=[ord(x) for x in l1[i]]
here l1 is a linelist, l1[i] is the ith line of l1 but I got ...

28. gnu-binutils-strings utf-8 instead of utf-16 or ascii    stackoverflow.com

I've noticed gnu-binutils-strings can printout utf-16 content in a file - is it possible for the program to print out utf-8 strings? if so, which arguments are appropriate? i'm working in ...

29. How to find the ascii values of the characters in string?    stackoverflow.com

I'm trying to convert characters in string into ascii value in Python Like ord('a[i]') but ord expects only character not string!! Is there any other method to solve this problem in python ...

30. Approximately converting unicode string to ascii string in python    stackoverflow.com

don't know wether this is trivial or not, but I'd need to convert an unicode string to ascii string, and I wouldn't like to have all those escape chars around. I ...

31. converting a string from ascii    python-forum.org

32. find, replace and save string in ascii file    python-forum.org

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.