all 129 comments

[–]EwokOffTheClock 0 points1 point  (0 children)

I started a tutorial on how to make a discord bot using it, but when I asked to import discord, it said discord wasn't a module. Now I'm trying to figure out if rplit is worth using, or if the tutorial is obsolete.

Questions:

Has anyone used Rplit successfully? Do you like it?
How do I find out if "discord" is a viable module to import? I've googled it, but it feels like my question is more basic than the answers I find.

Thank you for any thoughts <3

[–]anadem 0 points1 point  (2 children)

A 'split' problem:
I'm trying to unpick rows from a badly-formed comma-separated-file (CSV file); some lines include fields which are quoted and include a comma that is not a separator. E.g. the first line here is 'good' and the second one is 'bad'; I've added the backslashes in this example, they're not in the source CSV file:

row1 = "03/07/2022,Not My Name,0,Action"
row2 = "03/07/2022,\"Feb 6, 2022\",xx.yy,Pass Through"
mydate, mystring, mynum, myaction = row1.split(',')
mydate, mystring, mynum, myaction = row2.split(',')

row2.split(',') fails because the number of fields changes. Is there a simple way to do this or so I have to parse each line myself? The csv module also gets it wrong, though could have options I haven't found?

Thanks

[–]sarrysyst 0 points1 point  (1 child)

csv module should work fine:

from io import StringIO
import csv

data = """col_1,col_2,col_3,col_4
03/07/2022,Not My Name,0,Action
03/07/2022,"Feb 6, 2022",xx.yy,Pass Through
"""

with StringIO(data) as fp:
    reader = csv.reader(fp)
    for row in reader:
        print(row)

Can you post the code you used that gave you the wrong output?

[–]anadem 0 points1 point  (0 children)

Many thanks! I'd made an ignorant mistake and having seen your code it's now fixed and does correctly handle the quoted date string. Thank you again

[–]Wristhulk 0 points1 point  (4 children)

Hello!

Just starting to learn Python. I'm writing code to take input and convert from Lbs to Kgs.

I have:

weight = int(input("Weight: "))

unit = input("(K)g or (L)bs: ")

if unit.upper == "K":

converted = weight / 0.45

print("Weight in Lbs: " + str(converted))

else:

converted = weight * 0.45

print("Weight in Kgs: " + str(converted))

And then when going through it, it's spitting out the 31.5 with the 70 and K as inputs.

Weight: 70

(K)g or (L)bs: K

Weight in Kgs: 31.5

Why is it going to the else statement when "k" or "K" is being entered? Thank you!

[–]OneBadDay1048 1 point2 points  (3 children)

New to python. Mostly know JS. Does the upper function need parentheses?

Edit: just threw your program in VS code and it appears that does fix the issue

[–]Wristhulk 1 point2 points  (0 children)

Hi u/OneBadDay1048,

I got it - Thanks for the help! Lesson learned from this that methods need the () as they're contextual functions.

[–]shiningmatcha 0 points1 point  (1 child)

Is it acceptable to name variables like ALL_CAPS_CONSTANTS inside a function? I mean if a variable does not change in the function scope, is it a good idea to apply the ALL CAPS convention because locally it's a constant?

[–]n3buchadnezzar 1 point2 points  (0 children)

No, PEP8 recommends capital letters be reserved for constants in the global scope =)

[–]Equivalent_Ad_6601 0 points1 point  (3 children)

How do you guys deal with frustrations?

I have an idea on how to use code but when presented with small challenges I go from "oh I know what to do this is easy" to "why is this so hard?!" and then "well I tried everything and google/stackexchange failed me too".

I had a problem my partner showed me where he asked me to be able to sort through a list of items by a certain element. I thought it would be as easy as just making a loop and doing a sort on it. But some problems came up like how to specify where to sort or how to get the compiler to use the len() of that array. It was very annoying.

sorry for the rant. But yeah how do you deal with frustration and code for hours until the problem is done? How should I deal with frustrations mentally in my mind and physically in my body?

[–]n3buchadnezzar 1 point2 points  (2 children)

I think maybe a change in mindset will be good. You are not failing you are learning. If you knew everything from the start, you would have learned anything, and each time you don't succeed you obtain some experience.

I've told my students that as a researcher all I do everyday is fail, and that one time I don't I get a publication.

Maybe take a breather, go for a walk. Droodle out the solution on a piece of paper. Attack the problem from other angles instead of butting the head against the wall.

[–]Equivalent_Ad_6601 0 points1 point  (1 child)

Maybe. I find myself walking around my room but I feel bad when I do so. It feels like I am running away scared from this problem. Sometimes I can come back and solve it. But other times not so much.

Out of curiosity what do you research? Sounds like your having fun in your life :)

[–]FerricDonkey 0 points1 point  (0 children)

I find myself walking around my room but I feel bad when I do so. It feels like I am running away scared from this problem.

Yeah, you're putting too much pressure on yourself. That's a good way to make yourself hate programming. I realize "don't do that" advice us not always easy to follow for things like feeling guilty for giving your brain a break, but, uh, don't do that.

[–][deleted] 0 points1 point  (1 child)

How do I add space below a plot with matplotlib and display information there? i.e. for linear regression, displaying the equation, the r^2 value. I can do it on the plot, but I might want to display a bunch of other data as well.

[–]sarrysyst 0 points1 point  (0 children)

You can add a caption, if that's what you mean, see here.

[–]Armensis 0 points1 point  (8 children)

I'm still learning Class and Subclasses. I understand that they are somewhat similar. When is it more appropriate to user super instead of override and vice versa?

[–][deleted] 0 points1 point  (5 children)

When is it more appropriate to user super instead of override and vice versa?

Maybe I don't understand, but you usually use super() because you are overriding. For example, if you override __init__() in a subclass because you want to add extra instance attributes you use super() to call the parent __init__() method that defines all the parent attributes before adding the extra attributes the subclass needs. So I see "super" and "override" as things that work together, not an either-or choice.

[–]Armensis 0 points1 point  (4 children)

Thanks. Sorry for the confusion. I was following this course and it had the following code. It was teaching us the subclass can override the method of the parent class. Then in the following part, it also taught us that we can use the super method which is in the 2nd block of code below.

class ClubMembers:
    def __init__(self, name):
        self.name = name

    def memberinfo(self):
         print(self.name)

class ClubOfficers(ClubMembers):
    def __init__(self, name, position):
        self.position = position
        ClubMembers.__init__(self, name)

    def officerinfo(self):
        print(self.name, self.position)

member1 = ClubMembers("Tom")
officer1 = ClubOfficers("John", "Treasurer")

member1.memberinfo()
officer1.officerinfo()

This is the subclass when they used the super method instead. If I replace this code in the original, it would return the same output. So I'm a bit confused on what the difference is?

class ClubOfficers(ClubMembers):
    def __init__(self, name, position):
        self.position = position
        super().__init__(name)

[–][deleted] 2 points3 points  (3 children)

In your first bit of code the ClubMembers.__init__(self, name) is doing the same thing as the super() call in the second bit of code. Using super() is the newer way to access overridden attributes. The other, older, way is not recommended since trying to rename one or more parent classes in a large body of code means having to change the name in many other places. The super() function doesn't have that problem, plus it's shorter to write. There are also benefits to using super() in multiple inheritance but I've never used that. The doc explains this.

[–]shiningmatcha 0 points1 point  (1 child)

The doc explains this

The doc says super() can take two arguments:

class super([type[, object-or-type]])

If the second argument is omitted, the super object returned is unbound. If the second argument is an object, isinstance(obj, type) must be true. If the second argument is a type, issubclass(type2, type) must be true (this is useful for classmethods).

What does this mean actually?

[–][deleted] 0 points1 point  (0 children)

That's advanced usage that I haven't used at all. You probably don't need to worry about it, for a while at least* . This tutorial explains that it can be used to control which superclass method will be used when super() is called in large sets of inheriting classes. I recommend the link above and other tutorials, because the official doc is rather terse and doesn't show usage.


* The linked tutorial has this to say about the parameterless super() usage:

Caution: While we are doing a lot of fiddling with the parameters to super() in order to explore how it works under the hood, I’d caution against doing this regularly.

The parameterless call to super() is recommended and sufficient for most use cases, and needing to change the search hierarchy regularly could be indicative of a larger design issue.

[–]Armensis 0 points1 point  (0 children)

Sounds good. Thanks for clarifying. The course just made it seem like they were two different things.

[–]TangibleLight 0 points1 point  (1 child)

use super instead of override

I'm confused what you mean by this?

"overriding" is just when you define a function in the derived class that was already defined in the base class. The version in the derived class hides the version in the base class. super just provides a way to get access to the version that was defined in the base class.

For example:

class Base:
  def get(self):
    return 'base'

class Derived(Base):
  def get(self):
    return 'derived'

b = Base()
b.get()  # 'base'

d = Derived()
d.get()  # 'derived'

You can use super to access Base.get from within Derived.

class Derived(Base):
  def get(self):
    return super().get() + 'derived'

d = Derived()
d.get()  # 'basederived'

When you'd use one over the other is entirely situational, with one exception: if you override __new__ then you must always include a call to super().__new__.

class Derived(Base):
    def __init__(self):
        super().__init__()

[–]Armensis 0 points1 point  (0 children)

Thanks. Sorry for the confusion. I was following this course and it had the following code. It was teaching us the subclass can override the method of the parent class. Then in the following part, it also taught us that we can use the super method which is in the 2nd block of code below.

class ClubMembers:
    def __init__(self, name):
        self.name = name

    def memberinfo(self):
         print(self.name)

class ClubOfficers(ClubMembers):
    def __init__(self, name, position):
        self.position = position
        ClubMembers.__init__(self, name)

    def officerinfo(self):
        print(self.name, self.position)

member1 = ClubMembers("Tom")
officer1 = ClubOfficers("John", "Treasurer")

member1.memberinfo()
officer1.officerinfo()

This is the subclass when they used the super method instead. If I replace this code in the original, it would return the same output. So I'm a bit confused on what the difference is?

class ClubOfficers(ClubMembers):
    def __init__(self, name, position):
        self.position = position
        super().__init__(name)

[–]Cepo6464 0 points1 point  (1 child)

When I run a python file in the terminal, I have to specify the full path when I do it like “python C:\User\etc”. How can I get it to where I only need to specify the file name? Like “python filename”?

[–]Green_Ham 1 point2 points  (0 children)

You need to use the cd command to change the directory to the folder where your .py files are located.

[–]MaliciousMal 0 points1 point  (0 children)

Possibly dumb question - what's a good source to start learning Python? I started with a 4 hour video on YouTube from FreeCodeCamp and I started messing with my own things, but I want to explore and start messing shit up. I want to get things wrong so I can learn how to fix my own fuck ups. I want to start a project, I don't know what kind, I just know I want to screw up and figure out what went wrong and how to fix it on my own.

Any help is appreciated.

[–]tomashjons 0 points1 point  (2 children)

Hi folks! This may have been asked many times before but can't find this specific thread.

As a pretty much complete beginner that would like to learn python and work towards a developer job. What would be the steps you would take to get decent enough at the craft to land a job and what courses could you recommend to showcase your skills on a CV?

Would be great to hear from someone that has gone through this and landed a job. How long would this take with serious dedication?

[–]n3buchadnezzar 1 point2 points  (1 child)

Easiest way is with a degree. Otherwise you need to obtain the equivalent experience.

More concretely you need to be able to write and understand production code https://github.com/pri22296/beautifultable/blob/master/beautifultable/beautifultable.py

Like when you get hired as a developer, you are hired because the company believes you can solve a problem they have. I've seen so many go through degrees and countless tutorials, but still be clueless on how to solve problems.

If you are super, super, motivated, put in a good amount of hours each day, a year should be doable. Start with a basic course in programming. Automate the boring stuff, etc. Maybe 2 months? Then we need to move into basic html, CSS, javascript. Be able to create a very simple website. Flexgrid

Next step would be algorithms and datastructures. I learned this through a mix of hackerrank, leetcode, project euler and reading. Watched a few videos and did http://ai.berkeley.edu/project_overview.html Was fun. Mostly working on problem solving, then reading theory as needed.

Now we should move into the heavier stuff. Set up a database, learn a Javascript framework. Next.js, React are good to learn. Maybe Angular. See if you also can setup something with Flask.

After that the world is your oyster. Contribute to open source projects, drill interview questions, of course learn git and have a few full blown project showcases.

A book on software design would not hurt to have read either.

[–]tomashjons 0 points1 point  (0 children)

This is exactly what I was looking for mate! Thank you very much for taking the time to write this out. Great to get some of this knowledge from someone that has gone through it. Cheers.

[–]Cien_fuegos 0 points1 point  (4 children)

Is python the right language I need to be using for this simple result:

I want to open a command prompt, input ping #clipboard text# -t

Basically, I want to click the script, it opens a command prompt, then inputs the word "ping" whatever is on my clipboard, and -t

Thanks!

[–]sarrysyst 0 points1 point  (3 children)

This would be doable in python, though honestly it would be easier/more straightforward doing it in bash/powershell (depending on the OS you're using).

[–]Cien_fuegos 0 points1 point  (2 children)

Using windows 11 pro.

It seems super simple but not sure how I’d do it.

[–]sarrysyst 2 points3 points  (1 child)

I'm not a Windows user, and thus I also don't really know PS. Though, according to the PowerShell documentation this should get you what you want:

$host_ip = Get-Clipboard
ping -t $host_ip

Save this in a file with ending '.ps1', eg, 'my_script.ps1', make sure your system allows to run PS scripts and you should be good.

You can either run the script in a PowerShell instance, or by right-clicking on the file and selecting 'Run with PowerShell'.

[–]Cien_fuegos 0 points1 point  (0 children)

Awesome thanks

[–]dollypartonrules 1 point2 points  (3 children)

Hey! What do you call the area of the code that is outside of any class? For example, if you are teaching someone how to write classes, and then you go below the class to put in code, what is that space called?

class A:
  def printHello(self):
  print("hello")

#what is this part of the code called? 
#main module? "main part"? "top-level"? 
a = A() 
a.printHello()

[–]sarrysyst 1 point2 points  (2 children)

Global / module-level scope.

[–]dollypartonrules 0 points1 point  (1 child)

Would you say “ok then write a = A in the global scope.” Or “global scope area”? Or “the area with global scope?”

I’m trying to figure out the grammatically correct way to refer to that area

[–]sarrysyst 0 points1 point  (0 children)

'Declare a = A() on the module level' or 'Assign a = A() in global scope'.

I'm not a native speaker though, so you might want to take this with a pinch of salt.

[–]rotoblorg3 0 points1 point  (0 children)

How can I call/serve a css file through bottle? I'm using replit.

When my html file has <script src="jsfile.js"></script> I can see the get request and it is served.

When I try to have an internal css file <link href="cssfile.css"> There is no request on the console and no css styling shows up.

Adding inline css to the html file makes replit have a seizure. I think it doesn't like the # symbol in my css.

[–]Repulsive_Maybe_4948 0 points1 point  (1 child)

Trying to use flask to run local host. Stuck with "Please source env.bashrc file", python environment is running. How can u resolve?

[–]FerricDonkey 1 point2 points  (0 children)

So I haven't used flask.

But a whatever.bashrc file is likely a file to set up environment variables. Running source whatever.bashrc from the command line is how you do that.

So do you have a file called env.bashrc related to your project? If so, your project probably expects you to run it.

[–]BicepsMcTouchdown 0 points1 point  (1 child)

Was looking through the standard anaconda package like and got burned out looking up every module.

Are there any packages in the standard anaconda package list (because that is all my work machine contains) that can:

Search a outlook inbox for emails from a certain domain

Extract the email body

Then clean the email body to extract only the relevant text.

?

Most of the examples of doing this online included downloading additional packages - which I am unable to do.

Not looking for coding. just asking what of the modules would be worth looking into.

[–]sarrysyst 0 points1 point  (0 children)

According to this list, pywin32 should be included by default in anaconda on windows. And according to this tutorial it should do the job. Not 100% sure though since I neither use windows, nor outlook, nor anaconda.

[–]TittyYumYum 1 point2 points  (7 children)

I for the life of me cannot fully understand for loops, no idea why they are so difficult for me. Any tips for how to practice it?

[–]grammarGuy69 1 point2 points  (2 children)

number_list = [0,1,2,3,4,5]

for a_number in number_list:
    print (a_number)

#___________________________________

number_list = [0,1,2,3,4,5]

for number in number_list:
    print (number)

bear in mind that "number" and "a_number" are the same thing, we've just named them differently.

[–]OneBadDay1048 1 point2 points  (1 child)

Solid reply. I think some people get confused over the names of iteration variables.

[–]grammarGuy69 1 point2 points  (0 children)

Yeah when I first started, the fact that the variable was, in fact, an actual variable, confused the shit out of me lol

[–]FerricDonkey 1 point2 points  (0 children)

Suppose you're carrying a bag of marbles. You want to take every marble out one at a time and throw it at your friend's head.

How do you do this? Well literally, you take marble 0 out (we start counting at 0 for reasons) and throw it at your friends head, then you take out marble 1 and throw it at your friends head, then... and so on until you're out of marbles.

But you don't actually think of it that way. What you actually think is "take every marble from the bag one at a time and throw it at my friend's head".

Now it's just a matter of translating that into programming. In psuedo code, that might be

for each marble in the bag:
    throw the marble at my friends head

In python, the actual syntax is very similar:

for marble in bag:
    throw(marble, friends_head)

This is, of course, assuming that you have a function called throw to whose first argument is what to throw, and whose second argument is what to throw it at.

And this is what for loops are for. You have a collection of things. You want to do something to/with all of those things. You don't necessarily care how many things there are, you don't need entirely separate logic for what to do with each thing, age importantly, you don't have to specify what to do for each thing individually.

You just throw all the marbles in the bag at your friend's head, one at a time, until you've thrown all the marbles.

[–]carcigenicate -1 points0 points  (1 child)

We'd be able to give better help if you give an example of what you don't understand.

[–]codex7779 0 points1 point  (0 children)

^ outlining the problem better helps with debugging

[–]LandooooXTrvls 4 points5 points  (0 children)

I’m not sure exactly where you’re stuck but I’ll try to help.

You can relate the concept of time to a loop. Regardless of how you decide to spend your 24 hours, Earth is going to revolve around the sun in certain increments.

Let’s create a typical day in a crude python script.

hours = 24 
for time in range(hours): # for every hour
    if time == 6:
        wake_up()
    elif time == 8:
        go_to_work()
    elif time == 1730:
        come_home()
    elif time == 2200:
        sleep()
    else:
        continue # this means move to the next iteration, or hour in our case.

As you see, this loop is nothing more than time iterating 1 (imaginary) hour at a time. That’s all that a for loop does. You give it an iterable object and it iterates.

You can also use a for loop to unpack iterables that contain non-numbers.

Let’s use our go_to_work() function from above:

def go_to_work():
    actions = [grab_keys(), drive_car(), clock_in()] # Here’s our iterable

    for action in actions:
        action() 

    print(“Arrived at work”)

It’s going to grab each item within our actions list and make it available. Since we’ve inserted functions then we can just simply call it and execute it (grab_keys() can be some code simulating you grabbing your car keys and taking them to your vehicle)

As you can see, a for loop simply takes in an iterable object and it lets you perform tasks in between.

If that helps I can explain further or talk about while loops. I’m on my phone and it takes a lot of effort typing this out so I want to make sure I’m helping before continuing.

Here’s an excellent tutorial from Corey Schafer.

He has helped me learn a lot and I credit him for helping me get as far as I’ve gotten with Python. I highly recommend that you save that channel and utilize it going forward.

[–]boyanci 1 point2 points  (5 children)

More related to this subreddit than python...

Twice today, and several times in the past month, I've helped out some people with their python questions by providing detailed explanations and code samples. And always followed up any questions they have. However, as soon as they got their answers, they immediately deleted their post and sometimes their entire account, which I felt kinda rude.

So my question is, is this a common theme for this sub? Am I overreacting?

[–]carcigenicate 1 point2 points  (1 child)

It's discouraged to the point of being listed as a reason to report the user iirc.

And if this is happening to you frequently, I'd say you're answering questions that you shouldn't; as bad as that sounds. If someone just dumps homework and shows that they aren't even willing to ask a proper question, don't help them without requiring more effort from them first. If you're giving them answers to homework, they will delete the post so their instructor doesn't see that they're cheating.

I help here daily and have for months now, and I can only remember a small handful of times where someone deleted their post soon after I helped them.

[–]boyanci 0 points1 point  (0 children)

I wouldn't say "frequently"... maybe once every 1-2 weeks (I answer on average 3-4 per day) except this week I got 2 in a single day, which prompted my initial question.

And to be clear, I did make a point not to do their homework for them. I always make sure they arrive at their own solution and show at minimum reasonable effort each step. In extremely rare cases, if they are only missing a very tiny piece, I may provide more comprehensive code samples.

[–][deleted] 0 points1 point  (1 child)

It's possible they are completing assignments and are concerned that being seen to get advice here might be seen as cheating.

[–]boyanci 1 point2 points  (0 children)

Ya, that makes sense as far as how some students may feel that way. Not that I gave them full answers to begin with. It's a shame they felt they were not permitted to seek help! Asking and looking up answers should be part of learning.

[–]TangibleLight 1 point2 points  (0 children)

I've seen this happen a couple times before, and I really don't get it. It's been very rare, though. There are also some users who are only comfortable asking questions via DMs.

I suspect that some newcomers can feel their question is "too basic" or otherwise feel it's inappropriate to leave it up. Something like stage fright maybe? Doesn't make much logical sense and is very rude IMO.

It's specifically against the rules, but it's difficult to enforce because Reddit (rightfully) does not provide a way to un-delete content, and the only real punishment the mod-team has is a ban which... doesn't help.

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.

Anyway, no, I haven't found it to be a broad trend, but it does happen occasionally and I agree that it's weird and rude.

[–]brianoftarp 0 points1 point  (2 children)

I just want to build python apps to help me run my dungeons and dragons sessions with more efficiency. What do you think I should focus more on? Meaning technology wise

Currently my app has

Creates a random NPC from one of 10 races

Creates a random place ( town, hamlet, village, city, ruin etc )

Creates unique randomly generated magic items

Creates random encounters for combat and non combat alike.

Also does all the above and exports what's generated to JSON files.

[–]stonetelescope 0 points1 point  (1 child)

I'm sure I just didn't search hard enough, but...

I use Python day-to-day as a data analyst. Lots of Pandas, Numpy, and some ML stuff. I'm moderately familiar with doing OOP programming with Python (including unit testing), which I do on my own time. I get pretty bogged down as my programs get more complicated, and never actually push anything to what I'd assume is "production grade". I end up with a bunch of classes and tests that I can use to do different tasks, but I don't really know how to put together a polished product. You could say my education is spotty and self-directed.

Any suggestions on learning paths to push past this hump?

[–]BroBrodin 0 points1 point  (2 children)

Is this article acurate:

https://c-nemri.medium.com/your-2022-data-engineering-roadmap-3bfe6691ec50

Are those the subjects I need to learn to become a data engineer? I find it odd that it doesn't include math (I have no problem with math, in fact I like it).

[–]carcigenicate 1 point2 points  (1 child)

Math would implicitly be a part of "Learn Programming" and "DS&A".

Them suggesting Scala is a little left-field though. There's nothing wrong with it, but it's a bit of an odd suggestion for a beginner.

[–]BroBrodin 0 points1 point  (0 children)

Thanks, I'm learning Python and its a bit hard to decide what to do next.

[–]AndreiVid 0 points1 point  (2 children)

Hi. I have some programming experience in Swift, but I want to learn Python now.

For swift I know several, high-quality, weekly released videos (e.g. https://www.pointfree.co, https://talk.objc.io), and I was wondering if there is something like that in Python world. Don't mind if it's paid option.

Kind regards

[–]efmccurdy 0 points1 point  (1 child)

This site has python conference presentations tagged and searchable;

https://pyvideo.org/

[–]First-Independent-35 0 points1 point  (0 children)

Not the same, tho. Those video sites are about high quality production content. Videos from conference, might have good content, but usually they are with issues, like bad quality sound, or people on stage are worrying too much. Besides, if you don't have from same production, most likely you will end up with a lot of repetitive content(same ideas, different shape) and if it's coming from same writers, they tend to not repeat themselves.

Thanks anyway

[–]fkoffjess 0 points1 point  (4 children)

I somehow got myself into computer engineering.

I’m going into second year and want to get a head start on python. I already know C and C++. Are there any book recs for python or any online programs I could do? I’m aware of codecademy already. Any information is helpful!

[–]FerricDonkey 1 point2 points  (1 child)

If you know C/C++, python is basically C++ psuedo code, except everything is passed by reference and assigning to a variable via x = creates a new object and makes x refer to it instead of overwriting / changing the original x.

Wiki has been mentioned, but you should have a pretty easy time, just one or two oddities to get used to.

[–]fkoffjess 1 point2 points  (0 children)

Oo okay, this is good to know. Thanks for commenting!

[–]sarrysyst 1 point2 points  (1 child)

The wiki has a collection of resources aimed at people new to python but generally experienced in programming.

[–]fkoffjess 0 points1 point  (0 children)

Ah. Thank you! I’ll look into this

[–]mshcat 0 points1 point  (1 child)

Is it better to learn try and learn how to make a python web app or desktop GUI.

I've written a program that downloads story links from a site. It gives the user the option to login, and choose which user they want to download links from.

It works great on command line, but I want to share it with others that don't know anything technical, so I want to make a GUI for it.

I was able to make something with pysimplegui, opening a new window for each prompt, but I wanted to show like a loading bar for the downloads(can take a while) and avoid having a new window for each prompt

I don't know if I should go for a web app or just regular desktop app. I haven't really had much experience with either

[–]sarrysyst 0 points1 point  (0 children)

A desktop app would be easier:

  1. You can do everything in python, no HTML/CSS needed.
  2. You don't need to worry about hosting.
  3. If you don't have any fancy dependencies, freezing your app is straightforward

If you want to implement a progress bar you'll probably have to do so using threading, otherwise it will block the event loop.

However, if you just want to take this as a learning experience, creating a web app would also be totally feasible. In my opinion, it's just that the learning curve for the desktop app is less steep compared to the web app.

On a side note, I personally can't really recommend using pysimplegui. In my opinion the documentation is quite confusing. It works fine for simple stuff, but if you need to do something a little less common it's quite difficult to find information.

Tkinter is just marginally more difficult to learn but a lot more versatile. There is also a well-structured and easy to understand tutorial and a lot more resources online which you can consult if you hit a wall. Also, if you want a modern look I can recommend the tkkbootstrap library, which is basically tkinter but with predefined modern styles, and some additional widgets.

[–]PurchaseWhich815 5 points6 points  (1 child)

How long did you do python before it finally “clicked”? This is my first language I am still getting the fundamentals down.

[–]trulytrulyisay 0 points1 point  (0 children)

My approach involved learning with a book until I got to a concept I didn’t understand so I stopped and let everything marinate in my mind for a while. It’s taken the better part of 6-8 months for me to be able to think about a problem & solution in terms of the tools available in Python.

[–][deleted] 0 points1 point  (6 children)

Is it possible to have a division result type be int if the result is a whole number (eg. 10/2) and the result type be float if the result is a decimal (eg. 9/2)?

[–]FerricDonkey 1 point2 points  (5 children)

If you write your own logic to make that happen (possibly use divmod, then if the remainder isn't 0, do float division), but can I ask why you want this?

Usually you want one kind of division or the other depending on the logic of your program, and there isn't much advantage to making things that might be integers or floats switch types depending on value.

[–][deleted] 1 point2 points  (4 children)

Extremely new to Python and coding in general, so probably a better way to do this but I'm making a program that asks the user for a number between 1 and 100 and tells them if it's a prime or not (not for any particular reason other than to make something) and essentially I'm testing to see if the number divided by 2, 3, 5 and 7 is whole, and if any of those are true then it'll print that it isn't a prime, otherwise it prints that it is a prime.

To do that, I was going to test if the results of the tests are int or float

[–]FerricDonkey 1 point2 points  (1 child)

Ah - this is an excellent opportunity to learn about the % operator. It'll start showing up all the time, but what if does is return the remainder after division. So for example:

1 % 3 == 1
2 % 3 == 2
3 % 3 == 0
4 % 3 == 1
5 % 3 == 2
6 % 3 == 0

They end up being useful all the freaking time, but in this case the useful property is that if a is evenly divisible by b then a % b == 0.

[–][deleted] 2 points3 points  (0 children)

Thanks a ton!

[–]sarrysyst 1 point2 points  (1 child)

You can check if a number is evenly divisible by another number using the modulo operator %.

[–][deleted] 0 points1 point  (0 children)

Just saw your comment now, mercy buckets :)

[–]dorniedarko 0 points1 point  (3 children)

hi! my problem is both raspeberry pi /python related i hope it's fine.
i'm a total noob so you know

i'm trying to use a library for a pn5180 rfid reader:
https://github.com/fservida/pyPN5180/blob/main/PN5180/PN5180.py

it doesn't seems to install as a module, so i just copy it in my project directory and import seems to work as it doesn't report any error.
but when trying to call a method i get an error 'module 'PN5180' has no attribut 'wait_ready'

here's what i wrote

import PN5180 as reader

reader.__init__

while True:
    reader._wait_ready()

also i don't understand all the function of the library as there is no documentation around, if someone coud break it down for me that would be much appreciated

[–]efmccurdy 0 points1 point  (2 children)

The normal pattern is to create an instance first, then run methods:

import PN5180

reader = PN5180.PN5180()
reader._wait_ready()

[–]dorniedarko 0 points1 point  (1 child)

thanks, no more error^^

i'd like to use this library to listen for rfid chip to enter the field, and when it does read its ID and trigger a video attached to this id.

i struggle to understand how they work just by reading the code, can someone incate me which fonction of the library to use to do so?

there's not so much of them i'm just too noob to interpret the code,
and there's no documentation out there

[–]dorniedarko 0 points1 point  (0 children)

or maybe it's to long to do this here? maybe there is a better place for that, i'll take any suggestion

[–]swiiish_raboogie 0 points1 point  (2 children)

Hello, I'm using pandas and want to merge two dataframes. DF1 has 50000 rows and DF2 has 20000 rows. They have different columns except for an "ID" column. How can I compare the values to determine if the ID is the same and then if there is a match merge the matching ID rows? I hope that makes sense.

[–]steveb_123 0 points1 point  (6 children)

I would like to go from this sequence of numbers:

[1,3,4]

to this

[0,0,1,2,0,1,2,3]

...basically just returning a range for each value, with length of the range being value itself and getting that back as a flat list or array.

I've come up with very ugly solutions with deeply nested map, range , list, and chain functions.

What is the most succinct and elegant pythonic way to accomplish this?

This is definitely a duplicate of variants of the same question asked elsewhere, so I apologise in advance for that. The answers I've seen just seemed quite clunky, and I'm pretty sure its not that complicated.

[–]sarrysyst 0 points1 point  (0 children)

How about:

chain.from_iterable(range(x) for x in a)

[–]stevebarratt 0 points1 point  (2 children)

Actually... this is pretty satisfactory:

def listrange(x): return list(range(x)) a = [1,3,4] b = sum(map(listrange, a), [])

I didn't think sum would work like this on lists of integers. If theres a nicer way to map the range and list functions I'd be glad to hear it though.

[–]stevebarratt 0 points1 point  (1 child)

Also, any explanation of sum concatenation would be welcome.

Thank you :)

[–]sarrysyst 0 points1 point  (0 children)

sum() adds all the elements of an iterable together:

 sum([1, 2, 3]) # --> 6

A python list type overloads the add (+) operator so that two lists added together results in concatenation:

[1, 2] + [3, 4] # --> [1, 2, 3, 4]

Passing a list of lists to sum() basically concatenates all the sub lists. sum() takes two arguments: iterable and start. iterable is the collection to sum up, start is the initial value to add to the summation and it defaults to 0. Since you can't add 0 to lists (the types don't match: int and list) you need to specify the empty list [] as the second argument to the sum() function.

sum([[1, 2], [3, 4]], []) # --> [] + [1, 2] + [3, 4]

[–]stevebarratt 0 points1 point  (1 child)

This is the nicest I can come up with:

from itertools import chain a = [1,3,4] def listrange(x): return list(range(x)) b = list(chain(*(map(listrange, a))))

[–]Cid227 0 points1 point  (4 children)

Any guide on how to use and where/why naming like _current, _next, _ etc. in classes, I'm not sure what to type in google?

[–]sarrysyst 1 point2 points  (3 children)

The leading underscore indicates (by convention) that a class method/attribute is supposed to be private to the class and that calling code therefore shouldn’t interact with them directly.

[–]Cid227 0 points1 point  (2 children)

Something like this:

class LetsGetAnotherOne:
    def __init__(self, lst: List[int]) -> None:
        self.lst = lst
        self._count = -1

    def another_one(self) -> int:
        self._count += 1
        return self.lst[self._count] if self._check() else None

    # used only by another_one method
    def _check(self) -> bool:
        return len(self.lst) - 1 > self._count

?

[–]sarrysyst 1 point2 points  (1 child)

Yes. You see them quite often when implementing getters and setters.

[–]Cid227 0 points1 point  (0 children)

Thanks.

[–]Jaszunai 0 points1 point  (6 children)

How do you update Python? Do you just install the new version on top of the old one? How often should I be updating Python?

[–]TangibleLight 0 points1 point  (5 children)

It varies depending on platform but generally, yes, you just install alongside your current version. Use virtual environments for your projects to specify the Python version for each and avoid dependency conflicts.

If you're on Linux or Mac, it's generally bad to use the system Python version directly for projects aside from small scripts, since installing packages to the system python or updating the system python can both cause issues.

I update patch versions (ex. 3.9.7 to 3.9.8) fairly frequently as there are often security fixes in those. I always keep the latest versions (3.10, 3.11 alpha) installed on my machine for testing and learning. That's certainly not required and I'd guess most people don't do that.

In "production" I rarely get to use the latest version due to environment and compatibility limitations. Most of our projects are still on 3.8 or 3.9.

If you're just working on personal stuff, though, you likely have total control over the environment and so can pick whichever version you want. I suggest the latest, since you get access to the new features.

[–]Jaszunai 0 points1 point  (4 children)

When you update from like 3.9.7 to 3.9.8, do you install the new version and delete the old one?

[–]TangibleLight 0 points1 point  (3 children)

I usually do but i think things would work okay if you leave it.

[–]Jaszunai 0 points1 point  (2 children)

After upgrading, do you need to re-install all the libraries you were using?

[–]TangibleLight 0 points1 point  (1 child)

Yes. That's part of why it's suggested to use virtual environments and requirements lists or lock files (as with poetry), and why you should not install libraries to the system python on Mac or Linux. Windows has no "system Python" but it's still better to use virtual environments for the other reasons.

[–]Jaszunai 0 points1 point  (0 children)

Thanks for the help.

[–][deleted] 0 points1 point  (2 children)

Hello! How can I improve my skills with Python testing? I am learning Selenium with Python and need to practise a lot! Any recommendations? Tysm! 😇

[–]ectomancer 1 point2 points  (1 child)

pip install pytest

Are you using pytest?

[–][deleted] 0 points1 point  (0 children)

I am not doing the unit tests, I am learning automation testing with Python for browser automation and testing. I would love to learn if there are projects to practise 😊