Re: What does mean @ sign in first of statement
On Sun, Sep 1, 2013 at 8:53 PM, Mohsen Pahlevanzadeh moh...@pahlevanzadeh.org wrote: Dear all, What does mean @ sign in first of statement such as: // @hybrid_property def fullname(self): return self.firstname + + self.lastname /// Sorry for cheap question. Yours, Mohsen -- http://mail.python.org/mailman/listinfo/python-list @hybrid_property is a decorator. Great resource: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ -- Chris “Kwpolska” Warrick http://kwpolska.tk PGP: 5EAAEA16 stop html mail | always bottom-post | only UTF-8 makes sense -- http://mail.python.org/mailman/listinfo/python-list
Re: What does % mean/does in this context?
At first glance it looks like a replace for _button_cart with the dictionary items listed in the curly braces and stuffing them into a list item (cartitems) On Feb 2, 8:47 am, Tim Chase [EMAIL PROTECTED] wrote: for item in cart.values(): v = _button_cart % {idx: idx, itemname: item.name, amount: item.cost, quantity: item.quantity,} cartitems.append(v) What does the % operator is doing there? Unless _button_cart is some funky object with its modulo-operator overloaded, _button_cart is likely a string. For strings, the % does string formatting. If the RHS is a dict (in this case), it's flexible and allows for named lookups Thus, _button_cart likely contains something like _button_cart = %(idx)s The user bought %(quantity)s %(itemname)s. They cost $%(amount)0.02f You're likely already familiar with the case when the RHS is a tuple/list instead of a dict: s = I have %i tests to take on %s % ( test_count, day_of_week) You can read the nitty-gritty details at http://docs.python.org/lib/typesseq-strings.html -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: What does % mean/does in this context?
for item in cart.values(): v = _button_cart % {idx: idx, itemname: item.name, amount: item.cost, quantity: item.quantity,} cartitems.append(v) What does the % operator is doing there? Unless _button_cart is some funky object with its modulo-operator overloaded, _button_cart is likely a string. For strings, the % does string formatting. If the RHS is a dict (in this case), it's flexible and allows for named lookups Thus, _button_cart likely contains something like _button_cart = %(idx)s The user bought %(quantity)s %(itemname)s. They cost $%(amount)0.02f You're likely already familiar with the case when the RHS is a tuple/list instead of a dict: s = I have %i tests to take on %s % ( test_count, day_of_week) You can read the nitty-gritty details at http://docs.python.org/lib/typesseq-strings.html -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
I'm very new to Python, but I think it's really ':' and ':' side-by-side with no values, not a single ::. In V2.3 and higher, slicing supports an optional third index which works as a step, e.g., X[2:9:2] fetches every other item in indexes 2-8. The useage you cite is really defaulting the start and end indexes, and decrementing the step index. Regards, could ildg [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I know that : can do slice works. But I saw :: today and it puzzled me much, I can't find it in the python doc, so I raise this question here. The code is as below: -- Jython 2.2a1 on java1.5.0_03 (JIT: null) Type copyright, credits or license for more information. live='live';print live live live=live[::-1];print live evil [::-1] can reverse a string magicly, how did it do it? -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
Robert Kern wrote: Rob Williscroft wrote: import sys live = 'live' print live[ sys.maxint : : -1 ] print live[ len(live)-1 : : -1 ] print live[ len(live)-1 : -len(live)-1 : -1 ] print live[ len(live)-1 : -sys.maxint : -1 ] print live[ sys.maxint : -sys.maxint : -1 ] print live[ -1 : -len(live)-1 : -1 ] Of course there is only one obvious way to do it, but alas as I'm not Dutch I can't tell which it is. Well, that part's easy at least: live[::-1] :-) And so the circle is complete ... What about reversed(live)? Or if you want a list instead of an iterator, list(reversed(live))? -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
Michael Hoffman wrote: Robert Kern wrote: Well, that part's easy at least: live[::-1] :-) And so the circle is complete ... What about reversed(live)? Or if you want a list instead of an iterator, list(reversed(live))? That's fine if you want to iterate over it. Often, especially with strings, you just want an object of the same type back again. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
Robert Kern wrote: Michael Hoffman wrote: Robert Kern wrote: Well, that part's easy at least: live[::-1] :-) And so the circle is complete ... What about reversed(live)? Or if you want a list instead of an iterator, list(reversed(live))? That's fine if you want to iterate over it. Often, especially with strings, you just want an object of the same type back again. Then you could use: ''.join(reversed(live)) though, I think that live[::-1] is the most obvious way to do it. :-) Regards, Jim Sizelove -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
Hi Robert, I didn't succeed in reversing a string with the full form you proposed: live[len(live)-1:-1:-1] # where live=live The result is an empty string. To reverse live (in a full form), I have to put a char in front of the string and...: ('x'+live)[len(live)+1:0:-1] # -- evil Is it due to the Python's version (I still have 2.3.4)? Bye. -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
[EMAIL PROTECTED] wrote: Hi Robert, I didn't succeed in reversing a string with the full form you proposed: live[len(live)-1:-1:-1] # where live=live The result is an empty string. To reverse live (in a full form), I have to put a char in front of the string and...: ('x'+live)[len(live)+1:0:-1] # -- evil Is it due to the Python's version (I still have 2.3.4)? No, it's because I am stupid. There isn't a full form. live[len(live)::-1] is the closest expansion. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
Robert Kern wrote in news:mailman.1954.1121875043.10512.python- [EMAIL PROTECTED] in comp.lang.python: [EMAIL PROTECTED] wrote: Hi Robert, I didn't succeed in reversing a string with the full form you proposed: live[len(live)-1:-1:-1] # where live=live The result is an empty string. To reverse live (in a full form), I have to put a char in front of the string and...: ('x'+live)[len(live)+1:0:-1] # -- evil Is it due to the Python's version (I still have 2.3.4)? No, it's because I am stupid. There isn't a full form. live[len(live)::-1] is the closest expansion. import sys live = 'live' print live[ sys.maxint : : -1 ] print live[ len(live)-1 : : -1 ] print live[ len(live)-1 : -len(live)-1 : -1 ] print live[ len(live)-1 : -sys.maxint : -1 ] print live[ sys.maxint : -sys.maxint : -1 ] print live[ -1 : -len(live)-1 : -1 ] Of course there is only one obvious way to do it, but alas as I'm not Dutch I can't tell which it is. Rob. -- http://www.victim-prime.dsl.pipex.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
Rob Williscroft wrote: import sys live = 'live' print live[ sys.maxint : : -1 ] print live[ len(live)-1 : : -1 ] print live[ len(live)-1 : -len(live)-1 : -1 ] print live[ len(live)-1 : -sys.maxint : -1 ] print live[ sys.maxint : -sys.maxint : -1 ] print live[ -1 : -len(live)-1 : -1 ] Of course there is only one obvious way to do it, but alas as I'm not Dutch I can't tell which it is. Well, that part's easy at least: live[::-1] :-) And so the circle is complete ... -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: What does :: mean?
could ildg wrote: I know that : can do slice works. But I saw :: today and it puzzled me much, I can't find it in the python doc, so I raise this question here. The code is as below: -- Jython 2.2a1 on java1.5.0_03 (JIT: null) Type copyright, credits or license for more information. live='live';print live live live=live[::-1];print live evil [::-1] can reverse a string magicly, how did it do it? The full form would be live[len(live)-1:-1:-1] much like range(len(live)-1, -1, -1). [start:stop:step] step can be negative. -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list