I want to change the value of a particular string index, but unfortunately
string[4] = "a"
raises a TypeError, because strings are immutable ("item assignment is not supported").
So instead I use the rather clumsy
string = string[:4] + "a" + string[4:]
Is there a better way of doing this?
...
I'm writing a Python script that goes through a directory and gathers certain files, but there are a number of files I want excluded that all start the same.
Example code:
for name in files:
if name != "doc1.html" and name != "doc2.html" and name != "doc3.html":
print name
Let's say there are 100 hundred HTML files in the di...
I originally posted this question looking for an answer with using python, got some good help, but have still not been able to find a solution. I have a script running on OS X 10.5 client machines that captures internet browsing history (required as part of my sys admin duties in a US public school). Firefox 3.x stores history in a sqlit...
Does anyone know good books that discuss the underlying architectures, in-depth analysis of CPython implementation. Something like
how list / tuple / dict implemented (and performance comparison...)
OOP discussion in Python context
Sorry if it sounds like a silly question :(
...
How do I set the hardware clock with Python on embedded linux systems?
Regards,
...
I am creating a small PyQt application and got stuck up in MouseOver effect.
I have a QMainWindow which has three buttons named createProfileButton, downloadPackagesButton and installPackagesButton. All these are of type QPushButton
Now I have created a Label which will hold the text when someone hovers the mouse over any of these butt...
Hello,
how do I print help info if no arguments are passed to python script?
#!/usr/bin/env python
import sys
for arg in sys.argv:
if arg == "do":
do this
if arg == ""
print "usage is bla bla bla"
what I'm missing is if arg == "" line that I don't know how to express :(
...
I know it's wired to have such a case but somehow I have it:
class foo
#static method
@staticmethod
def test():
pass
# class variable
c = {'name' : <i want to reference test method here.>}
What's the way to it?
Just for the record:
I believe this should be considered as python worst practices. Using static methods is ...
I want to put multiple datasets on a bar graph and stop the smaller bars being obscured by the larger ones, and I don't want to offset them. For example,
bar(0, 1.)
bar(0, 2.)
only shows the second bar of height of 2.0, the first bar is hidden. Is there a way to get matplotlib to draw the bars with the smallest on top? NB I don't wan...
hello everyone, I have a file of lines and this in turn saves information, speed, timing and type of surfaces for each line. I want to do is sort this information in a np.array in the order shown below where the id is the number of the line.
(id) 0 1 2 3 4 5 6 7 8 9
0 t1 t2 t3 t4 t5 t6 t7 t8 t9 t10
1 t1 t2 t3 ...
Where should I write codes for checking validity of class' properties? (For examples: "amount" should be a positive integer, "email" should be a string with correct e-mail formatting) At the setter methods, At somewhere I use that (using try/catch), or others.
If I check validity at setter methods, it may be looked ugly (like type check...
In python I can easily get an index when iterating e.g.
>>> letters = ['a', 'b', 'c']
>>> [(char, i) for i, char in enumerate(letters)]
[('a', 0), ('b', 1), ('c', 2)]
How can I do something similar with linq?
...
I prefer to document each parameter (as needed) on the same line where I declare the parameter in order to apply D.R.Y.
If I have code like this:
def foo(
flab_nickers, # a series of under garments to process
has_polka_dots=False,
needs_pressing=False # Whether the list of garments should all be pressed
):
...
QGraphicsView is often hooked up to a QGraphicsScene. What if I want to swap that QGraphicsScene for a new one? How can I accomplish this? Doing it right now is just drawing over the old one.
...
Django's website seems good but for some reason I couldn't find where to download the documentation:
http://docs.djangoproject.com/en/1.1/
(Yes, I need the docs for 1.1)
Does anyone know?
...
I am using M2Crypto-0.20.2. I want to use engine_pkcs11 from the OpenSC project and the Aladdin PKI client for token based authentication making xmlrpc calls over ssl.
from M2Crypto import Engine
Engine.load_dynamic()
dynamic = Engine.Engine('dynamic')
# Load the engine_pkcs from the OpenSC project
dynamic.ctrl_cmd_string("SO_PATH", "/...
I use python based as well as rails applications on ubuntu linux. We have functionalities like register, forgot password, reset password, email alerts etc features based on emails. Since now a days, we go on offline development, we want to run a local smtp & pop3 server to send and receive emails.
Emails shall be send via the our web ap...
Suppose I have a string "a foobar" and I use "^a\s*" to match "a ".
Is there a way to easily get "foobar" returned? (What was NOT matched)
I want to use a regex to look for a command word and also use the regex to remove the command word from the string.
I know how to do this using something like:
mystring[:regexobj.start()] + email...
how do I know if a remote user is connected in django?, like gmail chat, or facebook chat... I need that in the templates system. Sorry for my english
...
I cannot get the example Python programs to run. When executing the Python command "from opencv import cv" I get the message "ImportError: No module named _cv". There is a stale _cv.pyd in the site-packages directory, but no _cv.py anywhere. See step 5 below.
MS Windows XP, VC++ 2008, Python 2.6, OpenCV 2.0
Here's what I have done.
...