1. virtualenv 로 개발 프로젝트 폴더 생성

1-1) virtualenv {프로젝트 폴더명}

[그림 1-1] virtualenv 실행

2. pycharm 셋팅

2-1) pycharm 프로젝트 오픈

[그림 2-1] pycharm 프로젝트 오픈

2-2) 방금 생성한 폴더를 프로젝트 폴더로 설정 합니다.

2-3) File - settings... 로 이동

[그림 2-2] settings 로 이동

2-4) project Interpreter 설정

[그림 2-3] Project Interpreter 설정

2-5) Interpreter 추가

[그림 2-4] Interpreter 추가

2-6) 생성 폴더/Scripts/python.exe 추가

[그림 2-5] Interpreter 추가

소수점 중 불필요한 0이 있을 수 있다. 

예를 들면

3.150 , 3.0, 4.000 과 같이 특정 이상 소수점 부터는 의미 없는 0일 수 있다.(엄밀히 말하면 의미 없다고 할 수 없지만!) 

그럴 때 다음과 같이 하면 0을 제거 할 수 있다.

print 10.0/2
print "%g" %(10.0/2)

결과는 다음과 같다.

5.0
5
[Finished in 0.1s]

python 에서 텍스트를 처리할 때 특수문자를 제거해야 할 때가 있습니다. 이럴 때 정규표현식 으로 처리할 수도 

있지만 다음과 같이 처리할 수도 있습니다.


sample_string = "1234567890abcdefgABCDEFG!@#$%^&*()_{}[]<>"
result_string = ""
 
for c in sample_string:
    if c.isalnum():
        result_string +=c
 
print result_string
결과는 다음과 같습니다.
1234567890abcdefgABCDEFG 
[Finished in 0.2s]


Python 에서 리스트(List)에 값은 함수를 적용하고 싶을 때 map 함수를 사용하면 됩니다.

예제 소스로 확인해 봅시다.

def plus(x):
    return x+x
 
lst = [1,2,3,4,5,6,7,8,9, "A", "B", "C"]
 
print map(plus, lst)

결과는 다음과 같습니다.

[2, 4, 6, 8, 10, 12, 14, 16, 18, 'AA', 'BB', 'CC']
[Finished in 0.1s]

Naming

module_name, package_name, ClassName, method_name, ExceptionName, function_name, GLOBAL_CONSTANT_NAME, global_var_name, instance_var_name, function_parameter_name, local_var_name.

Names to Avoid

single character names except for counters or iterators

dashes (-) in any package/module name

__double_leading_and_trailing_underscore__ names (reserved by Python)

Naming Convention

"Internal" means internal to a module or protected or private within a class.

Prepending a single underscore (_) has some support for protecting module variables and functions (not included with import * from). Prepending a double underscore (__) to an instance variable or method effectively serves to make the variable or method private to its class (using name mangling).

Place related classes and top-level functions together in a module. Unlike Java, there is no need to limit yourself to one class per module.

Use CapWords for class names, but lower_with_under.py for module names. Although there are many existing modules named CapWords.py, this is now discouraged because it's confusing when the module happens to be named after a class. ("wait -- did I write import StringIO or from StringIO import StringIO?")

Guidelines derived from Guido's Recommendations

Type Public Internal

Packages lower_with_under

Modules lower_with_under _lower_with_under

Classes CapWords _CapWords

Exceptions CapWords

Functions lower_with_under() _lower_with_under()

Global/Class Constants CAPS_WITH_UNDER _CAPS_WITH_UNDER

Global/Class Variables lower_with_under _lower_with_under

Instance Variables lower_with_under _lower_with_under (protected) or __lower_with_under (private)

Method Names lower_with_under() _lower_with_under() (protected) or __lower_with_under() (private)

Function/Method Parameters lower_with_under

Local Variables lower_with_under

Main

+ Recent posts