Python

6287 readers
8 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
101
16
submitted 6 months ago* (last edited 6 months ago) by jnovinger to c/python
 
 

The repo also links to some similar tools, like coveragepy, uncalled, and dead.

102
10
submitted 6 months ago* (last edited 6 months ago) by [email protected] to c/python
 
 

the code on the website is javascript here it is, make sure to create dice images for it to work (e.g dice1.png):

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dice Roller</title>
<style>
    body {
        font-family: Arial, sans-serif;
    }
    #result-frame {
        margin-top: 20px;
    }
</style>
</head>
<body>
<h2>Dice Roller</h2>
<label for="num-dice">Choose Number of Dice:</label><br><br>
<select id="num-dice">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
</select>
<button onclick="rollDice()">Roll</button>
<div id="result-frame"></div>

<script>
function rollDice() {
    var numDice = parseInt(document.getElementById('num-dice').value);
    var resultFrame = document.getElementById('result-frame');
    resultFrame.innerHTML = ''; // Clear previous results

    var diceImages = [];
    for (var i = 1; i <= 6; i++) {
        var img = document.createElement('img');
        img.src = 'https://www.slyautomation.com/wp-content/uploads/2024/03/' + 'dice' + i + '.png'; // Change the path to match your uploaded images
        diceImages.push(img);
    }

    for (var j = 0; j < numDice; j++) {
        var result = Math.floor(Math.random() * 6); // Random result from 0 to 5
        var diceImage = diceImages[result].cloneNode();
        resultFrame.appendChild(diceImage);
    }
}
</script>
</body>
</html>
103
11
submitted 6 months ago* (last edited 6 months ago) by [email protected] to c/python
 
 

Hi, I'm currently using this to log my python process

logging.basicConfig(filename='filename.log', level=logging.DEBUG)

logger = logging.getLogger()

sys.stderr.write = logger.error

sys.stdout.write = logger.info

And then using print(f'{datetime.now()} log message') where I want to log.

It's working OK, buy I would like to live it to ic, but can't find any info on how to send the ic output to the logger.

Thanks for any help.

104
9
submitted 6 months ago by jnovinger to c/python
105
 
 
106
 
 

Hi,

Following my previous post where quickly share code ?

I'm looking for a pastebin / git / github self-hosted software written in ๐Ÿ Python.

Here the features that I'm looking for (anyway like it's in Python I could create my self the missing one afterward :)

  • self-hosted, (but may have some instance public online)
  • compatible with git (and therefore history log )
  • syntax highlight for a various languages (especially ๐Ÿ Python )
  • Can show the difference between versions (modified, added, removed ) with color and nice interface.
  • Fully LOSS (aka FOSS)

Thanks.

107
108
 
 

cross-posted from: https://lemmy.ml/post/13397153

I'm just trying to control my smartlights with a script, it seems to be having a lot of problems, I really don't know what I'm doing, i'd appreciate any help I can get

Once I have a script that can individually turn lights on/off i can edit the rest myself, I just can't get the base functionality working.

109
 
 

If you care about performance, you may want to avoid CSV files. But since our data sources are often like our family, we can't make a choice, we'll see in this blog post how to process a CSV file as fast as possible.

110
25
Combining Rust and Python (www.youtube.com)
submitted 7 months ago by [email protected] to c/python
 
 

In this video, I'll show you how to seamlessly integrate Rust with Python using Pyo3. This library allows you to write Python modules with Rust. This means that we get the speed and safety of Rust along with Python's easy-to-use features!

111
13
submitted 7 months ago by learnbyexample to c/python
112
 
 

korn shell wrapper that outputs python code: you write shell > out comes the snake

113
114
25
submitted 7 months ago by learnbyexample to c/python
115
 
 

I'm sorry if this isn't the place to ask this, I also asked over at [email protected].

So what I want to do is this: Two RasPis are at different locations. They're on different networks but have internet access. Pressing a button on one of the Pis turns on an LED over at the other Pi via GPIO. How can I make the communication work? My first thought was Telegram bots as I'm familiar with those for notifications but you can't have Telegram bots communicate with each other, sadly. Is there a good (and secure) solution to this? Preferably using Python code and without continuous costs like server hosting, etc?

Thanks!

116
117
31
submitted 7 months ago by [email protected] to c/python
 
 

Did you know it takes about 17,000 CPU instructions to print("Hello") in Python? And that it takes ~2 billion of them to import a module?

118
28
submitted 7 months ago* (last edited 7 months ago) by [email protected] to c/python
 
 

Context

Being a full stack developer, I have decent experience with both python and Typescript. I often use python for API development and I have been trying to write code that is pep-484 compliant (aka fully typed). However, often I get the feeling that if I was using TypeScript it would be much easier.

That got me wondering why there isn't a fully typed language that compiles to python.

I am aware of some arguments, so I am going to get the conversation started by providing my thoughts on them.

ts2python

ts2python is a TypeScript to python compiler.

Unfortunately, it covers only a small subset of python's capabilities. I am not sure why this hasn't been adopted and/or expanded to cover more of python's capabilities, but I can see possible issues with some python features that are not supported by TypeScript like context managers or operator overloading.

Still wondering if it would be possible to extend the TypeScript compiles so it would support such features?

pep-484

pep-484 describes how to provide type hints for python, it's not ideal but good enough that don't have to invent a new language.

IMO that's a trap, pep-484 (and other typing related peps) are not a good enough solution, on the contrary sometimes they are straight up misleading.

For example, consider the stubs for comparisons with built-in types, you would notice that they are defined as __op__(self, other: Any) -> bool: ... which is not correct as when other implements __opposite_op__ that is called instead of builtin.__op__, and it's return value may be of a different type.

Typing tools have not caught up with it, right now only pyright has full compliance with pep-484 (and other typing related peps). For that reason, SQLAlchemy had to introduce more than a couple of workarounds so MyPy can understand what's is happening behind the scenes, even for features that are pep-484 compliant.

Use Another Language

Python was never meant to be fully typed, and they make it clear.

True, but there are a bunch of libraries unique to python that make it a mandatory choice for many tasks. Things are changing and other options become available, but it's going to take time until there is another viable alternative.

Conclusion

Interested to read your thoughts.

  1. Is there another reason typing support hasn't advanced?
  2. Are you satisfied with typing support for python?
  3. Are you transitioning to another language?
  4. Are you aware of any new and exciting typing tools?

Of course, if typing is not an issue for you, that's okay, every software has different constraints.

119
120
149
submitted 8 months ago* (last edited 8 months ago) by [email protected] to c/python
 
 

Previously LGPL, now re-licensed as closed-source/commercial. Previous code taken down.

Commercial users pay $99/year, free for personal use but each user has to make a free account after a trial period.

121
122
123
 
 

Been 2 months since the update but I don't see any news about code editor support for the new syntax.

This kind of makes sense, i don't expect code editor support to pop up so fast, but i was at least hoping to hear some news about it.

The PEP in question: PEP 695

124
125
12
submitted 8 months ago by norambna to c/python
view more: โ€น prev next โ€บ