Trying to get started with Python, autocomplete would be very useful.
As I now understand, Python is dynamically typed and defining the return type of functions is not required. Not so great for autocomplete, obviously.
Therefore I tried to type-hint my local variable in order to enable the IDE to autocomplete. While the IDE checks the existence of the type I hint, this seems to have no effect on auto complete at all.
Is there a way to get autocomplete or should I forget about it when using Python?
This is my code:
import turtle
def draw_square():
screen = turtle.Screen() # type: turtle.Screen
screen.bgcolor("blue")
screen.exitonclick()
draw_square()
There is autocomplete feature present in pycharm. I'm using pycharm professional. I have attached a screenshot.
Related
New vscode user here.
Just discovered the python interactive mode in the vscode-jupyter extension and it seems quite powerful.
I was wondering if it is possible to implement a shortcut that will open the data viewer window associated with the dataframe under the cursor?
Here is a quick sketch of what the workflow can look like
Move the cursor to df
Execute the line if df is not yet defined
Move the cursor to the interactive python group so as to see df in the jupyter: variables tab
Open the data viewer window associated with df
I am willing to take a shot at implementing this shortcut, but as stated above, I am quite a newbie in vscode. Before getting started I would therefore love to hear from you if it is difficult to implement this shortcut (or even simply feasible)? Are the required functions exposed by the vscode-jupyter API?
Any other pointers that can help me are of course very welcome :)
It seems impossible for now, and it's illogic, as you need to select the variable which you want to expose.
Welcome to jupyter extension on vscode community
Go to File -> Preferences -> Keyboard Shortcuts and
type this in the search bar:
"jupyter.showDataViewer"
now click on the result and customize your own shortcut for it
image guide
In the below example:
import tkinter
window = tkinter.Tk()
window.title("My Tkinter")
If I try code completion (Ctrl+Space) at window.titl PyCharm suggest title as field(f) and not as method(m) or function(F). As title is a function reference for wm_title(), I wonder why PyCharm behaves like that.
However in Pydev it suggest as title(string). So even a new programmer in python knows that it is a function have one parameter as string.
Is this correct behaviour of code completion in PyCharm ? Is there any way to achieve the code completion like that of PyDev especially in this case?
I want to use an input parameter in my Python code, but instead of being asked in the Python editor toolbox, the user should be prompted in the Python Turtle Graphics window. I believe that this should be done by built-in write(), but I have no idea how to implement it.
"Write" is used for the turtle to write something in the window. You can not currently have an input in the turtle window, unless you code it all yourself.
I'm creating a simple application through glade, and I want to be able to set the color displayed in the color selection dialog. I found the set_current_color function, however, it requires a gdk.Color object.
Trying to import gtk.gdk.Color fails (actually, just importing gtk fails). Is there another method I can use to create a color object?
It turned out to be an issue of mixing GTK2 and GTK3. gi.repository.Gtk has the Color constructor.
I'm trying to patch a waf issue, where the Windows command prompt output isn't coloured when it's supposed to be. I'm trying to figure out how to actually implement this patch, but I'm having trouble finding sufficient resources - could someone point me in right direction?
Update 1
Please don't suggest anything that requires Cygwin.
It is possible thanks to ctypes and SetConsoleTextAttribute
Here is an example
from ctypes import *
STD_OUTPUT_HANDLE_ID = c_ulong(0xfffffff5)
windll.Kernel32.GetStdHandle.restype = c_ulong
std_output_hdl = windll.Kernel32.GetStdHandle(STD_OUTPUT_HANDLE_ID)
for color in xrange(16):
windll.Kernel32.SetConsoleTextAttribute(std_output_hdl, color)
print "hello"
If you're keen on using normal cmd.exe consoles for the Python interactive interpreter, see this recipe. If you're OK with using special windows simulating a console, for example because you also need more advanced curses functionality anyway, then #TheLobster's suggestion of wcurses is just fine.