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使用jstl比较jsp中的日期对象   java JSF convertDateTime渲染前一天   java当重定向回另一个servlet时,如何显示错误消息?   当ulimit已更改为unlimit时,java无法增加Wildfly的“最大打开文件数”   Java和SWT:线程和侦听器   Java文件API跨网络复制文件   java如何使用闹钟。安卓系统中的动作\解除\警报   java无法将BLOB保存到数据库(ORA01460:未实现或不需要有意义的转换)   这个for循环的java复杂性   多行上的java正则表达式   spring mvc Java多URL模式,无扩展   java 安卓 json向文本添加超链接   Java泛型和转换   JavaSpringFramework。数据存储库。反应性。反应性积存。save()在从CompletableFuture调用时不持久化数据。运行异步   java ValidationException:调用TraversableResolver。isReachable()引发了异常   java将位图设置为具有特定高度的ImageView   Java:限制字符串中的字符   如何在java中将字节[]类型转换为证书类型?   javascript使用基于java的逻辑编写TinyMCE自定义插件