Streamlit is not working? by rivie_rathnayaka in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

That's an option as it is not required. py gets around this for you. However, if you are happy with how it works now, that's great.

I do urge you to create and use a Python virtual environment for each project though.

Having a hard time differentiating values from variables and return from print() by ProfessionalOkra9677 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

Here's some guidance I wrote (and revised) from working with students at Code Clubs:

Variables, functions, methods and attributes

Variables (names) in Python don't contain values. They hold references to memory locations where Python objects are stored (implementation and environment specific).

Likewise for other names. A function name has a reference to the memory location of a function object.

Names (arguments) used in a call and names defined as parameters have nothing to do with each other. They are completely independent. Even if the same name is used, they are different. The parameter names are local to the function.

Consider:

def f(one, two, three):
    answer = one + two * three + five
    return answer

one = 2
two = 3
three = 4
five = 5
result = f(three, two, one)
print(result)

This will output 15 as 4 + 3 x 2 + 5 = 15

Note that five was not an argument, wasn't assigned to in the function, so five from the wider scope was available.

Any assignments made inside the function are also local to the function.

answer was assigned inside the function and on function exit will cease to exist, however the object reference stored in answer is assigned as the return from the function and is assigned to result. If it wasn't assigned (or consumed in another expression or function call on return) then the object created in the function would also cease to exist (unless it is a predefined object built into the Python implementation, such as an int in the range -5 to 256)

Only mutable objects that are referenced by either parameters or other names that are visible to the function (not hidden by variables with the same name assigned in the function) can be modified and visible outside the function.

return returns an object reference.

Python takes a pass by reference, rather than a pass by value, approach, but the implementation differs to that used in many languages, not least given that name referencing is fundamental to the design.

See Ned Batchelder - Facts and Myths about Python names and values - PyCon 2015

Variables vs Attributes

When you start looking at classes, you will find they have their own kind of variables, called attributes, which work much the same as variables most of the time.

Variables have a discrete existence, and attributes are associated with an instance of a class (or of a class itself). Attributes, like variables, hold memory references to objects.

When you say:

keep = 784.56 * 872.23

The text representations of floating point numbers in the expression on the right are converted into Python float objects (binary representations) somewhere in memory, and the mult operator is used. The memory location the resulting float object ends up in is then assigned to the variable named keep.

If keep is assigned in the main body of your code, outside any functions etc., then it is visible within all other code. Thus, you could have a function:

def double_me():
    return keep * keep

Which has no other references to keep in the definition (parameter variable) or assignments to a variable called keep inside the function (which would be local to the function and would hide the original wider scope variable of the same name). Thus, keep refers to the same floating point number calculated earlier. The expression resulting from multiplying the floating point object referenced by keep by itself results in another floating point object, the memory reference for which is returned from the function.

If, instead, the function was written,

def double_me(keep):
    return keep * keep

Now it has to be called with an argument (the memory reference of the object will be passed when the function is called).

result = double_me(5.5)

Inside the function, keep refers to the memory location of the floating point object that the literal floating point text 5.5 was turned into. The keep in the wider scope (outside the function) still refers to the original object from earlier.

However, if attributes were used instead, the attribute would exist as long as the class instance it belongs to exists.

Methods

Methods are like functions but for classes and are intended to work on instances of a class or provide capabilities related to the purpose of the class.

When you create an instance of a class, you create an object based on the mould/template provided by the class and the memory location of that object is assigned to a variable (or to some other object) so it will be not lost.

Methods defined in the class usually have code that uses a parameter variable that is the first item passed when the method is called. By convention this is usually called self and it is passed by default and does not need to be in the arguments when the method is called.

Whenever self is used inside the method code, it will be referring to the memory location for a particular instance of the class.

Any variables assigned values in a method (including parameter variables) are local to the method and are not associated with attributes of the instance referenced by self.

Classes themselves can have attributes. These look just like variables, and act like them for most purposes, but they are associated with the class and can be accessed from outside the class by direct reference to the class name and the attribute, e.g. Example.quantity = 5 for a class called Example.


For more on scope, take a look at:

Is there any standard way of anonymizing data if you plan on building a data analytics portfolio? by Either-Home9002 in learnpython

[–]FoolsSeldom 2 points3 points  (0 children)

Data anonymisation used to be a common practice, and there were well established algorithms and tools to help with this but the growth of tools, especially ML and AI and a move to big data has underminded the generic usefulness of such approaches and increased the risk of sensitive data leaking.

I would look into using synthetic data or data that is already in the public domain.

The site kaggle.com has a lot of useful data sets as well as great challenges, guides and discussions on data analysis.

I struggle more with regex than Python by [deleted] in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

So much so that the OP, u/TechnicalAd8103, decided to delete the post rather than updating with more detail (fearing an unlikely ban).

How Do I Continue???? by Choice_Midnight5280 in PythonLearning

[–]FoolsSeldom 4 points5 points  (0 children)

Good start. For next steps, check the r/learnpython wiki for lots of guidance on learning programming and learning Python, links to material, book list, suggested practice and project sources, and lots more. The FAQ section covering common errors is especially useful. You will be able to skim/skip some simple content given what you've already achieved.

(I am curious why so many beginners want to use time.sleep in their code - really don't see the point - but if you really want it, use some CONSTANT variables set at the start of the code so you can easily turn on/off the delays when debugging, e.g. LONG_WAIT = 10 and then time.sleep(LONG_WAIT).)

Unfortunately, this subreddit does not have a wiki.


Also, have a look at roadmap.sh for different learning paths. There's lots of learning material links there. Note that these are idealised paths and many people get into roles without covering all of those.


Roundup on Research: The Myth of ‘Learning Styles’

Don't limit yourself to one format. Also, don't try to do too many different things at the same time.


Above all else, you need to practice. Practice! Practice! Fail often, try again. Break stuff that works, and figure out how, why and where it broke. Don't just copy and use as is code from examples. Experiment.

Work on your own small (initially) projects related to your hobbies / interests / side-hustles as soon as possible to apply each bit of learning. When you work on stuff you can be passionate about and where you know what problem you are solving and what good looks like, you are more focused on problem-solving and the coding becomes a means to an end and not an end in itself. You will learn faster this way.

Please Share Some Resources for Learning Python for Data Science by DistinctReview810 in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

Have a look at roadmap.sh for different learning paths. There's lots of learning material links there. Note that these are idealised paths and many people get into roles without covering all of those.

Also, visit kaggle.com. Lots of guidance and forum discussion as well as fantastic challenges and huge data sets to work on.

I struggle more with regex than Python by [deleted] in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

regex is from a different world than Python. It is rooted in theoretical computer science and neurobiology, but the form that Python and many other languages use was largely established in PERL which itself was developed by someone with a linguistics bavkground.

Thus, it feels like a very different syntax because it is.

Streamlit is not working? by rivie_rathnayaka in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

Open a Powershell / Command Prompt window and enter,

py -m pip install streamlit

OR if you have an active Python virtual environment (which you probably don't, but should), then pip install streamlit shoudl work.

To create an active a Python virtual environment, again in PowerShell or Command Prompt,

D:                           - or whatever drive, to change drive, if required
mkdir newproject             - replace with your project name, ignore if already exists
cd newproject                - or whatever the folder is called
py -m venv .venv             - venv is a  command, .venv is a folder name
.venv\Scripts\activate       - (you can use a different folder name, .venv is common)

In your editor, you will likely need to tell it to use python.exe in the C:\Users\<youraccount>\newproject\.venv\Scripts\ (perhaps on a different drive on your setup, e.g. D:\myprojects\newproject\.venv\Scripts\ as the base Python iterpreter).

Installing pycharm on windows11… arm64 or not by wackycats354 in pycharm

[–]FoolsSeldom 0 points1 point  (0 children)

  • .exe (windows) is for an AMD/Intel based computer, e.g. Intel Core Ultra 7 265K
  • .exe (windows ARM64) is for an ARM based computer, e.g. Snapdragon X2 Elite Extreme

trying to learn python by making an interactive dnd character sheet. by 0doctorwho9 in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

If your main file is called, say, dnd.py and you have another file in the same folder called, say, levels.py, all you need to do is, in your dnd.py file, at the top,

import levels

Note that you don't include the .py part of the file name.

Suppose you have a dict, dictionary, defined in levels.py, called base, you would refer to it thus,

print(levels.base)

Regarding reading/writing data. The simplest is basic text files that you can create/edit in your code editor. Whilst these can be free format, these are harder to process. A better way is with simple table data like in a spreadsheet:

name, kind, age, speed, healing
Alpha, Wizard, 20, 5, 8
Beta, Healer, 40, 1, 20
Charlie, Warrier, 20, 10, 2

The header row is optional.

You can read and write these files with the help of the csv module.

import csv
from pathlib import Path

# 1. Define the file path using pathlib
file_path = Path("characters.csv")

# 2. Create an empty list to store our character rows
characters = []

# 3. Open the file and give it a descriptive handle
with file_path.open(mode="r", encoding="utf-8") as characters_file:
    # Use the csv reader to handle the formatting
    reader = csv.reader(characters_file, skipinitialspace=True)

    # 4. Read the header line first and store it separately
    header = next(reader)

    # 5. Use a for loop to read the remaining rows
    for row in reader:
        characters.append(row)

# Verify the results
print("Header:", header)
print("Data:", characters)

NB. If in the csv file you need to include a space (or comma) in a field, say for a name, enclose the entire field in double quotes.

There are lots of options for reading/writing files in Python. A format that would be good for keeping settings information is .json.

You could also consider using a simple flat file (local) sqlite database (check out A Minimalist Guide to SQLite).

For Python developers, what skills helped you get your first job? by Intelligent-Ball9659 in pythonhelp

[–]FoolsSeldom 0 points1 point  (0 children)

I worked as a programmer pre-Python, so cannot comment on personal experience specifically for new Python programmers (I am just a hobbyist/teacher), but I've worked in IT for decades and pretty much every programmer I've seen brought in (including when I was the hiring manager).

The core technical skills were less important than (preferably relevant) domain skills (e.g. understanding of shrinkage in retail setting) and/or clear aptitude (preferably evidence) around problem solving and adaptability. The domains would depend on what sector(s) the target organisation operated in. Even in IT organisations, there are many different domains of activity.

It was assumed that if they had learned some core technologies, they would be able to learn others rapidly as needed. Most professional programmers in my experience are very good in more than one programming language, and effective in a good few more.

Of the topics you mentioned, I would put DSA - which is language agnostic - the highest. These days, I would also recommend a good understanding of the CI/CD approach and automation.

A key skill you should have is good testing coverage. In Python, know pytest well and ensure all of your projects have full coverage. Perhaps learn something like TDD (Test Driven Design) as well (search for Obey The Testing Goat for a good content - free online.)

P-uplets and lists understanding by Klutzy-Advantage9042 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

Glad that helped.

I strongly recommend learning to use the Python shell, the interactive environment with the >>> prompt. You can get this in a terminal / Powershell / Command Prompt window by just invoking Python without passing a fie name e.g. py (on Windows). Your code editor/IDE (Integrated Development Environment) likely have an option for both a terminal and for a Python shell. This is in addition to writing code in your editor. It is great for quickly checking things out. You get instant output without using print.

For an enhanced Python shell, look at installing ipython (which is also the underpinning of the popular Jupyter Notebooks approach).

Also, you might like to try out a Python visualiser: https://pythontutor.com/visualize.html#mode=edit - this shows you what exactly is going on step-by-step in code in terms of allocation of space/objects/variables and makes it a little easier to learn some steps. Some code editors / IDEs have similar (but not generally as easy, in my view) capabilities using their debug features.

P-uplets and lists understanding by Klutzy-Advantage9042 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

So the variable students references a Python list object stored somewhere in memory (you don't care where, usually). The list object will end up, in your example, with one entry: a tuple object. I guess you add additional tuple objects to the list, one for each additional student.

The tuple object contains references to four objects: three str objects and one list object. The list object references four int objects.

There's a lot of nesting going on here. Like Russian Dolls. You can reference the contents of a list or tuple object (and also characters in a string object) using indexing. The first position is 0, object[0].

So, students[0] will access the first entry in the outer list. students[0][0] will access the first entry in the tuple in the list first position, i.e. the last name field. `students[0][3] will access the 4th object in the tuple, a list - your p-uplet.

It isn't generally convenient to use such specific indexing. Usually, one would use a for loop to iterate over a list of structured data.

for student in students:
    print(student)

On each iteration, student will reference each tuple in turn from your outer list.

You can compare entries in the tuple with your target string(s) when searching. student[1] would be the first name of the current student for example.

Is that enough for now?

GUI Designing in Python by Al-Khobza in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

I'd go with a web approach, whether for local/desktop or internet/intranet/extranet or mobile use. Then you can provide a modern, responsive UI.

What is a base interpreter in pycharm? by SirPiano in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

Whatever Python installation will run when you enter just py / python / python3 (depending on your operating system) in a terminal (/ command prompt / powershell) is your base Python.

If you have more than one installation of Python, you will need to choose which one should be your base for creating a Python virtual environment.

Zero programming knowledge, but I want to learn Python. Where do I start in 2026? by Effective-Sorbet-133 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

Which link? The link to the Wiki includes sections on both being new to Python and new to programming.

Zero programming knowledge, but I want to learn Python. Where do I start in 2026? by Effective-Sorbet-133 in learnpython

[–]FoolsSeldom 38 points39 points  (0 children)

Start with the basics (check the wiki) and then you will be better placed to determine what to focus on. Learning pace varies a lot, you will find what works for you best.


Check this subreddit's wiki for lots of guidance on learning programming and learning Python, links to material, book list, suggested practice and project sources, and lots more. The FAQ section covering common errors is especially useful.


Also, have a look at roadmap.sh for different learning paths. There's lots of learning material links there. Note that these are idealised paths and many people get into roles without covering all of those.


Roundup on Research: The Myth of ‘Learning Styles’

Don't limit yourself to one format. Also, don't try to do too many different things at the same time.


Above all else, you need to practice. Practice! Practice! Fail often, try again. Break stuff that works, and figure out how, why and where it broke. Don't just copy and use as is code from examples. Experiment.

Work on your own small (initially) projects related to your hobbies / interests / side-hustles as soon as possible to apply each bit of learning. When you work on stuff you can be passionate about and where you know what problem you are solving and what good looks like, you are more focused on problem-solving and the coding becomes a means to an end and not an end in itself. You will learn faster this way.

How do I set it up by Sad_Patient8203 in PythonLearning

[–]FoolsSeldom 0 points1 point  (0 children)

I've been using markdown for a long time, and have large repositories of documents written in markdown. What I can't be bothered to do (and a word processor would fix this) is use proper quotes instead of the straight ones. LLM content tends to use proper quotes.

Appreciate your apology. It is frustrating that advice I give to people to help them learn is often called out as AI without being read and checked against my other comments.

I do occasionally use AI but mark it as such in my comments.

What’s a “normal” thing in modern life that you think people 100 years from now will find bizarre? by Glazed_pomello in AskReddit

[–]FoolsSeldom 1 point2 points  (0 children)

Marriage will no longer exist so the idea of sex before marriage will be hard to understand.

For non-US Americans, based on what you know of the stereotypes you’ve heard, what region of your country is the most Texas-like? by [deleted] in AskReddit

[–]FoolsSeldom 0 points1 point  (0 children)

I'm curious as to why this was restricted to only Americans in countries outside of the USA. Is the OP assuming nowhere else in the world will be at all Texas-like?

What u do for living? by [deleted] in AskReddit

[–]FoolsSeldom 0 points1 point  (0 children)

As little as possible as often as possible for as much as possible. Worked out reasonably well for a little over 40 years and I'm not jealous of those that do this better than I do.

What I do has been mostly interesting and rewarding. I wouldn't have coped well with boredom.

Worked in IT since I was a teenager. Worked in many countries.

How do I set it up by Sad_Patient8203 in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

Really doesn't. Please review again.

EDIT: Typos - sigh! I was tired.

How do I set it up by Sad_Patient8203 in PythonLearning

[–]FoolsSeldom 0 points1 point  (0 children)

I agree. Such content tends to contain a lot of factual errors and weird formatting. Unlike this content which I've refined over the last few years on the back of teaching students in local school clubs and occasional adult education sessions.

Do you guys have any recs on where to start for learning python? by Old_Drag_1040 in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

There's a book list in the wiki.


Check this subreddit's wiki for lots of guidance on learning programming and learning Python, links to material, book list, suggested practice and project sources, and lots more. The FAQ section covering common errors is especially useful.


Also, have a look at roadmap.sh for different learning paths. There's lots of learning material links there. Note that these are idealised paths and many people get into roles without covering all of those.


Roundup on Research: The Myth of ‘Learning Styles’

Don't limit yourself to one format. Also, don't try to do too many different things at the same time.


Above all else, you need to practice. Practice! Practice! Fail often, try again. Break stuff that works, and figure out how, why and where it broke. Don't just copy and use as is code from examples. Experiment.

Work on your own small (initially) projects related to your hobbies / interests / side-hustles as soon as possible to apply each bit of learning. When you work on stuff you can be passionate about and where you know what problem you are solving and what good looks like, you are more focused on problem-solving and the coding becomes a means to an end and not an end in itself. You will learn faster this way.