I am using PyCharm to write some python code and notice that I run into the following problem quite often:
I write a line of code like this
for item in myList:
Later, I realize that I would like the index of item
as well, so I try to turn that line into this:
for i,item in enumerate(myList):
In order to turn the first line into the second, I put the cursor to the left of item
and type i,
. Then, I put the cursor to the left of myList
and type enu
; by this time, the code-completer suggests that I might want to type enumerate
, which is exactly the behavior that I'm after. When I hit tab to implement the suggested enumerate
, I notice that my line turns into
for i,item in enumerate:
The myList
has been overwritten!
The behavior that I expect is this:
for i,item in enumerate(myList):
with the cursor immediately to the right of either the myList
or the :
.
Is there any way that I could make Pycharm behave according to my expectations?
Just in case it matters, my dev environment is Mac OSX 10.7.5 (Lion)
You can disable certain postfix completion templates in the Editor | General | Postfix Completion page of the IDE settings Ctrl+Alt+S .
In IDLE 1.2, you can use the key combination of 'CTRL' and 'space' to invoke the built-in auto-completion feature. (In Python Shell window, you can use TAB key besides the key combination of 'CTRL' and 'space' to invoke the built-in auto-completion feature.)
You need to go into the project settings and configure the interpreter to point at the virtualenv. PyCharm will then index the interpreter and allow you to autocomplete. The virtualenv may be auto-detected in the dropdown menu on the left.
This behavior is by design when you complete using Tab. Please use Enter instead of Tab to insert the completion variant instead of overwriting.
Code completion settings dialog also has an option to insert variant by typing dot, space, etc.
This is default behaviour in PyCharm, if you press TAB while being connected to another word like so en|myList
, then myList
will get deleted.
What you can do is this, double-click myList
, press CRTL+ALT+T, press ENTER, and then press <-. Then just type in enumerate
.
If you do this regularly, then you can just make a live template that surrounds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With