Tagged Questions

0
votes
1answer
32 views

Python regex: replace some chars just before pattern occurrences in a string

I'm having a problem in replacing chars in string using python's 3 regex. I am able to find the pattern occurrences, but I want to replace a char that appears as first in the pattern. Unfortunately ...
4
votes
2answers
86 views

Is it possible to handle an arbitrarily large string in Python? (created via the * operator)

We can build strings of fixed structure but arbitrary length with the * operator, with the following: length = 10 print "0" * length This returns what is expected, 0000000000. The problem arises ...
2
votes
1answer
48 views

How do i check encoding of string and insert a space where it is different? - Python

How do i loop through a string and insert a space whenever i see a difference in encoding? For example, the input: Bar bar black sheep就是其中 famous 的一家club Should yield an output: Bar bar black ...
5
votes
3answers
82 views

Search strings using regular expression in Python

When I try to use regular expression for finding strings in other strings, it does not work as expected. Here is an example: import re message = 'I really like beer, but my favourite beer is German ...
0
votes
1answer
19 views

JSON dump big list containing dict, text, datetime and ints gives “TypeError: 'str' does not support the buffer interface”

Using Python 3.2 64 bit on Windows 7 64 bit. f = open("raw_data/results.json", "wb") json.dump(dictio, f) f.close() Gives error: Traceback (most recent call last): File ...
0
votes
2answers
44 views

Error opening a Word 2007 (Windows 7) file in Python [closed]

With the following line: >>> file = open('C:\Users\mihir\Documents\test.txt') I'm getting this error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position ...
3
votes
1answer
61 views

Flask+Sqlite: Strings that are integers return as type int?

When I store a content with an integer value as a string, when I retrive it it's suddenly an int. So here is what I'm seeing: I store with this db = get_db() hello = ...
0
votes
3answers
35 views

string indices must be integers error in python, but indices are integers

I'm writing a program to add two numbers from a single line of input of the form: number + othernumber I keep getting a "string indices must be integers" error, but when I call type on all the ...
0
votes
3answers
43 views

Unable to retrieve code from webpage, because of query string? [closed]

I'm trying to write a Python script to retrieve the source code from a web page whose content depends on a query string. The specific page is: ...
-1
votes
1answer
54 views

Please explain this algorithm to get all permutations of a String

The following code generates all the permutations for a string: def permutations(word): if len(word)<=1: return [word] #get all permutations of length N-1 ...
0
votes
2answers
73 views

Trying to use output.write with UTF-8 str and get's an error (python 3.x)

I'm using the following code to print (to file) UTF-8 str : output.write(currentWord.m_wordHeb) tried also : output.write(currentWord.m_wordHeb.encode('utf-8') and also added : import sys ...
-1
votes
1answer
36 views

Own pretty print option in python script

I'm outputting pretty huge XML structure to file and I want user to be able to enable/disable pretty print. I'm working with approximately 150MB of data,when I tried xml.etree.ElementTree and build ...
0
votes
1answer
48 views

Error with String Slicing?

I am working on a fairly simple program to convert a given non-coding strand of DNA to all of it's counterparts (coding, mRNA, tRNA, and amino acid chain). I get an IndexError when I try to slice a ...
-3
votes
2answers
62 views

Insert string into string

I have a='Samsung' b='Nokia' I want to insert b to a, finaly the result is 'SNaomksiuang' How to do it in Python with Faster?
0
votes
3answers
47 views

Python 'str' object is not callable Python 2.7.3

I am currently writing a trade game, where users connect to a server, then trade with one another and earn money, etc. But when I try if(input.lower() == 'sell'): sMaterial = ...

1 2 3 4 5 191
15 30 50 per page