I'm trying to work out if there is a better way to achieve the following:
from lxml import html
from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup("<p>£682m</p>")
text = soup.find("p").string
print text
>>> £682m
print html.fromstring(text).text
>>> £682m
So I'm trying to produce the same string that lxml retu...
Some useful Python packages are broken on pypi, and the only acceptable version is a particular revision in a revision control system. Can that be expressed in setup.py e.g
requires = 'svn://example.org/useful.package/trunk@1234' ?
...
I am trying to develop a Facebook application using PyFacebook (hosted on Google App Engine). It's an FBML application (runs in a Facebook canvas instead of an iframe). I'm having problems getting any API calls to function. The sequence looks like this:
fb = facebook.Faceboook(api_key, secret_key)
fb.session_key = cherrypy.request.pa...
Hello,
I have a program that logs into a server and issues commands. The results are printed out at the end of the script. The below code shows the script I have created to pass commands through ssh.
import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
# my ssh command line
p=pexpect.spawn('ssh [email protected]')...
I want to know if a function is defined for an instance of a class
class c(object):
def func(self): pass
cc = c()
>>> is_function_defined_for_instance(cc,'func')
True
>>> is_function_defined_for_instance(cc,'cnuf')
False
my cleanest attempts at the function is:
def is_function_defined_for_instance(instance,function):
return call...
I have a written a Python module which due to its specifics needs to have a MySQL database connection. Right now, details of this connection (host, database, username and password to connect with) are stored in /etc/mymodule.conf in plaintext, which is obviously not a good idea.
Supposedly, the /etc/mymodule.conf file is edited by the r...
If I have a python function like so:
def some_func(arg1, arg2, arg3=1, arg4=2):
Is there a way to determine which arguments were passed by keyword from inside the function?
EDIT
For those asking why I need this, I have no real reason, it came up in a conversation and curiosity got the better of me.
...
iI am trying to write a recursive code that can convert a number to any base system. for example, the interger 10 into binary would convert to 1010
so far i have this but i'm having "None" in between my output. Can anyone help me with my code?
def convert(a,b):
add = a%b
if a<=1:
return a
else:
print(base(a/...
I'm trying to install said library for use with Python. I tried downloading the executable installer for Windows, which runs, but says it doesn't find a Python installation. Then tried registering (http://effbot.org/zone/python-register.htm) Python, but the script says it can't register (although the keys appear in my register).
Then I ...
I'm running pdb on my testcases in Python through the gud buffer. When I get a stacktrace/failure in my testcase, it looks like this:
FAIL: test_foo_function (__main__.TestFoo)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/testfoo.py", line 499, in test_foo_functi...
I was kindly directed to use GObject's "add_emission_hook" following a recent question on SO but I can't seem to find a usage example.
Does anyone have one to share, please?
...
Hi all,
I'm looking for a good library that will integrate stiff ODEs in Python. The issue is, scipy's odeint gives me good solutions sometimes, but the slightest change in the initial conditions causes it to fall down and give up. The same problem is solved quite happily by MATLAB's stiff solvers (ode15s and ode23s), but I can't use it...
From
Whats the java equivalent of Python’s urllib.urlencode?
Like
>>> urllib.urlencode({'abc':'d f', 'def': '-!2'})
'abc=d+f&def=-%212'
Where I can pass a HashMap of key values and it encodes and gives me the url string ..
Edit: I wanted to avoid this scenario
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.en...
When I run the following from a bash shell on my Mac:
$ file /usr/bin/python
I get the following three lines:
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc
this would see...
Hello,
Using boost build, if I can link to a boost python library with this in my jamfile:
project myProject : requirement
/boost/python//boost_python ;
how can I link to boost test? I have built the boost test library.
I don't want to use file paths since my code is portable. Thanks...
I really need upload files bigger that 1 Mb, so i only have the Blobstore API. But any use it in production? know any issue or problems?
...
I assumed sorting a CSV file on multiple text/numeric fields using Python would be a problem that was already solved. But I can't find any example code anywhere, except for specific code focusing on sorting date fields.
How would one go about sorting a relatively large CSV file (tens of thousand lines) on multiple fields, in order?
Py...
I want to install python to my local direcotory:
./configure --prefix=/home/alex/local-install && make && make install
When i import sqlite3 i get the following:
ImportError: No module named _sqlite3
the reason: there is no _sqlite3.so in /home/alex/local-install/lib/python2.6/lib-dynload.
How can i force python to build bindings ...
I am using Bazaar v2.0.1 on Max OS X 10.6.2
When I perform a commit after moving a large number of files/directories (over 10,000) I get the following error message:
bzr: ERROR: [Errno 24] open: Too many
open files: '.'
My first work-around was to break the commit up into several sub-sets. However, this is not ideal and I'm afr...
How do I set the timezone of a datetime instance that just came out of the datastore?
When it first comes out it is in UTC. I want to change it to EST.
I'm trying, for example:
class Book( db.Model ):
creationTime = db.DateTimeProperty()
When a Book is retrieved, I want to set its tzinfo immediately:
book.creationTime.tzinfo =...