I'm trying to install a python api for controlling imagemagick (this) and followed the instructions.
I imported easy_install:
import easy_install
and then input the line:
easy_install http://svn2.assembla.com/svn/pythonmagickwand/trunk
However I got the error
SyntaxError: invalid syntax
and 'http' was highlighted. I'm wondering...
In Python I have four strings that include the formatting of a list:
line1 ="['a.b.c','b.c.a','c.d.e']"
line2 ="['def','efg']"
line3 ="['f']"
line4 ="['g']"
How do I merge them all so I get a valid Python list such as:
SumLine = ['a.b.c','b.c.a','c.d.e','def','efg','f','g']
...
I've been programming for around a year now, and all the stuff that I've written works - it's just extremely poorly written from my point of view. I'd like to know if there are any (free) good books on Software Design out there that can offer a little guidance to the beginning programmer? I don't think I'd have as many problems if I knew...
I've got a QFrame with a QVBoxLayout and I'm adding my own custom widgets to the layout
to simulate a QListWidget but with more information/functionality in the items. I add the widget to the layout and keep a reference in a member variable (this is Python):
self.sv_widgets[purchase.id] = widget
self.vl_seatView.addW...
I can run my django application using the developer server, but it does not run under apache. The error is:
Unable to acquire Oracle environment handle
Adding an ORACLE_HOME environment variable pointing to my 10g client did not fix the issue.
NOTE: the ORACLE_HOME did not end with a slash. Also, this is using the XAMPP version of...
conn = MySQLdb.connect(host='db1', user='user', passwd='pass', db='db', port=3306)
cursor = conn.cursor()
count = int(sys.argv[1])
x = 0
while x < count:
x += 1
cursor.execute("INSERT INTO auth_group(name) VALUES(%s)", (str(x)))
#if I change %s to 'kkkk', it doesn't work either.
print str(x) + ' / ' + str(count)
print '...
I'm trying to calculate the SHA-1 value of a file.
I've fabricated this script:
def hashfile(filepath):
sha1 = hashlib.sha1()
f = open(filepath, 'rb')
try:
sha1.update(f.read())
finally:
f.close()
return sha1.hexdigest()
For a specific file I get this hash value:
8c3e109ff260f7b11087974ef7bcdbdc69...
I have a block of data, currently as a list of n-tuples but the format is pretty flexible, that I'd like to append to a Postgres table - in this case, each n-tuple corresponds to a row in the DB.
What I had been doing up to this point is writing these all to a CSV file and then using postgres' COPY to bulk load all of this into the data...
Im working on a data packet retrieval system which will take a packet, and process the various parts of the packet, based on a system of tags [similar to HTML tags].
[text based files only, no binary files].
Each part of the packet is contained between two identical tags, and here is a sample packet:
"<PACKET><HEAD><ID><ID><SEQ><SEQ><F...
Question for Python 2.6
I would like to create an simple web application which in specified time interval will run a script that modifies the data (in database). My problem is code for infinity loop or some other method to achieve this goal. The script should be run only once by the user. Next iterations should run automatically, even w...
I'm trying to write a simple load-balancer. It works ok till one of servers (BalanceServer) doesn't close connection then...
Client (ReverseProxy) disconnects but the connection in with BalanceServer stays open.
I tried to add callback (#3) to ReverseProxy.connectionLost to close the connection with one of the servers as I do with closin...
I have a small problem that I think should be easily handled by SQL Alchemy but I can't seem to get it right. I have two tables with one being a parent table and the other a child table. For each child record it needs a unique ID but only with the context of the unique parent record.
I am using the Declarative Base approach.
I setup ...
I have two files that are zipped with something like the following:
for line in zip(open(file1), open(file2)):
# do-something
Unfortunately, now file2 has changed, and there is an additional line at the beginning. Yes, I could get rid of that manually (or with an additional script/program), but since the actual number of involved ...
I have a Python script gathering info from some remote network devices. The output can be maybe 20 to 1000 lines of text. This then goes into excel on my local PC for now.
Now access to this Linux device is convoluted, a citrix session to a remote windows server then ssh to the Linux device half way around the world. There is no ftp, sc...
So I would like to grab stdout from a subprocess and then write the output to a file using python.
The problem I'm having is the stdout from the subprocess loses the formatting, it contains \n's where there are newlines. I would like to write the output to a file with formatting intact, meaning instead of one line containg \n's, the fi...
Hi!
is there something like Python's unhexlify for objc / cocoa?
>>> from binascii import unhexlify
>>> help(unhexlify)
Help on built-in function unhexlify in module binascii:
unhexlify(...)
a2b_hex(hexstr) -> s; Binary data of hexadecimal representation.
hexstr must contain an even number of hex digits (upper or lower case).
This ...
#!/usr/bin/python
import random
import string
appendToFile = open("appendedFile", "a" )
# Generator
for i in range(1, 100000):
chars = "".join( [random.choice(string.letters) for i in xrange(15)] )
chars2 = "".join( [random.choice(string.letters) for i in xrange(15)] )
appendToFile.write(chars + ":" + chars2 + "\n")
ap...
Hi,
I am using difflib to compare files in two directories (versions from consecutive years).
First, i am using filecmp to find files that have changed and then iteratively using difflib.SequenceMatcher to compare them and generate a html diff as explained here.
However, I find that the program is taking too long to run and python is u...
I have a project with a directory structure that looks like:
/foo/baz/__init__.py
/bar/foo.py
/bar/splat.py
Problem is, /bar/splat.py refers to the foo.baz module. This fails with the error No module named baz because it's trying to search for this module within /bar/foo.py. I don't want Python to search the bar module, I want to t...
Hi,
I am looking for an efficient way to compress a numpy array.
I have an array like: dtype=[(name, (np.str_,8), (job, (np.str_,8), (income, np.uint32)] (my favourite example;).
if I'm doing something like this: my_array.compress(my_array['income'] > 10000) I'm getting a new array with only incomes > 10000, and it's quite quick.
But if...