Space between print and round brackets

Completed

Hi

I am using Pycharm Professional 2019.2 and I noticed that it automatically insert a space between print statement and it's round brackets.

 

I don't like this and I want to use the classic print synthax "print()" instead of "print ()". In 2017 version (last I used before the new build) it was ok.

I already check my settings in Settings -> Editor -> Code Style -> Python -> Spaces and for me it's okay. I am doing something wrong ?

 

 

Thanks

0
17 comments

Hi,

Are you using the latest 2019.2.3 version?
If yes, try starting PyCharm with defaults by temporarily renaming/removing configuration folder https://www.jetbrains.com/help/pycharm/directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html

 

0

Hi

Using 2019.2.3 version. Starting the way you mentioned was the first thing I did. Still whitespace between "print" and "()".

By the way, I just created a new project and the IDE returned to it's normal behaviour. At this point I have to say that it was my old project fault.

What I did was to upgrade the IDE from 2017 to 2019, open the project I created with old version and try to work on it.

I don't know if it still to be considered an issue or not.

 

At this point, to solve the problem on my actual project, what I have to do ? It's a good idea to delete ".idea" folder from the project root ? Removing <SYSTEM DRIVE>\Users\<USER ACCOUNT NAME>\.<PRODUCT><VERSION> did not worked.

 

Thanks

0

Got it, thanks for the information.

Indeed, removing .idea folder should fix the issue.

0

Deleted .idea folder, restarted PyCharm but still whitespace. I think I will create a new project by now and copy all the code.

0

Hmmm, that's strange.

What type of project is it?

0

A simple Python 2.7 project. Just plain code for now, no particular modules or plugins.

I would like to add that, by pressing Ctr+Alt+L to auto-format code, it put a whitespace between function name ant the parentheses:

def my_function()
# became
def my_function ():
0

Interesting. I'm just wondering what can be the reason since it's not project-specific or IDE-specific settings or custom plugins.

Please let me know how it goes after you copy your project files to another project. 

0

Using the code within a new project, it's strange, but the problem is still there. Can be Python 2.7 ?

 

Can you please create a new project, test if print() works well and pass me the settings file ?


Thanks

0

Oh my... how did I miss the information about Python 2.7 in the previous message...

Isn't it expected that it puts space after you type print in Python 2.7?
As soon as you configure Python3 project interpreter, it should be print()

 

0

In Python 3 it's normal. The fact is that, at least for now, I must use Python 2.

I insist because in a previous version, while still using Python 2, the "problem" was not present.

I use "print()" in Python 2 by importing print_function from future, not just "print foobar".

It's like the editor try to force me to use "print foobar", by putting whitespace by itself instead of letting me "choose" (with choose I mean no space) of what to do (use parentheses or press spacebar by myself).

 

What I would like to know is that exist an option to disable this behaviour. Ok "space & no parentheses" for Python 2, not ok if importing from future.

 

0

Oh, I see. In fact, it should work exactly like that (no space adding) when importing print_function.

Are you choosing the correct option from code completion popup?

0

This last answer opened my eyes. I can't believe I didn't noticed before: I was not importing from __future__   O:

Using Python 2 with PyCharm without importing from __future__ will cause that, for example, a whitespace will appear before parentheses.

Like above but importing from __future__, functions like "print" will have parenthesis autocompletition and no whitespace.

I was sure at 100% that an import was made.

My mistake.

 

 

0

Hi people, I'm only new to the world of python and Pycharm, i remember one of the first tutorials i watched said to use pep8 so that spaces are automatically added by the editor, now Pycharm isn't adding the space between print() any ideas?

 

0

Where exactly do you expect spaces to be added? Between print() is pretty vague description.

0

Hi Andrew, yes after print so from print() to print () Pycharm was behaving like this when i started using it, i cant figure what I have changed to alter this behaviour.

0

This is enabled by the following options:

 

After that, reformat the code to apply the changes: https://www.jetbrains.com/help/pycharm/reformat-and-rearrange-code.html

0

OK thanks Andrew, appreciate it!

 

Kind regards

 

Brett

0

Please sign in to leave a comment.