python

Microphone access in Python

Can I access a users microphone in Python? Sorry I forgot not everyone is a mind reader: Windows at minimum XP but Vista support would be VERY good. ...

What are good rules of thumb for python imports?

I am a little confused by the multitude of ways in which you can import modules in python. import X import X as Y from A import B I have been reading up about scoping and namespaces but I would like some practical advice on what is the best strategy, under which circumstances and why. Should imports happen at a module level or a me...

Recommended data format for describing the rules of chess

I'm going to be writing a chess server and one or more clients for chess and I want to describe the rules of chess (e.g. allowable moves based on game state, rules for when a game is complete) in a programming language independant way. This is a bit tricky since some of the chess rules (e.g. King Castling, en passent, draws based on 3 or...

Python Code Organization Question : Eggs + Packages + Buildout + Unit Tests + SVN

I have several python projects that share common modules. Until now, I've been ... ahem ... keeping multiple copies of the common code and synchronizing by hand. But I'd clearly prefer to do something else. It looks to me now, as if zc.Buildout maybe what I need. I guess that what I should be doing is putting each reusable component of ...

Running a web app in Grails vs Django

I'm currently in the planning stage for a web application and I find myself trying to decide on using Grails or Django. From an operation perspective: Which ecosystem is easier to maintain (migrations, backup, disaster recovery etc.)? If using grails it'll probably be a typical tomcat + mysql on linux. If django it'll be apache + my...

Running compiled python (py2exe) as administrator in Vista

Is it possible to programaticly run compiled Python (comiled via py2exe) as administrator in Vista? Some more clarification: I have written a program that modifies the windows hosts file (c:\Windows\system32\drivers\etc\hosts) in Vista the program will not run and will fail with an exception unless you right-click and run as administrat...

Python Decimal

Does anyone know of a faster decimal implementation in python. As example below demonstrates, standard python decimal is ~100 times slower than float. from timeit import Timer def run(val, the_class): test = the_class(1) for c in xrange(10000): d = the_class(val) d + test d - test d * test ...

In production, Apache + mod_wsgi or Nginx + mod_wsgi ?

What to use for a medium to large python WSGI application, Apache + mod_wsgi or Nginx + mod_wsgi? Which combination will need more memory and CPU time? Which one is faster? Which is known for being more stable than the other? I am also thinking to use CherryPy's WSGI server but I hear it's not very suitable for a very high-load applicati...

What is the time complexity of popping elements from list in Python?

I wonder what is the time complexity of pop method of list objects in Python (in CPython particulary). Also does the value of N for list.pop(N) affects the complexity? ...

How to avoid computation every time a python module is reloaded

I have a python module that makes use of a huge dictionary global variable, currently I put the computation code in the top section, every first time import or reload of the module takes more then one minute which is totally unacceptable. How can I save the computation result somewhere so that the next import/reload doesn't have to compu...

What are the Zope essentials ?

I started a job where Zope is involved. I know Python and my new Boss think I am going to handle the application server quickly. I had a look to this system and it's obviously very complex, so I'd like to know where to start and to look next; Can somebody gives a step by step way to learn Zope ? For once, I don't need the how, I need ...

What's the easiest way/best tutorials to get familiar with SQLAlchemy ?

What are best resources/tutorials for starting up with SQLAlchemy? Maybe some simple step by step stuff like creating a simple table and using it and going up from there. ...

MySQLdb execute timeout

Sometimes in our production environment occurs situation when connection between service (which is python program that uses MySQLdb) and mysql server is flacky, some packages are lost, some black magic happens and .execute() of MySQLdb.Cursor object never ends (or take great amount of time to end). This is very bad because it is waste ...

How to check if a string in Python is in ASCII?

Hello, I am fighting with Python to understand how do I check whether a string is in ASCII or not. I am aware of ord(), however when I try ord('é'), I have TypeError: ord() expected a character, but string of length 2 found. I understood it is caused by the way I built Python (as explained in the ord()'s documentation). So my questio...

How can I search through stackoverflow questions from a script?

Given a string of keywords, such as "python best practices", I would like to obtain the first 10 stackoverflow questions that contain that keywords, sorted by relevance (?), say from a python script. My goal is to end up with a list of tuples (title, URL). How can I accomplish this? Would you consider querying google instead? (How would...

What is the best way to escape Python strings in PHP?

I have a PHP application which needs to output a python script, more specifically a bunch of variable assignment statements, eg. subject_prefix = 'This String From User Input' msg_footer = """This one too.""" The contents of subject_prefix et al need to be written to take user input; as such, I need to escape the contents of the strin...

Which AES library to use in Ruby/Python?

I need to be able to send encrypted data between a Ruby client and a Python server (and vice versa) and have been having trouble with the ruby-aes gem/library. The library is very easy to use but we've been having trouble passing data between it and the pyCrypto AES library for Python. These libraries seem to be fine when they're the onl...

Next step for System administrator?

I have been a system administrator for about 8 years. Have worked on various technologies including various linux/unix flavours as well as MS technologies. I have also dabbled in perl and bash programming purely for sysad jobs. I am planning to switch to programming. Is it advisable for a sysad to shift to programming. If no, why? If...

How do I emulate Python's named printf parameters in Ruby?

In Python, you can do this: print "Hi! I'm %(name)s, and I'm %(age)d years old." % ({"name":"Brian","age":30}) What's the closest, simplest Ruby idiom to replicate this behavior? (No monkeypatching the String class, please.) EDIT: One of the really excellent benefits of this is that you can store the pre-processed string in a varia...

Is there a better way to get a named series of constants (enumeration) in Python?

Just looking at ways of getting named constants in python. class constant_list: (A_CONSTANT, B_CONSTANT, C_CONSTANT) = range(3) Then of course you can refer to it like so: constant_list.A_CONSTANT I suppose you could use a dictionary, using strings: constant_dic = { "A_CONSTANT" : 1, "B_CONSTANT" : 2, "C_CONSTA...