Sub-Functions In Python? - python-3.x

I'm creating a project which the user can call functions from my script. My goal is to try and make the syntax very clean. I would like to add a "sub function" for my script, to make the user's code more compact.
I'm already using a class for the script, so that wouldn't be an option.
Currently I've got this:
myDatabase.fetch("notes")
How can I make my syntax look more like this?
myDatabase.fetch("notes").where("theseNotes")
Here is another example:
firstFunction().secondFunction()

Related

How to print function call timeline?

I would like to print location and function name of each function during a run.
It would help during debug to identify which function is called when multiple functions have the same name in different places.
It is possible but time costly to add by hand message such as:
println!("(function_name) file = {}, line = {}",file!(),line!());
Do you know such a solution? Have you suggestions to identify easily which function is called and who calls it?
The easiest option would probably be to use something like dtrace or ebpf: hook onto the "function entry" probe (not sure what it's called in linux / ebpf land but I'd think it exists) and just print the relevant information. You may want to add stack-based indentation though, and of course because of compiler optimisations you might have functions going missing. And you might get the mangled names which is not great, but de-mangling is a thing.
You might be able to do something similar by running your program in gdb and creating some sort of programmatic breakpoints which print and immediately continue?
Alternatively, a module-level attribute procedural macro could work: if you get a token stream for the entire module, it might be possible to automatically inject logging data into every function header.

Initiate "Sys" object in vbs

i'm trying to do some stuff in vbscript, and i have to take a screenshot of the screen. I don't want to use an external executable (Auto Screenshot using VBS).
I find a vbs which can be nice (how to take screenshot by vbscript?) but when i use this, it use an object (Sys), but i don't know how to create it.
I find some resources here, but i really don't know how to initiate the object "Sys", apparently it's like already "in" the vbscript, but it doesn't works for me.
I tried some stuff (Set Sys = CreateObject("System") or things like that, but nothing works :(
I hope you'll find something ^^
The question you've referenced looks like a low-quality question. The references to "Sys" that you see appear to be in a product called TestComplete. See How to capture a screenshot using VBScript in TestComplete? You'd need to acquire and install TestComplete to use it, or find another program to capture screenshots instead.

Can I alter Python source code while executing?

What I mean by this is:
I have a program. The end user is currently using it. I submit a new piece of source code and expect it to run as if it were always there?
I can't find an answer that specifically answers the point.
I'd like to be able to say, "extend" or add new features (rather than fix something that's already there on the fly) to the program without requiring a termination of the program (eg. Restart or exit).
Yes, you can definitely do that in python.
Although, it opens a security hole, so be very careful.
You can easily do this by setting up a "loader" class that can collect the source code you want it to use and then call the exec builtin function, just pass some python source code in and it will be evaluated.
Check the package
http://opensourcehacker.com/2011/11/08/sauna-reload-the-most-awesomely-named-python-package-ever/ . It allows to overcome certain raw edges of plain exec. Also it may be worth to check Dynamically reload a class definition in Python

Is there any way to run an individual test method in groovy?

I'd like to run an individual test method instead of the entire test class in Groovy on the cli - is this possible?
So instead of all the test methods in MyTestClass, I'd like to run just the testArbitrary method in MyTestClass.
Any help appreciated.
In Intellij Idea you could create run configuration, that will start single test method. Command will be copied to output panel and will look like so
com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit3 package.TestClass,testMethod
Like this, you can create your custom JUnitStarter class as described here https://stackoverflow.com/a/9288513/1601606
Natively, there is no such class, but it's pretty simple to create it.

Use global recursive from different functions in vimscript

I want to use multiple globals in different functions in vimscript but I get the following error:
"Cannot do :global recursive"
To my problem: I have a config file with paths to multiple XML-files. I want to use a global for every path in the config file and a global for every tag in each XML-File.
So I have some thing like this:
global search-for-a-file-path call functionX(filepath)
functionX(filepath)
edit filepath
global search-for-tags call functionThatDoesStuff()
functionThatDoesStuff()
Stuff happens here...
Is there a possibility to make this work with globals or do I need to use a different approach?
P.S.: I already saw this Q&A but it did not help me because I use the globals in different functions and the solution only shows how it is done in a "one-liner".
Vimscript does simply not seem to be able to do it, so I came up with the following solution:
while search("the-thing-I-search-for") > 0
call functionThatDoesStuff()
end while
My thanks go to Martin for help on the matter.

Resources