Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: Good way to ignore case when searching elements?
Post: Good way to ignore case when searching elements?

Hello, In the files I need to work with, I notice that the values in the following meta line can be either lower-case or capitalized. What would be the right way to convert them to lower-case regard...
Winfried General Coding Help 1 65 4 hours ago
  Question Thread: Right way to open files with different encodings?
Post: Right way to open files with different encodings?

Hello, Some of the files could be Windows (latin1, iso9959-1, cp1252), others could be utf-8. Is try/except the right way to do it? #with open(file, 'r') as f: #with open(file, 'r',encoding='utf-8'...
Winfried General Coding Help 2 180 Apr-23-2024, 08:49 AM
    Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?

Thanks much. The list I'll work on is tiny enough that I don't need a generator, but it's nice to know that it's available. Ditto for one liners and function annotations.
Winfried General Coding Help 10 330 Apr-23-2024, 07:52 AM
    Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?

Thank you. (Apr-22-2024, 07:10 PM)Gribouillis Wrote: files = [os.path.join(d, f) for d, _, files in os.walk(root) for f in files] I'm not used to one-liners. Am I correct in understanding it's the ...
Winfried General Coding Help 10 330 Apr-23-2024, 02:02 AM
    Thread: Loop through all files in a directory?
Post: Loop through all files in a directory?

Hello, I need to find all the files located under a given directory, including all the sub-directories it may contain. Is this a/the right way to do it? import os import glob for filename in glob....
Winfried General Coding Help 10 330 Apr-22-2024, 06:16 PM
    Thread: How to add multi-line comment section?
Post: How to add multi-line comment section?

Edit (since this forum doesn't support deleting a thread): My mistake. After using the (shift+)TAB keys, the script runs. Guess there were useless TAB characters. ----------------- Hello, Is there...
Winfried General Coding Help 1 210 Mar-24-2024, 01:33 PM
    Thread: Running Python script through Task Scheduler?
Post: RE: Running Python script through Task Scheduler?

I'll try that instead. Thank you!
Winfried General Coding Help 8 492 Mar-10-2024, 07:24 PM
    Thread: Running Python script through Task Scheduler?
Post: RE: Running Python script through Task Scheduler?

What a pain… What about using PyInstaller to compile the whole thing into a single binary?
Winfried General Coding Help 8 492 Mar-10-2024, 06:38 PM
    Thread: Running Python script through Task Scheduler?
Post: RE: Running Python script through Task Scheduler?

Thanks. Yes, like I said, "The script works when launched manually." After I followed the instructions above, I can see the screen flicker every minute (looks like a CMD window opens and closes real...
Winfried General Coding Help 8 492 Mar-10-2024, 06:03 PM
  Question Thread: Running Python script through Task Scheduler?
Post: Running Python script through Task Scheduler?

Hello, This is my first try at running a Python (3.12.0) script through Windows 10's Task Scheduler… and it didn't work (as pretty much expected). It's a simple script that 1) fetches a web page fro...
Winfried General Coding Help 8 492 Mar-10-2024, 03:39 PM
    Thread: [SOLVED] Correct way to convert file from cp-1252 to utf-8?
Post: RE: [SOLVED] Correct way to convert file from cp-1...

Turns out there's a lot easier solution: Just open the file and feed it to Beautiful Soup, which will take care of 1) converting data to utf-8 if needed, and add/edit the relevant meta line in the hea...
Winfried General Coding Help 8 870 Feb-29-2024, 12:30 AM
    Thread: [SOLVED] Correct way to convert file from cp-1252 to utf-8?
Post: RE: Correct way to convert file from cp-1252 to ut...

Looks like it. After converting it to utf-8, chardet says a file is still "ascii with confidence 1.0" while both Notepad++ and Notepad2 say it's utf-8. Bottom line: chardet doesn't seem reliable to ...
Winfried General Coding Help 8 870 Feb-26-2024, 06:19 PM
    Thread: [SOLVED] Correct way to convert file from cp-1252 to utf-8?
Post: RE: Correct way to convert file from cp-1252 to ut...

Using this code, the second run still says files are not in utf-8. It doesn't look like it's the right way to convert Windows files to utf-8: for file in files: rawdata = open(file, "rb").read() ...
Winfried General Coding Help 8 870 Feb-26-2024, 03:38 PM
    Thread: [SOLVED] Correct way to convert file from cp-1252 to utf-8?
Post: RE: Correct way to convert file from cp-1252 to ut...

The two lines you mean? #data = open(file, "r").read() #data.encode(encoding = 'UTF-8', errors = 'strict') data = rawdata.decode(encoding=encoding) #with open(file, 'w', encoding='utf-8') as outp: wit...
Winfried General Coding Help 8 870 Feb-26-2024, 03:21 PM
  Question Thread: [SOLVED] Correct way to convert file from cp-1252 to utf-8?
Post: [SOLVED] Correct way to convert file from cp-1252 ...

Hello, In a directory, I have a bunch of HTML files that were written in cp-1252 (ie. Latin1) that I need to convert to utf-8. The following doesn't seem to work: After running the loop once, the se...
Winfried General Coding Help 8 870 Feb-26-2024, 02:28 PM
    Thread: [Faircom CTree] Access from Python?
Post: RE: [Faircom CTree] Access from Python?

I'll give it a shot, thank you.
Winfried Data Science 2 557 Feb-23-2024, 01:26 PM
  Question Thread: [Faircom CTree] Access from Python?
Post: [Faircom CTree] Access from Python?

Hello, There's a long dead application — development stopped in the late 90's — that used Faircom's CTree database engine (the DLL says: Company=FairCom Corporation, Description=CTree, Prod version=4...
Winfried Data Science 2 557 Feb-21-2024, 03:52 PM
  Question Thread: [SOLVED] Tiny web server as standalone executable?
Post: [SOLVED] Tiny web server as standalone executable?

Hello, I need a basic, standalone web server with support for directory listing. Windows' antivirus blocks Mongoose ("Trojan Win32 Wacatac.B!ml"), and neither Ritlabs Tinyweb server, Rebex Tiny Web ...
Winfried General Coding Help 0 338 Feb-09-2024, 11:48 AM
    Thread: [SOLVED] Pad strings to always get three-digit number?
Post: RE: Pad strings to always get three-digit number?

Thank you.
Winfried General Coding Help 2 349 Jan-27-2024, 05:23 PM
    Thread: [SOLVED] Pad strings to always get three-digit number?
Post: [SOLVED] Pad strings to always get three-digit num...

Hello, I've tried different things, but still can't strings to always be left-padded, three-digits long even for strings that contain a dash sign: file1 = open('input.txt', 'r') for line in file1.re...
Winfried General Coding Help 2 349 Jan-27-2024, 03:46 PM

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020