python

Python: find most frequent bytes?

I'm looking for a (preferably simple) way to find and order the most common bytes in a python stream element. e.g. >>> freq_bytes(b'hello world') b'lohe wrd' or even >>> freq_bytes(b'hello world') [108,111,104,101,32,119,114,100] I currently have a function that returns a list in the form list[97] == occurrences of "a". I need th...

Best interface paradigm for time interval selection?

I'm working on a small project that involves selecting time intervals and then using them for my nefarious purposes (which basically boils down to making a robot voice shout things at me). However, I can't decide on a proper paradigm for choosing these intervals. The required data is as follows: Action (Text) Starting At (Time, can be...

Problem with model inheritance and polymorphism

Hi, i came with new django problem. The situtaion: i have a model class UploadItemModel, i subcallss it to create uploadable items, like videos, audio files ... class UploadItem(UserEntryModel): category = 'abstract item' file = models.FileField(upload_to=get_upload_directory) i subclass it like this: class Video(UploadItem)...

Wrapper on conneting Sybase ASE using pyodbc in Django?

I wonder any one is conneting Sybase ASE using pyodbc in Django? Any wrapper available for that? Any solution? Currently there are: - sqlany-django (http://code.google.com/p/sqlany-django/) for Sybase SQL Anywhere and not Sybase ASE - django-pyodbc (http://code.google.com/p/django-pyodbc/) for MS SQL Server through pyodbc Thanks. ...

What is the most 'pythonic' way to logically combine a list of booleans?

I have a list of booleans I'd like to logically combine using and/or. The expanded operations would be: vals = [True, False, True, True, True, False] # And-ing them together result = True for item in vals: result = result and item # Or-ing them together result = False for item in vals: result = result or item Are there nift...

What is a 'good practice' way to write a Python GTK+ application?

I'm currently writing a PyGTK application and I'd like some advice as to the best way to structure my application. Basically the application will read a specific file specification and present it in a GUI for editing. Currently I have a parser.py which handles all the low level file IO and parsing of the file. I'm displaying the content...

python: replacing regex with BNF or pyparsing

I am parsing a relatively simple text, where each line describes a game unit. I have little knowledge of parsing techniques, so I used the following ad hoc solution: class Unit: # rules is an ordered dictionary of tagged regex that is intended to be applied in the given order # the group named V would correspond to the value (if...

Terminating a wxPython app cleanly

Hi, I'm working on a wxPython app which has multiple frames and a serial connection. I need to be able to exit the app cleanly, closing the serial connection as the app terminates. What is the best way to do this? Should this be handled by a subclass of wxApp? Thanks, Josh ...

Convert int to ascii and back in Python

I'm working on making a URL shortener for my site, and my current plan (I'm open to suggestions) is to use a node ID to generate the shortened URL. So, in theory, node 26 might be short.com/z, node 1 might be short.com/a, node 52 might be short.com/Z, and node 104 might be short.com/ZZ. Something like that. And when a user goes to that U...

Find subsequences of strings within strings

I want to make a function which checks a string for occurrences of other strings within them. However, the substrings which are being checked may be interrupted within the main string by other letters. For instance: a = 'abcde' b = 'ace' c = 'acb' The function in question should return as b being in a, but not c. I've tried set(a).i...

Why don't you need a powerful ide for writing Python?

I have heard before that many Python developers don't use an IDE like Eclipse because it is unnecessary with a language like Python. What are the reasons people use to justify this claim? ...

What module is PYSIGNAL defined in PyQt4

All of the examples I read online use from PyQt4 import * or some variant of that, importing everything. I don't want to do this, but I can't find where PYSIGNAL is defined! ...

What is a best practice method to log visits per page / object

Take my profile for example, or any question number of views on this site, what is the process of logging the number of visits per page or object on a website, which I presumably think includes: Counting registered users once (this must be reflected in the db, which pages / objects the user has visited). this will also not include unre...

How to require a key_name when creating model classes with App Engine?

I want to require that one of my model classes specify my own custom key as the key_name, that way I can always rely on it being there. How can I require this? For example, I may have a model class such as: class Account(db.Model): user = db.UserProperty(required=True) email = db.EmailProperty() And I want to require that k...

pyHook + pythoncom stop working after too much keys pressed [Python]

this is my script: import pyHook import pythoncom hookManager = pyHook.HookManager() def onKeyboardEvent(event): if event.KeyID == 113: # F2 #do something# return True hookManager.KeyDown = onKeyboardEvent hookManager.HookKeyboard() pythoncom.PumpMessages() after the key specified on the keyboard event, or the F2 ...

TypedChoiceField or ChoiceField in Django

When should you use TypedChoiceField with a coerce function over a ChoiceField with a clean method on the form for the field? In other words why would you use MyForm over MyForm2 or vice versa. Is this simply a matter of preference? from django import forms CHOICES = (('A', '1'), ('B', '2'), ('C', '3')) class MyForm(forms.Form): ...

Django query to list

I have a database which has records with several fields containing some info. To get all the data in the table matching some filter I'd do this: records = Record.objects.filter(fieldA='a') records, I suppose, is a QuerySet object and contains a "list" of records. Is that correct? Now let's say I want a list of the values in one fie...

regex regarding symbols in urls

Hi guys, I want to replace consecutive symbols just one such as; this is a dog??? to this is a dog? I'm using str = re.sub("([^\s\w])(\s*\1)+", "\\1",str) however I notice that this might replace symbols in urls that might happen in my text. like http://example.com/this--is-a-page.html Can someone give me some advice h...

Write a regex for a pattern?

a + (ab or cd ) + g is my expression. How can I write a regex in Python to match these? ...

Whatever data is input to the server the server have to respond back with the http URL with/without http:// if its a valid HTTP request

Whatever data is input to the server, either via telnet(console) or browser, the server have to respond back with the http URL with/without http:// if its a valid HTTP request . What has to be done? INPUT GET /learn/tutorials/351079-weekend-project-secure-your-system-with-port-knocking?name=MyName&married=not+single&male=yes HTTP/1.1 ...