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

1. Reading "raw" Unicode-strings in Python    stackoverflow.com

I am quite new to Python so my question might be silly, but even though reading through a lot of threads I didn't find an answer to my question. I have a ...

2. How to treat a returned/stored string like a raw string in Python?    stackoverflow.com

I am trying to .split() a hex string i.e. '\xff\x00' to get a list i.e. ['ff', '00'] This works if I split on a raw string literal i.e. r'\xff\x00' using .split('\\x') ...

3. get `object.__doc__` as raw string    stackoverflow.com

Is there a way to get object.__doc__ as a raw string, apart from adding an 'r' in-front of the doctring itself in the source code? I have latex code inside and the ...

4. how to access sys.argv (or any string variable) in raw mode?    stackoverflow.com

I'm having difficulties parsing filepaths sent as arguments: If I type:

os.path.normpath('D:\Data2\090925')
I get
'D:\\Data2\x0090925'
Obviously the \0 in the folder name is upsetting the formatting. I can correct it with the following:
os.path.normpath(r'D:\Data2\090925')
which gives
'D:\\Data2\\090925'
My problem is, ...

5. What exactly do "u" and "r"string flags in Python, and what are raw string litterals?    stackoverflow.com

While asking this question, I realized I didn't know much about raw strings. For somebody claiming to be a django trainer, this suck. I know what an encoding is, and I ...

6. casting raw strings python    stackoverflow.com

in python, given a variable which holds a string is there a quick way to cast that into another raw string variable? the following code should illustrate what im after...

def checkEqual(x, y):
 ...

7. Python get raw_input but manually decide when string is done    stackoverflow.com

I want someone to type words in the console, and autocomplete from a list when they hit "tab" key. However, raw_input won't return a string until someone hits [Enter]. How do ...

8. How can you print a string using raw_unicode_escape encoding in python 3?    stackoverflow.com

The following code with fail in Python 3.x with TypeError: must be str, not bytes because now encode() returns bytes and print() expects only str.

#!/usr/bin/python
from __future__ import print_function
str2 = "some unicode ...

9. Apply raw string to function return value    stackoverflow.com

I'm not sure if I've phrased it correctly, but hopefully the example will clear it up:

re.search(fileMask.replace('*','.*?'),fileName):
For the first parameter in the re.search() call, how can I ensure that I will pass ...

10. Python raw literal string    stackoverflow.com

str = r'c:\path\to\folder\'   # my comment
IDE: Eclipse, Python2.6 When the last character in the string is backslash, it seems will escape the last single quote and treat my comment as ...

11. Python input string error (don't want to use raw_input)    stackoverflow.com

I have a menu that asks for the user to pick one of the options. Since this menu is from 1 to 10, I'm using input besides raw_input. My code as an ...

12. Python Raw Strings    stackoverflow.com

I have the string U, it's contents are variable. I'd like to make it a raw string. How do I go about this? Something similar to the r'' method.

U = ...

13. How to include a quote in a raw Python string?    stackoverflow.com

>>> r"what"ever"
SyntaxError: invalid syntax
>>> r"what\"ever"
'what\\"ever'
So how do we get the quote but not the slash? And please don't suggest r'what"ever' because then the question just becomes how do we include both types ...

14. What Python Module extracts certain chars from raw input?    stackoverflow.com

What Python module can I use to extract certain chars from raw input? Example: user types in "1J1J"... I want Python to extract both the "J"s.

15. Strange vanishing of CR in strings coming from a copy of a file's content passed to raw_input()    stackoverflow.com

Trying to clear up the reasons of what seemed to be a bug, I finally bumped into a weird behaviour of the raw_input() function in Python 2.7: it removes the CR ...

16. How to set a default string for raw_input?    stackoverflow.com

I'm using raw_input to read from stdin. I want to let the user change a given default string. Code:

i = raw_input("Please enter name:")
Console:
Please enter name: Jack
The user should be presented with "Jack" but ...

17. python replace backslashes to slashes    stackoverflow.com

How can I escape backslashe in string: 'pictures\12761_1.jpg'? I know about raw string. But how can I convert str to raw if I take 'pictures\12761_1.jpg' value from xml file for example?

18. How to decode unicode raw literals to readable string?    stackoverflow.com

If I assign unicode raw literals to a variable, I can read its value:

>>> s =  u'\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e'
>>> s
u'\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e'
>>> print s
????????? ??????????
But when I have already assigned value to ...

19. Loading document as raw string in yaml with PyYAML    stackoverflow.com

I want to parse yaml documents like the following

meta-info-1: val1
meta-info-2: val2

---

Plain text/markdown content!
jhaha
If I load_all this with PyYAML, I get the following
>>> list(yaml.load_all(open('index.yml')))
[{'meta-info-1': 'val1', 'meta-info-2': 'val2'}, 'Plain text/markdown content! jhaha']
What I ...

20. python : how to convert string literal to raw string literal?    stackoverflow.com

I read in a string from a GUI textbox entered by the user and process it through pandoc. The string contains latex directives for math which have backslash characters. ...

21. python raw string assignment    stackoverflow.com

Given a file contains lines such as:

(?i:\bsys\.user_catalog\b)
While reading those line, I want the value to be a raw string (unescaped), meaning, in memory, line should be
r'(?i:\bsys\.user_catalog\b)'
instead of
(?i:\bsys\.user_catalog\b)
Which is escaped ...

23. Validating raw input string length    python-forum.org

import re name = raw_input("Enter Candidate's name : ") while len(name) < 3: name = raw_input("name must be at least 3 letters\nEnter Candidate's name :") regNo = raw_input("Enter registration number : ") keyword = re.compile(r"^[a-z|A-Z]\d\d\d\d\d\d\d\d$") while len(regNo) != 9 or not keyword.search(regNo): regNo = raw_input("RegNo ...

24. comparing raw_input and string, what's the problem?    python-forum.org

#!/usr/bin/python # Filename: login.py def authorizeUser(): inputUsername = str(raw_input("Username : ")) user = "user" if inputUsername == user: print "Logged in" else: ...

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.