Skip to main content

a python library that convert string to code.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tocode-0.1.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

tocode-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file tocode-0.1.3.tar.gz.

File metadata

  • Download URL: tocode-0.1.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for tocode-0.1.3.tar.gz
Algorithm Hash digest
SHA256 571d4d2143afa07e1a68d8b9b60aeaacfaaa78b2439f90fcfba796a7e90f5ae3
MD5 535145380488de05847dc1f13bab5364
BLAKE2b-256 e331f78f2e3d48ce3bc56f51d48e7e448fb4d09add189432a0557f67a349f628

See more details on using hashes here.

File details

Details for the file tocode-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tocode-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for tocode-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24a7306718713884cda570ad736735ddf8fafa32ffaaa8f8f19083b302cf39b0
MD5 979b729d697e19f1e03ca6b7975cd43b
BLAKE2b-256 25f7ad891cd1976176ad099e4585a5da907ea78df2d851ee51835982022e58c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page