Oddball issue arising with use of TextWrangler to edit Python 2.7 script which tests multithreading and Queue modules - queue

I'm writing a script in Python 2.7 exploring the use of the multithreading and Queue modules. the script just defines two functions, one of which will be started in a thread instance to fill a Queue, and a second one which will be started in a second thread instance to pull something off the Queue. However, I cannot even get this script to execute, as it chokes on one of the function definitions even before it executes. The code snippet with the problem is:
def listenThread(counter):
while queue.empty() != True:
try:
outcome = queue.get()
print outcome
counter -=1
print counter
except:
return 'queue.get() command loop failing.'
The error message I am getting is:
$ python threading-and-queue-test.py
File "threading-and-queue-test.py", line 34
except:
^
IndentationError: unindent does not match any outer indentation level
$
I've searched SO and checked the docs for correct formation of the try-except construct, and it seems OK. I had earlier versions of the code (without the try-except ) working, so I am getting suspicious about the text editor, TextWrangler v4.0.1.
Can anyone suggest a debug approach or code correction?
Thanks!
Red

As you have already suspected, it is most likely an indentation error. Your text editor is probably mixing the use of tabs and spaces. Replace all tabs with spaces (or vice versa though the standard in python is 4 spaces) and you should see the error disappear.

For those who find this question later like I did it's easy to fix TextWrangler's settings and stop this issue altogether; Go to "Preferences" -> "Editor Defaults" -> "Auto-expand tabs" then set tabs to 4 spaces. Restart TextWrangler for changes to take affect. For existing documents that continue giving you a problem read this.

Related

vscode "lint ignore" for task output (languages that are not in-built into vscode - tasks.json/settings.json?)

scenario
Using vscode with COBOL and a task to compile the sources + a defined problemMatcher does:
execute the task correctly (all output shown in the Terminal pane)
parses errors and warnings correctly showing them in the Problems pane
issue
Some warnings are "unwanted" and decided to be ignored (not by the compiler, so they will still be raised and seen in the terminal), but they should not be shown in the Problems pane.
Moving the mouse over the error says "add a lint comment to ignore the warning, but clicking on it does not change the code (which I guess is what it is intended to do).
question
Is there an option to define rules to ignore warnings where the linter is not known to vscode (actually the "linter" is the problemMatcher defined in tasks.json), likely settings.json/tasks.json?
If nothing can be done directly it may be possible to define a problem-matcher to say "ignore"? If yes - how?
If that is still not possible then I'd define a fixed pattern to have these warnings matched as info - but I'd like to find a better solution.
The issue has been raised with the extension author and an answer to the specific questions can be found # https://github.com/spgennard/vscode_cobol/issues/216.
Most important:
The issue [...] observed was related to [a bug:] the linter being triggered for non-linter issues and this was resolved a months ago [in the extension]
You can add a negative lookahead to the problemmatcher:
(?!.*(?:sometextYouDontWant|otherTextNotWanted))here_the_original_regex

Complete command from history in ipython

For reasons outside of my control I'm stuck using python 2.6.6 and IPython 0.10.2. I also normally use the tcsh shell, and have gotten quite used to completing a command from the history using <A-p> (i.e. pressing the ALT key and p). However, this doesn't work in IPython. I know I can press <C-r> and then start typing a command, but what inevitably is happening is that I start a command, press <A-p>, get a colon indicating some weird state, then exit out of that state, delete my command, press <C-r> then search for my command. It's getting rather irritating. Is there any way to make <A-p> complete my already started command by relying on the history?
Ouch, this is an old version of IPython, Python (and pip). The bad news is I don't have much experience with such an old version of IPython, the good new is; it was way simpler at that time.
Most of the shortcut and feature are provided using readline, and the python bindings of stdlib. Meaning that most likely what you are trying to configure is readline itself and not only IPython; so you can find more information on that outside of IPython !
The secret is to grep in the source-code for parse_and_bind, then you'll find the following example configuration, leading me to change the ~/.ipython/ipy_user_conf.py to be like so at around line 99 (all indented an extra 4 space to be in the main() function):
import readline
readline.parse_and_bind('set completion-query-items 1000')
readline.parse_and_bind('set page-completions no')
rlopts = """\
tab: complete
"\C-l": possible-completions
set show-all-if-ambiguous on
"\C-o": tab-insert
"\M-i": " "
"\M-o": "\d\d\d\d"
"\M-I": "\d\d\d\d"
"\C-r": reverse-search-history
"\C-s": forward-search-history
"\C-p": history-search-backward
"\C-n": history-search-forward
"\e[A": history-search-backward
"\e[B": history-search-forward
"\C-k": kill-line
"\C-u": unix-line-discard"""
for cmd in rlopts.split('\n'):
readline.parse_and_bind(cmd)
The repetition of commands make me think that what \C,\M or [e mean might be system dependant. I would bet on \C being Control, and \M being Meta (Alt, Opt), but at least one of these line did the trick for me (and also now tab allows to complete). See also man readline for the list of commands you can bind to what, and enjoy! Hoping you can upgrade to Python 3 and IPython 6 at some point.
[Edit]
See Eric Carlsen second comment under this answer for how it was resolved.

Can't Close and Delete Open MSWord 2010 Document (ActiveDocument.Close prevents Kill command from running.)

I'm trying to close the open word document and delete it as part of my DocumentBeforeClose event. I keep running across the following code in my searches (+/- some error trapping statements):
Dim Killfile As String
Killfile = Dir$(ActiveDocument.FullName)
If Len(Dir$(Killfile)) > 0 Then
SetAttr Killfile, vbNormal
ActiveDocument.Close False
Kill Killfile
End if
I've found similar code (well, frankly almost identical code) in several places, and everyone seems to confirm that it works, but I cannot get it to run correctly in my own attempts, regardless of what module I have the code in. When run, the document always closes, but the code also stops there and never gets to the Kill command. In theory the instance of Word is supposed to keep running the script once the document closes; in my case the instance is open, but there's nothing running anymore at that point. Am I doing something obviously wrong here?
If it's helpful, in another version of the code I'm working with I have a Do While loop going through a directory and deleting documents containing "temp.doc" in the name. That code has no trouble running through and deleting closed files, but also will not delete the active/open document after closing.
Is this something I need to place in the Normal module in order for it to work? (Would reeeaally like to avoid that if possible). Thanks for any help!
Editing to add the top few relevant Search Results from Googling "MSWord VBA Delete Open Document":
http://word.tips.net/T001346_Deleting_the_Open_Document_File.html
http://geekgirls.com/2010/02/deleting-an-open-document-in-microsoft-word/
Delete doc when macro finishes
Again, the unifying factor appears to be:
Activedocument.close
Kill WhateverOpenFile
...which just plain doesn't seem to make sense.

How do you cope with emacs halting on receiving big input?

I am developing project in clojure using emacs cider under windows. And sometimes I have a problem that after accidently forgotten println function or on printing contents of big file Emacs stops responding (cursor and all key combinations doesn't work) and retire into oneself for processing that information to show it in repl. The only way to continue I know is to close program and open project files from scratch. And it is so simple to get in this trap.
Are there any other better solutions or configuration restrictions?
Though this suggestion will not solve your problem completely, it can help you a little.
First, set *print-length* to some value to limit the number of items of each collection to be printed.
(set! *print-length* 10)
And use cider-connect instead of cider-jack-in. You should run lein repl in a separate console window, then run cider-connect to connect to the repl. Then you can evaluate some expressions in the console window.
It would be good if there's an option to limit the contents to be printed by number of characters, however, I couldn't find it.

Multiline CoffeeScript REPL in Sublime Text 2

I want to be able to send entire files and selections to the SublimeREPL and eval them, but it doesn't work. CoffeeScript REPL will only read one line at a time.
Coffee will only take single lines, until you use ctrl+v to switch CoffeeScript to multiline (which works in Terminal), but is blocked by sublime's interface... I'd really like to be able to eval more than one line using SublimeREPL's "ctrl+, s", "ctrl+, f" key bindings. There seems to be no direct way to open coffee with multiline mode automatically.
Maybe I'm going about this wrong, but it's only reasonable that I could use multiline JS Object notation in a CoffeeScript file, for example, and then test it in the REPL. I do it in Python and straight up Node all the time.
You need to be able to switch multi-line on then off again, so ideally if I could edit Sublime REPL to run that key shortcut ( ctrl+v ) before and after running a snippet of code that would be the best.
SublimeREPL v2.0.9 will fix your problem using multiline hack in repl.coffee.
[Ctrl+, s] and [ctrl+, f] should work as expected now :)
Release notes: https://github.com/wuub/SublimeREPL/releases/tag/2.0.9
repl.coffee http://coffeescript.org/documentation/docs/repl.html#section-2
I made a plugin: https://github.com/billymoon/Sublime-Pipe-Dream/ which aims to do this - and much much more. It needs patching up a bit - so any help appreciated. I use it on my mac with sublime text 2 to pass arbitrary selected text, or whole buffers (not saved files) to shell commands and either display the result in the console, or replace the selected text with the console output.
This is very handy for converting coffee to js, js to coffee, executing js/coffee/sql, beautifying and uglifying code and anything else where you want to pass text through a command line script.