0
votes
1answer
34 views

Python string “b” prefix (byte literals)

I am looking through some unit testing code and I found this: self.assertIn(b'Hello', res.body) I know that this means bytes in python 3 which returns a byte array, as i found here. I believe that ...
0
votes
5answers
60 views

I want to cut variable on another variables using Python

I have a variable c. c = ' FR,DE,UK,IT ' I want to cut this variable on another variables: c1, c2, c3, c4 So that c1 = 'FR', c2 = 'DE', c3 = 'UK', c4 = 'IT'. How do I do that?
0
votes
2answers
23 views

I want to isolate the IP and the port from a string in a python script

I have a script which will read in information, and process it. I have the script so that it reads in the information. For example: RawInfo[0] = "192.168.100.254:8081" I want to be able to ...
0
votes
3answers
37 views

Append a list of strings to a file in a single line? - Python

Is there a way to append a list of lines to a file in a line of python code? I've been doing it as such: lines = ['this is the foo bar line to append','this is the second line', 'whatever third ...
-8
votes
2answers
57 views

Explain the difference please? [duplicate]

Could someone please explain the difference between these two? data=[] for row in csv_file_object: data.append(row[1:]) and data=[] for row in csv_file_object: data.append(row)
-1
votes
3answers
68 views

How to reduce the duplicated characters in a string using Python

Is there a way to reduce a duplicated characters to specific number, for example if we have this string. "I liiiiked it, thaaaaaaank you" Expected output: "I liiiiked it thaaaank you" so if the ...
5
votes
2answers
68 views

Join string before, between, and after

Suppose I have this list: lis = ['a','b','c','d'] If I do 'x'.join(lis) the result is: 'axbxcxd' What would be a clean, simple way to get this output? 'xaxbxcxdx' I could write a helper ...
0
votes
2answers
34 views

Extract email sub-strings from large document

I have a very large .txt file with hundreds of thousands of email addresses scattered throughout. They all take the format: ...<[email protected]>... What is the best way to have Python to ...
0
votes
1answer
26 views

Referencing a RegEx Variable

I'm using python to loop through a large list of self reported locations to try to match them to their home states. The RegEx expression I'm using is: /^"[^\s]+,\s*([a-zA-Z]{2})"$/ Basically, I'm ...
1
vote
2answers
21 views

How to figure out what the current system preferred language is

Is there an easy way to get the preferred language on a system? I am writing an application that has to support different language, but needs to pick what language to display based on the system ...
3
votes
3answers
41 views

Python : UTF-8 : How to count number of words in UTF-8 string?

I need to count number of words in UTF-8 string. ie I need to write a python function which takes "एक बार,एक कौआ, बहुत प्यासा, था" as input and returns 7 ( number of words ). I tried regular ...
1
vote
1answer
18 views

How to deal with link text or link image with string from BeautifulSoup in python?

I've some tds which include link text or link image like below. And when I get the td text by BeautifulSoup . The text is shown here: How can I make the strings like "u'Language pack English" and ...
2
votes
3answers
84 views

Remove \n or \t from a given string

How can I strip a string with all \n and \t in python other than using strip()? I want to format a string like "abc \n \t \t\t \t \nefg" to "abcefg"? result = re.match("\n\t ", "abc \n\t efg") ...
0
votes
1answer
37 views

Python-Regex-Distinguish and use repeated pattern in a string

Edit: so I came to realize, with the kind help from answers below, that parsing html with regex is generally a bad idea. For what it's worth, if someone else comes across my post someday with the same ...
2
votes
1answer
26 views

Python: Get common characters from strings

So, a newbious question: I'm looking for the smallest (and nicest) way of comparing two strings and being able to get back, as separate strings: All the common characters, The uncommon characters, ...

1 2 3 4 5 259
15 30 50 per page