I need to calculate the checksum of an IP packet as described in http://www.faqs.org/rfcs/rfc1071.html.
I have already the following code:
#!/usr/bin/python
import struct
data = "45 00 00 47 73 88 40 00 40 06 a2 c4 83 9f 0e 85 83 9f 0e a1"
# a test for the checksum calculation
def _checksum(data):
#calculate the header sum
i...
For code:
#!/usr/bin/python
src = """
print '!!!'
import os
"""
obj = compile(src, '', 'exec')
eval(obj, {'__builtins__': False})
I get output:
!!!
Traceback (most recent call last):
File "./test.py", line 9, in <module>
eval(obj, {'__builtins__': False})
File "", line 3, in <module>
ImportError: __import__ not found
Bot...
I always found links in html source stored in such format, the question is how do I change such links back to what it's normally like?
Thanks a lot!
...
hello there
i was wondering if it was possible to connect to a http host (I.e. for example google.com)
and download the source of the webpage?
Thanks in advance.
...
Given a Python compiled as a shared library, how do I determine the name and path of this library?
The output I'm looking for is like "/usr/local/lib/libpython2.7.so" or "/System/Library/Frameworks/Python.framework/Versions/2.6/Python" (for a framework build on OS X).
...
Hello,
I am new to the world of PyQt.I am using PyQt designer for designing the UI and coding to provide functionality in it.But unfortunately I am getting confused to link with the UI.By importing the class we generally doing in examples.But when I try my own code its not happening.
I guess I need better understanding to work with PyQt....
hello there
i wanted to know if it was possible to calculate the screen size of the user via python
this way i can make the program open up in the center of the screen because my tkinter window resize needs to know what coordinates (x and Y) to start the window on
Thanks a lot
...
I have been using the random function to generate color values xi = [a, b, c] where a, b, and c can be any number from 0 to 255.
I need ideas to write a function that generate x values as different as possible for the human eye. One of the problems I am having is that I don't know the number of x elements that will be generated. So my p...
hello there
i am making a text editor in Tkinter (python)
and so i made a menu and wanted to know how i can call a function that will display the windows Save-as or open boxes that every program uses.
For example in notepad you can click file-save and then it opens the windows save box.
I already have the menu but how can i open the sav...
Possible Duplicate:
How do you split a list into evenly sized chunks in Python?
mylist = [1, 2, 3, 4, 5, 6, 7, 8, 9]
I need to pass blocks of these to a third party API that can only deal with 4 items at a time. I could do one at a time but it's a HTTP request and process for each go so I'd prefer to do it in the lowest poss...
I want to add a context variable in Django, so that I could define its value on per-application basis, or leave it empty.
Example:
apps/someapp/views.py:
def_context_var('app_name', 'Calendar')
templates/base.html:
{% if app_name %}You are in {{ app_name }} app.{% endif %}
....
{% if app_name %}Subsections of {{ app_name }}: ...{%...
Using Python and Pythonwin, how do i get python to answer true or yes to dialogs boxes.
xl = Dispatch("Excel.Application")
xl.Visible = 1
xl.Workbooks.Open("C:\pyVBA.xls", True, True)
xl.Run("pyVBA.xls!Macro1")
If pyVBA has macro1 has a yesno dialog box (which is fine if visible = 1, but not if visible is = 0), how do...
Is there a way to change python2.x source code to python 3.x manually. I guess using lib2to3 this can be done but I don't know exactly how to do this ?
...
Hello.
I want to copy an installer file from a location where one of the folder names changes as per the build number
This works for defining the path where the last folder name changes
import glob
import os
dirname = "z:\\zzinstall\\*.install"
filespec = "setup.exe"
print glob.glob (os.path.join (dirname, filespec))
# the print...
Hi! I'm using Django / Python. After saving the model I want to make a screenshot (preview) of how it looks in the template and save it on model field. Please tell me how to do it.
...
Possible Duplicate:
What do I use for a max-heap implementation in Python?
Python has a min heap implemented in the heapq module. However, if one would want a max heap, would one have to build from scratch?
...
Is there is a simple, pythonic way of rounding to the nearest whole number without using floating point? I'd like to do the following but with integer arithmetic:
skip = int(round(1.0 * total / surplus))
==============
@John: Floating point is not reproducible across platforms. If you want your code to pass tests across different p...
I know try/except can handle errors in my program.
But, is there a way of making the error be displayed in the program execution, be ignored and let the execution go on?
...
I'm trying to use this python script to upload a file to the w3c validator.
~/Desktop/urllib2_file$ python test-upload.py -u http://validator.w3.org/ -f ../index.php -n uploaded_file -p Content-Type=text/html > ../results.html && firefox ../results.html
Any help will be greatly appreciated!
EDIT:
cyraxjoe pointed out I needed to run...
I have a Python application that, to be brief, receives data from a remote server, processes it, responds to the server, and occasionally saves the processed data to disk. The problem I've encountered is that there is a lot of data to write, and the save process can take upwards of half a minute. This is apparently a blocking operation, ...