26
23
submitted 1 year ago by rev@ihax0r.com to c/python@lemmy.ml

Meta is dedicating 3 engineers to get the nogil patches into cpython. There are some other companies stepping up as well. This is huge this is the closest we have ever been to solving the issue of the GIL.

27
16
submitted 1 year ago by nathanpc@lemmy.ml to c/python@lemmy.ml

Hello Python community! There are a lot of resources online targeted at beginners that want to learn Python but very rarely do you see articles talking about moving to Python when you already have tons of experience in other languages like Ruby, and especially, many years of Perl experience and is interested in moving to Python.

I'm not looking for information on how to program in Python, that's really easy to find and most of the learning curve will be learning about the standard libraries and overcoming the years of muscle memory from other languages. I'm looking for information on the following topics:

  • What's the recommended project structure for a library or a program that'll be distributed via PyPI?
  • What are the general best practices to follow when writing "clean Python code"?
  • What's the most commonly followed style guide for the language?
  • How does import work internally and how does it perform its path lookup for local files (specifically for importing modules internal to a project)?
  • How to properly set up pyenv for a project? (This one is tricky for me because the Python community loves pyenv and I'm used to having packages globally installed in Ruby and Perl)
28
5
submitted 1 year ago by Ajsra@lemmy.ml to c/python@lemmy.ml
29
2
submitted 1 year ago* (last edited 1 year ago) by SurpriseCandid8978@lemmy.ca to c/python@lemmy.ml

Hi,

Does Anyone have any great resources to learn python for a non-programmer? Youtube? Free online courses, etc?

Im starting out and there is a lot out there. They all look good too.

So far, i got python installed lol.

Thanks,

Edit: thanks everyone. I have some homework to do and check out all the resources !

30
2
submitted 1 year ago by uthredii@lemmy.ml to c/python@lemmy.ml
31
1
32
2
submitted 1 year ago by aswin@lemmy.sdf.org to c/python@lemmy.ml

Pyscan v0.1.4 | GitHub

Pyscan is the fastest CLI tool to find dependency vulnerabilities in your python projects.

  • blazingly fast scanner that can be used within large projects.
  • automatically finds requirements.txt, pyproject.toml or, the source code.
  • can be integrated into existing build processes.
  • In its early stage, thus hasn't been battle-hardened yet.

Install

pip install pyscan-rs

look out for the "-rs" part or

cargo install pyscan

Usage

Go to your python source directory (or wherever you keep your requirements.txt/pyproject.toml) and run:

> pyscan

or

> pyscan -d path/to/src

Pyscan is a tool written in Rust that uses OSV, which is an open source vulnerabilities database, which inspired me to make this tool.

33
1
Compiling typed Python (bernsteinbear.com)
submitted 1 year ago by pumpkin@sh.itjust.works to c/python@lemmy.ml
34
1
submitted 1 year ago by Limeey@lemmy.world to c/python@lemmy.ml

I switched from notebook to labs recently and I'm missing how the notebook name is displayed in notebooks. it seems like the only way to know which notebook I'm in now is through the tab, but if I have multiple tabs open it compresses them.

Is there any extension or something that will display the notebook name (and make it easily editable) like in notebooks?

35
1
36
1
submitted 1 year ago by pumpkin@sh.itjust.works to c/python@lemmy.ml
37
1
submitted 1 year ago by radarsat1@lemmy.ml to c/python@lemmy.ml

Let's say I have a context manager that provides a resource that then mutates on exit:

from contextlib import contextmanager

@contextmanager
def context():
    x = ['hi']
    yield x
    x[0] = 'there'

I found that if I want to make another context class that uses this, such that the context (before mutation) is valid, I have to pass it in:

class Example1:
    def __init__(self, obj):
        self.obj = obj
    def use_obj(self):
        print(self.obj)
    def __enter__(self):
        print("start")
        return self
    def __exit__(self, *exc):
        print("end")

with context() as x:
    with Example1(x) as y:
        y.use_obj()

prints:

start
['hi']
end

However, what I don't like is, let's say that obj is an internal detail of my class. I don't want the user to have to define it beforehand and pass it in.

The only way I can figure how to do this is by calling the context manager's __enter__() explicitly:

class Example2:
    def use_obj(self):
        print(self.obj)
    def __enter__(self):
        print("start")
        self.ctx = context()
        self.obj = self.ctx.__enter__()
        return self
    def __exit__(self, *exc):
        print("end")
        self.ctx.__exit__(None, None, None)

with Example2() as y:
    y.use_obj()

which also prints,

start
['hi']
end

For comparison, just as some other random attempt, the following doesn't work because the context ends when self.obj is created:

class Example3:
    def use_obj(self):
        print(self.obj)
    def __enter__(self):
        print("start")
        with context() as x:
            self.obj = x
        return self
    def __exit__(self, *exc):
        print("end")

with Example3() as y:
    y.use_obj()

which prints,

start
['there']
end

Okay, so my point is that Example2 is the right solution here. But, it's really ugly. So my question is, is there a better way to write Example2?

38
1

I'm setting up a new laptop and considering which of the (many) environment managers to use this time around. My standard has been miniconda, since a big plus for me is the ability to set and download specific python version for different projects all in one tool. I also quite like having global access to different environments (i.e. environments aren't tied to specific projects). I typically have a standard GenDataSci environment always available for initially testing things out, then if I know I'll be continuing as a single project I'll make a stand alone environment for it.

But I've also used poetry for tighter control and reproducibility when I'm actually packaging to publish on PyPI. Hatch looks interesting as well but I can't tell if it includes the ability to have separate python version installs for each environment.

What workflows and managers are people using now?

39
1
submitted 1 year ago by gwilikers@lemmy.ml to c/python@lemmy.ml

Brendan Metcalfe's intro series to list comprehensions is one of the best I've come across. In addition to showing how to use them, he compares it to other similar methods and shows why LCs can be more effective. Wanted to share his stuff here.

40
2

cross-posted from: https://programming.dev/post/21515

Some surprising, but valid, python syntax examples.

41
1
submitted 1 year ago by recnexus@beehaw.org to c/python@lemmy.ml

I’m looking for some conference talks about python that I could watch during some downtime at work. Give me your favorites!

42
0
submitted 1 year ago by lntl@lemmy.ml to c/python@lemmy.ml

I have a large object that I want to save to the disk because it takes a minute to generate. The OOM reaper kills the process while pickle.dump ing the object.

It's a tuple of dicts of tuple of array.array.

Can pickle dump in chunks? If not, is there another technique I can use?

43
1
submitted 1 year ago by jnovinger@lemmy.ml to c/python@lemmy.ml
44
1
submitted 1 year ago by jnovinger@lemmy.ml to c/python@lemmy.ml
45
1
submitted 1 year ago by jnovinger@lemmy.ml to c/python@lemmy.ml

Some neat tricks for using Makefiles with Python that I hadn't seen before. The one I have seen, having a help target, has been super useful in team environments and for debugging when used with variables.

46
1
submitted 1 year ago by pingveno@lemmy.ml to c/python@lemmy.ml
47
1
submitted 2 years ago by cypherpunks@lemmy.ml to c/python@lemmy.ml
48
1
SciPy 2023 Program Review Committee (www.scipy2023.scipy.org)
submitted 2 years ago by kir0ul@lemmy.ml to c/python@lemmy.ml
49
1
submitted 2 years ago by cypherpunks@lemmy.ml to c/python@lemmy.ml

(there is a discussion about this post here https://news.ycombinator.com/item?id=34787092 ...)

50
2
submitted 2 years ago by cypherpunks@lemmy.ml to c/python@lemmy.ml
view more: ‹ prev next ›

Python

3222 readers
1 users here now

News and discussions about the programming language Python


founded 5 years ago
MODERATORS