Mercurial > vim
comparison runtime/doc/if_pyth.txt @ 4639:52a4f66ae1f5 v7.3.1067
updated for version 7.3.1067
Problem: Python: documentation lags behind.
Solution: Python patch 26. (ZyX)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Thu, 30 May 2013 13:32:30 +0200 |
parents | 18ba89e06fab |
children | 2eb30f341e8d |
comparison
equal
deleted
inserted
replaced
4638:fe00ea72e9af | 4639:52a4f66ae1f5 |
---|---|
478 Value Description ~ | 478 Value Description ~ |
479 zero Dictionary is not a scope one | 479 zero Dictionary is not a scope one |
480 vim.VAR_DEF_SCOPE |g:| or |l:| dictionary | 480 vim.VAR_DEF_SCOPE |g:| or |l:| dictionary |
481 vim.VAR_SCOPE Other scope dictionary, | 481 vim.VAR_SCOPE Other scope dictionary, |
482 see |internal-variables| | 482 see |internal-variables| |
483 Methods: | 483 Methods (note: methods do not support keyword arguments): |
484 Method Description ~ | 484 Method Description ~ |
485 keys() Returns a list with dictionary keys. | 485 keys() Returns a list with dictionary keys. |
486 values() Returns a list with dictionary values. | 486 values() Returns a list with dictionary values. |
487 items() Returns a list of 2-tuples with dictionary contents. | 487 items() Returns a list of 2-tuples with dictionary contents. |
488 update(iterable) | 488 update(iterable), update(dictionary), update(**kwargs) |
489 update(dictionary) | |
490 update(**kwargs) | |
491 Adds keys to dictionary. | 489 Adds keys to dictionary. |
490 get(key[, default=None]) | |
491 Obtain key from dictionary, returning the default if it is | |
492 not present. | |
493 pop(key[, default]) | |
494 Remove specified key from dictionary and return | |
495 corresponding value. If key is not found and default is | |
496 given returns the default, otherwise raises KeyError. | |
497 popitem(key) | |
498 Remove specified key from dictionary and return a pair | |
499 with it and the corresponding value. Returned key is a new | |
500 object. | |
501 has_key(key) | |
502 Check whether dictionary contains specified key, similar | |
503 to `key in dict`. | |
504 | |
505 __new__(), __new__(iterable), __new__(dictionary), __new__(update) | |
506 You can use `vim.Dictionary()` to create new vim | |
507 dictionaries. `d=vim.Dictionary(arg)` is the same as | |
508 `d=vim.bindeval('{}');d.update(arg)`. Without arguments | |
509 constructs empty dictionary. | |
510 | |
492 Examples: > | 511 Examples: > |
493 py d = vim.bindeval('{}') | 512 d = vim.Dictionary(food="bar") # Constructor |
494 d['a'] = 'b' # Item assignment | 513 d['a'] = 'b' # Item assignment |
495 print d['a'] # getting item | 514 print d['a'] # getting item |
496 d.update({'c': 'd'}) # .update(dictionary) | 515 d.update({'c': 'd'}) # .update(dictionary) |
497 d.update(e='f') # .update(**kwargs) | 516 d.update(e='f') # .update(**kwargs) |
498 d.update((('g', 'h'), ('i', 'j'))) # .update(iterable) | 517 d.update((('g', 'h'), ('i', 'j'))) # .update(iterable) |
499 for key in d.keys(): # .keys() | 518 for key in d.keys(): # .keys() |
500 for val in d.values(): # .values() | 519 for val in d.values(): # .values() |
501 for key, val in d.items(): # .items() | 520 for key, val in d.items(): # .items() |
502 print isinstance(d, vim.Dictionary) # True | 521 print isinstance(d, vim.Dictionary) # True |
503 for key in d: # Iteration over keys | 522 for key in d: # Iteration over keys |
523 class Dict(vim.Dictionary): # Subclassing | |
504 < | 524 < |
505 Note: when iterating over keys you should not modify dictionary. | 525 Note: when iterating over keys you should not modify dictionary. |
506 | 526 |
507 vim.List object *python-List* | 527 vim.List object *python-List* |
508 Sequence-like object providing access to vim |List| type. | 528 Sequence-like object providing access to vim |List| type. |
509 Supports `.locked` attribute, see |python-.locked|. Also supports the | 529 Supports `.locked` attribute, see |python-.locked|. Also supports the |
510 following methods: | 530 following methods: |
511 Method Description ~ | 531 Method Description ~ |
512 extend(item) Add items to the list. | 532 extend(item) Add items to the list. |
533 | |
534 __new__(), __new__(iterable) | |
535 You can use `vim.List()` to create new vim lists. | |
536 `l=vim.List(iterable)` is the same as | |
537 `l=vim.bindeval('[]');l.extend(iterable)`. Without | |
538 arguments constructs empty list. | |
513 Examples: > | 539 Examples: > |
514 l = vim.bindeval('[]') | 540 l = vim.List("abc") # Constructor, result: ['a', 'b', 'c'] |
515 l.extend(['abc', 'def']) # .extend() method | 541 l.extend(['abc', 'def']) # .extend() method |
516 print l[1:] # slicing | 542 print l[1:] # slicing |
517 l[:0] = ['ghi', 'jkl'] # slice assignment | 543 l[:0] = ['ghi', 'jkl'] # slice assignment |
518 print l[0] # getting item | 544 print l[0] # getting item |
519 l[0] = 'mno' # assignment | 545 l[0] = 'mno' # assignment |
520 for i in l: # iteration | 546 for i in l: # iteration |
521 print isinstance(l, vim.List) # True | 547 print isinstance(l, vim.List) # True |
548 class List(vim.List): # Subclassing | |
522 | 549 |
523 vim.Function object *python-Function* | 550 vim.Function object *python-Function* |
524 Function-like object, acting like vim |Funcref| object. Supports `.name` | 551 Function-like object, acting like vim |Funcref| object. Supports `.name` |
525 attribute and is callable. Accepts special keyword argument `self`, see | 552 attribute and is callable. Accepts special keyword argument `self`, see |
526 |Dictionary-function|. | 553 |Dictionary-function|. You can also use `vim.Function(name)` constructor, |
554 it is the same as `vim.bindeval('function(%s)'%json.dumps(name))`. | |
555 | |
527 Examples: > | 556 Examples: > |
528 f = vim.bindeval('function("tr")') | 557 f = vim.Function('tr') # Constructor |
529 print f('abc', 'a', 'b') # Calls tr('abc', 'a', 'b') | 558 print f('abc', 'a', 'b') # Calls tr('abc', 'a', 'b') |
530 vim.command(''' | 559 vim.command(''' |
531 function DictFun() dict | 560 function DictFun() dict |
532 return self | 561 return self |
533 endfunction | 562 endfunction |