The question is, basically: what would be more preferable, both performance-wise and design-wise - to have a list of objects of a Python class or to have several lists of numerical properties?
I am writing some sort of a scientific simulation which involves a rather large system of interacting particles. For simplicity, let's say we hav...
Hi,
Could anyone tell me how I could remove extra-quotes from my HTML using uTidy. The malformed HTML tag looks like this:
<th align="left"">
<input type="submit" style="font-weight: bold;" value="Go">
</th>
I would also like to remove some empty attributes in the HTML that looks like this (notice the alt tag):
<img src="http://sta...
I have a very old .sql backup of a vbulletin site that I ran around 8 years ago. I am trying to see the file attachments that are stored in the DB. The script below extracts them all and is verified to be JPEG by hex dumping and checking the SOI (start of image) and EOI (end of image) bytes (FFD8 and FFD9, respectively) according to the ...
I've got an array listing days of the week:
days = ['Monday', 'Tuesday', 'Wednesday']
Whats the easiest / best way to output it in a human readable format:
Monday, Tuesday and Wednesday
The best I have is a rather ugly:
', '.join(days[:-2]+['']) + ' and '.join(days[-2:])
...
My Python Interpreter (v2.6.5) raises the above error in the following codepart:
fd = open("some_filename", "r")
fd.seek(-2, os.SEEK_END) #same happens if you exchange the second arg. w/ 2
data=fd.read(2);
last call is fd.seek()
Traceback (most recent call last):
File "bot.py", line 250, in <module>
fd.seek(iterator, os.S...
I'm trying to write a simple decorator to check the authentication of a user, and to redirect to the login page if s/he is not authenticated:
def authenticate(f):
try:
if user['authenticated'] is True:
return f
except:
redirect_to(controller='login', action='index')
class IndexController(BaseControll...
In Python, if you want to programmatically import a module, you can do:
module = __import__('module_name')
If you want to import a submodule, you would think it would be a simple matter of:
module = __import__('module_name.submodule')
Of course, this doesn't work; you just get module_name again. You have to do:
module = __import__...
According to the official documentation, os.path is a module. Thus, what is the preferred way of importing it?
# Should I always import it explicitly?
import os.path
Or...
# Is importing os enough?
import os
Please DON'T answer "importing os works for me". I know, it works for me too right now (as of Python 2.6). What I want to kno...
Recently Zed Shaw (a programmer who blogs) mentioned that ODBC references should be removed from the popular python book Dive into Python. I have never worked with ODBC and I just wanted to understand why ODBC is so "bad". What are the pros and cons of the technology? What alternatives are there?
...
If I obfuscated python code, would it provide the same level of 'security' as c#/java obfuscating?
i.e it makes things a little hard, but really you can still reverse engineer if you really wanted to, its just a bit cryptic.
...
I can filter the following dictionary like:
data = {
1: {'name': 'stackoverflow', 'traffic': 'high'},
2: {'name': 'serverfault', 'traffic': 'low'},
3: {'name': 'superuser', 'traffic': 'low'},
4: {'name': 'mathoverflow', 'traffic': 'low'},
}
traffic = 'low'
for k, v in data.items():
if v['traffic'] == traffic:
...
I have a (single line) TextCtrl. The user types data into this. When they press enter, the contents of the box need to be extracted so they can be processed. I can't figure out how to catch enter being pressed.
According to the docs, with the style wx.TE_PROCESS_ENTER set on my TextCtrl, it should generate a wx.EVT_COMMAND_TEXT_ENTER ev...
So my problem is the look and feel from my application, as it looks like an old look app.
It is an wxPython application, and on python it runs fine and looks fine, but when I convert it to .exe using py2exe, the look is just bad.
Now I know that if you are using XP you need some manifest to correct it but I am in other circumstances. I...
In another question I was provided with a great answer involving generating certain sets for the Chinese Postman Problem.
The answer provided was:
def get_pairs(s):
if not s: yield []
else:
i = min(s)
for j in s - set([i]):
for r in get_pairs(s - set([i, j])):
yield [(i, j)] + r
for x ...
In a recent question I asked about the fastest way to convert a large numpy array to a delimited string. My reason for asking was because I wanted to take that plain text string and transmit it (over HTTP for instance) to clients written in other programming languages. A delimited string of numbers is obviously something that any client ...
Hello:
I'm looking for an easy-to-use graphics lib for python that can output to screen as well as pdf. So, I would use code to draw some stuff (simple prims like ovals, rectangles, lines and points) to screen and then when things look good, have it output to pdf.
Make sense?
Thanks!
Blue
...
I have an array like:
a = array([[1,2,3],[3,4,5],[4,5,6]])
what's the most efficient way to slice out a 1x2 array out of this that has only the first two columns of "a"?
I.e.,
array([[2,3],[4,5],[5,6]]) in this case.
thanks.
...
Hi Everyone,
I am really new to Python, and programming in general, but I have a python script I would like to run at regular intervals. I am running windows 7. What is the best way to accomplish this? Easiest way?
Any help you can provide will be very much appreciated!
Brock
...
In the config file I have the varible defined as
BackgroundColor = 0,0,0
Which should work for the screen.fill settings for Pygame or any color argument for that matter. Where I can just do screen.fill(0,0,0)
The problem I think is with this is that for integers read through a configfile I have to put int() to convert the string to a...
I am unable to find examples where xlwt is used to write into existing files. I have a existing xls file that I need to write to. When I use xlrd to read the file, I cant seem to figure out how to transform the "Book" type returned into a xlwt.Workbook. I would appreciate if someone can point me to an example.
...