Hi,
Can someone indicate what I am doing wrong here?
import numpy as np
a = np.array([1,2,3,4,5],dtype=int)
b = np.array(['a','b','c','d','e'],dtype='|S1')
np.savetxt('test.txt',zip(a,b),fmt="%i %s")
The output is:
Traceback (most recent call last):
File "loadtxt.py", line 6, in <module>
np.savetxt('test.txt',zip(a,b),fmt="%...
Hi!
I'm not sure if i need lamda, or something else. But still, i need following:
I have an array = [1,2,3,4,5]
I need to put this array, for instance, into another array. But write it all in one line.
for item in array:
array2.append (item)
I know that this is completely possible to iterate through the items and make it one-l...
I've created a custom Manager for a Django model which returns a QuerySet holding a subset of objects.all(). I need this to be the model's default Manager, since I am also creating a custom tag which will retrieve content from any model (specified by an argument), and needs to use the default Manager for the specified model. All that wor...
Suppose I have
@someDecorator
def func():
'''this function does something'''
print 1
Now, the object func is an instance of someDecorator. Is there some way I can access the function it holds, i.e something like func.getInnerFunction().
For instance, if I need to retrieve the doc string of func().
...
I'm trying to log a UTF-8 encoded string to a file using Python's logging package. As a toy example:
import logging
def logging_test():
handler = logging.FileHandler("/home/ted/logfile.txt", "w",
encoding = "UTF-8")
formatter = logging.Formatter("%(message)s")
handler.setFormatter(formatte...
What is the best way to implement a python program that will take a string and will output its result according to operator precedence (for example: "4+3*5" will output 19). I've googled for ways to solve this problem but they were all too complex, and I'm looking for a (relatively) simple one.
clarification: I need something slightly m...
Hello world!
I am a newbie to python but, believe me I have done a day of browsing to find an answer for this issue, :(
The error message I am trying to get rid of is:
AttributeError: 'sqlite3.Connection'
object has no attribute
'enable_load_extension'
I have 'easy_install'-ed the latest sqlite3 version and python somehow kno...
Hi, I'm trying to figure out how to apply a for-loop to this script and I'm having a lot of trouble. I want to iterate through a list of subdomains which are stored in csv format (ie: one column with 20 subdomains) and print the html for each. They all have the same SourceDomain. Thanks!
#Python 2.6
from selenium import selenium
impo...
I am looking for Python implementation of k-means algorithm with examples to cluster and cache my database of coordinates.
...
If my string was:
Business -- way's
I'd like to turn this into:
Business ways
ie. replace NON abc/123 into ""
...
Hello, check the following script:
from mechanize import Browser
br = Browser()
page = br.open('http://scottishladiespool.com/register.php')
br.select_form(nr = 5)
r = br.click(type = "submit", nr = 0)
print r.data
#prints username=&password1=&password2=&email=&user_hide_email=1&captcha_code=&user_msn=&user_yahoo=&user_web=&user_loca...
I'd like to replace " and -
with "" nothing! make it disappear.
s = re.sub(r'[^\w\s]', '', s) this makes all punctuation disappear, but I just want those 2 characters. Thanks.
...
I'm new to python an I decided to give it a try with TG2 by developing a small store. So far I've been loving it, but I'm guessing that my coding parading is still very attached to java's Like for example, the add to cart method in my CartController.
def add(self, **kw):
pid=kw['pid']
product = model.Product.by_id(pid)
c...
Does anyone have a simple example of sending an XML POST request to a RESTful API with Python? I am trying to use the urllib2 Python library to "create a new project" in the Harvest API, with no luck. The payload variable is a valid XML document that is a near copy/paste of their documentation (under the Create New Project heading) sho...
I'm trying to scrape some information from a web site, but am having trouble reading the relevant pages. The pages seem to first send a basic setup, then more detailed info. My download attempts only seem to capture the basic setup. I've tried urllib and mechanize so far.
Firefox and Chrome have no trouble displaying the pages, altho...
I want to transform photos in python to look like this:
taken from doctype.com
I will use it in django, PIL is installed.
How can I achieve this?
...
Suppose this is the string:
The fox jumped over the log.
It would result in:
The fox jumped over the log.
What is the simplest, 1-2 liner that can do this? Without splitting and going into lists...
...
I have a struct I'm accessing via ctypes:
struct attrl {
char *name;
char *resource;
char *value;
struct attrl *next;
enum batch_op op;
};
So far I have Python code like:
# struct attropl
class attropl(Structure):
pass
attrl._fields_ = [
("next", POINTER(attropl)),
("name", c_char_p),
...
I need for testing purposes to populate few hundred email boxes with various messages, and was going to use smtplib for that. But among other things I need to be able to send messages not only TO specific mailboxes, but CC and BCC them as well. It does not look like smtplib supports CC-ing and BCC-ing while sending emails.
Looking for...
This is only the second question with the parallel-python tag. After looking through the documentation and googling for the subject, I've come here as it's where I've had the best luck with answers and suggestions.
The following is the API (I think it's called) that submits all pertinent info to pp.
def submit(self, func, args=(), ...