0
votes
2answers
32 views

Replace characters in a string with whitespaces

I am writing a simple Python script that retrieves the latest tweet of any twitter user (in this case BBC) and uses the integrated text-to-speech system on Mac to read out the content of that ...
0
votes
5answers
38 views

Strings with embedded variables in Python

Maybe some already asked this but I didn't find it and I wanted to know how to embed variables into a string in Python. I usually do it like this: print('Hi, my name is %s and my age is %d' %(name, ...
2
votes
3answers
54 views

Best way to find strings between two points

I know this is fairly basic, however I was wondering what the best way to find a string between two referenced points. For example: finding the string between 2 commas: Hello, This is the string I ...
0
votes
1answer
38 views

how to change the string with decimal and hyphen into int

I am grabbing IP addresses from a site and part of the result looks like this. 192.168.1.1\t12345\t12345\t2013-05-14\t2013-05-14\n192.168.1.1\t98765\t98765\t2013-05-14\t2013-05-14 And of course ...
2
votes
3answers
65 views

Python: String will not convert to float

I wrote this program up a few hours ago: while True: print 'What would you like me to double?' line = raw_input('> ') if line == 'done': break else: float(line) ...
1
vote
1answer
58 views

Python 2.7: Faster/better way to extract all integer values from a string? [closed]

I want to be able to extract only integer numbers from a user-defined string that includes integers, floats, and strings. I am currently using the split() and isdigit() methods to yank out all the ...
1
vote
4answers
36 views

Remove extra characters in the string in Python

I have couple of strings (each string is a set of words) which has special characters in them. I know using strip() function, we can remove all occurrences of only one specific character from any ...
4
votes
1answer
67 views

Concatenate elements of a list

I have a list like l=['a', 'b', 'c'] I want a String like 'abc'. So in fact the result is l[0]+l[1]+l[2], which can also be writte as s = '' for i in l: s += i Is there any way to do this more ...
0
votes
2answers
54 views

Searching words from a file in another file

I have got 2 files: access.log.13 : a simple access log from a web server. bots.txt : that contains spider's and crawlers names, each one in a different line, for example: googlebot mj12bot baidu ...
0
votes
1answer
34 views

Given 2 strings find the indexes where one string occurs in another [duplicate]

As the title says, I have 2 strings, something like: string = """ for i in x: for y in z[i]: print y """ s2 = "for" What I want to get is: [1, 17] # positions where "for" starts in ...
0
votes
2answers
44 views

Replacing substrings given a dictionary of strings-to-be-replaced as keys and replacements as values. Python

I have a dictionary with the strings to be replaced as keys and its replacement as values. Other than looking through the strings token by token, is there a better/faster way of doing the replacement? ...
3
votes
2answers
82 views

Finding words around a substring

I have to extract two words before and after my substring match in a large string. For example: sub = 'name' str = '''My name is Avi. Name identifies who you are. It is important to have a name ...
0
votes
4answers
37 views

Removing many types of chars from a Python string

I have some string X and I wish to remove semicolons, periods, commas, colons, etc, all in one go. Is there a way to do this that doesn't require a big chain of .replace(somechar,"") calls?
1
vote
2answers
34 views

python 2.7 to python 3.2 string formatting error

I have this piece of python code: args =(12, 45, 7854) 2 result = 123 3 answer = 456 4 print 'Test with data: ', args, ' result: ', result, ' answer: ', answer Now when I run this with ...
0
votes
2answers
45 views

Bytes to String or String to Bytes?

I have read some of the examples here but I am such a novice I don't understand some of them and others don't seem to work(probably because I'm such a novice but... import urllib.request import re ...

1 2 3 4 5 235
15 30 50 per page