Many of my company's clients use our data acquisition software in a research basis. Due to the nature of research in general, some of the clients ask that data is encrypted to prevent tampering -- there could be serious ramifications if their data was shown to be falsified.
Some of our binary software encrypts output files with a passw...
I have seen several questions about exiting a script after a task is successfully completed, but is there a way to do the same for a script which has failed? I am writing a testing script which just checks that a camera is functioning correctly. If the first test fails it is more than likely that the following tests will also fail; there...
I'm using assert multiple times throughout multiple scripts, I was wondering if anyone has any suggestions on a better way to achieve this instead of the functions I have created below.
def assert_validation(expected, actual, type='', message=''):
if type == '==':
assert expected == actual, 'Expected: %s, Actual: %s, %s' %...
I am using Multi-table inheritance for an object, and I need to limit the choices of the parent object foreign key references to only the rules that apply the child system.
from schedule.models import Event, Rule
class AirShowRule(Rule):
"""
Inheritance of the schedule.Rule
"""
rule_type = models.TextField(default='onAi...
Possible Duplicate:
What does *args and **kwargs mean?
From reading this example and from my slim knowledge of Python it must be a shortcut for converting an array to a dictionary or something?
class hello:
def GET(self, name):
return render.hello(name=name)
# Another way:
#return render.hello(**loca...
import xml.parsers.expat
def start_element(name, attrs):
print('Start element:', name, attrs)
def end_element(name):
print('End element:', name)
def character_data(data):
print('Character data: %s' % data)
parser = xml.parsers.expat.ParserCreate()
parser.StartElementHandler = start_element
parser.EndElementHandler = end_e...
I'm learning how to use sqlite3 with python. The example in the text book I am following is a database where each Country record has a Region, Country, and Population.
The book says:
The following snippet uses the CONSTRAINT keyword to specify
that no two entries in the table being
created will ever have the same values
for r...
Hi,
I need to add some extra text to an existing PDF using Python, what is the best way to go about this and what extra modules will I need to install.
Note: Ideally I would like to be able to run this on both Windows and Linux, but at a push Linux only will do.
Thanks in advance.
Richard.
Edit: pyPDF and ReportLab look good but ne...
I have a service that runs that takes a list of about 1,000,000 dictionaries and does the following
myHashTable = {}
myLists = { 'hits':{}, 'misses':{}, 'total':{} }
sorted = { 'hits':[], 'misses':[], 'total':[] }
for item in myList:
id = item.pop('id')
myHashTable[id] = item
for k, v in item.iteritems():
myLists[k][id] = v
...
So, I have learnt that strings have a center method.
>>> 'a'.center(3)
' a '
Then I have noticed that I can do the same thing using the 'str' object which is a type, since
>>> type(str)
<type 'type'>
Using this 'type' object I could access the string methods like they were static functions.
>>> str.center('a',5)
' a '
Alas! Th...
I want to run my fabric script locally, which will in turn, log into my server, switch user to deploy, activate the projects .virtualenv, which will change dir to the project and issue a git pull.
def git_pull():
sudo('su deploy')
# here i need to switch to the virtualenv
run('git pull')
I typically use the workon command ...
I'm making an application that supports multi language. And I am using gettext and locale to solve this issue.
How to set LANG variable in Windows? In Linux and Unix-like systems it's just as simple as
$ LANG=en_US python appname.py
And it will automatically set the locale to that particular language. But in Windows, the
C:\>SET LA...
I'm trying to use python to run a program.
from subprocess import Popen
sa_proc = Popen(['C:\\sa\\sa.exe','--?'])
Running this small snippit gives the error:
WindowsError: [Error 2] The system cannot find the file specified
The program exists and I have copy and pasted directly from explorer the absolute path to the exe. I have...
I have some Python code that executes an external app which works fine when the app has a small amount of output, but hangs when there is a lot. My code looks like:
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
errcode = p.wait()
retval = p.stdout.read()
errmess = p.stderr.read()
if errcode:
l...
What am I doing wrong here?
i = 0
cursor.execute("insert into core_room (order) values (%i)", (int(i))
Error:
int argument required
The database field is an int(11), but I think the %i is generating the error.
Update:
Here's a more thorough example:
time = datetime.datetime.now()
floor = 0
i = 0
try:
booster_cursor.exe...
Possible Duplicate:
How to save a Python interactive session?
Can i save everything I type into a python session when "brain storming"?
For instance, not just default variables but of course even overriding the shell. I of course mean by invoking the actual python executable.
I seriously hope this is not a stupid question.
I ...
Is there a better way to express this using list comprehension? Or any other way of expressing this in one line?
I want to replace each value in the original dictionary with a corresponding value in the col dictionary, or leave it unchanged if its not in the col dictionary.
col = {'1':3.5, '6':4.7}
original = {'1':3, '2':1, '3':5, '4':...
This is a continuation of one of my previous questions
Here are my classes.
#Project class
class Project:
def __init__(self, name, children=[]):
self.name = name
self.children = children
#add object
def add(self, object):
self.children.append(object)
#get list of all actions
def actions(...
This only needs to work on a single subnet and is not for malicious use.
I have a load testing tool written in Python that basically blasts HTTP requests at a URL. I need to run performance tests against an IP-based load balancer, so the requests must come from a range of IP's. Most commercial performance tools provide this function...
When I start GVim and start writing my little program I'd like to save the file to the Desktop but it seems that Vim is starting the command line in:
C:\Windows\System32
How would I go about changing that to:
C:\Users\Casey
so then I could just:
:w Desktop\my_program.py
Thank you :)
...