Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: [SOLVED] Loop through directories and files one level down?
Post: RE: Loop through directories and files one level d...
(5 hours ago)Winfried Wrote: This finally works:You don't need to change the process' working directory for every subdirectory. A better code is
from pathlib import Path
for subdir in Path(ROOT).i... |
|
Gribouillis |
General Coding Help |
3 |
83 |
4 hours ago |
|
|
Thread: UART write binary code
Post: RE: UART write binary code
You could try this (perhaps not the most efficient)
>>> bytes([int('00001111', 2)])
b'\x0f'
>>> int('00001111', 2).to_bytes(1, 'little')
b'\x0f' |
|
Gribouillis |
General Coding Help |
3 |
94 |
10 hours ago |
|
|
Thread: intering int number
Post: RE: intering int number
(11 hours ago)akbarza Wrote: but this is inconsistence with result of running line 22 of the above code.
can explain to me the reason of this?It can be explained very easily by considering the bytec... |
|
Gribouillis |
General Coding Help |
1 |
87 |
10 hours ago |
|
|
Thread: API design an choice
Post: RE: API design an choice
(Yesterday, 05:26 PM)Skaperen Wrote: does it break anything if they can also take multiple arguments (e.g. args* in the prototype)?It does not break anything except perhaps future interfaces of your... |
|
Gribouillis |
News and Discussions |
4 |
166 |
Today, 06:44 AM |
|
|
Thread: negative memory usage
Post: RE: negative memory usage
(Yesterday, 07:41 AM)akbarza Wrote: the usage of memory is shown as a negative number! why?I think it is negative because the code deletes the previously calculated list cubes. You could correct thi... |
|
Gribouillis |
General Coding Help |
1 |
109 |
Yesterday, 08:43 AM |
|
|
Thread: API design an choice
Post: RE: API design an choice
Built-in functions all() and any() take a single iterable argument. That would be my preferred choice for the sake of consistency and simplicity. |
|
Gribouillis |
News and Discussions |
4 |
166 |
Yesterday, 07:27 AM |
|
|
Thread: Using xml.parsers.expat I can't get parser.ParseFile(f) to work
Post: RE: Using xml.parsers.expat I can't get parser.Par...
Have you tried opening in binary mode?
open(xmlfile, 'rb') |
|
Gribouillis |
General Coding Help |
3 |
184 |
Apr-24-2024, 06:23 AM |
|
|
Thread: Right way to open files with different encodings?
Post: RE: Right way to open files with different encodin...
(Apr-23-2024, 08:49 AM)Winfried Wrote: Is try/except the right way to do it?Normally, there is no way to decode a file having an unknown unicode encoding. Specialized modules such as chardet contain... |
|
Gribouillis |
General Coding Help |
2 |
251 |
Apr-23-2024, 09:15 AM |
|
|
Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?
(Apr-23-2024, 08:11 AM)snippsat Wrote: To mix ios and pathlib may be more confusing than it need to be,this dos just the same with pathlib alone.What I don't like with the pathlib solution is the ca... |
|
Gribouillis |
General Coding Help |
10 |
450 |
Apr-23-2024, 08:37 AM |
|
|
Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?
(Apr-23-2024, 02:02 AM)Winfried Wrote: I'm not used to one-liners. Am I correct in understanding it's the equivalent of the following?It is not exactly equivalent because the one-liner here produces... |
|
Gribouillis |
General Coding Help |
10 |
450 |
Apr-23-2024, 07:22 AM |
|
|
Thread: Loop through all files in a directory?
Post: RE: Loop through all files in a directory?
You could use
import os
root = '.'
files = [os.path.join(d, f) for d, _, files in os.walk(root) for f in files]
print(files) |
|
Gribouillis |
General Coding Help |
10 |
450 |
Apr-22-2024, 07:10 PM |
|
|
Thread: What does .flush do? How can I change this to write to the file?
Post: RE: What does .flush do? How can I change this to ...
Try
print(f'{ips[n]},{date},{docs[m]}', file=f)
f.flush() |
|
Gribouillis |
General Coding Help |
3 |
243 |
Apr-22-2024, 10:25 AM |
|
|
Thread: cmd terminal
Post: RE: cmd terminal
(Apr-22-2024, 04:30 AM)Rice23 Wrote: If one wishes to display the output from the command, how can it be obtained from the Popen call and displayed in a tkinter window?You can write
process = subpr... |
|
Gribouillis |
General Coding Help |
6 |
483 |
Apr-22-2024, 06:54 AM |
|
|
Thread: How does this code create a class?
Post: RE: How does this code create a class?
(Apr-21-2024, 05:08 AM)Pedroski55 Wrote: Now you are confusing me, but I am often confused, doesn't matter!Yes, the word function is misleading. The accurate word for this is callable. A class is ca... |
|
Gribouillis |
General Coding Help |
6 |
447 |
Apr-21-2024, 06:15 AM |
|
|
Thread: How does this code create a class?
Post: RE: How does this code create a class?
(Apr-19-2024, 04:38 PM)Pedroski55 Wrote: I am mainly interested in what practical use anything can be, in order to make a given task easier and faster.Having a consistent language makes the task of ... |
|
Gribouillis |
General Coding Help |
6 |
447 |
Apr-20-2024, 08:05 AM |
|
|
Thread: How does this code create a class?
Post: RE: How does this code create a class?
(Apr-19-2024, 10:56 AM)Pedroski55 Wrote: I don't understand classes in Python!
Why do I get a class like this, without declaring a class??Every object in python is an instance of some class. This a... |
|
Gribouillis |
General Coding Help |
6 |
447 |
Apr-19-2024, 12:00 PM |
|
|
Thread: convert to bin problem
Post: RE: convert to bin problem
Conversion to int removed the zeros at the beginning. You could simply add a 1 at the beginning
s = '1'+ a[2:]
c = int(s) |
|
Gribouillis |
General Coding Help |
3 |
281 |
Apr-19-2024, 05:21 AM |
|
|
Thread: python calculate float plus float is incorrect?
Post: RE: python calculate float plus float is incorrect...
I don't know PHP, but here is a warning about the same thing in PHP. I don't know why it displays 41.34 in your case (perhaps an effect of the echo command?). Try their example perhaps
Output:floor((0... |
|
Gribouillis |
General Coding Help |
6 |
327 |
Apr-16-2024, 10:34 AM |
|
|
Thread: python calculate float plus float is incorrect?
Post: RE: python calculate float plus float is incorrect...
It is all explained here. Also it has nothing to do with Python. It's due to the internal representation of floating point numbers by computers. The same issue exists in other programming languages. |
|
Gribouillis |
General Coding Help |
6 |
327 |
Apr-16-2024, 09:03 AM |
|
|
Thread: Hide CMD call window
Post: RE: Hide CMD call window
Is it the same if you use
cmd = ['arp', '-a'] |
|
Gribouillis |
General Coding Help |
8 |
326 |
Apr-15-2024, 07:53 PM |