python

Python import inconsistent behavior

I have a py file like this, which errors out. from world import acme def make_stuff_happen(): acme.account.foo() # Works acme.subscription.bar() # FAIL: "module 'object' has no attribute 'subscription'" make_stuff_happen() But this works! from world import acme from world.acme import subscription def make_stuff_hap...

Mutex locks vs Threading locks. Which to use?

hello all. My main question is does the Threading lock object create atomic locks? It doesn't say that the lock is atomic in the module documentation. in pythons mutex documentation it does say the mutex lock is atomic but it seems that I read somewhere that in fact it isn't. I am wondering if someone could could give me a bit of insight...

Troubles in installing python-sybase module

Hello guys, I am trying to install this module simply following the installation guide: http:// python-sybase.sourceforge.net/sybase/node5.html I get an error that I don't understand, I am wondering if it's not a firewall problem but I don't know how to handle that: C:\Documents and Settings\lippela\Desktop\python-sybase-0.39>python ...

Dynamically loading two libpython versions

I have a program which embeds both python2 and python3 interpreters. The libpython shared libraries are dlopen()ed by the respective commands which provide access to the interpreters and each interpreter maintains its own state. This all works just fine if the user only uses pure python modules or builtins. Trying to load a C extensio...

Recursively walking a Python inheritance tree at run-time

Hi, I'm writing some serialization/deserialization code in Python that will read/write an inheritance hierarchy from some JSON. The exact composition will not be known until the request is sent in. So, I deem the elegant solution to recursively introspect the Python class hierarchy to be emitted and then, on the way back up through the ...

Python: File not formatting like it should

The could below doesnt write to the text file as it should: import re download_results = open('download_result.txt', 'w') s = 'AAAAAAABBBBCDEEEEEFFFFFFFFFFFFFGGGGGGGGGGGG##GGGGGGHHHHHHHHHHHHHHIIIIIIIIIIIIIIIIIJJJJJJJJJJJJJJKKKKKKKKKKKKLLLLLLLLLLLLLLLLMMMMMMM&&MMMMMMMMNNNNNNNNNNNNOOOOOOOOOOOO' s = re.sub(r'[^\w]','',s) s = ''.join(s) fo...

Rails or Django?

Possible Duplicates: Rails or Django? (or something else?) Django or Rails? I come from a PHP background and was planning to try out a new framework. I have never done Ruby or Python before. Knowing PHP, what language would be easier to learn? ...

I need help making a list.

I am trying to make a disorganized text file into a list suitable for use with another python program. The text file is a list of data seperated by a few spaces but not in standard columns or anything organized. The goal of this program is to read through the file using python and after each piece of data that I want there is a space, so...

Python list remove method: how's the implementation?

In java, I have my client class that have the "code" attr, and the equals method. Method equals receives another client and compares with itself's code attr. In python, I just read that we have the __cmp__ method, to do the same as java method equals. Ok, I did that. I created my class client, with "code" attr and the method comp that v...

Implementing Load Balancing Using Python

I am doing some research this summer and working on parallelizing pre-existing code. The main focus right now is a way to load balance the code so that it will run more efficient on the cluster. The current task is to make a proof of concept that creates several processes with each one having their own stack available and when the proces...

My memcache is timing out. Does anyone know why?

I am using memcached and python-memcache. On my cache server, iptables is set perfectly, and it's allowed: ACCEPT all -- dev anywhere The process is this: /usr/local/bin/memcached -d -u root -m 3900 -p 11211 I do this in Django but it's not working. It times out at cache.set. cache.set("test","laa",333) prin...

Suppose I had a list in Python. What's the most pythonic and efficient way to randomize it by sections?

I have a list of X items. I want the first 10 to be randomized. Then, the 2nd 10 items to be randomized. Then the 3rd. What's the most efficient way to do this? ...

Search a file and save the lines the search term is in to a new file

Hi, I have two files. One is a csv and contains the search strings (one per line) and the other is a huge file which contains the search term at the start of each line but has extra information after which I would like to extract. The search terms file is called 'search.csv' and looks like this: 3ksr 3ky8 2g5w 2gou The file cont...

Is this method of file locking acceptable?

We have 10 Linux boxes that must run 100 different tasks each week. These computers work at these tasks mostly at night when we are at home. One of my coworkers is working on a project to optimize run time by automating the starting of the tasks with Python. His program is going to read a list of tasks, grab an open task, mark that ta...

Internal Server Error on Django Deploy

Im getting 500 internal server error everytime I try access my admin or login page. There's nothing in my error.log Any ideas ? ...

Ensuring code coverage in unit testing?

We have noticed that even though we have a lot of doctests in our Python code, when we trace the testing using the methods described here: traceit we find that there are certain lines of code that are never executed. We currently sift through the traceit logs to identify blocks of code that are never run, and then try to come up with ...

Making directories recursively in python

I need to create a file with python, in the directory: foo/bar/baz/filename.fil The only problem, is that I don't know if baz, bar, or even foo have been created (they may have been, but the script doesn't guarantee it). So, obiously I can't do simply: file = open('foo/bar/baz/filename.fil', 'wb') # Stuff # file.close() because I ...

Are there frameworks for Jython or JRuby, or is it you can run a py or ruby app on the JVM?

Are there specific frameworks for Jython or JRuby, or is it you can run a py or ruby app on the JVM? i.e. you take your python django app, and you can run in on tomcat using jython? Sorry little confused. ...

Why is Python saying pow only has 2 arguments

Why is python telling me "TypeError: pow expected 2 arguments, got 3" despite it working in IDLE (sometimes it tells me that in IDLE as well)? im simply doing pow(a,b,c). my program is very short and i do not change the definition of pow at any time since i need to use it for some exponentiation. NOTE: This is the pow from __builtin__, ...

Explain Polymorphism ?

Now can anyone explain polymorphism to me? I'm not sure I am understanding it correctly. In the Python scope, what I am getting out of it is that I can define parameters as followed: def blah (x, y) without having to specify the type, as opposed to another language like Java, where it'd look more along the lines of: public void blah...