python

Permission django admin interface

Hi all, I followed this tutorial: http://stackoverflow.com/posts/1348076/revisions Afterwards i made a user guest with permission 'Can view test' in the admin interface. When i did that it was only possible to see 'test' but not click on it and see it's actual data... so basicly i couldn't view the data from my model 'test' by only per...

Why is iPdb not displaying STOUT after my input?

I can't figure out why ipdb is not displaying stout properly. I'm trying to debug why a test is failing and so I attempt to use ipdb debugger. For some reason my Input seems to be accepted, but the STOUT is not displayed until I (c)ontinue. Is this something broken in ipdb? It makes it very difficult to debug a program. Below is an ex...

List of dict in Python

Hi everybody, I've got a list of dict in Python: dico_cfg = {'name': entry_name, 'ip': entry_ip, 'vendor': combo_vendor, 'stream': combo_stream} self.list_cfg.append(dico_cfg) I append to my list a lot of dict in the same way. Now I would like to delete one dict and only one dict in this list? What is the best way to proceed? I've ...

Python: Most efficient way to concatenate and rearrange files

Hi, I am reading from several files, each file is divided into 2 pieces, first a header section of a few thousand lines followed by a body of a few thousand. My problem is I need to concatenate these files into one file where all the headers are on the top followed by the body. Currently I am using two loops; one to pull out all the h...

Need to understand Python signals and modules

I am trying to get up to speed with Python, trying to replace some C with it. I have run into a problem with sharing data between modules, or more likely my understanding of the whole thing. I have a signal module which simplified is: import sys, signal sigterm_caught = False def SignalHandler(signum, stackframe): if signum == signa...

Convert or strip out "illegal" Unicode characters

I've got a database in MSSQL that I'm porting to SQLite/Django. I'm using pymssql to connect to the database and save a text field to the local SQLite database. However for some characters, it explodes. I get complaints like this: UnicodeDecodeError: 'ascii' codec can't decode byte 0x97 in position 1916: ordinal not in range(128) Is ...

Python: Convert a string to an integer

Does anybody have a quickie for converting an unsafe string to an int? The string typically comes back as: '234\r\n' or something like that. In this case I want 234. If '-1\r\n', I want -1. I never want the method to fail but I don't want to go so far as try, except, pass just to hide errors either (in case something extreme happens)....

How can I use the AppEngine::Datastore api's in JRuby like in python?

So in python I would do something like this: from google.appengine.ext import db class Thing(db.Model): name = db.StringProperty() In ruby how would I do this using the AppEngine::Datastore libs? The reason I ask this is because I'm hitting some hard walls using the Datamapper adapter and so I plan on just using the AppEngine ap...

python urllib2.openurl doesn't work with specific URL (redirect)?

I need to download a CSV file, which works fine in browsers using: http://www.ftse.com/objects/csv_to_csv.jsp?infoCode=100a&theseFilters=&csvAll=&theseColumns=Mw==&theseTitles=&tableTitle=FTSE%20100%20Index%20Constituents&dl=&p_encoded=1&e=.csv The following code works for any other file (url) (with a f...

Restful authentication between two GAE apps.

Hello everyone, i am trying to write a restful google app engine application (python) that accepts requests only from another GAE that i wrote. I dont like any of the ways that i thought of to get this done, please advice if you know of something better than: Get SSL setup, and simply add the credentials on the request that my consumin...

catalogue a list of dictionaries

I have a list of dictionaries: people = [{"name": "Roger", "city": "NY", "age": 20, "sex": "M"}, {"name": "Dan", "city": "Boston", "age": 20, "sex": "M"}, {"name": "Roger", "city": "Boston", "age": 21, "sex": "M"}, {"name": "Dana", "city": "Dallas", "age": 30, "sex": "F"}] I want to catalogue them, for ex...

Convert UTF-8 bytes to some other encoding in Python

I need to do in Python 2.4 (yes, 2.4 :-( ). I've got a plain string object, which represents some text encoded with UTF-8. It comes from an external library, which can't be modified. So, what I think I need to do, is to create an Unicode object using bytes from that source object, and then convert it to some other encoding (iso-8859-2,...

compare two following values in numpy array

What is the best way to touch two following values in an numpy array? example: npdata = np.array([13,15,20,25]) for i in range( len(npdata) ): print npdata[i] - npdata[i+1] this looks really messed up and additionally needs exception code for the last iteration of the loop. any ideas? Thanks! ...

Python - Nested List to Tab Delimited File?

Hi, I have a nested list comprising ~30,000 sub-lists, each with three entries, e.g., nested_list = [['x', 'y', 'z'], ['a', 'b', 'c']]. I wish to create a function in order to output this data construct into a tab delimited format, e.g., x y z a b c Any help greatly appreciated! Thanks in advance, Seafoid. ...

running python code in matlab?

hi,i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful.... ...

Can this be done with the ORM? - Django

Hi folks, I have a few item listed in a database, ordered through Reddit's algorithm. This is it: def reddit_ranking(post): t = time.mktime(post.created_on.timetuple()) - 1134000000 x = post.score if x>0: y=1 elif x==0: y=-0 else: y=-1 if x<0: z=1 else: z=x return (log(z) + y * t/45000) I'm wonde...

More nest Python nested dictionaries.

After reading http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python why is it wrong to do: c = collections.defaultdict(collections.defaultdict(int)) in python? I would think this would work to produce {key:{key:1}} or am I thinking about it wrong? ...

Python - create blacklist file of IP addresses that have more than 5 failed login attempts in the authlog

Basically I have an authlog/syslog file with a list of log in attempts and IP addresses - I need to make a Python program that will create a txt file with all the IP addresses that have more than 5 failed login attempts - a sort of "blacklist". So basically something like: if "uniqueipaddress" and "authentication failure" appear more t...

maintaining a large list in python

I need to maintain a large list of python pickleable objects. The list is too large to be all stored in the RAM, so some database\paging mechanism is required. I need that the mechanism will support fast access for close (nearby) areas in the list. The list should implement all the python-list features, but most of the time I will work ...

Keeping track of user habits and activities? - Django

Hi folks, I was working on a project a few months ago, and had the need to implement an award system. Similar to S*tackOverflow's badge system*. Badges I might have not implemented it in the best possible way, and I am curious what your say in it would be. What would a good way to track user activities, needed for badge awarding be?...