quotes

Remove quotes from a list of tuples in python

Remove quotes from a list of tuples in python Question: Hoping someone can help me to figure out how to exclude quotes from a list of tuples and display it in the final output. I’ve tried regex a nd f-string format but nothing seem to work 🙁 lts = [(‘A’, 1), (‘B’, 14), (‘C’, 12), …

Total answers: 2

Python replace "0" with 0 in string

Python replace "0" with 0 in string Question: This should be very simple, but I’m quite lost. I have an string like this: mystring='["variable1": 23.5, 24, 32.1, "0"; "variable2": "0", 34.4, 983.2, "0"; "variable3": …’ I wanted to replace all the "0" by 0, without quotes. So the result would be: mystring='["variable1": 23.5, 24, 32.1, …

Total answers: 2

f-string: unmatched '(' in line with function call

f-string: unmatched '(' in line with function call Question: I’m trying to use f-strings in python to substitute some variables into a string that I’m printing, and I’m getting a syntax error. Here’s my code: print(f"{index+1}. {value[-1].replace("[Gmail]/", ”)}") I only started having the problem after I added the replace. I’ve checked plenty of times and …

Total answers: 4

Why doesn't Python give any error when quotes around a string do not match?

Why doesn't Python give any error when quotes around a string do not match? Question: I’ve started learning Python recently and I don’t understand why Python behaves like this: >>> “OK” ‘OK’ >>> “””OK””” ‘OK’ >>> “not Ok’ File “<stdin>”, line 1 “not Ok’ ^ SyntaxError: EOL while scanning string literal >>> “not OK””” ‘not …

Total answers: 4

Pandas – Is it possible to read_csv with no quotechar?

Pandas – Is it possible to read_csv with no quotechar? Question: I am trying to read a csv file that has single instances of ” in certain lines, ex: car,”plane,jet jet,ski,”hat When I use pandas read_csv to read this file, it recognizes ” as a quote character and does not correctly read in lines such …

Total answers: 2

When to use triple single quotes instead of triple double quotes

When to use triple single quotes instead of triple double quotes Question: Learn Python the hard way, exercise 10.2: tabby_cat = “tI’m tabbed in.” persian_cat = “I’m splitnon a line.” backslash_cat = “I’m \ a \ cat.” fat_cat = “”” I’ll do a list: t* Cat food t* Fishies t* Catnipnt* Grass “”” print tabby_cat …

Total answers: 2

Difference between using ' and "?

Difference between using ' and "? Question: Possible Duplicates: Difference between the use of double quote and quotes in python Single quotes vs. double quotes in Python So I am now learning python, and was creating a function. What is the difference between using ‘ and “. I will create a sample function below to …

Total answers: 3

python equivalent to perl's qw()

python equivalent to perl's qw() Question: I do this a lot in Perl: printf “%8s %8s %8sn”, qw(date price ret); However, the best I can come up with in Python is print ‘%8s %8s %8s’ % (tuple(“date price ret”.split())) I’m just wondering if there is a more elegant way of doing it? I’m fine if …

Total answers: 3

Python "string_escape" vs "unicode_escape"

Python "string_escape" vs "unicode_escape" Question: According to the docs, the builtin string encoding string_escape: Produce[s] a string that is suitable as string literal in Python source code …while the unicode_escape: Produce[s] a string that is suitable as Unicode literal in Python source code So, they should have roughly the same behaviour. BUT, they appear to …

Total answers: 2

How to remove extra indentation of Python triple quoted multi-line strings?

How to remove extra indentation of Python triple quoted multi-line strings? Question: I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, …

Total answers: 10