検索結果
coding
- 全てのカテゴリ
- 全ての質問
- 各種スクリプト言語の記述時の文字コードについて
掲題の通り、メジャーなLL言語についての文字コードについて質問です。 例えば PHPでコンソール用にちょっとしたものを書くとき #! /usr/local/php print("文字列"); 書いて、ターミナルで php ./sample.php などとすると問題なく「文字列」という文字が表示されます。 このとき、ファイルはUTF-8で書いたとします。 次に、別のLL言語pythonで下記の様に記述したとします。 #! /usr/local/python print ("python文字列"); 上記内容を python ./sample.py などと実行すると SyntaxError: Non-ASCII character '\xe6' in file と上記のようなエラーがでます。どうやらアスキーコードの範囲外のバイト数が含まれているようです。 これを #! /usr/local/python #coding: utf-8 print ("python文字列"); としてやると問題なく「python 文字列」と表示されると思います。 これはRubyでも同じだと思います。 また同じ様に #! /usr/bin/bash echo "文字列" とシェルスクリプトで上記の様にかいてやると・・・ 問題なく「文字列」と表記されます。 ではなぜシェルスクリプト(bash)やPHPはマジックコメントを記述しなくても 暗黙のうちにUTF-8で文字列が表記されて pythonやRubyは明示的にUTF-8とマジコメを記述しなければならないのでしょうか? ご教授ください。
- audio/3gppを変換したい
はじめまして。探しても探しても分からなかったので、質問させていただきます。 あまり知識がないので、簡単な事を聞いているかもしれませんが、ご了承ください。 私は携帯を持っていないので、自分のPC(XP)に、友達から、携帯サイトの音楽をダウンロードしてもらい、yahoo!メールに送信してもらいました。 その音楽のファイル形式は『audio/3gpp』でして、そのまま開くと『Quick Time Player』が開きます。 ですが、『Quick Time 7 Pro』を購入していないし、する気もないので、保存できません。 『iTunes』も『Area61 ビデオダウンローダー』などはあるのですが、保存から出来ないので、これらも使えません。 『http://oshiete1.goo.ne.jp/qa3412392.html』を見てみたのですが、動画ではないですし、ファイル形式が『mp4かAAC』と仰っているので、これでは出来ないのかと思いまして…。(一度挑戦しようかと思いましたが、英語が読めませんでした。これじゃあ駄目ですよね…。) ゆくゆくは、『au Music Port』に入れたいので、『m4a-AAC(Advanced Audio Coding) オーディオファイル』『wma-Windows Media オーディオファイル』『mav-Wave サウンドファイル』のファイル形式ではないと、インポートできません。 やはり、『Quick Time 7 Pro』を購入して保存するか、諦めるしか道はないのでしょうか。
- ベストアンサー
- Windows XP
- rie-kr
- 回答数1
- japan timesの英文和訳お願いします。
Does this strike a chord with any Westerners living in Japan? Or Japanese when interacting with Westerners? Certainly, I can understand it. There are many occasions when expressions and emotions may be misunderstood, and this research might provide part of an explanation as to why that happens so frequently. Jack and colleagues investigated cultural differences in the recognition of facial expressions by recording the eye movements of 13 Western Caucasian and 13 East Asian people while they observed pictures of expressive faces. They then put them into categories: happy, sad, surprised, fearful, disgusted, angry, or neutral. The faces were standardized according to something called the Facial Action Coding System (FACS). This sets each expression as displaying a specific combination of facial muscles typically associated with each feeling of emotion. The researchers then compared how accurately participants read those facial expressions using their particular eye-movement strategies. It turned out that Easterners focused much greater attention on the eyes, and made significantly more errors than Westerners did. In other words, while Westerners use the whole face to convey emotion, Easterners use the eyes more and the mouth less. And interestingly, this cultural difference extends to cyberspace. Emoticons — text marks used to convey facial expressions of the writer’s mood — are different in Japan and the West. In the West, the commonest emoticons for “happy” and “sad” use the mouth to convey the emotion, so we have :) and :( In Japan, however, the eyes are used to convey the emotions, so ^.^ is commonly used for happy and ;-; for sad. “Emoticons are used to convey different emotions in cyberspace as they are the iconic representation of facial expressions,” Jack said. “Interestingly, there are clear cultural differences in the formations of these icons.” In summary, the researchers say, there are real perceptual differences between Western Caucasian and East Asian people. However, I doubt whether that applies to Caucasians who have grown up in Japan, or Japanese who have grown up in America, for example. It’s all about the culture you grow up in — your so-called nurture rather than nature. But, without overgeneralizing, it does help us understand how attempts to communicate emotions sometimes get lost in translation.
- Pythonで重複無しの出題をしたい。
Pytonで初歩的なcodeを書いております。 十個の四文字熟語があります。 重複のない四文字熟語を表示したいのです。 (1)のcodeでは上手く行くのですが、(2)の様にテキストファイルから読み込むと重複します。 多分while関数を使って重複が有ったら、再度randomで重複しないデータを抽出しろとでもやるのでしょうが、上手く行きません。 while以降どの様にcodingするのか、或いはそのほかの方法を教えて頂ければ嬉しいです。 宜しくお願い致します。 (1) リストから重複無しの熟語を表示する---OK ---------------------------- import random 四文字熟語=[ '0 百花繚乱', '1 疾風迅雷', '2 明鏡止水', '3 不撓不屈', '4 国士無双', '5 魑魅魍魎', '6 行雲流水', '7 花鳥風月', '8 天下無双', '9 行雲流水' ] 空リスト = [] for カウンター in range(10): 一時保存 = random.choice(四文字熟語) while 一時保存 in 空リスト: 一時保存 = random.choice(四文字熟語) 空リスト.append(一時保存) print(一時保存) これは重複無しの熟語を表示します。 --------------------- (1) テキストファイルから、重複無しの熟語を表示する---NG import random file = open("四文字熟語.txt") lines = file.readlines() file.close() for line in lines: line = line.rstrip("\n") temp = random.choice(lines) print(temp) Shellには、 7 花鳥風月 6 行雲流水 6 行雲流水 7 花鳥風月 2 明鏡止水 9 行雲流水 9 行雲流水 8 天下無双 7 花鳥風月 0 百花繚乱 -------------------------- このほうほうだと、こんな風に表示されます。
- ベストアンサー
- Python
- Kumasan2016
- 回答数1
- pythonでtwitterAPIを使用としたときのGAE上でのエラー
pythonでtwitterAPIを使用としたときのGAE上でのエラー <class 'urllib2.HTTPError'>: HTTP Error 401: Unauthorized GAE上にこの様なエラーが出てしまい。twitterbotに反映されません。 import urllib2は行っているのですが原因が分からず困っています。 よろしくお願いします # -*- coding: utf-8 -*- import twitter import random import os # from tenki import information from google.appengine.api import users from google.appengine.ext import webapp from google.appengine.ext.webapp import util from google.appengine.ext.webapp import template # twitter.Api.__init__ method for override. def twitter_api_init_gae(self, username=None, password=None, input_encoding=None, request_headers=None): import urllib2 from twitter import Api self._cache = None self._urllib = urllib2 self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT self._InitializeRequestHeaders(request_headers) self._InitializeUserAgent() self._InitializeDefaultParameters() self._input_encoding = input_encoding self.SetCredentials(username, password) # 天気用に追加 # from urllib2 import urlopen # from xml.dom.minidom import parseString # from xml.etree.ElementTree import * # information = [] # io = urlopen("http://www.google.com/ig/api?weather=Tokyo") # dom = ElementTree(file=io) # cond = dom.find("//current_conditions") # for name in ["condition","temp_c","humidity","wind_condition"]: # information.append(cond.find(name).get("data")) # overriding API __init__ twitter.Api.__init__ = twitter_api_init_gae list = [ u"ante" ,u"Do my best" ,u"piyopiyopiyo" ,u"piyopiyo" ,u"ponyo" ,u"piyo" ,u"my name is anteroom" # ,u"Today's weather is " + information[0] # ,u"Today's weather is " + information[1] # ,u"Today's weather is " + information[2] # ,u"Today's weather is " + information[3] ] post = random.choice(list) api = twitter.Api("hoge","hoge") api.PostUpdate(post)
- 締切済み
- その他(プログラミング・開発)
- mizomizorinrin
- 回答数1
- HD画質の動画を見たいのですが
カクカクしてしまい見るのに大変苦労します。 何が原因なのか検討もつかないので教えていただきたいです。 動画の情報 Video #1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L4.1 Format settings, CABAC : Yes Format settings, ReFrames : 9 frames Muxing mode : Container profile=Unknown@4.1 Codec ID : V_MPEG4/ISO/AVC Duration : 24mn 51s Bit rate : 5 742 Kbps Nominal bit rate : 6 000 Kbps Width : 1 280 pixels Height : 720 pixels Display aspect ratio : 16/9 Frame rate : 50.000 fps Resolution : 24 bits Colorimetry : 4:2:0 Scan type : Progressive Bits/(Pixel*Frame) : 0.125 Writing library : x264 core 68 r1195M 5d75a9b Language : English Audio #2 Format : AC-3 Format/Info : Audio Coding 3 Codec ID : A_AC3 Duration : 24mn 51s Bit rate mode : Constant Bit rate : 384 Kbps Channel(s) : 6 channels Channel positions : Front: L C R, Surround: L R, LFE Sampling rate : 48.0 KHz 私のパソコンのスペック等 ------------------ System Information ------------------ Machine name: NECCOMPUTER Operating System: Windows XP Home Edition (5.1, Build 2600) Service Pack 2 (2600.xpsp_sp2_gdr.090206-1233) Language: Japanese (Regional Setting: Japanese) System Manufacturer: NEC System Model: PC-VL570CD BIOS: Phoenix - AwardBIOS v6.00PG Processor: Intel(R) Celeron(R) CPU 2.93GHz Memory: 1016MB RAM --------------- Display Devices --------------- Card name: Intel(R) 82915G/GV/910GL Express Chipset Family Manufacturer: Intel Corporation Chip type: Intel(R) 82915G/GV/910GL Express Chipset DAC type: Internal Device Key: Enum\PCI\VEN_8086&DEV_2582&SUBSYS_826F1033&REV_04 Display Memory: 128.0 MB Current Mode: 1280 x 1024 (32 bit) (60Hz) Monitor: NEC F17R51
- 携帯3キャリア対応絵文字のPHPが上手く作動しません。
初めまして。 携帯サイトに3キャリア対応の絵文字を使いたく、http://www.dspt.net/tools/emoji/このサイトのPHPを使用しましたが 絵文字を挿入した部分に[an error occurred while processing this directive]というエラーが表示され、正常に絵文字が反映されません。 サーバーはPHP4.0、SSIに対応しているサーバーです(CORESERVER)。 プログラム設置は以下の通りにしました。 public_html / ●●.com / index.html | +-- php(←このphpフォルダはpublic_htmlの下の階層でいいのでしょうか?) | +-- emoji / trans.php emojih.csv emojix.csv | +-- images / .htaccessはindex.htmlと同じ場所に入れ、 AddType application/xhtml+xml .htm .html AddHandler server-parsed html と記載しています。 絵文字記載タグの相対パスは"/php/emoji/trans.php?emoji=絵文字番号" としています(デフォルトのまま)。 Mobile Site Coding&Designという本でも調べたのですが、こちらも同じPHPを使用(説明文もほぼ同じでした)しているのですが なぜか相対パスは"/php/emoji/trans.php?emoji=絵文字番号"となっていました。 また、AddHandler server-parsed htmlの記述の.htaccessもPHPフォルダの中に入れるとありました。 色々なパターンを試しましたがどれも上手くいかず、結局どれが正しいのか分からなくなってしまいました。 お詳しい方がいましたらご教授いただけましたら幸いです。よろしくお願い致します。
- Roxio Toast 8 Titanium にくわしい方へ
Roxio Toast 8 Titanium の アプリケーションの機能を使い、従来の標準動画フォーマット(形式)である、MPEG-1,MPEG-2 の 30 fpsの320×240、 30 fpsの640×480 などは、 Apple社の iPod や QuickTime などで標準動画フォーマット(形式)として採用されている、H.264/MPEG-4 AVC (MPEG-4 Version10 Advanced Video Coding ) の 30 fps の 640×480 の 解像度、もしくは、MPEG-4 Version 2 (Moving Picture Experts Group phase 4) の 30 fps の 640×480 の 解像度にコンバート(変換)できますか。出来る場合、30分の動画をコンバート(変換)するには、時間はどのくらいかかりますか。 http://www.roxio.jp/products/toast8/index.html http://e-words.jp/w/H2E264.html http://e-words.jp/w/MPEG-4.html Mac TV レコーダーEyeTV 250でMPEG-1、MPEG-2 で録画して、(現在では、H.264/MPEG-4 AVC または MPEG-4 Version 2 で録画出来ない)Toast 8 Titanium で H.264/MPEG-4 AVC の 30 fps の 640×480 の 解像度、もしくは、MPEG-4 Version 2 の 30 fps の 640×480 の 解像度にコンバート(変換) して、iTunes7.1.1 の ライブラリィーのテレビ番組、ビデオの項目に入れて、Apple TV に無線LAN で送信して、家電テレビで視聴したいためです。 http://www.roxio.jp/products/partner/eyetv250/index.html http://www.apple.com/jp/appletv/specs.html 使用環境 IMac G4 800、Intel Core 2 Duo プロセッサ、1GBメモリ お願いします。
- 上流でのトラブル
21 Mar. 2013 NATUREの記事です。 (1)Telomeres are non-coding sequences at the ends of chromosomes that shorten with every cell division as a result of incomplete DNA replication; telomerase acts to replenish these sequences. When the amount of functional telomerase is reduced, even by only half, telomere erosion occurs in yeast, mice and humans. テロメアは不完全なDNA複製が生じるごとに細胞文連つごてとに短絡する染色体末端における非コーディング塩基配列であり、テロメアーゼはこの塩基配列の補充機能を持つ。テロメアーゼの機能的な量が減少したとき、たった半分でさえもテロメアの腐敗は酵母、マウス、人において生じる。 even by only halfというのはなにが半分になったことなのでしょう。半分でさえもというか半分になったら酵素として役に立たないということがいいたいのでしょうか。 (2)Horn and colleagues began their study by examining the genetics of a large family to find a germline (inherited) mutation that predisposed four generations of family members to melanoma. この文章は 生殖系統を見るために行った実験から黒色腫の4メンバーが発生した あるいは 4つの黒色腫メンバーの素因(原因因子)を用意して生殖変異が起きることを調べるために実験した のどちらなのでしょうか。thatがややこしくなりました。 (3)Notably, it seems that melanocytes are especially sensitive to changes in TERT expression, because in Horn and colleagues’ study all but one person carrying the T-to-G mutation developed melanoma, and the unaffected carrier had multiple naevi. 注目すべきは、教授らの実験全てにおいて黒色腫細胞はTERT発現変化への著し感受性を示したが、一人の患者はT→G変異発生の黒色腫を生じ、この変異とは無関係な管じゃは多発性母斑を示しt。 手前の文章でテロメアーゼの過剰産生はがんを進行させるという文章が書いてありそのあとで上記の文章が続くのですが、何が言いたいのでしょうか。ちょっとまったく意味が解りません。
- pythonでスクレイピングがうまく出来ません
python2.7でbeautifulsoupを用いて、netkeiba.comから競馬情報(騎手の成績)をスクレイピングしています。 定法に基づきまして、『検証』からページのツリー構造を把握して、プログラムを作成しました。 馬名部分の構造が<td class="txt_l"> <a href="/horse/2011105901">テンテマリ</a></td> #テンテマリは馬名 となっておりましたので、"txt_l"を拾い出せるようにスクリプトを作りました。 しかしながら、 馬名以外の"txt_l"は全部スクレイピング出来るのですが、馬名部分だけがNoneと返ってまいります。 エラーメッセージではありませんが、何が原因でNoneとなるのかが、どうしても分かりません。 ちなみに、馬名以外で、ほぼ同様の構造を持つ、『レース名』、構造は <td class="bml txt_l"> <a href="/race/201603020812/" title="3歳上500万円下">3歳上500万円下</a> (3歳上500万円下はレース名) では、問題なくレース名を拾うことが出来ました。 該当のソースコード -*- coding:utf-8 -*- import urllib2 import codecs from bs4 import BeautifulSoup tpl_url='http://db.netkeiba.com/?pid=jockey_detail&id=00663&page={0}' for i in xrange( 1, 2 ): url=tpl_url.format( i ) soup = BeautifulSoup(urllib2.urlopen(url).read(),"lxml") tr_arr = soup.find('div', {'id':'contents_liquid'}).findAll('tbody') for tr in tr_arr: lrg1 = tr.findAll('td',{'class':'txt_l'}) for tr1 in lrg1: print tr1.string 試したこと 馬名以外の('td',{'class':'txt_l'})に準ずる『レース名』は、うまく拾うことが出来ました。 lrg1 = tr.findAll('td',{'class':'txt_l'}) で馬名を得ることが出来ない理由、併せて馬名を拾えるスクリプトを御教示くださいますよう、よろしくお願いいたします!
- 締切済み
- その他(プログラミング・開発)
- akakage13
- 回答数1
- pythonで次のようなプログラムを作りたいのですがうまくいきません。
pythonで次のようなプログラムを作りたいのですがうまくいきません。 アドバイスお願いします。 1.ゲーム開始時のユーザの手持ちのコインの枚数を10枚とする。手持ちのコインの枚数を画面に表示。 2.以下while文を使い、無限ループさせる。 3.コインを1枚入れて、スロットマシンを動かす。具体的には、手持ちのコインの枚数を1だけ減らし、さらに、0~9までの乱数を3つ作成し、画面に表示。 4.3の数が3つとも同じ場合はコインを100枚獲得。2つの場合はコインを10枚獲得。 5.現在の手持ちのコインの枚数を画面に表示し、ゲームを継続するかどうか尋ねる。 実行結果の例: your coin: 10 Coin Slot -> 960 残念! your coin: 9 insert coin(Y/N)?- Y Coin Slot -> 110 10コイン、ゲット! your coin: 18 insert coin(Y/N)?- Y Coin Slot -> 872 残念! your coin: 17 insert coin(Y/N)?- N See You Again! your coin: 17 Done! と、いう感じです。 無茶苦茶だと思うので、いろいろと細かい指摘をお願いします。 #coding:sjis #program name:coin_slot.py import random coin=10 print "your_coin",coin print while True: coin=coin-1 num1=random.randint(0,9) num2=random.randint(0,9) num3=random.randint(0,9) print "Coin Slot -> ",num1,num2,num3 if num1!=num2!=num3: print "残念!" elif num1==num2 or num2==num3 or num3==num1: print "10コイン、ゲット!" coin=coin+10 elif num1==num2==num3: print "100コイン、ゲット!" coin=coin+100 print "your_coin",coin print answer=input("insert coin(Y/N)?-") if answer==Y: continue elif answer==N: print "See You Again!" break raw_input("Done!")
- 締切済み
- その他(プログラミング・開発)
- massan0204
- 回答数1
- $obj->decode($bytes)って何?
Encode.pmのPODを読んでいます。その一文です。 [$obj =] find_encoding(ENCODING) Returns the encoding object corresponding to ENCODING. Returns undef if no matching ENCODING is find. This object is what actually does the actual (en|de)coding. $utf8 = decode($name, $bytes); is in fact $utf8 = do{ $obj = find_encoding($name); croak qq(encoding "$name" not found) unless ref $obj; $obj->decode($bytes) }; with more error checking. まず This object is what actually does the actual (en|de)codeing. 直訳すると、「このオブジェクトは実際のエンコードやデコードを実際に行うものです。」となります。実際の、実際の、と二つ並ぶのはあまり語感が良くないと思いますが、でもこのPODを書いたのは文学者ではないですから、原文の方に問題があるのではないかと思います。 次に「このオブジェクト」とは何を指しているのでしょう。find_encoding関数のことを言っているのでしょうか? というのは、下に $utf8 = decode($name, $bytes); は実際には、 $utf8 = do{ $obj = find_encoding($name); croak qq(encoding "$name" not found) unless ref $obj; $obj->decode($bytes) }; だと書いています。{}の中で一番重要なのはfind_encoding関数だと言いたいのではないかと・・・ そうすると This object is what actually does the actual (en|de)codeing. は、 「実際にエンコードやデコードを行っているのはこの関数です。」 と訳するのが正しいでしょうか? 最後に、 $obj->decode($bytes) $objという文字コードで記述されている$bytesという文字列をutf-8に変換したもの、という意味なはず。 でも浅学な私には、どのような文法でこのコードが書かれているか分かりません。 Perlにおいて、変数と言えば$objだったり@objだったり%objだったりします。そしてそのリファレンスはこれら変数の前に「\」を付ければ良くて、リファレンスはスカラー変数となるから、 $refobj=\($|@|%)obj; となります。 元の変数が(@|%)objの場合、元の変数の一要素を取り出すには、 $obj([index]|{'index'})=$refobj->index; となります。 これが私の知っている矢印記法の唯一の使い方です。 お手数ですが、どなたか教えていただけないでしょうか?
- Python について質問です
私はPythonの初心者です。 今Python でCSVのファイルを読んで数値だけ(数値以外に文字列や空白などがあります)を計算処理出来なくて困っています。教えて頂けませんか? 質問は、BB.csvというファイルの数値だけの合計と平均を計算したいです。 私のコードは以下です。 # coding: utf-8 import csv import re import string DATAFILE = 'BB.csv' class UnicodeDictReader(csv.DictReader): def __init__(self, f, fieldnames=None): csv.DictReader.__init__( self, f, fieldnames) def main(): total = 0 all_sum = 0 line_num = 0 with open(DATAFILE) as csvfile: reader = UnicodeDictReader(csvfile) for record in reader: # 値を数値で取得 A = int(record['38186']) B = int(record['38181']) C = int(record['38143']) item_total = A + B + C total = item_total all_sum += item_total line_num += 1 average = all_sum / reader.line_num print(" %d + %d + %d = %d " % ( A, B, C, total)) print(u"合計 %d " % all_sum) print(u"平均 %d " % average) if __name__ == '__main__': main() BB.csvは以下です、 38186,38181,38143 1,1,4 1,1,4 ,, ,, 2020,2020,2020 1412,1412,1412 625,625,625 75,75,75 75,75,75 75,75,75 75,75,75 4,4,4 4,4,4 4,4,4 7828,7828,7828 X,, 0,0,0 0,0,0 ○,, 0,0,0 0,0,0 0,0,0 ,,AAA 0,0,0 0,0,0 0,0,0 ,BBB, 0,0,0 0,0,0 0,0,0 ,, 0,0,0 ,, 0,0,0 0,0,0 ,, 0,0,0 0,0,0 750,750,750 400,400,400 400,400,400 ,, 0,0,0 0,0,0 0,0,0 ,, 0,0,0 0,0,0 0,0,0 0,0,0 0,0,0 0,0,0 0,0,0 6,6,6 6,6,6 18,18,18 18,18,18 18,18,18 18,18,18 18,18,18 16,16,16 16,16,16 6,6,6 6,6,6 18,18,18 18,18,18 18,18,18 18,18,18 18,18,18 11,11,11 11,11,11 11,11,11 3,3,3 3,3,3 3,3,3 3,3,3 4,4,4 4,4,4 3,3,3 3,3,3 16,16,16 16,16,16 16,16,16 14,8,11 8,14,11 8,14,11 8,14,11 8,14,11 8,14,11 8,14,11 8,14,11 8,14,11 15,15,15
- 締切済み
- その他(プログラミング・開発)
- noname#187756
- 回答数2
- 前回はごめんなさい。pythonでcgiとソケット
どうもこんにちは。 この前の質問は補足しようと思いサブアカウントを作成したら 利用規約に引っかかったみたいで削除されてしまいました。 自分が何も知らないばかりに回答者の方々には不快な思いをさせてしまったことをお詫びします。 本題ですが、 pythonのプログラムをサーバーで動かそうと思って、 .cgiのファイルを作成しました。 そして、httpの形にして文字を表示することは出来たのですが、 本当にしたいのはソケット通信なんです。 自分のPCでのソケット通信(サーバー&クライアント)はできますし、 cgiも簡単なものなら動くようになりました。 が、cgiでソケット通信ができません。 httpのリクエストでgetしろよ。と思うかもしれませんが、 ソケット通信じゃないとダメなんです。 無理なら諦めますが、出来るならやり方を教えて下さい。 自分のPCでのソケット通信のプログラムは以下のものとなります。 #!/usr/local/bin/python #coding: utf-8 import socket import time host = "localhost" port = 50000 data = "HOST:"+host+"\nPort:"+str(port) port = int(port) print ("python socket server") print (data) while(True): print ("wait...\n") sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_server.bind((host, port)) sock_server.listen(1) connect, addr = sock_server.accept() print ("Connect...\naddress:", addr) while(True): mes = connect.recv(1024) if not mes : break print ("Getmessage:", mes) connect.send("server message") print ("send message:server message") sock_server.close() これをサーバーに移そうと思うとこのままですとlocalhostでエラーが出ます。 なのでこれをgethostnameやgethostbynameにしようとすると、 こりゃまたエラーが出てしまいます。 どうしたら出来るのでしょうか?? サーバーは@pagesを今は使っていますが、 将来的には個人のサーバー(独自ドメインの)で動かすことになると思います。
- ベストアンサー
- CGI
- poteto0413
- 回答数2
- スマートフォンサイト制作について、ご教授ください。
現在、スマートフォンサイトを制作しており、JavaScriptを多数組み込んだ仕様にしているのですが、複数のJavaScriptを併用する上で行き詰ってしまいました。 具体的な問題点として、 ・「to-R」さんで公開されている「heightLine.js(http://blog.webcreativepark.net/2007/07/26-010338.html)」 ・「ChronoDrive」さんで公開されている「tilt.js(http://html-coding.co.jp/knowhow/smtp/000140/)」 上記の2種類のJavaScriptを組み込む際、「tilt.js」の機能である縦横切り替えがAndroid(確認した機種はauのIS03)で上手く機能しない状態となってしまいます。 自分なりに考えた結果、iOSの場合は「tilt.js」での切り替えを「window.onorientationchange」にて行っているのに対し、Androidは「window.onresize」にて行っているようですので、「heightLine.js」でも使っている「window.onresize」の処理だけが機能せず、Androidの場合にこのような現象が起きるものと推測しました。 JavaScriptに関する知識が浅いため、処理を追って理解する力が乏しい上、仮に推測が正しかったとしてもそれをどう改善すべきかがわからず、手詰まりとなっている状態です。 「heightLine.js」以外にもブロック要素の高さを揃えるJavaScriptがいくつかありますが、動的に変わる要素を揃えるためにも、できれば「heightLine.js」を使いたいと考えております。 また、高さを揃えるためのCSSも試したのですが、サイト構成上、不具合が生じてしまいましたので、JavaScriptによる制御を第一として制作を進めております。 長文・乱文で大変読みにくい文章かもしれませんが、ぜひお力をお借りしたいと思い、今回このような質問をさせていただきました。 どんな些細な情報でも構いませんので、ご教授の程、よろしくお願い致します。
- ベストアンサー
- JavaScript
- dededann
- 回答数1
- Python3でのメタプログラミングについて
下記の Ruby スクリプトと同じことを Python で行う場合、どのように実装すればいいでしょうか? <前提> ・メソッドを Klass クラスに実行時に動的に追加する。 ・追加したメソッドの動的削除、変更は必要ない。 ・メソッド定義は、Python のオブジェクトではなく単なる文字列。 ・メソッド内部から Klass クラス内のインスタンス変数にアクセスする。 ・Klass クラスや Klass インスタンスを扱う処理から、動的に追加したメソッドを呼び出す。 ・追加したメソッドはシングルトンメソッドである必要はない。 <目的> Klass クラスのカスタマイズ機能をメソッド定義文として外部に保存しておいて、実行時に呼び出して機能を拡張するような目的です。Klass クラスはめったに変更されないもの、カスタマイズ機能(メソッド定義文)はよく変更されるもの、という切り分けをしたいため、単純に多重継承や MixIn はしたくないです。(上手い方法があればいいのですが…) #!/usr/bin/env ruby # coding: utf-8 # 文字列のメソッド定義 $user_funcs = [' def user_foo() puts "foo" * @x end ', ' def user_bar() puts "bar" * @x end '] # ↑本来は文字列として外部DBに記録されている。 # ---- # # 拡張したいクラス # class Klass # インスタンス変数を持つ def initialize @x = 3 end attr_accessor :x # 文字列で定義されたメソッドを追加 $user_funcs.each do |f| eval f end end # ---- # # 呼出方法 # obj = Klass.new # 追加されたメソッド(user_から始まる名前)を列挙しながら実行する # => どんな定義がされていても、命名規則さえ守っていれば呼び出し側はそのメソッド名を知る必要はない。 obj.methods.select {|m| /^user_/ =~ m }.each do |m| eval "obj.#{m}" end # 追加されたメソッドはシングルトンメソッドではなく、あくまでもインスタンスメソッドである。 obj2 = Klass.new # インスタンス変数の書き換え obj2.x = 4 # インスタンスメソッドの書き換え def obj2.user_bar() puts "hoge" * @x end obj2.methods.select {|m| /^user_/ =~ m }.each do |m| eval "obj2.#{m}" end
- smb.confの[printers]とiptablesの631/tcpの関係を教えてください
いろいろ試したのですが どうもsmb.conf中に[printers]がある場合 通信制御の設定を iptables -A INPUT -p tcp --dport 631 -j ACCEPT iptables -A INPUT -p tcp --sport 631 -j ACCEPT としないとサンバが起動できません。 これは、あらゆるホストからのIPP要求を許可する設定なので、なんか嫌ですよね。 せめて iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 631 -j ACCEPT iptables -A INPUT -s 192.168.1.0/24 -p tcp --sport 631 -j ACCEPT というようにLAN内のホストだけに許可するように設定してみたのですが、これだとサンバが起動できませんでした。 また --dport 631とはクライアントからのIPP要求であることが読み取れますが --sport 631とは送信元ポート番号が631ということで何の要求なのか解せません。 この問題はsmb.confを適切に設定することによって解決できるような気がするのですが ちょっとどこを直したらいいのか分かりません。 smb.confとTCP/IPに詳しい方、助けてください~ smb.confは次のように設定してあります(関係なさそうなのは省略してます) [global] security = share coding system = euc client code page = 932 server string = ファイルサーバー encrypt passwords = yes create mask = 0777 directory mask = 0777 printing = cups printcap name = lpstat [printers] path = /var/spool/samba/ browseable = no guest ok = yes printable = yes print command = lpr -P%p -o raw %s -r 理想は iptables -A INPUT -s 192.168.1.0/24 -p tcp --dport 631 -j ACCEPT というふうにLAN内のホストだけにIPP要求を許可する設定にしてサンバを起動できるようにしたいです。 また iptables -A INPUT -p tcp --sport 631 -j ACCEPT については何のために必要なのかご存知の方は教えてください 以上よろしくお願いします
- nature(論文)の和訳添削のお願い(7)
QNo.7273050の続きです.natureに掲載された論文の訳です.苦戦しています.どなたか添削をお願いします. (1)Transition nucleotide changes were observed twice as often as transversions, indicating that variant calls reproduce the expected properties of natural variation in other mammals. (1)変異ヌクレオチドの変化は塩基置換するたびに2度観察され,その変化の兆候は,他の哺乳類の自然な変化の予想された特性の複写を予測する. (2)This low level of nucleotide diversity may reflect a low effective size of NMR population, but may also be due to a high level of inbreeding, a reduced mutation rate or high efficiency of the repair systems. この低レベルのヌクレオチドの相違点は,低い有効な大きさのNMRの個体数をもたらし,高いレベルの近親交配,限定された突然変異体の割合あるいは回復(修理)システムの高い効率の理由である(だろう) (自然な訳)このわずかなヌクレオチドの違いが,NMRの少ない個体数の原因であり,高レベルの近親交配,突然変異の少なさあるいは高い(遺伝子)修復システムの理由である. (3)The variation of diversity along the genome was consistent with inbreeding in the NMR population. (3)ゲノムに沿った種々の変化は,そのNMRの母集団の近親交配と矛盾しない. (自然な訳)ゲノムに沿った種々の変化は,そのNMRの母集団の近親交配を支持するものだった. (4)In protein-coding regions of the genome, our analysis identified 10,951 non-synonymous and 8,616 synonymous SNPs. (4)ゲノムのタンク質のコード化において,我々の解析は10951の非同義および8616の同義SNPs (一塩基変異多型)を同定した. (5)Their ratio is much higher than in other studied organisms, including human, which appears to signal relaxation of purifying selection in the NMR, potentially as a consequence of reduced effective population size. (5)これらの分配は,ヒトを含めた他の研究(者による)の生物より非常に高く,NMRの純化緩和の証拠となることに気づく. (自然な訳)これらの非同義および同義の分配(割合)はヒトを含めた生物(他の研究者)の研究結果と比べて非常に高く,NMRの純化を緩和している. (6)Finally, we analysed the context dependency of NMR SNPs (Supplementary Fig. 11). (6)最後に我々は,MNRのSNPs(一塩基変異多型)の前後関係の一貫性分析した(付図11). (7)Relative rates of nucleotide changes and nucleotide context dependencies were similar to those observed in human polymorphism, with the exception of a relative reduction of SNPs due to CpG mutations. (7)ヌクレオチドの変化とヌクレオチドの前後関係依存状態の相対的な比率は,CpG突然変異体に起因するSNPsの相対的減少を例外としてヒトの多型に見られるそれらと似ている.
- RNAスプライシングの問題
RNA splicing is an essential, precisely regulated process that occurs after gene transcription and before mRNA translation. A gene is first transcribed into a pre-mRNA, which is a copy of the genomic DNA containing intronic regions destined to be removed during pre-mRNA processing (RNA splicing), as well as exonic sequences that are retained within the mature mRNA. The splicing of pre-mRNA occurs in multicomponent molecular machines called spliceosomes, in which the two-step splicing reaction comprising intron removal and exon ligation takes place. To enable splicing to occur correctly, the positions of the exon–intron boundaries are marked by short consensus sequences. There are less clearly defined sequences within the exons and the introns that positively or negatively regulate splicing (referred to as enhancer or repressor sequences). As observed for transcriptional control, RNA splicing is subject to extensive regulation by signalling pathways. During splicing, exons can either be retained in the mature message or targeted for removal in different combinations to create a diverse array of mRNAs from a single pre-mRNA, a process referred to as alternative RNA splicing. This process occurs in several ways including the skipping of entire exons, the inclusion of alternative exons, the use of different splice sites and/or the retention of introns. Alternative splice events that affect the protein coding region of the RNA might give rise to proteins that differ in their sequence and therefore in their activities. Alternative splicing within the non-coding regions of the RNA can result in changes in regulatory elements, such as translation enhancers or RNA stability domains, which might have a dramatic effect on the level of protein expression . Alternative RNA splicing is controlled by a large number of factors but the SR protein family, together with hnRNP A/B proteins, are key regulatory components. Given that as many as 60% of all human genes are alternatively spliced, the potential impact of alternative splicing on both drug efficacy and toxicity is high, because of the large number of genes involved in drug response pathways. というRNAスプライシングの概略を説明した文章を読んで問に答える問題です (1)RNAスプライシングを上の文章に沿って200字で説明せよ (2)RNAスプライシング反応は2つのフェーズに分かれるどのような反応か本文にそって100字以内で説明せよ (3)RNAスプライシングのための必須塩基配列側の条件に付いて本文に記載されているものを日本語で列挙せよ (4)選択的RNAスプライシングはどのようなものか150字で説明せよ (5)Given that as many as 60% of all human genes are alternatively spliced, the potential impact of alternative splicing on both drug efficacy and toxicity is high, because of the large number of genes involved in drug response pathways. を150字以内で日本語訳せよ とありました。 (1)はRNAスプライシングとは遺伝子転写後からmRNA翻訳前の間に生じるRNAの正確な制御機構である。初めにpre-mRNA中に遺伝子が転写される。そしてこの中に含まれるイントロンと呼ばれる領域がスプライシングの際に除去され、成熟mRNA中に維持されるエクソン領域が保存される。Pre-mRNAのスプライシングはスプライソソームと呼ばれる複合体によって行われ、二段階の反応によってスプライシングは行われる。 としましたがこの文章量からして自分の解答は物足りないと感じましたがどこまで書けばいいのか混乱してしまいました。 (2)は二段階のステップ 1イントロン除去 2エクソン核酸連結なのはわかりますが150字の説明がまとまりません。 (3)はショートコンセンサス配列 (4)選択的スプライシングとは単一pre-mRNAからmRNAの多様性のある配列を作成するための組み合わせにおいて、各エクソンにおいて成熟RNA中に残すかあるいは除去をするかのいずれかが行われる過程である。としましたがこれも非コーディング領域の話などをおざなりにして物足りない説明だと思いました。 そして一番の難問は(5)です。 この手の問題はいつもそうですが確実に直訳をしたら150字など到底届かない気がします。 (5)は 人の全遺伝子の60%が与えられた結果と同様に選択的スプライシングを受け、選択的スプライシングの薬品効果と毒性における潜在的な影響は高い。なぜなら薬品反応伝達経路に関係する遺伝子群のほとんどをこの含んでいるためである。 と108字しかありません。どうすればいいのでしょうか。恐らくGivenのところをもう少し修飾しなければならないのだと思いますがそうすると余計なことまで書いてしまいそうで不安です。けれども150字といわれているので確実に減点対象だと思います。 適切なアドバイスお願い申し上げます。 こういった問題が沢山英語では出てくるのですが 上手く日本語にまとめられませんでした。お時間がございましたら是非ご教授お願い申し上げます。
- Pythonスクリプトが実行できない
インターネット上で公開されているスクリプトなのですが、実行しようとするとエラーが出てしまいます。どうすれば正しく実行することができるのか、分かる方教えていただけると助かります。よろしくお願いします。 エラーメッセージはスクリプトの下に記載します。 ニコニコ動画にログインし、マイページに新規マイリストを作成して、任意の動画をマイリストに登録するスクリプトです。 #!/usr/bin/env python #coding: utf8 userid="ここにメールアドレスを入力" passwd="ここにパスワードを入力" import sys, re, cgi, urllib, urllib2, cookielib, xml.dom.minidom, time import simplejson as json def getToken(): html = urllib2.urlopen("http://www.nicovideo.jp/my/mylist").read() for line in html.splitlines(): mo = re.match(r'^\s*NicoAPI\.token = "(?P<token>[\d\w-]+)";\s*',line) if mo: token = mo.group('token') break assert token return token def mylist_create(name): cmdurl = "http://www.nicovideo.jp/api/mylistgroup/add" q = {} q['name'] = name.encode("utf8") q['description'] = "" q['public'] = 0 q['default_sort'] = 0 q['icon_id'] = 0 q['token'] = token cmdurl += "?" + urllib.urlencode(q) j = json.load( urllib2.urlopen(cmdurl), encoding='utf8') return j['id'] def addvideo_tomylist(mid,smids): for smid in smids: cmdurl = "http://www.nicovideo.jp/api/mylist/add" q = {} q['group_id'] = mid q['item_type'] = 0 q['item_id'] = smid q['description'] = u"" q['token'] = token cmdurl += "?" + urllib.urlencode(q) j = json.load( urllib2.urlopen(cmdurl), encoding='utf8') time.sleep(0.5) #ログイン opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) urllib2.install_opener(opener) urllib2.urlopen("https://secure.nicovideo.jp/secure/login", urllib.urlencode( {"mail":userid, "password":passwd}) ) #トークン取得 token = getToken() #マイリストの作成と動画の登録 mid = mylist_create(u"テストリスト") addvideo_tomylist(mid, ["sm9","sm1097445", "sm1715919" ] ) <エラーメッセージ> >>> #?^í?^°?^¤?^ó ... opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar())) >>> urllib2.install_opener(opener) >>> urllib2.urlopen("https://secure.nicovideo.jp/secure/login", ... urllib.urlencode( {"mail":userid, "password":passwd}) ) <addinfourl at 4311877104 whose fp = <socket._fileobject object at 0x101007758>> >>> #?^?^??^ü?^¯?^ó?^?^??^? ... token = getToken() Traceback (most recent call last): File "<stdin>", line 2, in <module> File "<stdin>", line 8, in getToken UnboundLocalError: local variable 'token' referenced before assignment >>> #?^?^??^¤?^ê?^¹?^?^??^???^??^?^??^???^?^??^Ի?^???^ٻ?^̲ ... mid = mylist_create(u"?^?^??^¹?^?^??^ê?^¹?^?^?") Traceback (most recent call last): File "<stdin>", line 2, in <module> File "<stdin>", line 9, in mylist_create NameError: global name 'token' is not defined >>> addvideo_tomylist(mid, ["sm9","sm1097445", "sm1715919" ] ) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'mid' is not defined >>> <環境>imac, mac os x, ターミナルを使用
- 締切済み
- Mac
- myu0528myu
- 回答数1