python

Open web page with custom cookies in Python

Hi everyone. For example, I have cookies my_cookies = {'name': 'Albert', 'uid': '654897897564'} and I want to open page http://website.com opener = urllib2.build_opener(urllib2.HTTPCookieProcessor()) opener.addheaders.append(('User-agent', 'Mozilla/5.0 (compatible)')) opener.open('http://website.com').read() How I can do this with...

What cool hacks can be done using sys.settrace?

I love being able to modify the arguments the get sent to a function, using settrace, like : import sys def trace_func(frame,event,arg): value = frame.f_locals["a"] if value % 2 == 0: value += 1 frame.f_locals["a"] = value def f(a): print a if __name__ == "__main__": sys.settrace(trace_func) for i ...

What is the use of Python's basic optimizations mode? (`python -O`)

Python has a flag -O that you can execute the interpreter with. The option will generate "optimized" bytecode (written to .pyo files), and given twice, it will discard docstrings. From Python's man page: -O Turn on basic optimizations. This changes the filename exten‐ sion for compiled (bytecode) files from .pyc ...

How does ironpython speed compare to other .net languages?

Hi, I would like to give sources for what I'm saying but I just dont have them, it's something I heard. Once a programming professor told me that some software benchmarking done to .net vs Python in some particular items it gave a relation of 5:8 in favor of .NET . That was his argument in favor of Python not being so much slower than ...

X-Sendfile and VERY big files on Apache2

Any filesize over about 4GB is not going to work with the mod_xsendfile for Apache2 (as it sets the content length to a long). I am willing to rewrite it to support this; however, I can find no documentation on how to set content length from the apache api to something larger than a long and thus serve large files through Apache. I know...

Move or copy an entity to another kind

Is there a way to move an entity to another kind in appengine. Say you have a kind defines, and you want to keep a record of deleted entities of that kind. But you want to separate the storage of live object and archived objects. Kinds are basically just serialized dicts in the bigtable anyway. And maybe you don't need to index the arch...

Need a GUI Builder for Tkinter / Python

Hello, I need a GUI Builder for Tkinter... was using something a couple of years ago, but I can't find it anymore (I remember something related to Komodo IDE, but perhaps I'm wrong). Please don't give me links to non-functional, old or dead projects, because I found lots of them and none worked; I need something functional. Also, I don'...

Finding a logic bug in converting Python code to PHP

The input 7|12|1|14|2|13|8|11|16|3|10|5|9|6|15|4 returns 0 by the PHP -code, while 1 by Python code: 1 means that the sums of the 4x4 magic square are the same, while 0 means the reverse. Python code is correct. The problem of the PHP code seems to be in the function divide's for -loop, since PHP gives too many sums. How does the logi...

Getting the Current Table in Numbers (Python/Appscript)

How do I access the current table in Numbers using py-appscript? For posterity, the program I created using this information clears all the cells of the current table and returns the selection to cell A1. I turned it into a Service using a python Run Shell Script in Automator and attached it to Numbers. from appscript import * N...

Using md5 on BeautifulSoup result

Im trying to use the md5 algorithm on web pages to avoid seeing duplicates. Is there an easy way to convert the result from beautifulsoup into a string which is digestible by md5? Many thanks ...

Joomla and XMLRPC

How do I get started with getting going with XML-RPC with joomla? I've been looking around for documentation and finding nothing... I'd like to connect to a joomla server, (after enabling the Core Joomla XML-RPC plugin), and be able to do things like login and add an article, and tweak all the parameters of the article if possible. My ...

MapReduce, Python and NetworkX

I have implemented an unweighted random walk function for a graph that I built in Python using NetworkX. Below is a snippet of my program that deals with the random walk. Elsewhere in my program, I have a method that creates the graph, and I have a method that simulates various custom graph testing methods that I've written. One of these...

Reasons to prefer zope 3 over grok

I am familiar with zope 2 and think that zope 3 is superior in many ways, as far as I've used it (i.e. primarily with Five). Now I'm considering to dive deeper into zope 3. Would you recommend going even one step further and use grok instead, and if so, why? (and if not, why not? :) ...

Python XPath Result displaying only []

Hey I have just started to use Python recently and I want to use it with a bit of xPath, the thing is when I print the result of the query I only get [] and I don't know why =S import libxml2, urllib doc = libxml2.parseDoc(urllib.urlopen("http://www.domain.com/").read()) result = doc.xpathEval("//th//td[(((count(preceding-sibling:...

Set Selection in Numbers (Python/Appscript)

How do you set the selection for a table in Numbers using py-appscript? This seems like it should be really simple to do but the solution is frustratingly evasive. I can get the current selection: current_table.selection_range and I can get its cells: current_table.selection_range.cells() but trying to set() either of them gets...

Difference between ^ Operator in JS and Python

I need to port some JS code which involves Math.random()*2147483648)^(new Date).getTime(). While it looks like for smaller numbers, the python function and the JS function are equivalent in function, but with large numbers like this, the values end up entirely different. Python: 2147483647^1257628307380 =1257075044427 Javascr...

generating javascript string in python

i have string stored in python variables, and i am outputting a html that contains javascript, and the i need to create javascript variables. for ex, in python title = "What's your name?" i use Cheetah to generate the html. Cheetah code: var title = '$title'; how do i escape this correctly so that a correct javascript variable is ...

Secure Python intepreter?

Is there a secure Python intepreter? Imagine a Python VM you can run on your machine, that restricts the operations. No files can be opened, no system calls, etc. It just transforms stdin to stdout, maybe with text processing + math etc. Does such a secure Python VM exist? ...

How to percent-encode url parameters in python?

If I do url = "http://example.com?p=" + urllib.quote(query) It doens't encode "/" to "%2F" (breaks OAuth normalization) It doens't handle unicode (it throw an exception) is there a better library? ...

"".join(reversed(val)) vs val[::-1]...which is pythonic?

So according to the Zen of Python ... Explicit is better than implicit...Sparse is better than dense...Readability counts...but then again Flat is better than nested...so then which is pythonic? val = "which is pythonic?" print("".join(reversed(val))) or print(val[::-1]) I'm just a Java programmer learning Python so I find this py...