Django 타임존 설정

python 2014. 7. 30. 16:33
반응형

Django 타임존 설정


환경  : ubuntu 14.04.1 LTS , Django 1.6.5 , python 2.7.6




해당 project 폴더의 settings.py 내부 TIME_ZONE 항목을 아래와 같이 수정한다.


TIME_ZONE = 'Asia/Seoul'




타임존 참고 사이트http://en.wikipedia.org/wiki/List_of_tz_database_time_zones



반응형
Posted by 자유프로그램
,
반응형

장고처럼 instance 생성시 class 변수에 값 설정하기.



장고 예 : https://docs.djangoproject.com/en/1.6/intro/overview/#design-your-model


from django.db import models

class Reporter(models.Model):
    full_name = models.CharField(max_length=70)   # class 변수

    # On Python 3: def __str__(self):
    def __unicode__(self):
        return self.full_name

class Article(models.Model):
    pub_date = models.DateField()
    headline = models.CharField(max_length=200)
    content = models.TextField()
    reporter = models.ForeignKey(Reporter)

    # On Python 3: def __str__(self):
    def __unicode__(self):
        return self.headline


>>> from news.models import Reporter, Article # Create a new Reporter. >>> r = Reporter(full_name='John Smith') # 요거 흉내내기...



** 부모 class (Test) 의 생성자 (__init__) 내부에서 클래스변수 존재여부 확인후, 존재하면 값 설정한다.

     주의 : 인스턴스변수가 없으면 클래스변수에서 찾는다

             (아래의 경우, self.student_name 가  instance 변수에 없으므로 class 변수 student_name 를 찾는다.)

class Test:
    def __init__(self,**name):
        for k , v in name.items():
            # print repr(k), repr(v)
            try:
                getattr(self, k)  # check if variable exist
            except Exception as excp:
                print excp
                pass   # pass if variable not exist
            else:
                setattr(self,k,v)   # 인스턴스변수 없으면 클래스변수에 값 설정함.
                print 'new val : self.' + k + ' = ',  getattr(self,k)
 
    def __str__(self):
        pass
         
    def __unicode__(self):
        pass
 
    def save(self):
        print 'save.. data'
        pass
 
 
class NewTest(Test):
    student_name =''   # 데이터 입력할 class 변수...
    def __str__(self):
        return "my student name == " + self.student_name



 
>>> tt = Test(name = 'AA', name2 = 'BB', name3 = 'CC')
Test instance has no attribute 'name2'
Test instance has no attribute 'name3'
Test instance has no attribute 'name'
>>> 
>>> tt3 = NewTest(student_name = 'YY')     ##  ... 성공...
new val : self.student_name =  YY
>>> 
>>> tt2 = NewTest(name = 'KKK')
NewTest instance has no attribute 'name'
>>> 







*** 추가 참고 

      http://blog.kevinastone.com/django-model-descriptors.html








반응형
Posted by 자유프로그램
,
반응형

terminal (interactive) 입력여부인지 확인하기


환경 : windows 7 32bit, python 2.7.8

         ubuntu 12.04 LTS, python 2.7.3



참조 : http://stackoverflow.com/a/1285045

         http://stackoverflow.com/a/699446


         http://www.popmartian.com/tipsntricks/2011/07/25/how-to-detect-stdin-with-python/



** windows IDLE 환경.




** Ubuntu 12.04 LTS, terminal 환경.
















반응형
Posted by 자유프로그램
,
반응형

windows  --  console 키보드 입출력



참조 : https://docs.python.org/2/library/msvcrt.html

import msvcrt
import time

while 1:
    if msvcrt.kbhit():
        c = msvcrt.getwch()
        if c == u'\x1b':  # ESC key  -> exit
            print '\n -- exit ---\n'
            time.sleep(1) 
            break
        if c == u'\00' or c == u'\xe0':  # function key
            msvcrt.getwch() # skip function keycode 
        else :
            msvcrt.putwch(c)








반응형
Posted by 자유프로그램
,
반응형

windows 7 에서 pyPdf 모듈 설치하기


환경 : windows 7 64bit , python 2.7.8, pyPdf 1.13


pyPdf 사이트 :  http://pybrary.net/pyPdf/

                  ---> 여기에서  pyPdf-1.13.zip  파일을 다운받는다.


command 창에서

       python setup.py install 

입력하면 설치 완료됨....







** 설치 완료 테스트  (IDLE 에서)


>>> from pyPdf import PdfFileWriter, PdfFileReader

>>> 


로 나오면 성공!!!



반응형
Posted by 자유프로그램
,