Hi,
I have a numpy array:
A = array([['id1', '1', '2', 'NaN'],
['id2', '2', '0', 'NaN']])
I also have a list:
li = ['id1', 'id3', 'id6']
I wish to iterate over the array and the list and where the first element in each row of the array is not in the list, then delete that entire row from the array.
My code to date:
fr...
Hi there.
How do I find multiple occurrences of a string within a string in Python? Consider this:
>>> text = "Allowed Hello Hollow"
>>> text.find("ll")
1
>>>
So the first occurrence of ll is at 1 as expected. How do I find the next occurrence of it?
Same question is valid for a list. Consider:
>>> x = ['ll', 'ok', 'll']
How do ...
I have a form that I need to post data to, however it must have a specific user agent string and HTTP/1.1 headers, (not just host it explicitly looks for HTTP/1.1 in the POST string.)
I've attempted this so far as follow:
class AppURLopener(urllib.FancyURLopener):
version = "The User Agent String"
urllib._urlopener = AppURLopener(...
Hello,
In my Python application, I would like to be able to send mail to addresses like っていった@example.jp, dé[email protected], or even عرض@وزارة-الأتصالات.مصر, which are perfectly valid.
When passing the address as UTF-8, I get an UnicodeDecodeException. If I encode the address with address.encode('utf-8'), no Python error but I get bounce...
I have the following incoming value:
variants = {
"debug" : ["on", "off"],
"locale" : ["de_DE", "en_US", "fr_FR"],
...
}
I want to process them so I get the following result:
combinations = [
[{"debug":"on"},{"locale":"de_DE"}],
[{"debug":"on"},{"locale":"en_US"}],
[{"debug":"on"},{"locale":"fr_FR"}],
[{"debug":"off"},{...
Im trying to setup situation where users of application can do statistical analysis of data.
There are 3 tables, users, exams, polls
I should have gui to build custom queries, like these:
users born between 1930 and 1940, that have 3 exams taken; show
name, surname, group by age of person
count of users born 1945 that have not taken...
I'd like to create a function, like:
def generateThumbnail(self, width, height):
"""
Generates thumbnails for an image
"""
im = Image.open(self._file)
im.thumbnail((width, height), Image.ANTIALIAS)
im.save(self._path + str(width) + 'x' +
str(height) + '-' + self._filename, "JPEG")
Where a fi...
I'm a php programmer who's just getting started with Python. I'm trying to get Python to handle login/logout via database-stored sessions. Things work, but seem inconsistent. For example, sometimes a user isn't logged out. Sometimes users "switch" logins. I'm guessing this has something to do with thread-safety, but I'm just not sur...
I have some data (text files) that is formatted in the most uneven manner one could think of. I am trying to minimize the amount of manual work on parsing this data.
Sample Data :
Name Degree CLASS CODE EDU Scores
--------------------------------------------------------------------------------------
John M...
I am attempting to create an html document parser with Python. I am very familiar with jQuery and I would like to use its traversing functionality to parse these html files and return the data gathered with jQuery back to my Python program.
Is there any way to use javascript scripts through Python? Or is this just a pipe dream?
...
Currently i'm using Alchemy as a ORM, and I look for a way to speed up my insert operation, I have bundle of XML files to import
for name in names:
p=Product()
p.name="xxx"
session.commit()
i use above code to insert my data paser from batch xml file to mysql,it's very slow
also i tried to
for name in names:
p=Produc...
Hi,
I'm getting a writeTimeout on a serial connection using pyserial.
I have googled a lot and so far i have found nothing. I thought some other might have had the same problem and solved it.
However here is my example code
ser = serial.Serial('COM10',
baudrate=115200,
timeout=2,
...
In development, it's a bit of a hassle to run the celeryd as well as the Django development server. Is it possible to, for example, ask celery to run tasks synchronously during development? Or something similar?
...
I have a simple script where I am fetching an HTML page, passing it to BeautifulSoup to remove all script and style tags, then I want to pass the HTML result to another method. Is there an easy way to do this? Skimming the BeautifulSoup.py, I haven't seen it yet.
soup = BeautifulSoup(html)
for script in soup("script"):
soup.script.e...
Hi,
I am really new to python, just played around with the scrapy framework that is used to crawl websites and extract data.
My question is, how to I pass parameters to a python script that is hosted somewhere online.
E.g. I make following request mysite.net/rest/index.py
Now I want to pass some parameters similar to php like *.php?i...
In linux, I can use lsof -i as in the following function:
def FindProcessUsingPort(portnum):
import os
fp = os.popen("lsof -i :%s" % portnum)
lines = fp.readlines()
fp.close()
pid = None
if len(lines) >= 2:
pid = int(lines[1].split()[1])
return pid
Is there a cross-platform way to figure this out?
...
I am using a large list of variables inside some definitions and classes (mainly because I want to be able to use the code-folding feature of pydev). Is there any constructor I can use on a definition or class to make its variables automatically considered globals?
This is an example of what I did after following some of the recommend...
how do i write a function removeThese(stringToModify,charsToRemove) that will return a string which is the original stringToModify string with the characters in charsToRemove removed from it.
...
I have a tool producing NewsML type XML files and I want to validate them after producing the files.
I'm receiving an error:
Attempt to load network entity http://www.w3.org/TR/ruby/xhtml-ruby-1.mod
The python call is:
parser = etree.XMLParser(load_dtd=True, dtd_validation=True)
treeObject = etree.parse(f, parser)
First I'm not sure...
Hi there
I've installed Lamson via easy_install on my webfaction shared hosting. Went to do the '30 Second Introduction' (See http://lamsonproject.org/docs/getting_started.html) but after:
[almacmillan@web129 python2.6]$ lamson gen -project mymailserver
I get:
Traceback (most recent call last):
File "/home/almacmillan/bin/lams...