what's best solution using regex, to remove special characters from the begin and the end of every word.
"as-df-- as-df- as-df (as-df) 'as-df' asdf-asdf) (asd-f asdf' asd-f' -asdf- %asdf%s asdf& $asdf$ +asdf+ asdf++ asdf''"
the output should be:
"as-df-- as-df- as-df (as-df) as-df asdf-asdf) (asd-f asdf' asd-f' asd...
If the my_list variable is global, you can't do:
my_list = []
that just create a new reference in the local scope.
Also, I found disgusting using the global keyword, so how can I empty a list using its methods?
...
I have the following code:
def f():
class XYZ:
# ...
cls = type('XXX', (XYZ, ), {})
# ...
return cls
I am now using it as follows:
C1 = f()
C2 = f()
and it seems to work fine: C1 is C2 returns False, there's no conflict between the class attributes of the two classes, etc.
Question 1
Why is that? How is it...
I am using ElementTree and cannot figure out if the childnode is text or not. childelement.text does not seem to work as it gives false positive even on nodes which are not text nodes.
Any suggestions?
Example
<tr>
<td><a href="sdas3">something for link</a></td>
<td>tttttk</td>
<td><a href="tyty">tyt for link</a></td>
</tr>
Af...
Hello everyone. I have a question regarding regular expressions in Python. The expressions are composed of data that would be read from a server, connected via socket. I'm trying to use and read wildcards in these expressions. Example: Let's say I run a chat server. When a message is recieved, the server sends to all clients (JSmith send...
I'm in a situation where I need to merge two Django apps into a single, re-usable app. Neither are particularly large, but they are certainly not trivial apps and to preserve readability / sanity I'm trying to keep the two apps separated to some extent.
I could set up each app as a sub-package (which would be a pythonic way to achieve ...
I'm not asking about Python's scoping rules; I understand generally how scoping works in Python for loops. My question is why the design decisions were made in this way. For example (no pun intended):
for foo in xrange(10):
bar = 2
print(foo, bar)
The above will print (9,2).
This strikes me as weird: 'foo' is really just control...
I'm trying to return a django object in a XML-RPC response. Is it possible to serialize a model as XML-RPC methodResponse?
...
I want to use all the data in my python app engine memcache. I do not know the keys in advance.
How do I go about getting all data?
...
I wrote a simple Python script to download a web page for offline viewing. The problem is that the relative links are broken. So the offline file "c:\temp\webpage.html" has a href="index.aspx" but when opened in a browser it resolves to "file:///C:/temp/index.aspx" instead of "http://myorginalwebsite.com/index.aspx".
So I imagine that...
Er, so im juggling parsers and such, and I'm going from one thing which processes files to another.
The output from the first part of my code is a list of strings; I'm thinking of each string as a line from a text file.
The second part of the code needs a file type as an input.
So my question is, is there a proper, pythonic, way to co...
Suppose I have a directory: /home/user/files/. This dir has a bunch of files:
/home/user/files/
-- test.py
-- config.py
I want to zip this directory using ZipFile in python. Do I need to loop through the directory and add these files recursively, or is it possible do pass the directory name and the ZipFile class automatically adds...
Wanted an easy way to extract year month and day from a string.
Using Python 3.1.2
Tried this:
processdate = "20100818"
print(processdate[0:4])
print(processdate[4:2])
print(processdate[6:2])
Results in:
...2010
...
...
Reread all the string docs, did some searching, can't figure out why it'd be doing this.
I'm sure this is a no b...
I've been wondering why python gets installed in directory named Frameworks? (though it's not Framework)
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Somebody please explain! Thanks!
...
level: beginner
why do i get error "can't multiply sequence by non-int of type 'float'"?
def nestEgVariable(salary, save, growthRates):
SavingsRecord = []
fund = 0
depositPerYear = salary * save * 0.01
for i in growthRates:
fund = fund * (1 + 0.01 * growthRates) + depositPerYear
SavingsRecord += [fund...
I don't get what Clyther is or how to use it.
My stuff:
ATI OpenCl SDK (just dl'd)
clyther beta (just dl'd)
windows 7 pro 64 bit
active python 3.1.2
Xfxs Ati radeon 5850 video card
I downloaded the ATI OpenCl SDK and the clyther beta from sourceforge. Then I tooke the sample 'reduce' function from the sourceforge documents ...
Program design:
Class A, which implements lower level data handling
Classes B-E, which provide a higher level interface to A to perform various functions
Class F, which is a UI object that interacts with B-E according to user input
There can only be one instantiation of A at any given time, to avoid race conditions, data corrupti...
I am trying to capture / extract numeric values from some strings.
Here is a sample string:
s='The shipping company had 93,999,888.5685 gallons of fuel on hand'
I want to pull the 93,999,888.5685 value
I have gotten my regex to this
> mine=re.compile("(\d{1,3}([,\d{3}])*[.\d+]*)")
However, when I do a findall I get the following...
What is the best way to deal with multiple forms? I want to combine several forms into one. For example, I want to combine ImangeFormSet and EntryForm into one form:
class ImageForm(forms.Form):
image = forms.ImageField()
ImageFormSet = formset_factory(ImageForm)
class EntryForm(forms.Form):
title = forms.CharField(max_length=1...
I am new to installers and up until now have just been manually executing a line by line list of items to install. Clearly this is not a scaleable approach, especially when new servers need to be installed regularly, and not by the same person.
Currently I need to install about 30 packages via Yum (from large ones like mySQL to smaller ...