python

Python - Function has a list as argument. How to return another list without changing the first?

I'm pretty new in Python (and programming as a whole). I'm pretty sure the answer to this is obvious, but I really don't know what to do. def do_play(value, slot, board): temp=board (i,j) = slot temp[i][j] = value return temp board is a list of lists. value is an integer. slot is and integer tuple. What I am trying to...

Python: How to export Sympy image to png?

Python: How to export Sympy image to png? Who has any idea with this? ...

Creating a custom file like object python suggestions?

Hi i am looking to implement my own custom file like object for an internal binary format we use at work(i don't really want to go into too much detail because i don't know if i can). I am trying to go for a more pythonic way of doing things since currently we have two functions read/write(each ~4k lines of code) which do everything. How...

not None test in Python

Out of three not None test. if val != None: if not (val is None): if val is not None: Which is preferable, and why? ...

rotating the tires in a car (open gl)

Based on the answer i got for the same question earlier, i changed my code, as per the homework i had to use glmultmatrix. But this is not working. Here is the code, what i am doing is that i translate the center of tire to the center of car, rotate the tire, and then translate back. But it is not placing back the tire where it should be...

Nested SELECT queries sometimes stall.

I've been using sqlite3 in a python application, and when testing it, my queries sometimes cause the program to freeze up. A rough (from memory) example: SELECT id,name FROM main_table WHERE name IN (SELECT name FROM another_table WHERE another_table.attribute IN ('foo', 'bar', 'baz')) Often, the first time I attempt something like...

Generate html files from MySQL data with file names as function paramater names from MySQL categories?

Hi all. So building on my question posted here http://stackoverflow.com/questions/3951716/using-python-to-write-to-html-file-with-mysql-data-as-source I have worked out how to do that although a bit different to the answers. Now my question is related to how to create html files from the data stored in MySQL, using the Category names fro...

NetworkX (Python): how to change edges' weight by designated rule

I have a weighted graph: F=nx.path_graph(10) G=nx.Graph() for (u, v) in F.edges(): G.add_edge(u,v,weight=1) get the nodes list: [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)] I want to change each edge's weight by this rule: remove one node, such as node 5, clearly, edge (4, 5) and (5, 6) will be del...

Integrating Pyjamas with Pinax+Django?

I'm going to start looking into this tomorrow when I begin my project, but could anyone point me in the right direction? (Maybe some integration code and/or a sample Pyjamas interface which uses Pinax as the backend -- all with adequate explanation, if possible? :) Thanks! ...

method signature for jacobian func in scipy leastsq

Hi, Can anyone provide an example of providing a jacobian to a leastsq function in scipy? ( http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.leastsq.html#scipy.optimize.leastsq ) I can't figure out the method signature they want - they say it should be a function, yet it's very hard to figure out what input parameter...

about python list step issue when the element is long type

In [2]: list=range(627) In [3]: list[::150] Out[3]: [0, 150, 300, 450, 600] the above code is right,but if i use the bellow code,caution:the l means long type, the return result is not like above,what's the hell? In [4]: list=[1323l,123123l,4444l,12312312l] In [5]: list=[1323l,123123l,4444l,12312312l] In [6]: list[::2] Out[6]: [13...

How come there's no C# equivalent of python's doctest feature?

Seems like it would be a good way to introduce some people to unit testing. ...

Create a function in Python which creates a mySQL database

Hi, I've created a program in python and mySQL which creates a database and imports the data from text files and puts them into 4 different columns. The code works but I want to change the code and create functions. Can anyone please help me create a function that creates a mySQL database? Here is the code I have at the moment. Thanks ...

Nltk installation

Hi In want to setup python's nltk library including wordnet in such a way that it can be easily copied from development system to production server, without having requirement for downloading wordnet separately. Any suggestion would be helpful... ...

Using Python's re to swap case.

I'm using the re library to normalize some text. One of the things I want to do is replace all uppercase letters in a string with their lower case equivalents. What is the easiest way to do this? ...

SciPy's non-linear least square

Dear All. I tried to do bundle adjustment by python. So I'm test non-linear least square module. Then I wrote code like below. I want to get right Pmat represents camera projection matrix for three cameras. But I have an error,"ValueError: object too deep for desired array". Anyone who can give clue to solve this issue? Regards, ...

How to approach web app development?

Hi, I have been going through Flask and it seems that now I have a decent understanding to go ahead and build a web application. However I want to know how would I approach the problem. For eg: I decide to build a blogging application. The first thing I do is write down all the things that come to my mind, from user registrations to pos...

How to update 400k rows on a production MySQL db and don't kill it

On our production server we need to split 900k images into different dirs and update 400k rows (MySQL with InnoDB engine). I wrote a python script which goes through next steps: Select small chunk of data from db (10 rows) Make new dirs Copy files to the created dirs and rename it Update db (there are some triggers on update which will...

How to do a multi-level CLI in Python?

Hi I'm trying to do a CLI, preferrably written in Python. I need a multi-level CLI, and I want tab completion. I looked at the cmd module (from the Python standard library) and readline with the "complete" function (for tab completion). They both lacked at something, i.e. I haven't figured out how to handle multiple levels such as: l...

how to use python list comprehensions replace the function invoke inside of "for" stmt?

Sorry, I just found the id = [conn.cursor() for x in range(100) ] also works, so my concern will not be a problem anymore. Thanks for all of your answer, all of you are really fast. ===================== All, id = [(conn.cursor(),x) for x in range(100) ] >>> id [(<sqlite3.Cursor object at 0x01D14DA0>, 0), (<sqlite3.Cursor object ...