I want to make a python script that every 30 minutes checks the status of a torrent on my RPI (where deluge is up and running) and if completed sends an email. I know how to make a timer, loop and email, but I don't know about deluge. I've read this: https://media.readthedocs.org/pdf/deluge/latest/deluge.pdf.
I know I need to import deluge and start with get_session_state() and get it to string, but it doesn't work.
Here's the error:
Traceback (most recent call last):
File "torrents_status.py", line 3, in <module>
get_session_state()
NameError: name 'get_session_state' is not defined
If you are just doing import deluge, you have to use the full module name for the methods.
deluge.get_session_state()
However, I'm imagining there is some connection object to the session that you should actually be calling that method on. I don't want to read through that 300 page manual, though, to find the correct module you should import.
Alternatively, you could do something like
from deluge import get_session_state
Then call
get_session_state()
Once again, you'll need to use the correct module name instead of deluge.
Related
I'm writing a program that I would like to make a stand alone for my company. It works perfectly when I run it from the sublime text shell and I have everything set up to go except one issue that I can't seem to solve; file paths that involve usernames. Does anyone have any suggestion on how to handle this?
An example is
wb.save(r'C:\Users******\Desktop\Excel.xlsx')
I want to make the ****** part either be automatic or an input box.
Use os.path.expanduser() with '~' where you want the home directory:
import os
print(os.path.expanduser('~/Desktop/Excel.xlsx'))
Alternatively use pathlib.Path:
from pathlib import Path
print(Path.home() / 'Desktop' / 'Excel.xlsx')
os.getlogin() will do
import os
path = os.path.join(r'C:\Users',os.getlogin(),'Desktop','Excel.xlsx')
print(path)
Awesome! Looks like that worked but it presented another error now when I create it as a stand alone.
Wait originally works when I run it from the shell using this code, where EC is expected conditions:
wait.until(EC.frame_to_be_available_and_switch_to_it(driver.find_element_by_name('AppBody')))
Whenever I run it as a stand alone though I get the following error:
Traceback (most recent call last):
File "Stand_Alone_CAS_Automation", line 57, in <module>
NameError: name 'wait' is not defined
[17344] Failed to execute script Stand_Alone_CAS_Automation
After following the instructions given on this site: https://sourceware.org/gdb/wiki/STLSupport
GDB is still unable to print the contents of stl containers like vectors, other than printing out a huge amount of useless information. When GDB loads, I also get the following errors, which I think are related to the Python that I put into ~/.gdbinit
Traceback (most recent call last):
File "<string>", line 4, in <module>
File "/Users/mayankp/gdb_printers/python/libstdcxx/v6/printers.py", line 1247, in register_libstdcxx_printers
gdb.printing.register_pretty_printer(obj, libstdcxx_printer)
File "/usr/local/share/gdb/python/gdb/printing.py", line 146, in register_pretty_printer
printer.name)
RuntimeError: pretty-printer already registered: libstdc++-v6
/Users/mayankp/.gdbinit:6: Error in sourced command file:
Error while executing Python code.
When GDB loads, I also get the following errors...
It looks like instructions you followed on https://sourceware.org/gdb/wiki/STLSupport are invalid now. If you look at svn log you will see that registering of pretty printers was added in __init__.py recently:
------------------------------------------------------------------------
r215726 | redi | 2014-09-30 18:33:27 +0300 (Вт., 30 сент. 2014) | 4 lines
2014-09-30 Siva Chandra Reddy <sivachandra#google.com>
* python/hook.in: Only import libstdcxx.v6.
* python/libstdcxx/v6/__init__.py: Load printers and xmethods.
------------------------------------------------------------------------
And therefore second registration throws error. You can remove it or comment out:
#register_libstdcxx_printers (None)
GDB is still unable to print the contents of stl containers
You have probably mismatched pretty printers with your gcc. See https://stackoverflow.com/a/9108404/72178 for details.
From your traceback it seems that the register_libstdcxx_printers() call is failing because there already is such a pretty printer registered. To avoid that, you can wrap it in a try..except to make sure instructions in .gdbinit don't interfere with the launch of GDB if they fail:
python
import sys
sys.path.insert(0, '/home/user/gdb_printers/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
try:
register_libstdcxx_printers(None)
except:
pass
end
(Note: You should usually never use a bare except statement without qualifying the type of exceptions you want to catch. This is a special case though, in startup configuration files like .gdbinit, .pdbrc or your PYTHONSTARTUP file you'll probably want to write defensive code like that).
But chances are this will only get rid of the ugly traceback for you, and printing of STL vectors still wont work. Because it seems there is already a pretty printer registered from somewhere else.
Make sure the path /home/user/gdb_printers/python actually matches the path where you checked out the module mentioned in the STLSupport docs.
How can I use the navigation-policy-decision-requested (or equivalent) in association with webkit_web_policy_decision_ignore()?
The following is a small outtake form my code (the rest is just a wrapper and settings etc):
def check(view, frame, req, nav, policy):
webkit_web_policy_decision_ignore(TRUE)
...
view.connect("navigation-policy-decision-requested", check)
When I load a new page this error is returned:
Traceback (most recent call last):
File "browser.py", line 17, in check_exec
webkit_web_policy_decision_ignore(TRUE)
NameError: global name 'webkit_web_policy_decision_ignore' is not defined
What I'm trying to achieve is that if a certain address have been given, actions will be taken to prevent it from loading via Python. Any suggestions are welcome in the comments and any additional information you may need will be provided upon request.
Now I'm new to Python so please be specific in your answer, criticism and suggestions.
If you are using pygtk, try policy.ignore().
The object names are mapped slightly differently in pygtk. In python shell you can try after executing from gi.repository import WebKit
print dir(WebKit)
to find corresponding object and in your case
help(WebKit.WebPolicyDecision)
I am trying to run this python script called fselect in windows 7. It can be downloaded from this website: http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/ under this name called Feature selection tool. I am running it on Python 2.7.2.Facing a bit of problem running it..
Typed this first in IDLE:
>>> import pprint
>>> import sys
>>> print pprint.pprint(sys.path)
>>> sys.path.append("C:\Users\HP\Documents\MATLAB\libsvm-3.11\tools")
>>> import fselect
Usage: training_file [testing_file]
Then the problem is when i type the next part:
Tried this:
>>> ./fselect.py TrainVec
SyntaxError: invalid syntax
Next tried this:
>>> fselect.py TrainVec
SyntaxError: invalid syntax
Next tried this:
>>> TrainVec
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
TrainVec
NameError: name 'TrainVec' is not defined
Tried this also:
>>> TrainVec.mat
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
TrainVec.mat
NameError: name 'TrainVec' is not defined
What is the correct way of typing it? Need some guidance on it...
tried running using cmd but there is an error...
If you are trying to run the fselect.py directly from the command prompt, make sure that python is set into the path variable. For guidance with that, please read http://people.cis.ksu.edu/~schmidt/200f07/setpath.html.
The script will also invoke grid.py. grid.py requires gnuplot to be there. So ensure that grid.py is running properly and if necessary check the paths of the svm_train, svm_test in the script along with that of grid.py.
Hope it will work now.
If it is a tool, you should run it, not import it. And of course you should not try to enter random commands, even if they are valid shell commands, in your Python prompt.
Assuming TrainVec is your data (since you use it in the context of TrainVec.mat it must be a Matlab data file) then run it on the Command Prompt like this:
python fselect.py TrainVec.mat
The example of ./fselect.py is intended for Unix systems. Make sure you run the above command in what ever directory you have saved fselect.py in.
If you need to write your own scripts to leverage this .py file then I refer you here for an example of how to do this.
Like the previous answer said, it looks like you are (incorrectly) trying to run the script from inside the Python interpreter. According to the documentation on the page you link to, it is not a module but a free-standing script and should be run as such:
Usage: ./fselect.py training_file [testing_file]
I want to make a Python script to control VLC. VLC can be controlled through AppleScript and by using py-appscript I can run AppleScript code from Python.
Using AppleScript I can play/pause VLC by
tell application "VLC" to play
This equals to the following in py-appscript
app('VLC').play()
I should also be able to skip to next track by:
app('VLC').next()
But when doing so I get the following Python error:
Traceback (most recent call last):
File "vlclib.py", line 25, in <module>
app('VLC').next()
TypeError: next() takes exactly 2 arguments (1 given)
Does anyone know why I get this error? The above code should equal the following in AppleScript which works perfectly:
tell application "VLC" to next
From the appscript documentation:
Names that match Python keywords or names reserved by appscript have an underscore appended.
As next is a reserved keyword, you can fix this by running
app('VLC').next_()