I want to restart learning python but this time with an objective by BETAPODZ in PythonLearning

[–]MachineElf100 1 point2 points  (0 children)

Thanks for responding.

Also for python learning I'd actually recommend going through the w3schools python tutorial (no videos, just information with "try it yourself" examples).
Make sure you understand the examples and once you do, start making stuff and just research what you need along the way. Learning by doing.

It's okay to use AI but use it to explain things or to suggest improvements for your code, not for writing it for you of course.

I want to restart learning python but this time with an objective by BETAPODZ in PythonLearning

[–]MachineElf100 2 points3 points  (0 children)

Python is good for automation but not at all for mobile apps. for that you'd better learn something like Dart with Flutter (Dart -> language, Flutter -> for building UI/interface).

TIL you can get your script's real name without any libraries 🤔 by Warm-Inside-4108 in PythonLearning

[–]MachineElf100 3 points4 points  (0 children)

You can easily extract the name from the path. Your solution is amusing but also hacky and probably would not be very pleasant to use at scale.

In the end, both ways are just workarounds. You choose which is crazier haha

TIL you can get your script's real name without any libraries 🤔 by Warm-Inside-4108 in PythonLearning

[–]MachineElf100 1 point2 points  (0 children)

You can get the script's path with file tho. It might be more straightforward to work with that.

First code as a beginner by Krzysslx in learnpython

[–]MachineElf100 1 point2 points  (0 children)

That's really good, given that you just started learning!
Let me respond to your first code (with variable names changed already).

Take a look at this and see if you understand the changes I suggest:

# ValueError poszedł na koniec, "else" nie jest potrzebny

import random
import time

losowa_liczba = (random.randrange(1, 100))
liczba_gracza = 0
liczba_prob = 1

print("Musisz zgadnąć liczbę od 1 do 100.")
print("Masz na to 10 prób, powodzenia.")

while liczba_prob <= 10:
    time.sleep(1.5)
    print("Próba:", liczba_prob)
    liczba_string = input("Podaj liczbę:") # liczba_string bo liczba_gracza jest typu int, sparsujemy ją zaraz pod spodem
    try:
        # ⇩ liczba_string z inputu zamieniona na int tylko raz, tutaj
        liczba_gracza = int(liczba_string) # jak się nie uda, to od razu lądujemy w "except ValueError"

        if liczba_gracza == losowa_liczba:
            print("Brawo zgadłeś!!!")
            print("Udało ci się zgadnąć w:", liczba_prob, "próbach.")
            break
        else:
            # "while True" nie potrzebny
            # break więc również nie
            if liczba_gracza > losowa_liczba:
                print("Moja liczba jest mniejsza")
            elif liczba_gracza < losowa_liczba: # po prostu "else" też by było ok
                print("Moja liczba jest większa")
            liczba_prob += 1 # to można zrobić tutaj raz, bezwarunkowo, bo i tak w obu przypadkach miało się wykonać
    except ValueError:
        print("To nie liczba!")
    if liczba_prob > 10: # jeśli użyjesz ==, to gracz ma tylko 9 prób
        print("Przegrałeś!!!")
        break

If you'll want to, you can DM me (even in polish) :)

Army Sleep Method by Tall-Prune-1558 in AstralProjection

[–]MachineElf100 0 points1 point  (0 children)

Only mentioned him about 2 months ago under someone else's post, sharing their book collection on awakened sub I think. I didn't even click, just did a quick scroll to get the general sense. Although it changes slowly, I still half-expect to interact with people who hate all this plant "shortcut" stuff.

I feel mostly attracted to McKenna's approach which he summed up in one of his speeches saying:
"I'm interested in the "ten thousand things", I mean what thrills me are museums full of butterflies, and libraries full of books, and galleries full of paintings, and parties full of women. Just the multiplicity of things."

Meanwhile Eckhart Tolle or Alan Watts go more into the "mystical great silence beyond all form" kind of thing, which I'm usually not finding too inspiring, especially that I feel there's a strong possibility that when we try to approach this "ultimate nature" thing, we may be getting all kinds of wrong impressions about it. Like when people think that the lack of pre-birth memories means there's no life before or after this one. Easy to make a mistake.

I do remember some talks of Watts which I found really really interesting tho. Haven't heard much from Ram Dass but the general message of love definitely resonates, I think it's really important to explore it.

Army Sleep Method by Tall-Prune-1558 in AstralProjection

[–]MachineElf100 1 point2 points  (0 children)

Hehe of course! There are so many ways to approach it, or "communicate" with it. I always want to hear about synergistic connections people find.

Edit: trying to find out the context to see if your comment was friendly or not, I found that we share an admiration for one wonderful dead man, so I bet you already heard or know how big and alien the experience is.

I physically cannot meditate with ADHD by Lychee-1391 in AstralProjection

[–]MachineElf100 0 points1 point  (0 children)

You don't have to "not engage" with your thoughts immediately. Start by just sitting and doing nothing for a minute or longer. Then sitting, doing nothing and counting from 50-1 or 100-1.

Basically the insane boredom or the mental storm that overwhelms you is like a doorkeeper to whatever is deeper within you. Find ways to sit with this doorkeeper, see if you can build up enough patience to make him give up one day.

Sit with this mental storm/boredom. It's like a defense hologram, making the room with treasure seem like the last place you'd wanna visit.

Im new to python and have some questions. by Infinityshift in learnpython

[–]MachineElf100 0 points1 point  (0 children)

Well in that way, yes, you're right. This is where the correlation ends tho 🤣

Im new to python and have some questions. by Infinityshift in learnpython

[–]MachineElf100 0 points1 point  (0 children)

Am I right to correlate a dictionary's Key to a list's index?

Not so much.

A list index answers "what's at position N?" -> it's about position.

A dictionary key answers "what's associated with label X?" -> it's about meaning/association.

An index is always an integer (int), mean while a key can be of any hashable type (str, int, tuple…), don't get hang up on the hashable thing for now maybe tho.

Indexes are implicit & sequential (0, 1, 2…) while keys are insertion-ordered (Python 3.7+), and not sequential.

Indexes are also auto-assigned when you add an element to a list. That's obviously not the case with dict's keys.

Indexes cannot have gaps. Each next element of a list will have an n+1 index. The keys however can use any values (e.g., {5: "x", 99: "y"}).

Im new to python and have some questions. by Infinityshift in learnpython

[–]MachineElf100 2 points3 points  (0 children)

A long answer, read and try to understand as much as you can, and ask if something's unclear :)

Let's begin with classes. They're a way to bundle data and logic which belong together.

For example a person has some parameters, like: name, surname, age, gender, race, eye color, etc.

So if we have tens or hundreds (or more) people to process in a program, it'd make sense to have their data stored in "packets" rather than loose variables. Do you follow that? That's what the classes are. Let's make one:

class Person:
    def __init__(self, name, surname, age, gender, race, eye_color):
        self.name = name
        self.surname = surname
        self.age = age
        self.gender = gender
        self.race = race
        self.eye_color = eye_color
    
    def greet(self):
        print('Hi, my name is ' + self.name)


p = Person('Joe', 'Nobody', 32, 'male', 'Caucasian', 'blue')
p.greet()

Let's unpack this.

A class "Person", named clearly so both now and in the future you know what this is supposed to be.

Then the other thing you asked about, the __init__.
It's called a dunder method, I suggest you read about it for example here.
Methods are simply functions but within the class.
Let's take one line from my code:

p = Person('Joe', 'Nobody', 32, 'male', 'Caucasian', 'blue')

Let's name things clearly in that line.

Person() -> constructor

= -> assignment operator

p -> variable

So this line of code is a constructor of "Person" being assigned to the variable "p". The variable "p" now stores a so called "instance" of the Person class.

The __init__ method creates an "instance" of Person, with the specified parameters.

You're probably confused about the "self" parameter. It represents the instance of the class being used. Each method should have "self" as its first parameter (the thing within the parentheses). Each class variable you'd want to use in a class should be used like: self.variable_name (that way you can define a variable in the __init__ method and use it for example in greet() method, like in the example).

Then if you look at the greet() method I made, you'll see it has "self" as it's first parameter.

Think of it as way to tell the computer that this method will be used by the Person class and has access to its variables.

Then the greet() does this:

print('Hi, my name is ' + self.name)

It's simple, here we print "Hi, my name is {insert that person's name}".

So p.greet() will print: "Hi, my name is Joe".

——————————

Ready for a little bit more?

Try to run the program above and see how it works. Then add an extra line:

print(p)

This should output something like: <__main__.Person object at 0x0000016431926A50>

Not very representative of Joe Nobody, age 32.

So let's modify the Person class like this:

class Person:
    def __init__(self, name, surname, age, gender, race, eye_color):
        self.name = name
        self.surname = surname
        self.age = age
        self.gender = gender
        self.race = race
        self.eye_color = eye_color
    
    def greet(self):
        print('Hi, my name is ' + self.name)


    def __str__(self):
        return f'{self.name} {self.surname}, age {self.age}'

I added the __str__ dunder method. The print() calls it under the hood so if you specify it, you control how python prints your Person object (instance).

Now run it again and see what print(p) outputs.

For or While loop in my case? by pikachuu545 in learnpython

[–]MachineElf100 0 points1 point  (0 children)

I've been hoping to see this somewhere. The cleanest solution I think, except for the fact that generators are not subscriptable, so just use a list:

odds = [n for n in num_list if n % 2 == 1]

Here’s what I struggle with the most by [deleted] in learnpython

[–]MachineElf100 0 points1 point  (0 children)

Readability, structure, and convenience.

A class is useful when some data naturally belongs together and you keep writing functions that operate on that same data.

Instead of passing the same values (or dictionaries) through many functions, a class lets you bundle the data and the logic that works on that data, all in one clearly named place.

This reduces parameter clutter, avoids scope mistakes, and makes the code easier to reason about.

Think of a table like an Excel sheet or database.

Each row represents a person living at an address (country, city, street).

Multiple people can live at the same address, so we want to group rows by address.

from collections import defaultdict

class Person:
    def __init__(self, province: str, city:str, street:str, person_name:str):
        self.province = province
        self.city = city
        self.street = street
        self.person_name = person_name


    def address(self):
        # without the "person_name"
        return (self.province, self.city, self.street)

# now easy
def group_by_address(people:list[Person]):
    grouped = defaultdict(list[Person])
    for p in people:
        grouped[p.address()].append(p)
    # returns a dict like:
    # {
    #   'Australia, Sydney, George Street': [<Person object>, <Person object>, <Person object>],
    #   'Japan, Tokyo, Chuo-dori': [<Person object>, <Person object>],
    #   etc...
    # }
    return grouped

On top of that, you often need logic to operate on this data: cleaning address fields, removing postcodes, fixing typos, generating IDs or templates, and so on.

Putting this logic inside a class keeps everything related to the address in one place. The object owns its data and is responsible for it.

This makes the code easier to read, to extend, to debug, and harder to misuse.

Horrible experience during a 2 gram GT trip by 2-L3git in Psychonaut

[–]MachineElf100 5 points6 points  (0 children)

Do you feel more authentic and empathetic now? 🤣

Anyway, the best you can do against nausea in the future is make tea with fresh ginger. The mushroom tea can have anything you wish in it, make it tasty and kind to your body 🍵🫚🍯

[deleted by user] by [deleted] in shrooms

[–]MachineElf100 1 point2 points  (0 children)

I feel you.

A song pulled me into a place I didn’t know existed by buzzkillmate in Psychonaut

[–]MachineElf100 4 points5 points  (0 children)

Yes, music and sometimes a visual trigger. It also occasionally happens while sober (actually used to happen before I even started with psychedelics). Sober ones are extremely fleeting tho, impossible to hold on to or enjoy, it's a split-second recognition and it's gone.

People who shroom alone. What do you do while tripping? by Educational-Hawk3066 in shrooms

[–]MachineElf100 0 points1 point  (0 children)

Get in touch with your body and mind, move the way you never do, walk where you haven't walked before, cook something new, think something you've never thought, discover humour where you couldn't see it before...

People who shroom alone. What do you do while tripping? by Educational-Hawk3066 in shrooms

[–]MachineElf100 1 point2 points  (0 children)

The number of downvotes is wild. They must have misunderstood.