python

How to get the owner and group of a folder with Python on a Linux machine?

Title says it all pretty much. Is there any way how I can find out about the owner and group of a folder with Python? Thank you so much, you guys are amazing! ...

Python Class Inheritance issue

I'm playing with Python Class inheritance and ran into a problem where the inherited __init__ is not being executed if called from the sub-class (code below) the result I get from Active Python is: >>> start Tom Sneed Sue Ann Traceback (most recent call last): File "C:\Python26\Lib\site-packages\pythonwin\pywin\framework\scriptutils...

Formatting the output of a key from a dictionary

I have a dictionary which store a string as the key, and an integer as the value. In my output I would like to have the key displayed as a string without parenthesis or commas. How would I do this? for f_name,f_loc in dict_func.items(): print ('Function names:\n\n\t{0} -- {1} lines of code\n'.format(f_name, f_loc)) output: En...

Tkinter: Changing a variable within a function

I know this kind of question gets asked all the time but either i've been unable to come across the answer i need, or i've been unable to understand it when i did. I want to be able to do something like: spam = StringVar() spam.set(aValue) class MyScale(Scale): def __init__(self,var,*args,**kwargs): Scale.__init__(self,*arg...

How do I access the name of the class of an Object in Python?

The title says it mostly. If I have an object in Python and want to access the name of the class it is instantiated from is there a standard way to do this? ...

Python File Read + Write

I am working on porting over a database from a custom MSSQL CMS to MYSQL - Wordpress. I am using Python to read a txt file with \t delineated columns and one row per line. I am trying to write a Python script that will read this file (fread) and [eventually] create a MYSSQL ready .sql file with insert statements. A line in the file I'm...

Looping over a Python / IronPython Object Methods

What is the proper way to loop over a Python object's methods and call them? Given the object: class SomeTest(): def something1(self): print "something 1" def something2(self): print "something 2" ...

How do I access the child classes of an object in django without knowing the name of the child class?

In Django, when you have a parent class and multiple child classes that inherit from it you would normally access a child through parentclass.childclass1_set or parentclass.childclass2_set, but what if I don't know the name of the specific child class I want? Is there a way to get the related objects in the parent->child direction witho...

Eclipse + AppEngine =? autocomplete

I was doing some beginner AppEngine dev on a Windows box and installed Eclipse for that. I liked the autocompletion I got with the objects and functions. I moved my dev environment over to my Macbook, and installed Eclipse Ganymede. I installed the AppEngine SDK and Eclipse plug in. However, when I am typing out code now, the autocom...

Convert a number range to another range, maintaining ratio

I'm trying to convert one range of numbers to another, maintaining ratio. Maths is not my strong point. I have an image file where point values may range from -16000.00 to 16000.00 though the typical range may be much less. What I want to do is compress these values into the integer range 0-100, where 0 is the value of the smallest poin...

str.startswith() not working as I intended

I can't see why this won't work. I am performing lstrip() on the string being passed to the function, and trying to see if it starts with """. For some reason, it gets caught in an infinite loop def find_comment(infile, line): line_t = line.lstrip() if not line_t.startswith('"""') and not line_t.startswith('#'): print (...

Is there a Python module/recipe (not numpy) for 2d arrays for small games

Hi, I am writing some small games in Python with Pygame & Pyglet as hobby projects. A class for 2D array would be very handy. I use py2exe to send the games to relatives/friends and numpy is just too big and most of it's features are unnecessary for my requirements. Could you suggest a Python module/recipe I could use for this. -- C...

Django ORM Query to limit for the specific key instance.

Projectfundingdetail has a foreign key to project. The following query gives me the list of all projects that have any projectfundingdetail under 1000. How do I limit it to latest projectfundingdetail only. projects_list.filter(projectfundingdetail__budget__lte=1000).distinct() I have defined the following function, def latest_fundi...

Why doesn't inspect.getsource return the whole class source?

I have this code in my forms.py: from django import forms from formfieldset.forms import FieldsetMixin class ContactForm(forms.Form, FieldsetMixin): full_name = forms.CharField(max_length=120) email = forms.EmailField() website = forms.URLField() message = forms.CharField(max_length=500, widget=forms.Textarea) send...

Why does assigning to my global variables not work in Python?

I'm having terrible trouble trying to understand python scoping rules. With the following script: a = 7 def printA(): print "Value of a is %d" % (a) def setA(value): a = value print "Inside setA, a is now %d" %(a) print "Before setA" printA() setA(42) print "After setA" printA() Gives the unexpected (to me) output of:...

Runtime directory of Python

How do I find out the current runtime directory from within a Python script? ...

Two simple questions about python

I have 2 simple questions about python: 1.How to get number of lines of a file in python? 2.How to locate the position in a file object to the last line easily? ...

Equivalent for Python's lambda functions in Java?

Hi all, Can someone please tell me if there is an equivalent for Python's lambda functions in Java? ...

Python String Cleanup + Manipulation (Accented Characters)

I have a database full of names like: John Smith Scott J. Holmes Dr. Kaplan Ray's Dog Levi's Adrian O'Brien Perry Sean Smyre Carie Burchfield-Thompson Björn Árnason There are a few foreign names with accents in them that need to be converted to strings with non-accented characters. I'd like to convert the full names (...

What is the best way to get the last element of a list in python?

I found many different ways of getting the last element from a list in python alist[-1] alist[len(alist) -1] Which is the way you would do this? ...