Welcome to Python! A great language for program development.
Answers might be platform-dependent (are you using WIndows, Linux, etc.).
However, the following works for me on WIndows. You can put it in the
startup.py file so you don't have to type it every time you start up the
IDLE.
import
On 05/06/2024 04:09, Cameron Simpson wrote:
On 04Jun2024 22:43, Rob Cliffe wrote:
import os
def cls(): x=os.system("cls")
Now whenever you type
cls()
it will clear the screen and show the prompt at the top of the screen.
(The reason for the "x=" is: os.system returns a result, in this case
OK, here is the advanced version:
import os
class _cls(object):
def __repr__(self):
os.system('cls')
return ''
cls = _cls()
Now when you type
cls
it clears the screen. The only flaw is that there is a blank line at
the very top of the screen, and the ">>>" prompt appears on
import itertools
def chunk1(seq):
return [ ch * len(list(grp)) for (ch, grp) in itertools.groupby(s) ]
def chunk2(seq):
return [ (ch, len(list(grp))) for (ch, grp) in itertools.groupby(s) ]
s='aaabbaa'
print(chunk1(s))
print(chunk2(s))
###
Program out
Recently I acquired a new laptop running WIndows 11; my previous one
uses WIndows 10. I encountered a strange problem:
I am using the win32clipboard backage (part of pywin32), and when I use
SetClipboardData() to write text which consists ***entirely of digits***
to the clipboard, I either get
Consider this scenario (which I ran into in real life):
I want to open a text file and do a lot of processing on the lines
of that file.
If the file does not exist I want to take appropriate action, e.g.
print an error message and abort the program.
I might write it like this:
try:
On 07/07/2024 02:08, Cameron Simpson wrote:
On 06Jul2024 11:49, Rob Cliffe wrote:
try:
f = open(FileName) as f:
FileLines = f.readlines()
except FileNotFoundError:
print(f"File {FileName} not found")
sys.exit()
# I forgot to put "f.close()" here -:)
for ln in File Lines:
On 06/07/2024 12:57, Oscar Benjamin via Python-list wrote:
On Sat, 6 Jul 2024 at 11:55, Rob Cliffe via Python-list
wrote:
Consider this scenario (which I ran into in real life):
I want to open a text file and do a lot of processing on the lines
of that file.
If the file does not
On 07/09/2024 16:48, Karsten Hilbert via Python-list wrote:
Dear all,
unto now I had been thinking this is a wise idiom (in code
that needs not care whether it fails to do what it tries to
do^1):
conn = psycopg2.connection(...)
curs = conn.cursor()
try:
c
On 07/09/2024 22:20, Karsten Hilbert via Python-list wrote:
Am Sat, Sep 07, 2024 at 02:09:28PM -0700 schrieb Adrian Klaver:
Right, and this was suggested elsewhere ;)
And, yeah, the actual code is much more involved :-D
I see that.
The question is does the full code you show fail?
The co
On 12/11/2024 08:52, Loris Bennett via Python-list wrote:
Cameron Simpson writes:
Generally you should put a try/except around the smallest possible
piece of code.
That is excellent advice.
Best wishes
Rob Cliffe
So:
config = configparser.ConfigParser()
try:
config.r
From the documentation on the sys module at
https://docs.python.org/3/library/sys.html:
sys.call_tracing(/func/, /args/)
Call |func(*args)|, while tracing is enabled. The tracing state is
saved, and restored afterwards. This is intended to be called from a
debugger from a checkpoint, to recurs
On 19/05/2025 23:11, Thomas Passin via Python-list wrote:
On 5/19/2025 5:49 PM, Mats Wichmann via Python-list wrote:
On 5/19/25 09:51, Jonathan Gossage via Python-list wrote:
I have created a dynamic class using the type() function:
x = type('MyFlags', (), {'Flag1': 1, 'Flag2': 2, 'Flag3: 4,
On 25/05/2025 00:18, Mats Wichmann wrote:
On 5/23/25 16:05, Rob Cliffe via Python-list wrote:
On 23/05/2025 18:55, Mats Wichmann wrote:
On 5/22/25 21:04, Rob Cliffe via Python-list wrote:
It occurs to me that it might be useful if Python provided a
function to search for a file with a
It occurs to me that it might be useful if Python provided a function to
search for a file with a given name in various directories (much as the
import.import_lib function searches for a module in the directories in
sys.path).
This function would perhaps be best placed in the os.path or os modu
On 22/05/2025 23:45, Mats Wichmann wrote:
On 5/22/25 13:59, Michael F. Stemper via Python-list wrote:
I recently wrote a program to do some record-keeping for me. I found
myself hard-coding a bunch of different values into it. This didn't
seem right, so I made my first use of configparser.Conf
On 23/05/2025 18:55, Mats Wichmann wrote:
On 5/22/25 21:04, Rob Cliffe via Python-list wrote:
It occurs to me that it might be useful if Python provided a function
to search for a file with a given name in various directories (much
as the import.import_lib function searches for a module in
On 17/06/2025 00:19, Omar Ahmed via Python-list wrote:
Hi all,
I would like to propose a potential addition to Python's `import` syntax that
would improve clarity and ergonomics for cases where developers want both full
module access *and* a local alias to a specific attribute within that mod
I was surprised to find that in configparser, getboolean() does not
raise KeyError for a non-existent config parameter.
Demo program (Python 3.11.5, Windows 11):
import configparser
config = configparser.ConfigParser()
config.read('ThisFileDoesNotExist.ini') # This line could be removed
MY_BOOL
I am using Python 3.13.3 on Windows 11.
I notice that the compiler can optimise (some) constant expressions
containing operators plus numbers or strings, e.g.
2+2 is compiled as 4
1 + (2.5 + 3+4j) is compiled as 6.5+4j
'a' + 'b' is compiled as 'ab'
and even 'a'*4096 is compiled a
101 - 120 of 120 matches
Mail list logo