万年素人からHackerへの道

万年素人がHackerになれるまで殴り書きするぜ。

  • ・資産運用おすすめ
    10万円は1000円くらい利益
    資産運用ブログ アセマネ
    • ・寄付お願いします
      YENTEN:YYzNPzdsZWqr5THWAdMrKDj7GT8ietDc2W
      BitZenny:ZfpUbVya8MWQkjjGJMjA7P9pPkqaLnwPWH
      c0ban:8KG95GXdEquNpPW8xJAJf7nn5kbimQ5wj1
      Skycoin:KMqcn7x8REwwzMHPi9fV9fbNwdofYAWKRo

    tkinterをPython3で

    GUIを作るtkinterをPython3でやってみた
     空ウィンドウ表示

    import tkinter
    
    root = tkinter.Tk()
    f = tkinter.Frame(root)
    f.mainloop()
    

    SQLAlchemy チュートリアル

    →本よりここがよさげ
    http://omake.accense.com/static/doc-ja/sqlalchemy/ormtutorial.html

     「MySQL versions 3.23-5.1; and Python versions 2.3-2.6 are supported.」→ MySQL-pythonはPython3に対応してないらしい

    ・PyMySQL「Python3に対応してそうなモジュール」

    git clone https://github.com/petehunt/PyMySQL.git

    https://code.google.com/p/pymysql/downloads/list
    PyMySQL3-0.4.tar.gz ※Python3対応

    ・インストールはバージョン指定すればインストール成功した

    pip install pymysql3==0.4

    ※「pymysql」とか「pymysql3」だと失敗した

    ・create_engine
    →create_engineでは、記述に"+pymysql"が必要みたいだ

    from sqlalchemy import *
    engine = create_engine('mysql+pymysql://guest@192.168.222.1/test')
    

    →しかしこんなエラーが発生して解決できない

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Users\sugitashinsuke\env32\lib\site-packages\sqlalchemy\engine\__init__.py", line 327, in create_engine
        return strategy.create(*args, **kwargs)
      File "C:\Users\sugitashinsuke\env32\lib\site-packages\sqlalchemy\engine\strategies.py", line 64, in create
        dbapi = dialect_cls.dbapi(**dbapi_args)
      File "C:\Users\sugitashinsuke\env32\lib\site-packages\sqlalchemy\dialects\mysql\pymysql.py", line 37, in dbapi
        return __import__('pymysql')
      File "pymysql\__init__.py", line 30, in <module>
        from converters import escape_dict, escape_sequence, escape_string
    ImportError: No module named converters

    http://code.google.com/p/pymysql/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=60

    PostgresQL
    psycopg2・・・http://www.initd.org/pub/software/psycopg/

    Python3では動かないのでポート方法のBlogがある
    http://initd.org/psycopg/articles/2011/01/24/psycopg2-porting-python-3-report/
    →こちらにその人がポートしたと思われるPython3版psycopg2がある
     URL:https://github.com/dvarrazzo/psycopg


    Shift_JISのダメ文字チェッカー Python3.2

    ダメ文字Shift-JISの参考URL:https://sites.google.com/site/fudist/Home/grep/sjis-damemoji-jp

    ・dame_checker.py

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    import re
    import sys
    
    argvs = sys.argv
    word = '円'
    
    # parameter check
    if len(argvs) > 1:
        word = argvs[1]
    
    encoded = str(word.encode('cp932'))
    print('[' + word + ' => ' + encoded + ']')
    #  @ [ \ ] ^ _ ` { | } ~
    flg = False
    for x in ['@', '\[', '\\\\', '\]', '\^', '_', '`', '{', '\|', '}', '~']:
        if re.search(x + '\'$', encoded):
            print('**** BAD ****')
            print(x + 'is included')
            print('************')
            flg = True
    
    
    if flg == False:
        print('OK')
    

    →パラメータへ文字を送る
    ・デフォルトは「円」がチェックされます

    python dame_checker.py

    ・引数にダメ文字かをチェックしたいのを入力

    python dame_checker.py 倒

    cx_Freeze Python3.xにも対応したpy2exeのようなもの

    http://cx-freeze.sourceforge.net/