Tagged Questions
2
votes
4answers
66 views
Python: Comparing two strings that should be the same but that are not
I'm a noob so I hope this is the right place to ask this question. This is really driving me nuts. I'm looking for a sentence in some text file, here is the partial code:
SentenceIMLookingfor='blha ...
-9
votes
1answer
58 views
Find method in strings python [on hold]
Variables s1 and s2 refer to strs. The expression s1.find(s2) returns the index of the first occurrence of s2 in s1.
Write an expression that gives the index of the second occurrence of s2 in s1. If ...
0
votes
1answer
48 views
Find and replace a part of several lines in multiple documents using python?
I'm trying to replace parts of several lines in multiple latex documents using python. This is what I've done:
import fileinput, glob, string, sys, os
from os.path import join
def ...
2
votes
5answers
71 views
How to find a positive or negative value inside a string?
I have a Problem with a little program in Python 3.3, which should return a number from a string.
While it works well for positive values,
text = "XXXXXXX\nDateMinEnd=230\nXXXXXXX\n"
Dmin = ...
1
vote
9answers
83 views
How would I convert a string into a list of tokens in Python?
When I input this:
>>>tokenize('<[2{12.5 6.0}](3 -4 5)>')
I want to get this back:
['<', '[', 2, '{', 12.5, 6.0, '}', ']', '(', 3, -4, 5, ')', '>']
Basically, how would I ...
0
votes
1answer
56 views
What is the elegant way to find a number in a string? [on hold]
I want to get a number from a string, as in font: bold 13 Arial --> 13. What's the most elegant and Pythonic way to do this?
However, I also need the "context" of the number. I want to change it, ...
0
votes
5answers
21 views
Obtaining keyword for matching string in Python
I am writing a script that searches through text files in a directory for certain words. If "True" is returned, then it will print the text file it found it in. Is there a way to return/print the ...
0
votes
1answer
19 views
Accessing the original value of the unicode string when subclassing unicode
Try to get a class which would work like so:
>>> original = u"ABCD-123-foo"
>>> suffix = SuffixComparingUnicodeString("foo")
>>> suffix == original # if original ends ...
-1
votes
4answers
52 views
Matching an input from a string of characters? [on hold]
Suppose I have a string -> (a,b,c,1,2,3)
The user is to pick a character from that string, perhaps b?
PickCharacter=raw_input("Pick a character? ")
User inputs, 'b'
The code recognizes that 'b' ...
1
vote
3answers
61 views
How to change list of str into list of floats
def avg_temp_march(f):
"""(file open for reading) -> float
Return the average temperature for the month of March
over all years in f.
"""
file = open(f, 'r')
...
0
votes
7answers
80 views
Get two strings of text on the same line?
and sorry for the terrible title! I had no idea what to write, without making the tile 500 words long.
Let's say I have
print 'Hi!'
print 'How are you?'
Is there any way I can get this into the ...
1
vote
4answers
61 views
Reversing “group” of strings in Python
How to reverse "groups" (not list) of strings?
For example I would like to convert "123456789" into "321654987" given that the "group" size equals to 3.
Followings are my code but it turns out to ...
1
vote
2answers
32 views
PYTHON several times print from a reference file
I have a question about python programming.
If I have a reference file (ref.txt) like
3
5
6
I want to make a output file like if I want to 5 times these strings
3
5
6
3
5
6
3
5
6
3
5
6
3
5
6
...
0
votes
2answers
55 views
Replace all lines [fromString ,toString] in file
I would like to replace a certain section of text in my text file with a given string. For example, given the following file content:
1
---From here---
2
---To here---
3
I would like to write a ...
2
votes
7answers
83 views
Python: 'str' object is not callable
Log:
Traceback (most recent call last):
File "gen_big_file.py", line 8, in <module>
print str(i)+'% done'
TypeError: 'str' object is not callable
Code:
1
2 f = ...