Python, memo | 01:52 | 変更不可能な組み込みオブジェクトの場合 >>> i = 'str' >>> def hoge(): ... i = 'str2' ... >>> hoge() >>> i 'str' >>> i = 'str' >>> def hoge(): ... global i ... i = 'str2' ... >>> hoge() >>> i 'str2' 変更可能な組み込みオブジェクトの場合 >>> i = dict() >>> def hoge(): ... i['foo'] = 'foo' ... >>> hoge() >>> i {'foo': 'foo'}
Python, Perl, memo | 20:02 | 次のPerlスクリプトとPythonスクリプトは同等の処理を行う。Perl #!/usr/bin/env perl use strict; use warnings; my $str = "testhoge"; if($str =~ /(hoge)/){ print $1; } Python #!/usr/bin/env python import re r = re.compile('(?Phoge)') result = r.match('hogetest') print result.group('re1') どちらも、結果として「hoge」という文字列を出力する。
JavaScript | 00:38 | レシピ1.1 部分文字列を抽出する var str = "I love Python"; document.writeln(str.slice(7,13) + " "); document.writeln(str.substr(7,13) + " "); document.writeln(str.substring(7,13) + " "); document.writeln(str.substr(0,2) + " like " + str.substr(7,13) + " "); document.writeln(str.replace("Python","JavaScript")); 結果 Python Python Python I like Python I love JavaScript
Python | 23:04 | レシピ17.6 Unixドメインソケットを使用する。TCP,UDPの場合は、ソケットにバインドするのは、IPアドレスとポートでしたが、Unixドメインの場合は、ファイルをなる。 Server #!/usr/bin/env python2.5 #-*- coding: utf-8 -*- import os import socket, traceback if os.path.exists("/tmp/mysock"): os.remove("/tmp/mysock") s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.bind("/tmp/mysock") s.listen(1) conn, addr = s.accept() while 1: try: message = conn.rec
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く