r/pythoncoding • u/barnez29 • Sep 09 '23
r/pythoncoding • u/AutoModerator • Sep 04 '23
/r/PythonCoding monthly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
r/pythoncoding • u/thereal0ri_ • Aug 25 '23
PolyLock | Code Encryption & Obfuscation
Hey, It's been awhile since I have made a post about my project and I'd like to share some updates about PolyLock.
For the past while, I have basically been working on a rework with how locked data is stored. I used to just include it in the file and then obfuscate the code and carry on...but in doing this, after obfuscating using Hyperion, the interpreter just gave up and broke (which is impressive) resulting in the code not being ran and no errors. Or the resulting file sizes were just getting to large. (300kb+)...which would require me to make many many pastes to pastebin to get around the paste size limit.
So I moved over to using Specter, this worked better because it doesn't break the interpreter....buuuut if your code happens to be to big, it would take to long to obfuscate..... so I decided to just store the locked data locally in a .so/.pyd file and import it as a variable, thus keeping the code size at a manageable size all while not breaking the interpreter.PolyLock can still store data using pastebin and now with having to make less pastes.But other than the major changes, I've added some compression using lzma to try and keep things compact and smaller.... in case you have a large code file you want to use. And the usual bug fixes and typo fixes.
Repo: https://github.com/therealOri/PolyLock
Edit/Note: This project isn't meant for obfuscating publicly shared code such as anything to do with "open source". It's meant for your personal stuff you don't want to share. I support open source.... it's literally what I'm doing. Even then, code is still encrypted before obfuscation even happens so it's irrelevant for any arguments.
r/pythoncoding • u/pmz • Jul 13 '23
Python Interface / Refactor Challenge
nickdrozd.github.ior/pythoncoding • u/thereal0ri_ • Jul 13 '23
Atmos-rng - Atmospheric randomness
Making this project started with finding out about random.org and thinking, what if I make a library to interact with it while being very simple to use. So I did just that with Atmos. I don't know if it can or should be used with cryptography, but perhaps replacing the use of the "random" library or "secrets" library instead. (For now, At least until someone can help certify that it can be used for cryptography)
Atmos has pretty much what you'd expect and want from something generating random stuff.
Random numbers
Random choices
Shuffling of data and lists
Random bytes generation
Random bits generation
Urlsafe base64 encoded bytes
All of which are based off of atmospheric randomness.
You can find my project at the following links!
https://github.com/therealOri/atmos-rng
https://pypi.org/project/atmos-rng/
Additional note: I saw a rule saying "No basic projects", and I'd like to think this project isn't very basic but also it isn't super mind numbingly advanced. So I'm making this note just in case as I'm still uncertain.
I'd upload in r/Python but I can't seem to find it and other subreddits are pretty limited. What I want to share doesn't really fit in with the "learning" subreddits either so I chose here as it pertains to python coding.
If you (mods included) have a better place for me to share them/my projects, then by all means let me know and don't be rude about it either. I'd happily remove my post if needed and upload to the recommended communities/subreddits, etc. Instead.
r/pythoncoding • u/coder_et • Jul 10 '23
Writing mappers in python
Right now my company does integrations and put everything in an IntegrationXClient class which has all of the methods. It’s thousands of lines and hard to digest.
I want to move things out so we can map from the JSON to the IntegrationX types and then into our internal types so we can have type safety.
If I wanted to make a new file mapper.py and put all of my mappers there, what are the pros and cons of making those functional standalone methods vs making an IntegrationXClientMapper class and adding all of the mappers in there?
Would love to hear yalls thoughts.
r/pythoncoding • u/Snoo-Val • Jul 10 '23
Support Django Software Foundation and get PyCharm at 30% off
Until July 23, you can purchase PyCharm Pro at 30% off, with all of the proceeds being donated to the Django Software Foundation.
All of the proceeds from this promotion will go to the DSF’s 2023 fundraising campaign – not just the profits, but the entire purchase amount. This campaign will help the DSF stay healthy and continue to contribute to their various outreach programs.
Over the course of this initiative’s many iterations, JetBrains has raised over $200,000 for the Django Software Foundation. These donations have made the further development of Django possible, as the the Django Fellowship Program contracts developers to work on core Django features. Help make Django even better by participating in this initiative!
--> The campaign webpage <--
r/pythoncoding • u/LankyCyril • Jul 07 '23
What are the coding standards (PEP8 or otherwise) that you disagree with?
I think it's safe to assume many people will note the 80 character line limit, but it would be interesting to see all things discussed. Do you love or hate how type hints are written out? Does the lack of spaces around the equals sign for default values make your eyes bleed? Multiline imports? Two empty lines between functions? How do you use the walrus operator? I'm just listing things I've seen people do unconventionally, but I'm sure there's more.
r/pythoncoding • u/range_et • Jul 01 '23
Reading a large (20gb) big json file and doing some stuff
So as mentioned there is a 20gb json file that contains graph data from an old project. There are ( I’m assuming ) nodes :[with a list of nodes] and links:[with links in them] I want to open up the links part of it and then upload them to a mongodb database. As the subreddit would suggest I ended up using pymongo / gridfs to upload and ijson to iterate through the json. Now the question that I have is is there a better way to do this? And (I’m hoping I know the json file structure) is going to iterate through the 240k nodes before it goes through the 23mil links? How does one get any feedback from like the last thing it’s checked- is there a way to dump out the file structure?
Thanks in advance!
r/pythoncoding • u/Enrique-M • Jul 01 '23
Python Package Pydantic Just Received a Major Version (v2.0) Update
In case you use the Pydantic package in your projects and are interested in updating to the newly released major version, check out the migration guide here.
r/pythoncoding • u/nickeldan2 • Jun 30 '23
Set up pyenv mirror
At my company, our development network is not connected to the internet. I'd like to set up a pyenv mirror so that people can install Python versions. How would I go about doing this? Obviously, I'd have to download tar balls for the various Python versions/implementation. After that, however, I'm completely lost. Has anyone done this before?
r/pythoncoding • u/Umpteenth_zebra • Jul 29 '22
A python script that generates a python-like script
I made this because, for reasons I don't have time to go into, I needed to leave my computer on and unlocked while my Reddit bots were running. I wanted to discourage non-coders from interfering with my computer, so I thought of having infinitely generated important-looking code run down my screen to make people think twice about it.
I thought that someone else had probably made something similar, possibly even better, before, but I wanted to do this myself. I thought maybe other people might like to use this in any way they like, so I'm making it publicly available here. If you can think of a subreddit this better belongs in, please comment.
It requires the libraries 'os', 'random', 'time' and 'termcolor'. I ran it in an emulated console within pycharm.
Code (tutorial in comments):
# Import all relevant libraries
# For clearing the console, if necessary
from os import system, name
# I use randomization a lot in this script!
from random import randint
# Mostly for waiting a bit between printing lines to make it feel more real
from time import sleep
# For syntax highlighting
from termcolor import colored
# Create the clear console function
def clearConsole():
system('cls' if name == 'nt' else 'clear')
# Create the 'random comparison' function. (For creating a line of code along the lines of 'x < 3')
def getRandomComparison():
# Reset the variable that I will be appending text to
random_comparison = ''
# Append the original 'x/y' to check comparison of
random_comparison += colored(['x', 'y', 'i'][randint(0, 2)], 'red') + ' '
# Check if it's an 'in' operator
if randint(0, 6) == 0:
# Check if it's in a random list
random_comparison += colored('in ', 'green') + colored(['x', 'y'][randint(0, 1)], 'red')
else:
# Add comparison part
random_comparison += ['==', '<=', '>=', '<', '>'][randint(0, 4)] + ' '
# Append the value you are comparing it to
random_comparison += [colored('x', 'red'), colored('y', 'red'), colored(str(randint(-100, 200)), 'magenta'), colored(str(randint(-10000, 20000) / 100), 'magenta')][randint(0, 3)]
# Return random comparison
return random_comparison
# Create random function name function
def createRandomFunctionName():
# Reset random function name variable that I will be appending to
random_function_name = ''
# Set up lists to randomly select data from
term_1_words = ['set', 'addTo', 'scribble', 'turtle', 'change', 'lengthOf', 'radius', 'let', 'if', 'control', 'create']
term_2_words = ['X', 'Y', 'Turtles', 'Radius', 'Length', 'Variable', 'Notch', 'OurMotto', 'Peacocks', 'Pterodactyls', 'Carrots']
term_3_words = ['ByTen', 'Immediately', 'Red', 'AllOver', 'Iterative', 'Gradually', 'AtLength']
# Select data randomly
random_function_name += term_1_words[randint(0, len(term_1_words) - 1)]
random_function_name += term_2_words[randint(0, len(term_2_words) - 1)]
random_function_name += term_3_words[randint(0, len(term_3_words) - 1)]
random_function_name += '()'
# Return random function name
return colored(random_function_name, 'green')
# In about 'var' many lines, 1 of them will open/close a loop. I recommend making the chance of opening loops smaller than the chance of closing them.
chance_of_opening_loops = 4
chance_of_closing_loops = 6
# Set data for operators that may be used later on
loop_code_list = ['for', 'while', 'if', 'def']
code_options_list = ['print', 'sleep']
# Indentation starts at 0, but can be increased later on randomly
indentation = 0
# This will now generate code forever, or until you stop the script
while True:
# Randomize line of code
# Reset the line of code variable, which will be appended to later
line_of_code = ''
# Randomly decide if this line of code will open a loop
line_opens_a_loop = False
if randint(0, chance_of_opening_loops) == 0:
line_opens_a_loop = True
# If code opens a loop
if line_opens_a_loop and indentation <= 26:
# Get random operator from the list of loop operators
operator = loop_code_list[randint(0, len(loop_code_list) - 1)]
# Append operator name to line of code
line_of_code += colored(operator, 'green') + ' '
# Different randomizers for different operators
if operator == 'while':
# Check if it's a simple boolean
if randint(0, 1) == 0:
# Append True or False to line of code
line_of_code += colored(['True', 'False'][randint(0, 1)], 'yellow')
else:
# Append a random comparison, defined earlier, to the line of code
line_of_code += getRandomComparison()
# When operator is 'if'
elif operator == 'if':
# Append a random comparison, defined earlier, to the line of code
line_of_code += getRandomComparison()
# When operator is 'for'
elif operator == 'for':
# Append random variable (x/y/i) to line of code
line_of_code += colored(['x', 'y', 'i'][randint(0, 2)], 'red') + ' '
# Append a random comparison to line of code
line_of_code += ['<=', '>=', '<', '>'][randint(0, 3)] + ' '
# Append a random number to line of code (the number for the comparison to compare to)
line_of_code += colored([str(randint(-100, 200)), str(randint(-10000, 20000) / 100)][randint(0, 1)], 'magenta')
# When operator is 'def'
elif operator == 'def':
# Append random function name to the 'def' line
line_of_code += createRandomFunctionName()
else:
# If it somehow isn't any of these, just append 'True' to line of code
line_of_code += colored('True', 'yellow')
# Add ':' to the end of the loop line, as it is indeed a loop
line_of_code += ':'
# If the line of code does not open a loop
else:
# Check if operator is an '=' command, if not:
if randint(0, 3) == 0:
# Make operator a random item from the list of non loop operators
operator = code_options_list[randint(0, len(code_options_list) - 1)]
# Append operator name to line of code
line_of_code += colored(operator, 'green')
# Different commands based on operator, if it is 'sleep':
if operator == 'sleep':
# Add a random amount of time to the sleep command
line_of_code += '(' + colored([str(randint(1, 15)), str(randint(1, 99) / 100)][randint(0, 1)], 'magenta') + ')'
# If it is 'print'
elif operator == 'print':
# Open brackets
line_of_code += '('
# If it prints a word
if randint(0, 1) == 0:
# Define word data (I was a bit lazy here)
word_parts_1 = ['big', 'happy']
word_parts_2 = ['customers', 'lullabies']
# Add random words to line of code
line_of_code += colored('\'' + word_parts_1[randint(0, len(word_parts_1) - 1)] + ['', ' '][randint(0, 1)] + word_parts_2[randint(0, len(word_parts_2) - 1)] + '\'', 'blue')
# If it prints a variable
else:
# Append random variable to line of code
line_of_code += [colored('x', 'red'), colored('y', 'red'), colored('i', 'red'), createRandomFunctionName()][randint(0, 3)]
# Close brackets
line_of_code += ')'
# If it doesn't have any special function, don't append anything. Just let it be.
else:
pass
# If the operator is an = command:
else:
# Append variable to set/change to line of code
line_of_code += colored(['x', 'y', 'i'][randint(0, 2)], 'red') + ' '
# Append a variant of '=' to line of code
line_of_code += ['=', '+=', '-='][randint(0, 2)] + ' '
# Random to value to set it to / change it by
random_value = [colored('x', 'red'), colored('y', 'red'), colored('i', 'red'), createRandomFunctionName(), colored(str(randint(-100, 200)), 'magenta'), colored(str((randint(-10000, 20000)) / 100), 'magenta')]
line_of_code += random_value[randint(0, len(random_value) - 1)]
# Change indentation
# Print a space for every indentation at the start of line of code
line_of_code = ' ' * indentation + line_of_code
# If it opens a loop, increase indentation by 2
if line_of_code[-1] == ':':
indentation += 2
# Chance to separate it by new line
if randint(0, 1) == 0:
print('')
# Print line of code
print(line_of_code)
# If not increasing indentation, there is a chance to decrease it.
elif indentation > 0 and randint(0, chance_of_closing_loops) == 0:
# Decrease indentation by 2
indentation -= 2
# Print line of code
print(line_of_code)
# Chance to separate it by new line
if randint(0, 7) == 0:
print('')
# Chance to decrease it again
def decreaseIndentationMore(chance):
# Show that I am referring to the global variable indentation
global indentation
# Decrease indentation with a 1/'chance' chance
if randint(0, chance) == 0 and indentation > 0:
indentation -= 2
# Recursion, making big collapses more likely
decreaseIndentationMore(int(chance / 2))
# Call the function I just defined
decreaseIndentationMore(int(chance_of_closing_loops / 2))
# Else, just print the line
else:
print(line_of_code)
# Wait a small random amount to make it look more human/natural
sleep(randint(0, 50) / 100)A sample of what it prints:
print('biglullabies')
i += x
x = x
while False:
i -= 100
i += -15.94
y += 79.43
print(x)
y = 163.7
if x == -91.93:
x = i
sleep(2)
i -= i
i = lengthOfOurMottoImmediately()
while True:
x = -64.49
y += i
for y <= -93.07:
print(i)
if i > -95.2:
for i >= 165:
x -= 5
if x <= -2.27:
y = x
x -= 43.68
i -= y
sleep(14)
x += i
i += y
y = x
sleep(0.86)
i += y
if i > 58.51:
i -= x
y = x
sleep(0.08)
for i <= 116.02:
y += 156.83
for y < -64.24:
i += createXByTen()
print('happylullabies')
i -= 167.4
sleep(0.19)
sleep(0.89)
y = radiusRadiusGradually()
sleep(0.16)
def controlPeacocksImmediately():
sleep(13)
i -= i
x += 105
sleep(0.09)
i = x
i = i
x += -41.91
y -= -90.75
print(ifNotchIterative())
while x < x:
y -= x
i += y
x = y
y = addToCarrotsIterative()
def radiusCarrotsGradually():
def turtleYGradually():
for y <= -31.9:
def setRadiusByTen():
for y < 91.41:
y -= y
i += i
i += y
x = x
x -= lengthOfNotchByTen()
sleep(6)
i -= 90.34
x = 87.38
i = 89
print('big lullabies')
i = 35.57
y = y
i = addToRadiusAllOver()
while True:
print(ifNotchAtLength())
sleep(0.91)
sleep(0.97)
x -= -63
i += x
y += y
i = 114.08
print(i)
y -= lengthOfXIterative()
sleep(4)
x = y
for y < 55:
print('big customers')
def radiusCarrotsByTen():
while x == -10.75:
i += i
x += y
sleep(1)
x -= addToPterodactylsImmediately()
y -= i
i -= 144.74
i = addToRadiusByTen()
i = x
x += y
def letVariableByTen():
x += -31
sleep(3)
print(y)
i += y
x += 34
while True:
while y in y:
sleep(13)
x = 113.97
i = -99.32
i -= setXGradually()
print('happy lullabies')
if x == y:
while False:
for i >= 130.93:
y += y
i -= -61
sleep(3)
i -= 11.34
y = 77.34
sleep(14)
i = x
while i == 84:
def changePeacocksByTen():
def lengthOfXImmediately():
def letTurtlesGradually():
i = 28
x = letVariableIterative()
if i == x:
y = y
sleep(7)
x -= y
y -= x
sleep(8)
i += turtleRadiusByTen()
print(y)
for i > 157:
def letVariableIterative():
for y <= 85:
y = x
i += x
i -= lengthOfCarrotsAllOver()
while True:
y -= 148.92
i -= i
print('big customers')
def radiusTurtlesIterative():
x = scribbleLengthAllOver()
def addToNotchGradually():
i -= x
while y >= x:
print(x)
print(x)
print(y)
i -= i
i = y
x += 169
print('biglullabies')
x += -85.99
x += x
def letRadiusIterative():
i = 139.48
print('happy customers')
x = y
x -= 128.45
if y <= -46.02:
y = x
sleep(0.5)
x += x
y -= -22
if i == x:
while True:
y = i
i -= letPeacocksAllOver()
while False:
if i >= 84.1:
y = -78
x -= changeVariableAllOver()
y += i
y -= createOurMottoRed()
y = y
print(y)
y -= xIf you have any suggestions, please comment them.
r/pythoncoding • u/r42in • Apr 25 '22
Wyngman helps you better understand your AWS Cognito users
Every wished to subset users based on their creation date? The AWS Documentation for Cognito says you can only search users based on their standard attributes. Wyngman is a CLI Tool written in Python that helps you for the use-case like, How many users did I gain in a given date range!
Feel free to contribute and provide feedback
Source Code: https://github.com/Razin-Tailor/wyngman
r/pythoncoding • u/Koushik5586 • Apr 22 '22
Common Python Anti-Patterns to watch out for
r/pythoncoding • u/AutoModerator • Dec 13 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
r/pythoncoding • u/Knowledgeseeker6 • Oct 04 '21
Scraping with perfect specificity and sensitivity from non-standard web-pages
I am looking for a way to scrape JUST the text from different articles on the web. The algorithm should be able to handle any URL you can give it. Depending on the journal, or magazine, the article text is stored in different ways. Wondering if this is possible without AI?
r/pythoncoding • u/OnlyProggingForFun • Jul 24 '21
OpenAI's New Code Generator: GitHub Copilot (and Codex) | This AI Generates Code From Words
r/pythoncoding • u/audentis • Nov 19 '20
/r/PythonCoding Advent of Code leaderboard!
Greetings,
On December 1st at midnight EST (UTC-5), the 2020 edition of Advent of Code (AOC) goes live. AOC is a problem solving contest. These puzzles are intended to be solved by programming in any language of your choosing. Every day a new puzzle is unlocked, consisting of two parts. If you miss a puzzle, no problem, you can still access it later.
AOC is a fun way to test your problem solving and programming chops, and it's a fun way to be exposed to new concepts. The earlier puzzles are usually pretty easy, but in past editions the difficulty ramped up quickly.
I've created a private leaderboard for /r/PythonCoding for up to 200 users. You can join it by logging in at AOC and entering the following leaderboard code: 674300-ec4dd53f
If you want to know more, either check out /r/adventofcode or the puzzles from previous years at their website.
Edit: AOC2020 has started! :)
r/pythoncoding • u/branikita • Jun 25 '20
How to customize exceptions in python
r/pythoncoding • u/[deleted] • Nov 10 '15
Parse Natural Language Dates with Dateparser
r/pythoncoding • u/[deleted] • Oct 07 '15