# namedtuple from dict / valid identifier from string
```python
# Tested with:
# Python 3.9.13
# Windows 10
pip install namedtuple-from-dict
from namedtuple_from_dict import create_valid_identifier, dict_to_namedtuple
from string import printable
from random import choices, randrange
# startwith will be added if the original string starts with a number
# 9times6 -> aa_9times6
testdict = {
1: "hallo",
"n k q": 223,
(1, 2, 4): {222, 333},
"validkey1": "test",
"validkey2": "tes1t",
"notvalidkey!1": "tes1t",
}
testtuple = dict_to_namedtuple(dic=testdict, name="testdata", startwith="aa_")
print(testtuple)
for i in range(10):
randomchars = "".join(choices(printable, k=randrange(3, 10)))
varname = create_valid_identifier(randomchars, startwith="aa_")
print(f"{randomchars=}")
print(f"{varname=}")
# testdata(aa_1='hallo', n_k_q=223, aa_1_2_4={333, 222}, validkey1='test', validkey2='tes1t', notvalidkey_1='tes1t')
# randomchars=':ga(F'
# varname='ga_F'
# randomchars='lh[)iN>A/'
# varname='lh_iN_A'
# randomchars='fI&mE)'
# varname='fI_mE'
# randomchars='//YW'
# varname='YW'
# randomchars='aY\x0c'
# varname='aY'
# randomchars='k|\ts \x0b'
# varname='k_s'
# randomchars='!kGhJ`'
# varname='kGhJ'
# randomchars='8u*s'
# varname='aa_8u_s'
# randomchars='\\z;_cP'
# varname='z__cP'
# randomchars='e)=Qb\t7p'
# varname='e_Qb_7p'
```
Raw data
{
"_id": null,
"home_page": "https://github.com/hansalemaos/namedtuple_from_dict",
"name": "namedtuple-from-dict",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "namedtuple,dict,identifier",
"author": "Johannes Fischer",
"author_email": "<aulasparticularesdealemaosp@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/17/f1/6420f251666fb7a7ea74fb66acb7065191b9f49aec9afa05f0066e9c96a3/namedtuple_from_dict-0.10.tar.gz",
"platform": null,
"description": "\n# namedtuple from dict / valid identifier from string \n\n\n```python\n# Tested with:\n# Python 3.9.13\n# Windows 10\n\npip install namedtuple-from-dict\n\nfrom namedtuple_from_dict import create_valid_identifier, dict_to_namedtuple\n\nfrom string import printable\nfrom random import choices, randrange\n\n# startwith will be added if the original string starts with a number\n# 9times6 -> aa_9times6\n\ntestdict = {\n 1: \"hallo\",\n \"n k q\": 223,\n (1, 2, 4): {222, 333},\n \"validkey1\": \"test\",\n \"validkey2\": \"tes1t\",\n \"notvalidkey!1\": \"tes1t\",\n}\n\ntesttuple = dict_to_namedtuple(dic=testdict, name=\"testdata\", startwith=\"aa_\")\n\nprint(testtuple)\nfor i in range(10):\n randomchars = \"\".join(choices(printable, k=randrange(3, 10)))\n varname = create_valid_identifier(randomchars, startwith=\"aa_\")\n print(f\"{randomchars=}\")\n print(f\"{varname=}\")\n\n\n# testdata(aa_1='hallo', n_k_q=223, aa_1_2_4={333, 222}, validkey1='test', validkey2='tes1t', notvalidkey_1='tes1t')\n# randomchars=':ga(F'\n# varname='ga_F'\n# randomchars='lh[)iN>A/'\n# varname='lh_iN_A'\n# randomchars='fI&mE)'\n# varname='fI_mE'\n# randomchars='//YW'\n# varname='YW'\n# randomchars='aY\\x0c'\n# varname='aY'\n# randomchars='k|\\ts \\x0b'\n# varname='k_s'\n# randomchars='!kGhJ`'\n# varname='kGhJ'\n# randomchars='8u*s'\n# varname='aa_8u_s'\n# randomchars='\\\\z;_cP'\n# varname='z__cP'\n# randomchars='e)=Qb\\t7p'\n# varname='e_Qb_7p'\n\n\t\n```\n\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "namedtuple from dict / valid identifier from string",
"version": "0.10",
"split_keywords": [
"namedtuple",
"dict",
"identifier"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "146c8960080071e75fac40f8327b5f93d025bf109db8b01fd6378b80611e7bb0",
"md5": "be43ac152506907d18cade5709683b7e",
"sha256": "0fc67e685acddae8d2533a93e6652cfb82f4428b58e95c8b1edff373bc73724c"
},
"downloads": -1,
"filename": "namedtuple_from_dict-0.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "be43ac152506907d18cade5709683b7e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5410,
"upload_time": "2023-01-04T00:27:03",
"upload_time_iso_8601": "2023-01-04T00:27:03.327356Z",
"url": "https://files.pythonhosted.org/packages/14/6c/8960080071e75fac40f8327b5f93d025bf109db8b01fd6378b80611e7bb0/namedtuple_from_dict-0.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "17f16420f251666fb7a7ea74fb66acb7065191b9f49aec9afa05f0066e9c96a3",
"md5": "d177d32834702b9774e70d5c695a5ff9",
"sha256": "cfa3c0073e7ef58786df4692b829d12ac9f459b2eeb7bcd9600c90c592cf064d"
},
"downloads": -1,
"filename": "namedtuple_from_dict-0.10.tar.gz",
"has_sig": false,
"md5_digest": "d177d32834702b9774e70d5c695a5ff9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3766,
"upload_time": "2023-01-04T00:27:04",
"upload_time_iso_8601": "2023-01-04T00:27:04.950134Z",
"url": "https://files.pythonhosted.org/packages/17/f1/6420f251666fb7a7ea74fb66acb7065191b9f49aec9afa05f0066e9c96a3/namedtuple_from_dict-0.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-04 00:27:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "hansalemaos",
"github_project": "namedtuple_from_dict",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "namedtuple-from-dict"
}