r/pythonhelp • • Oct 01 '26

How to pass a string of keyword arguments into a function

3 Upvotes

Having encountered, the seemingly impossible in Python, difficulty of passing a string of keyword arguments into a function like this:

args_in = "arg1 = 'var1', arg2 = 2, arg3 = True, arg4='var4'"

def myFunc(arg1=None, arg2=None, arg3=None, arg4=None):
    print(f"{arg1=}, {arg2=}, {arg3=}, {arg4=}")

myFunc(args_in)

One solutions I found was to use eval():

eval("myFunc(" + args_in ")") 

although I am informed that this is the work of the devil and should be avoided at all costs.

Next attempts were to convert the "string" into a dict{} and pass **dict, however all methods for doing this failed when any of the arguments contained a comma ','.

However a fully working solution to this was finally provided to me on the discuss.python.org forum:

args_in = "arg1 = 'var1', arg2 = 2, arg3 = True, arg4='va,r4'"

def myFunc(arg1=None, arg2=None, arg3=None, arg4=None):
    print(f"{arg1=}, {arg2=}, {arg3=}, {arg4=}")

def str2dict(str_in: str) -> dict[str, str]:
    import ast
    return {pair.arg: ast.literal_eval(pair.value)
        for pair in ast.parse(f"f({str_in})").body[0].value.keywords}

myFunc(**str2dict(args_in))

Unfortunately due to rather rude and overly zealous moderation on there that solution was deleted. Hence the reason for publishing it here for the archive and in case it helps someone else in the future.


r/pythonhelp • • Oct 01 '26

What's everyone using for Python coding these days?

3 Upvotes

I mostly code with python and i've been thinking about changing my setup.

I'm not looking for anything too complicated. Mainly something that can understand the project, help debugging and make changes across multiple files without me having to explain the whole thing every time.

If you mostly work with Python what does your setup look like these days and how it been working for you?


r/pythonhelp • • Aug 08 '26

Python game tic tac toe

3 Upvotes

Hello guys I am making a tic tac toe game using python.My question is how to make difficulty-easy, medium, hard etc.In easy level, I use random module but other level i am a little sutck althoug i have some solution .can you guide me ?


r/pythonhelp • • Jul 10 '26

Python "generate_chk" function

3 Upvotes

I am making a Program to upload a level to Geometry Dash in python and I got some of the code from https://wyliemaster.github.io/gddocs/#/endpoints/levels/uploadGJLevel21 but to generate "seed2" it does this:

generate_chk(key="41274", values=\[generate_upload_seed(levelString)\], salt="xI25fpAapCQg"),

This should activate some sort of function named generate_chk that is in one of the modules I have in the program (Requests, Base64, hashlib) but it is no where to be found. The repository for this documentation was archived recently, so I can't ask them for help. Also, here is my code:

import requests
import base64
import hashlib  # sha1() lives there

user = input("What is your username?")
accid = input("What is your Account ID?")
passwd = input("What is your password?")
lname = input ("What is the Level name?")
coin = input("How many coins are there?")
stars = input("How many stars do you want?")

def generate_gjp2(password: str = passwd, salt: str = "mI29fmAnxgTs") -> str:
    password += salt
    hash = hashlib.sha1(password.encode()).hexdigest()
    return hash


levelString = "H4sIAAAAAAAAC6WQwQ3DIAxFF3IlfxsIUU6ZIQP8AbJChy_GPSZqpF7-A4yfDOfhXcCiNMIqnVYrgYQl8rDwBTZCVbkQRI3oVHbiDU6F2jMF_lesl4q4kw2PJMbovxLBQxTpM3-I6q0oHmXjzx7N0240cu5w0UBNtESRkble8uSLHjh8nTubmYJZ2MvMrEITEN0gEJMxlLiMZ28frmj"

data = {
    "gameVersion": 22,
    "accountID": accid,
    "gjp": hash,
    "userName": user,
    "levelID": 0,
    "levelName": lname,
    "levelDesc": "Q3Vyc2VkIGxldmVsIG55ZWggaGVoIGhlaCBhbnl3YXkgaXRzIGEgdmVyeSBicm9rZW4gbGV2ZWwgaSBzZW50IGEgcmVxdWVzdCB0byByb2Igc2VydmVyIHRocm91Z2ggcHl0aG9uIGxvbA",
    "levelVersion": "-47577473775738573",
    "levelLength": 48483845738573486574873869465947694,
    "audioTrack": 0,
    "auto": 0,
    "password": 314159,
    "original": 55610687,
    "twoPlayer": 0,
    "songID": 839583504693858468444987694,
    "objects": 1,
    "coins": coin,
    "requestedStars": stars,
    "unlisted": 0,
    "ldm": 0,
    "levelString": levelString,
    "seed2": generate_chk(key="41274", values=[generate_upload_seed(levelString)], salt="xI25fpAapCQg"), # This is talked about in the CHK encryption,
    "secret": "Wmfd2893gb7"
}

headers = {
    "User-Agent": ""
}

url = "http://www.boomlings.com/database/uploadGJLevel21.php"

req = requests.post(url=url, data=data, headers=headers)
print(req.text)

And here is the error:

What is your username?levelnotinauto
What is your Account ID?38627839
What is your password?********
What is the Level name?Check Desc
How many coins are there?4848394
How many stars do you want?392084092849
Traceback (most recent call last):
  File "/home/***/scripts/usernm/upload", line 43, in <module>
    "seed2": generate_chk(key="41274", values=[generate_upload_seed(levelString)], salt="xI25fpAapCQg"), # This is talked about in the CHK encryption,
             ^^^^^^^^^^^^
NameError: name 'generate_chk' is not defined. Did you mean: 'generate_gjp2'?
[***@archlinux usernm]$ vim upload```

r/pythonhelp • • Jun 25 '26

Python file not running

3 Upvotes

When i open my python file directly i am unable to change the interpreter due to which it says pandas not found/installed and hence doesn’t work
Then when i open anaconda prompt and open “code” from there then i am able to change the interpreter if i had closed all tabs and terminals before
After which when i run the file it says keyboard interrupted press Y/N (something like this) then i have to press “N” after which it runs on a single click up until i close the app

Please help

Ps- i am a beginner go easy in comments and itd be great if you could explain it to me in a simple language


r/pythonhelp • • May 23 '26

Honest Question: Why use one Python editor over another, and is Geany not what the cool kids use?

3 Upvotes

I've used a lot of different editors in my time, and tbh I rarely notice much difference. They just seem to be text editors that highlight syntax, mostly in the same ways. Is there a reason to use one over another? A recent programming class I've been involved with insists on Spyder; really I don't see a reason for this. Is there some advantage I'm missing? For my home coding projects I use Geany, and it works fine.


r/pythonhelp • • May 20 '26

A simple visual guide to Python list aliasing and mutation

3 Upvotes

One of the most common traps in Python is not understanding when a list is modified in-place vs when a completely new list is created.

A few examples that confuse even experienced developers:

a = [1, 2, 3, 4, 5]

b = a

b.append(6)

print(a)


#Output  [1,2,3,4,5,6]

Explanation:

  • a and b point to the SAME list object

  • append() modifies the list in-place

  • so a also changes

Now

a = [1, 2, 3]

b = a

b = b + [4, 5]

print(a)

#Output - [1, 2, 3]

Explanation:

  • + creates a NEW list

  • b now points to a different object

  • original a is unchanged

Now

a = [1, 2, 3]

b = a

b += [4, 5]

print(a)

#Output [1, 2, 3, 4, 5] 

Explanation:

  • += modifies the list in-place

  • both variables still point to same list

  • so a changes too

Also

a = [1, 2, 3]

b = a

b.append(4)

print(a)
#Output - [1, 2, 3, 4]

Explanation:

  • append() changes original list directly

  • no new list is created


r/pythonhelp • • Apr 25 '26

Python Descriptors

3 Upvotes
class A:
	def __set_name__(self, owner, value):
		self.value = value

	def __get__(self, obj, type=None):
		return obj.__dict__.get(self.value)
	
	def __set__(self, obj, value):
		if value < 9:
			raise ValueError("no")
		obj.__dict__[self.value] = value
	
class B:
	a = A()

obj = B()
obj.a = 38
print(obj.a)

obj2 = B()
print(obj2.a)

I am Learning Descriptors In Python,

My 1st question Is how can I set a default value to attribute a In class B ? I have found a way but that doesn't look familiar :

a = A() if not A() else 87

My next confusion Is about __set_name__ , what it does and why to Implement It?

Another Question Is, does a = A() create class attribute or Instance attribute? It looks like a class attribute but it's an Instance attribute, Right?


r/pythonhelp • • Apr 14 '26

Need assitance setting up bot on private discord server

3 Upvotes

I have everything but i dont seem to understand how to make it run i just need help on how exactly to put it all together, its a program from Github i grabbed but im not quite understanding


r/pythonhelp • • Mar 16 '26

NumClass: a Python CLI for 200+ number-theory properties (looking for testers)

3 Upvotes

Hi everyone,

For the past few months I’ve been building a personal project called NumClass:

a Python CLI tool that analyzes an integer and classifies it into a large set of number-theory properties.

The idea started as a small experiment inspired by the YouTube channel Numberphile, but it quickly got out of hand and now supports 200+ classifiers.

Examples of things it can detect:

• perfect / abundant / weird numbers
• Mersenne primes and primorial numbers
• amicable, sociable and aspiring numbers (aliquot sequences)
• Carmichael numbers and other pseudoprimes
• narcissistic, Kaprekar and happy numbers
• palindromic and truncatable primes
• taxicab numbers (Hardy–Ramanujan style cube sums)
• Fibonacci, Lucas, Pell and Padovan numbers
• triangular, pentagonal and other figurate numbers
• strange curiosities like Belphegor’s prime, vampire numbers and Munchausen numbers

The current version contains 205 atomic classifiers plus 27 intersections (232 properties in total).

Example output

Some features:

• 200+ classifiers
• extensible plugin-like architecture
• configurable profiles (fast vs heavy computations)
• OEIS sequence integration
• support for very large integers (100000 digits by default)
• explanations for each classification

The project is open source:

https://github.com/c788630/Numclass

I’m now looking for people who would like to test it, especially:

• mathematicians
• Python developers
• people interested in number theory
• anyone who likes exploring interesting integer properties

If you decide to try it out, I would really appreciate feedback on:

• usability of the CLI
• additional number-theory properties to implement
• performance for very large numbers
• any issues or bugs you encounter

There are also a few small Easter eggs hidden in the program (including Klingon number input), so feel free to explore 🙂

Installation instructions and documentation are available in the repository (docs folder).


r/pythonhelp • • Feb 19 '26

How should I learn Python for Data Analytics roles (YouTube recommendations)?

3 Upvotes

Hi everyone, I’m aiming for a data analytics role and want to learn Python specifically for analytics (Pandas, NumPy, EDA, etc.). I have basic programming knowledge. I have completed SQL 30 hrs course by 'Data with Baraa' and practicing SQL questions on DataLemur. Can you recommend a good YouTube course or playlist that is practical and job-oriented? Thanks in advance!


r/pythonhelp • • Dec 20 '25

Question about python on raspberry pi

3 Upvotes

I've been considering getting a raspberry pi for python. I would just do this on my phone but I can't have projects that use files like JSON and before I got one I wanted to know if you could on the pi


r/pythonhelp • • Nov 29 '25

A simple way to embed, edit and run Python code and Jupyter Notebooks directly in any HTML page for CS lessons

Thumbnail
getpynote.net
3 Upvotes

r/pythonhelp • • Nov 28 '25

How do I disable pylance linting.

3 Upvotes

I just started learning python and I wanted to use Ruff so I installed it. But now, I see both pylance and ruff on problem window. How do I disable pylance?


r/pythonhelp • • Nov 23 '25

Is PyCharm worth it?

3 Upvotes

Hey guys,

PyCharm is much loved in the coding community, I've basically been using VS code since the beginning.

Should I make the swap (to the community edition).

Context:
I'm not that experienced
I want to specialise in Python AI agents


r/pythonhelp • • Nov 18 '25

renaming .doc and .docx files by creation date

3 Upvotes

Hello!

I'd like to rename my old and new .doc and .docx files on Windows to reflect the date they were originally created. I've tried searching online, but couldn't find anything related to my problem.

I have the files in a specific folder that also contains subfolders. I'd like to keep the folder structure and the original names, but I want to add the creation date to their end (e.g. file.docx --> file_yyyymmdd.docx)

I've asked ChatGPT, but its script adds today's date to the end of my files, not the creation date... :/

Could anyone help me please? I'm a beginner Python coder


r/pythonhelp • • Oct 25 '25

Need Support Building a Simple News Crawler in Python (I’m a Beginner)

3 Upvotes

Hi everyone,

I’m working on a small project to build a news crawler in Python and could really use some help. I’m fairly new to Python (only basic knowledge so far) and I’m not sure how to structure the script, handle crawling, parsing, storing results, etc.

What I’m trying to do: • Crawl news websites (e.g., headlines, article links) on a regular basis • Extract relevant content (title, summary, timestamp) • Store the data (e.g., into a CSV, or a database)

What I’ve done so far: • I’ve installed Python and set up a virtual environment • I’ve tried using requests and BeautifulSoup for a single site and got the headline page parsed • I’m stuck on handling multiple pages, scheduling the crawler, and storing the data in a meaningful way

Where I need help: • Suggested architecture or patterns for a simple crawler (especially for beginners) • Example code snippets or modules which might help (e.g., crawling, parsing, scheduling) • Advice on best practices (error handling, avoiding duplicate content, respecting site rules, performance)

I’d appreciate any guidance, references, sample code or suggestions you can share.

Thanks in advance for your help


r/pythonhelp • • Sep 18 '25

Which is the best IDE to learn python jupyter notebook or VS Code. I am newbie trying to learn python.. would appreciate if anyone take an initiative to teach me on weekends

Thumbnail reddit.com
3 Upvotes

r/pythonhelp • • Sep 06 '25

TIPS Python Memory Tricks: Optimize Your Code for Efficiency in 2025

Thumbnail
techbeamers.com
3 Upvotes

r/pythonhelp • • Jul 16 '25

GUIDE Can't get VS Code to use my virtual environment — packages not found

3 Upvotes

Hi, I’m new to Python and trying to learn web scraping and automation. I’ve already learned the basics (like functions, lists, dictionaries), and now I’m trying to install packages like beautifulsoup4 and requests.

I tried setting up a virtual environment in VS Code, but I keep getting errors like:

ModuleNotFoundError: No module named 'bs4'

What I’ve done so far:

  • Activated it with source myenv/bin/activate

  • Installed packages using pip install beautifulsoup4 requests

  • Selected the interpreter in VS Code (via Ctrl+Shift+P → Python: Select Interpreter → myenv/bin/python)

  • Still, the Run button and terminal keep defaulting to system Python

  • I'm on Ubuntu and using VS Code

It’s really confusing, and I feel stuck.
I’d really appreciate a beginner-friendly step-by-step guide — or even just how to confirm VS Code is using the correct interpreter.

I used chatgpt for helping me to set up virutal environment. But now i've stuck in this mess.

Thanks in advance to anyone who replies 🙏


r/pythonhelp • • Mar 18 '25

Looking for advice to really LEARN coding.

3 Upvotes

Hello everyone, I am a sophomore in college, and I want to go into cybersecurity. I am good at working with computers in general, but when it comes to coding I keep constantly looking up tutorials for how to do things, and I can feel that the concepts aren't really sticking with me. It's extremely frustrating because I keep going to Chatgpt to ask "what steps should I think to solve this" or looking up tut's on YouTube, and it REALLY doesn't help when I see people saying "python is so easy!" and whatnot.

Any advice on how you learned to program would be really helpful, and/ or anything you did to practice would be great!

Thanks for reading!


r/pythonhelp • • Mar 09 '25

Downloading PDFs from a Website, Converting them to Excel and combining them

3 Upvotes

Hello, I'm not sure if this belongs here. Please let me know if it doesn't. Sorry I know the basics of Python and at most I'm just a beginner.

My colleage at work has a task. He has to login on a website, that my company orders from. He then has to filter down completed orderes, download the PDF for each order and extract two data fields from the pdf and paste it into Excel.

I know that Python offers a lot of flexibility, so I wondering if these steps can be automated in Python. If yes, how easy would it be? Can I use Chat GPT to properly write the code?


r/pythonhelp • • Feb 19 '25

xlwings opening file with add ins not loaded?

3 Upvotes

Working on a report automation that I had working fine but now does not work. Essentially, I am trying to open an Excel file and execute a macro. The current break point is that the macro is reliant upon an add in and when xlwings is opening the file it loads it without any addins. If I manually open Excel it opens fine with all of the addins. Has anyone ran into this before and found a solution? I've been troubleshooting/googling for a couple days but can't seem to figure it out. I'm just an accountant trying to play around with Python.

import os
import xlwings as xw
import ctypes
import win32com.client

cwd = os.getcwd()
print(cwd)

os.chdir(filepath)
new_dir = os.getcwd()
print(new_dir)

wb = xw.Book('Billed vs Scaled Raw Input File (New).xlsm')

macro3 = wb.macro("Module1.Source_Refresh")
macro3()

r/pythonhelp • • Feb 16 '25

First Time Coding. Stuck Trying to Append Something Properly

3 Upvotes

I've tried following the Demo we were given and understanding why some things were added where they are added, then applying that logic to what I'm trying to do, which hopefully will be obvious in the code included. In case it's not, I'm trying to use the defined Planck function with 3 different values for T and over 300 values for lamda (wavelength), and sort them into spectral_radiances by which temps value was used, but I kept getting errors leading to no values printed at all, until I took the advice of the AI explanation for the error I was getting and put in 0 as the index; so now of course it is putting all the values into that space alone, then printing the other two brackets empty after all the calculated values. How do I fix this?

code:

# define temperatures (in Kelvin) of B, F, G stars and put them in a list
t_ofB = 10000
t_ofF = 6000
t_ofG = 5200
temps = [t_ofB,t_ofF,t_ofG]
# define a wavelength list
wavelengths = list(range(380,701,1))

# define the Planck function
def Planck(lam,T):
  h= 6.62607004e-34
  c= 299792458
  k= 1.38064852e-23

  B = ((2 * h * c**2) / lam**5) * (1 / (2.7182818**(h * c / (lam * k * T)) - 1))
  return B
# loop over all temperatures and wavelengths to compute 3 blackbody curves
spectral_radiances = [[],[],[]]
for T in temps:
  for lam in wavelengths:
    lam =lam/1e9
    radiance = Planck(lam,T)
    spectral_radiances[0].append(radiance)
print(spectral_radiances)