How to Round Up to the Nearest Quarter in Python
Sunday, August 22nd, 2010This seems to work for me:
math.ceil(val*4)/4
Archive for the ‘Python’ CategoryHow to Round Up to the Nearest Quarter in PythonSunday, August 22nd, 2010This seems to work for me: XMLRPC Server Slow in Python – How to FixFriday, February 19th, 2010Background: Problem and Solution: Below is a simple fix that solved the problem for me (in Python 2.4). This would probably work in future versions too. Assume this is your basic XMLRPC Server set up in Python:
import SimpleXMLRPCServer
class FuncGroup:
"""Just hold the funcs to be used in web service"""
def hi(self,val):
return "hi there"
#create server and start it
server_address = ('localhost',8000) # (address, port)
server = SimpleXMLRPCServer.SimpleXMLRPCServer(server_address)
server.register_instance(FuncGroup()) #reg. functions/class instance
server.serve_forever()
—
import SimpleXMLRPCServer
#new code
import BaseHTTPServer
def not_insane_address_string(self):
host, port = self.client_address[:2]
return '%s (no getfqdn)' % host #used to call: socket.getfqdn(host)
BaseHTTPServer.BaseHTTPRequestHandler.address_string = \
not_insane_address_string
#end new code
class FuncGroup:
"""Just hold the funcs to be used in web service"""
def hi(self,val):
return "hi there"
#create server and start it
server_address = ('localhost',8000) # (address, port)
server = SimpleXMLRPCServer.SimpleXMLRPCServer(server_address)
server.register_instance(FuncGroup()) #reg. functions/class instance
server.serve_forever()
— Making py2exe Work with ParamikoFriday, June 26th, 2009When running py2exe with a script importing Paramiko I noticed this in the output:
And then in the log file created when I run the exe I saw this: Traceback (most recent call last): ... ImportError: No module named paramiko This has to do with py2exe not being able to handle egg files. So what I did is pulled out the paramiko directory from the egg, and placed that in my site-packages directory, and then deleted the egg. It works now though the setup function still tells me this:
Luckily as far as I can tell, I don’t use those modules anywhere. This guy had the same problem and Tips for Using the Paramiko SFTP ClientFriday, June 19th, 2009The Paramiko library seems to be the best way to do an SFTP client in Python. Here is a good example of set up and usage. However in connecting to a WS FTP server, I was still hitting some problems. When I tried to do:
I got:
and when I tried:
I got:
It turns out the trick for working with WS FTP Server, you need to reference your files as current_directory/filename. (no idea why!) So the correct command is:
where PyCrypto – Fixing Setup script exited with error: The .NET Framework SDK needs to be instal led before building extensions for PythonThursday, June 18th, 2009So here’s this horrible thing that happening to me when trying to install Paramiko on Windows XP: C:\Documents and Settings\gpinero>easy_install paramiko Searching for paramiko Best match: paramiko 1.7.4 Processing paramiko-1.7.4-py2.4.egg paramiko 1.7.4 is already the active version in easy-install.pth Using c:\python24\lib\site-packages\paramiko-1.7.4-py2.4.egg Processing dependencies for paramiko Searching for pycrypto>=1.9 Reading http://pypi.python.org/simple/pycrypto/ Reading http://pycrypto.sourceforge.net Reading http://www.amk.ca/python/code/crypto Best match: pycrypto 2.0.1 Downloading http://www.amk.ca/files/python/crypto/pycrypto-2.0.1.tar.gz Processing pycrypto-2.0.1.tar.gz Running pycrypto-2.0.1\setup.py -q bdist_egg --dist-dir c:\docume~1\gpinero\loca ls~1\temp\easy_install-gpdsc5\pycrypto-2.0.1\egg-dist-tmp-8dcze9 error: Setup script exited with error: The .NET Framework SDK needs to be instal led before building extensions for Python. I heard it’s a bear to install the .NET framework SDK, and supposedly the install still won’t work. So what you do instead is download this prebuilt pycrypto binary from here, and install it. |