Literal « 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 » Literal 

1. Tricky Python string literals in passing parameter to timeit.Timer() function    stackoverflow.com

I'm having a hard time with the setup statement in Python's timeit.Timer(stmt, setup_stmt). I appreciate any help to get me out of this tricky problem: So my sniplet looks like this:

def compare(string1, ...

2. Why doesn't PyRun_String evaluate bool literals?    stackoverflow.com

I need to evaluate a Python expression from C++. This code seems to work:

PyObject * dict = PyDict_New();
PyObject * val = PyRun_String(expression, Py_eval_input, dict, 0);
Py_DECREF(dict);
Unfortunately, it fails horribly if expression is ...

3. comparing two strings with 'is' -- not performing as expected    stackoverflow.com

I'm attempting to compare two strings with is. One string is returned by a function, and the other is just declared in the comparison. is tests for object identity, but according ...

4. What's the u prefix in a python string    stackoverflow.com

Like in:

u'Hello' 
My guess is that it indicates "unicode", is it correct? If so, since when is it available?

5. Why allow concatenation of string literals?    stackoverflow.com

I was recently bitten by a subtle bug.

char ** int2str = {
   "zero", // 0
   "one",  // 1
   "two"   // 2
  ...

6. Bash equivalent to Python's string literal for utf string conversion    stackoverflow.com

I'm writing a bash script that needs to parse html that includes special characters such as @!'ó. Currently I have the entire script running and it ignores or trips on these ...

7. python: SyntaxError: EOL while scanning string literal    stackoverflow.com

i am saying

s1="some very long string............"
and it gives me the above mentioned error anyone konw what i am doing wrong?

8. inverted comma and string in python    stackoverflow.com

I'm kinda' new to python, but I have already written many programs including some like download-managers, games and text-editors which require a lot of string manipulation.
For representing a string literal I ...

9. Get warning for python string literals not prefixed with 'u'    stackoverflow.com

To follow best practices for Unicode in python, you should prefix all string literals of characters with 'u'. Is there any tool available (preferably PyDev compatible) that warns if ...

10. EOF while scanning triple-quoted string literal    stackoverflow.com

i've looked on the web and here but i didn't find an answer : here is my code

zlib.decompress("""
x???=??H?s~??ç\?îà
Z@ÑÁÔQÇlxÇÆïPP~ýVãì?M6ÛÐ|ê????=)}éÓUe?ö3??ú"}?ïÿ÷1þ8ñ?U÷?ñíLÒVi:`??L!Ê?p6-%Fë^?÷à,Q.K!?ô`ÄA!ÑêweÌ ÊÚA?YøøÂjôó?Âcñ?f?ù?úN :nüzAÝ7%?cdU??3ôP??l?yH??$/yz?íà?'ÕÓ&`|S!<'?÷Z??2??;?(ÅÛfb!úü$???,9ßhàP????ÑbØ??Q?-Ü}(n;??L?\^ï9???Dd?éÞ|åPOG?ÐÙ%â&AÔë)ÎTÐC ?ïc?í%Èï!??ëiq*?VKÐN?[?fOq{O?ÆÊ,0G??mt??O??$#î?qbY??U??ÞáP`
?×?ÃPwa??â×)?FcêÚ=!Åö?
)AFñ?/cM?!NóN?ór?pàÜòXw
Bvæ0ïçIÉo?>5p?-ØWÚN?ùF?ØPçÃþd?;?1[O??~6????ì??=øð@?V??)÷%?Üib{H?K?VlDC?îfÑWì÷ìáár.?îv?<d?n~ú*ÁÕ7ýá}EsY?W?È:R×ãQ???Ø1v?ä?~èR1?Ü*?ónA?jmNo???Ì??f[8?Û>?OW?|ÌbD?Ö?M=Ð÷èâ??'ÂÝÐ ;ë m?QÂä??:??d??L?1?_÷YZ?NòÛ â\?xÐl????øm5Ëá=ïoÍlM?[×#Yp??x[ÉÊyæ?o??z)??ÝÏìò
""")
so it was a string that i got ...

11. using Python to generate a C string literal of JSON    stackoverflow.com

I have a dictionary in Python that I would like to serialize in JSON and convert to a proper C string so that it contains a valid JSON string that corresponds ...

12. How to write string literals in python without having to escape them?    stackoverflow.com

Is there a way to declare a string variable in python such that everything inside of it is automatically escaped, or has its literal character value? I'm not asking how to ...

13. Python 3, Are there any known security holes in ast.literal_eval(node_or_string)?    stackoverflow.com

Are there any known ways for ast.literal_eval(node_or_string)'s evaluation to not actually be safe? If yes, are patches available for them? (I already know about PyPy[sandbox], which is presumably more secure, but ...

14. Force str() and the two string literals to create a custom string?    stackoverflow.com

I have a subclass of the 'str' object and I need to apply it to the application domain. Since the application is full of string literal and str() casts it will ...

15. how to properly pass literal strings python code to be excuted using python -c    stackoverflow.com

I need some help figuring out how to execute this python code from python -c I am have trouble formatting python so that it will execute for another app in cmd I understand ...

16. What does the 'b' character do in front of a string literal?    stackoverflow.com

Apparently, the following is valid syntax...

my_string = b'The string'
I would like to know...
  1. What does this b character infront of the string mean?
  2. What are the effects of using it?
  3. What are appropriate situations ...

17. Any yaml libraries in Python that support dumping of long strings as block literals or folded blocks?    stackoverflow.com

I'd like to be able to dump a dictionary containing long strings that I'd like to have in the block style for readability. For example:

foo: |
  this is a
  ...

18. Python AJAX response string literal    stackoverflow.com

I have an AJAX response that returns a JSON object. One of the dictionary values is supposed to read: "image\/jpeg" But instead in reads: "images\\/jpeg" I've gone through the documentation on string literals and how ...

19. Pyschool Quiz--String Concatenation    stackoverflow.com

Here's the quiz question:

Adding two strings or making multiple copies of the same string. Examples: greetings = "Hello World" len(greetings) ...

20. convert string literal to object attribute    bytes.com

def getAttributeForProperty(self,rollnumber,attribute) : # attribute have the value _ward ''' If year is null then use current year. Returns the value of the attribute for the given roll number ''' print 'Searching for attribute', attribute for index, i in enumerate(self._aa): if (rollnumber == i._roll_number) and ( hasattr(i,attribute) ) : print index,i.attribute (COMPILER ERROR HERE) return i.attribute return print "\n" return i ...

21. Concatenation of string literals    python-forum.org

redwraith wrote:Just to be sure: "foo" + "bar" is slower than "foo" "bar" because with "foo" + "bar" the result "foobar" is calculated at run time and with "foo" "bar" the result is calculated at compile time. Is this correct? I can't answer your question simply, because I do not know. I do know that Python is not a compiled language. ...

23. Error "EOL while scanning string literal"    python-forum.org

" " " Cheese Shop cheeseShop.py demonstrate comments raw input, and string variables from Game Programming - L-line 11/29/09 " " " #tell the user something print "welcome to the cheese shop!"

24. [SOLVED]"EOL while scanning string literal"    python-forum.org

25. weird error "EOF while scanning triple-quoted string literal    python-forum.org

I'm working on a fun little text-based game, where the user manages an off-world colony. All was running well until I made the user's rank subject to change, and now when I run it I get this error: "EOF while scanning triple-quoted string literal" and I am then prompted to click the "ok" button and return to my code. Code: Select ...

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.