Editing text in PyCharm - python

I've started using PyCharm 2 this year and it's working well for me, the only thing is that when I add comments in, it all sort of gets lost in the amounts of code.
Is there a way to add any text formatting to only certain parts of my programs? Like increasing the font of the comments that separate different practice questions, or even just bolding some of my comments to make the sections stand out more?
I know you can change the text for the entire file, but I want some diversity so it's a bit easier for other people (and sometimes myself) to read.

Go to Preferences->Editing->Color Scheme. From there you can change the way all the different types of program elements are displayed. You can use colors, bold, and italic to highlight things differently. I don't think you can assign different fonts or sizes, though.

Go to File -> Settings -> Editor -> Color scheme
Comments are under "Language Defaults"

Related

Are there any risks/downsides to putting emojis in code?

I sometimes use emojis in programs to highlight certain parts of the code (in open source libraries). I rarely use more than say 5-6 per script and I find they really stand out due to their colors in a text editor.
Typically, they are transient markers and will be removed when whatever issue they are associated with is closed.
My question is: are emojis liable to cause any issues in the general Python toolchain? This includes, but is not limited to: git, github, pypi, editors, linters, interpreter, CI/CD pipelines, command line usage...
I haven't seen any, but then again I rarely see emojis in code. This is a Python 3 only question, so Python 2 unicode aspects are out.
(This question is not about whether this looks professional or not. That's a valid, but entirely separate consideration.)
Some examples:
# ⚙️ this is where you configure foo
foo.max_cntr = 10
foo.tolerate_duplicates = False
# 🧟‍♂️🧟‍♂️🧟‍♂️ to indicate code to be removed
some dead code
# 👇 very important, don't forget to do this!
bar.deactivate_before_call()
In terms of risks, there aren't really any real ones. If you use them in comments they'll be removed/ignored at runtime anyway so performance-wise there's no issues.
The main issue that you could run into is that some Linux distributions (distros) DONT support emojis, so they'd fallback to some standard unicode character (generically a white rectangle with a cross through the middle), so this could make comments hard to understand.
But in personal use: no not really, there's no issues.
TLDR: Probably not, but maybe.

How do I add additional syntax highlighting/coloring to my Text Editor

So I'm using TextWrangler4.5.3 and primarily Python for scripting. When I write Python, I often like to make comments that say something like: # BEGINS foo and then later # ENDS foo I do this so, later editing and understanding is quick and clear. Finally getting to the point: i want to tell TextWrangler to make "# BEGINS" a different coler, say.. green.
Thanks SO much in advance for any insight =P
If you want to use a different color scheme than the factory defaults, go to Preferences->Text Colors. I would suggest creating a new theme, with green comments.
Next, go to Preferences->Languages and create a Custom Language Preference for Python.
Within the 'Display' tab of this language preference window, change the color scheme to the new one created earlier.
I'm not aware of a way to make some comments, such as """ vs ''' vs #, differ in color (it's probably a global "anything that is a comment will have the same theme" for TextWrangler).
Is this what you are trying to do?

Python highlighting in emacs

I am using emacs 23 -nw and xterm installed on Debian Squeeze. I need highlighting with python but I don't have it. How can I enable it?
Edit:
Thanks for all answers, the problem is that
I have googled a lot, really.
I have the code on a file with extension .py
The script starts with #!/usr/bin/python, as one of the the answers points I have changed to !#/usr/bin/env python
I used M-x and tried to find something related to python, well there many options which do not solve my problem.
Sorry my question was not very precise and I even accept -10 but I don't have highlight which would give me red highlight for lines starting # etc. To be more precise I have a very a dull highlight; lines with # are white, lines between """ """ are green, some of the variable names are yellow but don't know why not all. [import, as, from] are light blue, [open, max, and other function names] are dark blue etc. And besides my 200 lines of code is working.
I'm not sure if this is right, but try the following.
1) M-x
2) type in "python-mode". Tab completion works here so type in "pyth" and hit tab and you can see what your options are.
mj
If you run Emacs from xterm with emacs -nw, you'll have a different color layout than if you run the same color mode in an X window. Differences include big changes in the highlighting of comments, different colors assigned to various keywords and (rarely in my experience, though Python comments seem to fall into this category) failure to highlight some elements.
I'm not really sure why this happens, but it doesn't seem to be a problem on your end since it's consistent on every machine I've worked on. If it really bugs you, and you really, really want to keep running from xterm, take a look at the color-theme module, it may help.
Emacs 23 should know about Python out of the box. Does the name of your Python file end with .py, or does the file have #!/usr/bin/env python as the first line? If you're creating a new file, make sure the filename ends with .py. You can also use M-x python-mode as mentioned in another answer. If none of that works, check that your terminal actually supports color.

auto indenting wrapped Python code in Word

I'm wrestling with Microsoft Word to display my Python code correctly and am in need of some help.
I am trying to paste large amounts of Python scripts into Microsoft Word with documentation text written around the snippets. Some of these Python snippets are a few lines, others are over a page long. Since the document is now around 500 pages long there are around 200 snippet blocks scattered throughout the document.
I have a font style I created set to the snippets. So I can change font size, color, style etc for all of them at once. But I'm having a big problem with the word wrapping. Long statements in Python get wrapped in word which makes them hard to read since the indents are lost. I am able to successfully indent the level 1 wrapped line using "hanging indents". But I cannot do anything about a level 2 or level 3 indent since nested stuff is further indented.
Example (I've used dots instead of spaces because it kept removing them)
This is a statement
This is another statement
if (condition):
.........This is a third statement
.........This is a fourth statement
.........for loop :
..................This is a fifth statement
..................This is a sixth statement
..................if (condition):
...........................This is a seventh statement
Imagine each statement is fairly long and gets wrapped to the next line on a word page. I get
This is a statement
This is another statement
if (condition):
.........This is a third
statement
.........This is a fourth
statement
.........for loop:
.................This is
a fifth statement
.................This is a
sixth statement
How can I fix this in word? A hanging indent will fix the level 1 indents (the statements in the if condition) but not the level 2 indents (the statements in the for loop)
Note: I would like to use some sort of option, or plugin or macro within word. I cannot use a code editor and copy and paste code in rtf or some other format. Even if I did this 200 times to replace all my code snippets, the moment I change the font size in my document everything will get messed up again. Another option would be some IDE that embeds or links into word (without having to copy and paste) and allows changes to font style and size in its own environment which will get updated at all occurrences in Word automatically.
Please help if you can. I have searched like crazy and found nothing that works...
1) Follow PEP-8 recomendations and keep lines < 80 characters.
Sometimes this seems very difficult or inconvenient. In these cases allow you up to 90-95 characters. Longer lines are probably the result of a bad design of the code or of wrongly selected variable names. (There is people working with standard sizes of up to 120 characters but probably they are not trying to publish the code in Word in portrait mode).
2) Use a monospaced font
3) Keep font size small enough to provide 80-95 characters per line.
Have you tried using Word to draft a plain-text document? You can always convert it later.
Write your code in a Python-enabled code editor with syntax highlight. Save your snippets. Take screenshots. Paste them into MS Word. Resize and crop the images as desired.
Now all you have to do is fight MS Word on the word-wrapping around images, which is a fight you might even win.
Use docutils.
Instead of fighting against MS-Word (and other WYSIWYG editors) it's far, far easier to use docutils.
Write your document in approximately plain text. You'll use RST markup which is very simple and lightweight.
Run the rst2html.py conversion to create nice-looking HTML pages from your source.
Run the rst2latex.py conversion to create LaTeX from your source. There are a variety of tools that can produce PDF from the LaTeX.
In this case, the code snippets are handled perfectly every single time. No work.
If you're writing something really big and complex, you should be using Sphinx for this. It's an extension to docutils with even more cool markup features for code snippets.
I don't use word, but in LibreOffice, you could just use paragraph formatting - create a new paragraph style for each level of indent (pycode, pycode_indent1...). Put all of the formatting you want (mono-spaced, no paragraph spacing, etc.) in the top-level style, and make the indented styles use it as a parent. Then just add appropriate indents to each of the child styles. This is basically the same idea as multi-depth bulleted list, without the bullets. Then select the appropriate indent paragraph style for each line (hint: you can select multiple non-contiguous lines using ctrl+mouse in LibreOffice).
Granted, this way you have to do it line-by line, which could be a big pain in the arse. But if might work if it's just a few snippets that are being problematic.

Hidden features of PyCharm [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I know PyCharm is young IDE but id like to know if you guys have found some candy while using it. I know from experience that JetBrains IDE's are filled with candy and can't wait to find it all.
Please list your tips, perhaps something you did not first expected to be there.
As the lead developer of PyCharm, I can tell you that we don't usually hide features in random places, and there are a few reliable ways to discover most of them.
Try Ctrl-clicking on everything (methods, functions, template tag names and parameters, etc.)
If Ctrl-clicking works, usually so does completion (Ctrl-Space), rename (Shift-F6) and Find Usages (Alt-F7)
Look through the menus and try out the actions that seem interesting
Look at Settings | Inspections to configure the warnings which can be highlighted by PyCharm, and note that many of the inspections have quickfixes to correct the problems automatically
Read the blog and try out the features highlighted there.
I have recently discovered an option (I think it's off by default):
Surround selection on typing quote or brace
Basically if you can quickly make a string from anything, just press Ctrl-W to select and then type quote. Awesome :)
PS: To enable this use settings search function, search for: surround
I like ctrl-w, the select block function. I've never ran across this before I think it's great to be able to select a function/if block by just pressing ctrl-w a couple of times.
This isn't PyCharm specific, I actually discovered it in IntelliJ but I though the PyCharm users should benefit too...
Try Alt+Click (Ctrl+Alt+Click if using Gnome default keymap) and drag to select text. It will select bounded blocks instead of complete lines using word wrap. These selected blocks can be used to type repetitive text or delete many parts of a line at once. Try it, you will find uses for it more often than you think!
I don't know if this is a hidden feature really but when you know about it makes testing so much easier.
If you run your tests through PyCharm you can click on the names and lines of the backtrace to take you to the exact line in your python code. Makes testing so much easier.
Control-clicking a view method in a URLconf will open views.py and bring you right to that method. Similarly, control-clicking template names in a view, and in other templates (like in the extends tag) will bring you to that template.
Not hidden, but when editing a CSS file, it shows the colors in the gutter for any styles that use color. I love that. Also for CSS: code insight offers optimizations of tags, as well as graying out unused tags.
When editing an HTML file, moving the mouse towards the top-right of the editor will display icons for several browsers...clicking those will open the current HTML in the respective browser. Not as useful if you're using Django templates, but another piece of IDE-candy nonetheless.
Auto-import is also probably one of my favorite features. It still needs a bit of work, though. This is just a preview release, so I'm sure it'll continuously get better.
Well done, JetBrains!
Something I recently had to figure out was how to pass hardcoded arguments to a Python program when running it. I wanted to do it in the IDE rather than having to switch back and forth to a command window to run the program.
In PyCharm 1.5.2, you can click on Run, then Edit Configurations. The third textbox from the top, labeled Script parameters, allows you to hardcode program parameters. These will be used each time the program is run from PyCharm.

Categories

Resources