Python Forum
Search Results
Post Author Forum Replies Views Posted [asc]
    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 2 47 2 hours ago
    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 6 186 Yesterday, 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 393 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 399 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 393 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 393 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 614 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 716 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 594 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 525 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 466 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,208 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 834 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 819 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 819 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 421 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 754 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,049 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 728 Oct-11-2023, 10:55 AM
    Thread: problem in using enumerate
Post: RE: problem in using enumerate

(Oct-09-2023, 01:12 PM)akbarza Wrote: when you write and run the first for loop(lines 6.7), some data will be shown to you. but then if you write and run the for loop again (lines 9,10), nothing wi...
perfringo General Coding Help 4 728 Oct-09-2023, 03:36 PM

User Panel Messages

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