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 ... |
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') ... |
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 ... |
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, ... |
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 ... |
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):
...
|
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 ... |
|
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 ...
|
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 ... |
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 ... |
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 ... |
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 = ...
|
>>> 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 ... |
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.
|
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 ... |
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 ... |
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?
|
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 ... |
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 ... |
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. ... |
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 ... |
|
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 ... |
#!/usr/bin/python # Filename: login.py def authorizeUser(): inputUsername = str(raw_input("Username : ")) user = "user" if inputUsername == user: print "Logged in" else: ... |