Ubuntu

Ubuntuのバージョン確認

Ubuntuのバージョン情報は“/etc/os-release”にある。

$ cat /etc/os-release

NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

R

Rでvisioのファイルを読み込む。


unzipVisio <- function(x.dir = ".", exdir = "tmp"){
  # ---------------------------------------------------------------------------
  # 指定したフォルダにあるvsdx形式のvisioファイルを
  # 指定したフォルダへ展開する。
  # 
  # Args:
  #   x.dir: vsdx file source path(class is character)
  #   exdir: dst unzip path(class is character)
  #
  # Returns:
  #   nothing
  # ---------------------------------------------------------------------------
  
  x <- dir(x.dir, pattern = ".vsdx")
  
  if (file.exists(exdir)){
    dir.create(exdir)  
  }
  
  lapply(x, unzip, exdir = unzip.path)
  
}

extractVisioFile <- function(fname, exdir){
  # ---------------------------------------------------------------------------
  # visio fileを展開する。
  # 
  # Args:
  #   x: visio filename(class is character)
  #   exdir: extract path (class is character)
  #
  # Returns:
  #   extract path after extract.(class is character)
  #
  #
  # ---------------------------------------------------------------------------
  
  tryCatch(
    (rtn <- unzip(fname, exdir = exdir )),
    error = function(e) print(e)
  )
  
  z <- grep(".xml.rels", rtn)
  grep("pages", rtn[-z], value = TRUE)
}

getXML.documentType <- function(x){
  # ---------------------------------------------------------------------------
  # visio xml データのattributes(xml tab)情報をdoc typeとして返す。
  # 
  # Args:
  #   x: visio data(class is character)
  #
  # Returns:
  #   visio doc type(class is character)
  #
  # todo: 
  # そもそも、atributes情報をそのまま利用すれば、この関数は不要なので
  # この関数を利用しない処理を検討すべき。
  #
  # ---------------------------------------------------------------------------
  
  rtn <- c()
  x <- attributes(x)
  if(any(x$names == "Page")){
    rtn <- c(rtn, "info.pages")
  }
  
  if(any(x$names == "Connects")){
    rtn <- c(rtn, "info.Connects")
  }
  
  if(any(x$names == "Shapes")){
    rtn <- c(rtn, "info.Shapes")
  }
  if(any(x$names == "Shape")){
    rtn <- c(rtn, "info.Shape")
  }
  if(any(x$names == "Text")){
    rtn <- c(rtn, "info.Text")
  }
  if(any(x$names == "Cell")){
    rtn <- c(rtn, "info.Cell")
  }
  if(any(x$names == ".attrs")){
    rtn <- c(rtn, "info.Attrs")
  }
  if(is.null(rtn)){
    print("not found document type")
    print(x$names)
  }
  rtn
}

parseInfoPagesXML <- function(x){
  # ---------------------------------------------------------------------------
  # visio xml データのattributesからdoc typeを返す
  # 
  # Args:
  #   x: visio data
  #
  # Returns:
  #   visio doc type(character)
  #
  # todo: 
  # そもそも、atributes情報をそのまま利用すれば、この関数は不要なので
  # この関数を利用しない処理を検討すべき。
  #
  # ---------------------------------------------------------------------------
  
  z <- which(names(x) != ".attrs")
  n <- length(z)
  if(n == 0){
    print("parse error")
    return(NA)
  }
  # debug ----------------
  if(all(is.null(x[z]))){
    browser()
    print(paste(names(z), "data is NULL.", sep = " "))
    return(NA)
  }
  # ----------------------
  
  rtn <- lapply(x[z], listToDf, ".attrs")
  rtn <- bind.data.frame(rtn)
  rtn
}

parseInfoConnectsXML <- function(x){
  # ---------------------------------------------------------------------------
  # visio xml からConnects tagに含まれる情報を返す。
  # 
  # Args:
  #   x: visio data(class is list)
  #
  # Returns:
  #   visio connects data (class is list)
  #
  # ---------------------------------------------------------------------------
  
  z <- which(names(x) == "Connects")
  n <- length(z)
  if(n == 0){
    print("parse error")
    return(NA)
  }
  rtn <- lapply(x[[z]], t)
  rtn <- lapply(rtn, as.data.frame, stringsAsFactors = FALSE)
  #browser()
  rtn <- bind.data.frame(rtn)
  rtn <- getConnect(rtn)
  rtn <- bind.data.frame(rtn)
  rtn
}

parseInfoShapesXML <- function(x){
  # ---------------------------------------------------------------------------
  # visio xml かShapes tagに含まれる情報を返す。
  # 
  # Args:
  #   x: visio data(class is list)
  #
  # Returns:
  #   visio shapes data (class is data.frame)
  #
  # ---------------------------------------------------------------------------
  
  z <- which(names(x) == "Shapes")
  n <- length(z)
  if(n == 0){
    print("parse error")
    return(NA)
  }
  
  #docType <- getXML.documentType(x[[z]])
  
  rtn <- lapply(x[[z]], parseVisioDocAll)
  #rtn <- list(Shapes = rtn) 
  rtn <- lapply(rtn, listToDf.byCol, stringsAsFactors = FALSE)
  rtn <- bind.data.frame(rtn)
  
  if (any(names(rtn) == "Name")){
    rtn[["Name"]] <- iconv(rtn[["Name"]], "UTF-8", "cp932")
  }
  
  rtn
}

parseInfoShapeXML <- function(x, rtnAsDF = TRUE){
  # ---------------------------------------------------------------------------
  # visio xml から Shape tagに含まれる情報を返す。
  # 
  # Args:
  #   x: visio data(class is list)
  #   rtnAsDF: as data.frame Flag(class is logical)
  #           TRUE: return data is data.frame
  #           FALSE: return data is list
  #
  # Returns:
  #   visio shape data (class is data.frame or list.)
  #
  # ---------------------------------------------------------------------------
  
  docType <- getXML.documentType(x)
  
  rtn <- lapply(docType, parseVisioDoc, x)
  names(rtn) <- docType
  if(rtnAsDF){
    rtn <- listToDf.byCol(rtn, addName = TRUE, stringsAsFactors = FALSE)
    
  }
  
  rtn
}

parseInfoShapeAttrsXML <- function(x){
  # ---------------------------------------------------------------------------
  # Shape tagに含まれる.attrs情報を返す。
  # 
  # Args:
  #   x: visio data(class is list)
  #
  # Returns:
  #   visio .attris data of shape.(class is list.)
  #
  # ---------------------------------------------------------------------------
  z <- which(names(x) == ".attrs")
  n <- length(z)
  if(n == 0){
    print("parse error")
    return(NA)
  }
  
  # debug ----------------
  if(all(is.null(x[[z]]))){
    #browser()
    print(".attrs data is NULL.")
    return(NA)
  }
  # ----------------------
  
  rtn <- lapply(x[z], listToDf)
  rtn <- bind.data.frame(rtn)
  rtn
}

parseInfoShapeTextXML <- function(x){
  # ---------------------------------------------------------------------------
  # Shape tagに含まれるText情報を返す。
  # 
  # Args:
  #   x: visio data(class is list)
  #
  # Returns:
  #   visio text data of shape.(class is list.)
  #
  # ---------------------------------------------------------------------------
  
  #browser()
  z <- which(names(x) == "Text")
  n <- length(z)
  if(n == 0){
    print("parse error")
    return(NA)
  }
  
  if(all(is.null(x[[z]]))){
    #browser()
    print("Text data is NULL")
    return(NA)
    
  }
  
  rtn <- x[[z]]
  rtn.names <- names(rtn)
  if (is.list(rtn)){
    rtn <- lapply(rtn, listToDf)
  }
  
  rtn <- bind.data.frame(rtn)
  
  if (is.null(rtn.names)){
    rtn.names <- "text"
  }
  names(rtn) <- rtn.names
  # debug -----------------------------------------
  if(any(unlist(lapply(rtn, class)) == "factor")){
    browser()
  }
  # -----------------------------------------------
  
  rtn
}

parseCellXML <- function(x){
  # ---------------------------------------------------------------------------
  # Shape tagに含まれるCell情報を返す。
  # 
  # Args:
  #   x: visio data(class is list)
  #
  # Returns:
  #   visio cell data of shape.(class is list.)
  #
  # ---------------------------------------------------------------------------
  
  x.name <- "unkown"
  z <- (names(x) == "N")
  n <- length(z)
  if(any(z)){
    x.name <- x[z]
  }
  
  rtn <- x[!z]
  names(rtn) <- paste(x.name, names(x[!z]), sep = ".")
  rtn <- as.data.frame(t(rtn), stringsAsFactors = FALSE)
  rtn
}

parseInfoCellXML <- function(x){
  z <- which(attributes(x)$names == "Cell")
  n <- length(z)
  if (n == 0){
    print("parse error")
    return(NA)
  }
  rtn <- lapply(x[z], parseCellXML)
  rtn <- listToDf.byCol(rtn, stringsAsFactors = FALSE)
  rtn
  
} 

listToDf <- function(x, x.label = NULL){
  # ---------------------------------------------------------------------------
  # trance forme list to data.frame。
  # 
  # Args:
  #   x: list data(class is list)
  #   x.label: names character(class is character)
  #
  #
  # Returns:
  #   visio text data of shape.(class is list.)
  #
  # ---------------------------------------------------------------------------
  rtn <- NA
  if(is.null(x)){
    
    browser()
    return(rtn)
  }
  rtn <- as.data.frame(t(x), stringsAsFactors = FALSE)
  
  if(!is.null(x.label)){
    z <- (names(x) == x.label)
    if(any(z)){
      if(is.null(x[[x.label]])){
        browser()
      }
      rtn <- as.data.frame(t(x[[x.label]]), stringsAsFactors = FALSE)
    }
  }
  # debug -----------------------------------------
  if(any(unlist(lapply(rtn, class)) == "factor")){
    browser()
  }
  # -----------------------------------------------
  rtn
}

bind.data.frame <- function(x){
  # ---------------------------------------------------------------------------
  # bind the data.frame in the list and return it the data.frame.
  # 
  # Args:
  #   x: list data(class is list)
  #
  # Returns:
  #   data.frame (class is data.frame.)
  #
  # ---------------------------------------------------------------------------
  rtn <- data.frame()
  for (i in x){
    n.rtn <- length(rtn)
    n.i  0), (n.rtn != n.i))){
      rtn <- merge(rtn, i, all = TRUE)
      next
    }
    if(any(names(rtn) != names(i))){
      rtn <- merge(rtn, i, all = TRUE)
      next
    }
    rtn <- rbind(rtn, i, stringsAsFactors = FALSE)
  }
  
  rtn
}

listToDf.byCol <- function(x, addName = FALSE, ...){
  # ---------------------------------------------------------------------------
  # Transform the list to a data.frame by column.
  # 
  # Args:
  #   x: list data(class is list)
  #   addName: 
  #     TRUE: add data.frame names
  #
  # Returns:
  #   data.frame (class is data.frame.)
  #
  # ---------------------------------------------------------------------------
  
  #x <- lapply(x, t)
  rtn <- data.frame()
  rtn.names <- c()
  
  # for (i in x){
  #   if(length(rtn) <= 0){
  #     rtn <- data.frame(i, ...)
  #     next
  #   }
  #   rtn <- data.frame(rtn, i, ...)
  # }
  
  # for (i in names(x)){
  #   if (length(rtn) <= 0){
  #     rtn <- data.frame(x[[i]], ...)
  #     rtn.names <- paste(i, names(x[[i]]), sep = ".")
  #     next
  #   }
  #   rtn <- data.frame(rtn, x[[i]], ...)
  #   rtn.names <- c(rtn.names, paste(i, names(x[[i]]), sep = "."))
  # }
  n <- length(x)
  for (i in 1:n){
    if (length(rtn) <= 0){
      rtn <- data.frame(x[[i]], ...)
      rtn.names <- paste(names(x)[i], names(x[[i]]), sep = ".")
      next
    }
    rtn <- data.frame(rtn, x[[i]], ...)
    rtn.names <- c(rtn.names, paste(names(x)[i], names(x[[i]]), sep = "."))
  }
  
  if(addName){
    names(rtn) <- rtn.names
  }
  # debug -----------------------------------------
  if(any(unlist(lapply(rtn, class)) == "factor")){
    browser()
  }
  # -----------------------------------------------
  
  rtn
}

getParseXML.function <- function(x){
  # ---------------------------------------------------------------------------
  # return to the parse XML function.
  # 
  # Args:
  #   x: XML tag info type(class is character)
  #
  # Returns:
  #   parse XML function (class is function.)
  #
  # ---------------------------------------------------------------------------
  
  switch (x,
          "info.pages" = parseInfoPagesXML,
          "info.Connects" = parseInfoConnectsXML,
          "info.Shapes" = parseInfoShapesXML,
          "info.Shape" = parseInfoShapeXML,
          "info.Cell" = parseInfoCellXML,
          "info.Text" = parseInfoShapeTextXML,
          "info.Attrs" = parseInfoShapeAttrsXML,
          print(pasete("not found", x, sep = " : "))
  )
}

getConnect <- function(x.df){
  # ---------------------------------------------------------------------------
  # get Connect infomation.
  # 
  # Args:
  #   x.df: connect infomation XML tag(class is list)
  #
  # Returns:
  #   connect infomation data. (class is data.frame)
  #
  # ---------------------------------------------------------------------------
  
  f.0 <- function(x, x.df){
    x.df.names <- c("FromPart", "ToSheet", "ToCell", "ToPart")
    z <- (x.df$FromSheet == x)
    #z.Begin <- z & (x.df$FromCell == "BeginX")
    #z.End <- z & (x.df$FromCell == "EndX")
    
    rtn <- data.frame(FromSheet = x.df[z,]$FromSheet[1],
                      f.1("BeginX", x.df[z,]),
                      f.1("EndX", x.df[z,]),
                      stringsAsFactors = FALSE)
    rtn
  }
  
  f.1 <- function(x, x.df){
    x.df.names <- c("FromPart", "ToSheet", "ToCell", "ToPart")
    z <- (x.df$FromCell == x)
    #z.Begin <- z & (x.df$FromCell == "BeginX")
    #z.End <- z & (x.df$FromCell == "EndX")
    rtn <- lapply(rep(NA,4), data.frame)
    names(rtn) <- x.df.names
    rtn <- data.frame(rtn)
    if (any(z)){
      rtn <- x.df[z, x.df.names]
    }
    names(rtn) <- paste(x, x.df.names, sep = ".")
    rtn
  }
  
  from.sheets <- names(table(x.df$FromSheet))
  lapply(from.sheets, f.0, x.df)
}

parseVisioDoc <- function(doc.type, x){
  # ---------------------------------------------------------------------------
  # parse Visio document.
  # 
  # Args:
  #   x: XML data(class is list)
  #
  # Returns:
  #   visio document contents.(class is list.)
  #
  # ---------------------------------------------------------------------------
  
  f <- getParseXML.function(doc.type)
  rtn <- f(x)
  rtn
}

parseVisioDocAll <- function(x){
  # ---------------------------------------------------------------------------
  # visio xml データからxml contents dataを返すparseVisioDoc()のラッパー関数
  # 
  # Args:
  #   x: visio data(class is list)
  #
  # Returns:
  #   visio xml contents data(class is list)
  #
  # ---------------------------------------------------------------------------
  
  docType <- getXML.documentType(x)
  
  rtn <- lapply(docType, parseVisioDoc, x)
  names(rtn) <- docType
  
  rtn
}

parseVisio <- function(src.xml.path){
  # ---------------------------------------------------------------------------
  # visio xml データからxml contents dataを返す.
  # 
  # Args:
  #   src.xml.path: visio data(class is list)
  #
  # Returns:
  #   visio xml contents data(class is list)
  #
  # ---------------------------------------------------------------------------
  
  x <- xmlToList(xmlRoot(xmlParse(src.xml.path)))
  rtn <- parseVisioDocAll(x)
  rtn$file.path <- src.xml.path
  rtn$content.type <- "page"
    
  if (any(attributes(rtn)$names == "info.pages")){
    rtn$content.type <- "info.pages"
  }
  
  rtn
}

old.wd <- getwd()
my.wd <- "%mypath%/parseVisio"
setwd(my.wd)

#vsdx の展開

install.packages("XML")
install.packages("xml2")

library(XML)
library(xml2)

source("parseVisioFunction.R")

src.xml.path <- extractVisioFile("testFlow.vsdx", exdir = "tmp")
x <- lapply(src.xml.path, parseVisio)

Ubuntu

Ubuntu 18.04 Serverへ開発環境をセットアップ

Ubuntu18.04でgccやmakeが利用できるように開発環境のセットアップ手順のメモです。

ビルドツールのインストール

$ sudo apt-get install build-essential


gcc
makeのバージョン確認


$ gcc --version
gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Ubuntu

Ubuntu Server18.04へアップデートした際に発生した nginxのエラー対処

nginxを導入しているUbuntu Server 16.04から18.04へアップグレードした際に次のようなエラーが発生。


その時の対処方法について、メモを記録として残す。

Error 内容を logから確認する。

$ cat /var/log/nginx/error.log
2018/09/23 11:11:44 [crit] 2871#2871: *1 connect() to unix:run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, 

どうもUpgreadeした際にphpupdateされてphp7.0が使えなくなった模様。

どのバージョンのphpに更新されたか確認すると。

php7.2に更新されているみたい。

$ dpkg -l | grep php
rc  libapache2-mod-php7.0                 7.0.32-0ubuntu0.16.04.1            amd64        server-side, HTML-embedded scripting language (Apache 2 module)
rc  libapache2-mod-php7.2                 7.2.10-0ubuntu0.18.04.1            amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php-common                            1:60ubuntu1                        all          Common files for PHP packages
ii  php-mysql                             1:7.2+60ubuntu1                    all          MySQL module for PHP [default]
ii  php-pear                              1:1.10.5+submodules+notgz-1ubuntu1 all          PEAR Base System
rc  php7.0-cgi                            7.0.32-0ubuntu0.16.04.1            amd64        server-side, HTML-embedded scripting language (CGI binary)
rc  php7.0-cli                            7.0.32-0ubuntu0.16.04.1            amd64        command-line interpreter for the PHP scripting language
ii  php7.0-common                         7.0.32-0ubuntu0.16.04.1            amd64        documentation, examples and common module for PHP
rc  php7.0-fpm                            7.0.32-0ubuntu0.16.04.1            amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
rc  php7.0-json                           7.0.32-0ubuntu0.16.04.1            amd64        JSON module for PHP
rc  php7.0-mbstring                       7.0.32-0ubuntu0.16.04.1            amd64        MBSTRING module for PHP
rc  php7.0-mysql                          7.0.32-0ubuntu0.16.04.1            amd64        MySQL module for PHP
rc  php7.0-opcache                        7.0.32-0ubuntu0.16.04.1            amd64        Zend OpCache module for PHP
rc  php7.0-readline                       7.0.32-0ubuntu0.16.04.1            amd64        readline module for PHP
ii  php7.0-xml                            7.0.32-0ubuntu0.16.04.1            amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.2-cli                            7.2.10-0ubuntu0.18.04.1            amd64        command-line interpreter for the PHP scripting language
ii  php7.2-common                         7.2.10-0ubuntu0.18.04.1            amd64        documentation, examples and common module for PHP
ii  php7.2-fpm                            7.2.10-0ubuntu0.18.04.1            amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.2-json                           7.2.10-0ubuntu0.18.04.1            amd64        JSON module for PHP
ii  php7.2-mbstring                       7.2.10-0ubuntu0.18.04.1            amd64        MBSTRING module for PHP
ii  php7.2-mysql                          7.2.10-0ubuntu0.18.04.1            amd64        MySQL module for PHP
ii  php7.2-opcache                        7.2.10-0ubuntu0.18.04.1            amd64        Zend OpCache module for PHP
ii  php7.2-readline                       7.2.10-0ubuntu0.18.04.1            amd64        readline module for PHP
ii  php7.2-xml                            7.2.10-0ubuntu0.18.04.1            amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP

nginx default.confを修正してServiceを再起動する。

古い情報をコメントアウトして、新たにphp7.2-fpm.sockを追加する。

#fastcgi_pass unix:run/php/php7.0-fpm.sock;

fastcgi_pass unix:run/php/php7.2-fpm.sock;

$ sudo vi /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        #root   /usr/share/nginx/html;
        root   /var/www/html;
        #index  index.html index.htm;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    #    root           html;
        root /var/www/html;
    #    fastcgi_pass   127.0.0.1:9000;
        #fastcgi_pass unix:run/php/php7.0-fpm.sock;
        fastcgi_pass unix:run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

nginx serviceを再起動する。

$ sudo service nginx restart

まとめ

 これでnginxも問題なく利用できるようになりました。

R

R Studioの環境設定


R Studioの設定をカスタマイズして使いやすくする


 R StudioR標準のIDEに比べ、“IntelliSense”“Debug”など使いやすいですよね。

ここではR Studioを更に使いやすくする為に設定をカスタマイズします。

カスタマイズする設定は次の項目。

  • Code(エディタ設定)

・タブをスペースに置き換える。

・インデント量:2 (space-key x 2)

・改行文字数:80

  • Appearance(表示設定)

R Studio theme“modern”

Editor font“Lucida console”

Editor font size 12

Editor theme “Chaos”

R Studioの設定はGlobal Optionsから


Global Options を開く

[Tools] – [Global Options…]


Code – Editing (エディタ設定)

[Code] – [Editing]tab

・タブをスペースに置き換える。 Insert spaces for tab

・インデント量:2 (space-key x 2)  Tab width


Code – Display (改行文字数)

[Code] – [Display]tab

・改行文字数:80 Show margin


表示設定

[Appearance]

R Studio theme“modern”

Editor font“Lucida console”

Editor font size 12

Editor theme “Chaos”



まとめ


 簡単ですがR Studio 設定カスタマイズ方法について紹介しました。

使いやすくなったR StudioRを楽しんでいきましょう。

Python

pythonのコンソールでソースコードを読み込んで実行する。

pythonのコンソールでソースコードを実行する方法です。

あらかじめ作成してある、汎用的な関数を対話的に利用する際に重宝します。

方法1

exec を利用する。

>>> exec(open("./sample.py").read())

windowspython3で文字エンコードエラーが発生する場合は“encoding”を追加すればよい。

>>> exec(open("./sample.py").read())

Traceback (most recent call last):

 File "", line 1, in

UnicodeDecodeError: 'cp932' codec can't decode byte 0x82 in position 1240: illegal multibyte sequence

>>> exec(open("./sample.py", encoding="utf-8").read())

 
PC

Thinkpad Spec比較

現在利用しているメインマシンのThinkpad X240を性能に不満を感じつつもだましだまし使い約3年。

そろそろ新しマシンを手に入れたいと思いつつSPECを比べてみる。

そもそもX240の不満点はこんな感じ。

・RAM Sizeが8GBしかない事 → 64bit Win10だと余裕が無い。VMで利用する場合に足りなくなる事が多々ある。

・FHDサイズ(1920×1080) → 高さが1080しかないのは使い憎い。 最低1280以上はあった方が使いやすい!

画面画素数を考えるとX240後継のX260,X270は候補から外れるのでTシリーズが有力

TシリーズでもX240と同じぐらいのモビリティがあるT460s, T470sと比較

 

X240

X260

T460s

X270

T470s

発売日

2013/10/16

2016/1/16

2016/1/16

2017/2/8

2017/2/8

開発コード

Haswell

Skylake

Skylake

Kaby Lake

Kaby Lake

Chipset

Intel 8Series Chipset QM87 ※1

Intel 100Series Chipset QM170 ※1

Intel 100Series Chipset QM170 ※1

Intel 200Series Chipset QM175 ※1

Intel 200Series Chipset QM175 ※1

CPU

Core i7-4600U

Core i7-6600U

Core i7-6600U

Core i7-7600U

Core i7-7600U

Clock

2.1GHz

2.6GHz

2.6GHz

2.8GHz

2.8GHz

Core

2Core

2Core

2Core

2Core

2Core

Thread

4

4

4

4

4

Memory

DDR3L-1600/1333

DDR4-2133

DDR4-2133

DDR4-2133

DDR4-2133

容量

8GB

16GB

24GB

16GB

24GB

1st Bank

8GB DDR3L-1600

16GB DDR4-2133

8GB soldered

16GB DDR4-2133

8GB soldered

2nd Bank

16GB DDR4-2133

16GB DDR4-2133

iGPU

Intel HD Graphics 5000/4600/4400

Intel HD Graphics 520

Intel HD Graphics 520

Intel HD Graphics 620

Intel HD Graphics 620

iGPU VRAM

2160MB

2160MB

2160MB

2160MB

2160MB

dGPU

NVIDIA GeForce 930M

dGPU VRAM

2048MB

LCD Size

12.5Inch

12.5Inch

14 Inch

12.5Inch

14 Inch

Display

1920 x 1080

1920 x 1080

2560 × 1440

1920 x 1080

2560×1440

※1 機器の構成から予測した情報(仕様としては明記されてない為、不正確)

参考情報元:
http://psref.lenovo.com/

こうやってまとめてみると発売されたばかりのT470sは魅力的。

現実問題として価格の面で並売のT460sかな~

あとT460sはdGPUも選択可能な事もポイント高いかも。