string

Read b-string from file

Read b-string from file Question: I have a txt file that contains lines like b’111rn222rn333′. When I read the file with with open(‘raw2.txt’, ‘r’) as f: nums = f.read().splitlines() then the b-rows are turned into regular strings. "b’111\r\n222\r\n333’" If I read as ‘rb’, these lines become binary b"b’111\r\n222\r\n333’" How do I read the file correctly …

Total answers: 1

Reading strings with special characters in Python

Reading strings with special characters in Python Question: I have a string with special characters as follows req_str = ‘Nx08NAx08AMx08ME’ ## If I print it I correctly get the word "NAME" print(req_str) >>> print(req_str) NAME Now I want to extract the string NAME from the string. I tried ”.join(c for c in ‘Nx08NAx08AMx08ME’ if c.isprintable()) …

Total answers: 1

How can I use startswith without specifying a certain string? Is there any alternative?

How can I use startswith without specifying a certain string? Is there any alternative? Question: I would like to apply vocal_start to so many different variables and i can’t handle them all and i wouldn’t always repeat startswith. So I don’t want to write variable1.startswith(("a", "e", "i", "o", "u")), but i would like to apply …

Total answers: 6

How to use variable volume control for mac via python?

How to use variable volume control for mac via python? Question: I found this code in python to control mac volume: osascript.osascript("set volume output volume 35") I want to use a variable to control this volume instead like: volumes = [35, 35, 30, 35, 45, 45, 45, 45, 45, 40, 45, 45, 45, 45, 55, …

Total answers: 2

Convert lines of values in text file to a CSV

Convert lines of values in text file to a CSV Question: Here is my data from a text file: foo no 3.61 9.51 bar -26 67 2.35 0.50 70 baz dxo 6 2.37 quez -9.07 51 udx 9.66 9.66 scz -8 pdu hk 0.50 -5.34 -13 0.50 ytrs bl 1.27 -63 -0.66 xle 29 1.27 …

Total answers: 2

Finding maximum difference between each string in an list

Finding maximum difference between each string in an list Question: This was an interview question given to me: Given a list of n strings with length l which at any given index can contain either the character ‘a’ or ‘b’, how would I go about figuring out the maximum difference (meaning the amount of characters …

Total answers: 3

Amend string / URL and iterate through list

Amend string / URL and iterate through list Question: I’m looking to scrape a certain table where the link is amendable with a certain year and week. URL = https://www.debestseller60.nl/200511#top I have two lists; one having years ranging between 2005 and now and one having all the week numbers in a year. years = list(range(2005, …

Total answers: 2

In Python how to convert a string with special characters to a tuple

In Python how to convert a string with special characters to a tuple Question: would really appreciate any help on this one! I have a string: "<Cell ‘test’.B45>" I need to convert this to a tuple with only one object in it, so that looks like this: ((<Cell ‘test’.B45>)) So to do this I have …

Total answers: 1

Removing brackets at dataframe or list [Python]

Removing brackets at dataframe or list [Python] Question: I’m tryin to remove bracket and split a part of a string that duplicated in column 0 when I create a new DF or list with this two columns from a csv: indice Password Status Priority Arrive time Call time Begin End Standby Time %TME TME time_raw …

Total answers: 1

How do i write a string letter by letter using concatenation in python

How do i write a string letter by letter using concatenation in python Question: I currently have a way to write a string letter by letter but when i try and include more arguments it gives me the error that it was expecting 1 and not 3 I used this to define def delay_print(s): for …

Total answers: 2