python

Can I prevent modifying an object in Python?

I want to control global variables (or globally scoped variables) in a way that they are set only once in program initialization code, and lock them after that. I use UPPER_CASE_VARIABLES for global variables, but I want to have a sure way not to change the variable anyway. Does python provide that (or similar) feature? How do you c...

python bitwise operation

hi i am new in python just started learning with python i got a task in which i need to store "1" byte of integer into different bits just like RGB the value are store in that can any one would write a small program for me and explain that ,please i need a help Thankyou ...

Remove empty lines

I have large string which I split by newlines. How can I remove all lines that are empty, (whitespace only)? pseudo code: for stuff in largestring: remove stuff that is blank ...

Python import problem with Django management commands

For whatever reason, when I was new to Python and Django, I wrote some import statements like this at the top of a models.py file: from django.contrib import auth And I'd use it like this: class MyModel(models.Model): user = models.ForeignKey(auth.models.User) # ... This worked fine. A long time later, I wrote a custom mana...

distutils and package_data: cannot copy whole directory content

Let's take the following project layout: $ ls -R . .: package setup.py ./package: __init__.py dir file.dat module.py ./package/dir: tool1.dat tool2.dat And the following content for setup.py: $ cat setup.py from distutils.core import setup setup(name='pyproj', version='0.1', packages=[ 'package', ...

mediawiki / python auth integration advice needed

Hi, I'm trying to integrate my mediawiki site with some custom python web apps. I have complete control over the mediawiki server, and am free to change the authentication plugin if needed. For the time being, I would like all users to login via a screen on the mediawiki page (or at least they should believe they are, the whole process ...

How does Boost.Python work?

How is Python able to call C++ objects when the interpreter is C and has been built w/ a C compiler? ...

Why isn't posting a status update to Facebook working?

I had a working Python integration to Facebook, using the Graph API and the https://graph.facebook.com/<<id>>/feed URL, for about a month. And then all of a sudden a few days ago, I started getting this back whenever I tried to post a status update: {"error":{"type":"OAuthException","message":"(#200) The user hasn't authori...

Selenium-rc: How do you use CaptureNetworkTraffic in python

I've found many tutorials for selenium in java in which you first start selenium using s.start("captureNetworkTraffic=True"), but in python start() does not take any arguments. How do you pass this argument? Or don't you need it in python? ...

thread Locking/unlocking in constructor/destructor in python

I have a class that is only ever accessed externally through static methods. Those static methods then create an object of the class to use within the method, then they return and the object is presumably destroyed. The class is a getter/setter for a couple config files and now I need to place thread locks on the access to the config fil...

Python Regular Expression Question

Say I have text 'C:\somedir\test.log' and I want to replace 'somedir' with 'somedir\logs'. So I want to go from 'C:\somedir\test.log' to 'C:\somedir\logs\test.log' How do I do this using the re library and re.sub? I've tried this so far: find = r'(C:\\somedir)\\.*?\.log' repl = r'C:\\somedir\\logs' print re.sub(find,repl,r'random tex...

Convert string to tuple on Python

Hello I have a tuple in string that I revive from a PostgreSQL function> I want to convert that to a tuple but it gives me an error with the real string inside the tuple an EOF error, the code it's like this. eval('(4125, <html> <body> Heloo There! <body> </html>)') , this is just an example of the HTML because the real code it's to ...

Django querysets - make sure results are retrieved only once

I've got a simple function to get some additional data based on request.user: def getIsland(request): try: island = Island.objects.get(user=request.user) # Retrieve except Island.DoesNotExist: island = Island(user=request.user) # Doesn't exist, create default one island.save() island.update() # Run scheduled tasks return islan...

Does Python have a method that returns all the attributes in a module?

I already search for it on Google but I didn't have lucky. ...

How badly should I avoid surrogate primary keys in SQL?

Short story I have a technical problem with a third-party library at my hands that I seem to be unable to easily solve in a way other than creating a surrogate key (despite the fact that I'll never need it). I've read a number of articles on the Net discouraging the use of surrogate keys, and I'm a bit at a loss if it is okay to do what ...

Python: How to use platform.win32_ver() on a remote machine?

So of course I'm new to Python and to programming in general... I am trying to get OS version information from the network. For now I only care about the windows machines. using PyWin32 I can get some basic information, but it's not very reliable. This is an example of what I am doing right now: win32net.NetWkstaGetInfo(myip, 100) Howe...

Upgrading Python in Virtual Env

I have python 2.6.1 installed on Mac OS X. I wanted to play around with python 3.2, so i created a virtual enviromant using virtualenv python3.0 and then activated it using source python3.0/bin/activate if I update the python in the virtualenv will it leave my system python untouched? If yes, do I just install python 3 using pip in...

Python, Django, using Import from inside of a class, can't seem to figure this out

I want to use imports inside a class that is then inherited by another class so that I don't have to manually define my imports in each file. I am trying it like this but its not working, any advice is appreciated: class Djangoimports (): def __init__(self): from django.template import Context print Context class I...

python 2.6.x theading / signals /atexit fail on some versions?

I've seen a lot of questions related to this... but my code works on python 2.6.2 and fails to work on python 2.6.5. Am I wrong in thinking that the whole atexit "functions registered via this module are not called when the program is killed by a signal" thing shouldn't count here because I'm catching the signal and then exiting cleanly?...

Python: spawn or thread for long running background process?

Hi there, I am planning to make a long running background process with Python but I am still unsure whether to use os.spawnle or thread. I've only read about it therefore I have not much experience with either spawn or thread. Is there any rule of thumb when to use which? Thanks heaps ...