python

Load c++ memory file into Python

I have a file that in C++ I load into array using below code: int SomeTable[10000]; int LoadTable() { memset(SomeTable, 0, sizeof(SomeTable)); FILE * fin = fopen("SomeFile.dar", "rb"); size_t bytesread = fread(SomeTable, sizeof(SomeTable), 1, fin); fclose(fin); } The file is binary code of 10000 integers, so in C++ i...

Problem porting sudoku solver from C to Python

I recently wrote a sudoku solver in C to practice programming. After completing it I decided to write an equivalent program in Python for a comparison between the languages and more practice and this is where the problem is. It seems to be that a global variable (sudokupossibilities[][][]) I declared outside the while loop isn't availabl...

How can I specify the client's data port for a ftp server in active mode?

I use python ftplib to connect to a ftp server which is running on active mode; That means the server will connect my client machine on a random port when data is sent between us. Considering security issue, Can I specify the client's data port (or port range) and let the server connect the certain port? Many Thanks for your response....

error on localhost

hey, when i'm going to login i got the following error Traceback (most recent call last): File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3199, in _HandleRequest self._Dispatch(dispatcher, self.rfile, outfile, env_dict) File "C:\Program Files\Google\google_appengine\google\appengin...

ValueError: invalid literal for int(): Screw plugg (91_10 -> untitled) in python

hi, i have form = self.request.form partintid = int(form['item_01bom']) # value is 'Screw plugg (91_10 -> untitled)' print partintid i want to convert 'Screw plugg (91_10 -> untitled)' to int. but i get ValueError: invalid literal for int(): Screw plugg (91_10 -> untitled). ...

Returning only No. of Google Search Results via Python

I wish to return only the number of google search results for a particular keyword in the fastest manner possible, avoiding (keeping to minimum) the use of third party libraries. I have already considered xgoogle. ...

Is there Python Clang wrapper in the vein of pygccxml which wraps GCC-XML?

For a long time now I've been using pygccxml to parse and introspect my C++ source code: it helps me to do some clever code-generation during our build process. Recently I've read a lot about the benefits of the LLVM stack, and especially the benefits that the LLVM Clang parser brings to C++ compilation. I am now wondering if there is ...

How to simulate clicks on <a href="javascript:dosomething(12345)">text</a> using python?

I want to simulate such clicks without controlling web browsers to do the job. I don't know much about javascript and actually don't know where to start. Any ideas? ...

What is the best way to change python object into XML?

I've tried lxml and eventually had to write the whole code for saving object as xml which isn't perfect. I suppose there is a neat way to do it but I just can't find it. I'm looking for something more like pyxser. Unfortunately pyxser xml code looks different from what I need. For instance I have my own class Person Class Person: ...

Web server - ns2 middleware (in Python)

Hi Developers, I want to integrate ns2 with a web server to show some kind of simulation results. Could anyone plz suggest if there's any middleware for this purpose? Google failed to return me any suitable result for this :( Also, if I plan to develop a middleware from scratch for the same purpose, is there any guideline to follow? In...

Capturing event of client disconnecting! - Gevent/Python

Hi folks, I'm using long polling for a chat with gevent. I'm using Event.wait() when waiting for new messages to be posted on the chat. I would like to handle the occasion a client disconnects with some functionality: e.g. Return "client has disconnected" as a message for other chat users Is this possible? =) ...

python: urllib2 how to send cookie with urlopen request

Hi, I am trying to use urllib2 to open url and to send specific cookie text to the server. E.g. I want to open site Solve chess problems, with a specific cookie, e.g. search=1. How do I do it? I am trying to do the following: import urllib2 (need to add cookie to the request somehow) urllib2.urlopen("http://chess-problems.prg") Tha...

Mysql connection with python in a class

i'm trying to connect to a database building a class connection()saved in local folder in file utils.py .This is what i worked so far of it: class connection: def __init__(self): self.conn = MySQLdb.connect(host = "localhost",user = "xxx", passwd = "xxx", db = "xxx", ...

Get the current value of env.hosts list with Python Fabric Library

Hello, I've got this code (foo and bar are local servers): env.hosts = ['foo', 'bar'] def mytask(): print(env.hosts[0]) Which, of course prints foo every iteration. As you probably know, Fabric iterates through the env.hosts list and executes mytask() on each of them this way: fab mytask does task is executed on foo task is...

TypeError when iterate over DiGraph()

Hii! I want to get the time execution of my function ( test(G) ). when I use Timer I need to write the type of my object : "test(% ?? )" %G which is DiGraph here. How can I do that? from networkx import nx def test(G): for e in G.edges_iter(): print(e) if __name__=='__main__': from timeit import Timer G = nx.DiGrap...

Python - urllib2.urlopen - Why do I get garbled characters?

Here's my problem: import urllib2 response=urllib2.urlopen('http://proxy-heaven.blogspot.com/') html=response.read() print html It's just this site, and I don't know why the result is all garbled characters. Anyone can help? ...

Embed text into PNG

I'm looking for a tool that'd let me embed json-formatted information inside a PNG -file. This far it's been quite quiet. Do I have to write it myself? I'd be especially interested of doing it with javascript. Into an image I extract from a canvas with toDataURL -method. ...

Python access parent object instances

I'm currently trying to write a multiple-file Python (2.6.5) game using PyGame. The problem is that one of the files, "pyconsole.py", needs to be able to call methods on instances of other objects imported by the primary file, "main.py". The problem is that I have a list in the main file to hold instances of all of the game objects (pl...

Are object literals Pythonic?

JavaScript has object literals, e.g. var p = { name: "John Smith", age: 23 } and .NET has anonymous types, e.g. var p = new { Name = "John Smith", Age = 23}; // C# Something similar can be emulated in Python by (ab)using named arguments: class literal(object): def __init__(self, **kwargs): for (k,v) in kwargs.iter...

How to check if a MySQL connection is closed in Python?

The question says everything. How can I check if my MySQL connection is closed in Python? I'm using MySQLdb, see http://mysql-python.sourceforge.net/ ...