Hi people, i am in trouble with python quotes, see this:

string = "qwerty"

when i do a print string it returns:


how do i replace this singles quotes to double quotes when the value of the variable is returned? there is a way?

thanks in advance! ;)

Recommended Answers

All 5 Replies




You should post more data of what you want to accomplish if these do not produce what you want.

Why do you need this?
Singel and dobbels quotes dos the same in python.

>>> s = "qwerty"
>>> s
>>> print s
>>> repr(s)

>>> s = 'qwertys'
>>> s
>>> repr(s)
>>> print s

Confused why you need this. If you need to print with double quotes, do it like this print('"%s"'%"qwerty")

P.S. Bad idea to name your variable "string" as it conflicts with the string module (chant help("string") from the Python prompt)

Thanks, i figured out a way to acomplish what i was trying to do.

It was simple, i was trying to write a python list on a text field with sqlite3:

INSERT INTO table values ('qwerty', 'uiop', '[u'ás', u'és']', 'a');

It was not working, the SQL was getting confused about the single quotes in the python lists. Hopefully, i figured that the SQL language, supports double quotes to add a text on a field of the table:

INSERT INTO table values ('qwerty', 'uiop', "[u'ás', u'és']", 'a');

This worked. =)

thanks for all your help

Hold on for a moment, though; just how are you adding the list to the SQL statement, and how are you vetting the data, if at all? Generally speaking, any data added to a SQL query programatically should be done using a parameterized query:

cursor.executemany("INSERT INTO table values ('?', '?', \"?\", '?');", 'querty', 'uiop', "[u'ás', u'és']", 'a')

The way you describe it, it sounds like you were concatenating the strings together directly, which (unless the data is checked out ahead of time) could leave you open to a SQL injection attack.

commented: Very good point +11
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.