I have a feeling I’m stuck in tutorial hell, and I need to start actually building things. But I don’t know where to start :/

Also I’m really bad at syntax. I only know concepts like for loops, while loops, if-elif-elses, etc…

So maybe something that helps me learn more about coding syntax would be helpful.

Thanks!

  • Maiq@piefed.social
    link
    fedilink
    English
    arrow-up
    6
    ·
    edit-2
    20 hours ago

    Just a thought, install ipython. Then start exploring modules. ipython is very helpful with this.

    Here is a small example. After ipython is installed in a terminal start ipython shell by typing ipython. In my example we will use psutil.

    import psutil as ps

    You can access different methods in that module with a dot and you can see all available methods by hitting tab after the dot. ps.<tab>, then you can use the arrow keys to select different methods that interest you.

    Here i will use process_iter to get programs that are running. I’ll use firefox as an example.

    for proc in ps.process_iter():
        print(proc)
    

    You can start to figure out how to access properties. Some properties are methods and require the () and others are attributes and dont.

    for proc in ps.process_iter():
        if proc.name() == "firefox":
            print(proc.status())
            # or even kill the process
            proc.kill()
    

    This can be fun. It can help you explore and familiarize yourself with different modules as you read their documentation.

    You could teach yoursel list comprehension.

    [ x for x in ps.process_iter() if 'fire' in x.name() ]
    

    This gives you a list of processes with ‘fire’ in the name. A powerful way to sift generators, lists and the like becomes available.

    psutil is fun but you dont have to start there. The os module is very handy.

    import os
    
    down = os.path.join(os.path.expanduser('~'), 'Downloads')
    
    for zip in os.listdir(down):
        if os.path.splitext(zip)[1] == '.zip':
            # delete all zip files in Downloads
            os.remove(os.path.join(down, zip))
    
    # or with list comprehension
    
    zips = [ z for z in os.listdir(down) if os.path.splitext(z)[1] == '.zip' ]
    
    for zip in zips:
        os.remove(os.path.join(down, zip))
    
    

    Maybe try https://en.wikipedia.org/wiki/Fizz_buzz for fun.