Python

6419 readers
4 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
126
11
submitted 8 months ago* (last edited 8 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.

127
9
submitted 8 months ago by jnovinger to c/python
128
 
 
129
 
 

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.

130
131
 
 

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.

132
 
 

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.

133
25
Combining Rust and Python (www.youtube.com)
submitted 8 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!

134
13
submitted 8 months ago by learnbyexample to c/python
135
 
 

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

136
137
25
submitted 8 months ago by learnbyexample to c/python
138
 
 

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!

139
140
31
submitted 9 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?

141
28
submitted 9 months ago* (last edited 9 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.

142
143
149
submitted 9 months ago* (last edited 9 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.

144
145
146
 
 

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

147
148
12
submitted 9 months ago by norambna to c/python
149
4
submitted 9 months ago by [email protected] to c/python
 
 

I want to write my python code using thonny, but I seem to be getting some error when trying to open a file in thonny (Ctrl + O) and when instantiating a window, for example with TKinter. The exact error can be found here:

17:21:40.785 WARNING thonny.ui_utils: Zenity returned code 255 and stderr 'Diese Option steht nicht zur Verfügung. Bitte verwenden Sie »--help« für alle Anwendungsmöglichkeiten.\n' The text is german and says "This option is not available. lease use --help for viewing all options". For now I'll just use vim instead, but I really wanna go back to thonny. Has anyone ever experienced something like this before?

In case it matters, here is output I get from the terminal when running the program on startup:


17:25:36.099 INFO    thonny: Thonny version: 4.0.1
17:25:36.099 INFO    thonny: cwd: /home/marty
17:25:36.099 INFO    thonny: original argv: ['/usr/bin/python3', '/usr/bin/thonny']
17:25:36.100 INFO    thonny: sys.executable: /usr/bin/python3
17:25:36.100 INFO    thonny: sys.argv: ['/usr/bin/thonny']
17:25:36.100 INFO    thonny: sys.path: ['/usr/bin', '/usr/lib/python311.zip', '/usr/lib/python3.11', '/usr/lib/python3.11/lib-dynload', '/home/marty/.local/lib/python3.11/site-packages', '/usr/local/lib/python3.11/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.11/dist-packages']
17:25:36.100 INFO    thonny: sys.flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0, dev_mode=False, utf8_mode=0, warn_default_encoding=0, safe_path=False, int_max_str_digits=-1)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/thonny/__init__.py", line 235, in launch
    _delegate_to_existing_instance(sys.argv[1:])
  File "/usr/lib/python3/dist-packages/thonny/__init__.py", line 322, in _delegate_to_existing_instance
    sock, secret = _create_client_socket()
                   ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/thonny/__init__.py", line 365, in _create_client_socket
    client_socket.connect(get_ipc_file_path())
ConnectionRefusedError: [Errno 111] Connection refused
17:25:37.820 INFO    thonny.plugins.cpython_frontend.cp_front: Creating LocalCPythonProxy
17:25:37.820 INFO    thonny.running: Starting the backend: ['/usr/bin/python3', '-u', '-B', '-m', 'thonny.plugins.cpython_backend.cp_launcher', '/home/marty'] /home/marty
150
view more: ‹ prev next ›