15.07.2015       Выпуск 82 (13.07.2015 - 19.07.2015)       Интересные проекты, инструменты, библиотеки

pystr: библиотека для работы со строками как в R

pystr это обертка над стандартной библиотекой Python, которая предоставляет интерфейс работы со строками в режиме языка R.

Читать>>



Экспериментальная функция:

Ниже вы видите текст статьи по ссылке. По нему можно быстро понять ссылка достойна прочтения или нет

Просим обратить внимание, что текст по ссылке и здесь может не совпадать.

pystr Build Status Coverage Status downloads

String operations the Python way: a package for those of us who miss Python's string methods while we're working in R.

Install

From CRAN (Stable Release)

From GitHub (Latest Development Release)

Load the Package

String Formatting

Most importantly, pystr brings a port of Python's str.format to R with pystr_format.

Indexed Parameters

You can pass in parameters individually:

pystr_format("Hello {1}, my name is {2}.", "World", "Nicole")
## [1] "Hello World, my name is Nicole."

As a vector:

params = c("World", "Nicole")
pystr_format("Hello {1}, my name is {2}.", params)
## [1] "Hello World, my name is Nicole."

Or as a list:

params = list("World", "Nicole")
pystr_format("Hello {1}, my name is {2}.", params)
## [1] "Hello World, my name is Nicole."

Named Parameters

You can pass in named parameters individually:

pystr_format("Hello {thing}, my name is {name}.", thing="World", name="Nicole")
## [1] "Hello World, my name is Nicole."

As a named vector:

params = c(thing="World", name="Nicole")
pystr_format("Hello {thing}, my name is {name}.", params)
## [1] "Hello World, my name is Nicole."

Or as a named list:

params = list(thing="World", name="Nicole")
pystr_format("Hello {thing}, my name is {name}.", params)
## [1] "Hello World, my name is Nicole."

Repeated Parameters

Parameters can be used more than once throughout a string:

pystr_format("The name is {last}. {first} {last}.", last="Bond", first="James")
## [1] "The name is Bond. James Bond."

Replacement Types

Pass in characters and numbers:

pystr_format("Hello {name}, you have {n} new notifications!", name="Nicole", n=3)
## [1] "Hello Nicole, you have 3 new notifications!"

Other Ported Methods

pystr_capitalize

Port of str.capitalize.

## [1] "Once upon a time, "

pystr_center

Port of str.center.

## [1] "***center me***"

pystr_count

Port of str.count.

## [1] 2

pystr_endswith

Port of str.endswith.

## [1] TRUE
## [1] TRUE

pystr_find

Port of str.find.

## [1] 3

pystr_index

Port of str.index.

## [1] 3
## Error in pystr_index("12345", "xy"): ValueError

pystr_isalnum

Port of str.isalnum.

## [1] TRUE
## [1] FALSE

pystr_isalpha

Port of str.isalpha.

## [1] TRUE
## [1] FALSE

pystr_islower

Port of str.islower.

## [1] TRUE
## [1] FALSE

pystr_isnumeric

Port of str.isnumeric.

## [1] TRUE
## [1] FALSE

pystr_isspace

Port of str.isspace.

## [1] TRUE

pystr_istitle

Port of str.istitle.

## [1] TRUE
## [1] FALSE

pystr_isupper

Port of str.isupper.

## [1] TRUE

pystr_join

Port of str.join.

## [1] "ABBCCC"
## [1] "1+2+3"

pystr_ljust

Port of str.ljust.

## [1] "left      "
## [1] "left******"

pystr_lower

Port of str.lower.

## [1] "lowercase me!"

pystr_lstrip

Port of str.lstrip.

## [1] "example.com"

pystr_maketrans

Port of str.maketrans.

map = pystr_maketrans("abc", "123")
pystr_translate("a blue cat", map)
## [1] "1 2lue 31t"

pystr_partition

Port of str.partition.

## [1] "one"              "two"              "threeonetwothree"

pystr_replace

Port of str.replace.

## [1] "miXiXippi"
## [1] "miXissippi"

pystr_rfind

Port of str.rfind.

## [1] 7

pystr_rindex

Port of str.rindex.

## [1] 5
## Error in pystr_rindex("abcdab", "xy"): ValueError

pystr_rjust

Port of str.rjust.

## [1] "     right"
## [1] "*****right"

pystr_rpartition

Port of str.rpartition.

## [1] "onetwothreeone" "two"            "three"

pystr_rsplit

Port of str.rsplit.

## [1] "a--b" "c"

pystr_rstrip

Port of str.rstrip.

## [1] "mississ"

pystr_split

Port of str.split.

## [1] "1" "2" "3" "4"
## [1] "1"     "2+3+4"

pystr_splitlines

Port of str.splitlines.

## [1] "First"  "Second" "Third"

pystr_startswith

Port of str.startswith.

pystr_startswith("http://www.example.com", "http://")
## [1] TRUE
pystr_startswith("http://www.example.com", c("http://", "https://"))
## [1] TRUE

pystr_strip

Port of str.strip.

## [1] "very spacious"
## [1] "example"

pystr_swapcase

Port of str.swapcase.

## [1] "sWAP mE!"

pystr_title

Port of str.title.

## [1] "Make Me Pretty"

pystr_translate

Port of str.translate.

map = pystr_maketrans("abc", "123")
pystr_translate("a blue cat", map)
## [1] "1 2lue 31t"

pystr_upper

Port of str.upper.

## [1] "UPPERCASE ME!"

pystr_zfill

Port of str.zfill.

## [1] "00042"
## [1] "-0042"

Methods Not Ported (Yet)



Лучшая Python рассылка

Нас поддерживает


Python Software Foundation



Разместим вашу рекламу

Пиши: mail@pythondigest.ru

Нашли опечатку?

Выделите фрагмент и отправьте нажатием Ctrl+Enter.

Система Orphus