How to get PyCharm to show the keyword arguments while coding, like the options you can pick from? I can get VSCode to show this normally, but I just can't figure out how to get PyCharm to do it. You'll see the difference in the screenshots. One is from PyCharm and the other one is from VSCode
If you start a new project in PyCharm, add a .py file and entire the following code:
import os
os.chdir()
And you position the cursor between the two parentheses while typing, or when you press Ctrl+P in that position, PyCharm will show a hint saying "path: int | str | bytes | PathLike[str] | PathLike[bytes]", like this:
If you're just looking for the autocomplete, instead of the type hints, similarly ensure you're typing something that could be completed and PyCharm wil show type hints you can navigate with arrow keys (or can just complete by hitting Enter).
Note that you can cause PyCharm to show it again by hitting Ctrl+Space.
Mind you, if you type something that has no logical completion (i.e. nothing starts with the string you've written so far), there is no autocompletion, and so none is shown - instead PyCharm will show a small message in its place saying 'no suggestions'.
Related
I'll want to know how to call a function in vs code. I read the answer to similar questions, but they don't work:
def userInput(n):
return n*n
userInput(5)
And appends nothing
def Input(n):
return n*n
And in the terminal:
from file import *
from: can't read /var/mail/file
Can somebody help me?
You are doing everything correctly in the first picture. In order to call a function in python on vs code you first have to define the function, which you did by typing def userInput(n):. If you want to see the result of your function, you should not use return, you should use print instead. Return is a keyword- so when your computer reaches the return keyword it attempts to send that value from one point in your code to another. If you want to see the result of your code, typing print (n) would work better.
Your code should look like this:
def userInput(n):
print (n * n)
userInput(5)
The code would print the result 25
Your terminal is your general way to access your operating system, so you have to tell it that you want it to interpret your Python code first.
If you want to run the file you're typing in, you have to first know the location of that file. When you type ls in your terminal, does the name of your Python file show up? If not, hover over the tab in VSCode (it's close to the top of the editor) and see what path appears. Then in your terminal type cd (short for "change directory") and then the path that you saw, minus the <your filename here>.py bit. Type ls again, and you should see your Python file. Now you can type python <your filename here>.py to run it (provided you have Python installed).
You could also run the IDLE by just typing python in your terminal. This will allow you to write your code line-by-line and immediately evaluate it, but it's easier to write in VSCode and then run it with the method I described before.
I tried running the below code but VS Code is showing syntax error. I checked on internet and notes but found the loop is fine.
i = 1
while i <= 5:
print(i)
i = i + 1
While loop showing syntax error
I don't think there is anything wrong with your code but you should try to create a new folder preferably outside of Appdata. or One drive folder
There isn't anything wrong with your actual code. When I run it it executes as you would expect. I think the problem must be the way you are executing the program. I think you are attempting to run it in the python interpreter. Where it says "2:Python" you want it to be like "cmd" or "Code" or something and then you can just type in python loop.py maybe try clicking the plus next to it or select the first option in the dropdown.
YouCompleteMe is a lovely tool for autocompletion in vim. It also shows the docstring of the 'hovered' autocomplete candidate, which is a very useful tool for me. This preview is sadly closed as soon as one confirms the candidate, e.g. by opening parentheses.
Example:
First Docstring is shown:
Typing a parenthesis will kill the docstring though:
Now i would love to keep the docstring while my 'cursor' is in the parentheses of whatever i just autocompletion for (to be detailed: obviously the docstring of the innermost parentheses, if they are nested).
Can this be done, and if yes, how?
Thank you so much in advance,
LJKS
Add below to your vimrc
let g:ycm_autoclose_preview_window_after_completion = 0
or Default.
The optional g:ycm_autoclose_preview_window_after_completion is 0 by default.
I think this will help you out:
let g:ycm_autoclose_preview_window_after_completion = 0 " default
let g:ycm_autoclose_preview_window_after_insertion = 1
ycm_autoclose_preview_window_after_insertion:
When this option is set to 1, YCM will auto-close the preview window after the user leaves insert mode. This option is irrelevant if g:ycm_autoclose_preview_window_after_completion is set or if no preview window is triggered.
Default: 0
Using IDLE, I have appreciated the helpful hint that pops up when you type a function (user or built-in) and open the bracket:
function(
so now, in IDLE, the inputs of this function would pop up below, along with a short snippet of doc string. Sublimetext 2 just doesn't do this. Are there any plugins or ways to edit the settings file to make this happen?
SublimeRope offers code completion, GoTo Definition, etc.
EDIT-4
I've gotten my sitecustomize.py to execute, but it tosses up an error. Here's the code for it.
The error is:
Error in sitecustomize; set PYTHONVERBOSE for traceback:
RuntimeError: maximum recursion depth exceeded while calling a Python object
I'm not terribly advanced with Python yet, so I figured I'd comment out only the lines I did not think Iwould need. No encoding issues are showing up, so I just commented out lines 23-104, but that didn't help either.
EDIT-3
I also happened to have 2.5.1 installed, so I compiled another script with that.
print 'This will test carriage returns on Windows with PyDev on Eclipse Helios'
print'Type something:',
test = raw_input()
print('You entered the following ascii values:')
for c in test:
print(str(ord(c)))
This ran fine, and resulted in
This will test carriage returns on Windows with PyDev on Eclipse Helios
Type something: g
You entered the following ascii values:
103
So this is possibly a Python3 thing only? I know it's not the interpreter, because I'm able to run it in command prompt just fine. What gives?
EDIT-2
Just tested with Helios, still having the same problem. Here's my test program:
print('This will test carriage returns on Windows with PyDev on Eclipse Helios.')
print('Type something:', end='')
test = input()
print('You entered the following ascii values:')
for c in test:
print(str(ord(c)))
And here's the output when I type 'g' and press Enter:
This will test carriage returns on Windows with PyDev on Eclipse Helios.
Type something:g
You entered the following ascii values:
103
13
In the grand scheme of things, it's a small issue. I could use input().rstrip() and it works. But the workaround shouldn't even be necessary. I'm typing twice as much as I should need to in a language that I'm using because it's concise and pretty.
EDIT-1
This is Eclipse 3.5. Unfortunately that's the latest version that's been approved for use at work. I'm going to try 3.6 at home to see if that's any different, but I wouldn't be able to use it anyway.
(original question)
I've been learning some basic Python, and decided to go with PyDev since it supported Python 3 as well as having all the nice code snippet and auto complete features.
However, I'm running into that darned carriage return issue on Windows.
My searches always lead me back to this mailing list:
http://www.mail-archive.com/python-list#python.org/msg269758.html
So I have grabbed the sitecustomize.py file, tried to include it in the Python path for my configured interpreter, as well as my project, but to no avail.
Has anybody else managed to work through this? Or maybe knows how to get the new sitecustomize.py to actually execute so it can override input() and raw_input()?
I know I could always make a short module with my own replacement input() function, but I'd really like to fix the problem at its root. Aptana acknowledges the issue ( http://pydev.org/faq.html#why_raw_input_input_does_not_work_correctly ) but offers no solution. Thanks in advance for your help.
Figured out a hack to make it work locally to my Python installation. In \Lib\site-packages\ make a script called "sitecustomize.py", and put this code in it:
original_input = builtins.input
def input(prompt=''):
return original_input(prompt).rstrip('\r')
input.__doc__ = original_input.__doc__
builtins.input = input
I don't know anything about the side effects of this, or what sort of error checking I should be doing, but it works if you're using PyDev on Windows to write scripts with Python3.
Found out some more things about sitecustomize.py and how it relates to site.py.
I don't know how to add my own sitecustomize.py to PYTHONPATH for execution only in a PyDev project, so I just stuck it in ${Python31dir}\Libs\site-packages. The module runs now, but generates errors.