python包提供对woudc扩展csv格式的读/写支持。

woudc-extcsv的Python项目详细描述


Build StatusBuild statusDownloads this month on PyPILatest releaseLicense

woudc扩展csv库

python包提供对 WOUDC扩展csv格式。

安装

要求

woudc extcsv需要python 2.7、pywoudc和unicodecsv。

依赖性

requirements.txt

安装软件包

# via pip
pip install woudc-extcsv
# via easy_install
easy_install woudc-extcsv

用法

读卡器对象

fromwoudc_extcsvimportReader# read from filewithopen('file.csv','rb')asff:ecsv=Reader(ff.read(),encoding='utf-8')# read from stringecsv=Reader(my_ecsv_string)

writer对象

importwoudc_extcsv# create new writer object with common/metadata tables and fields availableecsv=woudc_extcsv.Writer(template=True)# Add file commentsecsv.add_comment('This is a file level comment.')ecsv.add_comment('This is another file level comment.')# Add metadataecsv.add_data('CONTENT','WOUDC,Spectral,1.0,1')ecsv.add_data('DATA_GENERATION','2002-05-29,JMA,1.0')ecsv.add_data('PLATFORM','STN,7,Kagoshima,JPN,47827')ecsv.add_data('INSTRUMENT','Brewer,MKII,059')ecsv.add_data('LOCATION','31.63,130.6,283')# Add new tableecsv.add_table('TIMESTAMP')# Add fieldsecsv.add_field('TIMESTAMP','UTCOffset,Date,Time')# Add dataecsv.add_data('TIMESTAMP','+08:38:47',field='UTCOffset')# Add more dataecsv.add_data('TIMESTAMP','1991-01-01',field='Date')ecsv.add_data('TIMESTAMP','06:38:47',field='Time')# Add new table, fields, and data at the same timeecsv.add_data('GLOBAL_SUMMARY','06:38:47,7.117E-04,8.980E-03,94.12,99.99,114.64,001000,999',field='Time,IntACGIH,IntCIE,ZenAngle,MuValue,AzimAngle,Flag,TempC')ecsv.add_data('GLOBAL','290.0,0.000E+00',field='Wavelength,S-Irradiance,Time')ecsv.add_data('GLOBAL','290.5,0.000E+00')ecsv.add_data('GLOBAL','291.0,0.000E+00')# Add table for new groupingsecsv.add_data('TIMESTAMP','+08:38:46,1991-01-01,07:38:46',field='UTCOffset,Date,Time',index=2)ecsv.add_data('GLOBAL_SUMMARY','07:38:46,2.376E-02,3.984E-01,82.92,6.75,122.69,100000,999',field='Time,IntACGIH,IntCIE,ZenAngle,MuValue,AzimAngle,Flag,TempC',index=2,table_comment='This is a table level comment.')# Write to stringecsvs=woudc_extcsv.dumps(ecsv)# Write to file# validate (check if all common tables and their fields are present), if so dump to file# if not, print violationswoudc_extcsv.dump(ecsv,'spectral-sample.csv')

便利功能

importwoudc_extcsv# load from file into Reader objectecsv=woudc_extcsv.load('file.csv')# load from string into Reader objectecsv=woudc_extcsv.loads(my_ecsv_string)# dump to file from Writer objectecsv=woudc_extcsv.dump('file.csv')# dump to string from Writer objectecsv=woudc_extcsv.dumps(my_ecsv_string)

错误处理

from woudc_extcsv import loads, WOUDCExtCSVReaderError

try:
    loads('bad content!')
except WOUDCExtCSVReaderError as err:
    print(err.message)
    for error in err.errors:
         print(error)

示例

有关示例脚本,请参见examples/目录。

开发

对于开发环境,请安装 在Python中virtualenv

virtualenv foo
cd foo
. bin/activate
# fork master# fork https://github.com/woudc/woudc-extcsv on GitHub# clone your fork to create a branch
git clone https://github.com/{your GitHub username}/woudc-extcsv.git
cd woudc-extcsv
# install dev packages
pip install -r requirements-dev.txt
# create upstream remote
git remote add upstream https://github.com/woudc/woudc-extcsv.git
git pull upstream master
git branch my-cool-feature
git checkout my-cool-feature
# start dev
git commit -m 'implement cool feature'# push to your fork
git push origin my-cool-feature
# issue Pull Request on GitHub
git checkout master
# cleanup/update once your branch is merged on GitHub# remove branch
git branch -D my-cool-feature
# update your fork
git pull upstream master
git push origin master

运行测试

# via distutils
python setup.py test# manually
python run_tests.py
# report test coverage
coverage run --source woudc_extcsv setup.py test
coverage report -m

代码约定

extcsv代码约定是否符合 PEP8

# code should always pass the following
find -type f -name "*.py"| xargs flake8

问题

所有错误、增强和问题都在 GitHub

历史记录

woudc extcsv的根源于woudc后端处理系统 支持处理数据提交。woudc extcsv被重构 提供数据中心的读/写支持的独立库 核心接收格式。

2015年,为支持财政部,向公众提供了woudc extcsv。 董事会[关于可接受的网络和设备使用的政策] (http://www.tbs-sct.gc.ca/pol/doc-eng.aspx?id=27122)。

联系人

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java访问私有字段而不使用getter方法?   使用PowerMockito在JavaEWSAPI中模拟测试拉订阅   启动活动时未保存java首选项并清除变量   java如何在servlet中检索子域?斯普林有帮手吗   java使用Docker从命令行构建Android项目   java Android,ActionBar后退按钮(setDisplayHomeAsUpEnabled(true))重新创建父活动   java在重用FileOutputStream时应该关闭流吗?   java使用RESTAPI将文件上载到s3 bucket   Java SOAP Web服务应用程序中的mysql用户登录方法不工作   java使用多个数字计算百分比并转换为长   java Android SQLiteDatabase查询忽略空格   java如何在Javafx中比较两个字段文本   java错误:未设置java_HOME,在Eclipse安装后找不到   java在安卓中保存对象   java如何使用jaxws从返回List<Object>的服务中检索值   java Google OAuth2 JWT令牌验证异常   SpringMVC中的JavaUTF8编码问题,当从JSP表单发送POST请求中的越南语信件时   java从webview重定向到安卓应用程序   JUnit 5中多个扩展的java顺序