I am in the process of writing a small(er) Python script to automate a semi-frequent, long, and error-prone task. This script is responsible for making various system calls - either though os.system or through os.(mkdir|chdir|etc).
Here is an example of my code right now:
class AClass:
def __init__(self, foo, bar, verbose=False, s...
I'm writing an app for tagging photos. One of the views handles adding new tags and without boilerplate for POST/GET and handling field errors it does this:
tagName = request.cleaned_attributes['tagName']
t = Tag.objects.create(name = tagName)
t.save()
Now in a view for another request to retrieve all tags I have:
tags = Tag.objects....
Hi,
I'm interested in writing a short python script which uploads a short binary file (.wav/.raw audio) via a POST request to a remote server.
I've done this with pycurl, which makes it very simple and results in a concise script; unfortunately it also requires that the end
user have pycurl installed, which I can't rely on.
I've al...
I have a program as follows:
a=reader.next()
if *some condition holds*:
#Do some processing and continue the iteration
else:
#Append the variable a back to the iterator
#That is nullify the operation *a=reader.next()*
How do I add an element to the start of the iterator?
(Or is there an easier way to do this?)
EDIT: OK l...
I am developing a multi-lingual site with Plone. I want to have one language per folder but the Plone navigation UI is causing problems.
I have several different folders in my root, such as en, de, nl, etcetera. Inside those folders is the actual content, such as en/news, nl/nieuw, de/nachrichten, etcetera. I have set up Plone Language ...
Is it possible to run Python egg files directly as you can run jar files with Java?
example: java -jar jar-file
...
I want to use python to get the executable file version, and i know of pefile.py
how to use it to do this?
notes: the executable file may be not complete.
...
Apparently when my signal handler exits, my program CONTINUE TO RUN. this is evident by the exception raised even AFTER the "log Done, close now".
Can someone explain why this is so? Note the functions have been simplified
^Clog Ctrl-C
backup State: not_span 328, pos 22, all_cycles 19
backup backup complete, you may force exit now
l...
While investigating Ruby I came across this to create a simple Struct-like class:
Person = Struct.new(:forname, :surname)
person1 = Person.new('John', 'Doe')
puts person1 #<struct Person forname="John", surname="Doe">
Which raised a few Python questions for me. I have written a [VERY] basic clone of this mechanism in Python:
def Str...
I use python-twitter to get the date of a tweet and try to parse it with the time.strptime() function. When I do it interactively, everything works fine. When I call the program from my bash, I get a ValueError saying (for example):
time data u'Wed Aug 12 08:43:35 +0000 2009' does not match
format '%a %b %d %H:%M:%S +0000 %Y...
I want to used python to get the executed file version, and i know the pefile.py
how to used it to do this?
notes: the executed file may be not completely.
...
cl = xmpp.Client('myserver.com')
if not cl.connect(server=('mysefver.com',5223)):
raise IOError('cannot connect to server')
cl.RegisterHandler('message',messageHandler)
cl.auth('[email protected]', 'mypassword', 'statusbot')
cl.sendInitPresence()
msgtext = formatToDo(cal, 'text')
message = xmpp.Message('anothe...
How play standard system sounds from a Python script?
I'm writing a GUI program in wxPython that needs to beep on events to attract user's attention, maybe there are functions in wxPython I can utilize?
...
Good day pythonistas and the rest of the coding crowd,
I have two QMainWindows designed and coded separately. I need to:
display first
on a button-press close the first window
construct and display the second window using the arguments from the first
I have tried to design a third class to control the flow but it does not understand...
Hi,
Is there any way to tell whether a string represents an integer (e.g., '3', '-17' but not '3.14' or 'asfasfas') Without using a try/except mechanism?
is_int('3.14') = False
is_int('-7') = True
Thanks,
Adam
...
How to change only hight of an object in wxPython, leaving its width automatic? In my case it's a TextCtrl.
How to make the height of the window available for change and lock the width?
...
I am installing imgseekweb according the instructions. I installed or had my hoster install imgSeekWeb.py, iswImage/images folder,
iswImage/thumbnail folder, Python Imaging Library (PIL), PyQT, imgSeek, imgSeekCmd (updated), and imgSeekWeb-0.0.1_2.
I was able to successfully create the database by running
imgSeekCmd add -b ~/data/img-d...
I have fairly large C++ library with several sub-libraries that support it, and I need to turn the whole thing into a python extension. I'm using distutils because it needs to be cross-platform, but if there's a better tool I'm open to suggestions.
Is there a way to make distutils first compile the sub-libraries, and link them in when ...
Python has syntactically sweet list comprehensions:
S = [x**2 for x in range(10)]
print S;
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
In PHP I would need to do some looping:
$output = array();
$Nums = range(0,9);
foreach ($Nums as $num)
{
$out[] = $num*=$num;
}
print_r($out);
to get:
Array
(
[0] => 0
[1] => 1
[2] => 4
...
I am in the final stretch of a project I have been working on. Everything is running smoothly but I have a bottleneck that I am having trouble working around.
I have a list of tuples. The list ranges in length from say 40,000 - 1,000,000 records. Now I have a dictionary where each and every (value, key) is a tuple in the list.
So, I...