Re: [Tutor] GUI selection help

2011-07-14 Thread Shwinn Ricci
by the way, I'm on a MAC if that helps/hurts at all.

On Wed, Jul 13, 2011 at 10:41 AM, Shwinn Ricci  wrote:

> Hey all,
>
> I am browsing through the large list of apps for creating GUIs from python
> on http://wiki.python.org/moin/GuiProgramming but unfortunately don't know
> which one is the best for my project, which involves mapping a point on a
> 2-Dimensional surface to a 3-Dimensional structure by having users move
> their mouse over the 2-D surface to light up a respective point on the 3-D
> surface. The GUI should also allow me to implement rotated camera angles for
> the 3-D structure. Does the GUI I select matter at all? Any pointers would
> be appreciated.
>
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Get file last user

2011-07-14 Thread Susana Iraiis Delgado Rodriguez
Thank you Alan for your answer!!

Well, I'm using Windows XP to run this script!!

So I guess there's nothing I can do, about it.

Than you

2011/7/12 Alan Gauld 

> Susana Iraiis Delgado Rodriguez wrote:
>
>> Hello list!!!
>>
>> I want to get the last user who accessed to a file, ...
>>
>> Is there a way to find out who used the file for the last time?
>>
>
> You don't say wgich OS you are using, which bis alklimportant.l Heavy duty
> industrial OS like OS.390,Pick and VAX VMS do record an audit trail, if the
> admin has switched that on. But mid range OS like Windows and Unix do not,
> so far as I know, record who made a change, just when the change was made.
> But that also probably depends on the filesystem in Linux, some of the more
> exotic ones may support audit trails.
>
> If you really need to know who made changes you need to use a version
> control system like RCS, CVS, SVN, etc. Thats what they are designed to do,
> amongst other things...
>
> HTH,
>
> Alan G.
> (From my Netbook because my PC broke! Boohoo... :-(
>
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Descriptors and type declaration order

2011-07-14 Thread Steven D'Aprano

Knacktus wrote:

Hi guys,

I've got the following (not working) code:

[...]

The problem is that the descriptors are created when the module is
evaluated. But at this time the class BaseItem is not known yet. Any ideas?


Yes -- don't do that.

What are you actually trying to accomplish? Embedding an instance of the 
class in the class is a means to an end, not the end itself. What 
problem are you trying to solve? There may be a better way.


My *guess* is that you're trying to create properties that automatically 
check their type. As much as I think that's probably a bad idea, this is 
how I would solve that:



import functools

class CheckedProperty(property):
def __init__(self, type, fget=None, fset=None, fdel=None, doc=None):
if fset is not None:
fset = self.checked(type, fset)
super().__init__(fget, fset, fdel, doc)
def checked(self, type, func):
@functools.wraps(func)
def inner(self, value):
if not isinstance(value, type):
raise TypeError('invalid type')
return func(self, value)
return inner

class Test(object):
def _getx(self):
return self.__x
def _setx(self, value):
self.__x = value
x = CheckedProperty(str, _getx, _setx)



But please don't over-use isinstance checks. They're a bad idea.


--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Descriptors and type declaration order

2011-07-14 Thread Emile van Sebille

On 7/14/2011 2:44 AM Knacktus said...

Hi guys,

I've got the following (not working) code:

class Attribute(object):

 def __init__(self, attribute_name, att_type_name):
 self._attribute_name = attribute_name
 try:
 self._attribute_type = globals()[att_type_name]
 except KeyError:
 self._attribute_type = getattr(globals()["__builtins__"],
att_type_name)

 def __get__(self, obj, obj_type):
 return getattr(obj, self._attribute_name)

 def __set__(self, obj, value):
 if isinstance(value, self._attribute_type):
 setattr(obj, self._attribute_name, value)
 else:
 raise ItemTypeException(self._attribute_type, type(value))

class BaseItem(object):

 ident = Attribute("ident", "int")
 owner = Attribute("owner", "str")
 item = Attribute("item", "BaseItem")

if __name__ == "__main__":
 print "About to create an item"
 test = BaseItem()
 print "OK"

The problem is that the descriptors are created when the module is
evaluated. But at this time the class BaseItem is not known yet. Any ideas?



You want to embed an instance of a class as an attribute of the same 
class? Does this help:


class BaseItem(object):

 ident = Attribute("ident", "int")
 owner = Attribute("owner", "str")


BaseItem.item = Attribute("item", "BaseItem")


Emile


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Descriptors and type declaration order

2011-07-14 Thread Dave Angel

On 07/14/2011 05:44 AM, Knacktus wrote:

Hi guys,

I've got the following (not working) code:

class Attribute(object):

 def __init__(self, attribute_name, att_type_name):
 self._attribute_name = attribute_name
 try:
 self._attribute_type = globals()[att_type_name]
 except KeyError:
 self._attribute_type = getattr(globals()["__builtins__"],
att_type_name)

 def __get__(self, obj, obj_type):
 return getattr(obj, self._attribute_name)

 def __set__(self, obj, value):
 if isinstance(value, self._attribute_type):
 setattr(obj, self._attribute_name, value)
 else:
 raise ItemTypeException(self._attribute_type, type(value))

class BaseItem(object):

 ident = Attribute("ident", "int")
 owner = Attribute("owner", "str")
 item = Attribute("item", "BaseItem")

if __name__ == "__main__":
 print "About to create an item"
 test = BaseItem()
 print "OK"

The problem is that the descriptors are created when the module is
evaluated. But at this time the class BaseItem is not known yet. Any ideas?

Cheers,

Jan

It's customary to include a traceback when asking a question like this, 
because many people might then be able to give advice without actually 
having to create the file and try it.


So here's the error I get with 2.7.1

Traceback (most recent call last):
  File "test2.py", line 19, in 
class BaseItem(object):
  File "test2.py", line 23, in BaseItem
item = Attribute("item", "BaseItem")
  File "test2.py", line 8, in __init__
self._attribute_type = getattr(globals()["__builtins__"], 
att_type_name)

AttributeError: 'module' object has no attribute 'BaseItem'


I had expected from your question that the error would occur when trying 
to instantiate the 'test' instance of BaseItem, but it never gets that 
far. The problem is that in creating the class, you're trying to use the 
class' type.  But that's not added to the globals dictionary till the 
class definition is complete.


One workaround is to move the last line of the class definition outside, 
so you end up with the following:


class BaseItem(object):

ident = Attribute("ident", "int")
owner = Attribute("owner", "str")

BaseItem.item = Attribute("item", "BaseItem")

There may very well be a better answer, and I'd enjoy knowing what it is.
-

DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] compare and arrange file

2011-07-14 Thread Edgar Almonte
On Wed, Jul 13, 2011 at 11:02 AM, Peter Otten <__pete...@web.de> wrote:
> Edgar Almonte wrote:
>
>> fist time i saw the statement "with" , is part of the module csv ? ,
>> that make a loop through the file ? is not the sortkey function
>> waiting for a paramenter ( the row ) ? i don't see how is get pass ,
>> the "key" is a parameter of sorted function ? , reader is a function
>> of csv module ? if "with..." is a loop  that go through the file is
>> the second with inside of that loop ? ( i dont see how the write of
>> the output file catch the line readed
>
> with open(filename) as fileobj:
>   do_something_with(fileobj)
>
> is a shortcut for
>
> fileobj = open(filename)
> do_something_with(fileobj)
> fileobj.close()
>
> But it is not only shorter; it also guarantees that the file will be closed
> even if an error occurs while it is being processed.
>
> In my code the file object is wrapped into a csv.reader.
>
> for row in csv.reader(fileobj, delimiter="|"):
>    # do something with row
>
> walks through the file one row at a time where the row is a list of the
> columns. To be able to sort these rows you have to read them all into
> memory. You typically do that with
>
> rows_iter = csv.reader(fileobj, delimiter="|")
> rows = list(rows_iter)
>
> and can then sort the rows with
>
> rows.sort()
>
> Because this two-step process is so common there is a builtin sorted() that
> converts an iterable (the rows here) into a sorted list. Now consider the
> following infile:
>
> $ cat infile.txt
> a | 0.00| 1.11|
> b | 0.00| 1.11|
> X | 0.00| 88115.39|
> X | 90453.29| 0.00|
> X | 0.00| 90443.29|
> c | 1.11| 0.00|
> X | 88115.39| 0.00|
> X | 0.00| 88335.39|
> X | 90453.29| 0.00|
> X | 88335.39| 0.00|
> X | 90443.29| 0.00|
> d | 1.11| 0.00|
>
> If we read it and sort it we get the following:
>
 import csv
 with open("infile.txt") as fileobj:
> ...     rows = sorted(csv.reader(fileobj, delimiter="|"))
> ...
 from pprint import pprint
 pprint(rows)
> [['X ', ' 0.00', ' 88115.39', ''],
>  ['X ', ' 0.00', ' 88335.39', ''],
>  ['X ', ' 0.00', ' 90443.29', ''],
>  ['X ', ' 88115.39', ' 0.00', ''],
>  ['X ', ' 88335.39', ' 0.00', ''],
>  ['X ', ' 90443.29', ' 0.00', ''],
>  ['X ', ' 90453.29', ' 0.00', ''],
>  ['X ', ' 90453.29', ' 0.00', ''],
>  ['a ', ' 0.00', ' 1.11', ''],
>  ['b ', ' 0.00', ' 1.11', ''],
>  ['c ', ' 1.11', ' 0.00', ''],
>  ['d ', ' 1.11', ' 0.00', '']]
>
> Can you infer the sort order of the list of lists above? The rows are sorted
> by the first item in the list, then rows whose first item compares equal are
> sorted by the second and so on. This sort order is not something built into
> the sort() method, but rather the objects that are compared. sort() uses the
> usual operators like < and == internally. Now what would you do if you
> wanted to sort your data by the third column, say? Here the key parameter
> comes into play. You can use it to provide a function that takes an item in
> the list to be sorted and returns something that is used instead of the
> items to compare them to each other:
>
>>> def extract_third_column(row):
> ...     return row[2]
> ...
 rows.sort(key=extract_third_column)
 pprint(rows)
> [['X ', ' 88115.39', ' 0.00', ''],
>  ['X ', ' 88335.39', ' 0.00', ''],
>  ['X ', ' 90443.29', ' 0.00', ''],
>  ['X ', ' 90453.29', ' 0.00', ''],
>  ['X ', ' 90453.29', ' 0.00', ''],
>  ['c ', ' 1.11', ' 0.00', ''],
>  ['d ', ' 1.11', ' 0.00', ''],
>  ['a ', ' 0.00', ' 1.11', ''],
>  ['b ', ' 0.00', ' 1.11', ''],
>  ['X ', ' 0.00', ' 88115.39', ''],
>  ['X ', ' 0.00', ' 88335.39', ''],
>  ['X ', ' 0.00', ' 90443.29', '']]
>
> The key function you actually need is a bit more sophisticated. You want
> rows with equal nonzero values to end close together, no matter whether the
> interesting val

[Tutor] Descriptors and type declaration order

2011-07-14 Thread Knacktus
Hi guys,

I've got the following (not working) code:

class Attribute(object):

def __init__(self, attribute_name, att_type_name):
self._attribute_name = attribute_name
try:
self._attribute_type = globals()[att_type_name]
except KeyError:
self._attribute_type = getattr(globals()["__builtins__"],
att_type_name)

def __get__(self, obj, obj_type):
return getattr(obj, self._attribute_name)

def __set__(self, obj, value):
if isinstance(value, self._attribute_type):
setattr(obj, self._attribute_name, value)
else:
raise ItemTypeException(self._attribute_type, type(value))

class BaseItem(object):

ident = Attribute("ident", "int")
owner = Attribute("owner", "str")
item = Attribute("item", "BaseItem")

if __name__ == "__main__":
print "About to create an item"
test = BaseItem()
print "OK"

The problem is that the descriptors are created when the module is
evaluated. But at this time the class BaseItem is not known yet. Any ideas?

Cheers,

Jan
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor