Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <utfo33$1o6mu$3@dont-email.me>
Deutsch   English   Français   Italiano  
<utfo33$1o6mu$3@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: DFS <nospam@dfs.com>
Newsgroups: comp.os.linux.advocacy
Subject: Re: Why Python When There Is Perl?
Date: Wed, 20 Mar 2024 18:31:00 -0400
Organization: A noiseless patient Spider
Lines: 290
Message-ID: <utfo33$1o6mu$3@dont-email.me>
References: <17be420c4f90bfc7$63225$1585792$802601b3@news.usenetexpress.com>
 <utd86u$1ipcj$1@solani.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 20 Mar 2024 22:30:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="37891cf52e1fbf2d7a6dba8b75260a75";
	logging-data="1841886"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/yrd8ohPrGxKXaqtsZ40wQ"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:jFDx2Shf4Ccc+aUJJybZ5svEMdU=
In-Reply-To: <utd86u$1ipcj$1@solani.org>
Content-Language: en-US
Bytes: 10050

On 3/19/2024 7:47 PM, Physfitfreak wrote:

> I think, if I had not relied on COLA to provide help on these matters, 
> by now, I'd be months into fruitful learning of ... probably C++ and 
> into several exciting programming projects.


First off, don't listen to ANYTHING Feeb says about programming.  He's 
incompetent, a liar, a nutcase, and makes contradictory statements all 
the time.

"Nothing but C from now on!"
"Only assembly for me from now on!"
"Python is for talentless idiots"
"Use Perl"
"C++ is for degenerate sissies"
"C++ is too complex"
"I despise OO programming"
"most programmers don't program.  They will use frameworks that
   literally produce the code for them."

That's all lies and idiocy.

I recently showed you 3 versions (C, python, VBA) of the same program. 
Python was the fewest lines of code, looked the cleanest, and was 
quickest to write.

After I learned enough python, I started working on the same problems 
with C.  C executes 5x to 10x faster than Python, but requires 3x to 5x 
the amt of time and code.  Note: you will NEVER recoup the extra C 
development time with savings in program execution time.

I'd say work on learning Python and C at the same time.  Leave C++ for 
later.


> This place is wasteful. It is like a drinking parlor. You go there 
> everyday and drink and joke and curse and argue, but in the background, 
> it is making you an alcoholic, making you drift.

If you wanted to focus on programming, you would.  Don't blame cola for 
your moral shortcomings.

Here's something to get you started with python.  This code reads the 
Linux kernel CREDITS file, parses it, and posts the data to a SQLite 
database table.  I just now wrote the python, but the original program 
was in C 3 years ago (for yet another programming challenge that weasel 
Feeb couldn't handle).


======================================================================
Python
======================================================================

import sqlite3

#copy or concat lines into string
#if entry has 1 linetype (NEWPDS), copy line into var
#if entry has 2+ of the same linetype, concat lines
def processvals(val, data, sep):
	if val[0] == ' ':
		val = data
	else:
		val += sep
		val += data
	return val

#strings
entry,Nval,Eval,Wval,Pval,Dval,Sval = ' ',' ',' ',' ',' ',' ',' '

#create and open new SQLite db file
dbname = "kernel_credits_py.db";
conn = sqlite3.connect(dbname)
db = conn.cursor()

#create table
db.execute("DROP TABLE IF EXISTS CREDITS;")
db.execute("BEGIN TRANSACTION;")
sql =  "CREATE TABLE CREDITS(nameid INTEGER NOT NULL PRIMARY KEY, name 
TEXT NOT NULL, email TEXT DEFAULT 'na' NOT NULL, web TEXT DEFAULT 'na' 
NOT NULL, pgp TEXT DEFAULT 'na' NOT NULL, description TEXT DEFAULT 'na' 
NOT NULL, address TEXT DEFAULT 'na' NOT NULL);";
db.execute(sql)

#read kernel CREDITS file, post data to db table
#each credit entry has one name, and 0+ other lines
creditsfile = "KERNEL_CREDITS.txt"
lines = open(creditsfile,'r').readlines()
for line in lines:
	if len(line) > 3: entry = line[3:-1]  #drop NEWPDS prefixes
	if line[0]=='N': Nval = entry
	if line[0]=='E': Eval = processvals(Eval,entry," / ")
	if line[0]=='W': Wval = processvals(Wval,entry," / ")
	if line[0]=='P': Pval = processvals(Pval,entry," / ")
	if line[0]=='D': Dval = processvals(Dval,entry," / ")
	if line[0]=='S': Sval = processvals(Sval,entry,", ")
	
	if line[0] == '\n':
		sql = "INSERT INTO CREDITS (name,email,web,pgp,description,address) 
VALUES (?,?,?,?,?,?);";
		db.execute(sql,(Nval, Eval, Wval, Pval, Dval, Sval))
		entry,Nval,Eval,Wval,Pval,Dval,Sval = ' ',' ',' ',' ',' ',' ',' '
		
conn.commit()

#print data in table
rows = db.execute("SELECT * FROM CREDITS ORDER BY nameID;")
for row in rows:
	for i,colname in enumerate(db.description):
		print("%-12s = %s" % (colname[0], row[i]))
	print()
	
#count rows in table
db.execute("SELECT COUNT(*) FROM CREDITS;")
print("Done.  %d records were posted to SQLite database '%s'" % 
(db.fetchone()[0],dbname))

#version
print("running SQLite %s" % sqlite3.sqlite_version)

db.close()
conn.close()

======================================================================





======================================================================
C
======================================================================
// 1. install libsqlite3-dev (sudo apt install libsqlite3-dev)
// 2. copy the Linux kernel CREDITS file to the folder this program is in
// 3. rename it KERNEL_CREDITS.txt

// compilation: gcc -Wall source.c -o executable -lsqlite3

#include <sqlite3.h>
#include <stdio.h>
#include <string.h>

//used when retrieving data from SQLite
int callback(void *na, int argc, char **argv, char **azColName)
{
     na = 0;
     for (int i = 0; i < argc; i++) {
         printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
     }
     printf("\n");
     return 0;
}

//right trim
void rtrim(char *s)
{
	s[strlen(s)-1]='\0';
}


//copy or concat lines into string
//if entry has 1 linetype (NEWPDS), copy line into var
//if entry has 2+ of the same linetype, concat lines
void processvals(char *val, char *data, char *sep)
{
	if(val[0] == '\0')
	{
		strncpy(val,data,strlen(data));
	}
	else
	{ 	strncat(val,sep,3);
		strncat(val,data,strlen(data));
	}
}


int main(void) {

========== REMAINDER OF ARTICLE TRUNCATED ==========