python

PyObjC giving strange error - [OC_PythonUnicode representations]: unrecognized selector sent to instance 0x258ae2a0

I have this line: NSWorkspace.sharedWorkspace().setIcon_forFile_options_(unicode(icon),unicode(target),0) Why does it give that error and how do I fix it? Thank you. ...

Can this Python code be written more efficiently?

So I have this code in python that writes some values to a Dictionary where each key is a student ID number and each value is a Class (of type student) where each Class has some variables associated with it. ' Code try: if ((str(i) in row_num_id.iterkeys()) and (row_num_id[str(i)]==varschosen[1])): ...

I would like to do some programming stuff during summer, what do you recommend?

Preferable C/C++, Python or Java. I'm tired of doing simple and silly applications. I would like to start or help in a big project, but I don't know how to do it and what to do. Any idea? ...

How to transform negative elements to zero without a loop?

If I have an array like a = np.array([2, 3, -1, -4, 3]) I want to set all the negative elements to zero: [2, 3, 0, 0, 3]. How to do it with numpy without an explicit for? I need to use the modified a in a computation, for example c = a * b where b is another array with the same length of the original a Conclusion import numpy as ...

if I run a .py script, can I open a new terminal, modify the file and run it also?

if I run a .py script, can I open a new terminal, modify the file and run it also? i.e. does the file that I run get loaded in memory, such that I can modify the file and run it at the same time in a different terminal? ...

Enable gzip compression in a Grok - Zope - PasteScript environment

Hello everyone! I am trying to make my server send gzipped data. I have a grok application that runs over Paste (Paste-1.7.2-py2.4.egg) I have been trying to google how to make all that environment to serve data in gzip... But without success... I think the answer comes in http://pythonpaste.org/modules/gzipper.html but if I do this: ...

Python : define a list of a specific type of object

I would like to inherit from list to produce the myList class, that ony accepts one specific type of object (say ints). I am sure decorators can do that elegantly. Thanks ...

Pydoc is not working (Windows XP)

Using Windows XP and Python 2.7 I tried to run "pydoc" through the terminal. unfortunately it doesn't work. Since I'm not allowed to post a screenshot (Newbie). Here is what it says (white on black) "C:\Python27>pydoc raw_input /"pydoc raw_input" is what I typed Der Befehl "pydoc" ist entweder falsch geschrieben oder konnte nicht gefu...

Implementing a per-model table modification time in Django?

I have a Django application which edits a database table, which another application polls and uses to update a downstream system. In order to minimize processing when the database has not been altered in between polls, I would like to use a global modification time for a model, which is updated every time a row is created/deleted/modifi...

Standard way of generating/ writing XML files

Hi. For a project, I need to generate XML files which adhere to a specific format. I was wondering, what is the standard way of doing this? For my part I am using lxml and then writing the XML files. For this, I wrote a small script that takes in XML data as input and then generates the files. Is this way of doing it 'OK'? Cause I a...

help with IOError for reading files

for subdir, dirs, files in os.walk(crawlFolder): for file in files: print os.getcwd() f=open(file,'r') lines=f.readlines() writeFile.write(lines) f.close() writeFile.close() I get the error as:- IOError: [Errno 2] No such file or directory In reference to my partial python code abov...

Linux kernel that runs python file for init

Would it be possible and not incredibly difficult to build a linux kernel, with a python interpreter built in or accessible from the kernel, that could run a python file as it's init process? ...

alpha beta pruning problem in python

In alpha, beta pruning algorithm, I have a class in which a fucntion def getAction(self,gamestate) id defined. I made 2 more function in def getAction Like: class BAC: def you(self,gamestate): def me(gamestate,depth,alpha, beta): ------ return v def both(gamestate,depth,alpha, beta): ------------------- ...

python: getting rid of values from a list

drug_input=['MORPHINE','CODEINE'] def some_function(drug_input) generic_drugs_mapping={'MORPHINE':0, 'something':1, 'OXYCODONE':2, 'OXYMORPHONE':3, 'METHADONE':4, ...

Python - Library that compute relevance score for text search

My idea is to achieve an execution similar to the MySQL MATCH / AGAINST keywords. Do you know a python library that compute relevance score for text searches? If not satisfying answers I am going to use a Python connector to MySQL. ...

Simply sqlalchemy filter not working

Select all works like this: q = session.query(products) Now I want to add a WHERE filter, so I am trying: q = session.query(products).filter_by(stock_count=0) I get an error saying 'nonetype' object has no attribute 'class_manager'. Not sure what the issue is? Update The column seems to be mapped fine, as when I do: q = session....

Disconnecting from host with Python Fabric when using the API

The website says: Closing connections: Fabric’s connection cache never closes connections itself – it leaves this up to whatever is using it. The fab tool does this bookkeeping for you: it iterates over all open connections and closes them just before it exits (regardless of whether the tasks failed or not.) Libr...

Python ABCs: registering vs. subclassing

(I am using python 2.7) The python documentation indicates that you can pass a mapping to the dict builtin and it will copy that mapping into the new dict: http://docs.python.org/library/stdtypes.html#mapping-types-dict I have a class that implements the Mapping ABC, but it fails: import collections class Mapping(object): def __i...

python: append values to a set

i have a set like this: keep = set(generic_drugs_mapping[drug] for drug in drug_input) how do i add values [0,1,2,3,4,5,6,7,8,9,10] in to this set? ...

python: how do i always start from the second row in csv?

b holds the contents of a csv file i need to go through every row of b; however, since it has a header, i dont want to pay attention to the header. how do i start from the second row? for row in b (starting from the second row!!): ...