python

How to change a tuple into array?

Let's say I have a tuple (1,2,3,4). What's the simple way to change it into Array? I can do something like this, array = [] for i in tuple: array.append(i) But I prefer something like x.toArray() or something. ...

Storing an inverted index

Hello, I am working on a project on Info Retrieval. I have made a Full Inverted Index using Hadoop/Python. Hadoop outputs the index as (word,documentlist) pairs which are written on the file. For a quick access, I have created a dictionary(hashtable) using the above file. My question is, how do I store such an index on disk that also ha...

Use of ctypes module

Hi; I need to program VIX API of VMware. It´s a dll wrote with C functions... I want program in python calling this functions using ctypes and I don´t understand the documentation of ctypes in python web page... Can someone give some samples with how to do this???? Thanks, ...

Python logging objects

Hi, I'm trying to reformat the output data sent to the logger based on it's class. For example: strings will be printed as they are dictionaries/lists will be automatically indented/beautified into html my custom classes will be handled on an individual basis and converted to html My problem is that the message sent to the formatte...

GUIs vs TUIs in Python

I'm interested in doing rapid app development in Python. Since this is mainly for prototyping purposes, I'm looking for a way of creating "rough" user interfaces. By this, I mean that they don't have to look professional, they just have to be flexible enough to make it look the way I want. Originally I was going to do this by creating a ...

How to Install rpy2 on Mac OS X

Hi everyone, I am trying, so far unsuccessfully, at installing the rpy2 for python on my Mac OSX. I have tried Macports and DarwinPorts but have had no luck with import rpy2 within the python shell environment. I don't know much about programming in Mac and I am a wiz at installing modules on a Windoze based system, but for the life of...

How to add a script to a buildout project?

I have setup.py in a buildout project: from distutils.core import setup setup(name='', version='1.0', author='Denis Kolodin', author_email='...', url='...', scripts = ['scripts/myscript.py'], # The script I want to add to 'bin/' dir ) Why buildout don't add that script to 'bin/'? Can I develop scripts (not eggs) with buildou...

How would I go about downloading a file from a submitted link then reuploading to my server for streaming?

I'm working on a project where a user can submit a link to a sound file hosted on another site through a form. I'd like to download that file to my server and make it available for streaming. I might have to upload it to Amazon S3. I'm doing this in Django but I'm new to Python. Can anyone point me in the right direction for how to do th...

I can't delete a folder that I just extracted from a zip file in python

So here's my problem. I have a python script that takes a zipfile and extracts its contents. Then based on some constraint, I will try to delete the folder whose contents were just extracted. For some reason I get an error, WindowsError: [Error 5] Access is denied: 'Foldername' when i try to delete that folder. The simple code looks like...

Convert function to single line list comprehension

Is it possible to convert this function, list comprehension combination into a single list comprehension (so that keep is not needed)? def keep(list, i, big): for small in list[i+1:]: if 0 == big % small: return False return True multiples[:] = [n for i,n in enumerate(multiples) if keep(multiples, i, n)] ...

Schedule a cron job for execution every hour on certain days on App Engine

I would like to schedule a cron task to run every hour, but only from Thursday through Monday. Is a schedule like this possible? From the documentation, it looks like I can schedule a cron task to run at an hourly interval or on specific days at a single specific time, but I cannot figure out how to schedule a cron task to run at an ho...

Python, safe, sandbox

Hello, I'd like to make a website where people could upload their Python scripts. Of course I'd like to execute those scripts. Those scripts should do some interesting work. The problem is that people could upload scripts that could harm my server and I'd like to prevent that. What is the option to run arbitrary scripts without harming ...

If my python class name has an acronym, should I keep it upper case, or only the first letter?

I have a class named SSLXMLRPCServer. Should it be that or SslXmlRpcServer? ...

How to get pydoc command working in Windows?

pydoc does not work in Windows. at this post http://stackoverflow.com/questions/3391998/pydoc-is-not-working-windows-xp the last answer by dave webb says to create a pydoc.bat file with this code in it: @python c:\Python27\Lib\pydoc.py %* After I create pydoc.bat where should it be placed so the pydoc command works in the command prom...

when converting a python list to json and back, do you cast?

When you convert a list of user objects into json, and then convert it back to its original state, do you have to cast? Are there any security issues of taking a javascript json object and converting it into a python list object? ...

How is pip install using git different that just cloning a repository?

I'm a beginner with Django and I'm having trouble installing django-basic-apps using pip. If I do this... $ cat requirements.txt git+git://github.com/nathanborror/django-basic-apps.git $ pip install -r requirements.txt I end up with lib/python2.6/site-packages/basic/blog that does NOT have a templates directory. If I do this.....

Merge SQLite files into one db file, and 'begin/commit' question.

This post refers to this page for merging SQLite databases. The sequence is as follows. Let's say I want to merge a.db and b.db. In command line I do the following. sqlite3 a.db attach 'b.db' as toM; begin; <-- insert into benchmark select * from toM.benchmark; commit; <-- detach database toM; It works well, but in the referred si...

How to remove "__main__." from the beginning of user-created exception classes in Python

Is there a way to get a "prettier" exception rather than one prefaced with __main__MyExceptionTitle? Example: >>> class BadThings(Exception): ... def __init__(self, msg): ... self.msg = msg ... return ... >>> class BadThings(Exception): ... def __init__(self, msg): ... self.msg = msg ... return ...

Will nginx+paste hold up in a production environment?

I've developed a website in Pylons (Python web framework) and have it running, on my production server, under Apache + mod_wsgi. I've been hearing a lot of good things about nginx recently and wanted to give it a try. Currently, it's running as a forwarding proxy to create a front end to Paste. It seems to be running pretty damn fast.....

Sorting list that has tuple as an element with Python

I have a list as follows. [(5,), (2,), (4,), (1,), (3,), (6,), (7,), (8,)] How can I sort the list to get [1,2,3,4,5,6,7,8] or [8,7,6,5,4,3,2,1] ? ...