python

How can I get the next string, in alphanumeric ordering, in Python?

I need a simple program that given a string, returns to me the next one in the alphanumeric ordering (or just the alphabetic ordering). f("aaa")="aab" f("aaZ")="aba" And so on. Is there a function for this in one of the modules already? ...

Expression up to comment or end of line

Although this question is similar to this thread I think I might be doing something wrong at the time of constructing the code with the Regular Expression. I want to match anything in a line up to a comment ("#") or the end of the line (if it doesn't have a comment). The regex I am using is: (.*)(#|$) (.*) = Everything (#|$) = commen...

How to parse angular values using regular expressions

Hi, I have very little experience using regular expressions and I need to parse an angle value expressed as bearings, using regular expressions, example: "N45°20'15.3"E" Which represents: 45 degrees, 20 minutes with 15.3 seconds, located at the NE quadrant. The restrictions are: The first character can be "N" or "S" The last charac...

retrieving a variable's name in python at runtime?

is there a way to know, during run-time, a variable's name (from the code) ? or do var names forgotten during compilation (byte-code or not) ? e.g. >>> vari = 15 >>> print vari.~~name~~() 'vari' note: i'm talking about plain data-type variables (int, str, list...) ...

XML characters in python xml.dom

I am working on producing an xml document from python. We are using the xml.dom package to create the xml document. We are having a problem where we want to produce the character φ which is a φ. However, when we put that string in a text node and call toxml() on it we get φ. Our current solution is to use saxutils....

Python module globals versus __init__ globals

Apologies, somewhat confused Python newbie question. Let's say I have a module called animals.py....... globvar = 1 class dog: def bark(self): print globvar class cat: def miaow(self): print globvar What is the difference between this and class dog: def __init__(self): global globvar def bark(self): ...

Python Regex combined with string substitution?

I'm wondering if its possible to use string substitution along with the python re module? For example I'm using optparse and have a variable named options.hostname which will change each time the user executes the script. I have the following regex matching 3 strings in each line of the log file. match = re.search (r'^\[(\d+)\] (SER...

Clipping FFT Matrix

Hello, Audio processing is pretty new for me. And currently using Python Numpy for processing wave files. After calculating FFT matrix I am getting noisy power values for non-existent frequencies. I am interested in visualizing the data and accuracy is not a high priority. Is there a safe way to calculate the clipping value to remove th...

Django-like abstract database API for non-Django projects

I love the abstract database API that comes with Django, I was wondering if I could use this (or something similar) to model, access, and manage my (postgres) database for my non-Django Python projects. ...

Control an embedded into website flash player with Python?

Hello, I am trying to write few simple python scripts, which will allow me to control one of the Internet radio (which I listen) with an keybinded python scripts. I am now able to connect and log into the website, I am able to get out the song data ( that is - all the data which are passed to the player). I noticed, that the player is...

Is there a way to invoke a Python function with the wrong number of arguments without invoking a TypeError?

When you invoke a function with the wrong number of arguments, or with a keyword argument that isn't in its definition, you get a TypeError. I'd like a piece of code to take a callback and invoke it with variable arguments, based on what the callback supports. One way of doing it would be to, for a callback cb, use cb.__code__.cb_argcoun...

Custom Markup in Django

Can anyone give me an idea or perhaps some references on how to create custom markups for django using textile or Markdown(or am I thinking wrong here)? For example: I'd like to convert the following markups(the outer bracket mean they are grouped as one tag: [ [Contacts] * Contact #1 * Contact #2 * Contact #3 [Friend Requests] * Jose ]...

What is the best way to fetch/render one-to-many relationships?

Hi, I have 2 models which look like that: class Entry(models.Model): user = models.ForeignKey(User) dataname = models.TextField() datadesc = models.TextField() timestamp = models.DateTimeField(auto_now=True) class EntryFile(models.Model): entry = models.ForeignKey(Entry) datafile = models.FileField(upload_to="uploads/%Y/%m/%d/...

Packaging script source files in IronPython and IronRuby

Does anyone know how to add python and ruby libs as a resource in a dll for deployment? I want to host a script engine in my app, but dont want to have to deploy the entire standard libraries of the respective languages in source files. Is there a simple way to do this so that a require or import statement will find the embedded resour...

Python Regex Search And Replace

I'm not new to Python but a complete newbie with regular expressions (on my to do list) I am trying to use python re to convert a string such as [Hollywood Holt](http://www.hollywoodholt.com) to <a href="http://www.hollywoodholt.com"&gt;Hollywood Holt</a> and a string like *Hello world* to <strong>Hello world</strong> ...

Python module for editing text in CLI

Is there some python module or commands that would allow me to make my python program enter a CLI text editor, populate the editor with some text, and when it exits, get out the text into some variable? At the moment I have users enter stuff in using raw_input(), but I would like something a bit more powerful than that, and have it disp...

Comparision of data in SQL through python

i have to parse a very complex dumps(whatever it is), i have done the parsing thruogh python.since the parsed data is very huge in amount, i have to feed it in the database (SQL), I have also done this... now the thing is i have to compare the data now present in the sql. in actual i have to compare the data of 1st dump with the data of...

Write to utf-8 file in python

I'm really confused with the codecs.open function. When I do: file = codecs.open("temp", "w", "utf-8") file.write(codecs.BOM_UTF8) file.close() It gives me the error UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 0: ordinal not in range(128) If I do: file = open("temp", "w") file.write(codecs.BOM_UTF8) file.cl...

python db connection

I am having a script which makes a db connection and pereform some select operation.accroding to the fetch data i am calling different functions which also perform db operations.How can i pass db connection to the functions which are being called as i donot want to make new connection ...

Getting response from bluetooth device

I'm trying to write a simple module that will enable sending SMS. I using bluetooth to connect to the mobile using the below example: file: bt-sendsms.py import bluetooth target = '00:32:AC:32:36:E8' # Mobile address print "Trying to send SMS on %s" % target BTSocket = bluetooth.BluetoothSocket(bluetooth.RFCOMM) BTSocket.connect(...