I'm trying to use matplotlib to prepare some figures for publication. In order to make the font sizes match the text of the manuscript I'm trying to create the figure in the final size to begin with, so that I avoid scaling the figure when inserting it into the manuscript.
The problem I'm having is that as the figure is then pretty smal...
I'm writing a python script that uses subprocess.Popen to execute two programs (from compiled C code) which each produce stdout. The script gets that output and saves it to a file. Because the output is sometimes large enough to overwhelm subprocess.PIPE, causing the script to hang, I send the stdout directly to the log file. I want to ...
How do I create a user in Linux using Python? I mean, I know about the subprocess module and thought about calling 'adduser' and passing all the parameters at once, but the 'adduser' command asks some questions like password, full name, phone and stuff. How would I answer this questions using subprocess?
I've seen module called pexpe...
I have been working on a spider that gathers data for research using Scrapy. It crawls around 100 sites that each have a large amount of links within them. I need to specifly were the spider crawls so that I can tell the spider to collect data from certain parts of the site, while not crawling others to save time. I have been having muc...
I'm writing a bash script that needs to parse html that includes special characters such as @!'ó. Currently I have the entire script running and it ignores or trips on these queries because they're returned from the server as decimal unicode like this: '. I've figured out how to parse and convert to hexadecimal and load these into py...
I started learning python about a month ago and just finished going through most of diveintopython. I'm planning to build a very simple stackoverflow clone to further enhance my python skills; however, I'm not sure how to go about doing this. I don't really have a broad knowledge of web frameworks/technologies available and I'm wondering...
Hi,
I'd like to implement an object, that bounds values within a given range after arithmetic operations have been applied to it. The code below works fine, but I'm pointlessly rewriting the methods. Surely there's a more elegant way of doing this. Is a metaclass the way to go?
def check_range(_operator):
def decorator1(instance,_v...
import itertools
import string
def crackdict(max, min=1, chars=None):
assert max >= min >= 1
if chars is None:
import string
chars = string.printable[:-5]
p = []
for i in xrange(min, max + 1):
p.append(itertools.product(string.printable[:-5], repeat=i))
return itertools.chain(*p)
#Just for test:
max, m...
Hello
I'm having some trouble with my script.
It's supposed to open a website trough a proxy but I get, always, this error, with several proxies that I'm trying to...
What could it be?
Traceback (most recent call last):
File "C:\Users\Shady\Desktop\ptzplace.3.0 - Copy.py", line 43, in <module>
h = urllib.urlopen(website, proxies...
How can I remove the ^M character from a text file (at the end of line) in Python script? I did the following, and there are ^M at every line-break. Please help.
file = open(filename, "w")
file.write(something)
Thanks in advance.
...
I want to make programs to windows with interface and I want to know what is the best, or the easier program to make gui with Python, not in text mode, but like kinda Delphi works...
What should I get?
...
I'm calling my form, with additional parameter 'validate :
form = MyForm(request.POST, request.FILES, validate=True)
How should I write form's init method to have access to this parameter inside body of my form (for example in _clean method) ? This is what I came up with :
def __init__(self, *args, **kwargs):
try:
validate...
I need to send objects around a network. I'm going to be using Twisted, and I've just started looking around the documentation for it.
As far as I know, the only way python implements sockets is through text. So how would I send an object using strings? Pickle? Or is there something better?
Thanks,
Alex
...
In Python 2.7 running on WinXPpro:
import csv
outfile = file('test.csv','w')
writer = csv.writer(outfile,delimiter=',',quoting=csv.QUOTE_MINIMAL)
writer.writerow(['hi','dude'])
writer.writerow(['hi2','dude2'])
outfile.close()
Generates a test.csv file with an extra \r at each row, like so:
test.csv
hi,dude\r\r\nhi2,dude2\r\r\n
ins...
I have a very simple waf script that I'm using to (at the moment) call out to another build system (baby steps you see). Our 'build' folder is under our source folder, so I figured using the first line
top = '..'
would set waf to look for source files starting at that directory for any build commands. However, when running waf, it's...
I have this form class :
class MyForm(forms.Form):
def __init__(self, *args, **kwargs):
self.notvalidate = kwargs.pop('notvalidate',False)
super(MyForm, self).__init__(*args, **kwargs)
email = forms.EmailField(widget=forms.TextInput(attrs=dict(attrs_dict,maxlength=75)))
(...)
if not notvalidate: ...
What happens internally when I press Enter?
My motivation for asking, besides plain curiosity, is to figure out what happens when you
from sympy import *
and enter an expression. How does it go from Enter to calling
__sympifyit_wrapper(a,b)
in sympy.core.decorators? (That's the first place winpdb took me when I tried inspecting an...
How can I fetch genomic sequence efficiently using Python? For example, from a .fa file or some other easily obtained format? I basically want an interface fetch_seq(chrom, strand, start, end) which will return the sequence [start, end] on the given chromosome on the specified strand.
Analogously, is there a programmatic python interf...
I'm new to the ideas of decorators (and still trying to wrap my head around them), but I think I've come across a problem that would be well suited for them. I'd like to have class that is decorated across all of the functions in the math library. More specifically my class has two members, x and flag. When flag is true, I'd like the ori...
Hi,
I have a big list of tuples (a, b), where both a and b are 9-dimensional vectors from the same space. This essentially encodes states of a system and some transitions. I would like to visualize the field described by these tuples, as arrows pointing from a->b, either in 2D or 3D. One of my problems however is that this is not a wel...