Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: I can't for the life of me get this basic If statement code to work
Post: RE: I can't for the life of me get this basic If s...

For the life of you? We don't want any deaths here! The problem is the 2 ifs, 1 after the other I think. I get: x = 5 if x < 10: print("smaller") x += 10 if x > 10: print('bigger'...
Pedroski55 General Coding Help 6 55 12 minutes ago
    Thread: Reading Baseball Box Scores
Post: RE: Reading Baseball Box Scores

This works for me and delivers a csv. You can then open the csv in pandas, or Excel, and calculate anything you want! (Don't know what you want.) There are 12 columns. Not all the lines we want are ...
Pedroski55 Homework 3 227 6 hours ago
    Thread: Can you explain the strings in Python
Post: RE: Can you explain the strings in Python

Just use f-string, no need for str() x = 2 print(f"Years on the force are {x}")You can even put a function in the curly brackets! x = 2 y = 2 def add(a, b): return a+b print(f"Years on the forc...
Pedroski55 General Coding Help 3 165 May-19-2024, 08:36 AM
    Thread: Help needed - UN voting records
Post: RE: Help needed - UN voting records

I am not an expert, like some of the guys here, but maybe this will help: A page with voting results looks like this: Quote:https://digitallibrary.un.org/record/4045078 You can get all these record...
Pedroski55 General Coding Help 2 182 May-19-2024, 06:49 AM
    Thread: Compare lists
Post: RE: Compare lists

I think it is best to make a third list as menator01 did. Keep the old ips_logged list unchanged, for possible future use. It is definitely not a good idea to delete items from a list as you iterate ...
Pedroski55 General Coding Help 4 228 May-18-2024, 04:03 PM
    Thread: Reading Baseball Box Scores
Post: RE: Reading Baseball Box Scores

Must be homework! I think you will find, people will not answer because they are waiting for you to show some effort, to show what you have tried so far. Here is a little something to get you starte...
Pedroski55 Homework 3 227 May-16-2024, 09:13 AM
    Thread: Regex to find triple characters
Post: RE: Regex to find triple characters

Quote:I am looking for a regex pattern to find the instance of 3 matching characters in series in a string. This finds all instances of "3 matching characters in series", as stated above. Is that NO...
Pedroski55 General Coding Help 14 462 May-14-2024, 01:04 PM
    Thread: Regex to find triple characters
Post: RE: Regex to find triple characters

This seems to work, although it contains 3 times opening bracket, (, but only 2 times closing bracket, ), which is weird! string = 'AAABBCCCDDEEEFFGGGHHIIIJJKKK' result = [match[0] for match in re.f...
Pedroski55 General Coding Help 14 462 May-14-2024, 08:20 AM
    Thread: Help!!!! Error in Code
Post: RE: Help!!!! Error in Code

Put the function names in only, without any quotes or brackets: operations = {"+" : add, "-" : subtract, "*" : multiply, "/" : divide }Then Answ...
Pedroski55 General Coding Help 3 254 May-13-2024, 02:12 PM
    Thread: Understanding subprocess.Popen
Post: RE: Understanding subprocess.Popen

OK, thanks again!
Pedroski55 General Coding Help 6 304 May-12-2024, 10:46 AM
    Thread: Understanding subprocess.Popen
Post: RE: Understanding subprocess.Popen

I use Ubuntu 22.04 LTS
Pedroski55 General Coding Help 6 304 May-12-2024, 10:20 AM
    Thread: Understanding subprocess.Popen
Post: RE: Understanding subprocess.Popen

Aha! Thanks! Using python I just get a lot of blurb + Output:FileNotFoundError: [Errno 2] No such file or directory: 'python'But if I use python3, it works: sp.run(['python3', '-c', 'import os; pri...
Pedroski55 General Coding Help 6 304 May-12-2024, 09:54 AM
    Thread: Understanding subprocess.Popen
Post: Understanding subprocess.Popen

The code I use is from here, Part 5 Just playing around with generators, I have a Python script to simulate a log file which is constantly updated, then another script, follow.py to get the last line...
Pedroski55 General Coding Help 6 304 May-12-2024, 07:30 AM
    Thread: short version of os.listdir()
Post: RE: short version of os.listdir()

Fun with generators! from pathlib import Path import sys mydir = Path('/home/pedro') filelist = (filename for filename in mydir.rglob("*") if filename.is_file()) type(filelist) # generator sys.getsi...
Pedroski55 General Coding Help 11 526 May-12-2024, 05:14 AM
    Thread: gnome-terminal
Post: RE: gnome-terminal

This worked for me: import os os.system("gnome-terminal -e 'sudo apt update'") os.system("gnome-terminal -e 'sudo apt upgrade'")But I could not link the 2 commands with && Why would you do ...
Pedroski55 General Coding Help 5 338 May-10-2024, 06:11 PM
    Thread: Trying to generating multiple json files using python script
Post: RE: Trying to generating multiple json files using...

Lately, I have been learning about generators, so I thought, "I could do this with a generator or two." This is the same as above, but using a generator: import json from pathlib import Path # save...
Pedroski55 General Coding Help 4 274 May-10-2024, 08:39 AM
    Thread: Trying to generating multiple json files using python script
Post: RE: Trying to generating multiple json files using...

You can try like this: import csv import json from pathlib import Path # save your Excel file as csv """ The first 7 column headers should be something like this version type productCode assetco...
Pedroski55 General Coding Help 4 274 May-10-2024, 07:45 AM
    Thread: Extending list doesn't work as expected
Post: RE: Extending list doesn't work as expected

I think, outside of the class Test you would need a copy of list1 or list2, or you will alter them, but within the class, this seems to work ok without list1.copy() or list2.copy(). Oh the joys of c...
Pedroski55 General Coding Help 2 238 May-09-2024, 05:39 PM
    Thread: Use or raw string on regular expressions
Post: RE: Use or raw string on regular expressions

It is important to know that re uses its own parser to look at string expressions. Python passes a string or a raw string to re and re takes over. Try this: Quote:pattern = '\n' pattern '\n' pattern...
Pedroski55 General Coding Help 5 341 May-09-2024, 06:26 AM
    Thread: Keep getting "SyntaxError: incomplete input" but can't see why.
Post: RE: Keep getting "SyntaxError: incomplete input" ...

Funny, I did not forget line 46. The script runs as a whole in bash, no problem. I just wanted to run it in bits in Idle and I get the syntax error. Thanks for the link!
Pedroski55 General Coding Help 3 453 May-08-2024, 06:40 AM

User Panel Messages

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