Im trying to grab all data(text) coming from a URL which is constantly sending text, I tried using PHP but that would mean having the script running the whole time which it isn’t really made for (I think). So I ended up using a BASH script.
At the moment I use wget (I couldn’t get CURL to output the text to a file)
wget --tries=0 --ret...
I read somewhere that functions should always return only one type
so the following code is considered as bad code:
def x(foo):
if 'bar' in foo:
return (foo, 'bar')
return None
I guess the better solution would be
def x(foo):
if 'bar' in foo:
return (foo, 'bar')
return ()
Wouldn't it be cheaper memory wise to return a None ...
I'm writing a web app using python with web.py, and I want to implement my own logging system. I'd like to log detailed information about each request that come to python (static files are handled by web servers).
Currently I'm thinking about writing the logs to a pipe. On the other side, there should be cronolog.
My main concern is th...
I have a vector consisting of a point, speed and direction. We will call this vector R. And another vector that only consists of a point and a speed. No direction. We will call this one T.
Now, what I am trying to do is to find the shortest intersection point of these two vectors. Since T has no direction, this is proving to be difficult...
Hello,
I am working on a site in Python built on the back of Django(awesome framework, cant get my head around python), I looking to split a string that is returned from a database and I want it to be split when the first space occurs so I tried something like this,
{{product.name.split(' ' ,1)}}
This did not work and I get this st...
I've always set up metaclasses something like this:
class SomeMetaClass(type):
def __new__(cls, name, bases, dict):
#do stuff here
But I just came across a metaclass that was defined like this:
class SomeMetaClass(type):
def __init__(self, name, bases, dict):
#do stuff here
Is there any reason to prefer one ...
I have the following chunk of python code:
import hashlib
class User:
def _set_password(self, value):
self._password = hashlib.sha1(value).hexdigest()
def _get_password(self):
return self._password
password = property(
fset = _set_password,
fget = _get_password)
def __init__(self, user...
Hello
I'm trying to understand how certificate and asymmetric encryption works. I'm looking for a python library where i can import public or private ca signed certificates and automatically encrypt or decrypt message in string format, i viewed the crypto library embedded in python source, but i don't know how to use the hex modulus and ...
I have been trying to get information regarding expired ssl certificates using python 3 but it would be nice to be able to get as verbose a workup as possible. any takers?
So far i have been trying to use urllib.request to get this info (to no avail), does this strike anyone as foolish?
I have seen some examples of similar work using o...
I'm trying to write a heavily email-based application in the Python SDK of Google App Engine. I've noticed that Google allows you to receive email via its API, and that it easily gives you access to the standard fields like From, To, Body, etc. However, if I'm trying to verify that an email address came from who it said it came from (kin...
EDIT:
This question is invalid. Turns out a transparent proxy was making an onward HTTP 1.0 request even though urllib/httplib was indeed making a HTTP 1.1 request originally.
ORIGINAL QUESTION:
By default urllib2.urlopen always makes a HTTP 1.0 request.
Is there any way to get it to talk HTTP 1.1 ?
...
If I make two lists of functions:
def makeFun(i): return lambda: i
a = [makeFun(i) for i in range(10)]
b = [lambda: i for i in range(10)]
why the lists a and b are not equal?
For example:
>>> a[2]()
2
>>> b[2]()
9
...
I am creating a program that reads a file and if the first line of the file is not blank, it reads the next four lines. Calculations are performed on those lines and then the next line is read. If that line is not empty it continues. However, I am getting this error:
ValueError: invalid literal for int() with base 10: ''.`
It is re...
When I use urllib2 to make a HTTP 1.1 connection via a squid proxy, squid makes a new ongoing connection in HTTP 1.0.
How can I persuade Squid to talk 1.1 to the destination server?
...
Problem Specification:
Given a directory, I want to iterate through the directory and its non-hidden sub-directories,
and add a whirlpool hash into the non-hidden
file's names.
If the script is re-run it would would replace an old hash with a new one.
<filename>.<extension> ==> <filename>.<a-whirlpool-hash>.<e...
PythonCE is a Python port for Windows CE and Windows Mobile. I'm currently working on a project that uses Bluetooth (actually PyBluez) to communicate with a remote device. My project works on Windows, Linux and Mac. The only problem I have porting it to Windows CE or Windows Mobile devices is that I don't know of any Bluetooth library th...
What is the best way to organize scraped data into a csv? More specifically each item is in this form
url
"firstName middleInitial, lastName - level - word1 word2 word3, & wordN practice officeCity."
JD, schoolName, date
Example:
http://www.examplefirm.com/jang
"Joe E. Ang - partner - privatization mergers, media & technology...
I'm using the trick "python -c 'import myscript.py'" to perform a syntax check on a script which uses 'import gtk'.
I get the following error when performing the syntax check, which implies that the gtk module is executing a check for the X display, even though all that's being done at this point is to import the module.
Traceback (mos...
I have a script that acts as a wrapper for some unit tests written using the Python unittest module. In addition to cleaning up some files, creating an output stream and generating some code, it loads test cases into a suite using
unittest.TestLoader().loadTestsFromTestCase()
I am already using optparse to pull out several command-li...
I've never used python before. I've used php for about 5 years now. I plan to learn python, but I'm not sure what for yet. If I can think of a project that might be better to do in python, I'll use that to learn it.
Edit: just to add this as an important note, I do mean strictly for linux, not multi-platform.
Edit 2: I'm hoping for obje...