"strip" refers to the process of removing (stripping) certain characters from a string. A common example is removing trailing whitespace characters.
Questions tagged [strip]
1330 questions
-2
votes
3 answers
WebDriver should be returning list but it's returning webelement
I have no clue why this is happening. I'm trying to convert what the webdriver returned (a money value of $1.00) to an integer so I can run it through a called function, but I can't split to take away the $ because of this error. Here is my code:
…

code_newb
- 1
- 2
-2
votes
1 answer
How to remove whitespaces in front/end of a string in Android
Assuming I have a String like this one in Android:
" This is an example String "
and i want to make it become:
"This is an example String"
I tried to use the split() but is not found in Android, is there any other method i'm not getting?
Thx

Anon
- 502
- 5
- 19
-2
votes
1 answer
What can I use instead of strip() to remove \n,\t and white spaces?
I am using strip() to avoid white spaces,\n, and \t in my scraper.
It works fine with selenium but sometimes with scrapy I get
'AttributeError':''Nonetype' obeject has no attribute 'strip'

Renuka
- 7
- 5
-2
votes
2 answers
Python changes \n to \\n when reading a text file
I have a text file that contains \n as new line in it.
In Python 3.6, when I load it using the following code:
file = open(file_name, 'r')
contents = file.read()
it changes all \n to \\n. For example:
Original in the txt file:
This is a test \n…

mah65
- 578
- 10
- 20
-2
votes
1 answer
Python iteration, replace(), and strip()
As simple as I can make it:
I have written a python script to extract embed links from an api. I can easily return a list of embed links similar to this:
[, ,…

WBR
- 1
- 1
-2
votes
1 answer
How to properly use rstrip to delete the last occurence of symbol?
if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
while True:
print('[', end="")
for i in range(0,x+1):
for j in range(0,y+1):
for k in range(0,z+1):
…

Gunjeet Jain
- 17
- 5
-2
votes
1 answer
Strip leading and trailing spaces on 851 files in Python
I would like to strip leading and trailing spaces from my 851 files. How can I do this? The first file is made up of 220 lines. The last file is made up of 1315 lines.
I tried:
x = 1
while x < 852:
f = open("final.%d.txt" % x)
lines =…

yellowcab
- 21
- 8
-2
votes
3 answers
Python .rstrip() strips a string even if it doesn't match exactly
print('345nov'.rstrip('nov'))
the code above prints what you would expect: 345
So why does print('345v'.rstrip('nov')) print the same thing. The string doesn't end with "nov". It only ends with "v". But rstrip() strips it all the same. Either way,…

Directory
- 135
- 1
- 2
- 10
-2
votes
1 answer
Which way is faster when stripping part of string in JavaScript
I need to strip part of JWT token and I am courious which one is faster, or less complex internally.
Example input string:
const input =…

Baterka
- 3,075
- 5
- 31
- 60
-2
votes
3 answers
Is there another way besides "strip()" and "replace()" to get rid of the extra white space in the data I scraped?
I am pretty new to python and I am trying to set up a webscraper that gathers data on characters who have died in the show Game of Thrones. I have gotten the data that I want but I can't seem to get some of the extra fluff out of the data.
I have…

vomag
- 9
-2
votes
4 answers
How to split list items newline in to comma in python
I used this
print(listing_jobs)
resulted in this
['Senior Cloud Specialist\nFull-time · Singapore · 5 - 10 Years\n12 days ago', 'Cloud Native Developer\nFull-time · Hyderabad · 2 - 5 Years\n13 days ago']
How can I convert \n to comma?
When I…

jaz
- 91
- 3
- 7
-2
votes
1 answer
"string difference " - how to remove a certain substring from a string obtaining the rest
If you had two strings,
string1 = "Rahul 123 Mumbai Shivani 234 Mumbai Akash 345 Mumbai Rahul 456 Bangalore"
string2 = "Rahul 123 Mumbai"
How do you find out the difference?
As in, the final output should be -
"Shivani 234 Mumbai Akash 345 Mumbai…

user10141156
- 170
- 7
-2
votes
1 answer
Function to return stripped dataframe
I have a dataframe from CSV file:
import pandas as pd
filename = 'mike.csv'
main_df = pd.read_csv(filename)
I need a function that will strip all string columns' (there are also numeric columns) contents from whitespaces and then return such…

barciewicz
- 3,511
- 6
- 32
- 72
-2
votes
1 answer
Remove parantheses inside tuple
I have a list of tuples:
listoftuples = [(('elementone', 'elementtwo'), 'elementthree')(....
Now I want to output this list as:
listoftuples = [('elementone', 'elementtwo', 'elementthree')(....
How can i remove those extra parantheses?
I have…

Joep Groentesoep
- 165
- 2
- 10
-2
votes
2 answers
Why is the strip() function depleting my mustard?
I'm creating a Hot Dog simulator in python, with a class "HotDog".
When I'm formatting the string, if there are 2 condiments, I wrote this code to add it to the string:
if len(self.condiments) == 2:
for i in self.condiments:
msg = msg +…