Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: detecting a generstor passed to a funtion
Post: RE: detecting a generstor passed to a funtion

(Sep-19-2021, 07:55 AM)buran Wrote: Not sure what you mean with this comment. The output is from inspect import isgeneratorfunction def normal_function(): return None def generator_function()...
DeaD_EyE General Coding Help 9 197 Sep-19-2021, 11:08 AM
    Thread: detecting a generstor passed to a funtion
Post: RE: detecting a generstor passed to a funtion

from collections.abc import Generator from typing import Generator as TypingGenerator from inspect import isgeneratorfunction, isgenerator def foo(): """Function""" def bar(): """Generatorf...
DeaD_EyE General Coding Help 9 197 Sep-19-2021, 06:06 AM
    Thread: Have to use Python 2.x to find "yesterday' files
Post: RE: Have to use Python 2.x to find "yesterday' fil...

from __future__ import print_function from collections import namedtuple from datetime import datetime, timedelta from os import listdir from os.path import getmtime from os.path import join as joinp...
DeaD_EyE General Coding Help 6 191 Sep-18-2021, 01:36 PM
    Thread: Simple Distance Between Points Calculator
Post: RE: Simple Distance Between Points Calculator

#This Program will ask the user to enter two points in the form #(x1,y1) and (x2,y2) import math x1 = float(input("Enter X1:")) y1 = float(input("Enter Y1:")) x2 = float(input("Enter X2:")) y2 = f...
DeaD_EyE Homework 1 135 Sep-17-2021, 03:14 PM
    Thread: VS Code Python Formatter
Post: RE: VS Code Python Formatter

(Sep-06-2021, 02:59 PM)muzikman Wrote: How many spaces do you use? I use 0 spaces. My IDE (PyCharm) indents by 4 Spaces (PEP8) if I press the tabulator key. Just use an IDE. PyCharm has also a 3rd ...
DeaD_EyE General Coding Help 6 313 Sep-16-2021, 04:40 PM
    Thread: python regex: get rid of double dot
Post: RE: python regex: get rid of double dot

ifconfig is deprecated and should not be used. If you use iproute2, which is state of the art, you can use json data and prevent the use of regex. To show ip addresses of all interfaces: ip addrTo sh...
DeaD_EyE General Coding Help 4 223 Sep-08-2021, 04:35 PM
    Thread: VS Code Python Formatter
Post: RE: VS Code Python Formatter

Just don't use tabs: https://www.python.org/dev/peps/pep-0008...-or-spaces If you use tabs, you've to use them everywhere. Mixing tabs and whitespace ends in a IndentationError which means also, tha...
DeaD_EyE General Coding Help 6 313 Sep-06-2021, 02:56 PM
  Information Thread: Multiple inputs on the same line (beginner)
Post: RE: Multiple inputs on the same line (beginner)

You can use datetime.datetime.strptime. If you want that the user must enter Month Day Year, use as format_str "%m %d %y" The format in my example: "%m/%d/%y" -> 12/31/21 %m = Month as a zero-pad...
DeaD_EyE General Coding Help 9 340 Sep-03-2021, 11:11 AM
    Thread: Running A Loop Until You See A Particular Result
Post: RE: Running A Loop Until You See A Particular Resu...

Some improvements + error corrections + info about urls.. import random import sys import time import requests # Take the right protocol # "testurl.com" is not a valid URL # "http://testurl.com" is...
DeaD_EyE General Coding Help 6 6,360 Sep-01-2021, 02:20 PM
    Thread: Which method for arrays is faster ?
Post: RE: Which method for arrays is faster ?

Scenario 1: You make a list and fill it with data. Task done. Scenario 2: You've to repeat this one million times. If scenario 2 is the case, then preallocate the numpy.array once. Then you can work...
DeaD_EyE General Coding Help 2 222 Aug-31-2021, 10:58 AM
    Thread: Serial connection connection issue
Post: RE: Serial connection connection issue

You should not type python or python3 in your terminal. First you should look, if you've installed more than one Python Interpreter on your system with py. This shows all available Python Interprete...
DeaD_EyE General Coding Help 15 652 Aug-30-2021, 01:20 PM
    Thread: Simple Method to calculate average and grade
Post: RE: Simple Method to calculate average and grade

You can use the bisect module, to get the index-position for a value to insert it in an ordered list (small to big values). import bisect def get_grade(value): grades_values = (70, 80, 90) ...
DeaD_EyE Homework 7 718 Aug-27-2021, 01:22 PM
    Thread: Pop function for lists
Post: RE: Pop function for lists

Example to modify the data: indices = [1,3,4] data = ['a','b','c','d','e'] for index in sorted(indices, reverse=True): del data[index]If you delete elements from a list, the list shrinks. To pre...
DeaD_EyE General Coding Help 8 432 Aug-25-2021, 03:09 PM
    Thread: Search string in mutliple .gz files
Post: RE: Search string in mutliple .gz files

(Aug-25-2021, 04:18 AM)ndc85430 Wrote: What's the reason for reimplementing zgrep? Reimplementing it in Python is better like this: import subprocess def zgrep(file, pattern): proc = subproce...
DeaD_EyE General Coding Help 10 678 Aug-25-2021, 08:47 AM
    Thread: Sorting and Merging text-files
Post: RE: Sorting and Merging text-files

#!/usr/bin/env python3 from pathlib import Path def sort_by_int(path): # Path has the stem attribute, which is # the filename without the last extension # to sort the paths by integer, ...
DeaD_EyE General Coding Help 10 519 Aug-19-2021, 02:08 PM
    Thread: Search string in mutliple .gz files
Post: RE: Search string in mutliple .gz files

It looks like an ancient example for Python 2, which is really out of date. Here is a working example with some Python magic: #!/usr/bin/env python3 # You should use Python 3 and don't touch Python ...
DeaD_EyE General Coding Help 10 678 Aug-18-2021, 02:35 PM
    Thread: String in a list
Post: RE: String in a list

If you iterate over a str, you'll get single characters as str. EAN is a str. I guess you want to split the str at the commas. EAN = '0036880008152317,004753b02142802,00138f825183,0246b6513b2f7' for...
DeaD_EyE General Coding Help 3 163 Aug-18-2021, 02:08 PM
    Thread: How would I use Watchdog to get triggered when DVD is inserted?
Post: RE: How would I use Watchdog to get triggered when...

I think you can't use the Watchdog to observe media Changes. Polling the directory the whole time is ineffective and if a CD is in your drive, it will always spin up during polling. This can be very a...
DeaD_EyE General Coding Help 12 650 Aug-17-2021, 08:15 AM
    Thread: best way to use switch case?
Post: RE: best way to use switch case?

Quote:OBD-II PIDs (On-board diagnostics Parameter IDs) are codes used to request data from a vehicle, used as a diagnostic tool. But programmers think of Process ID, if they read PID. Each parameter...
DeaD_EyE General Coding Help 8 498 Aug-11-2021, 02:09 PM
    Thread: enter string into list according to a known rule
Post: RE: enter string into list according to a known ru...

The provided example could not work because the quoting is missing. import binascii from_your_post = "d8 59 80 a2 c8 be f4 92".replace(" ","") # unhexlify can not handle whitespaces, so I've repla...
DeaD_EyE General Coding Help 10 496 Aug-11-2021, 02:06 PM

User Panel Messages

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