How to coment out existing block of code?

The attached snipped of editor shows the “start” of “comment out following…” , however, no matter where I move the “indent” I get an "indetattion is wrong " error pointing to the end of the “comment out previous”.

It looks as the “solution " is to type “”” , then I get another “”" AND I can copy the intended block “in between “”” here “”". Pretty awkward.

Is there a better way ?

I don’t know that it’s ‘better’, per se, but I well featured IDE or text editor that has a Python mode, will have an option to comment out a block of code, by highlighting said block and then, something like ‘Comment out region’. With the tools that I use, the option simply places a # on each line of the code block, at the LH margin.

To add: thinking about this some more, I conclude that the # comment is better, because if you comment out a block of code with a triple quote, that could conceivably constitute a docstring.

For instance, IDLE’s Format menu has Comment Out Region Alt+3 and Uncomment Region Alt+4. It adds ‘##’ to be different from a hand-created block, but will remove either ‘##’ or ‘#’ or even ‘’.

Inserting/deleting pairs of lines with triple quotes changes line numbers, will interact with included triple quotes of the same type, and will not be syntax colored as a comment.

1 Like

Thanks for replies. Unfortunately my editing got so hopelessly screwed-up so I reverted to the “base” copy.
Since I am still learning how to “indent” I am not too fond of “”" and its needs to be “indented”.
In my opinion comment out a line or a block should be just that. Requiring it to be indented makes it part of the code and defeats the "comment out "as an independed edit .
Perhaps that is why the code I am trying to decipher AKA reverse engineer is so void of comments.
Unless I misunderstood the replies - are you saying he different Python IDE would have a different symbols for commenting out ? I can see different ways implementing block of code comments , but not different symbols.

No, that’s not what we’re saying: in Python a comment line is prefixed with a # . It seems that the IDLE IDE uses double # for comments that are created as ‘blocks’ of code, is all.

OK, got it.
In other words - Python itself does not have "comment out block of code " symbol, it is "added feature " of the IDE.

1 Like

In case it hasn’t occurred, there’s also “disable lines of code”:

 if False:
     unwanted
     code
     here

Cheers,
Cameron Simpson cs@cskk.id.au

1 Like

I am sorry to post this here , but I am getting “e-mail not posted due…” and cannot figure it out.

I am also concerned about receiving replies "this is no python code / PyCharm issue …please post in python forum or PyCharm…

I have a simple question

my code file for nanovna-saver.py is in

/mnt/RAID_124/PYTHON_NANO_PROJECT_FOLDER/NANO_JULY17/nanovna-saver.py

however I am getting this trace saying it is working from DIFFERENT DIRECTORY / FILE

( in this case I am posting main_.py path )

/home/nov25-1/.local/lib/python3.10/site-packages/NanoVNASaver/main.py

This makes it impossible to actually trace / debug the code flow by setting
breakpoints in REAL source file - it never reaches the breakpoint since it is running form

different source.

I assuming I am missing some initialization when I boot and load PyCharm.

The PyCharm never starts same after initioalo power-up / reboot

( I’ll will post his in PyCharm forum )

/usr/bin/python3.10 /snap/pycharm-community/340/plugins/python-ce/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 40197 --file /mnt/RAID_124/PYTHON_NANO_PROJECT_FOLDER/NANO_JULY17/nanovna-saver.py
Connected to pydev debugger (build 231.9225.15)
TEST TRACE import subwindows ??
Current file /home/nov25-1/.local/lib/python3.10/site-packages/NanoVNASaver/NanoVNASaver.py
Current line 31
TEST TRACE continue main () ??
Current file /home/nov25-1/.local/lib/python3.10/site-packages/NanoVNASaver/main.py
Current line 49
TEST TRACE ArgumentParser ??
Current file /home/nov25-1/.local/lib/python3.10/site-packages/NanoVNASaver/main.py
Current line 55
TEST TRACE print INFO from aboput.py ??
Current file /home/nov25-1/.local/lib/python3.10/site-packages/NanoVNASaver/main.py
Current line 81
NanoVNASaver 0.5.4-pre
Copyright (C) 2019, 2020 Rune B. Broberg
Copyright (C) 2020ff NanoVNA-Saver Authors
This program comes with ABSOLUTELY NO WARRANTY
This program is licensed under the GNU General Public License version 3
See https://github.com/NanoVNA-Saver/nanovna-saver for further details.
TEST TRACE DONE print INFO from aboput.py ??
Current file /home/nov25-1/.local/lib/python3.10/site-packages/NanoVNASaver/main.py
Current line 90
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
WARNING:root:DUPE MY DEBUG Show NanoVNASaver main window
INFO:NanoVNASaver.NanoVNASaver:Settings from: /home/nov25-1/.config/NanoVNASaver/NanoVNASaver.ini
DEBUG:NanoVNASaver.Defaults:restored

I doubt it is a simple question :grinning:

What do you mean? E.g. what is the “REAL source file” you are referring to?

Let us look at the debug trace you helpfully supplied:

Here your code is started.

This means the NanoVNASaver is started, probably because you imported it. If you want to debug going into the library code, you have to put the breakpoint before the import and step into the library or put it in the NanoVNASaver code. When you import a module or package, its top level code is executed.

A bit further I find:

So the NanoVNASaver has taken over here and it shows its main screen, initialized with setting from your personal configuration directory. Sounds good, but probably only after the program has finished it will return to your code in /mnt/RAID_124/PYTHON_NANO_PROJECT_FOLDER/NANO_JULY17/nanovna-saver.py. That is not what you want?

Sorry, but until I figure out or somebody tells me how I am reluctant to start a new post.

This looks as sending an e-mail which should be no brainer, but I keep getting “, not delivered …”

I suspect my OS and e-mail software with connection to stupid AI is the problem.

So here is my very next and complicated question - it basically is about “:”

symbol usage .

would somebody kindly read and explain in English language what all these lines of code doing?

I am trying to replicate TDRWindow (class )

I know how to add “new python package” , name it DTWWindow and copy / modify the existing TDRWindow

code to it.

I am having issues "adding DTW " symbol and accessing it.

Basically - what does this do

“tdr”: TDRWindow(self), as far as “tdr” symbol goes ?

and

what

self.windows = { …}

does ?

self.windows = {
“about”: AboutWindow(self),

“analysis”: AnalysisWindow(self),

“calibration”: CalibrationWindow(self),
“device_settings”: DeviceSettingsWindow(self),
“file”: FilesWindow(self),
“sweep_settings”: SweepSettingsWindow(self),
“setup”: DisplaySettingsWindow(self),
“tdr”: TDRWindow(self),

add ??

“DTW”: TDRWindow(self),
}

: