I have mylist = [var1, var2, var3... varn].
os.path.join is called not one list, but with many vars.
I can't call os.path.join(mylist).
How to call os.path.join(var1, var2, var3... varn)?
...
I have two lists of strings that, in a better world, would be one list. I need to concatenate the lists, but the last element of the first list needs to be concatenated with the first element of the second list. So these guys:
list1 = ["bob", "sal"]
list2 = ["ly", "nigel"]
needs to become
out = ["bob", "sally", "nigel"]
So this isn...
Is it possible to do array broadcasting in numpy with parameters that are vectors?
For example, I know that I can do this
def bernoulli_fraction_to_logodds(fraction):
if fraction == 1.0:
return inf
return log(fraction / (1 - fraction))
bernoulli_fraction_to_logodds = numpy.frompyfunc(bernoulli_fraction_to_logodds, 1, 1)...
Hi,
i'am looking for a way to attune a song to the heart rate of someone.
I have a song in mp3 or wav format and i want to accelerate the speed of it while playing it.
Or playing it in loop and between each loop accelerate it or slow it.
Ideally it will be in python.
Do you know a way to do that ?
Regards and thanks.
Bussiere
...
Here is an example:
def g():
yield str('123')
yield int(123)
yield str('123')
o = g()
while True:
v = o.next()
if isinstance( v, str ):
print 'Many thanks to our generator...'
else:
# Or GOD! I don't know what to do with this type
#
raise TypeError( '%s:%d Unknown yield value type %s.' % \
...
I've got a socket from which I'm reading XML data. However, this socket will spit out multiple different XML documents, so I can't simply parse all the output I receive.
Is there a good way, preferably using the Python standard library, for me to parse multiple XML documents? In other words, if I end up getting
<foo/>
<bar/>
then i...
Dear Stackoverflow users,
I'm trying to perform GLM (Generalized linear model) repeatedly within a python script (within a loop).
1- I tried to use Stats within Scipy glm function but description is quite inexistant and I think I did not use it well --> error message "ValueError: only ttest_ind implemented". I searched within stats.py f...
All,
I have below functions
def foo_001(para):
tmp = para + 2
return tmp
def foo_002(para):
tmp = para * 2
return tmp
def foo_003(para):
tmp = para / 2
return tmp
def foo_004(para):
tmp = para - 2
return tmp
those functions only have different in function names while the algorithm line e.g. "tmp = p...
I'm working on a web parser using urllib. I need to be able to only save lines that lie within a certain div tag. for instance: I'm saving all text in the div "body." This means all text within the div tags will be returned. It also means if there are other divs inside of it thats fine, but as soon as I hit the parent it stops. An...
I'm running into some trouble with deploying Django on the passenger_wsgi module with virtualenv. The Python code in the passenger_wsgi.py file, which should fix my problem is:
import os, sys
INTERP = '/home/login/.virtualenvs/env_name/bin/python'
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
The first three lin...
I'm writing a small Python script using the PIL module to change the size of some textures used on a 3D Model in MultiGen Creator. I'm also using the openflight API so that's what the mg* functions are.
Here's the script
import PIL
from PIL import Image
db = mgGetCurrentDb()
ret,index,name = mgGetFirstTexture (db)
while (ret):
myAtt...
Hello,
i have an image saved on my HDD and i want to assign it to an ImageField, but i don't know how.
i've tried something like this:
object.imagefield.save(path,File(open(path)))
But this makes an additional (invalid) copy of the image.
Can someone help me please?
thanks!
...
Hey I need to save a temporarily jpg file and then remove it, is there any better way to do?
I tested the tempfile, but looks that doesn't work.
...
I'm writing a series of SQL statements to a file using python. The template string looks like:
store_insert = '\tinsert stores (storenum, ...) values (\'%s\', ...)'
I'm writing to the file like so:
for line in source:
line = line.rstrip()
fields = line.split('\t')
script.write(store_insert % tuple(fields))
script.writ...
I have a question about righteous way of programming in Python... Maybe there can be several different opinions, but here it goes:
Let's say I have a class with a couple of private attributes and that I have implemented two getters/setters (not overloading __getattr__ and __setattr__, but in a more “Java-tistic” style):
class MyClass:
...
I've been learning more about Python recently, and as I was going through the excellent Dive into Python the author noted here that the __init__ method is not technically a constructor, even though it generally functions like one.
I have two questions:
What are the differences between how
C++ constructs an object and how
Python "cons...
Hello,
My needs :
I need to develop an GUI application that is cross platform
the chosen solution must be the fastest to implement
it should be easy to extend
The application is just a database front-end, mainly for CRUD operations, listing, filtering, exporting, charts and graphs etc.
After reading about some solutions (Python Car...
I have this list:
single = ['key', 'value', 'key', 'value', 'key', 'value']
What's the best way to create a dictionary from this?
Thanks.
...
I have Publications and Authors. Since the ordering of Authors matters (the professor doesn't want to be listed after the intern that contributed some trivial data), I defined a custom many-to-many model:
class Authorship(models.Model):
author = models.ForeignKey("Author")
publication = models.ForeignKey("Publication")
order...
In the current implementation of CPython, there is an object known as the "GIL" or "Global Interpreter Lock". It is essentially a mutex that prevents two Python threads from executing Python code at the same time. This prevents two threads from being able to corrupt the state of the Python interpreter, but also prevents multiple threads ...