python

Is it possible to split a SWIG module for compilation, but rejoin it when linking?

Hi all I hit this issue about two years ago when I first implemented our SWIG bindings. As soon as we exposed a large amount of code we got to the point where SWIG would output C++ files so large the compiler could not handle them. The only way I could get around the issue was to split up the interfaces into multiple modules and to co...

abstracting the conversion between id3 tags, m4a tags, flac tags...

I'm looking for a resource in python or bash that will make it easy to take, for example, mp3 file X and m4a file Y and say "copy X's tags to Y". Python's "mutagen" module is great for manupulating tags in general, but there's no abstract concept of "artist field" that spans different types of tag; I want a library that handles all the ...

Dilemma: Should I learn Seaside or a Python framework?

I know it's kinda subjective but, if you were to put yourself in my shoes which would you invest the time in learning? I want to write a web app which deals securely with relatively modest amounts of peoples private data, a few thousand records of a few Kb each but stuff that needs to be kept safe, addresses, phone numbers etc. I've don...

How to send a session message to an anonymous user in a Django site?

I often show messages about user actions to logged in users in my Django app views using: request.user.message_set.create("message to user") How could I do the same for anonymous (not logged in) users? There is no request.user for anonymous users, but the Django documentation says that using the "session" middleware you can do the sa...

Easy way to parse .h file for comments using Python?

How to parse in easy way a .h file written in C for comments and entity names using Python? We're suppose for a further writing the content into the word file already developed. Source comments are formatted using a simple tag-style rules. Comment tags used for an easy distinguishing one entity comment from the other and non-documentin...

How can I parse a time string containing milliseconds in it with python?

Hi, I am able to parse strings containing date/time with time.strptime >>> import time >>> time.strptime('30/03/09 16:31:32', '%d/%m/%y %H:%M:%S') (2009, 3, 30, 16, 31, 32, 0, 89, -1) How can I parse a time string that contains milliseconds? >>> time.strptime('30/03/09 16:31:32:123', '%d/%m/%y %H:%M:%S') Traceback (most recent call l...

Google App Engine Local Environment Error: "cannot import name webapp"

I've built a GAE site on a Windows machine and I want to work on it from my MacBook. I have the code in SVN remotely and I installed the Mac version of GAE which comes with this launcher program. When I configured my application in the launcher and fire the application up, I get the following error: 22 from datetime import timedelta 2...

Python tkinter label won't change at beginning of function

I'm using tkinter with Python to create a user interface for a program that converts Excel files to CSV. I created a label to act as a status bar, and set statusBarText as a StringVar() as the textvariable. inputFileEntry and outputFileEntry are textvariables that contain the input and output file paths. def convertButtonClick(): s...

Python: Do Python Lists keep a count for len() or does it count for each call?

If I keep calling len() on a very long list, am I wasting time, or does it keep an int count in the background? ...

Programmatically submitting a form in Python?

Just started playing with Google App Engine & Python (as an excuse ;)). How do I correctly submit a form like this <form action="https://www.moneybookers.com/app/payment.pl" method="post" target="_blank"> <input type="hidden" name="pay_to_email" value="[email protected]"> <input type="hidden" name="status_url" <!-- etc....

Convert number to binary string

Is this the best way to convert a Python number to a hex string? number = 123456789 hex(number)[2:-1].decode('hex') Sometimes it doesn't work and complains about Odd-length string when you do 1234567890. Clarification: I am going from int to hex. Also, I need it to be escaped. IE: 1234567890 -> '\x49\x96\x02\xd2' not '499602D2' ...

Suppress output in Python calls to executables

I have a binary named A that generates output when called. If I call it from a Bash shell, most of the output is suppressed by A > /dev/null. All of the output is suppressed by A &> /dev/null I have a python script named B that needs to call A. I want to be able to generate output from B, while suppressing all the output from A. From w...

What's the best way to tell if a Python program has anything to read from stdin?

I want a program to do one thing if executed like this: cat something | my_program.py and do another thing if run like this my_program.py But if I read from stdin, then it will wait for user input, so I want to see if there is anything to read before trying to read from stdin. ...

Python/Django: Creating a simpler list from values_list()

Consider: >>>jr.operators.values_list('id') [(1,), (2,), (3,)] How does one simplify further to: ['1', '2', '3'] The purpose: class ActivityForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(ActivityForm, self).__init__(*args, **kwargs) if self.initial['job_record']: jr = JobRecord.ob...

Python HTML sanitizer / scrubber / filter

Does anyone have experience using a Python HTML sanitizer / scrubber / filter? I'm looking for a module that will remove any HTML tags from a string that are not found in a whitelist. Of course I've Googled it but haven't found anything definitive. Thanks, Everett ...

Is it possible to create a class that represents another type in Python, when directly referenced?

So if I have a class like: CustomVal I want to be able to represent a literal value, so like setting it in the constructor: val = CustomVal ( 5 ) val.SomeDefaultIntMethod Basically I want the CustomVal to represent whatever is specified in the constructor. I am not talking about custom methods that know how to deal with CustomVal...

python decorators and methods

Hi. New here. Also I'm (very) new to python and trying to understand the following behavior. Can someone explain to me why the two methods in this example have different output? def map_children(method): def wrapper(self,*args,**kwargs): res = method(self,*args,**kwargs) for child in self._children: m...

navigating through different drive letters in python os.system

I am having a problem with a bit of code on one windows machine but not all windows machines. i have the following code: path = "F:/dir/" os.system(path[0:2] + " && cd " + path + " && git init") On all but one of my windows systems it runs fine but on a windows 2003 server it gives a "directory not found" error but if i run the same c...

Python: Testing for unicode, and converting to time()

Sometimes self.start is unicode: eg. >>>self.start u'07:30:00' Which makes datetime.combine complain start = datetime.combine(self.job_record.date, self.start) How does one: Test for unicode? Convert from u'07:30:00' to datetime.time? ...

Browser interface to command line python program

I have a command line tool that I have written (in Python) that interfaces to a SQLite database (one DB per user). This program presents a lot of data to the user which can be cumbersome in a terminal. One option is to provide a wxPython interface, but another thought is to leverage Firefox or Webkit to provide an interface. Anyone eve...