Is there a way to configure PyCharm to be able to surround selected code with parenthesis by just typing on the parenthesis key, like when we use SublimText 2?
回答 0
我想你想要类似的东西
Settings | Editor | General | Smart Keys -> Surround selection on typing quote or brace
Windows: open pycharm and select file, settings, Editor, Smart Keys, in the list you will check “Surround selection on typing quote or brace”, then apply.
enter image description here
But when CtrlBdoes not work, Sublime Text probably can’t find the Python Interpreter. When trying to run your program, see the log and find the reference to Python in path.
The point is that it tries to run python via command line, the cmd looks like:
python -u C:\scripts\test.py
If you can’t run python from cmd, Sublime Text can’t too.
(Try it yourself in cmd, type python in it and run it, python commandline should appear)
SOLUTION
You can either change the Sublime Text build formula or the System %PATH%.
To set your %PATH%:
*You will need to restart your editor to load new %PATH%
Run Command Line* and enter this command: *needs to be run as administrator SETX /M PATH "%PATH%;<python_folder>"
for example: SETX /M PATH "%PATH%;C:\Python27;C:\Python27\Scripts"
OR manually: (preferable)
Add ;C:\Python27;C:\Python27\Scripts at the end of the string.
To set the interpreter’s path without messing with System %PATH% see this answer by ppy.
It explains (like one of the answers above) how to edit this exec.py in the default directory.
I had the problem that my PYTHON UI APPLICATION would not start. I commented out the last line from the following snipped:
# Hide the console window on Windows
startupinfo = None
if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
#startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
and, taaadaaaa, I could start my app by pressing Ctrl+B. Funny line anyways, uh? And a big thank you to whoever wrote that article ;-)
One thing to note about the aforementioned build system: you can write (and use) custom .sublime-build files or even per project build_systems clause (in your project settings). This allows you to do useful things like a fancy test runner with ANSI colors output.
For even more “full IDE” features, you can use the excellent SublimePythonIDE package:
code completion (intel)
jump to definition & object description
proper linting/pep8
supports different interpreters with virtualenv
Disclosure: I’ve contributed a PR to that package, and I use it all the time, but thereareothers.
Both Sublime’s build system and SublimeREPL (the answers above) are limited in that you can’t easily interact with the workspace variables after you run your file.
If you want to run a script, then work in a REPL-like fashion (like you would in an IDE), then I recommend having Sublime open alongside an IPython console. Using AutoHotKey (Windows) or AutoKey (Linux), you can set this up such that a single shortcut will copy the filename (or just the selected code) and then paste this in the console to run the file.
It’s flagging the second argument, the line that starts url(...)
I was about to disable this check in ST2 but I’d like to know what I’m doing wrong before I ignore it. You never know, if it seems important I might even change my ways :)
PEP-8 recommends you indent lines to the opening parentheses if you put anything on the first line, so it should either be indenting to the opening bracket: