r/learnpython • u/Nythious • Feb 20 '21
What are you having difficulty learning or are currently struggling to learn?
I'm curious what the community here has difficulty with when it comes to learning Python. Partly because I want to see if the more experienced community here (or myself) can help point you into the right direction. . . but also because I'm trying to come up with video tutorial ideas for future content and would love to hear from Python learners what would be most useful to dedicate our time on.
I'm looking forward to hearing what you guys have to say!
48
u/gd_choices_43 Feb 20 '21
To be honest I struggle with arrays , lists and dictionaries.
20
u/Nythious Feb 20 '21
I think this is a common struggle and I had this same struggle at first. I usually try to go into depth about how indexes work to explain all of these but I could definitely focus an entire few hours on just these containers!
4
u/gd_choices_43 Feb 20 '21
Would like to see a in depth video on these! If you do please post it so I can check it out
6
u/Nythious Feb 20 '21
Sure! I think I'll be doing these tonight on stream. I like going over containers and tonight is all about the basics so it's perfect!
11
u/0161WontForget Feb 20 '21
I struggle with these aswell, tools like set and practicing slicing really helped me though.
Trying to do challenges on websites and I struggled to get the data effectively so I decided to spend a day really playing with lists and dictionaries to better understand them
9
u/duquesne419 Feb 21 '21
Have you ever used a tool like pythontutor.com? Seeing the lists visualized helped me clear up some confusion I had with indexing.
→ More replies (4)3
u/piconet-2 Feb 21 '21
holy moly, bless you friend. I've been having the hardest time with a list of lists.
251
Feb 20 '21
Python
13
u/Nythious Feb 20 '21
Gotta start somewhere! That's why we've been putting together the streams and code along events. Mavenger and I usually teach/mentor in person at work but covid put a stop to that - we both got the itch to try it out virtually and so here we are. We both work in the field using python daily and are just doing this for fun and nothing else. If you're looking to learn and goof off or just looking for python nerds on a Saturday evening, please feel free to drop in on us and ask question or hang out. I won't broadcast our info in learnpython because this subreddit is for questions and community but if you check my r/python post you'll find us pretty quick!
→ More replies (2)103
51
u/solitarium Feb 20 '21
Self just hasn’t clicked for me yet...
23
u/Nythious Feb 20 '21
Self took a LONG time for me! It was forever until I realized self referred to an instance of a class and not the class. I'm gonna jot this one down to go over in the future.
15
u/Username_RANDINT def get_random_int(): return "RANDINT" # TODO Feb 20 '21
Here's a quick demonstration:
>>> class Foo: ... def __init__(self): ... print(self) ... >>> f = Foo() <__main__.Foo object at 0x7fdf79221710> >>> f <__main__.Foo object at 0x7fdf79221710>I think this often overlooked when trying to explain it.
→ More replies (1)5
u/forkheadbox Feb 20 '21
the first <__main...> is from the print statement right?
→ More replies (2)56
u/sje46 Feb 20 '21
I think what made it click for me was changing the word "self". "self" is arbitrary. It's convention, and you should definitely follow it. But it's not a special keyword or anything.
So if you have this:
class Planet: def __init__(self, name): self.name = name def transmit(self): print("Hello universe, this is the planet {}, is there anyone out there?".format(self.name)) ourplanet = Planet("Earth") outplanet.transmit()And change it to THIS:
class Planet: def __init__(banana, name): banana.name = name def transmit(myself): print("Hello universe, this is the planet {}, is there anyone out there?".format(myself.name)) ourplanet = Planet("Earth") outplanet.transmit()You can see that in the
__init__method, I changed it to the name "banana"...completely arbitrary. Change it to gorilla if you want. IT's just saying in this method, we will refer to the object itself as "banana".The transmit method makes more sense, because we're using "myself". In this method, we will refer to the object itself as "myself". The Planet object is referencing its own name, which we refer to as "myself.name".
"self" is absolutely nothing special as a variable. You can even change the name you use between functions...it literally doesn't matter. It's just an argument that pops up automatically in an object when you call a method.
I hope I didn't confuse you, but it's easier to learn by doing than reading. Just change the name of "self" for methods, and then hopefully it will stick out very clearly to you what it's doing.
And if you're confused about
__init__...that's a method that's automatically called when you create an object. Everything after hte first argument (the "self") is whatever you passed into the call, here, it would be "Earth". so "self.name = name" is essentially storing the name into the object itself for future use in other methods. It's just a storage system. We store "banana.name" and later on refer to it as "myself.name". Using multiple names for the object itself is confusing, so it's conventional to just use "self" all the time, like in the first example. But yeah, try renaming self in your programs, store arbitrary values, and call them in other methods. As soon as you got this down, you basically understand objects imo.4
u/gd_choices_43 Feb 21 '21
Wow I just played around with your explanation and it totally just clicked for me! Thank you so much for this!! 🙌👀🙏🏻
10
u/groovitude Feb 20 '21
Every time you create a new object, you run the
__init__()method to create a new instance of the class, but you're not completely rebuilding everything. In more concrete terms, if you have a classDogwith a methodbark(), you don't have forty copies of thebark()method if you have fortyDoginstances. You have one copy of thebark()method on theDogclass, which the forty instances all reference.So when you do this:
>>> fido = Dog() >>> fido.bark()That's a more readable version of what's actually going on under the hood:
>>> fido = Dog() >>> Dog.bark(fido) # try it with a class of your own!That's where you get
self-- the instance is passing itself as a parameter to a method stored in the class.3
u/MaraudingAvenger Feb 21 '21
I like this explanation a lot! -- pointing out that all the instructions for how an object behaves are stored in the class definition.
4
u/pedrocora Feb 20 '21
Self only clicked to me when I saw a video about classes on techwithtim yt channel. He spoke about self and bum, I got it once and for all.
→ More replies (4)4
u/MaraudingAvenger Feb 20 '21
So -- the best description of why we use
selfinside classes in python, to me, is to think of the method as a function outside of the class. Some examples first -- I used typing just to make things a little more explicit:class Bloop(): def __init__(self) -> None: self.blop = 5 def show_blop(self) -> None: print( f'blop is {self.blop}' ) b = Bloop() b.show_blop() #gets that 'b' (self) passed implicitlyso there we have an object called a Bloop, and when we make one of them, the thing we make has a blop with a value of 5 inside it.
I'm specifically interested in the
show_blop()function in there. It takesselfas a parameter, then accessesself.blopto print out theblopinsideself.What if that function was outside the class? How would it be written? The answer is almost exactly the same way:
class Bloop(): def __init__(self): self.blop = 5 def show_blop(thing: Bloop) -> None: print( f'blop is {thing.blop}' ) b = Bloop() show_blop(b) #gets a Bloop passed explicitlyin order for the function to work on a
thingthis is basically a design decision at its core; functions that work on class members are written the same inside and outside the class.selfjust represents the object that we're doing something to. The tricky thing is that class methods are all required to have self as the first argument, even if you don't use any members or methods from self in the function.3
u/unphamiliarterritory Feb 20 '21
What is the "-> None" stuff, I haven't seen that syntax before?
→ More replies (6)
11
u/pierraltaltal pierre-manchon Feb 20 '21
Regex man it's black magic
2
u/Nythious Feb 20 '21
Regex seems to be a popular one here. Guess that means I gotta figure out the best way to help you cast some black magic spells.
8
u/AchillesDev Feb 20 '21
https://regexcrossword.com was what I used when I was starting out. It helped get me solid on a few major fundamental concepts, anything more advanced still takes a good bit of testing and deciding if regexes are the right tool for what I'm doing.
→ More replies (2)6
Feb 20 '21
Honestly unless you do complex pattern-matching all the time IMO it's not worth learning Regex in great detail. Basics yes but there's plenty of tools that'll do it for you. It's powerful but it's a coding language of its own, tbh.
And I feel like in many cases a more simple tool like grep in a bash script may be less of a headache unless, like I said, you need that advanced crap. Depends what you're doing tho.
→ More replies (1)3
u/ASIC_SP learnbyexample Feb 21 '21
Regex is a mini-programming language by itself. Like a programming language, it will take time and practice to get comfortable with it.
I have an entire book dedicated for learning regex from the basics, with hundreds of examples and exercises. I cover both
reand third-partyregexmodule. It is free to read online: https://learnbyexample.github.io/py_regular_expressions/Useful tools and resources:
regex101 — visual aid and online testing tool for regular expressions, select flavor as Python before use
debuggex — railroad diagrams for regular expressions, select flavor as Python before use
Awesome Regex — curated collection of libraries, tools, frameworks and software
PythonVerbalExpressions — construct regular expressions with natural language terms
CommonRegex — collection of common regular expressions
8
Feb 20 '21
I would love to find more resources for practicing beginner level concepts.
I’ve googled and searched on YouTube “python exercises” or “mini-projects”. And while I’ve done many of those, I always feel like I haven’t really solidified some of the knowledge. I want more practice!!!
Can y’all share mini-projects (or bigger) that you personally loved to code when you were a beginner?
7
u/Nythious Feb 20 '21
A few fun ones we did recently:
Creating RPG abilities as functions and making 2 variables (Health Point tracker) fight each other using the abilities. (lots of fun learning randomness, health changes, attack order, etc)
Building RPG Character Classes (more complex than above - really challenging building the classes out and making the methods work and such)
Translating all the words in "Three Little Pigs" using googles definition API. (lots of text prep work, dedupe, use of stop word list, and API)
We also want to do a madlibs one soon but haven't had the chance to set that up yet.
but there's tons of challenge sites out there too!
→ More replies (2)3
u/AchillesDev Feb 20 '21
Advent of Code always has good ones, and the old exercises and answers stay up so you can check your work against that of others.
2
5
u/BlueBombadier Feb 20 '21
Lambdas. I kinda get the use cases but the syntax evades me. Any examples of how to lambda right compared to writing a function would be great.
4
u/Nythious Feb 20 '21
Oh yeah, I'm totally going to put together some lambda material in the future. I honestly didn't use lambda for the first year or two because I'd always just make a function. The syntax is very close to comprehension syntax except for the "lambda x:" part.
→ More replies (1)4
u/dupelize Feb 20 '21
Lambdas (in python) are just an argument and return statement pair.
lambda arg: ret_valtakes in and argumentargand returnsret_valthe same as:def not_lambda(arg): return ret_valThe only difference is that you don't need to explicitly name the function. The only real difference is that you can't have multiple statements within the lambda (you can hide complex computations in there, but it needs to be one statement).
3
u/remuladgryta Feb 21 '21 edited Feb 21 '21
Lambdas are a concept borrowed from functional (as in mathematical function) programming. Programmers who write in functional programming languages love when they spot a pattern in their program because then they get to write a general version of the pattern and never worry about writing similar code again.
An example is one time long ago a functional programmer noticed that they had a lot of functions that took a list as a parameter and returned a new list where each element of the result was based on each element of the parameter.
def square_list(lst): return [x**2 for x in lst] def add_ten_list(lst): return [x+10 for x in lst] def halve_list(lst): return [x/2 for x in lst]This made the functional programmer very excited. "Look, all these functions do exactly the same thing except for one little part! I bet I can write a general list transforming function." the functional programmer thought. And so they did:
def transform_list(operation, lst): return [operation(x) for x in lst]Now that they had a general version of their function, they could rewrite their old ones like this:
def square(x): return x**2 def add_ten(x): return x + 10 def halve(x): return x / 2 def square_list(lst): return list_transform(square, lst) def add_ten_list(lst): return list_transform(add_ten, lst) def halve_list(lst): return list_transform(halve, lst)But wait, that's kinda cluttered. Now you have all these functions
square,add_ten, andhalvethat have names even though you only care about them in the context of their corresponding blah_list function. You could move the helper functions into the function bodies of the "real" functions to hide some of that clutter from the rest of the program like so:def square_list(lst): def square(x): return x**2 return list_transform(square, lst)That's a bit better, but what's the point of declaring a function and giving it a name if the sole reason for that function existing is to be a behavioral parameter to some other function? That's the problem lambdas aim to help with. Lambdas are "throwaway" functions without a name and more concise notation, perfect for using smack dab in the middle of a function parameter list. The same list functions written using lambdas:
def square_list(lst): return list_transform(lambda x: x**2, lst) def add_ten_list(lst): return list_transform(lambda x: x+10, lst) def halve_list(lst): return list_transform(lambda x: x/2, lst)I've been calling the general function
list_transformall this time, but in reality there is an even more general version in the python standard library calledmap.mapbehaves similarly tolist_transformexcept it returns an iterator instead of a list and it can take more than just one iterable (lists are an example of iterable objects) as input. For example if you have two listsaandband you want to add them together element-wise you could write something like thisdef add_two_lists(a, b): """ Add the elements of a to the elements of b, resulting in a list c. Discards elements from the longer list that don't have a match in the shorter. """ shortest_length = min(len(a), len(b)) return [a[i] + b[i] for i in range(shortest_length)]but with
mapyou could instead write it like thisdef add_two_lists(a, b): """ Add the elements of the list a to the elements of the list b, resulting in a list c. Discards elements from the longer list that don't have a match in the shorter. """ return list(map(lambda x, y: x+y, a, b))
mapis a useful function, but in python it is often more natural to write these kinds of transformations as list comprehensions:def add_two_lists(a, b): """ Add the elements of the list a to the elements of the list b, resulting in a list c. Discards elements from the longer list that don't have a match in the shorter. """ return [x+y for x, y in zip(a, b)]However, there are tons of useful functions that take another function as one of their parameters to turn a general pattern into a specific one or to slightly modify a default behavior. Examples include but are not limited to the
sortedfunction, thefunctoolsmodule, and theitertoolsmodule.→ More replies (1)
4
Feb 20 '21
Data structures and algos :'(
2
u/Nythious Feb 20 '21
Do you mean things like containers? Nested json? Or other sorts of structures that my brain can't come up with atm?
3
2
u/alfa80211 Feb 20 '21
I want to save say 100 websites, and check the next day to see if any have changed... so I’m going to compare hashes. But i also want to print out the textual difference, so how should I store a list/tuple/csv (??) of huge chunks of text, along with address, hash? And how should I subtract one string from the other in order to print the differences ?
3
u/Nythious Feb 20 '21
ooo, I really like this one. I'd have to get my eyes on the data to form a few theories on an approach. Do you fuzzywuzzy? Ssdeep? some sort of modified TFIDF? It's really going to depend on what's being extracted from the websites too!
2
u/MaraudingAvenger Feb 20 '21
so you might have some luck exploring
difflib-- it's a little clunky, but it'll show you differences between big strings pretty well, when there's a change in hash.As for storage of big strings, you have a ton of options -- if you want to save the files as text and zip them up using the
zipfilelib, that is an option. If you want a cohesive data structure, you could turn them into a dict and usejsonto serialize them. Look into serialization methods (on the Googles) and find out which one suits you best!→ More replies (1)2
u/pfmiller0 Feb 20 '21
What's the reason for hashing the pages if you are going to store the text of the site anyway? Seems to me you aren't really saving any cycles by hashing the two pages and comparing the hashs versus just comparing the pages directly.
→ More replies (3)
2
u/mrpicachu Feb 20 '21
I am going to college for Cybersecurity and I have a passion for technology and networking. I have done a little JavaScript but this is different. I like it but we can only use what we learn in class, which is kinda hard because I can’t usually ask for help. I also struggle with staying focused I’ve realized which has made me wonder if I have developed ADHD over the years. I enjoy doing it but I always end up getting distracted or get frustrated when I can’t comprehend simple things.
3
u/Nythious Feb 20 '21
As someone with late diagnosed ADD I completely understand the frustration involved. I'd love to say I defeated my own brain but in reality medication truly helped me improve and focus on educational growth. I think the next most important thing is having a few people you can connect and lean on while you learn. Don't let them solve the problems for you but maybe they can nudge you towards the right answers. If that's not possible then try and gamify the learning - create your own fun challenges that interest you.
→ More replies (1)
2
u/skinner17 Feb 20 '21
RegEx
I don't really know why but they look so intimidating to me. I know I should just take it slow and go through simple examples one at a time to understand what is happening. But the examples used in the course I'm taking just look so complicated and intimidating that my brain shuts down instantly.
2
u/Nythious Feb 20 '21
I love crazy regex and am definitely planning something for regex in the future. Regex is like a whacky scientists art form. I can get fixated on regex extractors for hours just fine tuning a single one. lol
2
u/MaraudingAvenger Feb 20 '21 edited Feb 20 '21
Have you heard of regexpal? Copy a couple of the comments from this thread in, and try to pull out certain strings, or break things into sentences. Check out the docs, specifically things like
re.splitandre.sub, and play with those using patterns you make on regexpal. Don't worry! Regex has been called a write-only language, lol. You can write it, but it's impossible to read somebody else's.edit: scroll down on the right side of regexpal for the cheat sheet. the basics are,
[stuff]in square brackets matches one of any of the things between the brackets ([abc]will match an a, b, or c). add some curlies after that to say "more than one" ([abc]{2,5}will match between 2 and 5 a, b, or c's -- the 'abc' from 'abcde', or the 'aaaab' from 'aaaabqwerty').→ More replies (2)
2
u/Acetunez Feb 20 '21
python: boolean types
1
u/Nythious Feb 20 '21
As in: what is considered true and false or complex conditionals joined with boolean logic?
1
u/Acetunez Feb 20 '21
yes, Multi way if else statements as well
2
u/Nythious Feb 20 '21
I like this idea, I think I'll include that in tonight's stream along with loops, containers, and maybe some comprehension stuff.
25
u/FriendlyRussian666 Feb 20 '21
Struggling with ideas. All the tools are in front of me, but of what use if I can't think of anything to code.
Also struggling with direction. I love coding and problem solving, I tried web dev, net sec, automation, data visualisation and I still can't decide on a path. I love to come up with silly ideas and then code away for hours to solve problems after problems that I came up. Obviously all of that without a real use case. Would love to have a job related to coding, but none of the directions seem interesting for me. Code a backend for a site? Sure, sounds fun, but after doing it for the nth time it becomes boring. Make some blue/red team tool? Cool, but not for me. Visualise data of 10 million customers to provide feedback on target audience specifics and relations? Sure, can do, but again, booooring for me.
I wish I found a direction that utilises coding, is interesting to me and for which someone would pay, but so far no luck.
Peace to you all and hope you get through the struggles!
7
Feb 20 '21
Also struggling with direction.
I feel this. It's such a huge industry (tech in general - dev/IT/any mix of the two). Just one field has like 100 sub-fields. Then a few more subfields below that. Just keep reading up and talking to people and taking interviews and asking the right questions and a path will emerge.
I'm on the same journey but month after month what I think I wanna do becomes more clear.
→ More replies (2)2
u/RaidZ3ro Feb 21 '21
Find someone who's not a programmer but does need computers to work, ask them about their most time consuming (or whatever, problematic) work, and then solve it with your software.
22
u/Ijustlikepotatoes Feb 20 '21
Goddamn decorators...
I don't get it one bit. I've used it in flask a bit but honestly, I have no clue on how exactly it works.
FeelsConfusedMan
7
u/keraj93 Feb 20 '21
14
u/Ijustlikepotatoes Feb 20 '21
Me when I read python code:
"Mhm yes, oh yeah that. Yep I know some of these words"
Me when I see the @ :
"HnnnngksjdjdkddokdAaaaAwtf"
→ More replies (2)→ More replies (4)7
u/dupelize Feb 20 '21
Decorators just wrap a function. That means they take the function as an argument, do something, call the function, do something, and return. Depending on the decorator one of those "do somethings" might be nothing.
If you have something that you might want to do to modify a bunch of different functions, a decorator might be the way to do it.
If used sparingly, they're a great tool. IMO, flask over does it a bit.
3
u/NightSkyth Feb 20 '21
And what's the point? Is it something like you don't want to modify directly your function by being too intrusive for instance?
→ More replies (3)6
u/Moikle Feb 21 '21
possibly something like a certain behaviour that you want to happen before and/or after multiple functions, and you don't want to have to rewrite it for each.
They are great for debugging. Maybe you want something to time how long functions take without actually modifying the function itself.
Really though, the trick is to learn how they work, and a couple of tricks you can do with them, and suddenly you will start coming up with your own uses for them.
7
Feb 20 '21
I think my biggest struggle at the moment is learning how to break apart a module or framework to figure out what I want from it. I think it would be cool to see a tutorial that focuses more on the process of finding the information you need rather than just showing you how to use a framework.
5
u/nooberrypi Feb 20 '21 edited Feb 20 '21
Finding out how to use lambda, map, filter, classes and decorators to solve a problem. I usually just use normal functions and list comprehension everywhere. Finding real world use for what is considered intermediate in Tech with Tim's "Mastering Python-everything you need to know to become python master" and applying them is a pain unless someone explicitly points it out.
PS:I'm a RPA/Data science dev.
2
u/MaraudingAvenger Feb 21 '21
Lambdas are just throwaway unnamed functions that do one thing; they're only allowed to have one statement in them.
Basically if something is not worthy of being a named member of your program that you'll reuse, it's a candidate for lambda-hood. Specifically with map and filter, sometimes lambdas are the only thing that makes sense.
list_o_tups = [ (3, 5), (2, 8), (1, 4), (20, -2), (-1, 6) ]I have that list o' tuples above, and I want to filter it to only the tuples where the first number is divisible by two. I could create a function and pass that to
filter, but I'm never going to use that function again, so why clutter up my code/global namespace with that?>>> def first_thing_divable_by_2 (tup): ... return tup[0] % 2 == 0 # returns True or False >>> list(filter(first_thing_divable_by_2, list_o_tups) [(2, 8), (20, -2)]Instead it's probably better to use a lambda that I'm not going to save:
>>> list(filter( lambda thing: thing[0] % 2 == 0, ... list_o_tups)) [(2, 8), (20, -2)]Lambda syntax is just
lambda <what it's gonna get> : <what it do>
filterandmap(andfunctools.reduce, andsorted) all take a function as an argument and then apply it in some way to all the objects of the iterable you feed them.Let's say that
list_o_tupsis really a list of points on a graph I'm making. If I want to shift all the points up one and right one, I could do:>>> list(map( ... lambda tup: (tup[0]+1, tup[1]+1), ... list_o_tups)) [(4, 6), (3, 9), (2, 5), (21, -1), (0, 7)]instead of:
>>> def add_one_to_both(tup): ... return tup[0] + 1, tup[1] + 1 >>> list(map( ... add_one_to_both, ... list_o_tups)) [(4, 6), (3, 9), (2, 5), (21, -1), (0, 7)]2
u/MaraudingAvenger Feb 21 '21 edited Feb 21 '21
--also I realized in my response I focused on the how instead of the why. Fellow DS guy here.
I should say, for things like transforms (I want to change all these things in some way),
mapis the way.For combining long things into one thing (works on iterables full of strings as well),
functools.reduceis the bee's knees.I don't use
filterall that much, tbh.Classes -> when they make sense and don't overcomplicate things! I like to use API wrappers to simplify things. Let's say I'm going to look up terms on Wiktionary, I can wrap that code into a Wiktionary object and do something like:
w = Wiktionary() w.lookup('bananas')so I don't have to deal with either a bunch of functions, or a bunch of imperative code to do big lookups. Also that way I can share the Wiktionary class (or can publish wiki.py) to some internal repo, and other people can use it/don't have to reinvent the wheel when they are going to query wiktionary.
from wiki import Wiktionary w = Wiktionary() w.lookup('bananas')decorators -> almost never, but there are some big exceptions -- one decorator I probably overuse is one that I made to warn instead of error. It basically wraps a function in a try/except block, and pipes any exceptions to stderr. I use it to wrap calls to my company's notoriously janky internal APIs, so my program doesn't break because the API sucks.
→ More replies (1)
4
u/mostwant_ded Feb 20 '21
The idea in my head is to automate the more tedious tasks on my favourite game, then (if by the grace of God stick with it long enough) move on to the more cool(er) like having the script do one massive task, like completing a raid, with the data that I have provided.
The first problem is that I'm still quite new to Python, and automating even more, I suppose where I should start is by creating basic scripts for general pc tasks? But even here I get quite stuck, because, like, how??
Anyway the game is called old school runescape for those intrigued, we have a massive botting problem within the game but some have managed to go from automating cutting logs to scripts that will generally do anything in the game all whilst learning at the same time.
Kinda cool if you ask me
Edit// tl:dr = someone teach a noob how to bot pls
→ More replies (1)3
u/MaraudingAvenger Feb 20 '21
pyautogui! if you want to automate key presses and mouse movements, it's hilarious to debug, and very fun!
→ More replies (2)
4
4
u/Moikle Feb 21 '21
That I will never finish a project if I start 3 new projects partway through each of my other existing projects.
4
u/barryhakker Feb 21 '21
I’d love to see real life examples of concepts (mostly looking at you, OOP). This came up in a thread earlier but for some topics there are great practical tutorials that show you real life applications (e.g. a Flask tutorial where you build an actual website with tons of functions) whereas when it comes to OOP the examples come down to “YOU CAN MAKE CLASS DOG, DOG GO WOOF!” or if you dig a bit more you always get to the RPG example. So what if you don’t care about making an RPG? No other examples? There are of course and I remember seeing a video that used something like a map app as an example but those are rare. More examples of people using it in real life would be great.
→ More replies (4)2
u/Ne0_1 Feb 21 '21
I have been doing the MIT OCW courses myself with great success. The problem sets are challenging and fun to build. I recommend starting with the 6.00SC course. Specifically, for OOP psets 6, 7, and 8 are great and you learn how to incorporate OOP. I have never had success just watching tutorials. I need to write my own code to learn and incorporate the ideas I learned. They also go over Python implementations as well.
1
u/grouptherapy17 Feb 20 '21
I guess its for me its just that the whole programming world feels so alien to me.
I am so used to being good at understanding business terms and concepts that stuff like Recursion, OOPS etc just does not make any fundamental sense to me.
1
u/Nythious Feb 20 '21
Do you think it's the jargon that's holding you back or the technical side of things?
2
u/grouptherapy17 Feb 20 '21
I think its the frustration of feeling so stupid and blank. I have tried to give it time but I keep quitting.
2
u/MaraudingAvenger Feb 21 '21
This is why I hate it when people say "______ is easy" (Python, JavaScript, whatever)
Some of the concepts are maybe "simple" i.e. the opposite of "complex", maybe, but I hate it because it makes people get down on themselves for not understanding something -- this is not some deficiency with you, you're literally learning another language. Instead of Spanish, German, Chinese, you're learning a weird meta-language so you can communicate with some melted sand with little metal bits stuck in it (the CPU), to instruct it how to do what you want.
Don't get down on yourself if it's not clicking immediately, and don't give up hope -- u/Nythious still calls tuples "tuh-ples" instead of the infinitely superior "too-ples", and there's no cure for that, I've been told.
→ More replies (1)
1
u/Athenas-Helm Feb 20 '21 edited Feb 20 '21
Still very much a beginner, but comparing similar values between two lists (and returning a list of common values) is throwing me through a loop and feels a decent step up from other things I've practiced. Is there a better solution than
indexor = 0
common_list = []
for element in list1:
if list1[indexor] in list2:
common_list.append(list1[indexor])
indexor += 1
else:
continue
return(common_list)2
u/Nythious Feb 20 '21
There's a very sexy way to do this if you convert those lists into sets but if you're destined to using lists then you'll want to switch out "if list1 blah in list 2" with "if element....". That's my hint for you. Edit: on my phone, sorry about terrible formatting!
→ More replies (2)→ More replies (2)2
u/keraj93 Feb 20 '21
I assume that the code is a part of a function, otherwise, the return statement will cause an error
if you iterate directly over the elements with
for element in list1then you don't need theindexor. You can use the ´elementto check the if statement, like this:if element in list2:and common_list.append(element).Also a shortcut:
intersection = list(set.intersection(set(list1), set(list2)))`→ More replies (1)
3
u/ffrkAnonymous Feb 20 '21
Mine is a subjective difficulty. I've been practicing Test Driven Development from the testing goat book. Following along in the book is not an issue. But when writing my own code from scratch, I'm not sure how granular/piecemeal to make my tests/functions. And the "don't test constants" I understand, but don't quite know how to put into practice. Like how should (or not) test helloworld.py . And eventually, I'll need to test graphics (e.g. tkinter) which does stuff but not in the beginner test units of value-in begets value-out .
→ More replies (2)3
u/MaraudingAvenger Feb 20 '21
I'm one of the weirdos that doesn't worship the goat. If you're doing a massive project, I completely understand how writing your unit tests first and then programming to those unit tests makes a lot of sense, to keep a team focused on the same outcome... but.... for personal projects, or projects where I don't have a huge idea of the overall shape until I'm about halfway through, it's a total motivation killer and way overcomplicates something that I'd rather get going/make real progress on.
I think the right answer is probably, "make your tests as granular as you're comfortable with," or something along those lines -- good ideas are good, until they're not.
→ More replies (1)
3
u/seanpaul9000 Feb 20 '21
Trying to understand oop/ classes right now. I watched all of Corey Schaffer’s series and a tech with Tim tutorial... still was a bit confused. Restarted Corey’s series and things are starting to slowly click.
Would love to find a good project to work on to help me understand but not sure if I could actually do one solo dolo yet
→ More replies (5)2
u/Ne0_1 Feb 22 '21
Check out MIT OCW. Look up class 6.00SC and the problem sets 6, 7, and 8 are great projects for oop. The instructions for these problem sets tell you everything you need to know and they include all code you need to get setup and going. A great way to incorporate the Monte Carlo Simulation technique. Basically using an approach of randomness to solve non-random problems. If you want to be a data scientist or data engineer there are a bunch of useful concepts here.
3
u/skarizardpancake Feb 20 '21
I am struggling a lot with graphing data using matplotlib. I’m not necessarily sure when to use which type of graph and why. Also not sure when a data type should be converted to another type (such as it’s an integer type but needs to be classified as a categorical), but I know this varies depending on the case study and data that you’re looking at. My course has moved on to scaling/normalization and imputing missing values, but I’m still stuck on what I mentioned.
2
u/MaraudingAvenger Feb 21 '21
Oh man, this one hits close to home.
I think the first thing is the categorical vs. numerical -- basically categorical data, we don't care if the field we're looking at contains a number, a string, or something like that; that number/string means something. If you're working with that awful fuel economy spreadsheet that DS courses love so much, a car's type ("sedan", "truck", "hatchback", etc.) would be categorical. What if that was a number instead? If it was 1, 2, 3, we wouldn't care that it was a number, because the number doesn't represent a count of something; it just represents one of a number of categories that the vehicles might fall into. So that we don't accidentally treat that category like a number and maybe add something to it on accident, we could make it into a string instead.
With graph types, that is far more subjective than many instructors will admit. Really, if you can convey the information you want to convey with the combination of shapes and colors you create, then it's doing its job. I spend so much time tailoring things to certain color schemes, sizing points and adjusting alpha, etc. that ultimately has very little bearing on the overall presentation. This all boils down to "don't use a pie chart" basically, lol. I think the biggest thing is just to know what's out there (browse d3js.org front page to be inspired), and choose something that you like that communicates what you want it to communicate.
→ More replies (1)
3
u/temisola1 Feb 21 '21
How yield works.
2
u/MaraudingAvenger Feb 21 '21
Generators are cool!
They basically
yieldone thing at a time, and then stop until something tells them to roll out the next thing. They only dispense things when somebody asks, and then they go back to the beginning prepping for the next loop and forget everything that just happened, so they're nicely memory efficient as well.There aren't any tuple comprehensions in python. What would give you a list with square brackets will give you a generator if you use parentheses:
>>> [x for x in range(5)] [0, 1, 2, 3, 4] >>> (x for x in range(5)) <generator object <genexpr> at 0x0000024AB1234CD0>That comprehension is basically a generator lambda. You can make the same thing like this:
>>> def gen(): ... for x in range(5): ... yield x ... >>> gen() <generator object gen at 0x0000024AB1234E40>you can make a list out of them:
>>> thing = gen() >>> thing2 = (x for x in range(5)) >>> print(list(thing)) [0, 1, 2, 3, 4] >>> print(list(thing2)) [0, 1, 2, 3, 4]But now those generators have been used up:
>>> print(list(thing)) [] >>> print(list(thing2)) []There's nothing in them any more; they have yielded all of their things and are empty.
3
3
Feb 21 '21
Still only a few weeks in but sometimes struggle with how the logic works while loops/nested for loops.
Been doing a lot or codewars/codingbat exercises but can end up either doing things in an unnecessarily complicated way or just wrong.
3
u/lucadenhez Feb 21 '21
Thanks for helping us with some concepts we are struggling with! I would say one thing that’s pretty hard for me is grasping the concept of asynchronous methods and multi-threading. Like one question I have is does python only use one thread normally until I ask it to use multiple threads? Is the only advantage performance? And why use async over sync? All general questions like that.
→ More replies (1)
4
u/Corogue Feb 20 '21
I'm currently taking a cloud computing course and struggling with simple programs like map reduce. I believe my knowledge in Python is weak and holds me back from progressing in this course. The websites I've been to in the past to learn python are too rudimentary (e.g, codecademy, freecodecamp) and there are very few cloud computing resources to learn from out there.
tl;dr, we need more resources on learning Python for cloud computing.
3
u/MaraudingAvenger Feb 20 '21
Is it more the *how* of how map + reduce is affecting the data? Or is it more in the context of cloud computing (dealing with something like pyspark + RDDs, specific APIs, etc.)?
edit: totally agree that there's a serious dearth of python + cloud material out there.
→ More replies (2)
2
u/oderjunks Feb 20 '21
ctypes and win32 apis
Specifically BthProps.cpl
2
u/MaraudingAvenger Feb 20 '21
trying to control a bluetooth device using python? Are you using pywin32?
→ More replies (1)
2
u/Chreiol Feb 20 '21
PySimpleGUI. The documentation is difficult for me to follow. Any YouTube tutorials people recommend?
I’m ultimately trying to port a table dice game I just finished in Python into a GUI.
2
u/Sporocyst_grower Feb 20 '21
I have problems with oop; i still dont know how to create an object that doesnt admit, pej, an str value for a attribute that should be numeric
2
u/Academy- Feb 20 '21
I am having a hard time finding a good place to learn the more advanced Python stuff. I want to start writing backend, security, apis and network modules. I mainly want to learn this to be able to manage and work with my own MLOps setup. Any suggestions?
2
2
2
2
u/PartiZAn18 Feb 20 '21
Everyone is so far ahead of me and I'm just starting on functions on Zero to Hero bootcamp 😔
2
2
2
u/jclocks Feb 20 '21
Classes and objects. Never got far enough with a language to start putting this to use so it's a bit of an uphill climb with it. I need a good moment to really sit down with this concept and study it.
2
u/ThighSaveLivess Feb 20 '21
Figuring out how you can convert json to an excel format. It's quite complicated to format it correctly.
→ More replies (1)
2
2
u/shoguneye2 Feb 20 '21
For me, it's recursion. I understand the idea but can't wrap my head around what's happening. Particularly with the Towers of Hanoi problem. After lots of YouTube tutorials I still feel defeated.
2
u/Iorkh4n Feb 20 '21
Discord.py stuff, I'm creating a DnD discord bot but am still a complete python rookie so this is hard but enjoyable. Managed to get a functional but very basic character generator (doesn't yet do any racial, class, or background bonuses) going that I've used for the dnd game I run to roll up NPC adventurers.
2
u/namyggis Feb 21 '21
I cant come up with a good project to do next. I've just finished a command line type rpg to learn the basics of lists function, classes, loops, and things of that sort. I've thought about trying to make something with a gui but things like pygame seem like a huge leap for me.
2
u/MaraudingAvenger Feb 21 '21
Have you considered making it into a web-based game? You could serve up a page with Flask, and have the page communicate REST API style with the server for all the game logic. JS isn't terrible for animating things on a <canvas> element on a webpage, and if you really wanted to go all out you could do something with WebGL -- you would get some exposure to a second programming language at the same time -- could be fun!
→ More replies (1)
2
u/jcgthomas Feb 21 '21
Classes and init. Since then have learned JavaScript and using 'this.' so feel like returning to Python won't be quite as hard
→ More replies (2)
2
u/Debunkthebed Feb 21 '21
Navigating pandas dataframes just isn't intuitive to me. I've had a lot of headaches over accessing individuals tired, columns, or specific locations. I don't get using loc iloc etc.
2
u/MaraudingAvenger Feb 21 '21
We've been planning to do a stream on pandas for awhile now -- both u/Nythious and I use pandas on the daily. Pandas is definitely its own beast, and has some really strange syntax in the context of whatever is considered "normal" in regular python.
if you want to play with the simple df I'm using for the below examples, it's just:
import pandas as pd df = pd.DataFrame( {'col_1':list('abc'), 'col_2':list('def')} )that
dfthat looks like this:| col_1 | col_2| | 0 | 'a' | 'd' | | 1 | 'b' | 'e' | | 2 | 'c' | 'f' |
locandiloclook at the index column, and return the row at that index. The index column in this case is integers, sodf.loc[1]anddf.iloc[1]are the same, so it doesn't matter which one you use; they do the same thing -- they give you a Series object representing the row at that index.A Series object is basically a mini-dataframe that consists of one column, and has a whole lot of the same functionality. When we get the row from index 1 back using
df.iloc[1]up there:col_1 b col_2 e Name: 1, dtype: objectPretend we turned the df sideways, so now the row at index 1 became a column. It messed up the indexes too -- now the thing at integer index 0 has an index of
'col_1', and the thing at integer index 1 has an index of'col_2'.You can select that thing if you want:
>>> df.iloc[1].iloc[1] 'e'that is -- df.iloc[1] calls up the row Series, and the second .iloc[1] goes to integer/index location 1 in that Series.
but here's where .loc comes into play. The index is a thing that's not an integer, it's a couple of strings -- 'col_1' and 'col_2'. You can use those if you choose:
>>> df.iloc[1].loc['col_2'] 'e'So there we went down the rows first, then across the columns to select a cell. It's a bit easier to go columns->rows, though. The syntax for that is just (2 examples):
>>> df['col_2'][1] # Series support list-like indexing 'e' >>> df['col_2'].iloc[1] # or .loc if you want 'e'All they're doing is giving you multiple ways to get at the same thing.
2
u/MaraudingAvenger Feb 21 '21
--also, if you want a slightly more intuitive/visual way to navigate/edit dataframes, check out Qgrid. Qgrid makes a df display under a cell in jupyter as a sortable, editable table (like a spreadsheet, basically).
2
Feb 21 '21
State importing, exporting in classes. No idea how the original develop did it.
Also abstract classes. I made one but not fully sure why.
Learning a lot of advanced oop on the job.
→ More replies (1)
2
2
u/jiavlb Feb 21 '21
I am having problem understanding the relation between python and C. The packages that python needs, glibc, alpine or debian docker image for running python (i know docker but these small details sound how to choose a base image is not clear to me). These are the words in the conversation of my senior devs that I do not understand. Can someone help.
2
u/MaraudingAvenger Feb 21 '21
So, you may already know, but just in case: Python, that we're using to interpret the stuff we're coding in text files into instructions for the CPU to execute, is a program written in C. There are other implementations of python -- Jython, Cython, and others -- that are written in other languages and serve other purposes. The big thing is that Python is just an interpreter that takes text strings, evaluates what those mean, does a thing, and then reads in the next string.
There are many libraries that are written in C, and then provide Python an API to use to talk to the C code. Pandas and numpy are examples of these. The big deal about some of these packages is that they need to compile to be usable; i.e. you need
glibcso that python can use some of the basic C functions that it needs to interact with the linux distro that you're including in your docker image.It's also possible to write your own C extensions for Python, and there's a pretty thorough explanation of how to do it in the python documentation. You don't need to read/understand all of that -- just know that the code you're typing by itself is not something a computer will know how to run; the python interpreter does all of the translating between your code and machine code based on a set of instructions written in C.
→ More replies (1)
2
u/0nly0bjective Feb 21 '21
Not sure how helpful this will be because I literally JUST starting.. but using some stuff from Udemy (the codex, the guys name is Avinash).
I feel like it’s basically just copying what he does without any real explanation of what it actually means. Is that how they all are? Maybe I just need to start at a more basic level
2
u/MaraudingAvenger Feb 21 '21
bad tutorials don't teach you anything -- and presenting concepts without explanation is not very helpful when it comes to programming! I'd suggest trying to find a different class/tutorial, or trying to get involved with a well-known MOOC of some kind. You're also welcome to join any of the streams we do (check out u/Nythious's post history for stream links posted on r/Python). Hopefully you can find something that'll get you the knowledge you're seeking in a format that you can digest well!
2
u/mugobsessed Feb 21 '21
Setting things up properly. Most courses and tutorials skip right over this. I'm really struggling with env variables, virtual env, git, project lay out, paths, etc.
2
u/Yungpastorphillswift Feb 21 '21
I'm having a lot of difficulty with graphs right now. I have a column that displays only 2 different values, "1" and "3". 1 representing yes, 3 representing no. I just want to make a bar graph that visualizes the difference in their amounts, and I cannot for the life of me figure it out.
→ More replies (1)
2
u/MyUsernameIs3pic Feb 21 '21
Recursion and Id like to learn serialization using databases if that’s even a thing
2
2
u/Yetsubou Feb 21 '21
I have to find out how to change huge XML files to sqlite so that I can make structured json files for an application. Also I have difficulty finding ways to use stardict dictionary files and transform them into structured json or make them useable for kindle. Basically it would be amazing to know how to transfer many dictionary files into different formats or how to scrape an internet source to add info to a dictionary like example sentences in a useful format and then transform then to a structured json file.
2
u/MaraudingAvenger Feb 21 '21
You can use
xml.etree.ElementTreeto parse and navigate XML. Check out the docs for some good code examples.Changing what you parse into sqlite syntax is a matter of string formatting -- I highly recommend getting familiar with the string formatting mini-language if you have a chance -- that is everything after the colon in the squirrelly brackets in:
"{name:-^30}".format(name="middle")I assume you're interacting with your sqlite database using the sqlite3 library (or maybe pandas).
A JSON is almost exactly a python dictionary, written out in a string, the way it looks when you write one out in your code. The
jsonlibrary can parse json strings coming in into python dicts (json.loads), or dump python dicts out into json strings (json.dumps).Basically combining all of those things should give you the ability to go from huge XML files to sqlite to JSONs! If you want to share more specifics I could maybe help point the way.
As for stardict files, from what I can gather from https://en.wikipedia.org/wiki/DICT, the format looks pretty approachable -- you should probably use a good regex combined with some string cleanup (probably also using regex) to extract definitions from the files.
Hopefully that's enough to get you at least some stuff to Google!
→ More replies (1)
2
u/JohnZenRider Feb 23 '21
I like what everyone had to say here. I think for me it is a bit different. In the beginning, I could learn like there is no tomorrow. I just absorbed information readily. Now, after being in the industry for over 32 years, I have slowed down a ton. I find it hard to learn new things. I am starting the process of learning Python since I have several Raspberry Pi PICO boards and what to use in my projects but learning MicroPython has been a little challenging. As I have gotten older, I don't seem to learn as easily as I used to. I also have tinnitus and have heard that this has an effect on the brain and learning. If anyone knows how to get rid of it, I am all ears!! (yes, pun intended). Great topic.
1
1
u/Ecstatic-Highway1017 Jul 15 '24
When I started learning python online from youtube videos, I was not able to create notes while learning.Notes helps you to note down your understanding like what you have thought and when you don't create notes it's tough to go back to your thoughts and revision of your understanding of the code.
I started using OneBook extension and my experience is very good with it, it helps you in taking notes in just 2 clicks, you don’t even have to move to another tab to take notes.
Chrome extension link : https://chromewebstore.google.com/detail/onebook/loecbgjbgcgjkhibllnjokjefojoheim?utm_source=rtc
1
1
u/WarpWing Feb 20 '21 edited Aug 28 '24
automatic hateful numerous glorious workable murky theory obtainable aspiring grandfather
This post was mass deleted and anonymized with Redact
1
u/dddash Feb 20 '21
The basics! When I first started learning programming /Python I tried to consume as much material as possible. But I wasn’t actually taking in anything. If I would’ve just focused on the basics (variables, loops, if statements ...etc), I wouldn’t have been constantly lost.
I actually just started a YouTube channel to help talk through my projects and problems. It’s basically from the POV of a beginner for beginners. But I like said, it’s more for myself than to become a successful YouTuber or whatever.
But this all started the other day when I was thinking “am I the only who is still struggling with applying classes?” I know the answer is no.
Anyway, as I talk through some stuff and acknowledge why I struggle with some things. I am realizing why and also coming to terms with that it’s okay. This stuff is hard.
1
u/vercig09 Feb 20 '21
i struggle with decorators... havent managed to include them in any project I’ve done. also, i dont understand the concept of context managers
1
u/Lin1232020 Feb 20 '21
List comprehension. I want to use it more, but I always forget to use it. But when I do remember to use it, I struggle with the syntax lol
1
1
Feb 20 '21
I struggle with the broader concept of "programming". I always think I'm not following best practices. I'd like to watch a professional approach a problem from start to finish including their work setup and thought process. It just feels like there's so much to grasp that it's overwhelming
1
1
u/kabooozie Feb 20 '21
Not particular to Python, but two general things:
“handlers” for asynchronous apps
using APIs (like general tips for how to learn a new API and use it effectively)
1
Feb 20 '21
How to make proper unitary tests for a commit. Not the technology... but the idea process of what to test and what not to test for.
1
1
u/praise_jeeebus Feb 21 '21
Lambda functions. How do you have a fake function, and what are the use cases? I can't seem to wrap my head around it no matter how much I look at w3schools.
1
1
u/casino_alcohol Feb 21 '21
Django
I kinda gave up on it. But I would love to learn hours to make a website
→ More replies (2)
1
u/LordWaffle27 Feb 21 '21
Does anyone know how to incorporate a summation?
I'm trying to build a financial calculator. So far, I've managed to include succesfully many modules (capitalization, discounts and constant rents) and right now I'm working on the Net Present Value.
I know the formula, I know the fundamentals, but I don't know how to include it. Basically, I need to make an input statement to get many cashflows, then I'd had to divide those cashflows by this expression: (1+i)^n
Being:
i= interest rate
n= ordinal number of each cashflow
Co= Initial capital
It goes something like this:
NPV = -Co + (Cashflow1/(1+i)) + (Cashflow2/(1+i)^2) + (Cashflow3/(1+i)^3) + ..... + (Cashflown/(1+i)^n)
I'd really appreciate any help I could get.
2
u/fernly Feb 21 '21
If you ask Doctor Google "npv in python" as I just did, you find that the well-known numpy library has an NPV function. However translating your formula into Python should be a doable exercise.
One problem you are likely having is that it starts with a sub-problem that is only tangentially related: how to get user input of a series of cash flows, or to put it another way, how to get user input of a list of decimal numbers.
If you start by writing a function for that, and debugging it, you will have a handy little piece of code you can probably use later in other projects.
def get_list_of_numbers( prompt ): '''return a list of zero or more numbers from user input''' '''input is a string to prompt the user''' number_list = [] print(prompt) print("hit return to end") while True: # i.e. until we break out pass # replace with code # end of the loop return number_listWhen that is working, you can start solving the original problem with
capital = input('Starting capital: ') cashflows = get_list_of_numbers('List of cash flows')and then where in your formula you have "Cashflow[1]" you might think you could write
cashflows[1]-- and you could except for the gotcha that Python indexes lists starting with 0. But here's a trick. You could insert the negative of the initial capital as the 0th item in the list,cashflows.insert(0,-capital)and that's kind of neat because really,
-Cois the same amount as-Co/(1+0)^0(dividing by 1 doesn't change it), so now the starting capital isn't a special case, and you just loop over the integers 0..length of list less 1, dividing each list item by its index plus one, to the power of its index and adding them up. Easy!
1
u/standardtrickyness1 Feb 21 '21
For me it's mostly everything goes in one ear and out the other. I would like to commit a small working python lexigon well enough to memory to be fluent.As small as possible for now I can't seem to remember anything. Afterwards to be fluent in a bit of numpy.
1
u/negike360 Feb 21 '21
Let’s see, dictionary comprehension and nested dictionaries. I’m starting to grasp the syntax of dictionary comprehension but it’s still kinda hard to create my own. Getting information out of nested dictionaries is also pretty confusing because I’m struggling to keep track of the levels I go down (kinda like in inception).
I also notice that my code is very redundant. I’ll code a solution and when I look at the answer key, I think “Crap, that’s genius and makes so much sense! Why didn’t I think of that??” But as a beginner, this one will probably just correct itself with experience
1
Feb 21 '21
I find it difficult to be creative with python. I have a good understanding of how to do the things I want, such as a pipeline for machine learning, but building custom functions I get stumped and have to use Stack and Reddit. I have a hard time thinking like a computer...because I'm not one (at least I don't think)
1
u/upthewaterfall Feb 21 '21
I’m brand new to python and coding in general. What is the most efficient way of learning to code and python in particular?
1
u/pplesspp Feb 21 '21
Trying to make a beautiful API that is deep and useful but people keep wanting access to lower and lower level stuff forcing my code to become a spaghetti monster.
1
1
1
u/SconiGrower Feb 21 '21
When do you break up code into multiple files and then how do you access code in other files? Right now I can only build a monolithic codebase, not that any of my projects are actually that big.
2
u/MaraudingAvenger Feb 21 '21
This is a kind of wonky description, but it gets the point across: https://pythonhowtoprogram.com/how-to-split-and-organise-your-source-code-into-multiple-files-in-python-3/
Basically, you can import functions, classes, etc. from any .py file in the same directory as your main python file (and it doesn't have to be named main, or anything like that).
If you have one file called "mymodule.py" and inside it you have defined some function called "my_func", you can do this in another file in the same directory:
import mymodule # it's just the file name minus ".py" mymodule.my_func()or something like this:
from mymodule import my_funcIf you want to put the .py file you are importing things from into a folder, python treats that like a module too:
from folder_name.file_name import functionHope that helps!
1
1
1
1
u/tapherj Feb 21 '21
Using Docker and Python to setup a dev environment.
Projects that are meaningful, confidence boosting and allow for integrating different aspects of Python. I think I am stuck in tutorial pergatory - any topic I am interested in is a chore to get through due to an outbreak of "wtf did he just say?". Seriously, annunciation, spoken grammar and punctuation as well as pace help. And please, no mote "Jero". Z z z Zero.
1
u/totemcatcher Feb 21 '21
How to apply more advanced features of python even though I understand how they work. It may be fully functioning python code, but my projects could have just as easily been written in ANSI-C in the 1980s. ;)
1
u/CordyZen Feb 21 '21
Machine learning, no matter how many times I try to learn it i just fail. I really want to get straight to the big applications of ML but that means I would have to stary small which is something i struggle with
1
u/Forschkeeper EE Feb 21 '21
Concurrency in a clean way - Threads, multiprocessing and asyncio.
How to pass values from A to B, how to deal with exceptions/errors, how to close/kill them in a clean way.
1
u/ionezation Feb 21 '21
Now, I am struggling with Auth stuff in Django ... just need to learn more about it in few days. I am working on vanilla PHP project and again stuck in Auth matters like username login change the sign up or register to profile and sign out :)
1
Feb 21 '21
I can write and understand code. Solve the CP problems but don't know how to do anything useful with my what I've learnt.
1
u/Volumunox Feb 21 '21
coming from MATLAB, the datatypes and structures and the when and how of going from one to another.
Array, lists, etc. Have different functions and behaviours associated with them when multiplying or building loops and throwing int, uint, float, etc. On top og that just boogled my mind. I am starting to get it though and i am definitely a better programmer for knowing it, especially now that i also have to use C++
1
1
u/WizTaku Feb 21 '21
Architecture. Most guides show some small example with the purpose to only explain that part. In a real world app you have to combine so many things to make it work. The bigger the app is the more complex and more important the architecture is. I scrapped so many projects because once it got big enough it was impossible to add new things and fix bugs without rewriting everything.
1
1
1
1
1
u/MrBananaLoca Feb 21 '21
Regex and sometimes I lack programming problem solving skill and creativity.
1
Feb 21 '21
OOP. Like, I get the concept of course. I also get why it’s better maintainable than functional Programming. But I have no idea how to actually implement OOP. I’ve been struggling to understand that stuff on and off for a year. I’ll take a real-world university course on OOP and hopefully I’ll get it then.
1
1
u/mo_leahq Feb 21 '21
The beginning of semester and the work and study required by school, then an episode of depression.i learnt the basics and was starting to learn object oriented programming of python, but I hope soon I will go back to learning python again.anyway,thanks for asking and offering help.
1
u/painlessblade Feb 21 '21
I'm very much a hobbyist, pretty new and have no training. I also know I'm trying to run before I can walk but that's just me and how I learn I guess.
I've made a few bots and and done some small things but the thing that's stuck in my head at the moment is trying to tackle machine learning, I want to make a bot that plays a game.
The tutorials are either made for scientists or just teach me how to classify either a dog or a cat.
I'm in no way saying the tutorials are bad, just that my understanding of them is a ways off of where it needs to be but I can't shake this idea and the frustration is killing me!
1
1
1
u/postgeographic Feb 21 '21
I am struggling with Pyppeteer. The documentation could do with some work. And all of three very basic tutorials.
1
u/hugthemachines Feb 21 '21
My problem is, when I get a thick book and try to read up on subjects I get super sleepy and lose my concentration very quickly. I also get a bit of light anxiety over the amount of time it will take to get through it and I start feeling like I will never get through it and lose motivation of reading the book at all.
I suppose I could use excuses like having a family and job and not having so much energy but I think I have been like this earlier too. The last book I read without geting tired was "Clean Code" but that is pretty interesting and easy to read.
It is problematic because there are things I would really like to know more about.
1
1
u/evol1knobi Feb 21 '21
I sometimes hit a wall when I see a deeply nested API that I'm trying to pull info from. I also have trouble with iterating through pages trying extract info from those pages.
1
u/stamp0307 Feb 21 '21
Seamless usage of Python scripts and libraries wherever you attempt to load and use it when the environment you work on is highly restricted on any manipulation to a user’s C drive or a server’s configuration drives.
1
u/BungalowsAreScams Feb 21 '21
Need to practice with pytest but I only have MacOS and the big surr update seems to have made it impossible to install :(
1
137
u/TheRealDangerPaws Feb 20 '21
GOING LIVE (in web app development)
Every guide, tutorial, video, blog post, etc... is all about learning the language, the syntax, how to build, this, that, or the other. It's all about building, creating, and so on. But I have never seen a single piece of useful information regarding moving from DEVELOPMENT to PRODUCTION and indeed beyond, along with all the common things to look out for, the quirks of different hosting providers, the checklists that people use to prepare, secure, and look after their applications.
Have I somehow missed or overlooked these or do they not exist?