I want to convert a tuples list into a nested list using Python. How do I do that?
I have a sorted list of tuples (sorted by the second value):
[(1, 5), (5, 4), (13, 3), (4, 3), (3, 2), (14, 1), (12, 1),
(10, 1), (9, 1), (8, 1), (7, 1), (6, 1), (2, 1)]
Now I want it to have like this (second value ignored and nested in lists):
[...
I'm having difficulties parsing filepaths sent as arguments:
If I type:
os.path.normpath('D:\Data2\090925')
I get
'D:\\Data2\x0090925'
Obviously the \0 in the folder name is upsetting the formatting. I can correct it with the following:
os.path.normpath(r'D:\Data2\090925')
which gives
'D:\\Data2\\090925'
My problem is, how d...
Hello there!
If I have a Python class, and would like to call a function from it depending on a variable, how would I do so? I imagined following could do it:
class CallMe: # Class
def App(): # Method one
...
def Foo(): # Method two
...
variable = "App" # Method to call
CallMe.variable() # Calling App()
But it...
I'm trying to do some customization of a Trac project management website and have run into an interesting problem. The project has a set of images that are both SVG and PNG. The SVG images have numerous advantages including multiple hyperlinks and a smaller transmitted size against PNG which is bigger and can only link to a single docu...
I've been researching this on and off for a number of months now, but I am incapable of finding clear direction.
My goal is to have a page which has a form on it and a graph on it. The form can be filled out and then sent to the CGI Python script (yeah, I'll move to WSGI or fast_cgi later, I'm starting simple!) I'd like the form to be ...
I use regexps to transform text as I want, but I want to preserve the HTML tags.
e.g. if I want to replace "stack overflow" with "stack underflow", this should work as
expected: if the input is stack <sometag>overflow</sometag>, I must obtain stack <sometag>underflow</sometag> (i.e. the string substitution is done, but the
tags are sti...
I have a python module which contains a few objects, one of which uses a MySQL connection to persist some data. What's the best way to allow for easy configuration of the MySQL connection information without making the user go into the installed module location and edit files?
...
I am wring a small forensic app which looks like this so far
import time, os,sys
def getter():
filename = sys.argv[1]
print "File Entered: " + filename
os.system('file ' + filename)
print "\n"
pipe = os.popen("xxd " + filename, "r")
print pipe.read()
I input via the command line a file and it prints out the t...
Consider these two snippets:
try:
a+a=a
except SyntaxError:
print "first exception caught"
.
try:
eval("a+a=a")
except SyntaxError:
print "second exception caught"
In the second case the "second exception .." statement is printed (exception caught), while in the first one isn't.
Is first exception (lets call it "S...
I'm installing Django on Bluehost and one of the steps to install it was to install flup on their server. I did so and everything works great when I'm logged in via the SSH. However when I actually hit the page in my browser it can't find flup. I get this error in the server log:
ERROR: No module named flup. Unable to load the flup p...
Hi,
I am trying to remove a file after reading from it, but getting "WindowsError: [Error 32] The process cannot access the file because it is being used by another process"
file = open(self.filePath)
for line in file:
#do things
file.close()
os.remove(self.filePath) #throws error
os.rename(self.filePath, self.filePath + "old...
I'm working on writing a Python client for Direct Connect P2P networks. Essentially, it works by connecting to a central server, and responding to other users who are searching for files.
Occasionally, another client will ask us to connect to them, and they might begin downloading a file from us. This is a direct connection to the other...
The answers in this question didn't get to the heart of the problem. In a CLI-based Python program, I want the user to be able to edit a file and then return to the program. Before returning, I want them to be able to cancel their edits. This should feel like the commit-note-editing feature in Subversion.
What are the current best pract...
I have configured a proxy using proxyhandler and sent a request with some POST data:
cookiejar = cookielib.CookieJar()
proxies = {'http':'http://some-proxy:port/'}
opener = urllib2.build_opener(urllib2.ProxyHandler(proxies),urllib2.HTTPCookieProcessor(cookiejar) )
opener.addheaders = [('User-agent', "USER AGENT")]
urllib2.install_opene...
Hello all,
I am currently building a GUI based Python application on my mac and was wondering could anyone suggest a good GUI library to use?
I was looking at python's gui programming faq and there was a lot of options making it hard to choose.
I am developing on snow leopard and cross-platform is not essential (if it makes a differen...
I have the following PHP example code:
$client = new SoapClient("http://example.com/example.wsdl");
$h = Array();
array_push($h, new SoapHeader("http://example2.com/example2/", "h", "v"));
$client->__setSoapHeaders($h);
$s = $client->__soapCall('Op', $data);
My question: what's the SOAPpy equivalent for the SoapHeader() and __setSoa...
Hi Everyone,
I am trying to do this in my program:
dest = socket.gethostbyname(host)
I have included the line
from socket import *
in the beginning of the file
I am getting an Attribute Error that says:
AttributeError: type object
'_socketobject' has no attribute
'gethostbyname'
I really do not understand what I need to...
I found this utility, pytranslate, which translates a variety of languages into each other using Google's translation API. It works exactly as described.
However I've gotten sick of selecting a word I do not understand, then middle-clicking it into the command. The command format is as such:
pytranslate WORD
Is there a program/scrip...
Using python's optparse module I would like to add extra example lines below the regular usage output. My current help_print() output looks like this:
usage: check_dell.py [options]
options:
-h, --help show this help message and exit
-s, --storage checks virtual and physical disks
-c, --chassis checks specified chassis components...
I am currently working through the tutorial on Django's website. Upon completing the following command:
python manage.py startapp polls
it creates the following structure:
polls/
__init__.py
models.py
tests.py
views.py
As I was going through the tutorial it occurred to me that the views file could grow to this huge ...