I am supporting an application with a hard dependency on python-devel 2.3.7. The application runs the python interpreter embedded, attempting to load libpython2.3.so - but since the local machine has libpython2.4.so under /usr/lib64, the application is failing.
I see that there are RPMs for python-devel (but not version 2.3.x). Another...
What is the "most pythonic" way to build a dictionary where I have the values in a sequence and each key will be a function of its value? I'm currently using the following, but I feel like I'm just missing a cleaner way. NOTE: values is a list that is not related to any dictionary.
for value in values:
new_dict[key_from_value(value)...
Hello!
Can you tell me how to code a Python script which reads a file from an external server? I look for something similar to PHP's file_get_contents() or file() function.
It would be great if someone could post the entire code for such a script.
Thanks in advance!
...
I hope I framed the question right. I am trying to force myself to be a better programmer. By better I mean efficient. I want to write a program to identify the files in a directory and read each file for further processing. After some shuffling I got to this:
for file in os.listdir(dir):
y=open(dir+'\\'+file,'r').readlines()
...
I have a bit of Python to connect to a database with a switch throw in for local versus live.
LOCAL_CONNECTION = {"server": "127.0.0.1", "user": "root", "password": "", "database": "testing"}
LIVE_CONNECTION = {"server": "10.1.1.1", "user": "x", "password": "y", "database": "nottesting"}
if debug_mode:
connection_info = LOCAL_...
I'm a total python noob so please bear with me. I want to have python scan a page of html and replace instances of Microsoft Word entities with something UTF-8 compatible.
My question is, how do you do that in Python (I've Googled this but haven't found a clear answer so far)? I want to dip my toe in the Python waters so I figure somet...
A good example of this is: http://github.com/tav/tweetapp/blob/a711404f2935c3689457c61e073105c1756b62af/app/root.py
In Visual Studio (ASP.net C#) where I come from, the classes are usually split into separate files + I can set break points to understand the code level.
If I run a program like this, do I just do "system.out" to print ou...
I'm unclear on why the sub-interpreter API exists and why it's used in modules such as the mod_wsgi apache module. Is it mainly used for creating a security sandbox for different applications running within the same process, or is it a way to allow concurrency with multiple threads? Maybe both? Are there other purposes?
...
Hi,
I have a somewhat complex regular expression which I'm trying to match against a long string (65,535 characters). I'm looking for multiple occurrences of the re in the string, and so am using finditer. It works, but for some reason it hangs after identifying the first few occurrences. Does anyone know why this might be? Here's the c...
I have three modules as:
one.py:
def abc():
print "Heeeeeeeeeeeiiiiiioooooooooo"
two.py:
import one
def defg():
one.abc()
three.py:
import os
from time import sleep
import two
two.defg()
sleep(20)
directory = os.listdir('.')
for filename in directory:
if filename[-3:] == 'pyc':
print '- ' + filename
os...
I look for a possibility to create pseudo-cronjobs as I cannot use the real jobs on UNIX.
Since Python scripts can run for an unlimited period, I thought Python would be a great solution.
On Google App Engine you can set up Python scripts and it's free. So I should use the App Engine.
The App Engine allows 160,000 external URL accesse...
Suppose I have a model:
class SomeModel(models.Model):
id = models.AutoField(primary_key=True)
a = models.CharField(max_length=10)
b = models.CharField(max_length=7)
Currently I am using the defauly admin to create/edit objects of this type.
How do I remove the field b from the admin so that each object cannot be created w...
For a block like this:
try:
#some stuff
except Exception:
pass
pylint raises warning W0703 'Catch "Exception"'. Why?
...
I like this 6 line solution a lot and am trying to replicate it in C#. Basically, it permutes the elements of an array:
def permute(xs, pre=[]):
if len(xs) == 0:
yield pre
for i, x in enumerate(xs):
for y in permute(xs[:i] + xs[i+1:], pre + [x]):
yield y
...
I want to use the @after_insert decorator of Elixir, but i can't access the Session within the model. Since i have autocommit set to False, i can't commit any changes in the event handler. Is there any best practice how to deal with that?
The Code I used to build model, database connection etc. are mostly taken off the documentations.
...
What is the nicest way of splitting this:
tuple = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h')
into this:
tuples = [('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')]
Assuming that the input always has an even number of values.
...
I am new in binary conversion.
I use Python, Bash and AWK daily.
I would like to see binary conversion's applications in these languages.
For example, I am interested in problems which you solve by it at your work.
Where do you use binary conversion in Python/Bash/AWK?
I would like to see examples of codes.
...
from Tkinter import *
master = Tk()
listbox = Listbox(master)
listbox.pack()
listbox.insert(END, "a list entry")
for item in ["one", "two", "three", "four"]:
listbox.insert(END, item)
listbox2 = Listbox(master)
listbox2.pack()
listbox2.insert(END, "a list entry")
for item in ["one", "two", "three", "four"]:
listbox2.insert...
I have a mako template that looks something like this:
% if staff:
<!-- begin staff -->
...
<!-- end staff -->
% endif
That way if I pass the staff variable as being True, those comments should appear. I'm trying to test this by using a regular expression that looks like this:
re.search('<!-- begin staff -->.*<!-- end st...
I have a ctypes wrapper for a library. Unfortunately, this library is not 100% reliable (occasional segfaults, etc.). Because of how it's used, I want the wrapper to be reasonably resilient to the library crashing.
The best way to do this seems to be forking a process and sending the results back from the child. I'd like to do something...