版本:
System version : Windows 10 64-bit
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
list1=[1,2,4,3,1,2]
list1_remove_duplicate = sorted(set(list1),key=list1.index)
print(list1_remove_duplicate)
執行結果
[1, 2, 4, 3]
System version : Windows 10 64-bit
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
list1=[1,2,4,3,1,2]
list1_remove_duplicate = sorted(set(list1),key=list1.index)
print(list1_remove_duplicate)
[1, 2, 4, 3]
Exception: Cython-generated file 'statsmodels/tsa/kalmanf/kalman_loglike.c' not found.
Cython is required to compile statsmodels from a development branch.
Please install Cython or download a source release of statsmodels.
pip install statsmodels-0.8.0-cp36-cp36m-win_amd64.whl
System version : Windows 10,Ubuntu16.04
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Django version : 1.11.2
◢ project_name
◢ app_name
◢ templates
◢ app_name
page1.html
404.html
urls.py
views.py
◢ project_name
settings.py
urls.py
views.py
◢ static
◢ css
◢ js
◢ image
favicon.png
manage.py
project_name/project_name/settings.py
# DEBUG = True
DEBUG = False
STATIC_URL = '/static/'
if DEBUG is False:
STATIC_ROOT = (
os.path.join(BASE_DIR, 'static')
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
project_name/project_name/urls.py
from django.views.static import serve
from . import settings
if settings.DEBUG is False:
urlpatterns.append(url(r'^static/(?P<path>.*)$', serve, {'document_root': settings.STATIC_ROOT}))
System version : Windows 10,Ubuntu16.04
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Django version : 1.11.2
◢ project_name
◢ app_name
◢ templates
◢ app_name
page1.html
404.html
urls.py
views.py
◢ project_name
settings.py
urls.py
views.py
◢ static
◢ css
◢ js
◢ image
favicon.png
manage.py
project_name/project_name/urls.py
handler404 = views.error_404
handler500 = views.error_404
project_name/project_name/views.py
from django.shortcuts import render
def error_404(request):
return render(request, 'app_name/404.html')
project_name/project_name/settings.py
# DEBUG = True
DEBUG = False
System version : Windows 10,Ubuntu16.04
Python version : Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
Django version : 1.11.2
◢ project_name
◢ app_name
◢ templates
◢ app_name
page1.html
404.html
urls.py
views.py
◢ project_name
settings.py
urls.py
views.py
◢ static
◢ css
◢ js
◢ image
favicon.png
manage.py
project_name/app_name/templates/app_name/page1.html
{% load staticfiles %}
<head>
<title>...</title>
<link href="{% static 'image/favicon.png' %}" rel="shortcut icon"></link>
</head>
Python version :Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
System version :Windows 10
import xmltodict, json
xml_str = '<root><rule>a</rule><right>1</right></root>'
order_dict_tmp = xmltodict.parse(xml_str)
dict_temp = json.loads(json.dumps(order_dict_tmp))
print( xml_str )
print('-'*35)
print( order_dict_tmp )
print( type(order_dict_tmp) )
print('-'*35)
print( dict_temp )
print( type(dict_temp) )
Python version :Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
System version :Windows 10
# dict to xml
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import tostring
def dict_to_xml(tag, d):
ele = Element(tag)
for key, val in d.items():
child = Element('key',{'name':key})
child.text = str(val)
ele.append(child)
return ele
dic1 = {'a':5,'123b':22,'c':'str1'}
print(dic1)
print('-'*85)
xml_str = tostring(dict_to_xml('score', dic1) )
xml_str2 = xml_str.decode()
print(xml_str2)
print('='*85)
xml_str = tostring(dict_to_xml('score', dic1), encoding='utf8', method='xml')
xml_str2 = xml_str.decode()
print(xml_str2)
list1 = ['a'+str(x) for x in range(7)]
print(list1)
print('='*40)
list2=[]
for a in range(2):
list2=list2+list1
print(list2)
print('='*40)
num = 3
for a in range(0,len(list2),num):
print(list2[a:a+num])
['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6']
========================================
['a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6']
========================================
['a0', 'a1', 'a2']
['a3', 'a4', 'a5']
['a6', 'a0', 'a1']
['a2', 'a3', 'a4']
['a5', 'a6']
str1 = '背景,0,特性,1,元件,3'
list1 = str1.split(",")
dic1 = {list1[i]: list1[i+1] for i in range(0, len(list1), 2)}
print(list1)
print(dic1)
['背景', '0', '特性', '1', '元件', '3']
{'背景': '0', '特性': '1', '元件': '3'}
from pprint
import pprint
dic1 ={'name':'Dondonaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'number':9527,'item':['a','b','a','b','a','b','a','b','a','b','a','b','a','b','a','b']}
print(dic1)
print('='*30)
pprint(dic1)
import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
from datetime import datetime,timedelta
string_date = '20170727'
# Convert String to datetime object - 字串轉日期
datetime_date = datetime.strptime(string_date, "%Y%m%d").date()
# 日期的加減法
date_sub_1 = datetime_date - timedelta(1)
# Convert datetime to String - 日期轉字串
date_sub_1_string = date_sub_1.strftime("%Y-%m-%d")
print('datetime_date :',datetime_date,'\t,type :',type(datetime_date))
print('date_sub_1 :',date_sub_1,'\t,type :',type(date_sub_1))
print('date_sub_1_string :',date_sub_1_string,'\t,type :',type(date_sub_1_string))
datetime_date : 2017-07-27 ,type : <class 'datetime.date'>
date_sub_1 : 2017-07-26 ,type : <class 'datetime.date'>
date_sub_1_string : 2017-07-26 ,type : <class 'str'>
list1 = ['A','B','C']
dic1 = {k:v for k,v in enumerate(list1)}
dic1
{0: 'A', 1: 'B', 2: 'C'}