Skip to main content

tocode

Python version BSD Licence Project Initiator Repo Size Downloads PyPI version shields.io GitHub Workflow Status

This is a library that can convert the strings to code and return the literal eval of that, it will convert strings which contain:

  • lists
  • tuples
  • dictionaries
  • sets into the python eval.

Overview

The most important thing in this library that make it unique is:
if your strings don't have any quotation no worries it will add quotations for you!

example

before:

! "{'this': 5, (Alex, Daniel): are good boys, (5, 4): 8.5}" 

after:

+ "{'this': 5, ('Alex', 'Daniel'): 'are good boys', (5, 4): 8.5}

Usage

In the following paragraphs, I am going to describe how you can get and use tocode for your own projects.

Getting it

To download tocode library, either fork this github repo or simply use Pypi via pip.

$ pip install tocode

Using it

tocode was programmed with ease-of-use in mind. First, import literal_eval from tocode.

for more exact usage documents you can see the example files here

import tocode

# Example:
my_array = " ['Hello', Goodbye my friend, 2.5, (4, ok), {one: 450, 'two': 12}] "
my_array = tocode.literal_eval(my_array, no_string_quotation=True)
"""
  if some of the strings don't have quotation set `no_string_quotation` to True
  otherwise, set it to False or leave it.
"""
# will return the list into a python list

output:

['Hello', 'Goodbye my friend', 2.5, (4, 'ok'), {'one': 450, 'two': 12}]

Support

Supported versions of python for this library are as follow:

License

This project is under BST license read it here:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Release files for tocode 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tocode 0.1.3
File Size Uploaded
tocode-0.1.3.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tocode 0.1.3
File Interpreter ABI Platform
tocode-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / tocode-0.1.3.tar.gz

Download URL tocode-0.1.3.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
571d4d2143afa07e1a68d8b9b60aeaacfaaa78b2439f90fcfba796a7e90f5ae3
BLAKE2b-256 checksum
How to use checksums
e331f78f2e3d48ce3bc56f51d48e7e448fb4d09add189432a0557f67a349f628
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release files / tocode-0.1.3-py3-none-any.whl

Download URL tocode-0.1.3-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24a7306718713884cda570ad736735ddf8fafa32ffaaa8f8f19083b302cf39b0
BLAKE2b-256 checksum
How to use checksums
25f7ad891cd1976176ad099e4585a5da907ea78df2d851ee51835982022e58c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page