When I try to use the script from afl-unicorn I get the error below when I try to run it:
AttributeError("'NoneType' object has no attribute 'GetTriple'")
Related line is arch, arch_vendor, arch_os = lldb.target.GetTriple().split('-') but it works when I just type lldb.target.GetTriple() on interactive console. I don't know why it does not work when importing as comments in the script states.
I tried to add the script as a command later by doing command script add dumper -f unicorn_dumper_lldb but this throws error: unable to execute script function; so that didn't work.
Any idea why?
The error message is because lldb.target is None. To understand why this is so, see the couple of paragraphs in this section of the lldb Python reference after the table:
https://lldb.llvm.org/use/python-reference.html#embedded-python-interpreter
The lldb.target, etc variables are only defined when running in the embedded script interpreter. It doesn't make sense to use a global "selected target" in general purpose scripting, since lldb supports more than one target at a time, and you have no way of knowing that the currently selected target will be the one you want to operate on.
To work properly, the script will have to figure out how to pass the target it intends to work on around within the script.
Related
I am trying to run a python script that is triggered by a rule in outlook. My current process is to write a VBA script that is triggered by the rule - the script simply just calls the shell method as so:
Shell (".../Anaconda3/python.exe" & ".../test_email.py")
However, when I call the script in VBA I receive the error message "Compile Error: Invalid outside procedure" and the reference to my python exe path is highlighted. Does anyone know how I can resolve this issue? I've added what I have in the VBA portion with the actual error
When I put the code in a sub, I am not able to call the actual code from the rules manager.
You must define a sub which has the following signature:
Public Sub Test(mail as MailItem)
Shell (".../Anaconda3/python.exe" & ".../test_email.py")
End Sub
Then Outlook will be able to recognize the method to run for a rule.
See Outlook's Rules and Alerts: Run a Script for more information.
I think you need to put the code inside a Sub, and then call the sub - not just launch it from the editor.
Sub PyExecSub()
Shell (".../Anaconda3/python.exe" & ".../test_email.py")
End Sub
The two answers above are great. However, I ran into the issue of not being able to track potential errors in my script, so I ultimately ended up creating a .bat file that referenced the python executable and script and created an error logger in the bat.
Public Sub PyExecSub(mail As MailItem)
Shell "...\Desktop\test_email.bat"
End Sub
I'm currently doing some work in a server (Ubuntu) without admin rights nor contact with the administrator. When using the help(command) in the python command line I get an error.
Here's an example:
>>> help(someCommand)
/bin/sh: most: command not found
So, this error indicates that most pager is not currently installed. However, the server I'm working on has "more" and "less" pagers installed. So, how can I change the default pager configuration for this python utility?
This one is annoyingly difficult to research, but I think I found it.
The built-in help generates its messages using the standard library pydoc module (the module is also intended to be usable as a standalone script). In that documentation, we find:
When printing output to the console, pydoc attempts to paginate the output for easier reading. If the PAGER environment variable is set, pydoc will use its value as a pagination program.
So, presumably, that's been set to most on your system. Assuming it won't break anything else on your system, just unset or change it. (It still pages without a value set - even on Windows. I assume it has a built-in fallback.)
You can make a custom most script that just invokes less (or even more).
The steps would be:
Set up a script called most, the contents of which are:
#!/bin/sh
less ${#:1} # wierdess is just "all arguments except argument 0"
Put that script in a location that is on your PATH
Then most filename should just run less on that file, and that command should get called from in your python interpreter.
To be honest though, I'd just use Karl's approach.
You can view the various pager options in the source code. That function can be replaced to return whatever is desired. For example:
import pydoc
pydoc.getpager = lambda: lambda text: pydoc.pipepager(text, 'less')
I am trying to create a Shiny app where a user will choose a short string from a drop-down menu, that string will then be passed to a python script which will output some values which will be used in the shiny app.
Using reticulate's py_run_file function with the needed values hardcoded works great. However, using this:
py_run_file('test_script.py arg1')
gives this:
Error in py_run_file_impl(file, local, convert) :
Unable to open file 'test_script.py arg1' (does it exist?)
Several threads suggest using a system() call to run a .py script with command line arguments but I don't think that would be feasible for the goals because the argument needs to be able to change. Other threads have suggested creating a python file that calls the original python file using os.system() with arguments, but that also doesn't work for my situation.
Does anyone have any ideas?
Thanks
If anyone else is struggling with this problem: I found a workaround.
Instead of feeding an argument to the python script, I just create a R global environment variable then call it in the python script.
Had no idea you could reference R environment variables by calls such as r.RVar in the python script, similar to py$PythonVar when calling python variables in R scripts.
I am using vs code for python scripts. These scripts run on the server only.
The server however, passes certain variables to the script while executing the script.
e.g mbo is always passed in it. mbo is special keyword which corresponds to a some class.
Sample mbo.py
class Mbo:
def getString(column: str)-> str:
return 'ABC'
def setString(columnName: str)-> None:
# do something with columnName.
Goal:
In my project in any python file whenever the user types mbo followed by a . vs code should show autoscomplete for .getString() and .setString() without importing this class as it is passed to the script by server.
I can try to write an extension for vs code to add this feature.
Here, I am stuck that what kind of extension is needed here. A LSP? I don't want to loose the feature of the existing python LSP for python.
Can any one proficient with vs code extension API guide me in right direction.
Note: I cannot import this Mbo class just for autocompletion in vscode because I import it. Then I run the same script on server. The server throws errors about the file.
You could try making the imports conditional:
try:
mbo
except NameError:
import mbo
That might be enough to make one of the two IntelliSense engines in the Python extension work.
Otherwise you are looking at your own extension. LSP is obviously the best option but there's also the classic style of registering classes. The VS Code docs have the details. But you are still probably going to clash with the Python extension as both it and your extension will be registered to work with Python files.
I am currently working on adding some features to a plone website and I would like to be able to run a python script using content rules. For example, I've written an article and I want to publish it : using a rule triggered by a condition I want to run a certain script which is not related to the object.
I have already installed Runscript but the problem is that apparently the script has to be related to the object that triggered the action.
I have a simple script that just opens a text file to write 'Hello World' in it :
with open("hello.txt", "w") as fichier:
fichier.write("Hello world")
and plone give me the following error on my script (which works outside of plone) :
Module script, line 1, in hello
<FSPythonScript at /Plone2/hello used for /Plone2/news/azertyazert> Line 1
NameError: global name 'open' is not defined
On other scripts I also get the page I don't have sufficient rights to change the state of the article (thus triggering the condition rule).
Anyway, that was with Runscript, does anyone know either a another way to do execute scripts when rules are triggered or how to make runscript any script ?
Python scripts inside Zope / Plone run in a restricted environment. The error is thrown because you cannot open files from the filesystem there.
Use an External Method instead to point to a file-system stored script if you want to execute Python code that is not restricted.
The runscript action only uses the object as a context. Your script is free to ignore that context.