I'd like to know if the following situation and scripts are at all possible:
I'm looking to have a photo-gallery (Javascript) webpage that will display in order of the latest added to the Dropbox folder (PHP or Python?).
That is, when someone adds a picture to the Dropbox folder, there is a script on the webpage that will check the D...
I'm making a 2D list and I would like to initialize it with a list comprehension. I would like it to do something like this:
[[x for i in range(3) if j <= 1: x=1 else x=2] for j in range(3)]
so it should return something like:
[[1,1,1],
[1,1,1],
[2,2,2]]
How might I go about doing this?
Thanks for your help.
...
Is there a way to halt the parsing from inside a content handler? Or is throwing an exception the only way?
Note that I am using xml.sax.parseString.
...
def getStuff(x):
return 'stuff'+x
def getData(x):
return 'data'+x
thefunctions = []
thefunctions.append("getStuff")
thefunctions.append("getData")
for i in thefunctions:
print i('abc')
Is this possible? Thank you.
...
Is there an elegant way of skipping first line of file when using python fileinput module?
I have data file with nicely formated data but the first line is header. Using fileinput I would have to include check and discard line if the line does not seem to contain data.
The problem is that it would apply the same check for the rest of t...
I came across the following header format for Python source files in a document about Python coding guidelines:
#!/usr/bin/env python
"""Foobar.py: Description of what foobar does."""
__author__ = "Barack Obama"
__copyright__ = "Copyright 2009, Planet Earth"
Is this the standard format of headers in the Python world?
What oth...
How can I add, subtract, and compare binary numbers in Python without converting to decimal?
...
My current .vimrc configuration is below:
set nohlsearch
set ai
set bg=dark
set showmatch
highlight SpecialKey ctermfg=DarkGray
set listchars=tab:>-,trail:~
set list
autocmd BufRead *.py set smartindent cinwords=if,elif,else,for,while,try,except,finally,def,class
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartinden...
Hi,
I am trying to work on a dev environment but am find problems in that python seems to be using modules from the site-packages directory. I want it to be using the modules from my dev directory.
sys.path returns a bunch of dirs, like this
['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib...
Sorry about the odd title.
I am using eSearch & eSummary to go from
Accession Number --> gID --> TaxID
Assume that 'accessions' is a list of 20 accession numbers (I do 20 at a time because that's the maximum that NCBI will allow).
I do:
handle = Entrez.esearch(db="nucleotide", rettype="xml", term=accessions)
record = Entrez.read(ha...
I am constructing a table of routes in my Pylons app. I can't get redirect() to work the way that it should work. I'm not sure what I'm doing wrong.
Here is an example of redirect() usage from the Routes documentation:
map.redirect("/home/index", "/", _redirect_code="301 Moved Permanently")
Here is what appears in my routing.py f...
This is what my code looks like:
url_object = urlparse(url)
hostname = url_object.hostname
port = url_object.port
uri = url_object.path if url_object.path else '/'
ctx = SSL.Context()
if ctx.load_verify_locations(cafile='ca-bundle.crt') != 1: raise Exception("Could not load CA certificates.")
ctx.set_verify(SSL.verify_peer | SSL.verify...
In PHP, I can do this:
echo '<pre>'
print_r($array);
echo '</pre>'
In Python, I currently just do this:
print the_list
However, this will cause a big jumbo of data. Is there any way to print it nicely into a readable tree? (with indents)?
...
What is the simplest way to create this list in Python?
First, suppose I have this nested list:
oldList = [ [{'letter':'a'}], [{'letter':'b'}], [{'letter':'c'}] ]
I want a function to spit out:
newList = [ {'letter':a}, {'letter':'b'}, {'letter':'c'} ]
Well, this could be done manually. However, what if there are three nested? ......
I've been looking really hard at all of the way**(s)** one can develop web applications using Python. For reference, we are using RHEL 64bit, apache, mod_wsgi.
History:
PHP + MySQL years ago
PHP + Python 2.x + MySQL recently and current
Python + PostgreSQL working on it
We use a great library for communicating between PHP and Pytho...
I have an open source project containing both Python and C code. I'm wondering that is there any use for distutils for me, because I'm planning to do a ubuntu/debian package. The C code is not something that I could or want to use as Python extension. C and Python programs communicate with TCP/IP through localhost.
So the bottom line he...
Suppose I have a integer matrix which represents who has emailed whom and how many times. For social network analysis I'd like to make a simple undirected graph. So I need to convert the matrix to binary matrix and later into a list of tuples.
My question: is there a fast, convenient way to reduce the decimal matrix to a binary matrix. ...
This is similar to http://stackoverflow.com/questions/1523660/how-to-print-a-list-in-python-nicely, but I would like to print the list even more nicely -- without the brackets and apostrophes and commas, and even better in columns.
foolist = ['exiv2-devel', 'mingw-libs', 'tcltk-demos', 'fcgi', 'netcdf',
'pdcurses-devel', 'msvcr...
thelist = ['a','b','c','d']
What's the best way to scramble them in Python?
...
Suppose I have this code in Python:
l = dict['link']
t = dict['title'] <<<<<<<<error here, there is no "title"
d = dict['description']
k = dict['keyword']
What if there is an error on line 2, but I want it to continue running the script and assign the other values? Can I just "ignore" the errors?
EDIT: I know how to do a simp...