task_boiler
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
task_boiler [2023/05/03 16:40] – [find depth of a file or directory] admin | task_boiler [2024/01/22 22:59] – [Issue] raju | ||
---|---|---|---|
Line 4: | Line 4: | ||
Start the first heading with " | Start the first heading with " | ||
- | ===== find depth ===== | + | ===== blocked by barrons |
- | ==== find depth of a file or directory | + | ==== Issue ==== |
+ | barrons.com is giving the following error. | ||
< | < | ||
- | import os | + | You have been blocked. |
- | + | ||
- | def get_depth(file_or_dir_path): | + | |
- | abs_path = os.path.abspath(os.path.expanduser(file_or_dir_path)) | + | |
- | depth = os.path.normpath(abs_path).count(os.sep) | + | |
- | return depth | + | |
- | </ | + | |
- | Examples: | + | Why? |
- | < | + | Something about the behaviour of the browser has caught our |
- | In [2]: | + | attention. |
- | os.path.abspath(os.path.expanduser(' | + | |
- | Out[2]: | + | |
- | '/ | + | |
- | In [3]: | + | There are various possible explanations for this: |
- | get_depth(' | + | * You are browsing and clicking at a speed much faster than |
- | Out[3]: | + | |
- | 2 | + | * Something is preventing JavaScript from working on your |
+ | computer. | ||
+ | * There is a robot on the same network (IP WW.XX.YY.ZZ) as you. | ||
- | In [4]: | + | Having problems accessing the site? Submit feedback. |
- | get_depth('/ | + | ID: a-b-c-d-e |
- | Out[4]: | + | |
- | 2 | + | |
- | + | ||
- | In [5]: | + | |
- | get_depth('/ | + | |
- | Out[5]: | + | |
- | 2 | + | |
- | + | ||
- | In [6]: | + | |
- | get_depth('/ | + | |
- | Out[6]: | + | |
- | 3 | + | |
- | + | ||
- | In [7]: | + | |
- | get_depth('/' | + | |
- | Out[7]: | + | |
- | 1 | + | |
- | + | ||
- | In [8]: | + | |
- | get_depth('/ | + | |
- | Out[8]: | + | |
- | 1 | + | |
</ | </ | ||
- | Using Python 3.10.6, Ipython 8.6.0 | + | ==== Solution ==== |
+ | Click on the extensions button in the top right | ||
+ | -> Bypass Paywalls Clean -> settings button -> Options | ||
+ | -> scroll down to "BPC settings" | ||
+ | -> check " | ||
+ | -> Save | ||
- | tags | measure the depth of a file system path | + | ==== System Information |
- | + | * bypass paywalls clean extension version: 3.5.2.1 (latest asof 2024-01-22) | |
- | See also: | + | * google chrome: 120.0.6099.200 |
- | * https:// | + | * OS: Windows 10 Enterprise |
- | * https:// | + | |
- | + | ||
- | ==== depth of a directory relative to a parent directory | + | |
- | < | + | |
- | import os | + | |
- | + | ||
- | def dir_depth_relative(child, | + | |
- | child = os.path.abspath(os.path.expanduser(child)) | + | |
- | parent = os.path.abspath(os.path.expanduser(parent)) | + | |
- | assert child.startswith(parent), | + | |
- | name_space = os.path.relpath(child, | + | |
- | level = os.path.normpath(name_space).count(os.sep) + 1 if name_space != ' | + | |
- | return level | + | |
- | </ | + | |
- | + | ||
- | Examples: | + | |
- | < | + | |
- | In [2]: | + | |
- | [dir_depth_relative(' | + | |
- | | + | |
- | | + | |
- | | + | |
- | Out[2]: | + | |
- | [0, 0, 1, 1, 1, 0, 2] | + | |
- | + | ||
- | In [3]: | + | |
- | dir_depth_relative('/ | + | |
- | --------------------------------------------------------------------------- | + | |
- | AssertionError | + | |
- | Cell In [3], line 1 | + | |
- | ----> 1 dir_depth_relative('/ | + | |
- | + | ||
- | Cell In [1], line 6, in dir_depth_relative(child, | + | |
- | 4 child = os.path.abspath(os.path.expanduser(child)) | + | |
- | 5 parent = os.path.abspath(os.path.expanduser(parent)) | + | |
- | ----> 6 assert child.startswith(parent), | + | |
- | 7 name_space = os.path.relpath(child, | + | |
- | 8 level = os.path.normpath(name_space).count(os.sep) + 1 if name_space != ' | + | |
- | + | ||
- | AssertionError: child parent relation violated. parent = /tmp/foo, child = /tmp | + | |
- | </ | + | |
task_boiler.txt · Last modified: 2024/01/23 22:55 by raju