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 6074779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:25:13+00:00 2026-05-23T10:25:13+00:00

Is there a way where I’m able to generate the code in a file

  • 0

Is there a way where I’m able to generate the code in a file for a python data structure.

For example, if I had a dictionary, it would create a file with:
name_of_variable = { key: value, key:value}

and so on. The use for this is testing where I don’t want to manually code up a lot of data structures for my tests and I’d rather create some template structures where I can edit manually.

Thanks in advance.

  • 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-23T10:25:14+00:00Added an answer on May 23, 2026 at 10:25 am

    For simple data structures such dict, list, set and other built-in things you can use repr():

    >>> d = {'a': 2, 'b': 3, 'c': 4}
    >>> repr(d)
    "{'a': 2, 'c': 4, 'b': 3}"
    >>> l = range(10)
    >>> repr(l)
    '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'
    >>> s = set(range(10))
    >>> repr(s)
    'set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])'
    

    Documentation says: ”For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval()”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there way in next piece of code to only get the first record?
In PL/SQL Developer v7.1.x, is there way way to ignore large data types in
Is there any way to check whether a file is locked without using a
Is there way to attach client side SSL file (.pfx) file in WCF binding?
Is there way of creating empty .mo file? Usually when starting new project I
is there way to create a rule in the jquery validiation plugin that allows
Is there way to call an XSL template with optional parameters? For example: <xsl:call-template
Is there way in MySQL to create DATETIME from a given attribute of type
Is there way to configure the objects from inside the code rather than configuring
Is there way to overwrite the default values for internationalization? Example if I get

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.