python

Python - checking if a user has administrator privileges

I'm writing a little program as a self-learning project in Python 3.x. My idea is for the program to allow two fields of text entry to the user, and then plug the user's input into the value of two specific registry keys. Is there a simple way to make it check if the current user can access the registry? I'd rather it cleanly tell the u...

python simpleJSONDecoder and complex JSON issue

In a unit test case that I am running, I get a KeyError exception on the 4th json object in the json text below because the piece of code responsible for decoding is looking for an object that isn't there, but should be. I went through the sub-objects and found that it was the "cpuid" object that causes the problem. When I remove it ...

does webapp has 'elseif' or 'elif' in template tags..

my code is : Hello!~~~ {% if user %} <p>Logged in as {{ user.first_name }} {{ user.last_name }}.</p> {% elif openid_user%} <p>Hello, {{openid_user.nickname}}! Do you want to <a href="{{openid_logout_url}}">Log out?</p> {% else %} <p><a href="/login?redirect={{ current_url }}">google Log in</a>.</p> <p><a href="/twitter">...

Index of nth biggest item in Python list

I can't edit or sort the list. How can I get that index? ...

Where is python freeze utility

I just installed python 2.6 on my mac, mainly because I couldn't find freeze in my 2.5 distribution. I am wondering where freeze is. Is it even installed at all in the mac distribution? ...

Transitioning from php to python/pylons/SQLAlchemy -- Are ORMs the standard now?

Should I invest a lot of time trying to figure out an ORM style implementation, or is it still common to just stick with standard SQL queries in python/pylons/sqlalchemy? ...

Can I program Nvidia's CUDA using only Python or do I have to learn C?

I guess the question speaks for itself. I'm interested in doing some serious computations but am not a programmer by trade. I can string enough python together to get done what I want. But can I write a program in python and have the GPU execute it using CUDA? Or do I have to use some mix of python and C? The examples on Klockner's ...

Python vs all the major professional languages

I've been reading up a lot lately on comparisons between Python and a bunch of the more traditional professional languages - C, C++, Java, etc, mainly trying to find out if its as good as those would be for my own purposes. I can't get this thought out of my head that it isn't good for 'real' programming tasks beyond automation and macro...

What kind of data do I pass into a Django Model.save() method?

Lets say that we are getting POSTed a form like this in Django: rate=10 items= [23,12,31,52,83,34] The items are primary keys of an Item model. I have a bunch of business logic that will run and create more items based on this data, the results of some db lookups, and some business logic. I want to put that logic into a save signal or...

python,running command line servers - they're not listening properly

hello all Im attempting to start a server app (in erlang, opens ports and listens for http requests) via the command line using pexpect (or even directly using subprocess.Popen()). the app starts fine, logs (via pexpect) to the screen fine, I can interact with it as well via command line... the issue is that the servers wont listen fo...

Python ttk.Button -command, runs without button being pressed

I'm making a small script in python with ttk and I have a problem where a function runs where it shouldn't. The button code looks as follows: btReload = ttk.Button(treeBottomUI, text="Reload", width=17, command=loadModelTree(treeModel)) btReload.pack(side="left") and the function is as this: def loadModelTree(tree): print ("Loa...

Python: How do you insert into a list by slicing?

I was instructed to prevent this from happening in a Python program but frankly I have no idea how this is even possible. Can someone give an example of how you can slice a list and insert something into it to make it bigger? Thanks ...

optparse: No option string.

Hi. I am trying to use optparse but I am having a problem. My script usage would be: script <filename> I don't intend to add any option string, such as: script -f <filename> or script --file <filename> Is there any way I can choose not to pass an argument string? Or is there any way I can allow the user to do this: script -f <filena...

Problems parsing a xml file

I am editing a xml file that is originally like that: <SequencerLoopCommand id="1073" IterationCount="2" CommandList="1241 1242" Name="Loop Stream IDU64ToIDU63"> <IterateLoadSizeCommand id="1241" LoadType="STEP" LoadUnits="KILOBITS_PER_SECOND" LoadStart="100" LoadEnd="200" Lo...

how to get selected item in pyqt Qmenu

hello is there any way to get the selected item in a qmenu ? i want to bind all items in that list to one function and get the item once user click it . i've been looking for a way to get the item's label or index for 3 days , but couldn't find it . any ideas ? thanks in advance ...

Equivalent of alarm(3600) in Python

Starting a Perl script with alarm(3600) will make the script abort if it is still running after one hour (3600 seconds). Assume I want to set an upper bound on the running time of a Python script, what is the easiest way to achieve that? ...

Why can't my function access a variable in an enclosing function?

I know about the LEGB rule. But a simple test of whether a function has read access to variables defined in an enclosing function doesn't seem to actually work. Ie: #!/usr/bin/env python2.4 '''Simple test of Python scoping rules''' def myfunction(): print 'Hope this works: '+myvariable def enclosing(): myvariable = 'ooh this w...

How do I create a Django ModelForm, so that it's fields are sometimes required, sometimes not?

Ok, here is the question. Imagine I have a ModelForm which have only two fields. like this one: class ColorForm(forms.Form): color_by_name = forms.CharField() color = forms.IntegerField(widget = forms.Select(choices=COLOR_CHOICES)) So a user can either input a color name, a choose it from a list. Color is required, but that ...

Where to store a datastore cursor, in memcache or in the datastore?

In the google documentation it shows storing cursors in memcache, however as pointed out in an answer to this question memcache retention isn't guaranteed. So I was wondering how other people store cursors and what strategies you use for handling missing cursors? ...

Django - Expression based model constraints

Is it possible to set an expression based constraint on a django model object, e.g. If I want to impose a constraint where an owner can have only one widget of a given type that is not in an expired state, but can have as many others as long as they are expired. Obviously I can do this by overriding the save method, but I am wondering if...