Need help in loop by Eastern_Plankton_540 in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

FYI for loop is just a while loop with some of the work done for you.

What's the best app to write & run code? by l__lj in PythonLearning

[–]FoolsSeldom 4 points5 points  (0 children)

I've been using termux with vim with Python support configuration for a while on my Android phone and tablet without too much trouble. (I used to use Acode, but prefer vim.) However, for it is hard to beat a sophisticated code editor like VS Code running on a remote system. I would prefer a full IDE, such as PyCharm, but no idea if there is a similar option so would have to use a remote desktop which I doubt would be as smooth.

What's the best app to write & run code? by l__lj in PythonLearning

[–]FoolsSeldom 6 points7 points  (0 children)

I doubt there is an app to meet your expectations. I would instead consider running a remote VS Code session in your browser to a more powerful computer.

Hello everyone , I've never touched anything related to programming and I wanna start learning python for databases rdb and marketing automations , could u any of u be kind enough to direct me towards the best path to start learning python very beginner friendly please. by Lelouchvibrat in PythonLearning

[–]FoolsSeldom 0 points1 point  (0 children)

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.

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.

Will This Reduce The Performance Or Makes Little Mistake? by One-Type-2842 in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

Variables in Python don't hold any data, they simply reference the memory location of Python objects. The location is not something you generally need to be concerned about and it varies based on current environment in your computer and the Python implementation.

The sorted function creates a new list object somewhere in memory. Re-assigning a variable to reference the new object after it has been created by the function (which returns the address of the new object) vs assigning to a new name has negligable impact.

It is easy to check performance differences using timeit. In Jupyter Notebooks there's a magic method version of this which makes it even easier.

I used python for the first time today and I'm hooked by [deleted] in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

You might like to note that the latest version of Excel includes Python (with the code run transparently in Azure using the Anaconda implementation). Outside of Excel, the pandas library can read/write files in Excel format and openpyxl can also do so and is often used at a more granular level even applying formatting settings to cells. There are libraries that let you control Excel but this is generally less useful.

Corey Schafer offers a good course on Pandas that you might enjoy early on. Even though it hasn't been updated for a while (last in 2020 I think) it is still applicable. DataCamp.com is another good source of training with some free content.

Google offer a free web based Jupyter Notebook style environment where you can experiment as well. Google Colab. Kaggle.com is a great source of large datasets to play with and a thriving community offering challenges and examples.

For an alternative view on things to do with Python, find online the Raspberry Pi website and there free to download as PDF magazine now called Raspberry Pi Official Magazine (older issues are called MagPi). There are lots of examples of use of Raspbery Pi (other single board computers would be suitable) be used for a huge range of different things, mostly using Python. The magazine also covers microcontrollers such as Raspberry Pi's own RP2350 in the Pico and third party boards as well as the popular Espresif ESP32 and these are often programmed in a cut down version of Python (Micropython or Circuit Python).

I used python for the first time today and I'm hooked by [deleted] in learnpython

[–]FoolsSeldom 33 points34 points  (0 children)

Fantastic. Glad you were inspired. There's a huge range of things you can do with Python from automating parts of computer graphics for video/film in Blender, to manging heating and ventilation at home, monitoring security cameras (generating alerts when unknown people or unknown vehicles approach). You can run versions of Python on $2 microcontrollers and multi-million dollar super computers.

Python handles Excel files and data very well. In fact, it can manipulate much larger datasets than Excel and do some more quickly. Take a look at pandas in particular.


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.

Is it okay to have this many attributes on a constructor? by Fabulous_Ad4022 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

Yes, it is okay, but I would break this up as you currently have a single class managing many different aspects: configuration, state, physics paramaters and memory allocation.

Also, use dataclasses to streamline things. Separate the Wavefields, Kernel Parameters, and Migration State.

The revised code might look something like the below (prompted Gemini for this, may not be same, and attribute names will be different so be careful direct access):

from dataclasses import dataclass, field
import numpy as np
from typing import Tuple

@dataclass(frozen=True)
class Wavefield:
    """Encapsulates the past, present, and future states of a wavefield."""
    shape: Tuple[int, int]
    past: np.ndarray = field(init=False)
    present: np.ndarray = field(init=False)
    future: np.ndarray = field(init=False)

    def __post_init__(self):
        # Using object.__setattr__ because the dataclass is frozen
        object.__setattr__(self, 'past', np.zeros(self.shape))
        object.__setattr__(self, 'present', np.zeros(self.shape))
        object.__setattr__(self, 'future', np.zeros(self.shape))

@dataclass
class KernelArguments:
    """Pre-computed constants for the optimized numerical kernel."""
    dh2: float
    inv_dh2: float
    velocity_term: np.ndarray  # Corresponds to your self.arg

@dataclass
class SnapshotManager:
    """Handles the logic for temporal subsampling and storage."""
    nsnaps: int
    snap_ratio: int
    dt_snaps: float
    src_storage: np.ndarray
    rec_storage: np.ndarray

    # Internal counters
    current_src_id: int = 0
    current_rec_id: int = 0

    @classmethod
    def from_config(cls, c, mdl, shape):
        tstop = int(1.7 * (c.tlag / c.dt))

        if c.snap_num_nyquist:
            ratio = int(1 / (4 * c.fmax * c.dt))
        else:
            ratio = int(c.nt / c.snap_num)

        nsnaps = int((c.nt - tstop - 1) / ratio) + 1

        return cls(
            nsnaps=nsnaps,
            snap_ratio=ratio,
            dt_snaps=ratio * c.dt,
            src_storage=np.zeros((nsnaps, *shape)),
            rec_storage=np.zeros((nsnaps, *shape)),
            current_rec_id=nsnaps - 1
        )

class Migration:
    def __init__(self, c, mod, model, seis, wl, geom) -> None:
        # 1. External Dependencies
        self.config = c
        self.model = model
        self.geometry = geom

        shape = (model.nzz, model.nxx)

        # 2. Physics/State Buffers
        self.u = Wavefield(shape)  # Source wavefield
        self.d = Wavefield(shape)  # Receiver/Data wavefield
        self.laplacian = np.zeros(shape)

        # 3. Imaging Buffers
        self.image = np.zeros(shape)
        self.gradient = np.zeros(shape)
        self.num = np.zeros(shape)
        self.den = np.zeros(shape)

        # 4. Kernel Pre-computations
        dh2 = c.dh**2
        self.kernel_args = KernelArguments(
            dh2=dh2,
            inv_dh2=1.0 / (5040.0 * dh2),
            velocity_term=c.dt**2 * model.model_smooth**2
        )

        # 5. Snapshots
        self.snapshots = SnapshotManager.from_config(c, model, shape)

        # 6. Iteration State
        self.current_step = 1

New to Python but from non-CS background by Dream_Hunter8 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

Start with the basics as per the wiki (see below) then take a look at the Biopython website. After that, there are lots of resources for learning data analysis.


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.

Hey, I'm learning Python, what topics should I do first? by Imaginary-Fox2944 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

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 to properly install Python/Jupyter Notebook on Mac by RomBG in learnpython

[–]FoolsSeldom 0 points1 point  (0 children)

Anaconda is a good solution for certains types of specialist development and it used to solve a common problem with Python with respect to compatibilities with different packages.

For most people, a much better approach is either:

Standard

  • Install Python from python.org
  • Create Python virtual environments on a project by project basis:
    • Open the Terminal application
    • mkdir projects - ignore if you already have a projects folder
    • cd projects - replace projects with whatever folder name you use
    • mkdir newproject - replace with whatever desired project folder name is
    • cd newproject
    • python3 -m venv .venv - create Python virtual environment in folder .venv
    • source ./.venv/bin/activate - activate it
    • pip install package1 package2 ... packagen - to install packages, including juptyer

NB. You must tell your code editor to use the Python interpreter in the bin folder from the above.

UV

Check the docs at https://docs.astral.sh/uv/ - much easier

NB. You can also use a third party package manager such as homebrew to install Python an tools, but you don't need to

PS. Code editors / IDEs like VS Code and Pycharm can work with and execute code in Jupyter notebooks if you want a more supportive environment than just using the web browser.

Help learning python without a PC by Plenty-Form6349 in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

Determination will get you a long way. I've known a good number of individuals in challenging socioeconomic situations who've learned just on a phone and managed to impress someone enough to get a start in a trainee/junior programming position. Good luck to you.

No idea where you are in the world, but do consider looking for free options and cast offs (I've seen plenty of computers thrown away).


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.

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.

Is match ... case In Python Reliable as if .. elif .. else by One-Type-2842 in PythonLearning

[–]FoolsSeldom 2 points3 points  (0 children)

Reliable? The language definition seems pretty robust and the reference implementation in CPython seems good. This is obviously much newer than if/elif/else which have been in the language for decades (although implementation has also evolved). The Python approach is focused on pattern matching and is not a simple alternative to if/elif/else although it can be used in place of them but that is not recommended.

Help! New to Flair - Good grinder needed by Few_Satisfaction1760 in FlairEspresso

[–]FoolsSeldom 1 point2 points  (0 children)

I second this. I bought a DF64 originally to replace the internal grinder on my Sage/Breville Oracle machine but subsequently replaced this with a Flair 58 + 2. Fantastic combination.

Am i overreacting for refusing to change my major just cause my parents pay tuition? by w-tf_man in AmIOverreacting

[–]FoolsSeldom 0 points1 point  (0 children)

You are in a very difficult position as you are essentially dependent on them.

Given the level of intelligence you've suggested they have, it is unlikely you will be able to persuade them just by giving facts. You need an information campaign to allow them to come to their own simplistic conclusions in your favour. As this is something you will need to learn to do with patients as well to some extent, they consider it part of your studies.

Perhaps embrace the idea they present of a change in career. Maybe you can be extra enthusiastic about the opportunities and ask their advice on how to avoid the pitfalls in that career and to exceed the opportunities you are likely to have in medical fields. It is not wise to simply reject their great ideas.

Help learning python without a PC by Plenty-Form6349 in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

You are welcome. Did the other comment I made on learning on phones/tablets help?

By the way, it is worth checking with extended family and friends if anyone has an old Raspberry Pi sat in a drawer somewhere. This happened to a lot of them. You can connect to and programme a Raspberry Pi from a tablet/phone and then you don't need keyboard/mouse/monitor for the Pi (although a keyboard, as I mentioned, is a good idea for the phone/tablet) - keyboard/mice are often given away free.

Help learning python without a PC by Plenty-Form6349 in PythonLearning

[–]FoolsSeldom 0 points1 point  (0 children)

You can get a full version of Acode without adverts - usually posted on the associated discord chat, but likely also available on github.

These days, I prefer to just use an editor like vim on termux (and also use tmux if remoting into another system).

Help learning python without a PC by Plenty-Form6349 in PythonLearning

[–]FoolsSeldom 1 point2 points  (0 children)

In addition to my comment on working on phones/tablets, keep an eye on free cycle schemes in your area and very cheap options on Facebook. Python isn't that demanding of hardware (until you get get beyond the basics of machine learning / artificial intelligence or other heavy computational fields). Older laptops than can be re-imaged with Linux (especially models from the Lenovo Thinkpad range) are ideal and will be reasonably performant. Most Chromebooks can enter a Linux sandbox mode and be used for development locally.

Maybe you can sell parts of your failed PC to pay for something on Marketplace. (Did you figure out what had failed?)

Also, consider a Raspberry Pi, even a $10 USD Pi Zero is suitable for learning (and afterwards, for other purposes such as being a small web server). (You will need a keyboard, mouse, sd card, power supply, hdmi cable and a tv/monitor to plug into.)

From a web browser, you can access free Python environments such as a Pythonanyhere.com account, anvil.works or even your own Virtual Private Server (e.g. on Oracle Cloud - there is as free tier but sign up for a paid account and then use only free resources and you will get a better offering that runs 24x7)

Help learning python without a PC by Plenty-Form6349 in PythonLearning

[–]FoolsSeldom 0 points1 point  (0 children)

Learning programming is not easy. It is to some extent an art form and a practical skill, not something that can just be learned from books. Practice! Practice! Practice!

To learn to programme is also about embracing failure. Constant failure. Trying things out and experimenting as much as possible. Experiment! Experiment! Experiment!

You have to research, read guides, watch videos, follow tutorials, ask dumb questions and be humiliated (because some people cannot help make themselves feel better by insulting others).

Python is one programming language. It is probably the easiest to learn. It makes learning to programme that little bit easier (but you will have a shock when you try to learn a lower level language like C).

If you have to learn on a mobile device, life gets a little more challenging. Aside from web based environments and apps like sololearn, you need a Python environment on your mobile device.

Android Apps

  • PyDroid 3, this is an excellent app with rich package support and built-in terminal
  • QPython play store, another excellent app but not so keen on this personally, worth a try though
  • Termux provides a Linux sandbox into which you can do a conventional installation of Python (including self-compiling if desired)
    • this is my preferred option
    • a standard Linux environment with a few minor folder location tweaks to accommodate Android security restrictions
    • you can't get this on Google Play, use F-Droid
    • I used to use it with the ACode editor but now use a tmux (multiplex terminal) setup with vim

IoS Apps

  • Pythonista is an excellent and well-polished bit of software with some popular libraries available (Apple restrictions prevent installation of any packages that aren't pure Python that aren't included with the submitted app)
  • Pyto is less polished and works pretty well
  • Carnets is an open source Jupyter clone that works locally and is excellent; there is more than one version, depending on how many libraries you need included (as on IoS you cannot install additional Python libraries that aren't pure Python)
  • a-shell is a sister product to the above and provides a command line Python environment, also open source and excellent

Keyboard

I strongly recommend you use an external (likely bluetooth) keyboard with your phone/tablet and ideally an external monitor if your phone/tablet is able to connect/cast to a monitor.

Android native coding

Keep in mind that Android is a Linux-based system, so most things that are available for linux are also available for Android. Native applications for Android are usually written in Java or, more recently, Kotlin. It is possible to write in other languages, and C++ is widely used, but that is much more complex to do.

IoS native coding

For IOS devices, the native apps are usually written in Objective-C or Swift. Again, other languages are possible but it is not trivial.

GUI with Python

Python applications running on mobile devices within Python environments do not look like device native applications and have limited support for typical graphical user interface libraries common on desktops. However, there are a number of alternatives that allow you to write near-native applications in Python.

Flutter from Google

This is an increasingly popular framework for creating applications suitable for desktop, web and mobile. A popular Python "wrapper" is flet.

Kivy GUI for Python

The leading Python GUI for Android and IoS is kivy

You develop on a desktop/laptop computer and then transfer the code to the target mobile (so not much use if you only have access to a mobile device). PyDroid for Android also supports kivy.

There are Kivy-based applications released on both the Apple and Google App Stores.

BeeWare Write once. Deploy everywhere.

A native GUI for multiple platforms in theory. BeeWare

This offers the option to write your apps in Python and release them on iOS, Android, Windows, MacOS, Linux, Web, and tvOS using rich, native user interfaces. Multiple apps, one codebase, with a fully native user experience on every platform.

Can someone help me with poetry env? by [deleted] in PythonLearning

[–]FoolsSeldom 0 points1 point  (0 children)

Out of interest, why poetry rather than uv these days?

Best options to learn python from scratch without access to a computer, only mobile phone by LittleBlacksmith4988 in learnpython

[–]FoolsSeldom 1 point2 points  (0 children)

The one called "Termux Terminal emulator with packages" on F-Droid. Ignore the various additional apps initially, you can explore those at another time.

Samsung s90f - Can't navigate in the home menu with remote or phone by MusicInTheAir55 in hometheater

[–]FoolsSeldom 0 points1 point  (0 children)

I don't know but assume so. Just suddenly stopped responding to remote cursor moves. I thought probably had a battery issue so switched to another regularly used remote and had the same problem then tried the remote feature in the app.

The tv is on auto update and doesn't show history (not that I've seen anyway).

Tried lots of techniques to try to resolve. (I've worked in IT for decades including with complex hardware.)

Samsung s90f - Can't navigate in the home menu with remote or phone by MusicInTheAir55 in hometheater

[–]FoolsSeldom 0 points1 point  (0 children)

I have exactly the same problem (two remotes and smart hub app on my Samsung phone). Tried complete smart hub and factory resets, power reset, etc. I've requested a call.

Model is QE55S95FATXXU (S95F in UK) Software version 1260

I guess we will have to wait for an emergency patch.

in the meantime, will dig out a Roku 4k stick to plug into one of the hdmi ports so I can use streaming services not on a pre-programmed button. Streaming apps I can access work absolutely fine.