Comment by Arminius on How does an exception know if it's being handled?
@Dschoni I am asking how the exception knows if it's being handled and can change behavior based on that. I am not asking about how to handle an exception. My SystemExit example demonstrates that it's...
View ArticleComment by Arminius on How to delete repeating letters in a string?
Your example currently has a syntax error at the for loop.
View ArticleComment by Arminius on Python Actions during an input()
@crazicrafter1 Do you mean it prints "waiting" before it asks for input?
View ArticleComment by Arminius on Is it possible to include subdirectories using dist...
Be careful here, because you might accidentally include test directories, etc. unless you explicitly exclude=... these.
View ArticleComment by Arminius on Running pytest repeatedly on changed test files
@hoefling Thanks, I am not really looking for a solution in the interactive shell. I simply have a Python script that repeatedly runs tests and should be able to pick up when the tests change.
View ArticleComment by Arminius on What are these extra symbols in a comprehension's...
@MartijnPieters Thanks for your insightful answer and digging so deep. Now I feel sorry I didn't think of at least disassembling the bytecode myself.
View ArticleComment by Arminius on Accessing the AST used for building a symtable
@AnthonySottile Any idea if I could maybe use some C extension magic to get a reference to the AST object?
View ArticleComment by Arminius on Python eval: is it still dangerous if I disable...
While it doesn't show up with the stdlib's tokenize module, the expression inside an f-string will show up in the AST when parsing f"{some code}".
View ArticleComment by Arminius on Ubuntu hotkeys with X11/xlib, X error: BadAccess
Maybe that thread helps: unix.stackexchange.com/questions/261371/…
View ArticleComment by Arminius on Keeping an object static in python
It seems you want to copy the list before appending. You can use I.copy() or I[:] for that.
View ArticleComment by Arminius on What is an alternative to execfile in Python 3?
@gerrit Thanks! I added a note. (It's (re-)executed on every call as the name of loader.exec_module() somewhat suggests.)
View ArticleComment by Arminius on Unrecognized or unpermitted key(s) in configuration...
Could you mark your answer as the accepted answer then?
View ArticleAnswer by Arminius for What does the tag
This notation is used for templates in the source code of Kirki, a Wordpress tool. You might be familiar with other template tag variations such as <% %> (Rails).I assume that the snippet from...
View ArticleAnswer by Arminius for Give params to a div created via document.createElement
Use setAttribute() instead:divs.setAttribute('data-id' , data[i].id); Also note that hyphens are not allowed in Javascript identifiers, they would be parsed as substraction.
View ArticleAnswer by Arminius for Class Method missing one positional argument
If you're calling Material.newMaterial(...) directly, self is not bound, so you're missing a mandatory argument. (You're trying to call newMaterial with self='elastic', etc.)Either remove the parameter...
View ArticleAnswer by Arminius for How to load custom plugin in py.test
If you want to load a plugin from the current directory, you can also just invoke pytest with python -m instead:python -m pytest -p mypluginThis way you don't need to set PYTHONPATH explicitly. From...
View ArticleWhat are these extra symbols in a comprehension's symtable?
I'm using symtable to get the symbol tables of a piece of code. Curiously, when using a comprehension (listcomp, setcomp, etc.), there are some extra symbols I didn't define.Reproduction (using CPython...
View ArticleAnswer by Arminius for Name resolution for class definition blocks and...
Take this example:x = 1def foo(): x = 2 class Bar: print(x) x = 3foo()# Output: 1When print() is called, x is local (because it's assigned in the next line), but still unbound because it's used before...
View ArticleHow to develop legacy Firefox add-ons in the future?
Firefox is moving towards the WebExtensions standard which promises improvements in stability, cross-browser compatibility, and more security. At the same time they're gradually dropping support for...
View ArticleAnswer by Arminius for Add HTML5 sandbox attribute to an iframe using Javascript
While you can set the iframe.sandbox property as a string, it's technically a DOMTokenList interface, so you can also add() and remove() single tokens:let myIframe =...
View ArticleAnswer by Arminius for How do I get the full path of the current file's...
In Python 3.x I do:from pathlib import Pathpath = Path(__file__).parent.absolute()Explanation:Path(__file__) is the path to the current file..parent gives you the directory the file is in..absolute()...
View ArticleAnswer by Arminius for Substring in vim script
The VimL expression mystring[a:b] returns a substring from byte index a up to (and including) b.But be aware that the semantics are different from Python's subscript notation or Javascript's...
View ArticleAnswer by Arminius for Bash: echo string that starts with "-"
In zsh, you can use a single dash (-) before your arguments. This ensures that no following arguments are interpreted as options.% VAR="-e xyz"% echo - $VAR-e xyzFrom the zsh docs: echo [ -neE ] [ arg...
View ArticleAnswer by Arminius for Removing csrf_token before inserting into MongoDB
This is a quirk/bug that can be solved as follows.Option 1Pass an instance of your model (Study) to the form constructor. You can just pass an empty instance which will get filled with the form values...
View ArticleAnswer by Arminius for How to increment version number in a shell script?
For the common use case to increase just the patch version, keep it clear and simple:$ awk -vFS=. -vOFS=. '{$NF++;print}'<<<1.2.991.2.100Explanation-vFS=.Set Field Separator to .-vOFS=.Set...
View ArticleAnswer by Arminius for How do I write standard error to a file while using...
If you're using Z shell (zsh), you can use multiple redirections, so you don't even need tee:./cmd 1>&1 2>&2 1>out_file 2>err_fileHere you're simply redirecting each stream to...
View ArticleAnswer by Arminius for Flake8: Ignore specific warning for entire file
Before version 3.7.0, ignoring specific errors was only implemented per-line but not per-file.The feature was discussed in issue #324 and the project chose not to implement. An implementation was...
View Article
More Pages to Explore .....