Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:56:48+00:00 2026-05-29T08:56:48+00:00

The title is fairly self-explanatory. When I save a tuple to a YAML file,

  • 0

The title is fairly self-explanatory.

When I save a tuple to a YAML file, I get something that looks like this:

ambient:  !!python/tuple [0.3, 0.3 ,0.3]

When I try to load it with yaml.safe_load(file_object), I keep getting an error that reads:

yaml.constructor.ConstructorError:  could not determine a constructor for the tag 'tag:yaml.org,2002:python/tuple'

What needs to be done?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:56:49+00:00Added an answer on May 29, 2026 at 8:56 am

    In pyyaml, the SafeLoader does not include a loader for the python native types, only the types defined in the yaml spec. You can see the types for the SafeLoader and the Loader here in the interaction sample below.

    You can define a new Loader class that adds in the python tuple, but not other types, so it should still be pretty safe:

    import yaml
    
    class PrettySafeLoader(yaml.SafeLoader):
        def construct_python_tuple(self, node):
            return tuple(self.construct_sequence(node))
    
    PrettySafeLoader.add_constructor(
        u'tag:yaml.org,2002:python/tuple',
        PrettySafeLoader.construct_python_tuple)
    
    doc = yaml.dump(tuple("foo bar baaz".split()))
    print repr(doc)
    thing = yaml.load(doc, Loader=PrettySafeLoader)
    print thing
    

    resulting in:

    '!!python/tuple [foo, bar, baaz]\n'
    ('foo', 'bar', 'baaz')
    

    See below for the constructors associated with the SafeLoader and the Loader classes.

    >>> yaml.SafeLoader.yaml_constructors
    {None: <unbound method SafeConstructor.construct_undefined>,
     u'tag:yaml.org,2002:binary': <unbound method SafeConstructor.construct_yaml_binary>,
     u'tag:yaml.org,2002:bool': <unbound method SafeConstructor.construct_yaml_bool>,
     u'tag:yaml.org,2002:float': <unbound method SafeConstructor.construct_yaml_float>,
     u'tag:yaml.org,2002:int': <unbound method SafeConstructor.construct_yaml_int>,
     u'tag:yaml.org,2002:map': <unbound method SafeConstructor.construct_yaml_map>,
     u'tag:yaml.org,2002:null': <unbound method SafeConstructor.construct_yaml_null>,
     u'tag:yaml.org,2002:omap': <unbound method SafeConstructor.construct_yaml_omap>,
     u'tag:yaml.org,2002:pairs': <unbound method SafeConstructor.construct_yaml_pairs>,
     u'tag:yaml.org,2002:seq': <unbound method SafeConstructor.construct_yaml_seq>,
     u'tag:yaml.org,2002:set': <unbound method SafeConstructor.construct_yaml_set>,
     u'tag:yaml.org,2002:str': <unbound method SafeConstructor.construct_yaml_str>,
     u'tag:yaml.org,2002:timestamp': <unbound method SafeConstructor.construct_yaml_timestamp>}
    
    >>> yaml.Loader.yaml_constructors
    {None: <unbound method SafeConstructor.construct_undefined>,
     u'tag:yaml.org,2002:binary': <unbound method SafeConstructor.construct_yaml_binary>,
     u'tag:yaml.org,2002:bool': <unbound method SafeConstructor.construct_yaml_bool>,
     u'tag:yaml.org,2002:float': <unbound method SafeConstructor.construct_yaml_float>,
     u'tag:yaml.org,2002:int': <unbound method SafeConstructor.construct_yaml_int>,
     u'tag:yaml.org,2002:map': <unbound method SafeConstructor.construct_yaml_map>,
     u'tag:yaml.org,2002:null': <unbound method SafeConstructor.construct_yaml_null>,
     u'tag:yaml.org,2002:omap': <unbound method SafeConstructor.construct_yaml_omap>,
     u'tag:yaml.org,2002:pairs': <unbound method SafeConstructor.construct_yaml_pairs>,
     u'tag:yaml.org,2002:python/bool': <unbound method Constructor.construct_yaml_bool>,
     u'tag:yaml.org,2002:python/complex': <unbound method Constructor.construct_python_complex>,
     u'tag:yaml.org,2002:python/dict': <unbound method Constructor.construct_yaml_map>,
     u'tag:yaml.org,2002:python/float': <unbound method Constructor.construct_yaml_float>,
     u'tag:yaml.org,2002:python/int': <unbound method Constructor.construct_yaml_int>,
     u'tag:yaml.org,2002:python/list': <unbound method Constructor.construct_yaml_seq>,
     u'tag:yaml.org,2002:python/long': <unbound method Constructor.construct_python_long>,
     u'tag:yaml.org,2002:python/none': <unbound method Constructor.construct_yaml_null>,
     u'tag:yaml.org,2002:python/str': <unbound method Constructor.construct_python_str>,
     u'tag:yaml.org,2002:python/tuple': <unbound method Constructor.construct_python_tuple>,
     u'tag:yaml.org,2002:python/unicode': <unbound method Constructor.construct_python_unicode>,
     u'tag:yaml.org,2002:seq': <unbound method SafeConstructor.construct_yaml_seq>,
     u'tag:yaml.org,2002:set': <unbound method SafeConstructor.construct_yaml_set>,
     u'tag:yaml.org,2002:str': <unbound method SafeConstructor.construct_yaml_str>,
     u'tag:yaml.org,2002:timestamp': <unbound method SafeConstructor.construct_yaml_timestamp>}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title is fairly self-explanatory, but I'll reiterate: What would be a good variable
The title is fairly self explanatory. Whenever I do a build in Delphi 2010,
I thought this would be something that's fairly common - but cant find it
Title is fairly self-explanitory, I'm working on a Microsoft Surface application, and I don't
I'm fairly sure that's a useless title... sorry. I want to be able to
The following code is fairly self explanatory, but I am running in to an
I think this question may be fairly evident from the title alone: I am
Title is the entire question. Can someone give me a reason why this happens?
Title more or less says it all. Specifically, I've become increasingly annoyed that in
Judging from the title, I kinda did my program in a fairly complicated way.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.