Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    Thread: reading a file like the unix tail -f command does
Post: RE: reading a file like the unix tail -f command d...

I suggest to read David Beazley's presentation Generator Tricks for Systems Programmers. On slides 74, 75, 76 there is example of tail -f implementation in Python. Following is excerpt from these sli...
perfringo News and Discussions 2 313 Mar-29-2024, 09:31 AM
    Thread: a better way to code this to fix a URL?
Post: RE: a better way to code this to fix a URL?

It seems that url will always contain // so why not just split and join and not bother whether is missing something or not: >>> urls = ["//example.com", "://example.com", "s://example.com", ...
perfringo News and Discussions 10 764 Mar-19-2024, 06:43 AM
    Thread: list.sort() returning None
Post: RE: list.sort() returning None

Reading documentation is always a good idea: Quote: list.sort(*, key=None, reverse=False) Sort the items of the list in place (the arguments can be used for sort customization, see sorted() for their...
perfringo General Coding Help 8 601 Mar-18-2024, 05:48 AM
    Thread: using > < for tuple , list,...
Post: RE: using > < for tuple , list,...

From documentation (Value Comparisons): Quote:Sequences compare lexicographically using comparison of corresponding elements. This means that order is important. This makes sense in strings (this is...
perfringo General Coding Help 3 487 Feb-05-2024, 12:31 PM
    Thread: [subprocess] Why stdout sent to stderr?
Post: RE: [subprocess] Why stdout sent to stderr?

I would be surprised if Python knows anything about run. However subprocess.run is another story.
perfringo General Coding Help 3 485 Jan-25-2024, 09:34 PM
    Thread: all of attributes and methods related to a special type
Post: RE: all of attributes and methods related to a spe...

(Jan-19-2024, 07:58 AM)akbarza Wrote: In IDLE, I typed list. and then pressed the tab key twice, it became list. and popped up a small window that contained all methods related to the list type. I ...
perfringo General Coding Help 4 492 Jan-19-2024, 01:11 PM
    Thread: all of attributes and methods related to a special type
Post: RE: all of attributes and methods related to a spe...

(Jan-18-2024, 06:48 AM)akbarza Wrote: how can I see all attributes and methods related to a special type? for example, I want to see all methods and attributes related to lists, how can I do it? For...
perfringo General Coding Help 4 492 Jan-18-2024, 10:59 AM
    Thread: Precision with Decimal Type
Post: RE: Precision with Decimal Type

Some things to consider: Documentation > 6.Modules > 6.1. More on modules Quote:Note that in general the practice of importing * from a module or package is frowned upon, since it often causes ...
perfringo General Coding Help 9 751 Jan-17-2024, 07:57 AM
    Thread: Stuck with using lists to solve task
Post: RE: Stuck with using lists to solve task

If using 0 and 1 to represent closed / open doors it's simple to toggle value using XOR (bitwise exclusive OR). Something along those lines (just an idea, haven't tested it): # 1 means door open, 0 m...
perfringo Homework 9 840 Jan-15-2024, 07:46 PM
    Thread: Why doesn't list require global keyword?
Post: RE: Why doesn't list require global keyword?

(Jan-15-2024, 01:35 AM)johnywhy Wrote: Unclear. x is mutable. I can say x+=1 It's always good idea to read documentation: 3. Data model > 3.1.1. Objects, values and types: Quote:The value of ...
perfringo General Coding Help 9 834 Jan-15-2024, 08:36 AM
    Thread: partial functions before knowing the values
Post: RE: partial functions before knowing the values

According to PEP 484 shouldn’t this be the intended way: def spam(*args: int): # do_something
perfringo General Coding Help 4 617 Dec-24-2023, 10:00 AM
    Thread: Can't Find Python (or Something)
Post: RE: Can't Find Python (or Something)

Too little information (for example how have you tried to run the code) but this should be self explanatory: Quote:zsh: command not found: python I have verified with the command python3 --version th...
perfringo General Coding Help 2 549 Nov-26-2023, 07:12 AM
    Thread: Grades Code":
Post: RE: Grades Code":

Just for fun: >>> [int(input(f"Enter mark {i}: ")) for i in range(1, 6)] Enter mark 1: 10 Enter mark 2: 20 Enter mark 3: 30 Enter mark 4: 40 Enter mark 5: 50 [10, 20, 30, 40, 50]
perfringo Homework 14 1,418 Nov-22-2023, 12:30 PM
    Thread: Create X Number of Variables and Assign Data
Post: RE: Create X Number of Variables and Assign Data

I concur that dictionary or list is the way to go. One way to create dictionary from sentence can be dictionary comprehension: >>> sentence = "All work and no play makes Jack a dull boy." ...
perfringo General Coding Help 8 973 Nov-14-2023, 08:46 AM
    Thread: usage of ^ in f_string
Post: RE: usage of ^ in f_string

Search is very wide subject and "how" depends on very many factors. For Python I personally follow this pattern: 1 Search Python built-in help 2. Search Python documentation at python.org 3. Search ...
perfringo General Coding Help 7 931 Nov-09-2023, 01:15 PM
    Thread: usage of ^ in f_string
Post: RE: usage of ^ in f_string

It's always a good idea to read documentation: Format String Syntax and Format Specification Mini-Language Quote:Three conversion flags are currently supported: '!s' which calls str() on the value, '...
perfringo General Coding Help 7 931 Nov-07-2023, 08:51 AM
    Thread: problem in using generator
Post: RE: problem in using generator

This is not generator specific. () signals to Python that this is a callable object and should be called. Python tries to do it. If you call it second time then it depends what first callable ret...
perfringo General Coding Help 2 546 Nov-07-2023, 08:40 AM
    Thread: difference between statement and expression
Post: RE: difference between statement and expression

It's always a good idea to start with documentation: Expression: Quote:A piece of syntax which can be evaluated to some value. In other words, an expression is an accumulation of expression elements...
perfringo General Coding Help 6 865 Oct-16-2023, 12:48 PM
    Thread: replace text in a txt
Post: RE: replace text in a txt

One way is to define required replacements in dictionary, then iterate over rows in file, split row to words and replace if needed or keep and write to new file. I haven't tested it but something like...
perfringo General Coding Help 19 2,249 Oct-12-2023, 09:43 AM
    Thread: problem in using enumerate
Post: RE: problem in using enumerate

(Oct-11-2023, 09:52 AM)akbarza Wrote: I have not seen * before in such syntax. what is it doing and for what is it used? This is iterable unpacking as described in PEP448. It is convenient and conci...
perfringo General Coding Help 4 799 Oct-11-2023, 10:55 AM

User Panel Messages

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