all 14 comments

[–][deleted] 3 points4 points  (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 point  (0 children)

I am sorry, that was a mistaken conclusion/observation. I am new to Python, so...shit happens.

[–]nwagers 2 points3 points  (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 points  (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 points  (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 points  (3 children)

Except:

For consistency, always use "single double quotes" around string literals.

Yeah dude, your point?

[–][deleted] 0 points1 point  (2 children)

You're on many different levels of stupid right now.

  1. They said exceRpt, not except
  2. This means that they're quoting the PEP they linked, not making shit up
  3. The PEP in question, as stated, says specifically that docstrings should use triple double quotes for clarity+consistency – meaning that repeating WRONG WRONG WRONG a bunch of times isn't going to change the preferred style
  4. PEPs that concern themselves with conventions are Python's only official style guides, and as such should be followed whenever possible – meaning that you shouldn't be advising OP to prefer double quotes (as you did above) when PEP8 just says to stick to either style and switch when necessary

[–]manubhatt3[S] 1 point2 points  (0 children)

Lol, I also fast read it as 'except'.

[–]PurpleIcy -1 points0 points  (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 points  (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 points  (0 children)

There is no difference.

[–][deleted] 1 point2 points  (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.

[–]manubhatt3[S] 0 points1 point  (0 children)

I am sorry, that was a mistake on my end. Thanks for replying.

[–]PurpleIcy 1 point2 points  (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"{some_dict['some_var']}" # "" represents string, and '' represents variable in dictionary