question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: path completion with pathlib objects

See original GitHub issue

So, I love how ipython can path-complete strings to dig through your folders. But I increasingly work with pathlib.Path objects for their increased readability and useful object attributes to access sub-paths. Would it be possible to have ipython to be able to path-complete on a pathlib.Path folder? So, I would like to be able to do something like this:

from pathlib import Path

root = Path("/abc/myfolder")

f1 = root / "f342<TAB>"
f2 = root / "f569<TAB>"

Hope this is understandable? With <TAB> I mean I press the TAB key at that point, to have ipython complete that string part of the full path.

Cheers!

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
carlsmithcommented, Apr 11, 2017

Opps! Sorry.

from IPython.core.magic import register_line_magic as line_magic
1reaction
carlsmithcommented, Apr 11, 2017

I wrapped the Path constructor in a line magic for doing a similar thing interactively.

from pathlib import Path

@line_magic
def path(args): return Path(args)

del path

With that set up, you can then do stuff like this (with tab completion):

home = %path ~/

It’s of pretty limited use, but it lets you create paths using tab completion when working interactively.

Read more comments on GitHub >

github_iconTop Results From Across the Web

File paths completion in Python pathlib.Path objects : PY-39983
File paths completion in Python pathlib.Path objects ; Type, Feature ; State, Submitted S ; Assignee, Andrey Vlasovskikh ; Subsystem, Code Insight ;...
Read more >
Python 3's pathlib Module: Taming the File System
In this tutorial, you have seen how to create Path objects, read and write files, manipulate paths and the underlying file system, as...
Read more >
How to enable the pathlib.Path autocompletion in VSCode ...
I would like to take advantage of this feature in the file editor too. Is there a way to activate it, or is...
Read more >
pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >
Easier Python paths with pathlib - Linux Journal
Rather than working with strings, instead you work with "Path" objects, which not only allows you to use all of your favorite path-...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found