preload
十一月 11

安裝

tar zxvf Django-*.tar.gz
cd Django-*.
sudo python setup.py install

開一個新專案

~/djcode$ django-admin.py startproject mysite
~/djcode$ ls -a mysite/
./           ../          __init__.py  manage.py    settings.py  urls.py
    __init__.py: 偽裝目錄成package
    manage.py: 一個cli的工具,讓妳可以用多種方式和Django專案互動
    settings.py: Django專案的設定/組態
    urls.py: 此Django專案的URL宣告

執行開發用Server

~/djcode/mysite$ python manage.py runserver
Validating models...
0 errors found
 
Django version 1.1.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[10/Nov/2009 19:55:59] "GET / HTTP/1.1" 200 2053
It worked!

It worked!

改Port或IP

python manage.py runserver 8080
python manage.py runserver 0.0.0.0:8080
Tagged with:
十一月 05

tchinese.py

#!/bin/python
print "Python是個酷玩意"
python tchinese.py
SyntaxError: Non-ASCII character '\xe6' in file tchinese.py on line 2, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

錯誤訊息中的連結到這篇文章:PEP 0263 — Defining Python Source Code Encodings
文中提到:

To define a source code encoding, a magic comment must be placed into the source files either as first or second line in the file, such as:

# coding=<encoding name>

or (using formats recognized by popular editors)

#!/usr/bin/python
# -*- coding: <encoding name> -*-

or

#!/usr/bin/python
# vim: set fileencoding=<encoding name> :

Example:

#!/bin/python
# -*- coding: utf-8 -*-
print "Python是個酷玩意"

Result:

Python是個酷玩意
Tagged with:
十一月 02
這是一本不錯的 Python 工具書,適合 Python 初學者閱讀的入門書
中譯版

電腦做什麼事是一系列Python程式語言的教學文章,我們嘗試提供給讀者以簡單、直覺的方式學習程式語言,進而了解體會電腦背後運作的道理。

來源:學習寫程式 – Sy3es_wiki

Tagged with:
十一月 02

PHP 檔案處理

讀檔:

1.fopen

範例:

<?php
$handle = fopen("open_file.txt", "r");
if( $handle === FALSE)
{    
    echo "Open File Fail" . "<br>";
} 
else
{    
    echo "Open File Success" . "<br>";
    while (!feof($handle))
    {
        $current_line = fgets($handle);
        echo $current_line . "<br>";
    }
}
 
?>

2.file_get_contents

範例:

<?php
 
$handle = file_get_contents('open_file.txt');
echo $handle;
 
?>

=========================================================

寫檔:

1.fwrite

<?php
$handle = fopen('open_file.txt', 'w');
fwrite($handle, "test1");
fclose($fp);
?>

ps:fwrite 是沒有加換行字元,如果要換行必須加上 \n 處理

2.file_put_contents

<?php
    $handle = 'open_file.txt';
    $current_line = "line1\n";
    file_put_contents($handle, $current_line);
?>

source: PHP:檔案處理 @ 拉不拉多的夢幻世界 :: 痞客邦 PIXNET ::

Tagged with:
十月 28

Hello World

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env perl
 
# helloworld.pl
#
# Created by Chun-Ting Liu on 2009-10-28
 
require 5.008008;
use warnings;
use strict;
use Tk;
my $mw = MainWindow->new;	#建立一個視窗
$mw->title("Hello World");	#改變視窗標題文字,若沒有指定則預設為檔名(首字母會自動大寫)。title method不是必要的但會比較好看。
$mw->Button(-text => "Done!",
	-command => sub { exit })->pack();
	#建立一個寫著Done!的Button widget,點擊後則執行 exit。
MainLoop;	#開始GUI事件處理

Hello World

Tagged with:
十月 18

探索Perl的世界 -1  本集是第一集,介紹Perl的概述。
探索Perl的世界 -2  本集是第二集,介紹Perl的簡單變量。
探索Perl的世界 -3  本集是第三集,介紹Perl的字符串變量。
探索Perl的世界 -4  本集是第四集,介紹字符串變量和小結
探索Perl的世界 -5  本集是第五集,這一章是講perl中的運算符,這一節為第一段,講算術運算符,比較運算符和邏輯運算符。
探索Perl的世界 -6  本集是第六集,這一章是講perl中的運算符
探索Perl的世界 -7  本集是第七集,這一章是講perl中的運算符優先級。
探索Perl的世界 -8  本集是第八集,這一章是講perl中的控制結構。
探索Perl的世界 -9  本集是第九集,這一章是講perl中的控制結構。
探索Perl的世界 – 10
探索Perl的世界 – 11
探索Perl的世界 – 12

Tagged with:
十月 18

先來一個例子吧

繼續閱讀 »

Tagged with: