0
votes
1answer
31 views

how to set spaces in strings

I am trying to have the program check the user input for "get up" or "rise and shine" then have it print "im up". The problem is it won't print "im up" it goes straight to the else statement. This ...
2
votes
4answers
52 views

Find specific string sections in python

I want to be able to grab sections of strings with a function. Here is an example: def get_sec(s1,s2,first='{',last='}'): start = s2.index(first) end = -(len(s2) - s2.index(last)) + 1 a = ...
1
vote
4answers
42 views

How can I print variable and string on same line in Python?

I am using python to work out how many children would be born in 5 years if a child was born every 7 seconds. The problem is on my last line. How do I get a variable to work when I'm printing text ...
0
votes
3answers
28 views

Check for a string in the user inout

I have this code but what it does is when someone types "goodmorning" or "morning" it prints "good morning" but if i were to type "hello goodmorning" it will not print good morning it will print test. ...
1
vote
4answers
43 views

Python: Enumerate a list of string 'keys' into ints

I searched for a while but didn't find anything that explained exactly what I'm trying to do. Basically I have a list of string "labels", e.g. ["brown", "black", "blue", "brown", "brown", "black"] ...
1
vote
4answers
71 views

Python 2.7 and 3.3.2, why int('0.0') does not work?

As the title says, in Python (I tried in 2.7 and 3.3.2), why int('0.0') does not work? It gives this error: ValueError: invalid literal for int() with base 10: '0.0' If you try int('0') or ...
1
vote
1answer
38 views

Python 3 replacement of string regex

I am working with a html script converted into a string How do I replace all the html code in tags with blank using regex?
3
votes
7answers
112 views

How to parse a string and return a nested array?

I want a Python function that takes a string, and returns an array, where each item in the array is either a character, or another array of this kind. Nested arrays are marked in the input string by ...
0
votes
2answers
13 views

Pyodbc query string quote escaping

I'm trying to execute a query using pyodbc with this kind of code cursor.execute("SELECT x from y where Name='%s'"%namepar) The parameter may have a quote and so it needs to be escaped in order to ...
0
votes
4answers
24 views

coverting string-like object into string python

I am using python and XMLBuilder, a module I downloaded off the internet (pypi). and in the end it returns an object, that works like a string (I can do print(x)) but when I use file.write(x) it ...
1
vote
6answers
122 views

how to convert string like “5cm” into an integer

I have an input list like [2,3,4,"5cm", 6,"2.5km"] and I would like to have a result: [2,3,4,5,6,2.5] I would like to start in this way for element in inputList:
0
votes
2answers
52 views

Python splitting unknown string by spaces and parentheses

If I have a string that may be: 'Hello (Test1 test2) (Hello1 hello2) other_stuff' I would like to split it into something like this: split1='hello' split2='Test1, test2' split3='Hello1, hello2' ...
2
votes
4answers
60 views

Python string comparison whilst in loop

I am both new to this forum & programming & Python. I am trying to develop my first program, however I keep coming up against a brick wall regarding one particular issue. I am hopng that some ...
0
votes
3answers
51 views

replace() string in python

I want to remove ">>> " and "... " form the doc using replace() but its not working for me (it prints the same doc). Check the last three lines of code. doc = """ >>> from sets import ...
2
votes
2answers
38 views

Trying to parse a string to two seperate strings based on case

I'm currently working on a python bot which retrieves information from a meta block on an HTML page. I get the content of the meta block, and now I am stuck on trying to parse it to two different ...
1
vote
1answer
33 views

plot x-y plot of words which match across two lists (string version of plt.scatter)

I don't really know how to start with this at all. I have two lists of strings: ['a','b','c','d'] ['a','c','g','e','f'] I would like to make a plot (using imshow perhaps) of the two lists of words, ...
1
vote
2answers
37 views

find string of arbitrary length before a known string

Just say I have a string such as: Lecture/NNP/B-NP/O delivered/VBD/B-VP/O at/IN/B-PP/B-PNP the/DT/B-NP/I-PNP UNESCO/NNP/I-NP/I-PNP House/NNP/I-NP/I-PNP in/IN/B-PP/B-PNP Paris/NNP-LOC/B-NP/I-PNP I ...
1
vote
1answer
35 views

Python Pandas: String Method to str

I think I have a relatively simply question but am not able to locate an appropriate answer to solve the coding problem. I have a pandas column of string: df1['tweet'].head(1) 0 ...
2
votes
4answers
84 views

How to get the first N sentences from text?

I need to get the first N sentences from a text where the last char of the sentence can be a period, a colon, or a semicolon. For example, given this text: Lorem ipsum, dolor sit amet. consectetur ...
0
votes
2answers
24 views

Python 3 - Getting some strings from a HTTPrequest response

I'm having a hard time extracting data from a httprequest response. Can somebody help me? Here's a part of my code: import requests r = requests.get('https://www.example.com', verify=True) keyword ...
1
vote
2answers
45 views

How can I deformat string with prices in python?

I got db where one of the field in record in table contain prices in form of string. String itself is not a big deal - but price is totally unformatted: $12,000.50 $3.50 From $3.50 to $12,000.50 ...
4
votes
2answers
39 views

Python add leading zeroes using str.format [duplicate]

Can you display an integer value with leading zeroes using the str.format function? Example input: "{0:some_format_specifying_width_3}".format(1) "{0:some_format_specifying_width_3}".format(10) ...
0
votes
1answer
29 views

Alter beautifulSoup code to extract words

here is some code I found online that will get prices (i.e. decimals) from websites. I need to alter this code so it doesn't return a decimal, but a string. from bs4 import BeautifulSoup import ...
0
votes
3answers
68 views

substrings from a string in python [closed]

I have this string str = ...
3
votes
2answers
119 views

Capitalize first letter in string if first character is not letter? [duplicate]

I'd like to capitalize the first letter in a string. The string will be a hash (and therefore mostly numbers), so string.title() won't work, because a string like 85033ba6c would be changed to ...
0
votes
2answers
57 views

Assert string only contains letters

I have seen methods like isAlpha(), but it accepts spaces and punctuations, which I don't want. Any way to check that a string contains only big or upper case alphabet letters? E.g. psudo: ...
0
votes
0answers
70 views

Accessing elements in unicode string [closed]

I have a simple list like: var = [u'test'] If I try, print var[0] I get nothing (on Pyscripter), but I get the string test in Python interpreter. What am I doing wrong?
1
vote
3answers
45 views

Python parse words from URL string

I have a large data set of urls and I need a way to parse words from the urls eg: realestatesales.com -> {"real","estate","sales"} I would prefer to do it in python. This seems like it should ...
2
votes
5answers
90 views

how to find the index of the first non-whitespace character in a string in python?

Scenario: >>> a=' Hello world' index = 3 In this case the "H" index is '3'. But I need a more general method such that for any string variable 'a' takes I need to know the index of the ...
2
votes
2answers
67 views

Python to C++ Character encoding

I have a C++ program that uses the Python C/API to call Python scripts for DB info, but the data received is not encoded in the right way. This is in France, so my data has accents and other ...

1 2 3 4 5 124
15 30 50 per page