Re: [Tutor] executionable file
On 6/22/07, Lucio Arteaga <[EMAIL PROTECTED]> wrote: Can any body tell me how I can make an executive file from a file.py? My knowledge of binaries is minimum. So please if you are sending me some method please do not be too sophisticated. Lucio Arteaga On Windows: http://www.py2exe.org/ I don't know of a equivalent for Unix/Linux platforms, however. HTH, John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Question regarding syntax
I'm editing some code from Mailman and seeing: legend = _("%(hostname)s Mailing Lists") Can anyone tell me what the _( means in that context? Thanks, John ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question regarding syntax
On 7/11/07, Dave Kuhlman <[EMAIL PROTECTED]> wrote: On Wed, Jul 11, 2007 at 11:03:18AM -0400, John Morris wrote: > I'm editing some code from Mailman and seeing: > > legend = _("%(hostname)s Mailing Lists") > The outer parentheses are a function call. The underscore is a name that has a callable as a value, I suppose. I believe that the value of the name underscore is the last expression evaluated, but I'm not sure. Right... Thanks, I figured it was something like that but it was not something I'd encountered. so if _ = foo then bar = _("test") is equivalent to bar = foo("test") Mailman is a great product. But that bit of code is not, I think, very good code. In Python explicitness is a virtue, and the use of the underscore is implicit and is not very Pythonic. Agreed. The _ stuff is reminiscent of Perl $_, @_ and friends. I'd go miles personally to avoid that usage, personally. I have done the whole 'import this' and mightily strive to grok it all properly on a regular basis. ;-) By the way, The inner parentheses are a formatting operation. %(x)s will be replaced by the value of x in Example: vals = {'animal': 'dog'} "Rover is a big %(animal)s." % vals "%(animal)s" will be replaced by "dog". When you use this form, the value on the right of the formatting operator must be a dictionary. More from the library reference: When the right argument is a dictionary (or other mapping type), then the formats in the string must include a parenthesised mapping key into that dictionary inserted immediately after the "%" character. The mapping key selects the value to be formatted from the mapping. For example: >>> print '%(language)s has %(#)03d quote types.' % \ {'language': "Python", "#": 2} Python has 002 quote types. -- http://docs.python.org/lib/typesseq-strings.html Thanks for this too, though it's more completeness than I needed (just wondered if _( was "special" usage or what. Kudos on an excellent reply. So, any really good tutorials on FP and map, filter, zip, lambda ? I'm trying to wrap my mind around those better... Thanks much! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Question regarding syntax
On 7/11/07, Andre Roberge <[EMAIL PROTECTED]> wrote: It is a standard convention. Lots of tools are built on the assumption that translatable strings are going to be enclosed in _(...) These tools extract the strings from programs, and put them in files (.po) that are easily editable by human translators. This convention is *not* limited to Python. So, it's used as a marker to allow for easy language portability for internal text strings? I did not know that. Thanks! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] dictionaries, objects and scoping...
class Foo: '''Represents a foo''' def __init__(self, name): '''Initializes the person's data''' self.name = name print '(Initializing %s)' % self.name self.ot = Bar(self.name) print '(After Other - %s)' % self.name class Bar: def __init__(self, name): self.name = name print 'Other', self.name self.name.pop('srv') print 'Other (Changed)', self.name dict = { "srv" : "why", "goo" : "sticky" } foo = Foo(dict) print foo.name Why does the pop in the Bar class nuke the srv k & v from Foo.name as well? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries, objects and scoping...
Does it have something to do with: http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm And if so can anyone explain it a bit for me, I'm being slow tonight. I thought each class got it's own namespace and this sharing of mutable objects is confusing me. Thanks. On Jan 21, 2008 9:16 PM, John Morris <[EMAIL PROTECTED]> wrote: > class Foo: > '''Represents a foo''' > def __init__(self, name): > '''Initializes the person's data''' > self.name = name > print '(Initializing %s)' % self.name > self.ot = Bar(self.name) > print '(After Other - %s)' % self.name > > class Bar: > def __init__(self, name): > self.name = name > print 'Other', self.name > self.name.pop('srv') > print 'Other (Changed)', self.name > > dict = { "srv" : "why", "goo" : "sticky" } > foo = Foo(dict) > print foo.name > > > Why does the pop in the Bar class nuke the srv k & v from Foo.name as > well? > > -- John Morris [EMAIL PROTECTED] "Do nothing which is of no use." -- Miyamoto Musashi http://profile.mygamercard.net/nerdality";> http://card.mygamercard.net/gbar/abyss/nerdality.gif"; border=0> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries, objects and scoping...
Thanks, so I could/should do self.ot = Bar(self.name.copy()) instead On Jan 21, 2008 9:25 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > John Morris wrote: > > > Why does the pop in the Bar class nuke the srv k & v from Foo.name > > <http://Foo.name> as well? > > Because they are both names for the same dict. > > Assignment in Python does not copy values; it binds a name to a value. > Some good references: > http://effbot.org/zone/python-objects.htm > > http://groups.google.com/group/comp.lang.python/browse_thread/thread/56e7d62bf66a435c/ > > Kent > -- John Morris [EMAIL PROTECTED] "Do nothing which is of no use." -- Miyamoto Musashi http://profile.mygamercard.net/nerdality";> http://card.mygamercard.net/gbar/abyss/nerdality.gif"; border=0> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries, objects and scoping...
So this seems like it will make scope/namespaces a bit interesting... Any good references on why this is this way? I.e., why assignment passes across scopes instead of copy. Or is it just explicit versus implicit? On Jan 21, 2008 9:32 PM, John Fouhy <[EMAIL PROTECTED]> wrote: > On 22/01/2008, John Morris <[EMAIL PROTECTED]> wrote: > > I thought each class got it's own namespace and this sharing of mutable > > objects is confusing me. > > Each class gets its own namespace, but names are different from > objects. For example: > > >>> x = [1, 2, 3] > >>> y = x > >>> y.append(4) > >>> x > [1, 2, 3, 4] > > In this case, x and y are both different names for the same object. > Classes increase the name space, but they don't change the fact that > in python, assignment is just giving something a new name. > > -- > John. > -- John Morris [EMAIL PROTECTED] "Do nothing which is of no use." -- Miyamoto Musashi http://profile.mygamercard.net/nerdality";> http://card.mygamercard.net/gbar/abyss/nerdality.gif"; border=0> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries, objects and scoping...
Ahhh. so namespaces are scoped, not objects... You have to keep your objects separate (and make copies when needed), Python just keeps namespaces (names that refer to an object) scoped according to it's rules: http://docs.python.org/ref/naming.html So if you create an object way up in terms of scope (global), then all python does is handle what names are available in a given scope to refer to it. If you want a separate object you have to take care of that yourself. Efficient. Massive potential for gotchas, especially with some of python's cleverness in terms of scoping rules. Sort of. I see some light beginning to dawn ;). On Jan 21, 2008 9:16 PM, John Morris <[EMAIL PROTECTED]> wrote: > class Foo: > '''Represents a foo''' > def __init__(self, name): > '''Initializes the person's data''' > self.name = name > print '(Initializing %s)' % self.name > self.ot = Bar(self.name) > print '(After Other - %s)' % self.name > > class Bar: > def __init__(self, name): > self.name = name > print 'Other', self.name > self.name.pop('srv') > print 'Other (Changed)', self.name > > dict = { "srv" : "why", "goo" : "sticky" } > foo = Foo(dict) > print foo.name > > > Why does the pop in the Bar class nuke the srv k & v from Foo.name as > well? > > -- John Morris [EMAIL PROTECTED] "Do nothing which is of no use." -- Miyamoto Musashi http://profile.mygamercard.net/nerdality";> http://card.mygamercard.net/gbar/abyss/nerdality.gif"; border=0> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] dictionaries, objects and scoping...
Thanks. I think this is understood better now. Thanks to everyone for their help. I was running low on ways to express this for clearer understanding. Awesomeness once again from [EMAIL PROTECTED] - John On Jan 21, 2008 10:18 PM, Kent Johnson <[EMAIL PROTECTED]> wrote: > John Morris wrote: > > Ahhh. so namespaces are scoped, not objects... > > I would say names are scoped, but I guess namespaces are too. > > > You have to keep your objects separate (and make copies when needed), > > Yes > > > Python just keeps namespaces (names that refer to an object) scoped > > according to it's rules: > > http://docs.python.org/ref/naming.html > > > > So if you create an object way up in terms of scope (global), then all > > python does is handle what names are available in a given scope to refer > > to it. If you want a separate object you have to take care of that > > yourself. Efficient. > > Yes. Assignment is not copying, it is name-binding. > > > Massive potential for gotchas, especially with some > > of python's cleverness in terms of scoping rules. > > In my experience it is rare to actually need a copy of an object, and > usually pretty clear when I do. The real hurdle is getting your mental > model in sync with what Python is actually doing, rather than what you > think it should be doing. > > Kent > -- John Morris [EMAIL PROTECTED] "Do nothing which is of no use." -- Miyamoto Musashi http://profile.mygamercard.net/nerdality";> http://card.mygamercard.net/gbar/abyss/nerdality.gif"; border=0> ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor