Skip to main content

Changes values in tuples using ctypes

Project description

Changes values in tuples using ctypes

Important: Never use this in a real project! Hacked tuples might lead to unexpected results!

from tuplechanger import tuplechanger


tutu = ('babaxxiq',-2,3.44, True, 800,1211)
print(id(tutu))
print(tutu)
tuindex = 0
tuplechanger(tutu, tuindex, 'bbbbxxxi')
print(tutu)
tuindex = 1
tuplechanger(tutu, tuindex, -4)
print(tutu)
tuindex = 2
tuplechanger(tutu, tuindex, 13.44)
print(tutu)
tuindex = 3
tuplechanger(tutu, tuindex, False)
print(tutu)
tuindex = 4
tuplechanger(tutu, tuindex, 17000)
print(tutu)
tuindex = 5
tuplechanger(tutu, tuindex, 1111)
print(tutu)
print(id(tutu))
# 1843849020512
# ('babaxxiq', -2, 3.44, True, 800, 1211)
# ('bbbbxxxi', -2, 3.44, True, 800, 1211)
# ('bbbbxxxi', -4, 3.44, True, 800, 1211)
# ('bbbbxxxi', -4, 13.44, True, 800, 1211)
# ('bbbbxxxi', -4, 13.44, False, 800, 1211)
# ('bbbbxxxi', -4, 13.44, False, 17000, 1211)
# ('bbbbxxxi', -4, 13.44, False, 17000, 1111)
# 1843849020512

Why you shouldn't use it in a real project:

# It looks pretty good as first sight, but ... 
# tutu[0] + 'xxxx'
# Out[3]: 'bbbbxxxixxxx'
# tutu[1] + 5
# Out[4]: 1
# tutu[2] + 5.999
# Out[5]: 19.439
# tutu[3] is False
# Out[6]: True
# tutu[4] > 15000
# Out[7]: True
# tutu[5] < 1200
# Out[8]: True
# tutu[-1] < 1200
# Out[9]: True
# tutu[-2] < 15000
# Out[10]: True
# tutu[-3] is False
# Out[11]: True
# tutu[-4] + 5.999
# Out[12]: 19.439
# tutu[1] + 5
# Out[13]: 1

# ... it isn't a good idea to hack tuples:


# tutu[2] + tutu[4]   # positive index, everything is fine 
# Out[3]: 17013.44


# WRONG!!!
# tutu[-2] + tutu[-4] # negative index, crap
# Out[6]: 26.88

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

tuplechanger-0.10.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

tuplechanger-0.10-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file tuplechanger-0.10.tar.gz.

File metadata

  • Download URL: tuplechanger-0.10.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for tuplechanger-0.10.tar.gz
Algorithm Hash digest
SHA256 99a48d124c063d2fbe3eb1b01b9c4e031294a7d0910f05df7b2ae330ed4ffb97
MD5 a0acb34ce06200b7e8be4356fa40e944
BLAKE2b-256 6521dfdf4201f2558fe82988dcb16530b1eadbe763ab59cde05b1ccb4fd1a29b

See more details on using hashes here.

File details

Details for the file tuplechanger-0.10-py3-none-any.whl.

File metadata

  • Download URL: tuplechanger-0.10-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for tuplechanger-0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 579d71c986bf20679a851a55a0cefcea8e20484ddfa66d6512ef4e376160f1ed
MD5 78f60e87589e559dc675f1c16a09a9f5
BLAKE2b-256 64e4e930e04810faa06073bacad75df647c3d1e39804b5ab2bc4f93efaea6f52

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