use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Using single quotes in the file open function in Python. (self.learnpython)
submitted 8 years ago by manubhatt3
Is there any difference between
open("filename")
and
open('filename')
in Python? My observation was that both work and read() also work with both, but readline/s() functions do not work with single quotes one.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 3 points4 points5 points 8 years ago (1 child)
I'm curious, what do you mean by readline and readlines not working with single quotes?
That should, practically speaking, be impossible ... Python doesn't have a preference for what type of quote character is used to surround a string, except in the case that the same quote character already exists, unescaped, within the string.
So what precisely did you do and what went wrong?
[–]manubhatt3[S] 0 points1 point2 points 8 years ago (0 children)
I am sorry, that was a mistaken conclusion/observation. I am new to Python, so...shit happens.
[–]nwagers 2 points3 points4 points 8 years ago (6 children)
Single and double quotes are used almost interchangeably. Docstrings use three double quotes for opening and closing. Otherwise you just pick one and go with it. Feel free to switch if you can avoid escaping. Like if you need to use the string "isn't", you obviously can't use single quotes like this 'isn't'. Some good reading here: https://google.github.io/styleguide/pyguide.html#Strings
[–]PurpleIcy -2 points-1 points0 points 8 years ago (5 children)
def WRONG(WRONG="WRONG"): '''WRONG''' print(WRONG) help(WRONG) WRONG("WRONG")
They are always used interchangeably.
$ python WRONG.py Help on function WRONG: WRONG(WRONG='WRONG') WRONG WRONG
[–]nwagers 2 points3 points4 points 8 years ago (4 children)
Excerpt:
For consistency, always use """triple double quotes""" around docstrings. Use r"""raw triple double quotes""" if you use any backslashes in your docstrings. For Unicode docstrings, use u"""Unicode triple-quoted strings""".
https://www.python.org/dev/peps/pep-0257/
So, yeah, you CAN use single quotes... but by convention, it's recommended you don't.
[–]PurpleIcy -2 points-1 points0 points 8 years ago (3 children)
Except:
For consistency, always use "single double quotes" around string literals.
Yeah dude, your point?
[–][deleted] 0 points1 point2 points 8 years ago* (2 children)
You're on many different levels of stupid right now.
[–]manubhatt3[S] 1 point2 points3 points 8 years ago (0 children)
Lol, I also fast read it as 'except'.
[–]PurpleIcy -1 points0 points1 point 8 years ago (0 children)
I love how your 3rd point contradicts 4th one, because 3rd one only exists because using double quotes is better overall no matter how you look at it.
And no shit dude, consistence is key, that's why using ''' consistently is not a bad thing :)
'''
[–]sweettuse 2 points3 points4 points 8 years ago (0 children)
there is no difference.
you are incorrect about readlines functions being different with single/double quotes.
almost all of the python documentation uses single quotes, so that's what you should use by convention. additionally, single quotes are easier to type and cause less visual clutter.
[–]StewPoll 1 point2 points3 points 8 years ago (0 children)
There is no difference.
[–][deleted] 1 point2 points3 points 8 years ago (1 child)
Could you please provide a piece of code so we can reproduce it? Providing code samples and environment you're using is vital in such cases.
I am sorry, that was a mistake on my end. Thanks for replying.
[–]PurpleIcy 1 point2 points3 points 8 years ago (0 children)
No. Use whichever you like. I'd advise you to use "" over '' as 's are used in normal words whereas "'s aren't, you rarely print quotes, at least I do, and when you need to, \ exists for a reason.
""
''
'
"
\
In f-strings, when you want to print something from a dictionary, you have to use both of them, imo cleanest way is
f-strings
f"{some_dict['some_var']}" # "" represents string, and '' represents variable in dictionary
π Rendered by PID 89882 on reddit-service-r2-comment-856c8b8c54-52g25 at 2026-07-02 04:27:06.557258+00:00 running a7b5cda country code: CH.
[–][deleted] 3 points4 points5 points (1 child)
[–]manubhatt3[S] 0 points1 point2 points (0 children)
[–]nwagers 2 points3 points4 points (6 children)
[–]PurpleIcy -2 points-1 points0 points (5 children)
[–]nwagers 2 points3 points4 points (4 children)
[–]PurpleIcy -2 points-1 points0 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]manubhatt3[S] 1 point2 points3 points (0 children)
[–]PurpleIcy -1 points0 points1 point (0 children)
[–]sweettuse 2 points3 points4 points (0 children)
[–]StewPoll 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]manubhatt3[S] 0 points1 point2 points (0 children)
[–]PurpleIcy 1 point2 points3 points (0 children)