Python Forum
How to instantly add quotation marks and comma for parameters?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to instantly add quotation marks and comma for parameters?
#1
Hello,

Does someone know how to instantly add quotation marks and comma for parameters?
For example:

data  = {
   type: a
   type: b
   type: c
}
I need to make the parameters as dictionary as below:
{
   'type': 'a',
   'type': 'b',
   'type': 'c'
}
In a Python tutorial, I saw an instructor instantly adds quotation marks and commas for the dictionary. He does not add them one by one, or write regular expresses in PyCharm. I guess he must use a certain extension for it.

Does someone know about this?

Please advise me.

I use VS Code.
snippsat write Oct-21-2020, 01:56 PM:
Added code tag in your post,look at BBCode on how to use.
yaythomas likes this post
Reply
#2
I would argue that this is not 'instantly'. There is no mind-reading plugins :-). Other than that - yes, there are several ways to achieve desired result with keyboard shortcuts.

In VS Code and for surrounding with " it quite straightforward: select text and press ".

If you need to surround " in column (as in this code snippet) then use multi cursor: place the cursor at the start of the first line, press ⌥ ⌘ ↓ (MacOS) to add another cursor below on the next line. Keep doing that until you have a cursor in front of all your words. Then just type " then fn → (END) then " and all your lines are surrounded by quotes (you can end with ", when needed). If you skip end part then you can just add at the beginning which is simple way to comment out parts of code (ESC for exiting multi cursor mode).

To find out what is your multi cursor keyboard shortcut use ⌘ SHIFT P (CTRL-SHIFT-P in Windows) and type "Add Cursor Below".

For more advanced use cases there are plugins or you can map code snippets to Keyboard Shortcut JSON.
cheers100 likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
Hello perfringo,

Thank you very much for your help. Sorry, I forgot to state I use desktop, operation system is Windows. I have some relevant questions as below:

1. Would you please tell me what's 'fn →' in Windows?
(I've searched it on the Interent, but found nothing. The rest MacOS keys that you show here are okay, and I've found them out in Windows.)
2. The following screenshot in gif is how that Python instructor makes the parameters as dictionary very soon. Could you please possibly figure out how he does this and tell me?
[Image: BiPEwD.gif]
Reply
#4
On Win keyboards there is key conveniently named 'End' Wink (which is missing from MacOS keyboard). I indicated that in my original post, albeit not very obviously.

This will move you to end of line. For more precision use SHIFT → to select character wise.

Regarding example you provided - you can observe that this is some sort of multi cursor (they are visually seen) but I have no experience with PyCharm to help. It might by something built-in, some plugin or Keyboard shortcut to execute some formatting-code snippet.
cheers100 likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#5
Thank you very much for your help. Smile
perfringo likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,114 Aug-19-2022, 08:07 PM
Last Post: Winfried
  How to format Excel column with comma? dee 0 1,360 Jun-13-2022, 10:11 PM
Last Post: dee
  decimal comma DPaul 9 2,268 Feb-22-2022, 12:25 PM
Last Post: DeaD_EyE
  Adding a comma in the resulting value stsxbel 6 2,637 May-22-2021, 09:24 PM
Last Post: stsxbel
  Escape Single quotation between each content tag usman 3 2,792 May-02-2021, 03:32 PM
Last Post: snippsat
  Something wrong with the quotation mark in dictionary definition Mark17 1 1,992 Jan-29-2021, 03:34 PM
Last Post: buran
  print scripts example includes comma that seems to serve no purpose flour_power_33 5 2,797 Sep-02-2020, 03:32 AM
Last Post: flour_power_33
  could someone explain keywords, marks, and function DrKatherineThuyMiller 14 4,506 Jul-23-2020, 07:14 PM
Last Post: DrKatherineThuyMiller
  local variable 'marks' referenced before assignment Calli 3 2,321 May-25-2020, 03:15 PM
Last Post: Calli
  Grabbing comma separed values from SQLite and putting them in a list PythonNPC 8 4,008 Apr-10-2020, 02:39 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020