quoting strings composed of digits
See original GitHub issueHi, Consider the following program:
import sys
import yaml
w = {'userName': 'scientist ', 'userEmail': 'wibble@example.com', 'sampleName': '08063075', 'fastqDir': '/foo/bar/baz/171108_M00139_0253_000000000-BHFD5/ProjectFolders/Project_Qux-Wombat-/Sample_08063075', 'analysis': 'Somatic_Run375_MY_DY_08112017', 'laneNo': 1, 'panel': 'Somatic_Panel_Manifest_v4_23_10_2015'}
yaml.dump(w, sys.stdout, default_flow_style=False)
The value for the key ‘sampleName’ is composed of digits, but is a string. When run the program produces the following output:
$ python quoting.py
analysis: Somatic_Run375_MY_DY_08112017
fastqDir: /foo/bar/baz/171108_M00139_0253_000000000-BHFD5/ProjectFolders/Project_Qux-Wombat-/Sample_08063075
laneNo: 1
panel: Somatic_Panel_Manifest_v4_23_10_2015
sampleName: 08063075
userEmail: wibble@example.com
userName: 'scientist '
This leads to problems downstream because the sequence of digits gets interpreted as an integer with the effect that when reserialized, the leading zero is lost.
Is this actually a bug? If not, how do I arrange for the value to be quoted?
Version information:
$ pip2 show pyyaml
Name: PyYAML
Version: 3.12
Summary: YAML parser and emitter for Python
Home-page: http://pyyaml.org/wiki/PyYAML
Author: Kirill Simonov
Author-email: xi@resolvent.net
License: MIT
Location: /Users/conwaythomas/Library/Python/2.7/lib/python/site-packages
Requires:
$ python --version
Python 2.7.10
$ uname -a
Darwin MA41192 16.7.0 Darwin Kernel Version 16.7.0: Wed Oct 4 00:17:00 PDT 2017; root:xnu-3789.71.6~1/RELEASE_X86_64 x86_64
Issue Analytics
- State:
- Created 6 years ago
- Reactions:10
- Comments:27 (8 by maintainers)
Top Results From Across the Web
JavaScript Strings: The Basic Methods and Functions
In JavaScript, Strings are values made up of text and can contain letters, numbers, symbols, punctuation, and even emojis!
Read more >Data Types and Variables : MGA - Web Development Tutorials
String data are composed of the lower-case alphabetic characters a - z, the upper-case characters A - Z, the numerals 0 - 9,...
Read more >hm02_ans.pdf - Programming Languages
The string of digits to the left of the decimal point may consist of a single zero (0). Otherwise, it must not start...
Read more >Strings in YAML - To Quote or not to Quote | tinita [blogs.perl.org]
You basically have five ways to express a string: Flow scalars (plain, single quoted, double quoted); Block Scalars (literal, folded). Table of ...
Read more >Tokens - IBM
A literal string is a sequence including any characters and delimited by the single quotation mark ( ' ) or the double quotation...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
+1 – I vote to fix this
Or should I say +“01”
@bxnxiong I forgot about this thread.
I’ve actually found a much nicer way to get around this. The answer was to stop using pyyaml. The below code snippets will work exactly like pyyaml, but with the YAML 1.2 spec, so you don’t have to mess with this stuff:
pip install ruamel.yaml
there’s no loads/load difference, it reads strings or file-like objects from the same function, but otherwise behaves almost identically aside from complying with the modern standard.