python

Python: What is the most feature-rich library for loading audio metadata from various formats?

I'm looking for a good, feature-rich, library for reading metadata from various audio formats (MP3, FLAC, OGG, WAV, etc.). I have already looked at Mutagen, but the documentation is nearly nonexistent, and it seems incapable of loading basic information such as artist and audio title. ...

Adding percentage in python - xlwt / pyexcelerator

Hello, just a quick question, how to add percent sign to numbers without modifying number. I have tried format percent with myStyleFont.num_format_str = '0.00%' but it multiplies with 100 but I need just to append percent. Ty in advance. Regards. ...

Moving to an arbitrary position in a file in Python

Let's say that I routinely have to work with files with an unknown, but large, number of lines. Each line contains a set of integers (space, comma, semicolon, or some non-numeric character is the delimiter) in the closed interval [0, R], where R can be arbitrarily large. The number of integers on each line can be variable. Often times I ...

accessing files after setup.py install

I'm developing a python application and have a question regarding coding it so that it still works after an user has installed it on his or her machine via setup.py install or similar. In one of my files, I use the following: file = "TestParser/View/MainWindow.ui" cwd = os.getcwd() argv_path = os.path.dirname(sys.argv[0]) file_path = o...

[Python] Tips for making a fraction calculator code more optimized (faster and using less memory)

Hello Everyone, Basicly, what I need for the program to do is to act a as simple fraction calculator (for addition, subtraction, multiplication and division) for the a single line of input, for example: -input: 1/7 + 3/5 -output: 26/35 My initial code: import sys def euclid(numA, numB): while numB != 0: numRem = numA % nu...

Python: why does this code take forever (infinite loop?)

I'm developing an app in Google App Engine. One of my methods is taking never completing, which makes me think it's caught in an infinite loop. I've stared at it, but can't figure it out. Disclaimer: I'm using http://code.google.com/p/gaeunitlink text to run my tests. Perhaps it's acting oddly? This is the problematic function: def _t...

python floating number

i am kind of confused why python add some additional decimal number in this case, please help to explain >>> mylist = ["list item 1", 2, 3.14] >>> print mylist ['list item 1', 2, 3.1400000000000001] ...

Google App Engine with local Django 1.1 gets Intermittent Failures

I'm using the Windows Launcher development environment for Google App Engine. I have downloaded Django 1.1.2 source, and un-tarrred the "django" subdirectory to live within my application directory (a peer of app.yaml) At the top of each .py source file, I do this: import settings import os os.environ["DJANGO_SETTINGS_MODULE"] = 'sett...

How do I convert a regex with pack and hex from Perl to Python?

I am a newcomer to Python and am converting a Perl script. What is the Python equivalent to... $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; Any help is greatly appreciated. ...

Talking to an Authentication Server

I'm building my startup and I'm thinking ahead for shared use of services. So far I want to allow people who have a user account on one app to be able to use the same user account on another app. This means I will have to build an authentication server. I would like some opinions on how to allow an app to talk to the authentication ser...

Best practice for installing python modules from an arbitrary VCS repository

I'm newish to the python ecosystem, and have a question about module editing. I use a bunch of third-party modules, distributed on PyPi. Coming from a C and Java background, I love the ease of easy_install <whatever>. This is a new, wonderful world, but the model breaks down when I want to edit the newly installed module for two reas...

Very simple python functions takes spends long time in function and not subfunctions

I have spent many hours trying to figure what is going on here. The function 'grad_logp' in the code below is called many times in my program, and cProfile and runsnakerun the visualize the results reveals that the function grad_logp spends about .00004s 'locally' every call not in any functions it calls and the function 'n' spends abou...

What is the best way to open a URL and get up to X bytes in Python?

I want to have a robot fetch a URL every hour, but if the site's operator is malicious he could have his server send me a 1 GB file. Is there a good way to limit downloading to, say, 100 KB and stop after that limit? I can imagine writing my own connection handler from scratch, but I'd like to use urllib2 if at all possible, just specif...

Python: what modules have been imported in my process?

How can I get a list of the modules that have been imported into my process? ...

Python C API from C++ app - know when to lock

Hi Everyone, I am trying to write a C++ class that calls Python methods of a class that does some I/O operations (file, stdout) at once. The problem I have ran into is that my class is called from different threads: sometimes main thread, sometimes different others. Obviously I tried to apply the approach for Python calls in multi-threa...

Need some help converting a MAC address to binary data for use in an ethernet frame

I've been looking over various internet postings and a lot of the code I've seen looks similar to this: def mactobinar(mac): addr = '' temp = mac.replace(':', '') for i in range(0, len(temp), 2): addr = ''.join([addr, struct.pack('B', int(temp[i: i + 2], 16)))]) return addr Can someone explain how this code w...

python code to retrieve url from mozilla

hi expert, is it any possibilities to retrieve currently open url in Mozilla firefox using python ...

what should i do after openid (or twitter ,facebook) user login my site ,on gae

how to integration local user and openid(or facebook twitter) user , did you know some framework have already done this , thanks updated my mean is : how to deal with 'local user' and 'openid user', and how to mix them in one model . please give me a framework that realize 'local user' and 'openid user' ...

Counting entries in a list of dictionaries: for loop vs. list comprehension with map(itemgetter)

In a Python program I'm writing I've compared using a for loop and increment variables versus list comprehension with map(itemgetter) and len() when counting entries in dictionaries which are in a list. It takes the same time using a each method. Am I doing something wrong or is there a better approach? Here is a greatly simplified and ...

need help in site classification

hi guys, I have to crawl the contents of several blogs. The problem is that I need to classify whether the blogs the authors are from a specific school and is talking about the school's stuff. May i know what's the best approach in doing the crawling or how should i go about the classification? ...