Skip to main content

Simple tools to quickly get the names of multiple variables out of the lines of code where they are defined.

Project description

This package contains the function 'canederlist'

i.e.

Comma
And
NEwline
Delimited
Elements
Reformatted as
LIst of
STrings

which allows to reformat a multiline string containing words separated by commas into a list of strings.

This is useful when we have hardcoded a list of variables and we want to quickly get a list of their names as strings.

canederlist spares us from copypasting

print(var1, var2, ..., var100)

and manually add quotes around each variable, like this

print("var1", "var2", ..., "var100")

usage

The list of variables (i.e. not the variable containing the list, the hardcoded list of variables) must be copied and pasted as argument of canederlist(), enclosed in triple quotes (""").

The function canederlist will remove

  • multiple spaces (double or more, but not single spaces)
  • newline characters
  • triple points ...
  • (if selected in the input) round () and square [] parentheses
  • (if selected in the input) single spaces and split the remaining elements separated by commas into a list of strings.

example

from canederli import canederlist
columns = [ names, 
            descriptions, 
            x_coordinates, 
            y_coordinates ]

columns_labels = canederlist("""
 names, 
            descriptions, 
            x_coordinates, 
            y_coordinates 
""")

print(columns_labels)
print(columns)
['names', 'descriptions', 'x_coordinates', 'y_coordinates']
...

example removing parentheses


from canederli import canederlist
columns = [ names, 
            descriptions, 
            x_coordinates, 
            y_coordinates ]

columns_labels = canederlist("""
 names, 
            descriptions, 
            x_coordinates, 
            y_coordinates ]
""",1)  # <--- this is the same as setting optional parameter rm_parentheses=True

print(columns_labels)
print(columns)
['names', 'descriptions', 'x_coordinates', 'y_coordinates']
...

long case example

var_1 = 42
var_2 = "Hello, world!"
var_3 = 3.14
var_4 = [1, 2, 3]
var_5 = {"name": "Mario", "age": 30}
var_6 = True
var_7 = (10, 20, 30)
var_8 = None
var_9 = 5.67
var_10 = "Python is fantastic!"
var_11 = [5, 10, 15]
var_12 = {"language": "Python", "level": "advanced"}
var_13 = False
var_14 = (1.5, 2.5, 3.5)
var_15 = "OpenAI is doing great things!"
var_16 = 12345
var_17 = "This is a test."
var_18 = [True, False]
var_19 = {"color": "blue", "shape": "circle"}
var_20 = 7.89
var_21 = ["a", "b", "c"]
var_22 = (100, 200, 300)
var_23 = 987654321
var_24 = "This is another string."
var_25 = {"animal": "cat", "age": 5}
var_26 = None
var_27 = 2.71828
var_28 = [7, 14, 21]
var_29 = "Python makes everything simpler!"
var_30 = ("x", "y", "z")
var_31 = True
var_32 = {"name": "Alice", "city": "Rome"}
var_33 = 4.567
var_34 = 111
var_35 = "I'm learning a lot with OpenAI!"
var_36 = [3.5, 7.2, 10.9]
var_37 = ("pen", "pencil", "eraser")
var_38 = False
var_39 = {"fruit": "apple", "color": "red"}
var_40 = 9.81
var_41 = ["alpha", "beta", "gamma"]
var_42 = (42, 84, 126)
var_43 = 55555
var_44 = "This sentence has five words."
var_45 = {"instrument": "guitar", "type": "acoustic"}
var_46 = None
var_47 = 3.14159
var_48 = [2, 4, 6]
var_49 = "Python is powerful and efficient!"
var_50 = ("one", "two", "three")
var_51 = True
var_52 = {"name": "Luca", "language": "Italian"}
var_53 = 2.345
var_54 = 987
var_55 = "OpenAI is changing the game!"
var_56 = [1.1, 2.2, 3.3]
var_57 = ("a", "b", "c")
var_58 = False
var_59 = {"element": "gold", "atomic number": 79}
var_60 = 6.626e-34
var_61 = ["plane", "train", "car"]
var_62 = (50, 100, 150)
var_63 = 777777
var_64 = "Knowledge is power."
var_65 = {"profession": "doctor", "specialty": "surgery"}
var_66 = None
var_67 = 9.12345
var_68 = [8, 16, 24]
var_69 = "GPT-3.5 is amazing!"
var_70 = ("one", "two", "three")
var_71 = True
var_72 = {"name": "Laura", "age": 25}
var_73 = 1.2345
var_74 = 654
var_75 = "Python opens new possibilities!"
var_76 = [4.4, 5.5, 6.6]
var_77 = ("A", "B", "C")
var_78 = False
var_79 = {"color": "green", "plant": "tree"}
var_80 = 299792458
var_81 = ["Monday", "Tuesday", "Wednesday"]
var_82 = (70, 140, 210)
var_83 = 333333
var_84 = "This is just an example."
var_85 = {"instrument": "piano", "type": "digital"}
var_86 = None
var_87 = 7.77777
var_88 = [6, 12, 18]
var_89 = "Python makes everything more interesting!"
var_90 = ("A", "B", "C")
var_91 = True
var_92 = {"name": "Mark", "language": "Spanish"}
var_93 = 8.765
var_94 = 123
var_95 = "OpenAI is transforming technologies!"
var_96 = [7.7, 8.8, 9.9]
var_97 = ("one", "two", "three")
var_98 = False
var_99 = {"city": "Paris", "country": "France"}
var_100 = 42.195

print(canederlist(""" var_78,
var_79,
var_80,
var_81,
var_82,
var_83,
var_84,
var_85,
var_86,
var_87,
var_88,
var_89,
var_90,
var_91,
var_92,
var_93,
var_94
"""))

print([
    var_78,
    var_79,
    var_80,
    var_81,
    var_82,
    var_83,
    var_84,
    var_85,
    var_86,
    var_87,
    var_88,
    var_89,
    var_90,
    var_91,
    var_92,
    var_93,
    var_94
])

['var_78', 'var_79', 'var_80', 'var_81', 'var_82', 'var_83', 'var_84', 'var_85', 'var_86', 'var_87', 'var_88', 'var_89', 'var_90', 'var_91', 'var_92', 'var_93', 'var_94']

[False, {'color': 'green', 'plant': 'tree'}, 299792458, ['Monday', 'Tuesday', 'Wednesday'], (70, 140, 210), 333333, 'This is just an example.', {'instrument': 'piano', 'type': 'digital'}, None, 7.77777, [6, 12, 18], 'Python makes everything more interesting!', ('A', 'B', 'C'), True, {'name': 'Mark', 'language': 'Spanish'}, 8.765, 123]

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

canederli-0.0.14.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

canederli-0.0.14-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file canederli-0.0.14.tar.gz.

File metadata

  • Download URL: canederli-0.0.14.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for canederli-0.0.14.tar.gz
Algorithm Hash digest
SHA256 3125be5bd0c09b660b7c41fd94c94f157abc54b4403b34ae5b6b15df07fc57b2
MD5 48dbc2a182dd2b2c6b21bdef092954ee
BLAKE2b-256 c6421db3abfda8ea26a9ea460669537d5fd8443cdd59b46f8a67f9726f31cac1

See more details on using hashes here.

File details

Details for the file canederli-0.0.14-py3-none-any.whl.

File metadata

  • Download URL: canederli-0.0.14-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12

File hashes

Hashes for canederli-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 8897734787bff7cd39e38317ce1e1716fb8878ad21535225c918e0031e8ec80e
MD5 c814725652912b876c4c9e474c705694
BLAKE2b-256 48a8f0e16e9b555029d161bc97ba3cabbfeca59e9d65da487eb7bd4df5628a87

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