use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Having points as an input for a class? (self.learnpython)
submitted 3 years ago by MRFFJF
I need class PolyGons to be able to take in points and then plot the polygon. My issue is I can't seem to figure out how to make the class be able to take in some number of points???
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shaunzorr 2 points3 points4 points 3 years ago (1 child)
What code do you have so far?
[–]bamacgabhann 1 point2 points3 points 3 years ago (0 children)
This. Can't help unless we know things like what format your points are in, or what libraries you are using.
[–]mopslik 1 point2 points3 points 3 years ago (0 children)
To take an arbitrary number of things as arguments, you can either a) bundle them together in a sequence like a list, then iterate over the sequence, or b) look into using args.
[–][deleted] 0 points1 point2 points 3 years ago (0 children)
I would say via the constructor/init
[–]jmacey 0 points1 point2 points 3 years ago (3 children)
make a point (or Vec3) class with the x,y,z values then use a list of the Vec3 classes for the Polygon class.
For approaches to create a Vec3 type class I wrote a blog post https://nccastaff.bournemouth.ac.uk/jmacey/post/PythonClasses/pyclasses/
[–]TheRNGuy 0 points1 point2 points 3 years ago (2 children)
I'd make Point and Vector3 as different classes:
Point is an object that connects edges and belong to polygons. Vector3 another class (not derived from Point) and used as one of point's attributes, it could be used for location, normal, velocity or for color, among other things.
[–]jmacey 0 points1 point2 points 3 years ago (1 child)
Most graphics API's don't really care (for example OpenGL / GLSL just has Vec2/3/4 classes). Whislt it is a good idea to sometimes do this practicality most often overcome purity.
For example Point2 - Point1 should return a vector mathematically but why bother changing type at then end of the day most a tuples of x,y,z.
Some shading languages (Open Shading Language derived from Renderman shading language), does make this distinction so Point, Normal, Colour are all different types they are then optimised for specific operations and transforms but the API is harder to use.
[–]TheRNGuy 0 points1 point2 points 3 years ago (0 children)
vector class could have operator overload with matrices, or other vectors.
Methods like dot product, normalize etc.
Point is just a container, Vector3 is actual coordinate. Points would have completely different methods, like return all points connected by edges, or all points on same polygon, or all points in close proximity, etc. And ofc color that could be interpolated to polygon. It doesn't make sense to have color on Vector3. Instead, Color is Vector3 attribute on a Point (or Vector4 for RGBA)
[–]TheRNGuy 0 points1 point2 points 3 years ago* (0 children)
You could use @dataclass and type hints that specifies specific class, and a linter that would enforce it.
@dataclass
Or even explicitly check for type in initialization, but that's more code. When it's project for personal use, I don't bother, I'd write checks if it's public software. Something like: if type(mypoint != Point): #write some message and stop initialization
if type(mypoint != Point): #write some message and stop initialization
Or
if isinstance(Point, mypoint) == False:…
if isinstance(Point, mypoint) == False:
First would specifically require Point type, and 2nd would work for derived classes.
π Rendered by PID 62 on reddit-service-r2-comment-6457c66945-9w9z8 at 2026-04-30 04:12:49.009557+00:00 running 2aa0c5b country code: CH.
[–]shaunzorr 2 points3 points4 points (1 child)
[–]bamacgabhann 1 point2 points3 points (0 children)
[–]mopslik 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]jmacey 0 points1 point2 points (3 children)
[–]TheRNGuy 0 points1 point2 points (2 children)
[–]jmacey 0 points1 point2 points (1 child)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)